From db7775a2c729d9224dafe71e92cd7777d17be752 Mon Sep 17 00:00:00 2001 From: asofold Date: Thu, 20 Nov 2014 12:28:50 +0100 Subject: [PATCH] Spaces. --- .../permissions/PermissionUtil.java | 362 +++++++++--------- .../players/PlayerMessageSender.java | 94 ++--- .../nocheatplus/players/PlayerTask.java | 98 ++--- 3 files changed, 277 insertions(+), 277 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java index 9e938425..d553964d 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java @@ -18,186 +18,186 @@ import fr.neatmonster.nocheatplus.config.ConfigManager; import fr.neatmonster.nocheatplus.utilities.ColorUtil; public class PermissionUtil { - - /** - * Entry for what the old state of a command was. - * @author mc_dev - * - */ - public static class CommandProtectionEntry{ - public final Command command; - public final String label; - public final String permission; - public final PermissionDefault permissionDefault; - public final String permissionMessage; - /** - * - * @param command - * @param label trim + lower case. - * @param permission - * @param permissionDefault - * @param permissionMessage - */ - public CommandProtectionEntry(Command command, String label, String permission, PermissionDefault permissionDefault, String permissionMessage) { - this.command = command; - this.label = label; - this.permission = permission; - this.permissionDefault = permissionDefault; - this.permissionMessage = permissionMessage; - } - - public void restore() { - // (Don't skip resetting, as there could be fall-back aliases.) -// Command registered = CommandUtil.getCommand(label); -// if (registered == null || registered != command) return; - if (!label.equalsIgnoreCase(command.getLabel().trim().toLowerCase())) { - command.setLabel(label); - } - command.setPermission(permission); - if (permission != null && permissionDefault != null) { - Permission perm = Bukkit.getPluginManager().getPermission(permission); - if (perm != null && perm.getDefault() != permissionDefault) { - perm.setDefault(permissionDefault); - } - } - command.setPermissionMessage(permissionMessage); - } - } - - /** - * - * @param commands Command white-list. - * @param permissionBase - * @param ops - * @return - */ - public static List protectCommands(Collection commands, String permissionBase, boolean ops) { - return protectCommands(permissionBase, commands, true, ops); - } - - /** - * Set up the command protection with the "unknown command" message for the permission message (attempt to hide the command). - * @param permissionBase - * @param ignoredCommands - * @param invertIgnored - * @param ops - * @return - */ - public static List protectCommands(String permissionBase, Collection ignoredCommands, boolean invertIgnored, boolean ops) { - return protectCommands(permissionBase, ignoredCommands, invertIgnored, ops, ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG))); - } - - /** - * Set up the command protection with the given permission message. - * @param permissionBase - * @param ignoredCommands - * @param invertIgnored - * @param ops - * @param permissionMessage - * @return - */ - public static List protectCommands(final String permissionBase, final Collection ignoredCommands, final boolean invertIgnored, final boolean ops, final String permissionMessage) { - final Set checked = new HashSet(); - for (String label : ignoredCommands) { - checked.add(CommandUtil.getCommandLabel(label, false)); - } - final PluginManager pm = Bukkit.getPluginManager(); - Permission rootPerm = pm.getPermission(permissionBase); - if (rootPerm == null) { - rootPerm = new Permission(permissionBase); - pm.addPermission(rootPerm); - } - final List changed = new LinkedList(); - // Apply protection based on white-list or black-list. - for (final Command command : CommandUtil.getCommands()) { - final String lcLabel = command.getLabel().trim().toLowerCase(); - if (checked.contains(lcLabel) || containsAnyAliases(checked, command)) { - if (!invertIgnored) { - continue; - } - } - else if (invertIgnored) { - continue; - } - // Set the permission for the command. - String cmdPermName = command.getPermission(); - boolean cmdHadPerm; - if (cmdPermName == null) { - // Set a permission. - cmdPermName = permissionBase + "." + lcLabel; - command.setPermission(cmdPermName); - cmdHadPerm = false; - } - else{ - cmdHadPerm = true; - } - // Set permission default behavior. - Permission cmdPerm = pm.getPermission(cmdPermName); - if (cmdPerm == null) { - if (!cmdHadPerm) { - cmdPerm = new Permission(cmdPermName); - cmdPerm.addParent(rootPerm, true); - pm.addPermission(cmdPerm); - } - } - // Create change history entry. - if (cmdHadPerm) { - if (cmdPerm == null) { - changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, null, command.getPermissionMessage())); - } - else { - changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, cmdPerm.getDefault(), command.getPermissionMessage())); - } - } - else { - changed.add(new CommandProtectionEntry(command, lcLabel, null, null, command.getPermissionMessage())); - } - // Change - cmdPerm.setDefault(ops ? PermissionDefault.OP : PermissionDefault.FALSE); - command.setPermissionMessage(permissionMessage); - } - return changed; - } - - /** - * Check if the checked set contains any trim+lower-case alias of the command. - * @param checked - * @param command - * @return - */ - private static final boolean containsAnyAliases(final Set checked, final Command command) { - final Collection aliases = command.getAliases(); - if (aliases != null) { - for (final String alias : aliases) { - if (checked.contains(alias.trim().toLowerCase())) { - return true; - } - } - } - return false; - } - /** - * Set a permission as child for all the other permissions given in a Collection. - * @param permissions Not expected to exist. - * @param childPermissionName - */ - public static void addChildPermission(final Collection permissions, final String childPermissionName, final PermissionDefault permissionDefault) { - final PluginManager pm = Bukkit.getPluginManager(); - Permission childPermission = pm.getPermission(childPermissionName); - if (childPermission == null) { - childPermission = new Permission(childPermissionName, "auto-generated child permission (NoCheatPlus)", permissionDefault); - pm.addPermission(childPermission); - } - for (final String permissionName : permissions) { - Permission permission = pm.getPermission(permissionName); - if (permission == null) { - permission = new Permission(permissionName, "auto-generated permission (NoCheatPlus)", permissionDefault); - pm.addPermission(permission); - } - if (!permission.getChildren().containsKey(childPermissionName)) { - childPermission.addParent(permission, true); - } - } - } + /** + * Entry for what the old state of a command was. + * @author mc_dev + * + */ + public static class CommandProtectionEntry{ + public final Command command; + public final String label; + public final String permission; + public final PermissionDefault permissionDefault; + public final String permissionMessage; + /** + * + * @param command + * @param label trim + lower case. + * @param permission + * @param permissionDefault + * @param permissionMessage + */ + public CommandProtectionEntry(Command command, String label, String permission, PermissionDefault permissionDefault, String permissionMessage) { + this.command = command; + this.label = label; + this.permission = permission; + this.permissionDefault = permissionDefault; + this.permissionMessage = permissionMessage; + } + + public void restore() { + // (Don't skip resetting, as there could be fall-back aliases.) + // Command registered = CommandUtil.getCommand(label); + // if (registered == null || registered != command) return; + if (!label.equalsIgnoreCase(command.getLabel().trim().toLowerCase())) { + command.setLabel(label); + } + command.setPermission(permission); + if (permission != null && permissionDefault != null) { + Permission perm = Bukkit.getPluginManager().getPermission(permission); + if (perm != null && perm.getDefault() != permissionDefault) { + perm.setDefault(permissionDefault); + } + } + command.setPermissionMessage(permissionMessage); + } + } + + /** + * + * @param commands Command white-list. + * @param permissionBase + * @param ops + * @return + */ + public static List protectCommands(Collection commands, String permissionBase, boolean ops) { + return protectCommands(permissionBase, commands, true, ops); + } + + /** + * Set up the command protection with the "unknown command" message for the permission message (attempt to hide the command). + * @param permissionBase + * @param ignoredCommands + * @param invertIgnored + * @param ops + * @return + */ + public static List protectCommands(String permissionBase, Collection ignoredCommands, boolean invertIgnored, boolean ops) { + return protectCommands(permissionBase, ignoredCommands, invertIgnored, ops, ColorUtil.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.PROTECT_PLUGINS_HIDE_NOCOMMAND_MSG))); + } + + /** + * Set up the command protection with the given permission message. + * @param permissionBase + * @param ignoredCommands + * @param invertIgnored + * @param ops + * @param permissionMessage + * @return + */ + public static List protectCommands(final String permissionBase, final Collection ignoredCommands, final boolean invertIgnored, final boolean ops, final String permissionMessage) { + final Set checked = new HashSet(); + for (String label : ignoredCommands) { + checked.add(CommandUtil.getCommandLabel(label, false)); + } + final PluginManager pm = Bukkit.getPluginManager(); + Permission rootPerm = pm.getPermission(permissionBase); + if (rootPerm == null) { + rootPerm = new Permission(permissionBase); + pm.addPermission(rootPerm); + } + final List changed = new LinkedList(); + // Apply protection based on white-list or black-list. + for (final Command command : CommandUtil.getCommands()) { + final String lcLabel = command.getLabel().trim().toLowerCase(); + if (checked.contains(lcLabel) || containsAnyAliases(checked, command)) { + if (!invertIgnored) { + continue; + } + } + else if (invertIgnored) { + continue; + } + // Set the permission for the command. + String cmdPermName = command.getPermission(); + boolean cmdHadPerm; + if (cmdPermName == null) { + // Set a permission. + cmdPermName = permissionBase + "." + lcLabel; + command.setPermission(cmdPermName); + cmdHadPerm = false; + } + else{ + cmdHadPerm = true; + } + // Set permission default behavior. + Permission cmdPerm = pm.getPermission(cmdPermName); + if (cmdPerm == null) { + if (!cmdHadPerm) { + cmdPerm = new Permission(cmdPermName); + cmdPerm.addParent(rootPerm, true); + pm.addPermission(cmdPerm); + } + } + // Create change history entry. + if (cmdHadPerm) { + if (cmdPerm == null) { + changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, null, command.getPermissionMessage())); + } + else { + changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, cmdPerm.getDefault(), command.getPermissionMessage())); + } + } + else { + changed.add(new CommandProtectionEntry(command, lcLabel, null, null, command.getPermissionMessage())); + } + // Change + cmdPerm.setDefault(ops ? PermissionDefault.OP : PermissionDefault.FALSE); + command.setPermissionMessage(permissionMessage); + } + return changed; + } + + /** + * Check if the checked set contains any trim+lower-case alias of the command. + * @param checked + * @param command + * @return + */ + private static final boolean containsAnyAliases(final Set checked, final Command command) { + final Collection aliases = command.getAliases(); + if (aliases != null) { + for (final String alias : aliases) { + if (checked.contains(alias.trim().toLowerCase())) { + return true; + } + } + } + return false; + } + + /** + * Set a permission as child for all the other permissions given in a Collection. + * @param permissions Not expected to exist. + * @param childPermissionName + */ + public static void addChildPermission(final Collection permissions, final String childPermissionName, final PermissionDefault permissionDefault) { + final PluginManager pm = Bukkit.getPluginManager(); + Permission childPermission = pm.getPermission(childPermissionName); + if (childPermission == null) { + childPermission = new Permission(childPermissionName, "auto-generated child permission (NoCheatPlus)", permissionDefault); + pm.addPermission(childPermission); + } + for (final String permissionName : permissions) { + Permission permission = pm.getPermission(permissionName); + if (permission == null) { + permission = new Permission(permissionName, "auto-generated permission (NoCheatPlus)", permissionDefault); + pm.addPermission(permission); + } + if (!permission.getChildren().containsKey(childPermissionName)) { + childPermission.addParent(permission, true); + } + } + } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerMessageSender.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerMessageSender.java index d4268238..ff0ae781 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerMessageSender.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerMessageSender.java @@ -13,58 +13,58 @@ import fr.neatmonster.nocheatplus.utilities.OnDemandTickListener; * */ public class PlayerMessageSender extends OnDemandTickListener { - - private final class MessageEntry{ - public final String playerName; - public final String message; - public MessageEntry(final String playerName, final String message){ - this.playerName = playerName; - this.message = message; - } - } - - /** Queued entries, also used as lock. */ - private List messageEntries = new LinkedList(); - @Override - public boolean delegateTick(int tick, long timeLast) { - // Copy entries. - final List entries; - synchronized (this) { - if (messageEntries.isEmpty()){ + private final class MessageEntry{ + public final String playerName; + public final String message; + public MessageEntry(final String playerName, final String message){ + this.playerName = playerName; + this.message = message; + } + } + + /** Queued entries, also used as lock. */ + private List messageEntries = new LinkedList(); + + @Override + public boolean delegateTick(int tick, long timeLast) { + // Copy entries. + final List entries; + synchronized (this) { + if (messageEntries.isEmpty()){ // Force unregister. unRegister(true); // Always continue here to never use external setRegistered. return true; } - entries = messageEntries; - messageEntries = new LinkedList(); - } - // Do messaging. - for (final MessageEntry entry : entries){ - final Player player = DataManager.getPlayerExact(entry.playerName); - if (player != null && player.isOnline()){ - player.sendMessage(entry.message); - } - } - // Unregister if no further entries are there. - synchronized (this) { - if (messageEntries.isEmpty()){ - // Force unregister. - unRegister(true); - } - } - // Always continue here to never use external setRegistered. - return true; - } - - public void sendMessageThreadSafe(final String playerName, final String message){ - final MessageEntry entry = new MessageEntry(playerName.toLowerCase(), message); - synchronized (this) { - messageEntries.add(entry); - // Called register asynchronously, potentially. - register(); - } - } + entries = messageEntries; + messageEntries = new LinkedList(); + } + // Do messaging. + for (final MessageEntry entry : entries){ + final Player player = DataManager.getPlayerExact(entry.playerName); + if (player != null && player.isOnline()){ + player.sendMessage(entry.message); + } + } + // Unregister if no further entries are there. + synchronized (this) { + if (messageEntries.isEmpty()){ + // Force unregister. + unRegister(true); + } + } + // Always continue here to never use external setRegistered. + return true; + } + + public void sendMessageThreadSafe(final String playerName, final String message){ + final MessageEntry entry = new MessageEntry(playerName.toLowerCase(), message); + synchronized (this) { + messageEntries.add(entry); + // Called register asynchronously, potentially. + register(); + } + } } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerTask.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerTask.java index 8aea0559..24d0cb1e 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerTask.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/players/PlayerTask.java @@ -10,56 +10,56 @@ import fr.neatmonster.nocheatplus.utilities.OnDemandTickListener; * */ public class PlayerTask extends OnDemandTickListener { - - // TODO: Consider overriding some logic, because it is used in the main thread only (context: isRegisterd + register). - - public final String lcName; - - protected boolean updateInventory = false; - -// protected boolean correctDirection = false; - /** - * - * @param name Not demanded to be case sensitive. - */ - public PlayerTask(final String name) { - this.lcName = name.toLowerCase(); - } + // TODO: Consider overriding some logic, because it is used in the main thread only (context: isRegisterd + register). - - @SuppressWarnings("deprecation") - @Override - public boolean delegateTick(final int tick, final long timeLast) { - final Player player = DataManager.getPlayer(lcName); - if (player != null) { - if (player.isOnline()) { -// if (correctDirection) { -// final MCAccess access = NCPAPIProvider.getNoCheatPlusAPI().getMCAccess(); -// access.correctDirection(player); -// } - if (updateInventory) { - player.updateInventory(); - } - } - } - // Reset values (players logging back in should be fine or handled differently). - updateInventory = false; -// correctDirection = false; - return false; - } - - public void updateInventory() { - // TODO: Might not allow registering every tick. - updateInventory = true; - register(); - } - -// public void correctDirection() { -// correctDirection = true; -// register(); -// } - - // TODO: updateHunger + public final String lcName; + + protected boolean updateInventory = false; + + // protected boolean correctDirection = false; + + /** + * + * @param name Not demanded to be case sensitive. + */ + public PlayerTask(final String name) { + this.lcName = name.toLowerCase(); + } + + + @SuppressWarnings("deprecation") + @Override + public boolean delegateTick(final int tick, final long timeLast) { + final Player player = DataManager.getPlayer(lcName); + if (player != null) { + if (player.isOnline()) { + // if (correctDirection) { + // final MCAccess access = NCPAPIProvider.getNoCheatPlusAPI().getMCAccess(); + // access.correctDirection(player); + // } + if (updateInventory) { + player.updateInventory(); + } + } + } + // Reset values (players logging back in should be fine or handled differently). + updateInventory = false; + // correctDirection = false; + return false; + } + + public void updateInventory() { + // TODO: Might not allow registering every tick. + updateInventory = true; + register(); + } + + // public void correctDirection() { + // correctDirection = true; + // register(); + // } + + // TODO: updateHunger }