From d1e9ccb3e8ce0f5da8d24985f4107e3763ceabc4 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 23 Feb 2015 11:05:25 +1100 Subject: [PATCH] misc fixes --- .../intellectualcrafters/plot/BukkitMain.java | 8 +++++ .../intellectualcrafters/plot/IPlotMain.java | 4 +++ .../plot/PlotSquared.java | 3 ++ .../plot/commands/BukkitCommand.java | 5 ++- .../plot/commands/Set.java | 12 +++---- .../plot/generator/ClassicPlotManager.java | 32 +++++++++---------- .../plot/listeners/PlayerEvents.java | 9 ++++++ .../plot/object/BukkitPlayer.java | 4 +-- .../plot/util/MainUtil.java | 32 ++++++++++--------- 9 files changed, 67 insertions(+), 42 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index e8de76e7b..a7c65b636 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -42,6 +42,7 @@ import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; +import com.intellectualcrafters.plot.util.AChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ConsoleColors; import com.intellectualcrafters.plot.util.MainUtil; @@ -50,6 +51,7 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetupUtils; import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; +import com.intellectualcrafters.plot.util.bukkit.ChunkManager; import com.intellectualcrafters.plot.util.bukkit.Metrics; import com.intellectualcrafters.plot.util.bukkit.SendChunk; import com.intellectualcrafters.plot.util.bukkit.SetBlockFast; @@ -298,6 +300,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } catch (final Throwable e) { MainUtil.canSendChunk = false; } + System.out.print("SET BLOCK MANAGER"); return BlockManager.manager = new BukkitUtil(); } @@ -376,4 +379,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return UUIDHandler.uuidWrapper; } + + @Override + public AChunkManager initChunkManager() { + return new ChunkManager(); + } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index c109c4149..6eef44f93 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -6,9 +6,11 @@ import net.milkbowl.vault.economy.Economy; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.util.AChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.bukkit.ChunkManager; import com.intellectualcrafters.plot.uuid.UUIDWrapper; public interface IPlotMain { @@ -40,6 +42,8 @@ public interface IPlotMain { public BlockManager initBlockManager(); + public AChunkManager initChunkManager(); + public SetupUtils initSetupUtils(); public HybridUtils initHybridUtils(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index ef965f8a3..3d3e0f442 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -49,6 +49,7 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.AChunkManager; import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ExpireManager; @@ -445,6 +446,8 @@ public class PlotSquared { SetupUtils.manager = IMP.initSetupUtils(); // Set block BlockManager.manager = IMP.initBlockManager(); + // Set chunk + AChunkManager.manager = IMP.initChunkManager(); // PlotMe TaskManager.runTaskLater(new Runnable() { @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java index 852bfeaa2..b075772a3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java @@ -22,11 +22,10 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender commandSender, Command command, String commandLabel, String[] args) { - Player player = null; if (commandSender instanceof Player) { - player = (Player) commandSender; + return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args); } - return MainCommand.onCommand(BukkitUtil.getPlayer(player), commandLabel, args); + return MainCommand.onCommand(null, commandLabel, args); } @Override diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index 46136d4a4..be64e30c6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -219,16 +219,16 @@ public class Set extends SubCommand { final String[] components = manager.getPlotComponents(plotworld, plot.id); for (final String component : components) { if (component.equalsIgnoreCase(args[0])) { - if (args.length < 2) { - MainUtil.sendMessage(plr, C.NEED_BLOCK); - return true; - } PlotBlock[] blocks; try { - blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseObject(args[2]); + blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseString(args[1]); } catch (final Exception e) { try { - blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[2]), (byte) 0) }; + if (args.length < 2) { + MainUtil.sendMessage(plr, C.NEED_BLOCK); + return true; + } + blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[1]), (byte) 0) }; } catch (final Exception e2) { MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK); return false; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index e33986100..f16f18df3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -49,7 +49,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { return false; } final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid); - final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid); + final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1); int x, z; z = bottom.getZ(); int length = top.getX() - bottom.getX(); @@ -59,7 +59,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final int[] zl = new int[size]; final PlotBlock[] bl = new PlotBlock[size]; int i = 0; - for (x = bottom.getX(); x < (top.getX() + 1); x++) { + for (x = bottom.getX(); x <= (top.getX() - 1); x++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { xl[i] = x; zl[i] = z; @@ -68,8 +68,8 @@ public abstract class ClassicPlotManager extends SquarePlotManager { i++; } } - x = top.getX() + 1; - for (z = bottom.getZ(); z < (top.getZ() + 1); z++) { + x = top.getX(); + for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { xl[i] = x; zl[i] = z; @@ -78,8 +78,8 @@ public abstract class ClassicPlotManager extends SquarePlotManager { i++; } } - z = top.getZ() + 1; - for (x = top.getX() + 1; x > (bottom.getX() - 1); x--) { + z = top.getZ(); + for (x = top.getX(); x >= (bottom.getX() + 1); x--) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { xl[i] = x; zl[i] = z; @@ -89,7 +89,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { } } x = bottom.getX(); - for (z = top.getZ() + 1; z > (bottom.getZ() - 1); z--) { + for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { xl[i] = x; zl[i] = z; @@ -98,7 +98,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { i++; } } - BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, blocks); + BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl); return true; } @@ -108,7 +108,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { return false; } final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid); - final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid); + final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1,0,1); int length = top.getX() - bottom.getX(); int size = (length) * 4; final int[] xl = new int[size]; @@ -119,23 +119,23 @@ public abstract class ClassicPlotManager extends SquarePlotManager { z = bottom.getZ(); int i = 0; int y = dpw.WALL_HEIGHT + 1; - for (x = bottom.getX(); x < (top.getX() + 1); x++) { + for (x = bottom.getX(); x <= (top.getX() - 1); x++) { xl[i] = x; zl[i] = z; yl[i] = y; bl[i] = blocks[BlockManager.random(blocks.length)]; i++; } - x = top.getX() + 1; - for (z = bottom.getZ(); z < (top.getZ() + 1); z++) { + x = top.getX(); + for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) { xl[i] = x; zl[i] = z; yl[i] = y; bl[i] = blocks[BlockManager.random(blocks.length)]; i++; } - z = top.getZ() + 1; - for (x = top.getX() + 1; x > (bottom.getX() - 1); x--) { + z = top.getZ(); + for (x = top.getX(); x >= (bottom.getX() + 1); x--) { xl[i] = x; zl[i] = z; yl[i] = y; @@ -143,14 +143,14 @@ public abstract class ClassicPlotManager extends SquarePlotManager { i++; } x = bottom.getX(); - for (z = top.getZ() + 1; z > (bottom.getZ() - 1); z--) { + for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) { xl[i] = x; zl[i] = z; yl[i] = y; bl[i] = blocks[BlockManager.random(blocks.length)]; i++; } - BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, blocks); + BlockManager.setBlocks(plotworld.worldname, xl, yl, zl, bl); return true; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 4e9fa59ef..a02289100 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -70,6 +70,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerEggThrowEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -90,6 +91,7 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; @@ -331,6 +333,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public static void onWorldChanged(final PlayerChangedWorldEvent event) { + PlotPlayer player = BukkitUtil.getPlayer(event.getPlayer()); + ((BukkitPlayer) player).hasPerm = null; + ((BukkitPlayer) player).noPerm = null; + } + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onPeskyMobsChangeTheWorldLikeWTFEvent(final EntityChangeBlockEvent event) { final String world = event.getBlock().getWorld().getName(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java index 02735f673..efcf20e53 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/BukkitPlayer.java @@ -13,8 +13,8 @@ public class BukkitPlayer implements PlotPlayer { public final Player player; UUID uuid; String name; - private HashSet hasPerm; - private HashSet noPerm; + public HashSet hasPerm; + public HashSet noPerm; private int op = 0; /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 249803912..05de4cff9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -845,12 +845,14 @@ public class MainUtil { return new String(b); } - public static boolean sendMessage(final PlotPlayer plr, final String msg, final boolean prefix) { + public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) { + msg = colorise('&', msg); + String prefixStr = colorise('&', C.PREFIX.s()); if ((msg.length() > 0) && !msg.equals("")) { if (plr == null) { - PlotSquared.log(C.PREFIX.s() + msg); + PlotSquared.log(prefixStr + msg); } else { - sendMessageWrapped(plr, colorise('&', C.PREFIX.s() + msg)); + sendMessageWrapped(plr, prefixStr + msg); } } return true; @@ -930,17 +932,17 @@ public class MainUtil { * @param msg Was used to wrap the chat client length (Packets out--) */ public static void sendMessageWrapped(final PlotPlayer plr, String msg) { - if (msg.length() > 65) { - final String[] ss = wordWrap(msg, 65); - final StringBuilder b = new StringBuilder(); - for (final String p : ss) { - b.append(p).append(p.equals(ss[ss.length - 1]) ? "" : "\n "); - } - msg = b.toString(); - } - if (msg.endsWith("\n")) { - msg = msg.substring(0, msg.length() - 2); - } +// if (msg.length() > 65) { +// final String[] ss = wordWrap(msg, 65); +// final StringBuilder b = new StringBuilder(); +// for (final String p : ss) { +// b.append(p).append(p.equals(ss[ss.length - 1]) ? "" : "\n "); +// } +// msg = b.toString(); +// } +// if (msg.endsWith("\n")) { +// msg = msg.substring(0, msg.length() - 2); +// } plr.sendMessage(msg); } @@ -963,7 +965,7 @@ public class MainUtil { } } if (plr == null) { - PlotSquared.log(msg); + PlotSquared.log(colorise('&', msg)); } else { sendMessage(plr, msg, c.usePrefix()); }