Forráskód Böngészése

table character size is set by snuvi script, bugfix

Kajetan Johannes Hammerle 3 éve
szülő
commit
84eedd87ec

+ 25 - 14
src/main/java/me/km/snuviscript/commands/PlotCommands.java

@@ -24,9 +24,12 @@ public class PlotCommands {
             PlotMap.Plot p = (PlotMap.Plot) in[0].get(sc);
             p.setFlag(in[1].getInt(sc), in[2].getBoolean(sc));
         });
-        sm.registerFunction("plot.hasflags", (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).hasFlags(in[1].getInt(sc)));
-        sm.registerFunction("plot.getflags", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getFlags());
-        sm.registerFunction("plot.getowners", (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).getOwners());
+        sm.registerFunction("plot.hasflags",
+                (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).hasFlags(in[1].getInt(sc)));
+        sm.registerFunction("plot.getflags",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getFlags());
+        sm.registerFunction("plot.getowners",
+                (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).getOwners());
         sm.registerFunction("plot.add", (sc, in) -> {
             Location l1 = (Location) in[0].get(sc);
             Location l2 = (Location) in[1].get(sc);
@@ -42,22 +45,30 @@ public class PlotCommands {
         sm.registerConsumer("plot.setname", (sc, in) -> {
             ((PlotMap.Plot) in[0].get(sc)).setName(in[1].getString(sc));
         });
-        sm.registerFunction("plot.getid", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getId());
+        sm.registerFunction("plot.getid",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getId());
         sm.registerFunction("plot.iterator", (sc, in) -> {
             World word = (World) in[0].get(sc);
             if(in.length >= 2) {
-                plots.getIterator(word, CommandUtils.getUUID(in[1].get(sc)));
+                return plots.getIterator(word, CommandUtils.getUUID(in[1].get(sc)));
             }
             return plots.getIterator(word);
         });
-        sm.registerFunction("plot.intersecting", (sc, in) -> plots.getIntersectingPlots((World) in[0].get(sc), in[1].getInt(sc),
-                in[2].getInt(sc), in[3].getInt(sc), in[4].getInt(sc),
-                in[5].getInt(sc), in[6].getInt(sc)));
-        sm.registerFunction("plot.getminx", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinX());
-        sm.registerFunction("plot.getminy", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinY());
-        sm.registerFunction("plot.getminz", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinZ());
-        sm.registerFunction("plot.getmaxx", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxX());
-        sm.registerFunction("plot.getmaxy", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxY());
-        sm.registerFunction("plot.getmaxz", (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxZ());
+        sm.registerFunction("plot.intersecting",
+                (sc, in) -> plots.getIntersectingPlots((World) in[0].get(sc), in[1].getInt(sc),
+                        in[2].getInt(sc), in[3].getInt(sc), in[4].getInt(sc), in[5].getInt(sc),
+                        in[6].getInt(sc)));
+        sm.registerFunction("plot.getminx",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinX());
+        sm.registerFunction("plot.getminy",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinY());
+        sm.registerFunction("plot.getminz",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinZ());
+        sm.registerFunction("plot.getmaxx",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxX());
+        sm.registerFunction("plot.getmaxy",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxY());
+        sm.registerFunction("plot.getmaxz",
+                (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxZ());
     }
 }

+ 3 - 0
src/main/java/me/km/snuviscript/commands/TableCommands.java

@@ -28,5 +28,8 @@ public class TableCommands {
             }
             return ((Table) in[0].get(sc)).get(columns);
         });
+        sm.registerConsumer("table.setsize", (sc, in) -> {
+            Table.addSizeMapping(in[0].getString(sc).charAt(0), in[1].getInt(sc));
+        });
     }
 }

+ 2 - 1
src/main/java/me/km/utils/LocationIterator.java

@@ -15,7 +15,8 @@ public class LocationIterator implements Iterator<Location> {
     private int y;
     private int z;
 
-    public LocationIterator(World world, int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
+    public LocationIterator(World world, int minX, int minY, int minZ, int maxX, int maxY,
+            int maxZ) {
         this.minX = minX;
         this.minY = minY;
         this.maxX = maxX;

+ 9 - 27
src/main/java/me/km/utils/Table.java

@@ -1,6 +1,14 @@
 package me.km.utils;
 
+import java.util.HashMap;
+
 public class Table {
+    private final static HashMap<Character, Integer> SIZE = new HashMap<>();
+
+    public static void addSizeMapping(char c, int size) {
+        SIZE.put(c, size);
+    }
+
     private final String color;
     private final int[] widths;
 
@@ -44,32 +52,6 @@ public class Table {
         return sb.toString();
     }
 
-    private int getCharWidth(char c) {
-        switch(c) {
-            case 'f':
-            case 'k':
-                return 5;
-            case 'I':
-            case 't':
-            case ' ':
-            case '[':
-            case ']':
-            case '{':
-            case '}':
-            case '(':
-            case ')':
-                return 4;
-            case 'l':
-                return 3;
-            case ';':
-            case ',':
-            case '.':
-            case 'i':
-                return 2;
-        }
-        return 6;
-    }
-
     private String shorten(String s, int max) {
         int sum = 0;
         int fat = 0;
@@ -90,7 +72,7 @@ public class Table {
                 }
                 continue;
             }
-            int width = getCharWidth(c) + fat;
+            int width = SIZE.getOrDefault(c, 6) + fat;
             if(sum + width > max) {
                 break;
             }