Inject PlotAreaManager

This commit is contained in:
Alexander Söderberg 2020-07-10 17:32:07 +02:00
parent c37cc40ad9
commit 2dab7c8dda
47 changed files with 450 additions and 295 deletions

View File

@ -180,10 +180,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
private boolean metricsStarted;
@Getter private BackupManager backupManager;
@Getter private PlatformWorldManager<World> worldManager;
private final BukkitPlayerManager playerManager = new BukkitPlayerManager();
private BukkitPlayerManager playerManager;
private EconHandler econ;
private PermHandler perm;
private PlotAreaManager plotAreaManager;
@Override public int[] getServerVersion() {
if (this.version == null) {
try {
@ -213,7 +214,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
this.pluginName = getDescription().getName();
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
new PlotSquared(this, "Bukkit");
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
this.plotAreaManager = plotSquared.getPlotAreaManager();
this.playerManager = new BukkitPlayerManager(this.plotAreaManager);
if (PlotSquared.platform().getServerVersion()[1] < 13) {
System.out.println(
@ -427,10 +430,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
event.printStackTrace();
}
}
final PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
if (this.plotAreaManager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
final SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea();
outer:
for (final World world : Bukkit.getWorlds()) {
@ -624,7 +627,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
@Override @SuppressWarnings("deprecation") public void runEntityTask() {
PlotSquared.log(Captions.PREFIX + "KillAllEntities started.");
TaskManager.runTaskRepeat(() -> PlotSquared.get().getPlotAreaManager().forEachPlotArea(plotArea -> {
TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
final World world = Bukkit.getWorld(plotArea.getWorldName());
try {
if (world == null) {
@ -883,7 +886,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
final String id) {
final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) {
result = new SingleWorldGenerator();
result = new SingleWorldGenerator(this.plotAreaManager);
} else {
result = PlotSquared.platform().getDefaultGenerator();
if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
@ -894,11 +897,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
}
@Override public void registerPlayerEvents() {
final PlayerEvents main = new PlayerEvents();
final PlayerEvents main = new PlayerEvents(this.plotAreaManager);
getServer().getPluginManager().registerEvents(main, this);
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
getServer().getPluginManager().registerEvents(new PaperListener(), this);
getServer().getPluginManager().registerEvents(new PaperListener(this.plotAreaManager), this);
}
PlotListener.startRunnable();
}
@ -982,18 +985,18 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
if (gen instanceof GeneratorWrapper<?>) {
return (GeneratorWrapper<?>) gen;
}
return new BukkitPlotGenerator(world, gen);
return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
} else {
return new BukkitPlotGenerator(world, PlotSquared.platform().getDefaultGenerator());
return new BukkitPlotGenerator(world, PlotSquared.platform().getDefaultGenerator(), this.plotAreaManager);
}
}
@Override public HybridUtils initHybridUtils() {
return new BukkitHybridUtils();
return new BukkitHybridUtils(this.plotAreaManager);
}
@Override public SetupUtils initSetupUtils() {
return new BukkitSetupUtils();
return new BukkitSetupUtils(this.plotAreaManager);
}
@Override public void startMetrics() {
@ -1011,7 +1014,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
}
map.put(plotAreaType.name().toLowerCase(), terrainTypes);
}
for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
final Map<String, Integer> terrainTypeMap =
map.get(plotArea.getType().name().toLowerCase());
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
@ -1040,11 +1043,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
}
@Override public void registerChunkProcessor() {
getServer().getPluginManager().registerEvents(new ChunkListener(), this);
getServer().getPluginManager().registerEvents(new ChunkListener(this.plotAreaManager), this);
}
@Override public void registerWorldEvents() {
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
getServer().getPluginManager().registerEvents(new WorldEvents(this.plotAreaManager), this);
}
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
@ -1072,7 +1075,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
world = Bukkit.getWorld(worldName);
} else {
try {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) {
if (!this.plotAreaManager.hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
} catch (Exception e) {
@ -1086,7 +1089,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
if (gen instanceof BukkitPlotGenerator) {
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
} else if (gen != null) {
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager));
} else if (PlotSquared.get().worlds.contains("worlds." + worldName)) {
PlotSquared.get().loadWorld(worldName, null);
}
@ -1144,7 +1147,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
@NonNull final IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(world, generator);
return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
}
@Override public List<Map.Entry<Map.Entry<String, String>, Boolean>> getPluginIds() {

View File

@ -25,10 +25,10 @@
*/
package com.plotsquared.bukkit.generator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
@ -42,10 +42,14 @@ import java.util.Random;
final class BlockStatePopulator extends BlockPopulator {
private final IndependentPlotGenerator plotGenerator;
private final PlotAreaManager plotAreaManager;
private LocalBlockQueue queue;
public BlockStatePopulator(IndependentPlotGenerator plotGenerator) {
public BlockStatePopulator(@NotNull final IndependentPlotGenerator plotGenerator,
@NotNull final PlotAreaManager plotAreaManager) {
this.plotGenerator = plotGenerator;
this.plotAreaManager = plotAreaManager;
}
@Override
@ -54,7 +58,7 @@ final class BlockStatePopulator extends BlockPopulator {
if (this.queue == null) {
this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
}
final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null);
final PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
if (area == null) {
return;
}

View File

@ -26,8 +26,13 @@
package com.plotsquared.bukkit.generator;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.plot.world.PlotAreaManager;
import org.jetbrains.annotations.NotNull;
public class BukkitHybridUtils extends HybridUtils {
public BukkitHybridUtils(@NotNull PlotAreaManager plotAreaManager) {
super(plotAreaManager);
}
}

View File

@ -33,6 +33,7 @@ import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.generator.SingleWorldGenerator;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.MainUtil;
@ -54,6 +55,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
@SuppressWarnings("unused") public final boolean PAPER_ASYNC_SAFE = true;
private final PlotAreaManager plotAreaManager;
private final IndependentPlotGenerator plotGenerator;
private final ChunkGenerator platformGenerator;
private final boolean full;
@ -62,24 +64,24 @@ public class BukkitPlotGenerator extends ChunkGenerator
@Getter private final String levelName;
public BukkitPlotGenerator(String name, IndependentPlotGenerator generator) {
if (generator == null) {
throw new IllegalArgumentException("Generator may not be null!");
}
public BukkitPlotGenerator(@NotNull final String name,
@NotNull final IndependentPlotGenerator generator, @NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
this.levelName = name;
this.plotGenerator = generator;
this.platformGenerator = this;
this.populators = new ArrayList<>();
this.populators.add(new BlockStatePopulator(this.plotGenerator));
this.populators.add(new BlockStatePopulator(this.plotGenerator, this.plotAreaManager));
this.full = true;
MainUtil.initCache();
}
public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
public BukkitPlotGenerator(final String world, final ChunkGenerator cg, @NotNull final PlotAreaManager plotAreaManager) {
if (cg instanceof BukkitPlotGenerator) {
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
+ " is already a BukkitPlotGenerator!");
}
this.plotAreaManager = plotAreaManager;
this.levelName = world;
this.full = false;
this.platformGenerator = cg;
@ -108,7 +110,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (!this.loaded) {
String name = world.getName();
PlotSquared.get().loadWorld(name, this);
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(name);
final Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(name);
if (!areas.isEmpty()) {
PlotArea area = areas.iterator().next();
if (!area.isMobSpawning()) {
@ -198,8 +200,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (ChunkManager.preProcessChunk(loc, result)) {
return;
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world.getName(), null);
if (area == null && (area = PlotSquared.get().getPlotAreaManager().getPlotArea(this.levelName, null)) == null) {
PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) {
throw new IllegalStateException(
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
+ ", world: " + world);

View File

@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.ReflectionUtils.RefClass;
import com.plotsquared.core.util.ReflectionUtils.RefField;
import com.plotsquared.core.util.ReflectionUtils.RefMethod;
@ -51,6 +52,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Method;
import java.util.HashSet;
@ -60,12 +62,15 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
@SuppressWarnings("unused")
public class ChunkListener implements Listener {
private final PlotAreaManager plotAreaManager;
private RefMethod methodGetHandleChunk;
private RefField mustSave;
private Chunk lastChunk;
private boolean ignoreUnload = false;
public ChunkListener() {
public ChunkListener(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
if (Settings.Chunk_Processor.AUTO_TRIM) {
try {
RefClass classChunk = getRefClass("{nms}.Chunk");
@ -90,7 +95,7 @@ public class ChunkListener implements Listener {
HashSet<Chunk> toUnload = new HashSet<>();
for (World world : Bukkit.getWorlds()) {
String worldName = world.getName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) {
if (!this.plotAreaManager.hasPlotArea(worldName)) {
continue;
}
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
@ -177,7 +182,7 @@ public class ChunkListener implements Listener {
Chunk chunk = event.getChunk();
if (Settings.Chunk_Processor.AUTO_TRIM) {
String world = chunk.getWorld().getName();
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (this.plotAreaManager.hasPlotArea(world)) {
if (unloadChunk(world, chunk, true)) {
return;
}
@ -200,7 +205,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true);
return;
}
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) {
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
return;
}
Entity[] entities = chunk.getEntities();
@ -230,7 +235,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true);
return;
}
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) {
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
return;
}
Entity[] entities = chunk.getEntities();
@ -281,7 +286,7 @@ public class ChunkListener implements Listener {
}
public boolean processChunk(Chunk chunk, boolean unload) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(chunk.getWorld().getName())) {
if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
return false;
}
Entity[] entities = chunk.getEntities();

View File

@ -33,7 +33,6 @@ import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.Command;
import com.plotsquared.core.command.MainCommand;
import com.plotsquared.core.configuration.Captions;
@ -43,6 +42,7 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import org.bukkit.Chunk;
import org.bukkit.block.Block;
import org.bukkit.block.TileState;
@ -58,6 +58,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
@ -71,8 +72,13 @@ import java.util.regex.Pattern;
@SuppressWarnings("unused")
public class PaperListener implements Listener {
private final PlotAreaManager plotAreaManager;
private Chunk lastChunk;
public PaperListener(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@EventHandler public void onEntityPathfind(EntityPathfindEvent event) {
if (!Settings.Paper_Components.ENTITY_PATHING) {
return;
@ -305,7 +311,7 @@ public class PaperListener implements Listener {
return;
}
Location location = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer<?> pp = BukkitUtil.getPlayer((Player) shooter);

View File

@ -99,6 +99,7 @@ import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag;
import com.plotsquared.core.plot.flag.implementations.VineGrowFlag;
import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EntityUtil;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
@ -210,6 +211,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -224,12 +226,13 @@ import java.util.regex.Pattern;
/**
* Player Events involving plots.
*/
@SuppressWarnings("unused")
public class PlayerEvents extends PlotListener implements Listener {
@SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener {
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
private final PlotAreaManager plotAreaManager;
private boolean pistonBlocks = true;
private float lastRadius;
// To prevent recursion
@ -237,8 +240,9 @@ public class PlayerEvents extends PlotListener implements Listener {
private Field fieldPlayer;
private PlayerMoveEvent moveTmp;
private String internalVersion;
{
public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
try {
fieldPlayer = PlayerEvent.class.getDeclaredField("player");
fieldPlayer.setAccessible(true);
@ -246,7 +250,7 @@ public class PlayerEvents extends PlotListener implements Listener {
e.printStackTrace();
}
}
public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) {
TaskManager.runTaskLater(() -> {
String world = bloc.getWorld().getName();
@ -254,7 +258,8 @@ public class PlayerEvents extends PlotListener implements Listener {
int z = bloc.getBlockZ();
int distance = Bukkit.getViewDistance() * 16;
for (final PlotPlayer<?> player : PlotSquared.platform().getPlayerManager().getPlayers()) {
for (final PlotPlayer<?> player : PlotSquared.platform().getPlayerManager()
.getPlayers()) {
Location location = player.getLocation();
if (location.getWorldName().equals(world)) {
if (16 * Math.abs(location.getX() - x) / 16 > distance
@ -359,19 +364,21 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot.isMerged()) {
disable = true;
for (UUID owner : plot.getOwners()) {
if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner) != null) {
if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner)
!= null) {
disable = false;
break;
}
}
} else {
disable = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs())
== null;
disable = PlotSquared.platform().getPlayerManager()
.getPlayerIfExists(plot.getOwnerAbs()) == null;
}
}
if (disable) {
for (UUID trusted : plot.getTrusted()) {
if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted) != null) {
if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted)
!= null) {
disable = false;
break;
}
@ -385,7 +392,8 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
if (Settings.Redstone.DISABLE_UNOCCUPIED) {
for (final PlotPlayer<?> player : PlotSquared.platform().getPlayerManager().getPlayers()) {
for (final PlotPlayer<?> player : PlotSquared.platform().getPlayerManager()
.getPlayers()) {
if (plot.equals(player.getCurrentPlot())) {
return;
}
@ -490,7 +498,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Location location = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer<Player> pp = BukkitUtil.getPlayer((Player) shooter);
@ -504,7 +512,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler public boolean onProjectileHit(ProjectileHitEvent event) {
Projectile entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return true;
}
PlotArea area = location.getPlotArea();
@ -1078,7 +1086,7 @@ public class PlayerEvents extends PlotListener implements Listener {
PlotArea area = location.getPlotArea();
boolean plotArea = location.isPlotArea();
if (!plotArea) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
return;
@ -1174,7 +1182,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityBlockForm(EntityBlockFormEvent event) {
String world = event.getBlock().getWorld().getName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (!this.plotAreaManager.hasPlotArea(world)) {
return;
}
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
@ -1505,7 +1513,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
PlotArea area = location.getPlotArea();
if (area == null) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
for (Block block1 : event.getBlocks()) {
@ -1542,7 +1550,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Location location = BukkitUtil.getLocation(block.getLocation());
PlotArea area = location.getPlotArea();
if (area == null) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
if (this.pistonBlocks) {
@ -1635,7 +1643,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(event.getWorld().getName())) {
if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) {
return;
}
List<org.bukkit.block.BlockState> blocks = event.getBlocks();
@ -1698,7 +1706,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}*/
HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player) || !PlotSquared.get().getPlotAreaManager()
if (!(entity instanceof Player) || !this.plotAreaManager
.hasPlotArea(entity.getWorld().getName())) {
return;
}
@ -1840,7 +1848,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onPotionSplash(LingeringPotionSplashEvent event) {
Projectile entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
if (!this.onProjectileHit(event)) {
@ -1863,8 +1871,8 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = location.getPlotAbs();
BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) {
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class)
&& !Permissions.hasPermission(pp, "plots.admin.interact.road")) {
if (!area.isRoadFlags() && !area.getRoadFlag(MiscInteractFlag.class) && !Permissions
.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, "plots.admin.interact.road");
e.setCancelled(true);
}
@ -1908,7 +1916,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Block block = event.getBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
String world = location.getWorldName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (!this.plotAreaManager.hasPlotArea(world)) {
return;
}
PlotArea area = location.getPlotArea();
@ -2182,7 +2190,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Block block = event.getBlock();
World world = block.getWorld();
String worldName = world.getName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(worldName)) {
if (!this.plotAreaManager.hasPlotArea(worldName)) {
return;
}
Location location = BukkitUtil.getLocation(block.getLocation());
@ -2600,8 +2608,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED);
event.setCancelled(true);
}
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || area
.isRoadFlags()) {
} else if ((plot != null && !plot.isAdded(pp.getUUID())) || area.isRoadFlags()) {
final Entity entity = event.getRightClicked();
final com.sk89q.worldedit.world.entity.EntityType entityType =
BukkitAdapter.adapt(entity.getType());
@ -2707,7 +2714,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onPotionSplash(PotionSplashEvent event) {
ThrownPotion damager = event.getPotion();
Location location = BukkitUtil.getLocation(damager);
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
int count = 0;
@ -2737,7 +2744,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
Location location = BukkitUtil.getLocation(damager);
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(location.getWorldName())) {
if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
Entity victim = event.getEntity();

View File

@ -36,17 +36,23 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.generator.ChunkGenerator;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class WorldEvents implements Listener {
private final PlotAreaManager plotAreaManager;
public WorldEvents(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWorldInit(WorldInitEvent event) {
World world = event.getWorld();
String name = world.getName();
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
if (manager instanceof SinglePlotAreaManager) {
SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
if (this.plotAreaManager instanceof SinglePlotAreaManager) {
final SinglePlotAreaManager single = (SinglePlotAreaManager) this.plotAreaManager;
if (single.isWorld(name)) {
world.setKeepSpawnInMemory(false);
return;
@ -56,7 +62,7 @@ public class WorldEvents implements Listener {
if (gen instanceof GeneratorWrapper) {
PlotSquared.get().loadWorld(name, (GeneratorWrapper<?>) gen);
} else {
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager));
}
}
}

View File

@ -34,6 +34,7 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.StringMan;
@ -76,15 +77,16 @@ public class BukkitPlayer extends PlotPlayer<Player> {
*
* @param player Bukkit player instance
*/
public BukkitPlayer(@NotNull final Player player) {
this(player, false);
public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player) {
this(plotAreaManager, player, false);
}
public BukkitPlayer(@NotNull final Player player, final boolean offline) {
this(player, offline, true);
public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player, final boolean offline) {
this(plotAreaManager, player, offline, true);
}
public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) {
public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player, final boolean offline, final boolean realPlayer) {
super(plotAreaManager);
this.player = player;
this.offline = offline;
if (realPlayer) {

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.bukkit.player;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.PlayerManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -38,11 +39,17 @@ import java.util.UUID;
*/
public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
private final PlotAreaManager plotAreaManager;
public BukkitPlayerManager(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) {
try {
return getPlayer(object.getUniqueId());
} catch (final NoSuchPlayerException exception) {
return new BukkitPlayer(object, object.isOnline(), false);
return new BukkitPlayer(this.plotAreaManager, object, object.isOnline(), false);
}
}
@ -51,7 +58,7 @@ public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
if (player == null || !player.isOnline()) {
throw new NoSuchPlayerException(uuid);
}
return new BukkitPlayer(player);
return new BukkitPlayer(this.plotAreaManager, player);
}
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {

View File

@ -33,6 +33,7 @@ import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.SetupUtils;
import io.papermc.lib.PaperLib;
@ -42,6 +43,7 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.HashMap;
@ -50,6 +52,12 @@ import java.util.Objects;
public class BukkitSetupUtils extends SetupUtils {
private final PlotAreaManager plotAreaManager;
public BukkitSetupUtils(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public void updateGenerators() {
if (!SetupUtils.generators.isEmpty()) {
return;
@ -66,7 +74,7 @@ public class BukkitSetupUtils extends SetupUtils {
if (generator instanceof GeneratorWrapper<?>) {
wrapped = (GeneratorWrapper<?>) generator;
} else {
wrapped = new BukkitPlotGenerator(testWorld, generator);
wrapped = new BukkitPlotGenerator(testWorld, generator, this.plotAreaManager);
}
SetupUtils.generators.put(name, wrapped);
}

View File

@ -129,7 +129,7 @@ public class BukkitUtil extends WorldUtil {
}
final Player player = OfflinePlayerUtil.loadPlayer(op);
player.loadData();
return new BukkitPlayer(player, true);
return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(), player, true);
}
/**

View File

@ -131,7 +131,6 @@ import java.util.zip.ZipInputStream;
@SuppressWarnings({"WeakerAccess"})
public class PlotSquared {
private static final Set<Plot> EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet());
private static PlotSquared instance;
// Implementation
@ -285,7 +284,7 @@ public class PlotSquared {
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName()
+ " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber());
WorldEdit.getInstance().getEventBus().register(new WESubscriber(this.plotAreaManager));
if (Settings.Enabled_Components.COMMANDS) {
new WE_Anywhere();
}
@ -431,7 +430,7 @@ public class PlotSquared {
ExpireManager.IMP = new ExpireManager();
ExpireManager.IMP.runAutomatedTask();
for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) {
ExpiryTask task = new ExpiryTask(settings);
ExpiryTask task = new ExpiryTask(settings, this.plotAreaManager);
ExpireManager.IMP.addTask(task);
}
}

View File

@ -40,6 +40,7 @@ import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
@ -65,6 +66,7 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileOutputStream;
@ -85,6 +87,12 @@ import java.util.Set;
confirmation = true)
public class Area extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Area(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
@ -104,7 +112,7 @@ public class Area extends SubCommand {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
return false;
}
final PlotArea existingArea = PlotSquared.get().getPlotAreaManager().getPlotArea(player.getLocation().getWorldName(), args[1]);
final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
return false;
@ -126,7 +134,7 @@ public class Area extends SubCommand {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE);
return false;
}
if (PlotSquared.get().getPlotAreaManager().getPlotAreas(
if (this.plotAreaManager.getPlotAreas(
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING);
}
@ -276,7 +284,7 @@ public class Area extends SubCommand {
final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower);
final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower);
final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz);
final Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager()
final Set<PlotArea> areas = this.plotAreaManager
.getPlotAreasSet(area.getWorldName(), region);
if (!areas.isEmpty()) {
Captions.CLUSTER_INTERSECTION
@ -342,12 +350,12 @@ public class Area extends SubCommand {
builder.worldName(split[0]);
final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
PlotSquared.platform().getDefaultGenerator(), null, null);
PlotArea other = PlotSquared.get().getPlotAreaManager().getPlotArea(pa.getWorldName(), id);
PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
if (other != null && Objects.equals(pa.getId(), other.getId())) {
Captions.SETUP_WORLD_TAKEN.send(player, pa.toString());
return false;
}
Set<PlotArea> areas = PlotSquared.get().getPlotAreaManager().getPlotAreasSet(pa.getWorldName());
Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
if (!areas.isEmpty()) {
PlotArea area = areas.iterator().next();
pa.setType(area.getType());
@ -492,7 +500,7 @@ public class Area extends SubCommand {
area = player.getApplicablePlotArea();
break;
case 2:
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
area = this.plotAreaManager.getPlotAreaByString(args[1]);
break;
default:
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " info [area]");
@ -554,7 +562,7 @@ public class Area extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]");
return false;
}
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(PlotSquared.get().getPlotAreaManager().getAllPlotAreas()));
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
paginate(player, areas, 8, page,
new RunnableVal3<Integer, PlotArea, PlotMessage>() {
@Override public void run(Integer i, PlotArea area, PlotMessage message) {
@ -637,7 +645,7 @@ public class Area extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, "/plot visit [area]");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]);
return false;

View File

@ -40,6 +40,7 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.MainUtil;
@ -47,6 +48,7 @@ import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.AutoClaimFinishTask;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@ -61,6 +63,12 @@ import java.util.Set;
usage = "/plot auto [length,width]")
public class Auto extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Auto(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Deprecated public static PlotId getNextPlotId(PlotId id, int step) {
return id.getNextId(step);
}
@ -158,7 +166,7 @@ public class Auto extends SubCommand {
PlotArea plotarea = player.getApplicablePlotArea();
if (plotarea == null) {
if (EconHandler.getEconHandler() != null) {
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
if (EconHandler.getEconHandler()
.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
if (plotarea != null) {
@ -169,8 +177,8 @@ public class Auto extends SubCommand {
}
}
}
if (PlotSquared.get().getPlotAreaManager().getAllPlotAreas().length == 1) {
plotarea = PlotSquared.get().getPlotAreaManager().getAllPlotAreas()[0];
if (this.plotAreaManager.getAllPlotAreas().length == 1) {
plotarea = this.plotAreaManager.getAllPlotAreas()[0];
}
if (plotarea == null) {
MainUtil.sendMessage(player, Captions.NOT_IN_PLOT_WORLD);

View File

@ -25,15 +25,16 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
@ -54,12 +55,18 @@ public class Condense extends SubCommand {
public static boolean TASK = false;
private final PlotAreaManager plotAreaManager;
public Condense(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length != 2 && args.length != 3) {
MainUtil.sendMessage(player, getUsage());
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]);
if (area == null || !WorldUtil.IMP.isWorld(area.getWorldName())) {
MainUtil.sendMessage(player, "INVALID AREA");
return false;

View File

@ -35,10 +35,12 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.sql.SQLException;
@ -57,6 +59,12 @@ import java.util.Map.Entry;
usage = "/plot database [area] <sqlite|mysql|import>")
public class DatabaseCommand extends SubCommand {
private final PlotAreaManager plotAreaManager;
public DatabaseCommand(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
public static void insertPlots(final SQLManager manager, final List<Plot> plots,
final PlotPlayer player) {
TaskManager.runTaskAsync(() -> {
@ -81,7 +89,7 @@ public class DatabaseCommand extends SubCommand {
return false;
}
List<Plot> plots;
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]);
if (area != null) {
plots = PlotSquared.get().sortPlotsByTemp(area.getPlots());
args = Arrays.copyOfRange(args, 1, args.length);
@ -117,7 +125,7 @@ public class DatabaseCommand extends SubCommand {
plots = new ArrayList<>();
for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
String areaName = entry.getKey();
PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(areaName);
PlotArea pa = this.plotAreaManager.getPlotAreaByString(areaName);
if (pa != null) {
for (Entry<PlotId, Plot> entry2 : entry.getValue().entrySet()) {
Plot plot = entry2.getValue();

View File

@ -28,6 +28,7 @@ package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.StringMan;
@ -37,6 +38,7 @@ import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.uuid.UUIDMapping;
import com.sk89q.worldedit.world.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Comparator;
@ -49,6 +51,12 @@ import java.util.Map;
permission = "plots.admin")
public class Debug extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Debug(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length > 0) {
if ("player".equalsIgnoreCase(args[0])) {
@ -119,7 +127,7 @@ public class Debug extends SubCommand {
information.append(header);
information.append(getSection(section, "PlotArea"));
information.append(
getLine(line, "Plot Worlds", StringMan.join(PlotSquared.get().getPlotAreaManager().getAllPlotAreas(), ", ")));
getLine(line, "Plot Worlds", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", ")));
information.append(getLine(line, "Owned Plots", PlotQuery.newQuery().allPlots().count()));
information.append(getSection(section, "Messages"));
information.append(getLine(line, "Total Messages", Captions.values().length));

View File

@ -44,6 +44,7 @@ import com.plotsquared.core.plot.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
@ -59,6 +60,7 @@ import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.world.block.BlockState;
import org.jetbrains.annotations.NotNull;
import javax.script.Bindings;
import javax.script.ScriptContext;
@ -81,10 +83,13 @@ import java.util.concurrent.CompletableFuture;
aliases = {"exec", "$"},
category = CommandCategory.DEBUG)
public class DebugExec extends SubCommand {
private final PlotAreaManager plotAreaManager;
private ScriptEngine engine;
private Bindings scope;
public DebugExec() {
public DebugExec(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
init();
/*
try {
@ -259,7 +264,7 @@ public class DebugExec extends SubCommand {
"&cInvalid syntax: /plot debugexec start-rgar <world>");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
if (area == null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[1]);
return false;

View File

@ -36,6 +36,7 @@ import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.UUID;
@ -47,8 +48,12 @@ import java.util.concurrent.CompletableFuture;
requiredType = RequiredType.CONSOLE,
category = CommandCategory.TELEPORT)
public class DebugImportWorlds extends Command {
public DebugImportWorlds() {
private final PlotAreaManager plotAreaManager;
public DebugImportWorlds(@NotNull final PlotAreaManager plotAreaManager) {
super(MainCommand.getInstance(), true);
this.plotAreaManager = plotAreaManager;
}
@Override
@ -56,12 +61,11 @@ public class DebugImportWorlds extends Command {
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
PlotAreaManager pam = PlotSquared.get().getPlotAreaManager();
if (!(pam instanceof SinglePlotAreaManager)) {
if (!(this.plotAreaManager instanceof SinglePlotAreaManager)) {
player.sendMessage("Must be a single plot area!");
return CompletableFuture.completedFuture(false);
}
SinglePlotArea area = ((SinglePlotAreaManager) pam).getArea();
SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea();
PlotId id = new PlotId(0, 0);
File container = PlotSquared.platform().getWorldContainer();
if (container.equals(new File("."))) {

View File

@ -31,11 +31,13 @@ import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
import com.sk89q.worldedit.world.gamemode.GameModes;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
@ -50,8 +52,11 @@ import java.util.concurrent.TimeoutException;
requiredType = RequiredType.PLAYER)
public class Deny extends SubCommand {
public Deny() {
private final PlotAreaManager plotAreaManager;
public Deny(@NotNull final PlotAreaManager plotAreaManager) {
super(Argument.PlayerName);
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
@ -136,8 +141,7 @@ public class Deny extends SubCommand {
Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName());
MainUtil.sendMessage(player, Captions.YOU_GOT_DENIED);
if (plot.equals(spawn.getPlot())) {
Location newSpawn =
WorldUtil.IMP.getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]);
Location newSpawn = WorldUtil.IMP.getSpawn(this.plotAreaManager.getAllWorlds()[0]);
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
player.kick(Captions.YOU_GOT_DENIED.getTranslated());

View File

@ -25,12 +25,12 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.SchematicHandler;
@ -38,6 +38,7 @@ import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.sk89q.jnbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import java.net.URL;
@ -50,9 +51,15 @@ import java.net.URL;
permission = "plots.download")
public class Download extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Download(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorldName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (!this.plotAreaManager.hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
final Plot plot = player.getCurrentPlot();

View File

@ -25,13 +25,13 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
@ -55,8 +55,12 @@ import java.util.concurrent.CompletableFuture;
requiredType = RequiredType.PLAYER,
category = CommandCategory.TELEPORT)
public class HomeCommand extends Command {
public HomeCommand() {
private final PlotAreaManager plotAreaManager;
public HomeCommand(@NotNull final PlotAreaManager plotAreaManager) {
super(MainCommand.getInstance(), true);
this.plotAreaManager = plotAreaManager;
}
private void home(@NotNull final PlotPlayer<?> player,
@ -132,7 +136,7 @@ public class HomeCommand extends Command {
break;
case 2:
// we assume args[0] is a plot area and args[1] an identifier
PlotArea plotArea = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
final PlotArea plotArea = this.plotAreaManager.getPlotAreaByString(args[0]);
identifier = args[1];
if (plotArea == null) {
// invalid command, therefore no plots

View File

@ -31,10 +31,12 @@ import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
@ -52,8 +54,11 @@ import java.util.concurrent.TimeoutException;
requiredType = RequiredType.PLAYER)
public class Kick extends SubCommand {
public Kick() {
private final PlotAreaManager plotAreaManager;
public Kick(@NotNull final PlotAreaManager plotAreaManager) {
super(Argument.PlayerName);
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
@ -108,8 +113,7 @@ public class Kick extends SubCommand {
Location spawn = WorldUtil.IMP.getSpawn(location.getWorldName());
Captions.YOU_GOT_KICKED.send(player2);
if (plot.equals(spawn.getPlot())) {
Location newSpawn = WorldUtil.IMP
.getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]);
Location newSpawn = WorldUtil.IMP.getSpawn(this.plotAreaManager.getAllWorlds()[0]);
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
player2.kick(Captions.YOU_GOT_KICKED.getTranslated());

View File

@ -36,6 +36,7 @@ import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
@ -47,6 +48,7 @@ import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.query.SortingStrategy;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.uuid.UUIDMapping;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
@ -69,6 +71,12 @@ import java.util.stream.Collectors;
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|player|world|done|fuzzy <search...>> [#]")
public class ListCmd extends SubCommand {
private final PlotAreaManager plotAreaManager;
public ListCmd(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
private String[] getArgumentList(PlotPlayer player) {
List<String> args = new ArrayList<>();
if (EconHandler.getEconHandler() != null && Permissions
@ -297,7 +305,7 @@ public class ListCmd extends SubCommand {
plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term));
break;
default:
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(args[0])) {
if (this.plotAreaManager.hasPlotArea(args[0])) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_LIST_WORLD);

View File

@ -25,7 +25,6 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
@ -33,11 +32,13 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import java.net.MalformedURLException;
import java.net.URL;
@ -52,9 +53,15 @@ import java.util.List;
usage = "/plot load")
public class Load extends SubCommand {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorldName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
private final PlotAreaManager plotAreaManager;
public Load(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
final String world = player.getLocation().getWorldName();
if (!this.plotAreaManager.hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
final Plot plot = player.getCurrentPlot();

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.location.Location;
@ -32,6 +33,7 @@ import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.Permissions;
@ -60,61 +62,62 @@ public class MainCommand extends Command {
public static MainCommand getInstance() {
if (instance == null) {
instance = new MainCommand();
final PlotAreaManager plotAreaManager = PlotSquared.get().getPlotAreaManager();
new Caps();
new Buy();
new Save();
new Load();
new Save(plotAreaManager);
new Load(plotAreaManager);
new Confirm();
new Template();
new Download();
new Template();
new Template(plotAreaManager);
new Download(plotAreaManager);
new Template(plotAreaManager);
new Setup();
new Area();
new Area(plotAreaManager);
new DebugSaveTest();
new DebugLoadTest();
new CreateRoadSchematic();
new DebugAllowUnsafe();
new RegenAllRoads();
new RegenAllRoads(plotAreaManager);
new Claim();
new Auto();
new HomeCommand();
new Visit();
new Auto(plotAreaManager);
new HomeCommand(plotAreaManager);
new Visit(plotAreaManager);
new Set();
new Clear();
new Delete();
new Trust();
new Add();
new Leave();
new Deny();
new Deny(plotAreaManager);
new Remove();
new Info();
new Near();
new ListCmd();
new Debug();
new SchematicCmd();
new ListCmd(plotAreaManager);
new Debug(plotAreaManager);
new SchematicCmd(plotAreaManager);
new PluginCmd();
new Purge();
new Reload();
new Purge(plotAreaManager);
new Reload(plotAreaManager);
new Relight();
new Merge();
new DebugPaste();
new Unlink();
new Kick();
new Kick(plotAreaManager);
new Inbox();
new Comment();
new DatabaseCommand();
new DatabaseCommand(plotAreaManager);
new Swap();
new Music();
new DebugRoadRegen();
new Trust();
new DebugExec();
new DebugExec(plotAreaManager);
new FlagCommand();
new Target();
new Move();
new Condense();
new Move(plotAreaManager);
new Condense(plotAreaManager);
new Copy();
new Chat();
new Trim();
new Trim(plotAreaManager);
new Done();
new Continue();
new Middle();
@ -126,7 +129,7 @@ public class MainCommand extends Command {
new Alias();
new SetHome();
new Cluster();
new DebugImportWorlds();
new DebugImportWorlds(plotAreaManager);
new Backup();
if (Settings.Ratings.USE_LIKES) {
@ -143,7 +146,7 @@ public class MainCommand extends Command {
return instance;
}
public static boolean onCommand(final PlotPlayer player, String... args) {
public static boolean onCommand(final PlotPlayer<?> player, String... args) {
if (args.length >= 1 && args[0].contains(":")) {
String[] split2 = args[0].split(":");
if (split2.length == 2) {

View File

@ -25,16 +25,17 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
@ -46,6 +47,12 @@ import java.util.concurrent.CompletableFuture;
requiredType = RequiredType.PLAYER)
public class Move extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Move(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
@ -70,7 +77,7 @@ public class Move extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return CompletableFuture.completedFuture(false);
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]);
Plot plot2;
if (area == null) {
plot2 = MainUtil.getPlotFromString(player, args[0], true);

View File

@ -34,8 +34,10 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.HashSet;
@ -53,6 +55,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
confirmation = true)
public class Purge extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Purge(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
@ -78,7 +86,7 @@ public class Purge extends SubCommand {
break;
case "area":
case "a":
area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(split[1]);
area = this.plotAreaManager.getPlotAreaByString(split[1]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, split[1]);
return false;

View File

@ -25,14 +25,15 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.generator.HybridPlotManager;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import org.jetbrains.annotations.NotNull;
@CommandDeclaration(command = "regenallroads",
description = "Regenerate all roads in the map using the set road schematic",
@ -43,6 +44,12 @@ import com.plotsquared.core.util.MainUtil;
permission = "plots.regenallroads")
public class RegenAllRoads extends SubCommand {
private final PlotAreaManager plotAreaManager;
public RegenAllRoads(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
int height = 0;
if (args.length == 2) {
@ -59,7 +66,7 @@ public class RegenAllRoads extends SubCommand {
"/plot regenallroads <world> [height]");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[0]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[0]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[0]);
return false;

View File

@ -32,7 +32,9 @@ import com.plotsquared.core.configuration.MemorySection;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Objects;
@ -45,13 +47,19 @@ import java.util.Objects;
category = CommandCategory.ADMINISTRATION)
public class Reload extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Reload(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
try {
// The following won't affect world generation, as that has to be
// loaded during startup unfortunately.
PlotSquared.get().setupConfigs();
Captions.load(PlotSquared.get().translationFile);
PlotSquared.get().getPlotAreaManager().forEachPlotArea(area -> {
this.plotAreaManager.forEachPlotArea(area -> {
ConfigurationSection worldSection = PlotSquared.get().worlds
.getConfigurationSection("worlds." + area.getWorldName());
if (worldSection == null) {

View File

@ -25,18 +25,19 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import org.jetbrains.annotations.NotNull;
import java.net.URL;
import java.util.List;
@ -49,9 +50,15 @@ import java.util.UUID;
permission = "plots.save")
public class Save extends SubCommand {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorldName();
if (!PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
private final PlotAreaManager plotAreaManager;
public Save(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
final String world = player.getLocation().getWorldName();
if (!this.plotAreaManager.hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
}
final Plot plot = player.getCurrentPlot();

View File

@ -26,7 +26,6 @@
package com.plotsquared.core.command;
import com.google.common.collect.Lists;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.location.Location;
@ -35,12 +34,14 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import java.net.URL;
import java.util.ArrayList;
@ -55,8 +56,13 @@ import java.util.UUID;
usage = "/plot schematic <save|saveall|paste>")
public class SchematicCmd extends SubCommand {
private final PlotAreaManager plotAreaManager;
private boolean running = false;
public SchematicCmd(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length < 1) {
sendMessage(player, Captions.SCHEMATIC_MISSING_ARG);
@ -150,7 +156,7 @@ public class SchematicCmd extends SubCommand {
MainUtil.sendMessage(player, Captions.SCHEMATIC_EXPORTALL_WORLD_ARGS);
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
if (area == null) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]);
return false;

View File

@ -36,6 +36,7 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.setup.SettingsNodesWrapper;
@ -44,6 +45,7 @@ import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.TaskManager;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileInputStream;
@ -61,6 +63,12 @@ import java.util.zip.ZipOutputStream;
category = CommandCategory.ADMINISTRATION)
public class Template extends SubCommand {
private final PlotAreaManager plotAreaManager;
public Template(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
public static boolean extractAllFiles(String world, String template) {
try {
File folder =
@ -159,7 +167,7 @@ public class Template extends SubCommand {
"/plot template import <world> <template>");
return false;
}
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (this.plotAreaManager.hasPlotArea(world)) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_TAKEN, world);
return false;
}
@ -203,7 +211,7 @@ public class Template extends SubCommand {
"/plot template export <world>");
return false;
}
final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(world);
final PlotArea area = this.plotAreaManager.getPlotAreaByString(world);
if (area == null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD);
return false;

View File

@ -31,6 +31,7 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.util.MainUtil;
@ -43,14 +44,8 @@ import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
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 java.util.Iterator;
import java.util.List;
@ -64,60 +59,14 @@ import java.util.Set;
category = CommandCategory.ADMINISTRATION)
public class Trim extends SubCommand {
public static ArrayList<Plot> expired = null;
private static volatile boolean TASK = false;
private final PlotAreaManager plotAreaManager;
public static boolean getBulkRegions(final ArrayList<BlockVector2> empty, final String world,
final Runnable whenDone) {
if (Trim.TASK) {
return false;
}
TaskManager.runTaskAsync(new Runnable() {
@Override public void run() {
String directory = world + File.separator + "region";
File folder = new File(PlotSquared.platform().getWorldContainer(), directory);
File[] regionFiles = folder.listFiles();
for (File file : regionFiles) {
String name = file.getName();
if (name.endsWith("mca")) {
if (file.getTotalSpace() <= 8192) {
checkMca(name);
} else {
Path path = Paths.get(file.getPath());
try {
BasicFileAttributes attr =
Files.readAttributes(path, BasicFileAttributes.class);
long creation = attr.creationTime().toMillis();
long modification = file.lastModified();
long diff = Math.abs(creation - modification);
if (diff < 10000) {
checkMca(name);
}
} catch (IOException ignored) {
}
}
}
}
Trim.TASK = false;
TaskManager.runTaskAsync(whenDone);
}
private void checkMca(String name) {
try {
String[] split = name.split("\\.");
int x = Integer.parseInt(split[1]);
int z = Integer.parseInt(split[2]);
BlockVector2 loc = BlockVector2.at(x, z);
empty.add(loc);
} catch (NumberFormatException ignored) {
PlotSquared.debug("INVALID MCA: " + name);
}
}
});
Trim.TASK = true;
return true;
public Trim(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
private static volatile boolean TASK = false;
/**
* Runs the result task with the parameters (viable, nonViable).
*
@ -167,7 +116,7 @@ public class Trim extends SubCommand {
return false;
}
final String world = args[0];
if (!WorldUtil.IMP.isWorld(world) || !PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (!WorldUtil.IMP.isWorld(world) || !this.plotAreaManager.hasPlotArea(world)) {
MainUtil.sendMessage(player, Captions.NOT_VALID_WORLD);
return false;
}

View File

@ -32,6 +32,7 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
@ -59,8 +60,11 @@ import java.util.concurrent.TimeoutException;
category = CommandCategory.TELEPORT)
public class Visit extends Command {
public Visit() {
private final PlotAreaManager plotAreaManager;
public Visit(@NotNull final PlotAreaManager plotAreaManager) {
super(MainCommand.getInstance(), true);
this.plotAreaManager = plotAreaManager;
}
private void visit(@NotNull final PlotPlayer player, @NotNull final PlotQuery query, final PlotArea sortByArea,
@ -164,7 +168,7 @@ public class Visit extends Command {
// /p v <name> [page]
case 2:
if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
sortByArea = PlotSquared.get().getPlotAreaManager().getPlotAreaByString(args[1]);
sortByArea = this.plotAreaManager.getPlotAreaByString(args[1]);
if (sortByArea == null) {
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
Captions.COMMAND_SYNTAX.send(player, getUsage());
@ -275,7 +279,7 @@ public class Visit extends Command {
}
private void completeAreas(final List<Command> commands, final String arg) {
for (final PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
final String areaName = area.getWorldName() + ";" + area.getId();
if (!areaName.toLowerCase().startsWith(arg.toLowerCase())) {
continue;

View File

@ -40,6 +40,7 @@ import com.plotsquared.core.plot.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.ChunkBlockQueue;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
@ -61,6 +62,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.ArrayDeque;
@ -83,6 +85,12 @@ public abstract class HybridUtils {
public static PlotArea area;
public static boolean UPDATE = false;
private final PlotAreaManager plotAreaManager;
public HybridUtils(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
public void analyzeRegion(final String world, final CuboidRegion region,
final RunnableVal<PlotAnalysis> whenDone) {
// int diff, int variety, int vertices, int rotation, int height_sd
@ -115,7 +123,7 @@ public abstract class HybridUtils {
final int width = tx - bx + 1;
final int length = tz - bz + 1;
PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(world, null);
final PlotArea area = this.plotAreaManager.getPlotArea(world, null);
if (!(area instanceof HybridPlotWorld)) {
return;

View File

@ -25,24 +25,31 @@
*/
package com.plotsquared.core.generator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.NotNull;
public class SingleWorldGenerator extends IndependentPlotGenerator {
private static final Location bedrock1 = Location.at("", 0, 0, 0);
private static final Location bedrock2 = Location.at("", 15, 0, 15);
private static final Location dirt1 = Location.at("", 0, 1, 0);
private static final Location dirt2 = Location.at("", 15, 2, 15);
private static final Location grass1 = Location.at("", 0, 3, 0);
private static final Location grass2 = Location.at("", 15, 3, 15);
private static final Location dirt1 = Location.at("", 0, 1, 0);
private static final Location dirt2 = Location.at("", 15, 2, 15);
private static final Location grass1 = Location.at("", 0, 3, 0);
private static final Location grass2 = Location.at("", 15, 3, 15);
private final PlotAreaManager plotAreaManager;
public SingleWorldGenerator(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public String getName() {
return "PlotSquared:single";
@ -64,10 +71,10 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
}
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
return ((SinglePlotAreaManager) PlotSquared.get().getPlotAreaManager()).getArea();
return ((SinglePlotAreaManager) this.plotAreaManager).getArea();
}
@Override public void initialize(PlotArea area) {
}
}

View File

@ -25,11 +25,11 @@
*/
package com.plotsquared.core.listener;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.WEManager;
@ -43,10 +43,17 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
public class WESubscriber {
private final PlotAreaManager plotAreaManager;
public WESubscriber(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Subscribe(priority = Priority.VERY_EARLY) public void onEditSession(EditSessionEvent event) {
if (!Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
@ -82,19 +89,19 @@ public class WESubscriber {
if (Permissions.hasPermission(plotPlayer, "plots.worldedit.bypass")) {
MainUtil.sendMessage(plotPlayer, Captions.WORLDEDIT_BYPASS);
}
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(new NullExtent());
}
return;
}
}
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(
new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(),
event.getExtent()));
}
} else if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world)) {
} else if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(new WEExtent(mask, event.getExtent()));
}
}

View File

@ -32,6 +32,7 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.gamemode.GameMode;
@ -45,8 +46,9 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
private static ConsolePlayer instance;
private ConsolePlayer() {
final PlotArea[] areas = PlotSquared.get().getPlotAreaManager().getAllPlotAreas();
private ConsolePlayer(final PlotAreaManager plotAreaManager) {
super(plotAreaManager);
final PlotArea[] areas = plotAreaManager.getAllPlotAreas();
final PlotArea area;
if (areas.length > 0) {
area = areas[0];
@ -67,7 +69,7 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
public static ConsolePlayer getConsole() {
if (instance == null) {
instance = new ConsolePlayer();
instance = new ConsolePlayer(PlotSquared.get().getPlotAreaManager());
instance.teleport(instance.getLocation());
}
return instance;

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.player;
import com.google.common.base.Preconditions;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.CommandCaller;
import com.plotsquared.core.command.RequiredType;
@ -87,6 +88,12 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
*/
private ConcurrentHashMap<String, Object> meta;
private int hash;
private final PlotAreaManager plotAreaManager;
public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
public static <T> PlotPlayer<T> from(@NonNull final T object) {
if (!converters.containsKey(object.getClass())) {
@ -270,7 +277,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
}
final AtomicInteger count = new AtomicInteger(0);
final UUID uuid = getUUID();
PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> {
this.plotAreaManager.forEachPlotArea(value -> {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
for (Plot plot : value.getPlotsAbs(uuid)) {
if (!DoneFlag.isDone(plot)) {
@ -289,7 +296,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
return getClusterCount(getLocation().getWorldName());
}
final AtomicInteger count = new AtomicInteger(0);
PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> {
this.plotAreaManager.forEachPlotArea(value -> {
for (PlotCluster cluster : value.getClusters()) {
if (cluster.isOwner(getUUID())) {
count.incrementAndGet();
@ -308,7 +315,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
public int getPlotCount(String world) {
UUID uuid = getUUID();
int count = 0;
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world)) {
for (PlotArea area : this.plotAreaManager.getPlotAreasSet(world)) {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
count +=
area.getPlotsAbs(uuid).stream().filter(plot -> !DoneFlag.isDone(plot)).count();
@ -322,7 +329,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
public int getClusterCount(String world) {
UUID uuid = getUUID();
int count = 0;
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world)) {
for (PlotArea area : this.plotAreaManager.getPlotAreasSet(world)) {
for (PlotCluster cluster : area.getClusters()) {
if (cluster.isOwner(getUUID())) {
count++;
@ -349,11 +356,11 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
* @return Plot area the player is currently in, or {@code null}
*/
@Nullable public PlotArea getPlotAreaAbs() {
return PlotSquared.get().getPlotAreaManager().getPlotArea(getLocation());
return this.plotAreaManager.getPlotArea(getLocation());
}
public PlotArea getApplicablePlotArea() {
return PlotSquared.get().getPlotAreaManager().getApplicablePlotArea(getLocation());
return this.plotAreaManager.getApplicablePlotArea(getLocation());
}
@Override public RequiredType getSuperCaller() {
@ -614,7 +621,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
*/
public int getPlayerClusterCount() {
final AtomicInteger count = new AtomicInteger();
PlotSquared.get().getPlotAreaManager().forEachPlotArea(value -> count.addAndGet(value.getClusters().size()));
this.plotAreaManager.forEachPlotArea(value -> count.addAndGet(value.getClusters().size()));
return count.get();
}
@ -645,7 +652,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
if (!Settings.Teleport.ON_LOGIN) {
return;
}
PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
PlotAreaManager manager = PlotPlayer.this.plotAreaManager;
if (!(manager instanceof SinglePlotAreaManager)) {
return;

View File

@ -25,11 +25,12 @@
*/
package com.plotsquared.core.plot.expiration;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.query.PlotQuery;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
@ -41,11 +42,14 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class ExpiryTask {
private final Settings.Auto_Clear settings;
private final PlotAreaManager plotAreaManager;
private long cutoffThreshold = Long.MIN_VALUE;
public ExpiryTask(Settings.Auto_Clear settings) {
public ExpiryTask(@NotNull final Settings.Auto_Clear settings, @NotNull final PlotAreaManager plotAreaManager) {
this.settings = settings;
this.plotAreaManager = plotAreaManager;
}
public Settings.Auto_Clear getSettings() {
@ -122,7 +126,7 @@ public class ExpiryTask {
public Set<Plot> getPlotsToCheck() {
final Collection<PlotArea> areas = new LinkedList<>();
for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
if (this.allowsArea(plotArea)) {
areas.add(plotArea);
}

View File

@ -56,8 +56,8 @@ public class SinglePlotArea extends GridPlotWorld {
public boolean VOID = false;
public SinglePlotArea() {
super("*", null, new SingleWorldGenerator(), null, null);
public SinglePlotArea(@NotNull final PlotAreaManager plotAreaManager) {
super("*", null, new SingleWorldGenerator(plotAreaManager), null, null);
this.setAllowSigns(false);
this.setDefaultHome(new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE));
}

View File

@ -41,11 +41,11 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
private PlotArea[] all;
public SinglePlotAreaManager() {
this.area = new SinglePlotArea();
this.area = new SinglePlotArea(this);
this.array = new SinglePlotArea[] {area};
this.all = new PlotArea[] {area};
SetupUtils.generators.put("PlotSquared:single",
new SingleWorldGenerator().specify("CheckingPlotSquaredGenerator"));
new SingleWorldGenerator(this).specify("CheckingPlotSquaredGenerator"));
}
public SinglePlotArea getArea() {

View File

@ -25,17 +25,11 @@
*/
package com.plotsquared.core.queue;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.util.task.RunnableVal3;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import org.jetbrains.annotations.NotNull;
public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
private final int minX;
@ -100,32 +94,4 @@ public class ScopedLocalBlockQueue extends DelegateLocalBlockQueue {
return Location.at(this.getWorld(), this.maxX, this.maxY, this.maxZ);
}
/**
* Run a task for each x,z value corresponding to the plot at that location<br>
* - Plot: The plot at the x,z (may be null)<br>
* - Location: The location in the chunk (y = 0)<br>
* - PlotChunk: Reference to this chunk object<br>
*
* @param task
*/
public void mapByType2D(@NotNull final RunnableVal3<Plot, Integer, Integer> task) {
final int bx = minX;
final int bz = minZ;
final PlotArea area = PlotSquared.get().getPlotAreaManager().getPlotArea(getWorld(), null);
final Location location = Location.at(getWorld(), bx, 0, bz);
if (area != null) {
PlotManager manager = area.getPlotManager();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
task.run(area.getPlotAbs(location.withX(bx + x).withZ(bz + z)), x, z);
}
}
} else {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
task.run(location.withX(bx + x).withZ(bz + z).getPlotAbs(), x, z);
}
}
}
}
}

View File

@ -25,9 +25,10 @@
*/
package com.plotsquared.core.util.query;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.world.PlotAreaManager;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.HashSet;
@ -35,9 +36,15 @@ import java.util.Set;
class GlobalPlotProvider implements PlotProvider {
private final PlotAreaManager plotAreaManager;
GlobalPlotProvider(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}
@Override public Collection<Plot> getPlots() {
final Set<Plot> plots = new HashSet<>();
for (final PlotArea plotArea : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
plots.addAll(plotArea.getPlots());
}
return plots;

View File

@ -32,6 +32,7 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MathMan;
import org.jetbrains.annotations.NotNull;
@ -59,12 +60,15 @@ import java.util.stream.Stream;
public final class PlotQuery {
private final Collection<PlotFilter> filters = new LinkedList<>();
private PlotProvider plotProvider = new GlobalPlotProvider();
private final PlotAreaManager plotAreaManager;
private PlotProvider plotProvider;
private SortingStrategy sortingStrategy = SortingStrategy.NO_SORTING;
private PlotArea priorityArea;
private Comparator<Plot> plotComparator;
private PlotQuery() {
private PlotQuery(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
this.plotProvider = new GlobalPlotProvider(plotAreaManager);
}
/**
@ -73,7 +77,7 @@ public final class PlotQuery {
* @return New query
*/
public static PlotQuery newQuery() {
return new PlotQuery();
return new PlotQuery(PlotSquared.get().getPlotAreaManager());
}
/**
@ -96,7 +100,7 @@ public final class PlotQuery {
*/
@NotNull public PlotQuery inWorld(@NotNull final String world) {
Preconditions.checkNotNull(world, "World may not be null");
this.plotProvider = new AreaLimitedPlotProvider(PlotSquared.get().getPlotAreaManager().getPlotAreasSet(world));
this.plotProvider = new AreaLimitedPlotProvider(this.plotAreaManager.getPlotAreasSet(world));
return this;
}
@ -129,7 +133,7 @@ public final class PlotQuery {
* @return The query instance
*/
@NotNull public PlotQuery allPlots() {
this.plotProvider = new GlobalPlotProvider();
this.plotProvider = new GlobalPlotProvider(this.plotAreaManager);
return this;
}