The full permission node typed by the player
+ * @returnAll known valid auto-complete options
+ */ + private ListThe values to filter
+ * @param typedTextThe text the player has started typing
+ * @returnThe given string values which start with the player's typed text
+ */ + private ListThe permission to load
+ */ + private static void loadPermission(Permission permission) { + String permissionName = permission.getName(); + 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 input string to replace in
* @param placeholderThe placeholder to replace
* @param replacementThe replacement value
- * @returnThe input string with all placeholder instances replaced
+ * @returnThe input string with the placeholder replaced
*/ public static String replacePlaceholder(String input, String placeholder, String replacement) { - return input.replaceAll(placeholder, replacement); + return input.replace(placeholder, replacement); } /** @@ -25,7 +25,7 @@ public class StringFormatter { * @param inputThe input string to replace in
* @param placeholdersThe placeholders to replace
* @param replacementsThe replacement values
- * @returnThe input string with all placeholder instances replaced
+ * @returnThe input string with placeholders replaced
*/ public static String replacePlaceholders(String input, String[] placeholders, String[] replacements) { for (int i = 0; i < Math.min(placeholders.length, replacements.length); i++) { @@ -61,7 +61,7 @@ public class StringFormatter { * @returnThe formatted message
*/ public static String formatInfoMessage(String message) { - return ChatColor.DARK_RED + formatMessage(message); + return ChatColor.DARK_GREEN + formatMessage(message); } /** @@ -71,7 +71,7 @@ public class StringFormatter { * @returnThe formatted message
*/ public static String formatErrorMessage(String message) { - return ChatColor.DARK_GREEN + formatMessage(message); + return ChatColor.DARK_RED + formatMessage(message); } /** @@ -82,7 +82,8 @@ public class StringFormatter { */ private static String formatMessage(String message) { return ChatColor.translateAlternateColorCodes('&', - Translator.getTranslatedMessage(TranslatableMessage.PREFIX)) + ChatColor.RESET + message; + Translator.getTranslatedMessage(TranslatableMessage.PREFIX)) + " " + ChatColor.RESET + + ChatColor.translateAlternateColorCodes('&', message); } } diff --git a/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java b/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java index 8efe385..86d0f57 100644 --- a/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java +++ b/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java @@ -135,7 +135,11 @@ public class SignListener implements Listener { if (!player.hasPermission(permissionNode)) { permissionsBuilder.append(permissionNode); permissionsBuilder.append(", "); - PermissionManager.addPermission(player, permissionNode, permissionSign.getDuration() == 0); + if (permissionSign.getDuration() == 0) { + PermissionManager.addPermission(player, permissionNode); + } else { + PermissionManager.addTemporaryPermission(player, permissionNode, permissionSign.getDuration()); + } } } @@ -144,7 +148,7 @@ public class SignListener implements Listener { 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})); + new String[]{grantedPermissions, permissionSign.getDuration() + " " + timeUnit})); } /** diff --git a/src/main/java/net/knarcraft/permissionsigns/manager/PermissionManager.java b/src/main/java/net/knarcraft/permissionsigns/manager/PermissionManager.java index 7c1be1d..3158a85 100644 --- a/src/main/java/net/knarcraft/permissionsigns/manager/PermissionManager.java +++ b/src/main/java/net/knarcraft/permissionsigns/manager/PermissionManager.java @@ -24,28 +24,13 @@ public class PermissionManager { PermissionManager.permission = permission; } - /** - * Grants a permission to the given player - * - * @param playerThe player to grant the permission to
- * @param permissionNodeThe permission node to grant the player
- * @param permanentWhether to permanently grant the permission node
- */ - public static void addPermission(Player player, String permissionNode, boolean permanent) { - if (permanent) { - addPermission(player, permissionNode); - } else { - addTemporaryPermission(player, permissionNode); - } - } - /** * Grants a permanent permission to a player * * @param playerThe player to grant the permission to
* @param permissionNodeThe permission node to grant to the player
*/ - private static void addPermission(Player player, String permissionNode) { + public static void addPermission(Player player, String permissionNode) { permission.playerAdd(player, permissionNode); } @@ -54,9 +39,11 @@ public class PermissionManager { * * @param playerThe player to give the permission to
* @param permissionNodeThe temporary permission to grant
+ * @param durationThe duration for which the player should keep the given permission
*/ - private static void addTemporaryPermission(OfflinePlayer player, String permissionNode) { + public static void addTemporaryPermission(OfflinePlayer player, String permissionNode, int duration) { permission.playerAddTransient(player, permissionNode); + temporaryPermissions.add(new TemporaryPermission(player, permissionNode, duration)); //TODO: Create and store a temporary permission // Check all stored temporary permissions on startup: // * Remove expired temporary permissions diff --git a/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java b/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java index 7d21a4c..89356b9 100644 --- a/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java +++ b/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.UUID; import java.util.logging.Level; /** @@ -81,10 +82,10 @@ public class SignManager { */ public static void loadSigns() { YamlConfiguration configuration = YamlConfiguration.loadConfiguration(signsFile); - ConfigurationSection signSection = configuration.getConfigurationSection("signs"); managedSigns = new HashMap<>(); if (signSection == null) { + PermissionSigns.getInstance().getLogger().log(Level.WARNING, "Signs section not found in signs.yml"); return; } for (String key : signSection.getKeys(false)) { @@ -95,6 +96,7 @@ public class SignManager { e.getMessage()); } } + PermissionSigns.getInstance().getLogger().log(Level.INFO, "Permission signs finished loading"); //TODO: Might want to re-draw signs here in case any signs have changed } @@ -120,8 +122,9 @@ public class SignManager { String[] locationParts = key.split(","); Location signLocation; try { - signLocation = new Location(Bukkit.getWorld(locationParts[0]), Double.parseDouble(locationParts[1]), - Double.parseDouble(locationParts[2]), Double.parseDouble(locationParts[3])); + signLocation = new Location(Bukkit.getWorld(UUID.fromString(locationParts[0])), + Double.parseDouble(locationParts[1]), Double.parseDouble(locationParts[2]), + Double.parseDouble(locationParts[3])); } catch (NumberFormatException exception) { throw new InvalidConfigurationException("Invalid sign coordinates"); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 90c0f18..4c5ac1a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: PermissionSigns -version: '${project.version}' -main: net.knarcraft.permissionsigns.Permissionsigns +version: 1.0 +main: net.knarcraft.permissionsigns.PermissionSigns api-version: 1.18 prefix: PermissionSigns depend: [ Vault ]