From 99745b8e596d3aaa5d5a80d286a1847987bf946c Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Wed, 15 Jul 2020 13:05:55 -0400 Subject: [PATCH] Fix piston breaking --- .../util/formatting/WorldEditText.java | 57 ++----------------- 1 file changed, 6 insertions(+), 51 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java index 3698ca881..334f7c2d4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/WorldEditText.java @@ -19,73 +19,28 @@ package com.sk89q.worldedit.util.formatting; -import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import org.enginehub.piston.config.Config; import org.enginehub.piston.config.ConfigHolder; +import org.enginehub.piston.config.ConfigRenderer; import org.enginehub.piston.config.TextConfig; import org.enginehub.piston.util.TextHelper; -import java.lang.reflect.Method; -import java.util.List; import java.util.Locale; public class WorldEditText { + private static final ConfigRenderer RENDERER = ConfigRenderer.getInstance(); public static final ConfigHolder CONFIG_HOLDER = ConfigHolder.create(); - private static final Method METHOD_APPLY; static { CONFIG_HOLDER.getConfig(TextConfig.commandPrefix()).setValue("/"); - try { - METHOD_APPLY = Config.class.getDeclaredMethod("apply", List.class); - METHOD_APPLY.setAccessible(true); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } } public static Component format(Component component, Locale locale) { - return CONFIG_HOLDER.replace(WorldEdit.getInstance().getTranslationManager().convertText(recursiveReplace(component), locale)); - } - - private static Component recursiveReplace(Component input) { - if (input instanceof TranslatableComponent) { - TranslatableComponent tc = (TranslatableComponent)input; - List args = tc.args(); - if (args != (args = replaceChildren(args))) { - input = tc = tc.args(args); - } - if (CONFIG_HOLDER.getConfigs().containsKey(tc.key())) { - Config config = CONFIG_HOLDER.getConfigs().get(tc.key()); - try { - return (Component) METHOD_APPLY.invoke(config, replaceChildren(tc.args())); - } catch (Throwable e) { - e.printStackTrace(); - } - } - } - List original = input.children(); - List replacement = replaceChildren(original); - return original == replacement ? input : input.children(replacement); - } - - private static List replaceChildren(List input) { - if (input.isEmpty()) { - return input; - } - ImmutableList.Builder copy = ImmutableList.builder(); - boolean modified = false; - for (Component component : input) { - Component replacement = recursiveReplace(component); - if (replacement != component) { - modified = true; - } - copy.add(replacement); - } - return modified ? copy.build() : input; + return WorldEdit.getInstance().getTranslationManager().convertText( + RENDERER.render(component, CONFIG_HOLDER), + locale + ); } public static String reduceToText(Component component, Locale locale) {