Skip to content

Commit

Permalink
Code overhaul/cleanup
Browse files Browse the repository at this point in the history
- Downsize classes
- Overhaul config.yml
- Take advantage of BlockDropItemEvent for drop logic
- Allow configuration of drops to remove
- Add /dropsoverhaul command
- Add /dropsoverhaul reload to reload configuration
- Rename /killdrops to /dropsoverhaul killdrops
- Allow messages to be configured in config.yml
- Remove default-everyone-killdrops option, permission can just be negated
- Add BitByLogic to authors
  • Loading branch information
BitByLogics committed May 21, 2024
1 parent 11ae51c commit 443f0b0
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 286 deletions.
43 changes: 43 additions & 0 deletions src/main/java/org/infotoast/dropsoverhaul/DropsOverhaul.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.infotoast.dropsoverhaul;

import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.infotoast.dropsoverhaul.command.DropsOverhaulCommand;

import java.util.HashMap;

public class DropsOverhaul extends JavaPlugin implements Listener {

@Override
public void onEnable() {
saveDefaultConfig();

getCommand("dropsoverhaul").setExecutor(new DropsOverhaulCommand(this));
getServer().getPluginManager().registerEvents(this, this);

getLogger().info("DropsOverhaul has been enabled!");
}

@EventHandler
public void onBlockDrop(BlockDropItemEvent event) {
if (!getConfig().getStringList("Settings.Drops-To-Remove").contains(event.getBlockState().getType().name())) {
return;
}

event.setCancelled(true);

ItemStack[] items = event.getItems().stream().map(Item::getItemStack).toArray(ItemStack[]::new);
HashMap<Integer, ItemStack> leftOver = event.getPlayer().getInventory().addItem(items);

if (leftOver.isEmpty() || getConfig().getBoolean("Settings.Full-Inventory-Delete")) {
return;
}

leftOver.values().forEach(item -> event.getPlayer().getWorld().dropItemNaturally(event.getPlayer().getLocation(), item));
}

}
100 changes: 0 additions & 100 deletions src/main/java/org/infotoast/dropsoverhaul/ItemLists.java

This file was deleted.

110 changes: 0 additions & 110 deletions src/main/java/org/infotoast/dropsoverhaul/Listener.java

This file was deleted.

61 changes: 0 additions & 61 deletions src/main/java/org/infotoast/dropsoverhaul/Plugin.java

This file was deleted.

Loading

0 comments on commit 443f0b0

Please sign in to comment.