592 lines
30 KiB
Java
Raw Normal View History

2015-01-29 14:20:29 +11:00
////////////////////////////////////////////////////////////////////////////////////////////////////
// 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;
2015-07-06 01:44:10 +10:00
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
2015-07-27 16:00:20 +10:00
import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PS;
2015-01-29 14:20:29 +11:00
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.PlotGenerator;
2015-07-26 21:33:54 +02:00
import com.intellectualsites.commands.CommandDeclaration;
2015-07-27 14:30:50 +10:00
import com.intellectualsites.commands.CommandCaller;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.generator.AugmentedPopulator;
2015-07-27 16:00:20 +10:00
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.generator.HybridGen;
2015-07-06 01:44:10 +10:00
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.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
2015-01-29 14:20:29 +11:00
import com.intellectualcrafters.plot.util.ClusterManager;
2015-02-20 22:23:48 +11:00
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
2015-07-27 16:00:20 +10:00
import com.intellectualcrafters.plot.util.StringMan;
import com.plotsquared.bukkit.util.SetupUtils;
2015-07-26 21:33:54 +02:00
import com.plotsquared.bukkit.util.UUIDHandler;
2015-01-29 14:20:29 +11:00
2015-07-26 21:33:54 +02:00
@CommandDeclaration(
command = "cluser",
aliases = {"clusters"},
category = CommandCategory.ACTIONS,
requiredType = PlotPlayer.class,
permission = "plots.cluster",
description = "Manage a plot cluster"
)
2015-01-29 14:20:29 +11:00
public class Cluster extends SubCommand {
2015-02-23 12:32:27 +11:00
2015-01-29 14:20:29 +11:00
@Override
2015-07-26 21:33:54 +02:00
public boolean onCommand(final CommandCaller caller, final String ... args) {
final PlotPlayer plr = (PlotPlayer) caller.getSuperCaller();
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
2015-01-29 14:20:29 +11:00
if (args.length == 0) {
// return arguments
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
final String sub = args[0].toLowerCase();
2015-01-29 14:20:29 +11:00
switch (sub) {
2015-01-31 18:09:48 +11:00
case "l":
2015-01-29 14:20:29 +11:00
case "list": {
if (!Permissions.hasPermission(plr, "plots.cluster.list")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.list");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 1) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-22 17:05:35 +11:00
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getLocation().getWorld());
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
2015-02-20 17:34:19 +11:00
for (final PlotCluster cluster : clusters) {
2015-01-29 14:20:29 +11:00
// Ignore unmanaged clusters
2015-02-20 17:34:19 +11:00
final String name = "'" + cluster.getName() + "' : " + cluster.toString();
2015-01-29 14:20:29 +11:00
if (UUIDHandler.getUUID(plr).equals(cluster.owner)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&a" + name);
2015-02-20 17:34:19 +11:00
} else if (cluster.helpers.contains(UUIDHandler.getUUID(plr))) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&3" + name);
2015-02-20 17:34:19 +11:00
} else if (cluster.invited.contains(UUIDHandler.getUUID(plr))) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, "&9" + name);
2015-02-20 17:34:19 +11:00
} else {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_LIST_ELEMENT, cluster.toString());
2015-01-29 14:20:29 +11:00
}
}
return true;
}
2015-01-31 18:09:48 +11:00
case "c":
2015-01-29 14:20:29 +11:00
case "create": {
if (!Permissions.hasPermission(plr, "plots.cluster.create")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 4) {
2015-02-20 17:34:19 +11:00
final PlotId id = ClusterManager.estimatePlotId(plr.getLocation());
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create <name> <id-bot> <id-top>");
MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id);
2015-01-29 14:20:29 +11:00
return false;
}
// check pos1 / pos2
2015-07-21 18:51:21 +10:00
PlotId pos1 = MainUtil.parseId(args[2]);
PlotId pos2 = MainUtil.parseId(args[3]);
2015-02-20 17:34:19 +11:00
if ((pos1 == null) || (pos2 == null)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
2015-01-29 14:20:29 +11:00
return false;
}
// check if name is taken
2015-02-20 17:34:19 +11:00
final String name = args[1];
2015-02-22 17:05:35 +11:00
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
2015-01-29 14:20:29 +11:00
if (name.equals(cluster.getName())) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
2015-02-20 17:34:19 +11:00
return false;
2015-01-29 14:20:29 +11:00
}
}
//check if overlap
2015-02-20 17:34:19 +11:00
final PlotClusterId id = new PlotClusterId(pos1, pos2);
2015-02-22 17:05:35 +11:00
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
2015-07-21 18:51:21 +10:00
if ((intersects.size() > 0)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
2015-02-20 17:34:19 +11:00
return false;
2015-01-29 14:20:29 +11:00
}
2015-07-21 18:51:21 +10:00
if ((pos2.x < pos1.x) || (pos2.y < pos1.y) ) {
pos1 = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y));
pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y));
}
2015-01-29 14:20:29 +11:00
// create cluster
2015-02-22 17:05:35 +11:00
final String world = plr.getLocation().getWorld();
2015-02-20 17:34:19 +11:00
final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
2015-01-29 14:20:29 +11:00
cluster.settings.setAlias(name);
DBFunc.createCluster(world, cluster);
2015-01-29 18:45:14 +11:00
if (!ClusterManager.clusters.containsKey(world)) {
ClusterManager.clusters.put(world, new HashSet<PlotCluster>());
}
2015-01-29 14:20:29 +11:00
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()) {
2015-02-20 17:34:19 +11:00
final PlotCluster current = ClusterManager.getCluster(plot);
2015-04-07 23:21:51 +10:00
if (cluster.equals(current) && !cluster.isAdded(plot.owner)) {
2015-03-20 15:11:02 +11:00
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);
2015-01-31 18:09:48 +11:00
}
else {
final String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin");
2015-07-27 16:00:20 +10:00
BukkitPlotGenerator generator;
if (gen_string == null) {
generator = new HybridGen(world);
} else {
2015-07-27 16:00:20 +10:00
ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator;
if (chunkgen instanceof BukkitPlotGenerator) {
generator = (BukkitPlotGenerator) chunkgen;
}
else {
MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ","));
return false;
}
}
new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "disband":
case "del":
2015-01-29 14:20:29 +11:00
case "delete": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
if ((args.length != 1) && (args.length != 2)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]");
2015-01-29 14:20:29 +11:00
return false;
}
2015-01-29 18:45:14 +11:00
PlotCluster cluster;
if (args.length == 2) {
2015-02-22 17:05:35 +11:00
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
2015-01-29 18:45:14 +11:00
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
2015-01-29 18:45:14 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
} else {
2015-01-29 18:45:14 +11:00
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
2015-01-29 18:45:14 +11:00
return false;
}
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.delete.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.delete.other");
return false;
}
}
final PlotWorld plotworld = PS.get().getPlotWorld(plr.getLocation().getWorld());
2015-02-08 10:44:53 +11:00
if (plotworld.TYPE == 2) {
2015-02-20 17:34:19 +11:00
final ArrayList<Plot> toRemove = new ArrayList<>();
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
2015-02-20 17:34:19 +11:00
final PlotCluster other = ClusterManager.getCluster(plot);
2015-01-29 18:45:14 +11:00
if (cluster.equals(other)) {
2015-01-31 18:09:48 +11:00
toRemove.add(plot);
}
}
2015-02-20 17:34:19 +11:00
for (final Plot plot : toRemove) {
2015-07-04 16:37:33 +10:00
plot.unclaim();
2015-01-31 18:09:48 +11:00
}
}
2015-01-29 18:45:14 +11:00
DBFunc.delete(cluster);
2015-02-08 10:44:53 +11:00
if (plotworld.TYPE == 2) {
2015-02-22 17:05:35 +11:00
AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster);
2015-01-31 18:09:48 +11:00
}
ClusterManager.last = null;
ClusterManager.clusters.get(cluster.world).remove(cluster);
ClusterManager.regenCluster(cluster);
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_DELETED);
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "res":
2015-01-29 14:20:29 +11:00
case "resize": {
if (!Permissions.hasPermission(plr, "plots.cluster.resize")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 3) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster resize <pos1> <pos2>");
2015-01-29 14:20:29 +11:00
return false;
}
// check pos1 / pos2
2015-02-20 22:23:48 +11:00
final PlotId pos1 = MainUtil.parseId(args[1]);
final PlotId pos2 = MainUtil.parseId(args[2]);
2015-02-20 17:34:19 +11:00
if ((pos1 == null) || (pos2 == null)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
2015-01-29 14:20:29 +11:00
return false;
}
// check if in cluster
2015-02-20 17:34:19 +11:00
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
2015-01-29 14:20:29 +11:00
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
2015-01-29 14:20:29 +11:00
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.resize.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.resize.other");
return false;
}
}
2015-01-29 14:20:29 +11:00
//check if overlap
2015-02-20 17:34:19 +11:00
final PlotClusterId id = new PlotClusterId(pos1, pos2);
2015-02-22 17:05:35 +11:00
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getLocation().getWorld(), id);
2015-01-31 18:09:48 +11:00
if (intersects.size() > 1) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
2015-02-20 17:34:19 +11:00
return false;
2015-01-29 14:20:29 +11:00
}
// resize cluster
DBFunc.resizeCluster(cluster, id);
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_RESIZED);
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "reg":
case "regenerate":
case "regen": {
if (!Permissions.hasPermission(plr, "plots.cluster.delete")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen");
2015-01-31 18:09:48 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
if ((args.length != 1) && (args.length != 2)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]");
2015-01-31 18:09:48 +11:00
return false;
}
PlotCluster cluster;
if (args.length == 2) {
2015-02-22 17:05:35 +11:00
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
2015-01-31 18:09:48 +11:00
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
2015-01-31 18:09:48 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
} else {
2015-01-31 18:09:48 +11:00
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
2015-01-31 18:09:48 +11:00
return false;
}
}
if (!cluster.owner.equals(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other");
2015-01-31 18:09:48 +11:00
return false;
}
}
ClusterManager.regenCluster(cluster);
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED);
2015-01-31 18:09:48 +11:00
return true;
}
2015-02-20 17:34:19 +11:00
case "add":
case "inv":
2015-01-29 14:20:29 +11:00
case "invite": {
if (!Permissions.hasPermission(plr, "plots.cluster.invite")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 2) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster invite <player>");
2015-01-29 14:20:29 +11:00
return false;
}
// check if in cluster
2015-02-20 17:34:19 +11:00
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
2015-01-29 14:20:29 +11:00
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
2015-01-29 14:20:29 +11:00
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.invite.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.invite.other");
return false;
}
}
2015-01-29 14:20:29 +11:00
// check uuid
2015-02-20 17:34:19 +11:00
final UUID uuid = UUIDHandler.getUUID(args[1]);
2015-01-29 14:20:29 +11:00
if (uuid == null) {
2015-04-07 23:28:41 +10:00
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
2015-01-29 14:20:29 +11:00
return false;
}
2015-04-07 23:21:51 +10:00
if (!cluster.isAdded(uuid)) {
2015-01-29 14:20:29 +11:00
// add the user if not added
cluster.invited.add(uuid);
2015-02-22 17:05:35 +11:00
final String world = plr.getLocation().getWorld();
2015-01-29 14:20:29 +11:00
DBFunc.setInvited(world, cluster, uuid);
2015-02-23 12:32:27 +11:00
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
2015-01-29 14:20:29 +11:00
if (player != null) {
2015-02-22 17:05:35 +11:00
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
2015-01-29 14:20:29 +11:00
}
}
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_ADDED_USER);
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "k":
case "remove":
2015-01-29 14:20:29 +11:00
case "kick": {
if (!Permissions.hasPermission(plr, "plots.cluster.kick")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 2) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick <player>");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.kick.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.kick.other");
return false;
}
}
// check uuid
2015-02-20 17:34:19 +11:00
final UUID uuid = UUIDHandler.getUUID(args[1]);
if (uuid == null) {
2015-02-21 22:24:46 +11:00
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
2015-04-07 23:21:51 +10:00
if (uuid.equals(UUIDHandler.getUUID(plr)) || uuid.equals(cluster.owner) || !cluster.isAdded(uuid)) {
2015-02-21 22:24:46 +11:00
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);
2015-02-23 12:32:27 +11:00
final PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) {
2015-02-22 17:05:35 +11:00
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
}
2015-07-04 16:37:33 +10:00
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
2015-02-20 17:34:19 +11:00
final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) {
2015-02-22 17:05:35 +11:00
final String world = plr.getLocation().getWorld();
2015-07-04 16:37:33 +10:00
plot.unclaim();
}
}
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_KICKED_USER);
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "quit":
2015-01-29 14:20:29 +11:00
case "leave": {
if (!Permissions.hasPermission(plr, "plots.cluster.leave")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.leave");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
if ((args.length != 1) && (args.length != 2)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]");
2015-01-29 14:20:29 +11:00
return false;
}
PlotCluster cluster;
if (args.length == 2) {
2015-02-22 17:05:35 +11:00
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
2015-02-20 17:34:19 +11:00
} else {
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
2015-02-20 17:34:19 +11:00
final UUID uuid = UUIDHandler.getUUID(plr);
2015-04-07 23:21:51 +10:00
if (!cluster.isAdded(uuid)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_NOT_ADDED);
return false;
}
if (uuid.equals(cluster.owner)) {
2015-02-21 22:24:46 +11:00
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);
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
2015-07-04 16:37:33 +10:00
for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
2015-02-20 17:34:19 +11:00
final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) {
2015-02-22 17:05:35 +11:00
final String world = plr.getLocation().getWorld();
2015-07-04 16:37:33 +10:00
plot.unclaim();
}
}
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "admin":
case "helper":
2015-01-29 14:20:29 +11:00
case "helpers": {
if (!Permissions.hasPermission(plr, "plots.cluster.helpers")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.helpers");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 3) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
2015-02-20 17:34:19 +11:00
final UUID uuid = UUIDHandler.getUUID(args[2]);
if (uuid == null) {
2015-04-07 23:28:41 +10:00
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[2]);
return false;
}
if (args[1].toLowerCase().equals("add")) {
cluster.helpers.add(uuid);
DBFunc.setHelper(cluster, uuid);
2015-02-21 22:24:46 +11:00
return MainUtil.sendMessage(plr, C.CLUSTER_ADDED_HELPER);
}
if (args[1].toLowerCase().equals("remove")) {
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
2015-02-21 22:24:46 +11:00
return MainUtil.sendMessage(plr, C.CLUSTER_REMOVED_HELPER);
}
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers <add|remove> <player>");
return false;
2015-01-29 14:20:29 +11:00
}
2015-01-31 18:09:48 +11:00
case "spawn":
case "home":
2015-01-29 14:20:29 +11:00
case "tp": {
if (!Permissions.hasPermission(plr, "plots.cluster.tp")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp");
2015-01-29 14:20:29 +11:00
return false;
}
if (args.length != 2) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-22 17:05:35 +11:00
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
2015-02-20 17:34:19 +11:00
final UUID uuid = UUIDHandler.getUUID(plr);
2015-04-07 23:21:51 +10:00
if (!cluster.isAdded(uuid)) {
if (!Permissions.hasPermission(plr, "plots.cluster.tp.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.tp.other");
return false;
}
}
plr.teleport(ClusterManager.getHome(cluster));
2015-02-21 22:24:46 +11:00
return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING);
2015-01-29 14:20:29 +11:00
}
2015-01-31 18:09:48 +11:00
case "i":
case "info":
case "show":
case "information": {
if (!Permissions.hasPermission(plr, "plots.cluster.info")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.info");
2015-01-29 14:20:29 +11:00
return false;
}
2015-02-20 17:34:19 +11:00
if ((args.length != 1) && (args.length != 2)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]");
2015-01-29 14:20:29 +11:00
return false;
}
PlotCluster cluster;
if (args.length == 2) {
2015-02-22 17:05:35 +11:00
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false;
}
2015-02-20 17:34:19 +11:00
} else {
cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
}
2015-02-20 17:34:19 +11:00
final String id = cluster.toString();
String owner = UUIDHandler.getName(cluster.owner);
if (owner == null) {
owner = "unknown";
}
2015-02-20 17:34:19 +11:00
final String name = cluster.getName();
final String size = ((cluster.getP2().x - cluster.getP1().x) + 1) + "x" + ((cluster.getP2().y - cluster.getP1().y) + 1);
2015-04-07 23:21:51 +10:00
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);
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, message);
2015-01-29 14:20:29 +11:00
return true;
}
2015-01-31 18:09:48 +11:00
case "sh":
case "setspawn":
case "sethome": {
if (!Permissions.hasPermission(plr, "plots.cluster.sethome")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome");
return false;
}
2015-02-20 17:34:19 +11:00
if ((args.length != 1) && (args.length != 2)) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome");
return false;
}
2015-02-20 17:34:19 +11:00
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation());
if (cluster == null) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER);
return false;
}
if (!cluster.hasHelperRights(UUIDHandler.getUUID(plr))) {
if (!Permissions.hasPermission(plr, "plots.cluster.sethome.other")) {
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.sethome.other");
return false;
}
}
2015-02-20 17:34:19 +11:00
final Location base = ClusterManager.getClusterBottom(cluster);
2015-02-22 17:05:35 +11:00
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);
2015-02-22 17:05:35 +11:00
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
2015-02-21 22:24:46 +11:00
return MainUtil.sendMessage(plr, C.POSITION_SET);
}
2015-01-29 14:20:29 +11:00
}
2015-02-21 22:24:46 +11:00
MainUtil.sendMessage(plr, C.CLUSTER_AVAILABLE_ARGS);
2015-01-29 14:20:29 +11:00
return false;
}
}