diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index c2b27dd14..57ad25c50 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.commands.Commandfireball; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.TextInput; @@ -68,9 +69,22 @@ public class EssentialsPlayerListener implements Listener { } } + private static boolean isArrowPickupEvent() { + try { + Class.forName("org.bukkit.event.player.PlayerPickupArrowEvent"); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } + } + public void registerEvents() { ess.getServer().getPluginManager().registerEvents(this, ess); + if (isArrowPickupEvent()) { + ess.getServer().getPluginManager().registerEvents(new ArrowPickupListener(), ess); + } + if (isEntityPickupEvent()) { ess.getServer().getPluginManager().registerEvents(new PickupListener1_12(), ess); } else { @@ -814,10 +828,21 @@ public class EssentialsPlayerListener implements Listener { user.updateActivityOnInteract(true); } + private final class ArrowPickupListener implements Listener { + @EventHandler(priority = EventPriority.LOW) + public void onArrowPickup(final org.bukkit.event.player.PlayerPickupArrowEvent event) { + if (event.getArrow().hasMetadata(Commandfireball.FIREBALL_META_KEY)) { + event.setCancelled(true); + } + } + } + private final class PickupListenerPre1_12 implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerPickupItem(final org.bukkit.event.player.PlayerPickupItemEvent event) { - if (ess.getSettings().getDisableItemPickupWhileAfk()) { + if (event.getItem().hasMetadata(Commandfireball.FIREBALL_META_KEY)) { + event.setCancelled(true); + } else if (ess.getSettings().getDisableItemPickupWhileAfk()) { if (ess.getUser(event.getPlayer()).isAfk()) { event.setCancelled(true); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java index 3c07079c5..b5bbea5a4 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandfireball.java @@ -7,6 +7,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.bukkit.Server; import org.bukkit.entity.*; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; import java.util.Collections; @@ -17,6 +18,9 @@ import java.util.stream.Collectors; import static com.earth2me.essentials.I18n.tl; public class Commandfireball extends EssentialsCommand { + + public static final String FIREBALL_META_KEY = "ess_fireball_proj"; + private static final Map> types; static { @@ -77,6 +81,7 @@ public class Commandfireball extends EssentialsCommand { Projectile projectile = user.getWorld().spawn(user.getBase().getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), types.get(type)); projectile.setShooter(user.getBase()); projectile.setVelocity(direction); + projectile.setMetadata(FIREBALL_META_KEY, new FixedMetadataValue(ess, true)); if (ride) { projectile.addPassenger(user.getBase());