Prevent entity portal use from plotworld

This commit is contained in:
Jesse Boyd 2018-03-18 09:28:23 +11:00
parent 368b9a0168
commit 3565e67137
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 110 additions and 0 deletions

1
.gitignore vendored
View File

@ -21,6 +21,7 @@ release.properties
dependency-reduced-pom.xml dependency-reduced-pom.xml
buildNumber.properties buildNumber.properties
.mvn/timing.properties .mvn/timing.properties
out/
### Java ### ### Java ###

View File

@ -525,6 +525,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} catch (NoSuchMethodException | ClassNotFoundException ignored) { } catch (NoSuchMethodException | ClassNotFoundException ignored) {
PS.debug("Not running Spigot. Skipping EntitySpawnListener event."); 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)) { if (PS.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
try { try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this); getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);

View File

@ -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<MetadataValue> 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();
}
}
}
}
}

View File

@ -144,6 +144,9 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
if (area == null) { if (area == null) {
return; return;
} }
EntityPortal_1_7_9.test(entity);
Plot plot = area.getPlotAbs(l); Plot plot = area.getPlotAbs(l);
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer()); PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) { if (plot == null) {