From e221e93243d151eb3937320052408f92ad44f2d1 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 3 Oct 2020 20:00:39 +0200 Subject: [PATCH 1/2] Fixed throw up items picked up by hoppers --- .../Indyuce/mmoitems/ability/Item_Bomb.java | 4 ++-- .../Indyuce/mmoitems/ability/Item_Throw.java | 4 ++-- .../mmoitems/ability/Present_Throw.java | 4 ++-- .../Indyuce/mmoitems/ability/Throw_Up.java | 4 ++-- ...nteractItemEntity.java => NoClipItem.java} | 21 ++++++++++++------- 5 files changed, 21 insertions(+), 16 deletions(-) rename src/main/java/net/Indyuce/mmoitems/api/util/{NoInteractItemEntity.java => NoClipItem.java} (68%) diff --git a/src/main/java/net/Indyuce/mmoitems/ability/Item_Bomb.java b/src/main/java/net/Indyuce/mmoitems/ability/Item_Bomb.java index e7572e61..055e1bca 100644 --- a/src/main/java/net/Indyuce/mmoitems/ability/Item_Bomb.java +++ b/src/main/java/net/Indyuce/mmoitems/ability/Item_Bomb.java @@ -18,7 +18,7 @@ import net.Indyuce.mmoitems.api.ability.Ability; import net.Indyuce.mmoitems.api.ability.AbilityResult; import net.Indyuce.mmoitems.api.ability.VectorAbilityResult; import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats; -import net.Indyuce.mmoitems.api.util.NoInteractItemEntity; +import net.Indyuce.mmoitems.api.util.NoClipItem; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.mmogroup.mmolib.api.AttackResult; import net.mmogroup.mmolib.api.DamageType; @@ -51,7 +51,7 @@ public class Item_Bomb extends Ability implements Listener { return; } - final NoInteractItemEntity item = new NoInteractItemEntity(stats.getPlayer().getLocation().add(0, 1.2, 0), itemStack); + final NoClipItem item = new NoClipItem(stats.getPlayer().getLocation().add(0, 1.2, 0), itemStack); item.getEntity().setVelocity(((VectorAbilityResult) ability).getTarget().multiply(1.3)); stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_SNOWBALL_THROW, 2, 0); diff --git a/src/main/java/net/Indyuce/mmoitems/ability/Item_Throw.java b/src/main/java/net/Indyuce/mmoitems/ability/Item_Throw.java index 988611b7..e7ec09ad 100644 --- a/src/main/java/net/Indyuce/mmoitems/ability/Item_Throw.java +++ b/src/main/java/net/Indyuce/mmoitems/ability/Item_Throw.java @@ -16,7 +16,7 @@ import net.Indyuce.mmoitems.api.ability.Ability; import net.Indyuce.mmoitems.api.ability.AbilityResult; import net.Indyuce.mmoitems.api.ability.VectorAbilityResult; import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats; -import net.Indyuce.mmoitems.api.util.NoInteractItemEntity; +import net.Indyuce.mmoitems.api.util.NoClipItem; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.mmogroup.mmolib.api.AttackResult; import net.mmogroup.mmolib.api.DamageType; @@ -45,7 +45,7 @@ public class Item_Throw extends Ability implements Listener { return; } - final NoInteractItemEntity item = new NoInteractItemEntity(stats.getPlayer().getLocation().add(0, 1.2, 0), itemStack); + final NoClipItem item = new NoClipItem(stats.getPlayer().getLocation().add(0, 1.2, 0), itemStack); item.getEntity().setVelocity(((VectorAbilityResult) ability).getTarget().multiply(1.5 * ability.getModifier("force"))); stats.getPlayer().getWorld().playSound(stats.getPlayer().getLocation(), Sound.ENTITY_SNOWBALL_THROW, 1, 0); new BukkitRunnable() { diff --git a/src/main/java/net/Indyuce/mmoitems/ability/Present_Throw.java b/src/main/java/net/Indyuce/mmoitems/ability/Present_Throw.java index 3e0ecc4d..f5dade0d 100644 --- a/src/main/java/net/Indyuce/mmoitems/ability/Present_Throw.java +++ b/src/main/java/net/Indyuce/mmoitems/ability/Present_Throw.java @@ -23,7 +23,7 @@ import net.Indyuce.mmoitems.api.ability.Ability; import net.Indyuce.mmoitems.api.ability.AbilityResult; import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult; import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats; -import net.Indyuce.mmoitems.api.util.NoInteractItemEntity; +import net.Indyuce.mmoitems.api.util.NoClipItem; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.mmogroup.mmolib.api.AttackResult; import net.mmogroup.mmolib.api.DamageType; @@ -69,7 +69,7 @@ public class Present_Throw extends Ability { double damage = ability.getModifier("damage"); double radiusSquared = Math.pow(ability.getModifier("radius"), 2); - final NoInteractItemEntity item = new NoInteractItemEntity(stats.getPlayer().getLocation().add(0, 1.2, 0), present); + final NoClipItem item = new NoClipItem(stats.getPlayer().getLocation().add(0, 1.2, 0), present); item.getEntity().setVelocity(stats.getPlayer().getEyeLocation().getDirection().multiply(1.5 * ability.getModifier("force"))); /* diff --git a/src/main/java/net/Indyuce/mmoitems/ability/Throw_Up.java b/src/main/java/net/Indyuce/mmoitems/ability/Throw_Up.java index 78c92904..cd76f1fc 100644 --- a/src/main/java/net/Indyuce/mmoitems/ability/Throw_Up.java +++ b/src/main/java/net/Indyuce/mmoitems/ability/Throw_Up.java @@ -18,7 +18,7 @@ import net.Indyuce.mmoitems.api.ability.Ability; import net.Indyuce.mmoitems.api.ability.AbilityResult; import net.Indyuce.mmoitems.api.ability.SimpleAbilityResult; import net.Indyuce.mmoitems.api.player.PlayerStats.CachedStats; -import net.Indyuce.mmoitems.api.util.NoInteractItemEntity; +import net.Indyuce.mmoitems.api.util.NoClipItem; import net.Indyuce.mmoitems.stat.data.AbilityData; import net.mmogroup.mmolib.MMOLib; import net.mmogroup.mmolib.api.AttackResult; @@ -65,7 +65,7 @@ public class Throw_Up extends Ability implements Listener { loc.getWorld().playSound(loc, Sound.ENTITY_ZOMBIE_HURT, 1, 1); - NoInteractItemEntity item = new NoInteractItemEntity(stats.getPlayer().getLocation().add(0, 1.2, 0), MMOLib.plugin.getVersion().getWrapper().getNBTItem(new ItemStack(Material.ROTTEN_FLESH)).addTag(new ItemTag("noStack", random.nextInt(1000))).toItem()); + NoClipItem item = new NoClipItem(stats.getPlayer().getLocation().add(0, 1.2, 0), MMOLib.plugin.getVersion().getWrapper().getNBTItem(new ItemStack(Material.ROTTEN_FLESH)).addTag(new ItemTag("noStack", random.nextInt(1000))).toItem()); Bukkit.getScheduler().scheduleSyncDelayedTask(MMOItems.plugin, () -> item.close(), 40); item.getEntity().setVelocity(loc.getDirection().multiply(.8)); stats.getPlayer().getWorld().spawnParticle(Particle.SMOKE_LARGE, stats.getPlayer().getLocation().add(0, 1.2, 0), 0, loc.getDirection().getX(), loc.getDirection().getY(), loc.getDirection().getZ(), 1); diff --git a/src/main/java/net/Indyuce/mmoitems/api/util/NoInteractItemEntity.java b/src/main/java/net/Indyuce/mmoitems/api/util/NoClipItem.java similarity index 68% rename from src/main/java/net/Indyuce/mmoitems/api/util/NoInteractItemEntity.java rename to src/main/java/net/Indyuce/mmoitems/api/util/NoClipItem.java index b7e83e68..09b0187c 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/util/NoInteractItemEntity.java +++ b/src/main/java/net/Indyuce/mmoitems/api/util/NoClipItem.java @@ -7,11 +7,12 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityPortalEnterEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.inventory.ItemStack; import net.Indyuce.mmoitems.MMOItems; -public class NoInteractItemEntity implements Listener { +public class NoClipItem implements Listener { private final Item item; /** @@ -23,7 +24,7 @@ public class NoInteractItemEntity implements Listener { * @param item * ItemStack used to summon the entity */ - public NoInteractItemEntity(Location loc, ItemStack item) { + public NoClipItem(Location loc, ItemStack item) { item.setAmount(1); this.item = loc.getWorld().dropItem(loc, item); @@ -38,16 +39,20 @@ public class NoInteractItemEntity implements Listener { public void close() { item.remove(); + EntityPortalEnterEvent.getHandlerList().unregister(this); + InventoryPickupItemEvent.getHandlerList().unregister(this); } - // @EventHandler(priority = EventPriority.LOWEST) - // public void a(InventoryPickupItemEvent event) { - // if (event.getItem().equals(item)) - // event.setCancelled(true); - // } + @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST) + public void a(InventoryPickupItemEvent event) { + if (event.getItem().equals(item)) { + event.setCancelled(true); + close(); + } + } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST) public void b(EntityPortalEnterEvent event) { if (event.getEntity().equals(item)) close(); From 0a022827c17f034e46ba3c618f8b5c6a02d8414d Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sun, 4 Oct 2020 15:09:20 +0200 Subject: [PATCH 2/2] Fixed an issue with /mi debug checkstat --- .../command/mmoitems/debug/CheckStatCommandTreeNode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/command/mmoitems/debug/CheckStatCommandTreeNode.java b/src/main/java/net/Indyuce/mmoitems/command/mmoitems/debug/CheckStatCommandTreeNode.java index a28b6850..328781f2 100644 --- a/src/main/java/net/Indyuce/mmoitems/command/mmoitems/debug/CheckStatCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmoitems/command/mmoitems/debug/CheckStatCommandTreeNode.java @@ -16,7 +16,7 @@ public class CheckStatCommandTreeNode extends CommandTreeNode { @Override public CommandResult execute(CommandSender sender, String[] args) { - if (args.length < 2) + if (args.length < 3) return CommandResult.THROW_USAGE; if (!(sender instanceof Player)) { @@ -24,7 +24,7 @@ public class CheckStatCommandTreeNode extends CommandTreeNode { return CommandResult.FAILURE; } - ItemStat stat = MMOItems.plugin.getStats().get(args[1].toUpperCase().replace("-", "_")); + ItemStat stat = MMOItems.plugin.getStats().get(args[2].toUpperCase().replace("-", "_")); if (stat == null) { sender.sendMessage(ChatColor.RED + "Couldn't find the stat called " + args[1].toUpperCase().replace("-", "_") + "."); return CommandResult.FAILURE;