Fixes #419 , among other things

This commit is contained in:
boy0001 2015-07-17 20:48:13 +10:00
parent 1564b58a3d
commit b2fbd74d4b
15 changed files with 226 additions and 141 deletions

View File

@ -68,6 +68,7 @@ import com.intellectualcrafters.plot.util.InventoryUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.PlayerManager; import com.intellectualcrafters.plot.util.PlayerManager;
import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler; import com.intellectualcrafters.plot.util.bukkit.BukkitEconHandler;
@ -175,10 +176,9 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
if (message == null) { if (message == null) {
return; return;
} }
message = message.replaceAll("\u00B2", "2");
if (THIS != null && Bukkit.getServer().getConsoleSender() != null) { if (THIS != null && Bukkit.getServer().getConsoleSender() != null) {
try { try {
message = ChatColor.translateAlternateColorCodes('&', message); message = C.color(message);
if (!Settings.CONSOLE_COLOR) { if (!Settings.CONSOLE_COLOR) {
message = ChatColor.stripColor(message); message = ChatColor.stripColor(message);
} }

View File

@ -68,11 +68,9 @@ public class DebugExec extends SubCommand {
@Override @Override
public void run() { public void run() {
List<Double> result = new ArrayList<>(); 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.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.faces * 100) / 100d);
result.add(Math.round(value.data * 100) / 100d);
result.add(Math.round(value.air * 100) / 100d); result.add(Math.round(value.air * 100) / 100d);
result.add(Math.round(value.variety * 100) / 100d); result.add(Math.round(value.variety * 100) / 100d);
Flag flag = new Flag(FlagManager.getFlag("analysis"), result); Flag flag = new Flag(FlagManager.getFlag("analysis"), result);

View File

@ -88,7 +88,7 @@ public class MainCommand {
final int start = page * perPage; final int start = page * perPage;
for (int x = start; x < max; x++) { for (int x = start; x < max; x++) {
cmd = commands.get(x); cmd = commands.get(x);
String s = t(C.HELP_ITEM.s()); String s = C.HELP_ITEM.s();
if (cmd.alias.size() > 0) { if (cmd.alias.size() > 0) {
s = s.replace("%alias%", cmd.alias.get(0)); s = s.replace("%alias%", cmd.alias.get(0));
} }
@ -99,15 +99,11 @@ public class MainCommand {
help.add(s); help.add(s);
} }
if (help.size() < 2) { if (help.size() < 2) {
help.add(t(C.NO_COMMANDS.s())); help.add(C.NO_COMMANDS.s());
} }
return help; 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) { 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")))) { if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
if (args.length < 2) { if (args.length < 2) {

View File

@ -225,6 +225,7 @@ public class Set extends SubCommand {
if (component.equalsIgnoreCase(args[0])) { if (component.equalsIgnoreCase(args[0])) {
if (!Permissions.hasPermission(plr, "plots.set." + component)) { if (!Permissions.hasPermission(plr, "plots.set." + component)) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component); MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component);
return false;
} }
PlotBlock[] blocks; PlotBlock[] blocks;
try { try {
@ -313,7 +314,7 @@ public class Set extends SubCommand {
} }
private String getString(final String s) { 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) { private String getArgumentList(final List<String> newValues) {
@ -326,7 +327,7 @@ public class Set extends SubCommand {
private String getBiomeList(final String[] biomes) { private String getBiomeList(final String[] biomes) {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
builder.append(MainUtil.colorise('&', C.NEED_BIOME.s())); builder.append(C.NEED_BIOME.s());
for (final String b : biomes) { for (final String b : biomes) {
builder.append(getString(b)); builder.append(getString(b));
} }

View File

@ -523,7 +523,7 @@ public class list extends SubCommand {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
String prefix = ""; String prefix = "";
for (final String s : strings) { for (final String s : strings) {
builder.append(prefix + MainUtil.colorise('&', s)); builder.append(prefix + s);
prefix = " | "; prefix = " | ";
} }
return builder.toString(); return builder.toString();

View File

@ -24,12 +24,15 @@ import com.intellectualcrafters.configuration.ConfigurationSection;
import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.configuration.file.YamlConfiguration;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import org.apache.commons.lang.StringEscapeUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.io.File; import java.io.File;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
@ -543,20 +546,34 @@ public enum C {
this(d, true, cat.toLowerCase()); this(d, true, cat.toLowerCase());
} }
public static String format(C c, Object... args) { public static String format(String m, Object... args) {
String m = c.s; if (args.length == 0) {
return m;
}
Map<String, String> map = new HashMap<String, String>();
if (args.length > 0) {
for (int i = args.length - 1 ; i >= 0; i--) { for (int i = args.length - 1 ; i >= 0; i--) {
if (args[i] == null) { if (args[i] == null) {
continue; args[i] = "";
} }
m = m.replaceAll("%s" + i, args[i].toString()); map.put("%s" + i, args[i].toString());
} }
if (args.length > 0) { map.put("%s", args[0].toString());
m = m.replaceAll("%s", args[0].toString());
} }
map.putAll(replacements);
m = StringMan.replaceFromMap(m, map);
return m; 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) { public static void load(File file) {
try { try {
if (!file.exists()) { if (!file.exists()) {

View File

@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
@ -43,47 +44,6 @@ public class BukkitHybridUtils extends HybridUtils {
public int task; public int task;
private long last; 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 @Override
public void analyzePlot(Plot plot, final RunnableVal<PlotAnalysis> whenDone) { public void analyzePlot(Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
// TODO Auto-generated method stub // 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); short[][] result = gen.generateExtBlockSections(world, r, chunk.getX(), chunk.getZ(), base);
int X = chunk.getX(); int X = chunk.getX();
int Z = chunk.getZ(); int Z = chunk.getZ();
int xb = ((X - cbx) << 4) - bx; int xb = ((X) << 4) - bx;
int zb = ((Z - cbz) << 4) - bz; int zb = ((Z) << 4) - bz;
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
if (result[i] == null) { if (result[i] == null) {
for (int j = 0; j < 4096; j++) { for (int j = 0; j < 4096; j++) {
@ -192,14 +152,13 @@ public class BukkitHybridUtils extends HybridUtils {
else { else {
// check verticies // check verticies
// modifications_adjacent // modifications_adjacent
if (x > 0 && z > 0 && y > 0 && x < width - 1 && z < length - 1 && y < 255) { 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 (newblocks[y - 1][x][z] == 0) faces[i]++;
if (oldblocks[y][x - 1][z] == 0) faces[i]++; if (newblocks[y][x - 1][z] == 0) faces[i]++;
if (oldblocks[y][x][z - 1] == 0) faces[i]++; if (newblocks[y][x][z - 1] == 0) faces[i]++;
if (oldblocks[y + 1][x][z] == 0) faces[i]++; if (newblocks[y + 1][x][z] == 0) faces[i]++;
if (oldblocks[y][x + 1][z] == 0) faces[i]++; if (newblocks[y][x + 1][z] == 0) faces[i]++;
if (oldblocks[y][x][z + 1] == 0) faces[i]++; if (newblocks[y][x][z + 1] == 0) faces[i]++;
} }
Material material = Material.getMaterial(now); Material material = Material.getMaterial(now);
@ -223,12 +182,18 @@ public class BukkitHybridUtils extends HybridUtils {
// run whenDone // run whenDone
PlotAnalysis analysis = new PlotAnalysis(); PlotAnalysis analysis = new PlotAnalysis();
analysis.changes = getMean(changes); analysis.changes = MathMan.getMean(changes);
analysis.faces = getMean(faces); analysis.faces = MathMan.getMean(faces);
analysis.data = getMean(data); analysis.data = MathMan.getMean(data);
analysis.air = getMean(air); analysis.air = MathMan.getMean(air);
analysis.variety = getMean(variety); analysis.variety = MathMan.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.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.value = analysis;
whenDone.run(); whenDone.run();
} }
@ -252,22 +217,27 @@ public class BukkitHybridUtils extends HybridUtils {
processed_chunks.add(chunk); processed_chunks.add(chunk);
int X = chunk.getX(); int X = chunk.getX();
int Z = chunk.getZ(); int Z = chunk.getZ();
short[][] current = new short[16][];
int minX; int minX;
int minZ; int minZ;
int maxX; int maxX;
int maxZ; int maxZ;
if (X == cbx) minX = mod(bx); if (X == cbx) minX = MathMan.mod(bx);
else minX = 0; else minX = 0;
if (Z == cbz) minZ = mod(bz); if (Z == cbz) minZ = MathMan.mod(bz);
else minZ = 0; else minZ = 0;
if (X == ctx) maxX = mod(tx); if (X == ctx) maxX = MathMan.mod(tx);
else maxX = 16; else maxX = 16;
if (Z == ctz) maxZ = mod(tz); if (Z == ctz) maxZ = MathMan.mod(tz);
else maxZ = 16; else maxZ = 16;
int xb = ((X - cbx) << 4) - bx; System.out.print("VALUES ====================");
int zb = ((Z - cbz) << 4) - bz; 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 x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) { for (int z = minZ; z <= maxZ; z++) {

View File

@ -77,7 +77,6 @@ public class WEListener implements Listener {
return max; return max;
} }
catch (NumberFormatException e) { catch (NumberFormatException e) {
e.printStackTrace();
return 0; return 0;
} }
} }

View File

@ -24,12 +24,16 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import sun.awt.SunHints.Value;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
@ -260,6 +264,18 @@ public class Plot implements Cloneable {
MainUtil.clear(this, false, whenDone); 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 * Delete a plot
* @see PS#removePlot(String, PlotId, boolean) * @see PS#removePlot(String, PlotId, boolean)

View File

@ -1,5 +1,12 @@
package com.intellectualcrafters.plot.object; 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 class PlotAnalysis {
public double changes; public double changes;
public double faces; public double faces;
@ -7,4 +14,43 @@ public class PlotAnalysis {
public double air; public double air;
public double variety; public double variety;
public double complexity; 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) {
}
} }

View File

@ -15,6 +15,7 @@ public class Rating {
private HashMap<String, Integer> ratingMap; private HashMap<String, Integer> ratingMap;
public Rating(int value) { public Rating(int value) {
ratingMap = new HashMap<>();
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) { if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) { for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1); ratingMap.put(Settings.RATING_CATEGORIES.get(i), (value % 10) - 1);

View File

@ -1309,17 +1309,6 @@ public class MainUtil {
return sendMessage(plr, msg, true); 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) { public static void sendConsoleMessage(String msg) {
sendMessage(null, msg); sendMessage(null, msg);
} }
@ -1329,13 +1318,11 @@ public class MainUtil {
} }
public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) { 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 ((msg.length() > 0) && !msg.equals("")) {
if (plr == null) { if (plr == null) {
PS.log(prefixStr + msg); PS.log(C.PREFIX.s() + msg);
} else { } else {
sendMessageWrapped(plr, prefixStr + msg); plr.sendMessage(C.PREFIX.s() + C.color(msg));
} }
} }
return true; return true;
@ -1408,27 +1395,6 @@ public class MainUtil {
return lines.toArray(new String[lines.size()]); 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 * Send a message to the player
* *
@ -1441,14 +1407,10 @@ public class MainUtil {
if (c.s().length() > 1) { if (c.s().length() > 1) {
String msg = c.s(); String msg = c.s();
if ((args != null) && (args.length > 0)) { if ((args != null) && (args.length > 0)) {
for (final String str : args) { msg = C.format(c, args);
if (msg.contains("%s")) {
msg = msg.replaceFirst("%s", str);
}
}
} }
if (plr == null) { if (plr == null) {
PS.log(colorise('&', msg)); PS.log(msg);
} else { } else {
sendMessage(plr, msg, c.usePrefix()); sendMessage(plr, msg, c.usePrefix());
} }

View File

@ -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;
}
}

View File

@ -1,16 +1,35 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public class StringMan { public class StringMan {
public static String replaceFromMap(String string, Map<String, String> replacements) { public static String replaceFromMap(String string, Map<String, String> replacements) {
StringBuilder sb = new StringBuilder(string); StringBuilder sb = new StringBuilder(string);
int size = string.length();
for (Entry<String, String> entry : replacements.entrySet()) { for (Entry<String, String> entry : replacements.entrySet()) {
if (size == 0) {
break;
}
String key = entry.getKey(); String key = entry.getKey();
String value = entry.getValue(); 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); int start = sb.indexOf(key, 0);
while (start > -1) { while (start > -1) {
int end = start + key.length(); int end = start + key.length();
@ -21,12 +40,4 @@ public class StringMan {
} }
return sb.toString(); 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);
}
} }

View File

@ -15,12 +15,18 @@ commands:
permission: plots.use permission: plots.use
permission-message: "You are lacking the permission node 'plots.use'" permission-message: "You are lacking the permission node 'plots.use'"
permissions: permissions:
plots.use: plotsquared_user_attributes:
default: true default: false
plotsquared_user_attributes.disabletitles:
default: false
plotsquared_user_attributes.*:
default: false
plots.admin: plots.admin:
children: children:
plots.*: true plots.*: true
default: op default: op
plots.use:
default: true
plots.permpack.basicflags: plots.permpack.basicflags:
default: op default: op
children: children: