Fire protection, plot component setting

Fixes #358
This commit is contained in:
boy0001 2015-06-30 05:30:36 +10:00
parent 8b3bc50f6e
commit b526ff4b72
12 changed files with 195 additions and 104 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>2.11.24</version> <version>2.11.25</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -92,13 +92,18 @@ public class DebugExec extends SubCommand {
ExpireManager.task = -1; ExpireManager.task = -1;
return MainUtil.sendMessage(player, "Cancelled task."); return MainUtil.sendMessage(player, "Cancelled task.");
} }
case "reset-modified": { case "remove-flag": {
if (args.length != 2) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec reset-flat <flag>");
return false;
}
String flag = args[1];
for (Plot plot : PlotSquared.getPlots()) { for (Plot plot : PlotSquared.getPlots()) {
if (FlagManager.getPlotFlag(plot, "modified-blocks") != null) { if (FlagManager.getPlotFlag(plot, flag) != null) {
FlagManager.removePlotFlag(plot, "modified-blocks"); FlagManager.removePlotFlag(plot, flag);
} }
} }
return MainUtil.sendMessage(player, "Cleared modified flag!"); return MainUtil.sendMessage(player, "Cleared flag: " + flag);
} }
case "start-rgar": { case "start-rgar": {
if (args.length != 2) { if (args.length != 2) {

View File

@ -33,6 +33,7 @@ import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue.PlotBlockListValue;
import com.intellectualcrafters.plot.listeners.APlotListener; import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
@ -46,6 +47,7 @@ import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
/** /**
@ -238,24 +240,50 @@ public class Set extends SubCommand {
} }
PlotBlock[] blocks; PlotBlock[] blocks;
try { try {
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseString(args[1]); if (args.length < 2) {
} catch (final Exception e) { MainUtil.sendMessage(plr, C.NEED_BLOCK);
try { return true;
if (args.length < 2) {
MainUtil.sendMessage(plr, C.NEED_BLOCK);
return true;
}
blocks = new PlotBlock[] { new PlotBlock((short) BlockManager.manager.getBlockIdFromString(args[1]), (byte) 0) };
for (PlotBlock block : blocks) {
if (!BlockManager.manager.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK);
return false;
}
}
} catch (final Exception e2) {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK);
return false;
} }
// if (!Configuration.BLOCKLIST.validateValue(args[1])) {
// MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, args[1]);
// return false;
// }
String[] split = args[1].split(",");
blocks = Configuration.BLOCKLIST.parseString(args[1]);
for (int i = 0; i < blocks.length; i++) {
PlotBlock block = blocks[i];
if (block == null) {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, split[i]);
String name;
if (split[i].contains("%")) {
name = split[i].split("%")[1];
}
else {
name = split[i];
}
StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
if (match != null) {
name = BlockManager.manager.getClosestMatchingName(match.best);
if (name != null) {
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase());
}
}
return false;
}
else if (!BlockManager.manager.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
}
}
for (PlotBlock block : blocks) {
if (!BlockManager.manager.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
}
}
} catch (final Exception e2) {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, args[1]);
return false;
} }
if (MainUtil.runners.containsKey(plot)) { if (MainUtil.runners.containsKey(plot)) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);

View File

@ -293,7 +293,6 @@ public enum C {
/* /*
* Block List * Block List
*/ */
NOT_VALID_BLOCK_LIST_HEADER("$2That's not a valid block. Valid blocks are:\\n", "Block List"),
BLOCK_LIST_ITEM(" $1%mat%$2,", "Block List"), BLOCK_LIST_ITEM(" $1%mat%$2,", "Block List"),
BLOCK_LIST_SEPARATER("$1,$2 ", "Block List"), BLOCK_LIST_SEPARATER("$1,$2 ", "Block List"),
/* /*
@ -322,7 +321,8 @@ public enum C {
* Invalid * Invalid
*/ */
NOT_VALID_DATA("$2That's not a valid data id.", "Invalid"), NOT_VALID_DATA("$2That's not a valid data id.", "Invalid"),
NOT_VALID_BLOCK("$2That's not a valid block.", "Invalid"), NOT_VALID_BLOCK("$2That's not a valid block: %s", "Invalid"),
NOT_ALLOWED_BLOCK("$2That block is not allowed: %s", "Invalid"),
NOT_VALID_NUMBER("$2That's not a valid number within the range: %s", "Invalid"), NOT_VALID_NUMBER("$2That's not a valid number within the range: %s", "Invalid"),
NOT_VALID_PLOT_ID("$2That's not a valid plot id.", "Invalid"), NOT_VALID_PLOT_ID("$2That's not a valid plot id.", "Invalid"),
PLOT_ID_FORM("$2The plot id must be in the form: $1X;Y $2e.g. $1-5;7", "Invalid"), PLOT_ID_FORM("$2The plot id must be in the form: $1X;Y $2e.g. $1-5;7", "Invalid"),

View File

@ -21,9 +21,11 @@
package com.intellectualcrafters.plot.config; package com.intellectualcrafters.plot.config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.StringComparison;
/** /**
* Main Configuration Utility * Main Configuration Utility
@ -32,29 +34,29 @@ import com.intellectualcrafters.plot.util.BlockManager;
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class Configuration { public class Configuration {
public static final SettingValue STRING = new SettingValue("STRING") { public static final SettingValue<String> STRING = new SettingValue<String>("STRING") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
return true; return true;
} }
@Override @Override
public Object parseString(final String string) { public String parseString(final String string) {
return string; return string;
} }
}; };
public static final SettingValue STRINGLIST = new SettingValue("STRINGLIST") { public static final SettingValue<String[]> STRINGLIST = new SettingValue<String[]>("STRINGLIST") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
return true; return true;
} }
@Override @Override
public Object parseString(final String string) { public String[] parseString(final String string) {
return string.split(","); return string.split(",");
} }
}; };
public static final SettingValue INTEGER = new SettingValue("INTEGER") { public static final SettingValue<Integer> INTEGER = new SettingValue<Integer>("INTEGER") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
@ -66,11 +68,11 @@ public class Configuration {
} }
@Override @Override
public Object parseString(final String string) { public Integer parseString(final String string) {
return Integer.parseInt(string); return Integer.parseInt(string);
} }
}; };
public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") { public static final SettingValue<Boolean> BOOLEAN = new SettingValue<Boolean>("BOOLEAN") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
@ -82,11 +84,11 @@ public class Configuration {
} }
@Override @Override
public Object parseString(final String string) { public Boolean parseString(final String string) {
return Boolean.parseBoolean(string); return Boolean.parseBoolean(string);
} }
}; };
public static final SettingValue DOUBLE = new SettingValue("DOUBLE") { public static final SettingValue<Double> DOUBLE = new SettingValue<Double>("DOUBLE") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
@ -98,11 +100,11 @@ public class Configuration {
} }
@Override @Override
public Object parseString(final String string) { public Double parseString(final String string) {
return Double.parseDouble(string); return Double.parseDouble(string);
} }
}; };
public static final SettingValue BIOME = new SettingValue("BIOME") { public static final SettingValue<String> BIOME = new SettingValue<String>("BIOME") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
@ -117,19 +119,14 @@ public class Configuration {
} }
@Override @Override
public Object parseString(final String string) { public String parseString(final String string) {
if (validateValue(string)) { if (validateValue(string)) {
return string.toUpperCase(); return string.toUpperCase();
} }
return "FOREST"; return "FOREST";
} }
@Override
public Object parseObject(final Object object) {
return object.toString();
}
}; };
public static final SettingValue BLOCK = new SettingValue("BLOCK") { public static final SettingValue<PlotBlock> BLOCK = new SettingValue<PlotBlock>("BLOCK") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
@ -147,7 +144,7 @@ public class Configuration {
} }
@Override @Override
public Object parseString(final String string) { public PlotBlock parseString(final String string) {
if (string.contains(":")) { if (string.contains(":")) {
final String[] split = string.split(":"); final String[] split = string.split(":");
return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1])); return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
@ -155,13 +152,8 @@ public class Configuration {
return new PlotBlock(Short.parseShort(string), (byte) 0); return new PlotBlock(Short.parseShort(string), (byte) 0);
} }
} }
@Override
public Object parseObject(final Object object) {
return object;
}
}; };
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { public static final SettingValue<PlotBlock[]> BLOCKLIST = new SettingValue<PlotBlock[]>("BLOCKLIST") {
@Override @Override
public boolean validateValue(final String string) { public boolean validateValue(final String string) {
try { try {
@ -171,12 +163,9 @@ public class Configuration {
Integer.parseInt(split[0]); Integer.parseInt(split[0]);
block = split[1]; block = split[1];
} }
if (block.contains(":")) { StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(block);
final String[] split = block.split(":"); if (value == null || value.match > 1) {
Short.parseShort(split[0]); return false;
Short.parseShort(split[1]);
} else {
Short.parseShort(block);
} }
} }
return true; return true;
@ -186,33 +175,34 @@ public class Configuration {
} }
@Override @Override
public Object parseString(final String string) { public PlotBlock[] parseString(final String string) {
final String[] blocks = string.split(","); final String[] blocks = string.split(",");
final ArrayList<PlotBlock> parsedvalues = new ArrayList<>(); final ArrayList<PlotBlock> parsedvalues = new ArrayList<>();
final PlotBlock[] values = new PlotBlock[blocks.length]; final PlotBlock[] values = new PlotBlock[blocks.length];
final int[] counts = new int[blocks.length]; final int[] counts = new int[blocks.length];
int min = 100; int min = 100;
for (int i = 0; i < blocks.length; i++) { for (int i = 0; i < blocks.length; i++) {
if (blocks[i].contains("%")) { try {
final String[] split = blocks[i].split("%"); if (blocks[i].contains("%")) {
blocks[i] = split[1]; final String[] split = blocks[i].split("%");
final int value = Integer.parseInt(split[0]); blocks[i] = split[1];
counts[i] = value; final int value = Integer.parseInt(split[0]);
if (value < min) { counts[i] = value;
min = value; if (value < min) {
min = value;
}
} else {
counts[i] = 1;
if (1 < min) {
min = 1;
}
} }
} else { StringComparison<PlotBlock>.ComparisonResult result = BlockManager.manager.getClosestBlock(blocks[i]);
counts[i] = 1; if (result != null && result.match < 2) {
if (1 < min) { values[i] = result.best;
min = 1;
} }
} }
if (blocks[i].contains(":")) { catch (Exception e) {}
final String[] split = blocks[i].split(":");
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
} else {
values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0);
}
} }
final int gcd = gcd(counts); final int gcd = gcd(counts);
for (int i = 0; i < counts.length; i++) { for (int i = 0; i < counts.length; i++) {
@ -223,11 +213,6 @@ public class Configuration {
} }
return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]); return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]);
} }
@Override
public Object parseObject(final Object object) {
return object;
}
}; };
public static int gcd(final int a, final int b) { public static int gcd(final int a, final int b) {
@ -248,7 +233,7 @@ public class Configuration {
/** /**
* Create your own SettingValue object to make the management of plotworld configuration easier * Create your own SettingValue object to make the management of plotworld configuration easier
*/ */
public static abstract class SettingValue { public static abstract class SettingValue<T> {
private final String type; private final String type;
public SettingValue(final String type) { public SettingValue(final String type) {
@ -259,11 +244,7 @@ public class Configuration {
return this.type; return this.type;
} }
public Object parseObject(final Object object) { public abstract T parseString(final String string);
return object;
}
public abstract Object parseString(final String string);
public abstract boolean validateValue(final String string); public abstract boolean validateValue(final String string);
} }

View File

@ -102,7 +102,7 @@ public class FlagManager {
public static boolean addFlag(AbstractFlag af, boolean reserved) { public static boolean addFlag(AbstractFlag af, boolean reserved) {
PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af); PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
for (PlotWorld plotworld : PlotSquared.getPlotWorldObjects()) { for (PlotWorld plotworld : PlotSquared.getPlotWorldObjects()) {
Flag flag = plotworld.DEFAULT_FLAGS.get(af.getKey()); Flag flag = ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(af.getKey());
if (flag != null) { if (flag != null) {
flag.setKey(af); flag.setKey(af);
} }
@ -129,7 +129,7 @@ public class FlagManager {
if (plotworld == null) { if (plotworld == null) {
return null; return null;
} }
return plotworld.DEFAULT_FLAGS.get(id); return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id);
} }
return flag; return flag;
} }

View File

@ -831,10 +831,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
Material type = block.getType(); Material type = block.getType();
if (true || type.isSolid() && type.isBlock() && type.isOccluding()) { if (action == Action.RIGHT_CLICK_BLOCK && type.isSolid() && type.isBlock() && type.isOccluding() && !type.isBurnable()) {
BlockState state = block.getState(); BlockState state = block.getState();
MaterialData data = state.getData(); if (state.getData().getClass().equals(MaterialData.class)) {
if (data instanceof Tree || data instanceof Wool || state.getData().getClass().equals(MaterialData.class)) {
Class<? extends BlockState> clazz = state.getClass(); Class<? extends BlockState> clazz = state.getClass();
if (clazz.getSimpleName().equals("CraftBlockState")) { if (clazz.getSimpleName().equals("CraftBlockState")) {
return; return;

View File

@ -239,7 +239,7 @@ public abstract class PlotWorld {
* Saving generator specific settings * Saving generator specific settings
*/ */
for (final ConfigurationNode setting : settings) { for (final ConfigurationNode setting : settings) {
options.put(setting.getConstant(), setting.getType().parseObject(setting.getValue())); options.put(setting.getConstant(), setting.getValue());
} }
for (final String option : options.keySet()) { for (final String option : options.keySet()) {
if (!config.contains(option)) { if (!config.contains(option)) {

View File

@ -3,12 +3,17 @@ package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.StringComparison.ComparisonResult;
public abstract class BlockManager { public abstract class BlockManager {
public static BlockManager manager; public static BlockManager manager;
public abstract boolean isBlockSolid(PlotBlock block); public abstract boolean isBlockSolid(PlotBlock block);
public abstract StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name);
public abstract String getClosestMatchingName(PlotBlock block);
public abstract String[] getBiomeList(); public abstract String[] getBiomeList();
public abstract boolean addItems(String world, PlotItem items); public abstract boolean addItems(String world, PlotItem items);

View File

@ -1569,7 +1569,6 @@ public class MainUtil {
for (Entry<UUID, Integer> entry : rating.entrySet()) { for (Entry<UUID, Integer> entry : rating.entrySet()) {
val += entry.getValue(); val += entry.getValue();
} }
System.out.print(val);
return val / (double) rating.size(); return val / (double) rating.size();
} }
} }

View File

@ -31,11 +31,11 @@ import org.apache.commons.lang.StringUtils;
* @author Citymonstret * @author Citymonstret
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class StringComparison { public class StringComparison<T> {
/** /**
* Best Match * Best Match
*/ */
private String bestMatch; private T bestMatch;
/** /**
* Match Value * Match Value
* *
@ -45,7 +45,7 @@ public class StringComparison {
/** /**
* The actual object * The actual object
*/ */
private Object bestMatchObject; private T bestMatchObject;
/** /**
* Constructor * Constructor
@ -53,15 +53,24 @@ public class StringComparison {
* @param input Input Base Value * @param input Input Base Value
* @param objects Objects to compare * @param objects Objects to compare
*/ */
public StringComparison(String input, final Object[] objects) { public StringComparison(String input, final T[] objects) {
init(input, objects);
}
/**
* You should call init(...) when you are ready to get a String comparison value
*/
public StringComparison() {}
public void init(String input, final T[] objects) {
int c; int c;
this.bestMatch = objects[0].toString(); this.bestMatch = objects[0];
this.bestMatchObject = objects[0]; this.bestMatchObject = objects[0];
input = input.toLowerCase(); input = input.toLowerCase();
for (final Object o : objects) { for (final T o : objects) {
if ((c = compare(input, o.toString().toLowerCase())) < this.match) { if ((c = compare(input, o.toString().toLowerCase())) < this.match) {
this.match = c; this.match = c;
this.bestMatch = o.toString(); this.bestMatch = o;
this.bestMatchObject = o; this.bestMatchObject = o;
} }
} }
@ -93,7 +102,7 @@ public class StringComparison {
* *
* @return ArrayList * @return ArrayList
*/ */
public static ArrayList wLetterPair(final String s) { public static ArrayList<String> wLetterPair(final String s) {
final ArrayList<String> aPairs = new ArrayList<>(); final ArrayList<String> aPairs = new ArrayList<>();
final String[] wo = s.split("\\s"); final String[] wo = s.split("\\s");
for (final String aWo : wo) { for (final String aWo : wo) {
@ -124,7 +133,7 @@ public class StringComparison {
* *
* @return match object * @return match object
*/ */
public Object getMatchObject() { public T getMatchObject() {
return this.bestMatchObject; return this.bestMatchObject;
} }
@ -134,7 +143,7 @@ public class StringComparison {
* @return match value * @return match value
*/ */
public String getBestMatch() { public String getBestMatch() {
return this.bestMatch; return this.bestMatch.toString();
} }
/** /**
@ -142,7 +151,16 @@ public class StringComparison {
* *
* @return object[] containing: double, String * @return object[] containing: double, String
*/ */
public Object[] getBestMatchAdvanced() { public ComparisonResult getBestMatchAdvanced() {
return new Object[] { this.match, this.bestMatch }; return new ComparisonResult(this.match, this.bestMatch);
}
public class ComparisonResult {
public T best;
public final double match;
public ComparisonResult(double match, T best) {
this.match = match;
this.best = best;
}
} }
} }

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Material; import org.bukkit.Material;
@ -18,6 +19,11 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.material.Sandstone;
import org.bukkit.material.Step;
import org.bukkit.material.Tree;
import org.bukkit.material.Wool;
import com.intellectualcrafters.plot.object.BukkitPlayer; import com.intellectualcrafters.plot.object.BukkitPlayer;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
@ -27,6 +33,8 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringComparison.ComparisonResult;
public class BukkitUtil extends BlockManager { public class BukkitUtil extends BlockManager {
private static HashMap<String, World> worlds = new HashMap<>(); private static HashMap<String, World> worlds = new HashMap<>();
@ -317,10 +325,58 @@ public class BukkitUtil extends BlockManager {
public boolean isBlockSolid(PlotBlock block) { public boolean isBlockSolid(PlotBlock block) {
try { try {
Material material = Material.getMaterial(block.id); Material material = Material.getMaterial(block.id);
return material.isBlock() && material.isSolid() && material.isOccluding() && !material.hasGravity(); if (material.isBlock() && material.isSolid() && !material.hasGravity()) {
Class<? extends MaterialData> data = material.getData();
if (data.equals(MaterialData.class) || data.equals(Tree.class) || data.equals(Sandstone.class) || data.equals(Wool.class) || data.equals(Step.class)) {
return true;
}
}
return false;
} }
catch (Exception e) { catch (Exception e) {
return false; return false;
} }
} }
@Override
public String getClosestMatchingName(PlotBlock block) {
try {
return Material.getMaterial(block.id).name();
}
catch (Exception e) {
return null;
}
}
@Override
public StringComparison<PlotBlock>.ComparisonResult getClosestBlock(String name) {
try {
double match;
short id;
byte data;
String[] split = name.split(":");
if (split.length == 2) {
data = Byte.parseByte(split[1]);
name = split[0];
}
else {
data = 0;
}
if (StringUtils.isNumeric(split[0])) {
id = Short.parseShort(split[0]);
match = 0;
}
else {
StringComparison<Material>.ComparisonResult comparison = new StringComparison<Material>(name, Material.values()).getBestMatchAdvanced();
match = comparison.match;
id = (short) comparison.best.getId();
}
PlotBlock block = new PlotBlock(id, data);
StringComparison<PlotBlock> outer = new StringComparison<PlotBlock>();
return outer.new ComparisonResult(match, block);
}
catch (Exception e) {}
return null;
}
} }