Guice progress

This commit is contained in:
Alexander Söderberg
2020-07-10 22:12:37 +02:00
parent 55bf41d2da
commit c0f69f321d
90 changed files with 1026 additions and 830 deletions

View File

@ -102,7 +102,7 @@ import java.util.UUID;
* @see ChunkManager
*/
public ChunkManager getChunkManager() {
return ChunkManager.manager;
return PlotSquared.platform().getInjector().getInstance(ChunkManager.class);
}
/**
@ -111,7 +111,7 @@ import java.util.UUID;
* @return GlobalBlockQueue.IMP
*/
public GlobalBlockQueue getBlockQueue() {
return GlobalBlockQueue.IMP;
return PlotSquared.platform().getGlobalBlockQueue();
}
/**
@ -122,7 +122,7 @@ import java.util.UUID;
* @see SchematicHandler
*/
public SchematicHandler getSchematicHandler() {
return SchematicHandler.manager;
return PlotSquared.platform().getInjector().getInstance(SchematicHandler.class);
}
/**

View File

@ -25,27 +25,21 @@
*/
package com.plotsquared.core;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.inject.annotations.DefaultGenerator;
import com.plotsquared.core.location.World;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.queue.QueueProvider;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.ChatManager;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.extension.platform.Actor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -94,20 +88,6 @@ public interface PlotPlatform<P> extends ILogger {
*/
void shutdown();
/**
* Gets the version of the PlotSquared being used.
*
* @return the plugin version
*/
int[] getPluginVersion();
/**
* Gets the version of the PlotSquared being used as a string.
*
* @return the plugin version as a string
*/
String getPluginVersionString();
default String getPluginName() {
return "PlotSquared";
}
@ -129,13 +109,6 @@ public interface PlotPlatform<P> extends ILogger {
*/
String getNMSPackage();
/**
* Gets the schematic handler.
*
* @return The {@link SchematicHandler}
*/
SchematicHandler initSchematicHandler();
/**
* Starts the {@link ChatManager}.
*
@ -143,86 +116,6 @@ public interface PlotPlatform<P> extends ILogger {
*/
ChatManager initChatManager();
/**
* The task manager will run and manage Minecraft tasks.
*
* @return the PlotSquared task manager
*/
TaskManager getTaskManager();
/**
* Run the task that will kill road mobs.
*/
void runEntityTask();
/**
* Registerss the implementation specific commands.
*/
void registerCommands();
/**
* Register the protection system.
*/
void registerPlayerEvents();
/**
* Register force field events.
*/
void registerForceFieldEvents();
/**
* Registers the WorldEdit hook.
*/
boolean initWorldEdit();
/**
* Gets the economy provider, if there is one
*
* @return the PlotSquared economy manager
*/
@Nullable EconHandler getEconomyHandler();
/**
* Gets the permission provider, if there is one
*
* @return the PlotSquared permission manager
*/
@Nullable PermHandler getPermissionHandler();
/**
* Gets the {@link QueueProvider} class.
*/
QueueProvider initBlockQueue();
/**
* Gets the {@link WorldUtil} class.
*/
WorldUtil initWorldUtil();
/**
* Gets the chunk manager.
*
* @return the PlotSquared chunk manager
*/
ChunkManager initChunkManager();
/**
* Gets the region manager.
*
* @return the PlotSquared region manager
*/
RegionManager initRegionManager();
/**
* Gets the {@link SetupUtils} class.
*/
SetupUtils initSetupUtils();
/**
* Gets {@link HybridUtils} class.
*/
HybridUtils initHybridUtils();
/**
* Start Metrics.
*/
@ -235,12 +128,6 @@ public interface PlotPlatform<P> extends ILogger {
*/
void setGenerator(String world);
/**
* Gets the {@link InventoryUtil} class (used for implementation specific
* inventory guis).
*/
InventoryUtil initInventoryUtil();
/**
* Unregisters a {@link PlotPlayer} from cache e.g. if they have logged off.
*
@ -259,49 +146,43 @@ public interface PlotPlatform<P> extends ILogger {
GeneratorWrapper<?> wrapPlotGenerator(String world, IndependentPlotGenerator generator);
/**
* Register the chunk processor which will clean out chunks that have too
* many block states or entities.
*/
void registerChunkProcessor();
/**
* Register the world initialization events (used to keep track of worlds
* being generated).
*/
void registerWorldEvents();
/**
* Usually HybridGen
*
* @return Default implementation generator
*/
@NotNull IndependentPlotGenerator getDefaultGenerator();
@NotNull default IndependentPlotGenerator getDefaultGenerator() {
return getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
}
List<Map.Entry<Map.Entry<String, String>, Boolean>> getPluginIds();
Actor getConsole();
/**
* Get the backup manager instance
*
* @return Backup manager
*/
@NotNull BackupManager getBackupManager();
@NotNull default BackupManager getBackupManager() {
return getInjector().getInstance(BackupManager.class);
}
/**
* Get the platform specific world manager
*
* @return World manager
*/
@NotNull PlatformWorldManager<?> getWorldManager();
@NotNull default PlatformWorldManager<?> getWorldManager() {
return getInjector().getInstance(PlatformWorldManager.class);
}
/**
* Get the player manager implementation for the platform
*
* @return Player manager
*/
@NotNull PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager();
@NotNull default PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager() {
return getInjector().getInstance(PlayerManager.class);
}
/**
* Get a platform world wrapper from a world name
@ -311,4 +192,38 @@ public interface PlotPlatform<P> extends ILogger {
*/
@NotNull World<?> getPlatformWorld(@NotNull final String worldName);
/**
* Get the {@link com.google.inject.Injector} instance used by PlotSquared
*
* @return Injector instance
*/
@NotNull Injector getInjector();
/**
* Get the world utility implementation
*
* @return World utility
*/
@NotNull default WorldUtil getWorldUtil() {
return getInjector().getInstance(WorldUtil.class);
}
/**
* Get the global block queue implementation
*
* @return Global block queue implementation
*/
@NotNull default GlobalBlockQueue getGlobalBlockQueue() {
return getInjector().getInstance(GlobalBlockQueue.class);
}
/**
* Get the hybrid utility class
*
* @return Hybrid utility class
*/
@NotNull default HybridUtils getHybridUtils() {
return getInjector().getInstance(HybridUtils.class);
}
}

View File

@ -25,8 +25,6 @@
*/
package com.plotsquared.core;
import com.plotsquared.core.command.WE_Anywhere;
import com.plotsquared.core.components.ComponentPresetManager;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
@ -47,7 +45,6 @@ import com.plotsquared.core.generator.HybridPlotWorld;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.listener.WESubscriber;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.plot.BlockBucket;
@ -65,21 +62,13 @@ import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
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.GlobalBlockQueue;
import com.plotsquared.core.util.ChatManager;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.LegacyConverter;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.ReflectionUtils;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
@ -202,10 +191,6 @@ public class PlotSquared {
"PlotSquared-" + platform + ".jar");
}
}
TaskManager.IMP = this.platform.getTaskManager();
// World Util. Has to be done before config files are loaded
WorldUtil.IMP = this.platform.initWorldUtil();
if (!setupConfigs()) {
return;
@ -215,24 +200,7 @@ public class PlotSquared {
+ ".use_THIS.yml");
Captions.load(this.translationFile);
// WorldEdit
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
if (this.platform.initWorldEdit()) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName()
+ " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber(this.plotAreaManager));
if (Settings.Enabled_Components.COMMANDS) {
new WE_Anywhere();
}
}
} catch (Throwable e) {
PlotSquared.debug(
"Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master");
}
}
this.worldedit = WorldEdit.getInstance();
// Create Event utility class
this.eventDispatcher = new EventDispatcher(this.worldedit);
@ -263,85 +231,11 @@ public class PlotSquared {
// Comments
CommentManager.registerDefaultInboxes();
// Kill entities
if (Settings.Enabled_Components.KILL_ROAD_MOBS
|| Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
this.platform.runEntityTask();
}
if (Settings.Enabled_Components.EVENTS) {
this.platform.registerPlayerEvents();
}
// Required
this.platform.registerWorldEvents();
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
this.platform.registerChunkProcessor();
}
startExpiryTasks();
// create Hybrid utility class
HybridUtils.manager = this.platform.initHybridUtils();
// Inventory utility class
InventoryUtil.manager = this.platform.initInventoryUtil();
// create setup util class
SetupUtils.manager = this.platform.initSetupUtils();
// Set block
GlobalBlockQueue.IMP =
new GlobalBlockQueue(this.platform.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME);
GlobalBlockQueue.IMP.runTask();
// Set chunk
ChunkManager.manager = this.platform.initChunkManager();
RegionManager.manager = this.platform.initRegionManager();
// Schematic handler
SchematicHandler.manager = this.platform.initSchematicHandler();
// Chat
// This is getting removed so I won't even bother migrating it
ChatManager.manager = this.platform.initChatManager();
// Commands
if (Settings.Enabled_Components.COMMANDS) {
this.platform.registerCommands();
}
// Economy
if (Settings.Enabled_Components.ECONOMY) {
TaskManager.runTask(() -> EconHandler.initializeEconHandler());
}
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
try {
new ComponentPresetManager();
} catch (final Exception e) {
PlotSquared.log(Captions.PREFIX + "Failed to initialize the preset system");
e.printStackTrace();
}
}
// World generators:
final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
if (section != null) {
for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (WorldUtil.IMP.isWorld(world)) {
this.platform.setGenerator(world);
}
}
TaskManager.runTaskLater(() -> {
for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) {
continue;
}
if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) {
debug("`" + world + "` was not properly loaded - " + this.platform.getPluginName()
+ " will now try to load it properly: ");
debug(
" - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
debug(
" - Your world management plugin may be faulty (or non existent)");
debug(
" This message may also be a false positive and could be ignored.");
PlotSquared.this.platform.setGenerator(world);
}
}
}, 1);
}
// Copy files
copyFile("addplots.js", Settings.Paths.SCRIPTS);
@ -552,7 +446,7 @@ public class PlotSquared {
PlotSquared.debug(" Regions: " + regions.size());
PlotSquared.debug(" Chunks: " + chunks.size());
HybridUtils.UPDATE = true;
HybridUtils.manager.scheduleRoadUpdate(plotArea, regions, height, chunks);
PlotSquared.platform().getHybridUtils().scheduleRoadUpdate(plotArea, regions, height, chunks);
} catch (IOException | ClassNotFoundException e) {
PlotSquared.log(Captions.PREFIX + "Error restarting road regeneration.");
e.printStackTrace();

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.backup;
import com.google.inject.Singleton;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@ -37,7 +38,7 @@ import java.util.Objects;
/**
* {@inheritDoc}
*/
public class NullBackupManager implements BackupManager {
@Singleton public class NullBackupManager implements BackupManager {
@Override @NotNull public BackupProfile getProfile(@NotNull Plot plot) {
return new NullBackupProfile();

View File

@ -25,13 +25,14 @@
*/
package com.plotsquared.core.backup;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@ -51,12 +52,20 @@ import java.util.concurrent.CompletableFuture;
* plot, which is used to store and retrieve plot backups
* {@inheritDoc}
*/
@RequiredArgsConstructor
public class PlayerBackupProfile implements BackupProfile {
private final UUID owner;
private final Plot plot;
private final BackupManager backupManager;
private final SchematicHandler schematicHandler;
@Inject public PlayerBackupProfile(@Assisted @NotNull final UUID owner, @Assisted @NotNull final Plot plot,
@NotNull final BackupManager backupManager, @NotNull final SchematicHandler schematicHandler) {
this.owner = owner;
this.plot = plot;
this.backupManager = backupManager;
this.schematicHandler = schematicHandler;
}
private volatile List<Backup> backupCache;
private final Object backupLock = new Object();
@ -141,7 +150,7 @@ public class PlayerBackupProfile implements BackupProfile {
backups.get(backups.size() - 1).delete();
}
final List<Plot> plots = Collections.singletonList(plot);
final boolean result = SchematicHandler.manager.exportAll(plots, getBackupDirectory().toFile(),
final boolean result = this.schematicHandler.exportAll(plots, getBackupDirectory().toFile(),
"%world%-%id%-" + System.currentTimeMillis(), () ->
future.complete(new Backup(this, System.currentTimeMillis(), null)));
if (!result) {
@ -161,14 +170,14 @@ public class PlayerBackupProfile implements BackupProfile {
TaskManager.runTaskAsync(() -> {
Schematic schematic = null;
try {
schematic = SchematicHandler.manager.getSchematic(backup.getFile().toFile());
schematic = this.schematicHandler.getSchematic(backup.getFile().toFile());
} catch (SchematicHandler.UnsupportedFormatException e) {
e.printStackTrace();
}
if (schematic == null) {
future.completeExceptionally(new IllegalArgumentException("The backup is non-existent or not in the correct format"));
} else {
SchematicHandler.manager.paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
@Override public void run(Boolean value) {
if (value) {
future.complete(null);

View File

@ -27,9 +27,12 @@ package com.plotsquared.core.backup;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.task.TaskManager;
@ -48,15 +51,17 @@ import java.util.concurrent.TimeUnit;
/**
* {@inheritDoc}
*/
@RequiredArgsConstructor public class SimpleBackupManager implements BackupManager {
@RequiredArgsConstructor @Singleton public class SimpleBackupManager implements BackupManager {
@Getter private final Path backupPath;
private final boolean automaticBackup;
@Getter private final int backupLimit;
private final Cache<PlotCacheKey, BackupProfile> backupProfileCache = CacheBuilder.newBuilder()
.expireAfterAccess(3, TimeUnit.MINUTES).build();
private final PlayerBackupProfileFactory playerBackupProfileFactory;
public SimpleBackupManager() throws Exception {
@Inject public SimpleBackupManager(@NotNull final PlayerBackupProfileFactory playerBackupProfileFactory) throws Exception {
this.playerBackupProfileFactory = playerBackupProfileFactory;
this.backupPath = Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath().resolve("backups");
if (!Files.exists(backupPath)) {
Files.createDirectory(backupPath);
@ -68,9 +73,9 @@ import java.util.concurrent.TimeUnit;
@Override @NotNull public BackupProfile getProfile(@NotNull final Plot plot) {
if (plot.hasOwner() && !plot.isMerged()) {
try {
return backupProfileCache.get(new PlotCacheKey(plot), () -> new PlayerBackupProfile(plot.getOwnerAbs(), plot, this));
return backupProfileCache.get(new PlotCacheKey(plot), () -> this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot));
} catch (ExecutionException e) {
final BackupProfile profile = new PlayerBackupProfile(plot.getOwnerAbs(), plot, this);
final BackupProfile profile = this.playerBackupProfileFactory.create(plot.getOwnerAbs(), plot);
this.backupProfileCache.put(new PlotCacheKey(plot), profile);
return profile;
}

View File

@ -26,8 +26,8 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldFile;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;

View File

@ -25,7 +25,8 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.google.inject.Inject;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.backup.BackupProfile;
import com.plotsquared.core.backup.NullBackupProfile;
import com.plotsquared.core.backup.PlayerBackupProfile;
@ -35,6 +36,7 @@ import com.plotsquared.core.plot.Plot;
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.nio.file.Files;
import java.time.Instant;
@ -60,8 +62,11 @@ import java.util.stream.Stream;
permission = "plots.backup")
public final class Backup extends Command {
public Backup() {
private final BackupManager backupManager;
@Inject public Backup(@NotNull final BackupManager backupManager) {
super(MainCommand.getInstance(), true);
this.backupManager = backupManager;
}
private static boolean sendMessage(PlotPlayer player, Captions message, Object... args) {
@ -90,8 +95,7 @@ public final class Backup extends Command {
final Plot plot = player.getCurrentPlot();
if (plot != null) {
final BackupProfile backupProfile =
Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot);
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
if (backupProfile instanceof PlayerBackupProfile) {
final CompletableFuture<List<com.plotsquared.core.backup.Backup>> backupList =
backupProfile.listBackups();
@ -135,8 +139,7 @@ public final class Backup extends Command {
.hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) {
sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER);
} else {
final BackupProfile backupProfile =
Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot);
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
if (backupProfile instanceof NullBackupProfile) {
sendMessage(player, Captions.BACKUP_IMPOSSIBLE,
Captions.GENERIC_OTHER.getTranslated());
@ -175,8 +178,7 @@ public final class Backup extends Command {
.hasPermission(player, Captions.PERMISSION_ADMIN_BACKUP_OTHER)) {
sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_ADMIN_BACKUP_OTHER);
} else {
final BackupProfile backupProfile =
Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot);
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
if (backupProfile instanceof NullBackupProfile) {
sendMessage(player, Captions.BACKUP_IMPOSSIBLE,
Captions.GENERIC_OTHER.getTranslated());
@ -237,8 +239,7 @@ public final class Backup extends Command {
sendMessage(player, Captions.NOT_A_NUMBER, args[0]);
return;
}
final BackupProfile backupProfile =
Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(plot);
final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
if (backupProfile instanceof NullBackupProfile) {
sendMessage(player, Captions.BACKUP_IMPOSSIBLE,
Captions.GENERIC_OTHER.getTranslated());

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.database.Database;

View File

@ -28,8 +28,8 @@ package com.plotsquared.core.command;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.ConfigFile;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.inject.annotations.ConfigFile;
import com.plotsquared.core.inject.annotations.WorldFile;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;

View File

@ -26,8 +26,8 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldFile;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.MemorySection;

View File

@ -26,8 +26,8 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldFile;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.components;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.backup.BackupManager;
import com.plotsquared.core.command.MainCommand;
@ -36,13 +37,14 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotInventory;
import com.plotsquared.core.plot.PlotItemStack;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.PatternUtil;
import com.plotsquared.core.util.Permissions;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.item.ItemTypes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
@ -59,8 +61,13 @@ public class ComponentPresetManager {
private final List<ComponentPreset> presets;
private final String guiName;
private final EconHandler econHandler;
private final InventoryUtil inventoryUtil;
public ComponentPresetManager() {
@Inject public ComponentPresetManager(@Nullable final EconHandler econHandler, @NotNull final
InventoryUtil inventoryUtil) {
this.econHandler = econHandler;
this.inventoryUtil = inventoryUtil;
final File file = new File(Objects.requireNonNull(PlotSquared.platform()).getDirectory(), "components.yml");
if (!file.exists()) {
boolean created = false;
@ -144,7 +151,7 @@ public class ComponentPresetManager {
allowedPresets.add(componentPreset);
}
final int size = (int) Math.ceil((double) allowedPresets.size() / 9.0D);
final PlotInventory plotInventory = new PlotInventory(player, size, this.guiName) {
final PlotInventory plotInventory = new PlotInventory(this.inventoryUtil, player, size, this.guiName) {
@Override public boolean onClick(final int index) {
if (!player.getCurrentPlot().equals(plot)) {
return false;
@ -170,12 +177,12 @@ public class ComponentPresetManager {
return false;
}
if (componentPreset.getCost() > 0.0D && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()) {
if (EconHandler.getEconHandler().getMoney(player) < componentPreset.getCost()) {
if (componentPreset.getCost() > 0.0D && econHandler != null && plot.getArea().useEconomy()) {
if (econHandler.getMoney(player) < componentPreset.getCost()) {
Captions.PRESET_CANNOT_AFFORD.send(player);
return false;
} else {
EconHandler.getEconHandler().withdrawMoney(player, componentPreset.getCost());
econHandler.withdrawMoney(player, componentPreset.getCost());
Captions.REMOVED_BALANCE.send(player, componentPreset.getCost() + "");
}
}
@ -186,7 +193,7 @@ public class ComponentPresetManager {
current.setComponent(componentPreset.getComponent().name(), pattern);
}
MainUtil.sendMessage(player, Captions.GENERATING_COMPONENT);
GlobalBlockQueue.IMP.addEmptyTask(plot::removeRunning);
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(plot::removeRunning);
});
return false;
}
@ -196,7 +203,7 @@ public class ComponentPresetManager {
for (int i = 0; i < allowedPresets.size(); i++) {
final ComponentPreset preset = allowedPresets.get(i);
final List<String> lore = new ArrayList<>();
if (preset.getCost() > 0 && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()){
if (preset.getCost() > 0 && this.econHandler != null && plot.getArea().useEconomy()){
lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%",
String.format("%.2f", preset.getCost())));
}

View File

@ -27,7 +27,7 @@ package com.plotsquared.core.database;
import com.google.common.base.Charsets;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings;
@ -1842,7 +1842,7 @@ public class SQLManager implements AbstractDB {
}
Plot p = new Plot(plot_id, user, new HashSet<>(), new HashSet<>(),
new HashSet<>(), "", null, null, null,
new boolean[] {false, false, false, false}, time, id, this.eventDispatcher, this.plotListener);
new boolean[] {false, false, false, false}, time, id);
HashMap<PlotId, Plot> map = newPlots.get(areaID);
if (map != null) {
Plot last = map.put(p.getId(), p);

View File

@ -32,7 +32,6 @@ import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.queue.AreaBoundDelegateLocalBlockQueue;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.LocationOffsetDelegateLocalBlockQueue;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
@ -87,7 +86,7 @@ public class AugmentedUtils {
IndependentPlotGenerator generator = area.getGenerator();
// Mask
if (queue == null) {
queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false);
queue.setChunkObject(chunkObject);
}
LocalBlockQueue primaryMask;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.generator;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;

View File

@ -25,13 +25,16 @@
*/
package com.plotsquared.core.generator;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class GridPlotWorld extends PlotArea {
@ -39,7 +42,9 @@ public abstract class GridPlotWorld extends PlotArea {
public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final
PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration);
PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration,
@NotNull final GlobalBlockQueue blockQueue,
@Nullable final EconHandler econHandler) {
super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration, blockQueue, econHandler);
}
}

View File

@ -26,8 +26,9 @@
package com.plotsquared.core.generator;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener;
@ -48,7 +49,7 @@ public class HybridGen extends IndependentPlotGenerator {
private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
public HybridGen(@NotNull final EventDispatcher eventDispatcher,
@Inject public HybridGen(@NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
this.eventDispatcher = eventDispatcher;

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.generator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings;

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.generator;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.PlotFlagAddEvent;
@ -76,9 +77,8 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class HybridUtils {
public class HybridUtils {
public static HybridUtils manager;
public static Set<BlockVector2> regions;
public static int height;
public static Set<BlockVector2> chunks = new HashSet<>();
@ -86,14 +86,26 @@ public abstract class HybridUtils {
public static boolean UPDATE = false;
private final PlotAreaManager plotAreaManager;
private final ChunkManager chunkManager;
private final GlobalBlockQueue blockQueue;
private final WorldUtil worldUtil;
private final RegionManager regionManager;
private final SchematicHandler schematicHandler;
public HybridUtils(@NotNull final PlotAreaManager plotAreaManager) {
@Inject public HybridUtils(@NotNull final PlotAreaManager plotAreaManager,
@NotNull final ChunkManager chunkManager, @NotNull final GlobalBlockQueue blockQueue,
@NotNull final WorldUtil worldUtil, @NotNull final RegionManager regionManager, @NotNull final SchematicHandler schematicHandler) {
this.plotAreaManager = plotAreaManager;
this.chunkManager = chunkManager;
this.blockQueue = blockQueue;
this.worldUtil = worldUtil;
this.regionManager = regionManager;
this.schematicHandler = schematicHandler;
}
public static boolean regeneratePlotWalls(final PlotArea area) {
public void regeneratePlotWalls(final PlotArea area) {
PlotManager plotManager = area.getPlotManager();
return plotManager.regenerateAllPlotWalls();
plotManager.regenerateAllPlotWalls();
}
public void analyzeRegion(final String world, final CuboidRegion region,
@ -111,7 +123,7 @@ public abstract class HybridUtils {
*
*/
TaskManager.runTaskAsync(() -> {
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
final LocalBlockQueue queue = blockQueue.getNewQueue(world, false);
final BlockVector3 bot = region.getMinimumPoint();
final BlockVector3 top = region.getMaximumPoint();
@ -365,7 +377,7 @@ public abstract class HybridUtils {
for (int z = z1; z <= z2; z++) {
BlockState block = queue.getBlock(x, y, z);
boolean same =
Arrays.stream(blocks).anyMatch(p -> WorldUtil.IMP.isBlockSame(block, p));
Arrays.stream(blocks).anyMatch(p -> this.worldUtil.isBlockSame(block, p));
if (!same) {
count++;
}
@ -392,7 +404,7 @@ public abstract class HybridUtils {
return false;
}
HybridUtils.UPDATE = true;
Set<BlockVector2> regions = RegionManager.manager.getChunkChunks(area.getWorldName());
Set<BlockVector2> regions = this.regionManager.getChunkChunks(area.getWorldName());
return scheduleRoadUpdate(area, regions, extend, new HashSet<>());
}
@ -424,7 +436,7 @@ public abstract class HybridUtils {
if (!regenedRoad) {
PlotSquared.debug("Failed to regenerate roads.");
}
ChunkManager.manager.unloadChunk(area.getWorldName(), chunk, true);
chunkManager.unloadChunk(area.getWorldName(), chunk, true);
}
PlotSquared.debug("Cancelled road task");
return;
@ -460,7 +472,7 @@ public abstract class HybridUtils {
}
}
if (!chunks.isEmpty()) {
TaskManager.IMP.sync(new RunnableVal<Object>() {
TaskManager.getImplementation().sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
long start = System.currentTimeMillis();
Iterator<BlockVector2> iterator = chunks.iterator();
@ -489,15 +501,14 @@ public abstract class HybridUtils {
int sz = loc.getZ() << 5;
for (int x = sx; x < sx + 32; x++) {
for (int z = sz; z < sz + 32; z++) {
ChunkManager.manager
.unloadChunk(area.getWorldName(), BlockVector2.at(x, z),
chunkManager.unloadChunk(area.getWorldName(), BlockVector2.at(x, z),
true);
}
}
PlotSquared.debug(" - Potentially skipping 1024 chunks");
PlotSquared.debug(" - TODO: recommend chunkster if corrupt");
}
GlobalBlockQueue.IMP.addEmptyTask(() -> TaskManager.runTaskLater(task, 20));
blockQueue.addEmptyTask(() -> TaskManager.runTaskLater(task, 20));
});
}
}
@ -507,7 +518,7 @@ public abstract class HybridUtils {
public boolean setupRoadSchematic(Plot plot) {
final String world = plot.getWorldName();
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
final LocalBlockQueue queue = blockQueue.getNewQueue(world, false);
Location bot = plot.getBottomAbs().subtract(1, 0, 1);
Location top = plot.getTopAbs();
final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea();
@ -531,13 +542,12 @@ public abstract class HybridUtils {
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.getArea()
.toString() + File.separator;
SchematicHandler.manager.getCompoundTag(world, sideRoad, new RunnableVal<CompoundTag>() {
this.schematicHandler.getCompoundTag(world, sideRoad, new RunnableVal<CompoundTag>() {
@Override public void run(CompoundTag value) {
SchematicHandler.manager.save(value, dir + "sideroad.schem");
SchematicHandler.manager
.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
schematicHandler.save(value, dir + "sideroad.schem");
schematicHandler.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
@Override public void run(CompoundTag value) {
SchematicHandler.manager.save(value, dir + "intersection.schem");
schematicHandler.save(value, dir + "intersection.schem");
plotworld.ROAD_SCHEMATIC_ENABLED = true;
try {
plotworld.setupSchematics();
@ -595,9 +605,9 @@ public abstract class HybridUtils {
z -= plotWorld.ROAD_OFFSET_Z;
final int finalX = x;
final int finalZ = z;
LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(plotWorld.getWorldName(), false);
LocalBlockQueue queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false);
if (id1 == null || id2 == null || id1 != id2) {
ChunkManager.manager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
if (id1 != null) {
Plot p1 = area.getPlotAbs(id1);
if (p1 != null && p1.hasOwner() && p1.isMerged()) {

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.generator;
import com.google.inject.Inject;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
@ -47,7 +48,7 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
private final PlotAreaManager plotAreaManager;
public SingleWorldGenerator(@NotNull final PlotAreaManager plotAreaManager) {
@Inject public SingleWorldGenerator(@NotNull final PlotAreaManager plotAreaManager) {
this.plotAreaManager = plotAreaManager;
}

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.generator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener;

View File

@ -0,0 +1,36 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface BackgroundPipeline {
}

View File

@ -23,7 +23,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.annoations;
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@ -0,0 +1,11 @@
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConsoleActor {
}

View File

@ -0,0 +1,11 @@
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface DefaultGenerator {
}

View File

@ -0,0 +1,36 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ImpromptuPipeline {
}

View File

@ -23,14 +23,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.annoations;
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface WorldConfig {
}

View File

@ -23,14 +23,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.annoations;
package com.plotsquared.core.inject.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface WorldFile {
}

View File

@ -0,0 +1,13 @@
package com.plotsquared.core.inject.factory;
import com.plotsquared.core.backup.PlayerBackupProfile;
import com.plotsquared.core.plot.Plot;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public interface PlayerBackupProfileFactory {
PlayerBackupProfile create(@NotNull UUID uuid, @NotNull Plot plot);
}

View File

@ -0,0 +1,59 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.inject.modules;
import com.google.inject.AbstractModule;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.inject.annotations.BackgroundPipeline;
import com.plotsquared.core.inject.annotations.ConfigFile;
import com.plotsquared.core.inject.annotations.ImpromptuPipeline;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldFile;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import java.io.File;
public class PlotSquaredModule extends AbstractModule {
@Override protected void configure() {
final PlotSquared plotSquared = PlotSquared.get();
bind(YamlConfiguration.class).annotatedWith(WorldConfig.class).toInstance(plotSquared.getWorldConfiguration());
bind(File.class).annotatedWith(WorldFile.class).toInstance(plotSquared.getWorldsFile());
bind(File.class).annotatedWith(ConfigFile.class).toInstance(plotSquared.getConfigFile());
bind(PlotAreaManager.class).toInstance(plotSquared.getPlotAreaManager());
bind(PlotListener.class).toInstance(plotSquared.getPlotListener());
bind(UUIDPipeline.class).annotatedWith(ImpromptuPipeline.class).toInstance(plotSquared.getImpromptuUUIDPipeline());
bind(UUIDPipeline.class).annotatedWith(BackgroundPipeline.class).toInstance(plotSquared.getBackgroundUUIDPipeline());
bind(WorldEdit.class).toInstance(WorldEdit.getInstance());
bind(EventDispatcher.class).toInstance(plotSquared.getEventDispatcher());
}
}

View File

@ -59,27 +59,30 @@ import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
@RequiredArgsConstructor public class PlotListener {
public class PlotListener {
private final HashMap<UUID, Interval> feedRunnable = new HashMap<>();
private final HashMap<UUID, Interval> healRunnable = new HashMap<>();
private final EventDispatcher eventDispatcher;
public PlotListener(@Nullable final EventDispatcher eventDispatcher) {
this.eventDispatcher = eventDispatcher;
}
public void startRunnable() {
TaskManager.runTaskRepeat(() -> {
if (!healRunnable.isEmpty()) {
@ -90,15 +93,14 @@ import java.util.UUID;
++value.count;
if (value.count == value.interval) {
value.count = 0;
PlotPlayer player = WorldUtil.IMP.wrapPlayer(entry.getKey());
PlotPlayer<?> player = PlotPlayer.wrap(entry.getKey());
if (player == null) {
iterator.remove();
continue;
}
double level = WorldUtil.IMP.getHealth(player);
double level = PlotSquared.platform().getWorldUtil().getHealth(player);
if (level != value.max) {
WorldUtil.IMP
.setHealth(player, Math.min(level + value.amount, value.max));
PlotSquared.platform().getWorldUtil().setHealth(player, Math.min(level + value.amount, value.max));
}
}
}
@ -111,15 +113,14 @@ import java.util.UUID;
++value.count;
if (value.count == value.interval) {
value.count = 0;
PlotPlayer player = WorldUtil.IMP.wrapPlayer(entry.getKey());
PlotPlayer<?> player = PlotSquared.platform().getWorldUtil().wrapPlayer(entry.getKey());
if (player == null) {
iterator.remove();
continue;
}
int level = WorldUtil.IMP.getFoodLevel(player);
int level = PlotSquared.platform().getWorldUtil().getFoodLevel(player);
if (level != value.max) {
WorldUtil.IMP
.setFoodLevel(player, Math.min(level + value.amount, value.max));
PlotSquared.platform().getWorldUtil().setFoodLevel(player, Math.min(level + value.amount, value.max));
}
}
}

View File

@ -44,6 +44,7 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.HashMap;
@ -55,17 +56,19 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
private final Set<CuboidRegion> mask;
private final String world;
private final int max;
private final WorldUtil worldUtil;
int Ecount = 0;
boolean Eblocked = false;
private int count;
private Extent parent;
private Map<Long, Integer[]> tileEntityCount = new HashMap<>();
public ProcessedWEExtent(String world, Set<CuboidRegion> mask, int max, Extent child,
Extent parent) {
public ProcessedWEExtent(String world, Set<CuboidRegion> mask, int max, Extent child, Extent parent, @NotNull final WorldUtil worldUtil) {
super(child);
this.mask = mask;
this.world = world;
this.worldUtil = worldUtil;
if (max == -1) {
max = Integer.MAX_VALUE;
}
@ -92,10 +95,10 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 location, T block)
throws WorldEditException {
final boolean isTile = WorldUtil.IMP.getTileEntityTypes().contains(block.getBlockType());
final boolean isTile = this.worldUtil.getTileEntityTypes().contains(block.getBlockType());
if (isTile) {
final Integer[] tileEntityCount = this.tileEntityCount.computeIfAbsent(getChunkKey(location),
key -> new Integer[] {WorldUtil.IMP.getTileEntityCount(world,
key -> new Integer[] {this.worldUtil.getTileEntityCount(world,
BlockVector2.at(location.getBlockX() >> 4, location.getBlockZ() >> 4))});
if (tileEntityCount[0] >= Settings.Chunk_Processor.MAX_TILES) {
return false;

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.listener;
import com.google.inject.Inject;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
@ -33,6 +34,7 @@ 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;
import com.plotsquared.core.util.WorldUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
@ -50,9 +52,11 @@ import java.util.Set;
public class WESubscriber {
private final PlotAreaManager plotAreaManager;
public WESubscriber(@NotNull final PlotAreaManager plotAreaManager) {
private final WorldUtil worldUtil;
@Inject public WESubscriber(@NotNull final PlotAreaManager plotAreaManager, @NotNull final WorldUtil worldUtil) {
this.plotAreaManager = plotAreaManager;
this.worldUtil = worldUtil;
}
@Subscribe(priority = Priority.VERY_EARLY) public void onEditSession(EditSessionEvent event) {
@ -99,7 +103,7 @@ public class WESubscriber {
if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(
new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(),
event.getExtent()));
event.getExtent(), this.worldUtil));
}
} else if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(new WEExtent(mask, event.getExtent()));

View File

@ -267,7 +267,7 @@ public final class Location implements Comparable<Location> {
/**
* Check whether or not the location belongs to a plot area
*
* @return {@code true} if the location belongs to a plot area, else {@link false}
* @return {@code true} if the location belongs to a plot area, else {@code false}
*/
public boolean isPlotArea() {
return this.getPlotArea() != null;
@ -276,7 +276,7 @@ public final class Location implements Comparable<Location> {
/**
* Check whether or not the location belongs to a plot road
*
* @return {@code true} if the location belongs to a plot road, else {@link false}
* @return {@code true} if the location belongs to a plot road, else {@code false}
*/
public boolean isPlotRoad() {
final PlotArea area = this.getPlotArea();
@ -286,7 +286,7 @@ public final class Location implements Comparable<Location> {
/**
* Checks if anyone owns a plot at the current location.
*
* @return {@link true} if the location is a road, not a plot area, or if the plot is unclaimed.
* @return {@code true} if the location is a road, not a plot area, or if the plot is unclaimed.
*/
public boolean isUnownedPlotArea() {
final PlotArea area = this.getPlotArea();

View File

@ -25,14 +25,17 @@
*/
package com.plotsquared.core.player;
import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.RequiredType;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.inject.annotations.ConsoleActor;
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.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.CuboidRegion;
@ -40,6 +43,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
@ -47,8 +51,14 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
private static ConsolePlayer instance;
private ConsolePlayer(final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) {
super(plotAreaManager, eventDispatcher);
private final Actor actor;
@Inject private ConsolePlayer(@NotNull final PlotAreaManager plotAreaManager,
@NotNull final EventDispatcher eventDispatcher,
@ConsoleActor @NotNull final Actor actor,
@Nullable final EconHandler econHandler) {
super(plotAreaManager, eventDispatcher, econHandler);
this.actor = actor;
final PlotArea[] areas = plotAreaManager.getAllPlotAreas();
final PlotArea area;
if (areas.length > 0) {
@ -70,14 +80,14 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
public static ConsolePlayer getConsole() {
if (instance == null) {
instance = new ConsolePlayer(PlotSquared.get().getPlotAreaManager(), PlotSquared.get().getEventDispatcher());
instance = PlotSquared.platform().getInjector().getInstance(ConsolePlayer.class);
instance.teleport(instance.getLocation());
}
return instance;
}
@Override public Actor toActor() {
return PlotSquared.platform().getConsole();
return this.actor;
}
@Override public Actor getPlatformPlayer() {

View File

@ -91,10 +91,12 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher;
private final EconHandler econHandler;
public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) {
public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, @Nullable final EconHandler econHandler) {
this.plotAreaManager = plotAreaManager;
this.eventDispatcher = eventDispatcher;
this.econHandler = econHandler;
}
public static <T> PlotPlayer<T> from(@NonNull final T object) {
@ -764,23 +766,24 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer
* The amount of money this Player has.
*/
public double getMoney() {
return EconHandler.getEconHandler() == null ? 0 : EconHandler.getEconHandler().getMoney(this);
return this.econHandler == null ? 0 : this.econHandler.getMoney(this);
}
public void withdraw(double amount) {
if (EconHandler.getEconHandler() != null) {
EconHandler.getEconHandler().withdrawMoney(this, amount);
if (this.econHandler != null) {
this.econHandler.withdrawMoney(this, amount);
}
}
public void deposit(double amount) {
if (EconHandler.getEconHandler() != null) {
EconHandler.getEconHandler().depositMoney(this, amount);
if (this.econHandler != null) {
this.econHandler.depositMoney(this, amount);
}
}
@FunctionalInterface
public interface PlotPlayerConverter<BaseObject> {
PlotPlayer convert(BaseObject object);
PlotPlayer<?> convert(BaseObject object);
}
}

View File

@ -38,6 +38,7 @@ import com.plotsquared.core.events.PlotUnlinkEvent;
import com.plotsquared.core.events.Result;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.SquarePlotWorld;
import com.plotsquared.core.inject.annotations.ImpromptuPipeline;
import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.BlockLoc;
import com.plotsquared.core.location.Direction;
@ -64,6 +65,7 @@ import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
@ -124,9 +126,16 @@ public class Plot {
private static Set<CuboidRegion> regions_cache;
@NotNull private final PlotId id;
@NotNull private final EventDispatcher eventDispatcher;
@NotNull private final PlotListener plotListener;
// These will be injected
private EventDispatcher eventDispatcher;
private PlotListener plotListener;
private RegionManager regionManager;
private GlobalBlockQueue blockQueue;
private WorldUtil worldUtil;
private SchematicHandler schematicHandler;
@ImpromptuPipeline private UUIDPipeline impromptuPipeline;
/**
* Plot flag container
*/
@ -197,9 +206,8 @@ public class Plot {
* @param owner the plot owner
* @see Plot#getPlot(Location) for existing plots
*/
public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner,
@NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) {
this(area, id, owner, 0, eventDispatcher, plotListener);
public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner) {
this(area, id, owner, 0);
}
/**
@ -210,9 +218,8 @@ public class Plot {
* @param id the plot id
* @see Plot#getPlot(Location) for existing plots
*/
public Plot(@NotNull final PlotArea area, @NotNull final PlotId id,
@NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) {
this(area, id, null, 0, eventDispatcher, plotListener);
public Plot(@NotNull final PlotArea area, @NotNull final PlotId id) {
this(area, id, null, 0);
}
/**
@ -226,15 +233,13 @@ public class Plot {
* @param temp Represents whatever the database manager needs it to
* @see Plot#getPlot(Location) for existing plots
*/
public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, final int temp,
@NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) {
public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, final int temp) {
this.area = area;
this.id = id;
this.owner = owner;
this.temp = temp;
this.flagContainer.setParentContainer(area.getFlagContainer());
this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener;
PlotSquared.platform().getInjector().injectMembers(this);
}
/**
@ -249,8 +254,7 @@ public class Plot {
*/
public Plot(@NotNull PlotId id, UUID owner, HashSet<UUID> trusted, HashSet<UUID> members,
HashSet<UUID> denied, String alias, BlockLoc position, Collection<PlotFlag<?, ?>> flags,
PlotArea area, boolean[] merged, long timestamp, int temp,
@NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) {
PlotArea area, boolean[] merged, long timestamp, int temp) {
this.id = id;
this.area = area;
this.owner = owner;
@ -271,8 +275,7 @@ public class Plot {
}
}
}
this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener;
PlotSquared.platform().getInjector().injectMembers(this);
}
/**
@ -950,7 +953,7 @@ public class Plot {
Runnable run = () -> {
for (CuboidRegion region : regions) {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
RegionManager.manager.clearAllEntities(corners[0], corners[1]);
regionManager.clearAllEntities(corners[0], corners[1]);
}
TaskManager.runTask(whenDone);
};
@ -961,14 +964,13 @@ public class Plot {
manager.claimPlot(current);
}
}
GlobalBlockQueue.IMP.addEmptyTask(run);
blockQueue.addEmptyTask(run);
return;
}
Plot current = queue.poll();
if (Plot.this.area.getTerrain() != PlotAreaTerrainType.NONE) {
try {
RegionManager.manager
.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false,
regionManager.regenerateRegion(current.getBottomAbs(), current.getTopAbs(), false,
this);
} catch (UnsupportedOperationException exception) {
MainUtil.sendMessage(null,
@ -1005,7 +1007,7 @@ public class Plot {
return;
}
CuboidRegion region = regions.poll();
RegionManager.manager.setBiome(region, extendBiome, biome, getWorldName(), this);
regionManager.setBiome(region, extendBiome, biome, getWorldName(), this);
}
};
run.run();
@ -1057,7 +1059,7 @@ public class Plot {
current.setMerged(merged);
}
if (createSign) {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
blockQueue.addEmptyTask(() -> {
TaskManager.runTaskAsync(() -> {
for (Plot current : plots) {
current.setSign(MainUtil.getName(current.getOwnerAbs()));
@ -1092,14 +1094,13 @@ public class Plot {
"%plr%", name),
Captions.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll(
"%plr%", name)};
WorldUtil.IMP
.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(),
this.worldUtil.setSign(this.getWorldName(), location.getX(), location.getY(), location.getZ(),
lines);
}
}
public boolean isLoaded() {
return WorldUtil.IMP.isWorld(getWorldName());
return this.worldUtil.isWorld(getWorldName());
}
/**
@ -1270,7 +1271,7 @@ public class Plot {
public int[] countEntities() {
int[] count = new int[6];
for (Plot current : this.getConnectedPlots()) {
int[] result = RegionManager.manager.countEntities(current);
int[] result = this.regionManager.countEntities(current);
count[CAP_ENTITY] += result[CAP_ENTITY];
count[CAP_ANIMAL] += result[CAP_ANIMAL];
count[CAP_MONSTER] += result[CAP_MONSTER];
@ -1377,7 +1378,7 @@ public class Plot {
result.accept(location);
return;
}
WorldUtil.IMP.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> {
this.worldUtil.getHighestBlock(getWorldName(), location.getX(), location.getZ(), y -> {
int height = y;
if (area.allowSigns()) {
height = Math.max(y, getManager().getSignLoc(this).getY());
@ -1398,8 +1399,7 @@ public class Plot {
if (!isLoaded()) {
return location;
}
int y = WorldUtil.IMP
.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ());
int y = this.worldUtil.getHighestBlockSynchronous(getWorldName(), location.getX(), location.getZ());
if (area.allowSigns()) {
y = Math.max(y, getManager().getSignLoc(this).getY());
}
@ -1415,7 +1415,7 @@ public class Plot {
+ largest.getMinimumPoint().getX();
int z = largest.getMinimumPoint().getZ() - 1;
PlotManager manager = getManager();
int y = isLoaded() ? WorldUtil.IMP.getHighestBlockSynchronous(getWorldName(), x, z) : 62;
int y = isLoaded() ? this.worldUtil.getHighestBlockSynchronous(getWorldName(), x, z) : 62;
if (area.allowSigns() && (y <= 0 || y >= 255)) {
y = Math.max(y, manager.getSignLoc(this).getY() - 1);
}
@ -1429,7 +1429,7 @@ public class Plot {
int z = largest.getMinimumPoint().getZ() - 1;
PlotManager manager = getManager();
if (isLoaded()) {
WorldUtil.IMP.getHighestBlock(getWorldName(), x, z, y -> {
this.worldUtil.getHighestBlock(getWorldName(), x, z, y -> {
int height = y;
if (area.allowSigns() && (y <= 0 || y >= 255)) {
height = Math.max(y, manager.getSignLoc(this).getY() - 1);
@ -1460,9 +1460,8 @@ public class Plot {
if (!isLoaded()) {
return location;
}
if (!WorldUtil.IMP.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
location = location.withY(Math.max(1 + WorldUtil.IMP
.getHighestBlockSynchronous(this.getWorldName(), location.getX(),
if (!this.worldUtil.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
location = location.withY(Math.max(1 + this.worldUtil.getHighestBlockSynchronous(this.getWorldName(), location.getX(),
location.getZ()), bottom.getY()));
}
return location;
@ -1485,10 +1484,9 @@ public class Plot {
result.accept(location);
return;
}
WorldUtil.IMP.getBlock(location, block -> {
this.worldUtil.getBlock(location, block -> {
if (!block.getBlockType().getMaterial().isAir()) {
WorldUtil.IMP
.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
y -> result.accept(location.withY(Math.max(1 + y, bottom.getY()))));
} else {
result.accept(location);
@ -1547,7 +1545,7 @@ public class Plot {
}
int y = loc.getY() < 1 ?
(isLoaded() ?
WorldUtil.IMP.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 :
this.worldUtil.getHighestBlockSynchronous(plot.getWorldName(), x, z) + 1 :
63) :
loc.getY();
return Location.at(plot.getWorldName(), x, y, z);
@ -1577,7 +1575,7 @@ public class Plot {
}
if (loc.getY() < 1) {
if (isLoaded()) {
WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z,
this.worldUtil.getHighestBlock(plot.getWorldName(), x, z,
y -> result.accept(Location.at(plot.getWorldName(), x, y + 1, z)));
} else {
result.accept(Location.at(plot.getWorldName(), x, 63, z));
@ -1680,7 +1678,7 @@ public class Plot {
* This should not need to be called
*/
public void refreshChunks() {
LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false);
LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false);
HashSet<BlockVector2> chunks = new HashSet<>();
for (CuboidRegion region : Plot.this.getRegions()) {
for (int x = region.getMinimumPoint().getX() >> 4;
@ -1704,7 +1702,7 @@ public class Plot {
return;
}
Location location = manager.getSignLoc(this);
LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false);
LocalBlockQueue queue = this.blockQueue.getNewQueue(getWorldName(), false);
queue.setBlock(location.getX(), location.getY(), location.getZ(),
BlockTypes.AIR.getDefaultState());
queue.flush();
@ -1718,7 +1716,7 @@ public class Plot {
this.setSign("unknown");
return;
}
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(this.getOwnerAbs(), (username, sign) ->
this.impromptuPipeline.getSingle(this.getOwnerAbs(), (username, sign) ->
this.setSign(username));
}
@ -1769,18 +1767,18 @@ public class Plot {
Schematic sch;
try {
if (schematic == null || schematic.isEmpty()) {
sch = SchematicHandler.manager.getSchematic(plotworld.getSchematicFile());
sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
} else {
sch = SchematicHandler.manager.getSchematic(schematic);
sch = schematicHandler.getSchematic(schematic);
if (sch == null) {
sch = SchematicHandler.manager.getSchematic(plotworld.getSchematicFile());
sch = schematicHandler.getSchematic(plotworld.getSchematicFile());
}
}
} catch (SchematicHandler.UnsupportedFormatException e) {
e.printStackTrace();
return true;
}
SchematicHandler.manager.paste(sch, this, 0, 1, 0, Settings.Schematics.PASTE_ON_TOP,
schematicHandler.paste(sch, this, 0, 1, 0, Settings.Schematics.PASTE_ON_TOP,
new RunnableVal<Boolean>() {
@Override public void run(Boolean value) {
if (value) {
@ -1827,7 +1825,7 @@ public class Plot {
DBFunc.createPlotAndSettings(this, () -> {
PlotArea plotworld = Plot.this.area;
if (notify && plotworld.isAutoMerge()) {
PlotPlayer player = WorldUtil.IMP.wrapPlayer(uuid);
PlotPlayer player = this.worldUtil.wrapPlayer(uuid);
PlotMergeEvent event = this.eventDispatcher
.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player);
if (event.getEventResult() == Result.DENY) {
@ -1861,7 +1859,7 @@ public class Plot {
* Retrieve the biome of the plot.
*/
public void getBiome(Consumer<BiomeType> result) {
this.getCenter(location -> WorldUtil.IMP
this.getCenter(location -> this.worldUtil
.getBiome(location.getWorldName(), location.getX(), location.getZ(), result));
}
@ -1870,7 +1868,7 @@ public class Plot {
*/
@Deprecated public BiomeType getBiomeSynchronous() {
final Location location = this.getCenterSynchronous();
return WorldUtil.IMP
return this.worldUtil
.getBiomeSynchronous(location.getWorldName(), location.getX(), location.getZ());
}
@ -2022,7 +2020,7 @@ public class Plot {
Location top = this.getTopAbs();
Location pos1 = Location.at(this.getWorldName(), top.getX(), 0, bot.getZ());
Location pos2 = Location.at(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ());
RegionManager.manager.regenerateRegion(pos1, pos2, true, null);
this.regionManager.regenerateRegion(pos1, pos2, true, null);
} else if (this.area.getTerrain()
!= PlotAreaTerrainType.ALL) { // no road generated => no road to remove
this.area.getPlotManager().removeRoadEast(this);
@ -2176,7 +2174,7 @@ public class Plot {
* Export the plot as a schematic to the configured output directory.
*/
public void export(final RunnableVal<Boolean> whenDone) {
SchematicHandler.manager.getCompoundTag(this, new RunnableVal<CompoundTag>() {
this.schematicHandler.getCompoundTag(this, new RunnableVal<CompoundTag>() {
@Override public void run(final CompoundTag value) {
if (value == null) {
if (whenDone != null) {
@ -2187,7 +2185,7 @@ public class Plot {
TaskManager.runTaskAsync(() -> {
String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil
.getName(Plot.this.getOwnerAbs());
boolean result = SchematicHandler.manager.save(value,
boolean result = schematicHandler.save(value,
Settings.Paths.SCHEMATICS + File.separator + name + ".schem");
if (whenDone != null) {
whenDone.value = result;
@ -2205,9 +2203,9 @@ public class Plot {
* @param whenDone value will be null if uploading fails
*/
public void upload(final RunnableVal<URL> whenDone) {
SchematicHandler.manager.getCompoundTag(this, new RunnableVal<CompoundTag>() {
this.schematicHandler.getCompoundTag(this, new RunnableVal<CompoundTag>() {
@Override public void run(CompoundTag value) {
SchematicHandler.manager.upload(value, null, null, whenDone);
schematicHandler.upload(value, null, null, whenDone);
}
});
}
@ -2221,7 +2219,7 @@ public class Plot {
* @see WorldUtil
*/
public void uploadWorld(RunnableVal<URL> whenDone) {
WorldUtil.IMP.upload(this, null, null, whenDone);
this.worldUtil.upload(this, null, null, whenDone);
}
@Override public boolean equals(Object obj) {
@ -2394,7 +2392,7 @@ public class Plot {
Location top = this.getTopAbs();
Location pos1 = Location.at(this.getWorldName(), bot.getX(), 0, top.getZ());
Location pos2 = Location.at(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ());
RegionManager.manager.regenerateRegion(pos1, pos2, true, null);
this.regionManager.regenerateRegion(pos1, pos2, true, null);
} else if (this.area.getTerrain()
!= PlotAreaTerrainType.ALL) { // no road generated => no road to remove
this.getManager().removeRoadSouth(this);
@ -2570,7 +2568,7 @@ public class Plot {
Plot other = this.getRelative(1, 1);
Location pos1 = this.getTopAbs().add(1, 0, 1).withY(0);
Location pos2 = other.getBottomAbs().subtract(1, 0, 1).withY(MAX_HEIGHT);
RegionManager.manager.regenerateRegion(pos1, pos2, true, null);
this.regionManager.regenerateRegion(pos1, pos2, true, null);
} else if (this.area.getTerrain()
!= PlotAreaTerrainType.ALL) { // no road generated => no road to remove
this.area.getPlotManager().removeRoadSouthEast(this);
@ -3228,7 +3226,7 @@ public class Plot {
Location pos2 = corners[1];
Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
Location pos4 = pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
RegionManager.manager.swap(pos1, pos2, pos3, pos4, this);
regionManager.swap(pos1, pos2, pos3, pos4, this);
}
}
}.run();
@ -3259,7 +3257,7 @@ public class Plot {
final Location pos1 = corners[0];
final Location pos2 = corners[1];
Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
RegionManager.manager.copyRegion(pos1, pos2, newPos, task);
regionManager.copyRegion(pos1, pos2, newPos, task);
}
}.run();
}
@ -3353,7 +3351,7 @@ public class Plot {
Location pos1 = corners[0];
Location pos2 = corners[1];
Location newPos = pos1 .add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
RegionManager.manager.copyRegion(pos1, pos2, newPos, this);
regionManager.copyRegion(pos1, pos2, newPos, this);
}
};
run.run();

View File

@ -28,7 +28,7 @@ package com.plotsquared.core.plot;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.collection.QuadMap;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
@ -140,15 +140,21 @@ public abstract class PlotArea {
private final EventDispatcher eventDispatcher;
private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
private final GlobalBlockQueue globalBlockQueue;
private final EconHandler econHandler;
public PlotArea(@NotNull final String worldName, @Nullable final String id,
@NotNull IndependentPlotGenerator generator, @Nullable final PlotId min,
@Nullable final PlotId max, @NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener, @WorldConfig @Nullable final YamlConfiguration worldConfiguration) {
@NotNull final PlotListener plotListener,
@WorldConfig @Nullable final YamlConfiguration worldConfiguration,
@NotNull final GlobalBlockQueue blockQueue,
@Nullable final EconHandler econHandler) {
this.worldName = worldName;
this.id = id;
this.plotManager = createManager();
this.generator = generator;
this.globalBlockQueue = blockQueue;
if (min == null || max == null) {
if (min != max) {
throw new IllegalArgumentException(
@ -164,12 +170,13 @@ public abstract class PlotArea {
this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener;
this.worldConfiguration = worldConfiguration;
this.econHandler = econHandler;
}
@NotNull protected abstract PlotManager createManager();
public LocalBlockQueue getQueue(final boolean autoQueue) {
return GlobalBlockQueue.IMP.getNewQueue(worldName, autoQueue);
return this.globalBlockQueue.getNewQueue(worldName, autoQueue);
}
/**
@ -288,7 +295,7 @@ public abstract class PlotArea {
this.schematicClaimSpecify = config.getBoolean("schematic.specify_on_claim");
this.schematics = new ArrayList<>(config.getStringList("schematic.schematics"));
this.schematics.replaceAll(String::toLowerCase);
this.useEconomy = config.getBoolean("economy.use") && EconHandler.getEconHandler() != null;
this.useEconomy = config.getBoolean("economy.use") && this.econHandler != null;
ConfigurationSection priceSection = config.getConfigurationSection("economy.prices");
if (this.useEconomy) {
this.prices = new HashMap<>();
@ -650,7 +657,7 @@ public abstract class PlotArea {
//todo check if this method is needed in this class
public int getPlotCount(@Nullable final PlotPlayer player) {
public int getPlotCount(@Nullable final PlotPlayer<?> player) {
return player != null ? getPlotCount(player.getUUID()) : 0;
}
@ -661,7 +668,7 @@ public abstract class PlotArea {
|| id.y > this.max.y)) {
return null;
}
return new Plot(this, id, this.eventDispatcher, this.plotListener);
return new Plot(this, id);
}
return plot;
}
@ -673,7 +680,7 @@ public abstract class PlotArea {
|| id.y > this.max.y)) {
return null;
}
return new Plot(this, id, this.eventDispatcher, this.plotListener);
return new Plot(this, id);
}
return plot.getBasePlot(false);
}

View File

@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.InventoryUtil;
import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
public class PlotInventory {
@ -38,19 +39,14 @@ public class PlotInventory {
private final PlotItemStack[] items;
private String title;
private boolean open = false;
public PlotInventory(PlotPlayer<?> player) {
this.size = 4;
this.title = null;
this.player = player;
this.items = InventoryUtil.manager.getItems(player);
}
public PlotInventory(PlotPlayer<?> player, int size, String name) {
private final InventoryUtil inventoryUtil;
public PlotInventory(@NotNull final InventoryUtil inventoryUtil, PlotPlayer<?> player, int size, String name) {
this.size = size;
this.title = name == null ? "" : name;
this.player = player;
this.items = new PlotItemStack[size * 9];
this.inventoryUtil = inventoryUtil;
}
public static boolean hasPlotInventoryOpen(@NonNull final PlotPlayer<?> plotPlayer) {
@ -84,7 +80,7 @@ public class PlotInventory {
} else {
this.open = true;
setPlotInventoryOpen(player, this);
InventoryUtil.manager.open(this);
this.inventoryUtil.open(this);
}
}
@ -93,13 +89,13 @@ public class PlotInventory {
return;
}
removePlotInventoryOpen(player);
InventoryUtil.manager.close(this);
this.inventoryUtil.close(this);
this.open = false;
}
public void setItem(int index, PlotItemStack item) {
this.items[index] = item;
InventoryUtil.manager.setItem(this, index, item);
this.inventoryUtil.setItem(this, index, item);
}
public PlotItemStack getItem(int index) {

View File

@ -80,7 +80,7 @@ public class PlotAnalysis {
}
public static void analyzePlot(Plot plot, RunnableVal<PlotAnalysis> whenDone) {
HybridUtils.manager.analyzePlot(plot, whenDone);
PlotSquared.platform().getInjector().getInstance(HybridUtils.class).analyzePlot(plot, whenDone);
}
/**

View File

@ -26,7 +26,7 @@
package com.plotsquared.core.plot.world;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;

View File

@ -25,7 +25,7 @@
*/
package com.plotsquared.core.plot.world;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.collection.ArrayUtil;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.generator.SingleWorldGenerator;

View File

@ -51,6 +51,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
private int lastZ = Integer.MIN_VALUE;
private boolean setbiome = false;
private GlobalBlockQueue globalBlockQueue;
public BasicLocalBlockQueue(String world) {
super(world);
this.world = world;
@ -182,8 +184,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
}
@Override public void flush() {
GlobalBlockQueue.IMP.dequeue(this);
TaskManager.IMP.sync(new RunnableVal<Object>() {
this.globalBlockQueue.dequeue(this);
TaskManager.getImplementation().sync(new RunnableVal<Object>() {
@Override public void run(Object value) {
while (next()) {
}

View File

@ -38,7 +38,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class GlobalBlockQueue {
public static GlobalBlockQueue IMP;
private final int PARALLEL_THREADS;
private final ConcurrentLinkedDeque<LocalBlockQueue> activeQueues;
private final ConcurrentLinkedDeque<LocalBlockQueue> inactiveQueues;
@ -92,6 +91,8 @@ public class GlobalBlockQueue {
public LocalBlockQueue getNewQueue(String world, boolean autoQueue) {
LocalBlockQueue queue = provider.getNewQueue(world);
// Auto-inject into the queue
PlotSquared.platform().getInjector().injectMembers(queue);
if (autoQueue) {
inactiveQueues.add(queue);
}

View File

@ -48,12 +48,17 @@ public abstract class LocalBlockQueue {
@Getter @Setter private boolean forceSync = false;
@Getter @Setter @Nullable private Object chunkObject;
private SchematicHandler schematicHandler;
private WorldUtil worldUtil;
private GlobalBlockQueue blockQueue;
/**
* Needed for compatibility with FAWE.
*
* @param world unused
*/
@Deprecated public LocalBlockQueue(String world) {
PlotSquared.platform().getInjector().injectMembers(this);
}
public ScopedLocalBlockQueue getForChunk(int x, int z) {
@ -94,7 +99,7 @@ public abstract class LocalBlockQueue {
}
public boolean setTile(int x, int y, int z, CompoundTag tag) {
SchematicHandler.manager.restoreTile(this, tag, x, y, z);
this.schematicHandler.restoreTile(this, tag, x, y, z);
return true;
}
@ -123,18 +128,18 @@ public abstract class LocalBlockQueue {
fixChunkLighting(x, z);
BlockVector2 loc = BlockVector2.at(x, z);
for (final PlotPlayer pp : PlotSquared.platform().getPlayerManager().getPlayers()) {
for (final PlotPlayer<?> pp : PlotSquared.platform().getPlayerManager().getPlayers()) {
Location pLoc = pp.getLocation();
if (!StringMan.isEqual(getWorld(), pLoc.getWorldName()) || !pLoc.getChunkLocation()
.equals(loc)) {
continue;
}
pp.teleport(pLoc.withY(WorldUtil.IMP.getHighestBlockSynchronous(getWorld(), pLoc.getX(), pLoc.getZ())));
pp.teleport(pLoc.withY(this.worldUtil.getHighestBlockSynchronous(getWorld(), pLoc.getX(), pLoc.getZ())));
}
}
public boolean enqueue() {
return GlobalBlockQueue.IMP.enqueue(this);
return blockQueue.enqueue(this);
}
public void setCuboid(Location pos1, Location pos2, BlockState block) {

View File

@ -38,7 +38,6 @@ import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -214,7 +213,7 @@ public enum CommonSetupSteps implements SetupStep {
MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_NAME_FORMAT + argument);
return this;
}
if (WorldUtil.IMP.isWorld(argument)) {
if (PlotSquared.platform().getWorldUtil().isWorld(argument)) {
if (PlotSquared.get().getPlotAreaManager().hasPlotArea(argument)) {
MainUtil.sendMessage(plotPlayer, Captions.SETUP_WORLD_NAME_TAKEN);
return this;
@ -225,12 +224,12 @@ public enum CommonSetupSteps implements SetupStep {
plotPlayer.deleteMeta("setup");
String world;
if (builder.setupManager() == null) {
world = SetupUtils.manager.setupWorld(builder);
world = PlotSquared.platform().getInjector().getInstance(SetupUtils.class).setupWorld(builder);
} else {
world = builder.setupManager().setupWorld(builder);
}
try {
plotPlayer.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND);
plotPlayer.teleport(PlotSquared.platform().getWorldUtil().getSpawn(world), TeleportCause.COMMAND);
} catch (Exception e) {
plotPlayer.sendMessage("&cAn error occurred. See console for more information");
e.printStackTrace();

View File

@ -49,6 +49,13 @@ public class PlotAreaBuilder {
@Getter @Setter private SettingsNodesWrapper settingsNodesWrapper;
@Getter @Setter private SetupUtils setupManager;
private PlotAreaBuilder() {
}
public static PlotAreaBuilder newBuilder() {
return new PlotAreaBuilder();
}
public static PlotAreaBuilder ofPlotArea(PlotArea area) {
return new PlotAreaBuilder()
.worldName(area.getWorldName())

View File

@ -39,7 +39,7 @@ public class SetupProcess {
private SetupStep current;
public SetupProcess() {
this.builder = new PlotAreaBuilder();
this.builder = PlotAreaBuilder.newBuilder();
this.history = new Stack<>();
this.current = CommonSetupSteps.CHOOSE_GENERATOR;
}

View File

@ -28,7 +28,6 @@ package com.plotsquared.core.util;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.util.task.RunnableVal;
@ -47,11 +46,10 @@ public abstract class ChunkManager {
new ConcurrentHashMap<>();
private static final Map<BlockVector2, RunnableVal<ScopedLocalBlockQueue>> addChunks =
new ConcurrentHashMap<>();
public static ChunkManager manager = null;
public static void setChunkInPlotArea(RunnableVal<ScopedLocalBlockQueue> force,
RunnableVal<ScopedLocalBlockQueue> add, String world, BlockVector2 loc) {
LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false);
LocalBlockQueue queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false);
if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get().isNonStandardGeneration(world, loc)) {
int blockX = loc.getX() << 4;
int blockZ = loc.getZ() << 4;

View File

@ -25,41 +25,12 @@
*/
package com.plotsquared.core.util;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import org.jetbrains.annotations.Nullable;
public abstract class EconHandler {
/**
* @deprecated This will be removed in the future,
* call {@link PlotPlatform#getEconomyHandler()} instead.
*/
@Deprecated @Nullable public static EconHandler manager;
/**
* Initialize the economy handler using {@link PlotPlatform#getEconomyHandler()}
* @deprecated Call {@link #init} instead or use {@link PlotPlatform#getEconomyHandler()}
* which does this already.
*/
@Deprecated public static void initializeEconHandler() {
manager = PlotSquared.platform().getEconomyHandler();
}
/**
* Return the econ handler instance, if one exists
*
* @return Economy handler instance
* @deprecated Call {@link PlotPlatform#getEconomyHandler()} instead
*/
@Deprecated @Nullable public static EconHandler getEconHandler() {
manager = PlotSquared.platform().getEconomyHandler();
return manager;
}
public abstract boolean init();
public double getMoney(PlotPlayer<?> player) {
@ -88,4 +59,5 @@ public abstract class EconHandler {
@Deprecated public boolean hasPermission(String player, String perm) {
return hasPermission(null, player, perm);
}
}

View File

@ -34,11 +34,6 @@ import com.plotsquared.core.plot.PlotItemStack;
*/
public abstract class InventoryUtil {
/**
* This class is only used by internal functions, for most cases use the PlotInventory class
*/
public static InventoryUtil manager = null;
public abstract void open(final PlotInventory inv);
public abstract void close(final PlotInventory inv);

View File

@ -64,7 +64,7 @@ public final class LegacyConverter {
}
private BlockBucket blockToBucket(@NonNull final String block) {
final BlockState plotBlock = WorldUtil.IMP.getClosestBlock(block).best;
final BlockState plotBlock = PlotSquared.platform().getWorldUtil().getClosestBlock(block).best;
return BlockBucket.withSingle(plotBlock);
}
@ -101,7 +101,7 @@ public final class LegacyConverter {
}
private BlockState[] splitBlockList(@NonNull final List<String> list) {
return list.stream().map(s -> WorldUtil.IMP.getClosestBlock(s).best)
return list.stream().map(s -> PlotSquared.platform().getWorldUtil().getClosestBlock(s).best)
.toArray(BlockState[]::new);
}

View File

@ -240,8 +240,7 @@ public class MainUtil {
*/
public static boolean resetBiome(PlotArea area, Location pos1, Location pos2) {
BiomeType biome = area.getPlotBiome();
if (!Objects.equals(WorldUtil.IMP
.getBiomeSynchronous(area.getWorldName(), (pos1.getX() + pos2.getX()) / 2,
if (!Objects.equals(PlotSquared.platform().getWorldUtil().getBiomeSynchronous(area.getWorldName(), (pos1.getX() + pos2.getX()) / 2,
(pos1.getZ() + pos2.getZ()) / 2), biome)) {
MainUtil
.setBiome(area.getWorldName(), pos1.getX(), pos1.getZ(), pos2.getX(), pos2.getZ(),
@ -613,14 +612,14 @@ public class MainUtil {
BlockVector3 pos1 = BlockVector2.at(p1x, p1z).toBlockVector3();
BlockVector3 pos2 = BlockVector2.at(p2x, p2z).toBlockVector3(Plot.MAX_HEIGHT - 1);
CuboidRegion region = new CuboidRegion(pos1, pos2);
WorldUtil.IMP.setBiomes(world, region, biome);
PlotSquared.platform().getWorldUtil().setBiomes(world, region, biome);
}
/**
* Get the highest block at a location.
*/
public static void getHighestBlock(String world, int x, int z, IntConsumer result) {
WorldUtil.IMP.getHighestBlock(world, x, z, highest -> {
PlotSquared.platform().getWorldUtil().getHighestBlock(world, x, z, highest -> {
if (highest == 0) {
result.accept(63);
} else {
@ -802,7 +801,7 @@ public class MainUtil {
int num = plot.getConnectedPlots().size();
String alias = !plot.getAlias().isEmpty() ? plot.getAlias() : Captions.NONE.getTranslated();
Location bot = plot.getCorners()[0];
WorldUtil.IMP.getBiome(plot.getWorldName(), bot.getX(), bot.getZ(), biome -> {
PlotSquared.platform().getWorldUtil().getBiome(plot.getWorldName(), bot.getX(), bot.getZ(), biome -> {
String info = iInfo;
String trusted = getPlayerList(plot.getTrusted());
String members = getPlayerList(plot.getMembers());

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.util;
public class PremiumVerification {
private static Boolean usingPremium;
/**

View File

@ -37,6 +37,7 @@ import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Collection;
@ -45,19 +46,23 @@ import java.util.Set;
public abstract class RegionManager {
public static RegionManager manager = null;
public static BlockVector2 getRegion(Location location) {
int x = location.getX() >> 9;
int z = location.getZ() >> 9;
return BlockVector2.at(x, z);
}
public static void largeRegionTask(final String world, final CuboidRegion region,
private final ChunkManager chunkManager;
public RegionManager(@NotNull final ChunkManager chunkManager) {
this.chunkManager = chunkManager;
}
public void largeRegionTask(final String world, final CuboidRegion region,
final RunnableVal<BlockVector2> task, final Runnable whenDone) {
TaskManager.runTaskAsync(() -> {
HashSet<BlockVector2> chunks = new HashSet<>();
Set<BlockVector2> mcrs = manager.getChunkChunks(world);
Set<BlockVector2> mcrs = this.getChunkChunks(world);
for (BlockVector2 mcr : mcrs) {
int bx = mcr.getX() << 9;
int bz = mcr.getZ() << 9;
@ -85,7 +90,7 @@ public abstract class RegionManager {
}
TaskManager.objectTask(chunks, new RunnableVal<BlockVector2>() {
@Override public void run(BlockVector2 value) {
ChunkManager.manager.loadChunk(world, value, false)
chunkManager.loadChunk(world, value, false)
.thenRun(() -> task.run(value));
}
}, whenDone);

View File

@ -93,10 +93,15 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public abstract class SchematicHandler {
public static SchematicHandler manager;
private boolean exportAll = false;
private final WorldUtil worldUtil;
public SchematicHandler(@NotNull final WorldUtil worldUtil) {
this.worldUtil = worldUtil;
}
public boolean exportAll(Collection<Plot> collection, final File outputDir,
final String namingScheme, final Runnable ifSuccess) {
if (this.exportAll) {
@ -144,15 +149,14 @@ public abstract class SchematicHandler {
}
final Runnable THIS = this;
SchematicHandler.manager.getCompoundTag(plot, new RunnableVal<CompoundTag>() {
getCompoundTag(plot, new RunnableVal<CompoundTag>() {
@Override public void run(final CompoundTag value) {
if (value == null) {
MainUtil.sendMessage(null, "&7 - Skipped plot &c" + plot.getId());
} else {
TaskManager.runTaskAsync(() -> {
MainUtil.sendMessage(null, "&6ID: " + plot.getId());
boolean result = SchematicHandler.manager
.save(value, directory + File.separator + name + ".schem");
boolean result = save(value, directory + File.separator + name + ".schem");
if (!result) {
MainUtil
.sendMessage(null, "&7 - Failed to save &c" + plot.getId());
@ -223,7 +227,7 @@ public abstract class SchematicHandler {
if (pw instanceof ClassicPlotWorld) {
y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT;
} else {
y_offset_actual = yOffset + 1 + WorldUtil.IMP
y_offset_actual = yOffset + 1 + this.worldUtil
.getHighestBlockSynchronous(plot.getWorldName(),
region.getMinimumPoint().getX() + 1,
region.getMinimumPoint().getZ() + 1);
@ -493,7 +497,7 @@ public abstract class SchematicHandler {
final Location top = corners[1];
CuboidRegion cuboidRegion =
new CuboidRegion(WorldUtil.IMP.getWeWorld(world), bot.getBlockVector3(),
new CuboidRegion(this.worldUtil.getWeWorld(world), bot.getBlockVector3(),
top.getBlockVector3());
final int width = cuboidRegion.getWidth();

View File

@ -34,8 +34,6 @@ import java.util.HashMap;
public abstract class SetupUtils {
public static SetupUtils manager;
public static HashMap<String, GeneratorWrapper<?>> generators = new HashMap<>();
public abstract void updateGenerators();
@ -48,4 +46,5 @@ public abstract class SetupUtils {
public abstract String setupWorld(final PlotAreaBuilder builder);
public abstract void unload(String world, boolean save);
}

View File

@ -61,7 +61,12 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public abstract class WorldUtil {
public static WorldUtil IMP;
private final RegionManager regionManager;
public WorldUtil(@NotNull final RegionManager regionManager) {
this.regionManager = regionManager;
}
public abstract String getMainWorld();
@ -150,8 +155,7 @@ public abstract class WorldUtil {
int brz = bot.getZ() >> 9;
int trx = top.getX() >> 9;
int trz = top.getZ() >> 9;
Set<BlockVector2> files =
RegionManager.manager.getChunkChunks(bot.getWorldName());
Set<BlockVector2> files = regionManager.getChunkChunks(bot.getWorldName());
for (BlockVector2 mca : files) {
if (mca.getX() >= brx && mca.getX() <= trx && mca.getZ() >= brz
&& mca.getZ() <= trz) {

View File

@ -25,6 +25,8 @@
*/
package com.plotsquared.core.util.entity;
import com.plotsquared.core.PlotSquared;
/**
* A collection of {@link EntityCategory entity categories}
*/
@ -48,7 +50,7 @@ public class EntityCategories {
public static final EntityCategory PLAYER = register("player");
public static EntityCategory register(final String id) {
final EntityCategory entityCategory = new EntityCategory(id);
final EntityCategory entityCategory = new EntityCategory(PlotSquared.platform().getWorldUtil(), id);
EntityCategory.REGISTRY.register(entityCategory.getId(), entityCategory);
return entityCategory;
}

View File

@ -41,15 +41,17 @@ public class EntityCategory extends Category<EntityType> implements Keyed {
public static final NamespacedRegistry<EntityCategory> REGISTRY =
new NamespacedRegistry<>("entity type");
private final WorldUtil worldUtil;
private final String key;
protected EntityCategory(final String id) {
protected EntityCategory(final WorldUtil worldUtil, final String id) {
super("plotsquared:" + id);
this.key = id;
this.worldUtil = worldUtil;
}
@Override protected Set<EntityType> load() {
return WorldUtil.IMP.getTypesInCategory(this.key);
return this.worldUtil.getTypesInCategory(this.key);
}
}

View File

@ -27,6 +27,8 @@ package com.plotsquared.core.util.task;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.util.RuntimeExceptionRunnableVal;
import lombok.Getter;
import lombok.Setter;
import java.util.Collection;
import java.util.HashMap;
@ -39,46 +41,47 @@ public abstract class TaskManager {
public static final HashSet<String> TELEPORT_QUEUE = new HashSet<>();
public static final HashMap<Integer, Integer> tasks = new HashMap<>();
public static TaskManager IMP;
public static AtomicInteger index = new AtomicInteger(0);
@Getter @Setter private static TaskManager implementation;
public static int runTaskRepeat(Runnable runnable, int interval) {
if (runnable != null) {
if (IMP == null) {
if (getImplementation() == null) {
throw new IllegalArgumentException("disabled");
}
return IMP.taskRepeat(runnable, interval);
return getImplementation().taskRepeat(runnable, interval);
}
return -1;
}
public static int runTaskRepeatAsync(Runnable runnable, int interval) {
if (runnable != null) {
if (IMP == null) {
if (getImplementation() == null) {
throw new IllegalArgumentException("disabled");
}
return IMP.taskRepeatAsync(runnable, interval);
return getImplementation().taskRepeatAsync(runnable, interval);
}
return -1;
}
public static void runTaskAsync(Runnable runnable) {
if (runnable != null) {
if (IMP == null) {
if (getImplementation() == null) {
runnable.run();
return;
}
IMP.taskAsync(runnable);
getImplementation().taskAsync(runnable);
}
}
public static void runTask(Runnable runnable) {
if (runnable != null) {
if (IMP == null) {
if (getImplementation() == null) {
runnable.run();
return;
}
IMP.task(runnable);
getImplementation().task(runnable);
}
}
@ -90,21 +93,21 @@ public abstract class TaskManager {
*/
public static void runTaskLater(Runnable runnable, int delay) {
if (runnable != null) {
if (IMP == null) {
if (getImplementation() == null) {
runnable.run();
return;
}
IMP.taskLater(runnable, delay);
getImplementation().taskLater(runnable, delay);
}
}
public static void runTaskLaterAsync(Runnable runnable, int delay) {
if (runnable != null) {
if (IMP == null) {
if (getImplementation() == null) {
runnable.run();
return;
}
IMP.taskLaterAsync(runnable, delay);
getImplementation().taskLaterAsync(runnable, delay);
}
}
@ -133,7 +136,7 @@ public abstract class TaskManager {
final AtomicBoolean running = new AtomicBoolean(true);
final RuntimeExceptionRunnableVal<T> run =
new RuntimeExceptionRunnableVal<>(function, running);
TaskManager.IMP.task(run);
TaskManager.getImplementation().task(run);
try {
synchronized (function) {
while (running.get()) {