mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2025-08-10 22:35:29 +00:00
cleanup
This commit is contained in:
parent
dea6e84407
commit
0d382ac9c3
215 changed files with 4930 additions and 6474 deletions
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -24,284 +23,269 @@ import com.intellectualcrafters.plot.object.PlotClusterId;
|
|||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitTaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
||||
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.util.bukkit.SetBlockManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class ClusterManager {
|
||||
public static HashMap<String, HashSet<PlotCluster>> clusters;
|
||||
private static HashSet<String> regenerating = new HashSet<>();
|
||||
public static PlotCluster last;
|
||||
|
||||
public static boolean contains(PlotCluster cluster, PlotId id) {
|
||||
if (cluster.getP1().x <= id.x && cluster.getP1().y <= id.y && cluster.getP2().x >= id.x && cluster.getP2().y >= id.y) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HashSet<PlotCluster> getClusters(World world) {
|
||||
return getClusters(world.getName());
|
||||
}
|
||||
|
||||
public static HashSet<PlotCluster> getClusters(String world) {
|
||||
if (clusters.containsKey(world)) {
|
||||
return clusters.get(world);
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
public static Location getHome(PlotCluster cluster) {
|
||||
BlockLoc home = cluster.settings.getPosition();
|
||||
Location toReturn;
|
||||
if (home.y == 0) {
|
||||
// default pos
|
||||
PlotId center = getCenterPlot(cluster);
|
||||
toReturn = PlotHelper.getPlotHome(cluster.world, center);
|
||||
if (toReturn.getY() == 0) {
|
||||
final PlotManager manager = PlotSquared.getPlotManager(cluster.world);
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(cluster.world);
|
||||
final Location loc = manager.getSignLoc(plotworld, PlotHelper.getPlot(cluster.world, center));
|
||||
toReturn.setY(loc.getY());
|
||||
}
|
||||
}
|
||||
else {
|
||||
toReturn = getClusterBottom(cluster).add(home.x, home.y, home.z);
|
||||
}
|
||||
int max = BukkitUtil.getHeighestBlock(cluster.world, toReturn.getX(), toReturn.getZ());
|
||||
if (max > toReturn.getY()) {
|
||||
toReturn.setY(max);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static PlotId getCenterPlot(PlotCluster cluster) {
|
||||
PlotId bot = cluster.getP1();
|
||||
PlotId top = cluster.getP2();
|
||||
return new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
||||
}
|
||||
|
||||
public static Location getClusterBottom(PlotCluster cluster) {
|
||||
String world = cluster.world;
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
return manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
|
||||
}
|
||||
|
||||
public static Location getClusterTop(PlotCluster cluster) {
|
||||
String world = cluster.world;
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
return manager.getPlotTopLocAbs(plotworld, cluster.getP2());
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(String world, String name) {
|
||||
if (!clusters.containsKey(world)) {
|
||||
return null;
|
||||
}
|
||||
for (PlotCluster cluster : clusters.get(world)) {
|
||||
if (cluster.getName().equals(name)) {
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean contains(PlotCluster cluster, Location loc) {
|
||||
String world = loc.getWorld();
|
||||
PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
|
||||
Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1,0,1);
|
||||
if (bot.getX() < loc.getX() && bot.getZ() < loc.getZ() && top.getX() > loc.getX() && top.getZ() > loc.getZ()) {
|
||||
public static HashMap<String, HashSet<PlotCluster>> clusters;
|
||||
private static HashSet<String> regenerating = new HashSet<>();
|
||||
public static PlotCluster last;
|
||||
|
||||
public static boolean contains(final PlotCluster cluster, final PlotId id) {
|
||||
if ((cluster.getP1().x <= id.x) && (cluster.getP1().y <= id.y) && (cluster.getP2().x >= id.x) && (cluster.getP2().y >= id.y)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HashSet<PlotCluster> getIntersects(String world, PlotClusterId id) {
|
||||
if (!clusters.containsKey(world)) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
HashSet<PlotCluster> list = new HashSet<PlotCluster>();
|
||||
for (PlotCluster cluster : clusters.get(world)) {
|
||||
if (intersects(cluster, id)) {
|
||||
list.add(cluster);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean intersects(PlotCluster cluster, PlotClusterId id) {
|
||||
PlotId pos1 = cluster.getP1();
|
||||
PlotId pos2 = cluster.getP2();
|
||||
if (pos1.x <= id.pos2.x && pos2.x >= id.pos1.x && pos1.y <= id.pos2.y && pos2.y >= id.pos1.y) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
public static HashSet<PlotCluster> getClusters(final World world) {
|
||||
return getClusters(world.getName());
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(Plot plot) {
|
||||
return getCluster(plot.world, plot.id);
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(Location loc) {
|
||||
String world = loc.getWorld();
|
||||
if (last != null && last.world.equals(world)) {
|
||||
if (contains(last, loc)) {
|
||||
return last;
|
||||
}
|
||||
}
|
||||
if (clusters == null) {
|
||||
return null;
|
||||
}
|
||||
HashSet<PlotCluster> local = clusters.get(world);
|
||||
if (local == null) {
|
||||
return null;
|
||||
}
|
||||
for (PlotCluster cluster : local) {
|
||||
if (contains(cluster, loc)) {
|
||||
last = cluster;
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(String world, PlotId id) {
|
||||
if (last != null && last.world.equals(world)) {
|
||||
if (contains(last, id)) {
|
||||
return last;
|
||||
}
|
||||
}
|
||||
if (clusters == null) {
|
||||
return null;
|
||||
}
|
||||
HashSet<PlotCluster> local = clusters.get(world);
|
||||
if (local == null) {
|
||||
return null;
|
||||
}
|
||||
for (PlotCluster cluster : local) {
|
||||
if (contains(cluster, id)) {
|
||||
last = cluster;
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean removeCluster(PlotCluster cluster) {
|
||||
if (clusters != null) {
|
||||
if (clusters.containsKey(cluster.world)) {
|
||||
clusters.get(cluster.world).remove(cluster);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PlotClusterId getClusterId(PlotCluster cluster) {
|
||||
return new PlotClusterId(cluster.getP1(), cluster.getP2());
|
||||
}
|
||||
|
||||
public static AugmentedPopulator getPopulator(PlotCluster cluster) {
|
||||
World world = Bukkit.getWorld(cluster.world);
|
||||
for (Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();) {
|
||||
BlockPopulator populator = iterator.next();
|
||||
|
||||
public static HashSet<PlotCluster> getClusters(final String world) {
|
||||
if (clusters.containsKey(world)) {
|
||||
return clusters.get(world);
|
||||
}
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
public static Location getHome(final PlotCluster cluster) {
|
||||
final BlockLoc home = cluster.settings.getPosition();
|
||||
Location toReturn;
|
||||
if (home.y == 0) {
|
||||
// default pos
|
||||
final PlotId center = getCenterPlot(cluster);
|
||||
toReturn = PlotHelper.getPlotHome(cluster.world, center);
|
||||
if (toReturn.getY() == 0) {
|
||||
final PlotManager manager = PlotSquared.getPlotManager(cluster.world);
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(cluster.world);
|
||||
final Location loc = manager.getSignLoc(plotworld, PlotHelper.getPlot(cluster.world, center));
|
||||
toReturn.setY(loc.getY());
|
||||
}
|
||||
} else {
|
||||
toReturn = getClusterBottom(cluster).add(home.x, home.y, home.z);
|
||||
}
|
||||
final int max = BukkitUtil.getHeighestBlock(cluster.world, toReturn.getX(), toReturn.getZ());
|
||||
if (max > toReturn.getY()) {
|
||||
toReturn.setY(max);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static PlotId getCenterPlot(final PlotCluster cluster) {
|
||||
final PlotId bot = cluster.getP1();
|
||||
final PlotId top = cluster.getP2();
|
||||
return new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2);
|
||||
}
|
||||
|
||||
public static Location getClusterBottom(final PlotCluster cluster) {
|
||||
final String world = cluster.world;
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
return manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
|
||||
}
|
||||
|
||||
public static Location getClusterTop(final PlotCluster cluster) {
|
||||
final String world = cluster.world;
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
return manager.getPlotTopLocAbs(plotworld, cluster.getP2());
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(final String world, final String name) {
|
||||
if (!clusters.containsKey(world)) {
|
||||
return null;
|
||||
}
|
||||
for (final PlotCluster cluster : clusters.get(world)) {
|
||||
if (cluster.getName().equals(name)) {
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean contains(final PlotCluster cluster, final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
final Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
|
||||
final Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
|
||||
if ((bot.getX() < loc.getX()) && (bot.getZ() < loc.getZ()) && (top.getX() > loc.getX()) && (top.getZ() > loc.getZ())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static HashSet<PlotCluster> getIntersects(final String world, final PlotClusterId id) {
|
||||
if (!clusters.containsKey(world)) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
final HashSet<PlotCluster> list = new HashSet<PlotCluster>();
|
||||
for (final PlotCluster cluster : clusters.get(world)) {
|
||||
if (intersects(cluster, id)) {
|
||||
list.add(cluster);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static boolean intersects(final PlotCluster cluster, final PlotClusterId id) {
|
||||
final PlotId pos1 = cluster.getP1();
|
||||
final PlotId pos2 = cluster.getP2();
|
||||
if ((pos1.x <= id.pos2.x) && (pos2.x >= id.pos1.x) && (pos1.y <= id.pos2.y) && (pos2.y >= id.pos1.y)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(final Plot plot) {
|
||||
return getCluster(plot.world, plot.id);
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(final Location loc) {
|
||||
final String world = loc.getWorld();
|
||||
if ((last != null) && last.world.equals(world)) {
|
||||
if (contains(last, loc)) {
|
||||
return last;
|
||||
}
|
||||
}
|
||||
if (clusters == null) {
|
||||
return null;
|
||||
}
|
||||
final HashSet<PlotCluster> local = clusters.get(world);
|
||||
if (local == null) {
|
||||
return null;
|
||||
}
|
||||
for (final PlotCluster cluster : local) {
|
||||
if (contains(cluster, loc)) {
|
||||
last = cluster;
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PlotCluster getCluster(final String world, final PlotId id) {
|
||||
if ((last != null) && last.world.equals(world)) {
|
||||
if (contains(last, id)) {
|
||||
return last;
|
||||
}
|
||||
}
|
||||
if (clusters == null) {
|
||||
return null;
|
||||
}
|
||||
final HashSet<PlotCluster> local = clusters.get(world);
|
||||
if (local == null) {
|
||||
return null;
|
||||
}
|
||||
for (final PlotCluster cluster : local) {
|
||||
if (contains(cluster, id)) {
|
||||
last = cluster;
|
||||
return cluster;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean removeCluster(final PlotCluster cluster) {
|
||||
if (clusters != null) {
|
||||
if (clusters.containsKey(cluster.world)) {
|
||||
clusters.get(cluster.world).remove(cluster);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static PlotClusterId getClusterId(final PlotCluster cluster) {
|
||||
return new PlotClusterId(cluster.getP1(), cluster.getP2());
|
||||
}
|
||||
|
||||
public static AugmentedPopulator getPopulator(final PlotCluster cluster) {
|
||||
final World world = Bukkit.getWorld(cluster.world);
|
||||
for (final BlockPopulator populator : world.getPopulators()) {
|
||||
if (populator instanceof AugmentedPopulator) {
|
||||
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
|
||||
return (AugmentedPopulator) populator;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PlotId estimatePlotId(Location loc) {
|
||||
PlotId a = new PlotId(0, 0);
|
||||
PlotId b = new PlotId(1, 1);
|
||||
int xw;
|
||||
int zw;
|
||||
|
||||
String world = loc.getWorld();
|
||||
PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
if (plotworld == null) {
|
||||
xw = 39;
|
||||
zw = 39;
|
||||
}
|
||||
else {
|
||||
PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
Location al = manager.getPlotBottomLocAbs(plotworld, a);
|
||||
Location bl = manager.getPlotBottomLocAbs(plotworld, b);
|
||||
|
||||
xw = bl.getX() - al.getX();
|
||||
zw = bl.getZ() - al.getZ();
|
||||
}
|
||||
|
||||
int x = loc.getX();
|
||||
int z = loc.getZ();
|
||||
|
||||
return new PlotId((x/xw) + 1,(z/zw) + 1);
|
||||
}
|
||||
|
||||
public static void regenCluster(final PlotCluster cluster) {
|
||||
if (regenerating.contains(cluster.world + ":" + cluster.getName())) {
|
||||
return;
|
||||
}
|
||||
regenerating.add(cluster.world + ":" + cluster.getName());
|
||||
int interval = 1;
|
||||
int i = 0;
|
||||
final Random rand = new Random();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static PlotId estimatePlotId(final Location loc) {
|
||||
final PlotId a = new PlotId(0, 0);
|
||||
final PlotId b = new PlotId(1, 1);
|
||||
int xw;
|
||||
int zw;
|
||||
final String world = loc.getWorld();
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(world);
|
||||
if (plotworld == null) {
|
||||
xw = 39;
|
||||
zw = 39;
|
||||
} else {
|
||||
final PlotManager manager = PlotSquared.getPlotManager(world);
|
||||
final Location al = manager.getPlotBottomLocAbs(plotworld, a);
|
||||
final Location bl = manager.getPlotBottomLocAbs(plotworld, b);
|
||||
xw = bl.getX() - al.getX();
|
||||
zw = bl.getZ() - al.getZ();
|
||||
}
|
||||
final int x = loc.getX();
|
||||
final int z = loc.getZ();
|
||||
return new PlotId((x / xw) + 1, (z / zw) + 1);
|
||||
}
|
||||
|
||||
public static void regenCluster(final PlotCluster cluster) {
|
||||
if (regenerating.contains(cluster.world + ":" + cluster.getName())) {
|
||||
return;
|
||||
}
|
||||
regenerating.add(cluster.world + ":" + cluster.getName());
|
||||
final int interval = 1;
|
||||
int i = 0;
|
||||
final Random rand = new Random();
|
||||
final World world = Bukkit.getWorld(cluster.world);
|
||||
final PlotWorld plotworld = PlotSquared.getWorldSettings(cluster.world);
|
||||
|
||||
Location bot = getClusterBottom(cluster);
|
||||
Location top = getClusterTop(cluster);
|
||||
|
||||
int minChunkX = bot.getX() >> 4;
|
||||
int maxChunkX = (top.getX() >> 4) + 1;
|
||||
int minChunkZ = bot.getZ() >> 4;
|
||||
int maxChunkZ = (top.getZ() >> 4) + 1;
|
||||
|
||||
final AugmentedPopulator populator = getPopulator(cluster);
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
final Location bot = getClusterBottom(cluster);
|
||||
final Location top = getClusterTop(cluster);
|
||||
final int minChunkX = bot.getX() >> 4;
|
||||
final int maxChunkX = (top.getX() >> 4) + 1;
|
||||
final int minChunkZ = bot.getZ() >> 4;
|
||||
final int maxChunkZ = (top.getZ() >> 4) + 1;
|
||||
final AugmentedPopulator populator = getPopulator(cluster);
|
||||
final ArrayList<Chunk> chunks = new ArrayList<>();
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClusterManager.regenerating.remove(cluster.world + ":" + cluster.getName());
|
||||
Player owner = UUIDHandler.uuidWrapper.getPlayer(cluster.owner);
|
||||
final Player owner = UUIDHandler.uuidWrapper.getPlayer(cluster.owner);
|
||||
if (owner != null) {
|
||||
PlayerFunctions.sendMessage(owner, C.CLEARING_DONE);
|
||||
}
|
||||
}
|
||||
}, interval * chunks.size() + 20);
|
||||
|
||||
// chunks
|
||||
for (int x = minChunkX; x <= maxChunkX; x++) {
|
||||
}, (interval * chunks.size()) + 20);
|
||||
// chunks
|
||||
for (int x = minChunkX; x <= maxChunkX; x++) {
|
||||
for (int z = minChunkZ; z <= maxChunkZ; z++) {
|
||||
final Chunk chunk = world.getChunkAt(x, z);
|
||||
chunks.add(chunk);
|
||||
}
|
||||
}
|
||||
for (final Chunk chunk : chunks) {
|
||||
i+=interval;
|
||||
BukkitTaskManager.runTaskLater(new Runnable() {
|
||||
for (final Chunk chunk : chunks) {
|
||||
i += interval;
|
||||
TaskManager.runTaskLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (populator == null || plotworld.TYPE == 0) {
|
||||
SetBlockManager.setBlockManager.update(Arrays.asList( new Chunk[] {chunk}));
|
||||
|
||||
if ((populator == null) || (plotworld.TYPE == 0)) {
|
||||
SetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
|
||||
world.regenerateChunk(chunk.getX(), chunk.getZ());
|
||||
chunk.unload(true, true);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
populator.populate(world, rand, chunk);
|
||||
}
|
||||
}
|
||||
}, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue