mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 12:14:42 +02:00
Move all files! Hahah
This commit is contained in:
@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Add extends SubCommand {
|
||||
public Add() {
|
||||
super(Command.ADD, "Allow a user to build while you are online", "add <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot add <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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
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("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[0]);
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.members.contains(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
plot.addMember(uuid);
|
||||
}
|
||||
else {
|
||||
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
|
||||
return false;
|
||||
}
|
||||
if (plot.denied.contains(uuid)) {
|
||||
plot.removeDenied(uuid);
|
||||
}
|
||||
plot.addMember(uuid);
|
||||
}
|
||||
EventUtil.manager.callMember(plr, plot, uuid, true);
|
||||
MainUtil.sendMessage(plr, C.MEMBER_ADDED);
|
||||
return true;
|
||||
}
|
||||
}
|
238
src/main/java/com/intellectualcrafters/plot/commands/Auto.java
Normal file
238
src/main/java/com/intellectualcrafters/plot/commands/Auto.java
Normal file
@ -0,0 +1,238 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
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;
|
||||
|
||||
public class Auto extends SubCommand {
|
||||
public Auto() {
|
||||
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
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) {
|
||||
return new PlotId(id.x, id.y + 1);
|
||||
} else {
|
||||
return new PlotId(id.x, id.y - 1);
|
||||
}
|
||||
} else if (absY > absX) {
|
||||
if (id.y > 0) {
|
||||
return new PlotId(id.x - 1, id.y);
|
||||
} 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);
|
||||
}
|
||||
return new PlotId(id.x + 1, id.y);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO auto claim a mega plot with schematic
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
String world;
|
||||
int size_x = 1;
|
||||
int size_z = 1;
|
||||
String schematic = "";
|
||||
if (PS.get().getPlotWorlds().size() == 1) {
|
||||
world = PS.get().getPlotWorlds().iterator().next();
|
||||
} else {
|
||||
world = plr.getLocation().getWorld();
|
||||
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 {
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, "&cError: size<=0");
|
||||
}
|
||||
if ((size_x > 4) || (size_z > 4)) {
|
||||
MainUtil.sendMessage(plr, "&cError: size>4");
|
||||
}
|
||||
if (args.length > 1) {
|
||||
schematic = args[1];
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
size_x = 1;
|
||||
size_z = 1;
|
||||
schematic = args[0];
|
||||
// PlayerFunctions.sendMessage(plr,
|
||||
// "&cError: Invalid size (X,Y)");
|
||||
// return false;
|
||||
}
|
||||
} else {
|
||||
schematic = args[0];
|
||||
// PlayerFunctions.sendMessage(plr, C.NO_PERMISSION);
|
||||
// return false;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + "");
|
||||
} 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) {
|
||||
double cost = pWorld.PLOT_PRICE;
|
||||
cost = (size_x * size_z) * cost;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + cost);
|
||||
return true;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
if (!schematic.equals("")) {
|
||||
// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) {
|
||||
if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic);
|
||||
return true;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin.command.schematic")) {
|
||||
MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic);
|
||||
return true;
|
||||
}
|
||||
// }
|
||||
}
|
||||
final String worldname = world;
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
|
||||
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);
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(loc);
|
||||
// Must be standing in a cluster
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
final PlotId bot = cluster.getP1();
|
||||
final PlotId top = cluster.getP2();
|
||||
final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
||||
PlotId id = new PlotId(0, 0);
|
||||
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++) {
|
||||
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.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
|
||||
Claim.claimPlot(plr, current, true, true);
|
||||
return true;
|
||||
}
|
||||
id = getNextPlot(id, 1);
|
||||
}
|
||||
// no free plots
|
||||
MainUtil.sendMessage(plr, C.NO_FREE_PLOTS);
|
||||
return false;
|
||||
}
|
||||
boolean br = false;
|
||||
if ((size_x == 1) && (size_z == 1)) {
|
||||
while (!br) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
|
||||
if (MainUtil.canClaim(plr, plot)) {
|
||||
Claim.claimPlot(plr, plot, true, true);
|
||||
br = true;
|
||||
}
|
||||
MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1));
|
||||
}
|
||||
} else {
|
||||
boolean lastPlot = true;
|
||||
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().getPlots(worldname).get(start) != null) && (PS.get().getPlots(worldname).get(start).owner != null)) {
|
||||
continue;
|
||||
} 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++) {
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
br = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
MainUtil.lastPlot.put(worldname, new PlotId(0, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
/**
|
||||
* Created 2015-02-20 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class BukkitCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender commandSender, final Command command, final String commandLabel, final String[] args) {
|
||||
if (commandSender instanceof Player) {
|
||||
return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), commandLabel, args);
|
||||
}
|
||||
return MainCommand.onCommand(null, commandLabel, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(final CommandSender commandSender, final Command command, final String s, final String[] strings) {
|
||||
if (!(commandSender instanceof Player)) {
|
||||
return null;
|
||||
}
|
||||
final PlotPlayer player = BukkitUtil.getPlayer((Player) commandSender);
|
||||
if (strings.length < 1) {
|
||||
if ((strings.length == 0) || "plots".startsWith(s)) {
|
||||
return Arrays.asList("plots");
|
||||
}
|
||||
}
|
||||
if (strings.length > 1) {
|
||||
return null;
|
||||
}
|
||||
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
||||
return null;
|
||||
}
|
||||
final List<String> tabOptions = new ArrayList<>();
|
||||
final String[] commands = new String[MainCommand.subCommands.size()];
|
||||
for (int x = 0; x < MainCommand.subCommands.size(); x++) {
|
||||
commands[x] = MainCommand.subCommands.get(x).cmd;
|
||||
}
|
||||
String best = new StringComparison(strings[0], commands).getBestMatch();
|
||||
tabOptions.add(best);
|
||||
final String arg = strings[0].toLowerCase();
|
||||
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||
if (!cmd.cmd.equalsIgnoreCase(best)) {
|
||||
if (cmd.permission.hasPermission(player)) {
|
||||
if (cmd.cmd.startsWith(arg)) {
|
||||
tabOptions.add(cmd.cmd);
|
||||
} else if (cmd.alias.size() > 0 && cmd.alias.get(0).startsWith(arg)) {
|
||||
tabOptions.add(cmd.alias.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tabOptions.size() > 0) {
|
||||
return tabOptions;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
119
src/main/java/com/intellectualcrafters/plot/commands/Buy.java
Normal file
119
src/main/java/com/intellectualcrafters/plot/commands/Buy.java
Normal file
@ -0,0 +1,119 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotHandler;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Buy extends SubCommand {
|
||||
public Buy() {
|
||||
super(Command.BUY, "Buy the plot you are standing on", "b", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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);
|
||||
}
|
||||
Plot plot;
|
||||
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) {
|
||||
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
} else {
|
||||
plot = MainUtil.getPlot(loc);
|
||||
}
|
||||
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);
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlag(plot, "price");
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, price);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, price + "");
|
||||
EconHandler.manager.depositMoney(UUIDHandler.uuidWrapper.getOfflinePlayer(plot.owner), initPrice);
|
||||
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
|
||||
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);
|
||||
myPlot.owner = plr.getUUID();
|
||||
DBFunc.setOwner(plot, myPlot.owner);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLAIMED);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
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;
|
||||
|
||||
public class Chat extends SubCommand {
|
||||
public Chat() {
|
||||
super(Command.CHAT, "Toggle plot chat on or off", "chat", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(PlotPlayer plr, String... args) {
|
||||
final String world = plr.getLocation().getWorld();
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
boolean enable = !(plr.getMeta("chat") != null && (Boolean) plr.getMeta("chat"));
|
||||
if (args.length > 0) {
|
||||
if (args[0].equalsIgnoreCase("on")) {
|
||||
enable = true;
|
||||
} else if (args[0].equalsIgnoreCase("off")) {
|
||||
enable = false;
|
||||
}
|
||||
}
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (!enable && plotworld.PLOT_CHAT) {
|
||||
return !sendMessage(plr, C.PLOT_CHAT_FORCED);
|
||||
}
|
||||
plr.setMeta("chat", enable);
|
||||
return sendMessage(plr, enable ? C.PLOT_CHAT_ON : C.PLOT_CHAT_OFF);
|
||||
}
|
||||
}
|
123
src/main/java/com/intellectualcrafters/plot/commands/Claim.java
Normal file
123
src/main/java/com/intellectualcrafters/plot/commands/Claim.java
Normal file
@ -0,0 +1,123 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Claim extends SubCommand {
|
||||
public Claim() {
|
||||
super(Command.CLAIM, "Claim the current plot you're standing on.", "claim", CommandCategory.CLAIMING, true);
|
||||
}
|
||||
|
||||
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.settings.isMerged()) {
|
||||
return false;
|
||||
}
|
||||
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
||||
if (result) {
|
||||
MainUtil.createPlot(player.getUUID(), plot);
|
||||
MainUtil.setSign(player.getName(), plot);
|
||||
MainUtil.sendMessage(player, C.CLAIMED);
|
||||
final Location loc = player.getLocation();
|
||||
if (teleport) {
|
||||
MainUtil.teleportPlayer(player, loc, plot);
|
||||
}
|
||||
final String world = plot.world;
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
final Plot plot2 = PS.get().getPlots(world).get(plot.id);
|
||||
if (plotworld.SCHEMATIC_ON_CLAIM) {
|
||||
Schematic sch;
|
||||
if (schematic.equals("")) {
|
||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||
} else {
|
||||
sch = SchematicHandler.manager.getSchematic(schematic);
|
||||
if (sch == null) {
|
||||
sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE);
|
||||
}
|
||||
}
|
||||
SchematicHandler.manager.paste(sch, plot2, 0, 0);
|
||||
}
|
||||
PS.get().getPlotManager(world).claimPlot(plotworld, plot);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
String schematic = "";
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
final PlotWorld world = PS.get().getPlotWorld(plot.world);
|
||||
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);
|
||||
}
|
||||
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) && !plr.hasPermission("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);
|
||||
}
|
||||
}
|
144
src/main/java/com/intellectualcrafters/plot/commands/Clear.java
Normal file
144
src/main/java/com/intellectualcrafters/plot/commands/Clear.java
Normal file
@ -0,0 +1,144 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
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.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Clear extends SubCommand {
|
||||
public Clear() {
|
||||
super(Command.CLEAR, "Clear a plot", "clear", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
// Is console
|
||||
if (args.length < 2) {
|
||||
PS.log("You need to specify two arguments: ID (0;0) & World (world)");
|
||||
} else {
|
||||
final PlotId id = PlotId.fromString(args[0]);
|
||||
final String world = args[1];
|
||||
if (id == null) {
|
||||
PS.log("Invalid Plot ID: " + args[0]);
|
||||
} else {
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
PS.log("Invalid plot world: " + world);
|
||||
} else {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
if (plot == null) {
|
||||
PS.log("Could not find plot " + args[0] + " in world " + world);
|
||||
} else {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.clear(plot, plot.owner == null, null);
|
||||
PS.log("Plot " + plot.getId().toString() + " cleared.");
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot clear " + id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
plot = plots.iterator().next();
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlot(loc.getWorld(), id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlot(loc);
|
||||
}
|
||||
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);
|
||||
}
|
||||
assert plot != null;
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,567 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.BlockLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
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.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Cluster extends SubCommand {
|
||||
public Cluster() {
|
||||
super(Command.CLUSTER, "Manage a plot cluster", "cluster", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
|
||||
if (args.length == 0) {
|
||||
// return arguments
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||
return false;
|
||||
}
|
||||
final String sub = args[0].toLowerCase();
|
||||
switch (sub) {
|
||||
case "l":
|
||||
case "list": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
// Ignore unmanaged clusters
|
||||
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
|
||||
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
|
||||
} 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))) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "c":
|
||||
case "create": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
// check pos1 / pos2
|
||||
final PlotId pos1 = MainUtil.parseId(args[2]);
|
||||
final PlotId pos2 = MainUtil.parseId(args[3]);
|
||||
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())) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//check if overlap
|
||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
||||
if ((intersects.size() > 0) || (pos2.x < pos1.x) || (pos2.y < pos1.y)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
|
||||
return false;
|
||||
}
|
||||
// create cluster
|
||||
final String world = plr.getLocation().getWorld();
|
||||
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
|
||||
cluster.settings.setAlias(name);
|
||||
DBFunc.createCluster(world, cluster);
|
||||
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 (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
|
||||
cluster.invited.add(plot.owner);
|
||||
DBFunc.setInvited(world, cluster, plot.owner);
|
||||
}
|
||||
}
|
||||
PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
if (plotworld == null) {
|
||||
PS.get().config.createSection("worlds." + world);
|
||||
PS.get().loadWorld(world, null);
|
||||
}
|
||||
else {
|
||||
final String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
|
||||
PlotGenerator generator;
|
||||
if (gen_string == null) {
|
||||
generator = new HybridGen(world);
|
||||
} else {
|
||||
generator = (PlotGenerator) PS.get().IMP.getGenerator(world, gen_string);
|
||||
}
|
||||
new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
|
||||
return true;
|
||||
}
|
||||
case "disband":
|
||||
case "del":
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
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")) {
|
||||
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) {
|
||||
final ArrayList<Plot> toRemove = new ArrayList<>();
|
||||
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
final PlotCluster other = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(other)) {
|
||||
toRemove.add(plot);
|
||||
}
|
||||
}
|
||||
for (final Plot plot : toRemove) {
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
DBFunc.delete(cluster);
|
||||
if (plotworld.TYPE == 2) {
|
||||
AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster);
|
||||
}
|
||||
ClusterManager.last = null;
|
||||
ClusterManager.clusters.get(cluster.world).remove(cluster);
|
||||
ClusterManager.regenCluster(cluster);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_DELETED);
|
||||
return true;
|
||||
}
|
||||
case "res":
|
||||
case "resize": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
|
||||
return false;
|
||||
}
|
||||
if (args.length != 3) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
|
||||
return false;
|
||||
}
|
||||
// check pos1 / pos2
|
||||
final PlotId pos1 = MainUtil.parseId(args[1]);
|
||||
final PlotId pos2 = MainUtil.parseId(args[2]);
|
||||
if ((pos1 == null) || (pos2 == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
// check if in cluster
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
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")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//check if overlap
|
||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
|
||||
if (intersects.size() > 1) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
|
||||
return false;
|
||||
}
|
||||
// resize cluster
|
||||
DBFunc.resizeCluster(cluster, id);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
|
||||
return true;
|
||||
}
|
||||
case "reg":
|
||||
case "regenerate":
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
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")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ClusterManager.regenCluster(cluster);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED);
|
||||
return true;
|
||||
}
|
||||
case "add":
|
||||
case "inv":
|
||||
case "invite": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
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]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED_USER);
|
||||
return true;
|
||||
}
|
||||
case "k":
|
||||
case "remove":
|
||||
case "kick": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
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]);
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.CANNOT_KICK_PLAYER, cluster.getName());
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||
}
|
||||
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();
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_KICKED_USER);
|
||||
return true;
|
||||
}
|
||||
case "quit":
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(plr);
|
||||
if (!cluster.isAdded(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
if (uuid.equals(cluster.owner)) {
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_CANNOT_LEAVE);
|
||||
return false;
|
||||
}
|
||||
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))) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if ((current != null) && current.equals(cluster)) {
|
||||
final String world = plr.getLocation().getWorld();
|
||||
plot.unclaim();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "admin":
|
||||
case "helper":
|
||||
case "helpers": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[2]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
|
||||
return false;
|
||||
}
|
||||
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")) {
|
||||
cluster.helpers.remove(uuid);
|
||||
DBFunc.removeHelper(cluster, uuid);
|
||||
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
|
||||
return false;
|
||||
}
|
||||
case "spawn":
|
||||
case "home":
|
||||
case "tp": {
|
||||
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
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")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
plr.teleport(ClusterManager.getHome(cluster));
|
||||
return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING);
|
||||
}
|
||||
case "i":
|
||||
case "info":
|
||||
case "show":
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
|
||||
return false;
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
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) {
|
||||
owner = "unknown";
|
||||
}
|
||||
final String name = cluster.getName();
|
||||
final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1);
|
||||
final String rights = cluster.isAdded(UUIDHandler.getUUID(plr)) + "";
|
||||
String message = C.CLUSTER_INFO.s();
|
||||
message = message.replaceAll("%id%", id);
|
||||
message = message.replaceAll("%owner%", owner);
|
||||
message = message.replaceAll("%name%", name);
|
||||
message = message.replaceAll("%size%", size);
|
||||
message = message.replaceAll("%rights%", rights);
|
||||
MainUtil.sendMessage(plr, message);
|
||||
return true;
|
||||
}
|
||||
case "sh":
|
||||
case "setspawn":
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
|
||||
return false;
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
|
||||
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")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final Location base = ClusterManager.getClusterBottom(cluster);
|
||||
final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
|
||||
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
|
||||
cluster.settings.setPosition(blockloc);
|
||||
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-08-03.
|
||||
*
|
||||
* @author Citymonstret
|
||||
* @author Empire92
|
||||
*/
|
||||
public enum Command {
|
||||
// TODO new commands
|
||||
// (economy)
|
||||
// - /plot buy
|
||||
// - /plot sell <value>
|
||||
// (Rating system) (ratings can be stored as the average, and number of
|
||||
// ratings)
|
||||
// - /plot rate <number out of 10>
|
||||
|
||||
ADD("add","a"),
|
||||
TRUST("trust", "t"),
|
||||
DENY("deny", "d"),
|
||||
REMOVE("remove", "r"),
|
||||
UNTRUST("untrust", "ut"),
|
||||
UNDENY("undeny", "ud"),
|
||||
TOGGLE("toggle", "attribute"),
|
||||
DOWNLOAD("download", "dl"),
|
||||
MOVE("move"),
|
||||
FLAG("flag", "f"),
|
||||
TARGET("target"),
|
||||
CLUSTER("cluster", "clusters"),
|
||||
BUY("buy", "b"),
|
||||
CREATEROADSCHEMATIC("createroadschematic", "crs"),
|
||||
DEBUGROADREGEN("debugroadregen"),
|
||||
DEBUGFIXFLAGS("debugfixflags"),
|
||||
REGENALLROADS("regenallroads"),
|
||||
ALLOWUNSAFE("debugallowunsafe"),
|
||||
DEBUGLOADTEST("debugloadtest"),
|
||||
DEBUGSAVETEST("debugsavetest"),
|
||||
UNCLAIM("unclaim"),
|
||||
DEBUGCLEAR("debugclear", "fastclear"),
|
||||
SWAP("swap"),
|
||||
INBOX("inbox"),
|
||||
DEBUGCLAIMTEST("debugclaimtest"),
|
||||
COMMENT("comment", "msg"),
|
||||
PASTE("paste"),
|
||||
CLIPBOARD("clipboard", "cboard"),
|
||||
COPY("copy"),
|
||||
KICK("kick", "k"),
|
||||
CLAIM("claim", "c"),
|
||||
MERGE("merge", "m"),
|
||||
UNLINK("unlink", "u"),
|
||||
CLEAR("clear", "", new CommandPermission("plots.clear")),
|
||||
DELETE("delete", "", new CommandPermission("plots.delete")),
|
||||
DEBUG("debug", "", new CommandPermission("plots.admin")),
|
||||
INTERFACE("interface", "int", new CommandPermission("plots.interface")),
|
||||
HOME("home", "h"),
|
||||
INFO("info", "i"),
|
||||
LIST("list", "l"),
|
||||
SET("set", "s"),
|
||||
PURGE("purge"),
|
||||
DATABASE("database", "convert"),
|
||||
CONFIRM("confirm"),
|
||||
TP("tp", "tp"),
|
||||
CHAT("chat", "on|off", new CommandPermission("plots.chat"));
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
private final String command;
|
||||
/**
|
||||
* Alias
|
||||
*/
|
||||
private final String alias;
|
||||
/**
|
||||
* Permission Node
|
||||
*/
|
||||
private final CommandPermission permission;
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
*/
|
||||
Command(final String command) {
|
||||
this.command = command;
|
||||
this.alias = command;
|
||||
this.permission = new CommandPermission("plots." + command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param permission Command Permission Node
|
||||
*/
|
||||
Command(final String command, final CommandPermission permission) {
|
||||
this.command = command;
|
||||
this.permission = permission;
|
||||
this.alias = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param alias Command Alias
|
||||
*/
|
||||
Command(final String command, final String alias) {
|
||||
this.command = command;
|
||||
this.alias = alias;
|
||||
this.permission = new CommandPermission("plots." + command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command "name" (/plot [cmd])
|
||||
* @param alias Command Alias
|
||||
* @param permission Required Permission Node
|
||||
*/
|
||||
Command(final String command, final String alias, final CommandPermission permission) {
|
||||
this.command = command;
|
||||
this.alias = alias;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return command
|
||||
*/
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return alias
|
||||
*/
|
||||
public String getAlias() {
|
||||
return this.alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return permission object
|
||||
*
|
||||
* @see com.intellectualcrafters.plot.commands.CommandPermission
|
||||
*/
|
||||
public CommandPermission getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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);
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.Arrays;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.comment.CommentInbox;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentManager;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Comment extends SubCommand {
|
||||
public Comment() {
|
||||
super(Command.COMMENT, "Comment on a plot", "comment", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length < 2) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
if (inbox == null) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
Plot plot;
|
||||
Location loc = player.getLocation();
|
||||
PlotId id = PlotId.fromString(args[1]);
|
||||
int index;
|
||||
if (id != null) {
|
||||
if (args.length < 4) {
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
index = 2;
|
||||
plot = MainUtil.getPlot(loc.getWorld(), id);
|
||||
}
|
||||
else {
|
||||
index = 1;
|
||||
plot = MainUtil.getPlot(loc);
|
||||
}
|
||||
if (!inbox.canWrite(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX, "");
|
||||
return false;
|
||||
}
|
||||
String message = StringUtils.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) {
|
||||
sendMessage(player, C.NO_PLOT_INBOX, "");
|
||||
sendMessage(player, C.COMMENT_SYNTAX, StringUtils.join(CommentManager.inboxes.keySet(),"|"));
|
||||
return false;
|
||||
}
|
||||
sendMessage(player, C.COMMENT_ADDED);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Condense extends SubCommand {
|
||||
public static boolean TASK = false;
|
||||
|
||||
public Condense() {
|
||||
super("condense", "plots.admin", "Condense a plotworld", "condense", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
public static void sendMessage(final String message) {
|
||||
PS.log("&3PlotSquared -> Plot condense&8: &7" + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, "INVALID WORLD");
|
||||
return false;
|
||||
}
|
||||
switch (args[1].toLowerCase()) {
|
||||
case "start": {
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||
return false;
|
||||
}
|
||||
if (TASK) {
|
||||
MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
|
||||
return false;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||
return false;
|
||||
}
|
||||
if (!StringUtils.isNumeric(args[2])) {
|
||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||
return false;
|
||||
}
|
||||
final int radius = Integer.parseInt(args[2]);
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final int size = plots.size();
|
||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||
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)) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, start);
|
||||
if (!plot.hasOwner()) {
|
||||
free.add(plot.id);
|
||||
}
|
||||
start = Auto.getNextPlot(start, 1);
|
||||
}
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!TASK) {
|
||||
sendMessage("CONDENSE TASK CANCELLED");
|
||||
return;
|
||||
}
|
||||
to_move.remove(0);
|
||||
free.remove(0);
|
||||
int index = 0;
|
||||
for (final PlotId id : to_move) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, id);
|
||||
if (plot.hasOwner()) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
for (int i = 0; i < index; i++) {
|
||||
to_move.remove(0);
|
||||
}
|
||||
index = 0;
|
||||
for (final PlotId id : free) {
|
||||
final Plot plot = MainUtil.getPlot(worldname, id);
|
||||
if (!plot.hasOwner()) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
for (int i = 0; i < index; i++) {
|
||||
free.remove(0);
|
||||
}
|
||||
if (to_move.size() == 0) {
|
||||
sendMessage("TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
||||
TASK = false;
|
||||
return;
|
||||
}
|
||||
if (free.size() == 0) {
|
||||
sendMessage("TASK FAILED. NO FREE PLOTS FOUND!");
|
||||
TASK = false;
|
||||
return;
|
||||
}
|
||||
sendMessage("MOVING " + to_move.get(0) + " to " + free.get(0));
|
||||
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), this);
|
||||
}
|
||||
});
|
||||
TASK = true;
|
||||
MainUtil.sendMessage(plr, "TASK STARTED...");
|
||||
return true;
|
||||
}
|
||||
case "stop": {
|
||||
if (!TASK) {
|
||||
MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
|
||||
return false;
|
||||
}
|
||||
TASK = false;
|
||||
MainUtil.sendMessage(plr, "TASK STOPPED");
|
||||
return true;
|
||||
}
|
||||
case "info": {
|
||||
if (args.length == 2) {
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
|
||||
return false;
|
||||
}
|
||||
if (!StringUtils.isNumeric(args[2])) {
|
||||
MainUtil.sendMessage(plr, "INVALID RADIUS");
|
||||
return false;
|
||||
}
|
||||
final int radius = Integer.parseInt(args[2]);
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final int size = plots.size();
|
||||
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
|
||||
if (radius < minimum_radius) {
|
||||
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
|
||||
return false;
|
||||
}
|
||||
final int max_move = getPlots(plots, minimum_radius).size();
|
||||
final int user_move = getPlots(plots, radius).size();
|
||||
MainUtil.sendMessage(plr, "=== DEFAULT EVAL ===");
|
||||
MainUtil.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius);
|
||||
MainUtil.sendMessage(plr, "MAXIMUM MOVES: " + max_move);
|
||||
MainUtil.sendMessage(plr, "=== INPUT EVAL ===");
|
||||
MainUtil.sendMessage(plr, "INPUT RADIUS: " + radius);
|
||||
MainUtil.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
||||
MainUtil.sendMessage(plr, "ESTIMATED TIME: " + "No idea, times will drastically change based on the system performance and load");
|
||||
MainUtil.sendMessage(plr, "&e - Radius is measured in plot width");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, "/plot condense " + worldname + " <start|stop|info> [radius]");
|
||||
return false;
|
||||
}
|
||||
|
||||
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)) {
|
||||
outside.add(plot.id);
|
||||
}
|
||||
}
|
||||
return outside;
|
||||
}
|
||||
}
|
@ -0,0 +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.CmdInstance;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Confirm extends SubCommand {
|
||||
public Confirm() {
|
||||
super("confirm", "plots.use", "Confirm an action", "confirm", "confirm", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Copy extends SubCommand {
|
||||
public Copy() {
|
||||
super("copy", "plots.copy", "Copy a plot", "copypaste", "", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
|
||||
return false;
|
||||
}
|
||||
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()) && !plr.hasPermission(Permissions.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)) {
|
||||
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)) {
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.COPY_SUCCESS);
|
||||
}
|
||||
})) {
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class CreateRoadSchematic extends SubCommand {
|
||||
public CreateRoadSchematic() {
|
||||
super(Command.CREATEROADSCHEMATIC, "Add a road schematic to your world using the road around your current plot", "crs", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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);
|
||||
}
|
||||
HybridUtils.manager.setupRoadSchematic(plot);
|
||||
MainUtil.sendMessage(player, "&6Saved new road schematic");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.MySQL;
|
||||
import com.intellectualcrafters.plot.database.SQLManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* Created 2014-11-15 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Database extends SubCommand {
|
||||
public Database() {
|
||||
super(Command.DATABASE, "Convert/Backup Storage", "database [type] [...details]", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
private static boolean sendMessageU(final UUID uuid, final String msg) {
|
||||
if (uuid == null) {
|
||||
PS.log(msg);
|
||||
} else {
|
||||
final PlotPlayer p = UUIDHandler.getPlayer(uuid);
|
||||
if ((p != null) && p.isOnline()) {
|
||||
return MainUtil.sendMessage(p, msg);
|
||||
} else {
|
||||
return sendMessageU(null, msg);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void insertPlots(final SQLManager manager, final UUID requester, final Connection c) {
|
||||
final java.util.Set<Plot> plots = PS.get().getPlots();
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final ArrayList<Plot> ps = new ArrayList<>();
|
||||
for (final Plot p : plots) {
|
||||
ps.add(p);
|
||||
}
|
||||
sendMessageU(requester, "&6Starting...");
|
||||
manager.createPlotsAndData(ps, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendMessageU(requester, "&6Database conversion finished!");
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
sendMessageU(requester, "Failed to insert plot objects, see stacktrace for info");
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
c.close();
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
return sendMessage(plr, "/plot database [sqlite/mysql]");
|
||||
}
|
||||
final String type = new StringComparison(args[0], new String[] { "mysql", "sqlite" }).getBestMatch().toLowerCase();
|
||||
switch (type) {
|
||||
case "mysql":
|
||||
if (args.length < 6) {
|
||||
return sendMessage(plr, "/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];
|
||||
String prefix = "";
|
||||
if (args.length > 6) {
|
||||
prefix = args[6];
|
||||
}
|
||||
Connection n;
|
||||
try {
|
||||
n = new MySQL(host, port, database, username, password).openConnection();
|
||||
// Connection
|
||||
if (n.isClosed()) {
|
||||
return sendMessage(plr, "Failed to open connection");
|
||||
}
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return sendMessage(plr, "Failed to open connection, read stacktrace for info");
|
||||
}
|
||||
final SQLManager manager = new SQLManager(n, prefix);
|
||||
try {
|
||||
manager.createTables("mysql");
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
return sendMessage(plr, "Could not create the required tables and/or load the database") && sendMessage(plr, "Please see the stacktrace for more information");
|
||||
}
|
||||
UUID requester = null;
|
||||
if (plr != null) {
|
||||
requester = UUIDHandler.getUUID(plr);
|
||||
}
|
||||
insertPlots(manager, requester, n);
|
||||
break;
|
||||
case "sqlite":
|
||||
if (args.length < 2) {
|
||||
return sendMessage(plr, "/plot database sqlite [file name]");
|
||||
}
|
||||
sendMessage(plr, "This is not supported yet");
|
||||
break;
|
||||
default:
|
||||
return sendMessage(plr, "Unknown database type");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean sendMessage(final PlotPlayer player, final String msg) {
|
||||
if (player == null) {
|
||||
PS.log(msg);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.Lag;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Debug extends SubCommand {
|
||||
public Debug() {
|
||||
super(Command.DEBUG, "Show debug information", "debug [msg]", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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()) {
|
||||
msg.append(c.s()).append("\n");
|
||||
}
|
||||
MainUtil.sendMessage(plr, msg.toString());
|
||||
return true;
|
||||
}
|
||||
StringBuilder information;
|
||||
String header, line, section;
|
||||
{
|
||||
information = new StringBuilder();
|
||||
header = C.DEBUG_HEADER.s();
|
||||
line = C.DEBUG_LINE.s();
|
||||
section = C.DEBUG_SECTION.s();
|
||||
}
|
||||
{
|
||||
final StringBuilder worlds = new StringBuilder("");
|
||||
for (final String world : PS.get().getPlotWorlds()) {
|
||||
worlds.append(world).append(" ");
|
||||
}
|
||||
information.append(header);
|
||||
information.append(getSection(section, "Lag / TPS"));
|
||||
information.append(getLine(line, "Ticks Per Second", Lag.getTPS()));
|
||||
information.append(getLine(line, "Lag Percentage", (int) Lag.getPercentage() + "%"));
|
||||
information.append(getLine(line, "TPS Percentage", (int) Lag.getFullPercentage() + "%"));
|
||||
information.append(getSection(section, "PlotWorld"));
|
||||
information.append(getLine(line, "Plot Worlds", worlds));
|
||||
information.append(getLine(line, "Owned Plots", PS.get().getPlots().size()));
|
||||
information.append(getSection(section, "Messages"));
|
||||
information.append(getLine(line, "Total Messages", C.values().length));
|
||||
information.append(getLine(line, "View all captions", "/plot debug msg"));
|
||||
}
|
||||
{
|
||||
MainUtil.sendMessage(plr, information.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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) {
|
||||
return line.replaceAll("%var%", var).replaceAll("%val%", "" + val) + "\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DebugAllowUnsafe extends SubCommand {
|
||||
|
||||
public static final List<UUID> unsafeAllowed = new ArrayList<>();
|
||||
|
||||
public DebugAllowUnsafe() {
|
||||
super(Command.ALLOWUNSAFE, "Allow unsafe actions until toggled off", "allowunsafe", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
MainUtil.sendMessage(plr, C.IS_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (unsafeAllowed.contains(plr.getUUID())) {
|
||||
unsafeAllowed.remove(plr.getUUID());
|
||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_OFF);
|
||||
} else {
|
||||
unsafeAllowed.add(plr.getUUID());
|
||||
sendMessage(plr, C.DEBUGALLOWUNSAFE_ON);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DebugClaimTest extends SubCommand {
|
||||
public DebugClaimTest() {
|
||||
super(Command.DEBUGCLAIMTEST, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. Execution time may vary", "debugclaimtest", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
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) {
|
||||
final boolean result = EventUtil.manager.callClaim(player, plot, false);
|
||||
if (result) {
|
||||
MainUtil.createPlot(player.getUUID(), plot);
|
||||
MainUtil.setSign(player.getName(), plot);
|
||||
MainUtil.sendMessage(player, C.CLAIMED);
|
||||
if (teleport) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||
}
|
||||
}
|
||||
return !result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
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!");
|
||||
}
|
||||
PlotId min, max;
|
||||
try {
|
||||
final String[] split1 = args[1].split(";");
|
||||
final String[] split2 = args[2].split(";");
|
||||
min = new PlotId(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
|
||||
max = new PlotId(Integer.parseInt(split2[0]), Integer.parseInt(split2[1]));
|
||||
} 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)) {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
final boolean contains = PS.get().getPlots(world).containsKey(plot.id);
|
||||
if (contains) {
|
||||
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);
|
||||
if (!result) {
|
||||
continue;
|
||||
}
|
||||
final String[] lines = BlockManager.manager.getSign(loc);
|
||||
if (lines != null) {
|
||||
String line = lines[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())) {
|
||||
uuid = map.get(string);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uuid == null) {
|
||||
uuid = UUIDHandler.getUUID(line);
|
||||
}
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(null, " - &aFound plot: " + plot.id + " : " + line);
|
||||
plot.owner = uuid;
|
||||
plot.hasChanged = true;
|
||||
plots.add(plot);
|
||||
} else {
|
||||
MainUtil.sendMessage(null, " - &cInvalid playername: " + plot.id + " : " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plots.size() > 0) {
|
||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Updating '" + plots.size() + "' plots!");
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(null, "&6Database update finished!");
|
||||
}
|
||||
});
|
||||
for (final Plot plot : plots) {
|
||||
PS.get().updatePlot(plot);
|
||||
}
|
||||
MainUtil.sendMessage(null, "&3Sign Block&8->&3PlotSquared&8: &7Complete!");
|
||||
} else {
|
||||
MainUtil.sendMessage(null, "No plots were found for the given search.");
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
|
||||
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.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class DebugClear extends SubCommand {
|
||||
public DebugClear() {
|
||||
super(Command.DEBUGCLEAR, "Clear a plot using a fast experimental algorithm", "debugclear", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
// Is console
|
||||
if (args.length < 2) {
|
||||
PS.log("You need to specify two arguments: ID (0;0) & World (world)");
|
||||
} else {
|
||||
final PlotId id = PlotId.fromString(args[0]);
|
||||
final String world = args[1];
|
||||
if (id == null) {
|
||||
PS.log("Invalid Plot ID: " + args[0]);
|
||||
} else {
|
||||
if (!PS.get().isPlotWorld(world) || !(PS.get().getPlotWorld(world) instanceof SquarePlotWorld)) {
|
||||
PS.log("Invalid plot world: " + world);
|
||||
} else {
|
||||
final Plot plot = MainUtil.getPlot(world, id);
|
||||
if (plot == null) {
|
||||
PS.log("Could not find plot " + args[0] + " in world " + world);
|
||||
} else {
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(null, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
PS.log("Plot " + plot.getId().toString() + " cleared.");
|
||||
PS.log("&aDone!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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 == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
|
||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
MainUtil.sendMessage(plr, "&aDone!");
|
||||
}
|
||||
});
|
||||
// sign
|
||||
// wall
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.OfflinePlotPlayer;
|
||||
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.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class DebugExec extends SubCommand {
|
||||
public DebugExec() {
|
||||
super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final List<String> allowed_params = Arrays.asList("analyze", "reset-modified", "stop-expire", "start-expire", "show-expired", "update-expired", "seen", "trim-check");
|
||||
if (args.length > 0) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
switch (arg) {
|
||||
case "analyze": {
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<Double> result = new ArrayList<>();
|
||||
result.add(Math.round(value.air * 100) / 100d);
|
||||
result.add(Math.round(value.changes * 100) / 100d);
|
||||
result.add(Math.round(value.complexity * 100) / 100d);
|
||||
result.add(Math.round(value.data * 100) / 100d);
|
||||
result.add(Math.round(value.faces * 100) / 100d);
|
||||
result.add(Math.round(value.air * 100) / 100d);
|
||||
result.add(Math.round(value.variety * 100) / 100d);
|
||||
Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
|
||||
FlagManager.addPlotFlag(plot, flag);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
case "stop-expire": {
|
||||
if (ExpireManager.task != -1) {
|
||||
Bukkit.getScheduler().cancelTask(ExpireManager.task);
|
||||
} else {
|
||||
return MainUtil.sendMessage(player, "Task already halted");
|
||||
}
|
||||
ExpireManager.task = -1;
|
||||
return MainUtil.sendMessage(player, "Cancelled task.");
|
||||
}
|
||||
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) {
|
||||
FlagManager.removePlotFlag(plot, flag);
|
||||
}
|
||||
}
|
||||
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
|
||||
}
|
||||
case "start-rgar": {
|
||||
if (args.length != 2) {
|
||||
PS.log("&cInvalid syntax: /plot debugexec start-rgar <world>");
|
||||
return false;
|
||||
}
|
||||
boolean result;
|
||||
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);
|
||||
}
|
||||
else {
|
||||
result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0);
|
||||
}
|
||||
if (!result) {
|
||||
PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "stop-rgar": {
|
||||
if (((BukkitHybridUtils)(HybridUtils.manager)).task == 0) {
|
||||
PS.log("&cTASK NOT RUNNING!");
|
||||
return false;
|
||||
}
|
||||
((BukkitHybridUtils)(HybridUtils.manager)).task = 0;
|
||||
Bukkit.getScheduler().cancelTask(((BukkitHybridUtils)(HybridUtils.manager)).task);
|
||||
PS.log("&cCancelling task...");
|
||||
while (BukkitHybridUtils.chunks.size() > 0) {
|
||||
ChunkLoc chunk = BukkitHybridUtils.chunks.get(0);
|
||||
BukkitHybridUtils.chunks.remove(0);
|
||||
HybridUtils.manager.regenerateRoad(BukkitHybridUtils.world, chunk, 0);
|
||||
ChunkManager.manager.unloadChunk(BukkitHybridUtils.world, chunk);
|
||||
}
|
||||
PS.log("&cCancelled!");
|
||||
return true;
|
||||
}
|
||||
case "start-expire": {
|
||||
if (ExpireManager.task == -1) {
|
||||
ExpireManager.runTask();
|
||||
} 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) {
|
||||
final String 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) {
|
||||
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]);
|
||||
}
|
||||
MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):");
|
||||
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>");
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[1]);
|
||||
if (uuid == null) {
|
||||
return MainUtil.sendMessage(player, "player not found: " + args[1]);
|
||||
}
|
||||
final OfflinePlotPlayer op = UUIDHandler.uuidWrapper.getOfflinePlayer(uuid);
|
||||
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]);
|
||||
MainUtil.sendMessage(player, "UUID: " + uuid);
|
||||
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
|
||||
MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
|
||||
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
|
||||
return true;
|
||||
}
|
||||
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]);
|
||||
}
|
||||
final ArrayList<ChunkLoc> empty = new ArrayList<>();
|
||||
final boolean result = Trim.getTrimRegions(empty, world, new Runnable() {
|
||||
@Override
|
||||
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 {
|
||||
writer = new PrintWriter(file);
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
Trim.sendMessage("File failed to save! :(");
|
||||
}
|
||||
Trim.sendMessage("How to get the chunk coords from a region file:");
|
||||
Trim.sendMessage(" - Locate the x,z values for the region file (the two numbers which are separated by a dot)");
|
||||
Trim.sendMessage(" - Multiply each number by 32; this gives you the starting position");
|
||||
Trim.sendMessage(" - Add 31 to each number to get the end position");
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, "Trim task already started!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, "Possible sub commands: /plot debugexec <" + StringUtils.join(allowed_params, "|") + ">");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SetBlockQueue;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class DebugFill extends SubCommand {
|
||||
public DebugFill() {
|
||||
super("fill", "plots.fill", "Fill or surround a plot in bedrock", "fill", "debugfill", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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 == null) || !plot.hasOwner()) {
|
||||
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
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)) {
|
||||
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
||||
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
||||
MainUtil.sendMessage(player, "&cPreparing task");
|
||||
MainUtil.runners.put(plot, 1);
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(player, "&7 - Starting");
|
||||
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 {
|
||||
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
|
||||
if (args.length == 3) {
|
||||
height = Integer.parseInt(args[2]);
|
||||
}
|
||||
}
|
||||
catch (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++) {
|
||||
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++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, air);
|
||||
}
|
||||
}
|
||||
}
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
MainUtil.sendMessage(player, "&aFill task complete!");
|
||||
}
|
||||
});
|
||||
}
|
||||
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++) {
|
||||
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++) {
|
||||
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++) {
|
||||
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++) {
|
||||
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
|
||||
}
|
||||
}
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
|
||||
bottom.setY(255);
|
||||
top.add(1,0,1);
|
||||
SetBlockQueue.setSlow(true);
|
||||
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
MainUtil.sendMessage(player, "&aFill task complete!");
|
||||
SetBlockQueue.setSlow(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class DebugFixFlags extends SubCommand {
|
||||
public DebugFixFlags() {
|
||||
super(Command.DEBUGFIXFLAGS, "Attempt to fix all flags for a world", "debugclear", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot debugfixflags <world>");
|
||||
return false;
|
||||
}
|
||||
final String world = args[0];
|
||||
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().getPlots(world).values()) {
|
||||
final HashMap<String, Flag> flags = plot.settings.flags;
|
||||
Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
|
||||
boolean changed = false;
|
||||
while (i.hasNext()) {
|
||||
if (FlagManager.getFlag(i.next().getKey()) == null) {
|
||||
changed = true;
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
DBFunc.setFlags(plot, plot.settings.flags.values());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, "&aDone!");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.lang.reflect.Field;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DebugLoadTest extends SubCommand {
|
||||
public DebugLoadTest() {
|
||||
super(Command.DEBUGLOADTEST, "This debug command will force the reload of all plots in the DB", "debugloadtest", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
try {
|
||||
final Field fPlots = PS.class.getDeclaredField("plots");
|
||||
fPlots.setAccessible(true);
|
||||
fPlots.set(null, DBFunc.getPlots());
|
||||
} catch (final Exception e) {
|
||||
PS.log("&3===FAILED&3===");
|
||||
e.printStackTrace();
|
||||
PS.log("&3===END OF STACKTRACE===");
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "&6This command can only be executed by console as it has been deemed unsafe if abused..");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class DebugRoadRegen extends SubCommand {
|
||||
public DebugRoadRegen() {
|
||||
super(Command.DEBUGROADREGEN, "Regenerate all road schematic in your current chunk", "debugroadregen", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Location loc = player.getLocation();
|
||||
final String world = loc.getWorld();
|
||||
if (!(PS.get().getPlotWorld(world) instanceof HybridPlotWorld)) {
|
||||
return sendMessage(player, C.NOT_IN_PLOT_WORLD);
|
||||
}
|
||||
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
|
||||
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, 0);
|
||||
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class DebugSaveTest extends SubCommand {
|
||||
public DebugSaveTest() {
|
||||
super(Command.DEBUGSAVETEST, "This debug command will force the recreation of all plots in the DB", "debugsavetest", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr == null) {
|
||||
final ArrayList<Plot> plots = new ArrayList<Plot>();
|
||||
plots.addAll(PS.get().getPlots());
|
||||
MainUtil.sendMessage(null, "&6Starting `DEBUGSAVETEST`");
|
||||
DBFunc.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(null, "&6Database sync finished!");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "This debug command can only be executed by console as it has been deemed unsafe if abused");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
|
||||
public class DebugSetup extends SubCommand {
|
||||
public DebugSetup() {
|
||||
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
public void displayGenerators(PlotPlayer plr) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("&6What generator do you want?");
|
||||
for (Entry<String, ChunkGenerator> entry : SetupUtils.generators.entrySet()) {
|
||||
if (entry.getKey().equals("PlotSquared")) {
|
||||
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof HybridGen) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof PlotGenerator) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
|
||||
}
|
||||
else {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
// going through setup
|
||||
String name;
|
||||
if (plr == null) {
|
||||
name = "*";
|
||||
}
|
||||
else {
|
||||
name = plr.getName();
|
||||
}
|
||||
if (!SetupUtils.setupMap.containsKey(name)) {
|
||||
final SetupObject object = new SetupObject();
|
||||
SetupUtils.setupMap.put(name, object);
|
||||
SetupUtils.manager.updateGenerators();
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
displayGenerators(plr);
|
||||
return false;
|
||||
}
|
||||
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")) {
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
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) {
|
||||
object.current--;
|
||||
}
|
||||
}
|
||||
}
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
final int index = object.current;
|
||||
switch (index) {
|
||||
case 0: { // choose plot manager // skip if 1 option
|
||||
}
|
||||
case 1: { // choose type (default, augmented, cluster)
|
||||
}
|
||||
case 2: { // Choose generator (vanilla, non plot generator) // skip if one option
|
||||
}
|
||||
case 3: { // world setup // skip if one option
|
||||
}
|
||||
case 4: { // world name
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,297 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
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;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.PlayerManager;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
|
||||
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
|
||||
|
||||
public class DebugUUID extends SubCommand {
|
||||
public DebugUUID() {
|
||||
super("uuidconvert", "plots.admin", "Debug uuid conversion", "debuguuid", "debuguuid", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
|
||||
UUIDWrapper currentUUIDWrapper = UUIDHandler.uuidWrapper;
|
||||
UUIDWrapper newWrapper = null;
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "lower": {
|
||||
newWrapper = new LowerOfflineUUIDWrapper();
|
||||
break;
|
||||
}
|
||||
case "offline": {
|
||||
newWrapper = new OfflineUUIDWrapper();
|
||||
break;
|
||||
}
|
||||
case "online": {
|
||||
newWrapper = new DefaultUUIDWrapper();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(args[0]);
|
||||
newWrapper = (UUIDWrapper) clazz.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot uuidconvert <lower|offline|online>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 - &cIf the process is interrupted, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
|
||||
MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
|
||||
MainUtil.sendMessage(player, "&cBACK UP YOUR DATABASE BEFORE USING THIS!!!");
|
||||
MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready");
|
||||
return false;
|
||||
}
|
||||
|
||||
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 user : UUIDHandler.players.values()) {
|
||||
PlayerManager.manager.kickPlayer(user, "PlotSquared UUID conversion has been initiated. You may reconnect when finished.");
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Initializing map");
|
||||
|
||||
HashMap<UUID, UUID> uCMap = new HashMap<UUID, UUID>();
|
||||
HashMap<UUID, UUID> uCReverse = new HashMap<UUID, UUID>();
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Collecting playerdata");
|
||||
|
||||
final HashSet<String> worlds = new HashSet<>();
|
||||
worlds.add(Bukkit.getWorlds().get(0).getName());
|
||||
worlds.add("world");
|
||||
final HashSet<UUID> uuids = new HashSet<>();
|
||||
final HashSet<String> names = new HashSet<>();
|
||||
for (final String worldname : worlds) {
|
||||
final File playerdataFolder = new File(worldname + File.separator + "playerdata");
|
||||
String[] dat = playerdataFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".dat");
|
||||
}
|
||||
});
|
||||
if (dat != null) {
|
||||
for (final String current : dat) {
|
||||
final String s = current.replaceAll(".dat$", "");
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(s);
|
||||
uuids.add(uuid);
|
||||
} catch (final Exception e) {
|
||||
PS.log(C.PREFIX.s() + "Invalid playerdata: " + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
final File playersFolder = new File(worldname + File.separator + "players");
|
||||
dat = playersFolder.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File f, final String s) {
|
||||
return s.endsWith(".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 {
|
||||
final OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
|
||||
uuid = currentUUIDWrapper.getUUID(op);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
PS.log(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat");
|
||||
}
|
||||
}
|
||||
for (final String name : names) {
|
||||
final UUID uuid = currentUUIDWrapper.getUUID(name);
|
||||
uuid2 = newWrapper.getUUID(name);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
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);
|
||||
uuid2 = newWrapper.getUUID(op);
|
||||
if (!uuid.equals(uuid2)) {
|
||||
uCMap.put(uuid, uuid2);
|
||||
uCReverse.put(uuid2, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uCMap.size() == 0) {
|
||||
MainUtil.sendConsoleMessage("&cError. Failed to collect UUIDs!");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendConsoleMessage("&a - Successfully repopulated");
|
||||
}
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Replacing cache");
|
||||
for (Entry<UUID, UUID> entry : uCMap.entrySet()) {
|
||||
String name = UUIDHandler.getName(entry.getKey());
|
||||
UUIDHandler.add(new StringWrapper(name), entry.getValue());
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Replacing wrapper");
|
||||
UUIDHandler.uuidWrapper = newWrapper;
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Updating plot objects");
|
||||
|
||||
for (Plot plot : PS.get().getPlotsRaw()) {
|
||||
UUID value = uCMap.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
plot.trusted = new ArrayList<>();
|
||||
plot.members = new ArrayList<>();
|
||||
plot.denied = new ArrayList<>();
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Deleting database");
|
||||
final AbstractDB database = DBFunc.dbManager;
|
||||
boolean result = database.deleteTables();
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Creating tables");
|
||||
|
||||
try {
|
||||
database.createTables(Settings.DB.USE_MYSQL ? "mysql" : "sqlite");
|
||||
if (!result) {
|
||||
MainUtil.sendConsoleMessage("&cConversion failed! Attempting recovery");
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
UUID value = uCReverse.get(plot.owner);
|
||||
if (value != null) {
|
||||
plot.owner = value;
|
||||
}
|
||||
}
|
||||
database.createPlotsAndData(new ArrayList<>(PS.get().getPlots()), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(null, "&6Recovery was successful!");
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newWrapper instanceof OfflineUUIDWrapper) {
|
||||
PS.get().config.set("UUID.force-lowercase", false);
|
||||
PS.get().config.set("UUID.offline", true);
|
||||
}
|
||||
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) {
|
||||
PS.get().config.set("UUID.force-lowercase", false);
|
||||
PS.get().config.set("UUID.offline", false);
|
||||
}
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
}
|
||||
catch (Exception e) {
|
||||
MainUtil.sendConsoleMessage("Could not save configuration. It will need to be manuall set!");
|
||||
}
|
||||
|
||||
MainUtil.sendConsoleMessage("&7 - Populating tables");
|
||||
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlots());
|
||||
database.createPlotsAndData(plots, new Runnable() {
|
||||
@Override
|
||||
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");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Delete extends SubCommand {
|
||||
public Delete() {
|
||||
super(Command.DELETE, "Delete a plot", "delete", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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 == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.uuidWrapper.getUUID(plr)))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
|
||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
EconHandler.manager.depositMoney(plr, c);
|
||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||
}
|
||||
}
|
||||
PS.get().removePlot(loc.getWorld(), plot.id, true);
|
||||
final long start = System.currentTimeMillis();
|
||||
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
});
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
DBFunc.delete(plot);
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Deny extends SubCommand {
|
||||
public Deny() {
|
||||
super(Command.DENY, "Deny a user from a plot", "deny <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot deny <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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
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("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[0]);
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.denied.contains(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
plot.removeMember(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.addDenied(uuid);
|
||||
EventUtil.manager.callDenied(plr, plot, uuid, true);
|
||||
MainUtil.sendMessage(plr, C.DENIED_ADDED);
|
||||
if (!uuid.equals(DBFunc.everyone)) {
|
||||
PS.get().IMP.handleKick(uuid, C.YOU_GOT_DENIED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Disable extends SubCommand {
|
||||
public static String downloads, version;
|
||||
|
||||
public Disable() {
|
||||
super("disable", "plots.admin", "Disable PlotSquared", "disable", "unload", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
PS.log("&cDisabling PlotSquared and all dependencies!");
|
||||
PS.get().IMP.disable();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import com.intellectualcrafters.jnbt.CompoundTag;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Download extends SubCommand {
|
||||
public Download() {
|
||||
super(Command.DOWNLOAD, "Download your plot", "dl", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, 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);
|
||||
}
|
||||
final Plot plot = MainUtil.getPlot(plr.getLocation());
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_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);
|
||||
final CompoundTag tag = SchematicHandler.manager.getCompoundTag(plot.world, plot.id);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
URL url = SchematicHandler.manager.upload(tag);
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(plr, C.GENERATING_LINK_FAILED);
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, url.toString());
|
||||
MainUtil.runners.remove(plot);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.flag.FlagValue;
|
||||
import com.intellectualcrafters.plot.listeners.APlotListener;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class FlagCmd extends SubCommand {
|
||||
public FlagCmd() {
|
||||
super(Command.FLAG, "Manage plot flags", "f", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
/*
|
||||
* plot flag set fly true
|
||||
* plot flag remove fly
|
||||
* plot flag remove use 1,3
|
||||
* plot flag add use 2,4
|
||||
* plot flag list
|
||||
*/
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(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])) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1]);
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag info <flag>");
|
||||
return false;
|
||||
}
|
||||
// flag key
|
||||
MainUtil.sendMessage(player, C.FLAG_KEY, af.getKey());
|
||||
// flag type
|
||||
MainUtil.sendMessage(player, C.FLAG_TYPE, af.value.getClass().getSimpleName());
|
||||
// Flag type description
|
||||
MainUtil.sendMessage(player, C.FLAG_DESC, af.getValueDesc());
|
||||
return true;
|
||||
}
|
||||
case "set": {
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed = af.parseValueRaw(value);
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||
APlotListener.manager.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
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)) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
|
||||
return false;
|
||||
}
|
||||
final AbstractFlag af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
if (af == null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final Flag flag = FlagManager.getPlotFlagAbs(plot, args[1].toLowerCase());
|
||||
if (flag == null) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
|
||||
DBFunc.setFlags(plot, plot.settings.flags.values());
|
||||
} else {
|
||||
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_REMOVED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FLAG_REMOVED);
|
||||
APlotListener.manager.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "add": {
|
||||
if (!Permissions.hasPermission(player, "plots.flag.add")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.add");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed = af.parseValueRaw(value);
|
||||
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()) {
|
||||
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
|
||||
} else {
|
||||
((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
|
||||
}
|
||||
final boolean result = FlagManager.addPlotFlag(plot, flag);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
DBFunc.setFlags(plot, plot.settings.flags.values());
|
||||
MainUtil.sendMessage(player, C.FLAG_ADDED);
|
||||
APlotListener.manager.plotEntry(player, plot);
|
||||
return true;
|
||||
}
|
||||
case "list": {
|
||||
if (!Permissions.hasPermission(player, "plots.flag.list")) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.flag.list");
|
||||
return false;
|
||||
}
|
||||
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()) {
|
||||
final String type = af.value.getClass().getSimpleName().replaceAll("Value", "");
|
||||
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()) {
|
||||
message += prefix + "&6" + flag + ": &7" + StringUtils.join(flags.get(flag), ", ");
|
||||
prefix = "\n";
|
||||
}
|
||||
MainUtil.sendMessage(player, message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag <set|remove|add|list|info>");
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
|
||||
* and/or monetize any of our intellectual property. IntellectualCrafters is not
|
||||
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
||||
*
|
||||
* >> File = Help.java >> Generated by: Citymonstret at 2014-08-11 17:32
|
||||
*/
|
||||
package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class Help extends SubCommand {
|
||||
public Help() {
|
||||
super("help", "", "Get this help menu", "help", "he", SubCommand.CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Home extends SubCommand {
|
||||
public Home() {
|
||||
super(Command.HOME, "Go to your plot", "home {id|alias}", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
private Plot isAlias(final String a) {
|
||||
for (final Plot p : PS.get().getPlots()) {
|
||||
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, String... args) {
|
||||
final ArrayList<Plot> plots = PS.get().sortPlotsByWorld(PS.get().getPlots(plr));
|
||||
if (plots.size() == 1) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
return true;
|
||||
} else if (plots.size() > 1) {
|
||||
if (args.length < 1) {
|
||||
args = new String[] { "1" };
|
||||
}
|
||||
int id = 0;
|
||||
try {
|
||||
id = Integer.parseInt(args[0]);
|
||||
} catch (final Exception e) {
|
||||
Plot temp;
|
||||
if ((temp = isAlias(args[0])) != null) {
|
||||
if (temp.hasOwner()) {
|
||||
if (temp.isOwner(plr.getUUID())) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.NOT_YOUR_PLOT);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_NUMBER, "(1, " + plots.size() + ")");
|
||||
return true;
|
||||
}
|
||||
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 {
|
||||
MainUtil.sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void teleportPlayer(final PlotPlayer player, final Plot plot) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), plot);
|
||||
}
|
||||
}
|
214
src/main/java/com/intellectualcrafters/plot/commands/Inbox.java
Normal file
214
src/main/java/com/intellectualcrafters/plot/commands/Inbox.java
Normal file
@ -0,0 +1,214 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentInbox;
|
||||
import com.intellectualcrafters.plot.object.comment.CommentManager;
|
||||
import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Inbox extends SubCommand {
|
||||
public Inbox() {
|
||||
super(Command.INBOX, "Review the comments for a plot", "inbox [inbox] [delete <index>|clear|page]", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public void displayComments(PlotPlayer player, 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) {
|
||||
page = 0;
|
||||
}
|
||||
// Get the total pages
|
||||
// int totalPages = ((int) Math.ceil(12 *
|
||||
final int totalPages = (int) Math.ceil(comments.length / 12);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
// Only display 12 per page
|
||||
int max = (page * 12) + 12;
|
||||
if (max > comments.length) {
|
||||
max = comments.length;
|
||||
}
|
||||
final StringBuilder string = new StringBuilder();
|
||||
string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("plot","comment").replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n");
|
||||
PlotComment c;
|
||||
// This might work xD
|
||||
for (int x = (page * 12); x < max; x++) {
|
||||
c = comments[x];
|
||||
String color;
|
||||
if (player.getName().equals(c.senderName)) {
|
||||
color = "&a";
|
||||
}
|
||||
else {
|
||||
color = "&7";
|
||||
}
|
||||
string.append("&8[&7#" + x + "&8][&7" + c.world + ";" + c.id + "&8][&6" + c.senderName + "&8]" + color + c.comment + "\n");
|
||||
}
|
||||
MainUtil.sendMessage(player, string.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
final Plot plot = MainUtil.getPlot(player.getLocation());
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (value != null) {
|
||||
int total = 0;
|
||||
int unread = 0;
|
||||
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||
total++;
|
||||
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
|
||||
unread++;
|
||||
}
|
||||
}
|
||||
if (total != 0) {
|
||||
String color;
|
||||
if (unread > 0) {
|
||||
color = "&c";
|
||||
}
|
||||
else {
|
||||
color = "";
|
||||
}
|
||||
sendMessage(player, C.INBOX_ITEM, color + inbox.toString() + " (" + total + "/" + unread + ")");
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
||||
}
|
||||
})) {
|
||||
sendMessage(player, C.INBOX_ITEM, inbox.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
final CommentInbox inbox = CommentManager.inboxes.get(args[0].toLowerCase());
|
||||
if (inbox == null) {
|
||||
sendMessage(player, C.INVALID_INBOX, StringUtils.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)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
if (args.length != 3) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||
}
|
||||
final int index;
|
||||
try {
|
||||
index = Integer.parseInt(args[2]);
|
||||
if (index < 1) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox " + inbox.toString() + " delete <index>");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlotComment> comments = (List<PlotComment>) value;
|
||||
if (index > comments.size()) {
|
||||
sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + "");
|
||||
}
|
||||
PlotComment comment = comments.get(index - 1);
|
||||
inbox.removeComment(plot, comment);
|
||||
plot.settings.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)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
|
||||
}
|
||||
inbox.clearInbox(plot);
|
||||
ArrayList<PlotComment> comments = plot.settings.getComments(inbox.toString());
|
||||
if (comments != null) {
|
||||
plot.settings.removeComments(comments);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
try {
|
||||
page = Integer.parseInt(args[1]) ;
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
page = 1;
|
||||
}
|
||||
if (!inbox.canRead(plot, player)) {
|
||||
sendMessage(player, C.NO_PERM_INBOX);
|
||||
return false;
|
||||
}
|
||||
if (!inbox.getComments(plot, new RunnableVal() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlotComment> comments = (List<PlotComment>) value;
|
||||
displayComments(player, comments, page);
|
||||
}
|
||||
})) {
|
||||
if (plot == null) {
|
||||
sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
else {
|
||||
sendMessage(player, C.PLOT_UNOWNED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
253
src/main/java/com/intellectualcrafters/plot/commands/Info.java
Normal file
253
src/main/java/com/intellectualcrafters/plot/commands/Info.java
Normal file
@ -0,0 +1,253 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "javadoc" })
|
||||
public class Info extends SubCommand {
|
||||
public Info() {
|
||||
super(Command.INFO, "Display plot info", "info", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
public static String getPlayerList(final Collection<UUID> uuids) {
|
||||
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()) {
|
||||
list.append(c.replace("%user%", getPlayerName(l.get(x))).replace(",", ""));
|
||||
} else {
|
||||
list.append(c.replace("%user%", getPlayerName(l.get(x))));
|
||||
}
|
||||
}
|
||||
return list.toString();
|
||||
}
|
||||
|
||||
public static String getPlayerName(final UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return "unknown";
|
||||
}
|
||||
if (uuid.equals(DBFunc.everyone) || uuid.toString().equalsIgnoreCase(DBFunc.everyone.toString())) {
|
||||
return "everyone";
|
||||
}
|
||||
final String name = UUIDHandler.getName(uuid);
|
||||
if (name == null) {
|
||||
return "unknown";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, String... args) {
|
||||
String arg = null;
|
||||
Plot plot;
|
||||
if (args.length > 0) arg = args[0] + "";
|
||||
if (arg != null) {
|
||||
switch (arg) {
|
||||
case "trusted":
|
||||
case "alias":
|
||||
case "inv":
|
||||
case "biome":
|
||||
case "denied":
|
||||
case "flags":
|
||||
case "id":
|
||||
case "size":
|
||||
case "members":
|
||||
case "owner":
|
||||
case "rating":
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
break;
|
||||
default:
|
||||
plot = MainUtil.getPlotFromString(player, arg, player == null);
|
||||
if (args.length == 2) {
|
||||
arg = args[1];
|
||||
}
|
||||
else {
|
||||
arg = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
}
|
||||
if (plot == null && arg != null) {
|
||||
plot = MainUtil.getPlotFromString(player, null, player == null);
|
||||
}
|
||||
if (plot == null) {
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (arg != null) {
|
||||
if (args.length == 1) {
|
||||
args = new String[0];
|
||||
}
|
||||
else {
|
||||
args = new String[] { args[1] };
|
||||
}
|
||||
}
|
||||
if ((args.length == 1) && args[0].equalsIgnoreCase("inv")) {
|
||||
new InfoInventory(plot, player).build().display();
|
||||
return true;
|
||||
}
|
||||
final boolean hasOwner = plot.hasOwner();
|
||||
boolean containsEveryone;
|
||||
boolean trustedEveryone;
|
||||
// Wildcard player {added}
|
||||
{
|
||||
containsEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone);
|
||||
trustedEveryone = (plot.members != null) && plot.members.contains(DBFunc.everyone);
|
||||
}
|
||||
// Unclaimed?
|
||||
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) {
|
||||
info = getCaption(arg);
|
||||
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 {
|
||||
formatAndSend(info, plot.world, plot, player, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String getCaption(final String string) {
|
||||
switch (string) {
|
||||
case "trusted":
|
||||
return C.PLOT_INFO_TRUSTED.s();
|
||||
case "alias":
|
||||
return C.PLOT_INFO_ALIAS.s();
|
||||
case "biome":
|
||||
return C.PLOT_INFO_BIOME.s();
|
||||
case "denied":
|
||||
return C.PLOT_INFO_DENIED.s();
|
||||
case "flags":
|
||||
return C.PLOT_INFO_FLAGS.s();
|
||||
case "id":
|
||||
return C.PLOT_INFO_ID.s();
|
||||
case "size":
|
||||
return C.PLOT_INFO_SIZE.s();
|
||||
case "members":
|
||||
return C.PLOT_INFO_MEMBERS.s();
|
||||
case "owner":
|
||||
return C.PLOT_INFO_OWNER.s();
|
||||
case "rating":
|
||||
return C.PLOT_INFO_RATING.s();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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.settings.getAlias().length() > 0 ? plot.settings.getAlias() : C.NONE.s();
|
||||
Location top = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1,0,1);
|
||||
final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2));
|
||||
final String trusted = getPlayerList(plot.trusted);
|
||||
final String members = getPlayerList(plot.members);
|
||||
final String denied = getPlayerList(plot.denied);
|
||||
|
||||
final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot).values(), "$1, $2") : C.NONE.s()), C.replacements);
|
||||
final boolean build = (player == null) || plot.isAdded(player.getUUID());
|
||||
|
||||
String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
|
||||
|
||||
info = info.replaceAll("%alias%", alias);
|
||||
info = info.replaceAll("%id%", id.toString());
|
||||
info = info.replaceAll("%id2%", id2.toString());
|
||||
info = info.replaceAll("%num%", num + "");
|
||||
info = info.replaceAll("%biome%", biome);
|
||||
info = info.replaceAll("%owner%", owner);
|
||||
info = info.replaceAll("%members%", members);
|
||||
info = info.replaceAll("%trusted%", trusted);
|
||||
info = info.replaceAll("%helpers%", members);
|
||||
info = info.replaceAll("%denied%", denied);
|
||||
info = info.replaceAll("%flags%", Matcher.quoteReplacement(flags));
|
||||
info = info.replaceAll("%build%", build + "");
|
||||
info = info.replaceAll("%desc%", "No description set.");
|
||||
if (info.contains("%rating%")) {
|
||||
final String newInfo = info;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
int max = 10;
|
||||
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) {
|
||||
String rating = "";
|
||||
String prefix = "";
|
||||
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 {
|
||||
info = newInfo.replaceAll("%rating%", String.format("%.1f", MainUtil.getAverageRating(plot)) + "/" + max);
|
||||
}
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||
MainUtil.sendMessage(player, info, false);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(player, C.PLOT_INFO_HEADER);
|
||||
MainUtil.sendMessage(player, info, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class Inventory extends SubCommand {
|
||||
public Inventory() {
|
||||
super("inventory", "plots.inventory", "Open a command inventory", "inventory", "inv", CommandCategory.INFO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final ArrayList<SubCommand> cmds = new ArrayList<>();
|
||||
for (final SubCommand cmd : MainCommand.subCommands) {
|
||||
if (cmd.permission.hasPermission(plr)) {
|
||||
cmds.add(cmd);
|
||||
}
|
||||
}
|
||||
final int size = 9 * (int) Math.ceil(cmds.size() / 9.0);
|
||||
final org.bukkit.inventory.Inventory inventory = Bukkit.createInventory(null, size, "PlotSquared Commands");
|
||||
for (final SubCommand cmd : cmds) {
|
||||
inventory.addItem(getItem(cmd));
|
||||
}
|
||||
((BukkitPlayer) plr).player.openInventory(inventory);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemStack getItem(final SubCommand cmd) {
|
||||
final ItemStack stack = new ItemStack(Material.COMMAND);
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
{
|
||||
meta.setDisplayName(ChatColor.GREEN + cmd.cmd + ChatColor.DARK_GRAY + " [" + ChatColor.GREEN + cmd.alias + ChatColor.DARK_GRAY + "]");
|
||||
meta.setLore(new ArrayList<String>() {
|
||||
{
|
||||
add(C.INVENTORY_CATEGORY.s().replace("{category}", cmd.category.toString()));
|
||||
add(C.INVENTORY_DESC.s().replace("{desc}", cmd.description));
|
||||
add(C.INVENTORY_USAGE.s().replace("{usage}", "/plot " + cmd.usage));
|
||||
}
|
||||
});
|
||||
}
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
@SuppressWarnings({ "unused", "deprecation", "javadoc" })
|
||||
public class Kick extends SubCommand {
|
||||
public Kick() {
|
||||
super(Command.KICK, "Kick a player from your plot", "kick", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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"))) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, "&c/plot kick <player>");
|
||||
return false;
|
||||
}
|
||||
final PlotPlayer player = UUIDHandler.getPlayer(args[0]);
|
||||
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))) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
player.teleport(BlockManager.manager.getSpawn(loc.getWorld()));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
|
||||
/**
|
||||
* PlotSquared command class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class MainCommand {
|
||||
/**
|
||||
* Main Permission Node
|
||||
*/
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { };
|
||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||
{
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
}
|
||||
};
|
||||
|
||||
public static boolean no_permission(final PlotPlayer player, final String permission) {
|
||||
MainUtil.sendMessage(player, C.NO_PERMISSION, permission);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final PlotPlayer player) {
|
||||
final List<SubCommand> cmds = new ArrayList<>();
|
||||
for (final SubCommand c : subCommands) {
|
||||
if (!c.isPlayer || (player != null)) {
|
||||
if ((c.category.equals(category)) && c.permission.hasPermission(player)) {
|
||||
cmds.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public static List<String> helpMenu(final PlotPlayer player, final SubCommand.CommandCategory category, int page) {
|
||||
List<SubCommand> commands;
|
||||
if (category != null) {
|
||||
commands = getCommands(category, player);
|
||||
} else {
|
||||
commands = subCommands;
|
||||
}
|
||||
// final int totalPages = ((int) Math.ceil(12 * (commands.size()) /
|
||||
// 100));
|
||||
final int perPage = 5;
|
||||
final int totalPages = (commands.size() / perPage) + (commands.size() % perPage == 0 ? 0 : 1);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
int max = (page * perPage) + perPage;
|
||||
if (max > commands.size()) {
|
||||
max = commands.size();
|
||||
}
|
||||
final List<String> help = new ArrayList<>();
|
||||
help.add(C.HELP_HEADER.s());
|
||||
// HELP_CATEGORY("&cCategory: &6%category%&c, Page: %current%&c/&6%max%&c, Displaying: &6%dis%&c/&6%total%"),
|
||||
help.add(C.HELP_CATEGORY.s().replace("%category%", category == null ? "All" : category.toString()).replace("%current%", "" + (page + 1)).replace("%max%", "" + (totalPages)).replace("%dis%", "" + (commands.size() % perPage)).replace("%total%", "" + commands.size()));
|
||||
SubCommand cmd;
|
||||
final int start = page * perPage;
|
||||
for (int x = start; x < max; x++) {
|
||||
cmd = commands.get(x);
|
||||
String s = t(C.HELP_ITEM.s());
|
||||
if (cmd.alias.size() > 0) {
|
||||
s = s.replace("%alias%", cmd.alias.get(0));
|
||||
}
|
||||
else {
|
||||
s = s.replace("%alias%", "");
|
||||
}
|
||||
s = s.replace("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage).replace("%cmd%", cmd.cmd).replace("%desc%", cmd.description).replace("[]", "");
|
||||
help.add(s);
|
||||
}
|
||||
if (help.size() < 2) {
|
||||
help.add(t(C.NO_COMMANDS.s()));
|
||||
}
|
||||
return help;
|
||||
}
|
||||
|
||||
private static String t(final String s) {
|
||||
return MainUtil.colorise('&', s);
|
||||
}
|
||||
|
||||
public static boolean onCommand(final PlotPlayer player, final String cmd, final String... args) {
|
||||
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||
if (args.length < 2) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all").replaceAll("%category_desc%", "Display all commands"));
|
||||
return MainUtil.sendMessage(player, builder.toString());
|
||||
}
|
||||
final String cat = args[1];
|
||||
SubCommand.CommandCategory cato = null;
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
if (cat.equalsIgnoreCase(category.toString())) {
|
||||
cato = category;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((cato == null) && !cat.equalsIgnoreCase("all")) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(C.HELP_INFO.s());
|
||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||
}
|
||||
return MainUtil.sendMessage(player, builder.toString(), false);
|
||||
}
|
||||
final StringBuilder help = new StringBuilder();
|
||||
int page = 0;
|
||||
boolean digit = true;
|
||||
String arg2;
|
||||
if (args.length > 2) {
|
||||
arg2 = args[2];
|
||||
} else {
|
||||
arg2 = "1";
|
||||
}
|
||||
for (final char c : arg2.toCharArray()) {
|
||||
if (!Character.isDigit(c)) {
|
||||
digit = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (digit) {
|
||||
page = Integer.parseInt(arg2);
|
||||
if (--page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
for (final String string : helpMenu(player, cato, page)) {
|
||||
help.append(string).append("\n");
|
||||
}
|
||||
MainUtil.sendMessage(player, help.toString());
|
||||
// return PlayerFunctions.sendMessage(player, help.toString());
|
||||
} else {
|
||||
for (final SubCommand command : subCommands) {
|
||||
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.contains(args[0].toLowerCase())) {
|
||||
final String[] arguments = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, arguments, 0, args.length - 1);
|
||||
if (command.permission.hasPermission(player)) {
|
||||
if ((player != null) || !command.isPlayer) {
|
||||
return command.execute(player, arguments);
|
||||
} else {
|
||||
return !MainUtil.sendMessage(null, C.IS_CONSOLE);
|
||||
}
|
||||
} else {
|
||||
return no_permission(player, command.permission.permission.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
||||
final String[] commands = new String[subCommands.size()];
|
||||
for (int x = 0; x < subCommands.size(); x++) {
|
||||
commands[x] = subCommands.get(x).cmd;
|
||||
}
|
||||
/* Let's try to get a proper usage string */
|
||||
final String command = new StringComparison(args[0], commands).getBestMatch();
|
||||
return MainUtil.sendMessage(player, C.DID_YOU_MEAN, "/plot " + command);
|
||||
// PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new
|
||||
// StringComparsion(args[0], commands).getBestMatch());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
231
src/main/java/com/intellectualcrafters/plot/commands/Merge.java
Normal file
231
src/main/java/com/intellectualcrafters/plot/commands/Merge.java
Normal file
@ -0,0 +1,231 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
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 Merge() {
|
||||
super(Command.MERGE, "Merge the plot you are standing on with another plot.", "merge", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public static String direction(float yaw) {
|
||||
yaw = yaw / 90;
|
||||
final int i = Math.round(yaw);
|
||||
switch (i) {
|
||||
case -4:
|
||||
case 0:
|
||||
case 4:
|
||||
return "SOUTH";
|
||||
case -1:
|
||||
case 3:
|
||||
return "EAST";
|
||||
case -2:
|
||||
case 2:
|
||||
return "NORTH";
|
||||
case -3:
|
||||
case 1:
|
||||
return "WEST";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
final boolean admin = Permissions.hasPermission(plr, "plots.admin.command.merge");
|
||||
if (!plot.isOwner(plr.getUUID()) && !admin) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
|
||||
return false;
|
||||
}
|
||||
int direction = -1;
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringUtils.join(values, C.BLOCK_LIST_SEPARATER.s()));
|
||||
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
|
||||
return false;
|
||||
}
|
||||
PlotId bot = MainUtil.getBottomPlot(plot).id;
|
||||
PlotId top = MainUtil.getTopPlot(plot).id;
|
||||
ArrayList<PlotId> selPlots;
|
||||
final String world = loc.getWorld();
|
||||
switch (direction) {
|
||||
case 0: // north = -y
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
||||
break;
|
||||
case 1: // east = +x
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
||||
break;
|
||||
case 2: // south = +y
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
||||
break;
|
||||
case 3: // west = -x
|
||||
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
final PlotId botId = selPlots.get(0);
|
||||
final PlotId topId = selPlots.get(selPlots.size() - 1);
|
||||
final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
|
||||
final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
|
||||
final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
|
||||
final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
|
||||
bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
|
||||
top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
|
||||
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 UUID u1 = plot.owner;
|
||||
for (final PlotId myid : plots) {
|
||||
final Plot myplot = PS.get().getPlots(world).get(myid);
|
||||
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)) {
|
||||
continue;
|
||||
}
|
||||
PlotPlayer p2 = UUIDHandler.getPlayer(u2);
|
||||
if (p2 == null) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
|
||||
return false;
|
||||
}
|
||||
multiMerge = true;
|
||||
multiPlots.add(myid);
|
||||
multiUUID.add(u2);
|
||||
}
|
||||
if (multiMerge) {
|
||||
if (!Permissions.hasPermission(plr, Permissions.MERGE_OTHER)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, Permissions.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() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
|
||||
multiUUID.remove(uuid);
|
||||
if (multiUUID.size() == 0) {
|
||||
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) {
|
||||
double cost = plotWorld.MERGE_PRICE;
|
||||
cost = plots.size() * cost;
|
||||
if (cost > 0d) {
|
||||
if (EconHandler.manager.getMoney(plr) < cost) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||
return;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
|
||||
MainUtil.mergePlots(world, plots, true);
|
||||
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
||||
}
|
||||
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
|
||||
}
|
||||
});
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.MERGE_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
|
||||
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) {
|
||||
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
|
||||
return false;
|
||||
}
|
||||
EconHandler.manager.withdrawMoney(plr, cost);
|
||||
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
|
||||
}
|
||||
}
|
||||
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
|
||||
MainUtil.mergePlots(world, plots, true);
|
||||
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Move extends SubCommand {
|
||||
public Move() {
|
||||
super(Command.MOVE, "Move a plot", "debugmove", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
|
||||
return false;
|
||||
}
|
||||
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()) && !plr.hasPermission(Permissions.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)) {
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE);
|
||||
return false;
|
||||
}
|
||||
world2 = other.worldname;
|
||||
}
|
||||
else {
|
||||
world2 = world;
|
||||
}
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
|
||||
}
|
||||
})) {
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.listeners.PlotListener;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotBlock;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class MusicSubcommand extends SubCommand {
|
||||
public MusicSubcommand() {
|
||||
super("music", "plots.music", "Play music in plot", "music", "mus", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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())) {
|
||||
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);
|
||||
int id = item.id == 7 ? 0 : item.id;
|
||||
if (id == 0) {
|
||||
FlagManager.removePlotFlag(plot, "music");
|
||||
}
|
||||
else {
|
||||
FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("music"), id));
|
||||
}
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlotListener.manager.plotEntry(player, plot);
|
||||
}
|
||||
}, 1);
|
||||
close();
|
||||
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);
|
||||
inv.setItem(index, item);
|
||||
index++;
|
||||
}
|
||||
if (player.getMeta("music") != null) {
|
||||
String name = "&r&6Cancel music";
|
||||
String[] lore = {"&r&cClick to cancel!"};
|
||||
inv.setItem(index, new PlotItemStack(7, (short) 0, 1, name, lore));
|
||||
}
|
||||
inv.openInventory();
|
||||
return true;
|
||||
}
|
||||
}
|
170
src/main/java/com/intellectualcrafters/plot/commands/Purge.java
Normal file
170
src/main/java/com/intellectualcrafters/plot/commands/Purge.java
Normal file
@ -0,0 +1,170 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
@SuppressWarnings({ "javadoc" })
|
||||
public class Purge extends SubCommand {
|
||||
public Purge() {
|
||||
super("purge", "plots.admin", "Purge all plots for a world", "purge", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
MainUtil.sendMessage(plr, "/plot purge x;z &l<world>");
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("player")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge &l<player> <world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("unowned")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge unowned &l<world>");
|
||||
return false;
|
||||
}
|
||||
if (arg.equals("unknown")) {
|
||||
MainUtil.sendMessage(plr, "/plot purge unknown &l<world>");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String worldname = args[1];
|
||||
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) {
|
||||
final HashSet<Integer> ids = new HashSet<Integer>();
|
||||
final int DBid = DBFunc.getId(worldname, id);
|
||||
if (DBid != Integer.MAX_VALUE) {
|
||||
ids.add(DBid);
|
||||
}
|
||||
DBFunc.purgeIds(worldname, ids);
|
||||
return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0);
|
||||
}
|
||||
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");
|
||||
}
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
if (arg.equals("unknown")) {
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
if (plot.owner != null) {
|
||||
final String name = UUIDHandler.getName(plot.owner);
|
||||
if (name == null) {
|
||||
ids.add(plot.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
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")) {
|
||||
final Collection<Plot> plots = PS.get().getPlots(worldname).values();
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
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");
|
||||
}
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
final UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
final Set<Plot> plots = PS.get().getPlots(worldname, uuid);
|
||||
final Set<PlotId> ids = new HashSet<>();
|
||||
for (final Plot plot : plots) {
|
||||
ids.add(plot.id);
|
||||
}
|
||||
int length = ids.size();
|
||||
DBFunc.purge(worldname, ids);
|
||||
return finishPurge(length);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean finishPurge(final int amount) {
|
||||
MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + "");
|
||||
return false;
|
||||
}
|
||||
}
|
212
src/main/java/com/intellectualcrafters/plot/commands/Rate.java
Normal file
212
src/main/java/com/intellectualcrafters/plot/commands/Rate.java
Normal file
@ -0,0 +1,212 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.events.PlotRateEvent;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
|
||||
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.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotInventory;
|
||||
import com.intellectualcrafters.plot.object.PlotItemStack;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Rate extends SubCommand {
|
||||
/*
|
||||
* String cmd, String permission, String description, String usage, String
|
||||
* alias, CommandCategory category
|
||||
*/
|
||||
public Rate() {
|
||||
super("rate", "plots.rate", "Rate the plot", "rate [#|next]", "rt", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
if (p1.settings.ratings != null) {
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
v1 -= 11 - entry.getValue().getAverageRating();
|
||||
}
|
||||
}
|
||||
if (p2.settings.ratings != null) {
|
||||
for (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 (p.settings.ratings == null || !p.settings.ratings.containsKey(uuid)) {
|
||||
MainUtil.teleportPlayer(player, player.getLocation(), p);
|
||||
MainUtil.sendMessage(player, C.RATE_THIS);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(player, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final Location loc = player.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, C.RATING_NOT_OWNED);
|
||||
return true;
|
||||
}
|
||||
if (plot.isOwner(player.getUUID())) {
|
||||
sendMessage(player, C.RATING_NOT_YOUR_OWN);
|
||||
return true;
|
||||
}
|
||||
if (Settings.RATING_CATEGORIES != null && Settings.RATING_CATEGORIES.size() != 0) {
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.settings.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) {
|
||||
rating.add((i + 1) * Math.pow(10, index.intValue()));
|
||||
index.increment();
|
||||
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
|
||||
close();
|
||||
// handle ratings
|
||||
int rV = rating.intValue();
|
||||
// CALL THE EVENT
|
||||
PlotRateEvent rateEvent = new PlotRateEvent(player, rV, plot);
|
||||
Bukkit.getPluginManager().callEvent(rateEvent);
|
||||
// DONE CALLING THE EVENT
|
||||
// get new rating
|
||||
rV = rateEvent.getRating();
|
||||
// set rating
|
||||
plot.settings.ratings.put(player.getUUID(), rV);
|
||||
DBFunc.setRating(plot, player.getUUID(), rV);
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
return false;
|
||||
}
|
||||
setTitle(Settings.RATING_CATEGORIES.get(index.intValue()));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
inventory.setItem(0, new PlotItemStack(35, (short) 12, 0, "0/8", null));
|
||||
inventory.setItem(1, new PlotItemStack(35, (short) 14, 1, "1/8", null));
|
||||
inventory.setItem(2, new PlotItemStack(35, (short) 1, 2, "2/8", null));
|
||||
inventory.setItem(3, new PlotItemStack(35, (short) 4, 3, "3/8", null));
|
||||
inventory.setItem(4, new PlotItemStack(35, (short) 5, 4, "4/8", null));
|
||||
inventory.setItem(5, new PlotItemStack(35, (short) 9, 5, "5/8", null));
|
||||
inventory.setItem(6, new PlotItemStack(35, (short) 11, 6, "6/8", null));
|
||||
inventory.setItem(7, new PlotItemStack(35, (short) 10, 7, "7/8", null));
|
||||
inventory.setItem(8, new PlotItemStack(35, (short) 2, 8, "8/8", null));
|
||||
inventory.openInventory();
|
||||
}
|
||||
};
|
||||
if (plot.settings.ratings == null) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plot.settings.ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
run.run();
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return true;
|
||||
}
|
||||
final String arg = args[0];
|
||||
|
||||
if (arg.equalsIgnoreCase("next")) {
|
||||
|
||||
}
|
||||
final int rating;
|
||||
if (StringUtils.isNumeric(arg) && arg.length() < 3 && arg.length() > 0) {
|
||||
rating = Integer.parseInt(arg);
|
||||
if (rating > 10) {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendMessage(player, C.RATING_NOT_VALID);
|
||||
return false;
|
||||
}
|
||||
final UUID uuid = player.getUUID();
|
||||
final Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (plot.settings.ratings.containsKey(uuid)) {
|
||||
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
|
||||
return;
|
||||
}
|
||||
plot.settings.ratings.put(uuid, rating);
|
||||
DBFunc.setRating(plot, uuid, rating);
|
||||
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
|
||||
}
|
||||
};
|
||||
if (plot.settings.ratings == null) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
plot.settings.ratings = DBFunc.getRatings(plot);
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
run.run();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.List;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.generator.HybridPlotManager;
|
||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
|
||||
public class RegenAllRoads extends SubCommand {
|
||||
public RegenAllRoads() {
|
||||
super(Command.REGENALLROADS, "Regenerate all roads in the map using the set road schematic", "rgar", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (player != null) {
|
||||
sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
sendMessage(player, C.NEED_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
int height = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
height = Integer.parseInt(args[1]);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
sendMessage(player, C.NOT_VALID_NUMBER, "(0, 256)");
|
||||
sendMessage(player, C.COMMAND_SYNTAX, "/plot regenallroads <world> [height]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final String name = args[0];
|
||||
final PlotManager manager = PS.get().getPlotManager(name);
|
||||
if ((manager == null) || !(manager instanceof HybridPlotManager)) {
|
||||
sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
|
||||
PS.log("&cIf no schematic is set, the following will not do anything");
|
||||
PS.log("&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
|
||||
PS.log("&6Potential chunks to update: &7" + (chunks.size() * 1024));
|
||||
PS.log("&6Estimated time: &7" + (chunks.size()) + " seconds");
|
||||
final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height);
|
||||
if (!result) {
|
||||
PS.log("&cCannot schedule mass schematic update! (Is one already in progress?)");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Reload extends SubCommand {
|
||||
public Reload() {
|
||||
super("reload", "plots.admin.command.reload", "Reload configurations", "reload", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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()) {
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(pw);
|
||||
plotworld.loadDefaultConfiguration(PS.get().config.getConfigurationSection("worlds." + pw));
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.RELOADED_CONFIGS);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(plr, C.RELOAD_FAILED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
123
src/main/java/com/intellectualcrafters/plot/commands/Remove.java
Normal file
123
src/main/java/com/intellectualcrafters/plot/commands/Remove.java
Normal file
@ -0,0 +1,123 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Remove extends SubCommand {
|
||||
public Remove() {
|
||||
super(Command.REMOVE, "Remove a player from a plot", "remove <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.remove")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.members);
|
||||
all.addAll(plot.trusted);
|
||||
all.addAll(plot.denied);
|
||||
for (UUID uuid : all) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
HashSet<UUID> all = new HashSet<>();
|
||||
all.addAll(plot.members);
|
||||
all.addAll(plot.trusted);
|
||||
all.addAll(plot.denied);
|
||||
for (UUID uuid : all) {
|
||||
toRemove.add(uuid);
|
||||
count++;
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
plot.removeTrusted(uuid);
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.trusted.contains(uuid)) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (plot.members.contains(uuid)) {
|
||||
if (plot.removeMember(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (plot.denied.contains(uuid)) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,297 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.DataCollection;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Dimension;
|
||||
import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
|
||||
public class SchematicCmd extends SubCommand {
|
||||
private int counter = 0;
|
||||
private boolean running = false;
|
||||
private int task;
|
||||
|
||||
public SchematicCmd() {
|
||||
super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false);
|
||||
// TODO command to fetch schematic from worldedit directory
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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 (plr == null) {
|
||||
PS.log(C.IS_CONSOLE.s());
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.paste")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.paste");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
final String file2 = args[1];
|
||||
this.running = true;
|
||||
this.counter = 0;
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Schematic schematic = SchematicHandler.manager.getSchematic(file2);
|
||||
if (schematic == null) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent or not in gzip format");
|
||||
SchematicCmd.this.running = false;
|
||||
return;
|
||||
}
|
||||
final int x;
|
||||
final int z;
|
||||
final Plot plot2 = MainUtil.getPlot(loc);
|
||||
final Dimension dem = schematic.getSchematicDimension();
|
||||
final Location bot = MainUtil.getPlotBottomLoc(loc.getWorld(), plot2.id).add(1, 0, 1);
|
||||
final int length2 = MainUtil.getPlotWidth(loc.getWorld(), plot2.id);
|
||||
if ((dem.getX() > length2) || (dem.getZ() > length2)) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", dem.getX(), dem.getZ(), length2));
|
||||
SchematicCmd.this.running = false;
|
||||
return;
|
||||
}
|
||||
if ((dem.getX() != length2) || (dem.getZ() != length2)) {
|
||||
final Location loc = plr.getLocation();
|
||||
x = Math.min(length2 - dem.getX(), loc.getX() - bot.getX());
|
||||
z = Math.min(length2 - dem.getZ(), loc.getZ() - bot.getZ());
|
||||
} else {
|
||||
x = 0;
|
||||
z = 0;
|
||||
}
|
||||
final DataCollection[] b = schematic.getBlockCollection();
|
||||
final int sy = BlockManager.manager.getHeighestBlock(bot);
|
||||
final int WIDTH = schematic.getSchematicDimension().getX();
|
||||
final int LENGTH = schematic.getSchematicDimension().getZ();
|
||||
final Location l1;
|
||||
if (!(schematic.getSchematicDimension().getY() == BukkitUtil.getMaxHeight(loc.getWorld()))) {
|
||||
l1 = bot.add(0, sy - 1, 0);
|
||||
}
|
||||
else {
|
||||
l1 = bot;
|
||||
}
|
||||
|
||||
final int blen = b.length - 1;
|
||||
SchematicCmd.this.task = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean result = false;
|
||||
while (!result) {
|
||||
final int start = SchematicCmd.this.counter * 5000;
|
||||
if (start > blen) {
|
||||
SchematicHandler.manager.pasteStates(schematic, plot, 0, 0);
|
||||
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
|
||||
SchematicCmd.this.running = false;
|
||||
PS.get().TASK.cancelTask(SchematicCmd.this.task);
|
||||
return;
|
||||
}
|
||||
final int end = Math.min(start + 5000, blen);
|
||||
result = SchematicHandler.manager.pastePart(loc.getWorld(), b, l1, x, z, start, end, WIDTH, LENGTH);
|
||||
SchematicCmd.this.counter++;
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
SchematicCmd.this.running = false;
|
||||
MainUtil.sendMessage(plr, "&cAn error occured, see console for more information");
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "test": {
|
||||
if (plr == null) {
|
||||
PS.log(C.IS_CONSOLE.s());
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
file = args[1];
|
||||
schematic = SchematicHandler.manager.getSchematic(file);
|
||||
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)) {
|
||||
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
|
||||
break;
|
||||
}
|
||||
sendMessage(plr, C.SCHEMATIC_VALID);
|
||||
break;
|
||||
}
|
||||
case "saveall":
|
||||
case "exportall": {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
final HashMap<PlotId, Plot> plotmap = PS.get().getPlots(args[1]);
|
||||
if ((plotmap == null) || (plotmap.size() == 0)) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall <world>");
|
||||
return false;
|
||||
}
|
||||
Collection<Plot> plots = plotmap.values();
|
||||
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 {
|
||||
PS.log("&3PlotSquared&8->&3Schemaitc&8: &7Mass export has started. This may take a while.");
|
||||
PS.log("&3PlotSquared&8->&3Schemaitc&8: &7Found &c" + plotmap.size() + "&7 plots...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "export":
|
||||
case "save": {
|
||||
if (!Permissions.hasPermission(plr, "plots.schematic.save")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.save");
|
||||
return false;
|
||||
}
|
||||
if (this.running) {
|
||||
MainUtil.sendMessage(plr, "&cTask is already running.");
|
||||
return false;
|
||||
}
|
||||
final String world;
|
||||
final Plot p2;
|
||||
if (plr != null) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if (plot == null) {
|
||||
return !sendMessage(plr, C.NOT_IN_PLOT);
|
||||
}
|
||||
if (!plot.isAdded(plr.getUUID())) {
|
||||
sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return false;
|
||||
}
|
||||
p2 = plot;
|
||||
world = loc.getWorld();
|
||||
} else {
|
||||
if (args.length == 3) {
|
||||
try {
|
||||
world = args[1];
|
||||
final String[] split = args[2].split(";");
|
||||
final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
|
||||
if ((PS.get().getPlots(world) == null) || (PS.get().getPlots(world).get(i) == null)) {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
p2 = PS.get().getPlots(world).get(i);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save <world> <id>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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.");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&7Starting export...");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
335
src/main/java/com/intellectualcrafters/plot/commands/Set.java
Normal file
335
src/main/java/com/intellectualcrafters/plot/commands/Set.java
Normal file
@ -0,0 +1,335 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Configuration;
|
||||
import com.intellectualcrafters.plot.flag.AbstractFlag;
|
||||
import com.intellectualcrafters.plot.flag.Flag;
|
||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||
import com.intellectualcrafters.plot.listeners.APlotListener;
|
||||
import com.intellectualcrafters.plot.object.*;
|
||||
import com.intellectualcrafters.plot.util.*;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
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" };
|
||||
|
||||
public Set() {
|
||||
super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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()) {
|
||||
sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(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>();
|
||||
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])) {
|
||||
args[0] = values[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("flag")) {
|
||||
if (args.length < 2) {
|
||||
final String message = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getFlags(plr), "$1, $2")), C.replacements);
|
||||
// final String message = StringUtils.join(FlagManager.getFlags(plr), "&c, &6");
|
||||
MainUtil.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", message));
|
||||
return false;
|
||||
}
|
||||
AbstractFlag af;
|
||||
try {
|
||||
af = FlagManager.getFlag(args[1].toLowerCase());
|
||||
} catch (final Exception e) {
|
||||
af = new AbstractFlag(args[1].toLowerCase());
|
||||
}
|
||||
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())) {
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
final boolean result = FlagManager.removePlotFlag(plot, args[1].toLowerCase());
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_REMOVED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.FLAG_REMOVED);
|
||||
APlotListener.manager.plotEntry(plr, plot);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
|
||||
final Object parsed_value = af.parseValueRaw(value);
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.FLAG_NOT_ADDED);
|
||||
return false;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.FLAG_ADDED);
|
||||
APlotListener.manager.plotEntry(plr, plot);
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(plr, "&c" + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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")) {
|
||||
plot.setHome(null);
|
||||
return true;
|
||||
}
|
||||
return MainUtil.sendMessage(plr, C.HOME_ARGUMENT);
|
||||
}
|
||||
//set to current location
|
||||
final String world = plr.getLocation().getWorld();
|
||||
final Location base = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||
base.setY(0);
|
||||
final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ());
|
||||
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ(), relative.getYaw(), relative.getPitch());
|
||||
plot.setHome(blockloc);
|
||||
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.MISSING_ALIAS);
|
||||
return false;
|
||||
}
|
||||
final String alias = args[1];
|
||||
if (alias.length() >= 50) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_TOO_LONG);
|
||||
return false;
|
||||
}
|
||||
for (final Plot p : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
|
||||
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
if (UUIDHandler.nameExists(new StringWrapper(alias))) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
plot.setAlias(alias);
|
||||
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")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.biome");
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(plr, C.NEED_BIOME);
|
||||
return true;
|
||||
}
|
||||
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]);
|
||||
/*
|
||||
* for (Biome b : Biome.values()) {
|
||||
* if (b.toString().equalsIgnoreCase(args[1])) {
|
||||
* biome = b;
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
if (biome == -1) {
|
||||
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
|
||||
return true;
|
||||
}
|
||||
plot.setBiome(args[1].toUpperCase());
|
||||
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
|
||||
return true;
|
||||
}
|
||||
// Get components
|
||||
final String world = plr.getLocation().getWorld();
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
||||
final PlotManager manager = PS.get().getPlotManager(world);
|
||||
final String[] components = manager.getPlotComponents(plotworld, plot.id);
|
||||
|
||||
boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID());
|
||||
|
||||
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);
|
||||
}
|
||||
PlotBlock[] blocks;
|
||||
try {
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(plr, C.NEED_BLOCK);
|
||||
return true;
|
||||
}
|
||||
String[] split = args[1].split(",");
|
||||
blocks = Configuration.BLOCKLIST.parseString(args[1]);
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
PlotBlock block = blocks[i];
|
||||
if (block == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, split[i]);
|
||||
String name;
|
||||
if (split[i].contains("%")) {
|
||||
name = split[i].split("%")[1];
|
||||
}
|
||||
else {
|
||||
name = split[i];
|
||||
}
|
||||
StringComparison<PlotBlock>.ComparisonResult match = BlockManager.manager.getClosestBlock(name);
|
||||
if (match != null) {
|
||||
name = BlockManager.manager.getClosestMatchingName(match.best);
|
||||
if (name != null) {
|
||||
MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!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)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final Exception e2) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, args[1]);
|
||||
return false;
|
||||
}
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
MainUtil.runners.put(plot, 1);
|
||||
manager.setComponent(plotworld, plot.id, component, blocks);
|
||||
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
|
||||
SetBlockQueue.addNotify(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.runners.remove(plot);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
{
|
||||
AbstractFlag af;
|
||||
try {
|
||||
af = new AbstractFlag(args[0].toLowerCase());
|
||||
} catch (final Exception e) {
|
||||
af = new AbstractFlag("");
|
||||
}
|
||||
if (FlagManager.getFlags().contains(af)) {
|
||||
final StringBuilder a = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int x = 1; x < args.length; x++) {
|
||||
a.append(" ").append(args[x]);
|
||||
}
|
||||
}
|
||||
MainCommand.onCommand(plr, world, ("plot set flag " + args[0] + a.toString()).split(" "));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
return MainUtil.colorise('&', C.BLOCK_LIST_ITEM.s().replaceAll("%mat%", s));
|
||||
}
|
||||
|
||||
private String getArgumentList(final List<String> newValues) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final String s : newValues) {
|
||||
builder.append(getString(s));
|
||||
}
|
||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||
}
|
||||
|
||||
private String getBiomeList(final String[] biomes) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append(MainUtil.colorise('&', C.NEED_BIOME.s()));
|
||||
for (final String b : biomes) {
|
||||
builder.append(getString(b));
|
||||
}
|
||||
return builder.toString().substring(1, builder.toString().length() - 1);
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
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.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class SetOwner extends SubCommand {
|
||||
public SetOwner() {
|
||||
super("setowner", "plots.set.owner", "Set the plot owner", "setowner <player>", "so", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* private UUID getUUID(String string) { OfflinePlayer player =
|
||||
* Bukkit.getOfflinePlayer(string); return ((player != null) &&
|
||||
* player.hasPlayedBefore()) ? UUIDHandler.getUUID(player) : null; }
|
||||
*/
|
||||
private UUID getUUID(final String string) {
|
||||
return UUIDHandler.getUUID(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location loc = plr.getLocation();
|
||||
final Plot plot = MainUtil.getPlot(loc);
|
||||
if ((plot == null) || (plot.owner == null)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
|
||||
int size = plots.size();
|
||||
final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(loc.getWorld(), other)) + size;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
final String world = loc.getWorld();
|
||||
for (final PlotId id : plots) {
|
||||
final Plot current = PS.get().getPlots(world).get(id);
|
||||
final UUID uuid = getUUID(args[0]);
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
current.owner = uuid;
|
||||
PS.get().updatePlot(current);
|
||||
DBFunc.setOwner(current, current.owner);
|
||||
}
|
||||
MainUtil.setSign(args[0], plot);
|
||||
MainUtil.sendMessage(plr, C.SET_OWNER);
|
||||
if (other != null) {
|
||||
MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
255
src/main/java/com/intellectualcrafters/plot/commands/Setup.java
Normal file
255
src/main/java/com/intellectualcrafters/plot/commands/Setup.java
Normal file
@ -0,0 +1,255 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
|
||||
public class Setup extends SubCommand {
|
||||
public Setup() {
|
||||
super("setup", "plots.admin.command.setup", "Plotworld setup command", "setup", "create", CommandCategory.ACTIONS, false);
|
||||
}
|
||||
|
||||
public void displayGenerators(PlotPlayer plr) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("&6What generator do you want?");
|
||||
for (Entry<String, ChunkGenerator> entry : SetupUtils.generators.entrySet()) {
|
||||
if (entry.getKey().equals("PlotSquared")) {
|
||||
message.append("\n&8 - &2" + entry.getKey() + " (Default Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof HybridGen) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Hybrid Generator)");
|
||||
}
|
||||
else if (entry.getValue() instanceof PlotGenerator) {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Plot Generator)");
|
||||
}
|
||||
else {
|
||||
message.append("\n&8 - &7" + entry.getKey() + " (Unknown structure)");
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
// going through setup
|
||||
String name;
|
||||
if (plr == null) {
|
||||
name = "*";
|
||||
}
|
||||
else {
|
||||
name = plr.getName();
|
||||
}
|
||||
if (!SetupUtils.setupMap.containsKey(name)) {
|
||||
final SetupObject object = new SetupObject();
|
||||
SetupUtils.setupMap.put(name, object);
|
||||
SetupUtils.manager.updateGenerators();
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
displayGenerators(plr);
|
||||
return false;
|
||||
}
|
||||
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")) {
|
||||
final SetupObject object = SetupUtils.setupMap.get(name);
|
||||
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) {
|
||||
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])) {
|
||||
final String prefix = "\n&8 - &7";
|
||||
MainUtil.sendMessage(plr, "&cYou must choose a generator!" + prefix + StringUtils.join(SetupUtils.generators.keySet(), prefix).replaceAll("PlotSquared", "&2PlotSquared"));
|
||||
sendMessage(plr, C.SETUP_INIT);
|
||||
return false;
|
||||
}
|
||||
object.setupGenerator = args[0];
|
||||
object.current++;
|
||||
final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : "";
|
||||
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) instanceof PlotGenerator) {
|
||||
types.add("default");
|
||||
}
|
||||
types.add("augmented");
|
||||
if (Settings.ENABLE_CLUSTERS) {
|
||||
types.add("partial");
|
||||
}
|
||||
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")) {
|
||||
MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
object.type = allTypes.indexOf(args[0].toLowerCase());
|
||||
ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator);
|
||||
if (object.type == 0) {
|
||||
object.current++;
|
||||
if (object.step == null) {
|
||||
object.plotManager = object.setupGenerator;
|
||||
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
|
||||
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);
|
||||
}
|
||||
if (object.step.length == 0) {
|
||||
object.current = 4;
|
||||
MainUtil.sendMessage(plr, "&6What do you want your world to be called?");
|
||||
object.setup_index = 0;
|
||||
return true;
|
||||
}
|
||||
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 instanceof PlotGenerator) {
|
||||
object.plotManager = object.setupGenerator;
|
||||
object.setupGenerator = null;
|
||||
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
|
||||
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);
|
||||
}
|
||||
else {
|
||||
object.plotManager = "PlotSquared";
|
||||
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as PlotGenerator");
|
||||
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
|
||||
object.step = ((PlotGenerator) 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");
|
||||
}
|
||||
object.current++;
|
||||
break;
|
||||
}
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
object.terrain = terrain.indexOf(args[0].toLowerCase());
|
||||
object.current++;
|
||||
if (object.step == null) {
|
||||
object.step = ((PlotGenerator) 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) {
|
||||
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) {
|
||||
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) {
|
||||
sendMessage(plr, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
|
||||
step.setValue(args[0]);
|
||||
object.setup_index++;
|
||||
if (object.setup_index == object.step.length) {
|
||||
execute(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 {
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, "&cYou need to choose a world name!");
|
||||
return false;
|
||||
}
|
||||
if (BlockManager.manager.isWorld(args[0])) {
|
||||
MainUtil.sendMessage(plr, "&cThat world name is already taken!");
|
||||
}
|
||||
object.world = args[0];
|
||||
SetupUtils.setupMap.remove(name);
|
||||
final String world;
|
||||
if (object.setupManager == null) {
|
||||
world = SetupUtils.manager.setupWorld(object);
|
||||
}
|
||||
else {
|
||||
world = object.setupManager.setupWorld(object);
|
||||
}
|
||||
try {
|
||||
if (plr != null) {
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
plr.sendMessage("&cAn error occured. See console for more information");
|
||||
e.printStackTrace();
|
||||
}
|
||||
sendMessage(plr, C.SETUP_FINISHED, object.world);
|
||||
SetupUtils.setupMap.remove(name);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
/**
|
||||
* SubCommand class
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public abstract class SubCommand {
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
public final String cmd;
|
||||
/**
|
||||
* Permission node
|
||||
*/
|
||||
public final CommandPermission permission;
|
||||
/**
|
||||
* Simple description
|
||||
*/
|
||||
public final String description;
|
||||
/**
|
||||
* Aliases
|
||||
*/
|
||||
public final ArrayList<String> alias;
|
||||
/**
|
||||
* Command usage
|
||||
*/
|
||||
public final String usage;
|
||||
/**
|
||||
* The category
|
||||
*/
|
||||
public final CommandCategory category;
|
||||
/**
|
||||
* Is this a player-online command?
|
||||
*/
|
||||
public final boolean isPlayer;
|
||||
|
||||
/**
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param alias Command alias
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final String alias, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = cmd;
|
||||
this.permission = new CommandPermission(permission);
|
||||
this.description = description;
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.add(alias);
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cmd Command /plot {cmd} <-- That!
|
||||
* @param permission Permission Node
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param aliases Command aliases
|
||||
* @param category CommandCategory. Pick whichever is closest to what you want.
|
||||
*/
|
||||
public SubCommand(final String cmd, final String permission, final String description, final String usage, final CommandCategory category, final boolean isPlayer, final String... aliases) {
|
||||
this.cmd = cmd;
|
||||
this.permission = new CommandPermission(permission);
|
||||
this.description = description;
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.addAll(Arrays.asList(aliases));
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param command Command /plot {cmd} <-- That!
|
||||
* @param description Simple description
|
||||
* @param usage Usage description: /plot command {args...}
|
||||
* @param category CommandCategory. Pick whichever closests to what you want.
|
||||
*/
|
||||
public SubCommand(final Command command, final String description, final String usage, final CommandCategory category, final boolean isPlayer) {
|
||||
this.cmd = command.getCommand();
|
||||
this.permission = command.getPermission();
|
||||
this.alias = new ArrayList<String>();
|
||||
this.alias.add(command.getAlias());
|
||||
this.description = description;
|
||||
this.usage = usage;
|
||||
this.category = category;
|
||||
this.isPlayer = isPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute.
|
||||
*
|
||||
* @param plr executor
|
||||
* @param args arguments
|
||||
*
|
||||
* @return true on success, false on failure
|
||||
*/
|
||||
public abstract boolean execute(final PlotPlayer plr, final String... args);
|
||||
|
||||
/**
|
||||
* Execute the command as console
|
||||
*
|
||||
* @param args Arguments
|
||||
*/
|
||||
public void executeConsole(final String... args) {
|
||||
this.execute(null, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
MainUtil.sendMessage(plr, c, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
135
src/main/java/com/intellectualcrafters/plot/commands/Swap.java
Normal file
135
src/main/java/com/intellectualcrafters/plot/commands/Swap.java
Normal file
@ -0,0 +1,135 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.intellectualcrafters.plot.object.PlotClusterId;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.ClusterManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Empire92
|
||||
*/
|
||||
public class Swap extends SubCommand {
|
||||
public Swap() {
|
||||
super(Command.SWAP, "Swap two plots", "switch", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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) {
|
||||
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 == null) || !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) {
|
||||
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);
|
||||
|
||||
// Getting secon selection
|
||||
Plot bot2 = MainUtil.getBottomPlot(plot2);
|
||||
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)) {
|
||||
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 ) {
|
||||
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) {
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (last) {
|
||||
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.STARTED_SWAP);
|
||||
return true;
|
||||
}
|
||||
}
|
103
src/main/java/com/intellectualcrafters/plot/commands/TP.java
Normal file
103
src/main/java/com/intellectualcrafters/plot/commands/TP.java
Normal file
@ -0,0 +1,103 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
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.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class TP extends SubCommand {
|
||||
public TP() {
|
||||
super(Command.TP, "Teleport to a plot", "tp {alias|id}", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
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])) {
|
||||
world = args[1];
|
||||
}
|
||||
}
|
||||
if (!PS.get().isPlotWorld(world)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
Plot temp;
|
||||
if ((temp = isAlias(world, id)) != null) {
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), temp);
|
||||
return true;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Plot isAlias(final String world, String a) {
|
||||
int index = 0;
|
||||
if (a.contains(";")) {
|
||||
final String[] split = a.split(";");
|
||||
if ((split[1].length() > 0) && StringUtils.isNumeric(split[1])) {
|
||||
index = Integer.parseInt(split[1]);
|
||||
}
|
||||
a = split[0];
|
||||
}
|
||||
final PlotPlayer player = UUIDHandler.getPlayer(a);
|
||||
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];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
for (final Plot p : PS.get().getPlots(world).values()) {
|
||||
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Target extends SubCommand {
|
||||
public Target() {
|
||||
super(Command.TARGET, "Target a plot with your compass", "target <X;Z>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
final Location ploc = plr.getLocation();
|
||||
if (!PS.get().isPlotWorld(ploc.getWorld())) {
|
||||
MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final PlotId id = MainUtil.parseId(args[0]);
|
||||
if (id == null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
|
||||
return false;
|
||||
}
|
||||
final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id);
|
||||
plr.setCompassTarget(loc);
|
||||
MainUtil.sendMessage(plr, C.COMPASS_TARGET);
|
||||
return true;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot target <X;Z>");
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,212 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.intellectualcrafters.configuration.ConfigurationSection;
|
||||
import com.intellectualcrafters.configuration.file.YamlConfiguration;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||
import com.intellectualcrafters.plot.object.FileBytes;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.SetupObject;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Template extends SubCommand {
|
||||
public Template() {
|
||||
super("template", "plots.admin", "Create or use a world template", "template", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
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()) {
|
||||
output.mkdirs();
|
||||
}
|
||||
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));
|
||||
new File(newFile.getParent()).mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(newFile);
|
||||
int len;
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
fos.write(buffer, 0, len);
|
||||
}
|
||||
fos.close();
|
||||
ze = zis.getNextEntry();
|
||||
}
|
||||
zis.closeEntry();
|
||||
zis.close();
|
||||
return true;
|
||||
} catch (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) {
|
||||
config.set("generator.plugin", generator);
|
||||
}
|
||||
for (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");
|
||||
output.mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(output + File.separator + world + ".template");
|
||||
ZipOutputStream zos = new ZipOutputStream(fos);
|
||||
|
||||
for (FileBytes file : files) {
|
||||
ZipEntry ze = new ZipEntry(file.path);
|
||||
zos.putNextEntry(ze);
|
||||
zos.write(file.data);
|
||||
}
|
||||
zos.closeEntry();
|
||||
zos.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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 false;
|
||||
}
|
||||
else if (args[0].equalsIgnoreCase("import")) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import <world> <template>");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template <import|export> <world> [template]");
|
||||
return false;
|
||||
}
|
||||
final String world = args[1];
|
||||
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)) {
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
File worldFile = new File(PS.get().IMP.getDirectory() + File.separator + "templates" + File.separator + "tmp-data.yml");
|
||||
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
|
||||
PS.get().config.set("worlds." + world, worldConfig.get(""));
|
||||
try {
|
||||
PS.get().config.save(PS.get().configFile);
|
||||
PS.get().config.load(PS.get().configFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String manager = worldConfig.getString("generator.plugin");
|
||||
if (manager == null) {
|
||||
manager = "PlotSquared";
|
||||
}
|
||||
String generator = worldConfig.getString("generator.init");
|
||||
if (generator == null) {
|
||||
generator = manager;
|
||||
}
|
||||
|
||||
int type = worldConfig.getInt("generator.type");
|
||||
int terrain = worldConfig.getInt("generator.terrain");
|
||||
|
||||
SetupObject setup = new SetupObject();
|
||||
setup.plotManager = manager;
|
||||
setup.setupGenerator = generator;
|
||||
setup.type = type;
|
||||
setup.terrain = terrain;
|
||||
setup.step = new ConfigurationNode[0];
|
||||
setup.world = world;
|
||||
SetupUtils.manager.setupWorld(setup);
|
||||
MainUtil.sendMessage(plr, "Done!");
|
||||
if (plr != null) {
|
||||
plr.teleport(BlockManager.manager.getSpawn(world));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
}
|
||||
final PlotManager manager = PS.get().getPlotManager(world);
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
manager.exportTemplate(plotworld);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MainUtil.sendMessage(plr, "Failed: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, "Done!");
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Toggle extends SubCommand {
|
||||
public Toggle() {
|
||||
super(Command.TOGGLE, "Toggle per user settings", "toggle <setting>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
public void noArgs(PlotPlayer player) {
|
||||
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot toggle <setting>");
|
||||
MainUtil.sendMessage(player, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + "titles");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer player, final String... args) {
|
||||
if (args.length == 0) {
|
||||
noArgs(player);
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "titles": {
|
||||
if (toggle(player, "disabletitles")) {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_ENABLED, args[0]);
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(player, C.TOGGLE_DISABLED, args[0]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean toggle(PlotPlayer player, String key) {
|
||||
if (player.getAttribute(key)) {
|
||||
player.removeAttribute(key);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
player.setAttribute(key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
212
src/main/java/com/intellectualcrafters/plot/commands/Trim.java
Normal file
212
src/main/java/com/intellectualcrafters/plot/commands/Trim.java
Normal file
@ -0,0 +1,212 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||
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.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Trim extends SubCommand {
|
||||
public static boolean TASK = false;
|
||||
public static ArrayList<Plot> expired = null;
|
||||
private static int TASK_ID = 0;
|
||||
|
||||
public Trim() {
|
||||
super("trim", "plots.admin", "Delete unmodified portions of your plotworld", "trim", "", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
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() {
|
||||
final String directory = world + File.separator + "region";
|
||||
final File folder = new File(directory);
|
||||
final File[] regionFiles = folder.listFiles();
|
||||
for (final File file : regionFiles) {
|
||||
final String name = file.getName();
|
||||
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) {
|
||||
PS.log("INVALID MCA: " + name);
|
||||
}
|
||||
} else {
|
||||
final Path path = Paths.get(file.getPath());
|
||||
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 {
|
||||
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) {
|
||||
PS.log("INVALID MCA: " + name);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
}
|
||||
});
|
||||
Trim.TASK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
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<>();
|
||||
plots.addAll(PS.get().getPlots(world).values());
|
||||
final HashSet<ChunkLoc> chunks = new HashSet<>(ChunkManager.manager.getChunkChunks(world));
|
||||
sendMessage(" - MCA #: " + chunks.size());
|
||||
sendMessage(" - CHUNKS: " + (chunks.size() * 1024) + " (max)");
|
||||
sendMessage(" - TIME ESTIMATE: " + (chunks.size() / 1200) + " minutes");
|
||||
Trim.TASK_ID = TaskManager.runTaskRepeat(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
while ((System.currentTimeMillis() - start) < 50) {
|
||||
if (plots.size() == 0) {
|
||||
empty.addAll(chunks);
|
||||
Trim.TASK = false;
|
||||
TaskManager.runTaskAsync(whenDone);
|
||||
PS.get().TASK.cancelTask(Trim.TASK_ID);
|
||||
return;
|
||||
}
|
||||
final Plot plot = plots.get(0);
|
||||
plots.remove(0);
|
||||
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
|
||||
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
|
||||
for (int x = pos1.getX(); x <= pos2.getX(); x += 512 ) {
|
||||
for (int z = pos1.getZ(); z <= pos2.getZ(); z += 512 ) {
|
||||
ChunkLoc chunk = ChunkManager.getChunkChunk(new Location(world, x, 0, z));
|
||||
chunks.remove(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
Trim.TASK = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void deleteChunks(final String world, final ArrayList<ChunkLoc> chunks) {
|
||||
ChunkManager.manager.deleteRegionFiles(world, chunks);
|
||||
}
|
||||
|
||||
public static void sendMessage(final String message) {
|
||||
PS.log("&3PlotSquared -> World trim&8: &7" + message);
|
||||
}
|
||||
|
||||
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) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
}
|
||||
if (args.length == 1) {
|
||||
final String arg = args[0].toLowerCase();
|
||||
final PlotId id = getId(arg);
|
||||
if (id != null) {
|
||||
MainUtil.sendMessage(plr, "/plot trim x;z &l<world>");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
MainUtil.sendMessage(plr, C.TRIM_SYNTAX);
|
||||
return false;
|
||||
}
|
||||
final String arg = args[0].toLowerCase();
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.NOT_VALID_WORLD);
|
||||
return false;
|
||||
}
|
||||
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() {
|
||||
@Override
|
||||
public void run() {
|
||||
deleteChunks(world, empty);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Trust extends SubCommand {
|
||||
public Trust() {
|
||||
super(Command.TRUST, "Allow a player to build in a plot", "trust <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot trust <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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
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("*")) {
|
||||
uuid = DBFunc.everyone;
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(args[0]);
|
||||
}
|
||||
if (uuid == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_OWNER);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plot.trusted.contains(uuid)) {
|
||||
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
|
||||
return false;
|
||||
}
|
||||
if (plot.removeMember(uuid)) {
|
||||
plot.addTrusted(uuid);
|
||||
}
|
||||
else {
|
||||
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
|
||||
return false;
|
||||
}
|
||||
if (plot.denied.contains(uuid)) {
|
||||
plot.removeDenied(uuid);
|
||||
}
|
||||
plot.addTrusted(uuid);
|
||||
}
|
||||
EventUtil.manager.callTrusted(plr, plot, uuid, true);
|
||||
MainUtil.sendMessage(plr, C.TRUSTED_ADDED);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class Unclaim extends SubCommand {
|
||||
public Unclaim() {
|
||||
super(Command.UNCLAIM, "Unclaim a plot", "unclaim", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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 == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
|
||||
return !sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
|
||||
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
EconHandler.manager.depositMoney(plr, c);
|
||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||
}
|
||||
}
|
||||
final boolean result = PS.get().removePlot(loc.getWorld(), plot.id, true);
|
||||
if (result) {
|
||||
plot.unclaim();
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "Plot removal has been denied.");
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.UNCLAIM_SUCCESS);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Undeny extends SubCommand {
|
||||
public Undeny() {
|
||||
super(Command.UNDENY, "Remove a denied user from a plot", "undeny <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot undeny <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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.undeny")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.denied) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
for (UUID uuid : new ArrayList<>(plot.denied)) {
|
||||
plot.removeDenied(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeDenied(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
/**
|
||||
* Created 2014-08-01 for PlotSquared
|
||||
*
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class Unlink extends SubCommand {
|
||||
public Unlink() {
|
||||
super(Command.UNLINK, "Unlink a mega-plot", "unlink", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(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.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() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!MainUtil.unlinkPlot(plot)) {
|
||||
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
|
||||
return;
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
|
||||
CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Untrust extends SubCommand {
|
||||
public Untrust() {
|
||||
super(Command.UNTRUST, "Remove a trusted user from a plot", "untrust <player>", CommandCategory.ACTIONS, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length != 1) {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot untrust <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()) {
|
||||
MainUtil.sendMessage(plr, C.PLOT_UNOWNED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.untrust")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
if (args[0].equals("unknown")) {
|
||||
ArrayList<UUID> toRemove = new ArrayList<>();
|
||||
for (UUID uuid : plot.trusted) {
|
||||
if (UUIDHandler.getName(uuid) == null) {
|
||||
toRemove.add(uuid);
|
||||
}
|
||||
}
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else if (args[0].equals("*")){
|
||||
for (UUID uuid : new ArrayList<>(plot.trusted)) {
|
||||
plot.removeTrusted(uuid);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (plot.removeTrusted(uuid)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.REMOVED_PLAYERS, count + "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
public class Update extends SubCommand {
|
||||
public static String downloads, version;
|
||||
|
||||
public Update() {
|
||||
super("update", "plots.admin", "Update PlotSquared", "update", "updateplugin", CommandCategory.DEBUG, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (plr != null) {
|
||||
MainUtil.sendMessage(plr, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
URL url;
|
||||
if (args.length == 0) {
|
||||
url = PS.get().update;
|
||||
}
|
||||
else if (args.length == 1) {
|
||||
try {
|
||||
url = new URL(args[0]);
|
||||
} catch (MalformedURLException e) {
|
||||
MainUtil.sendMessage(plr, "&cInvalid url: " + args[0]);
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot update [url]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot update");
|
||||
return false;
|
||||
}
|
||||
if (url == null) {
|
||||
MainUtil.sendMessage(plr, "&cNo update found!");
|
||||
MainUtil.sendMessage(plr, "&cTo manually specify an update URL: /plot update <url>");
|
||||
return false;
|
||||
}
|
||||
PS.get().update(url);
|
||||
return true;
|
||||
}
|
||||
}
|
153
src/main/java/com/intellectualcrafters/plot/commands/Visit.java
Normal file
153
src/main/java/com/intellectualcrafters/plot/commands/Visit.java
Normal file
@ -0,0 +1,153 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Visit extends SubCommand {
|
||||
public Visit() {
|
||||
super("visit", "plots.visit", "Visit someones plot", "visit {player} [#]", "v", CommandCategory.TELEPORT, true);
|
||||
}
|
||||
|
||||
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)) {
|
||||
plots.add(p);
|
||||
}
|
||||
}
|
||||
return plots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
return sendMessage(plr, C.COMMAND_SYNTAX, "/plot visit <player|alias|world|id> [#]");
|
||||
}
|
||||
ArrayList<Plot> plots = new ArrayList<>();
|
||||
UUID user = UUIDHandler.getUUID(args[0]);
|
||||
if (user != null ) {
|
||||
// do plots by username
|
||||
plots.addAll(PS.get().getPlots(user));
|
||||
} else if (PS.get().isPlotWorld(args[0])) {
|
||||
// do plots by world
|
||||
plots.addAll(PS.get().getPlots(args[0]).values());
|
||||
}
|
||||
else {
|
||||
Plot plot = MainUtil.getPlotFromString(plr, args[0], true);
|
||||
if (plot == null) {
|
||||
return false;
|
||||
}
|
||||
plots.add(plot);
|
||||
}
|
||||
if (plots.size() == 0) {
|
||||
sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
return false;
|
||||
}
|
||||
int index = 0;
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
index = Integer.parseInt(args[1]) - 1;
|
||||
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) {
|
||||
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")) {
|
||||
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")) {
|
||||
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")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.shared");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!Permissions.hasPermission(plr, "plots.visit.other")) {
|
||||
sendMessage(plr, C.NO_PERMISSION, "plots.visit.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(index));
|
||||
return true;
|
||||
|
||||
//
|
||||
// // from alias
|
||||
//
|
||||
//
|
||||
// id = PlotId.fromString(args[0]);
|
||||
//
|
||||
//
|
||||
//
|
||||
// final String username = args[0];
|
||||
// final UUID uuid = UUIDHandler.getUUID(username);
|
||||
// List<Plot> plots = null;
|
||||
// if (uuid != null) {
|
||||
// plots = PlotSquared.sortPlotsByWorld(getPlots(uuid));
|
||||
// }
|
||||
// if ((uuid == null) || plots.isEmpty()) {
|
||||
// return sendMessage(plr, C.FOUND_NO_PLOTS);
|
||||
// }
|
||||
// if (args.length < 2) {
|
||||
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0));
|
||||
// return true;
|
||||
// }
|
||||
// int i;
|
||||
// try {
|
||||
// i = Integer.parseInt(args[1]);
|
||||
// } catch (final Exception e) {
|
||||
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
// }
|
||||
// if ((i < 1) || (i > plots.size())) {
|
||||
// return sendMessage(plr, C.NOT_VALID_NUMBER);
|
||||
// }
|
||||
// MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(i - 1));
|
||||
// return true;
|
||||
}
|
||||
}
|
@ -0,0 +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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.listeners.worldedit.WEManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
|
||||
public class WE_Anywhere extends SubCommand {
|
||||
public WE_Anywhere() {
|
||||
super("weanywhere", "plots.worldedit.bypass", "Force bypass of WorldEdit", "weanywhere", "wea", CommandCategory.DEBUG, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (PS.get().worldEdit == null) {
|
||||
MainUtil.sendMessage(plr, "&cWorldEdit is not enabled on this server");
|
||||
return false;
|
||||
}
|
||||
if (Permissions.hasPermission(plr, "plots.worldedit.bypass")) {
|
||||
if (WEManager.bypass.contains(plr.getName())) {
|
||||
WEManager.bypass.remove(plr.getName());
|
||||
MainUtil.sendMessage(plr, C.WORLDEDIT_RESTRICTED);
|
||||
}
|
||||
else {
|
||||
WEManager.bypass.add(plr.getName());
|
||||
MainUtil.sendMessage(plr, C.WORLDEDIT_UNMASKED);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
531
src/main/java/com/intellectualcrafters/plot/commands/list.java
Normal file
531
src/main/java/com/intellectualcrafters/plot/commands/list.java
Normal file
@ -0,0 +1,531 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
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.BukkitPlayer;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
import com.intellectualcrafters.plot.util.bukkit.chat.FancyMessage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public class list extends SubCommand {
|
||||
public list() {
|
||||
super(Command.LIST, "List all plots", "list {mine|shared|all|world|forsale}", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
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 (player == null) {
|
||||
args.addAll(Arrays.asList("world", "all", "unowned", "unknown", "top", "<player", "<world>"));
|
||||
if (EconHandler.manager != null) {
|
||||
args.add("forsale");
|
||||
}
|
||||
} else {
|
||||
if (EconHandler.manager != null && player.hasPermission("plots.list.forsale")) {
|
||||
args.add("forsale");
|
||||
}
|
||||
if (player.hasPermission("plots.list.mine")) {
|
||||
args.add("mine");
|
||||
}
|
||||
if (player.hasPermission("plots.list.shared")) {
|
||||
args.add("shared");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("world");
|
||||
}
|
||||
if (player.hasPermission("plots.list.top")) {
|
||||
args.add("top");
|
||||
}
|
||||
if (player.hasPermission("plots.list..all")) {
|
||||
args.add("all");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unowned")) {
|
||||
args.add("unowned");
|
||||
}
|
||||
if (player.hasPermission("plots.list.unknown")) {
|
||||
args.add("unknown");
|
||||
}
|
||||
if (player.hasPermission("plots.list.player")) {
|
||||
args.add("<player>");
|
||||
}
|
||||
if (player.hasPermission("plots.list.world")) {
|
||||
args.add("<world>");
|
||||
}
|
||||
}
|
||||
return args.toArray(new String[args.size()]);
|
||||
}
|
||||
|
||||
public void noArgs(PlotPlayer plr) {
|
||||
// For #395
|
||||
// if (plr != null) {
|
||||
// if (EconHandler.manager != null) {
|
||||
// builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "top", "<player>", "<world>", "forsale",}));
|
||||
// }
|
||||
// else {
|
||||
// builder.append(getArgumentList(new String[] { "mine", "shared", "world", "all", "unowned", "unknown", "top", "<player>", "<world>"}));
|
||||
// }
|
||||
// } else {
|
||||
// builder.append(getArgumentList(new String[] { "world", "all", "unowned", "unknown", "top", "<player>", "<world>"}));
|
||||
// }
|
||||
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(getArgumentList(plr)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (args.length < 1) {
|
||||
noArgs(plr);
|
||||
return false;
|
||||
}
|
||||
int page = 0;
|
||||
if (args.length > 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args[1]);
|
||||
--page;
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
page = 0;
|
||||
}
|
||||
}
|
||||
|
||||
List<Plot> plots = null;
|
||||
|
||||
String world;
|
||||
if (plr != null) {
|
||||
world = plr.getLocation().getWorld();
|
||||
}
|
||||
else {
|
||||
Set<String> worlds = PS.get().getPlotWorlds();
|
||||
if (worlds.size() == 0) {
|
||||
world = "world";
|
||||
}
|
||||
else {
|
||||
world = worlds.iterator().next();
|
||||
}
|
||||
}
|
||||
String arg = args[0].toLowerCase();
|
||||
boolean sort = true;
|
||||
switch (arg) {
|
||||
case "mine": {
|
||||
if (plr == null) {
|
||||
break;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.list.mine")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.mine");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(plr));
|
||||
break;
|
||||
}
|
||||
case "shared": {
|
||||
if (plr == null) {
|
||||
break;
|
||||
}
|
||||
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.trusted.contains(plr.getUUID()) || plot.members.contains(plr.getUUID())) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + world);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(world).values());
|
||||
break;
|
||||
}
|
||||
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 "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>() {
|
||||
@Override
|
||||
public int compare(Plot p1, Plot p2) {
|
||||
double v1 = 0;
|
||||
double v2 = 0;
|
||||
if (p1.settings.ratings != null && p1.settings.ratings.size() > 0) {
|
||||
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v1 += av * av;
|
||||
}
|
||||
v1 /= p1.settings.ratings.size();
|
||||
v2 += p2.settings.ratings.size();
|
||||
}
|
||||
if (p2.settings.ratings != null && p2.settings.ratings.size() > 0) {
|
||||
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
|
||||
double av = entry.getValue().getAverageRating();
|
||||
v2 += av * av;
|
||||
}
|
||||
v2 /= p2.settings.ratings.size();
|
||||
v2 += p2.settings.ratings.size();
|
||||
}
|
||||
if (v2 == v1 && v2 != 0) {
|
||||
return p2.settings.ratings.size() - p1.settings.ratings.size();
|
||||
}
|
||||
return (int) Math.signum(v2 - v1);
|
||||
}
|
||||
});
|
||||
sort = false;
|
||||
break;
|
||||
}
|
||||
case "forsale": {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.forsale")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.forsale");
|
||||
return false;
|
||||
}
|
||||
if (EconHandler.manager == null) {
|
||||
break;
|
||||
}
|
||||
plots = new ArrayList<>();
|
||||
for (Plot plot : PS.get().getPlots()) {
|
||||
final Flag price = FlagManager.getPlotFlag(plot, "price");
|
||||
if (price != null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
if (UUIDHandler.getName(plot.owner) == null) {
|
||||
plots.add(plot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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])) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.world." + args[0]);
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(args[0]).values());
|
||||
break;
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(args[0]);
|
||||
if (uuid != null) {
|
||||
if (!Permissions.hasPermission(plr, "plots.list.player")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.list.player");
|
||||
return false;
|
||||
}
|
||||
plots = new ArrayList<>(PS.get().getPlots(uuid));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (plots == null) {
|
||||
sendMessage(plr, C.DID_YOU_MEAN, new StringComparison(args[0], new String[] { "mine", "shared", "world", "all" }).getBestMatch());
|
||||
return false;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (world != null) {
|
||||
plots = PS.get().sortPlots(plots, world);
|
||||
}
|
||||
else {
|
||||
plots = PS.get().sortPlots(plots);
|
||||
}
|
||||
}
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
final int totalPages = (int) Math.ceil(plots.size() / pageSize);
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
// Only display pageSize!
|
||||
int max = (page * pageSize) + pageSize;
|
||||
if (max > plots.size()) {
|
||||
max = plots.size();
|
||||
}
|
||||
|
||||
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");
|
||||
MainUtil.sendMessage(player, header);
|
||||
|
||||
int i = page * pageSize;
|
||||
for (Plot plot : subList) {
|
||||
if (plot.settings.isMerged()) {
|
||||
if (!MainUtil.getBottomPlot(plot).equals(plot)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
if (player != null && Settings.FANCY_CHAT) {
|
||||
ChatColor color;
|
||||
if (plot.owner == null) {
|
||||
color = ChatColor.GOLD;
|
||||
}
|
||||
else if (plot.isOwner(player.getUUID())) {
|
||||
color = ChatColor.BLUE;
|
||||
}
|
||||
else if (plot.isAdded(player.getUUID())) {
|
||||
color = ChatColor.DARK_GREEN;
|
||||
}
|
||||
else if (plot.isDenied(player.getUUID())) {
|
||||
color = ChatColor.RED;
|
||||
}
|
||||
else {
|
||||
color = ChatColor.GOLD;
|
||||
}
|
||||
FancyMessage trusted =
|
||||
new FancyMessage(
|
||||
ChatColor.stripColor(
|
||||
ChatColor.translateAlternateColorCodes('&',
|
||||
C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.trusted)))))
|
||||
.color(ChatColor.GOLD);
|
||||
|
||||
FancyMessage members =
|
||||
new FancyMessage(
|
||||
ChatColor.stripColor(
|
||||
ChatColor.translateAlternateColorCodes('&',
|
||||
C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.members)))))
|
||||
.color(ChatColor.GOLD);
|
||||
String strFlags = StringUtils.join(plot.settings.flags.values(), ",");
|
||||
if (strFlags.length() == 0) {
|
||||
strFlags = C.NONE.s();
|
||||
}
|
||||
FancyMessage flags =
|
||||
new FancyMessage(
|
||||
ChatColor.stripColor(
|
||||
ChatColor.translateAlternateColorCodes('&',
|
||||
C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags))))
|
||||
.color(ChatColor.GOLD);
|
||||
|
||||
FancyMessage message = new FancyMessage("")
|
||||
.then("[")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(i + "")
|
||||
.command("/plot visit " + plot.world + ";" + plot.id)
|
||||
.tooltip("/plot visit " + plot.world + ";" + plot.id)
|
||||
.color(ChatColor.GOLD)
|
||||
.then("]")
|
||||
|
||||
// teleport tooltip
|
||||
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(" " + plot.toString())
|
||||
|
||||
.formattedTooltip(trusted, members, flags)
|
||||
.command("/plot info " + plot.world + ";" + plot.id)
|
||||
|
||||
.color(color)
|
||||
.then(" - ")
|
||||
.color(ChatColor.GRAY);
|
||||
String prefix = "";
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
String name = UUIDHandler.getName(uuid);
|
||||
if (name == null) {
|
||||
message = message
|
||||
.then(prefix)
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("unknown")
|
||||
.color(ChatColor.GRAY)
|
||||
.tooltip(uuid.toString())
|
||||
.suggest(uuid.toString());
|
||||
}
|
||||
else {
|
||||
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
|
||||
if (pp != null) {
|
||||
message = message
|
||||
.then(prefix)
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(name).color(ChatColor.GOLD)
|
||||
.formattedTooltip(new FancyMessage("Online").color(ChatColor.DARK_GREEN));
|
||||
}
|
||||
else {
|
||||
message = message
|
||||
.then(prefix)
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(name).color(ChatColor.GOLD)
|
||||
.formattedTooltip(new FancyMessage("Offline").color(ChatColor.RED));
|
||||
}
|
||||
}
|
||||
prefix = ", ";
|
||||
}
|
||||
message.send(((BukkitPlayer) player).player);
|
||||
}
|
||||
else {
|
||||
String message = C.PLOT_LIST_ITEM.s()
|
||||
.replaceAll("%in", i + 1 + "")
|
||||
.replaceAll("%id", plot.id.toString())
|
||||
.replaceAll("%world", plot.world)
|
||||
.replaceAll("%owner", getName(plot.owner))
|
||||
|
||||
// Unused
|
||||
|
||||
.replaceAll("%trusted%", "")
|
||||
.replaceAll("%members%", "")
|
||||
.replaceAll("%tp%", "");
|
||||
MainUtil.sendMessage(player, message);
|
||||
}
|
||||
}
|
||||
if (player != null && Settings.FANCY_CHAT) {
|
||||
if (page < totalPages && page > 0) {
|
||||
// back | next
|
||||
new FancyMessage("")
|
||||
.then("<-")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page))
|
||||
.then(" | ")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("->")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page + 2))
|
||||
.send(((BukkitPlayer) player).player);
|
||||
return;
|
||||
}
|
||||
if (page == 0 && totalPages != 0) {
|
||||
// next
|
||||
new FancyMessage("")
|
||||
.then("<-")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then(" | ")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("->")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page + 2))
|
||||
.send(((BukkitPlayer) player).player);
|
||||
return;
|
||||
}
|
||||
if (page == totalPages && totalPages != 0) {
|
||||
// back
|
||||
new FancyMessage("")
|
||||
.then("<-")
|
||||
.color(ChatColor.GOLD)
|
||||
.command("/plot list " + args[0] + " " + (page))
|
||||
.then(" | ")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.then("->")
|
||||
.color(ChatColor.DARK_GRAY)
|
||||
.send(((BukkitPlayer) player).player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
String footer = C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.size() + "").replaceAll("%plot%", plots.size() == 1 ? "plot" : "plots");
|
||||
MainUtil.sendMessage(player, footer);
|
||||
}
|
||||
}
|
||||
|
||||
private String getArgumentList(final String[] strings) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String prefix = "";
|
||||
for (final String s : strings) {
|
||||
builder.append(prefix + MainUtil.colorise('&', s));
|
||||
prefix = " | ";
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class plugin extends SubCommand {
|
||||
|
||||
public plugin() {
|
||||
super("plugin", "plots.use", "Show plugin information", "plugin", "version", CommandCategory.INFO, false);
|
||||
}
|
||||
|
||||
private static String convertToNumericString(final String str, final boolean dividers) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final char c : str.toCharArray()) {
|
||||
if (Character.isDigit(c)) {
|
||||
builder.append(c);
|
||||
} else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String getInfo(final String link) throws Exception {
|
||||
final URLConnection connection = new URL(link).openConnection();
|
||||
connection.addRequestProperty("User-Agent", "Mozilla/4.0");
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String document = "", line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
document += (line + "\n");
|
||||
}
|
||||
reader.close();
|
||||
return document;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ArrayList<String> strings = new ArrayList<String>() {
|
||||
// $2>> $1%id$2:$1%world $2- $1%owner
|
||||
{
|
||||
add(String.format("$2>> $1&lPlotSquared $2(Version$2: $1%s$2)", PS.get().IMP.getVersion()));
|
||||
add(String.format("$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92"));
|
||||
add(String.format("$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"));
|
||||
add(String.format("$2>> $1&lWebsite$2: $1http://plotsquared.co"));
|
||||
add(String.format("$2>> $1&lNewest Version$2: $1" + (PS.get().update == null ? PS.get().IMP.getVersion() : PS.get().update)));
|
||||
}
|
||||
};
|
||||
for (final String s : strings) {
|
||||
MainUtil.sendMessage(plr, StringMan.replaceFromMap(s, C.replacements), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user