Added drop event for custom blocks (API)

This commit is contained in:
Aria Sangarin 2020-01-30 20:45:31 +01:00
parent 7f6e99edb9
commit 5be55f547b
3 changed files with 58 additions and 1 deletions

View File

@ -0,0 +1,47 @@
package net.Indyuce.mmoitems.api.event.blocks;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.api.CustomBlock;
public class CustomBlockDropEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final CustomBlock custom;
private final ItemStack drop;
public CustomBlockDropEvent(Player p, CustomBlock c, ItemStack d) {
super(p); custom = c; drop = d;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean value) {
cancelled = value;
}
public CustomBlock getCustomBlock() {
return custom;
}
public ItemStack getDrop() {
return drop;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -430,6 +430,11 @@ public class MMOItemsCommand implements CommandExecutor {
if (args[1].equalsIgnoreCase("recipes")) {
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> {
MMOItems.plugin.getRecipes().reloadRecipes();
if(MMOItems.plugin.getConfig().getBoolean("auto-recipe-book"))
for(Player p : Bukkit.getOnlinePlayers())
p.discoverRecipes(MMOItems.plugin.getRecipes().getNamespacedKeys());
sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reloaded recipes.");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getRecipes().size() + ChatColor.GRAY + " Recipes");
});

View File

@ -25,6 +25,7 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.CustomBlock;
import net.Indyuce.mmoitems.api.drop.DropTable;
import net.Indyuce.mmoitems.api.event.blocks.CustomBlockDropEvent;
import net.Indyuce.mmoitems.listener.CustomBlockListener;
import net.mmogroup.mmolib.MMOLib;
@ -97,7 +98,11 @@ public class DropTableManager implements Listener {
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
if(CustomBlockListener.getPickaxePower(player) >= custom.getRequiredPower())
for (ItemStack drop : customBlocks.get(custom.getId()).read(hasSilkTouchTool(player))) {
Item item = block.getWorld().dropItemNaturally(block.getLocation().add(.5, .1, .5), drop);
CustomBlockDropEvent called = new CustomBlockDropEvent(player, custom, drop);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
Item item = block.getWorld().dropItemNaturally(block.getLocation().add(.5, .1, .5), called.getDrop());
item.setVelocity(item.getVelocity().multiply(0.5f));
}
}, 2);