diff --git a/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java b/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java index 48cf117..58c8740 100644 --- a/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java +++ b/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java @@ -57,10 +57,9 @@ public class CreateCommand implements CommandExecutor { */ private PermissionSign parseSign(@NotNull CommandSender sender, @NotNull String[] args) { String name = args[0]; - String[] permissions = args[1].split(","); + String[] permissions = args[1].replaceAll("\\?", " ").split(","); for (String permission : permissions) { if (permission.contains(":")) { - //TODO: Might need to account for world names with spaces in the name String world = permission.split(":")[0]; if (!world.equalsIgnoreCase("all") && Bukkit.getWorld(world) == null) { sender.sendMessage(StringFormatter.replacePlaceholder(StringFormatter.getTranslatedErrorMessage( diff --git a/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java b/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java index e2e13ee..06f6a9e 100644 --- a/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java +++ b/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java @@ -5,13 +5,13 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.permissions.Permission; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.StringJoiner; /** * The tab completer for the create command @@ -121,38 +121,31 @@ public class CreateTabCompleter implements TabCompleter { private static void loadAvailablePermissions() { plugins = new ArrayList<>(); permissions = new HashMap<>(); - for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) { - for (Permission permission : plugin.getDescription().getPermissions()) { - loadPermission(permission); - } + + for (Permission permission : Bukkit.getPluginManager().getPermissions()) { + loadPermission(permission.getName()); } } /** * Loads a given permission into the proper lists and maps * - * @param permission
The permission to load
+ * @param permissionNameThe permission to load
*/ - private static void loadPermission(Permission permission) { - String permissionName = permission.getName(); + private static void loadPermission(String permissionName) { String[] permissionParts = permissionName.split("\\."); - for (int i = 0; i < permissionParts.length; i++) { - if (i == 0) { - plugins.add(permissionParts[0]); - } else { - StringBuilder pathBuilder = new StringBuilder(); - for (int j = 0; j < i; j++) { - pathBuilder.append("."); - pathBuilder.append(permissionParts[j]); - } - String path = pathBuilder.substring(1); - ListThe sign which is about to be created
* @param playerThe player starting to create the permission sign
- * @param initiationTime + * @param initiationTimeThe time the request was initiated
*/ public SignCreationRequest(PermissionSign permissionSign, Player player, long initiationTime) { this.permissionSign = permissionSign; diff --git a/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java b/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java index 19c4228..16a0134 100644 --- a/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java +++ b/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java @@ -90,6 +90,11 @@ public enum TranslatableMessage { */ PERMISSIONS_GRANTED, + /** + * The message to display when a permission sign successfully grants permissions to the player permanently + */ + PERMISSIONS_GRANTED_PERMANENTLY, + /** * The message to display if a player has specified an invalid world to set a permission for */ @@ -103,6 +108,11 @@ public enum TranslatableMessage { /** * The message to display when a permission sign has been successfully created */ - PERMISSION_SIGN_CREATED + PERMISSION_SIGN_CREATED, + + /** + * The message to display when a reload action has been successfully performed + */ + RELOAD_SUCCESSFUL } diff --git a/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java b/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java index 6da4a9d..5565382 100644 --- a/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java +++ b/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java @@ -6,6 +6,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import java.io.BufferedReader; import java.io.FileNotFoundException; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; @@ -56,7 +57,7 @@ public final class Translator { BufferedReader reader; try { reader = FileHelper.getBufferedReaderForInternalFile("/strings.yml"); - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | UnsupportedEncodingException e) { PermissionSigns.getInstance().getLogger().log(Level.SEVERE, "Unable to load translated messages"); return null; } diff --git a/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java b/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java index b555627..9dbf814 100644 --- a/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java +++ b/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java @@ -19,6 +19,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import java.util.Arrays; +import java.util.StringJoiner; /** * A listener for all events related to signs @@ -113,7 +114,7 @@ public class SignListener implements Listener { */ private void performPermissionTransaction(Player player, PermissionSign permissionSign) { EconomyManager.withdraw(player, permissionSign.getCost()); - StringBuilder permissionsBuilder = new StringBuilder(); + StringJoiner permissionsJoiner = new StringJoiner(", "); for (String permissionNode : permissionSign.getPermissionNodes()) { //Only grant the permission if not already owned boolean hasPermission; @@ -124,8 +125,7 @@ public class SignListener implements Listener { hasPermission = player.hasPermission(permissionNode); } if (!hasPermission) { - permissionsBuilder.append(permissionNode); - permissionsBuilder.append(", "); + permissionsJoiner.add(permissionNode); if (permissionSign.getDuration() == 0) { PermissionManager.addPermission(player, permissionNode); } else { @@ -134,12 +134,16 @@ public class SignListener implements Listener { } } - String successMessage = StringFormatter.getTranslatedInfoMessage(TranslatableMessage.PERMISSIONS_GRANTED); - String grantedPermissions = permissionsBuilder.toString(); - grantedPermissions = grantedPermissions.substring(0, grantedPermissions.length() - 2); - String timeUnit = Translator.getTranslatedMessage(TranslatableMessage.SIGN_TIME_UNIT); - player.sendMessage(StringFormatter.replacePlaceholders(successMessage, new String[]{"{permissions}", "{time}"}, - new String[]{grantedPermissions, permissionSign.getDuration() + " " + timeUnit})); + String grantedPermissions = permissionsJoiner.toString(); + if (permissionSign.getDuration() > 0) { + String successMessage = StringFormatter.getTranslatedInfoMessage(TranslatableMessage.PERMISSIONS_GRANTED); + String timeUnit = Translator.getTranslatedMessage(TranslatableMessage.SIGN_TIME_UNIT); + player.sendMessage(StringFormatter.replacePlaceholders(successMessage, new String[]{"{permissions}", "{time}"}, + new String[]{grantedPermissions, permissionSign.getDuration() + " " + timeUnit})); + } else { + player.sendMessage(StringFormatter.replacePlaceholder(StringFormatter.getTranslatedInfoMessage( + TranslatableMessage.PERMISSIONS_GRANTED_PERMANENTLY), "{permissions}", grantedPermissions)); + } } /**