add api version - fix legacy support

This commit is contained in:
Destro174 2020-10-20 21:11:16 +02:00
parent a1bfac4cd6
commit 110caa9d3f
2 changed files with 17 additions and 1 deletions

View File

@ -2,13 +2,15 @@ package com.alttd.destro174.custommotd;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.alttd.destro174.custommotd.commands.custommotdCommand; import com.alttd.destro174.custommotd.commands.custommotdCommand;
import com.alttd.destro174.custommotd.listener.PapiPingListener; import com.alttd.destro174.custommotd.listener.PapiPingListener;
import com.alttd.destro174.custommotd.listener.PingListener; import com.alttd.destro174.custommotd.listener.PingListener;
import com.alttd.destro174.custommotd.storage.MOTDConfig; import com.alttd.destro174.custommotd.storage.MOTDConfig;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -26,11 +28,24 @@ public class CustomMOTD extends JavaPlugin {
public static CachedServerIcon icon; public static CachedServerIcon icon;
public boolean useproxyonlinecount; public boolean useproxyonlinecount;
private Pattern PATTERN = Pattern.compile("\\{&#[0-9a-fA-F]{6}\\}");
private Pattern GRADIENT = Pattern.compile("\\{&#[0-9a-fA-F]{6}>\\}[^\\{]*\\{&#[0-9a-fA-F]{6}<\\}");
public List<String> colorList(List<String> list){ public List<String> colorList(List<String> list){
List<String> lines = new ArrayList<String>(); List<String> lines = new ArrayList<String>();
for (String s : list) { for (String s : list) {
Matcher matcher = PATTERN.matcher(s);
while(matcher.find()) {
/*
val hexcode = m.group()
val fixed = hexcode.substring(2, 8)
*/
String hexcode = matcher.group();
String color = hexcode.substring(2, 9);
s = s.replace(matcher.group(), ChatColor.of(color) + "");
matcher = PATTERN.matcher(s);
}
s = s.replace("%version%", Bukkit.getMinecraftVersion()); // 1.16 addon s = s.replace("%version%", Bukkit.getMinecraftVersion()); // 1.16 addon
lines.add(ChatColor.translateAlternateColorCodes('&', s)); lines.add(ChatColor.translateAlternateColorCodes('&', s));
} }

View File

@ -2,6 +2,7 @@ name: CustomMOTD
main: com.alttd.destro174.custommotd.CustomMOTD main: com.alttd.destro174.custommotd.CustomMOTD
version: 1.0 version: 1.0
author: destro174 author: destro174
api-version: 1.16
softdepend: [PlaceholderAPI] softdepend: [PlaceholderAPI]
commands: commands:
custommotd: custommotd: