From ed10877431fd77b5af5aa61f5678735e61071041 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Fri, 8 Mar 2019 23:04:38 +0000 Subject: [PATCH 1/2] Should fix IndexOutOfBoundsException when copying fixes#2290 --- .../bukkit/object/entity/ReplicatingEntityWrapper.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java index d59fabf1c..f05555947 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/entity/ReplicatingEntityWrapper.java @@ -10,6 +10,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; +import java.util.List; + public final class ReplicatingEntityWrapper extends EntityWrapper { private final short depth; @@ -38,9 +40,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { if (depth == 0) { return; } - Entity passenger = entity.getPassengers().get(0); - if (passenger != null) { - this.base.passenger = new ReplicatingEntityWrapper(passenger, depth); + List passengers = entity.getPassengers(); + if (passengers.size() > 0) { + this.base.passenger = new ReplicatingEntityWrapper(passengers.get(0), depth); } this.base.fall = entity.getFallDistance(); this.base.fire = (short) entity.getFireTicks(); From aa894b8ad91fed8b7f83ccbfac0d43708f21f239 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 9 Mar 2019 00:12:21 +0000 Subject: [PATCH 2/2] Fixes #2245 Also some minor fixes to PlayerInteractEvent main/off hand logic --- .../bukkit/listeners/PlayerEvents.java | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 5812e4e27..a259e62b1 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -10,12 +10,10 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; +import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.*; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -909,7 +907,7 @@ import java.util.regex.Pattern; if (!spies.isEmpty()) { String spyMessage = Captions.PLOT_CHAT_SPY_FORMAT.s().replace("%plot_id%", id.x + ";" + id.y) - .replace("%sender%", sender).replace("%msg%", message); + .replace("%sender%", sender).replace("%msg%", message); for (Player player : spies) { player.sendMessage(spyMessage); } @@ -1734,7 +1732,32 @@ import java.util.regex.Pattern; blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation())))); } - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW) + public void onCancelledInteract(PlayerInteractEvent event) { + if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) { + Player player = event.getPlayer(); + PlotPlayer pp = BukkitUtil.getPlayer(player); + PlotArea area = pp.getPlotAreaAbs(); + if (area == null) { + return; + } + Material type = player.getInventory().getItemInMainHand().getType(); + if (type.toString().toLowerCase().endsWith("egg")) { + Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY); + if (block != null && block.getType() != Material.AIR) { + Location location = BukkitUtil.getLocation(block.getLocation()); + if (!EventUtil.manager + .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, + new BukkitLazyBlock(PlotBlock.get(type.toString())), true)) { + event.setCancelled(true); + event.setUseItemInHand(Event.Result.DENY); + } + } + } + } + } + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = false) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); @@ -1907,25 +1930,25 @@ import java.util.regex.Pattern; } ItemStack hand = player.getInventory().getItemInMainHand(); ItemStack offHand = player.getInventory().getItemInOffHand(); - Material type = (hand == null) ? null : hand.getType(); - Material offType = (offHand == null) ? null : offHand.getType(); + Material type = (hand == null) ? Material.AIR : hand.getType(); + Material offType = (offHand == null) ? Material.AIR : offHand.getType(); if ((type == Material.AIR && offType != Material.AIR && !player.isSneaking() && blockType.isInteractable()) || (type == Material.AIR && offType == Material.AIR)) { eventType = PlayerBlockEventType.INTERACT_BLOCK; break; } - if (!(type != null && type.equals(offType))) { + if (type == Material.AIR) { type = offType; } - if (type == null || type.isBlock()) { + if (type.isBlock()) { location = BukkitUtil .getLocation(block.getRelative(event.getBlockFace()).getLocation()); eventType = PlayerBlockEventType.PLACE_BLOCK; break; } lb = new BukkitLazyBlock(PlotBlock.get(type.toString())); - if (type.toString().endsWith("egg")) { + if (type.toString().toLowerCase().endsWith("egg")) { eventType = PlayerBlockEventType.SPAWN_MOB; } else { switch (type) {