fixed some really weird bugs...

like WTF, how does checking event.getTo() cause the player spawns to
change!?
This commit is contained in:
boy0001 2014-10-19 22:12:23 +11:00
parent 3796f41be3
commit a79a3adcba
3 changed files with 32 additions and 17 deletions

View File

@ -770,23 +770,38 @@ public class PlotHelper {
PlotMain.updatePlot(plot); PlotMain.updatePlot(plot);
refreshPlotChunks(world, plot); refreshPlotChunks(world, plot);
} }
public static int getHeighestBlock(World world, int x, int z) {
boolean safe = false;
for (int i = 1; i<world.getMaxHeight(); i++) {
int id = world.getBlockAt(x,i,z).getTypeId();
if (id==0) {
if (safe) {
return i-1;
}
safe = true;
}
}
return 64;
}
public static Location getPlotHome(World w, PlotId plotid) { public static Location getPlotHome(World w, PlotId plotid) {
Location
bot = getPlotBottomLoc(w, plotid),
top = getPlotTopLoc(w, plotid);
if (getPlot(w, plotid).settings.getPosition() == PlotHomePosition.DEFAULT) { if (getPlot(w, plotid).settings.getPosition() == PlotHomePosition.DEFAULT) {
int x = bot.getBlockX() + (top.getBlockX() - bot.getBlockX());
Location bot = getPlotBottomLoc(w, plotid);
int x = bot.getBlockX();
int z = bot.getBlockZ() - 2; int z = bot.getBlockZ() - 2;
int y = w.getHighestBlockYAt(x, z); int y = getHeighestBlock(w, x, z);
return new Location(w, x, y, z); return new Location(w, x, y, z);
} }
else { else {
Location
bot = getPlotBottomLoc(w, plotid),
top = getPlotTopLoc(w, plotid);
int x = top.getBlockX() - bot.getBlockX(); int x = top.getBlockX() - bot.getBlockX();
int z = top.getBlockZ() - bot.getBlockZ(); int z = top.getBlockZ() - bot.getBlockZ();
int y = w.getHighestBlockYAt(x, z); int y = getHeighestBlock(w, x, z);
return new Location(w, bot.getBlockX() + x/2, y, bot.getBlockZ() + z/2); return new Location(w, bot.getBlockX() + x/2, y, bot.getBlockZ() + z/2);
} }
} }

View File

@ -574,7 +574,7 @@ public class PlayerEvents implements Listener {
} }
} }
@EventHandler @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void MobSpawn(CreatureSpawnEvent event) { public void MobSpawn(CreatureSpawnEvent event) {
World world = event.getLocation().getWorld(); World world = event.getLocation().getWorld();
if (!isPlotWorld(world)) { if (!isPlotWorld(world)) {
@ -589,9 +589,10 @@ public class PlayerEvents implements Listener {
} else if (reason == CreatureSpawnEvent.SpawnReason.CUSTOM && pW.SPAWN_CUSTOM) { } else if (reason == CreatureSpawnEvent.SpawnReason.CUSTOM && pW.SPAWN_CUSTOM) {
return; return;
} }
if (event.getEntity().getType() == EntityType.PLAYER) { if (event.getEntity() instanceof Player) {
return; return;
} }
System.out.print(event.getEntityType().getName());
if (!isInPlot(event.getLocation())) { if (!isInPlot(event.getLocation())) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -634,15 +635,15 @@ public class PlayerEvents implements Listener {
} }
} }
@EventHandler( @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) { public void onTeleport(PlayerTeleportEvent event) {
Location f = event.getFrom(); Location f = event.getFrom();
Location t = event.getTo(); Location t = event.getTo();
Location q = new Location(t.getWorld(),t.getBlockX(), 64, t.getZ());
if (isPlotWorld(event.getTo())) {
if (isInPlot(event.getTo())) { if (isPlotWorld(q)) {
if (isInPlot(q)) {
Plot plot = getCurrentPlot(event.getTo()); Plot plot = getCurrentPlot(event.getTo());
if (plot.deny_entry(event.getPlayer())) { if (plot.deny_entry(event.getPlayer())) {
PlayerFunctions.sendMessage(event.getPlayer(), C.YOU_BE_DENIED); PlayerFunctions.sendMessage(event.getPlayer(), C.YOU_BE_DENIED);

View File

@ -148,8 +148,7 @@ public class WorldEditListener implements Listener {
} }
} }
@EventHandler( @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent e) { public void onTeleport(final PlayerTeleportEvent e) {
if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) { if (PlotMain.hasPermission(e.getPlayer(), "plots.worldedit.bypass")) {
return; return;