diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java index 31858bbea..d2f6ea951 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java @@ -361,12 +361,18 @@ public enum C { /* * Help */ + HELP_HEADER("&c----------[ &6PlotSquared Help &c]----------"), + HELP_CATEGORY("&cCategory: &6%category%&c, Page: &6%current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"), + HELP_INFO("&6You have to specify a category"), + HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"), + HELP_ITEM("&6%usage% [%alias%]\n &c%desc%\n"), + /* HELP_CATEGORY("&6Current Category&c: &l%category%"), HELP_INFO("&6You need to specify a help category"), HELP_INFO_ITEM("&6/plots help %category% &c- &6%category_desc%"), HELP_PAGE("&c>> &6%usage% &c[&6%alias%&c]\n" + "&c>> &6%desc%\n"), HELP_ITEM_SEPARATOR("&c%lines"), - HELP_HEADER("&c(Page &6%cur&c/&6%max&c) &6Help for Plots"), + HELP_HEADER("&c(Page &6%cur&c/&6%max&c) &6Help for Plots"),*/ /* * Direction */ @@ -375,6 +381,8 @@ public enum C { * Custom */ CUSTOM_STRING("-"); + private static TranslationManager manager; + private static TranslationFile defaultFile; /** * Default */ @@ -406,6 +414,26 @@ public enum C { } } + public static void setupTranslations() { + if (manager == null) { + manager = new TranslationManager(); + } + if (defaultFile == null) { + defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), TranslationLanguage.englishAmerican, "PlotSquared", manager) + .read(); + } + // register everything in this class + for (C c : values()) { + manager.addTranslationObject( + new TranslationObject(c.toString(), c.d, "", "") + ); + } + } + + public static void saveTranslations() { + manager.saveAll(defaultFile).saveFile(defaultFile); + } + /** * Get the default string * @@ -442,27 +470,4 @@ public enum C { public String translated() { return ChatColor.translateAlternateColorCodes('&', this.s()); } - - private static TranslationManager manager; - private static TranslationFile defaultFile; - - public static void setupTranslations() { - if (manager == null) { - manager = new TranslationManager(); - } - if (defaultFile == null) { - defaultFile = new YamlTranslationFile(BukkitTranslation.getParent(PlotMain.getPlugin(PlotMain.class)), TranslationLanguage.englishAmerican, "PlotSquared", manager) - .read(); - } - // register everything in this class - for (C c : values()) { - manager.addTranslationObject( - new TranslationObject(c.toString(), c.d, "", "") - ); - } - } - - public static void saveTranslations() { - manager.saveAll(defaultFile).saveFile(defaultFile); - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java index 5a48cb5c9..65833d530 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Help.java @@ -10,9 +10,7 @@ package com.intellectualcrafters.plot.commands; import org.bukkit.entity.Player; -/** - * Created by Citymonstret on 2014-08-11. - */ + public class Help extends SubCommand { public Help() { super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 4101e915d..1ab356827 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -31,7 +31,6 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import org.bukkit.util.ChatPaginator; import java.util.ArrayList; import java.util.Arrays; @@ -60,6 +59,66 @@ public class MainCommand implements CommandExecutor, TabCompleter { return false; } + public static List getCommands(final SubCommand.CommandCategory category, final Player player) { + final List cmds = new ArrayList<>(); + for (final SubCommand c : subCommands) { + if ((c.category.equals(category)) && c.permission.hasPermission(player)) { + cmds.add(c); + } + } + return cmds; + } + + public static List helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { + final List commands = getCommands(category, player); + // final int totalPages = ((int) Math.ceil(12 * (commands.size()) / + // 100)); + final int perPage = 5; + final int totalPages = (int) Math.ceil(commands.size() / perPage); + if (page > totalPages) { + page = totalPages; + } + int max = (page * perPage) + perPage; + if (max > commands.size()) { + max = commands.size(); + } + + final List help = new ArrayList<>(); + + help.add(C.HELP_HEADER.s()); + // HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"), + help.add(C.HELP_CATEGORY.s() + .replace("%category%", category.toString()) + .replace("%current%", "" + (page + 1)) + .replace("%max%", "" + (totalPages + 1)) + .replace("%dis%", "" + perPage) + .replace("%total%", "" + commands.size()) + ); + + SubCommand cmd; + + final int start = page * perPage; + for (int x = start; x < max; x++) { + cmd = commands.get(x); + String s = t(C.HELP_ITEM.s()); + s = s + .replace("%alias%", cmd.alias) + .replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage) + .replace("%cmd%", cmd.cmd) + .replace("%desc%", cmd.description) + ; + help.add(s); + } + if (help.size() < 2) { + help.add(t(C.NO_COMMANDS.s())); + } + return help; + } + + private static String t(final String s) { + return ChatColor.translateAlternateColorCodes('&', s); + } + @Override public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { final Player player = (sender instanceof Player) ? (Player) sender : null; @@ -120,8 +179,8 @@ public class MainCommand implements CommandExecutor, TabCompleter { for (final String string : helpMenu(player, cato, page)) { help.append(string).append("\n"); } - - return PlayerFunctions.sendMessage(player, help.toString()); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', help.toString())); + //return PlayerFunctions.sendMessage(player, help.toString()); } else { for (final SubCommand command : subCommands) { if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.equalsIgnoreCase(args[0])) { @@ -150,63 +209,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command); //PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch()); } - } - - public static List getCommands(final SubCommand.CommandCategory category, final Player player) { - final List cmds = new ArrayList<>(); - for (final SubCommand c : subCommands) { - if ((c.category.equals(category)) && c.permission.hasPermission(player)) { - cmds.add(c); - } - } - return cmds; - } - - public static ArrayList helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { - final List commands = getCommands(category, player); - // final int totalPages = ((int) Math.ceil(12 * (commands.size()) / - // 100)); - final int perPage = 5; - final int totalPages = (int) Math.ceil(commands.size() / perPage); - if (page > totalPages) { - page = totalPages; - } - int max = (page * perPage) + perPage; - if (max > commands.size()) { - max = commands.size(); - } - final ArrayList help = new ArrayList<>(Arrays.asList(t(C.HELP_HEADER.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "")), t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString())))); - SubCommand cmd; - - String lines = ""; - for (int x = 0; x < (ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH * 0.75); x++) { - lines += "-"; - } - - final int start = page * perPage; - for (int x = start; x < max; x++) { - cmd = commands.get(x); - String s = t(C.HELP_PAGE.s()); - s = s.replaceAll("%alias%", cmd.alias); - s = s.replaceAll("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage); - s = s.replaceAll("%cmd%", cmd.cmd); - s = s.replaceAll("%desc%", cmd.description); - - help.add(s); - - if ((x != start)) { - help.add(t(C.HELP_ITEM_SEPARATOR.s().replaceAll("%lines", lines))); - } - - } - if (help.size() < 2) { - help.add(t(C.NO_COMMANDS.s())); - } - return help; - } - - private static String t(final String s) { - return ChatColor.translateAlternateColorCodes('&', s); + return true; } @Override 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 d53ba4f2b..06455c531 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -72,19 +72,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } - @EventHandler - public void onChangeWorld(final PlayerChangedWorldEvent event) { - /* - * if (isPlotWorld(event.getFrom()) && - * (Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1)) { - * event.getPlayer().setResourcePack(""); - * } - * else { - * textures(event.getPlayer()); - * } - */ - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public static void PlayerMove(final PlayerMoveEvent event) { try { @@ -167,26 +154,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } - @EventHandler(priority = EventPriority.HIGH) - public void BlockCreate(final BlockPlaceEvent event) { - final World world = event.getPlayer().getWorld(); - if (!isPlotWorld(world)) { - return; - } - if (PlotMain.hasPermission(event.getPlayer(), "plots.admin")) { - return; - } - if (isInPlot(event.getBlock().getLocation())) { - final Plot plot = getCurrentPlot(event.getBlockPlaced().getLocation()); - if (!plot.hasRights(event.getPlayer())) { - event.setCancelled(true); - } - } - if (PlayerFunctions.getPlot(event.getBlockPlaced().getLocation()) == null) { - event.setCancelled(true); - } - } - @EventHandler public static void onBigBoom(final EntityExplodeEvent event) { final World world = event.getLocation().getWorld(); @@ -304,6 +271,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public static void onBlockPistonExtend(final BlockPistonExtendEvent e) { if (isInPlot(e.getBlock().getLocation())) { + for (Block block : e.getBlocks()) { + if (!isInPlot(block.getLocation())) { + e.setCancelled(true); + } + } + } + /*if (isInPlot(e.getBlock().getLocation())) { e.getDirection(); final int modifier = e.getBlocks().size(); @@ -348,7 +322,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } } - } + }*/ } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -730,4 +704,37 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } } + + @EventHandler + public void onChangeWorld(final PlayerChangedWorldEvent event) { + /* + * if (isPlotWorld(event.getFrom()) && + * (Settings.PLOT_SPECIFIC_RESOURCE_PACK.length() > 1)) { + * event.getPlayer().setResourcePack(""); + * } + * else { + * textures(event.getPlayer()); + * } + */ + } + + @EventHandler(priority = EventPriority.HIGH) + public void BlockCreate(final BlockPlaceEvent event) { + final World world = event.getPlayer().getWorld(); + if (!isPlotWorld(world)) { + return; + } + if (PlotMain.hasPermission(event.getPlayer(), "plots.admin")) { + return; + } + if (isInPlot(event.getBlock().getLocation())) { + final Plot plot = getCurrentPlot(event.getBlockPlaced().getLocation()); + if (!plot.hasRights(event.getPlayer())) { + event.setCancelled(true); + } + } + if (PlayerFunctions.getPlot(event.getBlockPlaced().getLocation()) == null) { + event.setCancelled(true); + } + } }