diff --git a/pom.xml b/pom.xml index 0e59e0b..6f3f727 100644 --- a/pom.xml +++ b/pom.xml @@ -10,12 +10,12 @@ UTF-8 UTF-8 - ${project.groupId}.plugin.${project.groupId} - 1.0.2 + ${project.groupId}.plugin.${project.artifactId} + 1.1.0 com.artformgames usersuffix - 1.0.0 + 1.1.0 UserSuffix @@ -106,16 +106,16 @@ - com.artformgames - artcore-api - ${deps.core.version} - provided + org.bstats + bstats-bukkit + 3.0.0 + compile - net.luckperms - api - 5.4 + com.artformgames + artcore-api + ${deps.core.version} provided diff --git a/src/main/java/com/artformgames/plugin/usersuffix/Main.java b/src/main/java/com/artformgames/plugin/usersuffix/Main.java index 9d207c0..5d37fdf 100644 --- a/src/main/java/com/artformgames/plugin/usersuffix/Main.java +++ b/src/main/java/com/artformgames/plugin/usersuffix/Main.java @@ -53,9 +53,9 @@ protected boolean initialize() { log("Version checker is disabled, skipped."); } - log("Register placeholders..."); if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { - new SuffixPlaceholder(this, getName()); + log("Register placeholders..."); + new SuffixPlaceholder(this, getName()).register(); } else { log("PlaceholderAPI is not enabled, skipped."); } diff --git a/src/main/java/com/artformgames/plugin/usersuffix/command/UserSuffixCommands.java b/src/main/java/com/artformgames/plugin/usersuffix/command/UserSuffixCommands.java index 5201f08..5faca74 100644 --- a/src/main/java/com/artformgames/plugin/usersuffix/command/UserSuffixCommands.java +++ b/src/main/java/com/artformgames/plugin/usersuffix/command/UserSuffixCommands.java @@ -14,6 +14,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import java.util.Map; import java.util.stream.Collectors; @Command(name = "usersuffix", aliases = "suffix") @@ -31,8 +32,12 @@ void clearSuffix(@Context Player player) { @Execute(name = "content") void setContent(@Context Player player, @Join String content) { - if (content.contains("&")) { - PluginMessages.CONTAIN_COLOR_CODE.send(player); + int maxLength = PluginConfig.MAX_LENGTH.entrySet().stream() + .filter(e -> player.hasPermission(e.getValue())) + .mapToInt(Map.Entry::getKey).max().orElse(-1); + + if (maxLength <= 0) { + PluginMessages.NO_PERMISSION.send(player); return; } @@ -41,7 +46,8 @@ void setContent(@Context Player player, @Join String content) { return; } - if (content.length() > PluginConfig.MAX_LENGTH.getNotNull()) { + + if (ColorParser.clear(content).length() > maxLength) { PluginMessages.TOO_LONG.send(player, PluginConfig.MAX_LENGTH.getNotNull()); return; } diff --git a/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginConfig.java b/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginConfig.java index c33b979..a2e2f2c 100644 --- a/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginConfig.java +++ b/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginConfig.java @@ -3,7 +3,9 @@ import cc.carm.lib.configuration.core.Configuration; import cc.carm.lib.configuration.core.annotation.HeaderComment; import cc.carm.lib.configuration.core.value.ConfigValue; +import cc.carm.lib.configuration.core.value.impl.ConfigValueMap; import cc.carm.lib.configuration.core.value.type.ConfiguredList; +import cc.carm.lib.configuration.core.value.type.ConfiguredMap; import cc.carm.lib.configuration.core.value.type.ConfiguredValue; import org.bukkit.ChatColor; @@ -49,7 +51,12 @@ public interface PluginConfig extends Configuration { ChatColor.YELLOW, ChatColor.WHITE ).build(); - @HeaderComment("Maximum length of the suffix (excluding color symbols)") - ConfigValue MAX_LENGTH = ConfiguredValue.of(8); + @HeaderComment("Maximum length of the suffix of each permissions (excluding color symbols)") + ConfiguredMap MAX_LENGTH = ConfigValueMap.builderOf(Integer.class, String.class) + .asLinkedMap().fromString().parseKey(Integer::parseInt).parseValue(Object::toString) + .defaults(m -> { + m.put(8, "usersuffix.use"); + m.put(12, "group.vip"); + }).build(); } diff --git a/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginMessages.java b/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginMessages.java index 3e6b620..028f15e 100644 --- a/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginMessages.java +++ b/src/main/java/com/artformgames/plugin/usersuffix/conf/PluginMessages.java @@ -1,47 +1,50 @@ package com.artformgames.plugin.usersuffix.conf; import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList; -import com.artformgames.core.conf.MessagesRoot; +import com.artformgames.core.conf.Messages; import net.md_5.bungee.api.chat.BaseComponent; -public class PluginMessages extends MessagesRoot { +public interface PluginMessages extends Messages { - public static final ConfiguredMessageList CLEARED = list() + ConfiguredMessageList CLEARED = Messages.list() .defaults("&fThe existing suffix has been cleared for you. To set up again, enter &e/suffix content &f.") .build(); - public static final ConfiguredMessageList TOO_LONG = list() + ConfiguredMessageList NO_PERMISSION = Messages.list() + .defaults("&c&lSorry! &fBut you dont have enough permission to set a suffix!") + .build(); + + ConfiguredMessageList TOO_LONG = Messages.list() .defaults("&fThe suffix you want to set is too long, no longer than &e% (length) &f characters (excluding colors).") .params("length") .build(); - public static final ConfiguredMessageList TOO_SHORT = list() + ConfiguredMessageList TOO_SHORT = Messages.list() .defaults("&fYour suffix contains at least one character (excluding colors).") .build(); - public static final ConfiguredMessageList SUCCESS = list() + ConfiguredMessageList SUCCESS = Messages.list() .defaults("&fSuccessfully modified your suffix to &r%(suffix) &f.") .params("suffix") .build(); - public static final ConfiguredMessageList FAILED = list() + ConfiguredMessageList FAILED = Messages.list() .defaults("&fYou can't use this suffix because it may contain a violating word, please try again after changing something else.") .build(); - public static final ConfiguredMessageList NO_SPACE = list() + ConfiguredMessageList NO_SPACE = Messages.list() .defaults("&fSuffix should not contain spaces.") .build(); - public static final ConfiguredMessageList CONTAIN_COLOR_CODE = list() + ConfiguredMessageList CONTAIN_COLOR_CODE = Messages.list() .defaults("&fYou can't include color codes directly in your suffix!") .build(); - public static final ConfiguredMessageList INVALID_COLOR_CODE = list() + ConfiguredMessageList INVALID_COLOR_CODE = Messages.list() .defaults( "&fYour color is invalid!", "&fYou can choose from the following colors:" ).build(); - } diff --git a/src/main/java/com/artformgames/plugin/usersuffix/user/SuffixLoader.java b/src/main/java/com/artformgames/plugin/usersuffix/user/SuffixLoader.java index 1fd5333..e2cc45b 100644 --- a/src/main/java/com/artformgames/plugin/usersuffix/user/SuffixLoader.java +++ b/src/main/java/com/artformgames/plugin/usersuffix/user/SuffixLoader.java @@ -18,7 +18,7 @@ public class SuffixLoader extends UserHandlerLoader { protected SQLTable table = SQLTable.of("user_suffix", builder -> { builder.addColumn("user", "INT UNSIGNED NOT NULL PRIMARY KEY"); - builder.addColumn("suffix", "VARCHAR(16)"); + builder.addColumn("content", "VARCHAR(255)"); builder.addColumn("color", "CHAR(1)"); }); @@ -43,9 +43,9 @@ public SuffixLoader(@NotNull Plugin plugin) { .setLimit(1).build().execute()) { ResultSet rs = query.getResultSet(); if (rs.next()) { - String suffix = rs.getString("suffix"); + String content = rs.getString("content"); String color = rs.getString("color"); - return new SuffixAccount(user, suffix, color == null ? null : ChatColor.getByChar(color.charAt(0))); + return new SuffixAccount(user, content, color == null ? null : ChatColor.getByChar(color.charAt(0))); } } return null; @@ -57,7 +57,7 @@ public void saveData(UserKey user, SuffixAccount handler) throws Exception { table.createDelete().addCondition("user", user.id()).build().execute(); } else { table.createInsert() - .setColumnNames("user", "suffix", "color") + .setColumnNames("user", "content", "color") .setParams( user.id(), handler.getContent(), handler.getColor() == null ? null : handler.getColor().getChar() diff --git a/src/main/resources/PLUGIN_INFO b/src/main/resources/PLUGIN_INFO new file mode 100644 index 0000000..01dbad0 --- /dev/null +++ b/src/main/resources/PLUGIN_INFO @@ -0,0 +1,5 @@ +&e _ _ &f ___ __ __ _ +&e| | | |___ ___ _ _&f/ __|_ _ / _|/ _(_)_ __ +&e| |_| (_-