diff --git a/README.md b/README.md index 5b8ca9a..28d4410 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,11 @@ permanently by another cause) when they expire. ### The create command -/ps create - Creates a new permission sign. The name is used to -describe what the permission sign does. The permission,permission is the list of comma-separated permissions the -permission sign will grant to the using player. The cost is the cost to use the permission sign. The duration is the -number of seconds the player should keep the permission for. Use 0 for permanent. +/ps create - Creates a new permission sign. The name is +used to describe what the permission sign does, and is displayed on the sign. The description is used to describe what +the permission sign does, but without any limit on the length. The permission,permission is the list of comma-separated +permissions the permission sign will grant to the using player. The cost is the cost to use the permission sign. The +duration is the number of seconds the player should keep the permission for. Use 0 for permanent. #### The create command permission list diff --git a/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java b/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java index f8f712d..41afdaf 100644 --- a/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java +++ b/src/main/java/net/knarcraft/permissionsigns/command/CreateCommand.java @@ -22,7 +22,7 @@ public class CreateCommand implements CommandExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { // /ps create to create a new permission-sign //Name and permission(s) required, but duration and cost optional - String usage = "/ps create [cost] [duration] - Used for creating a new permission sign"; + String usage = "/ps create [cost] [duration] - Used for creating a new permission sign"; if (!(sender instanceof Player)) { sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COMMAND_PLAYER_ONLY)); return false; @@ -31,7 +31,7 @@ public class CreateCommand implements CommandExecutor { sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COMMAND_PERMISSION_DENIED)); return false; } - if (args.length < 2) { + if (args.length < 3) { sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.MISSING_CREATION_INFO)); sender.sendMessage(usage); return true; @@ -57,7 +57,8 @@ public class CreateCommand implements CommandExecutor { */ private PermissionSign parseSign(@NotNull CommandSender sender, @NotNull String[] args) { String name = args[0]; - String[] permissions = args[1].replaceAll("\\?", " ").split(","); + String description = args[1]; + String[] permissions = args[2].replaceAll("\\?", " ").split(","); for (String permission : permissions) { if (permission.contains(":")) { String world = permission.split(":")[0]; @@ -72,24 +73,24 @@ public class CreateCommand implements CommandExecutor { double cost = 0; int duration = 0; - if (args.length > 2) { + if (args.length > 3) { try { - cost = Double.parseDouble(args[2]); + cost = Double.parseDouble(args[3]); } catch (NumberFormatException exception) { sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COST_INVALID_NUMBER)); return null; } } - if (args.length > 3) { + if (args.length > 4) { try { - duration = Integer.parseInt(args[3]); + duration = Integer.parseInt(args[4]); } catch (NumberFormatException exception) { sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.DURATION_INVALID_NUMBER)); return null; } } - return new PermissionSign(name, List.of(permissions), duration, cost); + return new PermissionSign(name, description, List.of(permissions), duration, cost); } } diff --git a/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java b/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java index 06f6a9e..2b70378 100644 --- a/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java +++ b/src/main/java/net/knarcraft/permissionsigns/command/CreateTabCompleter.java @@ -23,6 +23,7 @@ public class CreateTabCompleter implements TabCompleter { private static List numbers; private static List empty; private static List name; + private static List description; @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @@ -37,14 +38,18 @@ public class CreateTabCompleter implements TabCompleter { empty = new ArrayList<>(); name = new ArrayList<>(); name.add(""); + description = new ArrayList<>(); + description.add(""); } - if (args.length > 4) { + if (args.length > 5) { return empty; - } else if (args.length > 2) { + } else if (args.length > 3) { return numbers; + } else if (args.length > 2) { + return tabCompletePermission(args[2]); } else if (args.length > 1) { - return tabCompletePermission(args[1]); + return description; } else { return name; } diff --git a/src/main/java/net/knarcraft/permissionsigns/container/PermissionSign.java b/src/main/java/net/knarcraft/permissionsigns/container/PermissionSign.java index dcab3ca..e2208ef 100644 --- a/src/main/java/net/knarcraft/permissionsigns/container/PermissionSign.java +++ b/src/main/java/net/knarcraft/permissionsigns/container/PermissionSign.java @@ -21,6 +21,7 @@ public class PermissionSign { private Location signLocation; private final String name; + private final String description; private final List permissionNodes; private final int duration; private final double cost; @@ -33,13 +34,16 @@ public class PermissionSign { * * @param signLocation

The location of the permission sing in the world

* @param name

The name to display on the permission sign

+ * @param description

