mirror of
				https://github.com/IntellectualSites/PlotSquared.git
				synced 2025-11-04 03:03:43 +01:00 
			
		
		
		
	Fixes #419 , among other things
This commit is contained in:
		@@ -68,6 +68,7 @@ import com.intellectualcrafters.plot.util.InventoryUtil;
 | 
			
		||||
import com.intellectualcrafters.plot.util.MainUtil;
 | 
			
		||||
import com.intellectualcrafters.plot.util.PlayerManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.SetupUtils;
 | 
			
		||||
import com.intellectualcrafters.plot.util.StringMan;
 | 
			
		||||
import com.intellectualcrafters.plot.util.TaskManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler;
 | 
			
		||||
@@ -175,10 +176,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
 | 
			
		||||
        if (message == null) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        message = message.replaceAll("\u00B2", "2");
 | 
			
		||||
        if (THIS != null && Bukkit.getServer().getConsoleSender() != null) {
 | 
			
		||||
            try {
 | 
			
		||||
                message = ChatColor.translateAlternateColorCodes('&', message);
 | 
			
		||||
                message = C.color(message);
 | 
			
		||||
                if (!Settings.CONSOLE_COLOR) {
 | 
			
		||||
                    message = ChatColor.stripColor(message);
 | 
			
		||||
                }
 | 
			
		||||
 
 | 
			
		||||
@@ -68,11 +68,9 @@ public class DebugExec extends SubCommand {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void run() {
 | 
			
		||||
                            List<Double> result = new ArrayList<>();
 | 
			
		||||
                            result.add(Math.round(value.air * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.changes * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.complexity * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.data * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.faces * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.data * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.air * 100) / 100d);
 | 
			
		||||
                            result.add(Math.round(value.variety * 100) / 100d);
 | 
			
		||||
                            Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
 | 
			
		||||
 
 | 
			
		||||
@@ -88,7 +88,7 @@ public class MainCommand {
 | 
			
		||||
        final int start = page * perPage;
 | 
			
		||||
        for (int x = start; x < max; x++) {
 | 
			
		||||
            cmd = commands.get(x);
 | 
			
		||||
            String s = t(C.HELP_ITEM.s());
 | 
			
		||||
            String s = C.HELP_ITEM.s();
 | 
			
		||||
            if (cmd.alias.size() > 0) {
 | 
			
		||||
                s = s.replace("%alias%", cmd.alias.get(0));
 | 
			
		||||
            }
 | 
			
		||||
@@ -99,14 +99,10 @@ public class MainCommand {
 | 
			
		||||
            help.add(s);
 | 
			
		||||
        }
 | 
			
		||||
        if (help.size() < 2) {
 | 
			
		||||
            help.add(t(C.NO_COMMANDS.s()));
 | 
			
		||||
            help.add(C.NO_COMMANDS.s());
 | 
			
		||||
        }
 | 
			
		||||
        return help;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static String t(final String s) {
 | 
			
		||||
        return MainUtil.colorise('&', s);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
 | 
			
		||||
        if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
 | 
			
		||||
 
 | 
			
		||||
@@ -225,6 +225,7 @@ public class Set extends SubCommand {
 | 
			
		||||
            if (component.equalsIgnoreCase(args[0])) {
 | 
			
		||||
                if (!Permissions.hasPermission(plr, "plots.set." + component)) {
 | 
			
		||||
                    MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component);
 | 
			
		||||
                    return false;
 | 
			
		||||
                }
 | 
			
		||||
                PlotBlock[] blocks;
 | 
			
		||||
                try {
 | 
			
		||||
@@ -313,7 +314,7 @@ public class Set extends SubCommand {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getString(final String s) {
 | 
			
		||||
        return MainUtil.colorise('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
 | 
			
		||||
        return StringMan.replaceAll(C.BLOCK_LIST_ITEM.s(), "%mat%", s);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String getArgumentList(final List<String> newValues) {
 | 
			
		||||
@@ -326,7 +327,7 @@ public class Set extends SubCommand {
 | 
			
		||||
 | 
			
		||||
    private String getBiomeList(final String[] biomes) {
 | 
			
		||||
        final StringBuilder builder = new StringBuilder();
 | 
			
		||||
        builder.append(MainUtil.colorise('&', C.NEED_BIOME.s()));
 | 
			
		||||
        builder.append(C.NEED_BIOME.s());
 | 
			
		||||
        for (final String b : biomes) {
 | 
			
		||||
            builder.append(getString(b));
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -523,7 +523,7 @@ public class list extends SubCommand {
 | 
			
		||||
        final StringBuilder builder = new StringBuilder();
 | 
			
		||||
        String prefix = "";
 | 
			
		||||
        for (final String s : strings) {
 | 
			
		||||
            builder.append(prefix + MainUtil.colorise('&', s));
 | 
			
		||||
            builder.append(prefix + s);
 | 
			
		||||
            prefix = " | ";
 | 
			
		||||
        }
 | 
			
		||||
        return builder.toString();
 | 
			
		||||
 
 | 
			
		||||
@@ -24,12 +24,15 @@ import com.intellectualcrafters.configuration.ConfigurationSection;
 | 
			
		||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
 | 
			
		||||
import com.intellectualcrafters.plot.PS;
 | 
			
		||||
import com.intellectualcrafters.plot.util.StringMan;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringEscapeUtils;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.util.EnumSet;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -543,20 +546,34 @@ public enum C {
 | 
			
		||||
        this(d, true, cat.toLowerCase());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String format(C c, Object... args) {
 | 
			
		||||
        String m = c.s;
 | 
			
		||||
        for (int i = args.length - 1 ; i >= 0; i--) {
 | 
			
		||||
            if (args[i] == null) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            m = m.replaceAll("%s" + i, args[i].toString());
 | 
			
		||||
    public static String format(String m, Object... args) {
 | 
			
		||||
        if (args.length == 0) {
 | 
			
		||||
            return m;
 | 
			
		||||
        }
 | 
			
		||||
        Map<String, String> map = new HashMap<String, String>();
 | 
			
		||||
        if (args.length > 0) {
 | 
			
		||||
            m = m.replaceAll("%s", args[0].toString());
 | 
			
		||||
            for (int i = args.length - 1 ; i >= 0; i--) {
 | 
			
		||||
                if (args[i] == null) {
 | 
			
		||||
                    args[i] = "";
 | 
			
		||||
                }
 | 
			
		||||
                map.put("%s" + i, args[i].toString());
 | 
			
		||||
            }
 | 
			
		||||
            map.put("%s", args[0].toString());
 | 
			
		||||
        }
 | 
			
		||||
        map.putAll(replacements);
 | 
			
		||||
        m = StringMan.replaceFromMap(m, map);
 | 
			
		||||
        return m;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String format(C c, Object... args) {
 | 
			
		||||
        return format(c.s, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    public static String color(String string) {
 | 
			
		||||
        return StringMan.replaceFromMap(string, replacements);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static void load(File file) {
 | 
			
		||||
        try {
 | 
			
		||||
            if (!file.exists()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
 | 
			
		||||
import com.intellectualcrafters.plot.object.RunnableVal;
 | 
			
		||||
import com.intellectualcrafters.plot.util.ChunkManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.MainUtil;
 | 
			
		||||
import com.intellectualcrafters.plot.util.MathMan;
 | 
			
		||||
import com.intellectualcrafters.plot.util.TaskManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
 | 
			
		||||
 | 
			
		||||
@@ -43,47 +44,6 @@ public class BukkitHybridUtils extends HybridUtils {
 | 
			
		||||
    public int task;
 | 
			
		||||
    private long last;
 | 
			
		||||
    
 | 
			
		||||
    public double getMean(int[] array) {
 | 
			
		||||
        double count = 0;
 | 
			
		||||
        for (int i : array) {
 | 
			
		||||
            count += i;
 | 
			
		||||
        }
 | 
			
		||||
        return count / array.length;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public double getMean(double[] array) {
 | 
			
		||||
        double count = 0;
 | 
			
		||||
        for (double i : array) {
 | 
			
		||||
            count += i;
 | 
			
		||||
        }
 | 
			
		||||
        return count / array.length;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public double getSD(double[] array, double av) {
 | 
			
		||||
        double sd = 0;
 | 
			
		||||
        for (int i=0; i<array.length;i++)
 | 
			
		||||
        {
 | 
			
		||||
            sd += Math.pow(Math.abs(array[i] - av), 2);
 | 
			
		||||
        }
 | 
			
		||||
        return Math.sqrt(sd/array.length);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public double getSD(int[] array, double av) {
 | 
			
		||||
        double sd = 0;
 | 
			
		||||
        for (int i=0; i<array.length;i++)
 | 
			
		||||
        {
 | 
			
		||||
            sd += Math.pow(Math.abs(array[i] - av), 2);
 | 
			
		||||
        }
 | 
			
		||||
        return Math.sqrt(sd/array.length);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public int mod(int x) {
 | 
			
		||||
        if (x < 0) {
 | 
			
		||||
            return (x % 16) + 16;
 | 
			
		||||
        }
 | 
			
		||||
        return x % 16;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    public void analyzePlot(Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
 | 
			
		||||
        // TODO Auto-generated method stub
 | 
			
		||||
@@ -143,8 +103,8 @@ public class BukkitHybridUtils extends HybridUtils {
 | 
			
		||||
                    short[][] result = gen.generateExtBlockSections(world, r, chunk.getX(), chunk.getZ(), base);
 | 
			
		||||
                    int X = chunk.getX();
 | 
			
		||||
                    int Z = chunk.getZ();
 | 
			
		||||
                    int xb = ((X - cbx) << 4) - bx;
 | 
			
		||||
                    int zb = ((Z - cbz) << 4) - bz;
 | 
			
		||||
                    int xb = ((X) << 4) - bx;
 | 
			
		||||
                    int zb = ((Z) << 4) - bz;
 | 
			
		||||
                    for (int i = 0; i < result.length; i++) {
 | 
			
		||||
                        if (result[i] == null) {
 | 
			
		||||
                            for (int j = 0; j < 4096; j++) {
 | 
			
		||||
@@ -192,14 +152,13 @@ public class BukkitHybridUtils extends HybridUtils {
 | 
			
		||||
                            else {
 | 
			
		||||
                                // check verticies
 | 
			
		||||
                                // modifications_adjacent
 | 
			
		||||
 | 
			
		||||
                                if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) {
 | 
			
		||||
                                    if (oldblocks[y - 1][x][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (oldblocks[y][x - 1][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (oldblocks[y][x][z - 1] == 0) faces[i]++;
 | 
			
		||||
                                    if (oldblocks[y + 1][x][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (oldblocks[y][x + 1][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (oldblocks[y][x][z + 1] == 0) faces[i]++;
 | 
			
		||||
                                    if (newblocks[y - 1][x][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (newblocks[y][x - 1][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (newblocks[y][x][z - 1] == 0) faces[i]++;
 | 
			
		||||
                                    if (newblocks[y + 1][x][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (newblocks[y][x + 1][z] == 0) faces[i]++;
 | 
			
		||||
                                    if (newblocks[y][x][z + 1] == 0) faces[i]++;
 | 
			
		||||
                                }
 | 
			
		||||
 | 
			
		||||
                                Material material = Material.getMaterial(now);
 | 
			
		||||
@@ -223,12 +182,18 @@ public class BukkitHybridUtils extends HybridUtils {
 | 
			
		||||
 | 
			
		||||
                // run whenDone
 | 
			
		||||
                PlotAnalysis analysis = new PlotAnalysis();
 | 
			
		||||
                analysis.changes = getMean(changes);
 | 
			
		||||
                analysis.faces = getMean(faces);
 | 
			
		||||
                analysis.data = getMean(data);
 | 
			
		||||
                analysis.air = getMean(air);
 | 
			
		||||
                analysis.variety = getMean(variety);
 | 
			
		||||
                analysis.complexity = getSD(changes, analysis.changes) + getSD(faces, analysis.faces) + getSD(data, analysis.data) + getSD(air, analysis.air) + getSD(variety, analysis.variety);
 | 
			
		||||
                analysis.changes = MathMan.getMean(changes);
 | 
			
		||||
                analysis.faces = MathMan.getMean(faces);
 | 
			
		||||
                analysis.data = MathMan.getMean(data);
 | 
			
		||||
                analysis.air = MathMan.getMean(air);
 | 
			
		||||
                analysis.variety = MathMan.getMean(variety);
 | 
			
		||||
                analysis.complexity =
 | 
			
		||||
                 + (analysis.changes + MathMan.getSD(changes, analysis.changes)) * PlotAnalysis.CHANGES_MODIFIER
 | 
			
		||||
                 + (analysis.faces + MathMan.getSD(changes, analysis.faces)) * PlotAnalysis.FACES_MODIFIER
 | 
			
		||||
                 + (analysis.data + MathMan.getSD(changes, analysis.data)) * PlotAnalysis.DATA_MODIFIER
 | 
			
		||||
                 + (analysis.air + MathMan.getSD(changes, analysis.air)) * PlotAnalysis.AIR_MODIFIER
 | 
			
		||||
                 + (analysis.variety + MathMan.getSD(changes, analysis.variety)) * PlotAnalysis.VARIETY_MODIFIER
 | 
			
		||||
                        ;
 | 
			
		||||
                whenDone.value = analysis;
 | 
			
		||||
                whenDone.run();
 | 
			
		||||
            }
 | 
			
		||||
@@ -252,22 +217,27 @@ public class BukkitHybridUtils extends HybridUtils {
 | 
			
		||||
                processed_chunks.add(chunk);
 | 
			
		||||
                int X = chunk.getX();
 | 
			
		||||
                int Z = chunk.getZ();
 | 
			
		||||
                short[][] current = new short[16][];
 | 
			
		||||
                int minX;
 | 
			
		||||
                int minZ;
 | 
			
		||||
                int maxX;
 | 
			
		||||
                int maxZ;
 | 
			
		||||
                if (X == cbx) minX = mod(bx);
 | 
			
		||||
                if (X == cbx) minX = MathMan.mod(bx);
 | 
			
		||||
                else minX = 0;
 | 
			
		||||
                if (Z == cbz) minZ = mod(bz);
 | 
			
		||||
                if (Z == cbz) minZ = MathMan.mod(bz);
 | 
			
		||||
                else minZ = 0;
 | 
			
		||||
                if (X == ctx) maxX = mod(tx);
 | 
			
		||||
                if (X == ctx) maxX = MathMan.mod(tx);
 | 
			
		||||
                else maxX = 16;
 | 
			
		||||
                if (Z == ctz) maxZ = mod(tz);
 | 
			
		||||
                if (Z == ctz) maxZ = MathMan.mod(tz);
 | 
			
		||||
                else maxZ = 16;
 | 
			
		||||
 | 
			
		||||
                int xb = ((X - cbx) << 4) - bx;
 | 
			
		||||
                int zb = ((Z - cbz) << 4) - bz;
 | 
			
		||||
                System.out.print("VALUES ====================");
 | 
			
		||||
                System.out.print(X + "," + Z + " | " + cbx + "," + cbz + " | " + bx + "," + bz);
 | 
			
		||||
                System.out.print("VALUES ====================");
 | 
			
		||||
                
 | 
			
		||||
                int xb = ((X) << 4) - bx;
 | 
			
		||||
                int zb = ((Z) << 4) - bz;
 | 
			
		||||
                
 | 
			
		||||
                System.out.print(xb + "," + zb + " | " + minX + "," + minZ + " | " + maxX + "," + maxZ);
 | 
			
		||||
 | 
			
		||||
                for (int x = minX; x <= maxX; x++) {
 | 
			
		||||
                    for (int z = minZ; z <= maxZ; z++) {
 | 
			
		||||
 
 | 
			
		||||
@@ -77,7 +77,6 @@ public class WEListener implements Listener {
 | 
			
		||||
            return max;
 | 
			
		||||
        }
 | 
			
		||||
        catch (NumberFormatException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -24,12 +24,16 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import sun.awt.SunHints.Value;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.PS;
 | 
			
		||||
import com.intellectualcrafters.plot.database.DBFunc;
 | 
			
		||||
import com.intellectualcrafters.plot.flag.Flag;
 | 
			
		||||
import com.intellectualcrafters.plot.flag.FlagManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.ChunkManager;
 | 
			
		||||
import com.intellectualcrafters.plot.util.MainUtil;
 | 
			
		||||
 | 
			
		||||
@@ -260,6 +264,18 @@ public class Plot implements Cloneable {
 | 
			
		||||
        MainUtil.clear(this, false, whenDone);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * This will return null if the plot hasn't been analyzed
 | 
			
		||||
     * @return analysis of plot
 | 
			
		||||
     */
 | 
			
		||||
    public PlotAnalysis getComplexity() {
 | 
			
		||||
        return PlotAnalysis.getAnalysis(this);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public void analyze(RunnableVal<PlotAnalysis> whenDone) {
 | 
			
		||||
        PlotAnalysis.analyzePlot(this, whenDone);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * Delete a plot
 | 
			
		||||
     * @see PS#removePlot(String, PlotId, boolean)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,12 @@
 | 
			
		||||
package com.intellectualcrafters.plot.object;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import com.intellectualcrafters.plot.flag.Flag;
 | 
			
		||||
import com.intellectualcrafters.plot.flag.FlagManager;
 | 
			
		||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
 | 
			
		||||
import com.intellectualcrafters.plot.util.TaskManager;
 | 
			
		||||
 | 
			
		||||
public class PlotAnalysis {
 | 
			
		||||
    public double changes;
 | 
			
		||||
    public double faces;
 | 
			
		||||
@@ -7,4 +14,43 @@ public class PlotAnalysis {
 | 
			
		||||
    public double air;
 | 
			
		||||
    public double variety;
 | 
			
		||||
    public double complexity;
 | 
			
		||||
    
 | 
			
		||||
    public static double CHANGES_MODIFIER = 32;
 | 
			
		||||
    public static double FACES_MODIFIER = 32;
 | 
			
		||||
    public static double DATA_MODIFIER = 32;
 | 
			
		||||
    public static double AIR_MODIFIER = 32;
 | 
			
		||||
    public static double VARIETY_MODIFIER = 32;
 | 
			
		||||
    
 | 
			
		||||
    public static PlotAnalysis getAnalysis(Plot plot) {
 | 
			
		||||
        Flag flag = FlagManager.getPlotFlag(plot, "analysis");
 | 
			
		||||
        if (flag != null) {
 | 
			
		||||
            PlotAnalysis analysis = new PlotAnalysis();
 | 
			
		||||
            List<Double> values = (List<Double>) flag.getValue();
 | 
			
		||||
            analysis.changes = values.get(0);
 | 
			
		||||
            analysis.faces = values.get(1);
 | 
			
		||||
            analysis.data = values.get(3);
 | 
			
		||||
            analysis.air = values.get(4);
 | 
			
		||||
            analysis.variety = values.get(5);
 | 
			
		||||
            return analysis;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static void analyzePlot(Plot plot, RunnableVal<PlotAnalysis> whenDone) {
 | 
			
		||||
        PlotAnalysis analysis = getAnalysis(plot);
 | 
			
		||||
        if (analysis != null) {
 | 
			
		||||
            whenDone.value = analysis;
 | 
			
		||||
            whenDone.run();
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        BukkitHybridUtils.manager.analyzePlot(plot, whenDone);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @param whenDone
 | 
			
		||||
     */
 | 
			
		||||
    public static void calcOptimalModifiers(Runnable whenDone) {
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ public class Rating {
 | 
			
		||||
    private HashMap<String, Integer> ratingMap;
 | 
			
		||||
    
 | 
			
		||||
    public Rating(int value) {
 | 
			
		||||
        ratingMap = new HashMap<>();
 | 
			
		||||
        if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
 | 
			
		||||
            for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
 | 
			
		||||
                ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1);
 | 
			
		||||
 
 | 
			
		||||
@@ -1309,17 +1309,6 @@ public class MainUtil {
 | 
			
		||||
        return sendMessage(plr, msg, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String colorise(final char alt, final String message) {
 | 
			
		||||
        final char[] b = message.toCharArray();
 | 
			
		||||
        for (int i = 0; i < (b.length - 1); i++) {
 | 
			
		||||
            if ((b[i] == alt) && ("0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[(i + 1)]) > -1)) {
 | 
			
		||||
                b[i] = '\u00A7';
 | 
			
		||||
                b[(i + 1)] = Character.toLowerCase(b[(i + 1)]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return new String(b);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static void sendConsoleMessage(String msg) {
 | 
			
		||||
        sendMessage(null, msg);
 | 
			
		||||
    }
 | 
			
		||||
@@ -1329,13 +1318,11 @@ public class MainUtil {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) {
 | 
			
		||||
        msg = colorise('&', msg);
 | 
			
		||||
        final String prefixStr = colorise('&', C.PREFIX.s());
 | 
			
		||||
        if ((msg.length() > 0) && !msg.equals("")) {
 | 
			
		||||
            if (plr == null) {
 | 
			
		||||
                PS.log(prefixStr + msg);
 | 
			
		||||
                PS.log(C.PREFIX.s() + msg);
 | 
			
		||||
            } else {
 | 
			
		||||
                sendMessageWrapped(plr, prefixStr + msg);
 | 
			
		||||
                plr.sendMessage(C.PREFIX.s() + C.color(msg));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
@@ -1408,27 +1395,6 @@ public class MainUtil {
 | 
			
		||||
        return lines.toArray(new String[lines.size()]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * \\previous\\
 | 
			
		||||
     *
 | 
			
		||||
     * @param plr
 | 
			
		||||
     * @param msg Was used to wrap the chat client length (Packets out--)
 | 
			
		||||
     */
 | 
			
		||||
    public static void sendMessageWrapped(final PlotPlayer plr, final String msg) {
 | 
			
		||||
        //        if (msg.length() > 65) {
 | 
			
		||||
        //            final String[] ss = wordWrap(msg, 65);
 | 
			
		||||
        //            final StringBuilder b = new StringBuilder();
 | 
			
		||||
        //            for (final String p : ss) {
 | 
			
		||||
        //                b.append(p).append(p.equals(ss[ss.length - 1]) ? "" : "\n ");
 | 
			
		||||
        //            }
 | 
			
		||||
        //            msg = b.toString();
 | 
			
		||||
        //        }
 | 
			
		||||
        //        if (msg.endsWith("\n")) {
 | 
			
		||||
        //            msg = msg.substring(0, msg.length() - 2);
 | 
			
		||||
        //        }
 | 
			
		||||
        plr.sendMessage(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send a message to the player
 | 
			
		||||
     *
 | 
			
		||||
@@ -1441,14 +1407,10 @@ public class MainUtil {
 | 
			
		||||
        if (c.s().length() > 1) {
 | 
			
		||||
            String msg = c.s();
 | 
			
		||||
            if ((args != null) && (args.length > 0)) {
 | 
			
		||||
                for (final String str : args) {
 | 
			
		||||
                    if (msg.contains("%s")) {
 | 
			
		||||
                        msg = msg.replaceFirst("%s", str);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                msg = C.format(c, args);
 | 
			
		||||
            }
 | 
			
		||||
            if (plr == null) {
 | 
			
		||||
                PS.log(colorise('&', msg));
 | 
			
		||||
                PS.log(msg);
 | 
			
		||||
            } else {
 | 
			
		||||
                sendMessage(plr, msg, c.usePrefix());
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,62 @@
 | 
			
		||||
package com.intellectualcrafters.plot.util;
 | 
			
		||||
 | 
			
		||||
public class MathMan {
 | 
			
		||||
    public static double getMean(int[] array) {
 | 
			
		||||
        double count = 0;
 | 
			
		||||
        for (int i : array) {
 | 
			
		||||
            count += i;
 | 
			
		||||
        }
 | 
			
		||||
        return count / array.length;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static double getMean(double[] array) {
 | 
			
		||||
        double count = 0;
 | 
			
		||||
        for (double i : array) {
 | 
			
		||||
            count += i;
 | 
			
		||||
        }
 | 
			
		||||
        return count / array.length;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static double getSD(double[] array, double av) {
 | 
			
		||||
        double sd = 0;
 | 
			
		||||
        for (int i=0; i<array.length;i++)
 | 
			
		||||
        {
 | 
			
		||||
            sd += Math.pow(Math.abs(array[i] - av), 2);
 | 
			
		||||
        }
 | 
			
		||||
        return Math.sqrt(sd/array.length);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static double getSD(int[] array, double av) {
 | 
			
		||||
        double sd = 0;
 | 
			
		||||
        for (int i=0; i<array.length;i++)
 | 
			
		||||
        {
 | 
			
		||||
            sd += Math.pow(Math.abs(array[i] - av), 2);
 | 
			
		||||
        }
 | 
			
		||||
        return Math.sqrt(sd/array.length);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static int mod(int x, int y) {
 | 
			
		||||
        if (isPowerOfTwo(y)) {
 | 
			
		||||
            return x & (y - 1);
 | 
			
		||||
        }
 | 
			
		||||
        return x % y;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static int unsignedmod(int x, int y) {
 | 
			
		||||
        if (isPowerOfTwo(y)) {
 | 
			
		||||
            return x & (y - 1);
 | 
			
		||||
        }
 | 
			
		||||
        return x % y;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static boolean isPowerOfTwo(int x) {
 | 
			
		||||
        return (x & (x - 1)) == 0;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static int mod(int x) {
 | 
			
		||||
        if (x < 0) {
 | 
			
		||||
            return (x % 16) + 16;
 | 
			
		||||
        }
 | 
			
		||||
        return x % 16;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +1,35 @@
 | 
			
		||||
package com.intellectualcrafters.plot.util;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
 | 
			
		||||
public class StringMan {
 | 
			
		||||
    public static String replaceFromMap(String string, Map<String, String> replacements) {
 | 
			
		||||
        StringBuilder sb = new StringBuilder(string);
 | 
			
		||||
        int size = string.length();
 | 
			
		||||
        for (Entry<String, String> entry : replacements.entrySet()) {
 | 
			
		||||
            if (size == 0) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            String key = entry.getKey();
 | 
			
		||||
            String value = entry.getValue();
 | 
			
		||||
 | 
			
		||||
            int start = sb.indexOf(key, 0);
 | 
			
		||||
            while (start > -1) {
 | 
			
		||||
                int end = start + key.length();
 | 
			
		||||
                int nextSearchStart = start + value.length();
 | 
			
		||||
                sb.replace(start, end, value);
 | 
			
		||||
                size -= end - start;
 | 
			
		||||
                start = sb.indexOf(key, nextSearchStart);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return sb.toString();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static String replaceAll(String string, Object... pairs) {
 | 
			
		||||
        StringBuilder sb = new StringBuilder(string);
 | 
			
		||||
        for (int i = 0; i < pairs.length; i+=2) {
 | 
			
		||||
            String key = pairs[i] + "";
 | 
			
		||||
            String value = pairs[i + 1] + "";
 | 
			
		||||
            int start = sb.indexOf(key, 0);
 | 
			
		||||
            while (start > -1) {
 | 
			
		||||
                int end = start + key.length();
 | 
			
		||||
@@ -21,12 +40,4 @@ public class StringMan {
 | 
			
		||||
        }
 | 
			
		||||
        return sb.toString();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static String replaceAll(String string, Object... pairs) {
 | 
			
		||||
        HashMap<String, String> replacements = new HashMap<>();
 | 
			
		||||
        for (int i = 0; i < pairs.length; i+=2) {
 | 
			
		||||
            replacements.put(pairs[i] + "", pairs[i+1] + "");
 | 
			
		||||
        }
 | 
			
		||||
        return replaceFromMap(string, replacements);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user