This commit is contained in:
boy0001 2015-02-22 17:05:35 +11:00
parent 2e7b5e794f
commit e572428e45
4 changed files with 42 additions and 87 deletions

View File

@ -28,7 +28,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class Clear extends SubCommand { public class Clear extends SubCommand {

View File

@ -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;
}
}

View File

@ -25,15 +25,12 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; 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.PlotSquared;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.generator.AugmentedPopulator; import com.intellectualcrafters.plot.generator.AugmentedPopulator;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotClusterId; 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.object.PlotWorld;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class Cluster extends SubCommand { public class Cluster extends SubCommand {
@ -69,7 +67,7 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list");
return false; 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() + ""); MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + "");
for (final PlotCluster cluster : clusters) { for (final PlotCluster cluster : clusters) {
// Ignore unmanaged clusters // Ignore unmanaged clusters
@ -107,7 +105,7 @@ public class Cluster extends SubCommand {
} }
// check if name is taken // check if name is taken
final String name = args[1]; 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())) { if (name.equals(cluster.getName())) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false; return false;
@ -115,13 +113,13 @@ public class Cluster extends SubCommand {
} }
//check if overlap //check if overlap
final PlotClusterId id = new PlotClusterId(pos1, pos2); 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)) { if ((intersects.size() > 0) || (pos2.x < pos1.x) || (pos2.y < pos1.y)) {
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + ""); MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + "");
return false; return false;
} }
// create cluster // 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)); final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr));
cluster.settings.setAlias(name); cluster.settings.setAlias(name);
DBFunc.createCluster(world, cluster); DBFunc.createCluster(world, cluster);
@ -130,7 +128,7 @@ public class Cluster extends SubCommand {
} }
ClusterManager.clusters.get(world).add(cluster); ClusterManager.clusters.get(world).add(cluster);
// Add any existing plots to the current 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); final PlotCluster current = ClusterManager.getCluster(plot);
if (cluster.equals(current) && !cluster.hasRights(plot.owner)) { if (cluster.equals(current) && !cluster.hasRights(plot.owner)) {
cluster.invited.add(plot.owner); cluster.invited.add(plot.owner);
@ -139,7 +137,7 @@ public class Cluster extends SubCommand {
} }
if (!PlotSquared.isPlotWorld(world)) { if (!PlotSquared.isPlotWorld(world)) {
PlotSquared.config.createSection("worlds." + world); PlotSquared.config.createSection("worlds." + world);
PlotSquared.loadWorld(plr.getWorld()); PlotSquared.loadWorld(world, null);
} }
MainUtil.sendMessage(plr, C.CLUSTER_ADDED); MainUtil.sendMessage(plr, C.CLUSTER_ADDED);
return true; return true;
@ -157,7 +155,7 @@ public class Cluster extends SubCommand {
} }
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]); cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
@ -175,10 +173,10 @@ public class Cluster extends SubCommand {
return false; return false;
} }
} }
final PlotWorld plotworld = PlotSquared.getPlotWorld(plr.getWorld()); final PlotWorld plotworld = PlotSquared.getPlotWorld(plr.getLocation().getWorld());
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
final ArrayList<Plot> toRemove = new ArrayList<>(); 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); final PlotCluster other = ClusterManager.getCluster(plot);
if (cluster.equals(other)) { if (cluster.equals(other)) {
toRemove.add(plot); toRemove.add(plot);
@ -190,14 +188,7 @@ public class Cluster extends SubCommand {
} }
DBFunc.delete(cluster); DBFunc.delete(cluster);
if (plotworld.TYPE == 2) { if (plotworld.TYPE == 2) {
for (final Iterator<BlockPopulator> iterator = plr.getWorld().getPopulators().iterator(); iterator.hasNext();) { AugmentedPopulator.removePopulator(plr.getLocation().getWorld(), cluster);
final BlockPopulator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
iterator.remove();
}
}
}
} }
for (final String set : ClusterManager.clusters.keySet()) { for (final String set : ClusterManager.clusters.keySet()) {
} }
@ -238,7 +229,7 @@ public class Cluster extends SubCommand {
} }
//check if overlap //check if overlap
final PlotClusterId id = new PlotClusterId(pos1, pos2); 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) { if (intersects.size() > 1) {
MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + ""); MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + "");
return false; return false;
@ -261,7 +252,7 @@ public class Cluster extends SubCommand {
} }
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]); cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
@ -315,11 +306,11 @@ public class Cluster extends SubCommand {
if (!cluster.hasRights(uuid)) { if (!cluster.hasRights(uuid)) {
// add the user if not added // add the user if not added
cluster.invited.add(uuid); cluster.invited.add(uuid);
final String world = plr.getWorld().getName(); final String world = plr.getLocation().getWorld();
DBFunc.setInvited(world, cluster, uuid); DBFunc.setInvited(world, cluster, uuid);
final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) { 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); MainUtil.sendMessage(plr, C.CLUSTER_ADDED_USER);
@ -364,14 +355,14 @@ public class Cluster extends SubCommand {
} }
cluster.invited.remove(uuid); cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid); DBFunc.removeInvited(cluster, uuid);
final Player player = UUIDHandler.uuidWrapper.getPlayer(uuid); PlotPlayer player = UUIDHandler.getPlayer(uuid);
if (player != null) { 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); final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
final String world = plr.getWorld().getName(); final String world = plr.getLocation().getWorld();
DBFunc.delete(world, plot); DBFunc.delete(world, plot);
} }
} }
@ -390,7 +381,7 @@ public class Cluster extends SubCommand {
} }
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]); cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
@ -418,10 +409,10 @@ public class Cluster extends SubCommand {
cluster.invited.remove(uuid); cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid); DBFunc.removeInvited(cluster, uuid);
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName()); 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); final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
final String world = plr.getWorld().getName(); final String world = plr.getLocation().getWorld();
DBFunc.delete(world, plot); DBFunc.delete(world, plot);
} }
} }
@ -470,7 +461,7 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>"); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp <name>");
return false; 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) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
@ -499,7 +490,7 @@ public class Cluster extends SubCommand {
} }
PlotCluster cluster; PlotCluster cluster;
if (args.length == 2) { if (args.length == 2) {
cluster = ClusterManager.getCluster(plr.getWorld().getName(), args[1]); cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]);
if (cluster == null) { if (cluster == null) {
MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]);
return false; return false;
@ -551,11 +542,10 @@ public class Cluster extends SubCommand {
} }
} }
final Location base = ClusterManager.getClusterBottom(cluster); final Location base = ClusterManager.getClusterBottom(cluster);
base.setY(0); final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ());
final Location relative = plr.getLocation().subtract(base); final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
final BlockLoc blockloc = new BlockLoc(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ());
cluster.settings.setPosition(blockloc); 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); return MainUtil.sendMessage(plr, C.POSITION_SET);
} }
} }

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.Random; import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -36,6 +37,18 @@ public class AugmentedPopulator extends BlockPopulator {
private final int tx; private final int tx;
private final int tz; 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) { 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 y = (i << 4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8)); final int a = (j - ((y & 0xF) << 8));