A description describing what buying the permission(s) allows

* @param permissionNodes

The permissions granted when this permission sign is used

* @param duration

The duration, in seconds, until the permission should be revoked. 0 for non-temporary

* @param cost

The cost of using this permission sign

*/ - public PermissionSign(Location signLocation, String name, List permissionNodes, int duration, double cost) { + public PermissionSign(Location signLocation, String name, String description, List permissionNodes, + int duration, double cost) { this.signLocation = signLocation; this.name = name; + this.description = description; this.permissionNodes = new ArrayList<>(permissionNodes); //Automatically fix negative values @@ -51,12 +55,14 @@ public class PermissionSign { * Instantiates a new permission sign * * @param name

The name to display on the permission sign

+ * @param description

A description describing what buying the permission(s) allows

* @param permissionNodes

The permissions granted when this permission sign is used

* @param duration

The duration, in seconds, until the permission should be revoked. 0 for non-temporary

* @param cost

The cost of using this permission sign

*/ - public PermissionSign(String name, List permissionNodes, int duration, double cost) { + public PermissionSign(String name, String description, List permissionNodes, int duration, double cost) { this.name = name; + this.description = description; this.permissionNodes = new ArrayList<>(permissionNodes); this.duration = Math.max(0, duration); this.cost = Math.max(0, cost); @@ -95,6 +101,15 @@ public class PermissionSign { return name; } + /** + * Gets the description of this permission sign + * + * @return

The description of this permission sign

+ */ + public String getDescription() { + return description; + } + /** * Gets the permissions nodes granted by this permission sign * diff --git a/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java b/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java index cabbd6a..72b53b2 100644 --- a/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java +++ b/src/main/java/net/knarcraft/permissionsigns/listener/SignListener.java @@ -111,9 +111,9 @@ public class SignListener implements Listener { } } - return StringFormatter.replacePlaceholders(rawSignInfo, new String[]{"{Name}", "{Permissions}", - "{Cost}", "{Duration}"}, new String[]{sign.getName(), permissionString.toString(), sign.getCostString(), - sign.getDurationString()}); + return StringFormatter.replacePlaceholders(rawSignInfo, new String[]{"{Name}", "{Description}", "{Permissions}", + "{Cost}", "{Duration}"}, new String[]{sign.getName(), sign.getDescription(), + permissionString.toString(), sign.getCostString(), sign.getDurationString()}); } /** diff --git a/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java b/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java index 14cc854..67cd763 100644 --- a/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java +++ b/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java @@ -78,6 +78,7 @@ public final class SignManager { signLocation.getBlockX() + "," + signLocation.getBlockY() + "," + signLocation.getBlockZ(); PermissionSign sign = managedSigns.get(signLocation); signSection.set(locationString + ".name", sign.getName()); + signSection.set(locationString + ".description", sign.getDescription()); signSection.set(locationString + ".permissions", sign.getPermissionNodes()); signSection.set(locationString + ".duration", sign.getDuration()); signSection.set(locationString + ".cost", sign.getCost()); @@ -174,6 +175,11 @@ public final class SignManager { throw new IllegalArgumentException("Name missing from sign data"); } + String signDescription = signSection.getString(key + ".description"); + if (signDescription == null) { + signDescription = ""; + } + List permissionStrings = new ArrayList<>(); List permissions = signSection.getList(key + ".permissions"); if (permissions == null) { @@ -188,7 +194,7 @@ public final class SignManager { int duration = signSection.getInt(key + ".duration"); double cost = signSection.getDouble(key + ".cost"); - PermissionSign loadedSign = new PermissionSign(signLocation, signName, permissionStrings, duration, cost); + PermissionSign loadedSign = new PermissionSign(signLocation, signName, signDescription, permissionStrings, duration, cost); managedSigns.put(signLocation, loadedSign); } diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index c719e8e..3f29918 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -35,6 +35,7 @@ en: SIGN_INFO: | &f---- &4Permission Sign&f ---- &f| &bName: &7{Name} + &f| &bDescription: &7{Description} &f| &bPermission(s): &7{Permissions} &f| &bCost: &7{Cost} &f| &bDuration: &7{Duration} @@ -78,6 +79,7 @@ nb-no: SIGN_INFO: | &f---- &4Tilgangsrettighetsskilt&f ---- &f| &bNavn: &7{Name} + &f| &bBeskrivelse: &7{Description} &f| &bTilgangsrettighet(er): &7{Permissions} &f| &bKostnad: &7{Cost} &f| &bVarighet: &7{Duration}