Add hex color support to translations

This commit is contained in:
libraryaddict
2020-06-27 21:01:58 +12:00
parent 5f2ac293bf
commit ffd6536565
70 changed files with 481 additions and 452 deletions

View File

@@ -40,6 +40,7 @@ import org.apache.commons.lang.math.RandomUtils;
import org.apache.logging.log4j.util.Strings;
import org.bukkit.*;
import org.bukkit.boss.KeyedBossBar;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.*;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@@ -280,10 +281,10 @@ public class DisguiseUtilities {
if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) {
String entityName = DisguiseType.getType(toClone).toReadable();
player.sendMessage(LibsMsg.MADE_REF.get(entityName, reference));
player.sendMessage(LibsMsg.MADE_REF_EXAMPLE.get(reference));
DisguiseUtilities.sendMessage(player, LibsMsg.MADE_REF, entityName, reference);
DisguiseUtilities.sendMessage(player, LibsMsg.MADE_REF_EXAMPLE, reference);
} else {
player.sendMessage(LibsMsg.REF_TOO_MANY.get());
DisguiseUtilities.sendMessage(player, LibsMsg.REF_TOO_MANY);
}
}
@@ -2056,6 +2057,14 @@ public class DisguiseUtilities {
return Strings.isEmpty(player.getPlayerListName()) ? player.getName() : player.getPlayerListName();
}
public static void sendMessage(CommandSender sender, LibsMsg msg, Object... args) {
if (!NmsVersion.v1_16.isSupported()) {
sender.sendMessage(msg.get(args));
} else {
sender.spigot().sendMessage(msg.getChat(args));
}
}
public static Logger getLogger() {
return LibsDisguises.getInstance().getLogger();
}

View File

@@ -9,7 +9,8 @@ import java.lang.reflect.Type;
/**
* Created by libraryaddict on 1/06/2017.
*/
public class SerializerWrappedBlockData implements JsonSerializer<WrappedBlockData>, JsonDeserializer<WrappedBlockData> {
public class SerializerWrappedBlockData implements JsonSerializer<WrappedBlockData>,
JsonDeserializer<WrappedBlockData> {
@Override
public JsonElement serialize(WrappedBlockData src, Type typeOfSrc, JsonSerializationContext context) {

View File

@@ -18,7 +18,7 @@ import me.libraryaddict.disguise.events.DisguiseInteractEvent;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

View File

@@ -140,13 +140,13 @@ public class PacketListenerModdedClient extends PacketAdapter {
PacketContainer packet1 = new PacketContainer(PacketType.Login.Server.CUSTOM_PAYLOAD);
packet1.getIntegers().write(0, packetId1);
packet1.getMinecraftKeys().write(0, new com.comphenix.protocol.wrappers.MinecraftKey("fml", "handshake"));
// packet1.getModifier()
// packet1.getModifier()
// .write(2, new PacketDataSerializer(Unpooled.wrappedBuffer(ModdedManager.getFmlHandshake())));
PacketContainer packet2 = new PacketContainer(PacketType.Login.Server.CUSTOM_PAYLOAD);
packet2.getIntegers().write(0, packetId2);
packet2.getMinecraftKeys().write(0, new MinecraftKey("fml", "handshake"));
// packet2.getModifier()
// packet2.getModifier()
// .write(2, new PacketDataSerializer(Unpooled.wrappedBuffer(ModdedManager.getFmlRegistries())));
//TODO

View File

@@ -54,10 +54,8 @@ public class PacketListenerTabList extends PacketAdapter {
if (list.isEmpty()) {
event.setCancelled(true);
}
else {
} else {
event.getPacket().getPlayerInfoDataLists().write(0, list);
}
}
}

View File

@@ -23,5 +23,4 @@ public class FakeBoundingBox {
public double getZ() {
return zMod / 2;
}
}

View File

@@ -5,5 +5,4 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
public interface LibsProfileLookup {
void onLookup(WrappedGameProfile gameProfile);
}

View File

@@ -20,5 +20,4 @@ public class LibsProfileLookupCaller implements ProfileLookupCallback {
public void onProfileLookupSucceeded(GameProfile profile) {
gameProfile = WrappedGameProfile.fromHandle(profile);
}
}

View File

@@ -9,7 +9,9 @@ import java.util.Map;
* Created by libraryaddict on 17/02/2020.
*/
public interface IAsm {
Class<?> createClassWithoutMethods(String className, ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException, IllegalAccessException, NoSuchMethodException, NoSuchFieldException;
Class<?> createClassWithoutMethods(String className,
ArrayList<Map.Entry<String, String>> illegalMethods) throws IOException, InvocationTargetException,
IllegalAccessException, NoSuchMethodException, NoSuchFieldException;
}

View File

@@ -1,9 +1,15 @@
package me.libraryaddict.disguise.utilities.translations;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by libraryaddict on 15/06/2017.
*/
@@ -351,6 +357,15 @@ public enum LibsMsg {
SELF_DISGUISE_HIDDEN(ChatColor.GREEN + "Self disguise hidden as it's too tall..");
private final String string;
private static final Pattern hexColor;
static {
if (NmsVersion.v1_16.isSupported()) {
hexColor = Pattern.compile("<#[0-9a-fA-F]{6}>");
} else {
hexColor = null;
}
}
LibsMsg(String string) {
this.string = string;
@@ -360,6 +375,35 @@ public enum LibsMsg {
return string;
}
public BaseComponent[] getChat(Object... strings) {
String string = get(strings);
if (hexColor == null) {
return new ComponentBuilder().appendLegacy(string).create();
}
Matcher match = hexColor.matcher(string);
ComponentBuilder builder = new ComponentBuilder();
int lastMatch = 0;
while (match.find()) {
if (match.start() > lastMatch) {
builder.appendLegacy(string.substring(lastMatch, match.start()));
}
lastMatch = match.end();
builder.color(net.md_5.bungee.api.ChatColor.of(match.group().substring(1, 8)));
}
if (lastMatch < string.length()) {
builder.appendLegacy(string.substring(lastMatch));
}
return builder.create();
}
public String get(Object... strings) {
if (StringUtils.countMatches(getRaw(), "%s") != strings.length) {
DisguiseUtilities.getLogger().severe("Mismatch in messages, incorrect parameters supplied for " + name() +

View File

@@ -80,7 +80,7 @@ public enum TranslateType {
}
if (!getFile().exists()) {
DisguiseUtilities.getLogger().info("Translations for " + name() + " missing! Skipping...");
DisguiseUtilities.getLogger().info("Translations for " + name() + " missing! Saving..");
return;
}
@@ -182,6 +182,7 @@ public enum TranslateType {
writer.write(
"# To translate, follow this example 'Original Message': 'My New Message'\n# The Original" +
" Message is used as a yaml config key to get your new message!");
writer.write("\n# To use hex color codes, use <#hexcolor> where hexcolor is the 6 char code");
}
}