Add MineDown support (and with that RGB colors)

This commit is contained in:
Phoenix616 2020-09-03 17:23:23 +01:00
parent fc40436422
commit a8db0033df
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
4 changed files with 29 additions and 8 deletions

10
pom.xml
View File

@ -50,8 +50,8 @@
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@ -61,6 +61,12 @@
<version>1.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.themoep</groupId>
<artifactId>minedown</artifactId>
<version>1.6.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.themoep.utils</groupId>
<artifactId>lang-bukkit</artifactId>

View File

@ -65,6 +65,10 @@
<pattern>io.papermc.lib</pattern>
<shadedPattern>de.themoep.randomteleport.libs.paperlib</shadedPattern>
</relocation>
<relocation>
<pattern>de.themoep.minedown</pattern>
<shadedPattern>de.themoep.randomteleport.libs.minedown</shadedPattern>
</relocation>
<relocation>
<pattern>de.themoep.utils.lang</pattern>
<shadedPattern>de.themoep.randomteleport.libs.lang</shadedPattern>

View File

@ -20,6 +20,7 @@ package de.themoep.randomteleport;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import de.themoep.minedown.MineDown;
import de.themoep.randomteleport.api.RandomTeleportAPI;
import de.themoep.randomteleport.hook.HookManager;
import de.themoep.randomteleport.listeners.SignListener;
@ -38,6 +39,8 @@ import de.themoep.randomteleport.searcher.validators.ProtectionValidator;
import de.themoep.randomteleport.searcher.validators.WorldborderValidator;
import de.themoep.utils.lang.bukkit.LanguageManager;
import io.papermc.lib.PaperLib;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
@ -276,16 +279,24 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
}
public boolean sendMessage(CommandSender sender, String key, String... replacements) {
String message = getMessage(sender, key, replacements);
if (message != null && !message.isEmpty()) {
sender.sendMessage(message);
BaseComponent[] message = getComponentMessage(sender, key, replacements);
if (message != null && message.length != 0) {
sender.spigot().sendMessage(message);
return true;
}
return false;
}
public String getMessage(CommandSender sender, String key, String... replacements) {
return lang.getConfig(sender).get(key, replacements);
public BaseComponent[] getComponentMessage(CommandSender sender, String key, String... replacements) {
return MineDown.parse(getLang(sender, key), replacements);
}
public String getTextMessage(CommandSender sender, String key, String... replacements) {
return TextComponent.toLegacyText(getComponentMessage(sender, key, replacements));
}
private String getLang(CommandSender sender, String key) {
return lang.getConfig(sender).get(key);
}
public HookManager getHookManager() {

View File

@ -58,7 +58,7 @@ public class SimpleOptionParser implements OptionParser {
}
if (aliases.contains(option)) {
if (!hasAccess(searcher.getInitiator())) {
throw new IllegalArgumentException(searcher.getPlugin().getMessage(
throw new IllegalArgumentException(searcher.getPlugin().getTextMessage(
searcher.getInitiator(), "error.no-permission.option",
"option", option,
"perm", "randomteleport.manual.option." + aliases.iterator().next()));