This commit is contained in:
boy0001
2015-09-11 20:09:22 +10:00
parent 37a8861fa0
commit c386f33df8
380 changed files with 43490 additions and 33913 deletions

View File

@ -32,71 +32,82 @@ import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.uuid.SQLUUIDHandler;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "add",
aliases = {"a"},
description = "Allow a user to build while you are online",
usage = "/plot add <player>",
category = CommandCategory.ACTIONS,
permission = "plots.add",
requiredType = RequiredType.NONE
)
public class Add extends SubCommand {
command = "add",
aliases = { "a" },
description = "Allow a user to build while you are online",
usage = "/plot add <player>",
category = CommandCategory.ACTIONS,
permission = "plots.add",
requiredType = RequiredType.NONE)
public class Add extends SubCommand
{
public Add() {
public Add()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(PlotPlayer plr, 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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.add"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
UUID uuid;
if (args[0].equalsIgnoreCase("*")) {
if (args[0].equalsIgnoreCase("*"))
{
uuid = DBFunc.everyone;
} else {
}
else
{
// TODO have a runnable for fetch
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.getMembers().contains(uuid)) {
if (plot.getMembers().contains(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
if (plot.removeTrusted(uuid)) {
if (plot.removeTrusted(uuid))
{
plot.addMember(uuid);
}
else {
if (plot.getMembers().size() + plot.getTrusted().size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
else
{
if ((plot.getMembers().size() + plot.getTrusted().size()) >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS)
{
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.getDenied().contains(uuid)) {
if (plot.getDenied().contains(uuid))
{
plot.removeDenied(uuid);
}
plot.addMember(uuid);

View File

@ -29,84 +29,102 @@ import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "auto",
permission = "plots.auto",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
description = "Claim the nearest plot",
aliases = {"a"},
usage = "/plot auto"
)
public class Auto extends SubCommand {
command = "auto",
permission = "plots.auto",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
description = "Claim the nearest plot",
aliases = { "a" },
usage = "/plot auto")
public class Auto extends SubCommand
{
public static PlotId getNextPlot(final PlotId id, final int step) {
public static PlotId getNextPlot(final PlotId id, final int step)
{
final int absX = Math.abs(id.x);
final int absY = Math.abs(id.y);
if (absX > absY) {
if (id.x > 0) {
if (absX > absY)
{
if (id.x > 0)
{
return new PlotId(id.x, id.y + 1);
} else {
}
else
{
return new PlotId(id.x, id.y - 1);
}
} else if (absY > absX) {
if (id.y > 0) {
}
else if (absY > absX)
{
if (id.y > 0)
{
return new PlotId(id.x - 1, id.y);
} else {
}
else
{
return new PlotId(id.x + 1, id.y);
}
} else {
if (id.x.equals(id.y) && (id.x > 0)) {
return new PlotId(id.x, id.y + step);
}
if (id.x == absX) {
return new PlotId(id.x, id.y + 1);
}
if (id.y == absY) {
return new PlotId(id.x, id.y - 1);
}
}
else
{
if (id.x.equals(id.y) && (id.x > 0)) { return new PlotId(id.x, id.y + step); }
if (id.x == absX) { return new PlotId(id.x, id.y + 1); }
if (id.y == absY) { return new PlotId(id.x, id.y - 1); }
return new PlotId(id.x + 1, id.y);
}
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
String world;
int size_x = 1;
int size_z = 1;
String schematic = "";
if (PS.get().getPlotWorlds().size() == 1) {
if (PS.get().getPlotWorlds().size() == 1)
{
world = PS.get().getPlotWorlds().iterator().next();
} else {
}
else
{
world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
if (!PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
}
if (args.length > 0) {
if (Permissions.hasPermission(plr, "plots.auto.mega")) {
try {
if (args.length > 0)
{
if (Permissions.hasPermission(plr, "plots.auto.mega"))
{
try
{
final String[] split = args[0].split(",");
size_x = Integer.parseInt(split[0]);
size_z = Integer.parseInt(split[1]);
if ((size_x < 1) || (size_z < 1)) {
if ((size_x < 1) || (size_z < 1))
{
MainUtil.sendMessage(plr, "&cError: size<=0");
}
if ((size_x > 4) || (size_z > 4)) {
if ((size_x > 4) || (size_z > 4))
{
MainUtil.sendMessage(plr, "&cError: size>4");
}
if (args.length > 1) {
if (args.length > 1)
{
schematic = args[1];
}
} catch (final Exception e) {
}
catch (final Exception e)
{
size_x = 1;
size_z = 1;
schematic = args[0];
@ -114,32 +132,42 @@ public class Auto extends SubCommand {
// "&cError: Invalid size (X,Y)");
// return false;
}
} else {
}
else
{
schematic = args[0];
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
// return false;
}
}
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE) {
if ((size_x * size_z) > Settings.MAX_AUTO_SIZE)
{
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + "");
return false;
}
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
final int diff = currentPlots - MainUtil.getAllowedPlots(plr);
if ((diff + (size_x * size_z)) > 0) {
if (diff < 0) {
if ((diff + (size_x * size_z)) > 0)
{
if (diff < 0)
{
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
} else {
}
else
{
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
return false;
}
final PlotWorld pWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY)
{
double cost = pWorld.PLOT_PRICE;
cost = (size_x * size_z) * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost)
{
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
@ -147,13 +175,16 @@ public class Auto extends SubCommand {
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (!schematic.equals(""))
{
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase()))
{
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
return true;
}
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) {
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic"))
{
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
return true;
}
@ -161,15 +192,15 @@ public class Auto extends SubCommand {
}
final String worldname = world;
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld.TYPE == 2) {
if (plotworld.TYPE == 2)
{
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
final PlotCluster cluster = plot.getCluster();
// Must be standing in a cluster
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
@ -180,10 +211,12 @@ public class Auto extends SubCommand {
final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1);
final int max = width * width;
//
for (int i = 0; i <= max; i++) {
for (int i = 0; i <= max; i++)
{
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
final Plot current = MainUtil.getPlot(worldname, currentId);
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster())) {
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster()))
{
Claim.claimPlot(plr, current, true, true);
return true;
}
@ -194,40 +227,50 @@ public class Auto extends SubCommand {
return false;
}
boolean br = false;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
if ((size_x == 1) && (size_z == 1))
{
while (!br)
{
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
if (MainUtil.canClaim(plr, plot)) {
if (MainUtil.canClaim(plr, plot))
{
Claim.claimPlot(plr, plot, true, true);
br = true;
}
MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1));
}
} else {
}
else
{
boolean lastPlot = true;
while (!br) {
while (!br)
{
final PlotId start = getNextPlot(getLastPlot(worldname), 1);
// Checking if the current set of plots is a viable option.
MainUtil.lastPlot.put(worldname, start);
if (lastPlot) {
}
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null)) {
if (lastPlot)
{}
if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null))
{
continue;
} else {
}
else
{
lastPlot = false;
}
final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
if (MainUtil.canClaim(plr, worldname, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
if (MainUtil.canClaim(plr, worldname, start, end))
{
for (int i = start.x; i <= end.x; i++)
{
for (int j = start.y; j <= end.y; j++)
{
final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j));
final boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport, true);
}
}
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) {
return false;
}
if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) { return false; }
br = true;
}
}
@ -236,8 +279,10 @@ public class Auto extends SubCommand {
return true;
}
public PlotId getLastPlot(final String world) {
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) {
public PlotId getLastPlot(final String world)
{
if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world))
{
MainUtil.lastPlot.put(world, new PlotId(0, 0));
}
return MainUtil.lastPlot.get(world);

View File

@ -21,67 +21,65 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BO3Handler;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "bo3",
aliases = {"bo2"},
description = "Mark a plot as done",
permission = "plots.bo3",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class BO3 extends SubCommand {
command = "bo3",
aliases = { "bo2" },
description = "Mark a plot as done",
permission = "plots.bo3",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class BO3 extends SubCommand
{
public void noArgs(PlotPlayer plr) {
public void noArgs(final PlotPlayer plr)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 export [category] [alias] [-r]");
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot bo3 import <file>");
}
@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 || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3")) {
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.bo3"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length == 0) {
if (args.length == 0)
{
noArgs(plr);
return false;
}
switch (args[0].toLowerCase()) {
switch (args[0].toLowerCase())
{
case "output":
case "save":
case "export": {
case "export":
{
return BO3Handler.saveBO3(plr, plot);
}
case "paste":
case "load":
case "import":
case "input": {
case "input":
{
// TODO NOT IMPLEMENTED YET
MainUtil.sendMessage(plr, "NOT IMPLEMENTED YET!!!");
return false;
}
default: {
default:
{
noArgs(plr);
return false;
}

View File

@ -38,83 +38,78 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "buy",
aliases = {"b"},
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE
)
public class Buy extends SubCommand {
command = "buy",
aliases = { "b" },
description = "Buy the plot you are standing on",
usage = "/plot buy",
permission = "plots.buy",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE)
public class Buy extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
if (EconHandler.manager == null) {
return sendMessage(plr, C.ECON_DISABLED);
}
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if (EconHandler.manager == null) { return sendMessage(plr, C.ECON_DISABLED); }
final Location loc = plr.getLocation();
final String world = loc.getWorld();
if (!PS.get().isPlotWorld(world)) {
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
Plot plot;
if (args.length > 0) {
try {
if (args.length > 0)
{
try
{
final String[] split = args[0].split(";");
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
plot = MainUtil.getPlot(world, id);
} catch (final Exception e) {
}
catch (final Exception e)
{
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
} else {
}
else
{
plot = MainUtil.getPlot(loc);
}
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
if (!plot.hasOwner()) {
return sendMessage(plr, C.PLOT_UNOWNED);
}
if (PlotHandler.isOwner(plot, plr.getUUID())) {
return sendMessage(plr, C.CANNOT_BUY_OWN);
}
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); }
if (!plot.hasOwner()) { return sendMessage(plr, C.PLOT_UNOWNED); }
if (PlotHandler.isOwner(plot, plr.getUUID())) { return sendMessage(plr, C.CANNOT_BUY_OWN); }
final Flag flag = FlagManager.getPlotFlag(plot, "price");
if (flag == null) {
return sendMessage(plr, C.NOT_FOR_SALE);
}
if (flag == null) { return sendMessage(plr, C.NOT_FOR_SALE); }
double initPrice = (double) flag.getValue();
double price = initPrice;
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld.USE_ECONOMY) {
if (plotworld.USE_ECONOMY)
{
price += plotworld.PLOT_PRICE * size;
initPrice += plotworld.SELL_PRICE * size;
}
if ((EconHandler.manager != null) && (price > 0d)) {
if (EconHandler.manager.getMoney(plr) < price) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
}
if ((EconHandler.manager != null) && (price > 0d))
{
if (EconHandler.manager.getMoney(plr) < price) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price); }
EconHandler.manager.withdrawMoney(plr, price);
sendMessage(plr, C.REMOVED_BALANCE, price + "");
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), initPrice);
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
if (owner != null) {
if (owner != null)
{
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
}
FlagManager.removePlotFlag(plot, "price");
}
Plot top = MainUtil.getTopPlot(plot);
for (PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) {
Plot myPlot = MainUtil.getPlot(plot.world, myId);
final Plot top = MainUtil.getTopPlot(plot);
for (final PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id))
{
final Plot myPlot = MainUtil.getPlot(plot.world, myId);
myPlot.owner = plr.getUUID();
DBFunc.setOwner(plot, myPlot.owner);
}

View File

@ -1,23 +1,21 @@
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "chat",
description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]",
permission = "plots.chat",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Chat extends SubCommand {
command = "chat",
description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]",
permission = "plots.chat",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Chat extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
return MainCommand.onCommand(player, "plot", new String[] {"toggle", "chat"});
public boolean onCommand(final PlotPlayer player, final String... args)
{
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "chat" });
}
}

View File

@ -37,53 +37,64 @@ import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "claim",
aliases = {"c"},
description = "Claim the current plot you're standing on",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
permission = "plots.claim",
usage = "/plot claim"
)
public class Claim extends SubCommand {
command = "claim",
aliases = { "c" },
description = "Claim the current plot you're standing on",
category = CommandCategory.CLAIMING,
requiredType = RequiredType.NONE,
permission = "plots.claim",
usage = "/plot claim")
public class Claim extends SubCommand
{
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto) {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final boolean auto)
{
return claimPlot(player, plot, teleport, "", auto);
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
if (plot.hasOwner() || plot.getSettings().isMerged()) {
return false;
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto)
{
if (plot.hasOwner() || plot.getSettings().isMerged()) { return false; }
final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) {
if (result)
{
MainUtil.createPlot(player.getUUID(), plot);
MainUtil.setSign(player.getName(), plot);
MainUtil.sendMessage(player, C.CLAIMED);
final Location loc = player.getLocation();
if (teleport) {
if (teleport)
{
MainUtil.teleportPlayer(player, loc, plot);
}
final String world = plot.world;
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final Plot plot2 = PS.get().getPlot(world, plot.id);
if (plotworld.SCHEMATIC_ON_CLAIM) {
if (plotworld.SCHEMATIC_ON_CLAIM)
{
Schematic sch;
if (schematic.equals("")) {
if (schematic.equals(""))
{
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
} else {
}
else
{
sch = SchematicHandler.manager.getSchematic(schematic);
if (sch == null) {
if (sch == null)
{
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
}
}
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>() {
SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal<Boolean>()
{
@Override
public void run() {
if (value) {
public void run()
{
if (value)
{
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS);
}
else {
else
{
MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_FAILED);
}
}
@ -95,43 +106,38 @@ public class Claim extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
String schematic = "";
if (args.length >= 1) {
if (args.length >= 1)
{
schematic = args[0];
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); }
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
if (!MainUtil.canClaim(plr, plot)) {
return sendMessage(plr, C.PLOT_IS_CLAIMED);
}
if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); }
if (!MainUtil.canClaim(plr, plot)) { return sendMessage(plr, C.PLOT_IS_CLAIMED); }
final PlotWorld world = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && world.USE_ECONOMY) {
if ((EconHandler.manager != null) && world.USE_ECONOMY)
{
final double cost = world.PLOT_PRICE;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
}
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost) { return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost); }
EconHandler.manager.withdrawMoney(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
if (!schematic.equals("")) {
if (world.SCHEMATIC_CLAIM_SPECIFY) {
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) {
return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
}
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) {
return sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
}
if (!schematic.equals(""))
{
if (world.SCHEMATIC_CLAIM_SPECIFY)
{
if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { return sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); }
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !Permissions.hasPermission(plr, "plots.admin.command.schematic")) { return sendMessage(plr,
C.NO_SCHEMATIC_PERMISSION, schematic); }
}
}
return claimPlot(plr, plot, false, schematic, false) || sendMessage(plr, C.PLOT_NOT_CLAIMED);

View File

@ -38,86 +38,105 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "clear",
description = "Clear a plot",
permission = "plots.clear",
category = CommandCategory.ACTIONS,
usage = "/plot clear [id]"
)
public class Clear extends SubCommand {
command = "clear",
description = "Clear a plot",
permission = "plots.clear",
category = CommandCategory.ACTIONS,
usage = "/plot clear [id]")
public class Clear extends SubCommand
{
@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;
if (args.length == 2) {
PlotId id = PlotId.fromString(args[0]);
if (id == null) {
if (args[1].equalsIgnoreCase("mine")) {
Set<Plot> plots = PS.get().getPlots(plr);
if (plots.size() == 0) {
if (args.length == 2)
{
final PlotId id = PlotId.fromString(args[0]);
if (id == null)
{
if (args[1].equalsIgnoreCase("mine"))
{
final Set<Plot> plots = PS.get().getPlots(plr);
if (plots.size() == 0)
{
MainUtil.sendMessage(plr, C.NO_PLOTS);
return false;
}
plot = plots.iterator().next();
}
else {
else
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
return false;
}
}
else {
else
{
plot = MainUtil.getPlot(loc.getWorld(), id);
}
}
else {
else
{
plot = MainUtil.getPlot(loc);
}
if (plot == null) {
if (plot == null)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
return sendMessage(plr, C.NOT_IN_PLOT);
}
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
// return sendMessage(plr, C.UNLINK_REQUIRED);
// }
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
// return sendMessage(plr, C.UNLINK_REQUIRED);
// }
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
assert plot != null;
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (FlagManager.getPlotFlag(plot, "done") != null && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))) {
if ((FlagManager.getPlotFlag(plot, "done") != null)
&& (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))))
{
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false;
}
Runnable runnable = new Runnable() {
final Runnable runnable = new Runnable()
{
@Override
public void run() {
public void run()
{
final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable()
{
@Override
public void run() {
public void run()
{
// If the state changes, then mark it as no longer done
if (FlagManager.getPlotFlag(plot, "done" ) != null) {
if (FlagManager.getPlotFlag(plot, "done") != null)
{
FlagManager.removePlotFlag(plot, "done");
}
if (FlagManager.getPlotFlag(plot, "analysis") != null) {
if (FlagManager.getPlotFlag(plot, "analysis") != null)
{
FlagManager.removePlotFlag(plot, "analysis");
}
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
});
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
}
}
};
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
{
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
}
else {
else
{
TaskManager.runTask(runnable);
}
return true;

View File

@ -53,60 +53,77 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "cluster",
aliases = {"clusters"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.cluster",
description = "Manage a plot cluster"
)
public class Cluster extends SubCommand {
command = "cluster",
aliases = { "clusters" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.cluster",
description = "Manage a plot cluster")
public class Cluster extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
if (args.length == 0) {
if (args.length == 0)
{
// return arguments
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
return false;
}
final String sub = args[0].toLowerCase();
switch (sub) {
switch (sub)
{
case "l":
case "list": {
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
case "list":
{
if (!Permissions.hasPermission(plr, "plots.cluster.list"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
return false;
}
if (args.length != 1) {
if (args.length != 1)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
return false;
}
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
for (final PlotCluster cluster : clusters) {
for (final PlotCluster cluster : clusters)
{
// Ignore unmanaged clusters
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
if (UUIDHandler.getUUID(plr).equals(cluster.owner))
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
} else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
}
else if (cluster.helpers.contains(UUIDHandler.getUUID(plr)))
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
} else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
}
else if (cluster.invited.contains(UUIDHandler.getUUID(plr)))
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
} else {
}
else
{
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
}
}
return true;
}
case "c":
case "create": {
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
case "create":
{
if (!Permissions.hasPermission(plr, "plots.cluster.create"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
return false;
}
if (args.length != 4) {
if (args.length != 4)
{
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
@ -115,37 +132,46 @@ public class Cluster extends SubCommand {
// check pos1 / pos2
PlotId pos1 = MainUtil.parseId(args[2]);
PlotId pos2 = MainUtil.parseId(args[3]);
if ((pos1 == null) || (pos2 == null)) {
if ((pos1 == null) || (pos2 == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
// check if name is taken
final String name = args[1];
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
if (name.equals(cluster.getName())) {
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld()))
{
if (name.equals(cluster.getName()))
{
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
}
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
if ((pos2.x < pos1.x) || (pos2.y < pos1.y))
{
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
}
//check if overlap
String world = plr.getLocation().getWorld();
final String world = plr.getLocation().getWorld();
final PlotClusterId id = new PlotClusterId(pos1, pos2);
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
if ((intersects.size() > 0)) {
if ((intersects.size() > 0))
{
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false;
}
// Check if it occupies existing plots
Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
if (plots.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) {
UUID uuid = plr.getUUID();
for (Plot plot : plots) {
if (!plot.isOwner(uuid)) {
final Set<Plot> plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
if (plots.size() > 0)
{
if (!Permissions.hasPermission(plr, "plots.cluster.create.other"))
{
final UUID uuid = plr.getUUID();
for (final Plot plot : plots)
{
if (!plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other");
return false;
}
@ -155,64 +181,76 @@ public class Cluster extends SubCommand {
// Check allowed cluster size
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
int current;
if (Settings.GLOBAL_LIMIT) {
if (Settings.GLOBAL_LIMIT)
{
current = ClusterManager.getPlayerClusterCount(plr);
}
else {
else
{
current = ClusterManager.getPlayerClusterCount(world, plr);
}
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if ((current + cluster.getArea()) > allowed)
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
return false;
}
// Set the generator (if applicable)
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null)
{
PS.get().config.createSection("worlds." + world);
PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null));
}
else {
else
{
String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
if (gen_string == null) {
if (gen_string == null)
{
gen_string = "PlotSquared";
}
PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
if (wrapper.isFull()) {
final PlotGenerator<?> wrapper = PS.get().IMP.getGenerator(world, gen_string);
if (wrapper.isFull())
{
wrapper.augment(cluster, plotworld);
}
else {
else
{
MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
return false;
}
// BukkitPlotGenerator generator;
// if (gen_string == null) {
// generator = new HybridGen(world);
// } else {
// ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator;
// if (chunkgen instanceof BukkitPlotGenerator) {
// generator = (BukkitPlotGenerator) chunkgen;
// }
// else {
// MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
// return false;
// }
// }
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
// BukkitPlotGenerator generator;
// if (gen_string == null) {
// generator = new HybridGen(world);
// } else {
// ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator;
// if (chunkgen instanceof BukkitPlotGenerator) {
// generator = (BukkitPlotGenerator) chunkgen;
// }
// else {
// MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
// return false;
// }
// }
// new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
// create cluster
cluster.settings.setAlias(name);
DBFunc.createCluster(world, cluster);
if (!ClusterManager.clusters.containsKey(world)) {
if (!ClusterManager.clusters.containsKey(world))
{
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
}
ClusterManager.clusters.get(world).add(cluster);
// Add any existing plots to the current cluster
for (Plot plot : plots) {
if (plot.hasOwner()) {
Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
for (final Plot plot : plots)
{
if (plot.hasOwner())
{
final Flag flag = new Flag(FlagManager.getFlag("cluster"), cluster);
FlagManager.addPlotFlag(plot, flag);
if (!cluster.isAdded(plot.owner)) {
if (!cluster.isAdded(plot.owner))
{
cluster.invited.add(plot.owner);
DBFunc.setInvited(world, cluster, plot.owner);
}
@ -223,50 +261,65 @@ public class Cluster extends SubCommand {
}
case "disband":
case "del":
case "delete": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
case "delete":
{
if (!Permissions.hasPermission(plr, "plots.cluster.delete"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other")) {
if (!cluster.owner.equals(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
return false;
}
}
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
if (plotworld.TYPE == 2) {
if (plotworld.TYPE == 2)
{
final ArrayList<Plot> toRemove = new ArrayList<>();
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld()))
{
final PlotCluster other = ClusterManager.getCluster(plot);
if (cluster.equals(other)) {
if (cluster.equals(other))
{
toRemove.add(plot);
}
}
for (final Plot plot : toRemove) {
for (final Plot plot : toRemove)
{
plot.unclaim();
}
}
DBFunc.delete(cluster);
if (plotworld.TYPE == 2) {
if (plotworld.TYPE == 2)
{
SetupUtils.manager.removePopulator(plr.getLocation().getWorld(), cluster);
}
ClusterManager.last = null;
@ -276,36 +329,44 @@ public class Cluster extends SubCommand {
return true;
}
case "res":
case "resize": {
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
case "resize":
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
return false;
}
if (args.length != 3) {
if (args.length != 3)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
return false;
}
// check pos1 / pos2
PlotId pos1 = MainUtil.parseId(args[1]);
PlotId pos2 = MainUtil.parseId(args[2]);
if ((pos1 == null) || (pos2 == null)) {
if ((pos1 == null) || (pos2 == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
if ((pos2.x < pos1.x) || (pos2.y < pos1.y))
{
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
}
// check if in cluster
Location loc = plr.getLocation();
String world = loc.getWorld();
final Location loc = plr.getLocation();
final String world = loc.getWorld();
final PlotCluster cluster = ClusterManager.getCluster(loc);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
return false;
}
@ -313,46 +374,56 @@ public class Cluster extends SubCommand {
//check if overlap
final PlotClusterId id = new PlotClusterId(pos1, pos2);
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(world, id);
if (intersects.size() > 1) {
if (intersects.size() > 1)
{
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
return false;
}
HashSet<Plot> existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2());
HashSet<Plot> newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
final HashSet<Plot> existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2());
final HashSet<Plot> newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2);
final HashSet<Plot> removed = ((HashSet<Plot>) existing.clone());
removed.removeAll(newplots);
// Check expand / shrink
if (removed.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink")) {
if (removed.size() > 0)
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize.shrink"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.shrink");
return false;
}
}
newplots.removeAll(existing);
if (newplots.size() > 0) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand")) {
if (newplots.size() > 0)
{
if (!Permissions.hasPermission(plr, "plots.cluster.resize.expand"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.expand");
return false;
}
}
// Check allowed cluster size
int current;
if (Settings.GLOBAL_LIMIT) {
if (Settings.GLOBAL_LIMIT)
{
current = ClusterManager.getPlayerClusterCount(plr);
}
else {
else
{
current = ClusterManager.getPlayerClusterCount(world, plr);
}
current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if (current + cluster.getArea() > allowed) {
current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y));
final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS);
if ((current + cluster.getArea()) > allowed)
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea()));
return false;
}
for (Plot plot : removed) {
for (final Plot plot : removed)
{
FlagManager.removePlotFlag(plot, "cluster");
}
for (Plot plot : newplots) {
for (final Plot plot : newplots)
{
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster));
}
// resize cluster
@ -362,76 +433,95 @@ public class Cluster extends SubCommand {
}
case "reg":
case "regenerate":
case "regen": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
case "regen":
{
if (!Permissions.hasPermission(plr, "plots.cluster.delete"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
if (!cluster.owner.equals(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
return false;
}
}
long start = System.currentTimeMillis();
final long start = System.currentTimeMillis();
ClusterManager.regenCluster(cluster);
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED, (System.currentTimeMillis() - start) + "");
return true;
}
case "add":
case "inv":
case "invite": {
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
case "invite":
{
if (!Permissions.hasPermission(plr, "plots.cluster.invite"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
return false;
}
// check if in cluster
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite.other");
return false;
}
}
// check uuid
final UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
return false;
}
if (!cluster.isAdded(uuid)) {
if (!cluster.isAdded(uuid))
{
// add the user if not added
cluster.invited.add(uuid);
final String world = plr.getLocation().getWorld();
DBFunc.setInvited(world, cluster, uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
if (player != null)
{
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
}
}
@ -440,51 +530,63 @@ public class Cluster extends SubCommand {
}
case "k":
case "remove":
case "kick": {
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
case "kick":
{
if (!Permissions.hasPermission(plr, "plots.cluster.kick"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick.other");
return false;
}
}
// check uuid
final UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[1]);
return false;
}
// Can't kick if the player is yourself, the owner, or not added to the cluster
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid))
{
MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
return false;
}
if (cluster.helpers.contains(uuid)) {
if (cluster.helpers.contains(uuid))
{
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
if (player != null)
{
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
}
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid)))
{
final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld();
if ((current != null) && current.equals(cluster))
{
plr.getLocation().getWorld();
plot.unclaim();
}
}
@ -492,49 +594,62 @@ public class Cluster extends SubCommand {
return true;
}
case "quit":
case "leave": {
if (!Permissions.hasPermission(plr, "plots.cluster.leave")) {
case "leave":
{
if (!Permissions.hasPermission(plr, "plots.cluster.leave"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
final UUID uuid = UUIDHandler.getUUID(plr);
if (!cluster.isAdded(uuid)) {
if (!cluster.isAdded(uuid))
{
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
return false;
}
if (uuid.equals(cluster.owner)) {
if (uuid.equals(cluster.owner))
{
MainUtil.sendMessage(plr, C.CLUSTER_CANNOT_LEAVE);
return false;
}
if (cluster.helpers.contains(uuid)) {
if (cluster.helpers.contains(uuid))
{
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid)))
{
final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld();
if ((current != null) && current.equals(cluster))
{
plr.getLocation().getWorld();
plot.unclaim();
}
}
@ -542,31 +657,38 @@ public class Cluster extends SubCommand {
}
case "admin":
case "helper":
case "helpers": {
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
case "helpers":
{
if (!Permissions.hasPermission(plr, "plots.cluster.helpers"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
return false;
}
if (args.length != 3) {
if (args.length != 3)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
final UUID uuid = UUIDHandler.getUUID(args[2], null);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
return false;
}
if (args[1].toLowerCase().equals("add")) {
if (args[1].toLowerCase().equals("add"))
{
cluster.helpers.add(uuid);
DBFunc.setHelper(cluster, uuid);
return MainUtil.sendMessage(plr, C.CLUSTER_ADDED_HELPER);
}
if (args[1].toLowerCase().equals("remove")) {
if (args[1].toLowerCase().equals("remove"))
{
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
@ -576,23 +698,29 @@ public class Cluster extends SubCommand {
}
case "spawn":
case "home":
case "tp": {
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
case "tp":
{
if (!Permissions.hasPermission(plr, "plots.cluster.tp"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
final UUID uuid = UUIDHandler.getUUID(plr);
if (!cluster.isAdded(uuid)) {
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
if (!cluster.isAdded(uuid))
{
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
return false;
}
@ -603,32 +731,41 @@ public class Cluster extends SubCommand {
case "i":
case "info":
case "show":
case "information": {
if (!Permissions.hasPermission(plr, "plots.cluster.info")) {
case "information":
{
if (!Permissions.hasPermission(plr, "plots.cluster.info"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
return false;
}
PlotCluster cluster;
if (args.length == 2) {
if (args.length == 2)
{
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
} else {
}
else
{
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
final String id = cluster.toString();
String owner = UUIDHandler.getName(cluster.owner);
if (owner == null) {
if (owner == null)
{
owner = "unknown";
}
final String name = cluster.getName();
@ -645,22 +782,28 @@ public class Cluster extends SubCommand {
}
case "sh":
case "setspawn":
case "sethome": {
if (!Permissions.hasPermission(plr, "plots.cluster.sethome")) {
case "sethome":
{
if (!Permissions.hasPermission(plr, "plots.cluster.sethome"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome");
return false;
}
if ((args.length != 1) && (args.length != 2)) {
if ((args.length != 1) && (args.length != 2))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
return false;
}
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
if (cluster == null)
{
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other")) {
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr)))
{
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
return false;
}

View File

@ -1,58 +1,59 @@
package com.intellectualcrafters.plot.commands;
/**
* CommandCategory
*
* @author Citymonstret
* @author Empire92
*/
public enum CommandCategory {
/**
* Claiming Commands
*
* Such as: /plot claim
*/
CLAIMING("Claiming"),
/**
* Teleportation Commands
*
* Such as: /plot visit
*/
TELEPORT("Teleportation"),
/**
* Action Commands
*
* Such as: /plot clear
*/
ACTIONS("Actions"),
/**
* Information Commands
*
* Such as: /plot info
*/
INFO("Information"),
/**
* Debug Commands
*
* Such as: /plot debug
*/
DEBUG("Debug");
/**
* The category name (Readable)
*/
private final String name;
/**
* Constructor
*
* @param name readable name
*/
CommandCategory(final String name) {
this.name = name;
}
@Override
public String toString() {
return this.name;
}
}
package com.intellectualcrafters.plot.commands;
/**
* CommandCategory
*
*/
public enum CommandCategory
{
/**
* Claiming Commands
*
* Such as: /plot claim
*/
CLAIMING("Claiming"),
/**
* Teleportation Commands
*
* Such as: /plot visit
*/
TELEPORT("Teleportation"),
/**
* Action Commands
*
* Such as: /plot clear
*/
ACTIONS("Actions"),
/**
* Information Commands
*
* Such as: /plot info
*/
INFO("Information"),
/**
* Debug Commands
*
* Such as: /plot debug
*/
DEBUG("Debug");
/**
* The category name (Readable)
*/
private final String name;
/**
* Constructor
*
* @param name readable name
*/
CommandCategory(final String name)
{
this.name = name;
}
@Override
public String toString()
{
return name;

View File

@ -1,52 +1,54 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Created by Citymonstret on 2014-08-03.
*
* @author Citymonstret
*/
public class CommandPermission {
/**
* Permission Node
*/
public final String permission;
/**
* @param permission Command Permission
*/
public CommandPermission(final String permission) {
this.permission = permission.toLowerCase();
}
/**
* @param player Does the player have the permission?
*
* @return true of player has the required permission node
*/
public boolean hasPermission(final PlotPlayer player) {
return Permissions.hasPermission(player, this.permission);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
/**
* Created by Citymonstret on 2014-08-03.
*
*/
public class CommandPermission
{
/**
* Permission Node
*/
public final String permission;
/**
* @param permission Command Permission
*/
public CommandPermission(final String permission)
{
this.permission = permission.toLowerCase();
}
/**
* @param player Does the player have the permission?
*
* @return true of player has the required permission node
*/
public boolean hasPermission(final PlotPlayer player)
{
return Permissions.hasPermission(player, permission);
}

View File

@ -36,56 +36,66 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "comment",
aliases = {"msg"},
description = "Comment on a plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.comment"
)
public class Comment extends SubCommand {
command = "comment",
aliases = { "msg" },
description = "Comment on a plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.comment")
public class Comment extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (args.length < 2) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (args.length < 2)
{
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null)
{
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
Plot plot;
Location loc = player.getLocation();
PlotId id = PlotId.fromString(args[1]);
final Location loc = player.getLocation();
final PlotId id = PlotId.fromString(args[1]);
int index;
if (id != null) {
if (args.length < 4) {
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
if (id != null)
{
if (args.length < 4)
{
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
index = 2;
plot = MainUtil.getPlot(loc.getWorld(), id);
}
else {
else
{
index = 1;
plot = MainUtil.getPlot(loc);
}
if (!inbox.canWrite(plot, player)) {
if (!inbox.canWrite(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX, "");
return false;
}
String message = StringMan.join(Arrays.copyOfRange(args,index, args.length), " ");
PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
boolean result = inbox.addComment(plot, comment);
if (!result) {
final String message = StringMan.join(Arrays.copyOfRange(args, index, args.length), " ");
final PlotComment comment = new PlotComment(loc.getWorld(), id, message, player.getName(), inbox.toString(), System.currentTimeMillis());
final boolean result = inbox.addComment(plot, comment);
if (!result)
{
sendMessage(player, C.NO_PLOT_INBOX, "");
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(),"|"));
sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
if (pp.getAttribute("chatspy")) {
for (final PlotPlayer pp : UUIDHandler.getPlayers().values())
{
if (pp.getAttribute("chatspy"))
{
MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " "));
}
}

View File

@ -36,42 +36,51 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "condense",
permission = "plots.admin",
description = "Condense a plotworld",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE
)
public class Condense extends SubCommand {
command = "condense",
permission = "plots.admin",
description = "Condense a plotworld",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE)
public class Condense extends SubCommand
{
public static boolean TASK = false;
@Override
public boolean onCommand(final PlotPlayer plr, String ... args) {
if ((args.length != 2) && (args.length != 3)) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if ((args.length != 2) && (args.length != 3))
{
MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
return false;
}
final String worldname = args[0];
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) {
if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname))
{
MainUtil.sendMessage(plr, "INVALID WORLD");
return false;
}
switch (args[1].toLowerCase()) {
case "start": {
if (args.length == 2) {
switch (args[1].toLowerCase())
{
case "start":
{
if (args.length == 2)
{
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
return false;
}
if (TASK) {
if (TASK)
{
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
return false;
}
if (args.length == 2) {
if (args.length == 2)
{
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
return false;
}
if (!MathMan.isInteger(args[2])) {
if (!MathMan.isInteger(args[2]))
{
MainUtil.sendMessage(plr, "INVALID RADIUS");
return false;
}
@ -79,61 +88,76 @@ public class Condense extends SubCommand {
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final int size = plots.size();
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
if (radius < minimum_radius) {
if (radius < minimum_radius)
{
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
return false;
}
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
final List<PlotId> free = new ArrayList<>();
PlotId start = new PlotId(0, 0);
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
while ((start.x <= minimum_radius) && (start.y <= minimum_radius))
{
final Plot plot = MainUtil.getPlot(worldname, start);
if (!plot.hasOwner()) {
if (!plot.hasOwner())
{
free.add(plot.id);
}
start = Auto.getNextPlot(start, 1);
}
if (free.size() == 0 || to_move.size() == 0) {
if ((free.size() == 0) || (to_move.size() == 0))
{
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
return false;
}
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() {
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable()
{
@Override
public void run() {
if (!TASK) {
public void run()
{
if (!TASK)
{
MainUtil.sendMessage(plr, "CONDENSE TASK CANCELLED");
return;
}
to_move.remove(0);
free.remove(0);
int index = 0;
for (final PlotId id : to_move) {
for (final PlotId id : to_move)
{
final Plot plot = MainUtil.getPlot(worldname, id);
if (plot.hasOwner()) {
if (plot.hasOwner())
{
break;
}
index++;
}
for (int i = 0; i < index; i++) {
for (int i = 0; i < index; i++)
{
to_move.remove(0);
}
index = 0;
for (final PlotId id : free) {
for (final PlotId id : free)
{
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plot.hasOwner()) {
if (!plot.hasOwner())
{
break;
}
index++;
}
for (int i = 0; i < index; i++) {
for (int i = 0; i < index; i++)
{
free.remove(0);
}
if (to_move.size() == 0) {
if (to_move.size() == 0)
{
MainUtil.sendMessage(plr, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
TASK = false;
return;
}
if (free.size() == 0) {
if (free.size() == 0)
{
MainUtil.sendMessage(plr, "TASK FAILED. NO FREE PLOTS FOUND!");
TASK = false;
return;
@ -146,8 +170,10 @@ public class Condense extends SubCommand {
MainUtil.sendMessage(plr, "TASK STARTED...");
return true;
}
case "stop": {
if (!TASK) {
case "stop":
{
if (!TASK)
{
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
return false;
}
@ -155,12 +181,15 @@ public class Condense extends SubCommand {
MainUtil.sendMessage(plr, "TASK STOPPED");
return true;
}
case "info": {
if (args.length == 2) {
case "info":
{
if (args.length == 2)
{
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
return false;
}
if (!MathMan.isInteger(args[2])) {
if (!MathMan.isInteger(args[2]))
{
MainUtil.sendMessage(plr, "INVALID RADIUS");
return false;
}
@ -168,7 +197,8 @@ public class Condense extends SubCommand {
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final int size = plots.size();
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
if (radius < minimum_radius) {
if (radius < minimum_radius)
{
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
return false;
}
@ -189,10 +219,13 @@ public class Condense extends SubCommand {
return false;
}
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius) {
public Set<PlotId> getPlots(final Collection<Plot> plots, final int radius)
{
final HashSet<PlotId> outside = new HashSet<>();
for (final Plot plot : plots) {
if ((plot.id.x > radius) || (plot.id.x < -radius) || (plot.id.y > radius) || (plot.id.y < -radius)) {
for (final Plot plot : plots)
{
if ((plot.id.x > radius) || (plot.id.x < -radius) || (plot.id.y > radius) || (plot.id.y < -radius))
{
outside.add(plot.id);
}
}

View File

@ -20,7 +20,6 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.CmdInstance;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -30,26 +29,29 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "confirm",
permission = "plots.use",
description = "Confirm an action",
category = CommandCategory.ACTIONS
)
public class Confirm extends SubCommand {
command = "confirm",
permission = "plots.use",
description = "Confirm an action",
category = CommandCategory.ACTIONS)
public class Confirm extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
CmdInstance command = CmdConfirm.getPending(plr);
if (command == null) {
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
CmdConfirm.removePending(plr);
if (System.currentTimeMillis() - command.timestamp > 20000) {
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
TaskManager.runTask(command.command);
return true;
@Override
public boolean onCommand(final PlotPlayer plr, final String... args)
{
final CmdInstance command = CmdConfirm.getPending(plr);
if (command == null)
{
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
CmdConfirm.removePending(plr);
if ((System.currentTimeMillis() - command.timestamp) > 20000)
{
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
return false;
}
TaskManager.runTask(command.command);
return true;
}
}

View File

@ -22,49 +22,46 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "continue",
description = "Continue a plot that was previously marked as done",
permission = "plots.continue",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Continue extends SubCommand {
command = "continue",
description = "Continue a plot that was previously marked as done",
permission = "plots.continue",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Continue extends SubCommand
{
@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 || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.continue")) {
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.continue"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (!plot.getSettings().flags.containsKey("done")) {
if (!plot.getSettings().flags.containsKey("done"))
{
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
return false;
}
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)) {
if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr)))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}

View File

@ -31,53 +31,61 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "copy",
permission = "plots.copy",
aliases = {"copypaste"},
category = CommandCategory.ACTIONS,
description = "Copy a plot",
usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE
)
public class Copy extends SubCommand {
command = "copy",
permission = "plots.copy",
aliases = { "copypaste" },
category = CommandCategory.ACTIONS,
description = "Copy a plot",
usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE)
public class Copy extends SubCommand
{
public Copy() {
public Copy()
{
requiredArguments = new Argument[] {
Argument.PlotID
Argument.PlotID
};
}
@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 plot1 = MainUtil.getPlot(loc);
if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
if (plot1 == null) { return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s()))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final String world = loc.getWorld();
final PlotId plot2 = MainUtil.parseId(args[0]);
if ((plot2 == null)) {
if ((plot2 == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (plot1.id.equals(plot2)) {
if (plot1.id.equals(plot2))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (MainUtil.copy(world, plot1.id, plot2, new Runnable() {
if (MainUtil.copy(world, plot1.id, plot2, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
}
})) {
}))
{
return true;
} else {
}
else
{
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
return false;
}

View File

@ -31,26 +31,23 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "createroadschematic",
aliases = {"crs"},
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.createroadschematic",
description = "Add a road schematic to your world using the roads around your current plot",
usage = "/plot createroadschematic"
)
public class CreateRoadSchematic extends SubCommand {
command = "createroadschematic",
aliases = { "crs" },
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.createroadschematic",
description = "Add a road schematic to your world using the roads around your current plot",
usage = "/plot createroadschematic")
public class CreateRoadSchematic extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT);
}
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
}
if (plot == null) { return sendMessage(player, C.NOT_IN_PLOT); }
if (!(PS.get().getPlotWorld(loc.getWorld()) instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); }
HybridUtils.manager.setupRoadSchematic(plot);
MainUtil.sendMessage(player, "&6Saved new road schematic. To test the road, fly to a few other plots and use /plot debugroadregen");
return true;

View File

@ -3,12 +3,10 @@ package com.intellectualcrafters.plot.commands;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.database.MySQL;
import com.intellectualcrafters.plot.database.SQLManager;
@ -21,35 +19,45 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "database",
aliases = {"convert"},
category = CommandCategory.DEBUG,
permission = "plots.database",
description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE,
usage = "/plots database [world] <sqlite|mysql|import>"
)
public class Database extends SubCommand {
command = "database",
aliases = { "convert" },
category = CommandCategory.DEBUG,
permission = "plots.database",
description = "Convert/Backup Storage",
requiredType = RequiredType.CONSOLE,
usage = "/plots database [world] <sqlite|mysql|import>"
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player) {
TaskManager.runTaskAsync(new Runnable() {
)
public class Database extends SubCommand
{
public static void insertPlots(final SQLManager manager, final ArrayList<Plot> plots, final PlotPlayer player)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
public void run()
{
try
{
final ArrayList<Plot> ps = new ArrayList<>();
for (final Plot p : plots) {
for (final Plot p : plots)
{
ps.add(p);
}
MainUtil.sendMessage(player, "&6Starting...");
manager.createPlotsAndData(ps, new Runnable() {
manager.createPlotsAndData(ps, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&6Database conversion finished!");
manager.close();
}
});
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(player, "Failed to insert plot objects, see stacktrace for info");
e.printStackTrace();
}
@ -58,42 +66,54 @@ public class Database extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length < 1) {
public boolean onCommand(final PlotPlayer player, String[] args)
{
if (args.length < 1)
{
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql>");
return false;
}
ArrayList<Plot> plots;
if (PS.get().isPlotWorld(args[0])) {
if (PS.get().isPlotWorld(args[0]))
{
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsInWorld(args[0]));
args = Arrays.copyOfRange(args, 1, args.length);
}
else {
else
{
plots = PS.get().sortPlotsByTemp(PS.get().getPlotsRaw());
}
if (args.length < 1) {
if (args.length < 1)
{
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
MainUtil.sendMessage(player, "[arg] indicates an optional argument");
return false;
}
try {
try
{
com.intellectualcrafters.plot.database.Database implementation;
String prefix = "";
switch (args[0].toLowerCase()) {
case "import": {
if (args.length < 2) {
switch (args[0].toLowerCase())
{
case "import":
{
if (args.length < 2)
{
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
return false;
}
MainUtil.sendMessage(player, "&6Starting...");
implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db");
SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<Plot>();
for (Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet()) {
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
Plot plot = entry2.getValue();
if (PS.get().getPlot(plot.world, plot.id) != null) {
for (final Entry<String, ConcurrentHashMap<PlotId, Plot>> entry : map.entrySet())
{
for (final Entry<PlotId, Plot> entry2 : entry.getValue().entrySet())
{
final Plot plot = entry2.getValue();
if (PS.get().getPlot(plot.world, plot.id) != null)
{
MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp);
continue;
}
@ -101,43 +121,44 @@ public class Database extends SubCommand {
plots.add(entry2.getValue());
}
}
DBFunc.createPlotsAndData(plots, new Runnable() {
DBFunc.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&6Database conversion finished!");
}
});
return true;
}
case "mysql":
if (args.length < 6) {
return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}");
}
if (args.length < 6) { return MainUtil.sendMessage(player, "/plot database mysql [host] [port] [username] [password] [database] {prefix}"); }
final String host = args[1];
final String port = args[2];
final String username = args[3];
final String password = args[4];
final String database = args[5];
if (args.length > 6) {
if (args.length > 6)
{
prefix = args[6];
}
implementation = new MySQL(host, port, database, username, password);
break;
case "sqlite":
if (args.length < 2) {
return MainUtil.sendMessage(player, "/plot database sqlite [file]");
}
if (args.length < 2) { return MainUtil.sendMessage(player, "/plot database sqlite [file]"); }
implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db");
break;
default:
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
}
try {
try
{
final SQLManager manager = new SQLManager(implementation, prefix, true);
insertPlots(manager, plots, player);
return true;
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, "$1Failed to save plots, read stacktrace for info");
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace();
@ -146,7 +167,8 @@ public class Database extends SubCommand {
return false;
}
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, "$1Failed to open connection, read stacktrace for info");
MainUtil.sendMessage(player, "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace();

View File

@ -28,19 +28,22 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debug",
category = CommandCategory.DEBUG,
description = "Show debug information",
usage = "/plot debug [msg]",
permission = "plots.admin"
)
public class Debug extends SubCommand {
command = "debug",
category = CommandCategory.DEBUG,
description = "Show debug information",
usage = "/plot debug [msg]",
permission = "plots.admin")
public class Debug extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
if ((args.length > 0) && args[0].equalsIgnoreCase("msg")) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if ((args.length > 0) && args[0].equalsIgnoreCase("msg"))
{
final StringBuilder msg = new StringBuilder();
for (final C c : C.values()) {
for (final C c : C.values())
{
msg.append(c.s()).append("\n");
}
MainUtil.sendMessage(plr, msg.toString());
@ -56,7 +59,8 @@ public class Debug extends SubCommand {
}
{
final StringBuilder worlds = new StringBuilder("");
for (final String world : PS.get().getPlotWorlds()) {
for (final String world : PS.get().getPlotWorlds())
{
worlds.append(world).append(" ");
}
information.append(header);
@ -77,11 +81,13 @@ public class Debug extends SubCommand {
return true;
}
private String getSection(final String line, final String val) {
private String getSection(final String line, final String val)
{
return line.replaceAll("%val%", val) + "\n";
}
private String getLine(final String line, final String var, final Object val) {
private String getLine(final String line, final String var, final Object val)
{
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
}
}

View File

@ -9,24 +9,28 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugallowunsafe",
description = "Allow unsafe actions until toggled off",
usage = "/plot debugallowunsafe",
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.debugallowunsafe"
)
public class DebugAllowUnsafe extends SubCommand {
command = "debugallowunsafe",
description = "Allow unsafe actions until toggled off",
usage = "/plot debugallowunsafe",
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE,
permission = "plots.debugallowunsafe")
public class DebugAllowUnsafe extends SubCommand
{
public static final List<UUID> unsafeAllowed = new ArrayList<>();
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
if (unsafeAllowed.contains(plr.getUUID())) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if (unsafeAllowed.contains(plr.getUUID()))
{
unsafeAllowed.remove(plr.getUUID());
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
} else {
}
else
{
unsafeAllowed.add(plr.getUUID());
sendMessage(plr, C.DEBUGALLOWUNSAFE_ON);
}

View File

@ -43,25 +43,29 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugclaimtest",
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot sighs. Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.debugclaimtest"
)
public class DebugClaimTest extends SubCommand {
command = "debugclaimtest",
description = "If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot sighs. Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.debugclaimtest")
public class DebugClaimTest extends SubCommand
{
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport) {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport)
{
return claimPlot(player, plot, teleport, "");
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) {
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic)
{
final boolean result = EventUtil.manager.callClaim(player, plot, false);
if (result) {
if (result)
{
MainUtil.createPlot(player.getUUID(), plot);
MainUtil.setSign(player.getName(), plot);
MainUtil.sendMessage(player, C.CLAIMED);
if (teleport) {
if (teleport)
{
MainUtil.teleportPlayer(player, player.getLocation(), plot);
}
}
@ -69,81 +73,103 @@ public class DebugClaimTest extends SubCommand {
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
if (args.length < 3) {
return !MainUtil.sendMessage(null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
}
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length < 3) { return !MainUtil
.sendMessage(
null,
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}"); }
final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
return !MainUtil.sendMessage(null, "&cInvalid plot world!");
}
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { return !MainUtil.sendMessage(null, "&cInvalid plot world!"); }
PlotId min, max;
try {
final String[] split1 = args[1].split(";");
final String[] split2 = args[2].split(";");
try
{
args[1].split(";");
args[2].split(";");
min = PlotId.fromString(args[1]);
max = PlotId.fromString(args[2]);
} catch (final Exception e) {
return !MainUtil.sendMessage(null, "&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion will only check the plots in the selected area.");
}
catch (final Exception e)
{
return !MainUtil.sendMessage(null,
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion will only check the plots in the selected area.");
}
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
final PlotManager manager = PS.get().getPlotManager(world);
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max))
{
final Plot plot = MainUtil.getPlot(world, id);
if (PS.get().getPlot(world, plot.id) != null) {
if (PS.get().getPlot(world, plot.id) != null)
{
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
continue;
}
final Location loc = manager.getSignLoc(plotworld, plot);
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
if (!result) {
if (!result)
{
continue;
}
final String[] lines = BlockManager.manager.getSign(loc);
if (lines != null) {
if (lines != null)
{
String line = lines[2];
if ((line != null) && (line.length() > 2)) {
if ((line != null) && (line.length() > 2))
{
line = line.substring(2);
final BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = (map.get(new StringWrapper(line)));
if (uuid == null) {
for (final StringWrapper string : map.keySet()) {
if (string.value.toLowerCase().startsWith(line.toLowerCase())) {
if (uuid == null)
{
for (final StringWrapper string : map.keySet())
{
if (string.value.toLowerCase().startsWith(line.toLowerCase()))
{
uuid = map.get(string);
break;
}
}
}
if (uuid == null) {
if (uuid == null)
{
uuid = UUIDHandler.getUUID(line, null);
}
if (uuid != null) {
if (uuid != null)
{
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
plot.owner = uuid;
plots.add(plot);
} else {
}
else
{
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
}
}
}
}
if (plots.size() > 0) {
if (plots.size() > 0)
{
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
DBFunc.createPlotsAndData(plots, new Runnable() {
DBFunc.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(null, "&6Database update finished!");
}
});
for (final Plot plot : plots) {
for (final Plot plot : plots)
{
PS.get().updatePlot(plot);
}
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
} else {
}
else
{
MainUtil.sendMessage(null, "No plots were found for the given search.");
}
return true;

View File

@ -33,36 +33,34 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugclear",
aliases = {"fastclear"},
description = "Clear a plot using a fast experiment algorithm",
category = CommandCategory.DEBUG
)
public class DebugClear extends SubCommand {
command = "debugclear",
aliases = { "fastclear" },
description = "Clear a plot using a fast experiment algorithm",
category = CommandCategory.DEBUG)
public class DebugClear extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, 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) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return sendMessage(plr, C.UNLINK_REQUIRED);
}
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) { return sendMessage(plr, C.NOT_IN_PLOT); }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_REQUIRED); }
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(plr, "&aDone!");
}

View File

@ -65,7 +65,6 @@ import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.ExpireManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.SetupUtils;
import com.intellectualcrafters.plot.util.StringMan;
@ -73,61 +72,67 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandCaller;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugexec",
permission = "plots.admin",
description = "Mutli-purpose debug command",
aliases = {"exec"},
category = CommandCategory.DEBUG
)
public class DebugExec extends SubCommand {
command = "debugexec",
permission = "plots.admin",
description = "Mutli-purpose debug command",
aliases = { "exec" },
category = CommandCategory.DEBUG)
public class DebugExec extends SubCommand
{
private ScriptEngine engine;
private Bindings scope;
public DebugExec() {
try {
File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
if (file.exists()) {
public DebugExec()
{
try
{
final File file = new File(PS.get().IMP.getDirectory(), "scripts" + File.separator + "start.js");
if (file.exists())
{
init();
String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8), System.getProperty("line.separator"));
scope.put("THIS", this);
scope.put("PlotPlayer", ConsolePlayer.getConsole());
engine.eval(script, scope);
final String script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), "start.js"), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
scope.put("THIS", this);
scope.put("PlotPlayer", ConsolePlayer.getConsole());
engine.eval(script, scope);
}
} catch (Exception e) {
}
catch (final Exception e)
{}
}
public ScriptEngine getEngine() {
public ScriptEngine getEngine()
{
return engine;
}
public Bindings getScope() {
public Bindings getScope()
{
return scope;
}
public void init() {
if (engine != null) {
return;
}
public void init()
{
if (engine != null) { return; }
engine = (new ScriptEngineManager(null)).getEngineByName("nashorn");
if (engine == null) {
if (engine == null)
{
engine = (new ScriptEngineManager(null)).getEngineByName("JavaScript");
}
ScriptContext context = new SimpleScriptContext();
final ScriptContext context = new SimpleScriptContext();
scope = context.getBindings(ScriptContext.ENGINE_SCOPE);
// stuff
scope.put("MainUtil", new MainUtil());
scope.put("Settings", new Settings());
scope.put("StringMan", new StringMan());
scope.put("MathMan", new MathMan());
scope.put("FlagManager", new FlagManager());
// Classes
scope.put("Location", Location.class);
scope.put("PlotBlock", PlotBlock.class);
@ -135,7 +140,7 @@ public class DebugExec extends SubCommand {
scope.put("PlotId", PlotId.class);
scope.put("Runnable", Runnable.class);
scope.put("RunnableVal", RunnableVal.class);
// Instances
scope.put("PS", PS.get());
scope.put("TaskManager", PS.get().TASK);
@ -152,112 +157,143 @@ public class DebugExec extends SubCommand {
scope.put("HybridUtils", HybridUtils.manager);
scope.put("IMP", PS.get().IMP);
scope.put("MainCommand", MainCommand.getInstance());
// enums
for (Enum<?> value : C.values()) {
for (final Enum<?> value : C.values())
{
scope.put("C_" + value.name(), value);
}
}
@Override
public boolean onCommand(final PlotPlayer player, String... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
final List<String> allowed_params = Arrays.asList("calibrate-analysis", "remove-flag", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
if (args.length > 0) {
if (args.length > 0)
{
final String arg = args[0].toLowerCase();
String script;
boolean async = false;
switch (arg) {
case "analyze": {
Plot plot = MainUtil.getPlot(player.getLocation());
if (plot == null) {
switch (arg)
{
case "analyze":
{
final Plot plot = MainUtil.getPlot(player.getLocation());
if (plot == null)
{
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
PlotAnalysis analysis = plot.getComplexity();
if (analysis != null) {
int complexity = analysis.getComplexity();
final PlotAnalysis analysis = plot.getComplexity();
if (analysis != null)
{
final int complexity = analysis.getComplexity();
MainUtil.sendMessage(player, "Changes: " + analysis.changes);
MainUtil.sendMessage(player, "Complexity: " + complexity);
return true;
}
MainUtil.sendMessage(player, "$1Starting task...");
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information");
}
});
return true;
}
case "calibrate-analysis": {
if (args.length != 2) {
case "calibrate-analysis":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec analyze <threshold>");
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating it)");
return false;
}
double threshold;
try {
try
{
threshold = Integer.parseInt(args[1]) / 100d;
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
MainUtil.sendMessage(player, "$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
return false;
}
PlotAnalysis.calcOptimalModifiers(new Runnable() {
PlotAnalysis.calcOptimalModifiers(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "$1Thank you for calibrating PlotSquared plot expiry");
}
}, threshold);
return true;
}
case "stop-expire": {
if (ExpireManager.task != -1) {
case "stop-expire":
{
if (ExpireManager.task != -1)
{
PS.get().TASK.cancelTask(ExpireManager.task);
} else {
}
else
{
return MainUtil.sendMessage(player, "Task already halted");
}
ExpireManager.task = -1;
return MainUtil.sendMessage(player, "Cancelled task.");
}
case "remove-flag": {
if (args.length != 2) {
case "remove-flag":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec remove-flag <flag>");
return false;
}
String flag = args[1];
for (Plot plot : PS.get().getPlots()) {
if (FlagManager.getPlotFlag(plot, flag) != null) {
final String flag = args[1];
for (final Plot plot : PS.get().getPlots())
{
if (FlagManager.getPlotFlag(plot, flag) != null)
{
FlagManager.removePlotFlag(plot, flag);
}
}
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
}
case "start-rgar": {
if (args.length != 2) {
case "start-rgar":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, "&cInvalid syntax: /plot debugexec start-rgar <world>");
return false;
}
boolean result;
if (!PS.get().isPlotWorld(args[1])) {
if (!PS.get().isPlotWorld(args[1]))
{
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]);
return false;
}
if (BukkitHybridUtils.regions != null) {
result = ((BukkitHybridUtils)(HybridUtils.manager)).scheduleRoadUpdate(args[1], BukkitHybridUtils.regions, 0);
if (HybridUtils.regions != null)
{
result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1], HybridUtils.regions, 0);
}
else {
else
{
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
}
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)");
return false;
}
return true;
}
case "stop-rgar": {
if (!HybridUtils.UPDATE) {
case "stop-rgar":
{
if (!HybridUtils.UPDATE)
{
MainUtil.sendMessage(player, "&cTASK NOT RUNNING!");
return false;
}
@ -265,55 +301,53 @@ public class DebugExec extends SubCommand {
MainUtil.sendMessage(player, "&cCancelling task... (please wait)");
return true;
}
case "start-expire": {
if (ExpireManager.task == -1) {
case "start-expire":
{
if (ExpireManager.task == -1)
{
ExpireManager.runTask();
} else {
}
else
{
return MainUtil.sendMessage(player, "Plot expiry task already started");
}
return MainUtil.sendMessage(player, "Started plot expiry task");
}
case "update-expired": {
if (args.length > 1) {
case "update-expired":
{
if (args.length > 1)
{
final String world = args[1];
if (!BlockManager.manager.isWorld(world)) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
}
if (!BlockManager.manager.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
MainUtil.sendMessage(player, "Updating expired plot list");
ExpireManager.updateExpired(args[1]);
return true;
}
return MainUtil.sendMessage(player, "Use /plot debugexec update-expired <world>");
}
case "show-expired": {
if (args.length > 1) {
case "show-expired":
{
if (args.length > 1)
{
final String world = args[1];
if (!BlockManager.manager.isWorld(world)) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
}
if (!ExpireManager.expiredPlots.containsKey(args[1])) {
return MainUtil.sendMessage(player, "No task for world: " + args[1]);
}
if (!BlockManager.manager.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
if (!ExpireManager.expiredPlots.containsKey(args[1])) { return MainUtil.sendMessage(player, "No task for world: " + args[1]); }
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) {
for (final Plot plot : ExpireManager.expiredPlots.get(args[1]))
{
MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.id.x + ";" + plot.id.y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner));
}
return true;
}
return MainUtil.sendMessage(player, "Use /plot debugexec show-expired <world>");
}
case "seen": {
if (args.length != 2) {
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
}
case "seen":
{
if (args.length != 2) { return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>"); }
final UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
return MainUtil.sendMessage(player, "player not found: " + args[1]);
}
if (uuid == null) { return MainUtil.sendMessage(player, "player not found: " + args[1]); }
final OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
if ((op == null) || (op.getLastPlayed() == 0)) {
return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]);
}
if ((op == null) || (op.getLastPlayed() == 0)) { return MainUtil.sendMessage(player, "player hasn't connected before: " + args[1]); }
final Timestamp stamp = new Timestamp(op.getLastPlayed());
final Date date = new Date(stamp.getTime());
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
@ -323,34 +357,40 @@ public class DebugExec extends SubCommand {
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
return true;
}
case "trim-check": {
if (args.length != 2) {
case "trim-check":
{
if (args.length != 2)
{
MainUtil.sendMessage(player, "Use /plot debugexec trim-check <world>");
MainUtil.sendMessage(player, "&7 - Generates a list of regions to trim");
return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run");
}
final String world = args[1];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) {
return MainUtil.sendMessage(player, "Invalid world: " + args[1]);
}
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); }
final ArrayList<ChunkLoc> empty = new ArrayList<>();
final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
final boolean result = Trim.getTrimRegions(empty, world, new Runnable()
{
@Override
public void run() {
public void run()
{
Trim.sendMessage("Processing is complete! Here's how many chunks would be deleted:");
Trim.sendMessage(" - MCA #: " + empty.size());
Trim.sendMessage(" - CHUNKS: " + (empty.size() * 1024) + " (max)");
Trim.sendMessage("Exporting log for manual approval...");
final File file = new File(PS.get().IMP.getDirectory() + File.separator + "trim.txt");
PrintWriter writer;
try {
try
{
writer = new PrintWriter(file);
for (final ChunkLoc loc : empty) {
for (final ChunkLoc loc : empty)
{
writer.println(world + "/region/r." + loc.x + "." + loc.z + ".mca");
}
writer.close();
Trim.sendMessage("File saved to 'plugins/PlotSquared/trim.txt'");
} catch (final FileNotFoundException e) {
}
catch (final FileNotFoundException e)
{
e.printStackTrace();
Trim.sendMessage("File failed to save! :(");
}
@ -360,7 +400,8 @@ public class DebugExec extends SubCommand {
Trim.sendMessage(" - Add 31 to each number to get the end position");
}
});
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, "Trim task already started!");
}
return result;
@ -368,90 +409,120 @@ public class DebugExec extends SubCommand {
case "h":
case "he":
case "?":
case "help": {
case "help":
{
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringMan.join(allowed_params, "|") + ">");
return false;
}
case "addcmd": {
try {
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator"));
Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0]) {
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
try {
scope.put("PlotPlayer", plr);
scope.put("args", args);
engine.eval(cmd, scope);
return true;
} catch (ScriptException e) {
e.printStackTrace();
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
return false;
case "addcmd":
{
try
{
final String cmd = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
final Command<PlotPlayer> subcommand = new Command<PlotPlayer>(args[1].split("\\.")[0])
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
try
{
scope.put("PlotPlayer", plr);
scope.put("args", args);
engine.eval(cmd, scope);
return true;
}
catch (final ScriptException e)
{
e.printStackTrace();
MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG);
return false;
}
}
}
};
MainCommand.getInstance().addCommand(subcommand);
return true;
};
MainCommand.getInstance().addCommand(subcommand);
return true;
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot debugexec addcmd <file>");
return false;
}
}
case "runasync": {
case "runasync":
{
async = true;
}
case "run": {
try {
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator"));
if (args.length > 2) {
HashMap<String, String> replacements = new HashMap<>();
for (int i = 2; i < args.length; i++) {
replacements.put("%s" + (i-2), args[i]);
case "run":
{
try
{
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
if (args.length > 2)
{
final HashMap<String, String> replacements = new HashMap<>();
for (int i = 2; i < args.length; i++)
{
replacements.put("%s" + (i - 2), args[i]);
}
script = StringMan.replaceFromMap(script, replacements);
}
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
return false;
}
break;
}
default: {
default:
{
script = StringMan.join(args, " ");
}
}
if (!ConsolePlayer.isConsole(player)) {
if (!ConsolePlayer.isConsole(player))
{
MainUtil.sendMessage(player, C.NOT_CONSOLE);
return false;
}
init();
scope.put("PlotPlayer", player);
PS.debug("> " + script);
try {
if (async) {
try
{
if (async)
{
final String toExec = script;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
long start = System.currentTimeMillis();
try {
public void run()
{
final long start = System.currentTimeMillis();
try
{
engine.eval(toExec, scope);
} catch (ScriptException e) {
}
catch (final ScriptException e)
{
e.printStackTrace();
}
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
}
});
}
else {
long start = System.currentTimeMillis();
else
{
final long start = System.currentTimeMillis();
engine.eval(script, scope);
PS.log("> " + (System.currentTimeMillis() - start) + "ms");
}
return true;
} catch (ScriptException e) {
}
catch (final ScriptException e)
{
e.printStackTrace();
return false;
}

View File

@ -32,36 +32,39 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "fill",
permission = "plots.fill",
description = "Fill or surround a plot in bedrock",
usage = "/plot fill",
aliases = {"debugfill"},
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE
)
public class DebugFill extends SubCommand {
command = "fill",
permission = "plots.fill",
description = "Fill or surround a plot in bedrock",
usage = "/plot fill",
aliases = { "debugfill" },
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE)
public class DebugFill extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
if (args.length != 1 || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all"))) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
if ((args.length != 1) || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all")))
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill <outline|all>");
return true;
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill"))
{
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
return false;
}
@ -69,89 +72,119 @@ public class DebugFill extends SubCommand {
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
MainUtil.sendMessage(player, "&cPreparing task");
MainUtil.runners.put(plot, 1);
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
public void run()
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&7 - Starting");
if (args[0].equalsIgnoreCase("all")) {
if (args[0].equalsIgnoreCase("all"))
{
int height = 255;
PlotBlock block = new PlotBlock((short) 7, (byte) 0);
PlotBlock air = new PlotBlock((short) 0, (byte) 0);
if (args.length > 2) {
try {
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
if (args.length > 2)
{
try
{
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
if (args.length == 3) {
if (args.length == 3)
{
height = Integer.parseInt(args[2]);
}
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill all <id> <height>");
MainUtil.runners.remove(plot);
return;
}
}
for (int y = 0; y <= height; y++) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = 0; y <= height; y++)
{
for (int x = bottom.getX(); x <= top.getX(); x++)
{
for (int z = bottom.getZ(); z <= top.getZ(); z++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, block);
}
}
}
for (int y = height + 1; y <= 255; y++) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = height + 1; y <= 255; y++)
{
for (int x = bottom.getX(); x <= top.getX(); x++)
{
for (int z = bottom.getZ(); z <= top.getZ(); z++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, air);
}
}
}
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(player, "&aFill task complete!");
}
});
}
else if (args[0].equals("outline")) {
else if (args[0].equals("outline"))
{
int x, z;
z = bottom.getZ();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= 255; y++) {
for (x = bottom.getX(); x <= (top.getX() - 1); x++)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= 255; y++) {
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= 255; y++) {
for (x = top.getX(); x >= (bottom.getX() + 1); x--)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= 255; y++) {
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--)
{
for (int y = 1; y <= 255; y++)
{
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
bottom.setY(255);
top.add(1,0,1);
top.add(1, 0, 1);
SetBlockQueue.setSlow(true);
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
MainUtil.sendMessage(player, "&aFill task complete!");
SetBlockQueue.setSlow(false);

View File

@ -37,40 +37,47 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugfixflags",
usage = "/plot debugfixflags <world>",
permission = "plots.debugfixflags",
description = "Attempt to fix all flags for a world",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG
)
public class DebugFixFlags extends SubCommand {
command = "debugfixflags",
usage = "/plot debugfixflags <world>",
permission = "plots.debugfixflags",
description = "Attempt to fix all flags for a world",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG)
public class DebugFixFlags extends SubCommand
{
public DebugFixFlags() {
public DebugFixFlags()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final String world = args[0];
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) {
if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]);
return false;
}
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
for (final Plot plot : PS.get().getPlotsInWorld(world)) {
for (final Plot plot : PS.get().getPlotsInWorld(world))
{
final HashMap<String, Flag> flags = plot.getSettings().flags;
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
boolean changed = false;
while (i.hasNext()) {
if (FlagManager.getFlag(i.next().getKey()) == null) {
while (i.hasNext())
{
if (FlagManager.getFlag(i.next().getKey()) == null)
{
changed = true;
i.remove();
}
}
if (changed) {
if (changed)
{
DBFunc.setFlags(plot, plot.getSettings().flags.values());
}
}

View File

@ -28,22 +28,26 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugloadtest",
permission = "plots.debugloadtest",
description = "This debug command will force the reload of all plots in the DB",
usage = "/plot debugloadtest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE
)
public class DebugLoadTest extends SubCommand {
command = "debugloadtest",
permission = "plots.debugloadtest",
description = "This debug command will force the reload of all plots in the DB",
usage = "/plot debugloadtest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE)
public class DebugLoadTest extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
try {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
try
{
final Field fPlots = PS.class.getDeclaredField("plots");
fPlots.setAccessible(true);
fPlots.set(null, DBFunc.getPlots());
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("&3===FAILED&3===");
e.printStackTrace();
PS.debug("&3===END OF STACKTRACE===");

View File

@ -15,30 +15,37 @@ import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugpaste",
aliases = {"dp"},
usage = "/plot debugpaste",
description = "Upload settings.yml & latest.log to hastebin",
permission = "plots.debugpaste",
category = CommandCategory.DEBUG
)
public class DebugPaste extends SubCommand {
command = "debugpaste",
aliases = { "dp" },
usage = "/plot debugpaste",
description = "Upload settings.yml & latest.log to hastebin",
permission = "plots.debugpaste",
category = CommandCategory.DEBUG)
public class DebugPaste extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, String[] args) {
TaskManager.runTaskAsync(new Runnable() {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
String settingsYML = HastebinUtility.upload(PS.get().configFile);
public void run()
{
try
{
final String settingsYML = HastebinUtility.upload(PS.get().configFile);
String latestLOG;
try {
try
{
latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log"));
} catch(final Exception e) {
}
catch (final Exception e)
{
plr.sendMessage("&clatest.log is too big to be pasted, will ignore");
latestLOG = "too big :(";
}
StringBuilder b = new StringBuilder();
final StringBuilder b = new StringBuilder();
b.append("# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your problem\n\n# We will start with some informational files\n");
b.append("links.settings_yml: '").append(settingsYML).append("'\n");
b.append("links.latest_log: '").append(latestLOG).append("'\n");
@ -47,11 +54,12 @@ public class DebugPaste extends SubCommand {
b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n");
b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n");
b.append("plugins:");
for (final Plugin p : Bukkit.getPluginManager().getPlugins()) {
for (final Plugin p : Bukkit.getPluginManager().getPlugins())
{
b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled());
}
b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n");
Runtime runtime = Runtime.getRuntime();
final Runtime runtime = Runtime.getRuntime();
b.append("memory.free: ").append(runtime.freeMemory()).append("\n");
b.append("memory.max: ").append(runtime.maxMemory()).append("\n");
b.append("java.specification.version: '").append(System.getProperty("java.specification.version")).append("'\n");
@ -63,9 +71,11 @@ public class DebugPaste extends SubCommand {
b.append("# Okay :D Great. You are now ready to create your bug report!");
b.append("\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
String link = HastebinUtility.upload(b.toString());
final String link = HastebinUtility.upload(b.toString());
plr.sendMessage(C.DEBUG_REPORT_CREATED.s().replace("%url%", link));
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
}
}

View File

@ -35,44 +35,49 @@ import com.intellectualcrafters.plot.util.MathMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugroadregen",
usage = "/plot debugroadregen",
requiredType = RequiredType.NONE,
description = "Regenerate all roads based on the road schematic",
category = CommandCategory.DEBUG,
permission = "plots.debugroadregen"
)
public class DebugRoadRegen extends SubCommand {
command = "debugroadregen",
usage = "/plot debugroadregen",
requiredType = RequiredType.NONE,
description = "Regenerate all roads based on the road schematic",
category = CommandCategory.DEBUG,
permission = "plots.debugroadregen")
public class DebugRoadRegen extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
final Location loc = player.getLocation();
final String world = loc.getWorld();
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (!(plotworld instanceof HybridPlotWorld)) {
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
}
Plot plot = player.getCurrentPlot();
if (plot == null) {
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (!(plotworld instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); }
final Plot plot = player.getCurrentPlot();
if (plot == null)
{
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
int extend = 0;
if (args.length == 1) {
if (MathMan.isInteger(args[0])) {
try {
if (args.length == 1)
{
if (MathMan.isInteger(args[0]))
{
try
{
extend = Integer.parseInt(args[0]);
}
catch (Exception e) {
catch (final Exception e)
{
C.NOT_VALID_NUMBER.send(player, "(0, <EXTEND HEIGHT>)");
return false;
}
}
}
boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend);
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend);
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads");
}
else {
HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world);
else
{
final HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world);
manager.createRoadEast(plotworld, plot);
manager.createRoadSouth(plotworld, plot);
manager.createRoadSouthEast(plotworld, plot);

View File

@ -30,23 +30,26 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "debugsavetest",
permission = "plots.debugsavetest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
usage = "/plot debugsavetest",
description = "This command will force the recreation of all plots in the DB"
)
public class DebugSaveTest extends SubCommand {
command = "debugsavetest",
permission = "plots.debugsavetest",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
usage = "/plot debugsavetest",
description = "This command will force the recreation of all plots in the DB")
public class DebugSaveTest extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final ArrayList<Plot> plots = new ArrayList<Plot>();
plots.addAll(PS.get().getPlots());
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
DBFunc.createPlotsAndData(plots, new Runnable() {
DBFunc.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(null, "&6Database sync finished!");
}
});

View File

@ -36,7 +36,6 @@ import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.AbstractDB;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
@ -55,54 +54,64 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "uuidconvert",
permission = "plots.admin",
description = "Debug UUID conversion",
usage = "/plot uuidconvert <lower|offline|online>",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG
)
public class DebugUUID extends SubCommand {
command = "uuidconvert",
permission = "plots.admin",
description = "Debug UUID conversion",
usage = "/plot uuidconvert <lower|offline|online>",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG)
public class DebugUUID extends SubCommand
{
public DebugUUID() {
public DebugUUID()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
PlotPlayer player = null;
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final PlotPlayer player = null;
final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
final UUIDWrapper newWrapper;
switch (args[0].toLowerCase()) {
case "lower": {
switch (args[0].toLowerCase())
{
case "lower":
{
newWrapper = new LowerOfflineUUIDWrapper();
break;
}
case "offline": {
case "offline":
{
newWrapper = new OfflineUUIDWrapper();
break;
}
case "online": {
case "online":
{
newWrapper = new DefaultUUIDWrapper();
break;
}
default: {
try {
Class<?> clazz = Class.forName(args[0]);
default:
{
try
{
final Class<?> clazz = Class.forName(args[0]);
newWrapper = (UUIDWrapper) clazz.newInstance();
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
return false;
}
}
}
if (args.length != 2 || !args[1].equals("-o")) {
if ((args.length != 2) || !args[1].equals("-o"))
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert " + args[0] + " - o");
MainUtil.sendMessage(player, "&cBe aware of the following!");
MainUtil.sendMessage(player, "&8 - &cUse the database command or another method to backup your plots beforehand");
@ -113,22 +122,24 @@ public class DebugUUID extends SubCommand {
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)");
return false;
}
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) {
if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName()))
{
MainUtil.sendMessage(player, "&cUUID mode already in use!");
return false;
}
MainUtil.sendConsoleMessage("&6Beginning UUID mode conversion");
MainUtil.sendConsoleMessage("&7 - Disconnecting players");
for (PlotPlayer pp : UUIDHandler.getPlayers().values()) {
for (final PlotPlayer pp : UUIDHandler.getPlayers().values())
{
pp.kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
}
MainUtil.sendConsoleMessage("&7 - Initializing map");
final HashMap<UUID, UUID> uCMap = new HashMap<UUID, UUID>();
final HashMap<UUID, UUID> uCReverse = new HashMap<UUID, UUID>();
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
final HashSet<String> worlds = new HashSet<>();
@ -136,212 +147,269 @@ public class DebugUUID extends SubCommand {
worlds.add("world");
final HashSet<UUID> uuids = new HashSet<>();
final HashSet<String> names = new HashSet<>();
for (final String worldname : worlds) {
for (final String worldname : worlds)
{
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
String[] dat = playerdataFolder.list(new FilenameFilter() {
String[] dat = playerdataFolder.list(new FilenameFilter()
{
@Override
public boolean accept(final File f, final String s) {
public boolean accept(final File f, final String s)
{
return s.endsWith(".dat");
}
});
if (dat != null) {
for (final String current : dat) {
if (dat != null)
{
for (final String current : dat)
{
final String s = current.replaceAll(".dat$", "");
try {
try
{
final UUID uuid = UUID.fromString(s);
uuids.add(uuid);
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(plr, C.PREFIX.s() + "Invalid playerdata: " + current);
}
}
}
final File playersFolder = new File(worldname + File.separator + "players");
dat = playersFolder.list(new FilenameFilter() {
dat = playersFolder.list(new FilenameFilter()
{
@Override
public boolean accept(final File f, final String s) {
public boolean accept(final File f, final String s)
{
return s.endsWith(".dat");
}
});
if (dat != null) {
for (final String current : dat) {
if (dat != null)
{
for (final String current : dat)
{
names.add(current.replaceAll(".dat$", ""));
}
}
}
MainUtil.sendConsoleMessage("&7 - Populating map");
UUID uuid2;
final UUIDWrapper wrapper = new DefaultUUIDWrapper();
for (UUID uuid : uuids) {
try {
for (UUID uuid : uuids)
{
try
{
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2)) {
if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse.containsKey(uuid2))
{
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
} catch (final Throwable e) {
}
catch (final Throwable e)
{
MainUtil.sendMessage(plr, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
}
}
for (final String name : names) {
for (final String name : names)
{
final UUID uuid = currentUUIDWrapper.getUUID(name);
uuid2 = newWrapper.getUUID(name);
if (!uuid.equals(uuid2)) {
if (!uuid.equals(uuid2))
{
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
}
if (uCMap.size() == 0) {
if (uCMap.size() == 0)
{
MainUtil.sendConsoleMessage("&c - Error! Attempting to repopulate");
for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
if (op.getLastPlayed() != 0) {
// String name = op.getName();
// StringWrapper wrap = new StringWrapper(name);
UUID uuid = currentUUIDWrapper.getUUID(op);
for (final OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers())
{
if (op.getLastPlayed() != 0)
{
// String name = op.getName();
// StringWrapper wrap = new StringWrapper(name);
final UUID uuid = currentUUIDWrapper.getUUID(op);
uuid2 = newWrapper.getUUID(op);
if (!uuid.equals(uuid2)) {
if (!uuid.equals(uuid2))
{
uCMap.put(uuid, uuid2);
uCReverse.put(uuid2, uuid);
}
}
}
if (uCMap.size() == 0) {
if (uCMap.size() == 0)
{
MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!");
return false;
}
else {
else
{
MainUtil.sendConsoleMessage("&a - Successfully repopulated");
}
}
MainUtil.sendConsoleMessage("&7 - Replacing cache");
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
String name = UUIDHandler.getName(entry.getKey());
if (name != null) {
public void run()
{
for (final Entry<UUID, UUID> entry : uCMap.entrySet())
{
final String name = UUIDHandler.getName(entry.getKey());
if (name != null)
{
UUIDHandler.add(new StringWrapper(name), entry.getValue());
}
}
MainUtil.sendConsoleMessage("&7 - Scanning for applicable files (uuids.txt)");
File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
if (file.exists()) {
try {
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines) {
try {
final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt");
if (file.exists())
{
try
{
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (String line : lines)
{
try
{
line = line.trim();
if (line.length() == 0) {
if (line.length() == 0)
{
continue;
}
line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
String[] split = line.split("\\|");
String name = split[0];
if (name.length() == 0 || name.length() > 16 || !StringMan.isAlphanumericUnd(name)) {
final String[] split = line.split("\\|");
final String name = split[0];
if ((name.length() == 0) || (name.length() > 16) || !StringMan.isAlphanumericUnd(name))
{
continue;
}
UUID old = currentUUIDWrapper.getUUID(name);
if (old == null) {
final UUID old = currentUUIDWrapper.getUUID(name);
if (old == null)
{
continue;
}
UUID now = newWrapper.getUUID(name);
final UUID now = newWrapper.getUUID(name);
UUIDHandler.add(new StringWrapper(name), now);
uCMap.put(old, now);
uCReverse.put(now, old);
}
catch (Exception e2) {
catch (final Exception e2)
{
e2.printStackTrace();
}
}
} catch (IOException e) {
}
catch (final IOException e)
{
e.printStackTrace();
}
}
MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
UUIDHandler.setUUIDWrapper(newWrapper);
MainUtil.sendConsoleMessage("&7 - Updating plot objects");
for (Plot plot : PS.get().getPlotsRaw()) {
UUID value = uCMap.get(plot.owner);
if (value != null) {
for (final Plot plot : PS.get().getPlotsRaw())
{
final UUID value = uCMap.get(plot.owner);
if (value != null)
{
plot.owner = value;
}
plot.getTrusted().clear();
plot.getMembers().clear();
plot.getDenied().clear();
}
MainUtil.sendConsoleMessage("&7 - Deleting database");
final AbstractDB database = DBFunc.dbManager;
boolean result = database.deleteTables();
final boolean result = database.deleteTables();
MainUtil.sendConsoleMessage("&7 - Creating tables");
try {
try
{
database.createTables();
if (!result) {
if (!result)
{
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
for (Plot plot : PS.get().getPlots()) {
UUID value = uCReverse.get(plot.owner);
if (value != null) {
for (final Plot plot : PS.get().getPlots())
{
final UUID value = uCReverse.get(plot.owner);
if (value != null)
{
plot.owner = value;
}
}
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(null, "&6Recovery was successful!");
}
});
return;
}
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
return;
}
if (newWrapper instanceof OfflineUUIDWrapper) {
if (newWrapper instanceof OfflineUUIDWrapper)
{
PS.get().config.set("UUID.force-lowercase", false);
PS.get().config.set("UUID.offline", true);
}
else if (newWrapper instanceof LowerOfflineUUIDWrapper) {
else if (newWrapper instanceof LowerOfflineUUIDWrapper)
{
PS.get().config.set("UUID.force-lowercase", true);
PS.get().config.set("UUID.offline", true);
}
else if (newWrapper instanceof DefaultUUIDWrapper) {
else if (newWrapper instanceof DefaultUUIDWrapper)
{
PS.get().config.set("UUID.force-lowercase", false);
PS.get().config.set("UUID.offline", false);
}
try {
try
{
PS.get().config.save(PS.get().configFile);
}
catch (Exception e) {
catch (final Exception e)
{
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
}
MainUtil.sendConsoleMessage("&7 - Populating tables");
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
database.createPlotsAndData(plots, new Runnable() {
public void run()
{
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
database.createPlotsAndData(plots, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendConsoleMessage("&aConversion complete!");
}
});
}
});
MainUtil.sendConsoleMessage("&aIt is now safe for players to join");
MainUtil.sendConsoleMessage("&cConversion is still in progress, you will be notified when it is complete");
}

View File

@ -36,66 +36,73 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "delete",
permission = "plots.delete",
description = "Delete a plot",
usage = "/plot delete",
aliases = {"dispose", "del"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Delete extends SubCommand {
command = "delete",
permission = "plots.delete",
description = "Delete a plot",
usage = "/plot delete",
aliases = { "dispose", "del" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Delete extends SubCommand
{
@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 (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return !sendMessage(plr, C.UNLINK_REQUIRED);
}
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
return !sendMessage(plr, C.NO_PLOT_PERMS);
}
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); }
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); }
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
Runnable runnable = new Runnable() {
final Runnable runnable = new Runnable()
{
@Override
public void run() {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
public void run()
{
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr)))
{
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
if (c > 0d)
{
EconHandler.manager.depositMoney(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
if (plot.unclaim()) {
if (plot.unclaim())
{
final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
});
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
}
}
else {
else
{
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
}
}
};
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
{
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
}
else {
else
{
TaskManager.runTask(runnable);
}
return true;

View File

@ -37,57 +37,68 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "deny",
aliases = {"d"},
description = "Deny a user from a plot",
usage = "/plot deny <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Deny extends SubCommand {
command = "deny",
aliases = { "d" },
description = "Deny a user from a plot",
usage = "/plot deny <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Deny extends SubCommand
{
public Deny() {
public Deny()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@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 == null) || !plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || !plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.deny"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
UUID uuid;
if (args[0].equalsIgnoreCase("*")) {
if (args[0].equalsIgnoreCase("*"))
{
uuid = DBFunc.everyone;
} else {
}
else
{
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (uuid == null)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.getDenied().contains(uuid)) {
if (plot.getDenied().contains(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
@ -96,15 +107,18 @@ public class Deny extends SubCommand {
plot.addDenied(uuid);
EventUtil.manager.callDenied(plr, plot, uuid, true);
MainUtil.sendMessage(plr, C.DENIED_ADDED);
if (!uuid.equals(DBFunc.everyone)) {
if (!uuid.equals(DBFunc.everyone))
{
handleKick(uuid, plot);
}
return true;
}
private void handleKick(final UUID uuid, final Plot plot) {
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null && plot.equals(MainUtil.getPlot(pp.getLocation()))) {
private void handleKick(final UUID uuid, final Plot plot)
{
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if ((pp != null) && plot.equals(MainUtil.getPlot(pp.getLocation())))
{
pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld()));
MainUtil.sendMessage(pp, C.YOU_GOT_DENIED);
}

View File

@ -30,53 +30,57 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "done",
aliases = {"submit"},
description = "Mark a plot as done",
permission = "plots.done",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Done extends SubCommand {
command = "done",
aliases = { "submit" },
description = "Mark a plot as done",
permission = "plots.done",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Done extends SubCommand
{
@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 || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.done")) {
if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.done"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (plot.getSettings().flags.containsKey("done")) {
if (plot.getSettings().flags.containsKey("done"))
{
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
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);
MainUtil.sendMessage(plr, C.GENERATING_LINK);
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
if (value == null || value.getComplexity() >= Settings.CLEAR_THRESHOLD) {
Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD))
{
final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000));
FlagManager.addPlotFlag(plot, flag);
MainUtil.sendMessage(plr, C.DONE_SUCCESS);
}
else {
else
{
MainUtil.sendMessage(plr, C.DONE_INSUFFICIENT_COMPLEXITY);
}
}

View File

@ -17,52 +17,58 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "download",
aliases = {"dl"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Download your plot",
permission = "plots.download"
)
public class Download extends SubCommand {
command = "download",
aliases = { "dl" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Download your plot",
permission = "plots.download")
public class Download extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (!Settings.METRICS)
{
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
final Plot plot = MainUtil.getPlot(plr.getLocation());
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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && FlagManager.getPlotFlag(plot, "done") != null)) && !Permissions.hasPermission(plr, "plots.admin.command.download")) {
if ((!plot.isOwner(plr.getUUID()) || (Settings.DOWNLOAD_REQUIRES_DONE && (FlagManager.getPlotFlag(plot, "done") != null))) && !Permissions.hasPermission(plr, "plots.admin.command.download"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
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);
MainUtil.sendMessage(plr, C.GENERATING_LINK);
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>()
{
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
public void run()
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
URL url = SchematicHandler.manager.upload(value, null, null);
if (url == null) {
public void run()
{
final URL url = SchematicHandler.manager.upload(value, null, null);
if (url == null)
{
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
MainUtil.runners.remove(plot);
return;

View File

@ -39,24 +39,26 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "flag",
aliases = {"f"},
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
description = "Manage plot flags",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.flag"
)
public class FlagCmd extends SubCommand {
command = "flag",
aliases = { "f" },
usage = "/plot flag <set|remove|add|list|info> <flag> <value>",
description = "Manage plot flags",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.flag")
public class FlagCmd extends SubCommand
{
@Override
public String getUsage() {
public String getUsage()
{
return super.getUsage().replaceAll("<flag>", StringMan.join(FlagManager.getFlags(), "|"));
}
@Override
public boolean onCommand(final PlotPlayer player, final String ... args) {
public boolean onCommand(final PlotPlayer player, final String... args)
{
/*
* plot flag set fly true
* plot flag remove fly
@ -64,40 +66,50 @@ public class FlagCmd extends SubCommand {
* plot flag add use 2,4
* plot flag list
*/
if (args.length == 0) {
if (args.length == 0)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
return false;
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
if (plot == null)
{
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
if (!plot.hasOwner()) {
if (!plot.hasOwner())
{
sendMessage(player, C.PLOT_NOT_CLAIMED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other")) {
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.set.flag.other"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag.other");
return false;
}
if (args.length > 1 && FlagManager.isReserved(args[1])) {
if ((args.length > 1) && FlagManager.isReserved(args[1]))
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
switch (args[0].toLowerCase()) {
case "info": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {
switch (args[0].toLowerCase())
{
case "info":
{
if (!Permissions.hasPermission(player, "plots.set.flag"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.info");
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1]);
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
return false;
@ -110,73 +122,92 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
return true;
}
case "set": {
if (!Permissions.hasPermission(player, "plots.set.flag")) {
case "set":
{
if (!Permissions.hasPermission(player, "plots.set.flag"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
return false;
}
if (args.length < 3) {
if (args.length < 3)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag set <flag> <value>");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase())) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase()))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + value.toLowerCase());
return false;
}
final Object parsed = af.parseValueRaw(value);
if (parsed == null) {
if (parsed == null)
{
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
return false;
}
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(player, C.FLAG_ADDED);
return true;
}
case "remove": {
if (!Permissions.hasPermission(player, "plots.flag.remove")) {
case "remove":
{
if (!Permissions.hasPermission(player, "plots.flag.remove"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
return false;
}
if ((args.length != 2) && (args.length != 3)) {
if ((args.length != 2) && (args.length != 3))
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()))
{
for (final String entry : args[2].split(","))
{
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
return false;
}
}
}
if (flag == null) {
if (flag == null)
{
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
return false;
}
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
if ((args.length == 3) && flag.getAbstractFlag().isList())
{
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
} else {
}
else
{
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
return false;
}
@ -184,23 +215,30 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_REMOVED);
return true;
}
case "add": {
if (!Permissions.hasPermission(player, "plots.flag.add")) {
case "add":
{
if (!Permissions.hasPermission(player, "plots.flag.add"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
return false;
}
if (args.length < 3) {
if (args.length < 3)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag add <flag> <values>");
return false;
}
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
if (af == null) {
if (af == null)
{
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false;
}
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase()))
{
for (final String entry : args[2].split(","))
{
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
return false;
}
@ -208,18 +246,23 @@ public class FlagCmd extends SubCommand {
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value);
if (parsed == null) {
if (parsed == null)
{
MainUtil.sendMessage(player, "&c" + af.getValueDesc());
return false;
}
Flag flag = FlagManager.getPlotFlag(plot, args[1].toLowerCase());
if ((flag == null) || !flag.getAbstractFlag().isList()) {
if ((flag == null) || !flag.getAbstractFlag().isList())
{
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
} else {
}
else
{
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
}
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false;
}
@ -227,26 +270,32 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_ADDED);
return true;
}
case "list": {
if (!Permissions.hasPermission(player, "plots.flag.list")) {
case "list":
{
if (!Permissions.hasPermission(player, "plots.flag.list"))
{
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
return false;
}
if (args.length != 1) {
if (args.length != 1)
{
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag list");
return false;
}
final HashMap<String, ArrayList<String>> flags = new HashMap<>();
for (final AbstractFlag af : FlagManager.getFlags()) {
for (final AbstractFlag af : FlagManager.getFlags())
{
final String type = af.value.getClass().getSimpleName().replaceAll("Value", "");
if (!flags.containsKey(type)) {
if (!flags.containsKey(type))
{
flags.put(type, new ArrayList<String>());
}
flags.get(type).add(af.getKey());
}
String message = "";
String prefix = "";
for (final String flag : flags.keySet()) {
for (final String flag : flags.keySet())
{
message += prefix + "&6" + flag + ": &7" + StringMan.join(flags.get(flag), ", ");
prefix = "\n";
}

View File

@ -9,79 +9,86 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Command;
public class GenerateDocs {
public static void main(String[] args) {
public class GenerateDocs
{
public static void main(final String[] args)
{
MainCommand.getInstance().addCommand(new WE_Anywhere());
MainCommand.getInstance().addCommand(new Cluster());
ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
final ArrayList<Command<PlotPlayer>> commands = MainCommand.getInstance().getCommands();
log("### Want to document some commands?");
log(" - This page is automatically generated");
log(" - Fork the project and add a javadoc comment to one of the command classes");
log(" - Then do a pull request and it will be added to this page");
log("");
log("# Contents");
for (CommandCategory category : CommandCategory.values()) {
for (final CommandCategory category : CommandCategory.values())
{
log("###### " + category.name());
for (Command<PlotPlayer> command : MainCommand.getCommands(category, null)) {
log(" - [/plot " + command.getCommand() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getCommand() +") ");
for (final Command<PlotPlayer> command : MainCommand.getCommands(category, null))
{
log(" - [/plot " + command.getCommand() + "](https://github.com/IntellectualSites/PlotSquared/wiki/Commands#" + command.getCommand() + ") ");
}
log("");
}
log("# Commands");
for (Command<PlotPlayer> command : commands) {
for (final Command<PlotPlayer> command : commands)
{
printCommand(command);
}
}
public static void printCommand(Command<PlotPlayer> command) {
try {
String clazz = command.getClass().getSimpleName();
String name = command.getCommand();
public static void printCommand(final Command<PlotPlayer> command)
{
try
{
final String clazz = command.getClass().getSimpleName();
final String name = command.getCommand();
// Header
String source = "https://github.com/IntellectualSites/PlotSquared/tree/master/src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java";
final String source = "https://github.com/IntellectualSites/PlotSquared/tree/master/src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java";
log("## [" + name.toUpperCase() + "](" + source + ") ");
File file = new File("src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java");
List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<String> perms = getPerms(name, lines);
String comment = getComments(lines);
final File file = new File("src/main/java/com/intellectualcrafters/plot/commands/" + clazz + ".java");
final List<String> lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
final List<String> perms = getPerms(name, lines);
final String comment = getComments(lines);
log("#### Description");
log("`" + command.getDescription() + "`");
if (comment.length() > 0) {
if (comment.length() > 0)
{
log("##### Comments");
log("``` java");
log(comment);
log("```");
}
log("#### Usage");
log("`" + command.getUsage().replaceAll("\\{label\\}", "plot") + "`");
if (command.getRequiredType() != RequiredType.NONE) {
if (command.getRequiredType() != RequiredType.NONE)
{
log("#### Required callers");
log("`" + command.getRequiredType().name() + "`");
}
Set<String> aliases = command.getAliases();
if (aliases.size() > 0) {
final Set<String> aliases = command.getAliases();
if (aliases.size() > 0)
{
log("#### Aliases");
log("`" + StringMan.getString(command.getAliases()) + "`");
}
log("#### Permissions");
log("##### Primary");
log(" - `" + command.getPermission() + "` ");
if (perms.size() > 0) {
if (perms.size() > 0)
{
log("");
log("##### Other");
log(" - `" + StringMan.join(perms, "`\n - `") + "`");
@ -90,54 +97,68 @@ public class GenerateDocs {
log("***");
log("");
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
}
public static List<String> getPerms(String cmd, List<String> lines) {
ArrayList<String> perms = new ArrayList<String>();
Pattern p = Pattern.compile("\"([^\"]*)\"");
for (String line : lines) {
if (line.contains("Permissions.hasPermission(")) {
Matcher m = p.matcher(line);
while (m.find()) {
public static List<String> getPerms(final String cmd, final List<String> lines)
{
final ArrayList<String> perms = new ArrayList<String>();
final Pattern p = Pattern.compile("\"([^\"]*)\"");
for (final String line : lines)
{
if (line.contains("Permissions.hasPermission("))
{
final Matcher m = p.matcher(line);
while (m.find())
{
String perm = m.group(1);
if (perm.endsWith(".")) {
if (perm.endsWith("."))
{
perm += "<arg>";
}
if (perm.startsWith(".")) {
if (perm.startsWith("."))
{
perms.set(perms.size() - 1, perms.get(perms.size() - 1) + perm);
}
else if (perm.contains(".")) {
else if (perm.contains("."))
{
perms.add(perm);
}
}
}
}
switch (cmd.toLowerCase()) {
switch (cmd.toLowerCase())
{
case "auto":
case "claim": {
case "claim":
{
perms.add("plots.plot.#");
break;
}
}
return perms;
}
public static String getComments(List<String> lines) {
StringBuilder result = new StringBuilder();
for (String line : lines) {
public static String getComments(final List<String> lines)
{
final StringBuilder result = new StringBuilder();
for (String line : lines)
{
line = line.trim();
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) {
if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* "))
{
line = (line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")).trim();
result.append(line + "\n");
}
}
return result.toString().trim();
}
public static void log(String s) {
public static void log(final String s)
{
System.out.println(s);
}
}

View File

@ -4,15 +4,16 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "help",
description = "Get this help menu",
aliases = {"he"},
category = CommandCategory.INFO
)
public class Help extends SubCommand {
command = "help",
description = "Get this help menu",
aliases = { "he" },
category = CommandCategory.INFO)
public class Help extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
return true;
}
}

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.PS.SortType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -31,42 +30,53 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "home",
aliases = {"h"},
description = "Go to your plot",
usage = "/plot home [id|alias]",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.NONE
)
public class Home extends SubCommand {
command = "home",
aliases = { "h" },
description = "Go to your plot",
usage = "/plot home [id|alias]",
category = CommandCategory.TELEPORT,
requiredType = RequiredType.NONE)
public class Home extends SubCommand
{
private Plot isAlias(final String a) {
for (final Plot p : PS.get().getPlots()) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
return p;
}
private Plot isAlias(final String a)
{
for (final Plot p : PS.get().getPlots())
{
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) { return p; }
}
return null;
}
@Override
public boolean onCommand(final PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, String[] args)
{
final ArrayList<Plot> plots = PS.get().sortPlotsByTemp(PS.get().getPlots(plr));//PS.get().sortPlots(PS.get().getPlots(plr), SortType.CREATION_DATE, null);
if (plots.size() == 1) {
if (plots.size() == 1)
{
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
return true;
} else if (plots.size() > 1) {
if (args.length < 1) {
}
else if (plots.size() > 1)
{
if (args.length < 1)
{
args = new String[] { "1" };
}
int id = 0;
try {
try
{
id = Integer.parseInt(args[0]);
} catch (final Exception e) {
}
catch (final Exception e)
{
Plot temp;
if ((temp = isAlias(args[0])) != null) {
if (temp.hasOwner()) {
if (temp.isOwner(plr.getUUID())) {
if ((temp = isAlias(args[0])) != null)
{
if (temp.hasOwner())
{
if (temp.isOwner(plr.getUUID()))
{
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
@ -77,19 +87,23 @@ public class Home extends SubCommand {
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
return true;
}
if ((id > (plots.size())) || (id < 1)) {
if ((id > (plots.size())) || (id < 1))
{
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
return false;
}
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(id - 1));
return true;
} else {
}
else
{
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
return true;
}
}
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
public void teleportPlayer(final PlotPlayer player, final Plot plot)
{
MainUtil.teleportPlayer(player, player.getLocation(), plot);
}
}

View File

@ -35,46 +35,54 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "inbox",
description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
permission = "plots.inbox",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Inbox extends SubCommand {
public void displayComments(PlotPlayer player, List<PlotComment> oldComments, int page) {
if (oldComments == null || oldComments.size() == 0) {
command = "inbox",
description = "Review the comments for a plot",
usage = "/plot inbox [inbox] [delete <index>|clear|page]",
permission = "plots.inbox",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Inbox extends SubCommand
{
public void displayComments(final PlotPlayer player, final List<PlotComment> oldComments, int page)
{
if ((oldComments == null) || (oldComments.size() == 0))
{
MainUtil.sendMessage(player, C.INBOX_EMPTY);
return;
}
PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
if (page < 0) {
final PlotComment[] comments = oldComments.toArray(new PlotComment[oldComments.size()]);
if (page < 0)
{
page = 0;
}
// Get the total pages
// int totalPages = ((int) Math.ceil(12 *
final int totalPages = (int) Math.ceil(comments.length / 12);
if (page > totalPages) {
if (page > totalPages)
{
page = totalPages;
}
// Only display 12 per page
int max = (page * 12) + 12;
if (max > comments.length) {
if (max > comments.length)
{
max = comments.length;
}
final StringBuilder string = new StringBuilder();
string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n");
PlotComment c;
// This might work xD
for (int x = (page * 12); x < max; x++) {
for (int x = (page * 12); x < max; x++)
{
c = comments[x];
String color;
if (player.getName().equals(c.senderName)) {
if (player.getName().equals(c.senderName))
{
color = "&a";
}
else {
else
{
color = "&7";
}
string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n");
@ -83,32 +91,43 @@ public class Inbox extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
final Plot plot = MainUtil.getPlot(player.getLocation());
if (args.length == 0) {
if (args.length == 0)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
for (final CommentInbox inbox : CommentManager.inboxes.values()) {
if (inbox.canRead(plot, player)) {
if (!inbox.getComments(plot, new RunnableVal() {
for (final CommentInbox inbox : CommentManager.inboxes.values())
{
if (inbox.canRead(plot, player))
{
if (!inbox.getComments(plot, new RunnableVal()
{
@Override
public void run() {
if (value != null) {
public void run()
{
if (value != null)
{
int total = 0;
int unread = 0;
for (PlotComment comment : (ArrayList<PlotComment>) value) {
for (final PlotComment comment : (ArrayList<PlotComment>) value)
{
total++;
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString()))
{
unread++;
}
}
if (total != 0) {
if (total != 0)
{
String color;
if (unread > 0) {
if (unread > 0)
{
color = "&c";
}
else {
else
{
color = "";
}
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")");
@ -117,7 +136,8 @@ public class Inbox extends SubCommand {
}
sendMessage(player, C.INBOX_ITEM, inbox.toString());
}
})) {
}))
{
sendMessage(player, C.INBOX_ITEM, inbox.toString());
}
}
@ -125,94 +145,120 @@ public class Inbox extends SubCommand {
return false;
}
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
if (inbox == null) {
sendMessage(player, C.INVALID_INBOX, StringMan.join(CommentManager.inboxes.keySet(),", "));
if (inbox == null)
{
sendMessage(player, C.INVALID_INBOX, StringMan.join(CommentManager.inboxes.keySet(), ", "));
return false;
}
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
final int page;
if (args.length > 1) {
switch (args[1].toLowerCase()) {
case "delete": {
if (!inbox.canModify(plot, player)) {
if (args.length > 1)
{
switch (args[1].toLowerCase())
{
case "delete":
{
if (!inbox.canModify(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
return false;
}
if (args.length != 3) {
if (args.length != 3)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
}
final int index;
try {
try
{
index = Integer.parseInt(args[2]);
if (index < 1) {
if (index < 1)
{
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
return false;
}
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
return false;
}
if (!inbox.getComments(plot, new RunnableVal() {
if (!inbox.getComments(plot, new RunnableVal()
{
@Override
public void run() {
List<PlotComment> comments = (List<PlotComment>) value;
if (index > comments.size()) {
public void run()
{
final List<PlotComment> comments = (List<PlotComment>) value;
if (index > comments.size())
{
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
}
PlotComment comment = comments.get(index - 1);
final PlotComment comment = comments.get(index - 1);
inbox.removeComment(plot, comment);
plot.getSettings().removeComment(comment);
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
}
})) {
}))
{
sendMessage(player, C.NOT_IN_PLOT);
return false;
}
return true;
}
case "clear": {
if (!inbox.canModify(plot, player)) {
case "clear":
{
if (!inbox.canModify(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
}
inbox.clearInbox(plot);
ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
if (comments != null) {
final ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
if (comments != null)
{
plot.getSettings().removeComments(comments);
}
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
return true;
}
default: {
try {
page = Integer.parseInt(args[1]) ;
default:
{
try
{
page = Integer.parseInt(args[1]);
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
return false;
}
}
}
}
else {
else
{
page = 1;
}
if (!inbox.canRead(plot, player)) {
if (!inbox.canRead(plot, player))
{
sendMessage(player, C.NO_PERM_INBOX);
return false;
}
if (!inbox.getComments(plot, new RunnableVal() {
if (!inbox.getComments(plot, new RunnableVal()
{
@Override
public void run() {
List<PlotComment> comments = (List<PlotComment>) value;
public void run()
{
final List<PlotComment> comments = (List<PlotComment>) value;
displayComments(player, comments, page);
}
})) {
if (plot == null) {
}))
{
if (plot == null)
{
sendMessage(player, C.NOT_IN_PLOT);
}
else {
else
{
sendMessage(player, C.PLOT_UNOWNED);
}
return false;

View File

@ -25,7 +25,6 @@ import java.util.Collection;
import java.util.UUID;
import java.util.regex.Matcher;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
@ -37,7 +36,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
@ -46,52 +44,56 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "info",
aliases = {"i"},
description = "Display plot info",
usage = "/plot info <id>",
category = CommandCategory.INFO
)
public class Info extends SubCommand {
command = "info",
aliases = { "i" },
description = "Display plot info",
usage = "/plot info <id>",
category = CommandCategory.INFO)
public class Info extends SubCommand
{
public static String getPlayerList(final Collection<UUID> uuids) {
ArrayList<UUID> l = new ArrayList<>(uuids);
if ((l == null) || (l.size() < 1)) {
return C.NONE.s();
}
public static String getPlayerList(final Collection<UUID> uuids)
{
final ArrayList<UUID> l = new ArrayList<>(uuids);
if ((l == null) || (l.size() < 1)) { return C.NONE.s(); }
final String c = C.PLOT_USER_LIST.s();
final StringBuilder list = new StringBuilder();
for (int x = 0; x < l.size(); x++) {
if ((x + 1) == l.size()) {
for (int x = 0; x < l.size(); x++)
{
if ((x + 1) == l.size())
{
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
} else {
}
else
{
list.append(c.replace("%user%", getPlayerName(l.get(x))));
}
}
return list.toString();
}
public static String getPlayerName(final UUID uuid) {
if (uuid == null) {
return C.UNKNOWN.s();
}
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
return "everyone";
}
public static String getPlayerName(final UUID uuid)
{
if (uuid == null) { return C.UNKNOWN.s(); }
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) { return "everyone"; }
final String name = UUIDHandler.getName(uuid);
if (name == null) {
return "unknown";
}
if (name == null) { return "unknown"; }
return name;
}
@Override
public boolean onCommand(final PlotPlayer player, String[] args) {
public boolean onCommand(final PlotPlayer player, String[] args)
{
String arg = null;
Plot plot;
if (args.length > 0) arg = args[0] + "";
if (arg != null) {
switch (arg) {
if (args.length > 0)
{
arg = args[0] + "";
}
if (arg != null)
{
switch (arg)
{
case "trusted":
case "alias":
case "inv":
@ -107,49 +109,66 @@ public class Info extends SubCommand {
break;
default:
plot = MainUtil.getPlotFromString(player, arg, false);
if (args.length == 2) {
if (args.length == 2)
{
arg = args[1];
}
else {
else
{
arg = null;
}
break;
}
}
else {
else
{
plot = MainUtil.getPlotFromString(player, null, false);
}
if (plot == null && arg != null) {
if ((plot == null) && (arg != null))
{
plot = MainUtil.getPlotFromString(player, null, false);
}
if (plot == null) {
if (plot == null)
{
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
}
if (arg != null) {
if (args.length == 1) {
if (arg != null)
{
if (args.length == 1)
{
args = new String[0];
}
else {
else
{
args = new String[] { args[1] };
}
}
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
PlotInventory inv = new PlotInventory(player) {
if ((args.length == 1) && args[0].equalsIgnoreCase("inv"))
{
final PlotInventory inv = new PlotInventory(player)
{
@Override
public boolean onClick(int index) {
public boolean onClick(final int index)
{
// TODO InfoInventory not implemented yet!!!!!!!!
// See plot rating or musicsubcommand on examples
return false;
}
};
UUID uuid = player.getUUID();
String name = MainUtil.getName(plot.owner);
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", new String[] { "&cID: &6" + plot.getId().toString(), "&cOwner: &6" + name, "&cAlias: &6" + plot.getSettings().getAlias(), "&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + plot.isAdded(uuid), "&cIs Denied: &6" + plot.isDenied(uuid)}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", new String[] {"&cAmount: &6" + plot.getTrusted().size(), "&8Click to view a list of the trusted users"}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", new String[] {"&cAmount: &6" + plot.getMembers().size(), "&8Click to view a list of plot members"}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", new String[] {"&cDenied", "&cAmount: &6" + plot.getDenied().size(), "&8Click to view a list of denied players"}));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] {"&cFlags", "&cAmount: &6" + plot.getSettings().flags.size(), "&8Click to view a list of plot flags"}));
final UUID uuid = player.getUUID();
final String name = MainUtil.getName(plot.owner);
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", new String[] {
"&cID: &6" + plot.getId().toString(),
"&cOwner: &6" + name,
"&cAlias: &6" + plot.getSettings().getAlias(),
"&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(),
"&cCan Build: &6" + plot.isAdded(uuid),
"&cIs Denied: &6" + plot.isDenied(uuid) }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", new String[] { "&cAmount: &6" + plot.getTrusted().size(), "&8Click to view a list of the trusted users" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", new String[] { "&cAmount: &6" + plot.getMembers().size(), "&8Click to view a list of plot members" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", new String[] { "&cDenied", "&cAmount: &6" + plot.getDenied().size(), "&8Click to view a list of denied players" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] { "&cFlags", "&cAmount: &6" + plot.getSettings().flags.size(), "&8Click to view a list of plot flags" }));
inv.openInventory();
return true;
}
@ -162,27 +181,33 @@ public class Info extends SubCommand {
trustedEveryone = (plot.getMembers() != null) && plot.getMembers().contains(DBFunc.everyone);
}
// Unclaimed?
if (!hasOwner && !containsEveryone && !trustedEveryone) {
if (!hasOwner && !containsEveryone && !trustedEveryone)
{
MainUtil.sendMessage(player, C.PLOT_INFO_UNCLAIMED, (plot.id.x + ";" + plot.id.y));
return true;
}
String info = C.PLOT_INFO.s();
if (arg != null) {
if (arg != null)
{
info = getCaption(arg);
if (info == null) {
if (info == null)
{
MainUtil.sendMessage(player, "&6Categories&7: &amembers&7, &aalias&7, &abiome&7, &adenied&7, &aflags&7, &aid&7, &asize&7, &atrusted&7, &aowner&7, &arating");
return false;
}
formatAndSend(info, plot.world, plot, player, true);
}
else {
else
{
formatAndSend(info, plot.world, plot, player, false);
}
return true;
}
private String getCaption(final String string) {
switch (string) {
private String getCaption(final String string)
{
switch (string)
{
case "trusted":
return C.PLOT_INFO_TRUSTED.s();
case "alias":
@ -208,25 +233,29 @@ public class Info extends SubCommand {
}
}
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full) {
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full)
{
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
final String alias = plot.getSettings().getAlias().length() > 0 ? plot.getSettings().getAlias() : C.NONE.s();
Location top = MainUtil.getPlotTopLoc(world, plot.id);
Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(world, plot.id);
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final String biome = BlockManager.manager.getBiome(plot.world, bot.getX() + ((top.getX() - bot.getX()) / 2), bot.getZ() + ((top.getZ() - bot.getZ()) / 2));
final String trusted = getPlayerList(plot.getTrusted());
final String members = getPlayerList(plot.getMembers());
final String denied = getPlayerList(plot.getDenied());
Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description");
final Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description");
final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
final String flags = StringMan.replaceFromMap("$2" + (StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "$1, $2") : C.NONE.s()), C.replacements);
final String flags = StringMan.replaceFromMap(
"$2"
+ (StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringMan.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true)
.values(), "$1, $2") : C.NONE.s()), C.replacements);
final boolean build = plot.isAdded(player.getUUID());
String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
info = info.replaceAll("%alias%", alias);
info = info.replaceAll("%id%", id.toString());
@ -242,27 +271,34 @@ public class Info extends SubCommand {
info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags));
info = info.replaceAll("%build%", build + "");
info = info.replaceAll("%desc%", "No description set.");
if (info.contains("%rating%")) {
if (info.contains("%rating%"))
{
final String newInfo = info;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
int max = 10;
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 0) {
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 0))
{
max = 8;
}
String info;
if (full && Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() > 1) {
if (full && (Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() > 1))
{
String rating = "";
String prefix = "";
double[] ratings = MainUtil.getAverageRatings(plot);
for (int i = 0; i < ratings.length; i++) {
final double[] ratings = MainUtil.getAverageRatings(plot);
for (int i = 0; i < ratings.length; i++)
{
rating += prefix + Settings.RATING_CATEGORIES.get(i) + "=" + String.format("%.1f", ratings[i]);
prefix = ",";
}
info = newInfo.replaceAll("%rating%", rating);
}
else {
else
{
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
}
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);

View File

@ -31,38 +31,41 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "kick",
aliases = {"k"},
description = "Kick a player from your plot",
permission = "plots.kick",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Kick extends SubCommand {
command = "kick",
aliases = { "k" },
description = "Kick a player from your plot",
permission = "plots.kick",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Kick extends SubCommand
{
@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 == null || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick"))) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.kick")))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (args.length != 1) {
if (args.length != 1)
{
MainUtil.sendMessage(plr, "&c/plot kick <player>");
return false;
}
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
if (player == null) {
if (player == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
Location otherLoc = player.getLocation();
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc))) {
final Location otherLoc = player.getLocation();
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc)))
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import java.util.UUID;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
@ -31,38 +30,40 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "limit",
permission = "plots.limit",
description = "Set or increment player plot claim limits",
aliases = {"setlimit"},
usage = "/plot limit <player> <expression>",
category = CommandCategory.DEBUG
)
public class Limit extends SubCommand {
command = "limit",
permission = "plots.limit",
description = "Set or increment player plot claim limits",
aliases = { "setlimit" },
usage = "/plot limit <player> <expression>",
category = CommandCategory.DEBUG)
public class Limit extends SubCommand
{
public Limit() {
public Limit()
{
requiredArguments = new Argument[] {
Argument.String,
Argument.String
Argument.String,
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
// get current plot limit
// increase
// EconHandler.manager.setPermission(op, perm, value);
// EconHandler.manager.setPermission(op, perm, value);
plr.sendMessage("TODO");
return true;
}
}

View File

@ -19,90 +19,106 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "load",
aliases = {"restore"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Load your plot",
permission = "plots.load",
usage = "/plot restore"
)
public class Load extends SubCommand {
command = "load",
aliases = { "restore" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
description = "Load your plot",
permission = "plots.load",
usage = "/plot restore")
public class Load extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (!Settings.METRICS)
{
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
final Plot plot = MainUtil.getPlot(plr.getLocation());
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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.load")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.load"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (MainUtil.runners.containsKey(plot))
{
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (args.length != 0) {
if (args.length == 1) {
if (args.length != 0)
{
if (args.length == 1)
{
// TODO load save here
List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null)
{
// No schematics found:
MainUtil.sendMessage(plr, C.LOAD_NULL);
return false;
}
String schem;
try {
try
{
schem = schematics.get(Integer.parseInt(args[0]) - 1);
}
catch (Exception e) {
catch (final Exception e)
{
// use /plot load <index>
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + schematics.size() + ")");
return false;
}
final URL url;
try {
try
{
url = new URL(Settings.WEB_URL + "saves/" + plr.getUUID() + "/" + schem + ".schematic");
} catch (MalformedURLException e) {
}
catch (final MalformedURLException e)
{
e.printStackTrace();
MainUtil.sendMessage(plr, C.LOAD_FAILED);
return false;
}
MainUtil.runners.put(plot, 1);
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
Schematic schematic = SchematicHandler.manager.getSchematic(url);
if (schematic == null) {
public void run()
{
final Schematic schematic = SchematicHandler.manager.getSchematic(url);
if (schematic == null)
{
MainUtil.runners.remove(plot);
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
return;
}
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>()
{
@Override
public void run() {
public void run()
{
MainUtil.runners.remove(plot);
if (this.value) {
if (value)
{
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
}
else {
else
{
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
}
@ -115,18 +131,22 @@ public class Load extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot load <index>");
return false;
}
// list schematics
List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null)
{
MainUtil.runners.put(plot, 1);
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
public void run()
{
final List<String> schematics = SchematicHandler.manager.getSaves(plr.getUUID());
MainUtil.runners.remove(plot);
if (schematics == null || schematics.size() == 0) {
if ((schematics == null) || (schematics.size() == 0))
{
MainUtil.sendMessage(plr, C.LOAD_FAILED);
return;
}
@ -135,76 +155,91 @@ public class Load extends SubCommand {
}
});
}
else {
else
{
displaySaves(plr, 0);
}
return true;
}
public void displaySaves(PlotPlayer player, int page) {
List<String> schematics = (List<String>) player.getMeta("plot_schematics");
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
try {
String schem = schematics.get(i);
String[] split = schem.split("_");
if (split.length != 6) {
public void displaySaves(final PlotPlayer player, final int page)
{
final List<String> schematics = (List<String>) player.getMeta("plot_schematics");
for (int i = 0; i < Math.min(schematics.size(), 32); i++)
{
try
{
final String schem = schematics.get(i);
final String[] split = schem.split("_");
if (split.length != 6)
{
continue;
}
String time = secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
String world = split[1];
PlotId id = PlotId.fromString(split[2] + ";" + split[3]);
String size = split[4];
String server = split[5].replaceAll(".schematic", "");
final String time = secToTime((System.currentTimeMillis() / 1000) - (Long.parseLong(split[0])));
final String world = split[1];
final PlotId id = PlotId.fromString(split[2] + ";" + split[3]);
final String size = split[4];
final String server = split[5].replaceAll(".schematic", "");
String color;
if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server)) {
if (PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "").equals(server))
{
color = "$4";
}
else {
else
{
color = "$1";
}
MainUtil.sendMessage(player, "$3[$2" + (i + 1) + "$3] " + color + time + "$3 | " + color + world + ";" + id + "$3 | " + color + size + "x" + size);
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
}
MainUtil.sendMessage(player, C.LOAD_LIST);
}
public String secToTime(long time) {
StringBuilder toreturn = new StringBuilder();
public String secToTime(long time)
{
final StringBuilder toreturn = new StringBuilder();
int years = 0;
int weeks = 0;
int days = 0;
int hours = 0;
int minutes = 0;
if (time>=33868800) {
years = (int) (time/33868800);
time-=years*33868800;
toreturn.append(years+"y ");
if (time >= 33868800)
{
years = (int) (time / 33868800);
time -= years * 33868800;
toreturn.append(years + "y ");
}
if (time>=604800) {
weeks = (int) (time/604800);
time-=weeks*604800;
toreturn.append(weeks+"w ");
if (time >= 604800)
{
weeks = (int) (time / 604800);
time -= weeks * 604800;
toreturn.append(weeks + "w ");
}
if (time>=86400) {
days = (int) (time/86400);
time-=days*86400;
toreturn.append(days+"d ");
if (time >= 86400)
{
days = (int) (time / 86400);
time -= days * 86400;
toreturn.append(days + "d ");
}
if (time>=3600) {
hours = (int) (time/3600);
time-=hours*3600;
toreturn.append(hours+"h ");
if (time >= 3600)
{
hours = (int) (time / 3600);
time -= hours * 3600;
toreturn.append(hours + "h ");
}
if (time>=60) {
minutes = (int) (time/60);
time-=minutes*60;
toreturn.append(minutes+"m ");
if (time >= 60)
{
minutes = (int) (time / 60);
time -= minutes * 60;
toreturn.append(minutes + "m ");
}
if (toreturn.equals("")||time>0){
toreturn.append((time)+"s ");
if (toreturn.equals("") || (time > 0))
{
toreturn.append((time) + "s ");
}
return toreturn.toString().trim();
}

View File

@ -42,22 +42,24 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "merge",
aliases = {"m"},
description = "Merge the plot you are standing on, with another plot",
permission = "plots.merge",
usage = "/plot merge [direction]",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Merge extends SubCommand {
command = "merge",
aliases = { "m" },
description = "Merge the plot you are standing on, with another plot",
permission = "plots.merge",
usage = "/plot merge [direction]",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Merge extends SubCommand
{
public final static String[] values = new String[] { "north", "east", "south", "west" };
public final static String[] aliases = new String[] { "n", "e", "s", "w" };
public static String direction(float yaw) {
public static String direction(float yaw)
{
yaw = yaw / 90;
final int i = Math.round(yaw);
switch (i) {
switch (i)
{
case -4:
case 0:
case 4:
@ -77,25 +79,28 @@ public class Merge extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location loc = plr.getLocationFull();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot == null) || !plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || !plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
if (!plot.isOwner(plr.getUUID()) && !admin) {
if (!plot.isOwner(plr.getUUID()) && !admin)
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
int direction = -1;
if (args.length == 0) {
switch (direction(plr.getLocationFull().getYaw())) {
if (args.length == 0)
{
switch (direction(plr.getLocationFull().getYaw()))
{
case "NORTH":
direction = 0;
break;
@ -110,20 +115,25 @@ public class Merge extends SubCommand {
break;
}
}
else {
if (args[0].equalsIgnoreCase("all")) {
plot.autoMerge(args.length != 2 || !args[1].equalsIgnoreCase("false"));
else
{
if (args[0].equalsIgnoreCase("all"))
{
plot.autoMerge((args.length != 2) || !args[1].equalsIgnoreCase("false"));
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
return true;
}
for (int i = 0; i < values.length; i++) {
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
for (int i = 0; i < values.length; i++)
{
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i]))
{
direction = i;
break;
}
}
}
if (direction == -1) {
if (direction == -1)
{
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
return false;
@ -132,7 +142,8 @@ public class Merge extends SubCommand {
PlotId top = MainUtil.getTopPlot(plot).id;
ArrayList<PlotId> selPlots;
final String world = loc.getWorld();
switch (direction) {
switch (direction)
{
case 0: // north = -y
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
break;
@ -148,8 +159,9 @@ public class Merge extends SubCommand {
default:
return false;
}
int size = selPlots.size();
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size) {
final int size = selPlots.size();
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size)
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
return false;
}
@ -164,20 +176,24 @@ public class Merge extends SubCommand {
final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
boolean multiMerge = false;
final HashSet<UUID> multiUUID = new HashSet<UUID>();
HashSet<PlotId> multiPlots = new HashSet<>();
final HashSet<PlotId> multiPlots = new HashSet<>();
final UUID u1 = plot.owner;
for (final PlotId myid : plots) {
for (final PlotId myid : plots)
{
final Plot myplot = PS.get().getPlot(world, myid);
if (myplot == null || myplot.owner == null) {
if ((myplot == null) || (myplot.owner == null))
{
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
UUID u2 = myplot.owner;
if (u2.equals(u1)) {
final UUID u2 = myplot.owner;
if (u2.equals(u1))
{
continue;
}
PlotPlayer p2 = UUIDHandler.getPlayer(u2);
if (p2 == null) {
final PlotPlayer p2 = UUIDHandler.getPlayer(u2);
if (p2 == null)
{
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
@ -185,30 +201,40 @@ public class Merge extends SubCommand {
multiPlots.add(myid);
multiUUID.add(u2);
}
if (multiMerge) {
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
if (multiMerge)
{
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
return false;
}
for (final UUID uuid : multiUUID) {
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() {
for (final UUID uuid : multiUUID)
{
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable()
{
@Override
public void run() {
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
public void run()
{
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
multiUUID.remove(uuid);
if (multiUUID.size() == 0) {
PlotPlayer pp = UUIDHandler.getPlayer(u1);
if (pp == null) {
if (multiUUID.size() == 0)
{
final PlotPlayer pp = UUIDHandler.getPlayer(u1);
if (pp == null)
{
sendMessage(accepter, C.MERGE_NOT_VALID);
return;
}
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY)
{
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost)
{
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return;
}
@ -217,7 +243,8 @@ public class Merge extends SubCommand {
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return;
}
@ -233,11 +260,14 @@ public class Merge extends SubCommand {
return true;
}
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY)
{
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
if (cost > 0d)
{
if (EconHandler.manager.getMoney(plr) < cost)
{
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return false;
}
@ -246,7 +276,8 @@ public class Merge extends SubCommand {
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return false;
}

View File

@ -33,68 +33,79 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "move",
description = "Move a plot",
aliases = {"debugmove"},
permission = "plots.move",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Move extends SubCommand {
command = "move",
description = "Move a plot",
aliases = { "debugmove" },
permission = "plots.move",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Move extends SubCommand
{
public Move() {
public Move()
{
requiredArguments = new Argument[] {
Argument.PlotID
Argument.PlotID
};
}
@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 plot1 = MainUtil.getPlot(loc);
if (plot1 == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
if (plot1 == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s()))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final String world = loc.getWorld();
final PlotId plot2id = MainUtil.parseId(args[0]);
if ((plot2id == null)) {
if ((plot2id == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
return false;
}
String world2;
if (args.length == 2) {
PlotWorld other = PS.get().getPlotWorld(args[1]);
PlotWorld current = PS.get().getPlotWorld(loc.getWorld());
if (other == null || current == null || !other.equals(current)) {
if (args.length == 2)
{
final PlotWorld other = PS.get().getPlotWorld(args[1]);
final PlotWorld current = PS.get().getPlotWorld(loc.getWorld());
if ((other == null) || (current == null) || !other.equals(current))
{
MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE);
return false;
}
world2 = other.worldname;
world2 = other.worldname;
}
else {
world2 = world;
else
{
world2 = world;
}
Plot plot2 = MainUtil.getPlot(world2, plot2id);
if (plot1.equals(plot2)) {
final Plot plot2 = MainUtil.getPlot(world2, plot2id);
if (plot1.equals(plot2))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
return false;
}
if (MainUtil.move(plot1, plot2, new Runnable() {
if (MainUtil.move(plot1, plot2, new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
}
})) {
}))
{
return true;
} else {
}
else
{
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
return false;
}

View File

@ -34,53 +34,60 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "music",
permission = "plots.music",
description = "Player music in a plot",
usage = "/plot music",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class MusicSubcommand extends SubCommand {
command = "music",
permission = "plots.music",
description = "Player music in a plot",
usage = "/plot music",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class MusicSubcommand extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.isAdded(player.getUUID())) {
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
if (!plot.isAdded(player.getUUID()))
{
sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox") {
public boolean onClick(int index) {
PlotItemStack item = getItem(index);
final PlotInventory inv = new PlotInventory(player, 2, "Plot Jukebox")
{
@Override
public boolean onClick(final int index)
{
final PlotItemStack item = getItem(index);
if (item == null) {
return true;
return true;
}
int id = item.id == 7 ? 0 : item.id;
if (id == 0) {
final int id = item.id == 7 ? 0 : item.id;
if (id == 0)
{
FlagManager.removePlotFlag(plot, "music");
}
else {
else
{
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id));
}
return false;
}
};
int index = 0;
for (int i = 2256; i < 2268; i++) {
String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
String[] lore = {"&r&aClick to play!"};
PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
for (int i = 2256; i < 2268; i++)
{
final String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0));
final String[] lore = { "&r&aClick to play!" };
final PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
inv.setItem(index, item);
index++;
}
if (player.getMeta("music") != null) {
String name = "&r&6Cancel music";
String[] lore = {"&r&cClick to cancel!"};
if (player.getMeta("music") != null)
{
final String name = "&r&6Cancel music";
final String[] lore = { "&r&cClick to cancel!" };
inv.setItem(index, new PlotItemStack(7, (short) 0, 1, name, lore));
}
inv.openInventory();

View File

@ -35,128 +35,147 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "purge",
permission = "plots.admin",
description = "Purge all plots for a world",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.CONSOLE
)
public class Purge extends SubCommand {
public PlotId getId(final String id) {
try {
command = "purge",
permission = "plots.admin",
description = "Purge all plots for a world",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.CONSOLE)
public class Purge extends SubCommand
{
public PlotId getId(final String id)
{
try
{
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
}
catch (final Exception e)
{
return null;
}
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length == 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length == 1)
{
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
if (id != null)
{
MainUtil.sendMessage(plr, "/plot purxe x;z &l<world>");
return false;
}
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (uuid != null)
{
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
return false;
}
if (arg.equals("player")) {
if (arg.equals("player"))
{
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
return false;
}
if (arg.equals("unowned")) {
if (arg.equals("unowned"))
{
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
return false;
}
if (arg.equals("unknown")) {
if (arg.equals("unknown"))
{
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
return false;
}
if (arg.equals("all")) {
if (arg.equals("all"))
{
MainUtil.sendMessage(plr, "/plot purge all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false;
}
final String worldname = args[1];
if (!PS.get().getAllPlotsRaw().containsKey(worldname)) {
if (!PS.get().getAllPlotsRaw().containsKey(worldname))
{
MainUtil.sendMessage(plr, "INVALID WORLD");
return false;
}
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
if (id != null)
{
final HashSet<Integer> ids = new HashSet<Integer>();
final int DBid = DBFunc.getId(MainUtil.getPlot(worldname, id));
if (DBid != Integer.MAX_VALUE) {
if (DBid != Integer.MAX_VALUE)
{
ids.add(DBid);
}
DBFunc.purgeIds(worldname, ids);
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
}
if (arg.equals("all")) {
if (arg.equals("all"))
{
final Set<PlotId> ids = PS.get().getPlots(worldname).keySet();
int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found");
}
final int length = ids.size();
if (length == 0) { return MainUtil.sendMessage(null, "&cNo plots found"); }
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
if (arg.equals("unknown")) {
if (arg.equals("unknown"))
{
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) {
if (plot.owner != null) {
for (final Plot plot : plots)
{
if (plot.owner != null)
{
final String name = UUIDHandler.getName(plot.owner);
if (name == null) {
if (name == null)
{
ids.add(plot.id);
}
}
}
int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found");
}
final int length = ids.size();
if (length == 0) { return MainUtil.sendMessage(null, "&cNo plots found"); }
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
if (arg.equals("unowned")) {
if (arg.equals("unowned"))
{
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) {
if (plot.owner == null) {
for (final Plot plot : plots)
{
if (plot.owner == null)
{
ids.add(plot.id);
}
}
int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found");
}
final int length = ids.size();
if (length == 0) { return MainUtil.sendMessage(null, "&cNo plots found"); }
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (uuid != null)
{
final Set<Plot> plots = PS.get().getPlots(worldname, uuid);
final Set<PlotId> ids = new HashSet<>();
for (final Plot plot : plots) {
for (final Plot plot : plots)
{
ids.add(plot.id);
}
int length = ids.size();
final int length = ids.size();
DBFunc.purge(worldname, ids);
return finishPurge(length);
}
@ -164,7 +183,8 @@ public class Purge extends SubCommand {
return false;
}
private boolean finishPurge(final int amount) {
private boolean finishPurge(final int amount)
{
MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + "");
return false;
}

View File

@ -28,13 +28,11 @@ import java.util.Map.Entry;
import java.util.UUID;
import org.apache.commons.lang.mutable.MutableInt;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotInventory;
@ -46,47 +44,60 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.events.PlotRateEvent;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "rate",
permission = "plots.rate",
description = "Rate the plot",
usage = "/plot rate [#|next]",
aliases = {"rt"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Rate extends SubCommand {
command = "rate",
permission = "plots.rate",
description = "Rate the plot",
usage = "/plot rate [#|next]",
aliases = { "rt" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Rate extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("next")) {
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
Collections.sort(plots, new Comparator<Plot>() {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("next"))
{
final ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
Collections.sort(plots, new Comparator<Plot>()
{
@Override
public int compare(Plot p1, Plot p2) {
public int compare(final Plot p1, final Plot p2)
{
double v1 = 0;
double v2 = 0;
if (p1.getSettings().ratings != null) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
if (p1.getSettings().ratings != null)
{
for (final Entry<UUID, Rating> entry : p1.getRatings().entrySet())
{
v1 -= 11 - entry.getValue().getAverageRating();
}
}
if (p2.getSettings().ratings != null) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
if (p2.getSettings().ratings != null)
{
for (final Entry<UUID, Rating> entry : p2.getRatings().entrySet())
{
v2 -= 11 - entry.getValue().getAverageRating();
}
}
return v2 > v1 ? 1 : -1;
}
});
UUID uuid = player.getUUID();
for (Plot p : plots) {
if ((!Settings.REQUIRE_DONE || p.getSettings().flags.containsKey("done")) && p.isBasePlot() && (p.getSettings().ratings == null || !p.getSettings().ratings.containsKey(uuid)) && !p.isAdded(uuid)) {
final UUID uuid = player.getUUID();
for (final Plot p : plots)
{
if ((!Settings.REQUIRE_DONE || p.getSettings().flags.containsKey("done"))
&& p.isBasePlot()
&& ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid))
&& !p.isAdded(uuid))
{
MainUtil.teleportPlayer(player, player.getLocation(), p);
MainUtil.sendMessage(player, C.RATE_THIS);
return true;
@ -98,40 +109,49 @@ public class Rate extends SubCommand {
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); }
if (!plot.hasOwner())
{
sendMessage(player, C.RATING_NOT_OWNED);
return false;
}
if (plot.isOwner(player.getUUID())) {
if (plot.isOwner(player.getUUID()))
{
sendMessage(player, C.RATING_NOT_YOUR_OWN);
return false;
}
if (Settings.REQUIRE_DONE && !plot.getSettings().flags.containsKey("done")) {
if (Settings.REQUIRE_DONE && !plot.getSettings().flags.containsKey("done"))
{
sendMessage(player, C.RATING_NOT_DONE);
return false;
}
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
final Runnable run = new Runnable() {
if ((Settings.RATING_CATEGORIES != null) && (Settings.RATING_CATEGORIES.size() != 0))
{
final Runnable run = new Runnable()
{
@Override
public void run() {
if (plot.getSettings().ratings.containsKey(player.getUUID())) {
public void run()
{
if (plot.getSettings().ratings.containsKey(player.getUUID()))
{
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return;
}
final MutableInt index = new MutableInt(0);
final MutableInt rating = new MutableInt(0);
String title = Settings.RATING_CATEGORIES.get(0);
PlotInventory inventory = new PlotInventory(player, 1, title) {
public boolean onClick(int i) {
final String title = Settings.RATING_CATEGORIES.get(0);
final PlotInventory inventory = new PlotInventory(player, 1, title)
{
@Override
public boolean onClick(final int i)
{
rating.add((i + 1) * Math.pow(10, index.intValue()));
index.increment();
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
if (index.intValue() >= Settings.RATING_CATEGORIES.size())
{
close();
int rV = rating.intValue();
Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV));
final int rV = rating.intValue();
final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV));
plot.getSettings().ratings.put(player.getUUID(), result.getAggregate());
DBFunc.setRating(plot, player.getUUID(), rV);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
@ -139,9 +159,11 @@ public class Rate extends SubCommand {
return false;
}
setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
if (Permissions.hasPermission(player, "plots.comment")) {
Command<PlotPlayer> command = MainCommand.getInstance().getCommand("comment");
if (command != null) {
if (Permissions.hasPermission(player, "plots.comment"))
{
final Command<PlotPlayer> command = MainCommand.getInstance().getCommand("comment");
if (command != null)
{
MainUtil.sendMessage(player, C.COMMENT_THIS, command.getUsage().replaceAll("{label}", "plot"));
}
}
@ -160,11 +182,15 @@ public class Rate extends SubCommand {
inventory.openInventory();
}
};
if (plot.getSettings().ratings == null) {
if (!Settings.CACHE_RATINGS) {
TaskManager.runTaskAsync(new Runnable() {
if (plot.getSettings().ratings == null)
{
if (!Settings.CACHE_RATINGS)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run();
}
@ -176,43 +202,54 @@ public class Rate extends SubCommand {
run.run();
return true;
}
if (args.length < 1) {
if (args.length < 1)
{
sendMessage(player, C.RATING_NOT_VALID);
return true;
}
final String arg = args[0];
final int rating;
if (MathMan.isInteger(arg) && arg.length() < 3 && arg.length() > 0) {
if (MathMan.isInteger(arg) && (arg.length() < 3) && (arg.length() > 0))
{
rating = Integer.parseInt(arg);
if (rating > 10) {
if (rating > 10)
{
sendMessage(player, C.RATING_NOT_VALID);
return false;
}
}
else {
else
{
sendMessage(player, C.RATING_NOT_VALID);
return false;
}
final UUID uuid = player.getUUID();
final Runnable run = new Runnable() {
final Runnable run = new Runnable()
{
@Override
public void run() {
if (plot.getSettings().ratings.containsKey(uuid)) {
public void run()
{
if (plot.getSettings().ratings.containsKey(uuid))
{
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return;
}
Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
int resultVal = result.getAggregate();
final Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
final int resultVal = result.getAggregate();
plot.getSettings().ratings.put(uuid, resultVal);
DBFunc.setRating(plot, uuid, resultVal);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
}
};
if (plot.getSettings().ratings == null) {
if (!Settings.CACHE_RATINGS) {
TaskManager.runTaskAsync(new Runnable() {
if (plot.getSettings().ratings == null)
{
if (!Settings.CACHE_RATINGS)
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run();
}

View File

@ -35,30 +35,35 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "regenallroads",
description = "Regenerate all roads in the map using the set road schematic",
aliases = {"rgar"},
usage = "/plot regenallroads <world>",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.regenallroads"
)
public class RegenAllRoads extends SubCommand {
command = "regenallroads",
description = "Regenerate all roads in the map using the set road schematic",
aliases = { "rgar" },
usage = "/plot regenallroads <world>",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.regenallroads")
public class RegenAllRoads extends SubCommand
{
public RegenAllRoads() {
public RegenAllRoads()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
int height = 0;
if (args.length == 2) {
try {
if (args.length == 2)
{
try
{
height = Integer.parseInt(args[1]);
}
catch (NumberFormatException e) {
catch (final NumberFormatException e)
{
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(0, 256)");
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
return false;
@ -66,7 +71,8 @@ public class RegenAllRoads extends SubCommand {
}
final String name = args[0];
final PlotManager manager = PS.get().getPlotManager(name);
if ((manager == null) || !(manager instanceof HybridPlotManager)) {
if ((manager == null) || !(manager instanceof HybridPlotManager))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
@ -76,7 +82,8 @@ public class RegenAllRoads extends SubCommand {
MainUtil.sendMessage(plr, "&6Potential chunks to update: &7" + (chunks.size() * 1024));
MainUtil.sendMessage(plr, "&6Estimated time: &7" + (chunks.size()) + " seconds");
final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, "&cCannot schedule mass schematic update! (Is one already in progress?)");
return false;
}

View File

@ -29,30 +29,35 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "reload",
permission = "plots.admin.command.reload",
description = "Reload configurations",
usage = "/plot reload",
category = CommandCategory.INFO
)
public class Reload extends SubCommand {
command = "reload",
permission = "plots.admin.command.reload",
description = "Reload configurations",
usage = "/plot reload",
category = CommandCategory.INFO)
public class Reload extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
try {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
try
{
// The following won't affect world generation, as that has to be
// loaded during startup unfortunately.
PS.get().config.load(PS.get().configFile);
PS.get().setupConfig();
C.load(PS.get().translationFile);
for (final String pw : PS.get().getPlotWorlds()) {
for (final String pw : PS.get().getPlotWorlds())
{
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw);
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw);
plotworld.saveConfiguration(section);
plotworld.loadDefaultConfiguration(section);
}
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
} catch (final Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
}

View File

@ -36,73 +36,84 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "remove",
aliases = {"r"},
description = "Remove a player from a plot",
usage = "/plot remove <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.remove"
)
public class Remove extends SubCommand {
command = "remove",
aliases = { "r" },
description = "Remove a player from a plot",
usage = "/plot remove <player>",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.remove")
public class Remove extends SubCommand
{
public Remove() {
public Remove()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length != 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length != 1)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot remove <player>");
return true;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((plot == null) || !plot.hasOwner()) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((plot == null) || !plot.hasOwner())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.remove")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.remove"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
case "unknown": {
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
switch (args[0])
{
case "unknown":
{
final ArrayList<UUID> toRemove = new ArrayList<>();
final HashSet<UUID> all = new HashSet<>();
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
if (UUIDHandler.getName(uuid) == null) {
for (final UUID uuid : all)
{
if (UUIDHandler.getName(uuid) == null)
{
toRemove.add(uuid);
count++;
}
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeDenied(uuid);
plot.removeTrusted(uuid);
plot.removeMember(uuid);
}
break;
}
case "*": {
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
case "*":
{
final ArrayList<UUID> toRemove = new ArrayList<>();
final HashSet<UUID> all = new HashSet<>();
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
for (final UUID uuid : all)
{
toRemove.add(uuid);
count++;
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeDenied(uuid);
plot.removeTrusted(uuid);
plot.removeMember(uuid);
@ -110,33 +121,47 @@ public class Remove extends SubCommand {
break;
}
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null)
{
if (plot.getTrusted().contains(uuid))
{
if (plot.removeTrusted(uuid))
{
count++;
}
} else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
}
else if (plot.getMembers().contains(uuid))
{
if (plot.removeMember(uuid))
{
count++;
}
} else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
}
else if (plot.getDenied().contains(uuid))
{
if (plot.removeDenied(uuid))
{
count++;
}
}
}
break;
}
if (count == 0) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (count == 0)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
else {
else
{
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;

View File

@ -2,13 +2,16 @@ package com.intellectualcrafters.plot.commands;
import com.plotsquared.general.commands.CommandCaller;
public enum RequiredType {
public enum RequiredType
{
CONSOLE,
PLAYER,
NONE;
public boolean allows(CommandCaller player) {
switch (this) {
public boolean allows(final CommandCaller player)
{
switch (this)
{
case NONE:
return true;
default:

View File

@ -19,66 +19,73 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "save",
aliases = {"backup"},
description = "Save your plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.save"
)
public class Save extends SubCommand {
command = "save",
aliases = { "backup" },
description = "Save your plot",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE,
permission = "plots.save")
public class Save extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (!Settings.METRICS) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (!Settings.METRICS)
{
MainUtil.sendMessage(plr, "&cPlease enable metrics in order to use this command.\n&7 - Or host it yourself if you don't like the free service");
return false;
}
final String world = plr.getLocation().getWorld();
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
if (!PS.get().isPlotWorld(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); }
final Plot plot = MainUtil.getPlot(plr.getLocation());
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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.save")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.save"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
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);
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>()
{
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
public void run()
{
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
String time = (System.currentTimeMillis() / 1000) + "";
String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "");
int size = plot.getTop().getX() - plot.getBottom().getX() + 1;
PlotId id = plot.id;
String world = plot.world.replaceAll("[^A-Za-z0-9]", "");
String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;
UUID uuid = plr.getUUID();
URL url = SchematicHandler.manager.upload(value, uuid, file);
if (url == null) {
public void run()
{
final String time = (System.currentTimeMillis() / 1000) + "";
final String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "");
final int size = (plot.getTop().getX() - plot.getBottom().getX()) + 1;
final PlotId id = plot.id;
final String world = plot.world.replaceAll("[^A-Za-z0-9]", "");
final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;
final UUID uuid = plr.getUUID();
final URL url = SchematicHandler.manager.upload(value, uuid, file);
if (url == null)
{
MainUtil.sendMessage(plr, C.SAVE_FAILED);
MainUtil.runners.remove(plot);
return;
}
MainUtil.sendMessage(plr, C.SAVE_SUCCESS);
List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics != null) {
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics != null)
{
schematics.add(file);
}
MainUtil.runners.remove(plot);

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
@ -32,7 +31,6 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil;
@ -45,93 +43,107 @@ import com.plotsquared.general.commands.CommandDeclaration;
// TODO Add sub-subcommands
@CommandDeclaration(
command = "schematic",
permission = "plots.schematic",
description = "Schematic command",
aliases = {"sch"},
category = CommandCategory.ACTIONS,
usage = "/plot schematic <arg...>"
)
public class SchematicCmd extends SubCommand {
command = "schematic",
permission = "plots.schematic",
description = "Schematic command",
aliases = { "sch" },
category = CommandCategory.ACTIONS,
usage = "/plot schematic <arg...>")
public class SchematicCmd extends SubCommand
{
private int counter = 0;
private boolean running = false;
private int task;
@Override
public boolean onCommand(final PlotPlayer plr, final String ... args) {
if (args.length < 1) {
public boolean onCommand(final PlotPlayer plr, final String... args)
{
if (args.length < 1)
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return true;
}
final String arg = args[0].toLowerCase();
final String file;
final Schematic schematic;
switch (arg) {
case "paste": {
if (!Permissions.hasPermission(plr, "plots.schematic.paste")) {
switch (arg)
{
case "paste":
{
if (!Permissions.hasPermission(plr, "plots.schematic.paste"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}
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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.paste")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.paste"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (this.running) {
if (running)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
final String location = args[1];
this.running = true;
this.counter = 0;
TaskManager.runTaskAsync(new Runnable() {
running = true;
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
Schematic schematic;
if (location.startsWith("url:")) {
try {
UUID uuid = UUID.fromString(location.substring(4));
URL base = new URL(Settings.WEB_URL);
URL url = new URL(base, "uploads/" + uuid + ".schematic");
if (location.startsWith("url:"))
{
try
{
final UUID uuid = UUID.fromString(location.substring(4));
final URL base = new URL(Settings.WEB_URL);
final URL url = new URL(base, "uploads/" + uuid + ".schematic");
schematic = SchematicHandler.manager.getSchematic(url);
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent url: " + location);
SchematicCmd.this.running = false;
running = false;
return;
}
}
else {
else
{
schematic = SchematicHandler.manager.getSchematic(location);
}
if (schematic == null) {
SchematicCmd.this.running = false;
if (schematic == null)
{
running = false;
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
return;
}
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>() {
SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal<Boolean>()
{
@Override
public void run() {
SchematicCmd.this.running = false;
if (this.value) {
public void run()
{
running = false;
if (value)
{
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
}
else {
else
{
sendMessage(plr, C.SCHEMATIC_PASTE_FAILED);
}
}
@ -140,31 +152,37 @@ public class SchematicCmd extends SubCommand {
});
break;
}
case "test": {
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
case "test":
{
if (!Permissions.hasPermission(plr, "plots.schematic.test"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
return false;
}
if (args.length < 2) {
if (args.length < 2)
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return false;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
if (plot == null)
{
sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
file = args[1];
schematic = SchematicHandler.manager.getSchematic(file);
if (schematic == null) {
if (schematic == null)
{
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
return false;
}
final int l1 = schematic.getSchematicDimension().getX();
final int l2 = schematic.getSchematicDimension().getZ();
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
if ((l1 < length) || (l2 < length)) {
if ((l1 < length) || (l2 < length))
{
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
break;
}
@ -172,82 +190,97 @@ public class SchematicCmd extends SubCommand {
break;
}
case "saveall":
case "exportall": {
if (!ConsolePlayer.isConsole(plr)) {
case "exportall":
{
if (!ConsolePlayer.isConsole(plr))
{
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
return false;
}
Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
if ((plots.size() == 0)) {
final Collection<Plot> plots = PS.get().getPlotsInWorld(args[1]);
if ((plots.size() == 0))
{
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
return false;
}
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, "&aFinished mass export");
}
});
if (!result) {
MainUtil.sendMessage(plr, "&cTask is already running.");
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable()
{
@Override
public void run()
{
MainUtil.sendMessage(plr, "&aFinished mass export");
}
});
if (!result)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
else {
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
else
{
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
MainUtil.sendMessage(plr, "&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plots.size() + "&7 plots...");
}
break;
}
case "export":
case "save": {
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
case "save":
{
if (!Permissions.hasPermission(plr, "plots.schematic.save"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
return false;
}
if (this.running) {
if (running)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
final String world;
final Plot p2;
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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.schematic.save"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
p2 = plot;
world = loc.getWorld();
Collection<Plot> plots = new ArrayList<Plot>();
loc.getWorld();
final Collection<Plot> plots = new ArrayList<Plot>();
plots.add(p2);
boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, "&aFinished export");
SchematicCmd.this.running = false;
}
});
if (!result) {
MainUtil.sendMessage(plr, "&cTask is already running.");
final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable()
{
@Override
public void run()
{
MainUtil.sendMessage(plr, "&aFinished export");
running = false;
}
});
if (!result)
{
MainUtil.sendMessage(plr, "&cTask is already running.");
return false;
}
else {
MainUtil.sendMessage(plr, "&7Starting export...");
else
{
MainUtil.sendMessage(plr, "&7Starting export...");
}
break;
}
default: {
default:
{
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
break;
}

View File

@ -48,81 +48,95 @@ import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
import com.plotsquared.listener.PlotListener;
// TODO Make sub-subcommands
@CommandDeclaration(
command = "set",
description = "Set a plot value",
aliases = {"s"},
usage = "/plot set <biome|alias|home|flag> <value...>",
permission = "plots.set",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Set extends SubCommand {
command = "set",
description = "Set a plot value",
aliases = { "s" },
usage = "/plot set <biome|alias|home|flag> <value...>",
permission = "plots.set",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
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) {
PlotManager manager = PS.get().getPlotManager(loc.getWorld());
ArrayList<String> newValues = new ArrayList<String>();
if (args.length < 1)
{
final PlotManager manager = PS.get().getPlotManager(loc.getWorld());
final ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values));
newValues.addAll(Arrays.asList(manager.getPlotComponents(PS.get().getPlotWorld(loc.getWorld()), plot.id)));
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.length < 2) {
if (args[0].equalsIgnoreCase("flag"))
{
if (args.length < 2)
{
final String message = StringMan.replaceFromMap("$2" + (StringMan.join(FlagManager.getFlags(plr), "$1, $2")), C.replacements);
// final String message = StringMan.join(FlagManager.getFlags(plr), "&c, &6");
MainUtil.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
return false;
}
AbstractFlag af;
try {
try
{
af = FlagManager.getFlag(args[1].toLowerCase());
} catch (final Exception e) {
}
catch (final Exception e)
{
af = new AbstractFlag(args[1].toLowerCase());
}
if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey())) {
if (!FlagManager.getFlags().contains(af) || FlagManager.isReserved(af.getKey()))
{
MainUtil.sendMessage(plr, C.NOT_VALID_FLAG);
return false;
}
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) {
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase()))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
return false;
}
if (args.length == 2) {
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null) {
if (args.length == 2)
{
if (FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase()) == null)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
return false;
}
final boolean result = FlagManager.removePlotFlag(plot, args[1].toLowerCase());
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_REMOVED);
return false;
}
@ -130,34 +144,43 @@ public class Set extends SubCommand {
PlotListener.plotEntry(plr, plot);
return true;
}
try {
try
{
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed_value = af.parseValueRaw(value);
if (parsed_value == null) {
if (parsed_value == null)
{
MainUtil.sendMessage(plr, af.getValueDesc());
return false;
}
final Flag flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed_value);
final boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) {
if (!result)
{
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
return false;
}
MainUtil.sendMessage(plr, C.FLAG_ADDED);
PlotListener.plotEntry(plr, plot);
return true;
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(plr, "&c" + e.getMessage());
return false;
}
}
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;
}
@ -172,50 +195,62 @@ 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(" ");
}
String descValue = desc.substring(0, desc.length() - 1);
final String descValue = desc.substring(0, desc.length() - 1);
Flag flag = new Flag(FlagManager.getFlag("description"), descValue);
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;
}
@ -224,39 +259,48 @@ 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;
}
@ -266,69 +310,89 @@ public class Set extends SubCommand {
final PlotManager manager = PS.get().getPlotManager(world);
final String[] components = manager.getPlotComponents(plotworld, plot.id);
boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
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;
}
String[] split = args[1].split(",");
final 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) {
for (int i = 0; i < blocks.length; i++)
{
final PlotBlock block = blocks[i];
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];
}
StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
if (match != null) {
final StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
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 (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);
}
});
@ -337,15 +401,21 @@ 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]);
}
}
@ -353,29 +423,34 @@ public class Set extends SubCommand {
return true;
}
}
ArrayList<String> newValues = new ArrayList<String>();
final ArrayList<String> newValues = new ArrayList<String>();
newValues.addAll(Arrays.asList(values));
newValues.addAll(Arrays.asList(manager.getPlotComponents(PS.get().getPlotWorld(loc.getWorld()), plot.id)));
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);

View File

@ -38,82 +38,98 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "setowner",
permission = "plots.set.owner",
description = "Set the plot owner",
usage = "/plot setowner <player>",
aliases = {"so"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class SetOwner extends SubCommand {
command = "setowner",
permission = "plots.set.owner",
description = "Set the plot owner",
usage = "/plot setowner <player>",
aliases = { "so" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class SetOwner extends SubCommand
{
public SetOwner() {
public SetOwner()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
private UUID getUUID(final String string) {
private UUID getUUID(final String string)
{
return UUIDHandler.getUUID(string, null);
}
@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) || (plot.owner == null && !Permissions.hasPermission(plr, "plots.admin.command.setowner"))) {
if ((plot == null) || ((plot.owner == null) && !Permissions.hasPermission(plr, "plots.admin.command.setowner")))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
if (args.length < 1) {
if (args.length < 1)
{
MainUtil.sendMessage(plr, C.NEED_USER);
return false;
}
final PlotId bot = MainUtil.getBottomPlot(plot).id;
final PlotId top = MainUtil.getTopPlot(plot).id;
final ArrayList<PlotId> plots = MainUtil.getPlotSelectionIds(bot, top);
PlotPlayer other = UUIDHandler.getPlayer(args[0]);
if (other == null) {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
final PlotPlayer other = UUIDHandler.getPlayer(args[0]);
if (other == null)
{
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner"))
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
}
else {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
int size = plots.size();
else
{
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner"))
{
final int size = plots.size();
final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(loc.getWorld(), other)) + size;
if (currentPlots > MainUtil.getAllowedPlots(other)) {
if (currentPlots > MainUtil.getAllowedPlots(other))
{
sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS);
return false;
}
}
}
}
if (!plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
return false;
}
if (!plot.isOwner(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
return false;
}
}
final String world = loc.getWorld();
final UUID uuid = getUUID(args[0]);
if (uuid == null) {
if (uuid == null)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
for (final PlotId id : plots) {
for (final PlotId id : plots)
{
Plot current = PS.get().getPlot(world, id);
if (current == null) {
if (current == null)
{
current = MainUtil.getPlot(world, id);
current.owner = uuid;
current.create();
}
else {
else
{
current.owner = uuid;
DBFunc.setOwner(current, current.owner);
}
@ -121,8 +137,9 @@ public class SetOwner extends SubCommand {
}
MainUtil.setSign(args[0], plot);
MainUtil.sendMessage(plr, C.SET_OWNER);
if (other != null) {
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id);
if (other != null)
{
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id);
}
return true;
}

View File

@ -39,26 +39,31 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "setup",
permission = "plots.admin.command.setup",
description = "Setup wizard for plot worlds",
usage = "/plot setup",
aliases = {"create"},
category = CommandCategory.ACTIONS
)
public class Setup extends SubCommand {
command = "setup",
permission = "plots.admin.command.setup",
description = "Setup wizard for plot worlds",
usage = "/plot setup",
aliases = { "create" },
category = CommandCategory.ACTIONS)
public class Setup extends SubCommand
{
public void displayGenerators(PlotPlayer plr) {
StringBuffer message = new StringBuffer();
public void displayGenerators(final PlotPlayer plr)
{
final StringBuffer message = new StringBuffer();
message.append("&6What generator do you want?");
for (Entry<String, PlotGenerator<?>> entry : SetupUtils.generators.entrySet()) {
if (entry.getKey().equals("PlotSquared")) {
for (final Entry<String, PlotGenerator<?>> entry : SetupUtils.generators.entrySet())
{
if (entry.getKey().equals("PlotSquared"))
{
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
}
else if (entry.getValue().isFull()) {
else if (entry.getValue().isFull())
{
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
}
else {
else
{
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
}
}
@ -66,10 +71,12 @@ public class Setup extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
// going through setup
String name = plr.getName();
if (!SetupUtils.setupMap.containsKey(name)) {
final String name = plr.getName();
if (!SetupUtils.setupMap.containsKey(name))
{
final SetupObject object = new SetupObject();
SetupUtils.setupMap.put(name, object);
SetupUtils.manager.updateGenerators();
@ -77,29 +84,38 @@ public class Setup extends SubCommand {
displayGenerators(plr);
return false;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("cancel")) {
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("cancel"))
{
SetupUtils.setupMap.remove(name);
MainUtil.sendMessage(plr, "&aCancelled setup");
return false;
}
if (args[0].equalsIgnoreCase("back")) {
if (args[0].equalsIgnoreCase("back"))
{
final SetupObject object = SetupUtils.setupMap.get(name);
if (object.setup_index > 0) {
if (object.setup_index > 0)
{
object.setup_index--;
final ConfigurationNode node = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", node.getDescription(), node.getType().getType(), node.getDefaultValue() + "");
return false;
} else if (object.current > 0) {
}
else if (object.current > 0)
{
object.current--;
}
}
}
final SetupObject object = SetupUtils.setupMap.get(name);
final int index = object.current;
switch (index) {
case 0: { // choose generator
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0])) {
switch (index)
{
case 0:
{ // choose generator
if ((args.length != 1) || !SetupUtils.generators.containsKey(args[0]))
{
final String prefix = "\n&8 - &7";
MainUtil.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringMan.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
sendMessage(plr, C.SETUP_INIT);
@ -111,40 +127,50 @@ public class Setup extends SubCommand {
MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial);
break;
}
case 1: { // choose world type
List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"});
List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"});
ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator).isFull()) {
case 1:
{ // choose world type
final List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial" });
final List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots" });
final ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator).isFull())
{
types.add("default");
}
types.add("augmented");
if (Settings.ENABLE_CLUSTERS) {
if (Settings.ENABLE_CLUSTERS)
{
types.add("partial");
}
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
if ((args.length != 1) || !types.contains(args[0].toLowerCase()))
{
MainUtil.sendMessage(plr, "&cYou must choose a world type!");
for (String type : types) {
int i = allTypes.indexOf(type);
if (type.equals("default")) {
for (final String type : types)
{
final int i = allTypes.indexOf(type);
if (type.equals("default"))
{
MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
}
else {
else
{
MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
}
}
return false;
}
object.type = allTypes.indexOf(args[0].toLowerCase());
PlotGenerator<?> gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == 0) {
final PlotGenerator<?> gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == 0)
{
object.current++;
if (object.step == null) {
if (object.step == null)
{
object.plotManager = object.setupGenerator;
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).processSetup(object);
}
if (object.step.length == 0) {
if (object.step.length == 0)
{
object.current = 4;
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0;
@ -152,93 +178,125 @@ public class Setup extends SubCommand {
}
final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
} else {
if (gen.isFull()) {
}
else
{
if (gen.isFull())
{
object.plotManager = object.setupGenerator;
object.setupGenerator = null;
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
SetupUtils.generators.get(object.plotManager).processSetup(object);
}
else {
else
{
object.plotManager = "PlotSquared";
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator");
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
}
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain seperated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
}
object.current++;
break;
}
case 2: { // Choose terrain
case 2:
{ // Choose terrain
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "road", "all" });
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ROAD&8 - &7Terrain seperated by roads" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase()))
{
MainUtil.sendMessage(plr, "&cYou must choose the terrain!"
+ "\n&8 - &2NONE&8 - &7No terrain at all"
+ "\n&8 - &7ORE&8 - &7Just some ore veins and trees"
+ "\n&8 - &7ROAD&8 - &7Terrain seperated by roads"
+ "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
return false;
}
object.terrain = terrain.indexOf(args[0].toLowerCase());
object.current++;
if (object.step == null) {
if (object.step == null)
{
object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes();
}
final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
break;
}
case 3: { // world setup
if (object.setup_index == object.step.length) {
case 3:
{ // world setup
if (object.setup_index == object.step.length)
{
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
object.setup_index = 0;
object.current++;
return true;
}
ConfigurationNode step = object.step[object.setup_index];
if (args.length < 1) {
if (args.length < 1)
{
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
}
final boolean valid = step.isValid(args[0]);
if (valid) {
if (valid)
{
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
step.setValue(args[0]);
object.setup_index++;
if (object.setup_index == object.step.length) {
if (object.setup_index == object.step.length)
{
onCommand(plr, args);
return false;
}
step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
} else {
}
else
{
sendMessage(plr, C.SETUP_INVALID_ARG, args[0], step.getConstant());
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
return false;
}
}
case 4: {
if (args.length != 1) {
case 4:
{
if (args.length != 1)
{
MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
return false;
}
if (BlockManager.manager.isWorld(args[0])) {
if (PS.get().isPlotWorld(args[0])) {
if (BlockManager.manager.isWorld(args[0]))
{
if (PS.get().isPlotWorld(args[0]))
{
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
return false;
}
MainUtil.sendMessage(plr, "&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!");
MainUtil.sendMessage(plr,
"&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!");
}
object.world = args[0];
SetupUtils.setupMap.remove(name);
final String world;
if (object.setupManager == null) {
if (object.setupManager == null)
{
world = SetupUtils.manager.setupWorld(object);
}
else {
else
{
world = object.setupManager.setupWorld(object);
}
try {
try
{
plr.teleport(BlockManager.manager.getSpawn(world));
} catch (final Exception e) {
}
catch (final Exception e)
{
plr.sendMessage("&cAn error occured. See console for more information");
e.printStackTrace();
}

View File

@ -1,52 +1,53 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
/**
* SubCommand class
*
* @author Citymonstret
*/
@SuppressWarnings({ "deprecation", "unused" })
public abstract class SubCommand extends com.plotsquared.general.commands.Command<PlotPlayer> {
/**
* The category
*/
public CommandCategory category;
/**
* Send a message
*
* @param plr Player who will receive the mssage
* @param c Caption
* @param args Arguments (%s's)
*
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
*/
public boolean sendMessage(PlotPlayer plr, final C c, final String... args) {
c.send(plr, args);
return true;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
/**
* SubCommand class
*
*/
@SuppressWarnings({ "deprecation", "unused" })
public abstract class SubCommand extends com.plotsquared.general.commands.Command<PlotPlayer>
{
/**
* The category
*/
public CommandCategory category;
/**
* Send a message
*
* @param plr Player who will receive the mssage
* @param c Caption
* @param args Arguments (%s's)
*
* @see com.intellectualcrafters.plot.util.MainUtil#sendMessage(PlotPlayer, C, String...)
*/
public boolean sendMessage(final PlotPlayer plr, final C c, final String... args)
{
c.send(plr, args);
return true;
}

View File

@ -36,95 +36,104 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "swap",
description = "Swap two plots",
aliases = {"switch"},
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE
)
public class Swap extends SubCommand {
command = "swap",
description = "Swap two plots",
aliases = { "switch" },
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Swap extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue.");
if (args.length < 1) {
if (args.length < 1)
{
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
Plot bot1 = MainUtil.getBottomPlot(plot);
Plot top1 = MainUtil.getTopPlot(plot);
PlotId id2 = PlotId.fromString(args[0]);
if (id2 == null) {
final Plot bot1 = MainUtil.getBottomPlot(plot);
final Plot top1 = MainUtil.getTopPlot(plot);
final PlotId id2 = PlotId.fromString(args[0]);
if (id2 == null)
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
final String world = loc.getWorld();
Plot plot2 = MainUtil.getPlot(world, id2);
PlotId id3 = new PlotId(id2.x + top1.id.x - bot1.id.x, id2.y + top1.id.y - bot1.id.y);
Plot plot3 = MainUtil.getPlot(world, id3);
final Plot plot2 = MainUtil.getPlot(world, id2);
final PlotId id3 = new PlotId((id2.x + top1.id.x) - bot1.id.x, (id2.y + top1.id.y) - bot1.id.y);
final Plot plot3 = MainUtil.getPlot(world, id3);
// Getting secon selection
Plot bot2 = MainUtil.getBottomPlot(plot2);
Plot top2 = MainUtil.getTopPlot(plot3);
final Plot bot2 = MainUtil.getBottomPlot(plot2);
final Plot top2 = MainUtil.getTopPlot(plot3);
// cancel swap if intersection
PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null);
PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id);
if (ClusterManager.intersects(cluster1, cluster2id)) {
final PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null);
final PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id);
if (ClusterManager.intersects(cluster1, cluster2id))
{
MainUtil.sendMessage(plr, C.SWAP_OVERLAP);
return false;
}
// Check dimensions
if (top1.id.x - bot1.id.x != top2.id.x - bot2.id.x || top1.id.y - bot1.id.y != top2.id.y - bot2.id.y ) {
if (((top1.id.x - bot1.id.x) != (top2.id.x - bot2.id.x)) || ((top1.id.y - bot1.id.y) != (top2.id.y - bot2.id.y)))
{
MainUtil.sendMessage(plr, C.SWAP_DIMENSIONS, "1");
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
// Getting selections as ids
final ArrayList<PlotId> selection1 = MainUtil.getPlotSelectionIds(bot1.id, top1.id);
final ArrayList<PlotId> selection2 = MainUtil.getPlotSelectionIds(bot2.id, top2.id);
// Getting selections as location coordinates
Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id);
Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1);
Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id);
Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1);
if (MainUtil.getPlot(pos2) != null) {
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id);
final Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1);
final Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id);
final Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1);
if (MainUtil.getPlot(pos2) != null)
{
pos1.add(1, 0, 1);
pos2.add(1, 0, 1);
pos3.add(1, 0, 1);
pos4.add(1, 0, 1);
}
// Swapping the blocks, states and entites
ChunkManager.manager.swap(world, pos1, pos2, pos3, pos4);
// Swapping the plot data
for (int i = 0; i < selection1.size(); i++) {
final boolean last = i == selection1.size() - 1;
PlotId swaper = selection1.get(i);
PlotId swapee = selection2.get(i);
MainUtil.swapData(world, swaper, swapee, new Runnable() {
for (int i = 0; i < selection1.size(); i++)
{
final boolean last = i == (selection1.size() - 1);
final PlotId swaper = selection1.get(i);
final PlotId swapee = selection2.get(i);
MainUtil.swapData(world, swaper, swapee, new Runnable()
{
@Override
public void run() {
if (last) {
public void run()
{
if (last)
{
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
}
}

View File

@ -34,74 +34,84 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "tp",
description = "Teleport to a plot",
permission = "plots.tp",
usage = "/plot tp <alias|id>",
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT
)
public class TP extends SubCommand {
command = "tp",
description = "Teleport to a plot",
permission = "plots.tp",
usage = "/plot tp <alias|id>",
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT)
public class TP extends SubCommand
{
public TP() {
public TP()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final String id = args[0];
PlotId plotid;
final Location loc = plr.getLocation();
final String pworld = loc.getWorld();
String world = pworld;
if (args.length == 2) {
if (BlockManager.manager.isWorld(args[1])) {
if (args.length == 2)
{
if (BlockManager.manager.isWorld(args[1]))
{
world = args[1];
}
}
if (!PS.get().isPlotWorld(world)) {
if (!PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
Plot temp;
if ((temp = isAlias(world, id)) != null) {
if ((temp = isAlias(world, id)) != null)
{
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
return true;
}
try {
try
{
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlot(world, plotid));
return true;
} catch (final Exception e) {
}
catch (final Exception e)
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
return false;
}
private Plot isAlias(final String world, String a) {
private Plot isAlias(final String world, String a)
{
int index = 0;
if (a.contains(";")) {
if (a.contains(";"))
{
final String[] split = a.split(";");
if ((split[1].length() > 0) && MathMan.isInteger(split[1])) {
if ((split[1].length() > 0) && MathMan.isInteger(split[1]))
{
index = Integer.parseInt(split[1]);
}
a = split[0];
}
final PlotPlayer player = UUIDHandler.getPlayer(a);
if (player != null) {
if (player != null)
{
final java.util.Set<Plot> plotMainPlots = PS.get().getPlots(world, player);
final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]);
if (plots.length > index) {
return plots[index];
}
if (plots.length > index) { return plots[index]; }
return null;
}
for (final Plot p : PS.get().getPlotsInWorld(world)) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
return p;
}
for (final Plot p : PS.get().getPlotsInWorld(world))
{
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) { return p; }
}
return null;
}

View File

@ -28,41 +28,47 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "target",
usage = "/plot target <X;Z|nearest>",
description = "Target a plot with your compass",
permission = "plots.target",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Target extends SubCommand {
command = "target",
usage = "/plot target <X;Z|nearest>",
description = "Target a plot with your compass",
permission = "plots.target",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Target extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
final Location ploc = plr.getLocation();
if (!PS.get().isPlotWorld(ploc.getWorld())) {
if (!PS.get().isPlotWorld(ploc.getWorld()))
{
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
return false;
}
PlotId id = MainUtil.parseId(args[0]);
if (id == null) {
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) {
if (id == null)
{
if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest"))
{
Plot closest = null;
int distance = Integer.MAX_VALUE;
for (Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) {
double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
if (current < distance) {
for (final Plot plot : PS.get().getPlotsInWorld(ploc.getWorld()))
{
final double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
if (current < distance)
{
distance = (int) current;
closest = plot;
}
}
id = closest.id;
}
else {
else
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
return false;
}

View File

@ -47,35 +47,38 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "template",
permission = "plots.admin",
description = "Create or use a world template",
usage = "/plot template [import|export] <world> <template>",
category = CommandCategory.DEBUG
)
public class Template extends SubCommand {
command = "template",
permission = "plots.admin",
description = "Create or use a world template",
usage = "/plot template [import|export] <world> <template>",
category = CommandCategory.DEBUG)
public class Template extends SubCommand
{
public static boolean extractAllFiles(String world, String template) {
byte[] buffer = new byte[2048];
try {
File folder = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
if (!folder.exists()) {
return false;
}
File input = new File(folder + File.separator + template + ".template");
File output = PS.get().IMP.getDirectory();
if (!output.exists()) {
public static boolean extractAllFiles(final String world, final String template)
{
final byte[] buffer = new byte[2048];
try
{
final File folder = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
if (!folder.exists()) { return false; }
final File input = new File(folder + File.separator + template + ".template");
final File output = PS.get().IMP.getDirectory();
if (!output.exists())
{
output.mkdirs();
}
ZipInputStream zis = new ZipInputStream(new FileInputStream(input));
final ZipInputStream zis = new ZipInputStream(new FileInputStream(input));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String name = ze.getName();
File newFile = new File((output + File.separator + name).replaceAll("__TEMP_DIR__", world));
while (ze != null)
{
final String name = ze.getName();
final File newFile = new File((output + File.separator + name).replaceAll("__TEMP_DIR__", world));
new File(newFile.getParent()).mkdirs();
FileOutputStream fos = new FileOutputStream(newFile);
final FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
while ((len = zis.read(buffer)) > 0)
{
fos.write(buffer, 0, len);
}
fos.close();
@ -84,33 +87,40 @@ public class Template extends SubCommand {
zis.closeEntry();
zis.close();
return true;
} catch (Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
return false;
}
}
public static byte[] getBytes(PlotWorld plotworld) {
ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname);
YamlConfiguration config = new YamlConfiguration();
String generator = SetupUtils.manager.getGenerator(plotworld);
if (generator != null) {
public static byte[] getBytes(final PlotWorld plotworld)
{
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname);
final YamlConfiguration config = new YamlConfiguration();
final String generator = SetupUtils.manager.getGenerator(plotworld);
if (generator != null)
{
config.set("generator.plugin", generator);
}
for (String key : section.getKeys(true)) {
for (final String key : section.getKeys(true))
{
config.set(key, section.get(key));
}
return config.saveToString().getBytes();
}
public static void zipAll(final String world, Set<FileBytes> files) throws IOException {
File output = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
public static void zipAll(final String world, final Set<FileBytes> files) throws IOException
{
final File output = new File(PS.get().IMP.getDirectory() + File.separator + "templates");
output.mkdirs();
FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
ZipOutputStream zos = new ZipOutputStream(fos);
final FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
final ZipOutputStream zos = new ZipOutputStream(fos);
for (FileBytes file : files) {
ZipEntry ze = new ZipEntry(file.path);
for (final FileBytes file : files)
{
final ZipEntry ze = new ZipEntry(file.path);
zos.putNextEntry(ze);
zos.write(file.data);
}
@ -119,14 +129,19 @@ public class Template extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length != 2 && args.length != 3) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("export")) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if ((args.length != 2) && (args.length != 3))
{
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("export"))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return true;
}
else if (args[0].equalsIgnoreCase("import")) {
else if (args[0].equalsIgnoreCase("import"))
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return true;
}
@ -135,43 +150,53 @@ public class Template extends SubCommand {
return true;
}
final String world = args[1];
switch (args[0].toLowerCase()) {
case "import": {
if (args.length != 3) {
switch (args[0].toLowerCase())
{
case "import":
{
if (args.length != 3)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
return false;
}
if (PS.get().isPlotWorld(world)) {
if (PS.get().isPlotWorld(world))
{
MainUtil.sendMessage(plr, C.SETUP_WORLD_TAKEN, world);
return false;
}
boolean result = extractAllFiles(world, args[2]);
if (!result) {
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] +".template");
final boolean result = extractAllFiles(world, args[2]);
if (!result)
{
MainUtil.sendMessage(plr, "&cInvalid template file: " + args[2] + ".template");
return false;
}
File worldFile = new File(PS.get().IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
final File worldFile = new File(PS.get().IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
final YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
PS.get().config.set("worlds." + world, worldConfig.get(""));
try {
try
{
PS.get().config.save(PS.get().configFile);
PS.get().config.load(PS.get().configFile);
} catch (Exception e) {
}
catch (final Exception e)
{
e.printStackTrace();
}
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
if (manager == null)
{
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
if (generator == null)
{
generator = manager;
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
final int type = worldConfig.getInt("generator.type");
final int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
final SetupObject setup = new SetupObject();
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
@ -179,34 +204,43 @@ public class Template extends SubCommand {
setup.step = new ConfigurationNode[0];
setup.world = world;
SetupUtils.manager.setupWorld(setup);
SetBlockQueue.addNotify(new Runnable() {
SetBlockQueue.addNotify(new Runnable()
{
@Override
public void run() {
public void run()
{
MainUtil.sendMessage(plr, "Done!");
plr.teleport(BlockManager.manager.getSpawn(world));
}
});
return true;
}
case "export": {
if (args.length != 2) {
case "export":
{
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template export <world>");
return false;
}
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (!BlockManager.manager.isWorld(world) || (plotworld == null)) {
if (!BlockManager.manager.isWorld(world) || (plotworld == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
final PlotManager manager = PS.get().getPlotManager(world);
final PlotPlayer finalPlr = plr;
TaskManager.runTaskAsync(new Runnable() {
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
try {
public void run()
{
try
{
manager.exportTemplate(plotworld);
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
MainUtil.sendMessage(finalPlr, "Failed: " + e.getMessage());
return;
@ -216,8 +250,9 @@ public class Template extends SubCommand {
});
return true;
}
default: {
C.COMMAND_SYNTAX.send(plr, this.getUsage());
default:
{
C.COMMAND_SYNTAX.send(plr, getUsage());
}
}
return false;

View File

@ -31,124 +31,151 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.general.commands.Command;
import com.plotsquared.general.commands.CommandCaller;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "toggle",
aliases = {"attribute"},
permission = "plots.use",
description = "Toggle per user settings",
usage = "/plot toggle <setting>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Toggle extends SubCommand {
command = "toggle",
aliases = { "attribute" },
permission = "plots.use",
description = "Toggle per user settings",
usage = "/plot toggle <setting>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Toggle extends SubCommand
{
public void noArgs(PlotPlayer plr) {
public void noArgs(final PlotPlayer plr)
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot toggle <setting>");
ArrayList<String> options = new ArrayList<>();
for (Entry<String, Command<PlotPlayer>> entry : toggles.entrySet()) {
if (Permissions.hasPermission(plr, entry.getValue().getPermission())) {
final ArrayList<String> options = new ArrayList<>();
for (final Entry<String, Command<PlotPlayer>> entry : toggles.entrySet())
{
if (Permissions.hasPermission(plr, entry.getValue().getPermission()))
{
options.add(entry.getKey());
}
}
if (options.size() > 0) {
if (options.size() > 0)
{
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(options, ","));
}
}
private HashMap<String, Command<PlotPlayer>> toggles;
public Toggle() {
public Toggle()
{
toggles = new HashMap<>();
toggles.put("titles",
new Command<PlotPlayer>("titles", "/plot toggle titles", "Toggle titles for yourself", C.PERMISSION_PLOT_TOGGLE_TITLES.s()) {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "disabletitles")) {
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
else {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
return true;
}
});
toggles.put("chatspy",
new Command<PlotPlayer>("chatspy", "/plot toggle chatspy", "Toggle chat spying", C.PERMISSION_COMMANDS_CHAT.s()) {
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "chatspy")) {
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
else {
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
return true;
}
});
toggles.put("chat",
new Command<PlotPlayer>("chat", "/plot toggle chat", "Toggle plot chat for yourself", C.PERMISSION_PLOT_TOGGLE_CHAT.s()) {
toggles.put("titles",
new Command<PlotPlayer>("titles", "/plot toggle titles", "Toggle titles for yourself", C.PERMISSION_PLOT_TOGGLE_TITLES.s())
{
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "chat")) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "disabletitles"))
{
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
else
{
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
return true;
}
});
toggles.put("chatspy",
new Command<PlotPlayer>("chatspy", "/plot toggle chatspy", "Toggle chat spying", C.PERMISSION_COMMANDS_CHAT.s())
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "chatspy"))
{
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, getCommand());
}
else
{
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, getCommand());
}
return true;
}
});
toggles.put("chat",
new Command<PlotPlayer>("chat", "/plot toggle chat", "Toggle plot chat for yourself", C.PERMISSION_PLOT_TOGGLE_CHAT.s())
{
@Override
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "chat"))
{
MainUtil.sendMessage(player, C.PLOT_CHAT_OFF);
}
else {
else
{
MainUtil.sendMessage(player, C.PLOT_CHAT_ON);
}
return true;
}
});
if (PS.get().worldedit != null) {
toggles.put("worldedit",
new Command<PlotPlayer>("worldedit", "/plot toggle worldedit", "Toggle worldedit bypass", C.PERMISSION_WORLDEDIT_BYPASS.s()) {
if (PS.get().worldedit != null)
{
toggles.put("worldedit",
new Command<PlotPlayer>("worldedit", "/plot toggle worldedit", "Toggle worldedit bypass", C.PERMISSION_WORLDEDIT_BYPASS.s())
{
@Override
public boolean onCommand(PlotPlayer player, String[] args) {
if (toggle(player, "worldedit")) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (toggle(player, "worldedit"))
{
MainUtil.sendMessage(player, C.WORLDEDIT_RESTRICTED);
}
else {
else
{
MainUtil.sendMessage(player, C.WORLDEDIT_UNMASKED);
}
return true;
}
});
}
}
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
if (args.length == 0) {
public boolean onCommand(final PlotPlayer player, final String[] args)
{
if (args.length == 0)
{
noArgs(player);
return false;
}
Command<PlotPlayer> cmd = toggles.get(args[0].toLowerCase());
if (cmd == null) {
final Command<PlotPlayer> cmd = toggles.get(args[0].toLowerCase());
if (cmd == null)
{
noArgs(player);
return false;
}
if (!Permissions.hasPermission(player, cmd.getPermission())) {
if (!Permissions.hasPermission(player, cmd.getPermission()))
{
C.NO_PERMISSION.send(player, cmd.getPermission());
return false;
}
return cmd.onCommand(player, Arrays.copyOfRange(args, 1, args.length));
}
public boolean toggle(PlotPlayer player, String key) {
if (player.getAttribute(key)) {
public boolean toggle(final PlotPlayer player, final String key)
{
if (player.getAttribute(key))
{
player.removeAttribute(key);
return true;
}
else {
else
{
player.setAttribute(key);
return false;
}

View File

@ -42,62 +42,77 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "trim",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
usage = "/plot trim",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG
)
public class Trim extends SubCommand {
command = "trim",
permission = "plots.admin",
description = "Delete unmodified portions of your plotworld",
usage = "/plot trim",
requiredType = RequiredType.CONSOLE,
category = CommandCategory.DEBUG)
public class Trim extends SubCommand
{
public static boolean TASK = false;
public static ArrayList<Plot> expired = null;
private static int TASK_ID = 0;
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
if (Trim.TASK) {
return false;
}
TaskManager.runTaskAsync(new Runnable() {
public static boolean getBulkRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone)
{
if (Trim.TASK) { return false; }
TaskManager.runTaskAsync(new Runnable()
{
@Override
public void run() {
public void run()
{
final String directory = world + File.separator + "region";
final File folder = new File(directory);
final File[] regionFiles = folder.listFiles();
for (final File file : regionFiles) {
for (final File file : regionFiles)
{
final String name = file.getName();
if (name.endsWith("mca")) {
if (file.getTotalSpace() <= 8192) {
try {
if (name.endsWith("mca"))
{
if (file.getTotalSpace() <= 8192)
{
try
{
final String[] split = name.split("\\.");
final int x = Integer.parseInt(split[1]);
final int z = Integer.parseInt(split[2]);
final ChunkLoc loc = new ChunkLoc(x, z);
empty.add(loc);
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("INVALID MCA: " + name);
}
} else {
}
else
{
final Path path = Paths.get(file.getPath());
try {
try
{
final BasicFileAttributes attr = Files.readAttributes(path, BasicFileAttributes.class);
final long creation = attr.creationTime().toMillis();
final long modification = file.lastModified();
final long diff = Math.abs(creation - modification);
if (diff < 10000) {
try {
if (diff < 10000)
{
try
{
final String[] split = name.split("\\.");
final int x = Integer.parseInt(split[1]);
final int z = Integer.parseInt(split[2]);
final ChunkLoc loc = new ChunkLoc(x, z);
empty.add(loc);
} catch (final Exception e) {
}
catch (final Exception e)
{
PS.debug("INVALID MCA: " + name);
}
}
} catch (final Exception e) {
}
catch (final Exception e)
{}
}
}
}
@ -109,10 +124,9 @@ public class Trim extends SubCommand {
return true;
}
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone) {
if (Trim.TASK) {
return false;
}
public static boolean getTrimRegions(final ArrayList<ChunkLoc> empty, final String world, final Runnable whenDone)
{
if (Trim.TASK) { return false; }
System.currentTimeMillis();
sendMessage("Collecting region data...");
final ArrayList<Plot> plots = new ArrayList<>();
@ -121,12 +135,16 @@ public class Trim extends SubCommand {
sendMessage(" - MCA #: " + chunks.size());
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() {
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable()
{
@Override
public void run() {
public void run()
{
final long start = System.currentTimeMillis();
while ((System.currentTimeMillis() - start) < 50) {
if (plots.size() == 0) {
while ((System.currentTimeMillis() - start) < 50)
{
if (plots.size() == 0)
{
empty.addAll(chunks);
Trim.TASK = false;
TaskManager.runTaskAsync(whenDone);
@ -137,14 +155,16 @@ public class Trim extends SubCommand {
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
int ccx1 = (pos1.getX() >> 9);
int ccz1 = (pos1.getZ() >> 9);
int ccx2 = (pos2.getX() >> 9);
int ccz2 = (pos2.getZ() >> 9);
for(int x = ccx1; x <= ccx2; x++) {
for(int z = ccz1; z <= ccz2; z++) {
final int ccx1 = (pos1.getX() >> 9);
final int ccz1 = (pos1.getZ() >> 9);
final int ccx2 = (pos2.getX() >> 9);
final int ccz2 = (pos2.getZ() >> 9);
for (int x = ccx1; x <= ccx2; x++)
{
for (int z = ccz1; z <= ccz2; z++)
{
chunks.remove(new ChunkLoc(x, z));
}
}
@ -155,62 +175,78 @@ public class Trim extends SubCommand {
return true;
}
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks)
{
ChunkManager.manager.deleteRegionFiles(world, chunks);
}
public static void sendMessage(final String message) {
public static void sendMessage(final String message)
{
PS.debug("&3PlotSquared -> World trim&8: &7" + message);
}
public PlotId getId(final String id) {
try {
public PlotId getId(final String id)
{
try
{
final String[] split = id.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
}
catch (final Exception e)
{
return null;
}
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length == 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length == 1)
{
final String arg = args[0].toLowerCase();
final PlotId id = getId(arg);
if (id != null) {
if (id != null)
{
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
return false;
}
if (arg.equals("all")) {
if (arg.equals("all"))
{
MainUtil.sendMessage(plr, "/plot trim all &l<world>");
return false;
}
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
if (args.length != 2) {
if (args.length != 2)
{
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String arg = args[0].toLowerCase();
if (!arg.equals("all")) {
if (!arg.equals("all"))
{
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
return false;
}
final String world = args[1];
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null)) {
if (!BlockManager.manager.isWorld(world) || (PS.get().getPlotWorld(world) == null))
{
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
return false;
}
if (Trim.TASK) {
if (Trim.TASK)
{
sendMessage(C.TRIM_IN_PROGRESS.s());
return false;
}
sendMessage(C.TRIM_START.s());
final ArrayList<ChunkLoc> empty = new ArrayList<>();
getTrimRegions(empty, world, new Runnable() {
getTrimRegions(empty, world, new Runnable()
{
@Override
public void run() {
public void run()
{
deleteChunks(world, empty);
PS.log("$1Trim task complete!");
}

View File

@ -37,69 +37,84 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "trust",
aliases = {"t"},
requiredType = RequiredType.NONE,
usage = "/plot trust <player>",
description = "Allow a player to build in a plot",
category = CommandCategory.ACTIONS
)
public class Trust extends SubCommand {
command = "trust",
aliases = { "t" },
requiredType = RequiredType.NONE,
usage = "/plot trust <player>",
description = "Allow a player to build in a plot",
category = CommandCategory.ACTIONS)
public class Trust extends SubCommand
{
public Trust() {
public Trust()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.trust")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.trust"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
UUID uuid;
if (args[0].equalsIgnoreCase("*")) {
if (args[0].equalsIgnoreCase("*"))
{
uuid = DBFunc.everyone;
} else {
}
else
{
uuid = UUIDHandler.getUUID(args[0], null);
}
if (uuid == null) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (uuid == null)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
return false;
}
if (plot.getTrusted().contains(uuid)) {
if (plot.getTrusted().contains(uuid))
{
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
if (plot.removeMember(uuid)) {
if (plot.removeMember(uuid))
{
plot.addTrusted(uuid);
}
else {
if (plot.getMembers().size() + plot.getTrusted().size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
else
{
if ((plot.getMembers().size() + plot.getTrusted().size()) >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS)
{
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.getDenied().contains(uuid)) {
if (plot.getDenied().contains(uuid))
{
plot.removeDenied(uuid);
}
plot.addTrusted(uuid);

View File

@ -32,42 +32,39 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "unclaim",
usage = "/plot unclaim",
requiredType = RequiredType.NONE,
description = "Unclaim a plot",
category = CommandCategory.ACTIONS
)
public class Unclaim extends SubCommand {
command = "unclaim",
usage = "/plot unclaim",
requiredType = RequiredType.NONE,
description = "Unclaim a plot",
category = CommandCategory.ACTIONS)
public class Unclaim extends SubCommand
{
@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()) {
return !sendMessage(plr, C.PLOT_NOT_CLAIMED);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return !sendMessage(plr, C.UNLINK_REQUIRED);
}
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
return !sendMessage(plr, C.NO_PLOT_PERMS);
}
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if (!plot.hasOwner()) { return !sendMessage(plr, C.PLOT_NOT_CLAIMED); }
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return !sendMessage(plr, C.UNLINK_REQUIRED); }
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) { return !sendMessage(plr, C.NO_PLOT_PERMS); }
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY)
{
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
if (c > 0d)
{
EconHandler.manager.depositMoney(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
if (plot.unclaim()) {
if (plot.unclaim())
{
MainUtil.sendMessage(plr, C.UNCLAIM_SUCCESS);
}
else {
else
{
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
}
return true;

View File

@ -35,75 +35,89 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "undeny",
aliases = {"ud"},
description = "Remove a denied user from a plot",
usage = "/plot undeny <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Undeny extends SubCommand {
command = "undeny",
aliases = { "ud" },
description = "Remove a denied user from a plot",
usage = "/plot undeny <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Undeny extends SubCommand
{
public Undeny() {
public Undeny()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
switch (args[0])
{
case "unknown":
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.getDenied()) {
if (UUIDHandler.getName(uuid) == null) {
final ArrayList<UUID> toRemove = new ArrayList<>();
for (final UUID uuid : plot.getDenied())
{
if (UUIDHandler.getName(uuid) == null)
{
toRemove.add(uuid);
}
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeDenied(uuid);
count++;
}
break;
case "*":
for (UUID uuid : new ArrayList<>(plot.getDenied())) {
for (final UUID uuid : new ArrayList<>(plot.getDenied()))
{
plot.removeDenied(uuid);
count++;
}
break;
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.removeDenied(uuid)) {
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null)
{
if (plot.removeDenied(uuid))
{
count++;
}
}
break;
}
if (count == 0) {
if (UUIDHandler.implementation instanceof SQLUUIDHandler) {
if (count == 0)
{
if (UUIDHandler.implementation instanceof SQLUUIDHandler)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER_WAIT, args[0]);
} else {
}
else
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
}
return false;
}
else {
else
{
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;

View File

@ -32,44 +32,43 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "unlink",
aliases = {"u", "unmerge"},
description = "Unlink a mega-plot",
usage = "/plot unlink",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Unlink extends SubCommand {
command = "unlink",
aliases = { "u", "unmerge" },
description = "Unlink a mega-plot",
usage = "/plot unlink",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Unlink extends SubCommand
{
@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() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
}
Runnable runnable = new Runnable() {
if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); }
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) { return sendMessage(plr, C.NO_PLOT_PERMS); }
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) { return sendMessage(plr, C.UNLINK_IMPOSSIBLE); }
final Runnable runnable = new Runnable()
{
@Override
public void run() {
if (!MainUtil.unlinkPlot(plot, true)) {
public void run()
{
if (!MainUtil.unlinkPlot(plot, true))
{
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
return;
}
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
}
};
if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass")))
{
CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable);
}
else {
else
{
TaskManager.runTask(runnable);
}
return true;

View File

@ -36,71 +36,82 @@ import com.plotsquared.general.commands.CommandDeclaration;
// UNTRUST("untrust", "ut"),
@CommandDeclaration(
command = "untrust",
aliases = {"ut"},
permission = "plots.untrust",
description = "Remove a trusted user from a plot",
usage = "/plot untrust <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS
)
public class Untrust extends SubCommand {
command = "untrust",
aliases = { "ut" },
permission = "plots.untrust",
description = "Remove a trusted user from a plot",
usage = "/plot untrust <player>",
requiredType = RequiredType.NONE,
category = CommandCategory.ACTIONS)
public class Untrust extends SubCommand
{
public Untrust() {
public Untrust()
{
requiredArguments = new Argument[] {
Argument.PlayerName
Argument.PlayerName
};
}
@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())
{
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust"))
{
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
switch (args[0])
{
case "unknown":
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.getTrusted()) {
if (UUIDHandler.getName(uuid) == null) {
final ArrayList<UUID> toRemove = new ArrayList<>();
for (final UUID uuid : plot.getTrusted())
{
if (UUIDHandler.getName(uuid) == null)
{
toRemove.add(uuid);
}
}
for (UUID uuid : toRemove) {
for (final UUID uuid : toRemove)
{
plot.removeTrusted(uuid);
count++;
}
break;
case "*":
for (UUID uuid : new ArrayList<>(plot.getTrusted())) {
for (final UUID uuid : new ArrayList<>(plot.getTrusted()))
{
plot.removeTrusted(uuid);
count++;
}
break;
default:
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null) {
if (plot.removeTrusted(uuid)) {
final UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid != null)
{
if (plot.removeTrusted(uuid))
{
count++;
}
}
break;
}
if (count == 0) {
if (count == 0)
{
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
else {
else
{
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
}
return true;

View File

@ -30,43 +30,52 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "update",
permission = "plots.admin",
description = "Update PlotSquared",
usage = "/plot update",
requiredType = RequiredType.NONE,
aliases = {"updateplugin"},
category = CommandCategory.DEBUG
)
public class Update extends SubCommand {
command = "update",
permission = "plots.admin",
description = "Update PlotSquared",
usage = "/plot update",
requiredType = RequiredType.NONE,
aliases = { "updateplugin" },
category = CommandCategory.DEBUG)
public class Update extends SubCommand
{
public static String version;
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
URL url;
if (args.length == 0) {
if (args.length == 0)
{
url = PS.get().update;
}
else if (args.length == 1) {
try {
else if (args.length == 1)
{
try
{
url = new URL(args[0]);
} catch (MalformedURLException e) {
}
catch (final MalformedURLException e)
{
MainUtil.sendConsoleMessage("&cInvalid url: " + args[0]);
MainUtil.sendConsoleMessage(C.COMMAND_SYNTAX, "/plot update [url]");
return false;
}
}
else {
else
{
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, getUsage().replaceAll("\\{label\\}", "plot"));
return false;
}
if (url == null) {
if (url == null)
{
MainUtil.sendMessage(plr, "&cNo update found!");
MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update <url>");
return false;
}
if (PS.get().update(null, url) && url == PS.get().update) {
if (PS.get().update(null, url) && (url == PS.get().update))
{
PS.get().update = null;
}
return true;

View File

@ -36,26 +36,30 @@ import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit <player|aliases|world|id> [#]",
aliases = {"v"},
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT
)
public class Visit extends SubCommand {
command = "visit",
permission = "plots.visit",
description = "Visit someones plot",
usage = "/plot visit <player|aliases|world|id> [#]",
aliases = { "v" },
requiredType = RequiredType.NONE,
category = CommandCategory.TELEPORT)
public class Visit extends SubCommand
{
public Visit() {
public Visit()
{
requiredArguments = new Argument[] {
Argument.String
Argument.String
};
}
public List<Plot> getPlots(final UUID uuid) {
public List<Plot> getPlots(final UUID uuid)
{
final List<Plot> plots = new ArrayList<>();
for (final Plot p : PS.get().getPlots()) {
if (p.hasOwner() && p.isOwner(uuid)) {
for (final Plot p : PS.get().getPlots())
{
if (p.hasOwner() && p.isOwner(uuid))
{
plots.add(p);
}
}
@ -63,65 +67,81 @@ public class Visit extends SubCommand {
}
@Override
public boolean onCommand(PlotPlayer plr, String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
ArrayList<Plot> plots = new ArrayList<>();
UUID user = UUIDHandler.getCachedUUID(args[0], null);
if (user != null ) {
final UUID user = UUIDHandler.getCachedUUID(args[0], null);
if (user != null)
{
// do plots by username
plots = PS.get().sortPlotsByTemp(PS.get().getPlots(user));
} else if (PS.get().isPlotWorld(args[0])) {
}
else if (PS.get().isPlotWorld(args[0]))
{
// do plots by world
plots = PS.get().sortPlots(PS.get().getPlotsInWorld(args[0]), SortType.DISTANCE_FROM_ORIGIN, null);
}
else {
Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
if (plot == null) {
return false;
}
else
{
final Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
if (plot == null) { return false; }
plots.add(plot);
}
if (plots.size() == 0) {
if (plots.size() == 0)
{
sendMessage(plr, C.FOUND_NO_PLOTS);
return false;
}
int index = 0;
if (args.length == 2) {
try {
if (args.length == 2)
{
try
{
index = Integer.parseInt(args[1]) - 1;
if (index < 0 || index >= plots.size()) {
if ((index < 0) || (index >= plots.size()))
{
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
return false;
}
}
catch (Exception e) {
catch (final Exception e)
{
sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit " + args[0] + " [#]");
return false;
}
}
Plot plot = plots.get(index);
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(plr, "plots.visit.unowned")) {
final Plot plot = plots.get(index);
if (!plot.hasOwner())
{
if (!Permissions.hasPermission(plr, "plots.visit.unowned"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.unowned");
return false;
}
}
else if (plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home")) {
else if (plot.isOwner(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.visit.owned") && !Permissions.hasPermission(plr, "plots.home"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.owned, plots.home");
return false;
}
}
else if (plot.isAdded(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.visit.shared")) {
else if (plot.isAdded(plr.getUUID()))
{
if (!Permissions.hasPermission(plr, "plots.visit.shared"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared");
return false;
}
}
else {
if (!Permissions.hasPermission(plr, "plots.visit.other")) {
else
{
if (!Permissions.hasPermission(plr, "plots.visit.other"))
{
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other");
return false;
}

View File

@ -20,30 +20,25 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.general.commands.CommandDeclaration;
import com.plotsquared.listener.WEManager;
@CommandDeclaration(
command = "weanywhere",
permission = "plots.worldedit.bypass",
description = "Force bypass of WorldEdit",
aliases = {"wea"},
usage = "/plot weanywhere",
requiredType = RequiredType.NONE,
category = CommandCategory.DEBUG
)
command = "weanywhere",
permission = "plots.worldedit.bypass",
description = "Force bypass of WorldEdit",
aliases = { "wea" },
usage = "/plot weanywhere",
requiredType = RequiredType.NONE,
category = CommandCategory.DEBUG)
@Deprecated
public class WE_Anywhere extends SubCommand {
public class WE_Anywhere extends SubCommand
{
@Override
public boolean onCommand(PlotPlayer player, String[] arguments) {
return MainCommand.onCommand(player, "plot", new String[] {"toggle", "worldedit"});
public boolean onCommand(final PlotPlayer player, final String[] arguments)
{
return MainCommand.onCommand(player, "plot", new String[] { "toggle", "worldedit" });
}
}

View File

@ -25,18 +25,13 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.PS.SortType;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotMessage;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -48,98 +43,109 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "list",
aliases = {"l"},
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO
)
public class list extends SubCommand {
command = "list",
aliases = { "l" },
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO)
public class list extends SubCommand
{
private static String getName(final UUID id) {
if (id == null) {
return "none";
}
final String name = UUIDHandler.getName(id);
if (name == null) {
return "unknown";
}
return name;
}
private String[] getArgumentList(PlotPlayer player) {
List<String> args = new ArrayList<>();
if (EconHandler.manager != null && Permissions.hasPermission(player, "plots.list.forsale")) {
private String[] getArgumentList(final PlotPlayer player)
{
final List<String> args = new ArrayList<>();
if ((EconHandler.manager != null) && Permissions.hasPermission(player, "plots.list.forsale"))
{
args.add("forsale");
}
if (Permissions.hasPermission(player, "plots.list.mine")) {
if (Permissions.hasPermission(player, "plots.list.mine"))
{
args.add("mine");
}
if (Permissions.hasPermission(player, "plots.list.shared")) {
if (Permissions.hasPermission(player, "plots.list.shared"))
{
args.add("shared");
}
if (Permissions.hasPermission(player, "plots.list.world")) {
if (Permissions.hasPermission(player, "plots.list.world"))
{
args.add("world");
}
if (Permissions.hasPermission(player, "plots.list.top")) {
if (Permissions.hasPermission(player, "plots.list.top"))
{
args.add("top");
}
if (Permissions.hasPermission(player, "plots.list.all")) {
if (Permissions.hasPermission(player, "plots.list.all"))
{
args.add("all");
}
if (Permissions.hasPermission(player, "plots.list.unowned")) {
if (Permissions.hasPermission(player, "plots.list.unowned"))
{
args.add("unowned");
}
if (Permissions.hasPermission(player, "plots.list.unknown")) {
if (Permissions.hasPermission(player, "plots.list.unknown"))
{
args.add("unknown");
}
if (Permissions.hasPermission(player, "plots.list.player")) {
if (Permissions.hasPermission(player, "plots.list.player"))
{
args.add("<player>");
}
if (Permissions.hasPermission(player, "plots.list.world")) {
if (Permissions.hasPermission(player, "plots.list.world"))
{
args.add("<world>");
}
if (Permissions.hasPermission(player, "plots.list.done")) {
if (Permissions.hasPermission(player, "plots.list.done"))
{
args.add("done");
}
return args.toArray(new String[args.size()]);
}
public void noArgs(PlotPlayer plr) {
public void noArgs(final PlotPlayer plr)
{
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(getArgumentList(plr)));
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
if (args.length < 1) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
if (args.length < 1)
{
noArgs(plr);
return false;
}
int page = 0;
if (args.length > 1) {
try {
if (args.length > 1)
{
try
{
page = Integer.parseInt(args[1]);
--page;
if (page < 0) {
if (page < 0)
{
page = 0;
}
} catch (final Exception e) {
}
catch (final Exception e)
{
page = 0;
}
}
List<Plot> plots = null;
String world = plr.getLocation().getWorld();
String arg = args[0].toLowerCase();
final String world = plr.getLocation().getWorld();
final String arg = args[0].toLowerCase();
boolean sort = true;
switch (arg) {
case "mine": {
if (!Permissions.hasPermission(plr, "plots.list.mine")) {
switch (arg)
{
case "mine":
{
if (!Permissions.hasPermission(plr, "plots.list.mine"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine");
return false;
}
@ -147,79 +153,102 @@ public class list extends SubCommand {
plots = PS.get().sortPlotsByTemp(PS.get().getPlots(plr));
break;
}
case "shared": {
if (!Permissions.hasPermission(plr, "plots.list.shared")) {
case "shared":
{
if (!Permissions.hasPermission(plr, "plots.list.shared"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.shared");
return false;
}
plots = new ArrayList<Plot>();
for (Plot plot : PS.get().getPlots()) {
if (plot.getTrusted().contains(plr.getUUID()) || plot.getMembers().contains(plr.getUUID())) {
for (final Plot plot : PS.get().getPlots())
{
if (plot.getTrusted().contains(plr.getUUID()) || plot.getMembers().contains(plr.getUUID()))
{
plots.add(plot);
}
}
break;
}
case "world": {
if (!Permissions.hasPermission(plr, "plots.list.world")) {
case "world":
{
if (!Permissions.hasPermission(plr, "plots.list.world"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
return false;
}
if (!Permissions.hasPermission(plr, "plots.list.world." + world)) {
if (!Permissions.hasPermission(plr, "plots.list.world." + world))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
return false;
}
plots = new ArrayList<>(PS.get().getPlotsInWorld(world));
break;
}
case "all": {
if (!Permissions.hasPermission(plr, "plots.list.all")) {
case "all":
{
if (!Permissions.hasPermission(plr, "plots.list.all"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.all");
return false;
}
plots = new ArrayList<>(PS.get().getPlots());
break;
}
case "done": {
if (!Permissions.hasPermission(plr, "plots.list.done")) {
case "done":
{
if (!Permissions.hasPermission(plr, "plots.list.done"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.done");
return false;
}
plots = new ArrayList<>();
String match;
if (args.length == 2) {
if (args.length == 2)
{
match = args[1];
}
else {
else
{
match = null;
}
for (Plot plot : PS.get().getPlots()) {
Flag flag = plot.getSettings().flags.get("done");
if (flag == null) {
for (final Plot plot : PS.get().getPlots())
{
final Flag flag = plot.getSettings().flags.get("done");
if (flag == null)
{
continue;
}
if (match != null) {
try {
if (flag.getValueString().matches(match)) {
if (match != null)
{
try
{
if (flag.getValueString().matches(match))
{
plots.add(plot);
}
}
catch (Exception e) {
catch (final Exception e)
{
break;
}
}
else {
else
{
plots.add(plot);
}
}
Collections.sort(plots, new Comparator<Plot>() {
Collections.sort(plots, new Comparator<Plot>()
{
@Override
public int compare(Plot a, Plot b) {
String va = a.getSettings().flags.get("done").getValueString();
String vb = b.getSettings().flags.get("done").getValueString();
if (MathMan.isInteger(va)) {
public int compare(final Plot a, final Plot b)
{
final String va = a.getSettings().flags.get("done").getValueString();
final String vb = b.getSettings().flags.get("done").getValueString();
if (MathMan.isInteger(va))
{
if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va);
return Integer.parseInt(vb) - Integer.parseInt(va);
}
return -1;
}
@ -229,37 +258,45 @@ public class list extends SubCommand {
sort = false;
break;
}
case "top": {
if (!Permissions.hasPermission(plr, "plots.list.top")) {
case "top":
{
if (!Permissions.hasPermission(plr, "plots.list.top"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.top");
return false;
}
plots = new ArrayList<>(PS.get().getPlots());
Collections.sort(plots, new Comparator<Plot>() {
Collections.sort(plots, new Comparator<Plot>()
{
@Override
public int compare(Plot p1, Plot p2) {
public int compare(final Plot p1, final Plot p2)
{
double v1 = 0;
double v2 = 0;
int p1s = p1.getSettings().ratings != null ? p1.getSettings().ratings.size() : 0;
int p2s = p2.getSettings().ratings != null ? p2.getSettings().ratings.size() : 0;
if (p1.getSettings().ratings != null && p1s > 0) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
final int p1s = p1.getSettings().ratings != null ? p1.getSettings().ratings.size() : 0;
final int p2s = p2.getSettings().ratings != null ? p2.getSettings().ratings.size() : 0;
if ((p1.getSettings().ratings != null) && (p1s > 0))
{
for (final Entry<UUID, Rating> entry : p1.getRatings().entrySet())
{
final double av = entry.getValue().getAverageRating();
v1 += av * av;
}
v1 /= p1s;
v1 += p1s;
}
if (p2.getSettings().ratings != null && p2s > 0) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
if ((p2.getSettings().ratings != null) && (p2s > 0))
{
for (final Entry<UUID, Rating> entry : p2.getRatings().entrySet())
{
final double av = entry.getValue().getAverageRating();
v2 += av * av;
}
v2 /= p2s;
v2 += p2s;
}
if (v2 == v1 && v2 != 0) {
return p2s - p1s;
if ((v2 == v1) && (v2 != 0)) {
return p2s - p1s;
}
return (int) Math.signum(v2 - v1);
}
@ -267,59 +304,77 @@ public class list extends SubCommand {
sort = false;
break;
}
case "forsale": {
if (!Permissions.hasPermission(plr, "plots.list.forsale")) {
case "forsale":
{
if (!Permissions.hasPermission(plr, "plots.list.forsale"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.forsale");
return false;
}
if (EconHandler.manager == null) {
if (EconHandler.manager == null)
{
break;
}
plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) {
for (final Plot plot : PS.get().getPlots())
{
final Flag price = FlagManager.getPlotFlag(plot, "price");
if (price != null) {
if (price != null)
{
plots.add(plot);
}
}
break;
}
case "unowned": {
if (!Permissions.hasPermission(plr, "plots.list.unowned")) {
case "unowned":
{
if (!Permissions.hasPermission(plr, "plots.list.unowned"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unowned");
return false;
}
plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) {
if (plot.owner == null) {
for (final Plot plot : PS.get().getPlots())
{
if (plot.owner == null)
{
plots.add(plot);
}
}
break;
}
case "unknown": {
if (!Permissions.hasPermission(plr, "plots.list.unknown")) {
case "unknown":
{
if (!Permissions.hasPermission(plr, "plots.list.unknown"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.unknown");
return false;
}
plots = new ArrayList<>();
for (Plot plot : PS.get().getPlots()) {
if (plot.owner == null) {
for (final Plot plot : PS.get().getPlots())
{
if (plot.owner == null)
{
continue;
}
if (UUIDHandler.getName(plot.owner) == null) {
if (UUIDHandler.getName(plot.owner) == null)
{
plots.add(plot);
}
}
break;
}
default: {
if (PS.get().isPlotWorld(args[0])) {
if (!Permissions.hasPermission(plr, "plots.list.world")) {
default:
{
if (PS.get().isPlotWorld(args[0]))
{
if (!Permissions.hasPermission(plr, "plots.list.world"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world");
return false;
}
if (!Permissions.hasPermission(plr, "plots.list.world." + args[0])) {
if (!Permissions.hasPermission(plr, "plots.list.world." + args[0]))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
return false;
}
@ -327,14 +382,19 @@ public class list extends SubCommand {
break;
}
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null) {
try {
if (uuid == null)
{
try
{
uuid = UUID.fromString(args[0]);
}
catch (Exception e) {}
catch (final Exception e)
{}
}
if (uuid != null) {
if (!Permissions.hasPermission(plr, "plots.list.player")) {
if (uuid != null)
{
if (!Permissions.hasPermission(plr, "plots.list.player"))
{
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player");
return false;
}
@ -344,91 +404,107 @@ public class list extends SubCommand {
}
}
}
if (plots == null) {
if (plots == null)
{
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison<String>(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
return false;
}
if (plots.size() == 0) {
if (plots.size() == 0)
{
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
return false;
}
displayPlots(plr, plots, 12, page, world, args, sort);
return true;
}
public void displayPlots(PlotPlayer player, List<Plot> plots, int pageSize, int page, String world, String[] args, boolean sort) {
if (sort) {
public void displayPlots(final PlotPlayer player, List<Plot> plots, final int pageSize, int page, final String world, final String[] args, final boolean sort)
{
if (sort)
{
plots = PS.get().sortPlots(plots, SortType.DISTANCE_FROM_ORIGIN, world);
}
if (page < 0) {
if (page < 0)
{
page = 0;
}
final int totalPages = (int) Math.ceil(plots.size() / pageSize);
if (page > totalPages) {
if (page > totalPages)
{
page = totalPages;
}
// Only display pageSize!
int max = (page * pageSize) + pageSize;
if (max > plots.size()) {
if (max > plots.size())
{
max = plots.size();
}
List<Plot> subList = plots.subList(page * pageSize, max);
final List<Plot> subList = plots.subList(page * pageSize, max);
// Header
String header = C.PLOT_LIST_HEADER_PAGED.s()
.replaceAll("%cur", page + 1 + "")
.replaceAll("%max", totalPages + 1 + "")
.replaceAll("%amount%", plots.size() + "")
.replaceAll("%word%", "all");
final String header = C.PLOT_LIST_HEADER_PAGED.s()
.replaceAll("%cur", page + 1 + "")
.replaceAll("%max", totalPages + 1 + "")
.replaceAll("%amount%", plots.size() + "")
.replaceAll("%word%", "all");
MainUtil.sendMessage(player, header);
int i = page * pageSize;
for (Plot plot : subList) {
if (plot.getSettings().isMerged()) {
if (!MainUtil.getBottomPlot(plot).equals(plot)) {
for (final Plot plot : subList)
{
if (plot.getSettings().isMerged())
{
if (!MainUtil.getBottomPlot(plot).equals(plot))
{
continue;
}
}
i++;
String color;
if (plot.owner == null) {
if (plot.owner == null)
{
color = "$3";
}
else if (plot.isOwner(player.getUUID())) {
else if (plot.isOwner(player.getUUID()))
{
color = "$1";
}
else if (plot.isAdded(player.getUUID())) {
else if (plot.isAdded(player.getUUID()))
{
color = "$4";
}
else if (plot.isDenied(player.getUUID())) {
else if (plot.isDenied(player.getUUID()))
{
color = "$2";
}
else {
else
{
color = "$1";
}
PlotMessage trusted =
new PlotMessage()
.text(C.color(C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted()))))
.color("$1");
PlotMessage members =
new PlotMessage()
.text(C.color(C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers()))))
.color("$1");
final PlotMessage trusted =
new PlotMessage()
.text(C.color(C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted()))))
.color("$1");
final PlotMessage members =
new PlotMessage()
.text(C.color(C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers()))))
.color("$1");
String strFlags = StringMan.join(plot.getSettings().flags.values(), ",");
if (strFlags.length() == 0) {
if (strFlags.length() == 0)
{
strFlags = C.NONE.s();
}
PlotMessage flags =
new PlotMessage()
.text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags)))
.color("$1");
final PlotMessage flags =
new PlotMessage()
.text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags)))
.color("$1");
PlotMessage message = new PlotMessage()
.text("[")
.color("$3")
@ -439,48 +515,54 @@ public class list extends SubCommand {
.text("]")
.color("$3")
.text(" " + plot.toString())
.tooltip(trusted, members, flags)
.command("/plot info " + plot.world + ";" + plot.id)
.color(color)
.text(" - ")
.color("$2");
String prefix = "";
for (UUID uuid : plot.getOwners()) {
String name = UUIDHandler.getName(uuid);
if (name == null) {
for (final UUID uuid : plot.getOwners())
{
final String name = UUIDHandler.getName(uuid);
if (name == null)
{
message = message
.text(prefix)
.color("$4")
.text("unknown")
.color("$2")
.tooltip(uuid.toString())
.suggest(uuid.toString());
.text(prefix)
.color("$4")
.text("unknown")
.color("$2")
.tooltip(uuid.toString())
.suggest(uuid.toString());
}
else {
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null) {
else
{
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null)
{
message = message
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
}
else {
else
{
message = message
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Offline").color("$3"));
.text(prefix)
.color("$4")
.text(name).color("$1")
.tooltip(new PlotMessage("Offline").color("$3"));
}
}
prefix = ", ";
}
message.send(player);
}
if (page < totalPages && page > 0) {
// back | next
if ((page < totalPages) && (page > 0))
{
// back | next
new PlotMessage()
.text("<-")
.color("$1")
@ -495,7 +577,8 @@ public class list extends SubCommand {
.send(player);
return;
}
if (page == 0 && totalPages != 0) {
if ((page == 0) && (totalPages != 0))
{
// next
new PlotMessage()
.text("<-")
@ -510,7 +593,8 @@ public class list extends SubCommand {
.send(player);
return;
}
if (page == totalPages && totalPages != 0) {
if ((page == totalPages) && (totalPages != 0))
{
// back
new PlotMessage()
.text("<-")
@ -526,11 +610,13 @@ public class list extends SubCommand {
return;
}
}
private String getArgumentList(final String[] strings) {
private String getArgumentList(final String[] strings)
{
final StringBuilder builder = new StringBuilder();
String prefix = "";
for (final String s : strings) {
for (final String s : strings)
{
builder.append(prefix + s);
prefix = " | ";
}

View File

@ -27,16 +27,17 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "plugin",
permission = "plots.use",
description = "Show plugin information",
aliases = {"version"},
category = CommandCategory.INFO
)
public class plugin extends SubCommand {
command = "plugin",
permission = "plots.use",
description = "Show plugin information",
aliases = { "version" },
category = CommandCategory.INFO)
public class plugin extends SubCommand
{
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
public boolean onCommand(final PlotPlayer plr, final String[] args)
{
MainUtil.sendMessage(plr, String.format("$2>> $1&lPlotSquared $2($1Version$2: $1%s$2)", StringMan.join(PS.get().IMP.getPluginVersion(), ".")));
MainUtil.sendMessage(plr, String.format("$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92"));
MainUtil.sendMessage(plr, String.format("$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"));