diff --git a/API/pom.xml b/API/pom.xml new file mode 100644 index 00000000..b0825c1f --- /dev/null +++ b/API/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + nl.svenar + powerranks.api + ${revision} + PowerRanks API + Rank-based permission manager + + + 1.8 + UTF-8 + src/main/java + src/main/resources + false + + + + nl.svenar + powerranks + ${revision} + + + + clean compile package + ${project.name} + ${src.dir} + + + ${rsc.dir} + true + + + + + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.1 + + ${skipAPITests} + + + + + + + + jitpack.io + https://jitpack.io + + + svenar + https://svenar.nl/repo/ + + + + + + nl.svenar + powerranks.core + ${revision} + + + \ No newline at end of file diff --git a/API/src/main/java/nl/svenar/powerranks/api/PlayersAPI.java b/API/src/main/java/nl/svenar/powerranks/api/PlayersAPI.java new file mode 100644 index 00000000..535fe60e --- /dev/null +++ b/API/src/main/java/nl/svenar/powerranks/api/PlayersAPI.java @@ -0,0 +1,1113 @@ +package nl.svenar.powerranks.api; + +import java.util.Set; +import java.util.UUID; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; + +public class PlayersAPI { + + // ================================================================================ + // || || + // || GET PRPLAYER || + // || || + // ================================================================================ + + /** + * Get a PRPlayer object by UUID + * + * @param UUID + * @return PRPlayer + */ + public PRPlayer get(UUID uuid) { + return get(uuid.toString()); + } + + /** + * Get a PRPlayer object by identiefier + * + * @param identifier + * @return PRPlayer + */ + public PRPlayer get(String identifier) { + return PRCache.getPlayer(identifier); + } + + // ================================================================================ + // || || + // || NAME || + // || || + // ================================================================================ + + /** + * Change the name of a PRPlayer + * + * @param UUID + * @param name + * @return true if player is not null + */ + public boolean setName(UUID uuid, String name) { + return setName(uuid.toString(), name); + } + + /** + * Change the name of a PRPlayer + * + * @param identifier + * @param name + * @return true if player is not null + */ + public boolean setName(String identifier, String name) { + return setName(get(identifier), name); + } + + /** + * Change the name of a PRPlayer + * + * @param PRPlayer + * @param name + * @return true if player is not null + */ + public boolean setName(PRPlayer player, String name) { + if (player == null) { + return false; + } + + player.setName(name); + return true; + } + + /** + * Get the name of a PRPlayer + * + * @param UUID + * @return String or null if player is null + */ + public String getName(UUID uuid) { + return getName(uuid.toString()); + } + + /** + * Get the name of a PRPlayer + * + * @param identifier + * @return String or null if player is null + */ + public String getName(String identifier) { + return getName(get(identifier)); + } + + /** + * Get the name of a PRPlayer + * + * @param PRPlayer + * @return String or null if player is null + */ + public String getName(PRPlayer player) { + if (player == null) { + return null; + } + + return player.getName(); + } + + // ================================================================================ + // || || + // || NICKNAME || + // || || + // ================================================================================ + + /** + * Change the nickname of a PRPlayer + * + * @param UUID + * @param nickname + * @return true if player is not null + */ + public boolean setNickName(UUID uuid, String nickname) { + return setNickName(uuid.toString(), nickname); + } + + /** + * Change the nickname of a PRPlayer + * + * @param identifier + * @param nickname + * @return true if player is not null + */ + public boolean setNickName(String identifier, String nickname) { + return setNickName(get(identifier), nickname); + } + + /** + * Change the nickname of a PRPlayer + * + * @param PRPlayer + * @param nickname + * @return true if player is not null + */ + public boolean setNickName(PRPlayer player, String nickname) { + if (player == null) { + return false; + } + + player.setNickname(nickname); + return true; + } + + /** + * Get the nickname of a PRPlayer + * + * @param UUID + * @return String or null if player is null + */ + public String getNickName(UUID uuid) { + return getNickName(uuid.toString()); + } + + /** + * Get the nickname of a PRPlayer + * + * @param identifier + * @return String or null if player is null + */ + public String getNickName(String identifier) { + return getNickName(get(identifier)); + } + + /** + * Get the nickname of a PRPlayer + * + * @param PRPlayer + * @return String or null if player is null + */ + public String getNickName(PRPlayer player) { + if (player == null) { + return null; + } + + return player.getNickname(); + } + + // ================================================================================ + // || || + // || PLAYTIME || + // || || + // ================================================================================ + + /** + * Change the playtime of a PRPlayer + * + * @param UUID + * @param playtime + * @return true if player is not null + */ + public boolean setPlaytime(UUID uuid, long playtime) { + return setPlaytime(uuid.toString(), playtime); + } + + /** + * Change the playtime of a PRPlayer + * + * @param identifier + * @param playtime + * @return true if player is not null + */ + public boolean setPlaytime(String identifier, long playtime) { + return setPlaytime(get(identifier), playtime); + } + + /** + * Change the playtime of a PRPlayer + * + * @param PRPlayer + * @param playtime + * @return true if player is not null + */ + public boolean setPlaytime(PRPlayer player, long playtime) { + if (player == null) { + return false; + } + + player.setPlaytime(playtime); + return true; + } + + /** + * Get the playtime of a PRPlayer + * + * @param UUID + * @return long or -1 if player is null + */ + public long getPlaytime(UUID uuid) { + return getPlaytime(uuid.toString()); + } + + /** + * Get the playtime of a PRPlayer + * + * @param identifier + * @return long or -1 if player is null + */ + public long getPlaytime(String identifier) { + return getPlaytime(get(identifier)); + } + + /** + * Get the playtime of a PRPlayer + * + * @param PRPlayer + * @return long or -1 if player is null + */ + public long getPlaytime(PRPlayer player) { + if (player == null) { + return -1; + } + + return player.getPlaytime(); + } + + // ================================================================================ + // || || + // || RANKS || + // || || + // ================================================================================ + + /** + * Set the rank of a PRPlayer and remove all previous ranks + * + * @param UUID + * @param rankname + * @return true if player is not null + */ + public boolean setRank(UUID uuid, String rankname) { + return setRank(uuid.toString(), PRCache.getRank(rankname)); + } + + /** + * Set the rank of a PRPlayer and remove all previous ranks + * + * @param identifier + * @param rankname + * @return true if player is not null + */ + public boolean setRank(String identifier, String rankname) { + return setRank(get(identifier), PRCache.getRank(rankname)); + } + + /** + * Set the rank of a PRPlayer and remove all previous ranks + * + * @param UUID + * @param PRRank + * @return true if player is not null + */ + public boolean setRank(UUID uuid, PRRank rank) { + return setRank(uuid.toString(), rank); + } + + /** + * Set the rank of a PRPlayer and remove all previous ranks + * + * @param identifier + * @param PRRank + * @return true if player is not null + */ + public boolean setRank(String identifier, PRRank rank) { + return setRank(get(identifier), rank); + } + + /** + * Set the rank of a PRPlayer and remove all previous ranks + * + * @param PRPlayer + * @param PRRank + * @return true if player is not null + */ + public boolean setRank(PRPlayer player, PRRank rank) { + if (player == null) { + return false; + } + + player.getRanks().clear(); + player.getRanks().add(new PRPlayerRank(rank)); + return true; + } + + /** + * Add a rank to a PRPlayer + * + * @param UUID + * @param rankname + * @return true if the rank was added to the player, false if the rank already exists or player is null + */ + public boolean addRank(UUID uuid, String rankname) { + return addRank(uuid.toString(), PRCache.getRank(rankname)); + } + + /** + * Add a rank to a PRPlayer + * + * @param identifier + * @param rankname + * @return true if the rank was added to the player, false if the rank already exists or player is null + */ + public boolean addRank(String identifier, String rankname) { + return addRank(get(identifier), PRCache.getRank(rankname)); + } + + /** + * Add a rank to a PRPlayer + * + * @param UUID + * @param PRRank + * @return true if the rank was added to the player, false if the rank already exists or player is null + */ + public boolean addRank(UUID uuid, PRRank rank) { + return addRank(uuid.toString(), rank); + } + + /** + * Add a rank to a PRPlayer + * + * @param identifier + * @param PRRank + * @return true if the rank was added to the player, false if the rank already exists or player is null + */ + public boolean addRank(String identifier, PRRank rank) { + return addRank(get(identifier), rank); + } + + /** + * Add a rank to a PRPlayer + * + * @param PRPlayer + * @param PRRank + * @return true if the rank was added to the player, false if the rank already exists or player is null + */ + public boolean addRank(PRPlayer player, PRRank rank) { + if (player == null) { + return false; + } + + for (PRPlayerRank prPlayerRank : player.getRanks()) { + if (prPlayerRank.getName().equalsIgnoreCase(rank.getName())) { + return false; + } + } + + player.getRanks().add(new PRPlayerRank(rank)); + return true; + } + + /** + * Get all ranks of a PRPlayer + * + * @param UUID + * @return Set or null if player is null + */ + public Set getRanks(UUID uuid) { + return getRanks(uuid.toString()); + } + + /** + * Get all ranks of a PRPlayer + * + * @param identifier + * @return Set or null if player is null + */ + public Set getRanks(String identifier) { + return getRanks(get(identifier)); + } + + /** + * Get all ranks of a PRPlayer + * + * @param PRPlayer + * @return Set or null if player is null + */ + public Set getRanks(PRPlayer player) { + if (player == null) { + return null; + } + + return player.getRanks(); + } + + /** + * Remove a rank from a PRPlayer + * + * @param UUID + * @param rankname + * @return true if the rank was removed from the player, false if the rank was not found or player is null + */ + public boolean removeRank(UUID uuid, String rankname) { + return removeRank(uuid.toString(), PRCache.getRank(rankname)); + } + + /** + * Remove a rank from a PRPlayer + * + * @param identifier + * @param rankname + * @return true if the rank was removed from the player, false if the rank was not found or player is null + */ + public boolean removeRank(String identifier, String rankname) { + return removeRank(get(identifier), PRCache.getRank(rankname)); + } + + /** + * Remove a rank from a PRPlayer + * + * @param UUID + * @param PRRank + * @return true if the rank was removed from the player, false if the rank was not found or player is null + */ + public boolean removeRank(UUID uuid, PRRank rank) { + return removeRank(uuid.toString(), rank); + } + + /** + * Remove a rank from a PRPlayer + * + * @param identifier + * @param PRRank + * @return true if the rank was removed from the player, false if the rank was not found or player is null + */ + public boolean removeRank(String identifier, PRRank rank) { + return removeRank(get(identifier), rank); + } + + /** + * Remove a rank from a PRPlayer + * + * @param PRPlayer + * @param PRRank + * @return true if the rank was removed from the player, false if the rank was not found or player is null + */ + public boolean removeRank(PRPlayer player, PRRank rank) { + if (player == null) { + return false; + } + + for (PRPlayerRank prPlayerRank : player.getRanks()) { + if (prPlayerRank.getName().equalsIgnoreCase(rank.getName())) { + player.getRanks().remove(prPlayerRank); + return true; + } + } + + return false; + } + + /** + * Check if a PRPlayer has a rank + * + * @param UUID + * @param rankname + * @return true if the player has the rank, false if the player does not have the rank or player is null + */ + public boolean hasRank(UUID uuid, String rankname) { + return hasRank(uuid.toString(), PRCache.getRank(rankname)); + } + + /** + * Check if a PRPlayer has a rank + * + * @param identifier + * @param rankname + * @return true if the player has the rank, false if the player does not have the rank or player is null + */ + public boolean hasRank(String identifier, String rankname) { + return hasRank(get(identifier), PRCache.getRank(rankname)); + } + + /** + * Check if a PRPlayer has a rank + * + * @param UUID + * @param PRRank + * @return true if the player has the rank, false if the player does not have the rank or player is null + */ + public boolean hasRank(UUID uuid, PRRank rank) { + return hasRank(uuid.toString(), rank); + } + + /** + * Check if a PRPlayer has a rank + * + * @param identifier + * @param PRRank + * @return true if the player has the rank, false if the player does not have the rank or player is null + */ + public boolean hasRank(String identifier, PRRank rank) { + return hasRank(get(identifier), rank); + } + + /** + * Check if a PRPlayer has a rank + * + * @param PRPlayer + * @param PRRank + * @return true if the player has the rank, false if the player does not have the rank or player is null + */ + public boolean hasRank(PRPlayer player, PRRank rank) { + if (player == null) { + return false; + } + + for (PRPlayerRank prPlayerRank : player.getRanks()) { + if (prPlayerRank.getName().equalsIgnoreCase(rank.getName())) { + return true; + } + } + + return false; + } + + // ================================================================================ + // || || + // || PERMISSIONS || + // || || + // ================================================================================ + + /** + * Add a permission to a PRPlayer + * + * @param UUID + * @param permissionNode + * @param isAllowed + * @return true if the permission was added, false if the permission already exists or player is null + */ + public boolean addPermission(UUID uuid, String permissionNode, boolean isAllowed) { + return addPermission(uuid.toString(), permissionNode, isAllowed); + } + + /** + * Add a permission to a PRPlayer + * + * @param identifier + * @param permissionNode + * @param isAllowed + * @return true if the permission was added, false if the permission already exists or player is null + */ + public boolean addPermission(String identifier, String permissionNode, boolean isAllowed) { + return addPermission(get(identifier), permissionNode, isAllowed); + } + + /** + * Add a permission to a PRPlayer + * + * @param PRPlayer + * @param permissionNode + * @param isAllowed + * @return true if the permission was added, false if the permission already exists or player is null + */ + public boolean addPermission(PRPlayer player, String permissionNode, boolean isAllowed) { + return addPermission(player, new PRPermission(permissionNode, isAllowed)); + } + + /** + * Add a permission to a PRPlayer + * + * @param UUID + * @param PRPermission + * @return true if the permission was added, false if the permission already exists or player is null + */ + public boolean addPermission(UUID uuid, PRPermission permission) { + return addPermission(uuid.toString(), permission); + } + + /** + * Add a permission to a PRPlayer + * + * @param identifier + * @param PRPermission + * @return true if the permission was added, false if the permission already exists or player is null + */ + public boolean addPermission(String identifier, PRPermission permission) { + return addPermission(get(identifier), permission); + } + + /** + * Add a permission to a PRPlayer + * + * @param PRPlayer + * @param PRPermission + * @return true if the permission was added, false if the permission already exists or player is null + */ + public boolean addPermission(PRPlayer player, PRPermission permission) { + if (player == null) { + return false; + } + + for (PRPermission prPermission : player.getPermissions()) { + if (prPermission.getName().equalsIgnoreCase(permission.getName())) { + return false; + } + } + + player.getPermissions().add(permission); + return true; + } + + /** + * Remove a permission from a PRPlayer + * + * @param UUID + * @param permissionNode + * @return true if the permission was removed from the player, false if the permission was not found or player is null + */ + public boolean removePermission(UUID uuid, String permissionNode) { + return removePermission(uuid.toString(), permissionNode); + } + + /** + * Remove a permission from a PRPlayer + * + * @param identifier + * @param permissionNode + * @return true if the permission was removed from the player, false if the permission was not found or player is null + */ + public boolean removePermission(String identifier, String permissionNode) { + return removePermission(get(identifier), permissionNode); + } + + /** + * Remove a permission from a PRPlayer + * + * @param PRPlayer + * @param permissionNode + * @return true if the permission was removed from the player, false if the permission was not found or player is null + */ + public boolean removePermission(PRPlayer player, String permissionNode) { + return removePermission(player, new PRPermission(permissionNode, false)); + } + + /** + * Remove a permission from a PRPlayer + * + * @param UUID + * @param PRPermission + * @return true if the permission was removed from the player, false if the permission was not found or player is null + */ + public boolean removePermission(UUID uuid, PRPermission permission) { + return removePermission(uuid.toString(), permission); + } + + /** + * Remove a permission from a PRPlayer + * + * @param identifier + * @param PRPermission + * @return true if the permission was removed from the player, false if the permission was not found or player is null + */ + public boolean removePermission(String identifier, PRPermission permission) { + return removePermission(get(identifier), permission); + } + + /** + * Remove a permission from a PRPlayer + * + * @param PRPlayer + * @param PRPermission + * @return true if the permission was removed from the player, false if the permission was not found or player is null + */ + public boolean removePermission(PRPlayer player, PRPermission permission) { + if (player == null) { + return false; + } + + for (PRPermission prPermission : player.getPermissions()) { + if (prPermission.getName().equalsIgnoreCase(permission.getName())) { + player.getPermissions().remove(prPermission); + return true; + } + } + + return false; + } + + /** + * Check if a PRPlayer has a permission + * + * @param UUID + * @param permissionNode + * @return true if player has the permission, false if player does not have the permission or player is null + */ + public boolean hasPermission(UUID uuid, String permissionNode) { + return hasPermission(uuid.toString(), permissionNode); + } + + /** + * Check if a PRPlayer has a permission + * + * @param identifier + * @param permissionNode + * @return true if player has the permission, false if player does not have the permission or player is null + */ + public boolean hasPermission(String identifier, String permissionNode) { + return hasPermission(get(identifier), permissionNode); + } + + /** + * Check if a PRPlayer has a permission + * + * @param PRPlayer + * @param permissionNode + * @return true if player has the permission, false if player does not have the permission or player is null + */ + public boolean hasPermission(PRPlayer player, String permissionNode) { + if (player == null) { + return false; + } + + for (PRPermission prPermission : player.getPermissions()) { + if (prPermission.getName().equals(permissionNode)) { + return true; + } + } + + return false; + } + + /** + * Check if a PRPlayer's permission is allowed + * + * @param UUID + * @param PRPermission + * @return true if permission is allowed, false if permission is not allowed or not found + */ + public boolean isPermissionAllowed(UUID uuid, String permissionNode) { + return isPermissionAllowed(uuid.toString(), permissionNode); + } + + /** + * Check if a PRPlayer's permission is allowed + * + * @param identifier + * @param PRPermission + * @return true if permission is allowed, false if permission is not allowed or not found + */ + public boolean isPermissionAllowed(String identifier, String permissionNode) { + return isPermissionAllowed(get(identifier), permissionNode); + } + + /** + * Check if a PRPlayer's permission is allowed + * + * @param PRPlayer + * @param PRPermission + * @return true if permission is allowed, false if permission is not allowed or not found + */ + public boolean isPermissionAllowed(PRPlayer player, String permissionNode) { + if (player == null) { + return false; + } + + for (PRPermission prPermission : player.getPermissions()) { + if (prPermission.getName().equals(permissionNode)) { + return prPermission.getValue(); + } + } + + return false; + } + + /** + * Set a PRPlayer's permission to allowed + * + * @param UUID + * @param permissionNode + * @return true if permission was set to allowed, false if permission was not found or player is null + */ + public boolean setPermissionAllowed(UUID uuid, String permissionNode) { + return setPermissionAllowed(uuid.toString(), permissionNode); + } + + /** + * Set a PRPlayer's permission to allowed + * + * @param identifier + * @param permissionNode + * @return true if permission was set to allowed, false if permission was not found or player is null + */ + public boolean setPermissionAllowed(String identifier, String permissionNode) { + return setPermissionAllowed(get(identifier), permissionNode); + } + + /** + * Set a PRPlayer's permission to allowed + * + * @param PRPlayer + * @param permissionNode + * @return true if permission was set to allowed, false if permission was not found or player is null + */ + public boolean setPermissionAllowed(PRPlayer player, String permissionNode) { + if (player == null) { + return false; + } + + for (PRPermission prPermission : player.getPermissions()) { + if (prPermission.getName().equals(permissionNode)) { + prPermission.setValue(true); + return true; + } + } + + return false; + } + + /** + * Set a PRPlayer's permission to disallowed + * + * @param UUID + * @param PRPermission + * @return true if permission was set to disallowed, false if permission was not found or player is null + */ + public boolean setPermissionDisallowed(UUID uuid, String permissionNode) { + return setPermissionDisallowed(uuid.toString(), permissionNode); + } + + /** + * Set a PRPlayer's permission to disallowed + * + * @param identifier + * @param PRPermission + * @return true if permission was set to disallowed, false if permission was not found or player is null + */ + public boolean setPermissionDisallowed(String identifier, String permissionNode) { + return setPermissionDisallowed(get(identifier), permissionNode); + } + + /** + * Set a PRPlayer's permission to disallowed + * + * @param PRPlayer + * @param PRPermission + * @return true if permission was set to disallowed, false if permission was not found or player is null + */ + public boolean setPermissionDisallowed(PRPlayer player, String permissionNode) { + if (player == null) { + return false; + } + + for (PRPermission prPermission : player.getPermissions()) { + if (prPermission.getName().equals(permissionNode)) { + prPermission.setValue(false); + return true; + } + } + + return false; + } + + /** + * Get all permissions of a PRPlayer + * + * @param UUID + * @return Set or null if player is null + */ + public Set getPermissions(UUID uuid) { + return getPermissions(uuid.toString()); + } + + /** + * Get all permissions of a PRPlayer + * + * @param identifier + * @return Set or null if player is null + */ + public Set getPermissions(String identifier) { + return getPermissions(get(identifier)); + } + + /** + * Get all permissions of a PRPlayer + * + * @param PRPlayer + * @return Set or null if player is null + */ + public Set getPermissions(PRPlayer player) { + if (player == null) { + return null; + } + + return player.getPermissions(); + } + + // ================================================================================ + // || || + // || USERTAGS || + // || || + // ================================================================================ + + /** + * Add a usertag to a PRPlayer + * + * @param UUID + * @param usertag + * @return true if the usertag was added, false if the usertag already exists or player is null + */ + public boolean addUsertag(UUID uuid, String usertag) { + return addUsertag(uuid.toString(), usertag); + } + + /** + * Add a usertag to a PRPlayer + * + * @param identifier + * @param usertag + * @return true if the usertag was added, false if the usertag already exists or player is null + */ + public boolean addUsertag(String identifier, String usertag) { + return addUsertag(get(identifier), usertag); + } + + /** + * Add a usertag to a PRPlayer + * + * @param PRPlayer + * @param usertag + * @return true if the usertag was added, false if the usertag already exists or player is null + */ + public boolean addUsertag(PRPlayer player, String usertag) { + if (player == null) { + return false; + } + + for (String tag : player.getUsertags()) { + if (tag.equalsIgnoreCase(usertag)) { + return false; + } + } + + player.getUsertags().add(usertag); + return true; + } + + /** + * Remove a usertag from a PRPlayer + * + * @param UUID + * @param usertag + * @return true if the usertag was removed from the player, false if the usertag was not found or player is null + */ + public boolean removeUsertag(UUID uuid, String usertag) { + return removeUsertag(uuid.toString(), usertag); + } + + /** + * Remove a usertag from a PRPlayer + * + * @param identifier + * @param usertag + * @return true if the usertag was removed from the player, false if the usertag was not found or player is null + */ + public boolean removeUsertag(String identifier, String usertag) { + return removeUsertag(get(identifier), usertag); + } + + /** + * Remove a usertag from a PRPlayer + * + * @param PRPlayer + * @param usertag + * @return true if the usertag was removed from the player, false if the usertag was not found or player is null + */ + public boolean removeUsertag(PRPlayer player, String usertag) { + if (player == null) { + return false; + } + + for (String tag : player.getUsertags()) { + if (tag.equalsIgnoreCase(usertag)) { + player.getUsertags().remove(tag); + return true; + } + } + + return false; + } + + /** + * Check if a PRPlayer has a usertag + * + * @param UUID + * @param usertag + * @return true if player has the usertag, false if player does not have the usertag or player is null + */ + public boolean hasUsertag(UUID uuid, String usertag) { + return hasUsertag(uuid.toString(), usertag); + } + + /** + * Check if a PRPlayer has a usertag + * + * @param identifier + * @param usertag + * @return true if player has the usertag, false if player does not have the usertag or player is null + */ + public boolean hasUsertag(String identifier, String usertag) { + return hasUsertag(get(identifier), usertag); + } + + /** + * Check if a PRPlayer has a usertag + * + * @param PRPlayer + * @param usertag + * @return true if player has the usertag, false if player does not have the usertag or player is null + */ + public boolean hasUsertag(PRPlayer player, String usertag) { + if (player == null) { + return false; + } + + for (String tag : player.getUsertags()) { + if (tag.equalsIgnoreCase(usertag)) { + return true; + } + } + + return false; + } + + /** + * Get all usertags of a PRPlayer + * + * @param UUID + * @return Set or null if player is null + */ + public Set getUsertags(UUID uuid) { + return getUsertags(uuid.toString()); + } + + /** + * Get all usertags of a PRPlayer + * + * @param identifier + * @return Set or null if player is null + */ + public Set getUsertags(String identifier) { + return getUsertags(get(identifier)); + } + + /** + * Get all usertags of a PRPlayer + * + * @param PRPlayer + * @return Set or null if player is null + */ + public Set getUsertags(PRPlayer player) { + if (player == null) { + return null; + } + + return player.getUsertags(); + } +} diff --git a/API/src/main/java/nl/svenar/powerranks/api/PowerRanksAPI.java b/API/src/main/java/nl/svenar/powerranks/api/PowerRanksAPI.java new file mode 100644 index 00000000..b5858192 --- /dev/null +++ b/API/src/main/java/nl/svenar/powerranks/api/PowerRanksAPI.java @@ -0,0 +1,45 @@ +package nl.svenar.powerranks.api; + +public class PowerRanksAPI { + + private final String API_VERSION = "2.0"; + + private RanksAPI ranksAPI; + private PlayersAPI playersAPI; + + /** + * Initialize the API + */ + public PowerRanksAPI() { + ranksAPI = new RanksAPI(); + playersAPI = new PlayersAPI(); + } + + /** + * Get the api version + * + * @return String + */ + public String getApiVersion() { + return API_VERSION; + } + + /** + * Get the RanksAPI + * + * @return RanksAPI + */ + public RanksAPI getRanksAPI() { + return ranksAPI; + } + + /** + * Get the PlayersAPI + * + * @return PlayersAPI + */ + public PlayersAPI getPlayersAPI() { + return playersAPI; + } + +} \ No newline at end of file diff --git a/API/src/main/java/nl/svenar/powerranks/api/RanksAPI.java b/API/src/main/java/nl/svenar/powerranks/api/RanksAPI.java new file mode 100644 index 00000000..0239236b --- /dev/null +++ b/API/src/main/java/nl/svenar/powerranks/api/RanksAPI.java @@ -0,0 +1,914 @@ +package nl.svenar.powerranks.api; + +import java.util.ArrayList; +import java.util.List; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; + +public class RanksAPI { + + /** + * Create a new rank + * + * @param name + * @return PRRank or null if the rank already exists + */ + public PRRank create(String name) { + return PRCache.createRank(name); + } + + /** + * Get a rank by name + * + * @param name + * @return PRRank or null if the rank does not exists + */ + public PRRank get(String name) { + return PRCache.getRank(name); + } + + /** + * Get all ranks + * + * @return List + */ + public List getRanks() { + return PRCache.getRanks(); + } + + /** + * Delete a rank by name + * + * @param name + * @return true if the rank was deleted, false if the rank does not exists + */ + public boolean delete(String name) { + try { + PRRank rank = get(name); + PRCache.removeRank(rank); + return true; + } catch (NullPointerException e) { + return false; + } + } + + /** + * Check if a rank exists + * + * @param name + * @return true if the rank exists, false if the rank does not exists + */ + public boolean exists(String name) { + return get(name) != null; + } + + /** + * Rename a rank + * + * @param oldname + * @param newname + * @return true if the rank was renamed, false if the rank does not exists or the new name already exists + */ + public boolean rename(String oldname, String newname) { + if (!exists(oldname) || exists(newname)) { + return false; + } + + PRRank rank = get(oldname); + rank.setName(newname); + + return true; + } + + /** + * Set the prefix of a rank + * @param name + * @param prefix + * @return true if the prefix was set, false if the rank does not exists + */ + public boolean setPrefix(String name, String prefix) { + return setPrefix(get(name), prefix); + } + + /** + * Set the prefix of a rank + * @param rank + * @param prefix + * @return true if the prefix was set, false if the rank does not exists + */ + public boolean setPrefix(PRRank rank, String prefix) { + if (rank == null) { + return false; + } + + rank.setPrefix(prefix); + + return true; + } + + /** + * Get the prefix of a rank + * @param name + * @return String or null if the rank does not exists + */ + public String getPrefix(String name) { + return getPrefix(get(name)); + } + + /** + * Get the prefix of a rank + * @param rank + * @return String or null if the rank does not exists + */ + public String getPrefix(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getPrefix(); + } + + /** + * Set the suffix of a rank + * @param name + * @param suffix + * @return true if the suffix was set, false if the rank does not exists + */ + public boolean setSuffix(String name, String suffix) { + return setSuffix(get(name), suffix); + } + + /** + * Set the suffix of a rank + * @param rank + * @param suffix + * @return true if the suffix was set, false if the rank does not exists + */ + public boolean setSuffix(PRRank rank, String suffix) { + if (rank == null) { + return false; + } + + rank.setSuffix(suffix); + + return true; + } + + /** + * Get the suffix of a rank + * @param name + * @return String or null if the rank does not exists + */ + public String getSuffix(String name) { + return getSuffix(get(name)); + } + + /** + * Get the suffix of a rank + * @param rank + * @return String or null if the rank does not exists + */ + public String getSuffix(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getSuffix(); + } + + /** + * Set the weight of a rank + * @param name + * @param weight + * @return true if the weight was set, false if the rank does not exists + */ + public boolean setWeight(String name, int weight) { + return setWeight(get(name), weight); + } + + /** + * Set the weight of a rank + * @param rank + * @param weight + * @return true if the weight was set, false if the rank does not exists + */ + public boolean setWeight(PRRank rank, int weight) { + if (rank == null) { + return false; + } + + rank.setWeight(weight); + + return true; + } + + /** + * Get the weight of a rank + * @param name + * @return int or -1 if the rank does not exists + */ + public int getWeight(String name) { + return getWeight(get(name)); + } + + /** + * Get the weight of a rank + * @param rank + * @return int or -1 if the rank does not exists + */ + public int getWeight(PRRank rank) { + if (rank == null) { + return -1; + } + + return rank.getWeight(); + } + + /** + * Set the default state of a rank + * @param name + * @param isDefault + * @return true if the default state was set, false if the rank does not exists + */ + public boolean setDefault(String name, boolean isDefault) { + return setDefault(get(name), isDefault); + } + + /** + * Set the default state of a rank + * @param rank + * @param isDefault + * @return true if the default state was set, false if the rank does not exists + */ + public boolean setDefault(PRRank rank, boolean isDefault) { + if (rank == null) { + return false; + } + + rank.setDefault(isDefault); + + return true; + } + + /** + * Get the default state of a rank + * @param name + * @return boolean or false if the rank does not exists + */ + public boolean isDefault(String name) { + return isDefault(get(name)); + } + + /** + * Get the default state of a rank + * @param rank + * @return boolean or false if the rank does not exists + */ + public boolean isDefault(PRRank rank) { + if (rank == null) { + return false; + } + + return rank.isDefault(); + } + + /** + * Set the name color for a player of a rank + * @param name + * @param isDefault + * @return true if the default state was set, false if the rank does not exists + */ + public boolean setNameColor(String name, String nameColor) { + return setNameColor(get(name), nameColor); + } + + /** + * Set the name color for a player of a rank + * @param rank + * @param isDefault + * @return true if the default state was set, false if the rank does not exists + */ + public boolean setNameColor(PRRank rank, String nameColor) { + if (rank == null) { + return false; + } + + rank.setNamecolor(nameColor); + + return true; + } + + /** + * Get the name color for a player of a rank + * @param name + * @return String or null if the rank does not exists + */ + public String getNameColor(String name) { + return getNameColor(get(name)); + } + + /** + * Get the name color for a player of a rank + * @param rank + * @return String or null if the rank does not exists + */ + public String getNameColor(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getNamecolor(); + } + + /** + * Set the chat color for a player of a rank + * @param name + * @param isDefault + * @return true if the default state was set, false if the rank does not exists + */ + public boolean setChatColor(String name, String chatColor) { + return setChatColor(get(name), chatColor); + } + + /** + * Set the chat color for a player of a rank + * @param rank + * @param isDefault + * @return true if the default state was set, false if the rank does not exists + */ + public boolean setChatColor(PRRank rank, String chatColor) { + if (rank == null) { + return false; + } + + rank.setChatcolor(chatColor); + + return true; + } + + /** + * Get the chat color for a player of a rank + * @param name + * @return String or null if the rank does not exists + */ + public String getChatColor(String name) { + return getChatColor(get(name)); + } + + /** + * Get the chat color for a player of a rank + * @param rank + * @return String or null if the rank does not exists + */ + public String getChatColor(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getChatcolor(); + } + + /** + * Add a rank as inheritance to a rank + * @param name + * @param inherit + * @return true if the inheritance was added, false if the rank does not exists or the inheritance already exists + */ + public boolean addInheritance(String name, String inherit) { + return addInheritance(get(name), get(inherit)); + } + + /** + * Add a rank as inheritance to a rank + * @param PRRank + * @param inherit + * @return + */ + public boolean addInheritance(PRRank rank, String inherit) { + return addInheritance(rank, get(inherit)); + } + + /** + * Add a rank as inheritance to a rank + * @param rank + * @param inheritRank + * @return + */ + public boolean addInheritance(String name, PRRank inheritRank) { + return addInheritance(get(name), inheritRank); + } + + /** + * Add a rank as inheritance to a rank + * @param PRRank + * @param PRRank + * @return true if the inheritance was added, false if the rank does not exists or the inheritance already exists + */ + public boolean addInheritance(PRRank rank, PRRank inheritRank) { + if (rank == null || inheritRank == null) { + return false; + } + + for (String inheritance : rank.getInheritances()) { + if (inheritance.equalsIgnoreCase(inheritRank.getName())) { + return false; + } + } + + rank.getInheritances().add(inheritRank.getName()); + + return true; + } + + /** + * Remove a rank as inheritance from a rank + * @param name + * @param inherit + * @return true if the inheritance was removed, false if the rank does not exists or the inheritance does not exists + */ + public boolean removeInheritance(String name, String inherit) { + return removeInheritance(get(name), get(inherit)); + } + + /** + * Remove a rank as inheritance from a rank + * @param PRRank + * @param inherit + * @return true if the inheritance was removed, false if the rank does not exists or the inheritance does not exists + */ + public boolean removeInheritance(PRRank rank, String inherit) { + return removeInheritance(rank, get(inherit)); + } + + /** + * Remove a rank as inheritance from a rank + * @param name + * @param inheritRank + * @return true if the inheritance was removed, false if the rank does not exists or the inheritance does not exists + */ + public boolean removeInheritance(String name, PRRank inheritRank) { + return removeInheritance(get(name), inheritRank); + } + + /** + * Remove a rank as inheritance from a rank + * @param PRRank + * @param PRRank + * @return true if the inheritance was removed, false if the rank does not exists or the inheritance does not exists + */ + public boolean removeInheritance(PRRank rank, PRRank inheritRank) { + if (rank == null) { + return false; + } + + boolean found = false; + for (String inheritance : rank.getInheritances()) { + if (inheritance.equalsIgnoreCase(inheritRank.getName())) { + found = true; + break; + } + } + + if (!found) { + return false; + } + + rank.getInheritances().remove(inheritRank.getName()); + + return true; + } + + /** + * Get all inheritances of a rank + * @param name + * @return List or null if the rank does not exists + */ + public List getInheritances(String name) { + return getInheritances(get(name)); + } + + /** + * Get all inheritances of a rank + * @param rank + * @return List or null if the rank does not exists + */ + public List getInheritances(PRRank rank) { + if (rank == null) { + return null; + } + + List inheritances = new ArrayList(); + for (String inherit : rank.getInheritances()) { + PRRank prRank = get(inherit); + if (prRank != null) { + inheritances.add(prRank); + } + } + + return inheritances; + } + + /** + * Add a permission to a rank + * @param name + * @param permissionNode + * @param allowed + * @return true if the permission was added, false if the rank does not exists or the permission already exists + */ + public boolean addPermission(String name, String permissionNode, boolean allowed) { + return addPermission(get(name), new PRPermission(permissionNode, allowed)); + } + + /** + * Add a permission to a rank + * @param rank + * @param permissionNode + * @param allowed + * @return true if the permission was added, false if the rank does not exists or the permission already exists + */ + public boolean addPermission(PRRank rank, String permissionNode, boolean allowed) { + return addPermission(rank, new PRPermission(permissionNode, allowed)); + } + + /** + * Add a permission to a rank + * @param name + * @param permission + * @return true if the permission was added, false if the rank does not exists or the permission already exists + */ + public boolean addPermission(String name, PRPermission permission) { + return addPermission(get(name), permission); + } + + /** + * Add a permission to a rank + * @param rank + * @param permission + * @return true if the permission was added, false if the rank does not exists or the permission already exists + */ + public boolean addPermission(PRRank rank, PRPermission permission) { + if (rank == null) { + return false; + } + + for (PRPermission prPermission : rank.getPermissions()) { + if (prPermission.getName().equals(permission.getName())) { + return false; + } + } + + rank.getPermissions().add(permission); + + return true; + } + + /** + * Remove a permission from a rank + * @param name + * @param permissionNode + * @return true if the permission was removed, false if the rank does not exists or the permission does not exists + */ + public boolean removePermission(String name, String permission) { + return removePermission(get(name), permission); + } + + /** + * Remove a permission from a rank + * @param rank + * @param permissionNode + * @return true if the permission was removed, false if the rank does not exists or the permission does not exists + */ + public boolean removePermission(PRRank rank, String permission) { + if (rank == null) { + return false; + } + + PRPermission foundPermission = null; + for (PRPermission prPermission : rank.getPermissions()) { + if (prPermission.getName().equals(permission)) { + foundPermission = prPermission; + break; + } + } + + if (foundPermission == null) { + return false; + } + + rank.getPermissions().remove(foundPermission); + + return true; + } + + /** + * Get all permissions of a rank + * @param name + * @return List or null if the rank does not exists + */ + public List getPermissions(String name) { + return getPermissions(get(name)); + } + + /** + * Get all permissions of a rank + * @param rank + * @return List or null if the rank does not exists + */ + public List getPermissions(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getPermissions(); + } + + /** + * Add a rank to a rank as buyable + * @param name + * @param buyableRankName + * @return true if the buyable rank was added, false if the rank does not exists or the buyable rank already exists + */ + public boolean addBuyableRank(String name, String buyableRankName) { + return addBuyableRank(get(name), get(buyableRankName)); + } + + /** + * Add a rank to a rank as buyable + * @param name + * @param buyableRankName + * @return true if the buyable rank was added, false if the rank does not exists or the buyable rank already exists + */ + public boolean addBuyableRank(PRRank rank, String buyableRankName) { + return addBuyableRank(rank, get(buyableRankName)); + } + + /** + * Add a rank to a rank as buyable + * @param name + * @param buyableRank + * @return true if the buyable rank was added, false if the rank does not exists or the buyable rank already exists + */ + public boolean addBuyableRank(String name, PRRank buyableRank) { + return addBuyableRank(get(name), buyableRank); + } + + /** + * Add a rank to a rank as buyable + * @param rank + * @param buyableRank + * @return true if the buyable rank was added, false if the rank does not exists or the buyable rank already exists + */ + public boolean addBuyableRank(PRRank rank, PRRank buyableRank) { + if (rank == null) { + return false; + } + + for (String prBuyableRank : rank.getBuyableRanks()) { + if (prBuyableRank.equalsIgnoreCase(buyableRank.getName())) { + return false; + } + } + + rank.getBuyableRanks().add(buyableRank.getName()); + + return true; + } + + /** + * Remove a rank from a rank as buyable + * @param name + * @param buyableRankName + * @return true if the buyable rank was removed, false if the rank does not exists or the buyable rank does not exists + */ + public boolean removeBuyableRank(String name, String buyableRankName) { + return removeBuyableRank(get(name), get(buyableRankName)); + } + + /** + * Remove a rank from a rank as buyable + * @param name + * @param buyableRankName + * @return true if the buyable rank was removed, false if the rank does not exists or the buyable rank does not exists + */ + public boolean removeBuyableRank(PRRank rank, String buyableRankName) { + return removeBuyableRank(rank, get(buyableRankName)); + } + + /** + * Remove a rank from a rank as buyable + * @param name + * @param buyableRank + * @return true if the buyable rank was removed, false if the rank does not exists or the buyable rank does not exists + */ + public boolean removeBuyableRank(String name, PRRank buyableRank) { + return removeBuyableRank(get(name), buyableRank); + } + + /** + * Remove a rank from a rank as buyable + * @param rank + * @param buyableRank + * @return true if the buyable rank was removed, false if the rank does not exists or the buyable rank does not exists + */ + public boolean removeBuyableRank(PRRank rank, PRRank buyableRank) { + if (rank == null) { + return false; + } + + boolean found = false; + for (String prBuyableRank : rank.getBuyableRanks()) { + if (prBuyableRank.equalsIgnoreCase(buyableRank.getName())) { + found = true; + break; + } + } + + if (!found) { + return false; + } + + rank.getBuyableRanks().remove(buyableRank.getName()); + + return true; + } + + /** + * Get all buyable ranks of a rank + * @param name + * @return List or null if the rank does not exists + */ + public List getBuyableRanks(String name) { + return getBuyableRanks(get(name)); + } + + /** + * Get all buyable ranks of a rank + * @param rank + * @return List or null if the rank does not exists + */ + public List getBuyableRanks(PRRank rank) { + if (rank == null) { + return null; + } + + List buyableRanks = new ArrayList(); + for (String buyableRank : rank.getBuyableRanks()) { + PRRank prRank = get(buyableRank); + if (prRank != null) { + buyableRanks.add(prRank); + } + } + + return buyableRanks; + } + + /** + * Set the buy cost of a rank + * @param name + * @param cost + * @return true if the buy cost was set, false if the rank does not exists + */ + public boolean setBuyCost(String name, float cost) { + return setBuyCost(get(name), cost); + } + + /** + * Set the buy cost of a rank + * @param rank + * @param cost + * @return true if the buy cost was set, false if the rank does not exists + */ + public boolean setBuyCost(PRRank rank, float cost) { + if (rank == null) { + return false; + } + + rank.setBuyCost(cost); + + return true; + } + + /** + * Get the buy cost of a rank + * @param name + * @return float or -1 if the rank does not exists + */ + public float getBuyCost(String name) { + return getBuyCost(get(name)); + } + + /** + * Get the buy cost of a rank + * @param rank + * @return float or -1 if the rank does not exists + */ + public float getBuyCost(PRRank rank) { + if (rank == null) { + return -1; + } + + return rank.getBuyCost(); + } + + /** + * Set the buy description of a rank + * @param name + * @param description + * @return true if the buy description was set, false if the rank does not exists + */ + public boolean setBuyDescription(String name, String description) { + return setBuyDescription(get(name), description); + } + + /** + * Set the buy description of a rank + * @param rank + * @param description + * @return true if the buy description was set, false if the rank does not exists + */ + public boolean setBuyDescription(PRRank rank, String description) { + if (rank == null) { + return false; + } + + rank.setBuyDescription(description); + + return true; + } + + /** + * Get the buy description of a rank + * @param name + * @return String or null if the rank does not exists + */ + public String getBuyDescription(String name) { + return getBuyDescription(get(name)); + } + + /** + * Get the buy description of a rank + * @param rank + * @return String or null if the rank does not exists + */ + public String getBuyDescription(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getBuyDescription(); + } + + /** + * Set the buy command of a rank + * This command will be executed when a player buys the rank + * @param name + * @param command + * @return true if the buy command was set, false if the rank does not exists + */ + public boolean setBuyCommand(String name, String command) { + return setBuyCommand(get(name), command); + } + + /** + * Set the buy command of a rank + * This command will be executed when a player buys the rank + * @param rank + * @param command + * @return true if the buy command was set, false if the rank does not exists + */ + public boolean setBuyCommand(PRRank rank, String command) { + if (rank == null) { + return false; + } + + rank.setBuyCommand(command); + + return true; + } + + /** + * Get the buy command of a rank + * This command will be executed when a player buys the rank + * @param name + * @return String or null if the rank does not exists + */ + public String getBuyCommand(String name) { + return getBuyCommand(get(name)); + } + + /** + * Get the buy command of a rank + * This command will be executed when a player buys the rank + * @param rank + * @return String or null if the rank does not exists + */ + public String getBuyCommand(PRRank rank) { + if (rank == null) { + return null; + } + + return rank.getBuyCommand(); + } +} diff --git a/API/src/test/java/nl/svenar/powerranks/test/tests/TestPlayersAPI.java b/API/src/test/java/nl/svenar/powerranks/test/tests/TestPlayersAPI.java new file mode 100644 index 00000000..0633226d --- /dev/null +++ b/API/src/test/java/nl/svenar/powerranks/test/tests/TestPlayersAPI.java @@ -0,0 +1,130 @@ +package nl.svenar.powerranks.test.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.After; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import nl.svenar.powerranks.api.PowerRanksAPI; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.test.util.TestDebugger; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestPlayersAPI { + + private PRRank rank1, rank2; + private PRPlayer player1; + private PowerRanksAPI api; + + @Before + public void setupCache() { + TestDebugger.log(this, "===== Setting up PRCache ====="); + PRCache.reset(); + + rank1 = PRCache.createRank("rank1"); + rank1.setWeight(10); + rank1.setPrefix("prefix1"); + rank1.setSuffix("suffix1"); + + rank2 = PRCache.createRank("rank2"); + rank2.setWeight(20); + rank2.setPrefix("prefix2"); + rank2.setSuffix("suffix2"); + + player1 = PRCache.createPlayer("player1", UUID.randomUUID()); + + api = new PowerRanksAPI(); + } + + @After + public void cleanupCache() { + TestDebugger.log(this, "===== Cleaning up PRCache ====="); + PRCache.reset(); + } + + @Test + public void A_TestRanks() { + TestDebugger.log(this, "[A_TestRanks] Setup..."); + + assertEquals(0, api.getPlayersAPI().getRanks(player1).size()); + + api.getPlayersAPI().addRank(player1, rank1); + api.getPlayersAPI().addRank(player1, rank1); + api.getPlayersAPI().addRank(player1, rank2); + assertEquals(2, api.getPlayersAPI().getRanks(player1).size()); + + api.getPlayersAPI().removeRank(player1, rank1); + api.getPlayersAPI().removeRank(player1, rank1); + assertEquals(1, api.getPlayersAPI().getRanks(player1).size()); + + TestDebugger.log(this, "[A_TestRanks] OK"); + } + + @Test + public void B_TestPermissions() { + TestDebugger.log(this, "[B_TestPermissions] Setup..."); + + assertEquals(0, api.getPlayersAPI().getPermissions(player1).size()); + + api.getPlayersAPI().addPermission(player1, new PRPermission("test.permission.1", true)); + api.getPlayersAPI().addPermission(player1, new PRPermission("test.permission.2", false)); + assertEquals(2, api.getPlayersAPI().getPermissions(player1).size()); + + assertTrue(api.getPlayersAPI().hasPermission(player1, "test.permission.1")); + assertTrue(api.getPlayersAPI().hasPermission(player1, "test.permission.2")); + assertTrue(api.getPlayersAPI().isPermissionAllowed(player1, "test.permission.1")); + assertTrue(!api.getPlayersAPI().isPermissionAllowed(player1, "test.permission.2")); + + api.getPlayersAPI().removePermission(player1, new PRPermission("test.permission.1", true)); + api.getPlayersAPI().removePermission(player1, new PRPermission("test.permission.1", true)); + assertEquals(1, api.getPlayersAPI().getPermissions(player1).size()); + + assertTrue(!api.getPlayersAPI().hasPermission(player1, "test.permission.1")); + assertTrue(api.getPlayersAPI().hasPermission(player1, "test.permission.2")); + assertTrue(!api.getPlayersAPI().isPermissionAllowed(player1, "test.permission.1")); + assertTrue(!api.getPlayersAPI().isPermissionAllowed(player1, "test.permission.2")); + + + TestDebugger.log(this, "[B_TestPermissions] OK"); + } + + @Test + public void C_TestPlaytime() { + TestDebugger.log(this, "[C_TestPlaytime] Setup..."); + + assertEquals(0, api.getPlayersAPI().getPlaytime(player1)); + + api.getPlayersAPI().setPlaytime(player1, 100); + + assertEquals(100, api.getPlayersAPI().getPlaytime(player1)); + + TestDebugger.log(this, "[C_TestPlaytime] OK"); + } + + @Test + public void D_TestUsertags() { + TestDebugger.log(this, "[D_TestUsertags] Setup..."); + + assertEquals(0, api.getPlayersAPI().getUsertags(player1).size()); + + api.getPlayersAPI().addUsertag(player1, "usertag1"); + api.getPlayersAPI().addUsertag(player1, "usertag2"); + assertEquals(2, api.getPlayersAPI().getUsertags(player1).size()); + + api.getPlayersAPI().removeUsertag(player1, "usertag1"); + api.getPlayersAPI().removeUsertag(player1, "usertag1"); + assertEquals(1, api.getPlayersAPI().getUsertags(player1).size()); + + TestDebugger.log(this, "[D_TestUsertags] OK"); + } + +} diff --git a/API/src/test/java/nl/svenar/powerranks/test/tests/TestRanksAPI.java b/API/src/test/java/nl/svenar/powerranks/test/tests/TestRanksAPI.java new file mode 100644 index 00000000..b2f05d14 --- /dev/null +++ b/API/src/test/java/nl/svenar/powerranks/test/tests/TestRanksAPI.java @@ -0,0 +1,145 @@ +package nl.svenar.powerranks.test.tests; + +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import nl.svenar.powerranks.api.PowerRanksAPI; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.test.util.TestDebugger; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestRanksAPI { + + private PRRank rank1, rank2, rank3; + private PowerRanksAPI api; + + @Before + public void setupCache() { + TestDebugger.log(this, "===== Setting up PRCache ====="); + PRCache.reset(); + + rank1 = PRCache.createRank("rank1"); + rank1.setWeight(10); + rank1.setPrefix("prefix1"); + rank1.setSuffix("suffix1"); + + rank2 = PRCache.createRank("rank2"); + rank2.setWeight(20); + rank2.setPrefix("prefix2"); + rank2.setSuffix("suffix2"); + + rank3 = PRCache.createRank("rank3"); + rank3.setWeight(30); + rank3.setPrefix("prefix3"); + rank3.setSuffix("suffix3"); + + api = new PowerRanksAPI(); + } + + @After + public void cleanupCache() { + TestDebugger.log(this, "===== Cleaning up PRCache ====="); + PRCache.reset(); + } + + @Test + public void A_TestGetRank() { + TestDebugger.log(this, "[A_TestGetRank] Setup..."); + + assertEquals(rank1, api.getRanksAPI().get("rank1")); + assertEquals(rank2, api.getRanksAPI().get("rank2")); + assertEquals(rank3, api.getRanksAPI().get("rank3")); + + TestDebugger.log(this, "[A_TestGetRank] OK"); + } + + @Test + public void B_TestPrefix() { + TestDebugger.log(this, "[B_TestPrefix] Setup..."); + + assertEquals(rank1.getPrefix(), api.getRanksAPI().getPrefix(rank1)); + + api.getRanksAPI().setPrefix(rank1, "newprefix1"); + assertEquals("newprefix1", api.getRanksAPI().getPrefix(rank1)); + + TestDebugger.log(this, "[B_TestPrefix] OK"); + } + + @Test + public void C_TestSuffix() { + TestDebugger.log(this, "[C_TestSuffix] Setup..."); + + assertEquals(rank1.getSuffix(), api.getRanksAPI().getSuffix(rank1)); + + api.getRanksAPI().setSuffix(rank1, "newprefix1"); + assertEquals("newprefix1", api.getRanksAPI().getSuffix(rank1)); + + TestDebugger.log(this, "[C_TestSuffix] OK"); + } + + @Test + public void D_TestPermissions() { + TestDebugger.log(this, "[D_TestPermissions] Setup..."); + + assertEquals(0, api.getRanksAPI().getPermissions(rank1).size()); + + PRPermission permission1 = new PRPermission("permission.1", true); + PRPermission permission2 = new PRPermission("permission.2", false); + api.getRanksAPI().addPermission(rank1, permission1); + api.getRanksAPI().addPermission(rank1, permission2); + assertEquals(2, api.getRanksAPI().getPermissions(rank1).size()); + + api.getRanksAPI().removePermission(rank1, permission1.getName()); + assertEquals(1, api.getRanksAPI().getPermissions(rank1).size()); + + TestDebugger.log(this, "[D_TestPermissions] OK"); + } + + @Test + public void E_NameColor() { + TestDebugger.log(this, "[E_NameColor] Setup..."); + + assertEquals(rank1.getNamecolor(), api.getRanksAPI().getNameColor(rank1)); + + api.getRanksAPI().setNameColor(rank1, "&a"); + assertEquals("&a", api.getRanksAPI().getNameColor(rank1)); + + TestDebugger.log(this, "[E_NameColor] OK"); + } + + @Test + public void F_ChatColor() { + TestDebugger.log(this, "[F_ChatColor] Setup..."); + + assertEquals(rank1.getNamecolor(), api.getRanksAPI().getChatColor(rank1)); + + api.getRanksAPI().setChatColor(rank1, "&a"); + assertEquals("&a", api.getRanksAPI().getChatColor(rank1)); + + TestDebugger.log(this, "[F_ChatColor] OK"); + } + + @Test + public void G_Inheritances() { + TestDebugger.log(this, "[G_Inheritances] Setup..."); + + assertEquals(0, api.getRanksAPI().getInheritances(rank1).size()); + + api.getRanksAPI().addInheritance(rank1, rank2); + api.getRanksAPI().addInheritance(rank1, rank3); + assertEquals(2, api.getRanksAPI().getInheritances(rank1).size()); + + api.getRanksAPI().removeInheritance(rank1, rank2); + assertEquals(1, api.getRanksAPI().getInheritances(rank1).size()); + + TestDebugger.log(this, "[G_Inheritances] OK"); + + } +} diff --git a/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java b/API/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java similarity index 100% rename from src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java rename to API/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml new file mode 100644 index 00000000..77302cb1 --- /dev/null +++ b/Bukkit/pom.xml @@ -0,0 +1,222 @@ + + 4.0.0 + nl.svenar + powerranks.bukkit + ${revision} + PowerRanks Bukkit + Rank-based permission manager + + + 1.8 + UTF-8 + src/main/java + src/main/resources + nl.svenar.lib + false + + + + nl.svenar + powerranks + ${revision} + + + + clean compile package + ${output.name} + ${src.dir} + + + ${rsc.dir} + true + + + + + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + true + false + false + false + false + + + *:* + + META-INF/license/** + META-INF/* + META-INF/maven/** + META-INF/versions/*/module-info.class + LICENSE + NOTICE + /*.txt + build.properties + com/fasterxml/jackson/databind/ext/Java7* + + + + + + nl.svenar:powerranks.core + nl.svenar:powerranks.api + com.squareup.okhttp3:okhttp + com.squareup.okio:okio + org.jetbrains.kotlin:kotlin-stdlib + org.yaml:snakeyaml + com.fasterxml.jackson.core:jackson-core + com.fasterxml.jackson.core:jackson-databind + com.fasterxml.jackson.core:jackson-annotations + com.fasterxml.jackson.dataformat:jackson-dataformat-yaml + com.googlecode.json-simple:json-simple + com.googlecode.json-simple:json-simple + + + + + okhttp3 + ${shade.basepattern}.okhttp3 + + + okio + ${shade.basepattern}.okio + + + kotlin + ${shade.basepattern}.kotlin + + + org.yaml + ${shade.basepattern}.yaml + + + com.fasterxml + ${shade.basepattern}.fasterxml + + + org.json + ${shade.basepattern}.json + + + target/reduced-pom.xml + + + + package + + shade + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.1 + + ${skipBukkitTests} + + + + + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + placeholderapi + https://repo.extendedclip.com/content/repositories/placeholderapi/ + + + jitpack.io + https://jitpack.io + + + svenar + https://svenar.nl/repo/ + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + + nl.svenar + powerranks.core + ${revision} + + + nl.svenar + powerranks.api + ${revision} + + + + com.github.seeseemelk + MockBukkit-v1.20 + 3.39.0 + test + + + + me.clip.deluxetags + deluxetags + 1.8.2 + provided + + + me.clip + placeholderapi + 2.11.4 + provided + + + com.github.MilkBowl + VaultAPI + 1.7.1 + provided + + + org.bukkit + bukkit + + + + + org.spigotmc + spigot-api + 1.20.2-R0.1-SNAPSHOT + provided + + + com.nametagedit + nametagedit + 4.5.20 + + + \ No newline at end of file diff --git a/src/main/java/nl/svenar/powerranks/PowerRanks.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/PowerRanks.java similarity index 89% rename from src/main/java/nl/svenar/powerranks/PowerRanks.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/PowerRanks.java index 117fc990..750a4b23 100644 --- a/src/main/java/nl/svenar/powerranks/PowerRanks.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/PowerRanks.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks; +package nl.svenar.powerranks.bukkit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -9,11 +9,13 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.Callable; import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.permissions.PermissionAttachmentInfo; import java.io.OutputStream; import java.lang.reflect.Field; @@ -39,48 +41,49 @@ import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitScheduler; -import nl.svenar.common.PowerLogger; -import nl.svenar.common.storage.PowerConfigManager; -import nl.svenar.common.storage.provided.YAMLConfigManager; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.common.utils.PowerColor; -import nl.svenar.powerranks.addons.AddonsManager; +import nl.svenar.powerranks.common.PowerLogger; +import nl.svenar.powerranks.common.storage.PermissionRegistry; +import nl.svenar.powerranks.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.provided.YAMLConfigManager; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.bukkit.addons.AddonsManager; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.cache.LanguageManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommandHandler; +import nl.svenar.powerranks.bukkit.data.BungeecordManager; +import nl.svenar.powerranks.bukkit.data.Messages; +import nl.svenar.powerranks.bukkit.data.PowerPermissibleBase; +import nl.svenar.powerranks.bukkit.data.PowerRanksVerbose; +import nl.svenar.powerranks.bukkit.data.TablistManager; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.events.ChatTabExecutor; +import nl.svenar.powerranks.bukkit.events.OnBlockChange; +import nl.svenar.powerranks.bukkit.events.OnChat; +import nl.svenar.powerranks.bukkit.events.OnInteract; +import nl.svenar.powerranks.bukkit.events.OnInventory; +import nl.svenar.powerranks.bukkit.events.OnJoin; +import nl.svenar.powerranks.bukkit.events.OnMove; +import nl.svenar.powerranks.bukkit.events.OnPreCommand; +import nl.svenar.powerranks.bukkit.events.OnSignChanged; +import nl.svenar.powerranks.bukkit.events.OnWorldChange; +import nl.svenar.powerranks.bukkit.external.DeluxeTagsHook; +import nl.svenar.powerranks.bukkit.external.PowerRanksExpansion; +import nl.svenar.powerranks.bukkit.external.VaultHook; +import nl.svenar.powerranks.bukkit.gui.GUI; +import nl.svenar.powerranks.bukkit.metrics.Metrics; +import nl.svenar.powerranks.bukkit.update.ConfigFilesUpdater; +import nl.svenar.powerranks.bukkit.update.Updater; +import nl.svenar.powerranks.bukkit.update.Updater.UpdateResult; +import nl.svenar.powerranks.bukkit.update.Updater.UpdateType; +import nl.svenar.powerranks.bukkit.util.BukkitPowerColor; +import nl.svenar.powerranks.bukkit.util.Util; + import nl.svenar.powerranks.api.PowerRanksAPI; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.cache.LanguageManager; -import nl.svenar.powerranks.commands.PowerCommandHandler; -import nl.svenar.powerranks.data.BungeecordManager; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.data.PowerPermissibleBase; -import nl.svenar.powerranks.data.PowerRanksVerbose; -import nl.svenar.powerranks.data.TablistManager; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.events.ChatTabExecutor; -import nl.svenar.powerranks.events.OnBlockChange; -import nl.svenar.powerranks.events.OnChat; -import nl.svenar.powerranks.events.OnInteract; -import nl.svenar.powerranks.events.OnInventory; -import nl.svenar.powerranks.events.OnJoin; -import nl.svenar.powerranks.events.OnMove; -import nl.svenar.powerranks.events.OnPreCommand; -import nl.svenar.powerranks.events.OnSignChanged; -import nl.svenar.powerranks.events.OnWorldChange; -import nl.svenar.powerranks.external.DeluxeTagsHook; -import nl.svenar.powerranks.external.PowerRanksExpansion; -import nl.svenar.powerranks.external.TABHook; -import nl.svenar.powerranks.external.VaultHook; -import nl.svenar.powerranks.gui.GUI; -import nl.svenar.powerranks.metrics.Metrics; -import nl.svenar.powerranks.update.ConfigFilesUpdater; -import nl.svenar.powerranks.update.Updater; -import nl.svenar.powerranks.update.Updater.UpdateResult; -import nl.svenar.powerranks.update.Updater.UpdateType; -import nl.svenar.powerranks.util.BukkitPowerColor; -import nl.svenar.powerranks.util.Util; import com.google.common.collect.ImmutableMap; import com.nametagedit.plugin.NametagEdit; @@ -111,6 +114,7 @@ public class PowerRanks extends JavaPlugin implements Listener { private static PowerConfigManager tablistConfigManager; private BungeecordManager bungeecordManager; + private PermissionRegistry permissionRegistry; // Soft Dependencies private VaultHook vaultHook; @@ -119,7 +123,6 @@ public class PowerRanks extends JavaPlugin implements Listener { public static boolean vaultEconomyEnabled = false; public static boolean vaultPermissionsEnabled = false; public static PowerRanksExpansion placeholderapiExpansion; - public static TABHook plugin_hook_tab; public static boolean plugin_hook_deluxetags = false; public static boolean plugin_hook_nametagedit = false; // Soft Dependencies @@ -146,7 +149,6 @@ public void onEnable() { Instant startTime = Instant.now(); PowerRanks.log = this.getLogger(); - PowerRanksAPI.plugin = this; ConfigFilesUpdater.updateOldDataFiles(); @@ -174,7 +176,7 @@ public void onEnable() { new Messages(this); new PowerRanksVerbose(this); - this.createDir(PowerRanks.fileLoc); + PRUtil.createDir(PowerRanks.fileLoc); PowerRanks.log.info("Loading config file"); configManager = new YAMLConfigManager(PowerRanks.fileLoc, "config.yml", "config.yml"); @@ -191,6 +193,11 @@ public void onEnable() { addonsManager = new AddonsManager(this); addonsManager.setup(); + permissionRegistry = new PermissionRegistry(); + for (PermissionAttachmentInfo pai : Bukkit.getConsoleSender().getEffectivePermissions()) { + permissionRegistry.queuePermission(pai.getPermission()); + } + PowerRanks.log.info(""); PowerRanks.log.info("=== ----------- LOADING DATA ----------- ==="); PowerRanks.log.info("Loading player & rank data"); @@ -249,8 +256,12 @@ public void onEnable() { } public void onDisable() { - this.tablistManager.stop(); - this.bungeecordManager.stop(); + if (this.tablistManager != null) { + this.tablistManager.stop(); + } + if (this.bungeecordManager != null) { + this.bungeecordManager.stop(); + } Bukkit.getServer().getScheduler().cancelTasks(this); @@ -439,26 +450,12 @@ public void run() { } }.runTaskTimer(this, update_check_interval, update_check_interval); - // new BukkitRunnable() { - // @Override - // public void run() { - // PowerRanksVerbose.log("task", "Running task check player name change"); - - // for (Player player : Bukkit.getServer().getOnlinePlayers()) { - // if (!playerNameCache.containsKey(player.getUniqueId())) { - // playerNameCache.put(player.getUniqueId(), player.getName()); - // } - - // if (!playerNameCache.get(player.getUniqueId()).equals(player.getName())) { - // log.info("Player name changed from '" + - // playerNameCache.get(player.getUniqueId()) + "' to '" + player.getName() + - // "'"); - // playerNameCache.put(player.getUniqueId(), player.getName()); - // CacheManager.getPlayer(player.getUniqueId().toString()).setName(player.getName()); - // } - // } - // } - // }.runTaskTimer(this, TASK_TPS, TASK_TPS); + new BukkitRunnable() { + @Override + public void run() { + permissionRegistry.tick(); + } + }.runTaskTimer(this, 1, 1); } private Player getPlayerFromUUID(UUID uuid) { @@ -627,7 +624,7 @@ public void run() { prPlayername = Util.getNameFromAPI(prPlayer.getUUID().toString()); } - getServer().getConsoleSender().sendMessage(Util.powerFormatter( + getServer().getConsoleSender().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage("general.player-rank-expired-console"), ImmutableMap.builder() @@ -641,7 +638,7 @@ public void run() { PowerRanks.getInstance().updateTablistName(player); PowerRanks.getInstance().getTablistManager().updateSorting(player); - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage("general.player-rank-has-expired"), ImmutableMap.builder() @@ -669,10 +666,6 @@ public void run() { }.runTaskTimer(this, Util.TASK_TPS, Util.TASK_TPS * 10); } - public TABHook getTABHook() { - return plugin_hook_tab; - } - public DeluxeTagsHook getDeluxeTagsHook() { return this.deluxeTagsHook; } @@ -821,30 +814,13 @@ public boolean configContainsKey(String path) { return configYaml.isSet(path); } - public void createDir(final String path) { - final File file = new File(path); - if (!file.exists()) { - file.mkdirs(); - } - } - - private boolean deleteDir(File directoryToBeDeleted) { - File[] allContents = directoryToBeDeleted.listFiles(); - if (allContents != null) { - for (File file : allContents) { - this.deleteDir(file); - } - } - return directoryToBeDeleted.delete(); - } - public void factoryReset(CommandSender sender) { CacheManager.setRanks(new ArrayList()); CacheManager.setPlayers(new ArrayList()); - this.deleteDir(new File(PowerRanks.fileLoc)); - this.createDir(PowerRanks.fileLoc); + PRUtil.deleteDir(new File(PowerRanks.fileLoc)); + PRUtil.createDir(PowerRanks.fileLoc); configManager = new YAMLConfigManager(PowerRanks.fileLoc, "config.yml", "config.yml"); languageManager = new LanguageManager(); @@ -896,11 +872,15 @@ public void copy(final InputStream in, final File file) { } public void playerInjectPermissible(Player player) { + if (isMockBukkitLoaded()) { + return; + } try { Field f = Util.obcClass("entity.CraftHumanEntity").getDeclaredField("perm"); f.setAccessible(true); f.set(player, new PowerPermissibleBase(player, this)); f.setAccessible(false); + // } catch (ClassNotFoundException e) { } catch (Exception e) { e.printStackTrace(); } @@ -930,7 +910,7 @@ public void run() { prefix_format = prefix.length() == 0 ? prefix_format.replaceAll("\\[prefix\\]( )?", "") : prefix_format; - prefix_format = Util.powerFormatter(prefix_format, + prefix_format = PRUtil.powerFormatter(prefix_format, ImmutableMap.builder() .put("prefix", prefix) .put("usertag", !PowerRanks.plugin_hook_deluxetags ? usertag @@ -940,7 +920,7 @@ public void run() { suffix_format = suffix.length() == 0 ? suffix_format.replaceAll("( )?\\[suffix\\]", "") : suffix_format; - suffix_format = Util.powerFormatter(suffix_format, + suffix_format = PRUtil.powerFormatter(suffix_format, ImmutableMap.builder() .put("suffix", suffix) .put("usertag", @@ -968,14 +948,16 @@ public void run() { } public void updateTablistName(Player player) { - try { - player.updateCommands(); // TODO find a better place for this - } catch (NoSuchMethodError e) { + if (!isMockBukkitLoaded()) { + try { + player.updateCommands(); // TODO find a better place for this + } catch (NoSuchMethodError e) { + } } PRPlayer prPlayer = CacheManager.getPlayer(player); - List playerRanks = prPlayer.getRanks(); + Set playerRanks = prPlayer.getRanks(); List ranks = new ArrayList(); for (PRPlayerRank playerRank : playerRanks) { @@ -1019,7 +1001,7 @@ public void updateTablistName(Player player) { } Map availableUsertags = getUsertagManager().getMap("usertags", new HashMap()); - ArrayList playerUsertags = prPlayer.getUsertags(); + Set playerUsertags = prPlayer.getUsertags(); for (String playerUsertag : playerUsertags) { String value = ""; @@ -1045,6 +1027,11 @@ public void updateTablistName(Player player, String prefix, String suffix, String usertag, String nameColor, boolean updateNTE) { PowerRanksVerbose.log("updateTablistName", "Updating " + player.getName() + "'s tablist format"); + PRPlayer prPlayer = CacheManager.getPlayer(player); + if (prPlayer.getNickname().length() > 0) { + player.setDisplayName(prPlayer.getNickname().length() > 0 ? prPlayer.getNickname() : player.getName()); + } + String player_formatted_name = (nameColor.length() == 0 ? "&r" : "") + applyMultiColorFlow(nameColor, player.getDisplayName()); @@ -1069,7 +1056,7 @@ public void updateTablistName(Player player, String prefix, String suffix, format = tmp_format; } - format = Util.powerFormatter(format, + format = PRUtil.powerFormatter(format, ImmutableMap.builder().put("prefix", prefix).put("suffix", suffix) .put("usertag", usertag) .put("player", player_formatted_name).put("world", player.getWorld().getName()).build(), @@ -1128,10 +1115,6 @@ public static String applyMultiColorFlow(String rawColors, String text) { return output; } - public PowerRanksAPI loadAPI() { - return new PowerRanksAPI(); - } - public void updatePlaytime(Player player, long join_time, long leave_time, boolean write_to_file) { long current_playtime = CacheManager.getPlayer(player.getUniqueId().toString()).getPlaytime(); @@ -1202,6 +1185,10 @@ public static BukkitPowerColor getPowerColor() { return powerColor; } + public static PowerRanksAPI getAPI() { + return new PowerRanksAPI(); + } + public static PowerRanks getInstance() { return instance; } @@ -1209,4 +1196,17 @@ public static PowerRanks getInstance() { public static String getVersion() { return instance.getDescription().getVersion(); } + + private boolean isMockBukkitLoaded() { + try { + Class.forName("be.seeseemelk.mockbukkit.MockBukkit"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + public PermissionRegistry getPermissionRegistry() { + return permissionRegistry; + } } diff --git a/src/main/java/nl/svenar/powerranks/addons/AddonDownloader.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/AddonDownloader.java similarity index 92% rename from src/main/java/nl/svenar/powerranks/addons/AddonDownloader.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/AddonDownloader.java index 6863caab..e1c3e6a6 100644 --- a/src/main/java/nl/svenar/powerranks/addons/AddonDownloader.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/AddonDownloader.java @@ -1,11 +1,11 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import java.util.ArrayList; import java.util.List; import com.google.gson.Gson; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.util.Util; public class AddonDownloader { private String addonsURL = "http://addons.powerranks.nl/addons.json"; diff --git a/src/main/java/nl/svenar/powerranks/addons/AddonsManager.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/AddonsManager.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/addons/AddonsManager.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/AddonsManager.java index 4028f97e..7ea1c280 100644 --- a/src/main/java/nl/svenar/powerranks/addons/AddonsManager.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/AddonsManager.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import java.io.File; import java.lang.reflect.InvocationTargetException; @@ -8,8 +8,8 @@ import java.util.List; import java.util.Map.Entry; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.util.Util; public class AddonsManager { diff --git a/src/main/java/nl/svenar/powerranks/addons/DownloadableAddon.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/DownloadableAddon.java similarity index 93% rename from src/main/java/nl/svenar/powerranks/addons/DownloadableAddon.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/DownloadableAddon.java index 9e68473c..69fb220b 100644 --- a/src/main/java/nl/svenar/powerranks/addons/DownloadableAddon.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/DownloadableAddon.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import java.io.BufferedInputStream; import java.io.File; @@ -8,9 +8,9 @@ import java.net.URLConnection; import java.util.ArrayList; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.AddonDownloader.Addon; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.AddonDownloader.Addon; +import nl.svenar.powerranks.bukkit.util.Util; public class DownloadableAddon { diff --git a/src/main/java/nl/svenar/powerranks/addons/PowerRanksAddon.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksAddon.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/addons/PowerRanksAddon.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksAddon.java index d4efccb4..3f7e4d43 100644 --- a/src/main/java/nl/svenar/powerranks/addons/PowerRanksAddon.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksAddon.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import java.util.ArrayList; import java.util.List; @@ -7,9 +7,9 @@ import org.bukkit.World; import org.bukkit.block.Block; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.events.ChatTabExecutor; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.events.ChatTabExecutor; public abstract class PowerRanksAddon { diff --git a/src/main/java/nl/svenar/powerranks/addons/PowerRanksConfig.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksConfig.java similarity index 98% rename from src/main/java/nl/svenar/powerranks/addons/PowerRanksConfig.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksConfig.java index 6b7bc654..7d239823 100644 --- a/src/main/java/nl/svenar/powerranks/addons/PowerRanksConfig.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksConfig.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import java.io.File; import java.io.IOException; @@ -9,7 +9,7 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public class PowerRanksConfig { diff --git a/src/main/java/nl/svenar/powerranks/addons/PowerRanksFileUtil.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksFileUtil.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/addons/PowerRanksFileUtil.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksFileUtil.java index 629464ef..183f9dfb 100644 --- a/src/main/java/nl/svenar/powerranks/addons/PowerRanksFileUtil.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksFileUtil.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import java.io.File; import java.io.IOException; diff --git a/src/main/java/nl/svenar/powerranks/addons/PowerRanksPlayer.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksPlayer.java similarity index 87% rename from src/main/java/nl/svenar/powerranks/addons/PowerRanksPlayer.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksPlayer.java index 810dd229..4ad3c18b 100644 --- a/src/main/java/nl/svenar/powerranks/addons/PowerRanksPlayer.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/addons/PowerRanksPlayer.java @@ -1,10 +1,9 @@ -package nl.svenar.powerranks.addons; +package nl.svenar.powerranks.bukkit.addons; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.api.PowerRanksAPI; -import nl.svenar.powerranks.data.Users; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.data.Users; public class PowerRanksPlayer { @@ -12,7 +11,6 @@ public class PowerRanksPlayer { private Player player; private Users users; private String name; - private PowerRanksAPI api; public PowerRanksPlayer(PowerRanks powerRanks, Player player) { this.powerRanks = powerRanks; @@ -20,14 +18,12 @@ public PowerRanksPlayer(PowerRanks powerRanks, Player player) { this.users = new Users(this.powerRanks); if (player != null) name = player.getName(); - this.api = new PowerRanksAPI(); } public PowerRanksPlayer(PowerRanks powerRanks, String name) { this.powerRanks = powerRanks; this.name = name; this.users = new Users(this.powerRanks); - this.api = new PowerRanksAPI(); } public PowerRanks getPowerRanks() { @@ -49,10 +45,6 @@ public String getRank() { return users.getPrimaryRank(getPlayer()); } - public PowerRanksAPI getAPI() { - return api; - } - // // Set the users rank // // Arguments: rankname(as registered in powerRanks) // // Returns: boolean (true on success & false on fail) diff --git a/src/main/java/nl/svenar/powerranks/cache/CacheManager.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/cache/CacheManager.java similarity index 87% rename from src/main/java/nl/svenar/powerranks/cache/CacheManager.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/cache/CacheManager.java index 09005337..7ae76e44 100755 --- a/src/main/java/nl/svenar/powerranks/cache/CacheManager.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/cache/CacheManager.java @@ -1,30 +1,31 @@ -package nl.svenar.powerranks.cache; +package nl.svenar.powerranks.bukkit.cache; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.UUID; import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import nl.svenar.common.storage.PowerConfigManager; -import nl.svenar.common.storage.PowerSQLConfiguration; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.storage.provided.JSONStorageManager; -import nl.svenar.common.storage.provided.MySQLStorageManager; -import nl.svenar.common.storage.provided.PSMStorageManager; -import nl.svenar.common.storage.provided.SQLiteStorageManager; -import nl.svenar.common.storage.provided.YAMLStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRCache; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.events.OnJoin; +import nl.svenar.powerranks.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.PowerSQLConfiguration; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.storage.provided.MySQLStorageManager; +import nl.svenar.powerranks.common.storage.provided.PSMStorageManager; +import nl.svenar.powerranks.common.storage.provided.SQLiteStorageManager; +import nl.svenar.powerranks.common.storage.provided.YAMLStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.events.OnJoin; public class CacheManager { @@ -76,7 +77,7 @@ public static PRPlayer createPlayer(Player player) { return PRCache.createPlayer(player.getName(), player.getUniqueId()); } - public static List getDefaultRanks() { + public static Set getDefaultRanks() { return PRCache.getDefaultRanks(); } @@ -96,8 +97,8 @@ public static void load(String dataDirectory) { PowerSQLConfiguration configuration = new PowerSQLConfiguration(pcm.getString("storage.mysql.host", "127.0.0.1"), pcm.getInt("storage.mysql.port", 3306), pcm.getString("storage.mysql.database", "powerranks"), pcm.getString("storage.mysql.username", "username"), pcm.getString("storage.mysql.password", "password"), - pcm.getBool("storage.mysql.ssl", false), "ranks", "players", "messages"); - storageManager = new MySQLStorageManager(configuration, pcm.getBool("storage.mysql.verbose", false)); + pcm.getBool("storage.mysql.ssl", false), "ranks", "players", "messages", pcm.getBool("storage.mysql.verbose", false)); + storageManager = new MySQLStorageManager(configuration); } else { // Default to yaml PowerRanksAddon usedStorageManagerAddon = null; diff --git a/src/main/java/nl/svenar/powerranks/cache/LanguageManager.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/cache/LanguageManager.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/cache/LanguageManager.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/cache/LanguageManager.java index 2499cc20..2e0be7e0 100644 --- a/src/main/java/nl/svenar/powerranks/cache/LanguageManager.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/cache/LanguageManager.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.cache; +package nl.svenar.powerranks.bukkit.cache; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; -import nl.svenar.common.storage.PowerConfigManager; -import nl.svenar.common.storage.provided.YAMLConfigManager; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.provided.YAMLConfigManager; +import nl.svenar.powerranks.bukkit.PowerRanks; public class LanguageManager { diff --git a/src/main/java/nl/svenar/powerranks/commands/PowerCommand.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerCommand.java similarity index 91% rename from src/main/java/nl/svenar/powerranks/commands/PowerCommand.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerCommand.java index 4f63a326..d1b3845c 100644 --- a/src/main/java/nl/svenar/powerranks/commands/PowerCommand.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerCommand.java @@ -1,11 +1,11 @@ -package nl.svenar.powerranks.commands; +package nl.svenar.powerranks.bukkit.commands; import java.util.ArrayList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public abstract class PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/PowerCommandHandler.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerCommandHandler.java similarity index 69% rename from src/main/java/nl/svenar/powerranks/commands/PowerCommandHandler.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerCommandHandler.java index dc868954..aac6e369 100644 --- a/src/main/java/nl/svenar/powerranks/commands/PowerCommandHandler.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerCommandHandler.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands; +package nl.svenar.powerranks.bukkit.commands; import java.io.File; import java.util.ArrayList; @@ -14,67 +14,68 @@ import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; -import nl.svenar.powerranks.commands.PowerCommand.COMMAND_EXECUTOR; -import nl.svenar.powerranks.commands.addons.cmd_addoninfo; -import nl.svenar.powerranks.commands.addons.cmd_addonmanager; -import nl.svenar.powerranks.commands.addons.cmd_listaddons; -import nl.svenar.powerranks.commands.buyable.cmd_addbuyablerank; -import nl.svenar.powerranks.commands.buyable.cmd_buyrank; -import nl.svenar.powerranks.commands.buyable.cmd_delbuyablerank; -import nl.svenar.powerranks.commands.buyable.cmd_rankup; -import nl.svenar.powerranks.commands.buyable.cmd_setbuycommand; -import nl.svenar.powerranks.commands.buyable.cmd_setbuycost; -import nl.svenar.powerranks.commands.buyable.cmd_setbuydescription; -import nl.svenar.powerranks.commands.core.cmd_config; -import nl.svenar.powerranks.commands.core.cmd_dump; -import nl.svenar.powerranks.commands.core.cmd_factoryreset; -import nl.svenar.powerranks.commands.core.cmd_help; -import nl.svenar.powerranks.commands.core.cmd_pluginhook; -import nl.svenar.powerranks.commands.core.cmd_reload; -import nl.svenar.powerranks.commands.core.cmd_stats; -import nl.svenar.powerranks.commands.core.cmd_tablist; -import nl.svenar.powerranks.commands.core.cmd_verbose; -import nl.svenar.powerranks.commands.player.cmd_addownrank; -import nl.svenar.powerranks.commands.player.cmd_addplayerperm; -import nl.svenar.powerranks.commands.player.cmd_addrank; -import nl.svenar.powerranks.commands.player.cmd_checkrank; -import nl.svenar.powerranks.commands.player.cmd_delplayerperm; -import nl.svenar.powerranks.commands.player.cmd_delrank; -import nl.svenar.powerranks.commands.player.cmd_haspermission; -import nl.svenar.powerranks.commands.player.cmd_listplayerpermissions; -import nl.svenar.powerranks.commands.player.cmd_playerinfo; -import nl.svenar.powerranks.commands.player.cmd_setownrank; -import nl.svenar.powerranks.commands.player.cmd_setrank; -import nl.svenar.powerranks.commands.rank.cmd_addinheritance; -import nl.svenar.powerranks.commands.rank.cmd_addperm; -import nl.svenar.powerranks.commands.rank.cmd_createrank; -import nl.svenar.powerranks.commands.rank.cmd_deleterank; -import nl.svenar.powerranks.commands.rank.cmd_delinheritance; -import nl.svenar.powerranks.commands.rank.cmd_delperm; -import nl.svenar.powerranks.commands.rank.cmd_listdefaultranks; -import nl.svenar.powerranks.commands.rank.cmd_listpermissions; -import nl.svenar.powerranks.commands.rank.cmd_listranks; -import nl.svenar.powerranks.commands.rank.cmd_rankinfo; -import nl.svenar.powerranks.commands.rank.cmd_renamerank; -import nl.svenar.powerranks.commands.rank.cmd_setchatcolor; -import nl.svenar.powerranks.commands.rank.cmd_setdefault; -import nl.svenar.powerranks.commands.rank.cmd_setnamecolor; -import nl.svenar.powerranks.commands.rank.cmd_setprefix; -import nl.svenar.powerranks.commands.rank.cmd_setsuffix; -import nl.svenar.powerranks.commands.rank.cmd_setweight; -import nl.svenar.powerranks.commands.test.cmd_test; -import nl.svenar.powerranks.commands.usertags.cmd_addusertag; -import nl.svenar.powerranks.commands.usertags.cmd_clearusertag; -import nl.svenar.powerranks.commands.usertags.cmd_createusertag; -import nl.svenar.powerranks.commands.usertags.cmd_delusertag; -import nl.svenar.powerranks.commands.usertags.cmd_editusertag; -import nl.svenar.powerranks.commands.usertags.cmd_listusertags; -import nl.svenar.powerranks.commands.usertags.cmd_removeusertag; -import nl.svenar.powerranks.commands.usertags.cmd_setusertag; -import nl.svenar.powerranks.commands.webeditor.cmd_webeditor; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.commands.PowerCommand.COMMAND_EXECUTOR; +import nl.svenar.powerranks.bukkit.commands.addons.cmd_addoninfo; +import nl.svenar.powerranks.bukkit.commands.addons.cmd_addonmanager; +import nl.svenar.powerranks.bukkit.commands.addons.cmd_listaddons; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_addbuyablerank; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_buyrank; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_delbuyablerank; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_rankup; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_setbuycommand; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_setbuycost; +import nl.svenar.powerranks.bukkit.commands.buyable.cmd_setbuydescription; +import nl.svenar.powerranks.bukkit.commands.core.cmd_config; +import nl.svenar.powerranks.bukkit.commands.core.cmd_dump; +import nl.svenar.powerranks.bukkit.commands.core.cmd_factoryreset; +import nl.svenar.powerranks.bukkit.commands.core.cmd_help; +import nl.svenar.powerranks.bukkit.commands.core.cmd_pluginhook; +import nl.svenar.powerranks.bukkit.commands.core.cmd_reload; +import nl.svenar.powerranks.bukkit.commands.core.cmd_stats; +import nl.svenar.powerranks.bukkit.commands.core.cmd_tablist; +import nl.svenar.powerranks.bukkit.commands.core.cmd_verbose; +import nl.svenar.powerranks.bukkit.commands.player.cmd_addownrank; +import nl.svenar.powerranks.bukkit.commands.player.cmd_addplayerperm; +import nl.svenar.powerranks.bukkit.commands.player.cmd_addrank; +import nl.svenar.powerranks.bukkit.commands.player.cmd_checkrank; +import nl.svenar.powerranks.bukkit.commands.player.cmd_delplayerperm; +import nl.svenar.powerranks.bukkit.commands.player.cmd_delrank; +import nl.svenar.powerranks.bukkit.commands.player.cmd_haspermission; +import nl.svenar.powerranks.bukkit.commands.player.cmd_listplayerpermissions; +import nl.svenar.powerranks.bukkit.commands.player.cmd_nick; +import nl.svenar.powerranks.bukkit.commands.player.cmd_playerinfo; +import nl.svenar.powerranks.bukkit.commands.player.cmd_setownrank; +import nl.svenar.powerranks.bukkit.commands.player.cmd_setrank; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_addinheritance; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_addperm; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_createrank; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_deleterank; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_delinheritance; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_delperm; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_listdefaultranks; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_listpermissions; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_listranks; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_rankinfo; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_renamerank; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_setchatcolor; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_setdefault; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_setnamecolor; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_setprefix; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_setsuffix; +import nl.svenar.powerranks.bukkit.commands.rank.cmd_setweight; +import nl.svenar.powerranks.bukkit.commands.test.cmd_test; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_addusertag; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_clearusertag; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_createusertag; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_delusertag; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_editusertag; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_listusertags; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_removeusertag; +import nl.svenar.powerranks.bukkit.commands.usertags.cmd_setusertag; +import nl.svenar.powerranks.bukkit.commands.webeditor.cmd_webeditor; public class PowerCommandHandler implements CommandExecutor { @@ -112,6 +113,7 @@ public PowerCommandHandler(PowerRanks plugin) { new cmd_listusertags(plugin, "listusertags", COMMAND_EXECUTOR.ALL); new cmd_checkrank(plugin, "checkrank", COMMAND_EXECUTOR.ALL); + new cmd_nick(plugin, "nick", COMMAND_EXECUTOR.ALL); new cmd_createrank(plugin, "createrank", COMMAND_EXECUTOR.ALL); new cmd_deleterank(plugin, "deleterank", COMMAND_EXECUTOR.ALL); diff --git a/src/main/java/nl/svenar/powerranks/commands/PowerSubCommand.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerSubCommand.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/PowerSubCommand.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerSubCommand.java index 2ce9a9fc..67a291c8 100644 --- a/src/main/java/nl/svenar/powerranks/commands/PowerSubCommand.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/PowerSubCommand.java @@ -1,12 +1,12 @@ -package nl.svenar.powerranks.commands; +package nl.svenar.powerranks.bukkit.commands; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand.COMMAND_EXECUTOR; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand.COMMAND_EXECUTOR; public abstract class PowerSubCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/addons/cmd_addoninfo.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_addoninfo.java similarity index 90% rename from src/main/java/nl/svenar/powerranks/commands/addons/cmd_addoninfo.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_addoninfo.java index 05215ca3..cc2bf0a2 100644 --- a/src/main/java/nl/svenar/powerranks/commands/addons/cmd_addoninfo.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_addoninfo.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.addons; +package nl.svenar.powerranks.bukkit.commands.addons; import java.io.File; import java.util.ArrayList; @@ -6,10 +6,10 @@ import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.ChatColor; import org.bukkit.command.Command; @@ -52,7 +52,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, sender.sendMessage(ChatColor.BLUE + "===" + ChatColor.DARK_AQUA + "------------------------------" + ChatColor.BLUE + "==="); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-addon-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/addons/cmd_addonmanager.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_addonmanager.java similarity index 87% rename from src/main/java/nl/svenar/powerranks/commands/addons/cmd_addonmanager.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_addonmanager.java index bd832937..ece640e2 100644 --- a/src/main/java/nl/svenar/powerranks/commands/addons/cmd_addonmanager.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_addonmanager.java @@ -1,14 +1,14 @@ -package nl.svenar.powerranks.commands.addons; +package nl.svenar.powerranks.bukkit.commands.addons; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.DownloadableAddon; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.DownloadableAddon; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String addonmanagerCommand = args[0].toLowerCase(); if (addonmanagerCommand.equals("acceptterms")) { PowerRanks.getConfigManager().setBool("addon_manager.accepted_terms", true); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".terms-accepted"), ImmutableMap.builder() @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (addonmanagerCommand.equals("declineterms")) { PowerRanks.getConfigManager().setBool("addon_manager.accepted_terms", false); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".terms-declined"), ImmutableMap.builder() @@ -74,7 +74,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } if (addon == null) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".download-not-available"), ImmutableMap.builder() @@ -88,7 +88,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (addon.isCompatible()) { if (addon.download()) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".download-complete"), ImmutableMap.builder() @@ -97,7 +97,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".download-failed"), ImmutableMap.builder() @@ -107,7 +107,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".download-incompatible"), ImmutableMap.builder() @@ -116,7 +116,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".download-not-available"), ImmutableMap.builder() @@ -140,7 +140,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (addon != null) { addon.uninstall(); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".uninstall-complete"), ImmutableMap.builder() @@ -149,7 +149,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-addon-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/addons/cmd_listaddons.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_listaddons.java similarity index 95% rename from src/main/java/nl/svenar/powerranks/commands/addons/cmd_listaddons.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_listaddons.java index 41e0f4fd..fcc00ad1 100644 --- a/src/main/java/nl/svenar/powerranks/commands/addons/cmd_listaddons.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/addons/cmd_listaddons.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.addons; +package nl.svenar.powerranks.bukkit.commands.addons; import java.util.ArrayList; import java.util.Collection; @@ -8,10 +8,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.util.Util; public class cmd_listaddons extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_addbuyablerank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_addbuyablerank.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_addbuyablerank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_addbuyablerank.java index 60993088..2c1e87db 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_addbuyablerank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_addbuyablerank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -8,12 +8,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_addbuyablerank extends PowerCommand { @@ -34,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final boolean success = this.users.addBuyableRank(rankname, rankname2); if (CacheManager.getRank(rankname) != null && CacheManager.getRank(rankname2) != null) { if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-add"), ImmutableMap.builder() @@ -44,7 +44,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-add"), ImmutableMap.builder() @@ -55,7 +55,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.rank-not-found"), ImmutableMap.builder() .put("player", sender.getName()) diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_buyrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_buyrank.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_buyrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_buyrank.java index 5ad68861..03f7d66b 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_buyrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_buyrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -8,15 +8,15 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.external.VaultHook; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.external.VaultHook; public class cmd_buyrank extends PowerCommand { @@ -56,7 +56,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); CacheManager.getPlayer(player.getUniqueId().toString()).setRank(playerRank); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-buy"), ImmutableMap.builder() @@ -78,7 +78,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-buy-not-enough-money"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_delbuyablerank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_delbuyablerank.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_delbuyablerank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_delbuyablerank.java index 21d11657..32ea1295 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_delbuyablerank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_delbuyablerank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_delbuyablerank extends PowerCommand { @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String rankname2 = this.users.getRankIgnoreCase(args[1]); final boolean success = this.users.delBuyableRank(rankname, rankname2); if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-del"), ImmutableMap.builder() @@ -41,7 +41,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-del"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_rankup.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_rankup.java similarity index 79% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_rankup.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_rankup.java index 9e9e7632..e5367e16 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_rankup.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_rankup.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -6,10 +6,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.gui.GUI; -import nl.svenar.powerranks.gui.GUIPage.GUI_PAGE_ID; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.gui.GUI; +import nl.svenar.powerranks.bukkit.gui.GUIPage.GUI_PAGE_ID; public class cmd_rankup extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuycommand.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuycommand.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuycommand.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuycommand.java index 2313548f..d1fec5b9 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuycommand.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuycommand.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setbuycommand extends PowerCommand { @@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, buycommand = buycommand.substring(0, buycommand.length() - 1); final boolean success = this.users.setBuyCommand(rankname, buycommand); if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-set"), ImmutableMap.builder() @@ -46,7 +46,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-set"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuycost.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuycost.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuycost.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuycost.java index fdd26eab..f40481b9 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuycost.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuycost.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setbuycost extends PowerCommand { @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String cost = this.users.getRankIgnoreCase(args[1]); final boolean success = this.users.setBuyCost(rankname, cost); if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-set"), ImmutableMap.builder() @@ -41,7 +41,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-set"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuydescription.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuydescription.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuydescription.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuydescription.java index c943291c..2c469e99 100644 --- a/src/main/java/nl/svenar/powerranks/commands/buyable/cmd_setbuydescription.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/buyable/cmd_setbuydescription.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.buyable; +package nl.svenar.powerranks.bukkit.commands.buyable; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setbuydescription extends PowerCommand { @@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, description = description.substring(0, description.length() - 1); final boolean success = this.users.setBuyDescription(rankname, description); if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-set"), ImmutableMap.builder() @@ -46,7 +46,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-set"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_config.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_config.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_config.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_config.java index 7074d055..ce89ad7b 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_config.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_config.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; import java.util.regex.Matcher; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -55,7 +55,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, this.plugin.updateAllPlayersTABlist(); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".removed-world-tag"), ImmutableMap.builder() @@ -72,7 +72,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, boolean enable = args[0].equalsIgnoreCase("enable"); if (args[1].equalsIgnoreCase("chat_formatting")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -87,7 +87,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getConfigManager().setBool("chat.enabled", enable); } else if (args[1].equalsIgnoreCase("tablist_formatting")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -103,7 +103,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getConfigManager().setBool("tablist_modification.enabled", enable); } else if (args[1].equalsIgnoreCase("casesensitive_permissions")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -119,7 +119,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getConfigManager().setBool("general.case-sensitive-permissions", enable); } else if (args[1].equalsIgnoreCase("op")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -135,7 +135,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getConfigManager().setBool("general.disable-op", !enable); } else if (args[1].equalsIgnoreCase("bungeecord")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -167,7 +167,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, try { int time = Integer.parseInt(args[2]); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -189,7 +189,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } } else if (args[1].equalsIgnoreCase("language")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -205,7 +205,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getConfigManager().setString("general.language", args[2]); } else if (args[1].equalsIgnoreCase("bungeecord_server_name")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -224,7 +224,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, try { int time = Integer.parseInt(args[2]); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_dump.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_dump.java similarity index 95% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_dump.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_dump.java index 0ee56d74..226d4b07 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_dump.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_dump.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.io.File; import java.time.Duration; @@ -21,14 +21,14 @@ import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; -import nl.svenar.common.http.DatabinClient; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.storage.provided.JSONStorageManager; -import nl.svenar.common.utils.AsyncReadFile; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.PowerRanksVerbose; +import nl.svenar.powerranks.common.http.DatabinClient; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.utils.AsyncReadFile; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.PowerRanksVerbose; public class cmd_dump extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_factoryreset.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_factoryreset.java similarity index 86% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_factoryreset.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_factoryreset.java index b3328b96..c355e6cc 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_factoryreset.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_factoryreset.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; @@ -6,9 +6,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; public class cmd_factoryreset extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_help.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_help.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_help.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_help.java index 2480c457..a77581ec 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_help.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_help.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; import java.util.List; @@ -8,10 +8,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.LanguageManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.LanguageManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.util.Util; public class cmd_help extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_pluginhook.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_pluginhook.java similarity index 90% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_pluginhook.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_pluginhook.java index 452afa94..bf775b2c 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_pluginhook.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_pluginhook.java @@ -1,14 +1,14 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; import java.util.HashMap; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -34,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, && PowerRanks.getConfigManager().getMap("plugin_hook", new HashMap()).keySet() .contains(pluginname.toLowerCase())) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_reload.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_reload.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_reload.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_reload.java index 0eb894e9..9b896f38 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_reload.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_reload.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; @@ -6,10 +6,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.PluginReloader; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.util.PluginReloader; public class cmd_reload extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_stats.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_stats.java similarity index 77% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_stats.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_stats.java index 09768bdb..49802401 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_stats.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_stats.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; public class cmd_stats extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_tablist.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_tablist.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_tablist.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_tablist.java index 2299fef6..7a8a8783 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_tablist.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_tablist.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; import java.util.Arrays; @@ -11,10 +11,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; public class cmd_tablist extends PowerCommand { @@ -39,7 +38,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, boolean enable = args[0].equalsIgnoreCase("enable"); if (args[1].equalsIgnoreCase("tablist_sorting")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -58,7 +57,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().getTablistManager().start(); } else if (args[1].equalsIgnoreCase("reverse_tablist_sorting")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -77,7 +76,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().getTablistManager().start(); } else if (args[1].equalsIgnoreCase("header_footer")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -112,7 +111,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, try { int time = Integer.parseInt(args[2]); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -138,7 +137,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, try { int time = Integer.parseInt(args[2]); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() @@ -249,7 +248,7 @@ private void handleAnimationCommand(CommandSender sender, Command cmd, String co } int time = Integer.parseInt(args[2]); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".state-changed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/core/cmd_verbose.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_verbose.java similarity index 92% rename from src/main/java/nl/svenar/powerranks/commands/core/cmd_verbose.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_verbose.java index 55adfe61..3d416826 100644 --- a/src/main/java/nl/svenar/powerranks/commands/core/cmd_verbose.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/core/cmd_verbose.java @@ -1,14 +1,14 @@ -package nl.svenar.powerranks.commands.core; +package nl.svenar.powerranks.bukkit.commands.core; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.data.PowerRanksVerbose; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; +import nl.svenar.powerranks.bukkit.data.PowerRanksVerbose; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -59,7 +59,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } else if (verboseType.equals("stop")) { if (PowerRanksVerbose.USE_VERBOSE) { PowerRanksVerbose.stop(); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".stopped"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_addownrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addownrank.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_addownrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addownrank.java index 43bf2f58..489f1f8d 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_addownrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addownrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; @@ -9,14 +9,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_addownrank extends PowerCommand { @@ -55,7 +55,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .updateSorting(Bukkit.getPlayer(targetPlayer.getUUID())); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-executor"), @@ -65,7 +65,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-receiver"), ImmutableMap.builder() @@ -75,7 +75,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } else { if (targetPlayer != null && rank != null) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-executor"), diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_addplayerperm.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addplayerperm.java similarity index 83% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_addplayerperm.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addplayerperm.java index a4c2a663..b436f5ef 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_addplayerperm.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addplayerperm.java @@ -1,21 +1,19 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionAttachmentInfo; public class cmd_addplayerperm extends PowerCommand { @@ -41,7 +39,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } final boolean result = this.users.addPlayerPermission(targetPlayerName, permission, allowed); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -51,7 +49,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() @@ -81,8 +79,7 @@ public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { if (args.length == 2) { // for (Permission pai : Bukkit.getServer().getPermissions()) { - for (PermissionAttachmentInfo pai : Bukkit.getServer().getConsoleSender().getEffectivePermissions()) { - String perm = pai.getPermission(); + for (String perm : plugin.getPermissionRegistry().getPermissions()) { String userInput = args[1]; String autocompletePermission = ""; diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_addrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addrank.java similarity index 86% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_addrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addrank.java index e5c6a184..983533de 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_addrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_addrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; import java.util.Arrays; @@ -10,14 +10,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_addrank extends PowerCommand { @@ -72,7 +72,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .updateSorting(Bukkit.getPlayer(targetPlayer.getUUID())); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-executor"), @@ -82,7 +82,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); if (Bukkit.getPlayer(targetPlayer.getUUID()) != null) { - Bukkit.getPlayer(targetPlayer.getUUID()).sendMessage(Util.powerFormatter( + Bukkit.getPlayer(targetPlayer.getUUID()).sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-receiver"), ImmutableMap.builder() @@ -92,7 +92,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-already-has-rank"), @@ -104,7 +104,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } } else { if (targetPlayer != null && rank != null) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-executor"), diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_checkrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_checkrank.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_checkrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_checkrank.java index 6a25bb2d..86dc317c 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_checkrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_checkrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; import java.util.List; @@ -9,12 +9,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; public class cmd_checkrank extends PowerCommand { @@ -35,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, playerRanks.add(rank.getName()); } if (playerRanks.size() > 0) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage("commands." + commandName.toLowerCase() + ".success-self"), ImmutableMap.builder() @@ -44,7 +44,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-self-none"), @@ -65,7 +65,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, playerRanks.add(rank.getName()); } if (playerRanks.size() > 0) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage("commands." + commandName.toLowerCase() + ".success-target"), ImmutableMap.builder() @@ -75,7 +75,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-target-none"), @@ -86,7 +86,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-found"), ImmutableMap.builder() .put("player", sender.getName()) diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_delplayerperm.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_delplayerperm.java similarity index 86% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_delplayerperm.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_delplayerperm.java index 62634333..f144cbcd 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_delplayerperm.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_delplayerperm.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; @@ -8,13 +8,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_delplayerperm extends PowerCommand { @@ -34,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String permission = args[1]; final boolean result = this.users.delPlayerPermission(target_player, permission); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -44,7 +44,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_delrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_delrank.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_delrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_delrank.java index fe961704..13ecd76d 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_delrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_delrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; @@ -9,14 +9,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_delrank extends PowerCommand { @@ -63,7 +63,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .updateSorting(Bukkit.getPlayer(targetPlayer.getUUID())); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-executor"), @@ -74,7 +74,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); if (Bukkit.getPlayer(targetPlayer.getUUID()) != null) { - Bukkit.getPlayer(targetPlayer.getUUID()).sendMessage(Util.powerFormatter( + Bukkit.getPlayer(targetPlayer.getUUID()).sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-receiver"), ImmutableMap.builder() @@ -85,7 +85,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } } else { if (targetPlayer != null && rank != null) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-executor"), diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_haspermission.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_haspermission.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_haspermission.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_haspermission.java index 9bb1f19e..5c94d0f0 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_haspermission.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_haspermission.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; import java.util.List; @@ -10,14 +10,13 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionAttachmentInfo; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; public class cmd_haspermission extends PowerCommand { @@ -37,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, permissionNode = args[1]; if (prPlayer == null) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-found"), ImmutableMap.builder() .put("player", sender.getName()) @@ -47,7 +46,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } if (permissionNode == null || permissionNode.length() == 0) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.permission-not-found"), ImmutableMap.builder() .put("permission", args[1]) @@ -74,7 +73,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } } - ArrayList wildcardPermissions = Util.generateWildcardList(permissionNode); + ArrayList wildcardPermissions = PRUtil.generateWildcardList(permissionNode); for (PRPermission perm : playerPermissions) { if (wildcardPermissions.contains(perm.getName())) { @@ -106,7 +105,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, sender.sendMessage(ChatColor.BLUE + "===" + ChatColor.DARK_AQUA + "------------------------------" + ChatColor.BLUE + "==="); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-online"), ImmutableMap.builder() .put("player", sender.getName()) @@ -129,8 +128,7 @@ public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { if (args.length == 2) { // for (Permission pai : Bukkit.getServer().getPermissions()) { - for (PermissionAttachmentInfo pai : Bukkit.getServer().getConsoleSender().getEffectivePermissions()) { - String perm = pai.getPermission(); + for (String perm : plugin.getPermissionRegistry().getPermissions()) { String userInput = args[1]; String autocompletePermission = ""; diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_listplayerpermissions.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_listplayerpermissions.java similarity index 91% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_listplayerpermissions.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_listplayerpermissions.java index e900fbda..1d0b0515 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_listplayerpermissions.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_listplayerpermissions.java @@ -1,7 +1,7 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; -import java.util.List; +import java.util.Set; import com.google.common.collect.ImmutableMap; @@ -10,12 +10,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.util.Util; public class cmd_listplayerpermissions extends PowerCommand { @@ -32,7 +33,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (targetPlayer != null) { displayList(sender, targetPlayer, commandLabel, 0); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-found"), ImmutableMap.builder() .put("player", sender.getName()) @@ -46,7 +47,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (targetPlayer != null) { displayList(sender, targetPlayer, commandLabel, page); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-found"), ImmutableMap.builder() .put("player", sender.getName()) @@ -69,7 +70,7 @@ private void displayList(CommandSender sender, PRPlayer prPlayer, String command output_messages.add(ChatColor.BLUE + "===" + ChatColor.DARK_AQUA + "----------" + ChatColor.AQUA + plugin.getDescription().getName() + ChatColor.DARK_AQUA + "----------" + ChatColor.BLUE + "==="); - List playerPermissions = prPlayer.getPermissions(); + Set playerPermissions = prPlayer.getPermissions(); int lines_per_page = sender instanceof Player ? 5 : 10; int last_page = playerPermissions.size() / lines_per_page; diff --git a/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_nick.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_nick.java new file mode 100644 index 00000000..f38eab6e --- /dev/null +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_nick.java @@ -0,0 +1,151 @@ +package nl.svenar.powerranks.bukkit.commands.player; + +import java.util.ArrayList; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.util.Util; + +public class cmd_nick extends PowerCommand { + + public cmd_nick(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String commandName, + String[] args) { + if (args.length == 1) { // Change own nickname + if (sender instanceof Player) { + Player targetPlayer = (Player) sender; + String nickname = args[0]; + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".setown")) { + if (updateNickname(targetPlayer, nickname)) { + + sender.sendMessage(PRUtil.powerFormatter( + PowerRanks.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setown.success"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + } else { + + sender.sendMessage(PRUtil.powerFormatter( + PowerRanks.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setown.failed"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(PowerRanks.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + } else if (args.length == 2) { // Change other's nickname + String targetPlayername = args[0]; + Player targetPlayer = Util.getPlayerByName(targetPlayername); + if (targetPlayer != null) { + String nickname = args[1]; + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".setother")) { + if (updateNickname(targetPlayer, nickname)) { + + targetPlayer.sendMessage(PRUtil.powerFormatter( + PowerRanks.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setown.success"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + + sender.sendMessage(PRUtil.powerFormatter( + PowerRanks.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setother.success"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + + } else { + sender.sendMessage(PRUtil.powerFormatter( + PowerRanks.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setother.failed"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + + } + } else { + sender.sendMessage(PowerRanks.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + } else { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase()) + || sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".*")) { + sender.sendMessage( + PowerRanks.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } else { + sender.sendMessage(PowerRanks.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + return false; + } + + private boolean updateNickname(Player targetPlayer, String nickname) { + PRPlayer prPlayer = CacheManager.getPlayer(targetPlayer); + if (prPlayer == null) { + return false; + } + prPlayer.setNickname(nickname); + return true; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer prPlayer : CacheManager.getPlayers()) { + tabcomplete.add(prPlayer.getName()); + } + } + + if (args.length == 2) { + PRPlayer targetPlayer = CacheManager.getPlayer(args[0]); + if (targetPlayer != null) { + for (PRRank rank : CacheManager.getRanks()) { + if (!targetPlayer.hasRank(rank.getName())) { + tabcomplete.add(rank.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_playerinfo.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_playerinfo.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_playerinfo.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_playerinfo.java index e588e66a..10e361e5 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_playerinfo.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_playerinfo.java @@ -1,15 +1,15 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (targetPlayer != null) { Messages.messagePlayerInfo(sender, targetPlayer, 0); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-found"), ImmutableMap.builder() .put("player", sender.getName()) @@ -46,7 +46,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (targetPlayer != null) { Messages.messagePlayerInfo(sender, targetPlayer, page); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.player-not-found"), ImmutableMap.builder() .put("player", sender.getName()) diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_setownrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_setownrank.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_setownrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_setownrank.java index e38915c9..abc23a47 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_setownrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_setownrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; @@ -9,14 +9,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setownrank extends PowerCommand { @@ -55,7 +55,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .updateSorting(Bukkit.getPlayer(targetPlayer.getUUID())); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-executor"), @@ -66,7 +66,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } else { if (targetPlayer != null && rank != null) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-executor"), diff --git a/src/main/java/nl/svenar/powerranks/commands/player/cmd_setrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_setrank.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/commands/player/cmd_setrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_setrank.java index fc69c361..97be7893 100644 --- a/src/main/java/nl/svenar/powerranks/commands/player/cmd_setrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/player/cmd_setrank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.player; +package nl.svenar.powerranks.bukkit.commands.player; import java.util.ArrayList; import java.util.Arrays; @@ -12,15 +12,15 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setrank extends PowerCommand { @@ -95,7 +95,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } } if (hasRank) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-executor"), @@ -105,7 +105,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-executor"), @@ -117,7 +117,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, } if (Bukkit.getPlayer(targetPlayer.getUUID()) != null) { - Bukkit.getPlayer(targetPlayer.getUUID()).sendMessage(Util.powerFormatter( + Bukkit.getPlayer(targetPlayer.getUUID()).sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-receiver"), ImmutableMap.builder() @@ -127,7 +127,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed-executor"), diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_addinheritance.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_addinheritance.java similarity index 83% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_addinheritance.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_addinheritance.java index 13ae8778..77964a5b 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_addinheritance.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_addinheritance.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,12 +8,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_addinheritance extends PowerCommand { @@ -33,7 +33,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String inheritance = args[1]; final boolean result = this.users.addInheritance(rankname, inheritance); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_addperm.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_addperm.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_addperm.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_addperm.java index 2e4bb156..66ce7c06 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_addperm.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_addperm.java @@ -1,20 +1,18 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionAttachmentInfo; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_addperm extends PowerCommand { @@ -41,7 +39,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final boolean result = this.users.addPermission(rankname, permission, allowed); if (result) { if (rankname.equals("*")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-all"), ImmutableMap.builder() @@ -51,7 +49,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -62,7 +60,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { // Rank not found - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() @@ -92,8 +90,7 @@ public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { if (args.length == 2) { // for (Permission pai : Bukkit.getServer().getPermissions()) { - for (PermissionAttachmentInfo pai : Bukkit.getServer().getConsoleSender().getEffectivePermissions()) { - String perm = pai.getPermission(); + for (String perm : plugin.getPermissionRegistry().getPermissions()) { String userInput = args[1]; String autocompletePermission = ""; diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_createrank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_createrank.java similarity index 81% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_createrank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_createrank.java index ee027ec5..e241b09e 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_createrank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_createrank.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -33,7 +33,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] forbiddenCharacters = { "`", "~", "!", "@", "$", "%", "^", "*", "(", ")", "{", "}", "[", "]", ":", ";", "\"", "'", "|", "\\", "?", "/", ">", "<", ",", ".", "+", "=" }; if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -41,8 +41,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .put("rank", rankname) .build(), '[', ']')); - if (Util.stringContainsItemFromList(rankname, forbiddenColorCharacters)) { - sender.sendMessage(Util.powerFormatter( + if (PRUtil.stringContainsItemFromList(rankname, forbiddenColorCharacters)) { + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".warning-color"), ImmutableMap.builder() @@ -52,8 +52,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } - if (Util.stringContainsItemFromList(rankname, forbiddenCharacters)) { - sender.sendMessage(Util.powerFormatter( + if (PRUtil.stringContainsItemFromList(rankname, forbiddenCharacters)) { + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".warning-character"), ImmutableMap.builder() @@ -63,7 +63,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_deleterank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_deleterank.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_deleterank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_deleterank.java index d8751159..d205785e 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_deleterank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_deleterank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_deleterank extends PowerCommand { @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String rankname = this.users.getRankIgnoreCase(args[0]); final boolean success = this.users.deleteRank(rankname); if (success) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -40,7 +40,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_delinheritance.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_delinheritance.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_delinheritance.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_delinheritance.java index d3a5d809..ca5f43c0 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_delinheritance.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_delinheritance.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,12 +8,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_delinheritance extends PowerCommand { @@ -33,7 +33,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String inheritance = args[1]; final boolean result = this.users.removeInheritance(rankname, inheritance); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -43,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_delperm.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_delperm.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_delperm.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_delperm.java index 11ce1fcd..aeb7bb44 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_delperm.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_delperm.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; import java.util.List; @@ -9,12 +9,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_delperm extends PowerCommand { @@ -35,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final boolean result = this.users.removePermission(rankname, permission); if (result) { if (rankname.equals("*")) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-all"), ImmutableMap.builder() @@ -45,7 +45,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -56,7 +56,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { // Rank not found - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_listdefaultranks.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listdefaultranks.java similarity index 76% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_listdefaultranks.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listdefaultranks.java index 29ce2aba..0a414bf7 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_listdefaultranks.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listdefaultranks.java @@ -1,19 +1,19 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; +import java.util.Set; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; public class cmd_listdefaultranks extends PowerCommand { @@ -26,7 +26,7 @@ public cmd_listdefaultranks(PowerRanks plugin, String command_name, COMMAND_EXEC public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String commandName, String[] args) { if (args.length == 0) { - List ranks = CacheManager.getDefaultRanks(); + Set ranks = CacheManager.getDefaultRanks(); sender.sendMessage(ChatColor.BLUE + "===" + ChatColor.DARK_AQUA + "----------" + ChatColor.AQUA + plugin.getDescription().getName() + ChatColor.DARK_AQUA + "----------" + ChatColor.BLUE + "==="); @@ -35,11 +35,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, sender.sendMessage(ChatColor.AQUA + "Ranks (" + ranks.size() + "):"); int index = 0; - ranks = new ArrayList<>(new HashSet<>(ranks)); - PRUtil.sortRanksByWeight(ranks); - PRUtil.reverseRanks(ranks); + List sortedRanks = new ArrayList<>(ranks); + PRUtil.sortRanksByWeight(sortedRanks); + PRUtil.reverseRanks(sortedRanks); - for (PRRank rank : ranks) { + for (PRRank rank : sortedRanks) { index++; sender.sendMessage( ChatColor.DARK_GREEN + "#" + index + ". " + ChatColor.GRAY + "(" + rank.getWeight() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_listpermissions.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listpermissions.java similarity index 92% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_listpermissions.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listpermissions.java index bea2403c..af94f2d2 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_listpermissions.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listpermissions.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; import java.util.List; @@ -10,12 +10,13 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.util.Util; public class cmd_listpermissions extends PowerCommand { @@ -42,7 +43,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, // Messages.listRankPermissions(sender, s, rankName, 0); displayRankPermissions(sender, rankName, commandLabel, 0); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() @@ -58,7 +59,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, // Messages.listRankPermissions(sender, s, rankName, page); displayRankPermissions(sender, rankName, commandLabel, page); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_listranks.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listranks.java similarity index 77% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_listranks.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listranks.java index a2f1f378..fda25f31 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_listranks.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_listranks.java @@ -1,18 +1,17 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_listranks extends PowerCommand { @@ -35,11 +34,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, sender.sendMessage(ChatColor.AQUA + "Ranks (" + ranks.size() + "):"); int index = 0; - ranks = new ArrayList<>(new HashSet<>(ranks)); - PRUtil.sortRanksByWeight(ranks); - ranks = PRUtil.reverseRanks(ranks); + List sortedRanks = new ArrayList<>(ranks); + PRUtil.sortRanksByWeight(sortedRanks); + PRUtil.reverseRanks(sortedRanks); - for (PRRank rank : ranks) { + for (PRRank rank : sortedRanks) { index++; sender.sendMessage(ChatColor.DARK_GREEN + "#" + index + ". " + ChatColor.GRAY + "(" + rank.getWeight() + ") " + ChatColor.GREEN + rank.getName() + ChatColor.RESET + " " diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_rankinfo.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_rankinfo.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_rankinfo.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_rankinfo.java index 8c2a481d..719c9ed7 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_rankinfo.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_rankinfo.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,12 +8,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Messages; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Messages; public class cmd_rankinfo extends PowerCommand { @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (target_rank != null) { Messages.messageRankInfo(sender, target_rank, 0); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() @@ -47,7 +47,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (target_rank != null) { Messages.messageRankInfo(sender, target_rank, page); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_renamerank.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_renamerank.java similarity index 83% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_renamerank.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_renamerank.java index 59b6a10b..6bdfe8f4 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_renamerank.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_renamerank.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_renamerank extends PowerCommand { @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String to = args[1]; final boolean result = this.users.renameRank(from, to); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { // Rank not found or target name already exists - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setchatcolor.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setchatcolor.java similarity index 83% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_setchatcolor.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setchatcolor.java index ed0dc485..20608549 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setchatcolor.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setchatcolor.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setchatcolor extends PowerCommand { @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String color = args[1]; final boolean result = this.users.setChatColor(rankname, color); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setdefault.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setdefault.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_setdefault.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setdefault.java index d03afc1f..d346af27 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setdefault.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setdefault.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,12 +8,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setdefault extends PowerCommand { @@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, rank.setDefault(isDefault); if (isDefault) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-added"), ImmutableMap.builder() @@ -45,7 +45,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-removed"), ImmutableMap.builder() @@ -55,7 +55,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, '[', ']')); } } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setnamecolor.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setnamecolor.java similarity index 83% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_setnamecolor.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setnamecolor.java index d6e9d550..9c7d5d35 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setnamecolor.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setnamecolor.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setnamecolor extends PowerCommand { @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String color = args[1]; final boolean result = this.users.setNameColor(rankname, color); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setprefix.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setprefix.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_setprefix.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setprefix.java index acde42f9..d29301b0 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setprefix.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setprefix.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setprefix extends PowerCommand { @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String prefix = ""; final boolean result = this.users.setPrefix(rankname, prefix); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-clear"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage("general.rank-not-found"), ImmutableMap.builder() .put("player", sender.getName()) @@ -59,7 +59,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, prefix = prefix.substring(0, prefix.length() - 1); final boolean result = this.users.setPrefix(rankname, prefix); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -69,7 +69,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setsuffix.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setsuffix.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_setsuffix.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setsuffix.java index 5c9117be..fc3c3d98 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setsuffix.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setsuffix.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; @@ -8,11 +8,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setsuffix extends PowerCommand { @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String suffix = ""; final boolean result = this.users.setSuffix(rankname, suffix); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-clear"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() @@ -60,7 +60,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, suffix = suffix.substring(0, suffix.length() - 1); final boolean result = this.users.setSuffix(rankname, suffix); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -70,7 +70,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setweight.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setweight.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/commands/rank/cmd_setweight.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setweight.java index 09acdef6..a7568246 100644 --- a/src/main/java/nl/svenar/powerranks/commands/rank/cmd_setweight.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/rank/cmd_setweight.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.rank; +package nl.svenar.powerranks.bukkit.commands.rank; import java.util.ArrayList; import java.util.Objects; @@ -9,12 +9,12 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; public class cmd_setweight extends PowerCommand { @@ -34,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String rankname = this.users.getRankIgnoreCase(args[0]); final PRRank rank = CacheManager.getRank(rankname); if (Objects.isNull(rank)) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() @@ -48,7 +48,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, try { weight = Integer.parseInt(args[1]); } catch (Exception e) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".numbers-only"), ImmutableMap.builder() @@ -61,7 +61,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, if (rank != null) { rank.setWeight(weight); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/test/cmd_test.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/test/cmd_test.java similarity index 90% rename from src/main/java/nl/svenar/powerranks/commands/test/cmd_test.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/test/cmd_test.java index 2bcfba45..ba6a23bc 100644 --- a/src/main/java/nl/svenar/powerranks/commands/test/cmd_test.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/test/cmd_test.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.test; +package nl.svenar.powerranks.bukkit.commands.test; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -7,10 +7,10 @@ import java.util.Map; import java.util.Map.Entry; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.PowerPermissibleBase; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.PowerPermissibleBase; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_addusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_addusertag.java similarity index 89% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_addusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_addusertag.java index bdbe4261..6a3fc930 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_addusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_addusertag.java @@ -1,14 +1,15 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.util.Util; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -39,7 +40,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().updateTablistName(targetPlayer); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -49,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() @@ -76,7 +77,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().updateTablistName(targetPlayer); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -86,7 +87,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_clearusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_clearusertag.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_clearusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_clearusertag.java index 1d63e523..a2fada6e 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_clearusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_clearusertag.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -33,7 +33,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String playername = sender.getName(); final boolean result = this.users.clearUserTag(playername); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() @@ -64,7 +64,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String playername = args[0]; final boolean result = this.users.clearUserTag(playername); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -73,7 +73,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_createusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_createusertag.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_createusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_createusertag.java index c763a03d..667dea57 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_createusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_createusertag.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String text = args[1]; final boolean result = this.users.createUserTag(tag, text); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_delusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_delusertag.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_delusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_delusertag.java index 0fa59ce8..09bcc4d9 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_delusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_delusertag.java @@ -1,14 +1,15 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.util.Util; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -39,7 +40,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().updateTablistName(targetPlayer); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -49,7 +50,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() @@ -76,7 +77,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().updateTablistName(targetPlayer); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -86,7 +87,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_editusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_editusertag.java similarity index 86% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_editusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_editusertag.java index 362300c5..877a4d05 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_editusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_editusertag.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -32,7 +32,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String text = args[1]; final boolean result = this.users.editUserTag(tag, text); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -42,7 +42,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_listusertags.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_listusertags.java similarity index 95% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_listusertags.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_listusertags.java index 42508fb6..2b510010 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_listusertags.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_listusertags.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import java.util.Set; @@ -8,10 +8,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.util.Util; public class cmd_listusertags extends PowerCommand { diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_removeusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_removeusertag.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_removeusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_removeusertag.java index 4f9870d4..237f27a7 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_removeusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_removeusertag.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -31,7 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, final String tag = args[0]; final boolean result = this.users.removeUserTag(tag); if (result) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -40,7 +40,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_setusertag.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_setusertag.java similarity index 90% rename from src/main/java/nl/svenar/powerranks/commands/usertags/cmd_setusertag.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_setusertag.java index 0f6b98ae..5f04e67f 100644 --- a/src/main/java/nl/svenar/powerranks/commands/usertags/cmd_setusertag.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/usertags/cmd_setusertag.java @@ -1,13 +1,13 @@ -package nl.svenar.powerranks.commands.usertags; +package nl.svenar.powerranks.bukkit.commands.usertags; import java.util.ArrayList; import com.google.common.collect.ImmutableMap; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.common.utils.PRUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -38,7 +38,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().updateTablistName(targetPlayer); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -48,7 +48,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() @@ -75,7 +75,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, PowerRanks.getInstance().updateTablistName(targetPlayer); } - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success"), ImmutableMap.builder() @@ -85,7 +85,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, .build(), '[', ']')); } else { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".failed"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/commands/webeditor/cmd_webeditor.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/webeditor/cmd_webeditor.java similarity index 90% rename from src/main/java/nl/svenar/powerranks/commands/webeditor/cmd_webeditor.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/webeditor/cmd_webeditor.java index c712b0db..455e111c 100644 --- a/src/main/java/nl/svenar/powerranks/commands/webeditor/cmd_webeditor.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/commands/webeditor/cmd_webeditor.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.commands.webeditor; +package nl.svenar.powerranks.bukkit.commands.webeditor; import java.lang.reflect.Type; import java.util.ArrayList; @@ -16,17 +16,16 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.scheduler.BukkitRunnable; -import nl.svenar.common.http.DatabinClient; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.storage.provided.JSONStorageManager; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.commands.PowerCommand; -import nl.svenar.powerranks.data.PowerRanksVerbose; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.http.DatabinClient; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.commands.PowerCommand; +import nl.svenar.powerranks.bukkit.data.PowerRanksVerbose; public class cmd_webeditor extends PowerCommand { @@ -102,6 +101,9 @@ private void startWebeditor(CommandSender sender, String commandName) { outputJSON += ","; outputJSON += "\"usertags\":"; outputJSON += PowerRanks.getUsertagManager().toJSON("usertags", false); + outputJSON += ","; + outputJSON += "\"tablist\":"; + outputJSON += PowerRanks.getTablistConfigManager().toJSON(null, false); outputJSON += "}"; jsonmanager.removeAllData(); @@ -217,7 +219,7 @@ public void handleWebeditorDownload(CommandSender sender, Map js } if (!((String) serverData.get("powerranksVersion")).equals(PowerRanks.getVersion())) { - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".incompatible-version"), ImmutableMap.builder() @@ -232,6 +234,7 @@ public void handleWebeditorDownload(CommandSender sender, Map js LinkedTreeMap rankData = (LinkedTreeMap) jsonData.get("rankdata"); LinkedTreeMap playerData = (LinkedTreeMap) jsonData.get("playerdata"); LinkedTreeMap usertags = (LinkedTreeMap) jsonData.get("usertags"); + LinkedTreeMap tablist = (LinkedTreeMap) jsonData.get("tablist"); JSONStorageManager jsonmanager = new JSONStorageManager(PowerRanks.fileLoc, "dummyRanks.json", "dummyPlayers.json"); @@ -251,12 +254,13 @@ public void handleWebeditorDownload(CommandSender sender, Map js jsonmanager.removeAllData(); PowerRanks.getUsertagManager().fromJSON("usertags", usertags); + PowerRanks.getTablistConfigManager().fromJSON(null, tablist); sender.sendMessage( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".success-downloaded")); - sender.sendMessage(Util.powerFormatter( + sender.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands." + commandName.toLowerCase() + ".download-stats"), ImmutableMap.builder() @@ -283,8 +287,8 @@ private String getServerDataAsJSON() { List server_permissions = new ArrayList(); - for (PermissionAttachmentInfo permission : Bukkit.getServer().getConsoleSender().getEffectivePermissions()) { - server_permissions.add("\"" + permission.getPermission() + "\""); + for (String perm : plugin.getPermissionRegistry().getPermissions()) { + server_permissions.add("\"" + perm + "\""); } output += "{"; diff --git a/src/main/java/nl/svenar/powerranks/data/BannerItem.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/BannerItem.java similarity index 95% rename from src/main/java/nl/svenar/powerranks/data/BannerItem.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/BannerItem.java index 9a8373ee..38fe66ed 100644 --- a/src/main/java/nl/svenar/powerranks/data/BannerItem.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/BannerItem.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/nl/svenar/powerranks/data/BungeecordManager.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/BungeecordManager.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/data/BungeecordManager.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/BungeecordManager.java index 25915f5d..5732742e 100644 --- a/src/main/java/nl/svenar/powerranks/data/BungeecordManager.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/BungeecordManager.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.time.Duration; import java.time.Instant; @@ -9,12 +9,12 @@ import org.bukkit.scheduler.BukkitRunnable; -import nl.svenar.common.storage.provided.MySQLStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; +import nl.svenar.powerranks.common.storage.provided.MySQLStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; public class BungeecordManager { diff --git a/src/main/java/nl/svenar/powerranks/data/Messages.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/Messages.java similarity index 97% rename from src/main/java/nl/svenar/powerranks/data/Messages.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/Messages.java index 6d30b63a..b2998e09 100644 --- a/src/main/java/nl/svenar/powerranks/data/Messages.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/Messages.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.io.File; import java.text.SimpleDateFormat; @@ -6,8 +6,10 @@ import java.time.Instant; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import java.util.TimeZone; @@ -18,20 +20,20 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.common.utils.PowerColor; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.AddonsManager; -import nl.svenar.powerranks.addons.DownloadableAddon; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.external.VaultHook; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.AddonsManager; +import nl.svenar.powerranks.bukkit.addons.DownloadableAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.external.VaultHook; +import nl.svenar.powerranks.bukkit.util.Util; import com.google.common.collect.ImmutableMap; @@ -479,7 +481,7 @@ private static String getSampleChatFormat(Player player) { PRPlayer targetPlayer = CacheManager.getPlayer(player.getUniqueId().toString()); Map availableUsertags = PowerRanks.getUsertagManager().getMap("usertags", new HashMap()); - ArrayList playerUsertags = targetPlayer.getUsertags(); + Set playerUsertags = targetPlayer.getUsertags(); for (String playerUsertag : playerUsertags) { String value = ""; @@ -502,7 +504,7 @@ private static String getSampleChatFormat(Player player) { String player_formatted_chat_msg = (chatColor.length() == 0 ? "&r" : "") + PowerRanks.applyMultiColorFlow(chatColor, playersChatMessage); - format = Util.powerFormatter(format, ImmutableMap.builder().put("prefix", formatted_prefix) + format = PRUtil.powerFormatter(format, ImmutableMap.builder().put("prefix", formatted_prefix) .put("suffix", formatted_suffix) .put("usertag", !PowerRanks.plugin_hook_deluxetags ? usertag @@ -544,7 +546,7 @@ private static String getSampleChatFormat(CommandSender sender, String name, Str String player_formatted_chat_msg = (chatColor.length() == 0 ? "&r" : "") + PowerRanks.applyMultiColorFlow(chatColor, playersChatMessage); - format = Util.powerFormatter(format, ImmutableMap.builder().put("prefix", formatted_prefix) + format = PRUtil.powerFormatter(format, ImmutableMap.builder().put("prefix", formatted_prefix) .put("suffix", formatted_suffix) .put("usertag", !PowerRanks.plugin_hook_deluxetags ? usertag @@ -927,7 +929,7 @@ public static void listRankPermissions(CommandSender sender, Users users, String } public static void listPlayerPermissions(CommandSender sender, Users users, String target_player, int page) { - List lines = users.getPlayerPermissions(target_player); + Set lines = users.getPlayerPermissions(target_player); int lines_per_page = 10; if (page < 0) @@ -957,9 +959,13 @@ public static void listPlayerPermissions(CommandSender sender, Users users, Stri Messages.powerRanks.getServer().dispatchCommand( (CommandSender) Messages.powerRanks.getServer().getConsoleSender(), page_selector_tellraw); + Iterator permissionIterator = lines.iterator(); for (int i = 0; i < lines_per_page; i++) { if (lines_per_page * page + i < lines.size()) { - PRPermission permission = lines.get(lines_per_page * page + i); + if (!permissionIterator.hasNext()) { + break; + } + PRPermission permission = permissionIterator.next(); if (permission.getName().length() > 0) sender.sendMessage( (permission.getValue() ? ChatColor.GREEN : ChatColor.RED) + permission.getName()); diff --git a/src/main/java/nl/svenar/powerranks/data/PowerPermissibleBase.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/PowerPermissibleBase.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/data/PowerPermissibleBase.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/PowerPermissibleBase.java index bea5a60b..804ac196 100644 --- a/src/main/java/nl/svenar/powerranks/data/PowerPermissibleBase.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/PowerPermissibleBase.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.util.Map.Entry; import java.util.HashMap; @@ -12,16 +12,18 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.storage.PermissionRegistry; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; public class PowerPermissibleBase extends PermissibleBase { private PowerRanks plugin; private Player player; + private PermissionRegistry permissionRegistry; private PRPlayer prPlayer; public static Map permissionCallCount = new HashMap(); @@ -30,6 +32,7 @@ public PowerPermissibleBase(Player player, PowerRanks plugin) { super(player); this.player = player; this.plugin = plugin; + this.permissionRegistry = plugin.getPermissionRegistry(); this.prPlayer = CacheManager.getPlayer(player.getUniqueId().toString()); if (prPlayer == null) { CacheManager.createPlayer(player); @@ -68,9 +71,11 @@ public boolean isPermissionSet(String name) { throw new IllegalArgumentException("Permission name cannot be null"); } + permissionRegistry.queuePermission(name); + PRPermission prPermission = getPRPermission(name); if (prPermission == null) { - for (String wildCardPermissionName : Util.generateWildcardList(name)) { + for (String wildCardPermissionName : PRUtil.generateWildcardList(name)) { prPermission = getPRPermission(wildCardPermissionName); if (prPermission != null) { break; @@ -104,6 +109,8 @@ public boolean hasPermission(String inName) { throw new IllegalArgumentException("Permission name cannot be null"); } + permissionRegistry.queuePermission(inName); + if (permissionCallCount.get(inName) == null) { permissionCallCount.put(inName, 0); } else { @@ -112,7 +119,7 @@ public boolean hasPermission(String inName) { PRPermission prPermission = getPRPermission(inName); if (prPermission == null) { - for (String wildCardPermissionName : Util.generateWildcardList(inName)) { + for (String wildCardPermissionName : PRUtil.generateWildcardList(inName)) { prPermission = getPRPermission(wildCardPermissionName); if (prPermission != null) { break; @@ -120,14 +127,22 @@ public boolean hasPermission(String inName) { } } + boolean defaultHasPermission = false; + try { + defaultHasPermission = super.hasPermission(inName); + } catch (NullPointerException e) { + PowerRanksVerbose.log("hasPermission(String inName) failed", e.getMessage()); + super.recalculatePermissions(); + } + PowerRanksVerbose.log("hasPermission(String inName)", - "called with inName: " + inName + " (" + super.hasPermission(inName) + ") - prPermission value: " + "called with inName: " + inName + " (" + defaultHasPermission + ") - prPermission value: " + (prPermission == null ? "null" : prPermission.getValue())); if (prPermission != null) { return prPermission.getValue(); } - return super.hasPermission(inName); + return defaultHasPermission; } @Override diff --git a/src/main/java/nl/svenar/powerranks/data/PowerRanksVerbose.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/PowerRanksVerbose.java similarity index 97% rename from src/main/java/nl/svenar/powerranks/data/PowerRanksVerbose.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/PowerRanksVerbose.java index 71820b67..501b5795 100644 --- a/src/main/java/nl/svenar/powerranks/data/PowerRanksVerbose.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/PowerRanksVerbose.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.io.BufferedReader; import java.io.File; @@ -9,7 +9,7 @@ import java.util.ArrayList; import java.util.Date; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public class PowerRanksVerbose { diff --git a/src/main/java/nl/svenar/powerranks/data/TablistAnimation.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/TablistAnimation.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/data/TablistAnimation.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/TablistAnimation.java index 615164d9..864e32e4 100644 --- a/src/main/java/nl/svenar/powerranks/data/TablistAnimation.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/TablistAnimation.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.util.ArrayList; diff --git a/src/main/java/nl/svenar/powerranks/data/TablistManager.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/TablistManager.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/data/TablistManager.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/TablistManager.java index b22f2ee7..24735928 100644 --- a/src/main/java/nl/svenar/powerranks/data/TablistManager.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/TablistManager.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.time.Duration; import java.time.Instant; @@ -11,13 +11,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.common.utils.PowerColor; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; diff --git a/src/main/java/nl/svenar/powerranks/data/Users.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/Users.java similarity index 97% rename from src/main/java/nl/svenar/powerranks/data/Users.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/Users.java index 301e2d8e..cfdb1ead 100644 --- a/src/main/java/nl/svenar/powerranks/data/Users.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/data/Users.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.data; +package nl.svenar.powerranks.bukkit.data; import java.util.ArrayList; import java.util.HashMap; @@ -13,14 +13,14 @@ import org.bukkit.entity.Player; import org.bukkit.event.Listener; -// import nl.svenar.PowerRanks.Cache.CachedConfig; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; +// import nl.svenar.powerranks.bukkit.cache.CachedConfig; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; public class Users implements Listener { PowerRanks m; @@ -712,7 +712,7 @@ public boolean addPlayerPermission(String targetPlayerName, String permission, b if (targetPlayer != null) { try { - List list = targetPlayer.getPermissions(); + Set list = targetPlayer.getPermissions(); PRPermission targetPermission = null; for (PRPermission prPermission : list) { if (prPermission.getName().equals(permission)) { @@ -744,7 +744,7 @@ public boolean delPlayerPermission(String target_player_name, String permission) if (target_player != null) { try { if (CacheManager.getPlayer(target_player.getUniqueId().toString()) != null) { - List list = CacheManager.getPlayer(target_player.getUniqueId().toString()) + Set list = CacheManager.getPlayer(target_player.getUniqueId().toString()) .getPermissions(); PRPermission targetPermission = null; for (PRPermission prPermission : list) { @@ -775,7 +775,7 @@ public boolean delPlayerPermission(String target_player_name, String permission) if (uuid.length() > 0) { if (CacheManager.getPlayer(uuid) != null) { - List list = CacheManager.getPlayer(uuid).getPermissions(); + Set list = CacheManager.getPlayer(uuid).getPermissions(); PRPermission targetPermission = null; for (PRPermission prPermission : list) { if (prPermission.getName().equals(permission)) { @@ -810,8 +810,8 @@ public boolean delPlayerPermission(String target_player_name, String permission) return false; } - public List getPlayerPermissions(String playername) { - List list = new ArrayList(); + public Set getPlayerPermissions(String playername) { + Set list = new HashSet(); Player player = Bukkit.getServer().getPlayer(playername); if (player == null) @@ -1041,7 +1041,7 @@ public String getUserTagValue(Player player) { return ""; } - String usertag = targetPlayer.getUsertags().get(0); + String usertag = targetPlayer.getUsertags().iterator().next(); if (usertag.length() > 0) { return getUserTagValue(usertag); } @@ -1058,7 +1058,7 @@ public boolean clearUserTag(String playername) { return false; } - targetPlayer.setUsertags(new ArrayList()); + targetPlayer.setUsertags(new HashSet()); return true; } diff --git a/src/main/java/nl/svenar/powerranks/events/ChatTabExecutor.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/ChatTabExecutor.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/events/ChatTabExecutor.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/ChatTabExecutor.java index f7528a31..32b8e206 100644 --- a/src/main/java/nl/svenar/powerranks/events/ChatTabExecutor.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/ChatTabExecutor.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.util.ArrayList; import java.util.Arrays; @@ -8,8 +8,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.commands.PowerCommandHandler; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.commands.PowerCommandHandler; public class ChatTabExecutor implements TabCompleter { diff --git a/src/main/java/nl/svenar/powerranks/events/OnBlockChange.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnBlockChange.java similarity index 91% rename from src/main/java/nl/svenar/powerranks/events/OnBlockChange.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnBlockChange.java index 01d69c51..ea841de8 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnBlockChange.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnBlockChange.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.io.File; import java.util.Map.Entry; @@ -16,10 +16,10 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.MoistureChangeEvent; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; -import nl.svenar.powerranks.addons.PowerRanksAddon.BlockChangeCause; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon.BlockChangeCause; public class OnBlockChange implements Listener { diff --git a/src/main/java/nl/svenar/powerranks/events/OnChat.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnChat.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/events/OnChat.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnChat.java index c4b5bec5..a177efc7 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnChat.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnChat.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.io.File; import java.util.ArrayList; @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.Map.Entry; import org.bukkit.ChatColor; @@ -14,16 +15,15 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.common.utils.PowerColor; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.cache.CacheManager; import com.google.common.collect.ImmutableMap; @@ -92,7 +92,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent e) { PRPlayer targetPlayer = CacheManager.getPlayer(player.getUniqueId().toString()); Map availableUsertags = PowerRanks.getUsertagManager().getMap("usertags", new HashMap()); - ArrayList playerUsertags = targetPlayer.getUsertags(); + Set playerUsertags = targetPlayer.getUsertags(); for (String playerUsertag : playerUsertags) { String value = ""; @@ -132,7 +132,7 @@ public void onPlayerChat(final AsyncPlayerChatEvent e) { "" + PowerColor.UNFORMATTED_COLOR_CHAR); } - format = Util.powerFormatter( + format = PRUtil.powerFormatter( format, ImmutableMap.builder().put("prefix", formatted_prefix) .put("suffix", formatted_suffix) .put("usertag", diff --git a/src/main/java/nl/svenar/powerranks/events/OnInteract.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnInteract.java similarity index 82% rename from src/main/java/nl/svenar/powerranks/events/OnInteract.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnInteract.java index fa09407f..b833d990 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnInteract.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnInteract.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.util.ArrayList; import java.util.List; @@ -7,21 +7,23 @@ import org.bukkit.block.Block; import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.external.VaultHook; -import nl.svenar.powerranks.gui.GUI; -import nl.svenar.powerranks.gui.GUIPage.GUI_PAGE_ID; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.external.VaultHook; +import nl.svenar.powerranks.bukkit.gui.GUI; +import nl.svenar.powerranks.bukkit.gui.GUIPage.GUI_PAGE_ID; +import nl.svenar.powerranks.bukkit.util.Util; public class OnInteract implements Listener { @@ -45,12 +47,31 @@ public void onPlayerInteract(PlayerInteractEvent event) { } } + @SuppressWarnings("deprecation") private void handlePowerRanksSign(Sign sign, Player player) { final Users users = new Users(this.plugin); - String sign_command = sign.getLine(1); - String sign_argument = sign.getLine(2); - String sign_argument2 = sign.getLine(3); - boolean sign_error = sign.getLine(3).toLowerCase().contains("error"); + String sign_command; + String sign_argument; + String sign_argument2; + boolean sign_error; + + try { + Class.forName("org.bukkit.block.sign.Side"); + Side signSide = Side.FRONT; + sign_command = sign.getSide(signSide).getLine(1); + if (sign_command.length() == 0) { + signSide = Side.BACK; + sign_command = sign.getSide(signSide).getLine(1); + } + sign_argument = sign.getSide(signSide).getLine(2); + sign_argument2 = sign.getSide(signSide).getLine(3); + sign_error = sign.getSide(signSide).getLine(3).toLowerCase().contains("error"); + } catch (ClassNotFoundException e) { + sign_command = sign.getLine(1); + sign_argument = sign.getLine(2); + sign_argument2 = sign.getLine(3); + sign_error = sign.getLine(3).toLowerCase().contains("error"); + } if (!sign_error) { // if (sign_command.equalsIgnoreCase("promote")) { @@ -78,7 +99,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { if (rank != null) { PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); CacheManager.getPlayer(player.getUniqueId().toString()).setRank(playerRank); - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.setrank.success-receiver"), ImmutableMap.builder() @@ -99,7 +120,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { CacheManager.getPlayer(player.getUniqueId().toString()).addRank(playerRank); // Messages.messageSetRankSuccessSender(player, t, rank); - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.setrank.success-receiver"), ImmutableMap.builder() @@ -120,7 +141,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { playerRanks.add(rank.getName()); } if (playerRanks.size() > 0) { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage("commands.checkrank.success-self"), ImmutableMap.builder() @@ -129,7 +150,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { .build(), '[', ']')); } else { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager() .getFormattedMessage( "commands.checkrank.success-self-none"), @@ -153,7 +174,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { if (player.hasPermission("powerranks.signs.usertag")) { if (users.setUserTag(player, sign_argument)) { if (sign_argument.length() > 0) { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.setusertag.success"), ImmutableMap.builder() @@ -162,7 +183,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { .build(), '[', ']')); } else { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.clearusertag.success"), ImmutableMap.builder() @@ -172,7 +193,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { '[', ']')); } } else { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.setusertag.failed"), ImmutableMap.builder() @@ -204,7 +225,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); CacheManager.getPlayer(player.getUniqueId().toString()).addRank(playerRank); - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.setrank.success-receiver"), ImmutableMap.builder() @@ -215,7 +236,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { } } // users.setGroup(player, users.getRankIgnoreCase(sign_argument), true); - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.buyrank.success-buy"), ImmutableMap.builder() @@ -224,7 +245,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { .build(), '[', ']')); } else { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.buyrank.failed-buy-not-enough-money"), ImmutableMap.builder() @@ -234,7 +255,7 @@ private void handlePowerRanksSign(Sign sign, Player player) { '[', ']')); } } else { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.buyrank.failed-buy-not-enough-money"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/events/OnInventory.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnInventory.java similarity index 86% rename from src/main/java/nl/svenar/powerranks/events/OnInventory.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnInventory.java index 64785395..8ec6c680 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnInventory.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnInventory.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import org.bukkit.event.EventHandler; @@ -7,8 +7,8 @@ import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.inventory.Inventory; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.gui.GUI; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.gui.GUI; import org.bukkit.event.Listener; diff --git a/src/main/java/nl/svenar/powerranks/events/OnJoin.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnJoin.java similarity index 87% rename from src/main/java/nl/svenar/powerranks/events/OnJoin.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnJoin.java index 25f22338..b794da25 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnJoin.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnJoin.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.io.File; import java.util.Date; @@ -10,12 +10,12 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.PowerRanksVerbose; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.PowerRanksVerbose; public class OnJoin implements Listener { PowerRanks plugin; diff --git a/src/main/java/nl/svenar/powerranks/events/OnMove.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnMove.java similarity index 79% rename from src/main/java/nl/svenar/powerranks/events/OnMove.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnMove.java index 634c22ba..3077b62f 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnMove.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnMove.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.io.File; import java.util.Map.Entry; @@ -8,9 +8,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; public class OnMove implements Listener { diff --git a/src/main/java/nl/svenar/powerranks/events/OnPreCommand.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnPreCommand.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/events/OnPreCommand.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnPreCommand.java index 97b973ff..04c56452 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnPreCommand.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnPreCommand.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; @@ -7,7 +7,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.server.ServerCommandEvent; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public class OnPreCommand implements Listener { diff --git a/src/main/java/nl/svenar/powerranks/events/OnSignChanged.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnSignChanged.java similarity index 85% rename from src/main/java/nl/svenar/powerranks/events/OnSignChanged.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnSignChanged.java index 6ad6858e..45244dad 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnSignChanged.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnSignChanged.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.util.List; import java.util.Set; @@ -9,10 +9,11 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.SignChangeEvent; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.util.Util; public class OnSignChanged implements Listener { @@ -38,7 +39,7 @@ public void onSignChange(SignChangeEvent event) { if (sign_command.equalsIgnoreCase("promote") || sign_command.equalsIgnoreCase("demote") || sign_command.equalsIgnoreCase("checkrank") || sign_command.equalsIgnoreCase("gui")) { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.created"), ImmutableMap.builder() @@ -56,7 +57,7 @@ public void onSignChange(SignChangeEvent event) { } if (!rank_exists) { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() @@ -66,7 +67,7 @@ public void onSignChange(SignChangeEvent event) { '[', ']')); event.setLine(3, PowerRanks.chatColor("&4Error", true)); } else { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.created"), ImmutableMap.builder() @@ -88,7 +89,7 @@ public void onSignChange(SignChangeEvent event) { usertag_exists = true; } if (!usertag_exists) { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.usertags.not-found"), ImmutableMap.builder() @@ -98,7 +99,7 @@ public void onSignChange(SignChangeEvent event) { '[', ']')); event.setLine(3, PowerRanks.chatColor("&4Error", true)); } else { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.created"), ImmutableMap.builder() @@ -109,7 +110,7 @@ public void onSignChange(SignChangeEvent event) { } else if (sign_command.equalsIgnoreCase("rankup")) { List ranks = s.getGroups(); if (sign_argument.length() == 0) { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.created"), ImmutableMap.builder() @@ -125,7 +126,7 @@ public void onSignChange(SignChangeEvent event) { } } if (!rank_exists) { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "general.rank-not-found"), ImmutableMap.builder() @@ -137,7 +138,7 @@ public void onSignChange(SignChangeEvent event) { } else { if (sign_argument2.length() > 0) { if (!sign_argument2.chars().anyMatch(Character::isLetter)) { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.created"), ImmutableMap.builder() @@ -145,7 +146,7 @@ public void onSignChange(SignChangeEvent event) { .build(), '[', ']')); } else { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.unknown-command"), ImmutableMap.builder() @@ -156,7 +157,7 @@ public void onSignChange(SignChangeEvent event) { } } else { event.setLine(3, String.valueOf(s.getRankCost(s.getRankIgnoreCase(sign_argument)))); - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.created"), ImmutableMap.builder() @@ -168,7 +169,7 @@ public void onSignChange(SignChangeEvent event) { } } } else { - event.getPlayer().sendMessage(Util.powerFormatter( + event.getPlayer().sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "messages.signs.unknown-command"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/events/OnWorldChange.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnWorldChange.java similarity index 76% rename from src/main/java/nl/svenar/powerranks/events/OnWorldChange.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnWorldChange.java index 6506afdd..81e7b879 100644 --- a/src/main/java/nl/svenar/powerranks/events/OnWorldChange.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/events/OnWorldChange.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.events; +package nl.svenar.powerranks.bukkit.events; import java.io.File; import java.util.Map.Entry; @@ -8,11 +8,11 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.addons.PowerRanksAddon; -import nl.svenar.powerranks.addons.PowerRanksPlayer; -import nl.svenar.powerranks.cache.CacheManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.addons.PowerRanksAddon; +import nl.svenar.powerranks.bukkit.addons.PowerRanksPlayer; +import nl.svenar.powerranks.bukkit.cache.CacheManager; public class OnWorldChange implements Listener { PowerRanks powerRanks; diff --git a/src/main/java/nl/svenar/powerranks/external/DeluxeTagsHook.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/DeluxeTagsHook.java similarity index 92% rename from src/main/java/nl/svenar/powerranks/external/DeluxeTagsHook.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/DeluxeTagsHook.java index a9bcbb45..2c0e3dec 100644 --- a/src/main/java/nl/svenar/powerranks/external/DeluxeTagsHook.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/DeluxeTagsHook.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.external; +package nl.svenar.powerranks.bukkit.external; import java.util.List; @@ -7,7 +7,7 @@ import me.clip.deluxetags.DeluxeTags; import me.clip.deluxetags.tags.DeluxeTag; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public class DeluxeTagsHook { diff --git a/src/main/java/nl/svenar/powerranks/external/PowerRanksExpansion.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksExpansion.java similarity index 95% rename from src/main/java/nl/svenar/powerranks/external/PowerRanksExpansion.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksExpansion.java index 6fca0479..fdb7fba5 100644 --- a/src/main/java/nl/svenar/powerranks/external/PowerRanksExpansion.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksExpansion.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.external; +package nl.svenar.powerranks.bukkit.external; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -9,12 +9,12 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.Users; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.Users; import me.clip.placeholderapi.expansion.PlaceholderExpansion; /** diff --git a/src/main/java/nl/svenar/powerranks/external/PowerRanksVaultChat.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksVaultChat.java similarity index 93% rename from src/main/java/nl/svenar/powerranks/external/PowerRanksVaultChat.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksVaultChat.java index 9add845d..07503bd6 100644 --- a/src/main/java/nl/svenar/powerranks/external/PowerRanksVaultChat.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksVaultChat.java @@ -1,12 +1,11 @@ -package nl.svenar.powerranks.external; +package nl.svenar.powerranks.bukkit.external; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.api.PowerRanksAPI; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.Users; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.Users; import java.util.ArrayList; import java.util.List; @@ -17,13 +16,11 @@ public class PowerRanksVaultChat extends Chat { final PowerRanks plugin; final Users users; - final PowerRanksAPI prapi; public PowerRanksVaultChat(PowerRanks plugin, Permission perms) { super(perms); this.plugin = plugin; this.users = new Users(plugin); - this.prapi = new PowerRanksAPI(plugin); } @Override diff --git a/src/main/java/nl/svenar/powerranks/external/PowerRanksVaultPermission.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksVaultPermission.java similarity index 87% rename from src/main/java/nl/svenar/powerranks/external/PowerRanksVaultPermission.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksVaultPermission.java index 3173d21e..10d59579 100644 --- a/src/main/java/nl/svenar/powerranks/external/PowerRanksVaultPermission.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/PowerRanksVaultPermission.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.external; +package nl.svenar.powerranks.bukkit.external; import java.util.ArrayList; import java.util.List; @@ -7,14 +7,13 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitScheduler; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.api.PowerRanksAPI; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.PowerRanksVerbose; -import nl.svenar.powerranks.data.Users; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.PowerRanksVerbose; +import nl.svenar.powerranks.bukkit.data.Users; import com.google.common.collect.Iterables; @@ -24,13 +23,11 @@ public class PowerRanksVaultPermission extends Permission { final PowerRanks plugin; final Users users; - final PowerRanksAPI prapi; private boolean playerHasErrorQueueOffline = false; PowerRanksVaultPermission(PowerRanks plugin) { this.plugin = plugin; this.users = new Users(plugin); - this.prapi = new PowerRanksAPI(plugin); } @Override @@ -97,13 +94,13 @@ public boolean groupHas(String world, String name, String permission) { @Override public boolean groupAdd(final String world, String name, final String permission) { PowerRanksVerbose.log("PowerRanksVaultPermission.groupAdd(...)", "Called"); - return prapi.addPermission(name, permission); + return false; // return prapi.addPermission(name, permission); // TODO: add support } @Override public boolean groupRemove(final String world, String name, final String permission) { PowerRanksVerbose.log("PowerRanksVaultPermission.groupRemove(...)", "Called"); - return prapi.removePermission(name, permission); + return false; // return prapi.removePermission(name, permission); // TODO: add support } @@ -145,7 +142,7 @@ public void run() { @Override public boolean playerAdd(final String world, OfflinePlayer player, final String permission) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerAdd(...)", "Called, player: " + player.getName()); - return prapi.addPermission(player.getPlayer(), permission); + return false; // return prapi.addPermission(player.getPlayer(), permission); // TODO: add support } @Override @@ -166,20 +163,20 @@ public boolean playerAddTransient(Player player, String permission) { public boolean playerAddTransient(final String worldName, OfflinePlayer player, final String permission) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerAddTransient(...)", "Called, player: " + player.getName()); - return prapi.addPermission(player.getPlayer(), permission); + return false; // return prapi.addPermission(player.getPlayer(), permission); // TODO: add support } @Override public boolean playerRemoveTransient(final String worldName, OfflinePlayer player, final String permission) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerRemoveTransient(...)", "Called, player: " + player.getName()); - return prapi.removePermission(player.getPlayer(), permission); + return false; // return prapi.removePermission(player.getPlayer(), permission); // TODO: add support } @Override public boolean playerRemove(final String world, OfflinePlayer player, final String permission) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerRemove(...)", "Called, player: " + player.getName()); - return prapi.removePermission(player.getPlayer(), permission); + return false; // return prapi.removePermission(player.getPlayer(), permission); // TODO: add support } @Override @@ -199,20 +196,20 @@ public boolean playerRemoveTransient(OfflinePlayer player, String permission) { @Override public boolean playerInGroup(String world, OfflinePlayer player, String group) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerInGroup(...)", "Called, player: " + player.getName()); - return prapi.getSubranks(player.getPlayer()).contains(group); + return false; // return prapi.getSubranks(player.getPlayer()).contains(group); // TODO: add support } @Override public boolean playerAddGroup(final String world, OfflinePlayer player, final String group) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerAddGroup(...)", "Called, player: " + player.getName()); - return prapi.addSubrank(player.getPlayer(), group); + return false; // return prapi.addSubrank(player.getPlayer(), group); // TODO: add support } @Override public boolean playerRemoveGroup(final String world, OfflinePlayer player, final String group) { PowerRanksVerbose.log("PowerRanksVaultPermission.playerRemoveGroup(...)", "Called, player: " + player.getName()); - return prapi.removeSubrank(player.getPlayer(), group); + return false; // return prapi.removeSubrank(player.getPlayer(), group); // TODO: add support } @Override diff --git a/src/main/java/nl/svenar/powerranks/external/VaultHook.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/VaultHook.java similarity index 94% rename from src/main/java/nl/svenar/powerranks/external/VaultHook.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/VaultHook.java index ec77b799..f05c53b1 100644 --- a/src/main/java/nl/svenar/powerranks/external/VaultHook.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/external/VaultHook.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.external; +package nl.svenar.powerranks.bukkit.external; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; @@ -8,7 +8,7 @@ import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public class VaultHook { diff --git a/src/main/java/nl/svenar/powerranks/gui/GUI.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/gui/GUI.java similarity index 88% rename from src/main/java/nl/svenar/powerranks/gui/GUI.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/gui/GUI.java index ef503536..f2f909c8 100644 --- a/src/main/java/nl/svenar/powerranks/gui/GUI.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/gui/GUI.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.gui; +package nl.svenar.powerranks.bukkit.gui; import java.util.HashMap; @@ -8,14 +8,14 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.external.VaultHook; -import nl.svenar.powerranks.gui.GUIPage.GUI_PAGE_ID; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.external.VaultHook; +import nl.svenar.powerranks.bukkit.gui.GUIPage.GUI_PAGE_ID; public class GUI { @@ -91,7 +91,7 @@ public static void clickedItem(Player player, int slot) { if (rank != null) { PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); CacheManager.getPlayer(player.getUniqueId().toString()).setRank(playerRank); - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.setrank.success-receiver"), ImmutableMap.builder() @@ -112,7 +112,7 @@ public static void clickedItem(Player player, int slot) { .replaceAll("%rankname%", rankname)); } } - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.buyrank.success-buy"), ImmutableMap.builder() @@ -121,7 +121,7 @@ public static void clickedItem(Player player, int slot) { .build(), '[', ']')); } else { - player.sendMessage(Util.powerFormatter( + player.sendMessage(PRUtil.powerFormatter( PowerRanks.getLanguageManager().getFormattedMessage( "commands.buyrank.failed-buy-not-enough-money"), ImmutableMap.builder() diff --git a/src/main/java/nl/svenar/powerranks/gui/GUIPage.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/gui/GUIPage.java similarity index 98% rename from src/main/java/nl/svenar/powerranks/gui/GUIPage.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/gui/GUIPage.java index cc209c06..d1ddcc71 100644 --- a/src/main/java/nl/svenar/powerranks/gui/GUIPage.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/gui/GUIPage.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.gui; +package nl.svenar.powerranks.bukkit.gui; import java.util.ArrayList; import java.util.Arrays; @@ -16,11 +16,11 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.BannerItem; -import nl.svenar.powerranks.data.Users; -import nl.svenar.powerranks.external.VaultHook; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.bukkit.data.BannerItem; +import nl.svenar.powerranks.bukkit.data.Users; +import nl.svenar.powerranks.bukkit.external.VaultHook; public class GUIPage { diff --git a/src/main/java/nl/svenar/powerranks/metrics/Metrics.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/metrics/Metrics.java similarity index 99% rename from src/main/java/nl/svenar/powerranks/metrics/Metrics.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/metrics/Metrics.java index f70b13c9..6c41a08a 100644 --- a/src/main/java/nl/svenar/powerranks/metrics/Metrics.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/metrics/Metrics.java @@ -1,11 +1,11 @@ -package nl.svenar.powerranks.metrics; +package nl.svenar.powerranks.bukkit.metrics; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import nl.svenar.powerranks.addons.AddonsManager; +import nl.svenar.powerranks.bukkit.addons.AddonsManager; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/nl/svenar/powerranks/update/ConfigFilesUpdater.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/update/ConfigFilesUpdater.java similarity index 96% rename from src/main/java/nl/svenar/powerranks/update/ConfigFilesUpdater.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/update/ConfigFilesUpdater.java index 642bc781..95c86a06 100644 --- a/src/main/java/nl/svenar/powerranks/update/ConfigFilesUpdater.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/update/ConfigFilesUpdater.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.update; +package nl.svenar.powerranks.bukkit.update; import java.io.File; import java.io.FileNotFoundException; @@ -13,16 +13,16 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import nl.svenar.common.storage.PowerConfigManager; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.storage.provided.YAMLConfigManager; -import nl.svenar.common.storage.provided.YAMLStorageManager; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; +import nl.svenar.powerranks.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.YAMLConfigManager; +import nl.svenar.powerranks.common.storage.provided.YAMLStorageManager; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.cache.CacheManager; public class ConfigFilesUpdater { diff --git a/src/main/java/nl/svenar/powerranks/update/Updater.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/update/Updater.java similarity index 99% rename from src/main/java/nl/svenar/powerranks/update/Updater.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/update/Updater.java index 55fb4dfc..bbdce8fb 100644 --- a/src/main/java/nl/svenar/powerranks/update/Updater.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/update/Updater.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.update; +package nl.svenar.powerranks.bukkit.update; import java.io.*; import java.net.HttpURLConnection; @@ -19,7 +19,7 @@ import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import nl.svenar.powerranks.util.Util; +import nl.svenar.powerranks.bukkit.util.Util; /** * Check for updates on BukkitDev for a given plugin, and download the updates diff --git a/src/main/java/nl/svenar/powerranks/util/BukkitPowerColor.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/BukkitPowerColor.java similarity index 84% rename from src/main/java/nl/svenar/powerranks/util/BukkitPowerColor.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/BukkitPowerColor.java index 96af4a97..3bef2024 100644 --- a/src/main/java/nl/svenar/powerranks/util/BukkitPowerColor.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/BukkitPowerColor.java @@ -1,6 +1,6 @@ -package nl.svenar.powerranks.util; +package nl.svenar.powerranks.bukkit.util; -import nl.svenar.common.utils.PowerColor; +import nl.svenar.powerranks.common.utils.PowerColor; public class BukkitPowerColor { diff --git a/src/main/java/nl/svenar/powerranks/util/PluginReloader.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/PluginReloader.java similarity index 97% rename from src/main/java/nl/svenar/powerranks/util/PluginReloader.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/PluginReloader.java index 68109429..18c65746 100644 --- a/src/main/java/nl/svenar/powerranks/util/PluginReloader.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/PluginReloader.java @@ -1,4 +1,4 @@ -package nl.svenar.powerranks.util; +package nl.svenar.powerranks.bukkit.util; import java.io.File; import java.io.IOException; @@ -21,8 +21,8 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.RegisteredListener; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.util.PluginReloader; +import nl.svenar.powerranks.bukkit.PowerRanks; +import nl.svenar.powerranks.bukkit.util.PluginReloader; public class PluginReloader { diff --git a/src/main/java/nl/svenar/powerranks/util/Util.java b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/Util.java similarity index 62% rename from src/main/java/nl/svenar/powerranks/util/Util.java rename to Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/Util.java index 5654101e..fc43e2ef 100644 --- a/src/main/java/nl/svenar/powerranks/util/Util.java +++ b/Bukkit/src/main/java/nl/svenar/powerranks/bukkit/util/Util.java @@ -1,13 +1,11 @@ -package nl.svenar.powerranks.util; +package nl.svenar.powerranks.bukkit.util; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -15,11 +13,12 @@ import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import org.bukkit.entity.Player; import org.json.simple.JSONObject; import org.json.simple.JSONValue; -import nl.svenar.powerranks.PowerRanks; +import nl.svenar.powerranks.bukkit.PowerRanks; public class Util { @@ -83,57 +82,18 @@ public static String replaceAll(String source, String key, String value) { } } - public static String powerFormatter(String text, Map values, char openChar, char closeChar) { - StringBuilder result = new StringBuilder(); - int textIdx = 0; - - for (int startIdx; (startIdx = text.indexOf(openChar, textIdx)) != -1;) { - int endIdx = text.indexOf(closeChar, startIdx + 1); - - if (endIdx == -1) - break; - - if (startIdx < 2 || text.charAt(startIdx - 1) != '\\') { - result.append(text.substring(textIdx, startIdx)); - textIdx = endIdx + 1; - String value = values.get(text.substring(startIdx + 1, endIdx)); - - if (value != null && !value.isEmpty()) { - result.append(value); // Replace placeholder with non-empty value - - } else if (result.length() != 0 && result.charAt(result.length() - 1) == ' ') { - result.setLength(result.length() - 1); // Remove space before placeholder - - } else if (textIdx < text.length() && text.charAt(textIdx) == ' ') { - textIdx++; // Skip space after placeholder - } else { - result.append(openChar + text.substring(startIdx + 1, endIdx) + closeChar); // Add back the original - // placeholder when an - // replacement isn't - // found - } - } else { - String unformatted = text.substring(textIdx, endIdx + 1).replaceFirst("\\\\", ""); - if (unformatted.length() > 1) { - String replaceText = text.substring(startIdx, endIdx + 1); - String baseText = text.substring(startIdx, startIdx + 1); - String endText = text.substring(endIdx + 1, endIdx + 1); - String formattedReplacement = baseText - + powerFormatter(text.substring(startIdx + 1, endIdx + 1), values, openChar, closeChar) - + endText; - - unformatted = unformatted.replace(replaceText, formattedReplacement); - } - result.append(unformatted); - textIdx = endIdx + 1; + @SuppressWarnings("deprecation") + public static boolean isPowerRanksSign(PowerRanks main, Sign sign) { + String sign_header; + try { + Class.forName("org.bukkit.block.sign.Side"); + sign_header = sign.getSide(Side.FRONT).getLine(0); + if (sign_header.length() == 0) { + sign_header = sign.getSide(Side.BACK).getLine(0); } + } catch (ClassNotFoundException e) { + sign_header = sign.getLine(0); } - result.append(text.substring(textIdx)); - return result.toString(); - } - - public static boolean isPowerRanksSign(PowerRanks main, Sign sign) { - String sign_header = sign.getLine(0); return isPowerRanksSign(main, sign_header); } @@ -142,10 +102,6 @@ public static boolean isPowerRanksSign(PowerRanks main, String sign_header) { && PowerRanks.getConfigManager().getBool("signs.enabled", false); } - public static boolean stringContainsItemFromList(String inputStr, String[] items) { - return Arrays.stream(items).anyMatch(inputStr::contains); - } - public String getCraftBukkitClassName(String simpleName) { String version = Bukkit.getServer().getClass().getName().substring("org.bukkit.craftbukkit".length()); version = version.substring(0, version.length() - "CraftServer".length()); @@ -201,17 +157,6 @@ public static int calculateVersionFromString(String input) { return output; } - public static T[] array_push(T[] arr, T item) { - T[] tmp = Arrays.copyOf(arr, arr.length + 1); - tmp[tmp.length - 1] = item; - return tmp; - } - - public static T[] array_pop(T[] arr) { - T[] tmp = Arrays.copyOf(arr, arr.length - 1); - return tmp; - } - public static Player getPlayerByName(String target_player_name) { Player target_player = null; for (Player online_player : Bukkit.getOnlinePlayers()) { @@ -270,74 +215,6 @@ public static String readUrl(String urlString) throws Exception { return output; } - public static ArrayList generateWildcardList(String permission) { - ArrayList output = new ArrayList(); - String[] permission_split = permission.split("\\."); - - permission_split = Util.array_pop(permission_split); - for (int i = 0; i < permission_split.length + 1; i++) { - if (permission_split.length == 0) - break; - output.add(String.join(".", permission_split) + ".*"); - permission_split = Util.array_pop(permission_split); - } - - return output; - } - - /** - * Convert a time string to seconds - * - * @param time_input - * @return - */ - public static int timeStringToSecondsConverter(String time_input) { - Matcher regex_int = Pattern.compile("^\\d+[^a-zA-Z]{0,1}$").matcher(time_input); - - Matcher regex_seconds = Pattern.compile("\\d+[sS]").matcher(time_input); - Matcher regex_minutes = Pattern.compile("\\d+[mM]").matcher(time_input); - Matcher regex_hours = Pattern.compile("\\d+[hH]").matcher(time_input); - Matcher regex_days = Pattern.compile("\\d+[dD]").matcher(time_input); - Matcher regex_weeks = Pattern.compile("\\d+[wW]").matcher(time_input); - Matcher regex_years = Pattern.compile("\\d+[yY]").matcher(time_input); - - int seconds = 0; - - if (regex_int.find()) { - seconds = Integer.parseInt(time_input); - } else { - if (regex_seconds.find()) { - seconds += Integer.parseInt(time_input.substring(regex_seconds.start(), regex_seconds.end() - 1)); - } - - if (regex_minutes.find()) { - seconds += Integer.parseInt(time_input.substring(regex_minutes.start(), regex_minutes.end() - 1)) * 60; - } - - if (regex_hours.find()) { - seconds += Integer.parseInt(time_input.substring(regex_hours.start(), regex_hours.end() - 1)) - * (60 * 60); - } - - if (regex_days.find()) { - seconds += Integer.parseInt(time_input.substring(regex_days.start(), regex_days.end() - 1)) - * (60 * 60 * 24); - } - - if (regex_weeks.find()) { - seconds += Integer.parseInt(time_input.substring(regex_weeks.start(), regex_weeks.end() - 1)) - * (60 * 60 * 24 * 7); - } - - if (regex_years.find()) { - seconds += Integer.parseInt(time_input.substring(regex_years.start(), regex_years.end() - 1)) - * (60 * 60 * 24 * 365); - } - } - - return seconds; - } - public static UUID getUUIDFromAPI(String playerName) { try { URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + playerName); @@ -393,7 +270,7 @@ public static Long convertToLong(Object value) { } } - public static Object formatStringToType(String input) { + public static Object formatStringToType(String input) { Object output = input; if (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("false")) { @@ -415,6 +292,6 @@ public static Object formatStringToType(String input) { output = outputList; } - return output; - } + return output; + } } \ No newline at end of file diff --git a/src/main/resources/config.yml b/Bukkit/src/main/resources/config.yml similarity index 100% rename from src/main/resources/config.yml rename to Bukkit/src/main/resources/config.yml diff --git a/src/main/resources/lang.yml b/Bukkit/src/main/resources/lang.yml similarity index 97% rename from src/main/resources/lang.yml rename to Bukkit/src/main/resources/lang.yml index 53502c66..86036602 100644 --- a/src/main/resources/lang.yml +++ b/Bukkit/src/main/resources/lang.yml @@ -179,6 +179,14 @@ lang: playerinfo: arguments: "" description: "Show information about a player" + nick: + arguments: "[player_name] " + setown: + success: "&aYour nickname has been set to: [nickname]" + failed: "&cFailed to set your nickname to: [nickname]" + setother: + success: "&a[target]'s nickname has been set to: [nickname]" + failed: "&cFailed to set [target]'s nickname to: [nickname]" haspermission: arguments: " " description: "Check if a player has a certain permission" diff --git a/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml similarity index 98% rename from src/main/resources/plugin.yml rename to Bukkit/src/main/resources/plugin.yml index d013f45a..d1eaab9b 100644 --- a/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ -name: ${project.name} +name: ${output.name} version: ${project.version} -main: nl.svenar.powerranks.PowerRanks +main: nl.svenar.powerranks.bukkit.PowerRanks api-version: 1.13 authors: [svenar_nl] softdepend: [Vault, PlaceholderAPI, TAB, DeluxeTags, NametagEdit] diff --git a/src/main/resources/tablist.yml b/Bukkit/src/main/resources/tablist.yml similarity index 100% rename from src/main/resources/tablist.yml rename to Bukkit/src/main/resources/tablist.yml diff --git a/Bukkit/src/test/java/nl/svenar/powerranks/test/tests/TestPermissions.java b/Bukkit/src/test/java/nl/svenar/powerranks/test/tests/TestPermissions.java new file mode 100644 index 00000000..fd896ff1 --- /dev/null +++ b/Bukkit/src/test/java/nl/svenar/powerranks/test/tests/TestPermissions.java @@ -0,0 +1,133 @@ +package nl.svenar.powerranks.test.tests; + +import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.BeforeAll; +import org.junit.FixMethodOrder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.TestInstance.Lifecycle; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.bukkit.entity.Player; + +import be.seeseemelk.mockbukkit.ServerMock; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.test.util.Mock; +import nl.svenar.powerranks.test.util.TestDebugger; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestInstance(Lifecycle.PER_CLASS) +public class TestPermissions { + + private final int numPlayers = 20; + + private ServerMock server; + + @BeforeAll + public void setUp() { + Mock.init(); + server = Mock.getServerMock(); + + server.setPlayers(numPlayers); + } + + @AfterAll + public void tearDown() { + Mock.unmock(); + } + + @Test + public void A_testRankAddPermission() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[A_testRankAddPermissionA_testRankAddPermission] Start"); + + Player player1 = Mock.getPlayer(0); + Player player2 = Mock.getPlayer(1); + PRPlayer prPlayer2 = CacheManager.getPlayer(player2.getUniqueId().toString()); + + player1.setOp(true); + player2.setOp(false); + + server.execute("pr", player1, "createrank", "TestPermissions"); + server.execute("pr", player1, "setrank", player2.getName(), "TestPermissions"); + server.execute("pr", player1, "addperm", "TestPermissions", "test.permission.node.*"); + + prPlayer2.updatePermissionsFromRanks(); + + assertTrue(prPlayer2.hasPermission("test.permission.node.1", true)); + + server.execute("pr", player1, "deleterank", "TestPermissions"); + prPlayer2.updatePermissionsFromRanks(); + + assertTrue(!prPlayer2.hasPermission("test.permission.node.1", true)); + + TestDebugger.log(this, "[A_testRankAddPermissionA_testRankAddPermission] OK"); + } + + @Test + public void B_testRankPermissionWeightOverride() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[B_testRankPermissionWeightOverride] Start"); + + Player player1 = Mock.getPlayer(0); + Player player2 = Mock.getPlayer(1); + PRPlayer prPlayer2 = CacheManager.getPlayer(player2.getUniqueId().toString()); + + player1.setOp(true); + player2.setOp(false); + + server.execute("pr", player1, "createrank", "TestPermissions1"); + server.execute("pr", player1, "createrank", "TestPermissions2"); + server.execute("pr", player1, "addperm", "TestPermissions1", "test.permission.node.*"); + server.execute("pr", player1, "addperm", "TestPermissions2", "-test.permission.node.denied"); + + server.execute("pr", player1, "setrank", player2.getName(), "TestPermissions1"); + + prPlayer2.updatePermissionsFromRanks(); + + assertTrue(prPlayer2.isPermissionAllowed("test.permission.node.denied", true)); + + server.execute("pr", player1, "addrank", player2.getName(), "TestPermissions2"); + prPlayer2.updatePermissionsFromRanks(); + + assertTrue(!prPlayer2.isPermissionAllowed("test.permission.node.denied", true)); + + server.execute("pr", player1, "deleterank", "TestPermissions1"); + server.execute("pr", player1, "deleterank", "TestPermissions2"); + + TestDebugger.log(this, "[B_testRankPermissionWeightOverride] OK"); + } + + @Test + public void C_testPermissionWildcard() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[C_testPermissionWildcard] Start"); + + Player player1 = Mock.getPlayer(0); + Player player2 = Mock.getPlayer(1); + PRPlayer prPlayer2 = CacheManager.getPlayer(player2.getUniqueId().toString()); + + player1.setOp(true); + player2.setOp(false); + + server.execute("pr", player1, "createrank", "TestPermissions"); + server.execute("pr", player1, "setrank", player2.getName(), "TestPermissions"); + server.execute("pr", player1, "addperm", "TestPermissions", "test.permission.node1.*"); + server.execute("pr", player1, "addperm", "TestPermissions", "test.permission.node2.*"); + server.execute("pr", player1, "addperm", "TestPermissions", "test.permission.node3.*"); + prPlayer2.updatePermissionsFromRanks(); + + assertEquals("test.permission.node1.*", prPlayer2.getPermission("test.permission.node1.abc", true).getName()); + assertEquals("test.permission.node2.*", prPlayer2.getPermission("test.permission.node2.def", true).getName()); + assertEquals("test.permission.node3.*", prPlayer2.getPermission("test.permission.node3.ghi", true).getName()); + assertNull(prPlayer2.getPermission("test.permission.node1.abc", false)); + + TestDebugger.log(this, "[C_testPermissionWildcard] OK"); + } + +} diff --git a/Bukkit/src/test/java/nl/svenar/powerranks/test/tests/TestRanks.java b/Bukkit/src/test/java/nl/svenar/powerranks/test/tests/TestRanks.java new file mode 100644 index 00000000..2adee9c4 --- /dev/null +++ b/Bukkit/src/test/java/nl/svenar/powerranks/test/tests/TestRanks.java @@ -0,0 +1,121 @@ +package nl.svenar.powerranks.test.tests; + +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.TestInstance.Lifecycle; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.bukkit.entity.Player; + +import be.seeseemelk.mockbukkit.ServerMock; +import nl.svenar.powerranks.bukkit.cache.CacheManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.test.util.Mock; +import nl.svenar.powerranks.test.util.TestDebugger; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestInstance(Lifecycle.PER_CLASS) +public class TestRanks { + + private final int numPlayers = 20; + + private ServerMock server; + + @BeforeAll + public void setUp() { + Mock.init(); + server = Mock.getServerMock(); + + server.setPlayers(numPlayers); + } + + @AfterAll + public void tearDown() { + Mock.unmock(); + } + + @Test + public void A_testCreateRank() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[A_testCreateRank] Start"); + + Player player = Mock.getPlayer(0); + + player.setOp(true); + + assertEquals(numPlayers, CacheManager.getPlayers().size()); + int numRanks = CacheManager.getRanks().size(); + server.execute("pr", player, "createrank", "Test1"); + assertEquals(numRanks + 1, CacheManager.getRanks().size()); + + TestDebugger.log(this, "[A_testCreateRank] OK"); + } + + @Test + public void B_testSetrank() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[B_testSetrank] Start"); + + Player player1 = Mock.getPlayer(0); + Player player2 = Mock.getPlayer(1); + PRPlayer prPlayer2 = CacheManager.getPlayer(player2.getUniqueId().toString()); + + player1.setOp(true); + player2.setOp(false); + + server.execute("pr", player1, "createrank", "testSetDelrank"); + server.execute("pr", player1, "setrank", player2.getName(), "testSetDelrank"); + + assertTrue(prPlayer2.getRanks().stream().anyMatch(rank -> rank.getName().equals("testSetDelrank"))); + + TestDebugger.log(this, "[B_testSetrank] OK"); + } + + @Test + public void C_testDelrank() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[C_testDelrank] Start"); + + Player player1 = Mock.getPlayer(0); + Player player2 = Mock.getPlayer(1); + PRPlayer prPlayer2 = CacheManager.getPlayer(player2.getUniqueId().toString()); + + player1.setOp(true); + player2.setOp(false); + + server.execute("pr", player1, "delrank", player2.getName(), "testSetDelrank"); + + assertTrue(!prPlayer2.getRanks().stream().anyMatch(rank -> rank.getName().equals("testSetDelrank"))); + + TestDebugger.log(this, "[C_testDelrank] OK"); + } + + @Test + public void D_testDeleteRankUpdatePlayer() { + TestDebugger.log(this, ""); + TestDebugger.log(this, "[D_testDeleteRankUpdatePlayer] Start"); + + Player player1 = Mock.getPlayer(0); + Player player2 = Mock.getPlayer(1); + PRPlayer prPlayer2 = CacheManager.getPlayer(player2.getUniqueId().toString()); + + player1.setOp(true); + player2.setOp(false); + + server.execute("pr", player1, "createrank", "testDeleteRankUpdatePlayer"); + server.execute("pr", player1, "setrank", player2.getName(), "testDeleteRankUpdatePlayer"); + + assertTrue(prPlayer2.getRanks().stream().anyMatch(rank -> rank.getName().equals("testDeleteRankUpdatePlayer"))); + CacheManager.removeRank(CacheManager.getRank("testDeleteRankUpdatePlayer")); + assertTrue(!prPlayer2.getRanks().stream().anyMatch(rank -> rank.getName().equals("testDeleteRankUpdatePlayer"))); + + TestDebugger.log(this, "[D_testDeleteRankUpdatePlayer] OK"); + + } +} diff --git a/Bukkit/src/test/java/nl/svenar/powerranks/test/util/Mock.java b/Bukkit/src/test/java/nl/svenar/powerranks/test/util/Mock.java new file mode 100644 index 00000000..c3713282 --- /dev/null +++ b/Bukkit/src/test/java/nl/svenar/powerranks/test/util/Mock.java @@ -0,0 +1,58 @@ +package nl.svenar.powerranks.test.util; + +import static org.junit.Assert.assertNotNull; + +import org.bukkit.entity.Player; + +import be.seeseemelk.mockbukkit.MockBukkit; +import be.seeseemelk.mockbukkit.ServerMock; +import be.seeseemelk.mockbukkit.UnimplementedOperationException; +import nl.svenar.powerranks.bukkit.PowerRanks; + +public class Mock { + + private static ServerMock serverMock; + private static PowerRanks plugin; + + public static ServerMock getServerMock() { + return serverMock; + } + + public static void init() { + if (serverMock != null) { + return; + } + + serverMock = MockBukkit.mock(); + plugin = MockBukkit.load(PowerRanks.class); + } + + public static void unmock() { + if (serverMock == null) { + return; + } + + // MockBukkit.unmock(); + // serverMock = null; + // plugin = null; + } + + public static Player getPlayer(int num) { + if (serverMock == null) { + return null; + } + + Player player = null; + try { + player = serverMock.getPlayer(num); + } catch (UnimplementedOperationException e) { + e.printStackTrace(); + } + assertNotNull(player); + return player; + } + + public static PowerRanks getPlugin() { + return plugin; + } +} diff --git a/Bukkit/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java b/Bukkit/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java new file mode 100644 index 00000000..332cdf2b --- /dev/null +++ b/Bukkit/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java @@ -0,0 +1,26 @@ +package nl.svenar.powerranks.test.util; + +import java.time.Duration; +import java.time.Instant; +import java.util.Objects; + +public class TestDebugger { + + private static boolean DEBUG = true; + public static boolean DOPERFORMANCETEST = false; + private static Instant startTime; + private static String lastClassName = ""; + + public static void log(Object clazz, String message) { + if (!DEBUG) + return; + + if (Objects.isNull(startTime) || !clazz.getClass().getSimpleName().equals(lastClassName)) { + lastClassName = clazz.getClass().getSimpleName(); + startTime = Instant.now(); + } + + System.out.println("[" + String.format("%04d", Duration.between(startTime, Instant.now()).toMillis()) + "ms] [" + + clazz.getClass().getSimpleName() + "] " + message); + } +} \ No newline at end of file diff --git a/Core/pom.xml b/Core/pom.xml new file mode 100644 index 00000000..77f74bea --- /dev/null +++ b/Core/pom.xml @@ -0,0 +1,212 @@ + + 4.0.0 + nl.svenar + powerranks.core + ${revision} + PowerRanks Core + Rank-based permission manager + + + 1.8 + UTF-8 + src/main/java + src/main/resources + nl.svenar.lib + false + + + + nl.svenar + powerranks + ${revision} + + + + clean compile package + ${project.name} + ${src.dir} + + + ${rsc.dir} + true + + + + + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + true + false + false + false + false + + + *:* + + META-INF/license/** + META-INF/* + META-INF/maven/** + META-INF/versions/*/module-info.class + LICENSE + NOTICE + /*.txt + build.properties + com/fasterxml/jackson/databind/ext/Java7* + + + + + + com.squareup.okhttp3:okhttp + com.squareup.okio:okio + org.jetbrains.kotlin:kotlin-stdlib + org.yaml:snakeyaml + com.fasterxml.jackson.core:jackson-core + com.fasterxml.jackson.core:jackson-databind + com.fasterxml.jackson.core:jackson-annotations + com.fasterxml.jackson.dataformat:jackson-dataformat-yaml + com.googlecode.json-simple:json-simple + + + + + okhttp3 + ${shade.basepattern}.okhttp3 + + + okio + ${shade.basepattern}.okio + + + kotlin + ${shade.basepattern}.kotlin + + + org.yaml + ${shade.basepattern}.yaml + + + com.fasterxml + ${shade.basepattern}.fasterxml + + + org.json + ${shade.basepattern}.json + + + target/reduced-pom.xml + + + + package + + shade + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.1 + + ${skipCoreTests} + + + + + + + + jitpack.io + https://jitpack.io + + + svenar + https://svenar.nl/repo/ + + + + + + com.mysql + mysql-connector-j + 8.1.0 + test + + + org.xerial + sqlite-jdbc + 3.42.0.1 + test + + + + com.squareup.okhttp3 + okhttp + 4.9.3 + jar + + + org.yaml + snakeyaml + [2.0,) + jar + + + com.googlecode.json-simple + json-simple + 1.1 + jar + + + com.google.code.gson + gson + 2.10.1 + + + com.google.guava + guava + 32.1.3-jre + + + + com.fasterxml.jackson.core + jackson-core + 2.13.4 + + + com.fasterxml.jackson.core + jackson-databind + 2.13.4.2 + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.4 + jar + + + \ No newline at end of file diff --git a/src/main/java/nl/svenar/common/PowerLogger.java b/Core/src/main/java/nl/svenar/powerranks/common/PowerLogger.java similarity index 98% rename from src/main/java/nl/svenar/common/PowerLogger.java rename to Core/src/main/java/nl/svenar/powerranks/common/PowerLogger.java index a74c0852..cd617d0b 100644 --- a/src/main/java/nl/svenar/common/PowerLogger.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/PowerLogger.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common; +package nl.svenar.powerranks.common; import java.util.Objects; import java.util.logging.Logger; diff --git a/src/main/java/nl/svenar/common/http/DatabinClient.java b/Core/src/main/java/nl/svenar/powerranks/common/http/DatabinClient.java similarity index 97% rename from src/main/java/nl/svenar/common/http/DatabinClient.java rename to Core/src/main/java/nl/svenar/powerranks/common/http/DatabinClient.java index 72e0dd03..08fbb9ea 100644 --- a/src/main/java/nl/svenar/common/http/DatabinClient.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/http/DatabinClient.java @@ -1,4 +1,4 @@ -package nl.svenar.common.http; +package nl.svenar.powerranks.common.http; import java.io.IOException; import java.lang.reflect.Type; @@ -8,7 +8,7 @@ import com.google.common.reflect.TypeToken; import com.google.gson.Gson; -import nl.svenar.common.PowerLogger; +import nl.svenar.powerranks.common.PowerLogger; import okhttp3.Call; import okhttp3.OkHttpClient; import okhttp3.Request; diff --git a/src/main/java/nl/svenar/common/http/PowerHTTPClient.java b/Core/src/main/java/nl/svenar/powerranks/common/http/PowerHTTPClient.java similarity index 98% rename from src/main/java/nl/svenar/common/http/PowerHTTPClient.java rename to Core/src/main/java/nl/svenar/powerranks/common/http/PowerHTTPClient.java index 13b6f888..e79e304e 100644 --- a/src/main/java/nl/svenar/common/http/PowerHTTPClient.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/http/PowerHTTPClient.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.http; +package nl.svenar.powerranks.common.http; import java.io.IOException; diff --git a/src/main/java/nl/svenar/common/serializer/PRSerializer.java b/Core/src/main/java/nl/svenar/powerranks/common/serializer/PRSerializer.java similarity index 96% rename from src/main/java/nl/svenar/common/serializer/PRSerializer.java rename to Core/src/main/java/nl/svenar/powerranks/common/serializer/PRSerializer.java index 03526883..7754d807 100644 --- a/src/main/java/nl/svenar/common/serializer/PRSerializer.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/serializer/PRSerializer.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.serializer; +package nl.svenar.powerranks.common.serializer; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -30,8 +30,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * Serializes a given object into a Java map & deserializes a Java map into an diff --git a/Core/src/main/java/nl/svenar/powerranks/common/storage/PermissionRegistry.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/PermissionRegistry.java new file mode 100644 index 00000000..af90dfe0 --- /dev/null +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/PermissionRegistry.java @@ -0,0 +1,40 @@ +package nl.svenar.powerranks.common.storage; + +import java.util.HashSet; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.ConcurrentLinkedQueue; + +public class PermissionRegistry { + + private Set permissions = new HashSet(); + private Queue queue = new ConcurrentLinkedQueue<>(); + + public PermissionRegistry() { + } + + public void queuePermission(String permissionNode) { + this.queue.add(permissionNode); + } + + public void tick() { + String permissionNode = this.queue.poll(); + if (permissionNode != null) { + addPermission(permissionNode); + } + } + + private void addPermission(String permissionNode) { + if (permissionNode == null || permissionNode.isEmpty()) { + return; + } + if (permissions.contains(permissionNode)) { + return; + } + permissions.add(permissionNode); + } + + public Set getPermissions() { + return permissions; + } +} diff --git a/src/main/java/nl/svenar/common/storage/PowerConfigManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/PowerConfigManager.java similarity index 99% rename from src/main/java/nl/svenar/common/storage/PowerConfigManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/PowerConfigManager.java index c0177c39..544f1820 100644 --- a/src/main/java/nl/svenar/common/storage/PowerConfigManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/PowerConfigManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage; +package nl.svenar.powerranks.common.storage; import java.io.File; import java.io.FileNotFoundException; diff --git a/src/main/java/nl/svenar/common/storage/PowerSQLConfiguration.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/PowerSQLConfiguration.java similarity index 94% rename from src/main/java/nl/svenar/common/storage/PowerSQLConfiguration.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/PowerSQLConfiguration.java index 0a968c27..1836cbb0 100644 --- a/src/main/java/nl/svenar/common/storage/PowerSQLConfiguration.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/PowerSQLConfiguration.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage; +package nl.svenar.powerranks.common.storage; /** * Basic SQL connection data structure to store common connection information. @@ -39,6 +39,7 @@ public class PowerSQLConfiguration { private String tableRanks; private String tablePlayers; private String tableMessages; + private boolean silentErrors; /** * Constructor to initialize SQL connection data @@ -55,7 +56,7 @@ public class PowerSQLConfiguration { */ public PowerSQLConfiguration(String host, int port, String database, String username, String password, boolean useSSL, - String tableRanks, String tablePlayers, String tableMessages) { + String tableRanks, String tablePlayers, String tableMessages, boolean silentErrors) { this.host = host; this.port = port; this.database = database; @@ -65,6 +66,7 @@ public PowerSQLConfiguration(String host, int port, String database, String user this.tableRanks = tableRanks; this.tablePlayers = tablePlayers; this.tableMessages = tableMessages; + this.silentErrors = silentErrors; } /** @@ -141,4 +143,8 @@ public String getTablePlayers() { public String getTableMessages() { return this.tableMessages; } + + public boolean silentErrors() { + return this.silentErrors; + } } diff --git a/src/main/java/nl/svenar/common/storage/PowerStorageManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/PowerStorageManager.java similarity index 97% rename from src/main/java/nl/svenar/common/storage/PowerStorageManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/PowerStorageManager.java index 4472726a..85ac997b 100644 --- a/src/main/java/nl/svenar/common/storage/PowerStorageManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/PowerStorageManager.java @@ -22,16 +22,16 @@ * SOFTWARE. */ -package nl.svenar.common.storage; +package nl.svenar.powerranks.common.storage; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; -import nl.svenar.common.serializer.PRSerializer; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.serializer.PRSerializer; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * Storage core that can be implemented in multiple storage methods (for diff --git a/Core/src/main/java/nl/svenar/powerranks/common/storage/StorageLoader.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/StorageLoader.java new file mode 100644 index 00000000..97e15b7d --- /dev/null +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/StorageLoader.java @@ -0,0 +1,104 @@ +package nl.svenar.powerranks.common.storage; + +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.storage.provided.MySQLStorageManager; +import nl.svenar.powerranks.common.storage.provided.PSMStorageManager; +import nl.svenar.powerranks.common.storage.provided.SQLiteStorageManager; +import nl.svenar.powerranks.common.storage.provided.YAMLStorageManager; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; + +public class StorageLoader { + + public PowerStorageManager getStorageManager(String dataDirectory, String storageType) { + return getStorageManager(dataDirectory, storageType, null); + } + + public PowerStorageManager getStorageManager(String dataDirectory, String storageType, PowerSQLConfiguration sqlConfiguration) { + PowerStorageManager storageManager = null; + storageType = storageType.toUpperCase(); + + switch (storageType) { + case "JSON": + storageManager = new JSONStorageManager(dataDirectory, "ranks.json", "players.json"); + break; + case "PSM": + storageManager = new PSMStorageManager(dataDirectory, "ranks.psm", "players.psm"); + break; + case "SQLITE": + storageManager = new SQLiteStorageManager(dataDirectory, "ranks.db", "players.db"); + break; + case "MYSQL": + if (sqlConfiguration == null) { + throw new IllegalArgumentException("sqlConfiguration cannot be null when using MYSQL storage type"); + } + storageManager = new MySQLStorageManager(sqlConfiguration); + break; + case "YML": + case "YAML": + storageManager = new YAMLStorageManager(dataDirectory, "ranks.yml", "players.yml"); + + default: + break; + } + + return storageManager; + } + + public void loadData(PowerStorageManager storageManager) { + if (storageManager == null) { + throw new IllegalArgumentException("storageManager cannot be null"); + } + + storageManager.loadAll(); + + PRCache.setRanks(storageManager.getRanks()); + PRCache.setPlayers(storageManager.getPlayers()); + + populateInitialData(storageManager); + } + + public void saveData(PowerStorageManager storageManager) { + storageManager.setRanks(PRCache.getRanks()); + storageManager.setPlayers(PRCache.getPlayers()); + + storageManager.saveAll(); + } + + private void populateInitialData(PowerStorageManager storageManager) { + if (PRCache.getRanks().size() > 0) { + return; + } + + PRRank rankMember = new PRRank(); + rankMember.setName("Member"); + rankMember.setDefault(true); + rankMember.setWeight(0); + rankMember.setPrefix("[gradient=#127e00,#3eaf18]MEMBER[/gradient]"); + + PRRank rankModerator = new PRRank(); + rankModerator.setName("Moderator"); + rankModerator.setDefault(false); + rankModerator.setWeight(50); + rankModerator.setPrefix("[gradient=#9d1dff,#e22581]MODERATOR[/gradient]"); + + PRRank rankAdmin = new PRRank(); + rankAdmin.setName("Admin"); + rankAdmin.setDefault(false); + rankAdmin.setWeight(75); + rankAdmin.setPrefix("[gradient=#ffff00,#ef3300]ADMIN[/gradient]"); + + PRRank rankOwner = new PRRank(); + rankOwner.setName("Owner"); + rankOwner.setDefault(false); + rankOwner.setWeight(100); + rankOwner.setPrefix("[gradient=#ff00ff,#33ccff]OWNER[/gradient]"); + + PRCache.addRank(rankMember); + PRCache.addRank(rankModerator); + PRCache.addRank(rankAdmin); + PRCache.addRank(rankOwner); + + saveData(storageManager); + } +} diff --git a/src/main/java/nl/svenar/common/storage/provided/JSONStorageManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/JSONStorageManager.java similarity index 98% rename from src/main/java/nl/svenar/common/storage/provided/JSONStorageManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/provided/JSONStorageManager.java index 04478476..5eb07756 100644 --- a/src/main/java/nl/svenar/common/storage/provided/JSONStorageManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/JSONStorageManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage.provided; +package nl.svenar.powerranks.common.storage.provided; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -43,9 +43,9 @@ import com.google.gson.internal.LinkedTreeMap; import com.google.gson.reflect.TypeToken; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * JSON storage manager implementation using PowerStorageManager as base. diff --git a/src/main/java/nl/svenar/common/storage/provided/MySQLStorageManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/MySQLStorageManager.java similarity index 95% rename from src/main/java/nl/svenar/common/storage/provided/MySQLStorageManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/provided/MySQLStorageManager.java index 5b81bff3..0dad3d93 100644 --- a/src/main/java/nl/svenar/common/storage/provided/MySQLStorageManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/MySQLStorageManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage.provided; +package nl.svenar.powerranks.common.storage.provided; import java.lang.reflect.Type; import java.sql.Connection; @@ -42,10 +42,10 @@ import com.google.common.reflect.TypeToken; import com.google.gson.Gson; -import nl.svenar.common.storage.PowerSQLConfiguration; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.storage.PowerSQLConfiguration; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * MySQL storage manager implementation using PowerStorageManager as base. @@ -56,7 +56,6 @@ public class MySQLStorageManager extends PowerStorageManager { private Connection connection; private PowerSQLConfiguration sqlConfig; - private boolean hideErrors; /** * Initialize this storage method by connecting to the external database @@ -64,17 +63,16 @@ public class MySQLStorageManager extends PowerStorageManager { * @param sqlConfig * @param hideErrors */ - public MySQLStorageManager(PowerSQLConfiguration sqlConfig, boolean hideErrors) { + public MySQLStorageManager(PowerSQLConfiguration sqlConfig) { this.sqlConfig = sqlConfig; - this.hideErrors = hideErrors; - + try { Class.forName("com.mysql.cj.jdbc.Driver"); } catch (ClassNotFoundException e) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException ex) { - if (!hideErrors) + if (!sqlConfig.silentErrors()) ex.printStackTrace(); } } @@ -95,7 +93,7 @@ private void reconnect() { sqlConfig.getUsername(), sqlConfig.getPassword()); } catch (SQLException e) { - if (!this.hideErrors) + if (!this.sqlConfig.silentErrors()) e.printStackTrace(); } } @@ -125,6 +123,18 @@ public boolean isConnected() { } } + /** + * Close the connection to the database + */ + public void close() { + try { + this.connection.close(); + } catch (SQLException e) { + if (!this.sqlConfig.silentErrors()) + e.printStackTrace(); + } + } + /** * Create the database */ @@ -144,12 +154,12 @@ private void setupDatabase() { private void setupTables() { try { - String query = SQLCreateDatabase(this.sqlConfig.getDatabase()); - int result = this.connection.createStatement().executeUpdate(query); - checkSQLResult(result, query); + // String query = SQLCreateDatabase(this.sqlConfig.getDatabase()); + // int result = this.connection.createStatement().executeUpdate(query); + // checkSQLResult(result, query); - query = SQLCreateTable(this.sqlConfig.getDatabase(), this.sqlConfig.getTableRanks()); - result = this.connection.createStatement().executeUpdate(query); + String query = SQLCreateTable(this.sqlConfig.getDatabase(), this.sqlConfig.getTableRanks()); + int result = this.connection.createStatement().executeUpdate(query); checkSQLResult(result, query); query = SQLCreateTable(this.sqlConfig.getDatabase(), this.sqlConfig.getTablePlayers()); diff --git a/src/main/java/nl/svenar/common/storage/provided/PSMStorageManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/PSMStorageManager.java similarity index 98% rename from src/main/java/nl/svenar/common/storage/provided/PSMStorageManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/provided/PSMStorageManager.java index ff232653..56c2cd95 100644 --- a/src/main/java/nl/svenar/common/storage/provided/PSMStorageManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/PSMStorageManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage.provided; +package nl.svenar.powerranks.common.storage.provided; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -42,9 +42,9 @@ import com.google.common.reflect.TypeToken; import com.google.gson.Gson; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * PSM (Power Storage Method) storage manager implementation using PowerStorageManager as base. diff --git a/src/main/java/nl/svenar/common/storage/provided/SQLiteStorageManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/SQLiteStorageManager.java similarity index 95% rename from src/main/java/nl/svenar/common/storage/provided/SQLiteStorageManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/provided/SQLiteStorageManager.java index d6b864bd..db497ac3 100644 --- a/src/main/java/nl/svenar/common/storage/provided/SQLiteStorageManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/SQLiteStorageManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage.provided; +package nl.svenar.powerranks.common.storage.provided; import java.io.File; import java.io.IOException; @@ -44,9 +44,9 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * SQLite storage manager implementation using PowerStorageManager as base. @@ -119,7 +119,26 @@ public String getType() { * @return true if connected, false otherwise */ public boolean isConnected() { - return true; + try { + if (Objects.isNull(this.ranksSQLConnection) || Objects.isNull(this.ranksSQLConnection)) { + return false; + } + return !this.ranksSQLConnection.isClosed() && !this.playersSQLConnection.isClosed(); + } catch (SQLException e) { + return false; + } + } + + /** + * Close the connection to the database + */ + public void close() { + try { + this.ranksSQLConnection.close(); + this.playersSQLConnection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } /** diff --git a/src/main/java/nl/svenar/common/storage/provided/YAMLConfigManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/YAMLConfigManager.java similarity index 97% rename from src/main/java/nl/svenar/common/storage/provided/YAMLConfigManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/provided/YAMLConfigManager.java index 85ff84bc..6cb23005 100644 --- a/src/main/java/nl/svenar/common/storage/provided/YAMLConfigManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/YAMLConfigManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage.provided; +package nl.svenar.powerranks.common.storage.provided; import java.io.File; import java.io.FileInputStream; @@ -37,7 +37,7 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; -import nl.svenar.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.PowerConfigManager; import org.yaml.snakeyaml.constructor.Constructor; diff --git a/src/main/java/nl/svenar/common/storage/provided/YAMLStorageManager.java b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/YAMLStorageManager.java similarity index 97% rename from src/main/java/nl/svenar/common/storage/provided/YAMLStorageManager.java rename to Core/src/main/java/nl/svenar/powerranks/common/storage/provided/YAMLStorageManager.java index 4e2b6b75..b7cfc7a6 100644 --- a/src/main/java/nl/svenar/common/storage/provided/YAMLStorageManager.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/storage/provided/YAMLStorageManager.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.storage.provided; +package nl.svenar.powerranks.common.storage.provided; import java.io.File; import java.io.FileInputStream; @@ -43,9 +43,9 @@ import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.representer.Representer; -import nl.svenar.common.storage.PowerStorageManager; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; /** * YAML storage manager implementation using PowerStorageManager as base. diff --git a/src/main/java/nl/svenar/common/structure/PRPermission.java b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRPermission.java similarity index 98% rename from src/main/java/nl/svenar/common/structure/PRPermission.java rename to Core/src/main/java/nl/svenar/powerranks/common/structure/PRPermission.java index bd2096e9..e0c22541 100644 --- a/src/main/java/nl/svenar/common/structure/PRPermission.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRPermission.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.structure; +package nl.svenar.powerranks.common.structure; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; diff --git a/src/main/java/nl/svenar/common/structure/PRPlayer.java b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRPlayer.java similarity index 71% rename from src/main/java/nl/svenar/common/structure/PRPlayer.java rename to Core/src/main/java/nl/svenar/powerranks/common/structure/PRPlayer.java index ff47e89b..e9b3e5fe 100755 --- a/src/main/java/nl/svenar/common/structure/PRPlayer.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRPlayer.java @@ -22,20 +22,22 @@ * SOFTWARE. */ -package nl.svenar.common.structure; +package nl.svenar.powerranks.common.structure; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; import java.util.UUID; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -import nl.svenar.common.utils.PRCache; -import nl.svenar.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; import java.util.Map.Entry; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + /** * Structure to store player data. * @@ -46,18 +48,14 @@ public class PRPlayer { // Storage private UUID uuid; - private String name; - private ArrayList ranks; - private ArrayList permissions; - private ArrayList usertags; - private long playtime; + private String name = ""; + private String nickname = ""; + private Set ranks = new HashSet(); + private Set permissions = new HashSet(); + private Set usertags = new HashSet(); + private long playtime = 0L; public PRPlayer() { - this.name = ""; - this.ranks = new ArrayList(); - this.permissions = new ArrayList(); - this.usertags = new ArrayList(); - this.playtime = 0L; } /** @@ -96,12 +94,30 @@ public void setName(String name) { this.name = name; } + /** + * Get the nickname of this player + * + * @return String nickname of the player + */ + public String getNickname() { + return this.nickname; + } + + /** + * Set the nickname of this player + * + * @param nickname + */ + public void setNickname(String nickname) { + this.nickname = nickname; + } + /** * Get the rank of this player * * @return String rank of the player */ - public List getRanks() { + public Set getRanks() { return this.ranks; } @@ -127,7 +143,7 @@ public List getDefaultRanks() { * * @param ranks */ - public void setRanks(ArrayList ranks) { + public void setRanks(Set ranks) { this.ranks = ranks; } @@ -152,6 +168,16 @@ public void addRank(PRPlayerRank rank) { } } + + /** + * Add a rank on this player + * + * @param rank + */ + public void addRank(PRRank rank) { + addRank(new PRPlayerRank(rank.getName())); + } + /** * Remove a rank on this player * @@ -183,7 +209,7 @@ public boolean hasRank(String rankName) { * * @return Java ArrayList with all PRPermission instances */ - public ArrayList getPermissions() { + public Set getPermissions() { return this.permissions; } @@ -192,7 +218,7 @@ public ArrayList getPermissions() { * * @param permissions */ - public void setPermissions(ArrayList permissions) { + public void setPermissions(HashSet permissions) { this.permissions = permissions; } @@ -203,7 +229,7 @@ public void setPermissions(ArrayList permissions) { */ public void addPermission(PRPermission permission) { if (this.permissions == null) { - this.permissions = new ArrayList(); + this.permissions = new HashSet(); } this.permissions.add(permission); @@ -222,6 +248,73 @@ public void removePermission(PRPermission permission) { this.permissions.remove(permission); } + /** + * Update the permissions of this player from the ranks it has + */ + public void updatePermissionsFromRanks() { + if (this.permissions == null) { + this.permissions = new HashSet(); + } else { + this.permissions.clear(); + } + + List playerRanks = new ArrayList<>(); + for (PRPlayerRank playerRank : this.getRanks()) { + if (!playerRank.isDisabled()) { + PRRank rank = PRCache.getRank(playerRank.getName()); + if (rank != null) { + playerRanks.add(rank); + } + } + } + + PRUtil.sortRanksByWeight(playerRanks); + for (PRRank playerRank : playerRanks) { + if (Objects.nonNull(playerRank)) { + for (PRPermission permission : playerRank.getPermissions()) { + for (PRPermission existingPermission : this.permissions) { + if (permission.getName().equals(existingPermission.getName())) { + this.permissions.remove(existingPermission); + break; + } + } + this.permissions.add(permission); + } + } + } + + } + + /** + * Check if this player has a specific permission + * + * @param name + * @param wildcard + * @return true if this player has that permission, false otherwise + */ + public boolean hasPermission(String name, boolean wildcard) { + PRPermission permission = getPermission(name, wildcard); + if (permission != null) { + return true; + } + return false; + } + + /** + * Check if a specific permission is allowed for this player + * + * @param name + * @param wildcard + * @return true if this permission is allowed, false otherwise + */ + public boolean isPermissionAllowed(String name, boolean wildcard) { + PRPermission permission = getPermission(name, wildcard); + if (permission != null) { + return permission.getValue(); + } + return false; + } + /** * Get a permission by a String permission node (Eg. permission.node.123) * @@ -230,8 +323,19 @@ public void removePermission(PRPermission permission) { * instance was found */ public PRPermission getPermission(String name) { + return getPermission(name, false); + } + + /** + * Get a permission by a String permission node (Eg. permission.node.123) + * + * @param name + * @return PRPermission instance for the provided node, null if no PRPermission + * instance was found + */ + public PRPermission getPermission(String name, boolean wildcard) { if (this.permissions == null) { - this.permissions = new ArrayList(); + this.permissions = new HashSet(); } for (PRPermission permission : this.permissions) { @@ -239,6 +343,15 @@ public PRPermission getPermission(String name) { return permission; } } + + if (wildcard) { + List wildcardPermissions = PRUtil.generateWildcardList(name); + for (PRPermission permission : this.permissions) { + if (wildcardPermissions.contains(permission.getName())) { + return permission; + } + } + } return null; } @@ -325,7 +438,7 @@ public void setPlaytime(long playtime) { * * @return Java ArrayList with all stored usertag */ - public ArrayList getUsertags() { + public Set getUsertags() { return this.usertags; } @@ -334,7 +447,7 @@ public ArrayList getUsertags() { * * @param usertags */ - public void setUsertags(ArrayList usertags) { + public void setUsertags(Set usertags) { this.usertags = usertags; } @@ -344,7 +457,7 @@ public void setUsertags(ArrayList usertags) { * @param usertag */ public void setUsertag(String usertag) { - this.usertags = new ArrayList(); + this.usertags = new HashSet(); this.usertags.add(usertag); } @@ -356,7 +469,7 @@ public void setUsertag(String usertag) { */ public void addUsertag(String usertag) { if (Objects.isNull(this.usertags)) { - this.usertags = new ArrayList(); + this.usertags = new HashSet(); } if (!this.usertags.contains(usertag)) { @@ -385,7 +498,7 @@ public void removeUsertag(String usertag) { */ public boolean hasUsertag(String usertag) { if (Objects.isNull(this.usertags)) { - this.usertags = new ArrayList(); + this.usertags = new HashSet(); } for (String tag : this.usertags) { @@ -459,4 +572,15 @@ public void updateTags(String worldName) { } } } + + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof PRPlayer)) { + return false; + } + + PRPlayer prPlayer = (PRPlayer) obj; + + return this.getUUID().equals(prPlayer.getUUID()); + } } diff --git a/src/main/java/nl/svenar/common/structure/PRPlayerRank.java b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRPlayerRank.java similarity index 92% rename from src/main/java/nl/svenar/common/structure/PRPlayerRank.java rename to Core/src/main/java/nl/svenar/powerranks/common/structure/PRPlayerRank.java index f957d1a2..9f8a3cf4 100644 --- a/src/main/java/nl/svenar/common/structure/PRPlayerRank.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRPlayerRank.java @@ -22,15 +22,15 @@ * SOFTWARE. */ -package nl.svenar.common.structure; +package nl.svenar.powerranks.common.structure; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import nl.svenar.powerranks.common.utils.PRUtil; -import nl.svenar.powerranks.util.Util; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties("disabled") public class PRPlayerRank { @@ -49,6 +49,10 @@ public PRPlayerRank(String name) { this.name = name; } + public PRPlayerRank(PRRank rank) { + this(rank.getName()); + } + public String getName() { return this.name; } @@ -67,7 +71,7 @@ public void addTag(String tagName, Object tagValue) { if (tagName.equalsIgnoreCase("expires")) { long currentTimeMillis = System.currentTimeMillis(); - tagValue = Util.timeStringToSecondsConverter(String.valueOf(tagValue)); + tagValue = PRUtil.timeStringToSecondsConverter(String.valueOf(tagValue)); tagValue = currentTimeMillis + ((int) tagValue * 1000); } diff --git a/src/main/java/nl/svenar/common/structure/PRRank.java b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRRank.java similarity index 99% rename from src/main/java/nl/svenar/common/structure/PRRank.java rename to Core/src/main/java/nl/svenar/powerranks/common/structure/PRRank.java index a42be2a9..1aea8edf 100644 --- a/src/main/java/nl/svenar/common/structure/PRRank.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/structure/PRRank.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.structure; +package nl.svenar.powerranks.common.structure; import java.util.ArrayList; import java.util.Objects; diff --git a/src/main/java/nl/svenar/common/utils/AsyncReadFile.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/AsyncReadFile.java similarity index 98% rename from src/main/java/nl/svenar/common/utils/AsyncReadFile.java rename to Core/src/main/java/nl/svenar/powerranks/common/utils/AsyncReadFile.java index e96afeb4..464f5a43 100644 --- a/src/main/java/nl/svenar/common/utils/AsyncReadFile.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/AsyncReadFile.java @@ -1,4 +1,4 @@ -package nl.svenar.common.utils; +package nl.svenar.powerranks.common.utils; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/src/main/java/nl/svenar/common/utils/Color.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/Color.java similarity index 98% rename from src/main/java/nl/svenar/common/utils/Color.java rename to Core/src/main/java/nl/svenar/powerranks/common/utils/Color.java index 4adf48ea..1a6a5bdb 100644 --- a/src/main/java/nl/svenar/common/utils/Color.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/Color.java @@ -1,4 +1,4 @@ -package nl.svenar.common.utils; +package nl.svenar.powerranks.common.utils; public class Color { private static final int BIT_MASK = 0xff; diff --git a/src/main/java/nl/svenar/common/utils/PRCache.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/PRCache.java similarity index 51% rename from src/main/java/nl/svenar/common/utils/PRCache.java rename to Core/src/main/java/nl/svenar/powerranks/common/utils/PRCache.java index 4032da99..104dca08 100755 --- a/src/main/java/nl/svenar/common/utils/PRCache.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/PRCache.java @@ -1,20 +1,31 @@ -package nl.svenar.common.utils; +package nl.svenar.powerranks.common.utils; import java.util.ArrayList; -import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeMap; import java.util.UUID; +import java.util.stream.Collectors; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; public class PRCache { - private static Map registeredRanks = new HashMap(); - private static Map registeredPlayersByName = new HashMap(); - private static Map registeredPlayersByUUID = new HashMap(); + private static Map registeredRanks = new TreeMap(); + private static Map registeredPlayersByName = new TreeMap(); + private static Map registeredPlayersByUUID = new TreeMap(); + private static Set defaultRanks = new HashSet(); + + public static void reset() { + registeredRanks.clear(); + registeredPlayersByName.clear(); + registeredPlayersByUUID.clear(); + defaultRanks.clear(); + } public static List getRanks() { return new ArrayList<>(registeredRanks.values()); @@ -26,8 +37,12 @@ public static void setRanks(List ranks) { } registeredRanks.clear(); + defaultRanks.clear(); for (PRRank rank : ranks) { registeredRanks.put(rank.getName(), rank); + if (rank.isDefault()) { + defaultRanks.add(rank); + } } } @@ -37,6 +52,10 @@ public static void addRank(PRRank rank) { } registeredRanks.put(rank.getName(), rank); + if (rank.isDefault()) { + defaultRanks.add(rank); + } + } public static void removeRank(PRRank rank) { @@ -44,20 +63,38 @@ public static void removeRank(PRRank rank) { throw new NullPointerException("rank is null"); } - registeredRanks.remove(rank.getName()); + String rankName = rank.getName(); + + registeredRanks.remove(rankName); + defaultRanks.remove(rank); + + for (PRPlayer prPlayer : registeredPlayersByName.values()) { + if (prPlayer.hasRank(rankName)) { + prPlayer.getRanks() + .removeIf(prPlayerRank -> prPlayerRank.getName().equalsIgnoreCase(rankName)); + + } + } } public static PRRank getRank(String name) { return registeredRanks.get(name); } - public static List getDefaultRanks() { - List defaultRanks = new ArrayList(); - for (PRRank rank : getRanks()) { - if (rank.isDefault()) { - defaultRanks.add(rank); + public static PRRank getRankIgnoreCase(String name) { + PRRank rank = getRank(name); + if (rank != null) { + return rank; + } + for (PRRank prRank : registeredRanks.values()) { + if (prRank.getName().equalsIgnoreCase(name)) { + return prRank; } } + return null; + } + + public static Set getDefaultRanks() { return defaultRanks; } @@ -93,7 +130,7 @@ public static void removePlayer(PRPlayer player) { } for (PRPlayer prPlayer : registeredPlayersByName.values()) { - if (prPlayer.getName().equals(player.getName()) && prPlayer.getUUID().equals(player.getUUID())) { + if (prPlayer.equals(player)) { registeredPlayersByName.remove(prPlayer.getName()); registeredPlayersByUUID.remove(prPlayer.getUUID()); break; @@ -115,15 +152,53 @@ public static PRPlayer getPlayer(String identifier) { } public static PRPlayer createPlayer(String name, UUID uniqueID) { + for (PRPlayer prPlayer : getPlayers()) { + if (prPlayer.getUUID().toString().equalsIgnoreCase(uniqueID.toString())) { + return null; + } + } + PRPlayer prPlayer = new PRPlayer(); prPlayer.setUUID(uniqueID); prPlayer.setName(name); - for (PRRank rank : getDefaultRanks()) { - PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); - prPlayer.addRank(playerRank); - } + + Set playerRanks = getDefaultRanks().stream() + .map(PRPlayerRank::new) + .collect(Collectors.toSet()); + + prPlayer.setRanks(playerRanks); + addPlayer(prPlayer); return prPlayer; } + public static PRRank createRank(String name) { + return createRank(name, "&r[&7" + name + "&r]", "", 0, false); + } + + public static PRRank createRank(String name, int weight) { + return createRank(name, "&r[&7" + name + "&r]", "", weight, false); + } + + public static PRRank createRank(String name, String prefix, String suffix, int weight) { + return createRank(name, prefix, suffix, weight, false); + } + + public static PRRank createRank(String name, String prefix, String suffix, int weight, boolean isDefault) { + for (PRRank prRank : getRanks()) { + if (prRank.getName().equalsIgnoreCase(name)) { + return null; + } + } + + PRRank rank = new PRRank(); + rank.setName(name); + rank.setPrefix(prefix); + rank.setSuffix(suffix); + rank.setWeight(weight); + rank.setDefault(isDefault); + addRank(rank); + return rank; + } + } diff --git a/Core/src/main/java/nl/svenar/powerranks/common/utils/PRUtil.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/PRUtil.java new file mode 100644 index 00000000..02a7e98a --- /dev/null +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/PRUtil.java @@ -0,0 +1,265 @@ +/** + * This file is part of PowerRanks, licensed under the MIT License. + * + * Copyright (c) svenar (Sven) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +*/ + +package nl.svenar.powerranks.common.utils; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import nl.svenar.powerranks.common.structure.PRRank; + +public class PRUtil { + + private static Map playerPlayTimeCache = new HashMap(); + + /** + * Sort a list of ranks by weight + * + * @param ranks + */ + public static void sortRanksByWeight(List ranks) { + ranks.removeIf(Objects::isNull); + + ranks.sort(Comparator.comparingInt(PRRank::getWeight)); + } + + /** + * Reverse a list of ranks + * + * @param ranks + */ + public static void reverseRanks(List ranks) { + Collections.reverse(ranks); + } + + /** + * Check if a list of strings contains a string (case insensitive) + * + * @param objects + * @param object + * @return boolean + */ + public static boolean containsIgnoreCase(List objects, String object) { + for (String obj : objects) { + if (obj.equalsIgnoreCase(object)) { + return true; + } + } + return false; + } + + /** + * Check if a list of strings contains a string (case sensitive) + * + * @param inputStr + * @param items + * @return boolean + */ + public static boolean stringContainsItemFromList(String inputStr, String[] items) { + return Arrays.stream(items).anyMatch(inputStr::contains); + } + + /** + * Convert a time string to seconds + * + * @param time_input + * @return + */ + public static int timeStringToSecondsConverter(String time_input) { + Matcher regex_int = Pattern.compile("^\\d+[^a-zA-Z]{0,1}$").matcher(time_input); + + Matcher regex_seconds = Pattern.compile("\\d+[sS]").matcher(time_input); + Matcher regex_minutes = Pattern.compile("\\d+[mM]").matcher(time_input); + Matcher regex_hours = Pattern.compile("\\d+[hH]").matcher(time_input); + Matcher regex_days = Pattern.compile("\\d+[dD]").matcher(time_input); + Matcher regex_weeks = Pattern.compile("\\d+[wW]").matcher(time_input); + Matcher regex_years = Pattern.compile("\\d+[yY]").matcher(time_input); + + int seconds = 0; + + if (regex_int.find()) { + seconds = Integer.parseInt(time_input); + } else { + if (regex_seconds.find()) { + seconds += Integer.parseInt(time_input.substring(regex_seconds.start(), regex_seconds.end() - 1)); + } + + if (regex_minutes.find()) { + seconds += Integer.parseInt(time_input.substring(regex_minutes.start(), regex_minutes.end() - 1)) * 60; + } + + if (regex_hours.find()) { + seconds += Integer.parseInt(time_input.substring(regex_hours.start(), regex_hours.end() - 1)) + * (60 * 60); + } + + if (regex_days.find()) { + seconds += Integer.parseInt(time_input.substring(regex_days.start(), regex_days.end() - 1)) + * (60 * 60 * 24); + } + + if (regex_weeks.find()) { + seconds += Integer.parseInt(time_input.substring(regex_weeks.start(), regex_weeks.end() - 1)) + * (60 * 60 * 24 * 7); + } + + if (regex_years.find()) { + seconds += Integer.parseInt(time_input.substring(regex_years.start(), regex_years.end() - 1)) + * (60 * 60 * 24 * 365); + } + } + + return seconds; + } + + /** + * Push an item to the end of an array + * @param arr + * @param item + * @return T[] array + */ + public static T[] array_push(T[] arr, T item) { + T[] tmp = Arrays.copyOf(arr, arr.length + 1); + tmp[tmp.length - 1] = item; + return tmp; + } + + /** + * Remove the last item from an array + * + * @param arr + * @return T[] array + */ + public static T[] array_pop(T[] arr) { + T[] tmp = Arrays.copyOf(arr, arr.length - 1); + return tmp; + } + + /** + * Generate a list of wildcard permissions + * + * @param permission + * @return ArrayList wildcard permissions + */ + public static ArrayList generateWildcardList(String permission) { + ArrayList output = new ArrayList(); + String[] permission_split = permission.split("\\."); + + output.add("*"); + + permission_split = array_pop(permission_split); + for (int i = 0; i < permission_split.length + 1; i++) { + if (permission_split.length == 0) + break; + output.add(String.join(".", permission_split) + ".*"); + permission_split = array_pop(permission_split); + } + + return output; + } + + public static void createDir(final String path) { + final File file = new File(path); + if (!file.exists()) { + file.mkdirs(); + } + } + + public static boolean deleteDir(File directoryToBeDeleted) { + File[] allContents = directoryToBeDeleted.listFiles(); + if (allContents != null) { + for (File file : allContents) { + deleteDir(file); + } + } + return directoryToBeDeleted.delete(); + } + + public static void addPlayerPlaytimeCache(UUID playerUUID, long time) { + playerPlayTimeCache.put(playerUUID, time); + } + + public static long getPlayerPlaytimeCache(UUID playerUUID) { + return playerPlayTimeCache.get(playerUUID); + } + + public static String powerFormatter(String text, Map values, char openChar, char closeChar) { + StringBuilder result = new StringBuilder(); + int textIdx = 0; + + for (int startIdx; (startIdx = text.indexOf(openChar, textIdx)) != -1;) { + int endIdx = text.indexOf(closeChar, startIdx + 1); + + if (endIdx == -1) + break; + + if (startIdx < 2 || text.charAt(startIdx - 1) != '\\') { + result.append(text.substring(textIdx, startIdx)); + textIdx = endIdx + 1; + String value = values.get(text.substring(startIdx + 1, endIdx)); + + if (value != null && !value.isEmpty()) { + result.append(value); // Replace placeholder with non-empty value + + } else if (result.length() != 0 && result.charAt(result.length() - 1) == ' ') { + result.setLength(result.length() - 1); // Remove space before placeholder + + } else if (textIdx < text.length() && text.charAt(textIdx) == ' ') { + textIdx++; // Skip space after placeholder + } else { + result.append(openChar + text.substring(startIdx + 1, endIdx) + closeChar); // Add back the original + // placeholder when an + // replacement isn't + // found + } + } else { + String unformatted = text.substring(textIdx, endIdx + 1).replaceFirst("\\\\", ""); + if (unformatted.length() > 1) { + String replaceText = text.substring(startIdx, endIdx + 1); + String baseText = text.substring(startIdx, startIdx + 1); + String endText = text.substring(endIdx + 1, endIdx + 1); + String formattedReplacement = baseText + + powerFormatter(text.substring(startIdx + 1, endIdx + 1), values, openChar, closeChar) + + endText; + + unformatted = unformatted.replace(replaceText, formattedReplacement); + } + result.append(unformatted); + textIdx = endIdx + 1; + } + } + result.append(text.substring(textIdx)); + return result.toString(); + } +} diff --git a/src/main/java/nl/svenar/common/utils/PowerColor.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/PowerColor.java similarity index 99% rename from src/main/java/nl/svenar/common/utils/PowerColor.java rename to Core/src/main/java/nl/svenar/powerranks/common/utils/PowerColor.java index eb220bca..dd21d7c7 100644 --- a/src/main/java/nl/svenar/common/utils/PowerColor.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/PowerColor.java @@ -1,4 +1,4 @@ -package nl.svenar.common.utils; +package nl.svenar.powerranks.common.utils; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/nl/svenar/common/utils/ServerInfo.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/ServerInfo.java similarity index 98% rename from src/main/java/nl/svenar/common/utils/ServerInfo.java rename to Core/src/main/java/nl/svenar/powerranks/common/utils/ServerInfo.java index 137116eb..a68dd745 100644 --- a/src/main/java/nl/svenar/common/utils/ServerInfo.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/ServerInfo.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.utils; +package nl.svenar.powerranks.common.utils; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/nl/svenar/common/utils/VersionUtils.java b/Core/src/main/java/nl/svenar/powerranks/common/utils/VersionUtils.java similarity index 98% rename from src/main/java/nl/svenar/common/utils/VersionUtils.java rename to Core/src/main/java/nl/svenar/powerranks/common/utils/VersionUtils.java index d77a8095..db303700 100644 --- a/src/main/java/nl/svenar/common/utils/VersionUtils.java +++ b/Core/src/main/java/nl/svenar/powerranks/common/utils/VersionUtils.java @@ -22,7 +22,7 @@ * SOFTWARE. */ -package nl.svenar.common.utils; +package nl.svenar.powerranks.common.utils; /** * Common methods to get information about the host's Java version and calculate diff --git a/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPCCache.java b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPCCache.java new file mode 100644 index 00000000..f2fd7eef --- /dev/null +++ b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPCCache.java @@ -0,0 +1,96 @@ +package nl.svenar.powerranks.test.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.Iterator; +import java.util.Random; +import java.util.UUID; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.test.util.TestDebugger; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestPCCache { + + @Test + public void A_Setup() { + PRCache.reset(); + } + + @Test + public void B_testCreateDuration() { + final int numPlayers = 10000; + final int numRanks = 10000; + final float maxDurationEachRank = 0.5f; + final float maxDurationEachPlayer = 0.5f; + + TestDebugger.log(this, ""); + TestDebugger.log(this, "[B_testCreateDuration] Setup..."); + + Instant rankCreationStartTimestamp = Instant.now(); + for (int i = 0; i < numRanks; i++) { + PRCache.createRank("Rank" + i); + } + Instant rankCreationEndTimestamp = Instant.now(); + + Random random = new Random(0); + Instant playerCreationStartTimestamp = Instant.now(); + for (int i = 0; i < numPlayers; i++) { + PRCache.createPlayer("Player" + i, new UUID(random.nextLong(), random.nextLong())); + } + Instant playerCreationEndTimestamp = Instant.now(); + + TestDebugger.log(this, "[testPerformance] Creating Ranks " + numRanks + "x " + (rankCreationEndTimestamp.toEpochMilli() - rankCreationStartTimestamp.toEpochMilli()) + "ms (max: " + Math.round(maxDurationEachRank * numRanks) + "ms)"); + assertTrue(rankCreationEndTimestamp.toEpochMilli() - rankCreationStartTimestamp.toEpochMilli() < maxDurationEachRank * numRanks); + assertEquals(numRanks, PRCache.getRanks().size()); + + TestDebugger.log(this, "[testPerformance] Creating Players " + numPlayers + "x " + (playerCreationEndTimestamp.toEpochMilli() - playerCreationStartTimestamp.toEpochMilli()) + "ms (max: " + Math.round(maxDurationEachPlayer * numPlayers) + "ms)"); + assertTrue(playerCreationEndTimestamp.toEpochMilli() - playerCreationStartTimestamp.toEpochMilli() < maxDurationEachPlayer * numPlayers); + assertEquals(numPlayers, PRCache.getPlayers().size()); + + + TestDebugger.log(this, "[B_testCreateDuration] Done!"); + } + + + @Test + public void C_testRemoveDuration() { + final int numPlayers = PRCache.getPlayers().size(); + final int numRanks = PRCache.getRanks().size(); + final float maxDurationEachPlayer = 0.0020f; + final float maxDurationEachRank = 0.125f; + + Instant rankStartTimestamp = Instant.now(); + Iterator rankIterator = PRCache.getRanks().iterator(); + while (rankIterator.hasNext()) { + PRCache.removeRank(rankIterator.next()); + } + Instant rankEndTimestamp = Instant.now(); + + Instant playerStartTimestamp = Instant.now(); + Iterator playerIterator = PRCache.getPlayers().iterator(); + while (playerIterator.hasNext()) { + PRCache.removePlayer(playerIterator.next()); + } + Instant playerEndTimestamp = Instant.now(); + + + TestDebugger.log(this, "[testPerformance] Removing Ranks " + numRanks + "x " + (rankEndTimestamp.toEpochMilli() - rankStartTimestamp.toEpochMilli()) + "ms (max: " + Math.round(maxDurationEachRank * numPlayers) + "ms)"); + assertTrue(rankEndTimestamp.toEpochMilli() - rankStartTimestamp.toEpochMilli() < maxDurationEachRank * numRanks); + assertEquals(0, PRCache.getPlayers().size()); + + + TestDebugger.log(this, "[testPerformance] Removing Players " + numPlayers + "x " + (playerEndTimestamp.toEpochMilli() - playerStartTimestamp.toEpochMilli()) + "ms (max: " + Math.round(maxDurationEachPlayer * numPlayers) + "ms)"); + assertTrue(playerEndTimestamp.toEpochMilli() - playerStartTimestamp.toEpochMilli() < maxDurationEachPlayer * numPlayers); + assertEquals(0, PRCache.getPlayers().size()); + } + +} diff --git a/src/test/java/nl/svenar/powerranks/test/tests/TestPRData.java b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPRData.java similarity index 87% rename from src/test/java/nl/svenar/powerranks/test/tests/TestPRData.java rename to Core/src/test/java/nl/svenar/powerranks/test/tests/TestPRData.java index 29e587a8..8273f9fa 100644 --- a/src/test/java/nl/svenar/powerranks/test/tests/TestPRData.java +++ b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPRData.java @@ -11,11 +11,11 @@ import org.junit.Test; import org.junit.runners.MethodSorters; -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRCache; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; import nl.svenar.powerranks.test.util.TestDebugger; @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -176,4 +176,26 @@ public void D_testPRRankPermissionOrder() { TestDebugger.log(this, "[D_testPRRankPermissionOrder] Rank weight permission overriding OK"); } + + @Test + public void E_testPRRankRemoveFromPlayer() { + TestDebugger.log(this, "[E_testPRRankRemoveFromPlayer] Setup..."); + PRCache.reset(); + + PRRank rank1 = PRCache.createRank("testRank1"); + PRRank rank2 = PRCache.createRank("testRank2"); + PRRank rank3 = PRCache.createRank("testRank3"); + + PRPlayer testPlayer = PRCache.createPlayer("TestPlayer", UUID.randomUUID()); + + testPlayer.addRank(rank1); + testPlayer.addRank(rank2); + testPlayer.addRank(rank3); + + assertEquals(3, testPlayer.getRanks().size()); + PRCache.removeRank(rank1); + assertEquals(2, testPlayer.getRanks().size()); + + TestDebugger.log(this, "[E_testPRRankRemoveFromPlayer] Remove rank updates player OK"); + } } \ No newline at end of file diff --git a/src/test/java/nl/svenar/powerranks/test/tests/TestPowerColor.java b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPowerColor.java similarity index 93% rename from src/test/java/nl/svenar/powerranks/test/tests/TestPowerColor.java rename to Core/src/test/java/nl/svenar/powerranks/test/tests/TestPowerColor.java index d05dca88..0882d3e1 100644 --- a/src/test/java/nl/svenar/powerranks/test/tests/TestPowerColor.java +++ b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestPowerColor.java @@ -1,10 +1,13 @@ package nl.svenar.powerranks.test.tests; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; import org.junit.Test; -import nl.svenar.common.utils.PowerColor; +import nl.svenar.powerranks.common.utils.PowerColor; import nl.svenar.powerranks.test.util.TestDebugger; public class TestPowerColor { @@ -202,4 +205,27 @@ public void testSpecialColorFormat() { TestDebugger.log(this, "[testSpecialColorFormat] Done!"); } + + @Test + public void testPerformance() { + int numItems = 10000; + float maxDurationEachItem = 0.05f; + TestDebugger.log(this, ""); + TestDebugger.log(this, "[testPerformance] Start"); + + PowerColor powerColor = new PowerColor(); + + String inputString = "[gradient=#000000,#FFFFFF]This is a test message[/gradient]"; + + Instant start = Instant.now(); + for (int i = 0; i < numItems; i++) { + powerColor.formatSpecial(PowerColor.UNFORMATTED_COLOR_CHAR, inputString); + } + Instant end = Instant.now(); + assertTrue(end.toEpochMilli() - start.toEpochMilli() < maxDurationEachItem * numItems); + TestDebugger.log(this, "[testPerformance] " + (end.toEpochMilli() - start.toEpochMilli()) + "ms (max: " + Math.round(maxDurationEachItem * numItems) + "ms)"); + + TestDebugger.log(this, "[testPerformance] Done!"); + } + } diff --git a/Core/src/test/java/nl/svenar/powerranks/test/tests/TestStorage.java b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestStorage.java new file mode 100644 index 00000000..6cb082b5 --- /dev/null +++ b/Core/src/test/java/nl/svenar/powerranks/test/tests/TestStorage.java @@ -0,0 +1,351 @@ +package nl.svenar.powerranks.test.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import java.util.UUID; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import nl.svenar.powerranks.common.storage.PowerSQLConfiguration; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.storage.provided.PSMStorageManager; +import nl.svenar.powerranks.common.storage.provided.YAMLStorageManager; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.storage.provided.SQLiteStorageManager; +import nl.svenar.powerranks.common.storage.provided.MySQLStorageManager; +import nl.svenar.powerranks.test.util.TestDebugger; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestStorage { + + private final String storageDirectory = "storage"; + private final int numPlayers = 1000; + private final int numRanks = 1000; + + private static List storageSpeeds = new ArrayList(); + + @Test + public void setupCache() { + PRCache.reset(); + + for (int i = 0; i < numRanks; i++) { + PRCache.createRank("Rank" + i); + } + + Random random = new Random(0); + for (int i = 0; i < numPlayers; i++) { + PRCache.createPlayer("Player" + i, new UUID(random.nextLong(), random.nextLong())); + } + } + + @Test + public void A_TestYAML() { + setupCache(); + StorageSpeed storageSpeed = new StorageSpeed(); + storageSpeed.name = "YAML"; + TestDebugger.log(this, "[A_TestYAML] Setup..."); + + PowerStorageManager storageManager = new YAMLStorageManager(storageDirectory, "ranks.yml", "players.yml"); + + TestDebugger.log(this, "[A_TestYAML] Saving data..."); + storageManager.setRanks(PRCache.getRanks()); + storageManager.setPlayers(PRCache.getPlayers()); + + + Instant saveStartTimestamp = Instant.now(); + storageManager.saveAll(); + Instant saveEndTimestamp = Instant.now(); + storageSpeed.speedSave = (int) (saveEndTimestamp.toEpochMilli() - saveStartTimestamp.toEpochMilli()); + + storageManager = new YAMLStorageManager(storageDirectory, "ranks.yml", "players.yml"); + + TestDebugger.log(this, "[A_TestYAML] Loading data..."); + Instant loadStartTimestamp = Instant.now(); + storageManager.loadAll(); + Instant loadEndTimestamp = Instant.now(); + storageSpeed.speedLoad = (int) (loadEndTimestamp.toEpochMilli() - loadStartTimestamp.toEpochMilli()); + + PRCache.reset(); + PRCache.setRanks(storageManager.getRanks()); + PRCache.setPlayers(storageManager.getPlayers()); + + TestDebugger.log(this, "[A_TestYAML] Checking data..."); + assertEquals(numRanks, PRCache.getRanks().size()); + assertEquals(numPlayers, PRCache.getPlayers().size()); + + storageSpeeds.add(storageSpeed); + TestDebugger.log(this, "[A_TestYAML] OK"); + } + + @Test + public void B_TestJSON() { + setupCache(); + StorageSpeed storageSpeed = new StorageSpeed(); + storageSpeed.name = "JSON"; + TestDebugger.log(this, "[B_TestJSON] Setup..."); + + PowerStorageManager storageManager = new JSONStorageManager(storageDirectory, "ranks.json", "players.json"); + + TestDebugger.log(this, "[B_TestJSON] Saving data..."); + storageManager.setRanks(PRCache.getRanks()); + storageManager.setPlayers(PRCache.getPlayers()); + + + Instant saveStartTimestamp = Instant.now(); + storageManager.saveAll(); + Instant saveEndTimestamp = Instant.now(); + storageSpeed.speedSave = (int) (saveEndTimestamp.toEpochMilli() - saveStartTimestamp.toEpochMilli()); + + storageManager = new JSONStorageManager(storageDirectory, "ranks.json", "players.json"); + + TestDebugger.log(this, "[B_TestJSON] Loading data..."); + Instant loadStartTimestamp = Instant.now(); + storageManager.loadAll(); + Instant loadEndTimestamp = Instant.now(); + storageSpeed.speedLoad = (int) (loadEndTimestamp.toEpochMilli() - loadStartTimestamp.toEpochMilli()); + + PRCache.reset(); + PRCache.setRanks(storageManager.getRanks()); + PRCache.setPlayers(storageManager.getPlayers()); + + TestDebugger.log(this, "[B_TestJSON] Checking data..."); + assertEquals(numRanks, PRCache.getRanks().size()); + assertEquals(numPlayers, PRCache.getPlayers().size()); + + storageSpeeds.add(storageSpeed); + TestDebugger.log(this, "[B_TestJSON] OK"); + } + + @Test + public void C_TestPSM() { + setupCache(); + StorageSpeed storageSpeed = new StorageSpeed(); + storageSpeed.name = "PSM"; + TestDebugger.log(this, "[C_TestPSM] Setup..."); + + PowerStorageManager storageManager = new PSMStorageManager(storageDirectory, "ranks.psm", "players.psm"); + + TestDebugger.log(this, "[C_TestPSM] Saving data..."); + storageManager.setRanks(PRCache.getRanks()); + storageManager.setPlayers(PRCache.getPlayers()); + + + Instant saveStartTimestamp = Instant.now(); + storageManager.saveAll(); + Instant saveEndTimestamp = Instant.now(); + storageSpeed.speedSave = (int) (saveEndTimestamp.toEpochMilli() - saveStartTimestamp.toEpochMilli()); + + storageManager = new PSMStorageManager(storageDirectory, "ranks.psm", "players.psm"); + + TestDebugger.log(this, "[C_TestPSM] Loading data..."); + Instant loadStartTimestamp = Instant.now(); + storageManager.loadAll(); + Instant loadEndTimestamp = Instant.now(); + storageSpeed.speedLoad = (int) (loadEndTimestamp.toEpochMilli() - loadStartTimestamp.toEpochMilli()); + + PRCache.reset(); + PRCache.setRanks(storageManager.getRanks()); + PRCache.setPlayers(storageManager.getPlayers()); + + TestDebugger.log(this, "[C_TestPSM] Checking data..."); + assertEquals(numRanks, PRCache.getRanks().size()); + assertEquals(numPlayers, PRCache.getPlayers().size()); + + storageSpeeds.add(storageSpeed); + TestDebugger.log(this, "[C_TestPSM] OK"); + } + + @Test + public void D_TestSQLite() { + setupCache(); + StorageSpeed storageSpeed = new StorageSpeed(); + storageSpeed.name = "SQLite"; + TestDebugger.log(this, "[D_TestSQLite] Setup..."); + + SQLiteStorageManager storageManager = new SQLiteStorageManager(storageDirectory, "ranks.db", "players.db"); + + if (!storageManager.isConnected()) { + TestDebugger.log(this, "[D_TestSQLite] Skipping test, not connected to MySQL"); + return; + } + + TestDebugger.log(this, "[D_TestSQLite] Clearing database..."); + storageManager.removeAllData(); + storageManager.close(); + + storageManager = new SQLiteStorageManager(storageDirectory, "ranks.db", "players.db"); + assertTrue(storageManager.isConnected()); + + TestDebugger.log(this, "[D_TestSQLite] Saving data..."); + storageManager.setRanks(PRCache.getRanks()); + storageManager.setPlayers(PRCache.getPlayers()); + + + Instant saveStartTimestamp = Instant.now(); + storageManager.saveAll(); + Instant saveEndTimestamp = Instant.now(); + storageSpeed.speedSave = (int) (saveEndTimestamp.toEpochMilli() - saveStartTimestamp.toEpochMilli()); + storageManager.close(); + + storageManager = new SQLiteStorageManager(storageDirectory, "ranks.db", "players.db"); + assertTrue(storageManager.isConnected()); + + TestDebugger.log(this, "[D_TestSQLite] Loading data..."); + Instant loadStartTimestamp = Instant.now(); + storageManager.loadAll(); + Instant loadEndTimestamp = Instant.now(); + storageSpeed.speedLoad = (int) (loadEndTimestamp.toEpochMilli() - loadStartTimestamp.toEpochMilli()); + + PRCache.reset(); + PRCache.setRanks(storageManager.getRanks()); + PRCache.setPlayers(storageManager.getPlayers()); + + storageManager.close(); + + TestDebugger.log(this, "[D_TestSQLite] Checking data..."); + assertEquals(numRanks, PRCache.getRanks().size()); + assertEquals(numPlayers, PRCache.getPlayers().size()); + + storageSpeeds.add(storageSpeed); + TestDebugger.log(this, "[D_TestSQLite] OK"); + } + + @Test + public void E_TestMySQL() { + setupCache(); + StorageSpeed storageSpeed = new StorageSpeed(); + storageSpeed.name = "MySQL"; + + TestDebugger.log(this, "[E_TestMySQL] Setup..."); + + PowerSQLConfiguration configuration = new PowerSQLConfiguration( + "0.0.0.0", + 3306, + "powerranks", + "powerranks", + "powerranks", + false, + "ranks", + "players", + "messages", + true); + MySQLStorageManager storageManager = new MySQLStorageManager(configuration); + + if (!storageManager.isConnected()) { + TestDebugger.log(this, "[E_TestMySQL] Skipping test, not connected to MySQL"); + return; + } + + TestDebugger.log(this, "[E_TestMySQL] Clearing database..."); + storageManager.removeAllData(); + storageManager.close(); + + storageManager = new MySQLStorageManager(configuration); + assertTrue(storageManager.isConnected()); + + TestDebugger.log(this, "[E_TestMySQL] Saving data..."); + storageManager.setRanks(PRCache.getRanks()); + storageManager.setPlayers(PRCache.getPlayers()); + + + Instant saveStartTimestamp = Instant.now(); + storageManager.saveAll(); + Instant saveEndTimestamp = Instant.now(); + storageSpeed.speedSave = (int) (saveEndTimestamp.toEpochMilli() - saveStartTimestamp.toEpochMilli()); + storageManager.close(); + + storageManager = new MySQLStorageManager(configuration); + assertTrue(storageManager.isConnected()); + + TestDebugger.log(this, "[E_TestMySQL] Loading data..."); + Instant loadStartTimestamp = Instant.now(); + storageManager.loadAll(); + Instant loadEndTimestamp = Instant.now(); + storageSpeed.speedLoad = (int) (loadEndTimestamp.toEpochMilli() - loadStartTimestamp.toEpochMilli()); + + PRCache.reset(); + PRCache.setRanks(storageManager.getRanks()); + PRCache.setPlayers(storageManager.getPlayers()); + + storageManager.close(); + + TestDebugger.log(this, "[E_TestMySQL] Checking data..."); + assertEquals(numRanks, PRCache.getRanks().size()); + assertEquals(numPlayers, PRCache.getPlayers().size()); + + storageSpeeds.add(storageSpeed); + TestDebugger.log(this, "[E_TestMySQL] OK"); + } + + @Test + public void Y_Cleanup() { + File directory = new File(storageDirectory); + assertTrue(deleteDirectory(directory)); + } + + @Test + public void Z_ShowStorageStats() { + assertTrue(storageSpeeds.size() > 0); + + TestDebugger.log(this, "---------------------------------"); + + storageSpeeds.removeIf(Objects::isNull); + storageSpeeds.sort(Comparator.comparingInt(StorageSpeed::totalDuration)); + + for (StorageSpeed storageSpeed : storageSpeeds) { + TestDebugger.log(this, storageSpeed.name); + TestDebugger.log(this, " - Saving: " + storageSpeed.speedSave + "ms"); + TestDebugger.log(this, " - Loading: " + storageSpeed.speedLoad + "ms"); + } + + TestDebugger.log(this, "---------------------------------"); + } + + public boolean deleteDirectory(File directory) { + if (!directory.exists()) { + return true; // Directory doesn't exist, so it's already deleted. + } + + if (!directory.isDirectory()) { + return false; // Not a directory. + } + + File[] files = directory.listFiles(); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + if (!deleteDirectory(file)) { + return false; // Failed to delete a subdirectory. + } + } else { + if (!file.delete()) { + return false; // Failed to delete a file. + } + } + } + } + + return directory.delete(); // Delete the empty directory. + } + + private class StorageSpeed { + public String name; + public int speedSave; + public int speedLoad; + + public int totalDuration() { + return speedSave + speedLoad; + } + } +} diff --git a/Core/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java b/Core/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java new file mode 100644 index 00000000..332cdf2b --- /dev/null +++ b/Core/src/test/java/nl/svenar/powerranks/test/util/TestDebugger.java @@ -0,0 +1,26 @@ +package nl.svenar.powerranks.test.util; + +import java.time.Duration; +import java.time.Instant; +import java.util.Objects; + +public class TestDebugger { + + private static boolean DEBUG = true; + public static boolean DOPERFORMANCETEST = false; + private static Instant startTime; + private static String lastClassName = ""; + + public static void log(Object clazz, String message) { + if (!DEBUG) + return; + + if (Objects.isNull(startTime) || !clazz.getClass().getSimpleName().equals(lastClassName)) { + lastClassName = clazz.getClass().getSimpleName(); + startTime = Instant.now(); + } + + System.out.println("[" + String.format("%04d", Duration.between(startTime, Instant.now()).toMillis()) + "ms] [" + + clazz.getClass().getSimpleName() + "] " + message); + } +} \ No newline at end of file diff --git a/Nukkit/pom.xml b/Nukkit/pom.xml new file mode 100644 index 00000000..9f88a3d8 --- /dev/null +++ b/Nukkit/pom.xml @@ -0,0 +1,142 @@ + + 4.0.0 + nl.svenar + powerranks.nukkit + ${revision} + PowerRanks Nukkit + Rank-based permission manager + + + 1.8 + UTF-8 + src/main/java + src/main/resources + nl.svenar.lib + false + + + + nl.svenar + powerranks + ${revision} + + + + clean compile package + ${output.name} + ${src.dir} + + + ${rsc.dir} + true + + + + + maven-compiler-plugin + 3.8.0 + + ${java.version} + ${java.version} + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + true + false + false + false + false + + + *:* + + META-INF/license/** + META-INF/* + META-INF/maven/** + META-INF/versions/*/module-info.class + LICENSE + NOTICE + /*.txt + build.properties + com/fasterxml/jackson/databind/ext/Java7* + + + + + + nl.svenar:powerranks.core + nl.svenar:powerranks.api + + + target/reduced-pom.xml + + + + package + + shade + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.1 + + ${skipNukkitTests} + + + + + + + + svenar + https://svenar.nl/repo/ + + + opencollab-repo-release + https://repo.opencollab.dev/maven-releases + + + opencollab-repo-snapshot + https://repo.opencollab.dev/maven-snapshots + + + + + + nl.svenar + powerranks.core + ${revision} + + + nl.svenar + powerranks.api + ${revision} + + + + cn.nukkit + nukkit + 1.0-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/PowerRanks.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/PowerRanks.java new file mode 100644 index 00000000..1ec1f1ec --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/PowerRanks.java @@ -0,0 +1,227 @@ +package nl.svenar.powerranks.nukkit; + +import java.io.File; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.UUID; +import java.util.Map.Entry; + +import cn.nukkit.Player; +import cn.nukkit.command.CommandSender; +import cn.nukkit.event.Listener; +import cn.nukkit.plugin.Plugin; +import cn.nukkit.plugin.PluginBase; +import cn.nukkit.plugin.PluginLogger; +import cn.nukkit.utils.TextFormat; +import nl.svenar.powerranks.common.storage.PermissionRegistry; +import nl.svenar.powerranks.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.PowerSQLConfiguration; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.StorageLoader; +import nl.svenar.powerranks.common.storage.provided.YAMLConfigManager; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.commands.PowerCommandHandler; +import nl.svenar.powerranks.nukkit.events.OnChat; +import nl.svenar.powerranks.nukkit.events.OnJoin; +import nl.svenar.powerranks.nukkit.events.OnLeave; +import nl.svenar.powerranks.nukkit.manager.LanguageManager; +import nl.svenar.powerranks.nukkit.manager.UsertagManager; +import nl.svenar.powerranks.nukkit.permissible.PermissibleInjector; +import nl.svenar.powerranks.nukkit.util.NukkitPowerColor; +import nl.svenar.powerranks.nukkit.util.Util; + +public class PowerRanks extends PluginBase { + + private static PowerRanks instance; + + private StorageLoader storageLoader; + private PowerStorageManager storageManager; + private PowerConfigManager configManager; + private LanguageManager languageManager; + private PowerConfigManager usertagStorage; + private UsertagManager usertagManager; + + private PermissionRegistry permissionRegistry; + private NukkitPowerColor powerColor = new NukkitPowerColor(); + + private PluginLogger logger; + + private String chatPluginPrefix; + + public Instant pluginStartTime; + + public PowerRanks() { + instance = this; + } + + @Override + public void onLoad() { + this.logger = this.getLogger(); + + pluginStartTime = Instant.now(); + + Util.DATA_DIR = this.getDataFolder() + File.separator; + PRUtil.createDir(Util.DATA_DIR); + + + this.chatPluginPrefix = TextFormat.BLACK + "[" + TextFormat.AQUA + this.getDescription().getName() + TextFormat.BLACK + "]" + + TextFormat.RESET + " "; + + this.permissionRegistry = new PermissionRegistry(); + + // ===---------------------------------------------------------=== // + // ===-------------------- LOAD ALL CONFIGS -------------------=== // + // ===---------------------------------------------------------=== // + logger.info("Loading config file"); + configManager = new YAMLConfigManager(Util.DATA_DIR, "config.yml", "config.yml"); + logger.info("Loading language file"); + languageManager = new LanguageManager(); + languageManager.setLanguage(configManager.getString("general.language", "en")); + logger.info("Loading usertags file"); + usertagStorage = new YAMLConfigManager(Util.DATA_DIR, "usertags.yml"); + + // ===---------------------------------------------------------=== // + // ===--------------- LOAD PRPLAYERS & PRRANKS ----------------=== // + // ===---------------------------------------------------------=== // + logger.info("Loading player & rank data"); + this.storageLoader = new StorageLoader(); + PowerSQLConfiguration sqlConfig = new PowerSQLConfiguration( + configManager.getString("storage.mysql.host", "127.0.0.1"), + configManager.getInt("storage.mysql.port", 3306), + configManager.getString("storage.mysql.database", "powerranks"), + configManager.getString("storage.mysql.username", "username"), + configManager.getString("storage.mysql.password", "password"), + configManager.getBool("storage.mysql.ssl", false), "ranks", "players", "messages", + configManager.getBool("storage.mysql.verbose", false)); + + this.storageManager = storageLoader.getStorageManager(Util.DATA_DIR, + configManager.getString("storage.type", "yaml"), sqlConfig); + + this.storageLoader.loadData(storageManager); + + // ===---------------------------------------------------------=== // + // ===------------------- REGISTER COMMANDS -------------------=== // + // ===---------------------------------------------------------=== // + this.getServer().getCommandMap().register("powerranks", new PowerCommandHandler(this, "powerranks")); + + } + + @Override + public void onEnable() { + + // ===---------------------------------------------------------=== // + // ===-------------------- REGISTER EVENTS --------------------=== // + // ===---------------------------------------------------------=== // + getServer().getPluginManager().registerEvents((Listener) new OnJoin(this), (Plugin) this); + getServer().getPluginManager().registerEvents((Listener) new OnLeave(this), (Plugin) this); + getServer().getPluginManager().registerEvents((Listener) new OnChat(this), (Plugin) this); + + // ===---------------------------------------------------------=== // + // ===---------------- INJECT EXISTING PLAYERS ----------------=== // + // ===---------------------------------------------------------=== // + for (Entry playerData : this.getServer().getOnlinePlayers().entrySet()) { + PermissibleInjector.inject(this, playerData.getValue()); + } + + // ===---------------------------------------------------------=== // + // ===---------------- ALL DONE & SHOW STARTUP ----------------=== // + // ===---------------------------------------------------------=== // + logger.info(""); + logger.info(TextFormat.AQUA + " ██████ ██████ " + TextFormat.GREEN + " PowerRanks v" + this.getDescription().getVersion()); + logger.info(TextFormat.AQUA + " ██ ██ ██ ██" + TextFormat.GREEN + " Running on " + Util.getServerType(getServer()) + " v" + Util.getServerVersion(getServer())); + logger.info(TextFormat.AQUA + " ██████ ██████ " + TextFormat.GREEN + " Startup time: " + Duration.between(pluginStartTime, Instant.now()).toMillis() + "ms"); + logger.info(TextFormat.AQUA + " ██ ██ ██" + TextFormat.GREEN + " Loaded " + PRCache.getRanks().size() + " ranks and " + PRCache.getPlayers().size() + " players (" + getConfigManager().getString("storage.type", "yaml").toUpperCase() + ") "); // TODO : update_available message + logger.info(TextFormat.AQUA + " ██ ██ ██" + " " + TextFormat.RED + (System.getProperty("POWERRANKSRUNNING", "").equals("TRUE") ? "Reload detected, why do you hate yourself :C" : "")); + logger.info(""); + + System.setProperty("POWERRANKSRUNNING", "TRUE"); + } + + @Override + public void onDisable() { + logger.info("Saving config file"); + configManager.save(); + logger.info("Saving language file"); + languageManager.save(); + logger.info("Saving usertags file"); + usertagStorage.save(); + + this.logger.info("Saving player & rank data"); + if (this.storageLoader != null && this.storageManager != null) { + this.storageLoader.saveData(this.storageManager); + } + + if (this.getDescription() != null) { + this.logger.info("Disabled " + this.getDescription().getName() + " v" + this.getDescription().getVersion()); + } else { + this.logger.info("Disabled " + this.getClass().getSimpleName()); + } + } + + public PowerConfigManager getConfigManager() { + return configManager; + } + + public LanguageManager getLanguageManager() { + return languageManager; + } + + public PowerConfigManager getUsertagStorage() { + return usertagStorage; + } + + public UsertagManager getUsertagManager() { + return usertagManager; + } + + public PermissionRegistry getPermissionRegistry() { + return permissionRegistry; + } + + public NukkitPowerColor getPowerColor() { + return powerColor; + } + + public String getChatPluginPrefix() { + return chatPluginPrefix; + } + + public PowerStorageManager getStorageManager() { + return storageManager; + } + + public StorageLoader getStorageLoader() { + return storageLoader; + } + + public static PowerRanks getInstance() { + return instance; + } + + public void factoryReset(CommandSender sender) { + PRCache.setRanks(new ArrayList()); + PRCache.setPlayers(new ArrayList()); + + PRUtil.deleteDir(new File(Util.DATA_DIR)); + PRUtil.createDir(Util.DATA_DIR); + + configManager = new YAMLConfigManager(Util.DATA_DIR, "config.yml", "config.yml"); + languageManager = new LanguageManager(); + languageManager.setLanguage(configManager.getString("general.language", "en")); + + PowerConfigManager ranksManager = new YAMLConfigManager(Util.DATA_DIR, "ranks.yml"); + PowerConfigManager playersManager = new YAMLConfigManager(Util.DATA_DIR, "players.yml"); + ranksManager.save(); + playersManager.save(); + + getStorageLoader().loadData(getStorageManager()); + + for (Player player : this.getServer().getOnlinePlayers().values()) { + PermissibleInjector.inject(this, player); + } + } +} \ No newline at end of file diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerCommand.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerCommand.java new file mode 100644 index 00000000..7f6c8d98 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerCommand.java @@ -0,0 +1,44 @@ +package nl.svenar.powerranks.nukkit.commands; + +import java.util.ArrayList; + +import cn.nukkit.command.CommandSender; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public abstract class PowerCommand { + + protected PowerRanks plugin; + private String commandPermission = ""; + + public enum COMMAND_EXECUTOR { + NONE, + PLAYER, + CONSOLE, + COMMANDBLOCK, + ALL + } + + private COMMAND_EXECUTOR ce = COMMAND_EXECUTOR.NONE; + + public PowerCommand(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + PowerCommandHandler.add_power_command(command_name, this); + this.plugin = plugin; + this.ce = ce; + } + + public abstract boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args); + + public COMMAND_EXECUTOR getCommandExecutor() { + return this.ce; + } + + public abstract ArrayList tabCompleteEvent(CommandSender sender, String[] args); + + protected void setCommandPermission(String permission) { + this.commandPermission = permission; + } + + public String getCommandPermission() { + return this.commandPermission; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerCommandHandler.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerCommandHandler.java new file mode 100644 index 00000000..279bde60 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerCommandHandler.java @@ -0,0 +1,244 @@ +package nl.svenar.powerranks.nukkit.commands; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; + +import cn.nukkit.Player; +import cn.nukkit.command.CommandSender; +import cn.nukkit.command.ConsoleCommandSender; +import cn.nukkit.command.PluginCommand; +import cn.nukkit.command.data.CommandParamType; +import cn.nukkit.command.data.CommandParameter; +import cn.nukkit.utils.TextFormat; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand.COMMAND_EXECUTOR; +import nl.svenar.powerranks.nukkit.commands.core.cmd_config; +import nl.svenar.powerranks.nukkit.commands.core.cmd_dump; +import nl.svenar.powerranks.nukkit.commands.core.cmd_factoryreset; +import nl.svenar.powerranks.nukkit.commands.core.cmd_help; +import nl.svenar.powerranks.nukkit.commands.core.cmd_pluginhook; +import nl.svenar.powerranks.nukkit.commands.core.cmd_reload; +import nl.svenar.powerranks.nukkit.commands.core.cmd_stats; +import nl.svenar.powerranks.nukkit.commands.player.cmd_addownrank; +import nl.svenar.powerranks.nukkit.commands.player.cmd_addplayerperm; +import nl.svenar.powerranks.nukkit.commands.player.cmd_addrank; +import nl.svenar.powerranks.nukkit.commands.player.cmd_checkrank; +import nl.svenar.powerranks.nukkit.commands.player.cmd_delplayerperm; +import nl.svenar.powerranks.nukkit.commands.player.cmd_delrank; +import nl.svenar.powerranks.nukkit.commands.player.cmd_haspermission; +import nl.svenar.powerranks.nukkit.commands.player.cmd_listplayerpermissions; +import nl.svenar.powerranks.nukkit.commands.player.cmd_nick; +import nl.svenar.powerranks.nukkit.commands.player.cmd_playerinfo; +import nl.svenar.powerranks.nukkit.commands.player.cmd_setownrank; +import nl.svenar.powerranks.nukkit.commands.player.cmd_setrank; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_addinheritance; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_addperm; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_createrank; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_deleterank; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_delinheritance; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_delperm; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_listdefaultranks; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_listpermissions; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_listranks; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_rankinfo; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_renamerank; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_setchatcolor; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_setdefault; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_setnamecolor; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_setprefix; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_setsuffix; +import nl.svenar.powerranks.nukkit.commands.rank.cmd_setweight; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_addusertag; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_clearusertag; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_createusertag; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_delusertag; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_editusertag; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_listusertags; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_removeusertag; +import nl.svenar.powerranks.nukkit.commands.usertags.cmd_setusertag; +import nl.svenar.powerranks.nukkit.commands.webeditor.cmd_webeditor; + +public class PowerCommandHandler extends PluginCommand { + + private static HashMap power_commands = new HashMap(); + + private PowerRanks plugin; + + public PowerCommandHandler(PowerRanks plugin, String commandName) { + super("powerranks", plugin); + this.setAliases(new String[]{"pr"}); + this.getCommandParameters().clear(); + + this.plugin = plugin; + + this.getCommandParameters().put("help", new CommandParameter[]{ + CommandParameter.newType("page", false, CommandParamType.INT) + }); + + this.getCommandParameters().put("stats", new CommandParameter[]{ + }); + + new cmd_help(plugin, "help", COMMAND_EXECUTOR.ALL); + new cmd_reload(plugin, "reload", COMMAND_EXECUTOR.ALL); + new cmd_pluginhook(plugin, "pluginhook", COMMAND_EXECUTOR.ALL); + new cmd_config(plugin, "config", COMMAND_EXECUTOR.ALL); + new cmd_stats(plugin, "stats", COMMAND_EXECUTOR.ALL); + new cmd_factoryreset(plugin, "factoryreset", COMMAND_EXECUTOR.ALL); + new cmd_playerinfo(plugin, "playerinfo", COMMAND_EXECUTOR.ALL); + new cmd_haspermission(plugin, "haspermission", COMMAND_EXECUTOR.ALL); + new cmd_dump(plugin, "dump", COMMAND_EXECUTOR.ALL); + + new cmd_setrank(plugin, "setrank", COMMAND_EXECUTOR.ALL); + new cmd_setownrank(plugin, "setownrank", COMMAND_EXECUTOR.PLAYER); + new cmd_addrank(plugin, "addrank", COMMAND_EXECUTOR.ALL); + new cmd_addownrank(plugin, "addownrank", COMMAND_EXECUTOR.PLAYER); + new cmd_delrank(plugin, "delrank", COMMAND_EXECUTOR.ALL); + + new cmd_listranks(plugin, "listranks", COMMAND_EXECUTOR.ALL); + new cmd_listpermissions(plugin, "listpermissions", COMMAND_EXECUTOR.ALL); + new cmd_listplayerpermissions(plugin, "listplayerpermissions", COMMAND_EXECUTOR.ALL); + new cmd_listusertags(plugin, "listusertags", COMMAND_EXECUTOR.ALL); + + new cmd_checkrank(plugin, "checkrank", COMMAND_EXECUTOR.ALL); + new cmd_nick(plugin, "nick", COMMAND_EXECUTOR.ALL); + + new cmd_createrank(plugin, "createrank", COMMAND_EXECUTOR.ALL); + new cmd_deleterank(plugin, "deleterank", COMMAND_EXECUTOR.ALL); + new cmd_renamerank(plugin, "renamerank", COMMAND_EXECUTOR.ALL); + new cmd_setdefault(plugin, "setdefault", COMMAND_EXECUTOR.ALL); + new cmd_listdefaultranks(plugin, "listdefaultranks", COMMAND_EXECUTOR.ALL); + new cmd_addperm(plugin, "addperm", COMMAND_EXECUTOR.ALL); + new cmd_delperm(plugin, "delperm", COMMAND_EXECUTOR.ALL); + new cmd_setprefix(plugin, "setprefix", COMMAND_EXECUTOR.ALL); + new cmd_setsuffix(plugin, "setsuffix", COMMAND_EXECUTOR.ALL); + new cmd_setchatcolor(plugin, "setchatcolor", COMMAND_EXECUTOR.ALL); + new cmd_setnamecolor(plugin, "setnamecolor", COMMAND_EXECUTOR.ALL); + new cmd_addinheritance(plugin, "addinheritance", COMMAND_EXECUTOR.ALL); + new cmd_delinheritance(plugin, "delinheritance", COMMAND_EXECUTOR.ALL); + new cmd_setweight(plugin, "setweight", COMMAND_EXECUTOR.ALL); + new cmd_rankinfo(plugin, "rankinfo", COMMAND_EXECUTOR.ALL); + + new cmd_addplayerperm(plugin, "addplayerperm", COMMAND_EXECUTOR.ALL); + new cmd_delplayerperm(plugin, "delplayerperm", COMMAND_EXECUTOR.ALL); + new cmd_createusertag(plugin, "createusertag", COMMAND_EXECUTOR.ALL); + new cmd_editusertag(plugin, "editusertag", COMMAND_EXECUTOR.ALL); + new cmd_removeusertag(plugin, "removeusertag", COMMAND_EXECUTOR.ALL); + new cmd_addusertag(plugin, "addusertag", COMMAND_EXECUTOR.ALL); + new cmd_setusertag(plugin, "setusertag", COMMAND_EXECUTOR.ALL); + new cmd_delusertag(plugin, "delusertag", COMMAND_EXECUTOR.ALL); + new cmd_clearusertag(plugin, "clearusertag", COMMAND_EXECUTOR.ALL); + + new cmd_webeditor(plugin, "webeditor", COMMAND_EXECUTOR.ALL); + new cmd_webeditor(plugin, "we", COMMAND_EXECUTOR.ALL); + } + + private static boolean canExecuteCommand(CommandSender sender, PowerCommand command_handler) { + return (sender instanceof Player && (command_handler.getCommandExecutor() == COMMAND_EXECUTOR.PLAYER + || command_handler.getCommandExecutor() == COMMAND_EXECUTOR.ALL)) + || (sender instanceof ConsoleCommandSender + && (command_handler.getCommandExecutor() == COMMAND_EXECUTOR.CONSOLE + || command_handler.getCommandExecutor() == COMMAND_EXECUTOR.ALL)); + } + + + + @Override + public boolean execute(CommandSender sender, String commandLabel, String[] args) { + if (args.length == 0) { + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + "==="); + sender.sendMessage(TextFormat.GREEN + "/" + commandLabel + " help" + TextFormat.DARK_GREEN + " - For the command list."); + sender.sendMessage(""); + sender.sendMessage(TextFormat.DARK_GREEN + "Author: " + TextFormat.GREEN + plugin.getDescription().getAuthors().get(0)); + sender.sendMessage(TextFormat.DARK_GREEN + "Version: " + TextFormat.GREEN + plugin.getDescription().getVersion()); + sender.sendMessage(TextFormat.DARK_GREEN + "Website: " + TextFormat.GREEN + plugin.getDescription().getWebsite()); + sender.sendMessage(TextFormat.DARK_GREEN + "Documentation: " + TextFormat.GREEN + "https://docs.powerranks.nl"); + sender.sendMessage(TextFormat.DARK_GREEN + "Support me: " + TextFormat.YELLOW + "https://ko-fi.com/svenar"); + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + } else { + String command = args[0]; + PowerCommand command_handler = get_power_command(command); + if (command_handler != null) { + boolean is_allowed = canExecuteCommand(sender, command_handler); + boolean hasPermission = hasPermission(sender, command_handler); + if (is_allowed) { + if (hasPermission) { + return command_handler.onCommand(sender, commandLabel, command, + Arrays.copyOfRange(args, 1, args.length)); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage(plugin.getChatPluginPrefix() + TextFormat.DARK_RED + "You can't execute this command here"); + } + // } else { + // boolean addonCommandFound = false; + // PowerRanksPlayer prPlayer = null; + // if (sender instanceof Player) { + // prPlayer = new PowerRanksPlayer(this.plugin, (Player) sender); + // } else { + // prPlayer = new PowerRanksPlayer(this.plugin, "CONSOLE"); + // } + + // if (prPlayer != null) { + // for (Entry prAddon : this.plugin.addonsManager.addonClasses.entrySet()) { + // if (prAddon.getValue().onPowerRanksCommand(prPlayer, sender instanceof Player, args[0], args)) { + // addonCommandFound = true; + // } + // } + // } + // if (!addonCommandFound) + // sender.sendMessage(plugin.plp + TextFormat.DARK_RED + "Unknown Command"); + } + + } + return false; + } + + private boolean hasPermission(CommandSender sender, PowerCommand command_handler) { + if (command_handler.getCommandPermission().length() == 0) { + return true; + } + + return sender.hasPermission(command_handler.getCommandPermission()); + } + + public static PowerCommand get_power_command(String command_name) { + return power_commands.get(command_name.toLowerCase()); + } + + public static void add_power_command(String command_name, PowerCommand command_handler) { + power_commands.put(command_name.toLowerCase(), command_handler); + } + + private static boolean hasCommandPermission(CommandSender sender, String cmd) { + boolean hasPermission = sender instanceof Player ? ((Player) sender).hasPermission("powerranks.cmd." + cmd.toLowerCase()) : true; + return hasPermission; + } + + public static ArrayList handle_tab_complete(CommandSender sender, String cmd, String[] args) { + ArrayList output = new ArrayList(); + if (args.length == 0) { + for (Entry entry : power_commands.entrySet()) { + if (cmd.length() == 0 || entry.getKey().toLowerCase().contains(cmd.toLowerCase())) { + boolean is_allowed = canExecuteCommand(sender, entry.getValue()) && hasCommandPermission(sender, cmd); + if (is_allowed) { + output.add(entry.getKey()); + } + } + } + } else { + if (power_commands.containsKey(cmd.toLowerCase())) { + if (hasCommandPermission(sender, cmd)) { + output = power_commands.get(cmd.toLowerCase()).tabCompleteEvent(sender, args); + } + } + + } + return output; + } +} \ No newline at end of file diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerSubCommand.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerSubCommand.java new file mode 100644 index 00000000..66f4a554 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/PowerSubCommand.java @@ -0,0 +1,35 @@ +package nl.svenar.powerranks.nukkit.commands; + +import cn.nukkit.command.Command; +import cn.nukkit.command.CommandSender; +import cn.nukkit.command.ConsoleCommandSender; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand.COMMAND_EXECUTOR; + +public abstract class PowerSubCommand { + + protected PowerRanks plugin; + + private String commandName; + private COMMAND_EXECUTOR commandExecutor = COMMAND_EXECUTOR.NONE; + + public PowerSubCommand(PowerRanks plugin, String commandName, COMMAND_EXECUTOR commandExecutor) { + this.plugin = plugin; + this.commandExecutor = commandExecutor; + this.commandName = commandName; + } + + protected boolean verifyPermission(CommandSender sender, String permission_node) { + return sender instanceof ConsoleCommandSender || sender.hasPermission(permission_node); + } + + public abstract boolean onSubCommand(CommandSender sender, Command cmd, String commandLabel, String[] args); + + public COMMAND_EXECUTOR getCommandExecutor() { + return this.commandExecutor; + } + + public String commandName() { + return commandName; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_config.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_config.java new file mode 100644 index 00000000..307e0e55 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_config.java @@ -0,0 +1,311 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.util.ArrayList; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_config extends PowerCommand { + + public cmd_config(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + if (args[0].equalsIgnoreCase("removeworldtag")) { + String world_tag_regex = "[ ]{0,1}([&][a-fA-F0-9k-oK-OrR]){0,1}((&){0,1}[#][a-fA-F0-9]{6}){0,1}[ ]{0,1}[\\[]world[\\]][ ]{0,1}([&][a-fA-F0-9k-oK-OrR]){0,1}((&){0,1}[#][a-fA-F0-9]{6}){0,1}[ ]{0,1}"; + Pattern world_tag_pattern = Pattern.compile(world_tag_regex); + Matcher world_tag_matcher_chat = world_tag_pattern + .matcher(plugin.getConfigManager().getString("chat.format", "").toLowerCase()); + Matcher world_tag_matcher_tab = world_tag_pattern.matcher( + plugin.getConfigManager().getString("tablist_modification.format", "").toLowerCase()); + + while (world_tag_matcher_chat.find()) { + int start = world_tag_matcher_chat.start(); + int end = world_tag_matcher_chat.end(); + plugin.getConfigManager().setString("chat.format", + plugin.getConfigManager().getString("chat.format", "").replace( + plugin.getConfigManager().getString("chat.format", "").substring(start, end), + "")); + } + + while (world_tag_matcher_tab.find()) { + int start = world_tag_matcher_tab.start(); + int end = world_tag_matcher_tab.end(); + plugin.getConfigManager() + .setString("tablist_modification.format", + plugin.getConfigManager().getString("tablist_modification.format", "") + .replace(plugin.getConfigManager() + .getString("tablist_modification.format", "").substring(start, end), + "")); + } + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".removed-world-tag"), + ImmutableMap.builder() + .put("player", sender.getName()) + .build(), + '[', ']')); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + } else if (args.length == 2) { + if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("disable")) { + boolean enable = args[0].equalsIgnoreCase("enable"); + if (args[1].equalsIgnoreCase("chat_formatting")) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Chat formatting") + .put("old_state", + String.valueOf(plugin.getConfigManager().getBool("chat.enabled", true))) + .put("new_state", String.valueOf(enable)) + .build(), + '[', ']')); + + plugin.getConfigManager().setBool("chat.enabled", enable); + + } else if (args[1].equalsIgnoreCase("tablist_formatting")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Tablist formatting") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getBool("tablist_modification.enabled", true))) + .put("new_state", String.valueOf(enable)) + .build(), + '[', ']')); + + plugin.getConfigManager().setBool("tablist_modification.enabled", enable); + + } else if (args[1].equalsIgnoreCase("casesensitive_permissions")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Case Sensitive Permissions") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getBool("general.case-sensitive-permissions", true))) + .put("new_state", String.valueOf(enable)) + .build(), + '[', ']')); + + plugin.getConfigManager().setBool("general.case-sensitive-permissions", enable); + + } else if (args[1].equalsIgnoreCase("op")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Op command") + .put("old_state", + String.valueOf(!plugin.getConfigManager() + .getBool("general.disable-op", true))) + .put("new_state", String.valueOf(enable)) + .build(), + '[', ']')); + + plugin.getConfigManager().setBool("general.disable-op", !enable); + + } else if (args[1].equalsIgnoreCase("bungeecord")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Bungeecord integration") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getBool("bungeecord.enabled", false))) + .put("new_state", String.valueOf(enable)) + .build(), + '[', ']')); + + plugin.getConfigManager().setBool("bungeecord.enabled", enable); + + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + } else if (args.length == 3) { + if (args[0].equalsIgnoreCase("set")) { + + if (args[1].equalsIgnoreCase("playtime_update_interval")) { + try { + int time = Integer.parseInt(args[2]); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Player playtime update interval") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getInt("general.playtime-update-interval", 60))) + .put("new_state", String.valueOf(time)) + .build(), + '[', ']')); + + plugin.getConfigManager().setInt("general.playtime-update-interval", time); + } catch (Exception e) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".numbers-only")); + } + } + + } else if (args[1].equalsIgnoreCase("language")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "PowerRanks language (lang.yml)") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getString("general.language", "en"))) + .put("new_state", args[2]) + .build(), + '[', ']')); + + plugin.getConfigManager().setString("general.language", args[2]); + + } else if (args[1].equalsIgnoreCase("bungeecord_server_name")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "PowerRanks Bungeecord server name") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getString("bungeecors.server-name", "Global"))) + .put("new_state", args[2]) + .build(), + '[', ']')); + + plugin.getConfigManager().setString("bungeecors.server-name", args[2]); + + } else if (args[1].equalsIgnoreCase("autosave_files_interval")) { + try { + int time = Integer.parseInt(args[2]); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", "Data autosave interval") + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getInt("general.autosave-files-interval", 600))) + .put("new_state", String.valueOf(time)) + .build(), + '[', ']')); + + plugin.getConfigManager().setInt("general.autosave-files-interval", time); + } catch (Exception e) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".numbers-only")); + } + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + tabcomplete.add("removeworldtag"); + tabcomplete.add("enable"); + tabcomplete.add("disable"); + tabcomplete.add("set"); + } + + if (args.length == 2) { + if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("disable")) { + tabcomplete.add("chat_formatting"); + tabcomplete.add("tablist_formatting"); + tabcomplete.add("casesensitive_permissions"); + tabcomplete.add("op"); + tabcomplete.add("bungeecord"); + } + } + + if (args.length == 2) { + if (args[0].equalsIgnoreCase("set")) { + tabcomplete.add("language"); + tabcomplete.add("autosave_files_interval"); + tabcomplete.add("playtime_update_interval"); + tabcomplete.add("bungeecord_server_name"); + } + } + + if (args.length == 3) { + if (args[1].equalsIgnoreCase("language")) { + for (String key : plugin.getLanguageManager().getInstance().getKeys("lang")) { + tabcomplete.add(key); + } + } + } + + if (args.length == 3) { + if (args[1].equalsIgnoreCase("autosave_files_interval")) { + tabcomplete.add("60"); + tabcomplete.add("300"); + tabcomplete.add("600"); + tabcomplete.add("1800"); + tabcomplete.add("3600"); + } + } + + if (args.length == 3) { + if (args[1].equalsIgnoreCase("playtime_update_interval")) { + tabcomplete.add("1"); + tabcomplete.add("5"); + tabcomplete.add("10"); + tabcomplete.add("60"); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_dump.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_dump.java new file mode 100644 index 00000000..53d01f09 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_dump.java @@ -0,0 +1,281 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.io.File; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; +import cn.nukkit.scheduler.NukkitRunnable; + +import nl.svenar.powerranks.common.http.DatabinClient; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.utils.AsyncReadFile; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_dump extends PowerCommand { + + private String databin_url = "https://databin.svenar.nl"; + private String logs_powerranks_url = "https://logs.powerranks.nl/dump/?id="; + + ArrayList serverLog = new ArrayList(); + Map coreData = new HashMap(); + + public cmd_dump(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (sender instanceof Player) { + sender.sendMessage( + TextFormat.DARK_AQUA + "--------" + TextFormat.DARK_BLUE + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "--------"); + sender.sendMessage(TextFormat.GREEN + "Dump has started collecting data!"); + sender.sendMessage(TextFormat.GREEN + "Check the server console for more information."); + sender.sendMessage(TextFormat.DARK_AQUA + "--------------------------"); + } + prepareLog(sender, commandName); + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } + + private void readServerLog() { + serverLog.clear(); + + final String serverPath = plugin.getServer().getDataPath(); + final File serverLogFile = new File(serverPath.substring(0, serverPath.length() - 1), "logs/latest.log"); + + AsyncReadFile arf = new AsyncReadFile(); + arf.setFile(serverLogFile.getPath()); + long totalLength = arf.getFileLength(); + arf.read(); + + new NukkitRunnable() { + Instant startTime = Instant.now(); + int progressTimerIndex = Integer.MAX_VALUE; + + @Override + public void run() { + if (!arf.isReady()) { + if (progressTimerIndex > 20 * 10) { + progressTimerIndex = 0; + int currentLength = arf.getData().length(); + plugin.getLogger().info("Reading server log... (" + ((100 * currentLength) / totalLength) + "%)"); + } + progressTimerIndex++; + return; + } else { + plugin.getLogger().info("Server log:"); + + plugin.getLogger().info("- Removing sensitive information from server log..."); + for (String line : arf.getData().split("\n")) { + serverLog.add(removeIP(line).replaceAll("\"", "'")); + } + plugin.getLogger() + .info("- Reading took " + Duration.between(startTime, Instant.now()).toMillis() + "ms"); + plugin.getLogger() + .info("- Read " + arf.getData().split("\n").length + " lines (" + arf.getData().length() + " characters)!"); + this.cancel(); + plugin.getLogger().info(""); + } + } + }.runTaskTimer(plugin, 0, 1); + } + + private void readCoreData() { + coreData = new HashMap<>(); + + new NukkitRunnable() { + Instant startTime = Instant.now(); + + @Override + public void run() { + plugin.getLogger().info("Plugin data:"); + + JSONStorageManager jsonmanager = new JSONStorageManager(Util.DATA_DIR, "dummyRanks.json", "dummyPlayers.json"); + PowerStorageManager powermanager = plugin.getStorageManager(); + + jsonmanager.setRanks(powermanager.getRanks()); + jsonmanager.setPlayers(powermanager.getPlayers()); + + // jsonmanager.getRanksAsJSON(false); + // jsonmanager.getPlayersAsJSON(false); + // PowerRanks.getUsertagManager().toJSON("usertags", false); + + coreData.put("rankdata", jsonmanager.getRanksAsMap()); + coreData.put("playerdata", jsonmanager.getPlayersAsMap()); + coreData.put("config", plugin.getConfigManager().getRawData()); + coreData.put("usertags", plugin.getUsertagStorage().getRawData().get("usertags")); + + plugin.getLogger().info("- Reading took " + Duration.between(startTime, Instant.now()).toMillis() + "ms"); + plugin.getLogger().info("- Read " + jsonmanager.getRanks().size() + " ranks and " + jsonmanager.getPlayers().size() + " players!"); + plugin.getLogger().info("- Adding configuration & usertags"); + + jsonmanager.removeAllData(); + plugin.getLogger().info(""); + + this.cancel(); + + } + }.runTaskTimer(plugin, 0, 1); + } + + private void prepareLog(CommandSender sender, String commandName) { + plugin.getLogger().info(""); + plugin.getLogger().info("=== -------------------------------- ==="); + plugin.getLogger().info(" PowerRanks is collecting data! "); + plugin.getLogger().info("=== -------------------------------- ==="); + + readServerLog(); + readCoreData(); + + new NukkitRunnable() { + Instant startTime = Instant.now(); + int progressIndex = 0; + Map elements = new HashMap<>(); + boolean serverLogDone = false; + boolean coreDataDone = false; + + @Override + @SuppressWarnings("unchecked") + public void run() { + if (serverLog.size() > 0) { + plugin.getLogger().info("Server log found!"); + + elements.put("type", "dump"); + elements.put("version", new HashMap<>()); + ((Map) elements.get("version")).put("powerranks", plugin.getDescription().getVersion()); + ((Map) elements.get("version")).put("server", + plugin.getServer().getVersion() + " | " + plugin.getServer().getNukkitVersion()); + + // TODO + // String pluginData = ""; + // Plugin[] plugins = plugin.getPluginManager().getPlugins(); + // for (Plugin plugin : plugins) { + // pluginData += plugin.getName() + "(" + plugin.getDescription().getVersion() + "),"; + // } + // pluginData = pluginData.substring(0, pluginData.length() - 1); + // elements.put("plugins", pluginData); + + elements.put("serverlog", Arrays.asList(serverLog)); + + serverLog = new ArrayList<>(); + serverLogDone = true; + } + + if (coreData.keySet().size() > 0) { + plugin.getLogger().info("Core data found!"); + + elements.put("coredata", coreData); + coreData = new HashMap<>(); + coreDataDone = true; + } + + if (serverLogDone && coreDataDone) { + plugin.getLogger().info( + "Data collected successfully in " + Duration.between(startTime, Instant.now()).toMillis() + "ms, uploading..."); + startTime = Instant.now(); + + try { + ObjectMapper objectMapper = new ObjectMapper(); + String json = objectMapper.writeValueAsString(elements); + uploadDump(json); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + plugin.getLogger() + .info("Done! Uploading took " + Duration.between(startTime, Instant.now()).toMillis() + "ms"); + + this.cancel(); + } else { + progressIndex += 1; + if (progressIndex > 1200) { + plugin.getLogger().info("Failed to dump data!"); + plugin.getLogger() + .info("Timed out after " + Duration.between(startTime, Instant.now()).toMillis() + "ms!"); + this.cancel(); + } + } + } + }.runTaskTimer(plugin, 0, 1); + } + + private void uploadDump(String outputJSON) { + DatabinClient client = new DatabinClient(databin_url, "Databinclient/1.0"); + + int uploadSize = outputJSON.length() / 1024; + + plugin.getLogger().info("Uploading " + uploadSize + "KB, please wait..."); + + client.postJSON(outputJSON); + int updateInterval = 5; + int timeout = 5; + + new NukkitRunnable() { + int waitTime = 0; + + @Override + public void run() { + if (client.hasResponse()) { + Map response = client.getResponse(); + if (response.keySet().contains("key")) { + String key = response.get("key"); + + if (key.length() > 0 && !key.startsWith("[FAILED]")) { + plugin.getLogger().info(""); + plugin.getLogger().info("===----------" + plugin.getDescription().getName() + "----------==="); + plugin.getLogger().info("Data upload is ready " + "[" + logs_powerranks_url + key + "]"); + plugin.getLogger().info("ID: " + key); + plugin.getLogger().info("Uploaded: " + uploadSize + "KB"); + plugin.getLogger().info("===------------------------------==="); + } else { + plugin.getLogger().info("Uploading dump failed, received server error!"); + } + } + + + this.cancel(); + } + + if (waitTime / (20 / updateInterval) > timeout) { + + plugin.getLogger().info("Uploading dump timed-out!"); + this.cancel(); + } + } + }.runTaskTimer(plugin, 0, updateInterval); + } + + private String removeIP(String line) { + String output = line; + + String ipExp = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"; + Pattern ipPattern = Pattern.compile(ipExp); + + Matcher matcher = ipPattern.matcher(output); + output = matcher.replaceAll("<>"); + + return output; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_factoryreset.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_factoryreset.java new file mode 100644 index 00000000..d6fddfa3 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_factoryreset.java @@ -0,0 +1,60 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.util.ArrayList; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.TextFormat; +import cn.nukkit.Player; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_factoryreset extends PowerCommand { + + private String factoryresetid; + + public cmd_factoryreset(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0 || (args.length == 1 && factoryresetid == null) + || (args.length == 1 && !args[0].equalsIgnoreCase(factoryresetid))) { + factoryresetid = (100 + Math.round(Math.random() * 900)) + "-" + + (100 + Math.round(Math.random() * 900)) + "-" + (100 + Math.round(Math.random() * 900)); + + sender.sendMessage( + TextFormat.DARK_AQUA + "--------" + TextFormat.DARK_BLUE + plugin.getDescription().getName() + + TextFormat.DARK_AQUA + "--------"); + sender.sendMessage(TextFormat.DARK_RED + "WARNING!"); + sender.sendMessage(TextFormat.RED + "This action is irreversible if you continue"); + sender.sendMessage(TextFormat.RED + "Factory reset ID: " + TextFormat.GOLD + factoryresetid); + sender.sendMessage( + TextFormat.RED + "To continue do: " + TextFormat.GOLD + "/pr factoryreset " + + factoryresetid); + sender.sendMessage(TextFormat.DARK_AQUA + "--------------------------"); + } else if (args.length == 1) { + this.plugin.factoryReset(sender); + + sender.sendMessage(TextFormat.DARK_AQUA + "--------" + TextFormat.DARK_BLUE + plugin.getDescription().getName() + + TextFormat.DARK_AQUA + "--------"); + sender.sendMessage(TextFormat.GREEN + "Factory reset complete!"); + sender.sendMessage(TextFormat.GREEN + "It is recommended to restart your server."); + sender.sendMessage(TextFormat.DARK_AQUA + "--------------------------"); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_help.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_help.java new file mode 100644 index 00000000..73ec8496 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_help.java @@ -0,0 +1,82 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.util.ArrayList; +import java.util.List; + +import cn.nukkit.Player; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.TextFormat; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.manager.LanguageManager; + +public class cmd_help extends PowerCommand { + + public cmd_help(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + ArrayList help_messages = new ArrayList(); + + LanguageManager languageManager = plugin.getLanguageManager(); + List lines = languageManager.getKeys("commands"); + + int lines_per_page = sender instanceof Player ? 5 : 10; + int last_page = lines.size() / lines_per_page; + + int page = 0; + if (args.length > 0) { + page = args[0].replaceAll("[a-zA-Z]", "").length() > 0 + ? Integer.parseInt(args[0].replaceAll("[a-zA-Z]", "")) + : 0; + + if (!(sender instanceof Player)) { + page -= 1; + } + } + + page = page < 0 ? 0 : page; + page = page > last_page ? last_page : page; + + if (lines != null) { + help_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + + "==="); + help_messages.add(TextFormat.AQUA + "Page " + TextFormat.BLUE + (page + 1) + TextFormat.AQUA + "/" + + TextFormat.BLUE + (last_page + 1)); + help_messages.add(TextFormat.AQUA + "Next page " + TextFormat.BLUE + "/" + commandLabel + " help " + + TextFormat.BLUE + (page + 2 > last_page + 1 ? last_page + 1 : page + 2)); + + int line_index = 0; + for (String section : lines) { + if (line_index >= page * lines_per_page && line_index < page * lines_per_page + lines_per_page) { + String help_command = section + " " + + languageManager.getUnformattedMessage("commands." + section + ".arguments"); + String help_description = languageManager + .getUnformattedMessage("commands." + section + ".description"); + help_messages.add(TextFormat.BLACK + "[" + TextFormat.GREEN + "/" + commandLabel + " " + + help_command + TextFormat.BLACK + "] " + TextFormat.DARK_GREEN + help_description); + } + line_index += 1; + } + } + + help_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "-----------------------------" + + TextFormat.BLUE + "==="); + + if (plugin != null) + for (String msg : help_messages) + sender.sendMessage(msg); + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_pluginhook.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_pluginhook.java new file mode 100644 index 00000000..818535b4 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_pluginhook.java @@ -0,0 +1,94 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.TextFormat; +import cn.nukkit.Player; + +public class cmd_pluginhook extends PowerCommand { + + public cmd_pluginhook(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0) { + sender.sendMessage( + TextFormat.DARK_AQUA + "--------" + TextFormat.DARK_BLUE + plugin.getDescription().getName() + + TextFormat.DARK_AQUA + "--------"); + sender.sendMessage(TextFormat.GREEN + "Plugin hooks:"); + sender.sendMessage(TextFormat.GREEN + "- None"); + sender.sendMessage(TextFormat.DARK_AQUA + "--------------------------"); + } else if (args.length == 2) { + String state = args[0]; + String pluginname = args[1]; + + if ((state.equalsIgnoreCase("enable") || state.equalsIgnoreCase("disable")) + && plugin.getConfigManager().getMap("plugin_hook", new HashMap()).keySet() + .contains(pluginname.toLowerCase())) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".state-changed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("config_target", pluginname.toLowerCase()) + .put("old_state", + String.valueOf(plugin.getConfigManager() + .getBool("plugin_hook." + pluginname.toLowerCase(), true))) + .put("new_state", String.valueOf(state.equalsIgnoreCase("enable"))) + .build(), + '[', ']')); + + plugin.getConfigManager().setBool("plugin_hook." + pluginname.toLowerCase(), + state.equalsIgnoreCase("enable")); + + } else { + if (state.equalsIgnoreCase("enable") || state.equalsIgnoreCase("disable")) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".unknown-plugin")); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".unknown-state")); + } + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + tabcomplete.add("enable"); + tabcomplete.add("disable"); + } + + if (args.length == 2) { + for (Object plugin : plugin.getConfigManager().getMap("plugin_hook", new HashMap()) + .keySet()) { + tabcomplete.add((String) plugin); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_reload.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_reload.java new file mode 100644 index 00000000..3bf59ddd --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_reload.java @@ -0,0 +1,104 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.util.ArrayList; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_reload extends PowerCommand { + + public cmd_reload(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".warning")); + + if (args.length != 1) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } else { + if (args[0].equalsIgnoreCase("config")) { + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".config-start")); + + plugin.getConfigManager().reload(); + plugin.getLanguageManager().reload(); + plugin.getUsertagStorage().reload(); + + plugin.getStorageLoader().loadData(plugin.getStorageManager()); + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".config-done")); + + } else if (args[0].equalsIgnoreCase("plugin")) { + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".plugin-start")); + + sender.sendMessage("Not implemented yet"); // TODO + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".plugin-done")); + + } else if (args[0].equalsIgnoreCase("all")) { + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".config-start")); + + plugin.getConfigManager().reload(); + plugin.getLanguageManager().reload(); + plugin.getUsertagStorage().reload(); + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".config-done")); + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".plugin-start")); + + sender.sendMessage("Not implemented yet"); // TODO + + plugin.getStorageLoader().loadData(plugin.getStorageManager()); + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".plugin-done")); + + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + tabcomplete.add("plugin"); + tabcomplete.add("config"); + tabcomplete.add("all"); + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_stats.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_stats.java new file mode 100644 index 00000000..63ec52d9 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/core/cmd_stats.java @@ -0,0 +1,83 @@ +package nl.svenar.powerranks.nukkit.commands.core; + +import java.text.SimpleDateFormat; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.TimeZone; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.TextFormat; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_stats extends PowerCommand { + + public cmd_stats(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + + Instant current_time = Instant.now(); + + sender.sendMessage(TextFormat.DARK_AQUA + "--------" + TextFormat.DARK_BLUE + plugin.getDescription().getName() + + TextFormat.DARK_AQUA + "--------"); + sender.sendMessage(TextFormat.GREEN + "Server version: " + TextFormat.DARK_GREEN + plugin.getServer().getName() + + " " + plugin.getServer().getVersion() + " | " + + plugin.getServer().getNukkitVersion()); + sender.sendMessage( + TextFormat.GREEN + "Java version: " + TextFormat.DARK_GREEN + System.getProperty("java.version")); + sender.sendMessage(TextFormat.GREEN + "Storage method: " + TextFormat.DARK_GREEN + + plugin.getConfigManager().getString("storage.type", "yaml").toUpperCase()); + sender.sendMessage(TextFormat.GREEN + "Uptime: " + TextFormat.DARK_GREEN + + format.format(Duration.between(plugin.pluginStartTime, current_time).toMillis())); + sender.sendMessage( + TextFormat.GREEN + "PowerRanks Version: " + TextFormat.DARK_GREEN + + plugin.getDescription().getVersion()); + sender.sendMessage(TextFormat.GREEN + "Registered ranks: " + TextFormat.DARK_GREEN + PRCache.getRanks().size()); + sender.sendMessage( + TextFormat.GREEN + "Registered players: " + TextFormat.DARK_GREEN + PRCache.getPlayers().size()); + + boolean hex_color_supported = isHEXColorsSupported(); + + sender.sendMessage(TextFormat.GREEN + "RGB colors: " + + (hex_color_supported ? TextFormat.DARK_GREEN + "" : TextFormat.DARK_RED + "un") + "supported"); + + sender.sendMessage(TextFormat.GREEN + "Plugin hooks:"); + sender.sendMessage(TextFormat.GREEN + "- None // TODO"); + + // Plugin[] plugins = Bukkit.getPluginManager().getPlugins(); + // String pluginNames = ""; + // for (Plugin plugin : plugins) { + // pluginNames += plugin.getName() + "(" + plugin.getDescription().getVersion() + // + "), "; + // } + // pluginNames = pluginNames.substring(0, pluginNames.length() - 2); + + // sender.sendMessage(TextFormat.GREEN + "Plugins (" + plugins.length + "): " + + // TextFormat.DARK_GREEN + pluginNames); + sender.sendMessage(TextFormat.DARK_AQUA + "--------------------------"); + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } + + private boolean isHEXColorsSupported() { + try { + Class.forName("net.md_5.bungee.api.TextFormat"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addownrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addownrank.java new file mode 100644 index 00000000..8ad50954 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addownrank.java @@ -0,0 +1,105 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_addownrank extends PowerCommand { + + public cmd_addownrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + String targetRankName = args[0]; + + boolean commandAllowed = false; + if (sender instanceof Player) { + commandAllowed = sender + .hasPermission("powerranks.cmd." + commandName.toLowerCase() + "." + targetRankName); + } else { + commandAllowed = true; + } + + if (commandAllowed) { + PRRank rank = PRCache.getRankIgnoreCase(targetRankName); + PRPlayer targetPlayer = PRCache.getPlayer(sender.getName()); + if (rank != null && targetPlayer != null) { + PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); + targetPlayer.addRank(playerRank); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-receiver"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } else { + if (targetPlayer != null && rank != null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + if (sender instanceof Player) { + PRPlayer targetPlayer = PRCache.getPlayer(sender.getName()); + for (PRRank rank : PRCache.getRanks()) { + if (!targetPlayer.hasRank(rank.getName())) { + tabcomplete.add(rank.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addplayerperm.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addplayerperm.java new file mode 100644 index 00000000..eb6ad065 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addplayerperm.java @@ -0,0 +1,121 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_addplayerperm extends PowerCommand { + + public cmd_addplayerperm(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String targetPlayerName = args[0]; + String permission = args[1]; + boolean allowed = true; + // this.setValue(!name.startsWith("-")); + if (permission.startsWith("-")) { + permission = permission.replaceFirst("-", ""); + allowed = false; + } + + boolean result = false; + PRPlayer targetPlayer = PRCache.getPlayer(targetPlayerName); + PRPermission prPermission = new PRPermission(permission, allowed); + if (targetPlayer != null) { + targetPlayer.addPermission(prPermission); + result = true; + } + + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayerName) + .put("permission", permission) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayerName) + .put("permission", permission) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer player : PRCache.getPlayers()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + // for (Permission pai : Nukkit.getServer().getPermissions()) { + for (String perm : plugin.getPermissionRegistry().getPermissions()) { + String userInput = args[1]; + String autocompletePermission = ""; + + if (userInput.contains(".")) { + String[] permSplit = perm.split("\\."); + for (int i = 0; i < permSplit.length; i++) { + String targetPerm = String.join(".", permSplit); + while (targetPerm.endsWith(".")) { + targetPerm = targetPerm.substring(0, targetPerm.length() - 1); + } + if (targetPerm.contains(userInput)) { + autocompletePermission = targetPerm; + permSplit[permSplit.length - 1 - i] = ""; + + } else { + break; + } + } + } else { + autocompletePermission = perm.split("\\.")[0]; + } + + while (autocompletePermission.endsWith(".")) { + autocompletePermission = autocompletePermission.substring(0, autocompletePermission.length() - 1); + } + + if (!tabcomplete.contains(autocompletePermission)) { + tabcomplete.add(autocompletePermission); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addrank.java new file mode 100644 index 00000000..3332d8b6 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_addrank.java @@ -0,0 +1,144 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; +import java.util.Arrays; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_addrank extends PowerCommand { + + public cmd_addrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length >= 2) { + String target_rank = args[1]; + String[] tags = Arrays.copyOfRange(args, 2, args.length); + + boolean commandAllowed = false; + if (sender instanceof Player) { + commandAllowed = sender + .hasPermission("powerranks.cmd." + commandName.toLowerCase() + "." + target_rank); + } else { + commandAllowed = true; + } + + if (commandAllowed) { + PRRank rank = PRCache.getRankIgnoreCase(target_rank); + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (rank != null && targetPlayer != null) { + PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); + boolean alreadyHasRank = targetPlayer.hasRank(rank.getName()); + if (!alreadyHasRank) { + + for (String tag : tags) { + if (tag.split(":").length == 2) { + String[] tagParts = tag.split(":"); + String tagName = tagParts[0]; + String tagValue = tagParts[1]; + + if (tagName.length() > 0 && tagValue.length() > 0) { + playerRank.addTag(tagName, tagValue); + } + } + } + + targetPlayer.addRank(playerRank); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + if (Util.getPlayerByName(targetPlayer.getName()) != null) { + Util.getPlayerByName(targetPlayer.getName()).sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-receiver"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-already-has-rank"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } else { + if (targetPlayer != null && rank != null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } + // users.setGroup(sender instanceof Player ? (Player) sender : null, args[0], + // target_rank, true); + + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer player : PRCache.getPlayers()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + for (PRRank rank : PRCache.getRanks()) { + if (!targetPlayer.hasRank(rank.getName())) { + tabcomplete.add(rank.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_checkrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_checkrank.java new file mode 100644 index 00000000..6877f687 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_checkrank.java @@ -0,0 +1,116 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_checkrank extends PowerCommand { + + public cmd_checkrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0) { + if (sender instanceof Player) { + // String rankname = this.users.getPrimaryRank(); + List playerRanks = new ArrayList<>(); + for (PRPlayerRank rank : PRCache.getPlayer(((Player) sender).getUniqueId().toString()) + .getRanks()) { + playerRanks.add(rank.getName()); + } + if (playerRanks.size() > 0) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage("commands." + commandName.toLowerCase() + ".success-self"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("ranks", String.join(", ", playerRanks)) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-self-none"), + ImmutableMap.builder() + .put("player", sender.getName()) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage("general.console-is-no-player")); + } + } else if (args.length == 1) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + List playerRanks = new ArrayList<>(); + for (PRPlayerRank rank : PRCache.getPlayer((targetPlayer).getUUID().toString()).getRanks()) { + playerRanks.add(rank.getName()); + } + if (playerRanks.size() > 0) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage("commands." + commandName.toLowerCase() + ".success-target"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("ranks", String.join(", ", playerRanks)) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-target-none"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", args[0]) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer player : PRCache.getPlayers()) { + tabcomplete.add(player.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_delplayerperm.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_delplayerperm.java new file mode 100644 index 00000000..8f50f703 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_delplayerperm.java @@ -0,0 +1,121 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_delplayerperm extends PowerCommand { + + public cmd_delplayerperm(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String targetPlayerName = args[0]; + final String permission = args[1]; + + boolean result = false; + PRPlayer targetPlayer = PRCache.getPlayer(targetPlayerName); + if (targetPlayer != null) { + for (PRPermission prPermission : targetPlayer.getPermissions()) { + targetPlayer.removePermission(prPermission); + result = true; + break; + } + } + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayerName) + .put("permission", permission) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayerName) + .put("permission", permission) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer player : PRCache.getPlayers()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + // for (Permission pai : Nukkit.getServer().getPermissions()) { + for (PRPermission perm : targetPlayer.getPermissions()) { + // String perm = pai.getPermission(); + String userInput = args[1]; + String autocompletePermission = ""; + + if (userInput.contains(".")) { + String[] permSplit = perm.getName().split("\\."); + for (int i = 0; i < permSplit.length; i++) { + String targetPerm = String.join(".", permSplit); + while (targetPerm.endsWith(".")) { + targetPerm = targetPerm.substring(0, targetPerm.length() - 1); + } + if (targetPerm.contains(userInput)) { + autocompletePermission = targetPerm; + permSplit[permSplit.length - 1 - i] = ""; + + } else { + break; + } + } + } else { + autocompletePermission = perm.getName().split("\\.")[0]; + } + + while (autocompletePermission.endsWith(".")) { + autocompletePermission = autocompletePermission.substring(0, + autocompletePermission.length() - 1); + } + + if (!tabcomplete.contains(autocompletePermission)) { + tabcomplete.add(autocompletePermission); + } + } + } + } + + return tabcomplete; + } +} \ No newline at end of file diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_delrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_delrank.java new file mode 100644 index 00000000..7b8ca1bd --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_delrank.java @@ -0,0 +1,124 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_delrank extends PowerCommand { + + + public cmd_delrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + String target_rank = args[1]; + + boolean commandAllowed = false; + if (sender instanceof Player) { + commandAllowed = sender + .hasPermission("powerranks.cmd." + commandName.toLowerCase() + "." + target_rank); + } else { + commandAllowed = true; + } + + if (commandAllowed) { + PRRank rank = PRCache.getRankIgnoreCase(target_rank); + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (rank != null && targetPlayer != null) { + PRPlayerRank playerRank = null; + for (PRPlayerRank targetPlayerRank : targetPlayer.getRanks()) { + if (targetPlayerRank.getName().equals(rank.getName())) { + playerRank = targetPlayerRank; + break; + } + } + if (playerRank != null) { + targetPlayer.removeRank(playerRank); + } + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + + if (Util.getPlayerByName(targetPlayer.getName()) != null) { + Util.getPlayerByName(targetPlayer.getName()).sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-receiver"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } else { + if (targetPlayer != null && rank != null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } + // users.setGroup(sender instanceof Player ? (Player) sender : null, args[0], + // target_rank, true); + + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer player : PRCache.getPlayers()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + for (PRPlayerRank rank : targetPlayer.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_haspermission.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_haspermission.java new file mode 100644 index 00000000..d8bc6256 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_haspermission.java @@ -0,0 +1,165 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.ImmutableMap; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_haspermission extends PowerCommand { + + public cmd_haspermission(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + PRPlayer prPlayer = null; + String permissionNode = null; + + if (args.length == 2) { + prPlayer = PRCache.getPlayer(args[0]); + permissionNode = args[1]; + + if (prPlayer == null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", args[0]) + .build(), + '[', ']')); + } + + if (permissionNode == null || permissionNode.length() == 0) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.permission-not-found"), + ImmutableMap.builder() + .put("permission", args[1]) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + if (prPlayer != null && permissionNode != null && permissionNode.length() > 0) { + Player player = Util.getPlayerByName(prPlayer.getName()); + if (player != null) { + List playerPermissions = prPlayer.getEffectivePermissions(); + PRPermission targetPermission = null; + PRPermission targetWildcardPermission = null; + + for (PRPermission permission : playerPermissions) { + if (permission.getName().equals(permissionNode)) { + targetPermission = permission; + break; + } + } + + ArrayList wildcardPermissions = PRUtil.generateWildcardList(permissionNode); + for (PRPermission perm : playerPermissions) { + + if (wildcardPermissions.contains(perm.getName())) { + targetWildcardPermission = perm; + break; + } + } + + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + PowerRanks.getInstance().getDescription().getName() + TextFormat.DARK_AQUA + "----------" + + TextFormat.BLUE + "==="); + sender.sendMessage(TextFormat.GREEN + "Player: " + TextFormat.DARK_GREEN + player.getName()); + sender.sendMessage(TextFormat.GREEN + "Permission: " + TextFormat.DARK_GREEN + permissionNode); + sender.sendMessage(TextFormat.GREEN + "Player has permission: " + + (targetPermission == null ? TextFormat.DARK_RED + "no" : TextFormat.DARK_GREEN + "yes")); + sender.sendMessage(TextFormat.GREEN + "Permission allowed value: " + + (targetPermission == null ? TextFormat.GOLD + "unknown" + : (targetPermission.getValue() ? TextFormat.DARK_GREEN + "allowed" + : TextFormat.DARK_RED + "denied"))); + sender.sendMessage(TextFormat.GREEN + "has Wildcard variant: " + + (targetWildcardPermission == null ? TextFormat.GOLD + "no" + : TextFormat.DARK_GREEN + targetWildcardPermission.getName() + " (allowed: " + + (targetWildcardPermission.getValue() ? TextFormat.DARK_GREEN + "yes" + : TextFormat.DARK_RED + "no") + + TextFormat.DARK_GREEN + ")")); + sender.sendMessage(TextFormat.GREEN + "Is permission allowed: " + + (player.hasPermission(permissionNode) ? TextFormat.DARK_GREEN + "yes" + : TextFormat.DARK_RED + "no")); + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-online"), + ImmutableMap.builder() + .put("player", sender.getName()) + .build(), + '[', ']')); + } + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer player : PRCache.getPlayers()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + // for (Permission pai : Nukkit.getServer().getPermissions()) { + for (String perm : plugin.getPermissionRegistry().getPermissions()) { + String userInput = args[1]; + String autocompletePermission = ""; + + if (userInput.contains(".")) { + String[] permSplit = perm.split("\\."); + for (int i = 0; i < permSplit.length; i++) { + String targetPerm = String.join(".", permSplit); + while (targetPerm.endsWith(".")) { + targetPerm = targetPerm.substring(0, targetPerm.length() - 1); + } + if (targetPerm.contains(userInput)) { + autocompletePermission = targetPerm; + permSplit[permSplit.length - 1 - i] = ""; + + } else { + break; + } + } + } else { + autocompletePermission = perm.split("\\.")[0]; + } + + while (autocompletePermission.endsWith(".")) { + autocompletePermission = autocompletePermission.substring(0, autocompletePermission.length() - 1); + } + + if (!tabcomplete.contains(autocompletePermission)) { + tabcomplete.add(autocompletePermission); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_listplayerpermissions.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_listplayerpermissions.java new file mode 100644 index 00000000..701bd854 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_listplayerpermissions.java @@ -0,0 +1,155 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; +import java.util.Set; + +import com.google.common.collect.ImmutableMap; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_listplayerpermissions extends PowerCommand { + + public cmd_listplayerpermissions(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + displayList(sender, targetPlayer, commandLabel, 0); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", args[0]) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + int page = Integer.parseInt(args[1].replaceAll("[a-zA-Z]", "")); + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + displayList(sender, targetPlayer, commandLabel, page); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", args[0]) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + private void displayList(CommandSender sender, PRPlayer prPlayer, String commandLabel, int page) { + ArrayList output_messages = new ArrayList(); + + output_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + "==="); + + Set playerPermissions = prPlayer.getPermissions(); + + int lines_per_page = sender instanceof Player ? 5 : 10; + int last_page = playerPermissions.size() / lines_per_page; + + if (!(sender instanceof Player)) { + page -= 1; + } + + page = page < 0 ? 0 : page; + page = page > last_page ? last_page : page; + + if (sender instanceof Player) { + String page_selector_tellraw = "tellraw " + sender.getName() + + " [\"\",{\"text\":\"Page \",\"color\":\"aqua\"},{\"text\":\"" + "%next_page%" + + "\",\"color\":\"blue\"},{\"text\":\"/\",\"color\":\"aqua\"}" + + ",{\"text\":\"%last_page%\",\"color\":\"blue\"},{\"text\":\": \",\"color\":\"aqua\"}" + + ",{\"text\":\"[\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listplayerpermissions %playername% " + "%previous_page%" + + "\"}},{\"text\":\"<\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listplayerpermissions %playername% " + "%previous_page%" + + "\"}},{\"text\":\"]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listplayerpermissions %playername% " + "%previous_page%" + + "\"}},{\"text\":\" \",\"color\":\"aqua\"},{\"text\":\"[\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listplayerpermissions %playername% " + "%next_page%" + + "\"}},{\"text\":\">\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listplayerpermissions %playername% " + "%next_page%" + + "\"}},{\"text\":\"]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listplayerpermissions %playername% " + "%next_page%" + "\"}}]"; + + page_selector_tellraw = page_selector_tellraw.replaceAll("%next_page%", String.valueOf(page + 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%previous_page%", String.valueOf(page - 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%last_page%", + String.valueOf(last_page + 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%playername%", prPlayer.getName()); + page_selector_tellraw = page_selector_tellraw.replaceAll("%commandlabel%", commandLabel); + + output_messages.add(page_selector_tellraw); + + output_messages.add(TextFormat.AQUA + prPlayer.getName() + "'s permissions:"); + + // sender.sendMessage("[A] " + last_page + " " + lines_per_page); + } else { + output_messages.add(TextFormat.AQUA + "Page " + TextFormat.BLUE + (page + 1) + TextFormat.AQUA + "/" + + TextFormat.BLUE + (last_page + 1)); + output_messages.add(TextFormat.AQUA + "Next page " + TextFormat.BLUE + "/" + commandLabel + + " listplayerpermissions " + prPlayer.getName() + " " + TextFormat.BLUE + + (page + 2 > last_page + 1 ? last_page + 1 : page + 2)); + } + + int line_index = 0; + for (PRPermission permission : playerPermissions) { + if (line_index >= page * lines_per_page && line_index < page * lines_per_page + lines_per_page) { + output_messages.add(TextFormat.DARK_GREEN + "#" + (line_index + 1) + ". " + + (permission.getValue() ? TextFormat.GREEN : TextFormat.RED) + permission.getName()); + } + line_index += 1; + } + + output_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + + if (plugin != null) { + for (String msg : output_messages) { + if (msg.startsWith("tellraw")) { + plugin.getServer().dispatchCommand((CommandSender) plugin.getServer().getConsoleSender(), msg); + } else { + sender.sendMessage(msg); + } + } + } + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer prPlayer : PRCache.getPlayers()) { + tabcomplete.add(prPlayer.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_nick.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_nick.java new file mode 100644 index 00000000..b6d0ca99 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_nick.java @@ -0,0 +1,150 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_nick extends PowerCommand { + + public cmd_nick(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { // Change own nickname + if (sender instanceof Player) { + Player targetPlayer = (Player) sender; + String nickname = args[0]; + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".setown")) { + if (updateNickname(targetPlayer, nickname)) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setown.success"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + } else { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setown.failed"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + } else if (args.length == 2) { // Change other's nickname + String targetPlayername = args[0]; + Player targetPlayer = Util.getPlayerByName(targetPlayername); + if (targetPlayer != null) { + String nickname = args[1]; + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".setother")) { + if (updateNickname(targetPlayer, nickname)) { + + targetPlayer.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setown.success"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setother.success"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".setother.failed"), + ImmutableMap.builder() + .put("target", targetPlayer.getName()) + .put("nickname", nickname) + .build(), + '[', ']')); + + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + } else { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase()) + || sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".*")) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + return false; + } + + private boolean updateNickname(Player targetPlayer, String nickname) { + PRPlayer prPlayer = PRCache.getPlayer(targetPlayer.getUniqueId().toString()); + if (prPlayer == null) { + return false; + } + prPlayer.setNickname(nickname); + return true; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer prPlayer : PRCache.getPlayers()) { + tabcomplete.add(prPlayer.getName()); + } + } + + if (args.length == 2) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + for (PRRank rank : PRCache.getRanks()) { + if (!targetPlayer.hasRank(rank.getName())) { + tabcomplete.add(rank.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_playerinfo.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_playerinfo.java new file mode 100644 index 00000000..37f39bd1 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_playerinfo.java @@ -0,0 +1,263 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TimeZone; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.TextFormat; +import cn.nukkit.Player; + +public class cmd_playerinfo extends PowerCommand { + + public cmd_playerinfo(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + String targetPlayerName = args[0]; + PRPlayer targetPlayer = PRCache.getPlayer(targetPlayerName); + if (targetPlayer != null) { + messagePlayerInfo(sender, targetPlayer, 0); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayerName) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + try { + String targetPlayerName = args[0]; + int page = Integer.parseInt(args[1].replaceAll("[a-zA-Z]", "")); + PRPlayer targetPlayer = PRCache.getPlayer(targetPlayerName); + if (targetPlayer != null) { + messagePlayerInfo(sender, targetPlayer, page); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.player-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayerName) + .build(), + '[', ']')); + } + } catch (NumberFormatException e) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer prPlayer : PRCache.getPlayers()) { + tabcomplete.add(prPlayer.getName()); + } + } + + return tabcomplete; + } + + public void messagePlayerInfo(final CommandSender sender, final PRPlayer prPlayer, int page) { + Player player = Util.getPlayerByName(prPlayer.getName()); + + SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + + long playerPlaytime = prPlayer.getPlaytime(); + + final long days = TimeUnit.SECONDS.toDays(playerPlaytime); + final long hours = TimeUnit.SECONDS.toHours(playerPlaytime) + - TimeUnit.DAYS.toHours(TimeUnit.SECONDS.toDays(playerPlaytime)); + final long minutes = TimeUnit.SECONDS.toMinutes(playerPlaytime) + - TimeUnit.HOURS.toMinutes(TimeUnit.SECONDS.toHours(playerPlaytime)); + final long seconds = TimeUnit.SECONDS.toSeconds(playerPlaytime) + - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(playerPlaytime)); + + String playerPlaytimeFormatted = days > 0 + ? String.format("%02d %s %02d:%02d:%02d", days, days == 1 ? "day" : "days", hours, minutes, seconds) + : String.format("%02d:%02d:%02d", hours, minutes, seconds); + + String formatted_ranks = ""; + + List ranknames = new ArrayList<>(); + for (PRPlayerRank playerRank : prPlayer.getRanks()) { + if (!playerRank.isDisabled()) { + ranknames.add(playerRank.getName()); + } + } + + for (String rankname : ranknames) { + formatted_ranks += rankname + " "; + } + if (formatted_ranks.endsWith(" ")) { + formatted_ranks = formatted_ranks.substring(0, formatted_ranks.length() - 1); + } + + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + + "==="); + if (player == null) { + sender.sendMessage(TextFormat.GREEN + "Player not online, showing limited information."); + } + sender.sendMessage(TextFormat.GREEN + "UUID: " + TextFormat.DARK_GREEN + prPlayer.getUUID()); + if (player != null) { + sender.sendMessage(TextFormat.GREEN + "Player name: " + TextFormat.DARK_GREEN + player.getDisplayName() + + (!player.getDisplayName().equals(player.getName()) + ? (TextFormat.DARK_GREEN + " aka " + player.getName()) + : "")); + sender.sendMessage(TextFormat.GREEN + "First joined (UTC): " + TextFormat.DARK_GREEN + + format.format(player.getFirstPlayed())); + sender.sendMessage( + TextFormat.GREEN + "Last joined (UTC): " + TextFormat.DARK_GREEN + + format.format(player.getLastPlayed())); + } else { + sender.sendMessage(TextFormat.GREEN + "Player name: " + TextFormat.DARK_GREEN + prPlayer.getName()); + } + sender.sendMessage(TextFormat.GREEN + "Playtime: " + TextFormat.DARK_GREEN + playerPlaytimeFormatted); + if (player != null) { + sender.sendMessage(TextFormat.GREEN + "Chat format: " + TextFormat.RESET + getSampleChatFormat(player)); + } + sender.sendMessage(TextFormat.GREEN + "Rank(s): " + TextFormat.DARK_GREEN + formatted_ranks); + if (player != null) { + sender.sendMessage(TextFormat.GREEN + "Effective Permissions: "); + + List playerPermissions = prPlayer.getEffectivePermissions(); + int lines_per_page = sender instanceof Player ? 5 : 10; + int last_page = playerPermissions.size() / lines_per_page; + + if (!(sender instanceof Player)) { + page -= 1; + } + + page = page < 0 ? 0 : page; + page = page > last_page ? last_page : page; + + sender.sendMessage(TextFormat.AQUA + "Page " + TextFormat.BLUE + (page + 1) + TextFormat.AQUA + "/" + + TextFormat.BLUE + (last_page + 1)); + sender.sendMessage(TextFormat.AQUA + "Next page " + TextFormat.BLUE + "/pr" + " playerinfo " + + player.getName() + " " + TextFormat.BLUE + + (page + 2 > last_page + 1 ? last_page + 1 : page + 2)); + + int line_index = 0; + for (PRPermission permission : playerPermissions) { + if (line_index >= page * lines_per_page && line_index < page * lines_per_page + lines_per_page) { + sender.sendMessage(TextFormat.DARK_GREEN + "#" + (line_index + 1) + ". " + + (!permission.getValue() ? TextFormat.RED : TextFormat.GREEN) + permission.getName()); + } + line_index += 1; + } + } + + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + } + + private String getSampleChatFormat(Player player) { + String playersChatMessage = "message"; + + String format = plugin.getConfigManager().getString("chat.format", ""); + + List ranknames = new ArrayList<>(); + for (PRPlayerRank playerRank : PRCache.getPlayer(player.getUniqueId().toString()).getRanks()) { + ranknames.add(playerRank.getName()); + } + + List ranks = new ArrayList(); + for (String rankname : ranknames) { + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + ranks.add(rank); + } + } + + PRUtil.sortRanksByWeight(ranks); + PRUtil.reverseRanks(ranks); + + String formatted_prefix = ""; + String formatted_suffix = ""; + String chatColor = ranks.size() > 0 ? ranks.get(0).getChatcolor() : "&f"; + String nameColor = ranks.size() > 0 ? ranks.get(0).getNamecolor() : "&f"; + String usertag = ""; + + for (PRRank rank : ranks) { + formatted_prefix += rank.getPrefix() + " "; + formatted_suffix += rank.getSuffix() + " "; + } + + if (formatted_prefix.endsWith(" ")) { + formatted_prefix = formatted_prefix.substring(0, formatted_prefix.length() - 1); + } + + if (formatted_suffix.endsWith(" ")) { + formatted_suffix = formatted_suffix.substring(0, formatted_suffix.length() - 1); + } + + PRPlayer targetPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + Map availableUsertags = plugin.getUsertagStorage().getMap("usertags", new HashMap()); + Set playerUsertags = targetPlayer.getUsertags(); + + for (String playerUsertag : playerUsertags) { + String value = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(playerUsertag)) { + value = entry.getValue().toString(); + } + } + + if (value.length() > 0) { + usertag += (usertag.length() > 0 ? " " : "") + value; + } + } + + if (!player.hasPermission("powerranks.chat.chatcolor")) { + playersChatMessage = playersChatMessage.replaceAll("(&[0-9a-fA-FiIjJrRlLmMnNoO])|(#[0-9a-fA-F]{6})", ""); + } + String player_formatted_name = (nameColor.length() == 0 ? "&r" : nameColor) + player.getDisplayName(); + String player_formatted_chat_msg = (chatColor.length() == 0 ? "&r" : chatColor) + playersChatMessage; + + format = PRUtil.powerFormatter(format, ImmutableMap.builder().put("prefix", formatted_prefix) + .put("suffix", formatted_suffix) + .put("usertag", usertag) + .put("player", player_formatted_name).put("msg", player_formatted_chat_msg) + .put("world", player.getLevel().getName()).build(), '[', ']'); + + format = plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, format, true, false, false); + + return format; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_setownrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_setownrank.java new file mode 100644 index 00000000..46bbe972 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_setownrank.java @@ -0,0 +1,96 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setownrank extends PowerCommand { + + public cmd_setownrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + String targetRank = args[0]; + + boolean commandAllowed = false; + if (sender instanceof Player) { + commandAllowed = sender + .hasPermission("powerranks.cmd." + commandName.toLowerCase() + "." + targetRank); + } else { + commandAllowed = true; + } + + if (commandAllowed) { + PRRank rank = PRCache.getRankIgnoreCase(targetRank); + PRPlayer targetPlayer = PRCache.getPlayer(sender.getName()); + if (rank != null && targetPlayer != null) { + PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); + targetPlayer.setRank(playerRank); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } else { + if (targetPlayer != null && rank != null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + if (sender instanceof Player) { + PRPlayer targetPlayer = PRCache.getPlayer(sender.getName()); + for (PRRank rank : PRCache.getRanks()) { + if (!targetPlayer.hasRank(rank.getName())) { + tabcomplete.add(rank.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_setrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_setrank.java new file mode 100644 index 00000000..2ebc4761 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/player/cmd_setrank.java @@ -0,0 +1,173 @@ +package nl.svenar.powerranks.nukkit.commands.player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map.Entry; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_setrank extends PowerCommand { + + public cmd_setrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length >= 2) { + String target_rank = args[1]; + String[] tags = Arrays.copyOfRange(args, 2, args.length); + + boolean commandAllowed = sender.hasPermission("powerranks.cmd." + commandName.toLowerCase()); + if (sender instanceof Player) { + PRPlayer prPlayer = PRCache.getPlayer(((Player) sender).getUniqueId().toString()); + if (sender instanceof Player) { + for (PRPermission permission : prPlayer.getEffectivePermissions()) { + if (permission.getName() + .equalsIgnoreCase("powerranks.cmd." + commandName.toLowerCase() + "." + target_rank)) { + commandAllowed = permission.getValue(); + break; + } + } + } + } else { + commandAllowed = true; + } + + if (commandAllowed) { + PRRank rank = PRCache.getRankIgnoreCase(target_rank); + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (rank != null && targetPlayer != null) { + PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); + + for (String tag : tags) { + if (tag.split(":").length == 2) { + String[] tagParts = tag.split(":"); + String tagName = tagParts[0]; + String tagValue = tagParts[1]; + + if (tagName.length() > 0 && tagValue.length() > 0) { + playerRank.addTag(tagName, tagValue); + if (tagName.equalsIgnoreCase("expires")) { + List returnRanks = new ArrayList(); + for (PRPlayerRank prRank : targetPlayer.getRanks()) { + String prRankTags = ""; + for (Entry prRankTagEntry : prRank.getTags().entrySet()) { + prRankTags += ";" + prRankTagEntry.getKey() + ":" + prRankTagEntry.getValue(); + } + returnRanks.add(prRank.getName() + prRankTags); + } + playerRank.addTag("expiry-return-ranks", returnRanks); + } + } + } + } + + targetPlayer.setRank(playerRank); + + boolean hasRank = false; + for (PRPlayerRank playerrank : targetPlayer.getRanks()) { + if (playerrank.getName().equals(rank.getName())) { + hasRank = true; + break; + } + } + if (hasRank) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-executor"), + ImmutableMap.builder() + .put("player", targetPlayer.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + + if (Util.getPlayerByName(targetPlayer.getName()) != null) { + Util.getPlayerByName(targetPlayer.getName()).sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-receiver"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rank.getName()) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager() + .getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-executor"), + ImmutableMap.builder() + .put("player", targetPlayer == null ? args[0] : targetPlayer.getName()) + .put("rank", rank == null ? args[1] : rank.getName()) + .build(), + '[', ']')); + } + + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase()) + || sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".*")) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRPlayer prPlayer : PRCache.getPlayers()) { + tabcomplete.add(prPlayer.getName()); + } + } + + if (args.length == 2) { + PRPlayer targetPlayer = PRCache.getPlayer(args[0]); + if (targetPlayer != null) { + for (PRRank rank : PRCache.getRanks()) { + if (!targetPlayer.hasRank(rank.getName())) { + tabcomplete.add(rank.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_addinheritance.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_addinheritance.java new file mode 100644 index 00000000..2a13defd --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_addinheritance.java @@ -0,0 +1,80 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_addinheritance extends PowerCommand { + + + public cmd_addinheritance(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0]; + final String inheritance = args[1]; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.addInheritance(inheritance); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("inheritance", inheritance) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", PRCache.getRank(rankname) == null ? rankname : inheritance) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + if (args.length == 2) { + for (PRRank rank : PRCache.getRanks()) { + if (!rank.getName().toLowerCase().contains(args[0].toLowerCase())) { + tabcomplete.add(rank.getName()); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_addperm.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_addperm.java new file mode 100644 index 00000000..b642b423 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_addperm.java @@ -0,0 +1,127 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_addperm extends PowerCommand { + + + public cmd_addperm(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0].equals("*") ? args[0] : args[0]; + String permissionNode = args[1]; + boolean allowed = true; + // this.setValue(!name.startsWith("-")); + if (permissionNode.startsWith("-")) { + permissionNode = permissionNode.replaceFirst("-", ""); + allowed = false; + } + PRRank rank = PRCache.getRank(rankname); + PRPermission permission = new PRPermission(permissionNode, allowed); + if (rank != null) { + rank.addPermission(permission); + if (rankname.equals("*")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-all"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } + } else { // Rank not found + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + if (args.length == 2) { + // for (Permission pai : Nukkit.getServer().getPermissions()) { + for (String perm : plugin.getPermissionRegistry().getPermissions()) { + String userInput = args[1]; + String autocompletePermission = ""; + + if (userInput.contains(".")) { + String[] permSplit = perm.split("\\."); + for (int i = 0; i < permSplit.length; i++) { + String targetPerm = String.join(".", permSplit); + while (targetPerm.endsWith(".")) { + targetPerm = targetPerm.substring(0, targetPerm.length() - 1); + } + if (targetPerm.contains(userInput)) { + autocompletePermission = targetPerm; + permSplit[permSplit.length - 1 - i] = ""; + + } else { + break; + } + } + } else { + autocompletePermission = perm.split("\\.")[0]; + } + + while (autocompletePermission.endsWith(".")) { + autocompletePermission = autocompletePermission.substring(0, autocompletePermission.length() - 1); + } + + if (!tabcomplete.contains(autocompletePermission)) { + tabcomplete.add(autocompletePermission); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_createrank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_createrank.java new file mode 100644 index 00000000..88307351 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_createrank.java @@ -0,0 +1,85 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_createrank extends PowerCommand { + + + public cmd_createrank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String rankname = args[0]; + PRRank rank = PRCache.createRank(rankname); + String[] forbiddenColorCharacters = { "&", "#" }; + String[] forbiddenCharacters = { "`", "~", "!", "@", "$", "%", "^", "*", "(", ")", "{", "}", "[", "]", ":", + ";", "\"", "'", "|", "\\", "?", "/", ">", "<", ",", ".", "+", "=" }; + if (rank != null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + if (PRUtil.stringContainsItemFromList(rankname, forbiddenColorCharacters)) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".warning-color"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + + if (PRUtil.stringContainsItemFromList(rankname, forbiddenCharacters)) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".warning-character"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_deleterank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_deleterank.java new file mode 100644 index 00000000..b220929e --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_deleterank.java @@ -0,0 +1,70 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_deleterank extends PowerCommand { + + + public cmd_deleterank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String rankname = args[0]; + PRRank rank = PRCache.getRank(rankname); + PRCache.removeRank(rank); + if (PRCache.getRank(rankname) == null) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_delinheritance.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_delinheritance.java new file mode 100644 index 00000000..d8c0b316 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_delinheritance.java @@ -0,0 +1,81 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_delinheritance extends PowerCommand { + + + public cmd_delinheritance(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0]; + final String inheritance = args[1]; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.removeInheritance(inheritance); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("inheritance", inheritance) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", PRCache.getRank(rankname) == null ? rankname : inheritance) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + if (args.length == 2) { + PRRank rank = PRCache.getRankIgnoreCase(args[0]); + if (rank != null) { + for (String inheritance : rank.getInheritances()) { + tabcomplete.add(inheritance); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_delperm.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_delperm.java new file mode 100644 index 00000000..221836b7 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_delperm.java @@ -0,0 +1,117 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_delperm extends PowerCommand { + + + public cmd_delperm(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0].equals("*") ? args[0] : args[0]; + final String permissionNode = args[1]; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + boolean found = false; + for (PRPermission permission : rank.getPermissions()) { + if (permission.getName().equalsIgnoreCase(permissionNode)) { + rank.removePermission(permission); + found = true; + break; + } + } + if (found) { + if (rankname.equals("*")) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-all"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } + } else { // Permission not found + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } + } else { // Rank not found + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("permission", permissionNode) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + if (args.length == 2) { + PRRank rank = PRCache.getRankIgnoreCase(args[0]); + if (rank != null) { + for (PRPermission permission : rank.getPermissions()) { + + if (!tabcomplete.contains(permission.getName())) { + tabcomplete.add(permission.getName()); + } + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listdefaultranks.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listdefaultranks.java new file mode 100644 index 00000000..dd3ac500 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listdefaultranks.java @@ -0,0 +1,65 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_listdefaultranks extends PowerCommand { + + public cmd_listdefaultranks(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0) { + Set ranks = PRCache.getDefaultRanks(); + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + + "==="); + // sender.sendMessage(TextFormat.DARK_GREEN + "Number of ranks: " + + // TextFormat.GREEN + ranks.size()); + sender.sendMessage(TextFormat.AQUA + "Ranks (" + ranks.size() + "):"); + int index = 0; + + List sortedRanks = new ArrayList<>(ranks); + PRUtil.sortRanksByWeight(sortedRanks); + PRUtil.reverseRanks(sortedRanks); + + for (PRRank rank : sortedRanks) { + index++; + sender.sendMessage( + TextFormat.DARK_GREEN + "#" + index + ". " + TextFormat.GRAY + "(" + rank.getWeight() + + ") " + TextFormat.GREEN + rank.getName() + TextFormat.RESET + " " + + plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, rank.getPrefix(), true, false, false)); + } + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listpermissions.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listpermissions.java new file mode 100644 index 00000000..7c56288c --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listpermissions.java @@ -0,0 +1,167 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; +import java.util.List; + +import com.google.common.collect.ImmutableMap; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_listpermissions extends PowerCommand { + + + public cmd_listpermissions(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + String rankName = ""; + List ranks = new ArrayList(); + for (PRRank rank : PRCache.getRanks()) { + ranks.add(rank.getName()); + } + if (args.length == 1) { + rankName = args[0]; + + if (ranks.contains(rankName)) { + // Messages.listRankPermissions(sender, s, rankName, 0); + displayRankPermissions(sender, rankName, commandLabel, 0); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", args[0]) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + rankName = args[0]; + if (ranks.contains(rankName)) { + int page = Integer.parseInt(args[1].replaceAll("[a-zA-Z]", "")); + // Messages.listRankPermissions(sender, s, rankName, page); + displayRankPermissions(sender, rankName, commandLabel, page); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", args[0]) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + private void displayRankPermissions(CommandSender sender, String rankName, String commandLabel, int page) { + ArrayList output_messages = new ArrayList(); + + output_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + "==="); + + PRRank rank = PRCache.getRank(rankName); + List ranksPermissions = rank.getPermissions(); + + int lines_per_page = sender instanceof Player ? 5 : 10; + int last_page = ranksPermissions.size() / lines_per_page; + + if (!(sender instanceof Player)) { + page -= 1; + } + + page = page < 0 ? 0 : page; + page = page > last_page ? last_page : page; + + if (sender instanceof Player) { + String page_selector_tellraw = "tellraw " + sender.getName() + + " [\"\",{\"text\":\"Page \",\"color\":\"aqua\"},{\"text\":\"" + "%next_page%" + + "\",\"color\":\"blue\"},{\"text\":\"/\",\"color\":\"aqua\"}" + + ",{\"text\":\"%last_page%\",\"color\":\"blue\"},{\"text\":\": \",\"color\":\"aqua\"}" + + ",{\"text\":\"[\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listpermissions %rankname% " + "%previous_page%" + + "\"}},{\"text\":\"<\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listpermissions %rankname% " + "%previous_page%" + + "\"}},{\"text\":\"]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listpermissions %rankname% " + "%previous_page%" + + "\"}},{\"text\":\" \",\"color\":\"aqua\"},{\"text\":\"[\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listpermissions %rankname% " + "%next_page%" + + "\"}},{\"text\":\">\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listpermissions %rankname% " + "%next_page%" + + "\"}},{\"text\":\"]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listpermissions %rankname% " + "%next_page%" + "\"}}]"; + + page_selector_tellraw = page_selector_tellraw.replaceAll("%next_page%", String.valueOf(page + 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%previous_page%", String.valueOf(page - 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%last_page%", + String.valueOf(last_page + 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%rankname%", rankName); + page_selector_tellraw = page_selector_tellraw.replaceAll("%commandlabel%", commandLabel); + + output_messages.add(page_selector_tellraw); + + output_messages.add(TextFormat.AQUA + "Permissions:"); + + // sender.sendMessage("[A] " + last_page + " " + lines_per_page); + } else { + output_messages.add(TextFormat.AQUA + "Page " + TextFormat.BLUE + (page + 1) + TextFormat.AQUA + "/" + + TextFormat.BLUE + (last_page + 1)); + output_messages + .add(TextFormat.AQUA + "Next page " + TextFormat.BLUE + "/" + commandLabel + " listpermissions " + + rankName + " " + TextFormat.BLUE + (page + 2 > last_page + 1 ? last_page + 1 : page + 2)); + } + + int line_index = 0; + for (PRPermission permission : ranksPermissions) { + if (line_index >= page * lines_per_page && line_index < page * lines_per_page + lines_per_page) { + output_messages.add(TextFormat.DARK_GREEN + "#" + (line_index + 1) + ". " + + (permission.getValue() ? TextFormat.GREEN : TextFormat.RED) + permission.getName()); + } + line_index += 1; + } + + output_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + + if (plugin != null) { + for (String msg : output_messages) { + if (msg.startsWith("tellraw")) { + plugin.getServer().dispatchCommand((CommandSender) plugin.getServer().getConsoleSender(), msg); + } else { + sender.sendMessage(msg); + } + } + } + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listranks.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listranks.java new file mode 100644 index 00000000..b3fac45a --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_listranks.java @@ -0,0 +1,55 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; +import java.util.List; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_listranks extends PowerCommand { + + + public cmd_listranks(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + List ranks = PRCache.getRanks(); + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + "==="); + // sender.sendMessage(TextFormat.DARK_GREEN + "Number of ranks: " + + // TextFormat.GREEN + ranks.size()); + sender.sendMessage(TextFormat.AQUA + "Ranks (" + ranks.size() + "):"); + int index = 0; + + List sortedRanks = new ArrayList<>(ranks); + PRUtil.sortRanksByWeight(sortedRanks); + PRUtil.reverseRanks(sortedRanks); + + for (PRRank rank : sortedRanks) { + index++; + sender.sendMessage(TextFormat.DARK_GREEN + "#" + index + ". " + TextFormat.GRAY + "(" + rank.getWeight() + + ") " + TextFormat.GREEN + rank.getName() + TextFormat.RESET + " " + + plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, rank.getPrefix(), true, false, false)); + } + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_rankinfo.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_rankinfo.java new file mode 100644 index 00000000..e736cfb5 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_rankinfo.java @@ -0,0 +1,179 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.utils.TextFormat; +import cn.nukkit.Player; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_rankinfo extends PowerCommand { + + public cmd_rankinfo(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + String target_rank_name = args[0]; + PRRank target_rank = PRCache.getRank(target_rank_name); + if (target_rank != null) { + messageRankInfo(sender, target_rank, 0); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", target_rank_name) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + try { + String target_rank_name = args[0]; + int page = Integer.parseInt(args[1].replaceAll("[a-zA-Z]", "")); + PRRank target_rank = PRCache.getRank(target_rank_name); + if (target_rank != null) { + messageRankInfo(sender, target_rank, page); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", target_rank_name) + .build(), + '[', ']')); + } + } catch (NumberFormatException e) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } + + public void messageRankInfo(CommandSender sender, PRRank rank, int page) { + + String formatted_inheritances = ""; + for (String rankname : rank.getInheritances()) { + formatted_inheritances += rankname + " "; + } + if (formatted_inheritances.endsWith(" ")) { + formatted_inheritances = formatted_inheritances.substring(0, formatted_inheritances.length() - 1); + } + + String formatted_buyableranks = ""; + for (String rankname : rank.getBuyableRanks()) { + formatted_inheritances += rankname + " "; + } + if (formatted_inheritances.endsWith(" ")) { + formatted_inheritances = formatted_inheritances.substring(0, formatted_inheritances.length() - 1); + } + + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + + "==="); + sender.sendMessage(TextFormat.GREEN + "Name: " + TextFormat.DARK_GREEN + rank.getName()); + sender.sendMessage(TextFormat.GREEN + "Weight: " + TextFormat.DARK_GREEN + rank.getWeight()); + sender.sendMessage( + TextFormat.GREEN + "Prefix: " + TextFormat.RESET + plugin.getPowerColor() + .format(PowerColor.UNFORMATTED_COLOR_CHAR, rank.getPrefix(), true, false, false)); + sender.sendMessage( + TextFormat.GREEN + "Suffix: " + TextFormat.RESET + plugin.getPowerColor() + .format(PowerColor.UNFORMATTED_COLOR_CHAR, rank.getSuffix(), true, false, false)); + sender.sendMessage(TextFormat.GREEN + "Chat format: " + TextFormat.RESET + + getSampleChatFormat(null, sender.getName(), "world", rank)); + sender.sendMessage(TextFormat.YELLOW + "Buyable ranks: " + TextFormat.GOLD + formatted_buyableranks); + sender.sendMessage(TextFormat.YELLOW + "Buy cost: " + TextFormat.GOLD + rank.getBuyCost()); + sender.sendMessage(TextFormat.YELLOW + "Buy description: " + TextFormat.GOLD + rank.getBuyDescription()); + sender.sendMessage(TextFormat.YELLOW + "Buy command: " + TextFormat.GOLD + rank.getBuyCommand()); + sender.sendMessage(TextFormat.GREEN + "Inheritance(s): " + TextFormat.DARK_GREEN + formatted_inheritances); + sender.sendMessage(TextFormat.GREEN + "Effective Permissions: "); + + ArrayList playerPermissions = rank.getPermissions(); + int lines_per_page = sender instanceof Player ? 5 : 10; + int last_page = playerPermissions.size() / lines_per_page; + + if (!(sender instanceof Player)) { + page -= 1; + } + + page = page < 0 ? 0 : page; + page = page > last_page ? last_page : page; + + sender.sendMessage(TextFormat.AQUA + "Page " + TextFormat.BLUE + (page + 1) + TextFormat.AQUA + "/" + + TextFormat.BLUE + (last_page + 1)); + sender.sendMessage(TextFormat.AQUA + "Next page " + TextFormat.BLUE + "/pr" + " rankinfo " + + rank.getName() + " " + TextFormat.BLUE + (page + 2 > last_page + 1 ? last_page + 1 : page + 2)); + + int line_index = 0; + for (PRPermission permission : playerPermissions) { + if (line_index >= page * lines_per_page && line_index < page * lines_per_page + lines_per_page) { + sender.sendMessage(TextFormat.DARK_GREEN + "#" + (line_index + 1) + ". " + + (!permission.getValue() ? TextFormat.RED : TextFormat.GREEN) + permission.getName()); + } + line_index += 1; + } + + sender.sendMessage(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + } + + private String getSampleChatFormat(CommandSender sender, String name, String world, PRRank rank) { + String playersChatMessage = "message"; + + String format = plugin.getConfigManager().getString("chat.format", ""); + + String formatted_prefix = ""; + String formatted_suffix = ""; + String chatColor = rank.getChatcolor(); + String nameColor = rank.getNamecolor(); + String usertag = ""; + + formatted_prefix += rank.getPrefix(); + formatted_suffix += rank.getSuffix(); + + String player_formatted_name = (nameColor.length() == 0 ? "&r" : nameColor) + name; + String player_formatted_chat_msg = (chatColor.length() == 0 ? "&r" : chatColor) + playersChatMessage; + + format = PRUtil.powerFormatter(format, ImmutableMap.builder().put("prefix", formatted_prefix) + .put("suffix", formatted_suffix) + .put("usertag", usertag) + .put("player", player_formatted_name).put("msg", player_formatted_chat_msg) + .put("world", world).build(), '[', ']'); + + format = plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, rank.getSuffix(), true, false, false); + + return format; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_renamerank.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_renamerank.java new file mode 100644 index 00000000..b48f9dab --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_renamerank.java @@ -0,0 +1,73 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_renamerank extends PowerCommand { + + + public cmd_renamerank(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String from = args[0]; + final String to = args[1]; + PRRank rank = PRCache.getRank(from); + if (rank != null) { + rank.setName(to); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", from) + .put("new_rank", to) + .build(), + '[', ']')); + } else { // Rank not found or target name already exists + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", from) + .put("new_rank", to) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setchatcolor.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setchatcolor.java new file mode 100644 index 00000000..5a192beb --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setchatcolor.java @@ -0,0 +1,71 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setchatcolor extends PowerCommand { + + + public cmd_setchatcolor(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0]; + final String color = args[1]; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setChatcolor(color); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("color", color) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setdefault.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setdefault.java new file mode 100644 index 00000000..c3b18770 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setdefault.java @@ -0,0 +1,88 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setdefault extends PowerCommand { + + + public cmd_setdefault(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0]; + final boolean isDefault = args[1].equalsIgnoreCase("true"); + final PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setDefault(isDefault); + + if (isDefault) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-added"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-removed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + if (args.length == 2) { + tabcomplete.add("true"); + tabcomplete.add("false"); + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setnamecolor.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setnamecolor.java new file mode 100644 index 00000000..564325c5 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setnamecolor.java @@ -0,0 +1,72 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setnamecolor extends PowerCommand { + + + public cmd_setnamecolor(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String rankname = args[0]; + final String color = args[1]; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setNamecolor(color); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("color", color) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setprefix.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setprefix.java new file mode 100644 index 00000000..f8f7f464 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setprefix.java @@ -0,0 +1,100 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setprefix extends PowerCommand { + + + public cmd_setprefix(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String rankname = args[0]; + final String prefix = ""; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setSuffix(prefix); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-clear"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("prefix", prefix) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage("general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else if (args.length >= 2) { + final String rankname = args[0]; + String prefix = ""; + for (int i = 1; i < args.length; i++) { + prefix += args[i] + " "; + } + prefix = prefix.substring(0, prefix.length() - 1); + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setSuffix(prefix); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("prefix", prefix) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setsuffix.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setsuffix.java new file mode 100644 index 00000000..bf85c98e --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setsuffix.java @@ -0,0 +1,100 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setsuffix extends PowerCommand { + + + public cmd_setsuffix(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String rankname = args[0]; + final String suffix = ""; + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setSuffix(suffix); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-clear"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("suffix", suffix) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else if (args.length >= 2) { + final String rankname = args[0]; + String suffix = ""; + for (int i = 1; i < args.length; i++) { + suffix += args[i] + " "; + } + suffix = suffix.substring(0, suffix.length() - 1); + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + rank.setSuffix(suffix); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("suffix", suffix) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setweight.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setweight.java new file mode 100644 index 00000000..428bae1e --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/rank/cmd_setweight.java @@ -0,0 +1,89 @@ +package nl.svenar.powerranks.nukkit.commands.rank; + +import java.util.ArrayList; +import java.util.Objects; + +import com.google.common.collect.ImmutableMap; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_setweight extends PowerCommand { + + public cmd_setweight(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + + final String rankname = args[0]; + final PRRank rank = PRCache.getRank(rankname); + if (Objects.isNull(rank)) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "general.rank-not-found"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .build(), + '[', ']')); + } + + int weight = 0; + try { + weight = Integer.parseInt(args[1]); + } catch (Exception e) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".numbers-only"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("weight", args[1]) + .build(), + '[', ']')); + } + + if (rank != null) { + rank.setWeight(weight); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank", rankname) + .put("weight", String.valueOf(weight)) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (PRRank rank : PRCache.getRanks()) { + tabcomplete.add(rank.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_addusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_addusertag.java new file mode 100644 index 00000000..69b3bffa --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_addusertag.java @@ -0,0 +1,116 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_addusertag extends PowerCommand { + + public cmd_addusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String playername = sender.getName(); + final String tag = args[0]; + final boolean result = plugin.getUsertagManager().addUsertag(playername, tag); + Player targetPlayer = plugin.getServer().getPlayer(playername); + if (result) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".other")) { + final String playername = args[0]; + final String tag = args[1]; + final boolean result = plugin.getUsertagManager().addUsertag(playername, tag); + Player targetPlayer = plugin.getServer().getPlayer(playername); + if (result) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (Player player : plugin.getServer().getOnlinePlayers().values()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + for (String tag : plugin.getUsertagManager().getUsertags()) { + tabcomplete.add(tag); + } + Player target_player = Util.getPlayerByName(args[0]); + if (target_player != null) { + for (String tag : PRCache.getPlayer(target_player.getUniqueId().toString()).getUsertags()) { + tabcomplete.remove(tag); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_clearusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_clearusertag.java new file mode 100644 index 00000000..bb545673 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_clearusertag.java @@ -0,0 +1,96 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_clearusertag extends PowerCommand { + + public cmd_clearusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0) { + + final String playername = sender.getName(); + final boolean result = plugin.getUsertagManager().clearUsertag(playername); + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", playername) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", playername) + .build(), + '[', ']')); + } + + } else if (args.length == 1) { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".other")) { + + final String playername = args[0]; + final boolean result = plugin.getUsertagManager().clearUsertag(playername); + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", playername) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", playername) + .build(), + '[', ']')); + } + + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (Player player : plugin.getServer().getOnlinePlayers().values()) { + tabcomplete.add(player.getName()); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_createusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_createusertag.java new file mode 100644 index 00000000..c9681603 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_createusertag.java @@ -0,0 +1,61 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_createusertag extends PowerCommand { + + public cmd_createusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String tag = args[0]; + final String text = args[1]; + final boolean result = plugin.getUsertagManager().createUsertag(tag, text); + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("usertag", tag) + .put("text", text) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("usertag", tag) + .put("text", text) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_delusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_delusertag.java new file mode 100644 index 00000000..682c92a2 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_delusertag.java @@ -0,0 +1,113 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_delusertag extends PowerCommand { + + public cmd_delusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String playername = sender.getName(); + final String tag = args[0]; + final boolean result = plugin.getUsertagManager().delUsertag(playername, tag); + Player targetPlayer = plugin.getServer().getPlayer(playername); + if (result) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".other")) { + final String playername = args[0]; + final String tag = args[1]; + final boolean result = plugin.getUsertagManager().delUsertag(playername, tag); + Player targetPlayer = plugin.getServer().getPlayer(playername); + if (result) { + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (Player player : plugin.getServer().getOnlinePlayers().values()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + Player target_player = Util.getPlayerByName(args[0]); + if (target_player != null) { + for (String tag : PRCache.getPlayer(target_player.getUniqueId().toString()).getUsertags()) { + tabcomplete.add(tag); + } + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_editusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_editusertag.java new file mode 100644 index 00000000..3a84a040 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_editusertag.java @@ -0,0 +1,69 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_editusertag extends PowerCommand { + + public cmd_editusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 2) { + final String tag = args[0]; + final String text = args[1]; + final boolean result = plugin.getUsertagManager().editUsertag(tag, text); + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("usertag", tag) + .put("text", text) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("usertag", tag) + .put("text", text) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (String tag : plugin.getUsertagManager().getUsertags()) { + if (tag.toLowerCase().contains(args[0].toLowerCase())) + tabcomplete.add(tag); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_listusertags.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_listusertags.java new file mode 100644 index 00000000..404f3ed7 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_listusertags.java @@ -0,0 +1,120 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; +import java.util.Set; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; + +public class cmd_listusertags extends PowerCommand { + + public cmd_listusertags(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0) { + displayList(sender, commandLabel, 0); + } else if (args.length == 1) { + int page = Integer.parseInt(args[0].replaceAll("[a-zA-Z]", "")); + displayList(sender, commandLabel, page); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + return false; + } + + private void displayList(CommandSender sender, String commandLabel, int page) { + ArrayList output_messages = new ArrayList(); + + output_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "----------" + TextFormat.AQUA + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------" + TextFormat.BLUE + "==="); + + Set items = plugin.getUsertagManager().getUsertags(); + + int lines_per_page = sender instanceof Player ? 5 : 10; + int last_page = items.size() / lines_per_page; + + if (!(sender instanceof Player)) { + page -= 1; + } + + page = page < 0 ? 0 : page; + page = page > last_page ? last_page : page; + + if (sender instanceof Player) { + String page_selector_tellraw = "tellraw " + sender.getName() + + " [\"\",{\"text\":\"Page \",\"color\":\"aqua\"},{\"text\":\"" + "%next_page%" + + "\",\"color\":\"blue\"},{\"text\":\"/\",\"color\":\"aqua\"}" + + ",{\"text\":\"%last_page%\",\"color\":\"blue\"},{\"text\":\": \",\"color\":\"aqua\"}" + + ",{\"text\":\"[\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listusertags " + "%previous_page%" + + "\"}},{\"text\":\"<\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listusertags " + "%previous_page%" + + "\"}},{\"text\":\"]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listusertags " + "%previous_page%" + + "\"}},{\"text\":\" \",\"color\":\"aqua\"},{\"text\":\"[\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listusertags" + "%next_page%" + + "\"}},{\"text\":\">\",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listusertags " + "%next_page%" + + "\"}},{\"text\":\"]\",\"color\":\"aqua\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/" + + "%commandlabel%" + " listusertags " + "%next_page%" + "\"}}]"; + + page_selector_tellraw = page_selector_tellraw.replaceAll("%next_page%", String.valueOf(page + 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%previous_page%", String.valueOf(page - 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%last_page%", + String.valueOf(last_page + 1)); + page_selector_tellraw = page_selector_tellraw.replaceAll("%commandlabel%", commandLabel); + + output_messages.add(page_selector_tellraw); + + output_messages.add(TextFormat.AQUA + "Usertags:"); + + // sender.sendMessage("[A] " + last_page + " " + lines_per_page); + } else { + output_messages.add(TextFormat.AQUA + "Page " + TextFormat.BLUE + (page + 1) + TextFormat.AQUA + "/" + + TextFormat.BLUE + (last_page + 1)); + output_messages.add(TextFormat.AQUA + "Next page " + TextFormat.BLUE + "/" + commandLabel + " listusertags " + + " " + TextFormat.BLUE + (page + 2 > last_page + 1 ? last_page + 1 : page + 2)); + } + + int line_index = 0; + for (String item : items) { + if (line_index >= page * lines_per_page && line_index < page * lines_per_page + lines_per_page) { + String usertagValue = plugin.getUsertagManager().getUsertagValue(item); + output_messages + .add(TextFormat.DARK_GREEN + "#" + (line_index + 1) + ". " + TextFormat.GREEN + item + " " + + TextFormat.RESET + plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, usertagValue, true, false, false)); + } + line_index += 1; + } + + output_messages.add(TextFormat.BLUE + "===" + TextFormat.DARK_AQUA + "------------------------------" + + TextFormat.BLUE + "==="); + + if (plugin != null) { + for (String msg : output_messages) { + if (msg.startsWith("tellraw")) { + plugin.getServer().dispatchCommand((CommandSender) plugin.getServer().getConsoleSender(), msg); + } else { + sender.sendMessage(msg); + } + } + } + + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_removeusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_removeusertag.java new file mode 100644 index 00000000..4286ad1d --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_removeusertag.java @@ -0,0 +1,68 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_removeusertag extends PowerCommand { + + + public cmd_removeusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String tag = args[0]; + final boolean result = plugin.getUsertagManager().removeUsertag(tag); + if (result) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (String tag : plugin.getUsertagManager().getUsertags()) { + if (tag.toLowerCase().contains(args[0].toLowerCase())) + tabcomplete.add(tag); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_setusertag.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_setusertag.java new file mode 100644 index 00000000..b3116c43 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/usertags/cmd_setusertag.java @@ -0,0 +1,107 @@ +package nl.svenar.powerranks.nukkit.commands.usertags; + +import java.util.ArrayList; + +import com.google.common.collect.ImmutableMap; + +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.common.utils.PRUtil; + + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; + +public class cmd_setusertag extends PowerCommand { + + public cmd_setusertag(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 1) { + final String playername = sender.getName(); + final String tag = args[0]; + final boolean result = plugin.getUsertagManager().setUsertag(playername, tag); + if (result) { + Player targetPlayer = plugin.getServer().getPlayer(playername); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", playername) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else if (args.length == 2) { + if (sender.hasPermission("powerranks.cmd." + commandName.toLowerCase() + ".other")) { + final String playername = args[0]; + final String tag = args[1]; + final boolean result = plugin.getUsertagManager().setUsertag(playername, tag); + if (result) { + Player targetPlayer = plugin.getServer().getPlayer(playername); + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", targetPlayer.getName()) + .put("usertag", tag) + .build(), + '[', ']')); + } else { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("target", playername) + .put("usertag", tag) + .build(), + '[', ']')); + } + } else { + sender.sendMessage(plugin.getLanguageManager().getFormattedMessage("general.no-permission")); + } + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + for (Player player : plugin.getServer().getOnlinePlayers().values()) { + tabcomplete.add(player.getName()); + } + } + + if (args.length == 2) { + for (String tag : plugin.getUsertagManager().getUsertags()) { + tabcomplete.add(tag); + } + } + + return tabcomplete; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/webeditor/cmd_webeditor.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/webeditor/cmd_webeditor.java new file mode 100644 index 00000000..9d14be57 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/commands/webeditor/cmd_webeditor.java @@ -0,0 +1,292 @@ +package nl.svenar.powerranks.nukkit.commands.webeditor; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import com.google.common.collect.ImmutableMap; +import com.google.gson.Gson; +import com.google.gson.internal.LinkedTreeMap; +import com.google.gson.reflect.TypeToken; + +import cn.nukkit.utils.TextFormat; + +import cn.nukkit.command.CommandSender; +import cn.nukkit.Player; +import cn.nukkit.scheduler.NukkitRunnable; + +import nl.svenar.powerranks.common.http.DatabinClient; +import nl.svenar.powerranks.common.storage.PowerStorageManager; +import nl.svenar.powerranks.common.storage.provided.JSONStorageManager; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.commands.PowerCommand; +import nl.svenar.powerranks.nukkit.util.Util; + +public class cmd_webeditor extends PowerCommand { + + private String tellraw_url = "tellraw %player% [\"\",{\"text\":\"Web editor is ready \",\"color\":\"dark_green\"},{\"text\":\"[\",\"color\":\"black\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%url%\"}},{\"text\":\"click to open\",\"color\":\"dark_green\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%url%\"}},{\"text\":\"]\",\"color\":\"black\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%url%\"}}]"; + + private String powerranks_webeditor_url = "https://editor.powerranks.nl/?id="; + + public cmd_webeditor(PowerRanks plugin, String command_name, COMMAND_EXECUTOR ce) { + super(plugin, command_name, ce); + this.setCommandPermission("powerranks.cmd." + command_name.toLowerCase()); + } + + @Override + public boolean onCommand(CommandSender sender, String commandLabel, String commandName, String[] args) { + if (args.length == 0) { + // No args + } else if (args.length == 1 || args.length == 2) { + final String webeditorCommand = args[0].toLowerCase(); + + switch (webeditorCommand) { + case "start": + startWebeditor(sender, commandName); + break; + case "load": + if (args.length == 2) { + loadWebeditor(sender, args[1], commandName); + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + break; + default: + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + break; + } + + } else { + sender.sendMessage( + plugin.getLanguageManager().getFormattedUsageMessage(commandLabel, commandName, + "commands." + commandName.toLowerCase() + ".arguments", sender instanceof Player)); + } + + return false; + } + + private void startWebeditor(CommandSender sender, String commandName) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".preparing-session")); + + JSONStorageManager jsonmanager = new JSONStorageManager(Util.DATA_DIR, "dummyRanks.json", + "dummyPlayers.json"); + PowerStorageManager powermanager = plugin.getStorageManager(); + + jsonmanager.setRanks(powermanager.getRanks()); + jsonmanager.setPlayers(powermanager.getPlayers()); + + String outputJSON = ""; + + outputJSON += "{"; + outputJSON += "\"serverdata\":"; + outputJSON += getServerDataAsJSON(); + outputJSON += ","; + outputJSON += "\"rankdata\":"; + outputJSON += jsonmanager.getRanksAsJSON(false); + outputJSON += ","; + outputJSON += "\"playerdata\":"; + outputJSON += jsonmanager.getPlayersAsJSON(false); + outputJSON += ","; + outputJSON += "\"usertags\":"; + outputJSON += plugin.getUsertagStorage().toJSON("usertags", false); + outputJSON += "}"; + + jsonmanager.removeAllData(); + + // PowerRanks.getInstance().getLogger().info("JSON: "); + // PowerRanks.getInstance().getLogger().info(outputJSON); + + DatabinClient client = new DatabinClient("https://databin.svenar.nl", "Databinclient/1.0"); + + client.postJSON(outputJSON); + + int uploadSize = outputJSON.length() / 1024; + int updateInterval = 5; + int timeout = 5; + + new NukkitRunnable() { + int waitTime = 0; + + @Override + public void run() { + if (client.hasResponse()) { + String key = client.getResponse().get("key"); + + if (key.length() > 0 && !key.startsWith("[FAILED]")) { + sender.sendMessage(TextFormat.DARK_AQUA + "===----------" + TextFormat.DARK_BLUE + + plugin.getDescription().getName() + TextFormat.DARK_AQUA + "----------==="); + // sender.sendMessage(TextFormat.DARK_GREEN + getIdentifier() + TextFormat.GREEN + + // " v" + getVersion()); + if (sender instanceof Player) { + plugin.getServer().dispatchCommand((CommandSender) plugin.getServer().getConsoleSender(), + tellraw_url.replaceAll("%player%", sender.getName()) + .replaceAll("%url%", powerranks_webeditor_url + key).replaceAll("\n", "")); + } else { + sender.sendMessage(TextFormat.DARK_GREEN + "Web editor is ready " + TextFormat.BLACK + "[" + + TextFormat.GREEN + powerranks_webeditor_url + key + TextFormat.BLACK + "]"); + } + sender.sendMessage(TextFormat.DARK_GREEN + "Editor ID: " + TextFormat.GREEN + key); + sender.sendMessage(TextFormat.DARK_GREEN + "Uploaded: " + TextFormat.GREEN + uploadSize + "KB"); + sender.sendMessage(TextFormat.DARK_AQUA + "===------------------------------==="); + } + + this.cancel(); + } + + if (waitTime / (20 / updateInterval) > timeout) { + this.cancel(); + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".timed-out")); + } + + waitTime++; + } + }.runTaskTimer(plugin, 0, updateInterval); + } + + private void loadWebeditor(CommandSender sender, String key, String commandName) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".downloading-data")); + + DatabinClient client = new DatabinClient("https://databin.svenar.nl", "Databinclient/1.0"); + + client.getJSON(key); + + int updateInterval = 5; + int timeout = 5; + + new NukkitRunnable() { + int waitTime = 0; + + @Override + public void run() { + if (client.hasResponse()) { + this.cancel(); + + String rawJSON = client.getRawResponse(); + Gson gson = new Gson(); + Type mapType = new TypeToken>() { + }.getType(); + Map jsonData = gson.fromJson(rawJSON, mapType); + handleWebeditorDownload(sender, jsonData, commandName); + } + + if (waitTime / (20 / updateInterval) > timeout) { + this.cancel(); + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".timed-out")); + } + + waitTime++; + } + }.runTaskTimer(plugin, 0, updateInterval); + } + + public void handleWebeditorDownload(CommandSender sender, Map jsonData, String commandName) { + + LinkedTreeMap serverData = (LinkedTreeMap) jsonData.get("serverdata"); + + if (Objects.isNull(serverData) || !serverData.containsKey("powerranksVersion")) { + plugin.getLogger().warning(serverData.toString()); + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".downloaded-invalid-data")); + return; + } + + if (!((String) serverData.get("powerranksVersion")).equals(plugin.getDescription().getVersion())) { + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".incompatible-version"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("version", plugin.getDescription().getVersion()) + .put("downloaded_version", (String) serverData.get("powerranksVersion")) + .build(), + '[', ']')); + return; + } + + LinkedTreeMap rankData = (LinkedTreeMap) jsonData.get("rankdata"); + LinkedTreeMap playerData = (LinkedTreeMap) jsonData.get("playerdata"); + LinkedTreeMap usertags = (LinkedTreeMap) jsonData.get("usertags"); + + JSONStorageManager jsonmanager = new JSONStorageManager(Util.DATA_DIR, "dummyRanks.json", + "dummyPlayers.json"); + + if (!(rankData instanceof LinkedTreeMap && playerData instanceof LinkedTreeMap)) { + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".failed-downloaded")); + return; + } + + PRCache.setRanks(jsonmanager.getRanksFromJSON(rankData)); + PRCache.setPlayers(jsonmanager.getPlayersFromJSON(playerData)); + + plugin.getStorageLoader().saveData(plugin.getStorageManager()); + + jsonmanager.removeAllData(); + + plugin.getUsertagStorage().fromJSON("usertags", usertags); + + sender.sendMessage( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".success-downloaded")); + + sender.sendMessage(PRUtil.powerFormatter( + plugin.getLanguageManager().getFormattedMessage( + "commands." + commandName.toLowerCase() + ".download-stats"), + ImmutableMap.builder() + .put("player", sender.getName()) + .put("rank_count", String.valueOf(PRCache.getRanks().size())) + .put("player_count", String.valueOf(PRCache.getPlayers().size())) + .build(), + '[', ']')); + } + + public ArrayList tabCompleteEvent(CommandSender sender, String[] args) { + ArrayList tabcomplete = new ArrayList(); + + if (args.length == 1) { + tabcomplete.add("start"); + tabcomplete.add("load"); + } + + return tabcomplete; + } + + private String getServerDataAsJSON() { + String output = ""; + + List server_permissions = new ArrayList(); + + for (String perm : plugin.getPermissionRegistry().getPermissions()) { + server_permissions.add("\"" + perm + "\""); + } + + output += "{"; + output += "\"powerranksVersion\":"; + output += "\"" + plugin.getDescription().getVersion() + "\""; + output += ",\"serverPermissions\":"; + output += "[" + String.join(",", server_permissions) + "]"; + output += "}"; + + return output; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnChat.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnChat.java new file mode 100644 index 00000000..62f47dd6 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnChat.java @@ -0,0 +1,135 @@ +package nl.svenar.powerranks.nukkit.events; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import com.google.common.collect.ImmutableMap; + +import cn.nukkit.Player; +import cn.nukkit.event.EventHandler; +import cn.nukkit.event.Listener; +import cn.nukkit.event.player.PlayerChatEvent; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.structure.PRPlayerRank; +import nl.svenar.powerranks.common.structure.PRRank; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public class OnChat implements Listener { + + private PowerRanks plugin; + + public OnChat(PowerRanks plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onChat(PlayerChatEvent event) { + Player player = event.getPlayer(); + + try { + if (this.plugin.getConfigManager().getBool("chat.enabled", true)) { + + String format = this.plugin.getConfigManager().getString("chat.format", ""); + + List ranknames = new ArrayList<>(); + for (PRPlayerRank rank : PRCache.getPlayer(player.getUniqueId().toString()).getRanks()) { + ranknames.add(rank.getName()); + } + + List ranks = new ArrayList(); + for (String rankname : ranknames) { + PRRank rank = PRCache.getRank(rankname); + if (rank != null) { + ranks.add(rank); + } + } + + PRUtil.sortRanksByWeight(ranks); + PRUtil.reverseRanks(ranks); + + String formatted_prefix = ""; + String formatted_suffix = ""; + String chatColor = ranks.size() > 0 ? ranks.get(0).getChatcolor() : "&f"; + String nameColor = ranks.size() > 0 ? ranks.get(0).getNamecolor() : "&f"; + String usertag = ""; + + for (PRRank rank : ranks) { + formatted_prefix += rank.getPrefix() + " "; + formatted_suffix += rank.getSuffix() + " "; + } + + if (formatted_prefix.endsWith(" ")) { + formatted_prefix = formatted_prefix.substring(0, formatted_prefix.length() - 1); + } + + if (formatted_suffix.endsWith(" ")) { + formatted_suffix = formatted_suffix.substring(0, formatted_suffix.length() - 1); + } + + if (formatted_prefix.replaceAll(" ", "").length() == 0) { + formatted_prefix = ""; + } + + if (formatted_suffix.replaceAll(" ", "").length() == 0) { + formatted_suffix = ""; + } + + PRPlayer targetPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + Map availableUsertags = this.plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + Set playerUsertags = targetPlayer.getUsertags(); + + for (String playerUsertag : playerUsertags) { + String value = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(playerUsertag)) { + value = entry.getValue().toString(); + } + } + + if (value.length() > 0) { + usertag += (usertag.length() > 0 ? " " : "") + value; + } + } + + String playersChatMessage = event.getMessage(); + if (!player.hasPermission("powerranks.chat.chatcolor")) { + playersChatMessage = playersChatMessage.replaceAll("(&[0-9a-fA-FiIjJrRlLmMnNoO])|(#[0-9a-fA-F]{6})", + ""); + } + + String player_formatted_name = (nameColor.length() == 0 ? "&r" : nameColor) + player.getDisplayName(); + String player_formatted_chat_msg = (chatColor.length() == 0 ? "&r" : chatColor) + playersChatMessage; + + format = PRUtil.powerFormatter( + format, ImmutableMap.builder().put("prefix", formatted_prefix) + .put("suffix", formatted_suffix) + .put("usertag", usertag) + .put("player", player_formatted_name) + .put("msg", + this.plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, + player_formatted_chat_msg, true, false, false)) + .put("format", event.getFormat()) + .put("world", player.level.getName()) + .build(), + '[', ']'); + + format = this.plugin.getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, format, true, false, + false); + format = format.replaceAll("%", "%%"); + + event.setFormat(format); + } + } catch (Exception e2) { + e2.printStackTrace(); + event.setFormat("%1$s: %2$s"); + } + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnJoin.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnJoin.java new file mode 100644 index 00000000..43344cb3 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnJoin.java @@ -0,0 +1,35 @@ +package nl.svenar.powerranks.nukkit.events; + +import java.util.Date; + +import cn.nukkit.Player; +import cn.nukkit.event.EventHandler; +import cn.nukkit.event.Listener; +import cn.nukkit.event.player.PlayerJoinEvent; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.permissible.PermissibleInjector; + +public class OnJoin implements Listener { + + private PowerRanks plugin; + + public OnJoin(PowerRanks plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + + if (PRCache.getPlayer(player.getUniqueId().toString()) == null) { + PRCache.createPlayer(player.getName(), player.getUniqueId()); + } + + long time = new Date().getTime(); + PRUtil.addPlayerPlaytimeCache(player.getUniqueId(), time); + + PermissibleInjector.inject(plugin, player); + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnLeave.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnLeave.java new file mode 100644 index 00000000..b6de746d --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/events/OnLeave.java @@ -0,0 +1,39 @@ +package nl.svenar.powerranks.nukkit.events; + +import java.util.Date; + +import cn.nukkit.Player; +import cn.nukkit.event.EventHandler; +import cn.nukkit.event.Listener; +import cn.nukkit.event.player.PlayerQuitEvent; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public class OnLeave implements Listener { + + + public OnLeave(PowerRanks plugin) { + } + + @EventHandler + public void onLeave(PlayerQuitEvent event) { + Player player = event.getPlayer(); + + if (PRCache.getPlayer(player.getUniqueId().toString()) == null) { + PRCache.createPlayer(player.getName(), player.getUniqueId()); + } + + PRPlayer prPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + + long leave_time = new Date().getTime(); + long join_time = leave_time; + try { + join_time = PRUtil.getPlayerPlaytimeCache(player.getUniqueId()); + } catch (Exception e1) { + } + + prPlayer.setPlaytime(prPlayer.getPlaytime() + (leave_time - join_time) / 1000); + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/manager/LanguageManager.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/manager/LanguageManager.java new file mode 100644 index 00000000..b98d8904 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/manager/LanguageManager.java @@ -0,0 +1,140 @@ +package nl.svenar.powerranks.nukkit.manager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import nl.svenar.powerranks.common.storage.PowerConfigManager; +import nl.svenar.powerranks.common.storage.provided.YAMLConfigManager; +import nl.svenar.powerranks.common.utils.PowerColor; +import nl.svenar.powerranks.nukkit.PowerRanks; +import nl.svenar.powerranks.nukkit.util.Util; + +public class LanguageManager { + + private PowerConfigManager languageManager; + + private String language = "en"; + + /** + * Constructor - Loads language data from the file system. + */ + public LanguageManager() { + this.languageManager = new YAMLConfigManager(Util.DATA_DIR, "lang.yml", "lang.yml"); + + if (!this.languageManager.hasKey("lang")) { + this.languageManager.destroyFile(); + this.languageManager = new YAMLConfigManager(Util.DATA_DIR, "lang.yml", "lang.yml"); + } + } + + /** + * Get a list of keys for the given path + * + * @param path + * @return List of found keys + */ + public List getKeys(String path) { + path = "lang." + this.language + "." + path; + + List keys = new ArrayList(); + + for (Entry entry : this.languageManager.getMap(path, new HashMap()).entrySet()) { + keys.add(String.valueOf(entry.getKey())); + } + + return keys; + } + + /** + * Get a message from the language cache in a specific language. + * + * @param path + * @return Unformatted message with plugin prefix + */ + public String getMessage(String path) { + path = "lang." + this.language + "." + path; + String output = this.languageManager.getString(path); + output = output == null ? path : output; + output = this.languageManager.getString("lang." + this.language + ".general.prefix") + " " + output; + return output; + } + + /** + * Get a message from the language cache in a specific language. + * + * @param path + * @return Unformatted message + */ + public String getUnformattedMessage(String path) { + path = "lang." + this.language + "." + path; + String output = this.languageManager.getString(path); + output = output == null ? path : output; + return output; + } + + /** + * Get a message from the language cache in a specific language and return the + * chatcolor formatted message. + * + * @param path + * @return Chatcolor formatted message + */ + public String getFormattedMessage(String path) { + return PowerRanks.getInstance().getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, getMessage(path), true, false, false); + } + + public String getUsageMessage(String commandLabel, String commandName, String path, boolean isPlayer) { + path = "lang." + this.language + "." + path; + String output = this.languageManager.getString(path); + output = output == null ? path : output; + output = this.languageManager.getString("lang." + this.language + ".general.prefix") + " " + (isPlayer ? "/" : "") + commandLabel + " " + commandName + " " + output; + return output; + } + + public String getFormattedUsageMessage(String commandLabel, String commandName, String path, boolean isPlayer) { + return PowerRanks.getInstance().getPowerColor().format(PowerColor.UNFORMATTED_COLOR_CHAR, getUsageMessage(commandLabel, commandName, path, isPlayer), true, false, false); + } + + /** + * Get the currently configured language. + * + * @return current language + */ + public String getLanguage() { + return this.language; + } + + /** + * Change the language. + * + * @param language + */ + public void setLanguage(String language) { + this.language = language; + } + + /** + * Save the language data to the files system + */ + public void save() { + this.languageManager.save(); + } + /** + * Reload the language data + */ + public void reload() { + this.languageManager.reload(); + } + + /** + * Get the config file instance + * + * @return PowerConfigManager for lang.yml + */ + public PowerConfigManager getInstance() { + return this.languageManager; + } + +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/manager/UsertagManager.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/manager/UsertagManager.java new file mode 100644 index 00000000..1c066dce --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/manager/UsertagManager.java @@ -0,0 +1,247 @@ +package nl.svenar.powerranks.nukkit.manager; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import cn.nukkit.Player; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public class UsertagManager { + + private PowerRanks plugin; + public UsertagManager(PowerRanks plugin) { + this.plugin = plugin; + } + + @SuppressWarnings("unchecked") + public boolean createUsertag(String tag, String format) { + + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", new HashMap()); + + boolean exists = false; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + exists = true; + } + } + + if (exists) { + return false; + } + + availableUsertags.put(tag, format); + + plugin.getUsertagStorage().setMap("usertags", availableUsertags); + + return true; + } + + @SuppressWarnings("unchecked") + public boolean editUsertag(String tag, String format) { + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", new HashMap()); + + String key = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + key = entry.getKey().toString(); + } + } + + if (key.length() == 0) { + return false; + } + + availableUsertags.put(key, format); + + plugin.getUsertagStorage().setMap("usertags", availableUsertags); + + return true; + } + + @SuppressWarnings("unchecked") + public boolean removeUsertag(String tag) { + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + + String key = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + key = entry.getKey().toString(); + } + } + + if (key.length() == 0) { + return false; + } + + availableUsertags.remove(key); + + plugin.getUsertagStorage().setMap("usertags", availableUsertags); + + return true; + } + + @SuppressWarnings("unchecked") + public boolean setUsertag(Player player, String tag) { + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + + PRPlayer targetPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + if (targetPlayer == null) { + return false; + } + + String key = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + key = entry.getKey().toString(); + } + } + + if (key.length() == 0) { + return false; + } + + targetPlayer.setUsertag(key); + + return true; + } + + @SuppressWarnings("unchecked") + public boolean addUsertag(Player player, String tag) { + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + + PRPlayer targetPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + if (targetPlayer == null) { + return false; + } + + String key = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + key = entry.getKey().toString(); + } + } + + if (key.length() == 0) { + return false; + } + + targetPlayer.addUsertag(key); + + return true; + } + + @SuppressWarnings("unchecked") + public boolean delUsertag(Player player, String tag) { + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + + PRPlayer targetPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + if (targetPlayer == null) { + return false; + } + + String key = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + key = entry.getKey().toString(); + } + } + + if (key.length() == 0) { + return false; + } + + targetPlayer.removeUsertag(key); + + return true; + } + + public boolean setUsertag(String playername, String tag) { + Player player = plugin.getServer().getPlayer(playername); + return setUsertag(player, tag); + } + + public boolean addUsertag(String playername, String tag) { + Player player = plugin.getServer().getPlayer(playername); + return addUsertag(player, tag); + } + + public boolean delUsertag(String playername, String tag) { + Player player = plugin.getServer().getPlayer(playername); + return delUsertag(player, tag); + } + + @SuppressWarnings("unchecked") + public Set getUsertags() { + Set tags = new HashSet(); + + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + + for (Entry entry : availableUsertags.entrySet()) { + tags.add(entry.getKey()); + } + + return tags; + } + + @SuppressWarnings("unchecked") + public String getUsertagValue(String tag) { + + Map availableUsertags = (Map) plugin.getUsertagStorage().getMap("usertags", + new HashMap()); + + String key = ""; + for (Entry entry : availableUsertags.entrySet()) { + if (entry.getKey().toString().equalsIgnoreCase(tag)) { + key = entry.getValue().toString(); + } + } + + if (key.length() == 0) { + return ""; + } + + return key; + } + + public String getUsertagValue(Player player) { + PRPlayer targetPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + if (targetPlayer == null) { + return ""; + } + + if (targetPlayer.getUsertags().size() == 0) { + return ""; + } + + String usertag = targetPlayer.getUsertags().iterator().next(); + if (usertag.length() > 0) { + return getUsertagValue(usertag); + } + + return ""; + } + + public boolean clearUsertag(String playername) { + PRPlayer targetPlayer = PRCache.getPlayer(playername); + if (targetPlayer == null) { + targetPlayer = PRCache.getPlayer(plugin.getServer().getPlayer(playername).getUniqueId().toString()); + } + if (targetPlayer == null) { + return false; + } + + targetPlayer.setUsertags(new HashSet()); + + return true; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/permissible/PermissibleInjector.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/permissible/PermissibleInjector.java new file mode 100644 index 00000000..cb50b45c --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/permissible/PermissibleInjector.java @@ -0,0 +1,21 @@ +package nl.svenar.powerranks.nukkit.permissible; + +import java.lang.reflect.Field; + +import cn.nukkit.Player; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public class PermissibleInjector { + + public static void inject(PowerRanks plugin, Player player) { + try { + Field f = Player.class.getDeclaredField("perm"); + f.setAccessible(true); + f.set(player, new PowerPermissibleBase(player, plugin)); + f.setAccessible(false); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/permissible/PowerPermissibleBase.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/permissible/PowerPermissibleBase.java new file mode 100644 index 00000000..d3de9762 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/permissible/PowerPermissibleBase.java @@ -0,0 +1,178 @@ +package nl.svenar.powerranks.nukkit.permissible; + +import java.util.HashMap; +import java.util.Map; + +import cn.nukkit.Player; +import cn.nukkit.permission.PermissibleBase; +import cn.nukkit.permission.Permission; +import cn.nukkit.permission.PermissionAttachment; +import cn.nukkit.permission.PermissionAttachmentInfo; +import cn.nukkit.plugin.Plugin; +import nl.svenar.powerranks.common.storage.PermissionRegistry; +import nl.svenar.powerranks.common.structure.PRPermission; +import nl.svenar.powerranks.common.structure.PRPlayer; +import nl.svenar.powerranks.common.utils.PRCache; +import nl.svenar.powerranks.common.utils.PRUtil; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public class PowerPermissibleBase extends PermissibleBase { + + private PowerRanks plugin; + // private Player player; + private PermissionRegistry permissionRegistry; + private PRPlayer prPlayer; + + public static Map permissionCallCount = new HashMap(); + + public PowerPermissibleBase(Player player, PowerRanks plugin) { + super(player); + this.plugin = plugin; + // this.player = player; + this.permissionRegistry = plugin.getPermissionRegistry(); + this.prPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + if (prPlayer == null) { + PRCache.createPlayer(player.getName(), player.getUniqueId()); + this.prPlayer = PRCache.getPlayer(player.getUniqueId().toString()); + } + } + + @Override + public boolean isOp() { + return super.isOp(); + } + + @Override + public void setOp(boolean value) { + super.setOp(value); + } + + @Override + public boolean isPermissionSet(Permission perm) { + if (perm == null) { + throw new IllegalArgumentException("Permission cannot be null"); + } + + return isPermissionSet(perm.getName()); + } + + @Override + public boolean isPermissionSet(String name) { + if (name == null) { + throw new IllegalArgumentException("Permission name cannot be null"); + } + + permissionRegistry.queuePermission(name); + + PRPermission prPermission = getPRPermission(name); + if (prPermission == null) { + for (String wildCardPermissionName : PRUtil.generateWildcardList(name)) { + prPermission = getPRPermission(wildCardPermissionName); + if (prPermission != null) { + break; + } + } + } + + if (prPermission != null) { + return prPermission.getValue(); + } + + return super.isPermissionSet(name); + } + + @Override + public boolean hasPermission(Permission perm) { + if (perm == null) { + throw new IllegalArgumentException("Permission cannot be null"); + } + + return hasPermission(perm.getName()); + } + + @Override + public boolean hasPermission(String inName) { + if (inName == null) { + throw new IllegalArgumentException("Permission name cannot be null"); + } + + permissionRegistry.queuePermission(inName); + + if (permissionCallCount.get(inName) == null) { + permissionCallCount.put(inName, 0); + } else { + permissionCallCount.put(inName, permissionCallCount.get(inName) + 1); + } + + PRPermission prPermission = getPRPermission(inName); + if (prPermission == null) { + for (String wildCardPermissionName : PRUtil.generateWildcardList(inName)) { + prPermission = getPRPermission(wildCardPermissionName); + if (prPermission != null) { + break; + } + } + } + + boolean defaultHasPermission = false; + try { + defaultHasPermission = super.hasPermission(inName); + } catch (NullPointerException e) { + super.recalculatePermissions(); + } + + if (prPermission != null) { + return prPermission.getValue(); + } + return defaultHasPermission; + } + + @Override + public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) { + return super.addAttachment(plugin, name, value); + } + + @Override + public PermissionAttachment addAttachment(Plugin plugin) { + return super.addAttachment(plugin); + } + + @Override + public void removeAttachment(PermissionAttachment attachment) { + try { + super.removeAttachment(attachment); + } catch (Exception e) { + } + } + + @Override + public void recalculatePermissions() { + super.recalculatePermissions(); + } + + public synchronized void clearPermissions() { + super.clearPermissions(); + } + + @Override + public Map getEffectivePermissions() { + return super.getEffectivePermissions(); + } + + private PRPermission getPRPermission(String name) { + PRPermission prPermission = null; + + boolean caseSensitive = plugin.getConfigManager().getBool("general.case-sensitive-permissions", false); + + for (PRPermission permission : this.prPlayer.getEffectivePermissions()) { + if ((caseSensitive && permission.getName().equals(name)) + || (!caseSensitive && permission.getName().equalsIgnoreCase(name))) { + prPermission = permission; + break; + } + } + + return prPermission; + } + +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/util/NukkitPowerColor.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/util/NukkitPowerColor.java new file mode 100644 index 00000000..5a1903b9 --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/util/NukkitPowerColor.java @@ -0,0 +1,20 @@ +package nl.svenar.powerranks.nukkit.util; + +import nl.svenar.powerranks.common.utils.PowerColor; + +public class NukkitPowerColor { + + private PowerColor powerColor; + + public NukkitPowerColor() { + this.powerColor = new PowerColor(); + } + + public String format(char altColorChar, String text, boolean special, boolean addLeadingReset, boolean addTrailingReset) { + text = this.powerColor.formatSpecial(altColorChar, text); + text = this.powerColor.formatHEX(altColorChar, text); + text = this.powerColor.formatColor(altColorChar, text); + + return text; + } +} diff --git a/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/util/Util.java b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/util/Util.java new file mode 100644 index 00000000..49d0a7ac --- /dev/null +++ b/Nukkit/src/main/java/nl/svenar/powerranks/nukkit/util/Util.java @@ -0,0 +1,65 @@ +package nl.svenar.powerranks.nukkit.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import cn.nukkit.Player; +import cn.nukkit.Server; +import nl.svenar.powerranks.nukkit.PowerRanks; + +public class Util { + + public static String DATA_DIR = ""; + + public static String getServerVersion(Server server) { + try { + Matcher matcher = Pattern.compile("\\d{1,3}.\\d{1,3}.\\d{1,3}|\\d{1,3}.\\d{1,3}") + .matcher(server.getVersion()); + + List results = new ArrayList(); + while (matcher.find()) { + if (matcher.groupCount() > 0) { + results.add(matcher.group(1)); + } else { + results.add(matcher.group()); + } + } + + return results.get(0); + } catch (Exception e) { + return server.getVersion(); + } + } + + public static String getServerType(Server server) { + try { + Matcher matcher = Pattern.compile("-\\w{1,32}-").matcher(server.getVersion()); + + List results = new ArrayList(); + while (matcher.find()) { + if (matcher.groupCount() > 0) { + results.add(matcher.group(1)); + } else { + results.add(matcher.group()); + } + } + + return server.getName() + " " + results.get(0); + } catch (Exception e) { + return server.getName() + " " + server.getNukkitVersion(); + } + } + + public static Player getPlayerByName(String target_player_name) { + Player target_player = null; + for (Player online_player : PowerRanks.getInstance().getServer().getOnlinePlayers().values()) { + if (online_player.getName().equalsIgnoreCase(target_player_name)) { + target_player = online_player; + break; + } + } + return target_player; + } +} diff --git a/Nukkit/src/main/resources/config.yml b/Nukkit/src/main/resources/config.yml new file mode 100644 index 00000000..032a61f0 --- /dev/null +++ b/Nukkit/src/main/resources/config.yml @@ -0,0 +1,19 @@ +general: + language: en + autosave-files-interval: 600 + playtime-update-interval: 60 + case-sensitive-permissions: false + disable-op: false +storage: + type: YAML + mysql: + host: 127.0.0.1 + port: 3306 + database: powerranks + username: username + password: password + ssl: false + verbose: false +chat: + enabled: true + format: '&a[world]&r [usertag] [prefix] [player] [suffix]&r: [msg]' \ No newline at end of file diff --git a/Nukkit/src/main/resources/lang.yml b/Nukkit/src/main/resources/lang.yml new file mode 100644 index 00000000..1eb26f7b --- /dev/null +++ b/Nukkit/src/main/resources/lang.yml @@ -0,0 +1,263 @@ +lang: + en: + general: + prefix: "&0[&bPR&0]&r" + no-permission: "&4You do not have permissions to execute this command!" + permission-not-found: "&cPermission node '[permission]' not found!" + rank-not-found: "&cRank '[rank]' not found!" + player-not-found: "&cPlayer '[target]' not found!" + player-not-online: "&cPlayer '[target]' is not online!" + console-is-no-player: "&cThe console is not a player and has no ranks!" + player-rank-has-expired: "&aYour rank [rank] has expired!" + player-rank-expired-console: "&cRemoved expired rank [rank] from [player]" + messages: + usertags: + not-found: "&cUsertag [usertag] not found!" + commands: + config: + arguments: " / autosave_files_interval / language )>" + description: "Edit fields in the configuration file" + removed-world-tag: "&aThe world tag has been removed!" + state-changed: "&eChanged [config_target] from &c[old_state] &eto &a[new_state]" + numbers-only: "&cOnly numbers are allowed!" + factoryreset: + arguments: "[reset-ID]" + description: "Reset the configuration and remove all rank/player data" + help: + arguments: "[page]" + description: "Shows this menu" + pluginhook: + arguments: "[enable/disable] [plugin_name]" + description: "Enable or disable a plugin for PowerRanks to hook in to" + state-changed: "&eChanged [config_target] from &c[old_state] &eto &a[new_state]" + unknown-plugin: "&cUnknown plugin!" + unknown-state: "&cUnknown state!" + reload: + arguments: "[config/plugin/addons/all]" + description: "Reload (parts of) PowerRanks" + warning: "&4Reloading is not recommended and can cause unforseen problems. Restart the server instead!" + config-start: "&2Reloading config..." + config-done: "&2Reloaded config!" + plugin-start: "&2Reloading plugin..." + plugin-done: "&2Reloaded plugin!" + stats: + arguments: "" + description: "Show stats about PowerRanks" + addrank: + arguments: " " + description: "Add a rank to someone" + success-executor: "&aAdded rank [rank] to [player]" + failed-executor: "&cFailed to add the rank [rank] to [player]" + failed-already-has-rank: "&c[player] already has the rank [rank]" + success-receiver: "&aYou have been granted the rank [rank]" + addownrank: + arguments: "" + description: "Add a rank to yourself" + success-executor: "&aChanged your rank to [rank]" + failed-executor: "&cFailed to set your rank to: [rank]" + success-receiver: "&aYou have been granted the rank [rank]" + setrank: + arguments: " " + description: "Set someone's rank and remove all other ranks" + success-executor: "&aChanged [player]'s rank to [rank]" + failed-executor: "&cFailed to set '[player]' to rank: [rank]" + success-receiver: "&aYour rank has changed to [rank]" + setownrank: + arguments: "" + description: "Set your own rank and remove all other ranks" + success-executor: "&aChanged your rank to [rank]" + failed-executor: "&cFailed to set your rank to: [rank]" + success-receiver: "&aYour rank has changed to [rank]" + delrank: + arguments: " " + success-executor: "&aRemoved the rank [rank] from [player]" + failed-executor: "&cFailed to remove the rank [rank] from [player]" + success-receiver: "&aThe rank [rank] has been revoked from you" + checkrank: + arguments: "" + description: "Check someone's rank" + success-self: "&aYour ranks are: [ranks]" + success-self-none: "&eYou have no ranks" + success-target: "&a[target]'s ranks are: [ranks]" + success-target-none: "&e[target] has no ranks" + addplayerperm: + arguments: " [allowed]" + description: "Add a permission to a player" + success: "&aPermission [permission] added to player: [target]" + failed: "&cFailed to add the permission [permission] to [target]" + delplayerperm: + arguments: " [allowed]" + description: "Remove a permission from a player" + success: "&aPermission [permission] removed from player: [target]" + failed: "&cFailed to remove the permission [permission] from [target]" + listplayerpermissions: + arguments: "" + description: "List all permissions of a player" + playerinfo: + arguments: "" + description: "Show information about a player" + nick: + arguments: "[player_name] " + setown: + success: "&aYour nickname has been set to: [nickname]" + failed: "&cFailed to set your nickname to: [nickname]" + setother: + success: "&a[target]'s nickname has been set to: [nickname]" + failed: "&cFailed to set [target]'s nickname to: [nickname]" + haspermission: + arguments: " " + description: "Check if a player has a certain permission" + addinheritance: + arguments: " " + description: "Add a inheritance to a rank" + success: "&aInheritance [inheritance] added to rank: [rank]" + delinheritance: + arguments: " " + description: "Remove a inheritance from a rank" + success: "&aInheritance [inheritance] removed from rank: [rank]" + addperm: + arguments: " [allowed]" + description: "Add a permission to a rank" + success: "&aPermission [permission] added to rank: [rank]" + success-all: "&aPermission [permission] added to all ranks" + failed: "&cFailed to add the permission [permission] to [rank]" + delperm: + arguments: " " + description: "Remove a permission from a rank" + success: "&aPermission [permission] removed from rank: [rank]" + success-all: "&aPermission [permission] removed from all ranks" + failed: "&cFailed to remove the permission [permission] from [rank]" + createrank: + arguments: "" + description: "Create a new rank" + success: "&aRank [rank] created" + warning-color: "&cWarning the created rank contains characters related to colors, if this is intended you can ignore this message. Color codes in the rank name do not work, change the prefix instead." + warning-character: "&cWarning the created rank contains special characters, if this is intended you can ignore this message." + failed: "&cCould not create rank [rank]" + deleterank: + arguments: "" + description: "Delete a rank" + success: "&aRank [rank] deleted" + failed: "&cCould not delete rank [rank]" + listdefaultranks: + arguments: "" + description: "List all default ranks new players get" + listpermissions: + arguments: "" + description: "List all permissions in a rank" + listranks: + arguments: "" + description: "List all ranks" + rankinfo: + arguments: " [page]" + description: "Show information about a rank" + renamerank: + arguments: " " + description: "Rename a rank" + success: "&aRank [rank] renamed to [new_rank]!" + failed: "&cFailed to rename rank [rank] to [new_rank]!" + setchatcolor: + arguments: " " + description: "Change the chat color of a rank" + success: "&aChanged chat color to '[color]'' on rank [rank]" + setnamecolor: + arguments: " " + description: "Change the name color of a rank" + success: "&aChanged name color to '[color]'' on rank [rank]" + setdefault: + arguments: " " + description: "Set the default rank for new players" + success-added: "&aAdded [rank] as default for new players" + success-removed: "&aRemoved [rank] as default for new players" + setprefix: + arguments: " " + description: "Change the prefix of a rank" + success: "&aChanged prefix to '[prefix]' on rank: [rank]" + success-clear: "&aCleared the prefix on rank: [rank]" + setsuffix: + arguments: " " + description: "Change the suffix of a rank" + success: "&aChanged suffix to '[suffix]' on rank: [rank]" + success-clear: "&aCleared the suffix on rank: [rank]" + setweight: + arguments: " " + description: "Change the weight of the rank for permission handeling. Higher weight equals more priority." + success: "&aThe weight of rank [rank] has been changed to: [weight]" + numbers-only: "&cOnly numbers are allowed!" + clearusertag: + arguments: "[player_name] " + description: "Remove a usertag" + disabled: "&cCan't clear a player's usertag. Usertags are disabled!" + success: "&aCleared [target]'s usertag!" + failed: "&cFailed to clear [target]'s usertag!" + createusertag: + arguments: " " + description: "Create a new usertag" + disabled: "&cCan't create a new usertag. Usertags are disabled!" + success: "&aUsertag [usertag] successfully created with value: [text]" + failed: "&cFailed creating usertag [usertag] with value: [text]" + editusertag: + arguments: " " + description: "Edit a usertag" + disabled: "&cCan't edit a usertag. Usertags are disabled!" + success: "&aUsertag [usertag] successfully changed to value: [text]" + failed: "&cFailed to edit [usertag] to value: [text]" + listusertags: + arguments: "" + description: "List all usertags" + disabled: "&cCan't list usertags. Usertags are disabled!" + removeusertag: + arguments: "" + description: "Delete a usertag" + disabled: "&cCan't remove a usertag. Usertags are disabled!" + not-found: "&cUsertag [usertag] not found!" + success: "&aUsertag [usertag] successfully removed" + failed: "&cFailed removing usertag [usertag]" + setusertag: + arguments: "[player_name] " + description: "Assign a usertag to an player" + disabled: "&cCan't set a player's usertag. Usertags are disabled!" + not-found: "&cUsertag [usertag] not found!" + success: "&aSet [target]'s usertag to: [usertag]" + failed: "&cFailed to change [target]'s usertag to: [usertag]" + addusertag: + arguments: "[player_name] " + description: "Add a usertag to an player" + disabled: "&cCan't add a player's usertag. Usertags are disabled!" + not-found: "&cUsertag [usertag] not found!" + success: "&aAdded usertag [usertag] to: [target]" + failed: "&cFailed to add usertag [usertag] to: [target]" + delusertag: + arguments: "[player_name] " + description: "Remove an usertag from a player" + disabled: "&cCan't remove a player's usertag. Usertags are disabled!" + not-found: "&cUsertag [usertag] not found!" + success: "&aRemoved usertag [usertag] from: [target]" + failed: "&cFailed to removed usertag [usertag] from: [target]" + webeditor: + arguments: "" + description: "Upload/download your server data to/from the PowerRanks web-editor" + preparing-session: "&aPreparing web editor..." + timed-out: "&cThe web editor has timed out! Please try again later." + downloading-data: "&aDownloading data from the web editor..." + success-downloaded: "&aFinished downloading data from the web editor! &cIt is recommended to restart your server." + downloaded-invalid-data: "&cInvalid web editor data!" + failed-downloaded: "&cFailed to download data from the web editor!" + incompatible-version: "&cIncompattible PowerRanks version! (editor: [downloaded_version] | server: [version])" + download-stats: "&aLoaded [rank_count] ranks and [player_count] players from the web editor!" + we: + arguments: "" + description: "Upload/download your server data to/from the PowerRanks web-editor" + preparing-session: "&aPreparing web editor..." + timed-out: "&cThe web editor has timed out! Please try again later." + downloading-data: "&aDownloading data from the web editor..." + success-downloaded: "&aFinished downloading data from the web editor! &cIt is recommended to restart your server." + downloaded-invalid-data: "&cInvalid web editor data!" + failed-downloaded: "&cFailed to download data from the web editor!" + incompatible-version: "&cIncompattible PowerRanks version! (editor: [downloaded_version] | server: [version])" + download-stats: "&aLoaded [rank_count] ranks and [player_count] players from the web editor!" + dump: + arguments: "" + description: "Upload your server data to the PowerRanks server for debugging" + preparing-session: "&aPreparing upload..." + timed-out: "&cThe upload has timed out! Please try again later." diff --git a/Nukkit/src/main/resources/plugin.yml b/Nukkit/src/main/resources/plugin.yml new file mode 100644 index 00000000..348f18c4 --- /dev/null +++ b/Nukkit/src/main/resources/plugin.yml @@ -0,0 +1,11 @@ +name: ${output.name} +version: ${project.version} +main: nl.svenar.powerranks.nukkit.PowerRanks +api: ["1.0.14"] +author: svenar_nl +load: STARTUP +website: 'https://powerranks.nl' +commands: + powerranks: + aliases: [pr] + description: Main Command \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2206653a..bac9ffab 100644 --- a/pom.xml +++ b/pom.xml @@ -1,249 +1,38 @@ - 4.0.0 - nl.svenar - powerranks - 1.10.9B1 - PowerRanks - An amazing permission plugin! - - - 1.8 - UTF-8 - src/main/java - src/main/resources - nl.svenar.lib - ../../servers/latest/plugins/ - - - - clean compile package shade:shade - ${project.name} - ${src.dir} - - - ${rsc.dir} - true - - - - - - maven-compiler-plugin - 3.8.0 - - ${java.version} - ${java.version} - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.0 - - true - false - false - false - false - - - *:* - - META-INF/license/** - META-INF/* - META-INF/maven/** - META-INF/versions/*/module-info.class - LICENSE - NOTICE - /*.txt - build.properties - com/fasterxml/jackson/databind/ext/Java7* - - - - - - com.squareup.okhttp3:okhttp - com.squareup.okio:okio - org.jetbrains.kotlin:kotlin-stdlib - org.yaml:snakeyaml - com.fasterxml.jackson.core:jackson-core - com.fasterxml.jackson.core:jackson-databind - com.fasterxml.jackson.core:jackson-annotations - com.fasterxml.jackson.dataformat:jackson-dataformat-yaml - com.googlecode.json-simple:json-simple - - - - - okhttp3 - ${shade.basepattern}.okhttp3 - - - okio - ${shade.basepattern}.okio - - - kotlin - ${shade.basepattern}.kotlin - - - org.yaml - ${shade.basepattern}.yaml - - - com.fasterxml - ${shade.basepattern}.fasterxml - - - org.json - ${shade.basepattern}.json - - - target/reduced-pom.xml - - - - package - - shade - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.3.1 - - ${testserver.location} - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 - - - - - - - - - - spigotmc-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - placeholderapi - https://repo.extendedclip.com/content/repositories/placeholderapi/ - - - jitpack.io - https://jitpack.io - - - svenar - https://svenar.nl/repo/ - - - - - - junit - junit - 4.13.1 - test - - - - com.squareup.okhttp3 - okhttp - 4.9.3 - jar - - - org.yaml - snakeyaml - [2.0,) - jar - - - com.googlecode.json-simple - json-simple - 1.1 - jar - - - - com.fasterxml.jackson.core - jackson-core - 2.13.4 - - - com.fasterxml.jackson.core - jackson-databind - 2.13.4.2 - - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.13.4 - jar - - - - me.neznamy - tab-api - 3.0.1 - - - me.clip.deluxetags - deluxetags - 1.8.2 - provided - - - me.clip - placeholderapi - 2.11.1 - provided - - - com.github.MilkBowl - VaultAPI - 1.7.1 - provided - - - org.bukkit - bukkit - - - - - org.spigotmc - spigot-api - 1.19.4-R0.1-SNAPSHOT - provided - - - com.nametagedit - nametagedit - 4.5.4 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + nl.svenar + powerranks + ${revision} + PowerRanks + Rank-based permission manager + pom + + + 1.10.9 + PowerRanks + + + + Core + API + Bukkit + Nukkit + + + + clean compile package + ${project.name} + + + + + junit + junit + 4.13.1 + test + + + + \ No newline at end of file diff --git a/src/main/java/nl/svenar/common/utils/PRUtil.java b/src/main/java/nl/svenar/common/utils/PRUtil.java deleted file mode 100644 index 3d4ee151..00000000 --- a/src/main/java/nl/svenar/common/utils/PRUtil.java +++ /dev/null @@ -1,31 +0,0 @@ -package nl.svenar.common.utils; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Objects; - -import nl.svenar.common.structure.PRRank; - -public class PRUtil { - - public static void sortRanksByWeight(List ranks) { - ranks.removeIf(Objects::isNull); - - ranks.sort(Comparator.comparingInt(PRRank::getWeight)); - } - - public static List reverseRanks(List ranks) { - Collections.reverse(ranks); - return ranks; - } - - public static boolean containsIgnoreCase(List objects, String object) { - for (String obj : objects) { - if (obj.equalsIgnoreCase(object)) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/nl/svenar/powerranks/api/PowerRanksAPI.java b/src/main/java/nl/svenar/powerranks/api/PowerRanksAPI.java deleted file mode 100644 index fcf68ab5..00000000 --- a/src/main/java/nl/svenar/powerranks/api/PowerRanksAPI.java +++ /dev/null @@ -1,824 +0,0 @@ -package nl.svenar.powerranks.api; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.bukkit.entity.Player; - -import nl.svenar.common.structure.PRPermission; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.data.Users; - -public class PowerRanksAPI { - - private String API_VERSION = "1.4"; - - public static PowerRanks plugin; - private Users users; - - /** - * Initialize the API - * - * @param plugin - */ - public PowerRanksAPI(PowerRanks plugin) { - PowerRanksAPI.plugin = plugin; - this.users = new Users(plugin); - } - - /** - * Initialize the API - */ - public PowerRanksAPI() { - this.users = new Users(plugin); - } - - /** - * Get the plugin's name - * - * @return PowerRanks - */ - public String getName() { - return plugin.getName(); - } - - /** - * Get the PowerRanks version - * - * @return string X.X.X - */ - public String getVersion() { - return PowerRanks.getVersion(); - } - - /** - * Get the api version - * - * @return String X.X - */ - public String getApiVersion() { - return API_VERSION; - } - - /** - * Get the rankname of a player - * - * @param player - * @return player's rankname - */ - public String getPrimaryRank(Player player) { - String rank = users.getPrimaryRank(player); - return rank; - } - - public List getRanks(Player player) { - List ranks = new ArrayList<>(); - for (PRPlayerRank rank : CacheManager.getPlayer(player.getUniqueId().toString()).getRanks()) { - ranks.add(rank.getName()); - } - return ranks; - } - - /** - * Overwrite all ranks of a player and set it to a single one - * - * @param player - * @param rankname - * @return true if success, false otherwise - */ - public boolean setPlayerRank(Player player, String rankname) { - return setPlayerRank(player, rankname, null); - } - - /** - * Overwrite all ranks of a player and set it to a single one - * - * @param player - * @param rankname - * @param tags - * @return true if success, false otherwise - */ - public boolean setPlayerRank(Player player, String rankname, Map tags) { - PRRank rank = CacheManager.getRank(rankname); - if (rank != null) { - PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); - if (tags != null) { - for (String tag : tags.keySet()) { - playerRank.addTag(tag, tags.get(tag)); - } - } - CacheManager.getPlayer(player.getUniqueId().toString()).setRank(playerRank); - } - return rank != null; - } - - /** - * Add a rankname to the player's current ranks - * - * @param player - * @param rankname - * @return true if success, false otherwise - */ - public boolean addPlayerRank(Player player, String rankname) { - return addPlayerRank(player, rankname, null); - } - - /** - * Add a rankname to the player's current ranks - * - * @param player - * @param rankname - * @param tags - * @return true if success, false otherwise - */ - public boolean addPlayerRank(Player player, String rankname, Map tags) { - PRRank rank = CacheManager.getRank(rankname); - if (rank != null) { - PRPlayerRank playerRank = new PRPlayerRank(rank.getName()); - if (tags != null) { - for (String tag : tags.keySet()) { - playerRank.addTag(tag, tags.get(tag)); - } - } - CacheManager.getPlayer(player.getUniqueId().toString()).addRank(playerRank); - } - return rank != null; - } - - /** - * Remove a rank by name from the player - * - * @param player - * @param rankname - * @return true if success, false otherwise - */ - public boolean removePlayerRank(Player player, String rankname) { - PRRank rank = CacheManager.getRank(rankname); - if (rank != null) { - PRPlayer targetPlayer = CacheManager.getPlayer(player.getUniqueId().toString()); - PRPlayerRank playerRank = null; - for (PRPlayerRank targetPlayerRank : targetPlayer.getRanks()) { - if (targetPlayerRank.getName().equals(rank.getName())) { - playerRank = targetPlayerRank; - break; - } - } - if (playerRank != null) { - targetPlayer.removeRank(playerRank); - } - return playerRank != null; - } - return rank != null; - } - - /** - * Get all allowed permissions of a rank - * - * @param rank - * @return list of allowed permissions that a rank has - */ - public List getAllowedPermissions(String rank) { - List permissions = new ArrayList(); - for (PRPermission permission : CacheManager.getRank(users.getRankIgnoreCase(rank)).getPermissions()) { - if (permission.getValue()) { - permissions.add(permission.getName()); - } - } - return permissions; - } - - /** - * Get all allowed permissions of a player - * - * @param player - * @return list of allowed permissions that a player has - */ - public List getAllowedPlayerPermissions(Player player) { - List permissions = new ArrayList(); - for (PRPermission permission : CacheManager.getPlayer(player).getPermissions()) { - if (permission.getValue()) { - permissions.add(permission.getName()); - } - } - return permissions; - } - - /** - * Get all denied permissions of a rank - * - * @param rank - * @return list of denied permissions that a rank has - */ - public List getDeniedPermissions(String rank) { - List permissions = new ArrayList(); - for (PRPermission permission : CacheManager.getRank(users.getRankIgnoreCase(rank)).getPermissions()) { - if (!permission.getValue()) { - permissions.add(permission.getName()); - } - } - return permissions; - } - - /** - * Get all denied permissions of a player - * - * @param player - * @return list of denied permissions that a player has - */ - public List getDeniedPlayerPermissions(Player player) { - List permissions = new ArrayList(); - for (PRPermission permission : CacheManager.getPlayer(player).getPermissions()) { - if (!permission.getValue()) { - permissions.add(permission.getName()); - } - } - return permissions; - } - - /** - * Add a permission to a rank - * - * @param rank - * @param permission - * @param allowed - * @return true if success, false otherwise - */ - public boolean addPermission(String rank, String permission, boolean allowed) { - return this.users.addPermission(users.getRankIgnoreCase(rank), permission, allowed); - } - - /** - * Remove a permission from a rank - * - * @param rank - * @param permission - * @return true if success, false otherwise - */ - public boolean removePermission(String rank, String permission) { - return this.users.removePermission(users.getRankIgnoreCase(rank), permission); - } - - /** - * Get a list of inherited ranks on a rank - * - * @param rank - * @return List of inherited rank names - */ - public List getInheritances(String rank) { - return this.users.getInheritances(users.getRankIgnoreCase(rank)); - } - - /** - * Add a rankname as inheritance to a rank - * - * @param rank - * @param inheritance - * @return true if success, false otherwise - */ - public boolean addInheritance(String rank, String inheritance) { - return this.users.addInheritance(users.getRankIgnoreCase(rank), inheritance); - } - - /** - * Remove an inheritance from a rank - * - * @param rank - * @param inheritance - * @return true if success, false otherwise - */ - public boolean removeInheritance(String rank, String inheritance) { - return this.users.removeInheritance(users.getRankIgnoreCase(rank), inheritance); - } - - /** - * Should the rank be given to the players when they join for the first time? - * - * @param rank - * @param isDefault - * @return true if rank exists, false otherwise - */ - public boolean setDefault(String rank, boolean isDefault) { - PRRank targetRank = CacheManager.getRank(rank); - if (targetRank != null) { - targetRank.setDefault(isDefault); - } - return targetRank != null; - } - - /** - * Get the list of default ranks that are given to new players - * - * @return List of default ranks - */ - public List getDefaultRanks() { - List defaultRanks = new ArrayList(); - - for (PRRank rank : CacheManager.getRanks()) { - if (rank.isDefault()) { - defaultRanks.add(rank.getName()); - } - } - - return defaultRanks; - } - - /** - * Get all available ranknames - * - * @return list of ranks in PowerRanks - */ - public List getRanks() { - List ranks = new ArrayList(); - for (PRRank rank : CacheManager.getRanks()) { - ranks.add(rank.getName()); - } - return ranks; - } - - /** - * Get the unformatted prefix of a rank - * - * @param rank - * @return Unformatted prefix - */ - public String getPrefix(String rank) { - if (CacheManager.getRank(rank) != null) { - return CacheManager.getRank(rank).getPrefix(); - } - return null; - } - - /** - * Set the prefix of a rank - * - * @param rank - * @param new_value - * @return true if success, false otherwise - */ - public boolean setPrefix(String rank, String new_value) { - if (CacheManager.getRank(rank) != null) { - CacheManager.getRank(rank).setPrefix(new_value); - return true; - } - return false; - } - - /** - * Get the unformatted suffix of a rank - * - * @param rank - * @return Unformatted suffix - */ - public String getSuffix(String rank) { - if (CacheManager.getRank(rank) != null) { - return CacheManager.getRank(rank).getSuffix(); - } - return null; - } - - /** - * Set the suffix of a rank - * - * @param rank - * @param new_value - * @return true if success, false otherwise - */ - public boolean setSuffix(String rank, String new_value) { - if (CacheManager.getRank(rank) != null) { - CacheManager.getRank(rank).setSuffix(new_value); - return true; - } - return false; - } - - /** - * Get the player's name color of a rank - * - * @param rank - * @return Unformatted name color - */ - public String getNameColor(String rank) { - if (CacheManager.getRank(rank) != null) { - return CacheManager.getRank(rank).getNamecolor(); - } - return null; - } - - /** - * Set the player's name color of a rank - * - * @param rank - * @param new_value - * @return true if success, false otherwise - */ - public boolean setNameColor(String rank, String new_value) { - if (CacheManager.getRank(rank) != null) { - CacheManager.getRank(rank).setNamecolor(new_value); - return true; - } - return false; - } - - /** - * Get the player's chat color of a rank - * - * @param rank - * @return Unformatted chat color - */ - public String getChatColor(String rank) { - if (CacheManager.getRank(rank) != null) { - return CacheManager.getRank(rank).getChatcolor(); - } - return null; - } - - /** - * Set the player's chat color of a rank - * - * @param rank - * @param new_value - * @return true if success, false otherwise - */ - public boolean setChatColor(String rank, String new_value) { - if (CacheManager.getRank(rank) != null) { - CacheManager.getRank(rank).setChatcolor(new_value); - return true; - } - return false; - } - - /** - * Create a new rank - * - * @param rank - * @return true if success, false otherwise - */ - public boolean createRank(String rank) { - boolean value = users.createRank(rank); - return value; - } - - /** - * Delete an existing rank - * - * @param rank - * @return true if success, false otherwise - */ - public boolean deleteRank(String rank) { - boolean value = users.deleteRank(rank); - return value; - } - - /** - * Set a rank's weight - * Higher weight has more priority - * - * @param weight - * @return true if success, false otherwise - */ - public boolean setRankWeight(String rankname, int weight) { - PRRank rank = CacheManager.getRank(rankname); - if (rank != null) { - rank.setWeight(weight); - } - return rank != null; - } - - /** - * Add a rank as buyable to a rank - * - * @param rank - * @param buyable_rank - * @return true if success, false otherwise - */ - public boolean addBuyableRank(String rank, String buyable_rank) { - boolean value = users.addBuyableRank(rank, buyable_rank); - return value; - } - - /** - * Remove a rank as buyable from a rank - * - * @param rank - * @param buyable_rank - * @return true if success, false otherwise - */ - public boolean delBuyableRank(String rank, String buyable_rank) { - boolean value = users.delBuyableRank(rank, buyable_rank); - return value; - } - - /** - * Set the buy cost of a rank - * - * @param rank - * @param buyable_rank - * @return true if success, false otherwise - */ - public boolean setRankBuyCost(String rank, int cost) { - return this.users.setBuyCost(rank, String.valueOf(cost)); - } - - /** - * Add a permission to a rank - * - * @param rank - * @param permission - * @return true if success, false otherwise - */ - public boolean addPermission(Player player, String permission, boolean allowed) { - return this.users.addPlayerPermission(player.getName(), permission, allowed); - } - - /** - * Remove a permission from a player - * - * @param player - * @param permission - * @return true if success, false otherwise - */ - public boolean removePermission(Player player, String permission) { - return this.users.delPlayerPermission(player.getName(), permission); - } - - /** - * Create a usertag on the server - * - * @param usertag - * @param value - * @return true if successful, false otherwise - */ - public boolean createUsertag(String usertag, String value) { - return this.users.createUserTag(usertag, value); - } - - /** - * Change a usertag on the server - * - * @param usertag - * @param value - * @return true if successful, false otherwise - */ - public boolean editUsertag(String usertag, String value) { - return this.users.editUserTag(usertag, value); - } - - /** - * Delete a usertag from the server - * - * @param usertag - * @return true if successful, false otherwise - */ - public boolean removeUsertag(String usertag) { - return this.users.removeUserTag(usertag); - } - - /** - * Assign a usertag to an player - * - * @param player - * @param usertag - * @return true if successful, false otherwise - */ - public boolean setUsertag(Player player, String usertag) { - return this.users.setUserTag(player.getName(), usertag); - } - - /** - * Add a usertag to an player - * - * @param player - * @param usertag - * @return true if successful, false otherwise - */ - public boolean addUsertag(Player player, String usertag) { - return this.users.addUserTag(player.getName(), usertag); - } - - /** - * Remove an usertag from a player - * - * @param player - * @param usertag - * @return true if successful, false otherwise - */ - public boolean delUsertag(Player player, String usertag) { - return this.users.delUserTag(player.getName(), usertag); - } - - /** - * Deprecated | replaced by {@link #getPrimaryRank(Player)} - * - * Get the rankname of a player - * - * @param player - * @return player's rankname - */ - @Deprecated - public String getPlayerRank(Player player) { - String rank = users.getPrimaryRank(player); - return rank; - } - - /** - * Deprecated | replaced by {@link #getAllowedPermissions(String)} & - * {@link #getDeniedPermissions(String)} - * - * Get a list of permissions of a rank - * - * @param rank - * @return list of permissions that a rank has - */ - @Deprecated - public List getPermissions(String rank) { - List permissions = new ArrayList(); - for (PRPermission permission : CacheManager.getRank(users.getRankIgnoreCase(rank)).getPermissions()) { - permissions.add(permission.getName()); - } - return permissions; - } - - /** - * Deprecated | replaced by {@link #addPermission(String, String, boolean)} - * - * Add a permission to a rank - * If the permissions starts with '-' it will be denied - * - * @param rank - * @param permission - * @return true if success, false otherwise - */ - @Deprecated - public boolean addPermission(String rank, String permission) { - return this.users.addPermission(users.getRankIgnoreCase(rank), - permission.startsWith("-") ? permission.replaceFirst("-", "") : permission, - !permission.startsWith("-")); - } - - /** - * Deprecated | replaced by {@link #addPermission(Player, String, boolean)} - * - * Add a permission to a rank - * If the permissions starts with '-' it will be denied - * - * @param rank - * @param permission - * @return true if success, false otherwise - */ - @Deprecated - public boolean addPermission(Player player, String permission) { - return this.users.addPlayerPermission(player.getName(), - permission.startsWith("-") ? permission.replaceFirst("-", "") : permission, - !permission.startsWith("-")); - } - - /** - * Deprecated - * - * Is building enabled on a rank? - * return bool - */ - @Deprecated - public boolean isBuildingEnabled(String rank) { - return false; - } - - /** - * Deprecated - * - * set building enabled on a rank - * - * @param rank - * @param new_value - * @return bool - */ - @Deprecated - public boolean setBuildingEnabled(String rank, boolean new_value) { - return false; - } - - /** - * Deprecated - * - * Get the rankname to promote to - * - * @param rank - * @return String - */ - @Deprecated - public String getPromoteRank(String rank) { - return ""; - } - - /** - * Deprecated - * - * Set the rankname to promote to - * - * @param rank - * @param new_value - * @return bool - */ - @Deprecated - public boolean setPromoteRank(String rank, String new_value) { - return false; - } - - /** - * Deprecated - * - * Get the rankname to demote to - * - * @param rank - * @return String - */ - @Deprecated - public String getDemoteRank(String rank) { - return ""; - } - - /** - * Deprecated - * - * Set the rankname to demote to - * - * @param rank - * @param new_value - * @return bool - */ - @Deprecated - public boolean setDemoteRank(String rank, String new_value) { - return false; - } - - /** - * Deprecated - * - * Get all subranks of a player - * - * @return List - */ - @Deprecated - public List getSubranks(Player player) { - return new ArrayList(); - } - - /** - * Deprecated - * - * Add a subrank to a player - * - * @param player - * @param rank - * @return bool - */ - @Deprecated - public boolean addSubrank(Player player, String rank) { - return false; - } - - /** - * Deprecated - * - * Remove a subrank from a player - * - * @param player - * @param rank - * @return bool - */ - @Deprecated - public boolean removeSubrank(Player player, String rank) { - return false; - } - - /** - * Deprecated - * - * Get formatted subrank prefixes - * - * @param player - * @return String - */ - @Deprecated - public String getPlayerSubrankPrefixes(Player player) { - return ""; - } - - /** - * Deprecated - * - * Get formatted subrank suffixes - * - * @param player - * @return String - */ - @Deprecated - public String getPlayerSubrankSuffixes(Player player) { - return ""; - } -} \ No newline at end of file diff --git a/src/main/java/nl/svenar/powerranks/external/PRTABFeature.java b/src/main/java/nl/svenar/powerranks/external/PRTABFeature.java deleted file mode 100644 index 24f28261..00000000 --- a/src/main/java/nl/svenar/powerranks/external/PRTABFeature.java +++ /dev/null @@ -1,56 +0,0 @@ -package nl.svenar.powerranks.external; - -import java.util.List; - -import me.neznamy.tab.api.TabAPI; -import me.neznamy.tab.api.TabFeature; -import me.neznamy.tab.api.TabPlayer; -import me.neznamy.tab.api.team.TeamManager; -import nl.svenar.common.structure.PRRank; -import nl.svenar.powerranks.cache.CacheManager; - -public class PRTABFeature extends TabFeature { - - protected PRTABFeature(String featureName, String refreshDisplayName) { - super(featureName, refreshDisplayName); - } - - protected PRTABFeature(String featureName, String refreshDisplayName, List disabledServers, - List disabledWorlds) { - super(featureName, refreshDisplayName, disabledServers, disabledWorlds); - } - - /** - * Processes join event - * - * @param connectedPlayer - player who connected - */ - @Override - public void onJoin(TabPlayer connectedPlayer) { - // PowerRanks.getInstance().getLogger().warning("PRTABFeature: onJoin() called"); - TeamManager teamManager = TabAPI.getInstance().getTeamManager(); - // teamManager.pauseTeamHandling(connectedPlayer); - // teamManager.forceTeamName(connectedPlayer, "prtab" + - // connectedPlayer.getName()); - - List playerRanks = TABHook - .getSortedRanks(CacheManager.getPlayer(connectedPlayer.getUniqueId().toString())); - - teamManager.setPrefix(connectedPlayer, playerRanks.get(0).getPrefix() + " "); - teamManager.updateTeamData(connectedPlayer); - - TabAPI.getInstance().getTablistFormatManager().setPrefix(connectedPlayer, playerRanks.get(0).getPrefix() + " "); - } - - /** - * Performs refresh of specified player - * - * @param refreshed - player to refresh - * @param force - if refresh should be forced despite refresh seemingly not - * needed - */ - @Override - public void refresh(TabPlayer refreshed, boolean force) { - // PowerRanks.getInstance().getLogger().warning("PRTABFeature: refresh() called"); - } -} diff --git a/src/main/java/nl/svenar/powerranks/external/TABHook.java b/src/main/java/nl/svenar/powerranks/external/TABHook.java deleted file mode 100644 index 3e58102d..00000000 --- a/src/main/java/nl/svenar/powerranks/external/TABHook.java +++ /dev/null @@ -1,148 +0,0 @@ -package nl.svenar.powerranks.external; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.scheduler.BukkitRunnable; - -import me.neznamy.tab.api.TabAPI; -import nl.svenar.common.structure.PRPlayer; -import nl.svenar.common.structure.PRPlayerRank; -import nl.svenar.common.structure.PRRank; -import nl.svenar.common.utils.PRUtil; -import nl.svenar.powerranks.PowerRanks; -import nl.svenar.powerranks.cache.CacheManager; -import nl.svenar.powerranks.util.PluginReloader; - -public class TABHook { - - private boolean isReady = false; - private List sortedRanks = new ArrayList(); - private PRTABFeature prTabFeature = null; - - public void setup() { - prTabFeature = new PRTABFeature("powerranks", ""); - - new BukkitRunnable() { - @Override - public void run() { - if (PowerRanks.getInstance().getServer().getPluginManager().isPluginEnabled("TAB")) { - TabAPI.getInstance().getFeatureManager().registerFeature("powerranks", - new PRTABFeature("powerranks", "")); - load(); - this.cancel(); - } - } - }.runTaskTimer(PowerRanks.getInstance(), 5, 1); - - new BukkitRunnable() { - List ranks = new ArrayList(CacheManager.getRanks()); - - @Override - public void run() { - if (isReady) { - // PowerRanks.getInstance().getLogger().warning(CacheManager.getRanks().size() + - // " - " + ranks.size() + " | " + - // TabAPI.getInstance().getFeatureManager().isFeatureEnabled("powerranks")); - - if (CacheManager.getRanks().size() != ranks.size()) { - ranks = new ArrayList(CacheManager.getRanks()); - // updateRanks(); - isReady = false; - load(); - // this.cancel(); - // setup(); - } - - // if (!TabAPI.getInstance().getFeatureManager().isFeatureEnabled("powerranks")) - // { - // TabAPI.getInstance().getFeatureManager().registerFeature("powerranks", new - // PRTABFeature("powerranks", "")); - // } - } - } - }.runTaskTimer(PowerRanks.getInstance(), 20 * 5, 20 * 5); - } - - private void load() { - if (isReady) { - return; - } - - if (!updateRanks()) { - isReady = true; - // try { - // TabAPI.getInstance().getFeatureManager().registerFeature("powerranks", new - // PRTABFeature("powerranks", "")); - // } catch (Exception e) {} - TabAPI.getInstance().debug("Hooked into PowerRanks"); - } - } - - public boolean updateRanks() { - sortedRanks = getSortedRanks(); - - boolean doRestart = false; - - List sortingList = new ArrayList(); - for (PRRank rank : sortedRanks) { - sortingList.add(rank.getName()); - } - - List sortingTypes = TabAPI.getInstance().getConfig().getStringList("scoreboard-teams.sorting-types", - new ArrayList()); - List newSortingTypes = new ArrayList(); - - newSortingTypes.add("GROUPS:" + String.join(",", sortingList)); - - for (String type : sortingTypes) { - if (!type.split(":")[0].equals("GROUPS")) { - newSortingTypes.add(type); - } else { - - // PowerRanks.getInstance().getLogger().warning(type.split(":")[1] + " - " + - // String.join(",", sortingList)); - - if (String.join(",", sortingList).length() != type.split(":")[1].length()) { - // doRestart = true; // Restart the plugin - } - } - } - TabAPI.getInstance().getConfig().set("scoreboard-teams.sorting-types", newSortingTypes); - - TabAPI.getInstance().getConfig().save(); - - if (doRestart) { - TabAPI.getInstance().getFeatureManager().unregisterFeature("powerranks"); - PluginReloader pluginReloader = new PluginReloader(); - TabAPI.getInstance().debug("[PR] Restarting TAB..."); - pluginReloader.reload("TAB"); - TabAPI.getInstance().debug("[PR] Restarted TAB."); - TabAPI.getInstance().getFeatureManager().registerFeature("powerranks", prTabFeature); - load(); - } - - return doRestart; - - } - - private List getSortedRanks() { - List ranks = CacheManager.getRanks(); - PRUtil.sortRanksByWeight(ranks); - PRUtil.reverseRanks(ranks); - return ranks; - } - - static List getSortedRanks(PRPlayer prPlayer) { - List playerRanks = new ArrayList(); - for (PRPlayerRank rank : prPlayer.getRanks()) { - if (CacheManager.getRank(rank.getName()) != null) { - playerRanks.add(CacheManager.getRank(rank.getName())); - } - } - - PRUtil.sortRanksByWeight(playerRanks); - PRUtil.reverseRanks(playerRanks); - return playerRanks; - } -}