mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Minor fixes :D
This commit is contained in:
parent
d257ddb90d
commit
07895be660
@ -24,7 +24,10 @@ package com.intellectualcrafters.plot;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-23.
|
||||
* Created 2014-09-23 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public class AbstractFlag {
|
||||
|
||||
|
@ -21,15 +21,34 @@
|
||||
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper class for blocks, using
|
||||
* pure data rather than the object.
|
||||
* <p/>
|
||||
* Useful for NMS
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class BlockWrapper {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public int id;
|
||||
public byte data;
|
||||
|
||||
public BlockWrapper(final int x, final int y, final int z, final short id, final byte data) {
|
||||
// Public Final //////////////////////////
|
||||
public final int x; //
|
||||
public final int y; //
|
||||
public final int z; //
|
||||
public final int id; //
|
||||
public final byte data; //
|
||||
//////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param x X Loc Value
|
||||
* @param y Y Loc Value
|
||||
* @param z Z Loc Value
|
||||
* @param id Material ID
|
||||
* @param data Data Value
|
||||
*/
|
||||
public BlockWrapper(int x, int y, int z, short id, byte data) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
@ -26,7 +26,14 @@ import org.bukkit.block.Biome;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Main Configuration Utility
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Configuration {
|
||||
|
||||
public static final SettingValue STRING = new SettingValue("STRING") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
@ -55,7 +62,7 @@ public class Configuration {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
Integer.parseInt(string);
|
||||
int x = Integer.parseInt(string);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
@ -72,7 +79,7 @@ public class Configuration {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
Boolean.parseBoolean(string);
|
||||
boolean b = Boolean.parseBoolean(string);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
@ -89,7 +96,7 @@ public class Configuration {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
try {
|
||||
Double.parseDouble(string);
|
||||
double d = Double.parseDouble(string);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
@ -125,7 +132,7 @@ public class Configuration {
|
||||
|
||||
@Override
|
||||
public Object parseObject(final Object object) {
|
||||
return ((Biome) object).toString();
|
||||
return (((Biome) object)).toString();
|
||||
}
|
||||
};
|
||||
|
||||
@ -135,10 +142,12 @@ public class Configuration {
|
||||
try {
|
||||
if (string.contains(":")) {
|
||||
final String[] split = string.split(":");
|
||||
Short.parseShort(split[0]);
|
||||
Short.parseShort(split[1]);
|
||||
short s =
|
||||
Short.parseShort(split[0]);
|
||||
short z =
|
||||
Short.parseShort(split[1]);
|
||||
} else {
|
||||
Short.parseShort(string);
|
||||
short s = Short.parseShort(string);
|
||||
}
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
@ -161,22 +170,6 @@ public class Configuration {
|
||||
return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data;
|
||||
}
|
||||
};
|
||||
|
||||
public static int gcd(final int a, final int b) {
|
||||
if (b == 0) {
|
||||
return a;
|
||||
}
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
private static int gcd(final int[] a) {
|
||||
int result = a[0];
|
||||
for (int i = 1; i < a.length; i++) {
|
||||
result = gcd(result, a[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") {
|
||||
@Override
|
||||
public boolean validateValue(final String string) {
|
||||
@ -184,15 +177,15 @@ public class Configuration {
|
||||
for (String block : string.split(",")) {
|
||||
if (block.contains("%")) {
|
||||
final String[] split = block.split("%");
|
||||
Integer.parseInt(split[0]);
|
||||
int i = Integer.parseInt(split[0]);
|
||||
block = split[1];
|
||||
}
|
||||
if (block.contains(":")) {
|
||||
final String[] split = block.split(":");
|
||||
Short.parseShort(split[0]);
|
||||
Short.parseShort(split[1]);
|
||||
short s = Short.parseShort(split[0]);
|
||||
short z = Short.parseShort(split[1]);
|
||||
} else {
|
||||
Short.parseShort(block);
|
||||
short s = Short.parseShort(block);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -204,7 +197,7 @@ public class Configuration {
|
||||
@Override
|
||||
public Object parseString(final String string) {
|
||||
final String[] blocks = string.split(",");
|
||||
final ArrayList<PlotBlock> parsedvalues = new ArrayList<PlotBlock>();
|
||||
final ArrayList<PlotBlock> parsedvalues = new ArrayList<>();
|
||||
|
||||
final PlotBlock[] values = new PlotBlock[blocks.length];
|
||||
final int[] counts = new int[blocks.length];
|
||||
@ -239,12 +232,12 @@ public class Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
return parsedvalues.toArray(new PlotBlock[0]);
|
||||
return parsedvalues.toArray(new PlotBlock[parsedvalues.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object parseObject(final Object object) {
|
||||
final List<String> list = new ArrayList<String>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
for (final PlotBlock block : (PlotBlock[]) object) {
|
||||
list.add((block.id + ":" + (block.data)));
|
||||
}
|
||||
@ -252,6 +245,21 @@ public class Configuration {
|
||||
}
|
||||
};
|
||||
|
||||
public static int gcd(final int a, final int b) {
|
||||
if (b == 0) {
|
||||
return a;
|
||||
}
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
private static int gcd(final int[] a) {
|
||||
int result = a[0];
|
||||
for (int i = 1; i < a.length; i++) {
|
||||
result = gcd(result, a[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create your own SettingValue object to make the management of plotworld
|
||||
* configuration easier
|
||||
|
@ -30,10 +30,10 @@ public class ConfigurationNode {
|
||||
private final String constant;
|
||||
private final Object default_value;
|
||||
private final String description;
|
||||
private Object value;
|
||||
private final SettingValue type;
|
||||
private Object value;
|
||||
|
||||
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, final boolean required) {
|
||||
public ConfigurationNode(final String constant, final Object default_value, final String description, final SettingValue type, @SuppressWarnings("unused") final boolean required) {
|
||||
this.constant = constant;
|
||||
this.default_value = default_value;
|
||||
this.description = description;
|
||||
@ -48,10 +48,7 @@ public class ConfigurationNode {
|
||||
public boolean isValid(final String string) {
|
||||
try {
|
||||
final Object result = this.type.parseString(string);
|
||||
if (result == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return result != null;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -23,40 +23,12 @@ package com.intellectualcrafters.plot;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-22.
|
||||
*/
|
||||
public class ConsoleColors {
|
||||
|
||||
static enum ConsoleColor {
|
||||
RESET("\u001B[0m"),
|
||||
BLACK("\u001B[30m"),
|
||||
RED("\u001B[31m"),
|
||||
GREEN("\u001B[32m"),
|
||||
YELLOW("\u001B[33m"),
|
||||
BLUE("\u001B[34m"),
|
||||
PURPLE("\u001B[35m"),
|
||||
CYAN("\u001B[36m"),
|
||||
WHITE("\u001B[37m"),
|
||||
BOLD("\033[1m"),
|
||||
UNDERLINE("\033[0m"),
|
||||
ITALIC("\033[3m");
|
||||
|
||||
private final String win;
|
||||
private final String lin;
|
||||
|
||||
ConsoleColor(final String lin) {
|
||||
this.lin = lin;
|
||||
this.win = this.win;
|
||||
}
|
||||
|
||||
public String getWin() {
|
||||
return this.win;
|
||||
}
|
||||
|
||||
public String getLin() {
|
||||
return this.lin;
|
||||
}
|
||||
public static String fromString(String input) {
|
||||
input = input.replaceAll("&0", fromChatColor(ChatColor.BLACK)).replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE)).replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN)).replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA)).replaceAll("&4", fromChatColor(ChatColor.DARK_RED)).replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE)).replaceAll("&6", fromChatColor(ChatColor.GOLD)).replaceAll("&7", fromChatColor(ChatColor.GRAY)).replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY)).replaceAll("&9", fromChatColor(ChatColor.BLUE)).replaceAll("&a", fromChatColor(ChatColor.GREEN)).replaceAll("&b", fromChatColor(ChatColor.AQUA)).replaceAll("&c", fromChatColor(ChatColor.RED)).replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE)).replaceAll("&e", fromChatColor(ChatColor.YELLOW)).replaceAll("&f", fromChatColor(ChatColor.WHITE)).replaceAll("&k", fromChatColor(ChatColor.MAGIC)).replaceAll("&l", fromChatColor(ChatColor.BOLD)).replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH))
|
||||
.replaceAll("&n", fromChatColor(ChatColor.UNDERLINE)).replaceAll("&o", fromChatColor(ChatColor.ITALIC)).replaceAll("&r", fromChatColor(ChatColor.RESET));
|
||||
return input + "\u001B[0m";
|
||||
}
|
||||
|
||||
/*
|
||||
@ -72,12 +44,6 @@ public class ConsoleColors {
|
||||
* = "\033[3m]";
|
||||
*/
|
||||
|
||||
public static String fromString(String input) {
|
||||
input = input.replaceAll("&0", fromChatColor(ChatColor.BLACK)).replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE)).replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN)).replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA)).replaceAll("&4", fromChatColor(ChatColor.DARK_RED)).replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE)).replaceAll("&6", fromChatColor(ChatColor.GOLD)).replaceAll("&7", fromChatColor(ChatColor.GRAY)).replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY)).replaceAll("&9", fromChatColor(ChatColor.BLUE)).replaceAll("&a", fromChatColor(ChatColor.GREEN)).replaceAll("&b", fromChatColor(ChatColor.AQUA)).replaceAll("&c", fromChatColor(ChatColor.RED)).replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE)).replaceAll("&e", fromChatColor(ChatColor.YELLOW)).replaceAll("&f", fromChatColor(ChatColor.WHITE)).replaceAll("&k", fromChatColor(ChatColor.MAGIC)).replaceAll("&l", fromChatColor(ChatColor.BOLD)).replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH))
|
||||
.replaceAll("&n", fromChatColor(ChatColor.UNDERLINE)).replaceAll("&o", fromChatColor(ChatColor.ITALIC)).replaceAll("&r", fromChatColor(ChatColor.RESET));
|
||||
return input + "\u001B[0m";
|
||||
}
|
||||
|
||||
public static String fromChatColor(final ChatColor color) {
|
||||
return chatColor(color).getLin();
|
||||
}
|
||||
@ -119,4 +85,36 @@ public class ConsoleColors {
|
||||
return ConsoleColor.RESET;
|
||||
}
|
||||
}
|
||||
|
||||
static enum ConsoleColor {
|
||||
RESET("\u001B[0m"),
|
||||
BLACK("\u001B[30m"),
|
||||
RED("\u001B[31m"),
|
||||
GREEN("\u001B[32m"),
|
||||
YELLOW("\u001B[33m"),
|
||||
BLUE("\u001B[34m"),
|
||||
PURPLE("\u001B[35m"),
|
||||
CYAN("\u001B[36m"),
|
||||
WHITE("\u001B[37m"),
|
||||
BOLD("\033[1m"),
|
||||
UNDERLINE("\033[0m"),
|
||||
ITALIC("\033[3m");
|
||||
|
||||
private final String win;
|
||||
private final String lin;
|
||||
|
||||
ConsoleColor(final String lin) {
|
||||
this.lin = lin;
|
||||
this.win = lin;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public String getWin() {
|
||||
return this.win;
|
||||
}
|
||||
|
||||
public String getLin() {
|
||||
return this.lin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,28 +27,30 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Flag Manager Utility
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class FlagManager {
|
||||
|
||||
// TODO add some flags
|
||||
// - Plot clear interval
|
||||
// - Mob cap
|
||||
// - customized plot composition
|
||||
// - greeting / leaving message
|
||||
// OR in the flag command, allow users to set worldguard flags.
|
||||
|
||||
private static ArrayList<AbstractFlag> flags = new ArrayList<AbstractFlag>();
|
||||
private static ArrayList<AbstractFlag> flags = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Register an AbstractFlag with PlotSquared
|
||||
*
|
||||
* @param flag
|
||||
* @return
|
||||
* @param flag Flag to register
|
||||
* @return success?
|
||||
*/
|
||||
public static boolean addFlag(final AbstractFlag flag) {
|
||||
if (getFlag(flag.getKey()) != null) {
|
||||
return false;
|
||||
}
|
||||
return flags.add(flag);
|
||||
return getFlag(flag.getKey()) == null && flags.add(flag);
|
||||
}
|
||||
|
||||
public static Flag[] removeFlag(final Flag[] flags, final String r) {
|
||||
@ -101,7 +103,7 @@ public class FlagManager {
|
||||
/**
|
||||
* Get an AbstractFlag by a string Returns null if flag does not exist
|
||||
*
|
||||
* @param string
|
||||
* @param string Flag Key
|
||||
* @return AbstractFlag
|
||||
*/
|
||||
public static AbstractFlag getFlag(final String string) {
|
||||
@ -116,7 +118,7 @@ public class FlagManager {
|
||||
/**
|
||||
* Get an AbstractFlag by a string
|
||||
*
|
||||
* @param string
|
||||
* @param string Flag Key
|
||||
* @param create If to create the flag if it does not exist
|
||||
* @return AbstractFlag
|
||||
*/
|
||||
@ -132,7 +134,7 @@ public class FlagManager {
|
||||
/**
|
||||
* Remove a registered AbstractFlag
|
||||
*
|
||||
* @param flag
|
||||
* @param flag Flag Key
|
||||
* @return boolean Result of operation
|
||||
*/
|
||||
public static boolean removeFlag(final AbstractFlag flag) {
|
||||
@ -155,7 +157,7 @@ public class FlagManager {
|
||||
/**
|
||||
* Get the flags for a plot
|
||||
*
|
||||
* @param plot
|
||||
* @param plot Plot to search in
|
||||
* @return List (AbstractFlag)
|
||||
*/
|
||||
public static List<AbstractFlag> getPlotFlags(final Plot plot) {
|
||||
|
@ -55,8 +55,8 @@ public class PlayerFunctions {
|
||||
return (lp - cu) > 30l;
|
||||
}
|
||||
|
||||
public static ArrayList<PlotId> getPlotSelectionIds(final World world, final PlotId pos1, final PlotId pos2) {
|
||||
final ArrayList<PlotId> myplots = new ArrayList<PlotId>();
|
||||
public static ArrayList<PlotId> getPlotSelectionIds(@SuppressWarnings("unused") final World world, final PlotId pos1, final PlotId pos2) {
|
||||
final ArrayList<PlotId> myplots = new ArrayList<>();
|
||||
for (int x = pos1.x; x <= pos2.x; x++) {
|
||||
for (int y = pos1.y; y <= pos2.y; y++) {
|
||||
myplots.add(new PlotId(x, y));
|
||||
@ -78,7 +78,7 @@ public class PlayerFunctions {
|
||||
pos2 = getTopPlot(world, plot2).id;
|
||||
}
|
||||
|
||||
final ArrayList<PlotId> myplots = new ArrayList<PlotId>();
|
||||
final ArrayList<PlotId> myplots = new ArrayList<>();
|
||||
for (int x = pos1.x; x <= pos2.x; x++) {
|
||||
for (int y = pos1.y; y <= pos2.y; y++) {
|
||||
myplots.add(new PlotId(x, y));
|
||||
@ -193,7 +193,7 @@ public class PlayerFunctions {
|
||||
public static Set<Plot> getPlayerPlots(final World world, final Player plr) {
|
||||
final Set<Plot> p = PlotMain.getPlots(world, plr);
|
||||
if (p == null) {
|
||||
return new HashSet<Plot>();
|
||||
return new HashSet<>();
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class Plot implements Cloneable {
|
||||
this.deny_entry = this.owner == null;
|
||||
this.helpers = helpers;
|
||||
this.denied = denied;
|
||||
this.trusted = new ArrayList<UUID>();
|
||||
this.trusted = new ArrayList<>();
|
||||
this.settings.setAlias("");
|
||||
this.settings.setPosition(PlotHomePosition.DEFAULT);
|
||||
this.delete = false;
|
||||
|
@ -29,8 +29,11 @@ import org.bukkit.block.Block;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-10-12.
|
||||
* Created 2014-10-12 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PlotSelection {
|
||||
|
||||
public static HashMap<String, PlotSelection> currentSelection = new HashMap<>();
|
||||
@ -68,18 +71,6 @@ public class PlotSelection {
|
||||
// Yay :D
|
||||
}
|
||||
|
||||
public PlotBlock[] getBlocks() {
|
||||
return this.plotBlocks;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
public static boolean swap(final World world, final PlotId id1, final PlotId id2) {
|
||||
|
||||
final Location bot2 = PlotHelper.getPlotBottomLocAbs(world, id2).add(1, 0, 1);
|
||||
@ -133,6 +124,18 @@ public class PlotSelection {
|
||||
return new BlockWrapper(block.getX(), block.getY(), block.getZ(), (short) block.getTypeId(), block.getData());
|
||||
}
|
||||
|
||||
public PlotBlock[] getBlocks() {
|
||||
return this.plotBlocks;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
public void paste(final World world, final Plot plot) {
|
||||
|
||||
final Location bot = PlotHelper.getPlotBottomLocAbs(world, plot.getId()), top = PlotHelper.getPlotTopLocAbs(world, plot.getId());
|
||||
|
Loading…
Reference in New Issue
Block a user