This plugin's version
+ */ + public static String getPluginVersion() { + return pluginVersion; + } + + /** + * Adds a new sign creation request + * + * @param playerThe player that initiated the sign creation
+ * @param signThe sign the player is about to create
+ */ + public static void addSignCreationRequest(Player player, PermissionSign sign) { + signCreationRequests.add(new SignCreationRequest(sign, player, System.currentTimeMillis())); + } /** * Gets the sign creation request for the player with the given UUID - * + * * @param uuidThe UUID to get a sign creation request for
* @returnA sign creation request, or null if the UUID is not found
*/ @@ -34,10 +59,25 @@ public final class PermissionSigns extends JavaPlugin { } } + /** + * Cancels the sign creation request triggered by the user + * + * @param uuidThe UUID of the player to cancel the request for
+ */ + public static void cancelSignCreationRequest(UUID uuid) { + StreamThe command sender to get available commands for
+ * @returnThe commands available to the command sender
+ */ + private ListThe name to display on the permission sign
* @param permissionNodesThe permissions granted when this permission sign is used
* @param durationThe duration, in seconds, until the permission should be revoked. 0 for non-temporary
* @param costThe cost of using this permission sign
*/ - public PermissionSign(List>The location of this permission sign's actual sign
*/ public void setSignLocation(Location signLocation) { @@ -64,7 +69,7 @@ public class PermissionSign { * Gets the location of this permission sign * *The location might be null until a sign has been right-clicked
- * + * * @returnThe location of this permission sign
*/ public Location getSignLocation() { @@ -73,7 +78,7 @@ public class PermissionSign { /** * Gets the name of this permission sign - * + * * @returnThe name of this permission sign
*/ public String getName() { @@ -108,7 +113,21 @@ public class PermissionSign { public int getCost() { return this.cost; } - + + /** + * Gets the lines used to represent this permission sign on a sign + * + * @returnThe lines used to draw this permission sign
+ */ + public String[] getSignLines() { + String[] lines = new String[4]; + lines[0] = ChatColor.RED + Translator.getTranslatedMessage(TranslatableMessage.PREFIX); + lines[1] = getName(); + lines[2] = getDurationString(); + lines[3] = getCostString(); + return lines; + } + @Override public boolean equals(Object other) { if (!(other instanceof PermissionSign)) { @@ -117,8 +136,35 @@ public class PermissionSign { if (this == other) { return true; } - + return this.signLocation.equals(((PermissionSign) other).signLocation); } + /** + * Gets the string used for displaying this sign's duration + * + * @returnThe string used for displaying this sign's duration
+ */ + private String getDurationString() { + if (duration == 0) { + return Translator.getTranslatedMessage(TranslatableMessage.PERMANENT); + } else { + return duration + " " + Translator.getTranslatedMessage(TranslatableMessage.TIME_UNIT); + } + } + + /** + * Gets the string used for displaying this sign's cost + * + * @returnThe string used for displaying this sign's cost
+ */ + private String getCostString() { + if (cost == 0) { + return Translator.getTranslatedMessage(TranslatableMessage.COST_FREE); + } else { + //TODO: Get currency unit from Vault + return cost + "$"; + } + } + } diff --git a/src/main/java/net/knarcraft/permissionsigns/container/SignCreationRequest.java b/src/main/java/net/knarcraft/permissionsigns/container/SignCreationRequest.java index e7a8951..9cb6025 100644 --- a/src/main/java/net/knarcraft/permissionsigns/container/SignCreationRequest.java +++ b/src/main/java/net/knarcraft/permissionsigns/container/SignCreationRequest.java @@ -6,16 +6,16 @@ import org.bukkit.entity.Player; * A sign creation request represents the state where a player has used the create command, but not clicked a sign */ public class SignCreationRequest implements ComparableThe sign which is about to be created
- * @param playerThe player starting to create the permission sign
+ * @param playerThe player starting to create the permission sign
* @param initiationTime */ public SignCreationRequest(PermissionSign permissionSign, Player player, long initiationTime) { @@ -26,7 +26,7 @@ public class SignCreationRequest implements ComparableThe involved permission sign
*/ public PermissionSign getPermissionSign() { @@ -35,7 +35,7 @@ public class SignCreationRequest implements ComparableThe involved player
*/ public Player getPlayer() { @@ -44,13 +44,13 @@ public class SignCreationRequest implements ComparableThe time this request was initiated
*/ public long initiationTime() { return this.initiationTime; } - + @Override public boolean equals(Object other) { if (!(other instanceof SignCreationRequest otherRequest)) { @@ -59,7 +59,7 @@ public class SignCreationRequest implements ComparableThe message to format
+ * @returnThe formatted message
+ */ + public static String formatInfoMessage(String message) { + return ChatColor.DARK_RED + formatMessage(message); + } + + /** + * Formats an error message by adding the prefix and text color + * + * @param messageThe message to format
+ * @returnThe formatted message
+ */ + public static String formatErrorMessage(String message) { + return ChatColor.DARK_GREEN + formatMessage(message); + } + + /** + * Formats a message by adding the prefix and text color + * + * @param messageThe message to format
+ * @returnThe formatted message
+ */ + private static String formatMessage(String message) { + return Translator.getTranslatedMessage(TranslatableMessage.PREFIX) + ChatColor.GRAY + message; + } + +} diff --git a/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java b/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java new file mode 100644 index 0000000..dc8487c --- /dev/null +++ b/src/main/java/net/knarcraft/permissionsigns/formatting/TranslatableMessage.java @@ -0,0 +1,19 @@ +package net.knarcraft.permissionsigns.formatting; + +/** + * An enum representing all translatable messages + */ +public enum TranslatableMessage { + + PREFIX, + MISSING_CREATION_INFO, + TIME_UNIT, + COST_FREE, + PERMANENT, + COST_INVALID_NUMBER, + DURATION_INVALID_NUMBER, + COMMAND_PLAYER_ONLY, + PERMISSION_SIGN_DESTROY_DENY, + PERMISSION_SIGN_REMOVED + +} diff --git a/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java b/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java new file mode 100644 index 0000000..2c1c84b --- /dev/null +++ b/src/main/java/net/knarcraft/permissionsigns/formatting/Translator.java @@ -0,0 +1,67 @@ +package net.knarcraft.permissionsigns.formatting; + +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Map; + +/** + * A tool to get strings translated to the correct language + */ +public class Translator { + + private static MapThe message to translate
+ * @returnThe translated message
+ */ + public static String getTranslatedMessage(TranslatableMessage translatableMessage) { + if (translatedMessages.containsKey(translatableMessage)) { + return translatedMessages.get(translatableMessage); + } else if (backupTranslatedMessages.containsKey(translatableMessage)) { + return backupTranslatedMessages.get(translatableMessage); + } else { + return translatableMessage.toString(); + } + } + + /** + * Loads all translated messages for the given language + * + * @param languageThe language chosen by the user
+ * @returnA mapping of all strings for the given language
+ */ + public static MapThe clicked sign
+ * + * @param signThe clicked sign
* @param playerThe player that clicked the sign
*/ private void handleSignRightClick(Sign sign, Player player) { String[] lines = sign.getLines(); + + //TODO: Check if the sign is a registered permissions sign + //Don't allow non-empty signs to be overwritten if (!Arrays.stream(lines).allMatch(String::isEmpty)) { return; @@ -61,5 +86,5 @@ public class SignListener implements Listener { //TODO: Register the sign and remove the request } - + } diff --git a/src/main/java/net/knarcraft/permissionsigns/thread/SignCreationRequestTimeoutThread.java b/src/main/java/net/knarcraft/permissionsigns/thread/SignCreationRequestTimeoutThread.java index 0fd7bb2..ce43587 100644 --- a/src/main/java/net/knarcraft/permissionsigns/thread/SignCreationRequestTimeoutThread.java +++ b/src/main/java/net/knarcraft/permissionsigns/thread/SignCreationRequestTimeoutThread.java @@ -8,23 +8,23 @@ import java.util.Queue; * The sign creation request timeout thread is responsible for removing sign creation requests as they time out */ public class SignCreationRequestTimeoutThread implements Runnable { - + private final QueueA pointer to the queue of sign creation requests
*/ public SignCreationRequestTimeoutThread(Queue