From 3565e67137c35d60e5d7c321513e47c2d4b3a5dc Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sun, 18 Mar 2018 09:28:23 +1100 Subject: [PATCH] Prevent entity portal use from plotworld --- .gitignore | 1 + .../com/plotsquared/bukkit/BukkitMain.java | 7 ++ .../bukkit/listeners/EntityPortal_1_7_9.java | 99 +++++++++++++++++++ .../bukkit/listeners/PlayerEvents_1_8.java | 3 + 4 files changed, 110 insertions(+) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntityPortal_1_7_9.java diff --git a/.gitignore b/.gitignore index a2d06e145..f55b143d2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ release.properties dependency-reduced-pom.xml buildNumber.properties .mvn/timing.properties +out/ ### Java ### diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index a2762cd58..c5a71e0d2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -525,6 +525,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } catch (NoSuchMethodException | ClassNotFoundException ignored) { PS.debug("Not running Spigot. Skipping EntitySpawnListener event."); } + if (PS.get().checkVersion(getServerVersion(), 1, 7, 9)) { + try { + getServer().getPluginManager().registerEvents(new EntityPortal_1_7_9(), this); + } catch (Throwable e) { + e.printStackTrace(); + } + } if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) { try { getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntityPortal_1_7_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntityPortal_1_7_9.java new file mode 100644 index 000000000..20f029a3f --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/EntityPortal_1_7_9.java @@ -0,0 +1,99 @@ +package com.plotsquared.bukkit.listeners; + +import com.intellectualcrafters.plot.PS; +import java.util.List; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Vehicle; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityTeleportEvent; +import org.bukkit.event.vehicle.*; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.plugin.Plugin; + +public class EntityPortal_1_7_9 implements Listener { + public EntityPortal_1_7_9() { + } + + @EventHandler + public void onVehicle(VehicleUpdateEvent event) { + test(event.getVehicle()); + } + + @EventHandler + public void onVehicle(VehicleDestroyEvent event) { + test(event.getVehicle()); + } + + @EventHandler + public void onVehicle(VehicleEntityCollisionEvent event) { + test(event.getVehicle()); + } + + @EventHandler + public void onVehicle(VehicleCreateEvent event) { + test(event.getVehicle()); + } + + @EventHandler + public void onVehicle(VehicleBlockCollisionEvent event) { + test(event.getVehicle()); + } + + @EventHandler + public void onTeleport(EntityTeleportEvent event) { + Entity ent = event.getEntity(); + if (ent instanceof Vehicle || ent instanceof ArmorStand) test(event.getEntity()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException { + test(event.getVehicle()); + } + + @EventHandler + public void spawn(CreatureSpawnEvent event) { + switch (event.getEntityType()) { + case ARMOR_STAND: + test(event.getEntity()); + } + } + + private static boolean ignoreTP = false; + + public static void test(Entity entity) { + List meta = entity.getMetadata("plotworld"); + World world = entity.getLocation().getWorld(); + if (meta == null || meta.isEmpty()) { + if (PS.get().isPlotWorld(world.getName())) { + entity.setMetadata("plotworld", new FixedMetadataValue((Plugin) PS.get().IMP, entity.getLocation())); + } + } else { + Location origin = (Location) meta.get(0).value(); + World originWorld = origin.getWorld(); + if (!originWorld.equals(world)) { + if (!ignoreTP) { + if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) { + try { + ignoreTP = true; + entity.teleport(origin); + } finally { + ignoreTP = false; + } + if (entity.getLocation().getWorld().equals(world)) { + entity.remove(); + } + } + } else { + entity.remove(); + } + } + } + } +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java index be8a861a4..ffc23d1e1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents_1_8.java @@ -144,6 +144,9 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener { if (area == null) { return; } + + EntityPortal_1_7_9.test(entity); + Plot plot = area.getPlotAbs(l); PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); if (plot == null) {