mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-24 12:16:44 +01:00
Prevent entity portal use from plotworld
This commit is contained in:
parent
368b9a0168
commit
3565e67137
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@ release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
out/
|
||||
|
||||
|
||||
### 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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user