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>
</properties>
<artifactId>PlotSquared</artifactId>
<version>2.11.24</version>
<version>2.11.25</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -92,13 +92,18 @@ public class DebugExec extends SubCommand {
ExpireManager.task = -1;
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()) {
if (FlagManager.getPlotFlag(plot, "modified-blocks") != null) {
FlagManager.removePlotFlag(plot, "modified-blocks");
if (FlagManager.getPlotFlag(plot, flag) != null) {
FlagManager.removePlotFlag(plot, flag);
}
}
return MainUtil.sendMessage(player, "Cleared modified flag!");
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
}
case "start-rgar": {
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.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.FlagValue.PlotBlockListValue;
import com.intellectualcrafters.plot.listeners.APlotListener;
import com.intellectualcrafters.plot.object.BlockLoc;
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.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
/**
@ -238,24 +240,50 @@ public class Set extends SubCommand {
}
PlotBlock[] blocks;
try {
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseString(args[1]);
} catch (final Exception e) {
try {
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 (args.length < 2) {
MainUtil.sendMessage(plr, C.NEED_BLOCK);
return true;
}
// 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)) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);

View File

@ -293,7 +293,6 @@ public enum C {
/*
* 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_SEPARATER("$1,$2 ", "Block List"),
/*
@ -322,7 +321,8 @@ public enum C {
* 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_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"),

View File

@ -21,9 +21,11 @@
package com.intellectualcrafters.plot.config;
import java.util.ArrayList;
import java.util.List;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.StringComparison;
/**
* Main Configuration Utility
@ -32,29 +34,29 @@ import com.intellectualcrafters.plot.util.BlockManager;
*/
@SuppressWarnings("unused")
public class Configuration {
public static final SettingValue STRING = new SettingValue("STRING") {
public static final SettingValue<String> STRING = new SettingValue<String>("STRING") {
@Override
public boolean validateValue(final String string) {
return true;
}
@Override
public Object parseString(final String string) {
public String parseString(final String string) {
return string;
}
};
public static final SettingValue STRINGLIST = new SettingValue("STRINGLIST") {
public static final SettingValue<String[]> STRINGLIST = new SettingValue<String[]>("STRINGLIST") {
@Override
public boolean validateValue(final String string) {
return true;
}
@Override
public Object parseString(final String string) {
public String[] parseString(final String string) {
return string.split(",");
}
};
public static final SettingValue INTEGER = new SettingValue("INTEGER") {
public static final SettingValue<Integer> INTEGER = new SettingValue<Integer>("INTEGER") {
@Override
public boolean validateValue(final String string) {
try {
@ -66,11 +68,11 @@ public class Configuration {
}
@Override
public Object parseString(final String string) {
public Integer parseString(final String string) {
return Integer.parseInt(string);
}
};
public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") {
public static final SettingValue<Boolean> BOOLEAN = new SettingValue<Boolean>("BOOLEAN") {
@Override
public boolean validateValue(final String string) {
try {
@ -82,11 +84,11 @@ public class Configuration {
}
@Override
public Object parseString(final String string) {
public Boolean parseString(final String string) {
return Boolean.parseBoolean(string);
}
};
public static final SettingValue DOUBLE = new SettingValue("DOUBLE") {
public static final SettingValue<Double> DOUBLE = new SettingValue<Double>("DOUBLE") {
@Override
public boolean validateValue(final String string) {
try {
@ -98,11 +100,11 @@ public class Configuration {
}
@Override
public Object parseString(final String string) {
public Double parseString(final String string) {
return Double.parseDouble(string);
}
};
public static final SettingValue BIOME = new SettingValue("BIOME") {
public static final SettingValue<String> BIOME = new SettingValue<String>("BIOME") {
@Override
public boolean validateValue(final String string) {
try {
@ -117,19 +119,14 @@ public class Configuration {
}
@Override
public Object parseString(final String string) {
public String parseString(final String string) {
if (validateValue(string)) {
return string.toUpperCase();
}
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
public boolean validateValue(final String string) {
try {
@ -147,7 +144,7 @@ public class Configuration {
}
@Override
public Object parseString(final String string) {
public PlotBlock parseString(final String string) {
if (string.contains(":")) {
final String[] split = string.split(":");
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);
}
}
@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
public boolean validateValue(final String string) {
try {
@ -171,12 +163,9 @@ public class Configuration {
Integer.parseInt(split[0]);
block = split[1];
}
if (block.contains(":")) {
final String[] split = block.split(":");
Short.parseShort(split[0]);
Short.parseShort(split[1]);
} else {
Short.parseShort(block);
StringComparison<PlotBlock>.ComparisonResult value = BlockManager.manager.getClosestBlock(block);
if (value == null || value.match > 1) {
return false;
}
}
return true;
@ -186,33 +175,34 @@ public class Configuration {
}
@Override
public Object parseString(final String string) {
public PlotBlock[] parseString(final String string) {
final String[] blocks = string.split(",");
final ArrayList<PlotBlock> parsedvalues = new ArrayList<>();
final PlotBlock[] values = new PlotBlock[blocks.length];
final int[] counts = new int[blocks.length];
int min = 100;
for (int i = 0; i < blocks.length; i++) {
if (blocks[i].contains("%")) {
final String[] split = blocks[i].split("%");
blocks[i] = split[1];
final int value = Integer.parseInt(split[0]);
counts[i] = value;
if (value < min) {
min = value;
try {
if (blocks[i].contains("%")) {
final String[] split = blocks[i].split("%");
blocks[i] = split[1];
final int value = Integer.parseInt(split[0]);
counts[i] = value;
if (value < min) {
min = value;
}
} else {
counts[i] = 1;
if (1 < min) {
min = 1;
}
}
} else {
counts[i] = 1;
if (1 < min) {
min = 1;
StringComparison<PlotBlock>.ComparisonResult result = BlockManager.manager.getClosestBlock(blocks[i]);
if (result != null && result.match < 2) {
values[i] = result.best;
}
}
if (blocks[i].contains(":")) {
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);
}
catch (Exception e) {}
}
final int gcd = gcd(counts);
for (int i = 0; i < counts.length; i++) {
@ -223,11 +213,6 @@ public class Configuration {
}
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) {
@ -248,7 +233,7 @@ public class Configuration {
/**
* 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;
public SettingValue(final String type) {
@ -259,11 +244,7 @@ public class Configuration {
return this.type;
}
public Object parseObject(final Object object) {
return object;
}
public abstract Object parseString(final String string);
public abstract T parseString(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) {
PlotSquared.log(C.PREFIX.s() + "&8 - Adding flag: &7" + af);
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) {
flag.setKey(af);
}
@ -129,7 +129,7 @@ public class FlagManager {
if (plotworld == null) {
return null;
}
return plotworld.DEFAULT_FLAGS.get(id);
return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id);
}
return flag;
}

View File

@ -831,10 +831,9 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return;
}
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();
MaterialData data = state.getData();
if (data instanceof Tree || data instanceof Wool || state.getData().getClass().equals(MaterialData.class)) {
if (state.getData().getClass().equals(MaterialData.class)) {
Class<? extends BlockState> clazz = state.getClass();
if (clazz.getSimpleName().equals("CraftBlockState")) {
return;

View File

@ -239,7 +239,7 @@ public abstract class PlotWorld {
* Saving generator specific 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()) {
if (!config.contains(option)) {

View File

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

View File

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

View File

@ -31,11 +31,11 @@ import org.apache.commons.lang.StringUtils;
* @author Citymonstret
*/
@SuppressWarnings("unused")
public class StringComparison {
public class StringComparison<T> {
/**
* Best Match
*/
private String bestMatch;
private T bestMatch;
/**
* Match Value
*
@ -45,7 +45,7 @@ public class StringComparison {
/**
* The actual object
*/
private Object bestMatchObject;
private T bestMatchObject;
/**
* Constructor
@ -53,15 +53,24 @@ public class StringComparison {
* @param input Input Base Value
* @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;
this.bestMatch = objects[0].toString();
this.bestMatch = objects[0];
this.bestMatchObject = objects[0];
input = input.toLowerCase();
for (final Object o : objects) {
for (final T o : objects) {
if ((c = compare(input, o.toString().toLowerCase())) < this.match) {
this.match = c;
this.bestMatch = o.toString();
this.bestMatch = o;
this.bestMatchObject = o;
}
}
@ -93,7 +102,7 @@ public class StringComparison {
*
* @return ArrayList
*/
public static ArrayList wLetterPair(final String s) {
public static ArrayList<String> wLetterPair(final String s) {
final ArrayList<String> aPairs = new ArrayList<>();
final String[] wo = s.split("\\s");
for (final String aWo : wo) {
@ -124,7 +133,7 @@ public class StringComparison {
*
* @return match object
*/
public Object getMatchObject() {
public T getMatchObject() {
return this.bestMatchObject;
}
@ -134,7 +143,7 @@ public class StringComparison {
* @return match value
*/
public String getBestMatch() {
return this.bestMatch;
return this.bestMatch.toString();
}
/**
@ -142,7 +151,16 @@ public class StringComparison {
*
* @return object[] containing: double, String
*/
public Object[] getBestMatchAdvanced() {
return new Object[] { this.match, this.bestMatch };
public ComparisonResult getBestMatchAdvanced() {
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.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@ -18,6 +19,11 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
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.ChunkLoc;
@ -27,6 +33,8 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringComparison.ComparisonResult;
public class BukkitUtil extends BlockManager {
private static HashMap<String, World> worlds = new HashMap<>();
@ -317,10 +325,58 @@ public class BukkitUtil extends BlockManager {
public boolean isBlockSolid(PlotBlock block) {
try {
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) {
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;
}
}