Hows this?

This commit is contained in:
boy0001 2015-09-13 14:04:31 +10:00
parent 1cccdd9d4d
commit 5137b23357
379 changed files with 18471 additions and 28437 deletions

View file

@ -46,7 +46,6 @@ import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import com.plotsquared.listener.PlotListener;
// TODO Make sub-subcommands
@CommandDeclaration(
@ -57,33 +56,29 @@ usage = "/plot set <biome|alias|home|flag> <value...>",
permission = "plots.set",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Set extends SubCommand
{
public class Set extends SubCommand {
public final static String[] values = new String[] { "biome", "alias", "home", "flag" };
public final static String[] aliases = new String[] { "b", "w", "wf", "f", "a", "h", "fl" };
@Override
public boolean onCommand(final PlotPlayer plr, final String... args)
{
public boolean onCommand(final PlotPlayer plr, final String... args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
sendMessage(plr, C.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.set.other"))
{
if (!plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.set.other")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.other");
return false;
}
}
if (args.length < 1)
{
if (args.length < 1) {
final PlotManager manager = PS.get().getPlotManager(loc.getWorld());
final ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values));
@ -91,33 +86,26 @@ public class Set extends SubCommand
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false;
}
for (int i = 0; i < aliases.length; i++)
{
if (aliases[i].equalsIgnoreCase(args[0]))
{
for (int i = 0; i < aliases.length; i++) {
if (aliases[i].equalsIgnoreCase(args[0])) {
args[0] = values[i];
break;
}
}
if (args[0].equalsIgnoreCase("flag"))
{
if (args[0].equalsIgnoreCase("flag")) {
List<String> arglist = Arrays.asList("flag", "set");
for (String arg : Arrays.copyOfRange(args, 1, args.length)) {
arglist.add(arg);
}
return MainCommand.onCommand(plr, "plot", arglist.toArray(new String[0]));
}
if (args[0].equalsIgnoreCase("home"))
{
if (!Permissions.hasPermission(plr, "plots.set.home"))
{
if (args[0].equalsIgnoreCase("home")) {
if (!Permissions.hasPermission(plr, "plots.set.home")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.home");
return false;
}
if (args.length > 1)
{
if (args[1].equalsIgnoreCase("none"))
{
if (args.length > 1) {
if (args[1].equalsIgnoreCase("none")) {
plot.setHome(null);
return true;
}
@ -132,62 +120,50 @@ public class Set extends SubCommand
plot.setHome(blockloc);
return MainUtil.sendMessage(plr, C.POSITION_SET);
}
if (args[0].equalsIgnoreCase("desc"))
{
if (!Permissions.hasPermission(plr, "plots.set.desc"))
{
if (args[0].equalsIgnoreCase("desc")) {
if (!Permissions.hasPermission(plr, "plots.set.desc")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.desc");
return false;
}
if (args.length < 2)
{
if (args.length < 2) {
MainUtil.sendMessage(plr, C.MISSING_DESC);
return false;
}
final StringBuilder desc = new StringBuilder();
for (int i = 1; i < args.length; i++)
{
for (int i = 1; i < args.length; i++) {
desc.append(args[i]).append(" ");
}
final String descValue = desc.substring(0, desc.length() - 1);
final Flag flag = new Flag(FlagManager.getFlag("description"), descValue);
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result)
{
if (!result) {
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(plr, C.DESC_SET);
return true;
}
if (args[0].equalsIgnoreCase("alias"))
{
if (!Permissions.hasPermission(plr, "plots.set.alias"))
{
if (args[0].equalsIgnoreCase("alias")) {
if (!Permissions.hasPermission(plr, "plots.set.alias")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.alias");
return false;
}
if (args.length < 2)
{
if (args.length < 2) {
MainUtil.sendMessage(plr, C.MISSING_ALIAS);
return false;
}
final String alias = args[1];
if (alias.length() >= 50)
{
if (alias.length() >= 50) {
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
return false;
}
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld()))
{
if (p.getSettings().getAlias().equalsIgnoreCase(alias))
{
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
if (p.getSettings().getAlias().equalsIgnoreCase(alias)) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
if (UUIDHandler.nameExists(new StringWrapper(alias)))
{
if (UUIDHandler.nameExists(new StringWrapper(alias))) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
@ -196,48 +172,39 @@ public class Set extends SubCommand
MainUtil.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
return true;
}
if (args[0].equalsIgnoreCase("biome"))
{
if (!Permissions.hasPermission(plr, "plots.set.biome"))
{
if (args[0].equalsIgnoreCase("biome")) {
if (!Permissions.hasPermission(plr, "plots.set.biome")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.biome");
return false;
}
if (args.length < 2)
{
if (args.length < 2) {
MainUtil.sendMessage(plr, C.NEED_BIOME);
return true;
}
if (args[1].length() < 2)
{
if (args[1].length() < 2) {
sendMessage(plr, C.NAME_LITTLE, "Biome", args[1].length() + "", "2");
return true;
}
final int biome = BlockManager.manager.getBiomeFromString(args[1]);
if (biome == -1)
{
if (biome == -1) {
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
return true;
}
if (MainUtil.runners.containsKey(plot))
{
if (MainUtil.runners.containsKey(plot)) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
plot.setBiome(args[1].toUpperCase(), new Runnable()
{
plot.setBiome(args[1].toUpperCase(), new Runnable() {
@Override
public void run()
{
public void run() {
MainUtil.runners.remove(plot);
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
}
});
return true;
}
if (args[0].equalsIgnoreCase("limit"))
{
if (args[0].equalsIgnoreCase("limit")) {
// /plot set limit Empire92 +1
return true;
}
@ -246,90 +213,68 @@ public class Set extends SubCommand
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final PlotManager manager = PS.get().getPlotManager(world);
final String[] components = manager.getPlotComponents(plotworld, plot.id);
final boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
for (final String component : components)
{
if (component.equalsIgnoreCase(args[0]))
{
if (!Permissions.hasPermission(plr, "plots.set." + component))
{
for (final String component : components) {
if (component.equalsIgnoreCase(args[0])) {
if (!Permissions.hasPermission(plr, "plots.set." + component)) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component);
return false;
}
PlotBlock[] blocks;
try
{
if (args.length < 2)
{
try {
if (args.length < 2) {
MainUtil.sendMessage(plr, C.NEED_BLOCK);
return true;
}
final String[] split = args[1].split(",");
blocks = Configuration.BLOCKLIST.parseString(args[1]);
for (int i = 0; i < blocks.length; i++)
{
for (int i = 0; i < blocks.length; i++) {
final PlotBlock block = blocks[i];
if (block == null)
{
if (block == null) {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, split[i]);
String name;
if (split[i].contains("%"))
{
if (split[i].contains("%")) {
name = split[i].split("%")[1];
}
else
{
} else {
name = split[i];
}
final StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
if (match != null)
{
if (match != null) {
name = BlockManager.manager.getClosestMatchingName(match.best);
if (name != null)
{
if (name != null) {
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase());
}
}
return false;
}
else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block))
{
} else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
}
}
if (!allowUnsafe)
{
for (final PlotBlock block : blocks)
{
if (!BlockManager.manager.isBlockSolid(block))
{
if (!allowUnsafe) {
for (final PlotBlock block : blocks) {
if (!BlockManager.manager.isBlockSolid(block)) {
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
}
}
}
}
catch (final Exception e2)
{
} 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);
return false;
}
MainUtil.runners.put(plot, 1);
manager.setComponent(plotworld, plot.id, component, blocks);
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
SetBlockQueue.addNotify(new Runnable()
{
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run()
{
public void run() {
MainUtil.runners.remove(plot);
}
});
@ -338,21 +283,15 @@ public class Set extends SubCommand
}
{
AbstractFlag af;
try
{
try {
af = new AbstractFlag(args[0].toLowerCase());
}
catch (final Exception e)
{
} catch (final Exception e) {
af = new AbstractFlag("");
}
if (FlagManager.getFlags().contains(af))
{
if (FlagManager.getFlags().contains(af)) {
final StringBuilder a = new StringBuilder();
if (args.length > 1)
{
for (int x = 1; x < args.length; x++)
{
if (args.length > 1) {
for (int x = 1; x < args.length; x++) {
a.append(" ").append(args[x]);
}
}
@ -366,28 +305,23 @@ public class Set extends SubCommand
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(newValues));
return false;
}
private String getString(final String s)
{
private String getString(final String 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) {
final StringBuilder builder = new StringBuilder();
for (final String s : newValues)
{
for (final String s : newValues) {
builder.append(getString(s));
}
return builder.toString().substring(1, builder.toString().length() - 1);
}
private String getBiomeList(final String[] biomes)
{
private String getBiomeList(final String[] biomes) {
final StringBuilder builder = new StringBuilder();
builder.append(C.NEED_BIOME.s());
for (final String b : biomes)
{
for (final String b : biomes) {
builder.append(getString(b));
}
return builder.toString().substring(1, builder.toString().length() - 1);