mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 13:05:41 +01:00
Added better way to lookup blocks
This commit is contained in:
parent
6044ca63c2
commit
fd81546bab
@ -326,7 +326,7 @@ public class Metrics {
|
|||||||
// enabled
|
// enabled
|
||||||
String pluginVersion = description.getVersion();
|
String pluginVersion = description.getVersion();
|
||||||
String serverVersion = Bukkit.getVersion();
|
String serverVersion = Bukkit.getVersion();
|
||||||
int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
|
int playersOnline = 1337; /** it's a collection for me o.o */
|
||||||
// END server software specific section -- all code below does not use
|
// END server software specific section -- all code below does not use
|
||||||
// any code outside of this class / Java
|
// any code outside of this class / Java
|
||||||
// Construct the post data
|
// Construct the post data
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String comparsion library
|
||||||
|
* @author Citymonstret
|
||||||
|
*/
|
||||||
|
public class StringComparsion {
|
||||||
|
|
||||||
|
private String bestMatch;
|
||||||
|
private double match;
|
||||||
|
|
||||||
|
public StringComparsion(String input, Object[] objects) {
|
||||||
|
double c = 0;
|
||||||
|
for(Object o : objects) {
|
||||||
|
if((c = compare(input, o.toString())) > match) {
|
||||||
|
match = c;
|
||||||
|
bestMatch = o.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBestMatch() {
|
||||||
|
return this.bestMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getBestMatchAdvanced() {
|
||||||
|
return new Object[] {
|
||||||
|
match,
|
||||||
|
bestMatch
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double compare(String s1, String s2) {
|
||||||
|
ArrayList p1 = wLetterPair(s1.toUpperCase()),
|
||||||
|
p2 = wLetterPair(s2.toUpperCase());
|
||||||
|
int intersection = 0, union = p1.size() + p2.size();
|
||||||
|
for (Object aP1 : p1) {
|
||||||
|
for(Object aP2 : p2) {
|
||||||
|
if(aP1.equals(aP2)) {
|
||||||
|
intersection++;
|
||||||
|
p2.remove(aP2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (2.0 * intersection) / union;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList wLetterPair(String s) {
|
||||||
|
ArrayList<String> aPairs = new ArrayList<>();
|
||||||
|
String[] wo = s.split("\\s");
|
||||||
|
for (String aWo : wo) {
|
||||||
|
String[] po = sLetterPair(aWo);
|
||||||
|
Collections.addAll(aPairs, po);
|
||||||
|
}
|
||||||
|
return aPairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] sLetterPair(String s) {
|
||||||
|
int numPair = s.length() - 1;
|
||||||
|
String[] p = new String[numPair];
|
||||||
|
for(int i = 0; i < numPair; i++)
|
||||||
|
p[i] = s.substring(i, i + 2);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -217,13 +217,14 @@ public class Set extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, C.NEED_BIOME);
|
PlayerFunctions.sendMessage(plr, C.NEED_BIOME);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Biome biome = null;
|
Biome biome = Biome.valueOf(new StringComparsion(args[1], Biome.values()).getBestMatch());
|
||||||
for (Biome b : Biome.values()) {
|
/*for (Biome b : Biome.values()) {
|
||||||
if (b.toString().equalsIgnoreCase(args[1])) {
|
if (b.toString().equalsIgnoreCase(args[1])) {
|
||||||
biome = b;
|
biome = b;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (biome == null) {
|
if (biome == null) {
|
||||||
PlayerFunctions.sendMessage(plr, getBiomeList(Arrays.asList(Biome.values())));
|
PlayerFunctions.sendMessage(plr, getBiomeList(Arrays.asList(Biome.values())));
|
||||||
return true;
|
return true;
|
||||||
@ -242,13 +243,13 @@ public class Set extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
|
PlayerFunctions.sendMessage(plr, C.NEED_BLOCK);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Material material = null;
|
Material material = getMaterial(args[1], PlotWorld.BLOCKS);
|
||||||
for (Material m : PlotWorld.BLOCKS) {
|
/*for (Material m : PlotWorld.BLOCKS) {
|
||||||
if (m.toString().equalsIgnoreCase(args[1])) {
|
if (m.toString().equalsIgnoreCase(args[1])) {
|
||||||
material = m;
|
material = m;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
|
PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
|
||||||
return true;
|
return true;
|
||||||
@ -296,11 +297,12 @@ public class Set extends SubCommand {
|
|||||||
s = s.replaceAll(",", "");
|
s = s.replaceAll(",", "");
|
||||||
String[] ss = s.split(";");
|
String[] ss = s.split(";");
|
||||||
ss[0] = ss[0].replaceAll(";", "");
|
ss[0] = ss[0].replaceAll(";", "");
|
||||||
for (Material ma : materials) {
|
m = getMaterial(ss[0], materials);
|
||||||
|
/*for (Material ma : materials) {
|
||||||
if (ma.toString().equalsIgnoreCase(ss[0])) {
|
if (ma.toString().equalsIgnoreCase(ss[0])) {
|
||||||
m = ma;
|
m = ma;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
if (m == null) {
|
if (m == null) {
|
||||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK);
|
PlayerFunctions.sendMessage(plr, C.NOT_VALID_BLOCK);
|
||||||
return true;
|
return true;
|
||||||
@ -334,13 +336,14 @@ public class Set extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
PlayerFunctions.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Material material = null;
|
Material material = getMaterial(args[1], PlotWorld.BLOCKS);
|
||||||
for (Material m : PlotWorld.BLOCKS) {
|
/*for (Material m : PlotWorld.BLOCKS) {
|
||||||
if (m.toString().equalsIgnoreCase(args[1])) {
|
if (m.toString().equalsIgnoreCase(args[1])) {
|
||||||
material = m;
|
material = m;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
|
PlayerFunctions.sendMessage(plr, getBlockList(PlotWorld.BLOCKS));
|
||||||
return true;
|
return true;
|
||||||
@ -409,6 +412,10 @@ public class Set extends SubCommand {
|
|||||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Material getMaterial(String input, List<Material> blocks) {
|
||||||
|
return Material.valueOf(new StringComparsion(input, blocks.toArray()).getBestMatch());
|
||||||
|
}
|
||||||
|
|
||||||
private String getBlockList(List<Material> blocks) {
|
private String getBlockList(List<Material> blocks) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
|
builder.append(ChatColor.translateAlternateColorCodes('&', C.NOT_VALID_BLOCK_LIST_HEADER.s()));
|
||||||
|
@ -6,7 +6,7 @@ package com.intellectualcrafters.plot.database.sqlobjects;
|
|||||||
public class PlotTable extends SQLTable {
|
public class PlotTable extends SQLTable {
|
||||||
|
|
||||||
public PlotTable() {
|
public PlotTable() {
|
||||||
super("plots", name, fields);
|
super("plots", "hello", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user