diff --git a/pom.xml b/pom.xml
index 5c471a1..6432d73 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.majek.hexnicks
HexNicks
- 2.0.4
+ 2.0.5
jar
HexNicks
@@ -144,7 +144,7 @@
net.kyori
adventure-api
- 4.8.1
+ 4.9.1
compile
@@ -165,21 +165,21 @@
net.kyori
adventure-text-serializer-legacy
- 4.8.1
+ 4.9.1
compile
net.kyori
adventure-text-serializer-gson
- 4.8.1
+ 4.9.1
compile
net.kyori
adventure-text-serializer-plain
- 4.8.1
+ 4.9.1
compile
diff --git a/src/main/java/dev/majek/hexnicks/command/CommandNick.java b/src/main/java/dev/majek/hexnicks/command/CommandNick.java
index 53df7e7..3c34ede 100644
--- a/src/main/java/dev/majek/hexnicks/command/CommandNick.java
+++ b/src/main/java/dev/majek/hexnicks/command/CommandNick.java
@@ -29,6 +29,8 @@
import dev.majek.hexnicks.config.NicksMessages;
import java.util.Collections;
import java.util.List;
+
+import dev.majek.hexnicks.util.MiniMessageWrapper;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
@@ -64,7 +66,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
nickInput = Nicks.utils().legacyToMini(nickInput);
}
- Component nickname = MiniMessage.get().parse(nickInput);
+ MiniMessageWrapper wrapper = new MiniMessageWrapper(nickInput);
+
+ // Check permissions for colors
+ if(!player.hasPermission("hexnicks.nick.gradient")) {
+ wrapper.removeGradients();
+ }
+ if(!player.hasPermission("hexnicks.nick.hex")) {
+ wrapper.removeHex();
+ }
+ if(!player.hasPermission("hexnicks.nick.color")) {
+ wrapper.removeAllTokens();
+ }
+
+ Component nickname = wrapper.mmParse();
String plainTextNick = PlainTextComponentSerializer.plainText().serialize(nickname);
int maxLength = Nicks.config().MAX_LENGTH;
int minLength = Nicks.config().MIN_LENGTH;
diff --git a/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java b/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java
index 242d2f5..0f353fd 100644
--- a/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java
+++ b/src/main/java/dev/majek/hexnicks/command/CommandNickColor.java
@@ -29,6 +29,8 @@
import dev.majek.hexnicks.config.NicksMessages;
import java.util.Collections;
import java.util.List;
+
+import dev.majek.hexnicks.util.MiniMessageWrapper;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
@@ -72,10 +74,23 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}
+ MiniMessageWrapper wrapper = new MiniMessageWrapper(nickInput);
+
+ // Check permissions for colors
+ if(!player.hasPermission("hexnicks.nick.gradient")) {
+ wrapper.removeGradients();
+ }
+ if(!player.hasPermission("hexnicks.nick.hex")) {
+ wrapper.removeHex();
+ }
+ if(!player.hasPermission("hexnicks.nick.color")) {
+ wrapper.removeAllTokens();
+ }
+
// Get the players current nickname to apply color codes to
String plainTextNick = PlainTextComponentSerializer.plainText()
.serialize(Nicks.core().getDisplayName(player));
- Component nickname = MiniMessage.get().parse(nickInput + plainTextNick);
+ Component nickname = MiniMessage.get().parse(wrapper.mmString() + plainTextNick);
// Call event
NickColorEvent colorEvent = new NickColorEvent(player, nickname,
diff --git a/src/main/java/dev/majek/hexnicks/util/MiniMessageWrapper.java b/src/main/java/dev/majek/hexnicks/util/MiniMessageWrapper.java
new file mode 100644
index 0000000..77f140b
--- /dev/null
+++ b/src/main/java/dev/majek/hexnicks/util/MiniMessageWrapper.java
@@ -0,0 +1,102 @@
+/*
+ * This file is part of HexNicks, licensed under the MIT License.
+ *
+ * Copyright (c) 2020-2021 Majekdor
+ *
+ * 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 dev.majek.hexnicks.util;
+
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import org.jetbrains.annotations.NotNull;
+
+public class MiniMessageWrapper {
+
+ private String mmString;
+
+ /**
+ * Create a new wrapper with a string with {@link MiniMessage} tags to eventually be parsed.
+ *
+ * @param mmString String with {@link MiniMessage} tags.
+ */
+ public MiniMessageWrapper(@NotNull String mmString) {
+ this.mmString = mmString;
+ }
+
+ /**
+ * Remove {@link MiniMessage}'s hex color code tokens.
+ *
+ * @return Wrapper.
+ */
+ public MiniMessageWrapper removeHex() {
+ this.mmString = this.mmString.replaceAll("<#([0-9a-fA-F]{6})>", "");
+ this.mmString = this.mmString.replaceAll("#([0-9a-fA-F]{6})>", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ return this;
+ }
+
+ /**
+ * Remove {@link MiniMessage}'s gradient tokens.
+ *
+ * @return Wrapper.
+ */
+ public MiniMessageWrapper removeGradients() {
+ this.mmString = this.mmString.replaceAll("", "");
+ this.mmString = this.mmString.replaceAll("", "");
+ return this;
+ }
+
+ /**
+ * Remove all of {@link MiniMessage}'s tokens.
+ *
+ * @return Wrapper.
+ */
+ public MiniMessageWrapper removeAllTokens() {
+ this.mmString = MiniMessage.get().stripTokens(mmString);
+ return this;
+ }
+
+ /**
+ * Parse the string passed through in the constructor with {@link MiniMessage}.
+ *
+ * @return Parsed {@link Component}.
+ */
+ public Component mmParse() {
+ return MiniMessage.get().parse(mmString);
+ }
+
+ /**
+ * Return the modified string passed through in the constructor.
+ *
+ * @return Modified string.
+ */
+ public String mmString() {
+ return mmString;
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 3d4ac70..b4ea9f2 100755
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -31,6 +31,15 @@ permissions:
hexnicks.nick:
description: Permission to change nicknames.
default: true
+ hexnicks.nick.color:
+ description: Permission to use standard color codes in nicknames.
+ default: true
+ hexnicks.nick.hex:
+ description: Permission to use hex color codes in nicknames.
+ default: true
+ hexnicks.nick.gradient:
+ description: Permission to use gradients in nicknames.
+ default: true
hexnicks.nick.other:
description: Permission to change other player's nicknames.
default: op
@@ -41,7 +50,7 @@ permissions:
description: Permission to remove other player's nicknames.
default: op
hexnicks.nickcolor:
- description: Permission to change color of nickname.
+ description: Permission to use the nickcolor command to change only the nickname's color.
default: true
hexnicks.reload:
description: Permission to reload the plugin.