From 00ab472ba63410b31ac6dcd73620405c9b4a9dce Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Jul 2015 17:09:47 +1000 Subject: [PATCH] Tweaks --- .../plot/commands/MusicSubcommand.java | 29 ++-- .../plot/listeners/PlayerEvents.java | 153 ++++++++++++++---- .../plot/listeners/worldedit/WEListener.java | 14 +- 3 files changed, 148 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java index c457d10bb..799000d19 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java @@ -50,19 +50,22 @@ public class MusicSubcommand extends SubCommand { sendMessage(player, C.NO_PLOT_PERMS); return true; } -PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") { - public boolean onClick(int index) { - PlotItemStack item = getItem(index); - int id = item.id == 7 ? 0 : item.id; - if (id == 0) { - FlagManager.removePlotFlag(plot, "music"); - } - else { - FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); - } - return false; - } -}; + PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") { + public boolean onClick(int index) { + PlotItemStack item = getItem(index); + if (item == null) { + return true; + } + int id = item.id == 7 ? 0 : item.id; + if (id == 0) { + FlagManager.removePlotFlag(plot, "music"); + } + else { + FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id)); + } + return false; + } + }; int index = 0; for (int i = 2256; i < 2268; i++) { String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0)); diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 2657bb5df..a9f034356 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -1372,36 +1372,132 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (event.getTo() == null || event.getFrom() == null) { return; } - final Location f = BukkitUtil.getLocation(event.getFrom()); - final Location t = BukkitUtil.getLocation(event.getTo()); - final Location q = new Location(t.getWorld(), t.getX(), 64, t.getZ()); - final Player player = event.getPlayer(); - if (PS.get().isPlotWorld(q.getWorld())) { - final Plot plot = MainUtil.getPlot(q); - if (plot != null) { - final PlotPlayer pp = BukkitUtil.getPlayer(player); - if (plot.isDenied(pp.getUUID())) { - if (Permissions.hasPermission(pp, "plots.admin.enter.denied")) { - return; - } - MainUtil.sendMessage(pp, C.YOU_BE_DENIED); - event.setCancelled(true); - return; - } else { - if (MainUtil.enteredPlot(f, t)) { - plotEntry(pp, plot); - } - } - } else { - if (MainUtil.leftPlot(f, t)) { - final Plot plot2 = MainUtil.getPlot(f); - plotExit(BukkitUtil.getPlayer(player), plot2); - } - } - if ((q.getX() >= 29999999) || (q.getX() <= -29999999) || (q.getZ() >= 29999999) || (q.getZ() <= -29999999)) { - event.setCancelled(true); + final org.bukkit.Location from = event.getFrom(); + final org.bukkit.Location to = event.getTo(); + + int x2; + if (getInt(from.getX()) != (x2 = getInt(to.getX()))) { + String worldname = to.getWorld().getName(); + PlotWorld plotworld = PS.get().getPlotWorld(worldname); + if (plotworld == null) { return; } + PlotManager plotManager = PS.get().getPlotManager(worldname); + PlotId id = plotManager.getPlotId(plotworld, x2, 0, getInt(to.getZ())); + Player player = event.getPlayer(); + PlotPlayer pp = BukkitUtil.getPlayer(player); + Plot lastPlot = (Plot) pp.getMeta("lastplot"); + if (id == null) { + if (lastPlot == null) { + return; + } + if (!plotExit(pp, lastPlot)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.exit.denied"); + if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { + player.teleport(from); + } + else { + player.teleport(player.getWorld().getSpawnLocation()); + } + event.setCancelled(true); + return; + } + } + else if (lastPlot != null && id.equals(lastPlot.id)) { + return; + } + else { + Plot plot = MainUtil.getPlot(worldname, id); + if (!plotEntry(pp, plot)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied"); + if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { + player.teleport(from); + } + else { + player.teleport(player.getWorld().getSpawnLocation()); + } + event.setCancelled(true); + return; + } + } + Integer border = MainUtil.worldBorder.get(worldname); + if (border != null) { + if (x2 > border) { + to.setX(border - 4); + player.teleport(event.getTo()); + MainUtil.sendMessage(pp, C.BORDER); + return; + } + else if (x2 < -border) { + to.setX(-border + 4); + player.teleport(event.getTo()); + MainUtil.sendMessage(pp, C.BORDER); + return; + } + } + return; + } + int z2; + if (getInt(from.getZ()) != (z2 = getInt(to.getZ())) ) { + String worldname = to.getWorld().getName(); + PlotWorld plotworld = PS.get().getPlotWorld(worldname); + if (plotworld == null) { + return; + } + PlotManager plotManager = PS.get().getPlotManager(worldname); + PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2); + Player player = event.getPlayer(); + PlotPlayer pp = BukkitUtil.getPlayer(player); + Plot lastPlot = (Plot) pp.getMeta("lastplot"); + if (id == null) { + if (lastPlot == null) { + return; + } + if (!plotExit(pp, lastPlot)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.exit.denied"); + if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { + player.teleport(from); + } + else { + player.teleport(player.getWorld().getSpawnLocation()); + } + event.setCancelled(true); + return; + } + } + else if (lastPlot != null && id.equals(lastPlot.id)) { + return; + } + else { + Plot plot = MainUtil.getPlot(worldname, id); + if (!plotEntry(pp, plot)) { + MainUtil.sendMessage(pp, C.NO_PERMISSION, "plots.admin.entry.denied"); + if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) { + player.teleport(from); + } + else { + player.teleport(player.getWorld().getSpawnLocation()); + } + event.setCancelled(true); + return; + } + } + Integer border = MainUtil.worldBorder.get(worldname); + if (border != null) { + if (z2 > border) { + to.setZ(border - 4); + player.teleport(event.getTo()); + MainUtil.sendMessage(pp, C.BORDER); + return; + } + else if (z2 < -border) { + to.setZ(-border + 4); + player.teleport(event.getTo()); + MainUtil.sendMessage(pp, C.BORDER); + return; + } + } + return; } } @@ -1460,6 +1556,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi if (inv != null && event.getRawSlot() == event.getSlot()) { if (!inv.onClick(event.getSlot())) { event.setCancelled(true); + inv.close(); } } } diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java b/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java index d9417a806..8458c7553 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java @@ -120,14 +120,14 @@ public class WEListener implements Listener { } return true; } - } - if (!WEManager.regionContains(region, mask)) { - MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "pos1 + pos2"); - e.setCancelled(true); - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + if (!WEManager.regionContains(region, mask)) { + MainUtil.sendMessage(pp, C.REQUIRE_SELECTION_IN_MASK, "pos1 + pos2"); + e.setCancelled(true); + if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { + MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); + } + return true; } - return true; } long volume = Math.abs((pos1.getBlockX() - pos2.getBlockX()) * (pos1.getBlockY() - pos2.getBlockY()) * (pos1.getBlockZ() - pos2.getBlockZ())) * modifier; return checkVolume(pp, volume, max, e);