Adds a description to permission signs
The description is displayed when right-clicking the sign, and can be used to fully describe the effects, without the player needing to understand permissions.
This commit is contained in:
parent
f9fd999a7f
commit
a3f235fbf0
@ -23,10 +23,11 @@ permanently by another cause) when they expire.
|
||||
|
||||
### The create command
|
||||
|
||||
/ps create <name> <permission,permission> <cost> <duration> - 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 <name> <description> <permission,permission> <cost> <duration> - 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
|
||||
|
||||
|
@ -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 <name> <permission,permission> <cost> <duration> to create a new permission-sign
|
||||
//Name and permission(s) required, but duration and cost optional
|
||||
String usage = "/ps create <name> <permission,permission> [cost] [duration] - Used for creating a new permission sign";
|
||||
String usage = "/ps create <name> <description> <permission,permission> [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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public class CreateTabCompleter implements TabCompleter {
|
||||
private static List<String> numbers;
|
||||
private static List<String> empty;
|
||||
private static List<String> name;
|
||||
private static List<String> description;
|
||||
|
||||
@Override
|
||||
public List<String> 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("<name>");
|
||||
description = new ArrayList<>();
|
||||
description.add("<description>");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ public class PermissionSign {
|
||||
|
||||
private Location signLocation;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final List<String> permissionNodes;
|
||||
private final int duration;
|
||||
private final double cost;
|
||||
@ -33,13 +34,16 @@ public class PermissionSign {
|
||||
*
|
||||
* @param signLocation <p>The location of the permission sing in the world</p>
|
||||
* @param name <p>The name to display on the permission sign</p>
|
||||
* @param description <p>A description describing what buying the permission(s) allows</p>
|
||||
* @param permissionNodes <p>The permissions granted when this permission sign is used</p>
|
||||
* @param duration <p>The duration, in seconds, until the permission should be revoked. 0 for non-temporary</p>
|
||||
* @param cost <p>The cost of using this permission sign</p>
|
||||
*/
|
||||
public PermissionSign(Location signLocation, String name, List<String> permissionNodes, int duration, double cost) {
|
||||
public PermissionSign(Location signLocation, String name, String description, List<String> 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 <p>The name to display on the permission sign</p>
|
||||
* @param description <p>A description describing what buying the permission(s) allows</p>
|
||||
* @param permissionNodes <p>The permissions granted when this permission sign is used</p>
|
||||
* @param duration <p>The duration, in seconds, until the permission should be revoked. 0 for non-temporary</p>
|
||||
* @param cost <p>The cost of using this permission sign</p>
|
||||
*/
|
||||
public PermissionSign(String name, List<String> permissionNodes, int duration, double cost) {
|
||||
public PermissionSign(String name, String description, List<String> 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 <p>The description of this permission sign</p>
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the permissions nodes granted by this permission sign
|
||||
*
|
||||
|
@ -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()});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<String> 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);
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user