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
|
### The create command
|
||||||
|
|
||||||
/ps create <name> <permission,permission> <cost> <duration> - Creates a new permission sign. The name is used to
|
/ps create <name> <description> <permission,permission> <cost> <duration> - Creates a new permission sign. The name is
|
||||||
describe what the permission sign does. The permission,permission is the list of comma-separated permissions the
|
used to describe what the permission sign does, and is displayed on the sign. The description is used to describe what
|
||||||
permission sign will grant to the using player. The cost is the cost to use the permission sign. The duration is the
|
the permission sign does, but without any limit on the length. The permission,permission is the list of comma-separated
|
||||||
number of seconds the player should keep the permission for. Use 0 for permanent.
|
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
|
#### 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) {
|
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
|
// /ps create <name> <permission,permission> <cost> <duration> to create a new permission-sign
|
||||||
//Name and permission(s) required, but duration and cost optional
|
//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)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COMMAND_PLAYER_ONLY));
|
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COMMAND_PLAYER_ONLY));
|
||||||
return false;
|
return false;
|
||||||
@ -31,7 +31,7 @@ public class CreateCommand implements CommandExecutor {
|
|||||||
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COMMAND_PERMISSION_DENIED));
|
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COMMAND_PERMISSION_DENIED));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (args.length < 2) {
|
if (args.length < 3) {
|
||||||
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.MISSING_CREATION_INFO));
|
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.MISSING_CREATION_INFO));
|
||||||
sender.sendMessage(usage);
|
sender.sendMessage(usage);
|
||||||
return true;
|
return true;
|
||||||
@ -57,7 +57,8 @@ public class CreateCommand implements CommandExecutor {
|
|||||||
*/
|
*/
|
||||||
private PermissionSign parseSign(@NotNull CommandSender sender, @NotNull String[] args) {
|
private PermissionSign parseSign(@NotNull CommandSender sender, @NotNull String[] args) {
|
||||||
String name = args[0];
|
String name = args[0];
|
||||||
String[] permissions = args[1].replaceAll("\\?", " ").split(",");
|
String description = args[1];
|
||||||
|
String[] permissions = args[2].replaceAll("\\?", " ").split(",");
|
||||||
for (String permission : permissions) {
|
for (String permission : permissions) {
|
||||||
if (permission.contains(":")) {
|
if (permission.contains(":")) {
|
||||||
String world = permission.split(":")[0];
|
String world = permission.split(":")[0];
|
||||||
@ -72,24 +73,24 @@ public class CreateCommand implements CommandExecutor {
|
|||||||
|
|
||||||
double cost = 0;
|
double cost = 0;
|
||||||
int duration = 0;
|
int duration = 0;
|
||||||
if (args.length > 2) {
|
if (args.length > 3) {
|
||||||
try {
|
try {
|
||||||
cost = Double.parseDouble(args[2]);
|
cost = Double.parseDouble(args[3]);
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COST_INVALID_NUMBER));
|
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.COST_INVALID_NUMBER));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (args.length > 3) {
|
if (args.length > 4) {
|
||||||
try {
|
try {
|
||||||
duration = Integer.parseInt(args[3]);
|
duration = Integer.parseInt(args[4]);
|
||||||
} catch (NumberFormatException exception) {
|
} catch (NumberFormatException exception) {
|
||||||
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.DURATION_INVALID_NUMBER));
|
sender.sendMessage(StringFormatter.getTranslatedErrorMessage(TranslatableMessage.DURATION_INVALID_NUMBER));
|
||||||
return null;
|
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> numbers;
|
||||||
private static List<String> empty;
|
private static List<String> empty;
|
||||||
private static List<String> name;
|
private static List<String> name;
|
||||||
|
private static List<String> description;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
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<>();
|
empty = new ArrayList<>();
|
||||||
name = new ArrayList<>();
|
name = new ArrayList<>();
|
||||||
name.add("<name>");
|
name.add("<name>");
|
||||||
|
description = new ArrayList<>();
|
||||||
|
description.add("<description>");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length > 4) {
|
if (args.length > 5) {
|
||||||
return empty;
|
return empty;
|
||||||
} else if (args.length > 2) {
|
} else if (args.length > 3) {
|
||||||
return numbers;
|
return numbers;
|
||||||
|
} else if (args.length > 2) {
|
||||||
|
return tabCompletePermission(args[2]);
|
||||||
} else if (args.length > 1) {
|
} else if (args.length > 1) {
|
||||||
return tabCompletePermission(args[1]);
|
return description;
|
||||||
} else {
|
} else {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ public class PermissionSign {
|
|||||||
|
|
||||||
private Location signLocation;
|
private Location signLocation;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private final String description;
|
||||||
private final List<String> permissionNodes;
|
private final List<String> permissionNodes;
|
||||||
private final int duration;
|
private final int duration;
|
||||||
private final double cost;
|
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 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 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 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 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>
|
* @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.signLocation = signLocation;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
this.permissionNodes = new ArrayList<>(permissionNodes);
|
this.permissionNodes = new ArrayList<>(permissionNodes);
|
||||||
|
|
||||||
//Automatically fix negative values
|
//Automatically fix negative values
|
||||||
@ -51,12 +55,14 @@ public class PermissionSign {
|
|||||||
* Instantiates a new permission sign
|
* Instantiates a new permission sign
|
||||||
*
|
*
|
||||||
* @param name <p>The name to display on the permission sign</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 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 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>
|
* @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.name = name;
|
||||||
|
this.description = description;
|
||||||
this.permissionNodes = new ArrayList<>(permissionNodes);
|
this.permissionNodes = new ArrayList<>(permissionNodes);
|
||||||
this.duration = Math.max(0, duration);
|
this.duration = Math.max(0, duration);
|
||||||
this.cost = Math.max(0, cost);
|
this.cost = Math.max(0, cost);
|
||||||
@ -95,6 +101,15 @@ public class PermissionSign {
|
|||||||
return name;
|
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
|
* 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}",
|
return StringFormatter.replacePlaceholders(rawSignInfo, new String[]{"{Name}", "{Description}", "{Permissions}",
|
||||||
"{Cost}", "{Duration}"}, new String[]{sign.getName(), permissionString.toString(), sign.getCostString(),
|
"{Cost}", "{Duration}"}, new String[]{sign.getName(), sign.getDescription(),
|
||||||
sign.getDurationString()});
|
permissionString.toString(), sign.getCostString(), sign.getDurationString()});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +78,7 @@ public final class SignManager {
|
|||||||
signLocation.getBlockX() + "," + signLocation.getBlockY() + "," + signLocation.getBlockZ();
|
signLocation.getBlockX() + "," + signLocation.getBlockY() + "," + signLocation.getBlockZ();
|
||||||
PermissionSign sign = managedSigns.get(signLocation);
|
PermissionSign sign = managedSigns.get(signLocation);
|
||||||
signSection.set(locationString + ".name", sign.getName());
|
signSection.set(locationString + ".name", sign.getName());
|
||||||
|
signSection.set(locationString + ".description", sign.getDescription());
|
||||||
signSection.set(locationString + ".permissions", sign.getPermissionNodes());
|
signSection.set(locationString + ".permissions", sign.getPermissionNodes());
|
||||||
signSection.set(locationString + ".duration", sign.getDuration());
|
signSection.set(locationString + ".duration", sign.getDuration());
|
||||||
signSection.set(locationString + ".cost", sign.getCost());
|
signSection.set(locationString + ".cost", sign.getCost());
|
||||||
@ -174,6 +175,11 @@ public final class SignManager {
|
|||||||
throw new IllegalArgumentException("Name missing from sign data");
|
throw new IllegalArgumentException("Name missing from sign data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String signDescription = signSection.getString(key + ".description");
|
||||||
|
if (signDescription == null) {
|
||||||
|
signDescription = "";
|
||||||
|
}
|
||||||
|
|
||||||
List<String> permissionStrings = new ArrayList<>();
|
List<String> permissionStrings = new ArrayList<>();
|
||||||
List<?> permissions = signSection.getList(key + ".permissions");
|
List<?> permissions = signSection.getList(key + ".permissions");
|
||||||
if (permissions == null) {
|
if (permissions == null) {
|
||||||
@ -188,7 +194,7 @@ public final class SignManager {
|
|||||||
int duration = signSection.getInt(key + ".duration");
|
int duration = signSection.getInt(key + ".duration");
|
||||||
double cost = signSection.getDouble(key + ".cost");
|
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);
|
managedSigns.put(signLocation, loadedSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ en:
|
|||||||
SIGN_INFO: |
|
SIGN_INFO: |
|
||||||
&f---- &4Permission Sign&f ----
|
&f---- &4Permission Sign&f ----
|
||||||
&f| &bName: &7{Name}
|
&f| &bName: &7{Name}
|
||||||
|
&f| &bDescription: &7{Description}
|
||||||
&f| &bPermission(s): &7{Permissions}
|
&f| &bPermission(s): &7{Permissions}
|
||||||
&f| &bCost: &7{Cost}
|
&f| &bCost: &7{Cost}
|
||||||
&f| &bDuration: &7{Duration}
|
&f| &bDuration: &7{Duration}
|
||||||
@ -78,6 +79,7 @@ nb-no:
|
|||||||
SIGN_INFO: |
|
SIGN_INFO: |
|
||||||
&f---- &4Tilgangsrettighetsskilt&f ----
|
&f---- &4Tilgangsrettighetsskilt&f ----
|
||||||
&f| &bNavn: &7{Name}
|
&f| &bNavn: &7{Name}
|
||||||
|
&f| &bBeskrivelse: &7{Description}
|
||||||
&f| &bTilgangsrettighet(er): &7{Permissions}
|
&f| &bTilgangsrettighet(er): &7{Permissions}
|
||||||
&f| &bKostnad: &7{Cost}
|
&f| &bKostnad: &7{Cost}
|
||||||
&f| &bVarighet: &7{Duration}
|
&f| &bVarighet: &7{Duration}
|
||||||
|
Loading…
Reference in New Issue
Block a user