mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-01-19 08:55:25 +01:00
cluster
This commit is contained in:
parent
2e7b5e794f
commit
e572428e45
@ -28,7 +28,6 @@ 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.BukkitPlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Clear extends SubCommand {
|
||||
|
@ -1,47 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// 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.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
|
||||
public class Clipboard extends SubCommand {
|
||||
public Clipboard() {
|
||||
super(Command.CLIPBOARD, "View information about your current copy", "clipboard", CommandCategory.INFO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
if (!currentSelection.containsKey(plr.getName())) {
|
||||
return sendMessage(plr, C.NO_CLIPBOARD);
|
||||
}
|
||||
final PlotSelection selection = currentSelection.get(plr.getName());
|
||||
final PlotId plotId = selection.getPlot().getId();
|
||||
final int width = selection.getWidth();
|
||||
final int total = selection.getBlocks().length;
|
||||
String message = C.CLIPBOARD_INFO.s();
|
||||
message = message.replace("%id", plotId.toString()).replace("%width", width + "").replace("%total", total + "");
|
||||
MainUtil.sendMessage(plr, message);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -25,15 +25,12 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.generator.AugmentedPopulator;
|
||||
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;
|
||||
@ -42,6 +39,7 @@ 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 {
|
||||
@ -69,7 +67,7 @@ public class Cluster extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
|
||||
return false;
|
||||
}
|
||||
final HashSet<PlotCluster> clusters = ClusterManager.getClusters(plr.getWorld());
|
||||
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
|
||||
@ -107,7 +105,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
// check if name is taken
|
||||
final String name = args[1];
|
||||
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getWorld())) {
|
||||
for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) {
|
||||
if (name.equals(cluster.getName())) {
|
||||
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
|
||||
return false;
|
||||
@ -115,13 +113,13 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
//check if overlap
|
||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
|
||||
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.getWorld().getName();
|
||||
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);
|
||||
@ -130,7 +128,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
ClusterManager.clusters.get(world).add(cluster);
|
||||
// Add any existing plots to the current cluster
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getWorld()).values()) {
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(current) && !cluster.hasRights(plot.owner)) {
|
||||
cluster.invited.add(plot.owner);
|
||||
@ -139,7 +137,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
if (!PlotSquared.isPlotWorld(world)) {
|
||||
PlotSquared.config.createSection("worlds." + world);
|
||||
PlotSquared.loadWorld(plr.getWorld());
|
||||
PlotSquared.loadWorld(world, null);
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
|
||||
return true;
|
||||
@ -157,7 +155,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
@ -175,10 +173,10 @@ public class Cluster extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final PlotWorld plotworld = PlotSquared.getPlotWorld(plr.getWorld());
|
||||
final PlotWorld plotworld = PlotSquared.getPlotWorld(plr.getLocation().getWorld());
|
||||
if (plotworld.TYPE == 2) {
|
||||
final ArrayList<Plot> toRemove = new ArrayList<>();
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getWorld()).values()) {
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld()).values()) {
|
||||
final PlotCluster other = ClusterManager.getCluster(plot);
|
||||
if (cluster.equals(other)) {
|
||||
toRemove.add(plot);
|
||||
@ -190,14 +188,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
DBFunc.delete(cluster);
|
||||
if (plotworld.TYPE == 2) {
|
||||
for (final Iterator<BlockPopulator> iterator = plr.getWorld().getPopulators().iterator(); iterator.hasNext();) {
|
||||
final BlockPopulator populator = iterator.next();
|
||||
if (populator instanceof AugmentedPopulator) {
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster);
|
||||
}
|
||||
for (final String set : ClusterManager.clusters.keySet()) {
|
||||
}
|
||||
@ -238,7 +229,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
//check if overlap
|
||||
final PlotClusterId id = new PlotClusterId(pos1, pos2);
|
||||
final HashSet<PlotCluster> intersects = ClusterManager.getIntersects(plr.getWorld().getName(), id);
|
||||
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;
|
||||
@ -261,7 +252,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
@ -315,11 +306,11 @@ public class Cluster extends SubCommand {
|
||||
if (!cluster.hasRights(uuid)) {
|
||||
// add the user if not added
|
||||
cluster.invited.add(uuid);
|
||||
final String world = plr.getWorld().getName();
|
||||
final String world = plr.getLocation().getWorld();
|
||||
DBFunc.setInvited(world, cluster, uuid);
|
||||
final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
||||
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.CLUSTER_INVITED, cluster.getName());
|
||||
MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName());
|
||||
}
|
||||
}
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_ADDED_USER);
|
||||
@ -364,14 +355,14 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid);
|
||||
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.CLUSTER_REMOVED, cluster.getName());
|
||||
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
|
||||
}
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getWorld(), uuid)) {
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld(), uuid)) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if ((current != null) && current.equals(cluster)) {
|
||||
final String world = plr.getWorld().getName();
|
||||
final String world = plr.getLocation().getWorld();
|
||||
DBFunc.delete(world, plot);
|
||||
}
|
||||
}
|
||||
@ -390,7 +381,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
@ -418,10 +409,10 @@ public class Cluster extends SubCommand {
|
||||
cluster.invited.remove(uuid);
|
||||
DBFunc.removeInvited(cluster, uuid);
|
||||
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getWorld(), uuid)) {
|
||||
for (final Plot plot : PlotSquared.getPlots(plr.getLocation().getWorld(), uuid)) {
|
||||
final PlotCluster current = ClusterManager.getCluster(plot);
|
||||
if ((current != null) && current.equals(cluster)) {
|
||||
final String world = plr.getWorld().getName();
|
||||
final String world = plr.getLocation().getWorld();
|
||||
DBFunc.delete(world, plot);
|
||||
}
|
||||
}
|
||||
@ -470,7 +461,7 @@ public class Cluster extends SubCommand {
|
||||
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
|
||||
return false;
|
||||
}
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
||||
final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
@ -499,7 +490,7 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
PlotCluster cluster;
|
||||
if (args.length == 2) {
|
||||
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]);
|
||||
cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
|
||||
if (cluster == null) {
|
||||
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
|
||||
return false;
|
||||
@ -551,11 +542,10 @@ public class Cluster extends SubCommand {
|
||||
}
|
||||
}
|
||||
final Location base = ClusterManager.getClusterBottom(cluster);
|
||||
base.setY(0);
|
||||
final Location relative = plr.getLocation().subtract(base);
|
||||
final BlockLoc blockloc = new BlockLoc(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ());
|
||||
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.getBlockX() + "," + relative.getBlockY() + "," + relative.getBlockZ());
|
||||
DBFunc.setPosition(cluster, relative.getX() + "," + relative.getY() + "," + relative.getZ());
|
||||
return MainUtil.sendMessage(plr, C.POSITION_SET);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.intellectualcrafters.plot.generator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -36,6 +37,18 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
private final int tx;
|
||||
private final int tz;
|
||||
|
||||
public static void removePopulator(String worldname, PlotCluster cluster) {
|
||||
World world = Bukkit.getWorld(worldname);
|
||||
for (final Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();) {
|
||||
final BlockPopulator populator = iterator.next();
|
||||
if (populator instanceof AugmentedPopulator) {
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockWrapper get(final int X, final int Z, final int i, final int j, final short[][] r, final boolean c) {
|
||||
final int y = (i << 4) + (j >> 8);
|
||||
final int a = (j - ((y & 0xF) << 8));
|
||||
|
Loading…
x
Reference in New Issue
Block a user