Kajetan Johannes Hammerle 3 жил өмнө
parent
commit
e255538e8e

+ 22 - 18
src/main/java/me/km/snuviscript/commands/TextCommands.java

@@ -16,46 +16,50 @@ public class TextCommands {
         sm.registerFunction("text.item", (sc, in) -> ((ItemStack) in[0].get(sc)).write(new CompoundNBT()).toString());
         sm.registerFunction("text.click", (sc, in) -> {
             Object message = in[0].get(sc);
-            ITextComponent text;
-            if(message instanceof ITextComponent) {
-                text = (ITextComponent) message;
+            IFormattableTextComponent text;
+            if(message instanceof IFormattableTextComponent) {
+                text = (IFormattableTextComponent) message;
             } else {
                 text = new StringTextComponent(String.valueOf(message));
             }
-            Style style = text.getStyle();
-            style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, in[1].getString(sc)));
+            text.modifyStyle(style -> {
+                return style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, in[1].getString(sc)));
+            });
             return text;
         });
         sm.registerFunction("text.hover", (sc, in) -> {
             Object message = in[0].get(sc);
-            ITextComponent text;
-            if(message instanceof ITextComponent) {
-                text = (ITextComponent) message;
+            IFormattableTextComponent text;
+            if(message instanceof IFormattableTextComponent) {
+                text = (IFormattableTextComponent) message;
             } else {
                 text = new StringTextComponent(String.valueOf(message));
             }
-            Style style = text.getStyle();
-            style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent(in[1].getString(sc))));
+            text.modifyStyle(style -> {
+                return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new StringTextComponent(in[1].getString(sc))));
+            });
             return text;
         });
         sm.registerFunction("text.link", (sc, in) -> {
             StringTextComponent text = new StringTextComponent(in[0].getString(sc));
-            Style style = text.getStyle();
-            style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, in[1].getString(sc)));
+            text.modifyStyle(style -> {
+                return style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, in[1].getString(sc)));
+            });
             return text;
         });
         sm.registerFunction("text.clipboard", (sc, in) -> {
             StringTextComponent text = new StringTextComponent(in[0].getString(sc));
-            Style style = text.getStyle();
-            style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, in[1].getString(sc)));
+            text.modifyStyle(style -> {
+                return style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, in[1].getString(sc)));
+            });
             return text;
         });
         sm.registerFunction("text.copytext", (sc, in) -> {
-            String s = in[1].getString(sc);
-            s = s.replace(" ", "%20");
+            String s = in[1].getString(sc).replace(" ", "%20");
             StringTextComponent text = new StringTextComponent(in[0].getString(sc));
-            Style style = text.getStyle();
-            style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://minecraft.hammerle.me/showtext.php/?text=" + s));
+            text.modifyStyle(style -> {
+                return style.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "http://minecraft.hammerle.me/showtext.php/?text=" + s));
+            });
             return text;
         });
         sm.registerFunction("text.entity", (sc, in) -> {