diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle
index b053a2878..fef272b7a 100644
--- a/Bukkit/build.gradle
+++ b/Bukkit/build.gradle
@@ -29,7 +29,7 @@ dependencies {
exclude(module: "bukkit")
}
- compile("io.papermc:paperlib:1.0.2")
+ compile("io.papermc:paperlib:1.0.4")
implementation("net.kyori:text-adapter-bukkit:3.0.3")
compile("com.github.MilkBowl:VaultAPI:1.7") {
exclude(module: "bukkit")
@@ -44,6 +44,8 @@ dependencies {
implementation('net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT')
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
+ // logging
+ implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.8.1')
}
sourceCompatibility = 1.8
@@ -97,18 +99,28 @@ task copyFiles {
shadowJar {
dependencies {
include(dependency(":PlotSquared-Core"))
- include(dependency("io.papermc:paperlib:1.0.2"))
+ include(dependency("io.papermc:paperlib:1.0.4"))
include(dependency("net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT"))
include(dependency("net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT"))
include(dependency("org.bstats:bstats-bukkit:1.7"))
include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT"))
+ include(dependency("com.google.inject:guice:4.2.3"))
+ include(dependency("com.google.inject.extensions:guice-assistedinject:4.2.3"))
+ include(dependency("javax.annotation:javax-annotation-api"))
+ include(dependency('org.apache.logging.log4j:log4j-slf4j-impl'))
+ include(dependency('org.slf4j:slf4j-api'))
}
+
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
relocate("io.papermc.lib", "com.plotsquared.bukkit.paperlib")
relocate("org.bstats", "com.plotsquared.metrics")
relocate('com.sk89q.squirrelid', 'com.plotsquared.squirrelid')
relocate('org.khelekore.prtree', 'com.plotsquared.prtree')
+ relocate('org.apache.logging.slf4j', 'com.plotsquared.logging.apache')
+ relocate('org.slf4j', 'com.plotsquared.logging.slf4j')
+ relocate('com.google.inject', 'com.plotsquared.google')
+
archiveFileName = "${project.name}-${parent.version}.jar"
destinationDirectory = file "../target"
}
diff --git a/Bukkit/pom.xml b/Bukkit/pom.xml
index cde998b9a..d4848ae84 100644
--- a/Bukkit/pom.xml
+++ b/Bukkit/pom.xml
@@ -12,6 +12,12 @@
20200518compile
+
+ javax.annotation
+ javax.annotation-api
+ 1.3.2
+ compile
+ org.bstatsbstats-bukkit
@@ -176,6 +182,12 @@
4.0-dev-106runtime
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ 2.8.1
+ runtime
+ junitjunit
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
similarity index 71%
rename from Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
index d3a703f19..ebadb0dc2 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
@@ -25,17 +25,21 @@
*/
package com.plotsquared.bukkit;
-import com.plotsquared.bukkit.generator.BukkitHybridUtils;
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Stage;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
+import com.plotsquared.bukkit.inject.BackupModule;
+import com.plotsquared.bukkit.inject.BukkitModule;
+import com.plotsquared.bukkit.inject.WorldManagerModule;
import com.plotsquared.bukkit.listener.ChunkListener;
import com.plotsquared.bukkit.listener.EntitySpawnListener;
import com.plotsquared.bukkit.listener.PaperListener;
import com.plotsquared.bukkit.listener.PlayerEvents;
import com.plotsquared.bukkit.listener.SingleWorldListener;
import com.plotsquared.bukkit.listener.WorldEvents;
-import com.plotsquared.bukkit.managers.BukkitWorldManager;
-import com.plotsquared.bukkit.managers.HyperverseWorldManager;
-import com.plotsquared.bukkit.managers.MultiverseWorldManager;
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
import com.plotsquared.bukkit.placeholder.Placeholders;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
@@ -47,8 +51,10 @@ import com.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.plotsquared.bukkit.util.BukkitPermHandler;
import com.plotsquared.bukkit.util.BukkitRegionManager;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
+import com.plotsquared.bukkit.util.BukkitChatManager;
import com.plotsquared.bukkit.util.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
+import com.plotsquared.bukkit.util.BukkitWorld;
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.UpdateUtility;
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
@@ -58,57 +64,60 @@ import com.plotsquared.bukkit.uuid.OfflinePlayerUUIDService;
import com.plotsquared.bukkit.uuid.PaperUUIDService;
import com.plotsquared.bukkit.uuid.SQLiteUUIDService;
import com.plotsquared.bukkit.uuid.SquirrelIdUUIDService;
-import com.plotsquared.core.IPlotMain;
+import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.backup.BackupManager;
-import com.plotsquared.core.backup.NullBackupManager;
-import com.plotsquared.core.backup.SimpleBackupManager;
+import com.plotsquared.core.command.WE_Anywhere;
+import com.plotsquared.core.components.ComponentPresetManager;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ChatFormatter;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings;
+import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.generator.GeneratorWrapper;
-import com.plotsquared.core.generator.HybridGen;
-import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.generator.SingleWorldGenerator;
+import com.plotsquared.core.inject.annotations.BackgroundPipeline;
+import com.plotsquared.core.inject.annotations.DefaultGenerator;
+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.inject.modules.PlotSquaredModule;
import com.plotsquared.core.listener.PlotListener;
+import com.plotsquared.core.listener.WESubscriber;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
+import com.plotsquared.core.plot.comment.CommentManager;
+import com.plotsquared.core.plot.message.PlainChatManager;
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.QueueProvider;
+import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.setup.SettingsNodesWrapper;
import com.plotsquared.core.util.ChunkManager;
+import com.plotsquared.core.util.ChatManager;
import com.plotsquared.core.util.ConsoleColors;
import com.plotsquared.core.util.EconHandler;
-import com.plotsquared.core.util.InventoryUtil;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
-import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.PremiumVerification;
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.task.TaskManager;
import com.plotsquared.core.uuid.CacheUUIDService;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
import com.sk89q.worldedit.WorldEdit;
-import com.sk89q.worldedit.bukkit.WorldEditPlugin;
-import com.sk89q.worldedit.extension.platform.Actor;
import io.papermc.lib.PaperLib;
import lombok.Getter;
import lombok.NonNull;
@@ -120,7 +129,6 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
-import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@@ -131,9 +139,11 @@ import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.io.File;
import java.lang.reflect.Method;
import java.util.AbstractMap;
@@ -157,10 +167,10 @@ import static com.plotsquared.core.util.PremiumVerification.getResourceID;
import static com.plotsquared.core.util.PremiumVerification.getUserID;
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
-public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
+@SuppressWarnings("unused") public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPlatform {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + BukkitPlatform.class.getSimpleName());
private static final int BSTATS_ID = 1404;
- @Getter private static WorldEdit worldEdit;
static {
try {
@@ -175,12 +185,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
private Method methodUnloadChunk0;
private boolean methodUnloadSetup = false;
private boolean metricsStarted;
- @Getter private BackupManager backupManager;
- @Getter private PlatformWorldManager worldManager;
- private final BukkitPlayerManager playerManager = new BukkitPlayerManager();
private EconHandler econ;
private PermHandler perm;
+ @Getter private Injector injector;
+
+ @Inject private PlotAreaManager plotAreaManager;
+ @Inject private EventDispatcher eventDispatcher;
+ @Inject private PlotListener plotListener;
+ @Inject @WorldConfig private YamlConfiguration worldConfiguration;
+ @Inject @WorldFile private File worldfile;
+ @Inject private BukkitPlayerManager playerManager;
+ @Inject private BackupManager backupManager;
+ @Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
+ @Inject @BackgroundPipeline private UUIDPipeline backgroundPipeline;
+ @Inject private PlatformWorldManager worldManager;
+
@Override public int[] getServerVersion() {
if (this.version == null) {
try {
@@ -193,9 +213,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
}
} catch (NumberFormatException e) {
e.printStackTrace();
- PlotSquared.debug(StringMan.getString(Bukkit.getBukkitVersion()));
- PlotSquared.debug(
- StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\.")));
return new int[] {1, 13, 0};
}
}
@@ -208,11 +225,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
@Override public void onEnable() {
this.pluginName = getDescription().getName();
+
+ // Stuff that needs to be created before the PlotSquared instance
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
+ TaskManager.setImplementation(new BukkitTaskManager(this));
- new PlotSquared(this, "Bukkit");
+ final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
- if (PlotSquared.get().IMP.getServerVersion()[1] < 13) {
+ if (PlotSquared.platform().getServerVersion()[1] < 13) {
System.out.println(
"You can't use this version of PlotSquared on a server less than Minecraft 1.13.2.");
System.out
@@ -222,182 +242,283 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
return;
}
+ // We create the injector after PlotSquared has been initialized, so that we have access
+ // to generated instances and settings
+ this.injector = Guice.createInjector(Stage.PRODUCTION, new WorldManagerModule(), new PlotSquaredModule(),
+ new BukkitModule(this), new BackupModule());
+ this.injector.injectMembers(this);
+
if (PremiumVerification.isPremium() && Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
- new UpdateUtility(this).updateChecker();
+ injector.getInstance(UpdateUtility.class).updateChecker();
}
if (PremiumVerification.isPremium()) {
- PlotSquared.log(
- Captions.PREFIX + "&6PlotSquared version licensed to Spigot user " + getUserID());
- PlotSquared
- .log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/" + getResourceID());
- PlotSquared.log(Captions.PREFIX + "&6Download ID: " + getDownloadID());
- PlotSquared.log(Captions.PREFIX + "&6Thanks for supporting us :)");
+ logger.info("[P2] PlotSquared version licensed to Spigot user {}", getUserID());
+ logger.info("[P2] https://www.spigotmc.org/resources/{}", getResourceID());
+ logger.info("[P2] Download ID: {}", getDownloadID());
+ logger.info("[P2] Thanks for supporting us :)");
} else {
- PlotSquared.log(Captions.PREFIX + "&6Couldn't verify purchase :(");
+ logger.info("[P2] Couldn't verify purchase :(");
}
- final UUIDPipeline impromptuPipeline = PlotSquared.get().getImpromptuUUIDPipeline();
- final UUIDPipeline backgroundPipeline = PlotSquared.get().getBackgroundUUIDPipeline();
+ // Database
+ if (Settings.Enabled_Components.DATABASE) {
+ plotSquared.setupDatabase();
+ }
+
+ // Check if we need to convert old flag values, etc
+ if (!plotSquared.getConfigurationVersion().equalsIgnoreCase("v5")) {
+ // Perform upgrade
+ if (DBFunc.dbManager.convertFlags()) {
+ log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!");
+ // Update the config version
+ try {
+ plotSquared.setConfigurationVersion("v5");
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // Comments
+ CommentManager.registerDefaultInboxes();
+
+ plotSquared.startExpiryTasks();
+
+ // This is getting removed so I won't even bother migrating it
+ ChatManager.manager = this.initChatManager();
+
+ // Do stuff that was previously done in PlotSquared
+ // Kill entities
+ if (Settings.Enabled_Components.KILL_ROAD_MOBS
+ || Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
+ this.runEntityTask();
+ }
+
+ // WorldEdit
+ if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
+ try {
+ logger.info("[P2] {} hooked into WorldEdit", this.getPluginName());
+ WorldEdit.getInstance().getEventBus().register(this.getInjector().getInstance(WESubscriber.class));
+ if (Settings.Enabled_Components.COMMANDS) {
+ new WE_Anywhere();
+ }
+ } catch (Throwable e) {
+ logger.error("[P2] Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master");
+ }
+ }
+
+ if (Settings.Enabled_Components.EVENTS) {
+ getServer().getPluginManager().registerEvents(getInjector().getInstance(PlayerEvents.class), this);
+ getServer().getPluginManager().registerEvents(getInjector().getInstance(EntitySpawnListener.class), this);
+ if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
+ getServer().getPluginManager().registerEvents(getInjector().getInstance(PaperListener.class), this);
+ }
+ this.plotListener.startRunnable();
+ }
+
+ // Required
+ getServer().getPluginManager().registerEvents(getInjector().getInstance(WorldEvents.class), this);
+ if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
+ getServer().getPluginManager().registerEvents(getInjector().getInstance(ChunkListener.class), this);
+ }
+
+ // Start the global block queue
+ final GlobalBlockQueue globalBlockQueue = this.injector.getInstance(GlobalBlockQueue.class);
+ globalBlockQueue.runTask();
+
+ // Commands
+ if (Settings.Enabled_Components.COMMANDS) {
+ this.registerCommands();
+ }
+
+ // Economy
+ if (Settings.Enabled_Components.ECONOMY) {
+ TaskManager.runTask(() -> {
+ final PermHandler permHandler = getInjector().getInstance(PermHandler.class);
+ if (permHandler != null) {
+ permHandler.init();
+ }
+ final EconHandler econHandler = getInjector().getInstance(EconHandler.class);
+ if (econHandler != null) {
+ econHandler.init();
+ }
+ });
+ }
+
+ if (Settings.Enabled_Components.COMPONENT_PRESETS) {
+ try {
+ getInjector().getInstance(ComponentPresetManager.class);
+ } catch (final Exception e) {
+ logger.error("[P2] Failed to initialize the preset system", e);
+ }
+ }
+
+ // World generators:
+ final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
+ final WorldUtil worldUtil = getInjector().getInstance(WorldUtil.class);
+
+ if (section != null) {
+ for (String world : section.getKeys(false)) {
+ if (world.equals("CheckingPlotSquaredGenerator")) {
+ continue;
+ }
+ if (worldUtil.isWorld(world)) {
+ this.setGenerator(world);
+ }
+ }
+ TaskManager.runTaskLater(() -> {
+ for (String world : section.getKeys(false)) {
+ if (world.equals("CheckingPlotSquaredGenerator")) {
+ continue;
+ }
+ if (!worldUtil.isWorld(world) && !world.equals("*")) {
+ logger.warn("[P2] `{}` was not properly loaded - {} will now try to load it properly",
+ world, this.getPluginName());
+ logger.warn("[P2] - Are you trying to delete this world? Remember to remove it from the worlds.yml, bukkit.yml and multiverse worlds.yml");
+ logger.warn("[P2] - Your world management plugin may be faulty (or non existent)");
+ logger.warn("[P2] This message may also be a false positive and could be ignored.");
+ this.setGenerator(world);
+ }
+ }
+ }, 1);
+ }
// Services are accessed in order
- final CacheUUIDService cacheUUIDService =
- new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE);
- impromptuPipeline.registerService(cacheUUIDService);
- backgroundPipeline.registerService(cacheUUIDService);
- impromptuPipeline.registerConsumer(cacheUUIDService);
- backgroundPipeline.registerConsumer(cacheUUIDService);
+ final CacheUUIDService cacheUUIDService = new CacheUUIDService(Settings.UUID.UUID_CACHE_SIZE);
+ this.impromptuPipeline.registerService(cacheUUIDService);
+ this.backgroundPipeline.registerService(cacheUUIDService);
+ this.impromptuPipeline.registerConsumer(cacheUUIDService);
+ this.backgroundPipeline.registerConsumer(cacheUUIDService);
// Now, if the server is in offline mode we can only use profiles and direct UUID
// access, and so we skip the player profile stuff as well as SquirrelID (Mojang lookups)
if (Settings.UUID.OFFLINE) {
final OfflineModeUUIDService offlineModeUUIDService = new OfflineModeUUIDService();
- impromptuPipeline.registerService(offlineModeUUIDService);
- backgroundPipeline.registerService(offlineModeUUIDService);
- PlotSquared.log(Captions.PREFIX + "(UUID) Using the offline mode UUID service");
+ this.impromptuPipeline.registerService(offlineModeUUIDService);
+ this.backgroundPipeline.registerService(offlineModeUUIDService);
+ logger.info("[P2] (UUID) Using the offline mode UUID service");
}
- final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
- impromptuPipeline.registerService(offlinePlayerUUIDService);
- backgroundPipeline.registerService(offlinePlayerUUIDService);
+ if (Settings.UUID.SERVICE_BUKKIT) {
+ final OfflinePlayerUUIDService offlinePlayerUUIDService = new OfflinePlayerUUIDService();
+ this.impromptuPipeline.registerService(offlinePlayerUUIDService);
+ this.backgroundPipeline.registerService(offlinePlayerUUIDService);
+ }
final SQLiteUUIDService sqLiteUUIDService = new SQLiteUUIDService("user_cache.db");
final SQLiteUUIDService legacyUUIDService;
if (Settings.UUID.LEGACY_DATABASE_SUPPORT && MainUtil
- .getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db").exists()) {
+ .getFile(PlotSquared.platform().getDirectory(), "usercache.db").exists()) {
legacyUUIDService = new SQLiteUUIDService("usercache.db");
} else {
legacyUUIDService = null;
}
final LuckPermsUUIDService luckPermsUUIDService;
- if (Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
+ if (Settings.UUID.SERVICE_LUCKPERMS &&
+ Bukkit.getPluginManager().getPlugin("LuckPerms") != null) {
luckPermsUUIDService = new LuckPermsUUIDService();
- PlotSquared
- .log(Captions.PREFIX + "(UUID) Using LuckPerms as a complementary UUID service");
+ logger.info("[P2] (UUID) Using LuckPerms as a complementary UUID service");
} else {
luckPermsUUIDService = null;
}
final BungeePermsUUIDService bungeePermsUUIDService;
- if (Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
+ if (Settings.UUID.SERVICE_BUNGEE_PERMS &&
+ Bukkit.getPluginManager().getPlugin("BungeePerms") != null) {
bungeePermsUUIDService = new BungeePermsUUIDService();
- PlotSquared
- .log(Captions.PREFIX + "(UUID) Using BungeePerms as a complementary UUID service");
+ logger.info("[P2] (UUID) Using BungeePerms as a complementary UUID service");
} else {
bungeePermsUUIDService = null;
}
final EssentialsUUIDService essentialsUUIDService;
- if (Bukkit.getPluginManager().getPlugin("Essentials") != null) {
+ if (Settings.UUID.SERVICE_ESSENTIALSX && Bukkit.getPluginManager().getPlugin("Essentials") != null) {
essentialsUUIDService = new EssentialsUUIDService();
- PlotSquared
- .log(Captions.PREFIX + "(UUID) Using Essentials as a complementary UUID service");
+ logger.info("[P2] (UUID) Using EssentialsX as a complementary UUID service");
} else {
essentialsUUIDService = null;
}
if (!Settings.UUID.OFFLINE) {
// If running Paper we'll also try to use their profiles
- if (PaperLib.isPaper()) {
+ if (Bukkit.getOnlineMode() && PaperLib.isPaper() && Settings.UUID.SERVICE_PAPER) {
final PaperUUIDService paperUUIDService = new PaperUUIDService();
- impromptuPipeline.registerService(paperUUIDService);
- backgroundPipeline.registerService(paperUUIDService);
- PlotSquared
- .log(Captions.PREFIX + "(UUID) Using Paper as a complementary UUID service");
+ this.impromptuPipeline.registerService(paperUUIDService);
+ this.backgroundPipeline.registerService(paperUUIDService);
+ logger.info("[P2] (UUID) Using Paper as a complementary UUID service");
}
- impromptuPipeline.registerService(sqLiteUUIDService);
- backgroundPipeline.registerService(sqLiteUUIDService);
- impromptuPipeline.registerConsumer(sqLiteUUIDService);
- backgroundPipeline.registerConsumer(sqLiteUUIDService);
+ this.impromptuPipeline.registerService(sqLiteUUIDService);
+ this.backgroundPipeline.registerService(sqLiteUUIDService);
+ this.impromptuPipeline.registerConsumer(sqLiteUUIDService);
+ this.backgroundPipeline.registerConsumer(sqLiteUUIDService);
if (legacyUUIDService != null) {
- impromptuPipeline.registerService(legacyUUIDService);
- backgroundPipeline.registerService(legacyUUIDService);
+ this.impromptuPipeline.registerService(legacyUUIDService);
+ this.backgroundPipeline.registerService(legacyUUIDService);
}
// Plugin providers
if (luckPermsUUIDService != null) {
- impromptuPipeline.registerService(luckPermsUUIDService);
- backgroundPipeline.registerService(luckPermsUUIDService);
+ this.impromptuPipeline.registerService(luckPermsUUIDService);
+ this.backgroundPipeline.registerService(luckPermsUUIDService);
}
if (bungeePermsUUIDService != null) {
- impromptuPipeline.registerService(bungeePermsUUIDService);
- backgroundPipeline.registerService(bungeePermsUUIDService);
+ this.impromptuPipeline.registerService(bungeePermsUUIDService);
+ this.backgroundPipeline.registerService(bungeePermsUUIDService);
}
if (essentialsUUIDService != null) {
- impromptuPipeline.registerService(essentialsUUIDService);
- backgroundPipeline.registerService(essentialsUUIDService);
+ this.impromptuPipeline.registerService(essentialsUUIDService);
+ this.backgroundPipeline.registerService(essentialsUUIDService);
}
final SquirrelIdUUIDService impromptuMojangService =
new SquirrelIdUUIDService(Settings.UUID.IMPROMPTU_LIMIT);
- impromptuPipeline.registerService(impromptuMojangService);
+ this.impromptuPipeline.registerService(impromptuMojangService);
final SquirrelIdUUIDService backgroundMojangService =
new SquirrelIdUUIDService(Settings.UUID.BACKGROUND_LIMIT);
- backgroundPipeline.registerService(backgroundMojangService);
+ this.backgroundPipeline.registerService(backgroundMojangService);
} else {
- impromptuPipeline.registerService(sqLiteUUIDService);
- backgroundPipeline.registerService(sqLiteUUIDService);
- impromptuPipeline.registerConsumer(sqLiteUUIDService);
- backgroundPipeline.registerConsumer(sqLiteUUIDService);
+ this.impromptuPipeline.registerService(sqLiteUUIDService);
+ this.backgroundPipeline.registerService(sqLiteUUIDService);
+ this.impromptuPipeline.registerConsumer(sqLiteUUIDService);
+ this.backgroundPipeline.registerConsumer(sqLiteUUIDService);
if (legacyUUIDService != null) {
- impromptuPipeline.registerService(legacyUUIDService);
- backgroundPipeline.registerService(legacyUUIDService);
+ this.impromptuPipeline.registerService(legacyUUIDService);
+ this.backgroundPipeline.registerService(legacyUUIDService);
}
}
- impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);
+ this.impromptuPipeline.storeImmediately("*", DBFunc.EVERYONE);
if (Settings.UUID.BACKGROUND_CACHING_ENABLED) {
this.startUuidCaching(sqLiteUUIDService, cacheUUIDService);
}
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
- new Placeholders().register();
+ injector.getInstance(Placeholders.class).register();
if (Settings.Enabled_Components.EXTERNAL_PLACEHOLDERS) {
- ChatFormatter.formatters.add(new PlaceholderFormatter());
+ ChatFormatter.formatters.add(getInjector().getInstance(PlaceholderFormatter.class));
}
- PlotSquared.log(Captions.PREFIX + "&6PlotSquared hooked into PlaceholderAPI");
+ logger.info("[P2] PlotSquared hooked into PlaceholderAPI");
} else {
- PlotSquared
- .debug(Captions.PREFIX + "&6PlaceholderAPI is not in use. Hook deactivated.");
+ logger.info("[P2] PlaceholderAPI is not in use. Hook deactivated");
}
this.startMetrics();
if (Settings.Enabled_Components.WORLDS) {
- TaskManager.IMP.taskRepeat(this::unload, 20);
+ TaskManager.getImplementation().taskRepeat(this::unload, 20);
try {
- singleWorldListener = new SingleWorldListener(this);
+ singleWorldListener = getInjector().getInstance(SingleWorldListener.class);
} catch (Exception e) {
e.printStackTrace();
}
}
- try {
- this.backupManager = new SimpleBackupManager();
- } catch (final Exception e) {
- PlotSquared.log(Captions.PREFIX + "&6Failed to initialize backup manager");
- e.printStackTrace();
- PlotSquared.log(Captions.PREFIX + "&6Backup features will be disabled");
- this.backupManager = new NullBackupManager();
- }
-
- if (Bukkit.getPluginManager().getPlugin("Hyperverse") != null) {
- this.worldManager = new HyperverseWorldManager();
- } else if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) {
- this.worldManager = new MultiverseWorldManager();
- } else {
- this.worldManager = new BukkitWorldManager();
- }
-
- PlotSquared.log(
- Captions.PREFIX.getTranslated() + "Using platform world manager: " + this.worldManager
- .getName());
-
// Clean up potential memory leak
Bukkit.getScheduler().runTaskTimer(this, () -> {
try {
@@ -424,10 +545,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
event.printStackTrace();
}
}
- final PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
- if (manager instanceof SinglePlotAreaManager) {
+
+ if (this.plotAreaManager instanceof SinglePlotAreaManager) {
long start = System.currentTimeMillis();
- final SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea();
+ final SinglePlotArea area = ((SinglePlotAreaManager) this.plotAreaManager).getArea();
outer:
for (final World world : Bukkit.getWorlds()) {
@@ -457,7 +578,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
final Chunk[] chunks = world.getLoadedChunks();
if (chunks.length == 0) {
if (!Bukkit.unloadWorld(world, true)) {
- PlotSquared.debug("Failed to unload " + world.getName());
+ logger.warn("[P2] Failed to unload {}", world.getName());
}
return;
} else {
@@ -491,8 +612,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
}
}
- private void startUuidCaching(@NotNull final SQLiteUUIDService sqLiteUUIDService,
- @NotNull final CacheUUIDService cacheUUIDService) {
+ private void startUuidCaching(@Nonnull final SQLiteUUIDService sqLiteUUIDService,
+ @Nonnull final CacheUUIDService cacheUUIDService) {
// Load all uuids into a big chunky boi queue
final Queue uuidQueue = new LinkedBlockingQueue<>();
PlotSquared.get().forEachPlotRaw(plot -> {
@@ -507,8 +628,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
}
}
});
- PlotSquared.log(Captions.PREFIX.getTranslated() + "(UUID) " + uuidQueue.size()
- + " UUIDs will be cached.");
+
+ logger.info("[P2] (UUID) {} UUIDs will be cached", uuidQueue.size());
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
// Begin by reading all the SQLite cache at once
@@ -516,9 +637,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
// Now fetch names for all known UUIDs
final int totalSize = uuidQueue.size();
int read = 0;
- PlotSquared.log(Captions.PREFIX.getTranslated()
- + "(UUID) PlotSquared will fetch UUIDs in groups of "
- + Settings.UUID.BACKGROUND_LIMIT);
+ logger.info("[P2] (UUID) PlotSquared will fetch UUIDs in groups of {}", Settings.UUID.BACKGROUND_LIMIT);
final List uuidList = new ArrayList<>(Settings.UUID.BACKGROUND_LIMIT);
// Used to indicate that the second retrieval has been attempted
@@ -526,7 +645,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
while (!uuidQueue.isEmpty() || !uuidList.isEmpty()) {
if (!uuidList.isEmpty() && secondRun) {
- PlotSquared.log("Giving up on last batch. Fetching new batch instead.");
+ logger.warn("[P2] (UUID) Giving up on last batch. Fetching new batch instead");
uuidList.clear();
}
if (uuidList.isEmpty()) {
@@ -550,15 +669,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
uuidList.clear();
// Print progress
final double percentage = ((double) read / (double) totalSize) * 100.0D;
- PlotSquared.log(Captions.PREFIX.getTranslated() + String
- .format("(UUID) PlotSquared has cached %.1f%% of UUIDs", percentage));
+ if (Settings.DEBUG) {
+ logger.info("[P2] (UUID) PlotSquared has cached {} of UUIDs", String.format("%.1f%%", percentage));
+ }
} catch (final InterruptedException | ExecutionException e) {
- PlotSquared.log("Failed to retrieve that batch. Will try again.");
- e.printStackTrace();
+ logger.error("[P2] (UUID) Failed to retrieve last batch. Will try again", e);
}
}
- PlotSquared
- .log(Captions.PREFIX.getTranslated() + "(UUID) PlotSquared has cached all UUIDs");
+ logger.info("[P2] (UUID) PlotSquared has cached all UUIDs");
}, 10, TimeUnit.SECONDS);
}
@@ -567,7 +685,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
Bukkit.getScheduler().cancelTasks(this);
}
- @Override public void log(@NonNull String message) {
+ @Override public void log(@Nonnull String message) {
try {
message = Captions.color(message);
if (!Settings.Chat.CONSOLE_COLOR) {
@@ -583,21 +701,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
this.getServer().getPluginManager().disablePlugin(this);
}
- @Override public int[] getPluginVersion() {
- String ver = getDescription().getVersion();
- if (ver.contains("-")) {
- ver = ver.split("-")[0];
- }
- String[] split = ver.split("\\.");
- return new int[] {Integer.parseInt(split[0]), Integer.parseInt(split[1]),
- Integer.parseInt(split[2])};
- }
-
- @Override public String getPluginVersionString() {
- return getDescription().getVersion();
- }
-
- @Override public void registerCommands() {
+ private void registerCommands() {
final BukkitCommand bukkitCommand = new BukkitCommand();
final PluginCommand plotCommand = getCommand("plots");
if (plotCommand != null) {
@@ -615,13 +719,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
return Bukkit.getWorldContainer();
}
- @Override public TaskManager getTaskManager() {
- return new BukkitTaskManager(this);
- }
-
- @Override @SuppressWarnings("deprecation") public void runEntityTask() {
- PlotSquared.log(Captions.PREFIX + "KillAllEntities started.");
- TaskManager.runTaskRepeat(() -> PlotSquared.get().forEachPlotArea(plotArea -> {
+ @SuppressWarnings("deprecation") private void runEntityTask() {
+ logger.info("[P2] KillAllEntities started");
+ TaskManager.runTaskRepeat(() -> this.plotAreaManager.forEachPlotArea(plotArea -> {
final World world = Bukkit.getWorld(plotArea.getWorldName());
try {
if (world == null) {
@@ -756,7 +856,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
if (currentPlotId != null) {
entity.setMetadata("shulkerPlot",
new FixedMetadataValue(
- (Plugin) PlotSquared.get().IMP, currentPlotId));
+ (Plugin) PlotSquared.platform(), currentPlotId));
}
}
}
@@ -875,13 +975,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
}
@Override @Nullable
- public final ChunkGenerator getDefaultWorldGenerator(@NotNull final String worldName,
+ public final ChunkGenerator getDefaultWorldGenerator(@Nonnull final String worldName,
final String id) {
final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) {
- result = new SingleWorldGenerator();
+ result = getInjector().getInstance(SingleWorldGenerator.class);
} else {
- result = PlotSquared.get().IMP.getDefaultGenerator();
+ result = getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
return null;
}
@@ -889,85 +989,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
return (ChunkGenerator) result.specify(worldName);
}
- @Override public void registerPlayerEvents() {
- final PlayerEvents main = new PlayerEvents();
- getServer().getPluginManager().registerEvents(main, this);
- getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
- if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) {
- getServer().getPluginManager().registerEvents(new PaperListener(), this);
- }
- PlotListener.startRunnable();
- }
-
- @Override public void registerForceFieldEvents() {
- }
-
- @Override public boolean initWorldEdit() {
- if (getServer().getPluginManager().getPlugin("WorldEdit") != null) {
- worldEdit = WorldEdit.getInstance();
- return true;
- }
- return false;
- }
-
- @Override public EconHandler getEconomyHandler() {
- if (econ != null) {
- if (econ.init() /* is inited */) {
- return econ;
- } else {
- return null;
- }
- }
-
- try {
- econ = new BukkitEconHandler();
- if (econ.init()) {
- return econ;
- }
- } catch (Throwable ignored) {
- PlotSquared.debug("No economy detected!");
- }
- return null;
- }
-
- @Override public PermHandler getPermissionHandler() {
- if (perm != null) {
- if (perm.init() /* is inited */) {
- return perm;
- } else {
- return null;
- }
- }
-
- try {
- perm = new BukkitPermHandler();
- if (perm.init()) {
- return perm;
- }
- } catch (Throwable ignored) {
- PlotSquared.debug("No permissions detected!");
- }
- return null;
- }
-
- @Override public QueueProvider initBlockQueue() {
- //TODO Figure out why this code is still here yet isn't being called anywhere.
- // try {
- // new SendChunk();
- // MainUtil.canSendChunk = true;
- // } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) {
- // PlotSquared.debug(
- // SendChunk.class + " does not support " + StringMan.getString(getServerVersion()));
- // MainUtil.canSendChunk = false;
- // }
- return QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class);
- }
-
- @Override public WorldUtil initWorldUtil() {
- return new BukkitUtil();
- }
-
- @Override @Nullable public GeneratorWrapper> getGenerator(@NonNull final String world,
+ @Override @Nullable public GeneratorWrapper> getGenerator(@Nonnull final String world,
@Nullable final String name) {
if (name == null) {
return null;
@@ -978,20 +1000,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
if (gen instanceof GeneratorWrapper>) {
return (GeneratorWrapper>) gen;
}
- return new BukkitPlotGenerator(world, gen);
+ return new BukkitPlotGenerator(world, gen, this.plotAreaManager);
} else {
- return new BukkitPlotGenerator(world, PlotSquared.get().IMP.getDefaultGenerator());
+ return new BukkitPlotGenerator(world, getInjector()
+ .getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class)), this.plotAreaManager);
}
}
- @Override public HybridUtils initHybridUtils() {
- return new BukkitHybridUtils();
- }
-
- @Override public SetupUtils initSetupUtils() {
- return new BukkitSetupUtils();
- }
-
@Override public void startMetrics() {
if (this.metricsStarted) {
return;
@@ -1007,7 +1022,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
}
map.put(plotAreaType.name().toLowerCase(), terrainTypes);
}
- for (final PlotArea plotArea : PlotSquared.get().getPlotAreas()) {
+ for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
final Map terrainTypeMap =
map.get(plotArea.getType().name().toLowerCase());
terrainTypeMap.put(plotArea.getTerrain().name().toLowerCase(),
@@ -1023,56 +1038,31 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
"WorldEdit"));
}
- @Override public ChunkManager initChunkManager() {
- return new BukkitChunkManager();
- }
-
- @Override public RegionManager initRegionManager() {
- return new BukkitRegionManager();
- }
-
- @Override public void unregister(@NonNull final PlotPlayer player) {
+ @Override public void unregister(@Nonnull final PlotPlayer player) {
BukkitUtil.removePlayer(player.getUUID());
}
- @Override public void registerChunkProcessor() {
- getServer().getPluginManager().registerEvents(new ChunkListener(), this);
- }
-
- @Override public void registerWorldEvents() {
- getServer().getPluginManager().registerEvents(new WorldEvents(), this);
- }
-
- @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() {
- return new HybridGen();
- }
-
- @Override public InventoryUtil initInventoryUtil() {
- return new BukkitInventoryUtil();
- }
-
- @Override public void setGenerator(@NonNull final String worldName) {
+ @Override public void setGenerator(@Nonnull final String worldName) {
World world = BukkitUtil.getWorld(worldName);
if (world == null) {
// create world
- ConfigurationSection worldConfig =
- PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
+ ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", getPluginName());
- PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager)
+ PlotAreaBuilder builder = PlotAreaBuilder.newBuilder().plotManager(manager)
.generatorName(worldConfig.getString("generator.init", manager))
.plotAreaType(MainUtil.getType(worldConfig))
.terrainType(MainUtil.getTerrain(worldConfig))
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
.worldName(worldName);
- SetupUtils.manager.setupWorld(builder);
+ getInjector().getInstance(SetupUtils.class).setupWorld(builder);
world = Bukkit.getWorld(worldName);
} else {
try {
- if (!PlotSquared.get().hasPlotArea(worldName)) {
+ if (!this.plotAreaManager.hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
- } catch (Exception e) {
- PlotSquared.log("Failed to reload world: " + world + " | " + e.getMessage());
+ } catch (final Exception e) {
+ logger.error("[P2] Failed to reload world: {} | {}", world, e.getMessage());
Bukkit.getServer().unloadWorld(world, false);
return;
}
@@ -1082,16 +1072,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
if (gen instanceof BukkitPlotGenerator) {
PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
} else if (gen != null) {
- PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen));
- } else if (PlotSquared.get().worlds.contains("worlds." + worldName)) {
+ PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager));
+ } else if (this.worldConfiguration.contains("worlds." + worldName)) {
PlotSquared.get().loadWorld(worldName, null);
}
}
- @Override public SchematicHandler initSchematicHandler() {
- return new BukkitSchematicHandler();
- }
-
/**
* Attempt to retrieve a {@link PlotPlayer} from a player identifier.
* This method accepts:
@@ -1115,11 +1101,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
return BukkitUtil.getPlayer((OfflinePlayer) player);
}
if (player instanceof String) {
- return (PlotPlayer) PlotSquared.imp().getPlayerManager()
+ return (PlotPlayer) PlotSquared.platform().getPlayerManager()
.getPlayerIfExists((String) player);
}
if (player instanceof UUID) {
- return (PlotPlayer) PlotSquared.imp().getPlayerManager()
+ return (PlotPlayer) PlotSquared.platform().getPlayerManager()
.getPlayerIfExists((UUID) player);
}
return null;
@@ -1131,8 +1117,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
}
@Override public GeneratorWrapper> wrapPlotGenerator(@Nullable final String world,
- @NonNull final IndependentPlotGenerator generator) {
- return new BukkitPlotGenerator(world, generator);
+ @Nonnull final IndependentPlotGenerator generator) {
+ return new BukkitPlotGenerator(world, generator, this.plotAreaManager);
}
@Override public List, Boolean>> getPluginIds() {
@@ -1145,16 +1131,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
return names;
}
- @Override public Actor getConsole() {
- @NotNull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
- WorldEditPlugin wePlugin =
- ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
- return wePlugin.wrapCommandSender(console);
- }
-
- @Override @NotNull
- public PlayerManager extends PlotPlayer, ? extends Player> getPlayerManager() {
- return this.playerManager;
+ @Override public com.plotsquared.core.location.World> getPlatformWorld(@Nonnull final String worldName) {
+ return BukkitWorld.of(worldName);
}
@Override @NotNull public Audience getConsoleAudience() {
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/EntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/EntityWrapper.java
index 6e777f23a..08924e27a 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/EntityWrapper.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/EntityWrapper.java
@@ -26,11 +26,12 @@
package com.plotsquared.bukkit.entity;
import lombok.Getter;
-import lombok.NonNull;
+
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
+import javax.annotation.Nonnull;
@Getter
public abstract class EntityWrapper {
@@ -43,7 +44,7 @@ public abstract class EntityWrapper {
public double y;
public double z;
- EntityWrapper(@NonNull final Entity entity) {
+ EntityWrapper(@Nonnull final Entity entity) {
this.entity = entity;
this.type = entity.getType();
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
index 83740e9db..3522863ae 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
@@ -25,7 +25,7 @@
*/
package com.plotsquared.bukkit.entity;
-import com.plotsquared.core.PlotSquared;
+import com.plotsquared.core.configuration.Settings;
import org.bukkit.Art;
import org.bukkit.DyeColor;
import org.bukkit.Location;
@@ -55,11 +55,15 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.List;
public final class ReplicatingEntityWrapper extends EntityWrapper {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + ReplicatingEntityWrapper.class.getSimpleName());
+
private final short depth;
private final int hash;
private final EntityBaseStats base = new EntityBaseStats();
@@ -331,10 +335,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.dataByte = (byte) 0;
}
storeLiving((LivingEntity) entity);
- return;
// END LIVING //
- default:
- PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
}
}
@@ -390,7 +391,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
try {
entity.getInventory().setContents(this.inventory);
} catch (IllegalArgumentException e) {
- PlotSquared.debug("&c[WARN] Failed to restore inventory.\n Reason: " + e.getMessage());
+ logger.error("[P2] Failed to restore inventory", e);
}
}
@@ -736,7 +737,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreLiving((LivingEntity) entity);
return entity;
default:
- PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
+ if (Settings.DEBUG) {
+ logger.info("[P2] Could not identify entity: {}", entity.getType());
+ }
return entity;
// END LIVING
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java
index 45613a751..6a37571a3 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/TeleportEntityWrapper.java
@@ -25,7 +25,7 @@
*/
package com.plotsquared.bukkit.entity;
-import com.plotsquared.bukkit.BukkitMain;
+import com.plotsquared.bukkit.BukkitPlatform;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
@@ -53,7 +53,7 @@ public class TeleportEntityWrapper extends EntityWrapper {
getEntity().setInvulnerable(invulnerableOld);
getEntity().setFireTicks(fireTicksOld);
getEntity().setTicksLived(livingTicksOld);
- getEntity().removeMetadata("ps-tmp-teleport", BukkitMain.getPlugin(BukkitMain.class));
+ getEntity().removeMetadata("ps-tmp-teleport", BukkitPlatform.getPlugin(BukkitPlatform.class));
}
return getEntity();
}
@@ -78,7 +78,7 @@ public class TeleportEntityWrapper extends EntityWrapper {
this.fireTicksOld = this.getEntity().getFireTicks();
this.livingTicksOld = this.getEntity().getTicksLived();
this.getEntity().setMetadata("ps-tmp-teleport",
- new FixedMetadataValue(BukkitMain.getPlugin(BukkitMain.class), oldLocation));
+ new FixedMetadataValue(BukkitPlatform.getPlugin(BukkitPlatform.class), oldLocation));
final Chunk newChunk = getNewChunk();
this.getEntity().teleport(
new Location(newChunk.getWorld(), newChunk.getX() << 4, 5000, newChunk.getZ() << 4));
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java
index a89588598..3e3b74938 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BlockStatePopulator.java
@@ -29,32 +29,40 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.plot.PlotArea;
-import com.plotsquared.core.queue.GlobalBlockQueue;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Random;
final class BlockStatePopulator extends BlockPopulator {
private final IndependentPlotGenerator plotGenerator;
+ private final PlotAreaManager plotAreaManager;
+
private LocalBlockQueue queue;
- public BlockStatePopulator(IndependentPlotGenerator plotGenerator) {
+ public BlockStatePopulator(@Nonnull final IndependentPlotGenerator plotGenerator,
+ @Nonnull final PlotAreaManager plotAreaManager) {
this.plotGenerator = plotGenerator;
+ this.plotAreaManager = plotAreaManager;
}
@Override
- public void populate(@NotNull final World world, @NotNull final Random random,
- @NotNull final Chunk source) {
+ public void populate(@Nonnull final World world, @Nonnull final Random random,
+ @Nonnull final Chunk source) {
if (this.queue == null) {
- this.queue = GlobalBlockQueue.IMP.getNewQueue(world.getName(), false);
+ this.queue = PlotSquared.platform().getGlobalBlockQueue()
+ .getNewQueue(world.getName(), false);
+ }
+ final PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
+ if (area == null) {
+ return;
}
- final PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
final ChunkWrapper wrap =
new ChunkWrapper(area.getWorldName(), source.getX(), source.getZ());
final ScopedLocalBlockQueue chunk = this.queue.getForChunk(wrap.x, wrap.z);
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java
index ff158f295..7c08c6871 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java
@@ -29,7 +29,7 @@ import com.plotsquared.core.generator.AugmentedUtils;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Random;
@@ -51,7 +51,7 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
}
@Override
- public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk source) {
+ public void populate(@Nonnull World world, @Nonnull Random random, @Nonnull Chunk source) {
AugmentedUtils.generate(source, world.getName(), source.getX(), source.getZ(), null);
}
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java
index 6f886904f..60bb34b9a 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java
@@ -33,6 +33,7 @@ import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.generator.SingleWorldGenerator;
import com.plotsquared.core.location.ChunkWrapper;
import com.plotsquared.core.plot.PlotArea;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.MainUtil;
@@ -42,7 +43,7 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
@@ -54,6 +55,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
@SuppressWarnings("unused") public final boolean PAPER_ASYNC_SAFE = true;
+ private final PlotAreaManager plotAreaManager;
private final IndependentPlotGenerator plotGenerator;
private final ChunkGenerator platformGenerator;
private final boolean full;
@@ -62,24 +64,25 @@ public class BukkitPlotGenerator extends ChunkGenerator
@Getter private final String levelName;
- public BukkitPlotGenerator(String name, IndependentPlotGenerator generator) {
- if (generator == null) {
- throw new IllegalArgumentException("Generator may not be null!");
- }
+ public BukkitPlotGenerator(@Nonnull final String name,
+ @Nonnull final IndependentPlotGenerator generator,
+ @Nonnull final PlotAreaManager plotAreaManager) {
+ this.plotAreaManager = plotAreaManager;
this.levelName = name;
this.plotGenerator = generator;
this.platformGenerator = this;
this.populators = new ArrayList<>();
- this.populators.add(new BlockStatePopulator(this.plotGenerator));
+ this.populators.add(new BlockStatePopulator(this.plotGenerator, this.plotAreaManager));
this.full = true;
MainUtil.initCache();
}
- public BukkitPlotGenerator(final String world, final ChunkGenerator cg) {
+ public BukkitPlotGenerator(final String world, final ChunkGenerator cg, @Nonnull final PlotAreaManager plotAreaManager) {
if (cg instanceof BukkitPlotGenerator) {
throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName()
+ " is already a BukkitPlotGenerator!");
}
+ this.plotAreaManager = plotAreaManager;
this.levelName = world;
this.full = false;
this.platformGenerator = cg;
@@ -103,12 +106,12 @@ public class BukkitPlotGenerator extends ChunkGenerator
return this.platformGenerator;
}
- @Override @NotNull public List getDefaultPopulators(@NotNull World world) {
+ @Override @Nonnull public List getDefaultPopulators(@Nonnull World world) {
try {
if (!this.loaded) {
String name = world.getName();
PlotSquared.get().loadWorld(name, this);
- Set areas = PlotSquared.get().getPlotAreas(name);
+ final Set areas = this.plotAreaManager.getPlotAreasSet(name);
if (!areas.isEmpty()) {
PlotArea area = areas.iterator().next();
if (!area.isMobSpawning()) {
@@ -147,9 +150,9 @@ public class BukkitPlotGenerator extends ChunkGenerator
return toAdd;
}
- @Override @NotNull
- public ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z,
- @NotNull BiomeGrid biome) {
+ @Override @Nonnull
+ public ChunkData generateChunkData(@Nonnull World world, @Nonnull Random random, int x, int z,
+ @Nonnull BiomeGrid biome) {
GenChunk result = new GenChunk();
if (this.getPlotGenerator() instanceof SingleWorldGenerator) {
@@ -198,8 +201,8 @@ public class BukkitPlotGenerator extends ChunkGenerator
if (ChunkManager.preProcessChunk(loc, result)) {
return;
}
- PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null);
- if (area == null && (area = PlotSquared.get().getPlotArea(this.levelName, null)) == null) {
+ PlotArea area = this.plotAreaManager.getPlotArea(world.getName(), null);
+ if (area == null && (area = this.plotAreaManager.getPlotArea(this.levelName, null)) == null) {
throw new IllegalStateException(
"Cannot regenerate chunk that does not belong to a plot area." + " Location: " + loc
+ ", world: " + world);
@@ -213,7 +216,7 @@ public class BukkitPlotGenerator extends ChunkGenerator
ChunkManager.postProcessChunk(loc, result);
}
- @Override public boolean canSpawn(@NotNull final World world, final int x, final int z) {
+ @Override public boolean canSpawn(@Nonnull final World world, final int x, final int z) {
return true;
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java
index d5086b06d..6452941a2 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/DelegatePlotGenerator.java
@@ -38,7 +38,7 @@ import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import org.jetbrains.annotations.Range;
import java.util.Random;
@@ -61,7 +61,7 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
}
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
- return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
+ return PlotSquared.platform().getDefaultGenerator().getNewPlotArea(world, id, min, max);
}
@Override public void generateChunk(final ScopedLocalBlockQueue result, PlotArea settings) {
@@ -74,21 +74,21 @@ final class DelegatePlotGenerator extends IndependentPlotGenerator {
ChunkGenerator.BiomeGrid grid = new ChunkGenerator.BiomeGrid() {
@Override
public void setBiome(@Range(from = 0, to = 15) int x,
- @Range(from = 0, to = 15) int z, @NotNull Biome biome) {
+ @Range(from = 0, to = 15) int z, @Nonnull Biome biome) {
result.setBiome(x, z, BukkitAdapter.adapt(biome));
}
//do not annotate with Override until we discontinue support for 1.4.4
- public void setBiome(int x, int y, int z, @NotNull Biome biome) {
+ public void setBiome(int x, int y, int z, @Nonnull Biome biome) {
result.setBiome(x, z, BukkitAdapter.adapt(biome));
}
- @Override @NotNull public Biome getBiome(int x, int z) {
+ @Override @Nonnull public Biome getBiome(int x, int z) {
return Biome.FOREST;
}
- @Override public @NotNull Biome getBiome(int x, int y, int z) {
+ @Override public @Nonnull Biome getBiome(int x, int y, int z) {
return Biome.FOREST;
}
};
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BackupModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BackupModule.java
new file mode 100644
index 000000000..d97cf5d05
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BackupModule.java
@@ -0,0 +1,55 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.inject;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.plotsquared.core.backup.BackupManager;
+import com.plotsquared.core.backup.BackupProfile;
+import com.plotsquared.core.backup.NullBackupManager;
+import com.plotsquared.core.backup.PlayerBackupProfile;
+import com.plotsquared.core.backup.SimpleBackupManager;
+import com.plotsquared.core.inject.factory.PlayerBackupProfileFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BackupModule extends AbstractModule {
+
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + BackupModule.class.getSimpleName());
+
+ @Override protected void configure() {
+ try {
+ install(new FactoryModuleBuilder()
+ .implement(BackupProfile.class, PlayerBackupProfile.class).build(PlayerBackupProfileFactory.class));
+ bind(BackupManager.class).to(SimpleBackupManager.class);
+ } catch (final Exception e) {
+ logger.error("[P2] Failed to initialize backup manager", e);
+ logger.error("[P2] Backup features will be disabled");
+ bind(BackupManager.class).to(NullBackupManager.class);
+ }
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
new file mode 100644
index 000000000..c6fe99ba7
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
@@ -0,0 +1,122 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.inject;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.util.Providers;
+import com.plotsquared.bukkit.BukkitPlatform;
+import com.plotsquared.bukkit.player.BukkitPlayerManager;
+import com.plotsquared.bukkit.queue.BukkitLocalQueue;
+import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
+import com.plotsquared.bukkit.util.BukkitChunkManager;
+import com.plotsquared.bukkit.util.BukkitEconHandler;
+import com.plotsquared.bukkit.util.BukkitInventoryUtil;
+import com.plotsquared.bukkit.util.BukkitPermHandler;
+import com.plotsquared.bukkit.util.BukkitRegionManager;
+import com.plotsquared.bukkit.util.BukkitSetupUtils;
+import com.plotsquared.bukkit.util.BukkitUtil;
+import com.plotsquared.core.PlotPlatform;
+import com.plotsquared.core.configuration.Settings;
+import com.plotsquared.core.generator.HybridGen;
+import com.plotsquared.core.generator.IndependentPlotGenerator;
+import com.plotsquared.core.inject.annotations.ConsoleActor;
+import com.plotsquared.core.inject.annotations.DefaultGenerator;
+import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
+import com.plotsquared.core.plot.world.DefaultPlotAreaManager;
+import com.plotsquared.core.plot.world.PlotAreaManager;
+import com.plotsquared.core.plot.world.SinglePlotAreaManager;
+import com.plotsquared.core.queue.GlobalBlockQueue;
+import com.plotsquared.core.queue.QueueProvider;
+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.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.sk89q.worldedit.bukkit.WorldEditPlugin;
+import com.sk89q.worldedit.extension.platform.Actor;
+import lombok.RequiredArgsConstructor;
+import org.bukkit.Bukkit;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.plugin.java.JavaPlugin;
+import javax.annotation.Nonnull;
+
+@RequiredArgsConstructor public class BukkitModule extends AbstractModule {
+
+ private final BukkitPlatform bukkitPlatform;
+
+ @Override protected void configure() {
+ bind(PlayerManager.class).to(BukkitPlayerManager.class);
+ bind(JavaPlugin.class).toInstance(bukkitPlatform);
+ bind(PlotPlatform.class).toInstance(bukkitPlatform);
+ bind(IndependentPlotGenerator.class).annotatedWith(DefaultGenerator.class).to(HybridGen.class);
+ // Console actor
+ @Nonnull ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
+ WorldEditPlugin wePlugin = ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"));
+ bind(Actor.class).annotatedWith(ConsoleActor.class).toInstance(wePlugin.wrapCommandSender(console));
+ bind(InventoryUtil.class).to(BukkitInventoryUtil.class);
+ bind(SetupUtils.class).to(BukkitSetupUtils.class);
+ bind(WorldUtil.class).to(BukkitUtil.class);
+ bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(
+ QueueProvider.of(BukkitLocalQueue.class, BukkitLocalQueue.class), 1, Settings.QUEUE.TARGET_TIME));
+ bind(ChunkManager.class).to(BukkitChunkManager.class);
+ bind(RegionManager.class).to(BukkitRegionManager.class);
+ bind(SchematicHandler.class).to(BukkitSchematicHandler.class);
+ this.setupVault();
+ if (Settings.Enabled_Components.WORLDS) {
+ bind(PlotAreaManager.class).to(SinglePlotAreaManager.class);
+ } else {
+ bind(PlotAreaManager.class).to(DefaultPlotAreaManager.class);
+ }
+ install(new FactoryModuleBuilder().build(HybridPlotWorldFactory.class));
+ }
+
+ private void setupVault() {
+ if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
+ BukkitPermHandler bukkitPermHandler = null;
+ try {
+ bukkitPermHandler = new BukkitPermHandler();
+ bind(PermHandler.class).toInstance(bukkitPermHandler);
+ } catch (final Exception ignored) {
+ bind(PermHandler.class).toProvider(Providers.of(null));
+ }
+ try {
+ final BukkitEconHandler bukkitEconHandler = new BukkitEconHandler(bukkitPermHandler);
+ bind(EconHandler.class).toInstance(bukkitEconHandler);
+ } catch (final Exception ignored) {
+ bind(EconHandler.class).toProvider(Providers.of(null));
+ }
+ } else {
+ bind(PermHandler.class).toProvider(Providers.of(null));
+ bind(EconHandler.class).toProvider(Providers.of(null));
+ }
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java
new file mode 100644
index 000000000..f098192b5
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java
@@ -0,0 +1,52 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.inject;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+import com.plotsquared.bukkit.managers.BukkitWorldManager;
+import com.plotsquared.bukkit.managers.HyperverseWorldManager;
+import com.plotsquared.bukkit.managers.MultiverseWorldManager;
+import com.plotsquared.core.util.PlatformWorldManager;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+
+public class WorldManagerModule extends AbstractModule {
+
+ @Provides
+ @Singleton
+ PlatformWorldManager provideWorldManager() {
+ if (Bukkit.getPluginManager().getPlugin("Hyperverse") != null) {
+ return new HyperverseWorldManager();
+ } else if (Bukkit.getPluginManager().getPlugin("Multiverse-Core") != null) {
+ return new MultiverseWorldManager();
+ } else {
+ return new BukkitWorldManager();
+ }
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java
index 1cfc897d4..c22df7c54 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java
@@ -25,10 +25,12 @@
*/
package com.plotsquared.bukkit.listener;
+import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.ReflectionUtils.RefClass;
import com.plotsquared.core.util.ReflectionUtils.RefField;
import com.plotsquared.core.util.ReflectionUtils.RefMethod;
@@ -51,6 +53,9 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
+import javax.annotation.Nonnull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.HashSet;
@@ -60,12 +65,17 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
@SuppressWarnings("unused")
public class ChunkListener implements Listener {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + ChunkListener.class.getSimpleName());
+
+ private final PlotAreaManager plotAreaManager;
+
private RefMethod methodGetHandleChunk;
private RefField mustSave;
private Chunk lastChunk;
private boolean ignoreUnload = false;
- public ChunkListener() {
+ @Inject public ChunkListener(@Nonnull final PlotAreaManager plotAreaManager) {
+ this.plotAreaManager = plotAreaManager;
if (Settings.Chunk_Processor.AUTO_TRIM) {
try {
RefClass classChunk = getRefClass("{nms}.Chunk");
@@ -73,9 +83,6 @@ public class ChunkListener implements Listener {
this.mustSave = classChunk.getField("mustSave");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
} catch (Throwable ignored) {
- PlotSquared.debug(PlotSquared.get().IMP.getPluginName()
- + "/Server not compatible for chunk processor trim/gc");
-
Settings.Chunk_Processor.AUTO_TRIM = false;
}
}
@@ -90,7 +97,7 @@ public class ChunkListener implements Listener {
HashSet toUnload = new HashSet<>();
for (World world : Bukkit.getWorlds()) {
String worldName = world.getName();
- if (!PlotSquared.get().hasPlotArea(worldName)) {
+ if (!this.plotAreaManager.hasPlotArea(worldName)) {
continue;
}
Object w = world.getClass().getDeclaredMethod("getHandle").invoke(world);
@@ -150,23 +157,23 @@ public class ChunkListener implements Listener {
int z = chunkZ << 4;
int x2 = x + 15;
int z2 = z + 15;
- Plot plot = new Location(world, x, 1, z).getOwnedPlotAbs();
+ Plot plot = Location.at(world, x, 1, z).getOwnedPlotAbs();
if (plot != null && plot.hasOwner()) {
return true;
}
- plot = new Location(world, x2, 1, z2).getOwnedPlotAbs();
+ plot = Location.at(world, x2, 1, z2).getOwnedPlotAbs();
if (plot != null && plot.hasOwner()) {
return true;
}
- plot = new Location(world, x2, 1, z).getOwnedPlotAbs();
+ plot = Location.at(world, x2, 1, z).getOwnedPlotAbs();
if (plot != null && plot.hasOwner()) {
return true;
}
- plot = new Location(world, x, 1, z2).getOwnedPlotAbs();
+ plot = Location.at(world, x, 1, z2).getOwnedPlotAbs();
if (plot != null && plot.hasOwner()) {
return true;
}
- plot = new Location(world, x + 7, 1, z + 7).getOwnedPlotAbs();
+ plot = Location.at(world, x + 7, 1, z + 7).getOwnedPlotAbs();
return plot != null && plot.hasOwner();
}
@@ -177,7 +184,7 @@ public class ChunkListener implements Listener {
Chunk chunk = event.getChunk();
if (Settings.Chunk_Processor.AUTO_TRIM) {
String world = chunk.getWorld().getName();
- if (PlotSquared.get().hasPlotArea(world)) {
+ if (this.plotAreaManager.hasPlotArea(world)) {
if (unloadChunk(world, chunk, true)) {
return;
}
@@ -200,7 +207,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true);
return;
}
- if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
+ if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
return;
}
Entity[] entities = chunk.getEntities();
@@ -230,7 +237,7 @@ public class ChunkListener implements Listener {
event.setCancelled(true);
return;
}
- if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
+ if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
return;
}
Entity[] entities = chunk.getEntities();
@@ -251,7 +258,6 @@ public class ChunkListener implements Listener {
if (!chunk.isLoaded()) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
- PlotSquared.debug("Successfully processed and unloaded chunk!");
chunk.unload(true);
return;
}
@@ -259,7 +265,6 @@ public class ChunkListener implements Listener {
if (tiles.length == 0) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
- PlotSquared.debug("Successfully processed and unloaded chunk!");
chunk.unload(true);
return;
}
@@ -269,7 +274,6 @@ public class ChunkListener implements Listener {
if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) {
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
TaskManager.tasks.remove(currentIndex);
- PlotSquared.debug("Successfully processed and unloaded chunk!");
chunk.unload(true);
return;
}
@@ -281,7 +285,7 @@ public class ChunkListener implements Listener {
}
public boolean processChunk(Chunk chunk, boolean unload) {
- if (!PlotSquared.get().hasPlotArea(chunk.getWorld().getName())) {
+ if (!this.plotAreaManager.hasPlotArea(chunk.getWorld().getName())) {
return false;
}
Entity[] entities = chunk.getEntities();
@@ -296,16 +300,9 @@ public class ChunkListener implements Listener {
toRemove--;
}
}
-
- PlotSquared.debug(
- "PlotSquared detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (
- chunk.getX() << 4));
}
if (tiles.length > Settings.Chunk_Processor.MAX_TILES) {
if (unload) {
- PlotSquared.debug(
- "PlotSquared detected unsafe chunk: " + (chunk.getX() << 4) + "," + (
- chunk.getX() << 4));
cleanChunk(chunk);
return true;
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java
index 0bf5e75e8..85903eb9a 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java
@@ -53,7 +53,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.List;
@@ -65,7 +65,7 @@ public class EntitySpawnListener implements Listener {
private static String areaName = null;
public static void testNether(final Entity entity) {
- @NotNull World world = entity.getWorld();
+ @Nonnull World world = entity.getWorld();
if (world.getEnvironment() != World.Environment.NETHER
&& world.getEnvironment() != World.Environment.THE_END) {
return;
@@ -74,11 +74,11 @@ public class EntitySpawnListener implements Listener {
}
public static void testCreate(final Entity entity) {
- @NotNull World world = entity.getWorld();
+ @Nonnull World world = entity.getWorld();
if (areaName == world.getName()) {
} else {
areaName = world.getName();
- hasPlotArea = PlotSquared.get().hasPlotArea(areaName);
+ hasPlotArea = PlotSquared.get().getPlotAreaManager().hasPlotArea(areaName);
}
if (!hasPlotArea) {
return;
@@ -87,12 +87,12 @@ public class EntitySpawnListener implements Listener {
}
public static void test(Entity entity) {
- @NotNull World world = entity.getWorld();
+ @Nonnull World world = entity.getWorld();
List meta = entity.getMetadata(KEY);
if (meta.isEmpty()) {
- if (PlotSquared.get().hasPlotArea(world.getName())) {
+ if (PlotSquared.get().getPlotAreaManager().hasPlotArea(world.getName())) {
entity.setMetadata(KEY,
- new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation()));
+ new FixedMetadataValue((Plugin) PlotSquared.platform(), entity.getLocation()));
}
} else {
org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value();
@@ -161,13 +161,13 @@ public class EntitySpawnListener implements Listener {
case SHULKER:
if (!entity.hasMetadata("shulkerPlot")) {
entity.setMetadata("shulkerPlot",
- new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot.getId()));
+ new FixedMetadataValue((Plugin) PlotSquared.platform(), plot.getId()));
}
}
}
@EventHandler public void onChunkLoad(ChunkLoadEvent event) {
- @NotNull Chunk chunk = event.getChunk();
+ @Nonnull Chunk chunk = event.getChunk();
for (final Entity entity : chunk.getEntities()) {
testCreate(entity);
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java
index a512189f7..7dfe8fbcb 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java
@@ -32,8 +32,8 @@ import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
+import com.google.inject.Inject;
import com.plotsquared.bukkit.util.BukkitUtil;
-import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.command.Command;
import com.plotsquared.core.command.MainCommand;
import com.plotsquared.core.configuration.Captions;
@@ -43,6 +43,7 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import org.bukkit.Chunk;
import org.bukkit.block.Block;
import org.bukkit.block.TileState;
@@ -58,6 +59,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.projectiles.ProjectileSource;
+import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
@@ -71,8 +73,13 @@ import java.util.regex.Pattern;
@SuppressWarnings("unused")
public class PaperListener implements Listener {
+ private final PlotAreaManager plotAreaManager;
private Chunk lastChunk;
+ @Inject public PaperListener(@Nonnull final PlotAreaManager plotAreaManager) {
+ this.plotAreaManager = plotAreaManager;
+ }
+
@EventHandler public void onEntityPathfind(EntityPathfindEvent event) {
if (!Settings.Paper_Components.ENTITY_PATHING) {
return;
@@ -305,7 +312,7 @@ public class PaperListener implements Listener {
return;
}
Location location = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer> pp = BukkitUtil.getPlayer((Player) shooter);
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
index 96e348f3e..ce868a61e 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
@@ -27,6 +27,7 @@ package com.plotsquared.bukkit.listener;
import com.destroystokyo.paper.MaterialTags;
import com.google.common.base.Charsets;
+import com.google.inject.Inject;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.UpdateUtility;
@@ -99,14 +100,18 @@ import com.plotsquared.core.plot.flag.implementations.VillagerInteractFlag;
import com.plotsquared.core.plot.flag.implementations.VineGrowFlag;
import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
import com.plotsquared.core.plot.message.PlotMessage;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EntityUtil;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.RegExUtil;
+import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.TaskManager;
+import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import io.papermc.lib.PaperLib;
@@ -210,6 +215,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
+import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -224,12 +230,16 @@ import java.util.regex.Pattern;
/**
* Player Events involving plots.
*/
-@SuppressWarnings("unused")
-public class PlayerEvents extends PlotListener implements Listener {
+@SuppressWarnings("unused") public class PlayerEvents extends PlotListener implements Listener {
public static final com.sk89q.worldedit.world.entity.EntityType FAKE_ENTITY_TYPE =
new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake");
+ private final PlotAreaManager plotAreaManager;
+ private final EventDispatcher eventDispatcher;
+ private final WorldEdit worldEdit;
+
+ private boolean pistonBlocks = true;
private float lastRadius;
// To prevent recursion
private boolean tmpTeleport = true;
@@ -237,7 +247,14 @@ public class PlayerEvents extends PlotListener implements Listener {
private PlayerMoveEvent moveTmp;
private String internalVersion;
- {
+ @Inject public PlayerEvents(@Nonnull final PlotAreaManager plotAreaManager,
+ @Nonnull final EventDispatcher eventDispatcher,
+ @Nonnull final WorldEdit worldEdit,
+ @Nonnull final WorldUtil worldUtil) {
+ super(eventDispatcher);
+ this.plotAreaManager = plotAreaManager;
+ this.eventDispatcher = eventDispatcher;
+ this.worldEdit = worldEdit;
try {
fieldPlayer = PlayerEvent.class.getDeclaredField("player");
fieldPlayer.setAccessible(true);
@@ -253,9 +270,10 @@ public class PlayerEvents extends PlotListener implements Listener {
int z = bloc.getBlockZ();
int distance = Bukkit.getViewDistance() * 16;
- for (final PlotPlayer> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
+ for (final PlotPlayer> player : PlotSquared.platform().getPlayerManager()
+ .getPlayers()) {
Location location = player.getLocation();
- if (location.getWorld().equals(world)) {
+ if (location.getWorldName().equals(world)) {
if (16 * Math.abs(location.getX() - x) / 16 > distance
|| 16 * Math.abs(location.getZ() - z) / 16 > distance) {
continue;
@@ -358,20 +376,21 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot.isMerged()) {
disable = true;
for (UUID owner : plot.getOwners()) {
- if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner) != null) {
+ if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(owner)
+ != null) {
disable = false;
break;
}
}
} else {
- disable =
- PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs())
- == null;
+ disable = PlotSquared.platform().getPlayerManager()
+ .getPlayerIfExists(plot.getOwnerAbs()) == null;
}
}
if (disable) {
for (UUID trusted : plot.getTrusted()) {
- if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(trusted) != null) {
+ if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(trusted)
+ != null) {
disable = false;
break;
}
@@ -385,7 +404,8 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
if (Settings.Redstone.DISABLE_UNOCCUPIED) {
- for (final PlotPlayer> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
+ for (final PlotPlayer> player : PlotSquared.platform().getPlayerManager()
+ .getPlayers()) {
if (plot.equals(player.getCurrentPlot())) {
return;
}
@@ -455,16 +475,16 @@ public class PlayerEvents extends PlotListener implements Listener {
}
switch (piston.getFacing()) {
case EAST:
- location.setX(location.getX() + 1);
+ location = location.add(1, 0, 0);
break;
case SOUTH:
- location.setX(location.getX() - 1);
+ location = location.add(-1, 0, 0);
break;
case WEST:
- location.setZ(location.getZ() + 1);
+ location = location.add(0, 0, 1);
break;
case NORTH:
- location.setZ(location.getZ() - 1);
+ location = location.add(0, 0, -1);
break;
}
Plot newPlot = area.getOwnedPlotAbs(location);
@@ -490,7 +510,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Location location = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
@@ -504,7 +524,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler public boolean onProjectileHit(ProjectileHitEvent event) {
Projectile entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return true;
}
PlotArea area = location.getPlotArea();
@@ -680,7 +700,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!player.hasPlayedBefore() && player.isOnline()) {
player.saveData();
}
- PlotSquared.get().getEventDispatcher().doJoinTask(pp);
+ this.eventDispatcher.doJoinTask(pp);
}, 20);
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
@@ -703,7 +723,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void playerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
- PlotSquared.get().getEventDispatcher().doRespawnTask(pp);
+ this.eventDispatcher.doRespawnTask(pp);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -803,7 +823,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
} else if (toPlot != null) {
vehicle.setMetadata("plot",
- new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
+ new FixedMetadataValue((Plugin) PlotSquared.platform(), toPlot));
}
}
}
@@ -973,7 +993,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Set recipients = event.getRecipients();
recipients.clear();
Set spies = new HashSet<>();
- for (final PlotPlayer> pp : PlotSquared.imp().getPlayerManager().getPlayers()) {
+ for (final PlotPlayer> pp : PlotSquared.platform().getPlayerManager().getPlayers()) {
if (pp.getAttribute("chatspy")) {
spies.add(((BukkitPlayer) pp).player);
} else {
@@ -1000,7 +1020,8 @@ public class PlayerEvents extends PlotListener implements Listener {
player.sendMessage(spyMessage);
}
}
- PlotSquared.debug(full);
+ // TODO: Re-implement
+ // PlotSquared.debug(full);
}
@EventHandler(priority = EventPriority.LOWEST) public void blockDestroy(BlockBreakEvent event) {
@@ -1065,9 +1086,9 @@ public class PlayerEvents extends PlotListener implements Listener {
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
return;
}
- if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
+ if (this.worldEdit!= null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == Material
- .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
+ .getMaterial(this.worldEdit.getConfiguration().wandItem)) {
return;
}
}
@@ -1082,7 +1103,7 @@ public class PlayerEvents extends PlotListener implements Listener {
PlotArea area = location.getPlotArea();
boolean plotArea = location.isPlotArea();
if (!plotArea) {
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
return;
@@ -1105,7 +1126,7 @@ public class PlayerEvents extends PlotListener implements Listener {
.equals(EntityType.MINECART_TNT)) {
if (!near.hasMetadata("plot")) {
near.setMetadata("plot",
- new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
+ new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
}
}
}
@@ -1138,7 +1159,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot != null) {
plotExit(pp, plot);
}
- if (PlotSquared.get().worldedit != null) {
+ if (this.worldEdit != null) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_WORLDEDIT_BYPASS)) {
if (pp.getAttribute("worldedit")) {
pp.removeAttribute("worldedit");
@@ -1178,7 +1199,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityBlockForm(EntityBlockFormEvent event) {
String world = event.getBlock().getWorld().getName();
- if (!PlotSquared.get().hasPlotArea(world)) {
+ if (!this.plotAreaManager.hasPlotArea(world)) {
return;
}
Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
@@ -1509,13 +1530,14 @@ public class PlayerEvents extends PlotListener implements Listener {
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
PlotArea area = location.getPlotArea();
if (area == null) {
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
for (Block block1 : event.getBlocks()) {
Location bloc = BukkitUtil.getLocation(block1.getLocation());
- if (bloc.isPlotArea() || bloc.add(relative.getBlockX(),
- relative.getBlockY(), relative.getBlockZ()).isPlotArea()) {
+ if (bloc.isPlotArea() || bloc
+ .add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
+ .isPlotArea()) {
event.setCancelled(true);
return;
}
@@ -1546,8 +1568,8 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
}
- if (!plot.equals(area.getOwnedPlot(location.add(
- relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
+ if (!plot.equals(area.getOwnedPlot(
+ location.add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())))) {
// This branch is only necessary to prevent pistons from extending
// if they are: on a plot edge, facing outside the plot, and not
// pushing any blocks
@@ -1563,13 +1585,14 @@ public class PlayerEvents extends PlotListener implements Listener {
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
PlotArea area = location.getPlotArea();
if (area == null) {
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
for (Block block1 : event.getBlocks()) {
Location bloc = BukkitUtil.getLocation(block1.getLocation());
- if (bloc.isPlotArea() || bloc.add(relative.getBlockX(),
- relative.getBlockY(), relative.getBlockZ()).isPlotArea()) {
+ if (bloc.isPlotArea() || bloc
+ .add(relative.getBlockX(), relative.getBlockY(), relative.getBlockZ())
+ .isPlotArea()) {
event.setCancelled(true);
return;
}
@@ -1647,7 +1670,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(StructureGrowEvent event) {
- if (!PlotSquared.get().hasPlotArea(event.getWorld().getName())) {
+ if (!this.plotAreaManager.hasPlotArea(event.getWorld().getName())) {
return;
}
List blocks = event.getBlocks();
@@ -1710,7 +1733,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}*/
HumanEntity entity = event.getWhoClicked();
- if (!(entity instanceof Player) || !PlotSquared.get()
+ if (!(entity instanceof Player) || !this.plotAreaManager
.hasPlotArea(entity.getWorld().getName())) {
return;
}
@@ -1852,7 +1875,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onPotionSplash(LingeringPotionSplashEvent event) {
Projectile entity = event.getEntity();
Location location = BukkitUtil.getLocation(entity);
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
if (!this.onProjectileHit(event)) {
@@ -1918,8 +1941,8 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onBigBoom(BlockExplodeEvent event) {
Block block = event.getBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
- String world = location.getWorld();
- if (!PlotSquared.get().hasPlotArea(world)) {
+ String world = location.getWorldName();
+ if (!this.plotAreaManager.hasPlotArea(world)) {
return;
}
PlotArea area = location.getPlotArea();
@@ -1955,7 +1978,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
Material item = event.getMaterial();
- if (item.toString().toLowerCase().endsWith("egg")) {
+ if (item.toString().toLowerCase().endsWith("_egg")) {
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
}
@@ -1967,11 +1990,11 @@ public class PlayerEvents extends PlotListener implements Listener {
if (type == Material.AIR) {
type = offType;
}
- if (type.toString().toLowerCase().endsWith("egg")) {
+ if (type.toString().toLowerCase().endsWith("_egg")) {
Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY);
if (block != null && block.getType() != Material.AIR) {
Location location = BukkitUtil.getLocation(block.getLocation());
- if (!PlotSquared.get().getEventDispatcher()
+ if (!this.eventDispatcher
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null,
true)) {
event.setCancelled(true);
@@ -2102,13 +2125,13 @@ public class PlayerEvents extends PlotListener implements Listener {
default:
return;
}
- if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
+ if (this.worldEdit != null && pp.getAttribute("worldedit")) {
if (event.getMaterial() == Material
- .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
+ .getMaterial(this.worldEdit.getConfiguration().wandItem)) {
return;
}
}
- if (!PlotSquared.get().getEventDispatcher()
+ if (!this.eventDispatcher
.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) {
event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY);
@@ -2193,7 +2216,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Block block = event.getBlock();
World world = block.getWorld();
String worldName = world.getName();
- if (!PlotSquared.get().hasPlotArea(worldName)) {
+ if (!this.plotAreaManager.hasPlotArea(worldName)) {
return;
}
Location location = BukkitUtil.getLocation(block.getLocation());
@@ -2220,7 +2243,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
} else if (event.getTo() == Material.AIR) {
event.getEntity()
- .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
+ .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
}
}
@@ -2396,7 +2419,7 @@ public class PlayerEvents extends PlotListener implements Listener {
TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
pp.unregister();
- PlotListener.logout(pp.getUUID());
+ this.logout(pp.getUUID());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -2463,7 +2486,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
entity
- .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.get().IMP, plot));
+ .setMetadata("plot", new FixedMetadataValue((Plugin) PlotSquared.platform(), plot));
}
}
@@ -2477,7 +2500,6 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Player p = event.getPlayer();
if (p == null) {
- PlotSquared.debug("PlotSquared does not support HangingPlaceEvent for non-players.");
event.setCancelled(true);
return;
}
@@ -2718,7 +2740,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onPotionSplash(PotionSplashEvent event) {
ThrownPotion damager = event.getPotion();
Location location = BukkitUtil.getLocation(damager);
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
int count = 0;
@@ -2748,7 +2770,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
Location location = BukkitUtil.getLocation(damager);
- if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
+ if (!this.plotAreaManager.hasPlotArea(location.getWorldName())) {
return;
}
Entity victim = event.getEntity();
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java
index a5a5ff2f8..a5885d733 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java
@@ -37,7 +37,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.ChunkLoadEvent;
-import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -50,7 +50,7 @@ public class SingleWorldListener implements Listener {
private Method methodGetHandleChunk;
private Field mustSave;
- public SingleWorldListener(Plugin plugin) throws Exception {
+ public SingleWorldListener(JavaPlugin plugin) throws Exception {
ReflectionUtils.RefClass classChunk = getRefClass("{nms}.Chunk");
ReflectionUtils.RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle").getRealMethod();
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java
index 59e1fb2ec..dbd0e9dba 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/WorldEvents.java
@@ -25,6 +25,7 @@
*/
package com.plotsquared.bukkit.listener;
+import com.google.inject.Inject;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.generator.GeneratorWrapper;
@@ -36,17 +37,23 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldInitEvent;
import org.bukkit.generator.ChunkGenerator;
+import javax.annotation.Nonnull;
@SuppressWarnings("unused")
public class WorldEvents implements Listener {
+ private final PlotAreaManager plotAreaManager;
+
+ @Inject public WorldEvents(@Nonnull final PlotAreaManager plotAreaManager) {
+ this.plotAreaManager = plotAreaManager;
+ }
+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWorldInit(WorldInitEvent event) {
World world = event.getWorld();
String name = world.getName();
- PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
- if (manager instanceof SinglePlotAreaManager) {
- SinglePlotAreaManager single = (SinglePlotAreaManager) manager;
+ if (this.plotAreaManager instanceof SinglePlotAreaManager) {
+ final SinglePlotAreaManager single = (SinglePlotAreaManager) this.plotAreaManager;
if (single.isWorld(name)) {
world.setKeepSpawnInMemory(false);
return;
@@ -56,7 +63,7 @@ public class WorldEvents implements Listener {
if (gen instanceof GeneratorWrapper) {
PlotSquared.get().loadWorld(name, (GeneratorWrapper>) gen);
} else {
- PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen));
+ PlotSquared.get().loadWorld(name, new BukkitPlotGenerator(name, gen, this.plotAreaManager));
}
}
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java
index 4646868a1..8a8dd891e 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java
@@ -25,14 +25,15 @@
*/
package com.plotsquared.bukkit.managers;
+import com.google.inject.Singleton;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.util.PlatformWorldManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
@@ -44,13 +45,13 @@ import java.util.List;
* Default Bukkit world manager. It will handle world creation by
* registering the generator in bukkit.yml
*/
-public class BukkitWorldManager implements PlatformWorldManager {
+@Singleton public class BukkitWorldManager implements PlatformWorldManager {
@Override public void initialize() {
}
@Override @Nullable
- public World handleWorldCreation(@NotNull String worldName, @Nullable String generator) {
+ public World handleWorldCreation(@Nonnull String worldName, @Nullable String generator) {
this.setGenerator(worldName, generator);
final WorldCreator wc = new WorldCreator(worldName);
wc.environment(World.Environment.NORMAL);
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java
index 705a30286..9c96d596c 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/HyperverseWorldManager.java
@@ -25,9 +25,10 @@
*/
package com.plotsquared.bukkit.managers;
+import com.google.inject.Singleton;
import org.bukkit.World;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import se.hyperver.hyperverse.Hyperverse;
import se.hyperver.hyperverse.world.WorldConfiguration;
import se.hyperver.hyperverse.world.WorldConfigurationBuilder;
@@ -38,10 +39,10 @@ import se.hyperver.hyperverse.world.WorldType;
* Hyperverse specific manager that creates worlds
* using Hyperverse's API
*/
-public class HyperverseWorldManager extends BukkitWorldManager {
+@Singleton public class HyperverseWorldManager extends BukkitWorldManager {
@Override @Nullable
- public World handleWorldCreation(@NotNull String worldName, @Nullable String generator) {
+ public World handleWorldCreation(@Nonnull String worldName, @Nullable String generator) {
// First let Bukkit register the world
this.setGenerator(worldName, generator);
// Create the world
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java
index e8cb4cf1e..105b8c9c0 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/MultiverseWorldManager.java
@@ -25,19 +25,20 @@
*/
package com.plotsquared.bukkit.managers;
+import com.google.inject.Singleton;
import org.bukkit.Bukkit;
import org.bukkit.World;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* Multiverse specific manager that informs Multiverse of
* world creation by executing a console command
*/
-public class MultiverseWorldManager extends BukkitWorldManager {
+@Singleton public class MultiverseWorldManager extends BukkitWorldManager {
@Override @Nullable
- public World handleWorldCreation(@NotNull final String worldName, @Nullable final String generator) {
+ public World handleWorldCreation(@Nonnull final String worldName, @Nullable final String generator) {
// First let Bukkit register the world
this.setGenerator(worldName, generator);
// Then we send the console command
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
index c61b29f37..69a11523f 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
@@ -64,7 +64,7 @@ public class Placeholders extends PlaceholderExpansion {
}
@Override public String onPlaceholderRequest(Player p, String identifier) {
- final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
+ final PlotPlayer pl = PlotSquared.platform().getPlayerManager().getPlayerIfExists(p.getUniqueId());
if (pl == null) {
return "";
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java
index 8f46d3636..3aa5d12c3 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitOfflinePlayer.java
@@ -27,7 +27,7 @@ package com.plotsquared.bukkit.player;
import com.plotsquared.core.player.OfflinePlotPlayer;
import org.bukkit.OfflinePlayer;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.UUID;
@@ -45,7 +45,7 @@ public class BukkitOfflinePlayer implements OfflinePlotPlayer {
this.player = player;
}
- @NotNull @Override public UUID getUUID() {
+ @Nonnull @Override public UUID getUUID() {
return this.player.getUniqueId();
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
index 05db91ff2..110a0efed 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
@@ -34,7 +34,9 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotWeather;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor;
@@ -51,7 +53,8 @@ import org.bukkit.event.EventException;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.RegisteredListener;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Set;
@@ -66,27 +69,36 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
public class BukkitPlayer extends PlotPlayer {
private static boolean CHECK_EFFECTIVE = true;
+
+ private final EconHandler econHandler;
public final Player player;
private boolean offline;
private String name;
+
/**
*
Please do not use this method. Instead use
* BukkitUtil.getPlayer(Player), as it caches player objects.
*
* @param player Bukkit player instance
*/
- public BukkitPlayer(@NotNull final Player player) {
- this(player, false);
+ public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
+ @Nonnull final Player player, @Nullable final EconHandler econHandler) {
+ this(plotAreaManager, eventDispatcher, player, false, econHandler);
}
- public BukkitPlayer(@NotNull final Player player, final boolean offline) {
- this(player, offline, true);
+ public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher,
+ @Nonnull final Player player, final boolean offline, @Nullable final EconHandler econHandler) {
+ this(plotAreaManager, eventDispatcher, player, offline, true, econHandler);
}
- public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) {
+ public BukkitPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final
+ EventDispatcher eventDispatcher, @Nonnull final Player player, final boolean offline,
+ final boolean realPlayer, @Nullable final EconHandler econHandler) {
+ super(plotAreaManager, eventDispatcher, econHandler);
this.player = player;
this.offline = offline;
+ this.econHandler = econHandler;
if (realPlayer) {
super.populatePersistentMetaMap();
}
@@ -100,12 +112,12 @@ public class BukkitPlayer extends PlotPlayer {
return this.player;
}
- @NotNull @Override public Location getLocation() {
+ @Nonnull @Override public Location getLocation() {
final Location location = super.getLocation();
return location == null ? BukkitUtil.getLocation(this.player) : location;
}
- @NotNull @Override public UUID getUUID() {
+ @Nonnull @Override public UUID getUUID() {
if (Settings.UUID.OFFLINE) {
if (Settings.UUID.FORCE_LOWERCASE) {
return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
@@ -122,7 +134,7 @@ public class BukkitPlayer extends PlotPlayer {
return this.player.getLastPlayed();
}
- @Override public boolean canTeleport(@NotNull final Location location) {
+ @Override public boolean canTeleport(@Nonnull final Location location) {
final org.bukkit.Location to = BukkitUtil.getLocation(location);
final org.bukkit.Location from = player.getLocation();
PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);
@@ -135,10 +147,10 @@ public class BukkitPlayer extends PlotPlayer {
return true;
}
- private void callEvent(@NotNull final Event event) {
+ private void callEvent(@Nonnull final Event event) {
final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners();
for (final RegisteredListener listener : listeners) {
- if (listener.getPlugin().getName().equals(PlotSquared.imp().getPluginName())) {
+ if (listener.getPlugin().getName().equals(PlotSquared.platform().getPluginName())) {
continue;
}
try {
@@ -150,8 +162,8 @@ public class BukkitPlayer extends PlotPlayer {
}
@Override public boolean hasPermission(@NotNull final String permission) {
- if (this.offline && EconHandler.getEconHandler() != null) {
- return EconHandler.getEconHandler().hasPermission(getName(), permission);
+ if (this.offline && this.econHandler != null) {
+ return this.econHandler.hasPermission(getName(), permission);
}
return this.player.hasPermission(permission);
}
@@ -221,12 +233,12 @@ public class BukkitPlayer extends PlotPlayer {
}
@Override
- public void teleport(@NotNull final Location location, @NotNull final TeleportCause cause) {
+ public void teleport(@Nonnull final Location location, @Nonnull final TeleportCause cause) {
if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) {
return;
}
final org.bukkit.Location bukkitLocation =
- new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5,
+ new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX() + 0.5,
location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch());
PaperLib.teleportAsync(player, bukkitLocation, getTeleportCause(cause));
}
@@ -244,7 +256,7 @@ public class BukkitPlayer extends PlotPlayer {
@Override public void setCompassTarget(Location location) {
this.player.setCompassTarget(
- new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(),
+ new org.bukkit.Location(BukkitUtil.getWorld(location.getWorldName()), location.getX(),
location.getY(), location.getZ()));
}
@@ -252,7 +264,7 @@ public class BukkitPlayer extends PlotPlayer {
return BukkitUtil.getLocationFull(this.player);
}
- @Override public void setWeather(@NotNull final PlotWeather weather) {
+ @Override public void setWeather(@Nonnull final PlotWeather weather) {
switch (weather) {
case CLEAR:
this.player.setPlayerWeather(WeatherType.CLEAR);
@@ -267,7 +279,7 @@ public class BukkitPlayer extends PlotPlayer {
}
}
- @NotNull @Override public com.sk89q.worldedit.world.gamemode.GameMode getGameMode() {
+ @Override public com.sk89q.worldedit.world.gamemode.GameMode getGameMode() {
switch (this.player.getGameMode()) {
case ADVENTURE:
return ADVENTURE;
@@ -282,7 +294,7 @@ public class BukkitPlayer extends PlotPlayer {
}
@Override
- public void setGameMode(@NotNull final com.sk89q.worldedit.world.gamemode.GameMode gameMode) {
+ public void setGameMode(final com.sk89q.worldedit.world.gamemode.GameMode gameMode) {
if (ADVENTURE.equals(gameMode)) {
this.player.setGameMode(GameMode.ADVENTURE);
} else if (CREATIVE.equals(gameMode)) {
@@ -310,7 +322,7 @@ public class BukkitPlayer extends PlotPlayer {
this.player.setAllowFlight(fly);
}
- @Override public void playMusic(@NotNull final Location location, @NotNull final ItemType id) {
+ @Override public void playMusic(@Nonnull final Location location, @Nonnull final ItemType id) {
if (id == ItemTypes.AIR) {
// Let's just stop all the discs because why not?
for (final Sound sound : Arrays.stream(Sound.values())
@@ -344,7 +356,7 @@ public class BukkitPlayer extends PlotPlayer {
}
- public PlayerTeleportEvent.TeleportCause getTeleportCause(@NotNull final TeleportCause cause) {
+ public PlayerTeleportEvent.TeleportCause getTeleportCause(@Nonnull final TeleportCause cause) {
switch (cause) {
case COMMAND:
return PlayerTeleportEvent.TeleportCause.COMMAND;
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
index a15718a5f..7238709e3 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
@@ -25,33 +25,51 @@
*/
package com.plotsquared.bukkit.player;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.plotsquared.core.plot.world.PlotAreaManager;
+import com.plotsquared.core.util.EconHandler;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.PlayerManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
import java.util.UUID;
/**
* Player manager providing {@link BukkitPlayer Bukkit players}
*/
-public class BukkitPlayerManager extends PlayerManager {
+@Singleton public class BukkitPlayerManager extends PlayerManager {
- @NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) {
+ private final PlotAreaManager plotAreaManager;
+ private final EventDispatcher eventDispatcher;
+ private final EconHandler econHandler;
+
+ @Inject public BukkitPlayerManager(@Nonnull final PlotAreaManager plotAreaManager,
+ @Nonnull final EventDispatcher eventDispatcher,
+ @Nullable final EconHandler econHandler) {
+ this.plotAreaManager = plotAreaManager;
+ this.eventDispatcher = eventDispatcher;
+ this.econHandler = econHandler;
+ }
+
+ @Nonnull @Override public BukkitPlayer getPlayer(@Nonnull final Player object) {
try {
return getPlayer(object.getUniqueId());
} catch (final NoSuchPlayerException exception) {
- return new BukkitPlayer(object, object.isOnline(), false);
+ return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object,
+ object.isOnline(), false, this.econHandler);
}
}
- @Override @NotNull public BukkitPlayer createPlayer(@NotNull final UUID uuid) {
+ @Override @Nonnull public BukkitPlayer createPlayer(@Nonnull final UUID uuid) {
final Player player = Bukkit.getPlayer(uuid);
if (player == null || !player.isOnline()) {
throw new NoSuchPlayerException(uuid);
}
- return new BukkitPlayer(player);
+ return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player, this.econHandler);
}
@Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
@@ -61,7 +79,7 @@ public class BukkitPlayerManager extends PlayerManager {
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
}
- @NotNull @Override public BukkitOfflinePlayer getOfflinePlayer(@NotNull final String username) {
+ @Nonnull @Override public BukkitOfflinePlayer getOfflinePlayer(@Nonnull final String username) {
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java
index c8d6d929f..fa6ccd69d 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java
@@ -27,11 +27,9 @@ package com.plotsquared.bukkit.queue;
import com.plotsquared.bukkit.schematic.StateWrapper;
import com.plotsquared.bukkit.util.BukkitBlockUtil;
-import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.queue.BasicLocalBlockQueue;
import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MainUtil;
-import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
@@ -42,7 +40,6 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import io.papermc.lib.PaperLib;
-import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
@@ -51,6 +48,7 @@ import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.Container;
import org.bukkit.block.data.BlockData;
+import javax.annotation.Nonnull;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
@@ -85,8 +83,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
World worldObj = Bukkit.getWorld(getWorld());
if (worldObj != null) {
worldObj.refreshChunk(x, z);
- } else {
- PlotSquared.debug("Error Refreshing Chunk");
}
}
@@ -109,8 +105,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
world.regenerate(region, editSession);
}
}
- } else {
- PlotSquared.debug("Error Regenerating Chunk");
}
}
@@ -201,12 +195,12 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
return chunk;
}
- private void setMaterial(@NonNull final BlockState plotBlock, @NonNull final Block block) {
+ private void setMaterial(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
Material material = BukkitAdapter.adapt(plotBlock.getBlockType());
block.setType(material, false);
}
- private boolean equals(@NonNull final BlockState plotBlock, @NonNull final Block block) {
+ private boolean equals(@Nonnull final BlockState plotBlock, @Nonnull final Block block) {
return plotBlock.equals(BukkitBlockUtil.get(block));
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java
new file mode 100644
index 000000000..cc5c1f72f
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/ChunkCoordinator.java
@@ -0,0 +1,326 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.queue;
+
+import com.google.common.base.Preconditions;
+import com.plotsquared.bukkit.BukkitMain;
+import com.sk89q.worldedit.math.BlockVector2;
+import io.papermc.lib.PaperLib;
+import org.bukkit.Chunk;
+import org.bukkit.World;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
+
+/**
+ * Utility that allows for the loading and coordination of chunk actions
+ *
+ * The coordinator takes in collection of chunk coordinates, loads them
+ * and allows the caller to specify a sink for the loaded chunks. The
+ * coordinator will prevent the chunks from being unloaded until the sink
+ * has fully consumed the chunk
+ *
extends ILogger {
/**
* Logs a message to console.
@@ -93,20 +96,6 @@ public interface IPlotMain
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";
}
@@ -215,6 +204,13 @@ public interface IPlotMain
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.
*
@@ -251,49 +241,121 @@ public interface IPlotMain
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();
+ @Nonnull default IndependentPlotGenerator getDefaultGenerator() {
+ return getInjector().getInstance(Key.get(IndependentPlotGenerator.class, DefaultGenerator.class));
+ }
List, Boolean>> getPluginIds();
- Actor getConsole();
-
/**
* Get the backup manager instance
*
* @return Backup manager
*/
- @NotNull BackupManager getBackupManager();
+ @Nonnull default BackupManager getBackupManager() {
+ return getInjector().getInstance(BackupManager.class);
+ }
/**
* Get the platform specific world manager
*
* @return World manager
*/
- @NotNull PlatformWorldManager> getWorldManager();
+ @Nonnull default PlatformWorldManager> getWorldManager() {
+ return getInjector().getInstance(PlatformWorldManager.class);
+ }
/**
* Get the player manager implementation for the platform
*
* @return Player manager
*/
- @NotNull PlayerManager extends PlotPlayer
, ? extends P> getPlayerManager() {
+ return getInjector().getInstance(PlayerManager.class);
+ }
+
+ /**
+ * Get a platform world wrapper from a world name
+ *
+ * @param worldName World name
+ * @return Platform world wrapper
+ */
+ @Nonnull World> getPlatformWorld(@Nonnull final String worldName);
+
+ /**
+ * Get the {@link com.google.inject.Injector} instance used by PlotSquared
+ *
+ * @return Injector instance
+ */
+ @Nonnull Injector getInjector();
+
+ /**
+ * Get the world utility implementation
+ *
+ * @return World utility
+ */
+ @Nonnull default WorldUtil getWorldUtil() {
+ return getInjector().getInstance(WorldUtil.class);
+ }
+
+ /**
+ * Get the global block queue implementation
+ *
+ * @return Global block queue implementation
+ */
+ @Nonnull default GlobalBlockQueue getGlobalBlockQueue() {
+ return getInjector().getInstance(GlobalBlockQueue.class);
+ }
+
+ /**
+ * Get the {@link HybridUtils} implementation for the platform
+ *
+ * @return Hybrid utils
+ */
+ @Nonnull default HybridUtils getHybridUtils() {
+ return getInjector().getInstance(HybridUtils.class);
+ }
+
+ /**
+ * Get the {@link SetupUtils}Â implementation for the platform
+ *
+ * @return Setup utils
+ */
+ @Nonnull default SetupUtils getSetupUtils() {
+ return getInjector().getInstance(SetupUtils.class);
+ }
+
+ /**
+ * Get the {@link EconHandler} implementation for the platform
+ * *
+ * @return Econ handler
+ */
+ @Nullable default EconHandler getEconHandler() {
+ return getInjector().getInstance(EconHandler.class);
+ }
+
+ /**
+ * Get the {@link RegionManager} implementation for the platform
+ *
+ * @return Region manager
+ */
+ @Nonnull default RegionManager getRegionManager() {
+ return getInjector().getInstance(RegionManager.class);
+ }
+
+ /**
+ * Get the {@link ChunkManager} implementation for the platform
+ *
+ * @return Region manager
+ */
+ @Nonnull default ChunkManager getChunkManager() {
+ return getInjector().getInstance(ChunkManager.class);
+ }
/**
* Get the platform specific console {@link Audience}
diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
index 804528a4d..8c71c16e7 100644
--- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java
+++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
@@ -48,23 +48,19 @@ import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.HybridPlotWorld;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.generator.IndependentPlotGenerator;
-import com.plotsquared.core.listener.WESubscriber;
+import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
+import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location;
-import com.plotsquared.core.player.ConsolePlayer;
-import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotCluster;
-import com.plotsquared.core.plot.PlotFilter;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.PlotManager;
-import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.expiration.ExpiryTask;
-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;
@@ -72,29 +68,20 @@ import com.plotsquared.core.queue.GlobalBlockQueue;
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;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector2;
-import com.sk89q.worldedit.regions.CuboidRegion;
import lombok.Getter;
-import lombok.NonNull;
-import lombok.Setter;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -120,30 +107,29 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
-import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* An implementation of the core, with a static getter for easy access.
*/
-@SuppressWarnings({"unused", "WeakerAccess"})
+@SuppressWarnings({"WeakerAccess"})
public class PlotSquared {
+
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotSquared.class.getSimpleName());
private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet());
private static PlotSquared instance;
+
// Implementation
- public final IPlotMain> IMP;
+ private final PlotPlatform> platform;
// Current thread
private final Thread thread;
// UUID pipelines
@@ -152,14 +138,14 @@ public class PlotSquared {
@Getter private final UUIDPipeline backgroundUUIDPipeline =
new UUIDPipeline(Executors.newSingleThreadExecutor());
// WorldEdit instance
- public WorldEdit worldedit;
- public File configFile;
- public File worldsFile;
- public File translationFile;
- public YamlConfiguration worlds;
- public YamlConfiguration storage;
+ @Getter private WorldEdit worldedit;
+ @Getter private File configFile;
+ @Getter private File worldsFile;
+ public File translationFile; // TODO: REMOVE
+ public YamlConfiguration style; // TODO: REMOVE
+ @Getter private YamlConfiguration worldConfiguration;
// Temporary hold the plots/clusters before the worlds load
- public HashMap> clusters_tmp;
+ private HashMap> clustersTmp;
public HashMap> plots_tmp;
private YamlConfiguration config;
// Localization
@@ -171,24 +157,23 @@ public class PlotSquared {
// Files and configuration
@Getter private File jarFile = null; // This file
private File storageFile;
- @Getter private PlotAreaManager plotAreaManager;
@Getter private EventDispatcher eventDispatcher;
+ @Getter private PlotListener plotListener;
/**
* Initialize PlotSquared with the desired Implementation class.
*
- * @param iPlotMain Implementation of {@link IPlotMain} used
+ * @param iPlotMain Implementation of {@link PlotPlatform} used
* @param platform The platform being used
*/
- public PlotSquared(final IPlotMain iPlotMain, final String platform) {
+ public PlotSquared(final PlotPlatform> iPlotMain, final String platform) {
if (instance != null) {
throw new IllegalStateException("Cannot re-initialize the PlotSquared singleton");
}
instance = this;
this.thread = Thread.currentThread();
- this.IMP = iPlotMain;
- this.logger = iPlotMain;
+ this.platform = iPlotMain;
Settings.PLATFORM = platform;
//
@@ -197,24 +182,20 @@ public class PlotSquared {
ConfigurationSerialization.registerClass(BlockBucket.class, "BlockBucket");
try {
- new ReflectionUtils(this.IMP.getNMSPackage());
+ new ReflectionUtils(this.platform.getNMSPackage());
try {
- URL url = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
+ URL logurl = PlotSquared.class.getProtectionDomain().getCodeSource().getLocation();
this.jarFile = new File(
- new URL(url.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
+ new URL(logurl.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file"))
.toURI().getPath());
} catch (MalformedURLException | URISyntaxException | SecurityException e) {
e.printStackTrace();
- this.jarFile = new File(this.IMP.getDirectory().getParentFile(), "PlotSquared.jar");
+ this.jarFile = new File(this.platform.getDirectory().getParentFile(), "PlotSquared.jar");
if (!this.jarFile.exists()) {
- this.jarFile = new File(this.IMP.getDirectory().getParentFile(),
+ this.jarFile = new File(this.platform.getDirectory().getParentFile(),
"PlotSquared-" + platform + ".jar");
}
}
- TaskManager.IMP = this.IMP.getTaskManager();
-
- // World Util. Has to be done before config files are loaded
- WorldUtil.IMP = this.IMP.initWorldUtil();
if (!setupConfigs()) {
return;
@@ -230,129 +211,12 @@ public class PlotSquared {
}
this.captionMap = captionMap;
- // Setup plotAreaManager
- if (Settings.Enabled_Components.WORLDS) {
- this.plotAreaManager = new SinglePlotAreaManager();
- } else {
- this.plotAreaManager = new DefaultPlotAreaManager();
- }
+ this.worldedit = WorldEdit.getInstance();
- // Database
- if (Settings.Enabled_Components.DATABASE) {
- setupDatabase();
- }
-
- // Check if we need to convert old flag values, etc
- if (!getConfigurationVersion().equalsIgnoreCase("v5")) {
- // Perform upgrade
- if (DBFunc.dbManager.convertFlags()) {
- log(Captions.PREFIX.getTranslated() + "Flags were converted successfully!");
- // Update the config version
- setConfigurationVersion("v5");
- }
- }
-
- // Comments
- CommentManager.registerDefaultInboxes();
- // Kill entities
- if (Settings.Enabled_Components.KILL_ROAD_MOBS
- || Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
- this.IMP.runEntityTask();
- }
- if (Settings.Enabled_Components.EVENTS) {
- this.IMP.registerPlayerEvents();
- }
- // Required
- this.IMP.registerWorldEvents();
- if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
- this.IMP.registerChunkProcessor();
- }
- startExpiryTasks();
// Create Event utility class
- eventDispatcher = new EventDispatcher();
- // create Hybrid utility class
- HybridUtils.manager = this.IMP.initHybridUtils();
- // Inventory utility class
- InventoryUtil.manager = this.IMP.initInventoryUtil();
- // create setup util class
- SetupUtils.manager = this.IMP.initSetupUtils();
- // Set block
- GlobalBlockQueue.IMP =
- new GlobalBlockQueue(IMP.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME);
- GlobalBlockQueue.IMP.runTask();
- // Set chunk
- ChunkManager.manager = this.IMP.initChunkManager();
- RegionManager.manager = this.IMP.initRegionManager();
- // Schematic handler
- SchematicHandler.manager = this.IMP.initSchematicHandler();
- // Chat
- ChatManager.manager = this.IMP.initChatManager();
- // Commands
- if (Settings.Enabled_Components.COMMANDS) {
- this.IMP.registerCommands();
- }
- // WorldEdit
- if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
- try {
- if (this.IMP.initWorldEdit()) {
- PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + IMP.getPluginName()
- + " hooked into WorldEdit.");
- this.worldedit = WorldEdit.getInstance();
- WorldEdit.getInstance().getEventBus().register(new WESubscriber());
- 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");
- }
- }
- // 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.worlds.getConfigurationSection("worlds");
- if (section != null) {
- for (String world : section.getKeys(false)) {
- if (world.equals("CheckingPlotSquaredGenerator")) {
- continue;
- }
- if (WorldUtil.IMP.isWorld(world)) {
- this.IMP.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 - " + IMP.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.IMP.setGenerator(world);
- }
- }
- }, 1);
- }
+ this.eventDispatcher = new EventDispatcher(this.worldedit);
+ // Create plot listener
+ this.plotListener = new PlotListener(this.eventDispatcher);
// Copy files
copyFile("addplots.js", Settings.Paths.SCRIPTS);
@@ -377,10 +241,15 @@ public class PlotSquared {
} catch (Throwable e) {
e.printStackTrace();
}
+ }
- PlotSquared.log(Captions.PREFIX + CaptionUtility
- .format(ConsolePlayer.getConsole(), Captions.ENABLED.getTranslated(),
- IMP.getPluginName()));
+ /**
+ * Get the platform specific {@link PlotAreaManager} instance
+ *
+ * @return Plot area manager
+ */
+ @Nonnull public PlotAreaManager getPlotAreaManager() {
+ return this.platform.getInjector().getInstance(PlotAreaManager.class);
}
/**
@@ -392,54 +261,24 @@ public class PlotSquared {
return PlotSquared.instance;
}
- @NotNull public static IPlotMain> imp() {
- if (instance != null && instance.IMP != null) {
- return instance.IMP;
- }
- throw new IllegalStateException("Plot main implementation is missing");
- }
-
/**
- * Log a message to the IPlotMain logger.
+ * Get the platform specific implementation of PlotSquared
*
- * @param message Message to log
- * @see IPlotMain#log(String)
+ * @return Platform implementation
*/
- public static void log(Object message) {
- if (message == null || (message instanceof Caption ?
- ((Caption) message).getTranslated().isEmpty() :
- message.toString().isEmpty())) {
- return;
- }
- if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) {
- System.out.printf("[P2][Info] %s\n", StringMan.getString(message));
- } else {
- PlotSquared.get().getLogger().log(StringMan.getString(message));
+ @Nonnull public static PlotPlatform> platform() {
+ if (instance != null && instance.platform != null) {
+ return instance.platform;
}
+ throw new IllegalStateException("Plot platform implementation is missing");
}
- /**
- * Log a message to the IPlotMain logger.
- *
- * @param message Message to log
- * @see IPlotMain#log(String)
- */
- public static void debug(@Nullable Object message) {
- if (Settings.DEBUG) {
- if (PlotSquared.get() == null || PlotSquared.get().getLogger() == null) {
- System.out.printf("[P2][Debug] %s\n", StringMan.getString(message));
- } else {
- PlotSquared.get().getLogger().log(StringMan.getString(message));
- }
- }
- }
-
- private void startExpiryTasks() {
+ public void startExpiryTasks() {
if (Settings.Enabled_Components.PLOT_EXPIRY) {
- ExpireManager.IMP = new ExpireManager();
+ ExpireManager.IMP = new ExpireManager(this.eventDispatcher);
ExpireManager.IMP.runAutomatedTask();
for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) {
- ExpiryTask task = new ExpiryTask(settings);
+ ExpiryTask task = new ExpiryTask(settings, this.getPlotAreaManager());
ExpireManager.IMP.addTask(task);
}
}
@@ -481,15 +320,6 @@ public class PlotSquared {
return Settings.PLATFORM;
}
- public PlotManager getPlotManager(Plot plot) {
- return plot.getArea().getPlotManager();
- }
-
- public PlotManager getPlotManager(Location location) {
- PlotArea pa = getPlotAreaAbs(location);
- return pa != null ? pa.getPlotManager() : null;
- }
-
/**
* Add a global reference to a plot world.
*
@@ -519,10 +349,10 @@ public class PlotSquared {
}
}
Set clusters;
- if (clusters_tmp == null || (clusters = clusters_tmp.remove(plotArea.toString())) == null) {
+ if (clustersTmp == null || (clusters = clustersTmp.remove(plotArea.toString())) == null) {
if (plotArea.getType() == PlotAreaType.PARTIAL) {
- clusters = this.clusters_tmp != null ?
- this.clusters_tmp.get(plotArea.getWorldName()) :
+ clusters = this.clustersTmp != null ?
+ this.clustersTmp.get(plotArea.getWorldName()) :
null;
if (clusters != null) {
Iterator iterator = clusters.iterator();
@@ -540,13 +370,13 @@ public class PlotSquared {
cluster.setArea(plotArea);
}
}
- plotAreaManager.addPlotArea(plotArea);
+ getPlotAreaManager().addPlotArea(plotArea);
plotArea.setupBorder();
if (!Settings.Enabled_Components.PERSISTENT_ROAD_REGEN) {
return;
}
File file = new File(
- this.IMP.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
+ this.platform.getDirectory() + File.separator + "persistent_regen_data_" + plotArea.getId()
+ "_" + plotArea.getWorldName());
if (!file.exists()) {
return;
@@ -561,21 +391,16 @@ public class PlotSquared {
regionInts.forEach(l -> regions.add(BlockVector2.at(l[0], l[1])));
chunkInts.forEach(l -> chunks.add(BlockVector2.at(l[0], l[1])));
int height = (int) list.get(2);
- PlotSquared.log(
- Captions.PREFIX + "Incomplete road regeneration found. Restarting in world "
- + plotArea.getWorldName() + " with height " + height + ".");
- PlotSquared.debug(" Regions: " + regions.size());
- PlotSquared.debug(" Chunks: " + chunks.size());
+ logger.info("[P2] Incomplete road regeneration found. Restarting in world {} with height {}", plotArea.getWorldName(), height);
+ logger.info("[P2] - Regions: {}", regions.size());
+ logger.info("[P2] - 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();
+ logger.error("[P2] Error restarting road regeneration", e);
} finally {
if (!file.delete()) {
- PlotSquared.log(
- Captions.PREFIX + "Error deleting persistent_regen_data_" + plotArea.getId()
- + ". Please manually delete this file.");
+ logger.error("[P2] Error deleting persistent_regen_data_{}. Please delete this file manually", plotArea.getId());
}
}
});
@@ -587,12 +412,12 @@ public class PlotSquared {
* @param area the {@code PlotArea} to remove
*/
public void removePlotArea(PlotArea area) {
- plotAreaManager.removePlotArea(area);
+ getPlotAreaManager().removePlotArea(area);
setPlotsTmp(area);
}
- public void removePlotAreas(String world) {
- for (PlotArea area : getPlotAreas(world)) {
+ public void removePlotAreas(@Nonnull final String world) {
+ for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
if (area.getWorldName().equals(world)) {
removePlotArea(area);
}
@@ -608,15 +433,15 @@ public class PlotSquared {
for (Plot plot : area.getPlots()) {
map.put(plot.getId(), plot);
}
- if (this.clusters_tmp == null) {
- this.clusters_tmp = new HashMap<>();
+ if (this.clustersTmp == null) {
+ this.clustersTmp = new HashMap<>();
}
- this.clusters_tmp.put(area.toString(), area.getClusters());
+ this.clustersTmp.put(area.toString(), area.getClusters());
}
- public Set getClusters(String world) {
- Set set = new HashSet<>();
- for (PlotArea area : getPlotAreas(world)) {
+ public Set getClusters(@Nonnull final String world) {
+ final Set set = new HashSet<>();
+ for (final PlotArea area : this.getPlotAreaManager().getPlotAreasSet(world)) {
set.addAll(area.getClusters());
}
return Collections.unmodifiableSet(set);
@@ -823,13 +648,13 @@ public class PlotSquared {
// group by world
// sort each
HashMap> map = new HashMap<>();
- int totalSize = getPlotCount();
+ int totalSize = Arrays.stream(this.getPlotAreaManager().getAllPlotAreas()).mapToInt(PlotArea::getPlotCount).sum();
if (plots.size() == totalSize) {
- for (PlotArea area : plotAreaManager.getAllPlotAreas()) {
+ for (PlotArea area : getPlotAreaManager().getAllPlotAreas()) {
map.put(area, area.getPlots());
}
} else {
- for (PlotArea area : plotAreaManager.getAllPlotAreas()) {
+ for (PlotArea area : getPlotAreaManager().getAllPlotAreas()) {
map.put(area, new ArrayList<>(0));
}
Collection lastList = null;
@@ -844,7 +669,7 @@ public class PlotSquared {
}
}
}
- List areas = Arrays.asList(plotAreaManager.getAllPlotAreas());
+ List areas = Arrays.asList(getPlotAreaManager().getAllPlotAreas());
areas.sort((a, b) -> {
if (priorityArea != null) {
if (a.equals(priorityArea)) {
@@ -877,199 +702,25 @@ public class PlotSquared {
return toReturn;
}
- /**
- * A more generic way to filter plots - make your own method
- * if you need complex filters.
- *
- * @param filters the filter
- * @return a filtered set of plots
- * @deprecated Use {@link PlotQuery}
- */
- @Deprecated public Set getPlots(final PlotFilter... filters) {
- final List areas = new LinkedList<>();
- for (final PlotArea plotArea : this.getPlotAreas()) {
- for (final PlotFilter filter : filters) {
- if (filter.allowsArea(plotArea)) {
- areas.add(plotArea);
- }
- }
- }
- return PlotQuery.newQuery().inAreas(areas).thatPasses(plot -> {
- for (final PlotFilter filter : filters) {
- if (!filter.allowsPlot(plot)) {
- return false;
- }
- }
- return true;
- }).asSet();
- }
-
- /**
- * Gets all the plots across all plotworlds in one {@code Set}.
- *
- * @return all the plots on the server loaded by this plugin
- */
- public Set getPlots() {
- int size = getPlotCount();
- final Set result = new HashSet<>(size);
- forEachPlotArea(value -> result.addAll(value.getPlots()));
- return result;
- }
-
- public void setPlots(HashMap> plots) {
+ public void setPlots(@Nonnull final Map> plots) {
if (this.plots_tmp == null) {
this.plots_tmp = new HashMap<>();
}
- for (Entry> entry : plots.entrySet()) {
- String world = entry.getKey();
- PlotArea area = getPlotArea(world, null);
- if (area == null) {
- HashMap map =
- this.plots_tmp.computeIfAbsent(world, k -> new HashMap<>());
+ for (final Entry> entry : plots.entrySet()) {
+ final String world = entry.getKey();
+ final PlotArea plotArea = this.getPlotAreaManager().getPlotArea(world, null);
+ if (plotArea == null) {
+ Map map = this.plots_tmp.computeIfAbsent(world, k -> new HashMap<>());
map.putAll(entry.getValue());
} else {
for (Plot plot : entry.getValue().values()) {
- plot.setArea(area);
- area.addPlot(plot);
+ plot.setArea(plotArea);
+ plotArea.addPlot(plot);
}
}
}
}
- /**
- * Gets all the plots owned by a player name.
- *
- * @param world the world
- * @param player the plot owner
- * @return Set of Plot
- */
- public Set getPlots(String world, String player) {
- final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
- return getPlots(world, uuid);
- }
-
- /**
- * Gets all the plots owned by a player name.
- *
- * @param area the PlotArea
- * @param player the plot owner
- * @return Set of Plot
- */
- public Set getPlots(PlotArea area, String player) {
- final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
- return getPlots(area, uuid);
- }
-
- /**
- * Gets all plots by a PlotPlayer.
- *
- * @param world the world
- * @param player the plot owner
- * @return Set of plot
- */
- public Set getPlots(String world, PlotPlayer player) {
- return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet();
- }
-
- /**
- * Gets all plots by a PlotPlayer.
- *
- * @param area the PlotArea
- * @param player the plot owner
- * @return Set of plot
- */
- public Set getPlots(PlotArea area, PlotPlayer player) {
- return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet();
- }
-
- /**
- * Gets all plots by a UUID in a world.
- *
- * @param world the world
- * @param uuid the plot owner
- * @return Set of plot
- */
- public Set getPlots(String world, UUID uuid) {
- return PlotQuery.newQuery().inWorld(world).ownedBy(uuid).asSet();
- }
-
- /**
- * Gets all plots by a UUID in an area.
- *
- * @param area the {@code PlotArea}
- * @param uuid the plot owner
- * @return Set of plots
- */
- public Set getPlots(PlotArea area, UUID uuid) {
- return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet();
- }
-
- /**
- * Check if a plot world.
- *
- * @param world the world
- * @return if a plot world is registered
- * @see #getPlotAreaByString(String) to get the PlotArea object
- */
- public boolean hasPlotArea(String world) {
- return plotAreaManager.getPlotAreas(world, null).length != 0;
- }
-
- public Collection getPlots(String world) {
- return PlotQuery.newQuery().inWorld(world).asCollection();
- }
-
- /**
- * Gets the plots for a PlotPlayer.
- *
- * @param player the player to retrieve the plots for
- * @return Set of Plot
- */
- public Set getPlots(PlotPlayer player) {
- return PlotQuery.newQuery().ownedBy(player).asSet();
- }
-
- public Collection getPlots(PlotArea area) {
- return area == null ? EMPTY_SET : area.getPlots();
- }
-
- public Plot getPlot(PlotArea area, PlotId id) {
- return area == null ? null : id == null ? null : area.getPlot(id);
- }
-
- public Set getBasePlots(PlotPlayer player) {
- return getBasePlots(player.getUUID());
- }
-
- /**
- * Gets the plots for a UUID.
- *
- * @param uuid the plot owner
- * @return Set of Plot's owned by the player
- */
- public Set getPlots(final UUID uuid) {
- return PlotQuery.newQuery().ownedBy(uuid).asSet();
- }
-
- public boolean hasPlot(final UUID uuid) {
- return Arrays.stream(plotAreaManager.getAllPlotAreas())
- .anyMatch(area -> area.hasPlot(uuid));
- }
-
- public Set getBasePlots(final UUID uuid) {
- return PlotQuery.newQuery().ownedBy(uuid).whereBasePlot().asSet();
- }
-
- /**
- * Gets the plots for a UUID.
- *
- * @param uuid the UUID of the owner
- * @return Set of Plot
- */
- public Set getPlotsAbs(final UUID uuid) {
- return PlotQuery.newQuery().ownedBy(uuid).asSet();
- }
-
/**
* Unregisters a plot from local memory without calling the database.
*
@@ -1118,15 +769,15 @@ public class PlotSquared {
if (world.equals("CheckingPlotSquaredGenerator")) {
return;
}
- this.plotAreaManager.addWorld(world);
+ this.getPlotAreaManager().addWorld(world);
Set worlds;
- if (this.worlds.contains("worlds")) {
- worlds = this.worlds.getConfigurationSection("worlds").getKeys(false);
+ if (this.worldConfiguration.contains("worlds")) {
+ worlds = this.worldConfiguration.getConfigurationSection("worlds").getKeys(false);
} else {
worlds = new HashSet<>();
}
String path = "worlds." + world;
- ConfigurationSection worldSection = this.worlds.getConfigurationSection(path);
+ ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(path);
PlotAreaType type;
if (worldSection != null) {
type = MainUtil.getType(worldSection);
@@ -1134,8 +785,7 @@ public class PlotSquared {
type = PlotAreaType.NORMAL;
}
if (type == PlotAreaType.NORMAL) {
- if (plotAreaManager.getPlotAreas(world, null).length != 0) {
- debug("World possibly already loaded: " + world);
+ if (getPlotAreaManager().getPlotAreas(world, null).length != 0) {
return;
}
IndependentPlotGenerator plotGenerator;
@@ -1144,13 +794,13 @@ public class PlotSquared {
} else if (worldSection != null) {
String secondaryGeneratorName = worldSection.getString("generator.plugin");
GeneratorWrapper> secondaryGenerator =
- this.IMP.getGenerator(world, secondaryGeneratorName);
+ this.platform.getGenerator(world, secondaryGeneratorName);
if (secondaryGenerator != null && secondaryGenerator.isFull()) {
plotGenerator = secondaryGenerator.getPlotGenerator();
} else {
String primaryGeneratorName = worldSection.getString("generator.init");
GeneratorWrapper> primaryGenerator =
- this.IMP.getGenerator(world, primaryGeneratorName);
+ this.platform.getGenerator(world, primaryGeneratorName);
if (primaryGenerator != null && primaryGenerator.isFull()) {
plotGenerator = primaryGenerator.getPlotGenerator();
} else {
@@ -1163,20 +813,18 @@ public class PlotSquared {
// Conventional plot generator
PlotArea plotArea = plotGenerator.getNewPlotArea(world, null, null, null);
PlotManager plotManager = plotArea.getPlotManager();
- PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'");
- PlotSquared
- .log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + plotGenerator);
- PlotSquared.log(Captions.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName());
- PlotSquared.log(
- Captions.PREFIX + "&3 - plotAreaManager: &7" + plotManager.getClass().getName());
- if (!this.worlds.contains(path)) {
- this.worlds.createSection(path);
- worldSection = this.worlds.getConfigurationSection(path);
+ logger.info("[P2] Detected world load for '{}'", world);
+ logger.info("[P2] - generator: {}>{}", baseGenerator, plotGenerator);
+ logger.info("[P2] - plot world: {}", plotArea.getClass().getCanonicalName());
+ logger.info("[P2] - plot area manager: {}", plotManager.getClass().getCanonicalName());
+ if (!this.worldConfiguration.contains(path)) {
+ this.worldConfiguration.createSection(path);
+ worldSection = this.worldConfiguration.getConfigurationSection(path);
}
plotArea.saveConfiguration(worldSection);
plotArea.loadDefaultConfiguration(worldSection);
try {
- this.worlds.save(this.worldsFile);
+ this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) {
e.printStackTrace();
}
@@ -1189,15 +837,14 @@ public class PlotSquared {
}
ConfigurationSection areasSection = worldSection.getConfigurationSection("areas");
if (areasSection == null) {
- if (plotAreaManager.getPlotAreas(world, null).length != 0) {
- debug("World possibly already loaded: " + world);
+ if (getPlotAreaManager().getPlotAreas(world, null).length != 0) {
return;
}
- PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'");
- String gen_string = worldSection.getString("generator.plugin", IMP.getPluginName());
+ logger.info("[P2] Detected world load for '{}'", world);
+ String gen_string = worldSection.getString("generator.plugin", platform.getPluginName());
if (type == PlotAreaType.PARTIAL) {
Set clusters =
- this.clusters_tmp != null ? this.clusters_tmp.get(world) : new HashSet<>();
+ this.clustersTmp != null ? this.clustersTmp.get(world) : new HashSet<>();
if (clusters == null) {
throw new IllegalArgumentException("No cluster exists for world: " + world);
}
@@ -1209,9 +856,8 @@ public class PlotSquared {
String fullId = name + "-" + pos1 + "-" + pos2;
worldSection.createSection("areas." + fullId);
DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE
-
- PlotSquared.log(Captions.PREFIX + "&3 - " + name + "-" + pos1 + "-" + pos2);
- GeneratorWrapper> areaGen = this.IMP.getGenerator(world, gen_string);
+ logger.info("[P2] - {}-{}-{}", name, pos1, pos2);
+ GeneratorWrapper> areaGen = this.platform.getGenerator(world, gen_string);
if (areaGen == null) {
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
}
@@ -1220,18 +866,14 @@ public class PlotSquared {
pa.saveConfiguration(worldSection);
pa.loadDefaultConfiguration(worldSection);
try {
- this.worlds.save(this.worldsFile);
+ this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) {
e.printStackTrace();
}
- PlotSquared.log(
- Captions.PREFIX + "&c | &9generator: &7" + baseGenerator + ">"
- + areaGen);
- PlotSquared.log(Captions.PREFIX + "&c | &9plotworld: &7" + pa);
- PlotSquared.log(Captions.PREFIX + "&c | &9manager: &7" + pa);
- PlotSquared.log(
- Captions.PREFIX + "&cNote: &7Area created for cluster:" + name
- + " (invalid or old configuration?)");
+ logger.info("[P2] | generator: {}>{}", baseGenerator, areaGen);
+ logger.info("[P2] | plot world: {}", pa);
+ logger.info("[P2] | manager: {}", pa);
+ logger.info("[P2] Note: Area created for cluster '{}' (invalid or old configuration?)", name);
areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa);
toLoad.add(pa);
@@ -1241,7 +883,7 @@ public class PlotSquared {
}
return;
}
- GeneratorWrapper> areaGen = this.IMP.getGenerator(world, gen_string);
+ GeneratorWrapper> areaGen = this.platform.getGenerator(world, gen_string);
if (areaGen == null) {
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
}
@@ -1249,14 +891,13 @@ public class PlotSquared {
pa.saveConfiguration(worldSection);
pa.loadDefaultConfiguration(worldSection);
try {
- this.worlds.save(this.worldsFile);
+ this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) {
e.printStackTrace();
}
- PlotSquared
- .log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + areaGen);
- PlotSquared.log(Captions.PREFIX + "&3 - plotworld: &7" + pa);
- PlotSquared.log(Captions.PREFIX + "&3 - plotAreaManager: &7" + pa.getPlotManager());
+ logger.info("[P2] - generator: {}>{}", baseGenerator, areaGen);
+ logger.info("[P2] - plot world: {}", pa);
+ logger.info("[P2] - plot area manager: {}", pa.getPlotManager());
areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa);
addPlotArea(pa);
@@ -1268,7 +909,7 @@ public class PlotSquared {
+ PlotAreaType.AUGMENTED + "`");
}
for (String areaId : areasSection.getKeys(false)) {
- PlotSquared.log(Captions.PREFIX + " - " + areaId);
+ logger.info("[P2] - {}", areaId);
String[] split = areaId.split("(?<=[^;-])-");
if (split.length != 3) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
@@ -1281,7 +922,7 @@ public class PlotSquared {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
+ ". Expected form `--`");
}
- PlotArea existing = getPlotArea(world, name);
+ final PlotArea existing = this.getPlotAreaManager().getPlotArea(world, name);
if (existing != null && name.equals(existing.getId())) {
continue;
}
@@ -1303,8 +944,8 @@ public class PlotSquared {
clone.set(key, worldSection.get(key));
}
}
- String gen_string = clone.getString("generator.plugin", IMP.getPluginName());
- GeneratorWrapper> areaGen = this.IMP.getGenerator(world, gen_string);
+ String gen_string = clone.getString("generator.plugin", platform.getPluginName());
+ GeneratorWrapper> areaGen = this.platform.getGenerator(world, gen_string);
if (areaGen == null) {
throw new IllegalArgumentException("Invalid Generator: " + gen_string);
}
@@ -1326,15 +967,14 @@ public class PlotSquared {
}
pa.loadDefaultConfiguration(clone);
try {
- this.worlds.save(this.worldsFile);
+ this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) {
e.printStackTrace();
}
- PlotSquared.log(Captions.PREFIX + "&aDetected area load for '" + world + "'");
- PlotSquared
- .log(Captions.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen);
- PlotSquared.log(Captions.PREFIX + "&c | &9plotworld: &7" + pa);
- PlotSquared.log(Captions.PREFIX + "&c | &9manager: &7" + pa.getPlotManager());
+ logger.info("[P2] Detected area load for '{}'", world);
+ logger.info("[P2] | generator: {}>{}", baseGenerator, areaGen);
+ logger.info("[P2] | plot world: {}", pa);
+ logger.info("[P2] | manager: {}", pa.getPlotManager());
areaGen.getPlotGenerator().initialize(pa);
areaGen.augment(pa);
addPlotArea(pa);
@@ -1399,11 +1039,13 @@ public class PlotSquared {
split = combinedArgs;
}
- HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator, null, null);
+ final HybridPlotWorldFactory hybridPlotWorldFactory = this.platform.getInjector().getInstance(HybridPlotWorldFactory.class);
+ final HybridPlotWorld plotWorld = hybridPlotWorldFactory.create(world, null, generator, null, null);
+
for (String element : split) {
String[] pair = element.split("=");
if (pair.length != 2) {
- PlotSquared.log("&cNo value provided for: &7" + element);
+ logger.error("[P2] No value provided for '{}'", element);
return false;
}
String key = pair[0].toLowerCase();
@@ -1413,59 +1055,59 @@ public class PlotSquared {
switch (key) {
case "s":
case "size":
- this.worlds.set(base + "plot.size",
+ this.worldConfiguration.set(base + "plot.size",
ConfigurationUtil.INTEGER.parseString(value).shortValue());
break;
case "g":
case "gap":
- this.worlds.set(base + "road.width",
+ this.worldConfiguration.set(base + "road.width",
ConfigurationUtil.INTEGER.parseString(value).shortValue());
break;
case "h":
case "height":
- this.worlds.set(base + "road.height",
+ this.worldConfiguration.set(base + "road.height",
ConfigurationUtil.INTEGER.parseString(value).shortValue());
- this.worlds.set(base + "plot.height",
+ this.worldConfiguration.set(base + "plot.height",
ConfigurationUtil.INTEGER.parseString(value).shortValue());
- this.worlds.set(base + "wall.height",
+ this.worldConfiguration.set(base + "wall.height",
ConfigurationUtil.INTEGER.parseString(value).shortValue());
break;
case "f":
case "floor":
- this.worlds.set(base + "plot.floor",
+ this.worldConfiguration.set(base + "plot.floor",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break;
case "m":
case "main":
- this.worlds.set(base + "plot.filling",
+ this.worldConfiguration.set(base + "plot.filling",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break;
case "w":
case "wall":
- this.worlds.set(base + "wall.filling",
+ this.worldConfiguration.set(base + "wall.filling",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break;
case "b":
case "border":
- this.worlds.set(base + "wall.block",
+ this.worldConfiguration.set(base + "wall.block",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break;
default:
- PlotSquared.log("&cKey not found: &7" + element);
+ logger.error("[P2] Key not found: {}", element);
return false;
}
} catch (Exception e) {
+ logger.error("[P2] Invalid value '{}' for arg '{}'", value, element);
e.printStackTrace();
- PlotSquared.log("&cInvalid value: &7" + value + " in arg " + element);
return false;
}
}
try {
ConfigurationSection section =
- this.worlds.getConfigurationSection("worlds." + world);
- plotworld.saveConfiguration(section);
- plotworld.loadDefaultConfiguration(section);
- this.worlds.save(this.worldsFile);
+ this.worldConfiguration.getConfigurationSection("worlds." + world);
+ plotWorld.saveConfiguration(section);
+ plotWorld.loadDefaultConfiguration(section);
+ this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) {
e.printStackTrace();
}
@@ -1473,17 +1115,6 @@ public class PlotSquared {
return true;
}
- public boolean canUpdate(@NonNull final String current, @NonNull final String other) {
- final String s1 = normalisedVersion(current);
- final String s2 = normalisedVersion(other);
- return s1.compareTo(s2) < 0;
- }
-
- public String normalisedVersion(@NonNull final String version) {
- final String[] split = Pattern.compile(".", Pattern.LITERAL).split(version);
- return Arrays.stream(split).map(s -> String.format("%4s", s)).collect(Collectors.joining());
- }
-
/**
* Copies a file from inside the jar to a location
*
@@ -1492,7 +1123,7 @@ public class PlotSquared {
*/
public void copyFile(String file, String folder) {
try {
- File output = this.IMP.getDirectory();
+ File output = this.platform.getDirectory();
if (!output.exists()) {
output.mkdirs();
}
@@ -1500,7 +1131,7 @@ public class PlotSquared {
if (newFile.exists()) {
return;
}
- try (InputStream stream = this.IMP.getClass().getResourceAsStream(file)) {
+ try (InputStream stream = this.platform.getClass().getResourceAsStream(file)) {
byte[] buffer = new byte[2048];
if (stream == null) {
try (ZipInputStream zis = new ZipInputStream(
@@ -1534,24 +1165,11 @@ public class PlotSquared {
}
}
} catch (IOException e) {
+ logger.error("[P2] Could not save {}", file);
e.printStackTrace();
- PlotSquared.log("&cCould not save " + file);
}
}
- private Map> getPlotsRaw() {
- HashMap> map = new HashMap<>();
- for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
- Map map2 = map.get(area.toString());
- if (map2 == null) {
- map.put(area.toString(), area.getPlotsMap());
- } else {
- map2.putAll(area.getPlotsMap());
- }
- }
- return map;
- }
-
/**
* Safely closes the database connection.
*/
@@ -1570,8 +1188,8 @@ public class PlotSquared {
// Close the connection
DBFunc.close();
} catch (NullPointerException throwable) {
+ logger.error("[P2] Could not close database connection", throwable);
throwable.printStackTrace();
- PlotSquared.log("&cCould not close database connection!");
}
}
@@ -1583,10 +1201,9 @@ public class PlotSquared {
HybridUtils.regions.isEmpty() && HybridUtils.chunks.isEmpty())) {
return;
}
- PlotSquared.log(
- Captions.PREFIX + "Road regeneration incomplete. Saving incomplete regions to disk.");
- PlotSquared.debug(" Regions: " + HybridUtils.regions.size());
- PlotSquared.debug(" Chunks: " + HybridUtils.chunks.size());
+ logger.info("[P2] Road regeneration incomplete. Saving incomplete regions to disk");
+ logger.info("[P2] - regions: {}", HybridUtils.regions.size());
+ logger.info("[P2] - chunks: {}", HybridUtils.chunks.size());
ArrayList regions = new ArrayList<>();
ArrayList chunks = new ArrayList<>();
for (BlockVector2 r : HybridUtils.regions) {
@@ -1600,19 +1217,17 @@ public class PlotSquared {
list.add(chunks);
list.add(HybridUtils.height);
File file = new File(
- this.IMP.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area
+ this.platform.getDirectory() + File.separator + "persistent_regen_data_" + HybridUtils.area
.getId() + "_" + HybridUtils.area.getWorldName());
if (file.exists() && !file.delete()) {
- PlotSquared.log(Captions.PREFIX
- + "persistent_regen_data file already exists and could not be deleted.");
+ logger.error("[P2] persistent_regene_data file already exists and could not be deleted");
return;
}
try (ObjectOutputStream oos = new ObjectOutputStream(
Files.newOutputStream(file.toPath(), StandardOpenOption.CREATE_NEW))) {
oos.writeObject(list);
} catch (IOException e) {
- PlotSquared.log(Captions.PREFIX + "Error create persistent_regen_data file.");
- e.printStackTrace();
+ logger.error("[P2] Error creating persistent_region_data file", e);
}
}
@@ -1629,41 +1244,34 @@ public class PlotSquared {
database = new MySQL(Storage.MySQL.HOST, Storage.MySQL.PORT, Storage.MySQL.DATABASE,
Storage.MySQL.USER, Storage.MySQL.PASSWORD);
} else if (Storage.SQLite.USE) {
- File file = MainUtil.getFile(IMP.getDirectory(), Storage.SQLite.DB + ".db");
+ File file = MainUtil.getFile(platform.getDirectory(), Storage.SQLite.DB + ".db");
database = new SQLite(file);
} else {
- PlotSquared.log(Captions.PREFIX + "&cNo storage type is set!");
- this.IMP.shutdown(); //shutdown used instead of disable because no database is set
+ logger.error("[P2] No storage type is set. Disabling PlotSquared");
+ this.platform.shutdown(); //shutdown used instead of disable because no database is set
return;
}
- DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, false);
+ DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, this.eventDispatcher, this.plotListener, this.worldConfiguration);
this.plots_tmp = DBFunc.getPlots();
- if (plotAreaManager instanceof SinglePlotAreaManager) {
- SinglePlotArea area = ((SinglePlotAreaManager) plotAreaManager).getArea();
+ if (getPlotAreaManager() instanceof SinglePlotAreaManager) {
+ SinglePlotArea area = ((SinglePlotAreaManager) getPlotAreaManager()).getArea();
addPlotArea(area);
- ConfigurationSection section = worlds.getConfigurationSection("worlds.*");
+ ConfigurationSection section = worldConfiguration.getConfigurationSection("worlds.*");
if (section == null) {
- section = worlds.createSection("worlds.*");
+ section = worldConfiguration.createSection("worlds.*");
}
area.saveConfiguration(section);
area.loadDefaultConfiguration(section);
}
- this.clusters_tmp = DBFunc.getClusters();
+ this.clustersTmp = DBFunc.getClusters();
} catch (ClassNotFoundException | SQLException e) {
- PlotSquared.log(Captions.PREFIX
- + "&cFailed to open DATABASE connection. The plugin will disable itself.");
- if (Storage.MySQL.USE) {
- PlotSquared.log("$4MYSQL");
- } else if (Storage.SQLite.USE) {
- PlotSquared.log("$4SQLITE");
- }
- PlotSquared.log(
- "&d==== Here is an ugly stacktrace, if you are interested in those things ===");
+ logger.error("[P2] Failed to open database connection ({}). Disabling PlotSquared", Storage.MySQL.USE ? "MySQL" : "SQLite");
+ logger.error("[P2] ==== Here is an ugly stacktrace, if you are interested in those things ===");
e.printStackTrace();
- PlotSquared.log("&d==== End of stacktrace ====");
- PlotSquared.log("&6Please go to the " + IMP.getPluginName()
- + " 'storage.yml' and configure the database correctly.");
- this.IMP.shutdown(); //shutdown used instead of disable because of database error
+ logger.error("[P2] &d==== End of stacktrace ====");
+ logger.error("[P2] &6Please go to the {} 'storage.yml' and configure the database correctly",
+ platform.getPluginName());
+ this.platform.shutdown(); //shutdown used instead of disable because of database error
}
}
@@ -1683,11 +1291,11 @@ public class PlotSquared {
if (getConfig().contains("worlds")) {
ConfigurationSection worldSection =
getConfig().getConfigurationSection("worlds");
- worlds.set("worlds", worldSection);
+ worldConfiguration.set("worlds", worldSection);
try {
- worlds.save(worldsFile);
+ worldConfiguration.save(worldsFile);
} catch (IOException e) {
- PlotSquared.debug("Failed to save " + IMP.getPluginName() + " worlds.yml");
+ logger.error("[P2] Failed to save worlds.yml", e);
e.printStackTrace();
}
}
@@ -1718,84 +1326,79 @@ public class PlotSquared {
* - Translation: PlotSquared.use_THIS.yml, style.yml
*/
public boolean setupConfigs() {
- File folder = new File(this.IMP.getDirectory(), "config");
+ File folder = new File(this.platform.getDirectory(), "config");
if (!folder.exists() && !folder.mkdirs()) {
- PlotSquared.log(Captions.PREFIX
- + "&cFailed to create the /plugins/config folder. Please create it manually.");
+ logger.error("[P2] Failed to create the /plugins/config folder. Please create it manually");
}
try {
this.worldsFile = new File(folder, "worlds.yml");
if (!this.worldsFile.exists() && !this.worldsFile.createNewFile()) {
- PlotSquared.log(
- "Could not create the worlds file, please create \"worlds.yml\" manually.");
+ logger.error("[P2] Could not create the worlds file. Please create 'worlds.yml' manually");
}
- this.worlds = YamlConfiguration.loadConfiguration(this.worldsFile);
+ this.worldConfiguration = YamlConfiguration.loadConfiguration(this.worldsFile);
- if (this.worlds.contains("worlds")) {
- if (!this.worlds.contains("configuration_version") || (
- !this.worlds.getString("configuration_version")
- .equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worlds
+ if (this.worldConfiguration.contains("worlds")) {
+ if (!this.worldConfiguration.contains("configuration_version") || (
+ !this.worldConfiguration.getString("configuration_version")
+ .equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worldConfiguration
.getString("configuration_version").equalsIgnoreCase("v5"))) {
// Conversion needed
- log(Captions.LEGACY_CONFIG_FOUND.getTranslated());
+ logger.info(Captions.LEGACY_CONFIG_FOUND.getTranslated());
try {
com.google.common.io.Files
.copy(this.worldsFile, new File(folder, "worlds.yml.old"));
- log(Captions.LEGACY_CONFIG_BACKUP.getTranslated());
+ logger.info(Captions.LEGACY_CONFIG_BACKUP.getTranslated());
final ConfigurationSection worlds =
- this.worlds.getConfigurationSection("worlds");
+ this.worldConfiguration.getConfigurationSection("worlds");
final LegacyConverter converter = new LegacyConverter(worlds);
converter.convert();
- this.worlds.set("worlds", worlds);
+ this.worldConfiguration.set("worlds", worlds);
this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION);
- log(Captions.LEGACY_CONFIG_DONE.getTranslated());
+ logger.info(Captions.LEGACY_CONFIG_DONE.getTranslated());
} catch (final Exception e) {
- log(Captions.LEGACY_CONFIG_CONVERSION_FAILED.getTranslated());
- e.printStackTrace();
+ logger.error(Captions.LEGACY_CONFIG_CONVERSION_FAILED.getTranslated(), e);
}
// Disable plugin
- this.IMP.shutdown();
+ this.platform.shutdown();
return false;
}
} else {
- this.worlds.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION);
+ this.worldConfiguration.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION);
}
} catch (IOException ignored) {
- PlotSquared.log("Failed to save settings.yml");
+ logger.error("[P2] Failed to save worlds.yml");
}
try {
this.configFile = new File(folder, "settings.yml");
if (!this.configFile.exists() && !this.configFile.createNewFile()) {
- PlotSquared.log(
- "Could not create the settings file, please create \"settings.yml\" manually.");
+ logger.error("[P2] Could not create the settings file. Please create 'settings.yml' manually");
}
this.config = YamlConfiguration.loadConfiguration(this.configFile);
setupConfig();
} catch (IOException ignored) {
- PlotSquared.log("Failed to save settings.yml");
+ logger.error("[P2] Failed to save settings.yml");
}
try {
this.storageFile = new File(folder, "storage.yml");
if (!this.storageFile.exists() && !this.storageFile.createNewFile()) {
- PlotSquared.log(
- "Could not the storage settings file, please create \"storage.yml\" manually.");
+ logger.error("[P2] Could not create the storage settings file. Please create 'storage.yml' manually");
}
- this.storage = YamlConfiguration.loadConfiguration(this.storageFile);
+ YamlConfiguration.loadConfiguration(this.storageFile);
setupStorage();
} catch (IOException ignored) {
- PlotSquared.log("Failed to save storage.yml");
+ logger.error("[P2] Failed to save storage.yml");
}
return true;
}
public String getConfigurationVersion() {
- return this.worlds.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION)
+ return this.worldConfiguration.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION)
.toString();
}
public void setConfigurationVersion(final String newVersion) throws IOException {
- this.worlds.set("configuration_version", newVersion);
- this.worlds.save(this.worldsFile);
+ this.worldConfiguration.set("configuration_version", newVersion);
+ this.worldConfiguration.save(this.worldsFile);
}
/**
@@ -1804,7 +1407,7 @@ public class PlotSquared {
private void setupStorage() {
Storage.load(storageFile);
Storage.save(storageFile);
- storage = YamlConfiguration.loadConfiguration(storageFile);
+ YamlConfiguration.loadConfiguration(storageFile);
}
/**
@@ -1814,46 +1417,13 @@ public class PlotSquared {
if (Settings.DEBUG) {
Map components = Settings.getFields(Settings.Enabled_Components.class);
for (Entry component : components.entrySet()) {
- PlotSquared.log(Captions.PREFIX + String
- .format("&cKey: &6%s&c, Value: &6%s", component.getKey(),
- component.getValue()));
+ logger.info("[P2] Key: {} | Value: {}", component.getKey(), component.getValue());
}
}
}
- /**
- * Gets the Java version.
- *
- * @return the java version
- */
- private double getJavaVersion() {
- return Double.parseDouble(System.getProperty("java.specification.version"));
- }
-
- public void forEachPlotArea(Consumer super PlotArea> action) {
- for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
- action.accept(area);
- }
- }
-
- public void forEachPlotArea(@NonNull final String world, Consumer consumer) {
- final PlotArea[] array = this.plotAreaManager.getPlotAreas(world, null);
- if (array == null) {
- return;
- }
- for (final PlotArea area : array) {
- consumer.accept(area);
- }
- }
-
- public void forEachPlot(Consumer consumer) {
- for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
- area.getPlots().forEach(consumer);
- }
- }
-
public void forEachPlotRaw(Consumer consumer) {
- for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
+ for (final PlotArea area : this.getPlotAreaManager().getAllPlotAreas()) {
area.getPlots().forEach(consumer);
}
if (this.plots_tmp != null) {
@@ -1863,32 +1433,6 @@ public class PlotSquared {
}
}
- public void forEachBasePlot(Consumer consumer) {
- for (final PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
- area.forEachBasePlot(consumer);
- }
- }
-
- public PlotArea getFirstPlotArea() {
- PlotArea[] areas = plotAreaManager.getAllPlotAreas();
- return areas.length > 0 ? areas[0] : null;
- }
-
- public int getPlotAreaCount() {
- return this.plotAreaManager.getAllPlotAreas().length;
- }
-
- public int getPlotCount() {
- return Arrays.stream(this.plotAreaManager.getAllPlotAreas())
- .mapToInt(PlotArea::getPlotCount).sum();
- }
-
- public Set getPlotAreas() {
- final Set set = new HashSet<>();
- Collections.addAll(set, plotAreaManager.getAllPlotAreas());
- return Collections.unmodifiableSet(set);
- }
-
/**
* Check if the chunk uses vanilla/non-PlotSquared generation
*
@@ -1896,115 +1440,16 @@ public class PlotSquared {
* @param chunkCoordinates Chunk coordinates
* @return True if the chunk uses non-standard generation, false if not
*/
- public boolean isNonStandardGeneration(@NotNull final String world,
- @NotNull final BlockVector2 chunkCoordinates) {
- final Location location = new Location(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
- final PlotArea area = plotAreaManager.getApplicablePlotArea(location);
+ public boolean isNonStandardGeneration(@Nonnull final String world,
+ @Nonnull final BlockVector2 chunkCoordinates) {
+ final Location location = Location.at(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
+ final PlotArea area = getPlotAreaManager().getApplicablePlotArea(location);
if (area == null) {
return true;
}
return area.getTerrain() != PlotAreaTerrainType.NONE;
}
- public boolean isAugmented(@NonNull final String world) {
- final PlotArea[] areas = plotAreaManager.getPlotAreas(world, null);
- return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL);
- }
-
- /**
- * Gets a list of PlotArea objects.
- *
- * @param world the world
- * @return Collection of PlotArea objects
- */
- public Set getPlotAreas(@NonNull final String world) {
- final Set set = new HashSet<>();
- Collections.addAll(set, plotAreaManager.getPlotAreas(world, null));
- return set;
- }
-
- /**
- * Gets the relevant plot area for a specified location.
- *
- *
If there is only one plot area globally that will be returned.
- *
If there is only one plot area in the world, it will return that.
- *
If the plot area for a location cannot be unambiguously
- * resolved, null will be returned.
- *
- * Note: An applicable plot area may not include the location i.e. clusters
- *
- * @param location the location
- * @return
- */
- public PlotArea getApplicablePlotArea(@NonNull final Location location) {
- return plotAreaManager.getApplicablePlotArea(location);
- }
-
- public PlotArea getPlotArea(@NonNull final String world, final String id) {
- return plotAreaManager.getPlotArea(world, id);
- }
-
- /**
- * Gets the {@code PlotArea} which contains a location.
- *
- *
If the plot area does not contain a location, null
- * will be returned.
- *
- *
- * @param location the location
- * @return the {@link PlotArea} in the location, null if non existent
- */
- public PlotArea getPlotAreaAbs(@NonNull final Location location) {
- return plotAreaManager.getPlotArea(location);
- }
-
- public PlotArea getPlotAreaByString(@NonNull final String search) {
- String[] split = search.split("[;,]");
- PlotArea[] areas = plotAreaManager.getPlotAreas(split[0], null);
- if (areas == null) {
- for (PlotArea area : plotAreaManager.getAllPlotAreas()) {
- if (area.getWorldName().equalsIgnoreCase(split[0])) {
- if (area.getId() == null || split.length == 2 && area.getId()
- .equalsIgnoreCase(split[1])) {
- return area;
- }
- }
- }
- return null;
- }
- if (areas.length == 1) {
- return areas[0];
- } else if (split.length == 1) {
- return null;
- } else {
- for (PlotArea area : areas) {
- if (StringMan.isEqual(split[1], area.getId())) {
- return area;
- }
- }
- return null;
- }
- }
-
- /**
- * Gets Plots based on alias
- *
- * @param alias to search plots
- * @param worldname to filter alias to a specific world [optional] null means all worlds
- * @return Set<{@link Plot }> empty if nothing found
- */
- public Set getPlotsByAlias(@Nullable final String alias,
- @NonNull final String worldname) {
- return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet();
- }
-
- public Set getPlotAreas(final String world, final CuboidRegion region) {
- final PlotArea[] areas = plotAreaManager.getPlotAreas(world, region);
- final Set set = new HashSet<>();
- Collections.addAll(set, areas);
- return Collections.unmodifiableSet(set);
- }
-
public YamlConfiguration getConfig() {
return config;
}
diff --git a/Core/src/main/java/com/plotsquared/core/backup/Backup.java b/Core/src/main/java/com/plotsquared/core/backup/Backup.java
index a84fc497f..111edd8a7 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/Backup.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/Backup.java
@@ -28,7 +28,7 @@ package com.plotsquared.core.backup;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nullable;
import java.io.IOException;
import java.nio.file.Files;
diff --git a/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java
index 4ba4a44f4..5ae0dcdfe 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/BackupManager.java
@@ -28,8 +28,8 @@ package com.plotsquared.core.backup;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.nio.file.Path;
import java.util.Objects;
@@ -45,8 +45,8 @@ public interface BackupManager {
* @param plot Plot to perform the automatic backup on
* @param whenDone Action that runs when the automatic backup has been completed
*/
- static void backup(@Nullable PlotPlayer player, @NotNull final Plot plot, @NotNull Runnable whenDone) {
- Objects.requireNonNull(PlotSquared.imp()).getBackupManager().automaticBackup(player, plot, whenDone);
+ static void backup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone) {
+ Objects.requireNonNull(PlotSquared.platform()).getBackupManager().automaticBackup(player, plot, whenDone);
}
/**
@@ -56,7 +56,7 @@ public interface BackupManager {
* @param plot Plot to get the backup profile for
* @return Backup profile
*/
- @NotNull BackupProfile getProfile(@NotNull final Plot plot);
+ @Nonnull BackupProfile getProfile(@Nonnull final Plot plot);
/**
* This will perform an automatic backup of the plot iff the plot has an owner,
@@ -67,14 +67,14 @@ public interface BackupManager {
* @param plot Plot to perform the automatic backup on
* @param whenDone Action that runs when the automatic backup has been completed
*/
- void automaticBackup(@Nullable PlotPlayer player, @NotNull final Plot plot, @NotNull Runnable whenDone);
+ void automaticBackup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone);
/**
* Get the directory in which backups are stored
*
* @return Backup directory path
*/
- @NotNull Path getBackupPath();
+ @Nonnull Path getBackupPath();
/**
* Get the maximum amount of backups that may be stored for
diff --git a/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java
index 6664246e4..1a9dc7baa 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/BackupProfile.java
@@ -25,7 +25,7 @@
*/
package com.plotsquared.core.backup;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.nio.file.Path;
import java.util.List;
@@ -38,7 +38,7 @@ public interface BackupProfile {
*
* @return Future that will be completed with available backups
*/
- @NotNull CompletableFuture> listBackups();
+ @Nonnull CompletableFuture> listBackups();
/**
* Remove all backups stored for this profile
@@ -51,7 +51,7 @@ public interface BackupProfile {
*
* @return Folder that contains the backups for this profile
*/
- @NotNull Path getBackupDirectory();
+ @Nonnull Path getBackupDirectory();
/**
* Create a backup of the plot. If the profile is at the
@@ -59,7 +59,7 @@ public interface BackupProfile {
*
* @return Future that completes with the created backup.
*/
- @NotNull CompletableFuture createBackup();
+ @Nonnull CompletableFuture createBackup();
/**
* Restore a backup
@@ -67,6 +67,6 @@ public interface BackupProfile {
* @param backup Backup to restore
* @return Future that completes when the backup has finished
*/
- @NotNull CompletableFuture restoreBackup(@NotNull final Backup backup);
+ @Nonnull CompletableFuture restoreBackup(@Nonnull final Backup backup);
}
diff --git a/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java
index 2d8c04a76..c83a36c24 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/NullBackupManager.java
@@ -25,11 +25,12 @@
*/
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;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.nio.file.Path;
import java.util.Objects;
@@ -37,19 +38,19 @@ import java.util.Objects;
/**
* {@inheritDoc}
*/
-public class NullBackupManager implements BackupManager {
+@Singleton public class NullBackupManager implements BackupManager {
- @Override @NotNull public BackupProfile getProfile(@NotNull Plot plot) {
+ @Override @Nonnull public BackupProfile getProfile(@Nonnull Plot plot) {
return new NullBackupProfile();
}
@Override public void automaticBackup(@Nullable PlotPlayer plotPlayer,
- @NotNull Plot plot, @NotNull Runnable whenDone) {
+ @Nonnull Plot plot, @Nonnull Runnable whenDone) {
whenDone.run();
}
- @Override @NotNull public Path getBackupPath() {
- return Objects.requireNonNull(PlotSquared.imp()).getDirectory().toPath();
+ @Override @Nonnull public Path getBackupPath() {
+ return Objects.requireNonNull(PlotSquared.platform()).getDirectory().toPath();
}
@Override public int getBackupLimit() {
diff --git a/Core/src/main/java/com/plotsquared/core/backup/NullBackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/NullBackupProfile.java
index 39c833579..b16a589fc 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/NullBackupProfile.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/NullBackupProfile.java
@@ -25,7 +25,7 @@
*/
package com.plotsquared.core.backup;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.io.File;
import java.nio.file.Path;
@@ -39,22 +39,22 @@ import java.util.concurrent.CompletableFuture;
*/
public class NullBackupProfile implements BackupProfile {
- @Override @NotNull public CompletableFuture> listBackups() {
+ @Override @Nonnull public CompletableFuture> listBackups() {
return CompletableFuture.completedFuture(Collections.emptyList());
}
@Override public void destroy(){
}
- @Override @NotNull public Path getBackupDirectory() {
+ @Override @Nonnull public Path getBackupDirectory() {
return new File(".").toPath();
}
- @Override @NotNull public CompletableFuture createBackup() {
+ @Override @Nonnull public CompletableFuture createBackup() {
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
}
- @Override @NotNull public CompletableFuture restoreBackup(@NotNull final Backup backup) {
+ @Override @Nonnull public CompletableFuture restoreBackup(@Nonnull final Backup backup) {
return CompletableFuture.completedFuture(null);
}
diff --git a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java
index c71057ab5..e70ef4ac6 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java
@@ -25,14 +25,15 @@
*/
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 javax.annotation.Nonnull;
import java.io.IOException;
import java.nio.file.Files;
@@ -51,22 +52,30 @@ 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 @Nonnull final UUID owner, @Assisted @Nonnull final Plot plot,
+ @Nonnull final BackupManager backupManager, @Nonnull final SchematicHandler schematicHandler) {
+ this.owner = owner;
+ this.plot = plot;
+ this.backupManager = backupManager;
+ this.schematicHandler = schematicHandler;
+ }
private volatile List backupCache;
private final Object backupLock = new Object();
- private static boolean isValidFile(@NotNull final Path path) {
+ private static boolean isValidFile(@Nonnull final Path path) {
final String name = path.getFileName().toString();
return name.endsWith(".schem") || name.endsWith(".schematic");
}
- @Override @NotNull public CompletableFuture> listBackups() {
+ @Override @Nonnull public CompletableFuture> listBackups() {
synchronized (this.backupLock) {
if (this.backupCache != null) {
return CompletableFuture.completedFuture(backupCache);
@@ -112,12 +121,12 @@ public class PlayerBackupProfile implements BackupProfile {
});
}
- @NotNull public Path getBackupDirectory() {
+ @Nonnull public Path getBackupDirectory() {
return resolve(resolve(resolve(backupManager.getBackupPath(), Objects.requireNonNull(plot.getArea().toString(), "plot area id")),
Objects.requireNonNull(plot.getId().toDashSeparatedString(), "plot id")), Objects.requireNonNull(owner.toString(), "owner"));
}
- private static Path resolve(@NotNull final Path parent, final String child) {
+ private static Path resolve(@Nonnull final Path parent, final String child) {
Path path = parent;
try {
if (!Files.exists(parent)) {
@@ -133,7 +142,7 @@ public class PlayerBackupProfile implements BackupProfile {
return path;
}
- @Override @NotNull public CompletableFuture createBackup() {
+ @Override @Nonnull public CompletableFuture createBackup() {
final CompletableFuture future = new CompletableFuture<>();
this.listBackups().thenAcceptAsync(backups -> {
synchronized (this.backupLock) {
@@ -141,7 +150,7 @@ public class PlayerBackupProfile implements BackupProfile {
backups.get(backups.size() - 1).delete();
}
final List 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) {
@@ -153,7 +162,7 @@ public class PlayerBackupProfile implements BackupProfile {
return future;
}
- @Override @NotNull public CompletableFuture restoreBackup(@NotNull final Backup backup) {
+ @Override @Nonnull public CompletableFuture restoreBackup(@Nonnull final Backup backup) {
final CompletableFuture future = new CompletableFuture<>();
if (backup.getFile() == null || !Files.exists(backup.getFile())) {
future.completeExceptionally(new IllegalArgumentException("The specific backup does not exist"));
@@ -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() {
+ this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal() {
@Override public void run(Boolean value) {
if (value) {
future.complete(null);
diff --git a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java
index 57cbea1d8..97bae8f1c 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java
@@ -27,17 +27,20 @@ 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;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -48,16 +51,18 @@ 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 backupProfileCache = CacheBuilder.newBuilder()
.expireAfterAccess(3, TimeUnit.MINUTES).build();
+ private final PlayerBackupProfileFactory playerBackupProfileFactory;
- public SimpleBackupManager() throws Exception {
- this.backupPath = Objects.requireNonNull(PlotSquared.imp()).getDirectory().toPath().resolve("backups");
+ @Inject public SimpleBackupManager(@Nonnull 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);
}
@@ -65,12 +70,12 @@ import java.util.concurrent.TimeUnit;
this.backupLimit = Settings.Backup.BACKUP_LIMIT;
}
- @Override @NotNull public BackupProfile getProfile(@NotNull final Plot plot) {
+ @Override @Nonnull public BackupProfile getProfile(@Nonnull 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;
}
@@ -78,7 +83,7 @@ import java.util.concurrent.TimeUnit;
return new NullBackupProfile();
}
- @Override public void automaticBackup(@Nullable PlotPlayer player, @NotNull final Plot plot, @NotNull Runnable whenDone) {
+ @Override public void automaticBackup(@Nullable PlotPlayer player, @Nonnull final Plot plot, @Nonnull Runnable whenDone) {
final BackupProfile profile;
if (!this.shouldAutomaticallyBackup() || (profile = getProfile(plot)) instanceof NullBackupProfile) {
whenDone.run();
diff --git a/Core/src/main/java/com/plotsquared/core/command/Add.java b/Core/src/main/java/com/plotsquared/core/command/Add.java
index aa52e5e2c..a3efa64f2 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Add.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Add.java
@@ -25,17 +25,19 @@
*/
package com.plotsquared.core.command;
-import com.plotsquared.core.PlotSquared;
+import com.google.inject.Inject;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
+import javax.annotation.Nonnull;
import net.kyori.adventure.text.minimessage.Template;
import java.util.Collection;
@@ -53,8 +55,11 @@ import java.util.concurrent.TimeoutException;
requiredType = RequiredType.PLAYER)
public class Add extends Command {
- public Add() {
+ private final EventDispatcher eventDispatcher;
+
+ @Inject public Add(@Nonnull final EventDispatcher eventDispatcher) {
super(MainCommand.getInstance(), true);
+ this.eventDispatcher = eventDispatcher;
}
@Override
@@ -122,7 +127,7 @@ public class Add extends Command {
}
}
plot.addMember(uuid);
- PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true);
+ this.eventDispatcher.callMember(player, plot, uuid, true);
player.sendMessage(TranslatableCaption.of("member.member_added"));
}
}, null);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java
index 1a7faba09..f179a1953 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Area.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Area.java
@@ -25,14 +25,19 @@
*/
package com.plotsquared.core.command;
+import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
+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;
+import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.generator.HybridPlotWorld;
+import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
@@ -40,6 +45,8 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
+import com.plotsquared.core.plot.message.PlotMessage;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
@@ -66,11 +73,14 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import net.kyori.adventure.text.minimessage.Template;
+import javax.annotation.Nonnull;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -84,6 +94,30 @@ import java.util.Set;
confirmation = true)
public class Area extends SubCommand {
+ private final PlotAreaManager plotAreaManager;
+ private final YamlConfiguration worldConfiguration;
+ private final File worldFile;
+ private final HybridPlotWorldFactory hybridPlotWorldFactory;
+ private final SetupUtils setupUtils;
+ private final WorldUtil worldUtil;
+ private final RegionManager regionManager;
+
+ @Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
+ @WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
+ @WorldFile @Nonnull final File worldFile,
+ @Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory,
+ @Nonnull final SetupUtils setupUtils,
+ @Nonnull final WorldUtil worldUtil,
+ @Nonnull final RegionManager regionManager) {
+ this.plotAreaManager = plotAreaManager;
+ this.worldConfiguration = worldConfiguration;
+ this.worldFile = worldFile;
+ this.hybridPlotWorldFactory = hybridPlotWorldFactory;
+ this.setupUtils = setupUtils;
+ this.worldUtil = worldUtil;
+ this.regionManager = regionManager;
+ }
+
@Override public boolean onCommand(final PlotPlayer> player, String[] args) {
if (args.length == 0) {
sendUsage(player);
@@ -104,7 +138,7 @@ public class Area extends SubCommand {
player.sendMessage(TranslatableCaption.of("single.single_area_needs_name"));
return false;
}
- final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]);
+ final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
player.sendMessage(TranslatableCaption.of("single.single_area_name_taken"));
return false;
@@ -126,7 +160,7 @@ public class Area extends SubCommand {
player.sendMessage(TranslatableCaption.of("single.single_area_not_square"));
return false;
}
- if (PlotSquared.get().getPlotAreaManager().getPlotAreas(
+ if (this.plotAreaManager.getPlotAreas(
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
player.sendMessage(TranslatableCaption.of("single.single_area_overlapping"));
}
@@ -139,8 +173,8 @@ public class Area extends SubCommand {
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
// There's only one plot in the area...
final PlotId plotId = new PlotId(1, 1);
- final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorld(), args[1],
- Objects.requireNonNull(PlotSquared.imp()).getDefaultGenerator(), plotId, plotId);
+ final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory.create(player.getLocation().getWorldName(), args[1],
+ Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId);
// Plot size is the same as the region width
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
// We use a schematic generator
@@ -155,7 +189,7 @@ public class Area extends SubCommand {
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
// No sign plz
hybridPlotWorld.setAllowSigns(false);
- final File parentFile = MainUtil.getFile(PlotSquared.imp().getDirectory(), "schematics" + File.separator +
+ final File parentFile = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics" + File.separator +
"GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
hybridPlotWorld.getId());
if (!parentFile.exists() && !parentFile.mkdirs()) {
@@ -189,8 +223,8 @@ public class Area extends SubCommand {
// Now the schematic is saved, which is wonderful!
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld)
- .plotManager(PlotSquared.imp().getPluginName())
- .generatorName(PlotSquared.imp().getPluginName())
+ .plotManager(PlotSquared.platform().getPluginName())
+ .generatorName(PlotSquared.platform().getPluginName())
.maximumId(plotId)
.minimumId(plotId);
Runnable singleRun = () -> {
@@ -200,15 +234,13 @@ public class Area extends SubCommand {
final int offsetX = singlePos1.getX();
final int offsetZ = singlePos1.getZ();
if (offsetX != 0) {
- PlotSquared.get().worlds
- .set(path + ".road.offset.x", offsetX);
+ this.worldConfiguration.set(path + ".road.offset.x", offsetX);
}
if (offsetZ != 0) {
- PlotSquared.get().worlds
- .set(path + ".road.offset.z", offsetZ);
+ this.worldConfiguration.set(path + ".road.offset.z", offsetZ);
}
- final String world = SetupUtils.manager.setupWorld(singleBuilder);
- if (WorldUtil.IMP.isWorld(world)) {
+ final String world = this.setupUtils.setupWorld(singleBuilder);
+ if (this.worldUtil.isWorld(world)) {
PlotSquared.get().loadWorld(world, null);
player.sendMessage(TranslatableCaption.of("single.single_area_created"));
} else {
@@ -278,16 +310,16 @@ public class Area extends SubCommand {
final int offsetX = bx - (area.ROAD_WIDTH == 0 ? 0 : lower);
final int offsetZ = bz - (area.ROAD_WIDTH == 0 ? 0 : lower);
final CuboidRegion region = RegionUtil.createRegion(bx, tx, bz, tz);
- Set areas =
- PlotSquared.get().getPlotAreas(area.getWorldName(), region);
+ final Set areas = this.plotAreaManager
+ .getPlotAreasSet(area.getWorldName(), region);
if (!areas.isEmpty()) {
player.sendMessage(TranslatableCaption.of("cluster.cluster_intersection"),
Template.of("cluster", areas.iterator().next().toString()));
return false;
}
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area)
- .plotManager(PlotSquared.imp().getPluginName())
- .generatorName(PlotSquared.imp().getPluginName())
+ .plotManager(PlotSquared.platform().getPluginName())
+ .generatorName(PlotSquared.platform().getPluginName())
.minimumId(new PlotId(1, 1))
.maximumId(new PlotId(numX, numZ));
final String path =
@@ -295,21 +327,19 @@ public class Area extends SubCommand {
+ builder.minimumId() + '-' + builder.maximumId();
Runnable run = () -> {
if (offsetX != 0) {
- PlotSquared.get().worlds
- .set(path + ".road.offset.x", offsetX);
+ this.worldConfiguration.set(path + ".road.offset.x", offsetX);
}
if (offsetZ != 0) {
- PlotSquared.get().worlds
- .set(path + ".road.offset.z", offsetZ);
+ this.worldConfiguration.set(path + ".road.offset.z", offsetZ);
}
- final String world = SetupUtils.manager.setupWorld(builder);
- if (WorldUtil.IMP.isWorld(world)) {
+ final String world = this.setupUtils.setupWorld(builder);
+ if (this.worldUtil.isWorld(world)) {
PlotSquared.get().loadWorld(world, null);
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
- player.teleport(WorldUtil.IMP.getSpawn(world),
+ player.teleport(this.worldUtil.getSpawn(world),
TeleportCause.COMMAND);
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
- RegionManager.largeRegionTask(world, region,
+ this.regionManager.largeRegionTask(world, region,
new RunnableVal() {
@Override public void run(BlockVector2 value) {
AugmentedUtils
@@ -340,17 +370,17 @@ public class Area extends SubCommand {
} else {
id = null;
}
- PlotAreaBuilder builder = new PlotAreaBuilder();
+ PlotAreaBuilder builder = PlotAreaBuilder.newBuilder();
builder.worldName(split[0]);
- final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
- PlotSquared.get().IMP.getDefaultGenerator(), null, null);
- PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id);
+ final HybridPlotWorld pa = this.hybridPlotWorldFactory.create(builder.worldName(),
+ id, PlotSquared.platform().getDefaultGenerator(), null, null);
+ PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
if (other != null && Objects.equals(pa.getId(), other.getId())) {
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"),
Template.of("value", pa.toString()));
return false;
}
- Set areas = PlotSquared.get().getPlotAreas(pa.getWorldName());
+ Set areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
if (!areas.isEmpty()) {
PlotArea area = areas.iterator().next();
pa.setType(area.getType());
@@ -420,26 +450,25 @@ public class Area extends SubCommand {
}
}
if (pa.getType() != PlotAreaType.PARTIAL) {
- if (WorldUtil.IMP.isWorld(pa.getWorldName())) {
+ if (this.worldUtil.isWorld(pa.getWorldName())) {
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"),
Template.of("value", pa.getWorldName()));
return false;
}
Runnable run = () -> {
String path = "worlds." + pa.getWorldName();
- if (!PlotSquared.get().worlds.contains(path)) {
- PlotSquared.get().worlds.createSection(path);
+ if (!this.worldConfiguration.contains(path)) {
+ this.worldConfiguration.createSection(path);
}
- ConfigurationSection section =
- PlotSquared.get().worlds.getConfigurationSection(path);
+ ConfigurationSection section = this.worldConfiguration.getConfigurationSection(path);
pa.saveConfiguration(section);
pa.loadConfiguration(section);
- builder.plotManager(PlotSquared.imp().getPluginName());
- builder.generatorName(PlotSquared.imp().getPluginName());
- String world = SetupUtils.manager.setupWorld(builder);
- if (WorldUtil.IMP.isWorld(world)) {
+ builder.plotManager(PlotSquared.platform().getPluginName());
+ builder.generatorName(PlotSquared.platform().getPluginName());
+ String world = this.setupUtils.setupWorld(builder);
+ if (this.worldUtil.isWorld(world)) {
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
- player.teleport(WorldUtil.IMP.getSpawn(world),
+ player.teleport(this.worldUtil.getSpawn(world),
TeleportCause.COMMAND);
} else {
MainUtil.sendMessage(player,
@@ -447,7 +476,7 @@ public class Area extends SubCommand {
.getWorldName());
}
try {
- PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
+ this.worldConfiguration.save(this.worldFile);
} catch (IOException e) {
e.printStackTrace();
}
@@ -465,16 +494,16 @@ public class Area extends SubCommand {
+ " create [world[:id]] [=]...");
return false;
}
- if (WorldUtil.IMP.isWorld(pa.getWorldName())) {
- if (!player.getLocation().getWorld().equals(pa.getWorldName())) {
- player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()),
+ if (this.worldUtil.isWorld(pa.getWorldName())) {
+ if (!player.getLocation().getWorldName().equals(pa.getWorldName())) {
+ player.teleport(this.worldUtil.getSpawn(pa.getWorldName()),
TeleportCause.COMMAND);
}
} else {
builder.terrainType(PlotAreaTerrainType.NONE);
builder.plotAreaType(PlotAreaType.NORMAL);
- SetupUtils.manager.setupWorld(builder);
- player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()),
+ this.setupUtils.setupWorld(builder);
+ player.teleport(this.worldUtil.getSpawn(pa.getWorldName()),
TeleportCause.COMMAND);
}
player.setMeta("area_create_area", pa);
@@ -497,7 +526,7 @@ public class Area extends SubCommand {
area = player.getApplicablePlotArea();
break;
case 2:
- area = PlotSquared.get().getPlotAreaByString(args[1]);
+ area = this.plotAreaManager.getPlotAreaByString(args[1]);
break;
default:
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " info [area]");
@@ -561,7 +590,7 @@ public class Area extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]");
return false;
}
- ArrayList areas = new ArrayList<>(PlotSquared.get().getPlotAreas());
+ final List areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
paginate(player, areas, 8, page,
new RunnableVal3() {
@Override public void run(Integer i, PlotArea area, PlotMessage message) {
@@ -622,7 +651,7 @@ public class Area extends SubCommand {
"$4Stop the server and delete: " + area.getWorldName() + "/region");
return false;
}
- RegionManager.largeRegionTask(area.getWorldName(), area.getRegion(),
+ this.regionManager.largeRegionTask(area.getWorldName(), area.getRegion(),
new RunnableVal() {
@Override public void run(BlockVector2 value) {
AugmentedUtils
@@ -646,7 +675,7 @@ public class Area extends SubCommand {
Captions.COMMAND_SYNTAX.send(player, "/plot visit [area]");
return false;
}
- PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]);
+ PlotArea area = this.plotAreaManager.getPlotAreaByString(args[1]);
if (area == null) {
player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"),
Template.of("value", args[1]));
@@ -654,26 +683,23 @@ public class Area extends SubCommand {
}
Location center;
if (area.getType() != PlotAreaType.PARTIAL) {
- center = WorldUtil.IMP.getSpawn(area.getWorldName());
+ center = this.worldUtil.getSpawn(area.getWorldName());
player.teleport(center, TeleportCause.COMMAND);
} else {
CuboidRegion region = area.getRegion();
- center = new Location(area.getWorldName(), region.getMinimumPoint().getX()
+ center = Location.at(area.getWorldName(), region.getMinimumPoint().getX()
+ (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2,
0, region.getMinimumPoint().getZ()
+ (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2);
- WorldUtil.IMP
- .getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y -> {
- center.setY(1 + y);
- player.teleport(center, TeleportCause.COMMAND);
- });
+ this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y ->
+ player.teleport(center.withY(1 + y), TeleportCause.COMMAND));
}
return true;
case "delete":
case "remove":
MainUtil.sendMessage(player,
"$1World creation settings may be stored in multiple locations:"
- + "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2" + PlotSquared.imp()
+ + "\n$3 - $2Bukkit bukkit.yml" + "\n$3 - $2" + PlotSquared.platform()
.getPluginName() + " settings.yml"
+ "\n$3 - $2Multiverse worlds.yml (or any world management plugin)"
+ "\n$1Stop the server and delete it from these locations.");
diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java
index 0864a502f..81cd9b082 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Auto.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java
@@ -26,6 +26,7 @@
package com.plotsquared.core.command;
import com.google.common.primitives.Ints;
+import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
@@ -41,7 +42,9 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.EconHandler;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
@@ -50,6 +53,8 @@ import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import net.kyori.adventure.text.minimessage.Template;
import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Set;
@@ -63,6 +68,18 @@ import java.util.Set;
usage = "/plot auto [length,width]")
public class Auto extends SubCommand {
+ private final PlotAreaManager plotAreaManager;
+ private final EventDispatcher eventDispatcher;
+ private final EconHandler econHandler;
+
+ @Inject public Auto(@Nonnull final PlotAreaManager plotAreaManager,
+ @Nonnull final EventDispatcher eventDispatcher,
+ @Nullable final EconHandler econHandler) {
+ this.plotAreaManager = plotAreaManager;
+ this.eventDispatcher = eventDispatcher;
+ this.econHandler = econHandler;
+ }
+
@Deprecated public static PlotId getNextPlotId(PlotId id, int step) {
return id.getNextId(step);
}
@@ -139,7 +156,8 @@ public class Auto extends SubCommand {
player.setMeta(Auto.class.getName(), true);
autoClaimFromDatabase(player, area, start, new RunnableVal() {
@Override public void run(final Plot plot) {
- TaskManager.IMP.sync(new AutoClaimFinishTask(player, plot, area, schematic));
+ TaskManager.getImplementation().sync(new AutoClaimFinishTask(player, plot, area, schematic,
+ PlotSquared.get().getEventDispatcher()));
}
});
}
@@ -160,10 +178,9 @@ public class Auto extends SubCommand {
@Override public boolean onCommand(final PlotPlayer> player, String[] args) {
PlotArea plotarea = player.getApplicablePlotArea();
if (plotarea == null) {
- if (EconHandler.getEconHandler() != null) {
- for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
- if (EconHandler.getEconHandler()
- .hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
+ if (this.econHandler != null) {
+ for (PlotArea area : this.plotAreaManager.getAllPlotAreas()) {
+ if (this.econHandler.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
if (plotarea != null) {
plotarea = null;
break;
@@ -172,8 +189,8 @@ public class Auto extends SubCommand {
}
}
}
- if (PlotSquared.get().getPlotAreaManager().getAllPlotAreas().length == 1) {
- plotarea = PlotSquared.get().getPlotAreaManager().getAllPlotAreas()[0];
+ if (this.plotAreaManager.getAllPlotAreas().length == 1) {
+ plotarea = this.plotAreaManager.getAllPlotAreas()[0];
}
if (plotarea == null) {
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
@@ -216,7 +233,7 @@ public class Auto extends SubCommand {
// return false;
}
}
- PlayerAutoPlotEvent event = PlotSquared.get().getEventDispatcher()
+ PlayerAutoPlotEvent event = this.eventDispatcher
.callAuto(player, plotarea, schematic, size_x, size_z);
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Auto claim");
@@ -256,18 +273,18 @@ public class Auto extends SubCommand {
return true;
}
}
- if (EconHandler.getEconHandler() != null && plotarea.useEconomy()) {
+ if (this.econHandler != null && plotarea.useEconomy()) {
Expression costExp = plotarea.getPrices().get("claim");
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
player.getPlotCount() :
player.getPlotCount(plotarea.getWorldName())));
cost = (size_x * size_z) * cost;
if (cost > 0d) {
- if (!force && EconHandler.getEconHandler().getMoney(player) < cost) {
+ if (!force && this.econHandler.getMoney(player) < cost) {
sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
- EconHandler.getEconHandler().withdrawMoney(player, cost);
+ this.econHandler.withdrawMoney(player, cost);
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
}
@@ -297,7 +314,7 @@ public class Auto extends SubCommand {
}
ArrayList plotIds = MainUtil.getPlotSelectionIds(start, end);
final PlotId pos1 = plotIds.get(0);
- final PlotAutoMergeEvent mergeEvent = PlotSquared.get().getEventDispatcher()
+ final PlotAutoMergeEvent mergeEvent = this.eventDispatcher
.callAutoMerge(plotarea.getPlotAbs(pos1), plotIds);
if (!force && mergeEvent.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Auto merge");
diff --git a/Core/src/main/java/com/plotsquared/core/command/Backup.java b/Core/src/main/java/com/plotsquared/core/command/Backup.java
index 944eaaf6b..4c16458c6 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Backup.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java
@@ -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 javax.annotation.Nonnull;
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(@Nonnull 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.imp()).getBackupManager().getProfile(plot);
+ final BackupProfile backupProfile = Objects.requireNonNull(this.backupManager.getProfile(plot));
if (backupProfile instanceof PlayerBackupProfile) {
final CompletableFuture> 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.imp()).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.imp()).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.imp()).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());
diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java
index 337801385..f62f24bc2 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Buy.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java
@@ -25,6 +25,7 @@
*/
package com.plotsquared.core.command;
+import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.events.PlotFlagRemoveEvent;
@@ -34,10 +35,13 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
import com.plotsquared.core.util.EconHandler;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
+import javax.annotation.Nullable;
+import javax.annotation.Nonnull;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -49,8 +53,14 @@ import java.util.concurrent.CompletableFuture;
requiredType = RequiredType.NONE)
public class Buy extends Command {
- public Buy() {
+ private final EventDispatcher eventDispatcher;
+ private final EconHandler econHandler;
+
+ @Inject public Buy(@Nonnull final EventDispatcher eventDispatcher,
+ @Nullable final EconHandler econHandler) {
super(MainCommand.getInstance(), true);
+ this.eventDispatcher = eventDispatcher;
+ this.econHandler = econHandler;
}
@Override
@@ -58,7 +68,7 @@ public class Buy extends Command {
RunnableVal3 confirm,
final RunnableVal2 whenDone) {
- check(EconHandler.getEconHandler(), Captions.ECON_DISABLED);
+ check(this.econHandler, Captions.ECON_DISABLED);
final Plot plot;
if (args.length != 0) {
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
@@ -82,15 +92,14 @@ public class Buy extends Command {
confirm.run(this, () -> {
Captions.REMOVED_BALANCE.send(player, price);
- EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
+ this.econHandler.depositMoney(PlotSquared.platform().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
- PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
+ PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
if (owner != null) {
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
}
PlotFlag, ?> plotFlag = plot.getFlagContainer().getFlag(PriceFlag.class);
- PlotFlagRemoveEvent event =
- PlotSquared.get().getEventDispatcher().callFlagRemove(plotFlag, plot);
+ PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Caps.java b/Core/src/main/java/com/plotsquared/core/command/Caps.java
index b56d33dc0..55efd2519 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Caps.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Caps.java
@@ -71,7 +71,7 @@ public class Caps extends SubCommand {
}
private > void sendFormatted(final Plot plot,
- final PlotPlayer player, final Class capFlag, final int[] countedEntities,
+ final PlotPlayer> player, final Class capFlag, final int[] countedEntities,
final String name, final int type) {
final int current = countedEntities[type];
final int max = plot.getFlag(capFlag);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java
index 481a25bf5..7b51ea6cf 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Claim.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java
@@ -26,6 +26,7 @@
package com.plotsquared.core.command;
import com.google.common.primitives.Ints;
+import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
@@ -40,10 +41,15 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.EconHandler;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@CommandDeclaration(command = "claim",
aliases = "c",
@@ -54,18 +60,28 @@ import com.plotsquared.core.util.task.TaskManager;
usage = "/plot claim")
public class Claim extends SubCommand {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + Claim.class.getSimpleName());
+
+ private final EventDispatcher eventDispatcher;
+ private final EconHandler econHandler;
+
+ @Inject public Claim(@Nonnull final EventDispatcher eventDispatcher,
+ @Nullable final EconHandler econHandler) {
+ this.eventDispatcher = eventDispatcher;
+ this.econHandler = econHandler;
+ }
+
@Override public boolean onCommand(final PlotPlayer> player, String[] args) {
String schematic = null;
if (args.length >= 1) {
schematic = args[0];
}
Location location = player.getLocation();
- final Plot plot = location.getPlotAbs();
+ Plot plot = location.getPlotAbs();
if (plot == null) {
return sendMessage(player, Captions.NOT_IN_PLOT);
}
- PlayerClaimPlotEvent event =
- PlotSquared.get().getEventDispatcher().callClaim(player, plot, schematic);
+ final PlayerClaimPlotEvent event = this.eventDispatcher.callClaim(player, plot, schematic);
schematic = event.getSchematic();
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Claim");
@@ -74,7 +90,7 @@ public class Claim extends SubCommand {
boolean force = event.getEventResult() == Result.FORCE;
int currentPlots = Settings.Limit.GLOBAL ?
player.getPlotCount() :
- player.getPlotCount(location.getWorld());
+ player.getPlotCount(location.getWorldName());
int grants = 0;
if (currentPlots >= player.getAllowedPlots() && !force) {
if (player.hasPersistentMeta("grantedPlots")) {
@@ -105,14 +121,14 @@ public class Claim extends SubCommand {
}
}
}
- if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) {
+ if ((this.econHandler != null) && area.useEconomy() && !force) {
Expression costExr = area.getPrices().get("claim");
double cost = costExr.evaluate((double) currentPlots);
if (cost > 0d) {
- if (EconHandler.getEconHandler().getMoney(player) < cost) {
+ if (this.econHandler.getMoney(player) < cost) {
return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
}
- EconHandler.getEconHandler().withdrawMoney(player, cost);
+ this.econHandler.withdrawMoney(player, cost);
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
}
@@ -130,15 +146,15 @@ public class Claim extends SubCommand {
}
plot.setOwnerAbs(player.getUUID());
final String finalSchematic = schematic;
- DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal
*/
- @NotNull @Override public ConfigurationNode[] getSettingNodes() {
+ @Nonnull @Override public ConfigurationNode[] getSettingNodes() {
return new ConfigurationNode[] {
new ConfigurationNode("plot.height", this.PLOT_HEIGHT, "Plot height",
ConfigurationUtil.INTEGER),
diff --git a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java
index 8b753b170..108796e45 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java
@@ -25,16 +25,23 @@
*/
package com.plotsquared.core.generator;
+import com.plotsquared.core.configuration.file.YamlConfiguration;
+import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
-import org.jetbrains.annotations.NotNull;
+import com.plotsquared.core.queue.GlobalBlockQueue;
+import com.plotsquared.core.util.EconHandler;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
public abstract class GridPlotWorld extends PlotArea {
public short SIZE;
- public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
- PlotId min, PlotId max) {
- super(worldName, id, generator, min, max);
+ public GridPlotWorld(String worldName, String id, @Nonnull IndependentPlotGenerator generator,
+ PlotId min, PlotId max, @WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
+ @Nonnull final GlobalBlockQueue blockQueue,
+ @Nullable final EconHandler econHandler) {
+ super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java
index a4f955682..2560981ab 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java
@@ -26,8 +26,10 @@
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.configuration.Settings;
+import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
@@ -36,12 +38,18 @@ import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HybridGen extends IndependentPlotGenerator {
+ private final HybridPlotWorldFactory hybridPlotWorldFactory;
+
+ @Inject public HybridGen(@Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory) {
+ this.hybridPlotWorldFactory = hybridPlotWorldFactory;
+ }
+
@Override public String getName() {
- return PlotSquared.imp().getPluginName();
+ return PlotSquared.platform().getPluginName();
}
private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX,
@@ -68,7 +76,7 @@ public class HybridGen extends IndependentPlotGenerator {
}
@Override
- public void generateChunk(@NotNull ScopedLocalBlockQueue result, @NotNull PlotArea settings) {
+ public void generateChunk(@Nonnull ScopedLocalBlockQueue result, @Nonnull PlotArea settings) {
Preconditions.checkNotNull(result, "result cannot be null");
Preconditions.checkNotNull(settings, "settings cannot be null");
@@ -221,7 +229,7 @@ public class HybridGen extends IndependentPlotGenerator {
}
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
- return new HybridPlotWorld(world, id, this, min, max);
+ return this.hybridPlotWorldFactory.create(world, id, this, min, max);
}
@Override public void initialize(PlotArea area) {
diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java
index da4fa74b9..e7fd298a0 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotManager.java
@@ -34,7 +34,6 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
-import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.FileBytes;
@@ -48,6 +47,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import lombok.Getter;
+import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
@@ -59,10 +59,13 @@ public class HybridPlotManager extends ClassicPlotManager {
public static boolean REGENERATIVE_CLEAR = true;
@Getter private final HybridPlotWorld hybridPlotWorld;
+ private final RegionManager regionManager;
- public HybridPlotManager(HybridPlotWorld hybridPlotWorld) {
- super(hybridPlotWorld);
+ public HybridPlotManager(@Nonnull final HybridPlotWorld hybridPlotWorld,
+ @Nonnull final RegionManager regionManager) {
+ super(hybridPlotWorld, regionManager);
this.hybridPlotWorld = hybridPlotWorld;
+ this.regionManager = regionManager;
}
@Override public void exportTemplate() throws IOException {
@@ -74,7 +77,7 @@ public class HybridPlotManager extends ClassicPlotManager {
.getWorldName() + File.separator;
try {
File sideRoad =
- MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schem");
+ MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "sideroad.schem");
String newDir = "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator
+ "__TEMP_DIR__" + File.separator;
if (sideRoad.exists()) {
@@ -82,12 +85,12 @@ public class HybridPlotManager extends ClassicPlotManager {
Files.readAllBytes(sideRoad.toPath())));
}
File intersection =
- MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "intersection.schem");
+ MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "intersection.schem");
if (intersection.exists()) {
files.add(new FileBytes(newDir + "intersection.schem",
Files.readAllBytes(intersection.toPath())));
}
- File plot = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "plot.schem");
+ File plot = MainUtil.getFile(PlotSquared.platform().getDirectory(), dir + "plot.schem");
if (plot.exists()) {
files.add(new FileBytes(newDir + "plot.schem", Files.readAllBytes(plot.toPath())));
}
@@ -103,9 +106,8 @@ public class HybridPlotManager extends ClassicPlotManager {
PlotId id2 = new PlotId(id.x + 1, id.y);
Location bot = getPlotBottomLocAbs(id2);
Location top = getPlotTopLocAbs(id);
- Location pos1 =
- new Location(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1);
- Location pos2 = new Location(hybridPlotWorld.getWorldName(), bot.getX(),
+ Location pos1 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1, 0, bot.getZ() - 1);
+ Location pos2 = Location.at(hybridPlotWorld.getWorldName(), bot.getX(),
Math.min(getWorldHeight(), 255), top.getZ() + 1);
MainUtil.resetBiome(hybridPlotWorld, pos1, pos2);
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
@@ -165,9 +167,8 @@ public class HybridPlotManager extends ClassicPlotManager {
PlotId id2 = new PlotId(id.x, id.y + 1);
Location bot = getPlotBottomLocAbs(id2);
Location top = getPlotTopLocAbs(id);
- Location pos1 =
- new Location(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1);
- Location pos2 = new Location(hybridPlotWorld.getWorldName(), top.getX() + 1,
+ Location pos1 = Location.at(hybridPlotWorld.getWorldName(), bot.getX() - 1, 0, top.getZ() + 1);
+ Location pos2 = Location.at(hybridPlotWorld.getWorldName(), top.getX() + 1,
Math.min(getWorldHeight(), 255), bot.getZ());
MainUtil.resetBiome(hybridPlotWorld, pos1, pos2);
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
@@ -183,10 +184,8 @@ public class HybridPlotManager extends ClassicPlotManager {
super.createRoadSouthEast(plot);
PlotId id = plot.getId();
PlotId id2 = new PlotId(id.x + 1, id.y + 1);
- Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1);
- Location pos2 = getPlotBottomLocAbs(id2);
- pos1.setY(0);
- pos2.setY(Math.min(getWorldHeight(), 255));
+ Location pos1 = getPlotTopLocAbs(id).add(1, 0, 1).withY(0);
+ Location pos2 = getPlotBottomLocAbs(id2).withY(Math.min(getWorldHeight(), 255));
LocalBlockQueue queue = hybridPlotWorld.getQueue(false);
createSchemAbs(queue, pos1, pos2, true);
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
@@ -203,9 +202,9 @@ public class HybridPlotManager extends ClassicPlotManager {
*
*/
@Override public boolean clearPlot(Plot plot, final Runnable whenDone) {
- if (RegionManager.manager.notifyClear(this)) {
+ if (this.regionManager.notifyClear(this)) {
//If this returns false, the clear didn't work
- if (RegionManager.manager.handleClear(plot, whenDone, this)) {
+ if (this.regionManager.handleClear(plot, whenDone, this)) {
return true;
}
}
@@ -241,18 +240,18 @@ public class HybridPlotManager extends ClassicPlotManager {
// Set the biome
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], biome);
// These two locations are for each component (e.g. bedrock, main block, floor, air)
- Location bot = new Location(world, value[2], 0, value[3]);
- Location top = new Location(world, value[4], 1, value[5]);
+ Location bot = Location.at(world, value[2], 0, value[3]);
+ Location top = Location.at(world, value[4], 1, value[5]);
queue.setCuboid(bot, top, bedrock);
// Each component has a different layer
- bot.setY(1);
- top.setY(hybridPlotWorld.PLOT_HEIGHT);
+ bot = bot.withY(1);
+ top = top.withY(hybridPlotWorld.PLOT_HEIGHT);
queue.setCuboid(bot, top, filling);
- bot.setY(hybridPlotWorld.PLOT_HEIGHT);
- top.setY(hybridPlotWorld.PLOT_HEIGHT + 1);
+ bot = bot.withY(hybridPlotWorld.PLOT_HEIGHT);
+ top = top.withY(hybridPlotWorld.PLOT_HEIGHT + 1);
queue.setCuboid(bot, top, plotfloor);
- bot.setY(hybridPlotWorld.PLOT_HEIGHT + 1);
- top.setY(getWorldHeight());
+ bot = bot.withY(hybridPlotWorld.PLOT_HEIGHT + 1);
+ top = top.withY(getWorldHeight());
queue.setCuboid(bot, top, air);
// And finally set the schematic, the y value is unimportant for this function
pastePlotSchematic(queue, bot, top);
@@ -260,7 +259,7 @@ public class HybridPlotManager extends ClassicPlotManager {
}, () -> {
queue.enqueue();
// And notify whatever called this when plot clearing is done
- GlobalBlockQueue.IMP.addEmptyTask(whenDone);
+ PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone);
}, 10);
return true;
}
diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java
index a561a9ac3..a4a0d3a28 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java
@@ -25,18 +25,23 @@
*/
package com.plotsquared.core.generator;
+import com.google.inject.assistedinject.Assisted;
import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings;
+import com.plotsquared.core.configuration.file.YamlConfiguration;
+import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.plot.schematic.Schematic;
+import com.plotsquared.core.queue.GlobalBlockQueue;
+import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
+import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
@@ -51,8 +56,12 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
import lombok.Getter;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.inject.Inject;
import java.io.File;
import java.lang.reflect.Field;
import java.util.HashMap;
@@ -60,7 +69,8 @@ import java.util.Locale;
public class HybridPlotWorld extends ClassicPlotWorld {
- private static AffineTransform transform = new AffineTransform().rotateY(90);
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + HybridPlotWorld.class.getSimpleName());
+ private static final AffineTransform transform = new AffineTransform().rotateY(90);
public boolean ROAD_SCHEMATIC_ENABLED;
public boolean PLOT_SCHEMATIC = false;
public int PLOT_SCHEMATIC_HEIGHT = -1;
@@ -72,9 +82,22 @@ public class HybridPlotWorld extends ClassicPlotWorld {
private Location SIGN_LOCATION;
@Getter private File root = null;
- public HybridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
- PlotId min, PlotId max) {
- super(worldName, id, generator, min, max);
+ private final RegionManager regionManager;
+ private final SchematicHandler schematicHandler;
+
+ @Inject public HybridPlotWorld(@Assisted("world") final String worldName,
+ @Nullable @Assisted("id") final String id,
+ @Assisted @Nonnull final IndependentPlotGenerator generator,
+ @Nullable @Assisted("min") final PlotId min,
+ @Nullable @Assisted("max") final PlotId max,
+ @WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
+ @Nonnull final RegionManager regionManager,
+ @Nonnull final SchematicHandler schematicHandler,
+ @Nonnull final GlobalBlockQueue blockQueue,
+ @Nullable final EconHandler econHandler) {
+ super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler);
+ this.regionManager = regionManager;
+ this.schematicHandler = schematicHandler;
}
public static byte wrap(byte data, int start) {
@@ -124,19 +147,17 @@ public class HybridPlotWorld extends ClassicPlotWorld {
return BlockTransformExtent.transform(id, transform);
}
- @NotNull @Override protected PlotManager createManager() {
- return new HybridPlotManager(this);
+ @Nonnull @Override protected PlotManager createManager() {
+ return new HybridPlotManager(this, this.regionManager);
}
- public Location getSignLocation(Plot plot) {
+ public Location getSignLocation(@Nonnull Plot plot) {
plot = plot.getBasePlot(false);
- Location bot = plot.getBottomAbs();
+ final Location bot = plot.getBottomAbs();
if (SIGN_LOCATION == null) {
- bot.setY(ROAD_HEIGHT + 1);
- return bot.add(-1, 0, -2);
+ return bot.withY(ROAD_HEIGHT + 1).add(-1, 0, -2);
} else {
- bot.setY(0);
- return bot.add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ());
+ return bot.withY(0).add(SIGN_LOCATION.getX(), SIGN_LOCATION.getY(), SIGN_LOCATION.getZ());
}
}
@@ -160,13 +181,11 @@ public class HybridPlotWorld extends ClassicPlotWorld {
setupSchematics();
} catch (Exception event) {
event.printStackTrace();
- PlotSquared.debug("&c - road schematics are disabled for this world.");
}
// Dump world settings
if (Settings.DEBUG) {
- PlotSquared.debug(String.format("- Dumping settings for ClassicPlotWorld with name %s",
- this.getWorldName()));
+ logger.info("[P2] - Dumping settings for ClassicPlotWorld with name {}", this.getWorldName());
final Field[] fields = this.getClass().getFields();
for (final Field field : fields) {
final String name = field.getName().toLowerCase(Locale.ENGLISH);
@@ -182,12 +201,12 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} catch (final IllegalAccessException e) {
value = String.format("Failed to parse: %s", e.getMessage());
}
- PlotSquared.debug(String.format("-- %s = %s", name, value));
+ logger.info("[P2] -- {} = {}", name, value);
}
}
}
- @Override public boolean isCompatible(PlotArea plotArea) {
+ @Override public boolean isCompatible(@Nonnull final PlotArea plotArea) {
if (!(plotArea instanceof SquarePlotWorld)) {
return false;
}
@@ -200,9 +219,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
// Try to determine root. This means that plot areas can have separate schematic
// directories
- if (!(root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" +
+ if (!(root = MainUtil.getFile(PlotSquared.platform().getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" +
this.getWorldName() + "/" + this.getId())).exists()) {
- root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
+ root = MainUtil.getFile(PlotSquared.platform().getDirectory(),
"schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName());
}
@@ -215,9 +234,9 @@ public class HybridPlotWorld extends ClassicPlotWorld {
File schematic3File = new File(root, "plot.schem");
if (!schematic3File.exists())
schematic3File = new File(root, "plot.schematic");
- Schematic schematic1 = SchematicHandler.manager.getSchematic(schematic1File);
- Schematic schematic2 = SchematicHandler.manager.getSchematic(schematic2File);
- Schematic schematic3 = SchematicHandler.manager.getSchematic(schematic3File);
+ Schematic schematic1 = this.schematicHandler.getSchematic(schematic1File);
+ Schematic schematic2 = this.schematicHandler.getSchematic(schematic2File);
+ Schematic schematic3 = this.schematicHandler.getSchematic(schematic3File);
int shift = this.ROAD_WIDTH / 2;
int oddshift = (this.ROAD_WIDTH & 1) == 0 ? 0 : 1;
@@ -282,10 +301,14 @@ public class HybridPlotWorld extends ClassicPlotWorld {
}
}
- PlotSquared.debug(Captions.PREFIX + "&3 - plot schematic: &7" + schematic3File.getPath());
+ if (Settings.DEBUG) {
+ logger.info("[P2] - plot schematic: {}", schematic3File.getPath());
+ }
}
if (schematic1 == null || schematic2 == null || this.ROAD_WIDTH == 0) {
- PlotSquared.debug(Captions.PREFIX + "&3 - schematic: &7false");
+ if (Settings.DEBUG) {
+ logger.info("[P2] - schematic: false");
+ }
return;
}
this.ROAD_SCHEMATIC_ENABLED = true;
@@ -361,7 +384,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
int pair = MathMan.pair(x, z);
BaseBlock[] existing = this.G_SCH.computeIfAbsent(pair, k -> new BaseBlock[height]);
if (y >= height) {
- PlotSquared.log("Error adding overlay block. `y > height` ");
+ logger.error("[P2] Error adding overlay block. `y > height`");
return;
}
existing[y] = id;
diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java
index 539e9e1cd..30586db05 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/HybridUtils.java
@@ -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;
@@ -40,6 +41,7 @@ import com.plotsquared.core.plot.expiration.PlotAnalysis;
import com.plotsquared.core.plot.flag.GlobalFlagContainer;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.queue.ChunkBlockQueue;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
@@ -61,6 +63,9 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
import java.io.File;
import java.util.ArrayDeque;
@@ -74,7 +79,9 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-public abstract class HybridUtils {
+public class HybridUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + HybridUtils.class.getSimpleName());
public static HybridUtils manager;
public static Set regions;
@@ -83,9 +90,27 @@ public abstract class HybridUtils {
public static PlotArea area;
public static boolean UPDATE = false;
- public static boolean regeneratePlotWalls(final PlotArea area) {
+ private final PlotAreaManager plotAreaManager;
+ private final ChunkManager chunkManager;
+ private final GlobalBlockQueue blockQueue;
+ private final WorldUtil worldUtil;
+ private final RegionManager regionManager;
+ private final SchematicHandler schematicHandler;
+
+ @Inject public HybridUtils(@Nonnull final PlotAreaManager plotAreaManager,
+ @Nonnull final ChunkManager chunkManager, @Nonnull final GlobalBlockQueue blockQueue,
+ @Nonnull final WorldUtil worldUtil, @Nonnull final RegionManager regionManager, @Nonnull final SchematicHandler schematicHandler) {
+ this.plotAreaManager = plotAreaManager;
+ this.chunkManager = chunkManager;
+ this.blockQueue = blockQueue;
+ this.worldUtil = worldUtil;
+ this.regionManager = regionManager;
+ this.schematicHandler = schematicHandler;
+ }
+
+ public void regeneratePlotWalls(final PlotArea area) {
PlotManager plotManager = area.getPlotManager();
- return plotManager.regenerateAllPlotWalls();
+ plotManager.regenerateAllPlotWalls();
}
public void analyzeRegion(final String world, final CuboidRegion region,
@@ -103,7 +128,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();
@@ -120,7 +145,7 @@ public abstract class HybridUtils {
final int width = tx - bx + 1;
final int length = tz - bz + 1;
- PlotArea area = PlotSquared.get().getPlotArea(world, null);
+ final PlotArea area = this.plotAreaManager.getPlotArea(world, null);
if (!(area instanceof HybridPlotWorld)) {
return;
@@ -227,8 +252,8 @@ public abstract class HybridUtils {
});
System.gc();
MainUtil.initCache();
- Location botLoc = new Location(world, bot.getX(), bot.getY(), bot.getZ());
- Location topLoc = new Location(world, top.getX(), top.getY(), top.getZ());
+ Location botLoc = Location.at(world, bot.getX(), bot.getY(), bot.getZ());
+ Location topLoc = Location.at(world, top.getX(), top.getY(), top.getZ());
ChunkManager.chunkTask(botLoc, topLoc, new RunnableVal() {
@Override public void run(int[] value) {
int X = value[0];
@@ -357,7 +382,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++;
}
@@ -384,7 +409,7 @@ public abstract class HybridUtils {
return false;
}
HybridUtils.UPDATE = true;
- Set regions = RegionManager.manager.getChunkChunks(area.getWorldName());
+ Set regions = this.regionManager.getChunkChunks(area.getWorldName());
return scheduleRoadUpdate(area, regions, extend, new HashSet<>());
}
@@ -413,24 +438,25 @@ public abstract class HybridUtils {
BlockVector2 chunk = iter.next();
iter.remove();
boolean regenedRoad = regenerateRoad(area, chunk, extend);
- if (!regenedRoad) {
- PlotSquared.debug("Failed to regenerate roads.");
+ if (!regenedRoad && Settings.DEBUG) {
+ logger.info("[P2] Failed to regenerate roads");
}
- ChunkManager.manager.unloadChunk(area.getWorldName(), chunk, true);
+ chunkManager.unloadChunk(area.getWorldName(), chunk, true);
+ }
+ if (Settings.DEBUG) {
+ logger.info("[P2] Cancelled road task");
}
- PlotSquared.debug("Cancelled road task");
return;
}
count.incrementAndGet();
if (count.intValue() % 20 == 0) {
- PlotSquared.debug("PROGRESS: " + 100 * (2048 - chunks.size()) / 2048 + "%");
+ logger.info("[P2] Progress: {}%", 100 * (2048 - chunks.size()) / 2048);
}
if (HybridUtils.regions.isEmpty() && chunks.isEmpty()) {
- PlotSquared.debug("Regenerating plot walls");
regeneratePlotWalls(area);
HybridUtils.UPDATE = false;
- PlotSquared.log("Finished road conversion");
+ logger.info("[P2] Finished road conversion");
// CANCEL TASK
} else {
final Runnable task = this;
@@ -442,17 +468,17 @@ public abstract class HybridUtils {
HybridUtils.regions.iterator();
BlockVector2 loc = iterator.next();
iterator.remove();
- PlotSquared.debug(
- "Updating .mcr: " + loc.getX() + ", " + loc.getZ()
- + " (approx 1024 chunks)");
- PlotSquared
- .debug(" - Remaining: " + HybridUtils.regions.size());
+ if (Settings.DEBUG) {
+ logger.info("[P2] Updating .mcr: {}, {} (approx 1024 chunks)",
+ loc.getX(), loc.getZ());
+ logger.info("[P2] - Remaining: {}", HybridUtils.regions.size());
+ }
chunks.addAll(getChunks(loc));
System.gc();
}
}
if (!chunks.isEmpty()) {
- TaskManager.IMP.sync(new RunnableVal() {
+ TaskManager.getImplementation().sync(new RunnableVal() {
@Override public void run(Object value) {
long start = System.currentTimeMillis();
Iterator iterator = chunks.iterator();
@@ -462,8 +488,8 @@ public abstract class HybridUtils {
iterator.remove();
boolean regenedRoads =
regenerateRoad(area, chunk, extend);
- if (!regenedRoads) {
- PlotSquared.debug("Failed to regenerate road.");
+ if (!regenedRoads && Settings.DEBUG) {
+ logger.info("[P2] Failed to regenerate road");
}
}
}
@@ -474,22 +500,18 @@ public abstract class HybridUtils {
Iterator iterator = HybridUtils.regions.iterator();
BlockVector2 loc = iterator.next();
iterator.remove();
- PlotSquared.debug(
- "[ERROR] Could not update '" + area.getWorldName() + "/region/r."
- + loc.getX() + "." + loc.getZ() + ".mca' (Corrupt chunk?)");
+ logger.error("[P2] Error! Could not update '{}/region/r.{}.{}.mca' (Corrupt chunk?)",
+ area.getWorldHash(), loc.getX(), loc.getZ());
int sx = loc.getX() << 5;
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));
});
}
}
@@ -499,7 +521,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();
@@ -523,13 +545,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() {
+ this.schematicHandler.getCompoundTag(world, sideRoad, new RunnableVal() {
@Override public void run(CompoundTag value) {
- SchematicHandler.manager.save(value, dir + "sideroad.schem");
- SchematicHandler.manager
- .getCompoundTag(world, intersection, new RunnableVal() {
+ schematicHandler.save(value, dir + "sideroad.schem");
+ schematicHandler.getCompoundTag(world, intersection, new RunnableVal() {
@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();
@@ -587,9 +608,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()) {
diff --git a/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java
index 324f6d8d4..c42e54546 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/IndependentPlotGenerator.java
@@ -31,7 +31,6 @@ import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.setup.PlotAreaBuilder;
-import com.plotsquared.core.setup.SetupProcess;
/**
* This class allows for implementation independent world generation.
@@ -104,7 +103,7 @@ public abstract class IndependentPlotGenerator {
* @return
*/
public GeneratorWrapper specify(String world) {
- return (GeneratorWrapper) PlotSquared.get().IMP.wrapPlotGenerator(world, this);
+ return (GeneratorWrapper) PlotSquared.platform().wrapPlotGenerator(world, this);
}
@Override public String toString() {
diff --git a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java
index eb2037def..7e2f164d3 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/SingleWorldGenerator.java
@@ -25,23 +25,32 @@
*/
package com.plotsquared.core.generator;
-import com.plotsquared.core.PlotSquared;
+import com.google.inject.Inject;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockTypes;
+import javax.annotation.Nonnull;
public class SingleWorldGenerator extends IndependentPlotGenerator {
- private Location bedrock1 = new Location(null, 0, 0, 0);
- private Location bedrock2 = new Location(null, 15, 0, 15);
- private Location dirt1 = new Location(null, 0, 1, 0);
- private Location dirt2 = new Location(null, 15, 2, 15);
- private Location grass1 = new Location(null, 0, 3, 0);
- private Location grass2 = new Location(null, 15, 3, 15);
+
+ private static final Location bedrock1 = Location.at("", 0, 0, 0);
+ private static final Location bedrock2 = Location.at("", 15, 0, 15);
+ private static final Location dirt1 = Location.at("", 0, 1, 0);
+ private static final Location dirt2 = Location.at("", 15, 2, 15);
+ private static final Location grass1 = Location.at("", 0, 3, 0);
+ private static final Location grass2 = Location.at("", 15, 3, 15);
+
+ private final PlotAreaManager plotAreaManager;
+
+ @Inject public SingleWorldGenerator(@Nonnull final PlotAreaManager plotAreaManager) {
+ this.plotAreaManager = plotAreaManager;
+ }
@Override public String getName() {
return "PlotSquared:single";
@@ -63,10 +72,10 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
}
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
- return ((SinglePlotAreaManager) PlotSquared.get().getPlotAreaManager()).getArea();
+ return ((SinglePlotAreaManager) this.plotAreaManager).getArea();
}
@Override public void initialize(PlotArea area) {
-
}
+
}
diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java
index 9dbd2c611..27e093f1b 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotManager.java
@@ -25,7 +25,6 @@
*/
package com.plotsquared.core.generator;
-import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.location.Direction;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot;
@@ -34,8 +33,10 @@ import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.RegionManager;
import com.sk89q.worldedit.regions.CuboidRegion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
-import java.util.Arrays;
import java.util.Iterator;
import java.util.Set;
@@ -44,11 +45,15 @@ import java.util.Set;
*/
public abstract class SquarePlotManager extends GridPlotManager {
- private final SquarePlotWorld squarePlotWorld;
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + SquarePlotManager.class.getSimpleName());
- public SquarePlotManager(SquarePlotWorld squarePlotWorld) {
+ private final SquarePlotWorld squarePlotWorld;
+ private final RegionManager regionManager;
+
+ public SquarePlotManager(@Nonnull final SquarePlotWorld squarePlotWorld, @Nonnull final RegionManager regionManager) {
super(squarePlotWorld);
this.squarePlotWorld = squarePlotWorld;
+ this.regionManager = regionManager;
}
@Override public boolean clearPlot(final Plot plot, final Runnable whenDone) {
@@ -62,11 +67,9 @@ public abstract class SquarePlotManager extends GridPlotManager {
Iterator iterator = regions.iterator();
CuboidRegion region = iterator.next();
iterator.remove();
- Location pos1 = new Location(plot.getWorldName(), region.getMinimumPoint().getX(),
- region.getMinimumPoint().getY(), region.getMinimumPoint().getZ());
- Location pos2 = new Location(plot.getWorldName(), region.getMaximumPoint().getX(),
- region.getMaximumPoint().getY(), region.getMaximumPoint().getZ());
- RegionManager.manager.regenerateRegion(pos1, pos2, false, this);
+ final Location pos1 = Location.at(plot.getWorldName(), region.getMinimumPoint());
+ final Location pos2 = Location.at(plot.getWorldName(), region.getMaximumPoint());
+ regionManager.regenerateRegion(pos1, pos2, false, this);
}
};
run.run();
@@ -80,7 +83,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
+ squarePlotWorld.PLOT_WIDTH))) - (int) Math.floor(squarePlotWorld.ROAD_WIDTH / 2) - 1;
int z = (squarePlotWorld.ROAD_OFFSET_Z + (pz * (squarePlotWorld.ROAD_WIDTH
+ squarePlotWorld.PLOT_WIDTH))) - (int) Math.floor(squarePlotWorld.ROAD_WIDTH / 2) - 1;
- return new Location(squarePlotWorld.getWorldName(), x, Math.min(getWorldHeight(), 255), z);
+ return Location.at(squarePlotWorld.getWorldName(), x, Math.min(getWorldHeight(), 255), z);
}
@Override public PlotId getPlotIdAbs(int x, int y, int z) {
@@ -226,11 +229,9 @@ public abstract class SquarePlotManager extends GridPlotManager {
// northwest
return plot.getMerged(Direction.NORTHWEST) ? id : null;
}
- PlotSquared.debug("invalid location: " + Arrays.toString(merged));
} catch (Exception ignored) {
- PlotSquared.debug(
- "Invalid plot / road width in settings.yml for world: " + squarePlotWorld
- .getWorldName());
+ logger.error( "Invalid plot / road width in settings.yml for world: {}", squarePlotWorld
+ .getWorldName());
}
return null;
}
@@ -247,7 +248,6 @@ public abstract class SquarePlotManager extends GridPlotManager {
int z = (squarePlotWorld.ROAD_OFFSET_Z + (pz * (squarePlotWorld.ROAD_WIDTH
+ squarePlotWorld.PLOT_WIDTH))) - squarePlotWorld.PLOT_WIDTH - (int) Math
.floor(squarePlotWorld.ROAD_WIDTH / 2);
- return new Location(squarePlotWorld.getWorldName(), x, squarePlotWorld.getMinBuildHeight(),
- z);
+ return Location.at(squarePlotWorld.getWorldName(), x, squarePlotWorld.getMinBuildHeight(), z);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java
index 026b13ddc..7215f94c6 100644
--- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java
+++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java
@@ -25,26 +25,44 @@
*/
package com.plotsquared.core.generator;
-import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.ConfigurationSection;
+import com.plotsquared.core.configuration.Settings;
+import com.plotsquared.core.configuration.file.YamlConfiguration;
+import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.plot.PlotId;
-import org.jetbrains.annotations.NotNull;
+import com.plotsquared.core.queue.GlobalBlockQueue;
+import com.plotsquared.core.util.EconHandler;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class SquarePlotWorld extends GridPlotWorld {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + SquarePlotWorld.class.getSimpleName());
+
public int PLOT_WIDTH = 42;
public int ROAD_WIDTH = 7;
public int ROAD_OFFSET_X = 0;
public int ROAD_OFFSET_Z = 0;
- public SquarePlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
- PlotId min, PlotId max) {
- super(worldName, id, generator, min, max);
+ public SquarePlotWorld(final String worldName,
+ @Nullable final String id,
+ @Nonnull final IndependentPlotGenerator generator,
+ @Nullable final PlotId min,
+ @Nullable final PlotId max,
+ @WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
+ @Nonnull final GlobalBlockQueue blockQueue,
+ @Nullable final EconHandler econHandler) {
+ super(worldName, id, generator, min, max, worldConfiguration, blockQueue, econHandler);
}
@Override public void loadConfiguration(ConfigurationSection config) {
if (!config.contains("plot.height")) {
- PlotSquared.debug(" - &cConfiguration is null? (" + config.getCurrentPath() + ')');
+ if (Settings.DEBUG) {
+ logger.info("[P2] - Configuration is null? ({})", config.getCurrentPath());
+ }
+
}
this.PLOT_WIDTH = config.getInt("plot.size");
this.ROAD_WIDTH = config.getInt("road.width");
diff --git a/Core/src/test/java/com/plotsquared/core/plot/object/LocationTest.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/BackgroundPipeline.java
similarity index 69%
rename from Core/src/test/java/com/plotsquared/core/plot/object/LocationTest.java
rename to Core/src/main/java/com/plotsquared/core/inject/annotations/BackgroundPipeline.java
index cef1b4c94..60c6f475e 100644
--- a/Core/src/test/java/com/plotsquared/core/plot/object/LocationTest.java
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/BackgroundPipeline.java
@@ -23,25 +23,17 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package com.plotsquared.core.plot.object;
+package com.plotsquared.core.inject.annotations;
-import com.plotsquared.core.location.Location;
-import org.junit.Test;
+import com.google.inject.BindingAnnotation;
-import java.util.logging.Logger;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
-public class LocationTest {
-
- private static final Logger logger = Logger.getLogger(LocationTest.class.getName());
-
- @Test public void cloning() {
- String world = "plotworld";
- Location location1 = new Location(world, 0, 0, 0);
- logger.info(location1.toString());
- Location clone = location1.clone();
- world = "normal";
- logger.info(clone.toString());
- //location1.getBlockVector3();
-
- }
+@Target({ElementType.PARAMETER, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@BindingAnnotation
+public @interface BackgroundPipeline {
}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/ConfigFile.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConfigFile.java
new file mode 100644
index 000000000..6a8f950f8
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConfigFile.java
@@ -0,0 +1,39 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.annotations;
+
+import com.google.inject.BindingAnnotation;
+
+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)
+@BindingAnnotation
+public @interface ConfigFile {
+}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java
new file mode 100644
index 000000000..41213cc4f
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ConsoleActor.java
@@ -0,0 +1,39 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.annotations;
+
+import com.google.inject.BindingAnnotation;
+
+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)
+@BindingAnnotation
+public @interface ConsoleActor {
+}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java
new file mode 100644
index 000000000..26060efd6
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/DefaultGenerator.java
@@ -0,0 +1,39 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.annotations;
+
+import com.google.inject.BindingAnnotation;
+
+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)
+@BindingAnnotation
+public @interface DefaultGenerator {
+}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/ImpromptuPipeline.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/ImpromptuPipeline.java
new file mode 100644
index 000000000..76caa547e
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/ImpromptuPipeline.java
@@ -0,0 +1,39 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.annotations;
+
+import com.google.inject.BindingAnnotation;
+
+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)
+@BindingAnnotation
+public @interface ImpromptuPipeline {
+}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldConfig.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldConfig.java
new file mode 100644
index 000000000..f7aeb5d54
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldConfig.java
@@ -0,0 +1,39 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.annotations;
+
+import com.google.inject.BindingAnnotation;
+
+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)
+@BindingAnnotation
+public @interface WorldConfig {
+}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldFile.java b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldFile.java
new file mode 100644
index 000000000..4a6518a08
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/annotations/WorldFile.java
@@ -0,0 +1,39 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.annotations;
+
+import com.google.inject.BindingAnnotation;
+
+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)
+@BindingAnnotation
+public @interface WorldFile {
+}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java b/Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java
new file mode 100644
index 000000000..53c446949
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/factory/HybridPlotWorldFactory.java
@@ -0,0 +1,43 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.core.inject.factory;
+
+import com.google.inject.assistedinject.Assisted;
+import com.plotsquared.core.generator.HybridPlotWorld;
+import com.plotsquared.core.generator.IndependentPlotGenerator;
+import com.plotsquared.core.plot.PlotId;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+public interface HybridPlotWorldFactory {
+
+ @Nonnull HybridPlotWorld create(@Nonnull @Assisted("world") String worldName,
+ @Nullable @Assisted("id") String id,
+ @Nonnull IndependentPlotGenerator plotGenerator,
+ @Nullable @Assisted("min") PlotId min,
+ @Nullable @Assisted("max") PlotId max);
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java b/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java
similarity index 80%
rename from Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java
rename to Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java
index 2cf4a3b8b..512a6256f 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitHybridUtils.java
+++ b/Core/src/main/java/com/plotsquared/core/inject/factory/PlayerBackupProfileFactory.java
@@ -23,11 +23,16 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package com.plotsquared.bukkit.generator;
+package com.plotsquared.core.inject.factory;
-import com.plotsquared.core.generator.HybridUtils;
+import com.plotsquared.core.backup.PlayerBackupProfile;
+import com.plotsquared.core.plot.Plot;
+import javax.annotation.Nonnull;
-public class BukkitHybridUtils extends HybridUtils {
+import java.util.UUID;
+public interface PlayerBackupProfileFactory {
+
+ @Nonnull PlayerBackupProfile create(@Nonnull UUID uuid, @Nonnull Plot plot);
}
diff --git a/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java b/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java
new file mode 100644
index 000000000..2103602ff
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/inject/modules/PlotSquaredModule.java
@@ -0,0 +1,57 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+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.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(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());
+ }
+
+}
diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java
index 162129d52..06f011437 100644
--- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java
+++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java
@@ -57,10 +57,10 @@ import com.plotsquared.core.plot.flag.implementations.TimeFlag;
import com.plotsquared.core.plot.flag.implementations.TitlesFlag;
import com.plotsquared.core.plot.flag.implementations.WeatherFlag;
import com.plotsquared.core.plot.flag.types.TimedFlag;
+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;
@@ -68,6 +68,7 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import net.kyori.adventure.text.minimessage.Template;
+import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Iterator;
@@ -76,10 +77,16 @@ import java.util.UUID;
public class PlotListener {
- private static final HashMap feedRunnable = new HashMap<>();
- private static final HashMap healRunnable = new HashMap<>();
+ private final HashMap feedRunnable = new HashMap<>();
+ private final HashMap healRunnable = new HashMap<>();
- public static void startRunnable() {
+ private final EventDispatcher eventDispatcher;
+
+ public PlotListener(@Nullable final EventDispatcher eventDispatcher) {
+ this.eventDispatcher = eventDispatcher;
+ }
+
+ public void startRunnable() {
TaskManager.runTaskRepeat(() -> {
if (!healRunnable.isEmpty()) {
for (Iterator> iterator =
@@ -89,15 +96,14 @@ public class PlotListener {
++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));
}
}
}
@@ -110,15 +116,14 @@ public class PlotListener {
++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));
}
}
}
@@ -126,7 +131,7 @@ public class PlotListener {
}, 20);
}
- public static boolean plotEntry(final PlotPlayer> player, final Plot plot) {
+ public boolean plotEntry(final PlotPlayer> player, final Plot plot) {
if (plot.isDenied(player.getUUID()) && !Permissions
.hasPermission(player, "plots.admin.entry.denied")) {
return false;
@@ -139,7 +144,7 @@ public class PlotListener {
ExpireManager.IMP.handleEntry(player, plot);
}
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
- PlotSquared.get().getEventDispatcher().callEntry(player, plot);
+ this.eventDispatcher.callEntry(player, plot);
if (plot.hasOwner()) {
// This will inherit values from PlotArea
final TitlesFlag.TitlesFlagValue titleFlag = plot.getFlag(TitlesFlag.class);
@@ -163,7 +168,7 @@ public class PlotListener {
if (plot.getFlag(NotifyEnterFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) {
- final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
+ final PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
if (owner != null && !owner.getUUID().equals(player.getUUID())) {
MainUtil.sendMessage(owner, Captions.NOTIFY_ENTER.getTranslated()
.replace("%player", player.getName())
@@ -218,7 +223,7 @@ public class PlotListener {
PlotFlag, ?> plotFlag =
GlobalFlagContainer.getInstance().getFlag(TimeFlag.class);
PlotFlagRemoveEvent event =
- PlotSquared.get().getEventDispatcher().callFlagRemove(plotFlag, plot);
+ this.eventDispatcher.callFlagRemove(plotFlag, plot);
if (event.getEventResult() != Result.DENY) {
plot.removeFlag(event.getFlag());
}
@@ -292,9 +297,9 @@ public class PlotListener {
return true;
}
- public static boolean plotExit(final PlotPlayer> player, Plot plot) {
+ public boolean plotExit(final PlotPlayer> player, Plot plot) {
Object previous = player.deleteMeta(PlotPlayer.META_LAST_PLOT);
- PlotSquared.get().getEventDispatcher().callLeave(player, plot);
+ this.eventDispatcher.callLeave(player, plot);
if (plot.hasOwner()) {
PlotArea pw = plot.getArea();
if (pw == null) {
@@ -335,7 +340,7 @@ public class PlotListener {
if (plot.getFlag(NotifyLeaveFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) {
- final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
+ final PlotPlayer owner = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
if ((owner != null) && !owner.getUUID().equals(player.getUUID())) {
MainUtil.sendMessage(owner, Captions.NOTIFY_LEAVE.getTranslated()
.replace("%player", player.getName())
@@ -382,7 +387,7 @@ public class PlotListener {
return true;
}
- public static void logout(UUID uuid) {
+ public void logout(UUID uuid) {
feedRunnable.remove(uuid);
healRunnable.remove(uuid);
}
diff --git a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java
index 0df6c3a3c..fafaa9b1b 100644
--- a/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java
+++ b/Core/src/main/java/com/plotsquared/core/listener/ProcessedWEExtent.java
@@ -25,8 +25,6 @@
*/
package com.plotsquared.core.listener;
-import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.util.WEManager;
import com.plotsquared.core.util.WorldUtil;
@@ -44,6 +42,9 @@ 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
import java.lang.reflect.Field;
import java.util.HashMap;
@@ -52,20 +53,24 @@ import java.util.Set;
public class ProcessedWEExtent extends AbstractDelegateExtent {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + ProcessedWEExtent.class.getSimpleName());
+
private final Set 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 tileEntityCount = new HashMap<>();
- public ProcessedWEExtent(String world, Set mask, int max, Extent child,
- Extent parent) {
+ public ProcessedWEExtent(String world, Set mask, int max, Extent child, Extent parent, @Nonnull final WorldUtil worldUtil) {
super(child);
this.mask = mask;
this.world = world;
+ this.worldUtil = worldUtil;
if (max == -1) {
max = Integer.MAX_VALUE;
}
@@ -92,17 +97,15 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
public > 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;
} else {
tileEntityCount[0]++;
- PlotSquared.debug(Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getX() + ","
- + location.getZ());
}
}
if (WEManager.maskContains(this.mask, location.getX(), location.getY(), location.getZ())) {
@@ -133,9 +136,6 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
this.Ecount++;
if (this.Ecount > Settings.Chunk_Processor.MAX_ENTITIES) {
this.Eblocked = true;
- PlotSquared.debug(
- Captions.PREFIX + "&cDetected unsafe WorldEdit: " + location.getBlockX() + ","
- + location.getBlockZ());
}
if (WEManager.maskContains(this.mask, location.getBlockX(), location.getBlockY(),
location.getBlockZ())) {
diff --git a/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java b/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java
index c9d883f55..4ae1c5c1f 100644
--- a/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java
+++ b/Core/src/main/java/com/plotsquared/core/listener/WESubscriber.java
@@ -25,14 +25,16 @@
*/
package com.plotsquared.core.listener;
-import com.plotsquared.core.PlotSquared;
+import com.google.inject.Inject;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
+import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.WEManager;
+import com.plotsquared.core.util.WorldUtil;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
@@ -43,10 +45,19 @@ import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
+import javax.annotation.Nonnull;
import java.util.Set;
public class WESubscriber {
+
+ private final PlotAreaManager plotAreaManager;
+ private final WorldUtil worldUtil;
+
+ @Inject public WESubscriber(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final WorldUtil worldUtil) {
+ this.plotAreaManager = plotAreaManager;
+ this.worldUtil = worldUtil;
+ }
@Subscribe(priority = Priority.VERY_EARLY) public void onEditSession(EditSessionEvent event) {
if (!Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
@@ -66,9 +77,8 @@ public class WESubscriber {
if (plotPlayer == null) {
Player player = (Player) actor;
Location location = player.getLocation();
- com.plotsquared.core.location.Location pLoc =
- new com.plotsquared.core.location.Location(player.getWorld().getName(),
- location.getBlockX(), location.getBlockX(), location.getBlockZ());
+ com.plotsquared.core.location.Location pLoc = com.plotsquared.core.location.Location.at(player.getWorld().getName(),
+ location.toVector().toBlockPoint());
Plot plot = pLoc.getPlot();
if (plot == null) {
event.setExtent(new NullExtent());
@@ -83,19 +93,19 @@ public class WESubscriber {
if (Permissions.hasPermission(plotPlayer, "plots.worldedit.bypass")) {
MainUtil.sendMessage(plotPlayer, Captions.WORLDEDIT_BYPASS);
}
- if (PlotSquared.get().hasPlotArea(world)) {
+ if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(new NullExtent());
}
return;
}
}
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
- if (PlotSquared.get().hasPlotArea(world)) {
+ if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(
new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(),
- event.getExtent()));
+ event.getExtent(), this.worldUtil));
}
- } else if (PlotSquared.get().hasPlotArea(world)) {
+ } else if (this.plotAreaManager.hasPlotArea(world)) {
event.setExtent(new WEExtent(mask, event.getExtent()));
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/location/Location.java b/Core/src/main/java/com/plotsquared/core/location/Location.java
index 08db98a19..53db29ed7 100644
--- a/Core/src/main/java/com/plotsquared/core/location/Location.java
+++ b/Core/src/main/java/com/plotsquared/core/location/Location.java
@@ -25,101 +25,225 @@
*/
package com.plotsquared.core.location;
+import com.google.common.base.Preconditions;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
-import com.plotsquared.core.plot.PlotManager;
-import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
-import lombok.Setter;
-import org.jetbrains.annotations.NotNull;
import org.khelekore.prtree.MBR;
import org.khelekore.prtree.SimpleMBR;
-public class Location implements Cloneable, Comparable {
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
- private int x;
- private int y;
- private int z;
- @Getter @Setter private float yaw;
- @Getter @Setter private float pitch;
- @Getter @Setter private String world;
- @Getter private BlockVector3 blockVector3;
+/**
+ * An unmodifiable 6-tuple (world,x,y,z,yaw,pitch)
+ */
+@EqualsAndHashCode @SuppressWarnings("unused")
+public final class Location implements Comparable {
- public Location(String world, int x, int y, int z, float yaw, float pitch) {
- this.world = world;
- this.x = x;
- this.y = y;
- this.z = z;
+ @Getter private final float yaw;
+ @Getter private final float pitch;
+ @Getter private final BlockVector3 blockVector3;
+ private final World> world;
+
+ private Location(@Nonnull final World> world, @Nonnull final BlockVector3 blockVector3,
+ final float yaw, final float pitch) {
+ this.world = Preconditions.checkNotNull(world, "World may not be null");
+ this.blockVector3 = Preconditions.checkNotNull(blockVector3, "Vector may not be null");
this.yaw = yaw;
this.pitch = pitch;
- this.blockVector3 = BlockVector3.at(x, y, z);
}
- public Location(String world, int x, int y, int z) {
- this(world, x, y, z, 0f, 0f);
- }
-
- public int getX() {
- return this.x;
- }
-
- public void setX(int x) {
- this.x = x;
- this.blockVector3 = BlockVector3.at(x, y, z);
- }
-
- public int getY() {
- return this.y;
- }
-
- public void setY(int y) {
- this.y = y;
- this.blockVector3 = BlockVector3.at(x, y, z);
- }
-
- public int getZ() {
- return this.z;
- }
-
- public void setZ(int z) {
- this.z = z;
- this.blockVector3 = BlockVector3.at(x, y, z);
- }
-
- public void setBlockVector3(BlockVector3 blockVector3) {
- this.blockVector3 = blockVector3;
- this.x = blockVector3.getX();
- this.y = blockVector3.getY();
- this.z = blockVector3.getZ();
- }
-
- @Override public Location clone() {
- try {
- return (Location) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new AssertionError(); //can't happen
+ private Location(@Nonnull final String worldName, @Nonnull final BlockVector3 blockVector3,
+ final float yaw, final float pitch) {
+ Preconditions.checkNotNull(worldName, "World name may not be null");
+ if (worldName.isEmpty()) {
+ this.world = World.nullWorld();
+ } else {
+ this.world = PlotSquared.platform().getPlatformWorld(worldName);
}
+ this.blockVector3 = Preconditions.checkNotNull(blockVector3, "Vector may not be null");
+ this.yaw = yaw;
+ this.pitch = pitch;
}
/**
- * Return a copy of the location. This will pass {@link #equals(Object)}
- * but will have a different identity.
+ * Construct a new location
*
- * @return Copy of the location
+ * @param world World
+ * @param blockVector3 (x,y,z) vector
+ * @param yaw yaw
+ * @param pitch pitch
+ * @return New location
*/
- @NotNull public Location copy() {
- return new Location(this.world, this.x, this.y, this.z, this.yaw, this.pitch);
+ @Nonnull public static Location at(@Nonnull final String world,
+ @Nonnull final BlockVector3 blockVector3, final float yaw, final float pitch) {
+ return new Location(world, blockVector3, yaw, pitch);
}
- public PlotArea getPlotArea() {
- return PlotSquared.get().getPlotAreaAbs(this);
+ /**
+ * Construct a new location with yaw and pitch equal to 0
+ *
+ * @param world World
+ * @param blockVector3 (x,y,z) vector
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final String world,
+ @Nonnull final BlockVector3 blockVector3) {
+ return at(world, blockVector3, 0f, 0f);
}
- public Plot getOwnedPlot() {
- PlotArea area = getPlotArea();
+ /**
+ * Construct a new location
+ *
+ * @param world World
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param z Z coordinate
+ * @param yaw Yaw
+ * @param pitch Pitch
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final String world, final int x, final int y,
+ final int z, final float yaw, final float pitch) {
+ return at(world, BlockVector3.at(x, y, z), yaw, pitch);
+ }
+
+ /**
+ * Construct a new location with yaw and pitch equal to 0
+ *
+ * @param world World
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param z Z coordinate
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final String world, final int x, final int y,
+ final int z) {
+ return at(world, BlockVector3.at(x, y, z));
+ }
+
+ /**
+ * Construct a new location
+ *
+ * @param world World
+ * @param blockVector3 (x,y,z) vector
+ * @param yaw yaw
+ * @param pitch pitch
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final World> world,
+ @Nonnull final BlockVector3 blockVector3, final float yaw, final float pitch) {
+ return new Location(world, blockVector3, yaw, pitch);
+ }
+
+ /**
+ * Construct a new location with yaw and pitch equal to 0
+ *
+ * @param world World
+ * @param blockVector3 (x,y,z) vector
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final World> world,
+ @Nonnull final BlockVector3 blockVector3) {
+ return at(world, blockVector3, 0f, 0f);
+ }
+
+ /**
+ * Construct a new location
+ *
+ * @param world World
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param z Z coordinate
+ * @param yaw Yaw
+ * @param pitch Pitch
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final World> world, final int x, final int y,
+ final int z, final float yaw, final float pitch) {
+ return at(world, BlockVector3.at(x, y, z), yaw, pitch);
+ }
+
+ /**
+ * Construct a new location with yaw and pitch equal to 0
+ *
+ * @param world World
+ * @param x X coordinate
+ * @param y Y coordinate
+ * @param z Z coordinate
+ * @return New location
+ */
+ @Nonnull public static Location at(@Nonnull final World> world, final int x, final int y,
+ final int z) {
+ return at(world, BlockVector3.at(x, y, z));
+ }
+
+ /**
+ * Get the world object
+ *
+ * @return World object
+ */
+ @Nonnull public World> getWorld() {
+ return this.world;
+ }
+
+ /**
+ * Get the name of the world this location is in
+ *
+ * @return World name
+ */
+ @Nonnull public String getWorldName() {
+ return this.world.getName();
+ }
+
+ /**
+ * Get the X coordinate
+ *
+ * @return X coordinate
+ */
+ public int getX() {
+ return this.blockVector3.getBlockX();
+ }
+
+ /**
+ * Get the Y coordinate
+ *
+ * @return Y coordinate
+ */
+ public int getY() {
+ return this.blockVector3.getY();
+ }
+
+ /**
+ * Get the Z coordinate
+ *
+ * @return Z coordinate
+ */
+ public int getZ() {
+ return this.blockVector3.getZ();
+ }
+
+ /**
+ * Get the {@link PlotArea}, if any, that contains this location
+ *
+ * @return Plot area containing the location, or {@code null}
+ */
+ @Nullable public PlotArea getPlotArea() {
+ return PlotSquared.get().getPlotAreaManager().getPlotArea(this);
+ }
+
+ /**
+ * Get the owned {@link Plot}, if any, that contains this location
+ *
+ * @return Plot containing the location, or {@code null}
+ */
+ @Nullable public Plot getOwnedPlot() {
+ final PlotArea area = this.getPlotArea();
if (area != null) {
return area.getOwnedPlot(this);
} else {
@@ -127,8 +251,13 @@ public class Location implements Cloneable, Comparable {
}
}
- public Plot getOwnedPlotAbs() {
- PlotArea area = getPlotArea();
+ /**
+ * Get the (absolute) owned {@link Plot}, if any, that contains this location
+ *
+ * @return (Absolute) plot containing the location, or {@code null}
+ */
+ @Nullable public Plot getOwnedPlotAbs() {
+ final PlotArea area = this.getPlotArea();
if (area != null) {
return area.getOwnedPlotAbs(this);
} else {
@@ -136,36 +265,42 @@ public class Location implements Cloneable, Comparable {
}
}
+ /**
+ * Check whether or not the location belongs to a plot area
+ *
+ * @return {@code true} if the location belongs to a plot area, else {@code false}
+ */
public boolean isPlotArea() {
- return getPlotArea() != null;
+ return this.getPlotArea() != null;
}
+ /**
+ * Check whether or not the location belongs to a plot road
+ *
+ * @return {@code true} if the location belongs to a plot road, else {@code false}
+ */
public boolean isPlotRoad() {
- PlotArea area = getPlotArea();
+ final PlotArea area = this.getPlotArea();
return area != null && area.getPlotAbs(this) == null;
}
/**
* Checks if anyone owns a plot at the current location.
*
- * @return 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() {
- PlotArea area = getPlotArea();
+ final PlotArea area = this.getPlotArea();
return area != null && area.getOwnedPlotAbs(this) == null;
}
- public PlotManager getPlotManager() {
- PlotArea pa = getPlotArea();
- if (pa != null) {
- return pa.getPlotManager();
- } else {
- return null;
- }
- }
-
- public Plot getPlotAbs() {
- PlotArea area = getPlotArea();
+ /**
+ * Get the absolute {@link Plot}, if any, that contains this location
+ *
+ * @return (Absolute) plot containing the location, or {code null}
+ */
+ @Nullable public Plot getPlotAbs() {
+ final PlotArea area = this.getPlotArea();
if (area != null) {
return area.getPlotAbs(this);
} else {
@@ -173,8 +308,13 @@ public class Location implements Cloneable, Comparable {
}
}
- public Plot getPlot() {
- PlotArea area = getPlotArea();
+ /**
+ * Get the {@link Plot}, if any, that contains this location
+ *
+ * @return plot containing the location, or {code null}
+ */
+ @Nullable public Plot getPlot() {
+ final PlotArea area = this.getPlotArea();
if (area != null) {
return area.getPlot(this);
} else {
@@ -182,89 +322,133 @@ public class Location implements Cloneable, Comparable {
}
}
- public BlockVector2 getBlockVector2() {
- return BlockVector2.at(this.x >> 4, this.z >> 4);
+ /**
+ * Get the coordinates of the chunk that contains this location
+ *
+ * @return Chunk coordinates
+ */
+ @Nonnull public BlockVector2 getChunkLocation() {
+ return BlockVector2.at(this.getX() >> 4, this.getZ() >> 4);
}
- public Location add(int x, int y, int z) {
- this.x += x;
- this.y += y;
- this.z += z;
- this.blockVector3 = BlockVector3.at(this.x, this.y, this.z);
- return this;
+ /**
+ * Return a new location offset by the given coordinates
+ *
+ * @param x X offset
+ * @param y Y offset
+ * @param z Z offset
+ * @return New location
+ */
+ @Nonnull public Location add(final int x, final int y, final int z) {
+ return new Location(this.world, this.blockVector3.add(x, y, z), this.yaw, this.pitch);
}
- public double getEuclideanDistanceSquared(Location l2) {
+ /**
+ * Return a new location using the given X coordinate
+ *
+ * @param x New X coordinate
+ * @return New location
+ */
+ @Nonnull public Location withX(final int x) {
+ return new Location(this.world, this.blockVector3.withX(x), this.yaw, this.pitch);
+ }
+
+ /**
+ * Return a new location using the given Y coordinate
+ *
+ * @param y New Y coordinate
+ * @return New location
+ */
+ @Nonnull public Location withY(final int y) {
+ return new Location(this.world, this.blockVector3.withY(y), this.yaw, this.pitch);
+ }
+
+ /**
+ * Return a new location using the given Z coordinate
+ *
+ * @param z New Z coordinate
+ * @return New location
+ */
+ @Nonnull public Location withZ(final int z) {
+ return new Location(this.world, this.blockVector3.withZ(z), this.yaw, this.pitch);
+ }
+
+ /**
+ * Return a new location using the given yaw
+ *
+ * @param yaw New yaw
+ * @return New location
+ */
+ @Nonnull public Location withYaw(final float yaw) {
+ return new Location(this.world, this.blockVector3, yaw, this.pitch);
+ }
+
+ /**
+ * Return a new location using the given pitch
+ *
+ * @param pitch New pitch
+ * @return New location
+ */
+ @Nonnull public Location withPitch(final float pitch) {
+ return new Location(this.world, this.blockVector3, this.yaw, pitch);
+ }
+
+ /**
+ * Return a new location using the given world
+ *
+ * @param world New world
+ * @return New location
+ */
+ @Nonnull public Location withWorld(@Nonnull final String world) {
+ return new Location(world, this.blockVector3, this.yaw, this.pitch);
+ }
+
+ public double getEuclideanDistanceSquared(@Nonnull final Location l2) {
double x = getX() - l2.getX();
double y = getY() - l2.getY();
double z = getZ() - l2.getZ();
return x * x + y * y + z * z;
}
- public double getEuclideanDistance(Location l2) {
+ public double getEuclideanDistance(@Nonnull final Location l2) {
return Math.sqrt(getEuclideanDistanceSquared(l2));
}
- public boolean isInSphere(Location origin, int radius) {
- return getEuclideanDistanceSquared(origin) < radius * radius;
+ /**
+ * Return a new location offset by (-) the given coordinates
+ *
+ * @param x X offset
+ * @param y Y offset
+ * @param z Z offset
+ * @return New location
+ */
+ @Nonnull public Location subtract(int x, int y, int z) {
+ return this.add(-x, -y, -z);
}
- @Override public int hashCode() {
- return MathMan.pair((short) this.x, (short) this.z) * 17 + this.y;
+ /**
+ * Get a minimum bounding rectangle that contains this location only
+ *
+ * @return Minimum bounding rectangle
+ */
+ @Nonnull public MBR toMBR() {
+ return new SimpleMBR(this.getX(), this.getX(), this.getY(), this.getY(), this.getZ(),
+ this.getZ());
}
- public boolean isInAABB(Location min, Location max) {
- return this.x >= min.getX() && this.x <= max.getX() && this.y >= min.getY() && this.y <= max
- .getY() && this.z >= min.getX() && this.z < max.getZ();
- }
-
- public void lookTowards(int x, int y) {
- double l = this.x - x;
- double c = Math.sqrt(l * l + 0.0);
- if (Math.asin(0 / c) / Math.PI * 180 > 90) {
- setYaw((float) (180 - -Math.asin(l / c) / Math.PI * 180));
- } else {
- setYaw((float) (-Math.asin(l / c) / Math.PI * 180));
- }
- }
-
- public Location subtract(int x, int y, int z) {
- this.x -= x;
- this.y -= y;
- this.z -= z;
- this.blockVector3 = BlockVector3.at(this.x, this.y, this.z);
- return this;
- }
-
- public MBR toMBR() {
- return new SimpleMBR(this.getX(), this.getX(), this.getY(), this.getY(), this.getZ(), this.getZ());
- }
-
- @Override public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
- if (!(o instanceof Location)) {
- return false;
- }
- Location l = (Location) o;
- return this.x == l.getX() && this.y == l.getY() && this.z == l.getZ() && this.world
- .equals(l.getWorld()) && this.yaw == l.getYaw() && this.pitch == l.getPitch();
- }
-
- @Override public int compareTo(Location o) {
- if (this.x == o.getX() && this.y == o.getY() || this.z == o.getZ()) {
+ @Override public int compareTo(@Nonnull final Location o) {
+ if (this.getX() == o.getX() && this.getY() == o.getY() || this.getZ() == o.getZ()) {
return 0;
}
- if (this.x < o.getX() && this.y < o.getY() && this.z < o.getZ()) {
+ if (this.getX() < o.getX() && this.getY() < o.getY() && this.getZ() < o.getZ()) {
return -1;
}
return 1;
}
@Override public String toString() {
- return "\"plotsquaredlocation\":{\"x\":" + this.x + ",\"y\":" + this.y + ",\"z\":" + this.z
- + ",\"yaw\":" + this.yaw + ",\"pitch\":" + this.pitch + ",\"world\":\"" + this.world
- + "\"}";
+ return "\"plotsquaredlocation\":{\"x\":" + this.getX() + ",\"y\":" + this.getY() + ",\"z\":"
+ + this.getZ() + ",\"yaw\":" + this.yaw + ",\"pitch\":" + this.pitch + ",\"world\":\""
+ + this.world + "\"}";
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/location/PlotLoc.java b/Core/src/main/java/com/plotsquared/core/location/PlotLoc.java
index 6181f9fad..8301f23a7 100644
--- a/Core/src/main/java/com/plotsquared/core/location/PlotLoc.java
+++ b/Core/src/main/java/com/plotsquared/core/location/PlotLoc.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.location;
import com.plotsquared.core.util.StringMan;
import lombok.AllArgsConstructor;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nullable;
//todo better description needed
diff --git a/Core/src/main/java/com/plotsquared/core/location/World.java b/Core/src/main/java/com/plotsquared/core/location/World.java
new file mode 100644
index 000000000..2e4eb6c52
--- /dev/null
+++ b/Core/src/main/java/com/plotsquared/core/location/World.java
@@ -0,0 +1,84 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+
+package com.plotsquared.core.location;
+
+import javax.annotation.Nonnull;
+
+/**
+ * PlotSquared representation of a platform world
+ *
+ * @param Platform world type
+ */
+public interface World {
+
+ /**
+ * Get the platform world represented by this world
+ *
+ * @return Platform world
+ */
+ @Nonnull T getPlatformWorld();
+
+ /**
+ * Get the name of the world
+ *
+ * @return World name
+ */
+ @Nonnull String getName();
+
+ /**
+ * Get a {@link NullWorld} implementation
+ *
+ * @return NullWorld instance
+ */
+ static NullWorld nullWorld() {
+ return new NullWorld<>();
+ }
+
+ class NullWorld implements World {
+
+ private NullWorld() {
+ }
+
+ @Nonnull @Override public T getPlatformWorld() {
+ throw new UnsupportedOperationException("Cannot get platform world from NullWorld");
+ }
+
+ @Override public @Nonnull String getName() {
+ return "";
+ }
+
+ @Override public boolean equals(final Object obj) {
+ return obj instanceof NullWorld;
+ }
+
+ @Override public int hashCode() {
+ return "null".hashCode();
+ }
+
+ }
+
+}
diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java
index b55ef5057..410b4a716 100644
--- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java
+++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java
@@ -25,15 +25,20 @@
*/
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.configuration.Caption;
import com.plotsquared.core.configuration.caption.TranslatableCaption;
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;
import com.sk89q.worldedit.world.gamemode.GameMode;
@@ -43,6 +48,10 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.List;
@@ -50,40 +59,54 @@ import java.util.UUID;
public class ConsolePlayer extends PlotPlayer {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + ConsolePlayer.class.getSimpleName());
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private static ConsolePlayer instance;
- private ConsolePlayer() {
- PlotArea area = PlotSquared.get().getFirstPlotArea();
+ private final Actor actor;
+
+ @Inject private ConsolePlayer(@Nonnull final PlotAreaManager plotAreaManager,
+ @Nonnull final EventDispatcher eventDispatcher,
+ @ConsoleActor @Nonnull 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) {
+ area = areas[0];
+ } else {
+ area = null;
+ }
Location location;
if (area != null) {
CuboidRegion region = area.getRegion();
- location = new Location(area.getWorldName(),
+ location = Location.at(area.getWorldName(),
region.getMinimumPoint().getX() + region.getMaximumPoint().getX() / 2, 0,
region.getMinimumPoint().getZ() + region.getMaximumPoint().getZ() / 2);
} else {
- location = new Location("world", 0, 0, 0);
+ location = Location.at("", 0, 0, 0);
}
setMeta("location", location);
}
public static ConsolePlayer getConsole() {
if (instance == null) {
- instance = new ConsolePlayer();
+ instance = PlotSquared.platform().getInjector().getInstance(ConsolePlayer.class);
instance.teleport(instance.getLocation());
}
return instance;
}
@Override public Actor toActor() {
- return PlotSquared.get().IMP.getConsole();
+ return this.actor;
}
@Override public Actor getPlatformPlayer() {
return this.toActor();
}
- @Override public boolean canTeleport(@NotNull Location location) {
+ @Override public boolean canTeleport(@Nonnull Location location) {
return true;
}
@@ -92,7 +115,7 @@ public class ConsolePlayer extends PlotPlayer {
final int fadeIn, final int stay, final int fadeOut, @NotNull final Template... replacements) {
}
- @NotNull @Override public Location getLocation() {
+ @Nonnull @Override public Location getLocation() {
return this.getMeta("location");
}
@@ -100,7 +123,7 @@ public class ConsolePlayer extends PlotPlayer {
return getLocation();
}
- @NotNull @Override public UUID getUUID() {
+ @Nonnull @Override public UUID getUUID() {
return DBFunc.EVERYONE;
}
@@ -159,14 +182,14 @@ public class ConsolePlayer extends PlotPlayer {
return RequiredType.CONSOLE;
}
- @Override public void setWeather(@NotNull PlotWeather weather) {
+ @Override public void setWeather(@Nonnull PlotWeather weather) {
}
- @Override public @NotNull GameMode getGameMode() {
+ @Override public @Nonnull GameMode getGameMode() {
return GameModes.SPECTATOR;
}
- @Override public void setGameMode(@NotNull GameMode gameMode) {
+ @Override public void setGameMode(@Nonnull GameMode gameMode) {
}
@Override public void setTime(long time) {
@@ -179,7 +202,7 @@ public class ConsolePlayer extends PlotPlayer {
@Override public void setFlight(boolean fly) {
}
- @Override public void playMusic(@NotNull Location location, @NotNull ItemType id) {
+ @Override public void playMusic(@Nonnull Location location, @Nonnull ItemType id) {
}
@Override public void kick(String message) {
diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java
index 87a4acecb..0a6b4a772 100644
--- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java
+++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java
@@ -51,19 +51,23 @@ 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.util.EconHandler;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.Permissions;
+import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.item.ItemType;
-import lombok.NonNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template;
import net.kyori.adventure.title.Title;
-import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.time.Duration;
@@ -81,7 +85,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.Collectors;
/**
* The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}.
@@ -91,6 +94,8 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private static final String NON_EXISTENT_CAPTION = "PlotSquared does not recognize the caption: ";
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotPlayer.class.getSimpleName());
+
public static final String META_LAST_PLOT = "lastplot";
public static final String META_LOCATION = "location";
@@ -107,7 +112,17 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
private int hash;
private Locale locale;
- public static PlotPlayer from(@NonNull final T object) {
+ private final PlotAreaManager plotAreaManager;
+ private final EventDispatcher eventDispatcher;
+ private final EconHandler econHandler;
+
+ public PlotPlayer(@Nonnull final PlotAreaManager plotAreaManager, @Nonnull final EventDispatcher eventDispatcher, @Nullable final EconHandler econHandler) {
+ this.plotAreaManager = plotAreaManager;
+ this.eventDispatcher = eventDispatcher;
+ this.econHandler = econHandler;
+ }
+
+ public static PlotPlayer from(@Nonnull final T object) {
if (!converters.containsKey(object.getClass())) {
throw new IllegalArgumentException(String
.format("There is no registered PlotPlayer converter for type %s",
@@ -116,7 +131,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
return converters.get(object.getClass()).convert(object);
}
- public static void registerConverter(@NonNull final Class clazz,
+ public static void registerConverter(@Nonnull final Class clazz,
final PlotPlayerConverter converter) {
converters.put(clazz, converter);
}
@@ -125,7 +140,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
return Collections.unmodifiableCollection(debugModeEnabled);
}
- public static Collection> getDebugModePlayersInPlot(@NotNull final Plot plot) {
+ public static Collection> getDebugModePlayersInPlot(@Nonnull final Plot plot) {
if (debugModeEnabled.isEmpty()) {
return Collections.emptyList();
}
@@ -149,7 +164,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
* @return Wrapped player
*/
public static PlotPlayer> wrap(Object player) {
- return PlotSquared.get().IMP.wrapPlayer(player);
+ return PlotSquared.platform().wrapPlayer(player);
}
public abstract Actor toActor();
@@ -285,11 +300,11 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
*/
public int getPlotCount() {
if (!Settings.Limit.GLOBAL) {
- return getPlotCount(getLocation().getWorld());
+ return getPlotCount(getLocation().getWorldName());
}
final AtomicInteger count = new AtomicInteger(0);
final UUID uuid = getUUID();
- PlotSquared.get().forEachPlotArea(value -> {
+ this.plotAreaManager.forEachPlotArea(value -> {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
for (Plot plot : value.getPlotsAbs(uuid)) {
if (!DoneFlag.isDone(plot)) {
@@ -305,10 +320,10 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
public int getClusterCount() {
if (!Settings.Limit.GLOBAL) {
- return getClusterCount(getLocation().getWorld());
+ return getClusterCount(getLocation().getWorldName());
}
final AtomicInteger count = new AtomicInteger(0);
- PlotSquared.get().forEachPlotArea(value -> {
+ this.plotAreaManager.forEachPlotArea(value -> {
for (PlotCluster cluster : value.getClusters()) {
if (cluster.isOwner(getUUID())) {
count.incrementAndGet();
@@ -327,7 +342,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
public int getPlotCount(String world) {
UUID uuid = getUUID();
int count = 0;
- for (PlotArea area : PlotSquared.get().getPlotAreas(world)) {
+ for (PlotArea area : this.plotAreaManager.getPlotAreasSet(world)) {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
count +=
area.getPlotsAbs(uuid).stream().filter(plot -> !DoneFlag.isDone(plot)).count();
@@ -341,7 +356,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
public int getClusterCount(String world) {
UUID uuid = getUUID();
int count = 0;
- for (PlotArea area : PlotSquared.get().getPlotAreas(world)) {
+ for (PlotArea area : this.plotAreaManager.getPlotAreasSet(world)) {
for (PlotCluster cluster : area.getClusters()) {
if (cluster.isOwner(getUUID())) {
count++;
@@ -359,20 +374,20 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
* @see #getPlotCount() for the number of plots
*/
public Set getPlots() {
- return PlotSquared.get().getPlots(this);
+ return PlotQuery.newQuery().ownedBy(this).asSet();
}
/**
* Return the PlotArea this player is currently in, or null.
*
- * @return
+ * @return Plot area the player is currently in, or {@code null}
*/
- public PlotArea getPlotAreaAbs() {
- return PlotSquared.get().getPlotAreaAbs(getLocation());
+ @Nullable public PlotArea getPlotAreaAbs() {
+ return this.plotAreaManager.getPlotArea(getLocation());
}
public PlotArea getApplicablePlotArea() {
- return PlotSquared.get().getApplicablePlotArea(getLocation());
+ return this.plotAreaManager.getApplicablePlotArea(getLocation());
}
@Override @NotNull public RequiredType getSuperCaller() {
@@ -384,10 +399,10 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
*
* @return The location
*/
- @NotNull public Location getLocation() {
+ @Nonnull public Location getLocation() {
Location location = getMeta("location");
if (location != null) {
- return location.copy(); // Always return a copy of the location
+ return location;
}
return getLocationFull();
}
@@ -411,9 +426,9 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
*
* @return UUID
*/
- @Override @NotNull public abstract UUID getUUID();
+ @Override @Nonnull public abstract UUID getUUID();
- public boolean canTeleport(@NotNull final Location location) {
+ public boolean canTeleport(@Nonnull final Location location) {
Preconditions.checkNotNull(location, "Specified location cannot be null");
final Location current = getLocationFull();
teleport(location);
@@ -498,21 +513,21 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
*
* @param weather the weather visible to the player
*/
- public abstract void setWeather(@NotNull PlotWeather weather);
+ public abstract void setWeather(@Nonnull PlotWeather weather);
/**
* Get this player's gamemode.
*
* @return the gamemode of the player.
*/
- public abstract @NotNull GameMode getGameMode();
+ public abstract @Nonnull GameMode getGameMode();
/**
* Set this player's gameMode.
*
* @param gameMode the gamemode to set
*/
- public abstract void setGameMode(@NotNull GameMode gameMode);
+ public abstract void setGameMode(@Nonnull GameMode gameMode);
/**
* Set this player's local time (ticks).
@@ -541,7 +556,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
* @param location where to play the music
* @param id the record item id
*/
- public abstract void playMusic(@NotNull Location location, @NotNull ItemType id);
+ public abstract void playMusic(@Nonnull Location location, @Nonnull ItemType id);
/**
* Check if this player is banned.
@@ -588,21 +603,21 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
removePersistentMeta("quitLoc");
}
if (plot != null) {
- PlotSquared.get().getEventDispatcher().callLeave(this, plot);
+ this.eventDispatcher.callLeave(this, plot);
}
if (Settings.Enabled_Components.BAN_DELETER && isBanned()) {
for (Plot owned : getPlots()) {
owned.deletePlot(null);
- PlotSquared.debug(String
- .format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned",
- plot.getId(), getName()));
+ if (Settings.DEBUG) {
+ logger.info("[P2] Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName());
+ }
}
}
if (ExpireManager.IMP != null) {
ExpireManager.IMP.storeDate(getUUID(), System.currentTimeMillis());
}
- PlotSquared.imp().getPlayerManager().removePlayer(this);
- PlotSquared.get().IMP.unregister(this);
+ PlotSquared.platform().getPlayerManager().removePlayer(this);
+ PlotSquared.platform().unregister(this);
debugModeEnabled.remove(this);
}
@@ -626,7 +641,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
*/
public int getPlayerClusterCount() {
final AtomicInteger count = new AtomicInteger();
- PlotSquared.get().forEachPlotArea(value -> count.addAndGet(value.getClusters().size()));
+ this.plotAreaManager.forEachPlotArea(value -> count.addAndGet(value.getClusters().size()));
return count.get();
}
@@ -637,9 +652,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
* @return a {@code Set} of plots this player owns in the provided world
*/
public Set getPlots(String world) {
- UUID uuid = getUUID();
- return PlotSquared.get().getPlots(world).stream().filter(plot -> plot.isOwner(uuid))
- .collect(Collectors.toCollection(HashSet::new));
+ return PlotQuery.newQuery().inWorld(world).ownedBy(getUUID()).asSet();
}
public void populatePersistentMetaMap() {
@@ -659,7 +672,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
if (!Settings.Teleport.ON_LOGIN) {
return;
}
- PlotAreaManager manager = PlotSquared.get().getPlotAreaManager();
+ PlotAreaManager manager = PlotPlayer.this.plotAreaManager;
if (!(manager instanceof SinglePlotAreaManager)) {
return;
@@ -687,7 +700,7 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
return;
}
- final Location location = new Location(plot.getWorldName(), x, y, z);
+ final Location location = Location.at(plot.getWorldName(), x, y, z);
if (plot.isLoaded()) {
TaskManager.runTask(() -> {
if (getMeta("teleportOnLogin", true)) {
@@ -850,25 +863,26 @@ public abstract class PlotPlayer
implements CommandCaller, OfflinePlotPlayer,
* The amount of money this Player has.
*/
public double getMoney() {
- return EconHandler.getEconHandler() == null ?
+ return this.econHandler == null ?
0 :
- EconHandler.getEconHandler().getMoney(this);
+ 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 {
- PlotPlayer convert(BaseObject object);
+ PlotPlayer> convert(BaseObject object);
}
+
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java b/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java
index b5a6250ab..f467c595f 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/BlockBucket.java
@@ -38,8 +38,9 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import lombok.EqualsAndHashCode;
import lombok.Getter;
-import lombok.NonNull;
+
import lombok.RequiredArgsConstructor;
+import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Map;
@@ -81,28 +82,28 @@ public final class BlockBucket implements ConfigurationSerializable {
this.input = new StringBuilder();
}
- public static BlockBucket withSingle(@NonNull final BlockState block) {
+ public static BlockBucket withSingle(@Nonnull final BlockState block) {
final BlockBucket blockBucket = new BlockBucket();
blockBucket.addBlock(block, 100);
return blockBucket;
}
- public static BlockBucket deserialize(@NonNull final Map map) {
+ public static BlockBucket deserialize(@Nonnull final Map map) {
if (!map.containsKey("blocks")) {
return null;
}
return ConfigurationUtil.BLOCK_BUCKET.parseString(map.get("blocks").toString());
}
- public void addBlock(@NonNull final BlockState block) {
+ public void addBlock(@Nonnull final BlockState block) {
this.addBlock(block, -1);
}
- public void addBlock(@NonNull final BlockState block, final int chance) {
+ public void addBlock(@Nonnull final BlockState block, final int chance) {
addBlock(block, (double) chance);
}
- private void addBlock(@NonNull final BlockState block, double chance) {
+ private void addBlock(@Nonnull final BlockState block, double chance) {
if (chance == -1)
chance = 1;
String prefix = input.length() == 0 ? "" : ",";
diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
index 2adca5334..70f39aa08 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java
@@ -27,6 +27,7 @@ package com.plotsquared.core.plot;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import com.google.inject.Inject;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationUtil;
@@ -38,6 +39,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;
@@ -55,6 +57,7 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
@@ -63,6 +66,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;
@@ -71,8 +75,10 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes;
import lombok.Getter;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.awt.geom.Area;
import java.awt.geom.PathIterator;
@@ -117,12 +123,24 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
*/
public class Plot {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + Plot.class.getSimpleName());
+
public static final int MAX_HEIGHT = 256;
private static Set connected_cache;
private static Set regions_cache;
- @NotNull private final PlotId id;
+ @Nonnull private final PlotId id;
+
+ // These will be injected
+ @Inject private EventDispatcher eventDispatcher;
+ @Inject private PlotListener plotListener;
+ @Inject private RegionManager regionManager;
+ @Inject private GlobalBlockQueue blockQueue;
+ @Inject private WorldUtil worldUtil;
+ @Inject private SchematicHandler schematicHandler;
+ @Inject @ImpromptuPipeline private UUIDPipeline impromptuPipeline;
+
/**
* Plot flag container
*/
@@ -193,7 +211,7 @@ public class Plot {
* @param owner the plot owner
* @see Plot#getPlot(Location) for existing plots
*/
- public Plot(PlotArea area, @NotNull PlotId id, UUID owner) {
+ public Plot(final PlotArea area, @Nonnull final PlotId id, final UUID owner) {
this(area, id, owner, 0);
}
@@ -205,7 +223,7 @@ public class Plot {
* @param id the plot id
* @see Plot#getPlot(Location) for existing plots
*/
- public Plot(@NotNull PlotArea area, @NotNull PlotId id) {
+ public Plot(@Nonnull final PlotArea area, @Nonnull final PlotId id) {
this(area, id, null, 0);
}
@@ -220,12 +238,13 @@ public class Plot {
* @param temp Represents whatever the database manager needs it to
* @see Plot#getPlot(Location) for existing plots
*/
- public Plot(PlotArea area, @NotNull PlotId id, UUID owner, int temp) {
+ public Plot(final PlotArea area, @Nonnull 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());
+ PlotSquared.platform().getInjector().injectMembers(this);
}
/**
@@ -238,7 +257,7 @@ public class Plot {
* @param merged an array giving merged plots
* @see Plot#getPlot(Location) for existing plots
*/
- public Plot(@NotNull PlotId id, UUID owner, HashSet trusted, HashSet members,
+ public Plot(@Nonnull PlotId id, UUID owner, HashSet trusted, HashSet members,
HashSet denied, String alias, BlockLoc position, Collection> flags,
PlotArea area, boolean[] merged, long timestamp, int temp) {
this.id = id;
@@ -261,6 +280,7 @@ public class Plot {
}
}
}
+ PlotSquared.platform().getInjector().injectMembers(this);
}
/**
@@ -278,13 +298,13 @@ public class Plot {
return defaultArea.getPlotAbs(id);
}
} else if (split.length == 3) {
- PlotArea pa = PlotSquared.get().getPlotArea(split[0], null);
+ PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotArea(split[0], null);
if (pa != null) {
PlotId id = PlotId.fromString(split[1] + ';' + split[2]);
return pa.getPlotAbs(id);
}
} else if (split.length == 4) {
- PlotArea pa = PlotSquared.get().getPlotArea(split[0], split[1]);
+ PlotArea pa = PlotSquared.get().getPlotAreaManager().getPlotArea(split[0], split[1]);
if (pa != null) {
PlotId id = PlotId.fromString(split[1] + ';' + split[2]);
return pa.getPlotAbs(id);
@@ -401,7 +421,7 @@ public class Plot {
*/
public List> getPlayersInPlot() {
final List> players = new ArrayList<>();
- for (final PlotPlayer> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
+ for (final PlotPlayer> player : PlotSquared.platform().getPlayerManager().getPlayers()) {
if (this.equals(player.getCurrentPlot())) {
players.add(player);
}
@@ -424,7 +444,7 @@ public class Plot {
* @param uuid the player uuid
* @return if the provided uuid is the owner of the plot
*/
- public boolean isOwner(@NotNull UUID uuid) {
+ public boolean isOwner(@Nonnull UUID uuid) {
if (uuid.equals(this.getOwner())) {
return true;
}
@@ -553,7 +573,7 @@ public class Plot {
*
* @return the PlotId for this plot
*/
- @NotNull public PlotId getId() {
+ @Nonnull public PlotId getId() {
return this.id;
}
@@ -925,7 +945,7 @@ public class Plot {
if (isDelete) {
this.removeSign();
}
- PlotUnlinkEvent event = PlotSquared.get().getEventDispatcher()
+ PlotUnlinkEvent event = this.eventDispatcher
.callUnlink(getArea(), this, true, !isDelete,
isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR);
if (event.getEventResult() != Result.DENY) {
@@ -938,7 +958,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);
};
@@ -949,14 +969,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,
@@ -993,7 +1012,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();
@@ -1045,7 +1064,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()));
@@ -1064,7 +1083,7 @@ public class Plot {
*
* @param name name
*/
- public void setSign(@NotNull String name) {
+ public void setSign(@Nonnull String name) {
if (!isLoaded()) {
return;
}
@@ -1080,14 +1099,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());
}
/**
@@ -1258,7 +1276,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];
@@ -1325,12 +1343,12 @@ public class Plot {
for (Plot current : getConnectedPlots()) {
List> players = current.getPlayersInPlot();
for (PlotPlayer> pp : players) {
- PlotListener.plotExit(pp, current);
+ this.plotListener.plotExit(pp, current);
}
if (Settings.Backup.DELETE_ON_UNCLAIM) {
// Destroy all backups when the plot is unclaimed
- Objects.requireNonNull(PlotSquared.imp()).getBackupManager().getProfile(current)
+ Objects.requireNonNull(PlotSquared.platform()).getBackupManager().getProfile(current)
.destroy();
}
@@ -1339,7 +1357,7 @@ public class Plot {
current.setOwnerAbs(null);
current.settings = null;
for (PlotPlayer pp : players) {
- PlotListener.plotEntry(pp, current);
+ this.plotListener.plotEntry(pp, current);
}
}
return true;
@@ -1359,20 +1377,18 @@ public class Plot {
Location[] corners = getCorners();
Location top = corners[0];
Location bot = corners[1];
- Location location =
- new Location(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
+ Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
if (!isLoaded()) {
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());
}
- location.setY(1 + height);
- result.accept(location);
+ result.accept(location.withY(1 + height));
});
}
@@ -1383,19 +1399,16 @@ public class Plot {
Location[] corners = getCorners();
Location top = corners[0];
Location bot = corners[1];
- Location location =
- new Location(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
- MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
+ Location location = Location.at(this.getWorldName(), MathMan.average(bot.getX(), top.getX()),
+ MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ()));
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());
}
- location.setY(1 + y);
- return location;
+ return location.withY(1 + y);
}
/**
@@ -1407,11 +1420,11 @@ 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);
}
- return new Location(getWorldName(), x, y + 1, z);
+ return Location.at(getWorldName(), x, y + 1, z);
}
public void getSide(Consumer result) {
@@ -1421,19 +1434,19 @@ 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);
}
- result.accept(new Location(getWorldName(), x, height + 1, z));
+ result.accept(Location.at(getWorldName(), x, height + 1, z));
});
} else {
int y = 62;
if (area.allowSigns()) {
y = Math.max(y, manager.getSignLoc(this).getY() - 1);
}
- result.accept(new Location(getWorldName(), x, y + 1, z));
+ result.accept(Location.at(getWorldName(), x, y + 1, z));
}
}
@@ -1446,15 +1459,14 @@ public class Plot {
return this.getDefaultHomeSynchronous(true);
} else {
Location bottom = this.getBottomAbs();
- Location location = new Location(bottom.getWorld(), bottom.getX() + home.getX(),
+ Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(),
bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(),
home.getPitch());
if (!isLoaded()) {
return location;
}
- if (!WorldUtil.IMP.getBlockSynchronous(location).getBlockType().getMaterial().isAir()) {
- location.setY(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;
@@ -1470,21 +1482,17 @@ public class Plot {
this.getDefaultHome(result);
} else {
Location bottom = this.getBottomAbs();
- Location location = new Location(bottom.getWorld(), bottom.getX() + home.getX(),
+ Location location = Location.at(bottom.getWorldName(), bottom.getX() + home.getX(),
bottom.getY() + home.getY(), bottom.getZ() + home.getZ(), home.getYaw(),
home.getPitch());
if (!isLoaded()) {
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(),
- y -> {
- location.setY(Math.max(1 + y, bottom.getY()));
- result.accept(location);
- });
+ this.worldUtil.getHighestBlock(this.getWorldName(), location.getX(), location.getZ(),
+ y -> result.accept(location.withY(Math.max(1 + y, bottom.getY()))));
} else {
result.accept(location);
}
@@ -1542,10 +1550,10 @@ 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 new Location(plot.getWorldName(), x, y, z);
+ return Location.at(plot.getWorldName(), x, y, z);
}
// Side
return plot.getSideSynchronous();
@@ -1572,13 +1580,13 @@ public class Plot {
}
if (loc.getY() < 1) {
if (isLoaded()) {
- WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z,
- y -> result.accept(new Location(plot.getWorldName(), x, y + 1, z)));
+ this.worldUtil.getHighestBlock(plot.getWorldName(), x, z,
+ y -> result.accept(Location.at(plot.getWorldName(), x, y + 1, z)));
} else {
- result.accept(new Location(plot.getWorldName(), x, 63, z));
+ result.accept(Location.at(plot.getWorldName(), x, 63, z));
}
} else {
- result.accept(new Location(plot.getWorldName(), x, loc.getY(), z));
+ result.accept(Location.at(plot.getWorldName(), x, loc.getY(), z));
}
return;
}
@@ -1675,7 +1683,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 chunks = new HashSet<>();
for (CuboidRegion region : Plot.this.getRegions()) {
for (int x = region.getMinimumPoint().getX() >> 4;
@@ -1699,7 +1707,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();
@@ -1713,7 +1721,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));
}
@@ -1729,24 +1737,20 @@ public class Plot {
return this.create(this.owner, true);
}
- public boolean claim(@NotNull final PlotPlayer player, boolean teleport, String schematic) {
+ public boolean claim(@Nonnull final PlotPlayer player, boolean teleport, String schematic) {
if (!canClaim(player)) {
- PlotSquared.debug(Captions.PREFIX.getTranslated() + String
- .format("Player %s attempted to claim plot %s, but was not allowed",
- player.getName(), this.getId().toCommaSeparatedString()));
return false;
}
return claim(player, teleport, schematic, true);
}
- public boolean claim(@NotNull final PlotPlayer player, boolean teleport, String schematic,
+ public boolean claim(@Nonnull final PlotPlayer player, boolean teleport, String schematic,
boolean updateDB) {
if (updateDB) {
if (!create(player.getUUID(), true)) {
- PlotSquared.debug(Captions.PREFIX.getTranslated() + String.format(
- "Player %s attempted to claim plot %s, but the database failed to update",
- player.getName(), this.getId().toCommaSeparatedString()));
+ logger.error("[P2] Player {} attempted to claim plot {}, but the database failed to update",
+ player.getName(), this.getId().toCommaSeparatedString());
return false;
}
} else {
@@ -1764,18 +1768,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() {
@Override public void run(Boolean value) {
if (value) {
@@ -1800,7 +1804,7 @@ public class Plot {
* @param notify notify
* @return true if plot was created successfully
*/
- public boolean create(@NotNull UUID uuid, final boolean notify) {
+ public boolean create(@Nonnull UUID uuid, final boolean notify) {
this.setOwnerAbs(uuid);
Plot existing = this.area.getOwnedPlotAbs(this.id);
if (existing != null) {
@@ -1822,8 +1826,8 @@ public class Plot {
DBFunc.createPlotAndSettings(this, () -> {
PlotArea plotworld = Plot.this.area;
if (notify && plotworld.isAutoMerge()) {
- PlotPlayer player = WorldUtil.IMP.wrapPlayer(uuid);
- PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
+ PlotPlayer player = this.worldUtil.wrapPlayer(uuid);
+ PlotMergeEvent event = this.eventDispatcher
.callMerge(this, Direction.ALL, Integer.MAX_VALUE, player);
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Auto merge on claim");
@@ -1834,9 +1838,8 @@ public class Plot {
});
return true;
}
- PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + String
- .format("Failed to add plot %s to plot area %s", this.getId().toCommaSeparatedString(),
- this.area.toString()));
+ logger.info("[P2] Failed to add plot {} to plot area {}",
+ this.getId().toCommaSeparatedString(), this.area.toString());
return false;
}
@@ -1856,8 +1859,8 @@ public class Plot {
* Retrieve the biome of the plot.
*/
public void getBiome(Consumer result) {
- this.getCenter(location -> WorldUtil.IMP
- .getBiome(location.getWorld(), location.getX(), location.getZ(), result));
+ this.getCenter(location -> this.worldUtil
+ .getBiome(location.getWorldName(), location.getX(), location.getZ(), result));
}
/**
@@ -1865,8 +1868,8 @@ public class Plot {
*/
@Deprecated public BiomeType getBiomeSynchronous() {
final Location location = this.getCenterSynchronous();
- return WorldUtil.IMP
- .getBiomeSynchronous(location.getWorld(), location.getX(), location.getZ());
+ return this.worldUtil
+ .getBiomeSynchronous(location.getWorldName(), location.getX(), location.getZ());
}
//TODO Better documentation needed.
@@ -1875,9 +1878,7 @@ public class Plot {
* Returns the top location for the plot.
*/
public Location getTopAbs() {
- Location top = getManager().getPlotTopLocAbs(this.id);
- top.setWorld(getWorldName());
- return top;
+ return this.getManager().getPlotTopLocAbs(this.id).withWorld(this.getWorldName());
}
//TODO Better documentation needed.
@@ -1886,9 +1887,7 @@ public class Plot {
* Returns the bottom location for the plot.
*/
public Location getBottomAbs() {
- Location location = getManager().getPlotBottomLocAbs(this.id);
- location.setWorld(getWorldName());
- return location;
+ return this.getManager().getPlotBottomLocAbs(this.id).withWorld(this.getWorldName());
}
/**
@@ -1934,12 +1933,10 @@ public class Plot {
*/
public boolean moveData(Plot plot, Runnable whenDone) {
if (!this.hasOwner()) {
- PlotSquared.debug(plot + " is unowned (single)");
TaskManager.runTask(whenDone);
return false;
}
if (plot.hasOwner()) {
- PlotSquared.debug(plot + " is unowned (multi)");
TaskManager.runTask(whenDone);
return false;
}
@@ -1965,10 +1962,10 @@ public class Plot {
return top;
}
if (this.getMerged(Direction.SOUTH)) {
- top.setZ(this.getRelative(Direction.SOUTH).getBottomAbs().getZ() - 1);
+ top = top.withZ(this.getRelative(Direction.SOUTH).getBottomAbs().getZ() - 1);
}
if (this.getMerged(Direction.EAST)) {
- top.setX(this.getRelative(Direction.EAST).getBottomAbs().getX() - 1);
+ top = top.withX(this.getRelative(Direction.EAST).getBottomAbs().getX() - 1);
}
return top;
}
@@ -1986,10 +1983,10 @@ public class Plot {
return bot;
}
if (this.getMerged(Direction.NORTH)) {
- bot.setZ(this.getRelative(Direction.NORTH).getTopAbs().getZ() + 1);
+ bot = bot.withZ(this.getRelative(Direction.NORTH).getTopAbs().getZ() + 1);
}
if (this.getMerged(Direction.WEST)) {
- bot.setX(this.getRelative(Direction.WEST).getTopAbs().getX() + 1);
+ bot = bot.withX(this.getRelative(Direction.WEST).getTopAbs().getX() + 1);
}
return bot;
}
@@ -2019,9 +2016,9 @@ public class Plot {
Plot other = this.getRelative(Direction.EAST);
Location bot = other.getBottomAbs();
Location top = this.getTopAbs();
- Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ());
- Location pos2 = new Location(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ());
- RegionManager.manager.regenerateRegion(pos1, pos2, true, null);
+ Location pos1 = Location.at(this.getWorldName(), top.getX(), 0, bot.getZ());
+ Location pos2 = Location.at(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ());
+ 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);
@@ -2175,7 +2172,7 @@ public class Plot {
* Export the plot as a schematic to the configured output directory.
*/
public void export(final RunnableVal whenDone) {
- SchematicHandler.manager.getCompoundTag(this, new RunnableVal() {
+ this.schematicHandler.getCompoundTag(this, new RunnableVal() {
@Override public void run(final CompoundTag value) {
if (value == null) {
if (whenDone != null) {
@@ -2186,7 +2183,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;
@@ -2204,9 +2201,9 @@ public class Plot {
* @param whenDone value will be null if uploading fails
*/
public void upload(final RunnableVal whenDone) {
- SchematicHandler.manager.getCompoundTag(this, new RunnableVal() {
+ this.schematicHandler.getCompoundTag(this, new RunnableVal() {
@Override public void run(CompoundTag value) {
- SchematicHandler.manager.upload(value, null, null, whenDone);
+ schematicHandler.upload(value, null, null, whenDone);
}
});
}
@@ -2220,7 +2217,7 @@ public class Plot {
* @see WorldUtil
*/
public void uploadWorld(RunnableVal whenDone) {
- WorldUtil.IMP.upload(this, null, null, whenDone);
+ this.worldUtil.upload(this, null, null, whenDone);
}
@Override public boolean equals(Object obj) {
@@ -2366,7 +2363,7 @@ public class Plot {
*
* @param player the claiming player
*/
- public boolean canClaim(@NotNull PlotPlayer player) {
+ public boolean canClaim(@Nonnull PlotPlayer player) {
PlotCluster cluster = this.getCluster();
if (cluster != null) {
if (!cluster.isAdded(player.getUUID()) && !Permissions
@@ -2391,9 +2388,9 @@ public class Plot {
Plot other = this.getRelative(Direction.SOUTH);
Location bot = other.getBottomAbs();
Location top = this.getTopAbs();
- Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ());
- Location pos2 = new Location(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ());
- RegionManager.manager.regenerateRegion(pos1, pos2, true, null);
+ Location pos1 = Location.at(this.getWorldName(), bot.getX(), 0, top.getZ());
+ Location pos2 = Location.at(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ());
+ 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);
@@ -2567,11 +2564,9 @@ public class Plot {
if (this.area.getType() != PlotAreaType.NORMAL
&& this.area.getTerrain() == PlotAreaTerrainType.ROAD) {
Plot other = this.getRelative(1, 1);
- Location pos1 = this.getTopAbs().add(1, 0, 1);
- Location pos2 = other.getBottomAbs().subtract(1, 0, 1);
- pos1.setY(0);
- pos2.setY(MAX_HEIGHT);
- RegionManager.manager.regenerateRegion(pos1, pos2, true, null);
+ Location pos1 = this.getTopAbs().add(1, 0, 1).withY(0);
+ Location pos2 = other.getBottomAbs().subtract(1, 0, 1).withY(MAX_HEIGHT);
+ 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);
@@ -2647,7 +2642,6 @@ public class Plot {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH));
if (!tmp.getMerged(Direction.SOUTH)) {
// invalid merge
- PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.SOUTH, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
@@ -2664,7 +2658,6 @@ public class Plot {
assert tmp != null;
if (!tmp.getMerged(Direction.WEST)) {
// invalid merge
- PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.WEST, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
@@ -2681,7 +2674,6 @@ public class Plot {
assert tmp != null;
if (!tmp.getMerged(Direction.NORTH)) {
// invalid merge
- PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.NORTH, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
@@ -2697,7 +2689,6 @@ public class Plot {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST));
if (!tmp.getMerged(Direction.EAST)) {
// invalid merge
- PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.EAST, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
@@ -2712,10 +2703,6 @@ public class Plot {
Plot current;
while ((current = frontier.poll()) != null) {
if (!current.hasOwner() || current.settings == null) {
- // Invalid plot
- // merged onto unclaimed plot
- PlotSquared.debug(
- "Ignoring invalid merged plot: " + current + " | " + current.getOwnerAbs());
continue;
}
tmpSet.add(current);
@@ -2760,7 +2747,7 @@ public class Plot {
*
* @return
*/
- @NotNull public Set getRegions() {
+ @Nonnull public Set getRegions() {
if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) {
return regions_cache;
}
@@ -2919,13 +2906,13 @@ public class Plot {
public void reEnter() {
TaskManager.runTaskLater(() -> {
for (PlotPlayer> pp : Plot.this.getPlayersInPlot()) {
- PlotListener.plotExit(pp, Plot.this);
- PlotListener.plotEntry(pp, Plot.this);
+ this.plotListener.plotExit(pp, Plot.this);
+ this.plotListener.plotEntry(pp, Plot.this);
}
}, 1);
}
- public void debug(@NotNull final String message) {
+ public void debug(@Nonnull final String message) {
try {
final Collection> players = PlotPlayer.getDebugModePlayersInPlot(this);
if (players.isEmpty()) {
@@ -2963,7 +2950,7 @@ public class Plot {
int x = (int) MathMan.inverseRound(coords[0]);
int z = (int) MathMan.inverseRound(coords[1]);
if (type != 4) {
- locs.add(new Location(this.getWorldName(), x, 0, z));
+ locs.add(Location.at(this.getWorldName(), x, 0, z));
}
}
return locs;
@@ -2990,7 +2977,7 @@ public class Plot {
Consumer resultConsumer) {
Plot plot = this.getBasePlot(false);
Result result =
- PlotSquared.get().getEventDispatcher().callTeleport(player, player.getLocation(), plot)
+ this.eventDispatcher.callTeleport(player, player.getLocation(), plot)
.getEventResult();
if (result == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Teleport");
@@ -3037,11 +3024,11 @@ public class Plot {
return false;
}
if (!isMerged()) {
- return PlotSquared.imp().getPlayerManager()
+ return PlotSquared.platform().getPlayerManager()
.getPlayerIfExists(Objects.requireNonNull(this.getOwnerAbs())) != null;
}
for (final Plot current : getConnectedPlots()) {
- if (current.hasOwner() && PlotSquared.imp().getPlayerManager()
+ if (current.hasOwner() && PlotSquared.platform().getPlayerManager()
.getPlayerIfExists(Objects.requireNonNull(current.getOwnerAbs())) != null) {
return true;
}
@@ -3060,7 +3047,7 @@ public class Plot {
*/
public boolean setComponent(String component, Pattern blocks) {
PlotComponentSetEvent event =
- PlotSquared.get().getEventDispatcher().callComponentSet(this, component, blocks);
+ this.eventDispatcher.callComponentSet(this, component, blocks);
component = event.getComponent();
blocks = event.getPattern();
return this.getManager().setComponent(this.getId(), component, blocks);
@@ -3227,11 +3214,9 @@ public class Plot {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
Location pos1 = corners[0];
Location pos2 = corners[1];
- Location pos3 = pos1.clone().add(offsetX, 0, offsetZ);
- Location pos4 = pos2.clone().add(offsetX, 0, offsetZ);
- pos3.setWorld(destination.getWorldName());
- pos4.setWorld(destination.getWorldName());
- RegionManager.manager.swap(pos1, pos2, pos3, pos4, this);
+ Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
+ Location pos4 = pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
+ regionManager.swap(pos1, pos2, pos3, pos4, this);
}
}
}.run();
@@ -3261,9 +3246,8 @@ public class Plot {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
final Location pos1 = corners[0];
final Location pos2 = corners[1];
- Location newPos = pos1.clone().add(offsetX, 0, offsetZ);
- newPos.setWorld(destination.getWorldName());
- RegionManager.manager.copyRegion(pos1, pos2, newPos, task);
+ Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
+ regionManager.copyRegion(pos1, pos2, newPos, task);
}
}.run();
}
@@ -3356,9 +3340,8 @@ public class Plot {
Location[] corners = MainUtil.getCorners(getWorldName(), region);
Location pos1 = corners[0];
Location pos2 = corners[1];
- Location newPos = pos1.clone().add(offsetX, 0, offsetZ);
- newPos.setWorld(destination.getWorldName());
- RegionManager.manager.copyRegion(pos1, pos2, newPos, this);
+ Location newPos = pos1 .add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
+ regionManager.copyRegion(pos1, pos2, newPos, this);
}
};
run.run();
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java
index 08ac2f962..9ad26c0aa 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java
@@ -35,8 +35,10 @@ import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.Settings;
+import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.generator.GridPlotWorld;
import com.plotsquared.core.generator.IndependentPlotGenerator;
+import com.plotsquared.core.inject.annotations.WorldConfig;
import com.plotsquared.core.location.Direction;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.location.PlotLoc;
@@ -64,8 +66,10 @@ import com.sk89q.worldedit.world.gamemode.GameModes;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
@@ -85,14 +89,16 @@ import java.util.function.Consumer;
*/
public abstract class PlotArea {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotArea.class.getSimpleName());
+
protected final ConcurrentHashMap plots = new ConcurrentHashMap<>();
- @Getter @NotNull private final String worldName;
+ @Getter @Nonnull private final String worldName;
@Getter private final String id;
- @Getter @NotNull private final PlotManager plotManager;
+ @Getter @Nonnull private final PlotManager plotManager;
@Getter private final int worldHash;
private final PlotId min;
private final PlotId max;
- @Getter @NotNull private final IndependentPlotGenerator generator;
+ @Getter @Nonnull private final IndependentPlotGenerator generator;
@Getter private int maxPlotMembers = 128;
@Getter private boolean autoMerge = false;
@Setter private boolean allowSigns = true;
@@ -133,13 +139,21 @@ public abstract class PlotArea {
@Getter private final FlagContainer roadFlagContainer =
new FlagContainer(GlobalFlagContainer.getInstance());
- public PlotArea(@NotNull final String worldName, @Nullable final String id,
- @NotNull IndependentPlotGenerator generator, @Nullable final PlotId min,
- @Nullable final PlotId max) {
+ private final YamlConfiguration worldConfiguration;
+ private final GlobalBlockQueue globalBlockQueue;
+ private final EconHandler econHandler;
+
+ public PlotArea(@Nonnull final String worldName, @Nullable final String id,
+ @Nonnull IndependentPlotGenerator generator, @Nullable final PlotId min,
+ @Nullable final PlotId max,
+ @WorldConfig @Nullable final YamlConfiguration worldConfiguration,
+ @Nonnull 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(
@@ -152,12 +166,14 @@ public abstract class PlotArea {
this.max = max;
}
this.worldHash = worldName.hashCode();
+ this.worldConfiguration = worldConfiguration;
+ this.econHandler = econHandler;
}
- @NotNull protected abstract PlotManager createManager();
+ @Nonnull protected abstract PlotManager createManager();
public LocalBlockQueue getQueue(final boolean autoQueue) {
- return GlobalBlockQueue.IMP.getNewQueue(worldName, autoQueue);
+ return this.globalBlockQueue.getNewQueue(worldName, autoQueue);
}
/**
@@ -234,8 +250,8 @@ public abstract class PlotArea {
* @param plotArea the {@code PlotArea} to compare
* @return true if both areas are compatible
*/
- public boolean isCompatible(PlotArea plotArea) {
- ConfigurationSection section = PlotSquared.get().worlds.getConfigurationSection("worlds");
+ public boolean isCompatible(@Nonnull final PlotArea plotArea) {
+ final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
for (ConfigurationNode setting : plotArea.getSettingNodes()) {
Object constant = section.get(plotArea.worldName + '.' + setting.getConstant());
if (constant == null || !constant
@@ -276,7 +292,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<>();
@@ -369,7 +385,6 @@ public abstract class PlotArea {
}
}
- PlotSquared.log(Captions.PREFIX + "&3 - default flags: &7" + flagBuilder.toString());
this.spawnEggs = config.getBoolean("event.spawn.egg");
this.spawnCustom = config.getBoolean("event.spawn.custom");
this.spawnBreeding = config.getBoolean("event.spawn.breeding");
@@ -405,7 +420,8 @@ public abstract class PlotArea {
prefix = ", ";
}
}
- PlotSquared.log(Captions.PREFIX + "&3 - road flags: &7" + roadFlagBuilder.toString());
+
+ logger.info("[P2] - road flags: {}", roadFlagBuilder.toString());
loadConfiguration(config);
}
@@ -477,7 +493,7 @@ public abstract class PlotArea {
}
}
- @NotNull @Override public String toString() {
+ @Nonnull @Override public String toString() {
if (this.getId() == null) {
return this.getWorldName();
} else {
@@ -505,7 +521,7 @@ public abstract class PlotArea {
* @param location the location
* @return the {@code Plot} or null if none exists
*/
- @Nullable public Plot getPlotAbs(@NotNull final Location location) {
+ @Nullable public Plot getPlotAbs(@Nonnull final Location location) {
final PlotId pid =
this.getPlotManager().getPlotId(location.getX(), location.getY(), location.getZ());
if (pid == null) {
@@ -520,7 +536,7 @@ public abstract class PlotArea {
* @param location the location
* @return base Plot
*/
- @Nullable public Plot getPlot(@NotNull final Location location) {
+ @Nullable public Plot getPlot(@Nonnull final Location location) {
final PlotId pid =
this.getPlotManager().getPlotId(location.getX(), location.getY(), location.getZ());
if (pid == null) {
@@ -535,7 +551,7 @@ public abstract class PlotArea {
* @param location the location
* @return the base plot or null
*/
- @Nullable public Plot getOwnedPlot(@NotNull final Location location) {
+ @Nullable public Plot getOwnedPlot(@Nonnull final Location location) {
final PlotId pid =
this.getPlotManager().getPlotId(location.getX(), location.getY(), location.getZ());
if (pid == null) {
@@ -551,7 +567,7 @@ public abstract class PlotArea {
* @param location the location
* @return Plot or null
*/
- @Nullable public Plot getOwnedPlotAbs(@NotNull final Location location) {
+ @Nullable public Plot getOwnedPlotAbs(@Nonnull final Location location) {
final PlotId pid =
this.getPlotManager().getPlotId(location.getX(), location.getY(), location.getZ());
if (pid == null) {
@@ -566,11 +582,11 @@ public abstract class PlotArea {
* @param id the {@code PlotId}
* @return the plot or null
*/
- @Nullable public Plot getOwnedPlotAbs(@NotNull final PlotId id) {
+ @Nullable public Plot getOwnedPlotAbs(@Nonnull final PlotId id) {
return this.plots.get(id);
}
- @Nullable public Plot getOwnedPlot(@NotNull final PlotId id) {
+ @Nullable public Plot getOwnedPlot(@Nonnull final PlotId id) {
Plot plot = this.plots.get(id);
return plot == null ? null : plot.getBasePlot(false);
}
@@ -579,17 +595,17 @@ public abstract class PlotArea {
return this.getType() != PlotAreaType.PARTIAL || RegionUtil.contains(getRegionAbs(), x, z);
}
- public boolean contains(@NotNull final PlotId id) {
+ public boolean contains(@Nonnull final PlotId id) {
return this.min == null || (id.x >= this.min.x && id.x <= this.max.x && id.y >= this.min.y
&& id.y <= this.max.y);
}
- public boolean contains(@NotNull final Location location) {
- return StringMan.isEqual(location.getWorld(), this.getWorldName()) && (
+ public boolean contains(@Nonnull final Location location) {
+ return StringMan.isEqual(location.getWorldName(), this.getWorldName()) && (
getRegionAbs() == null || this.region.contains(location.getBlockVector3()));
}
- @NotNull public Set getPlotsAbs(final UUID uuid) {
+ @Nonnull public Set getPlotsAbs(final UUID uuid) {
if (uuid == null) {
return Collections.emptySet();
}
@@ -602,7 +618,7 @@ public abstract class PlotArea {
return myPlots;
}
- @NotNull public Set getPlots(@NotNull final UUID uuid) {
+ @Nonnull public Set getPlots(@Nonnull final UUID uuid) {
return getPlots().stream().filter(plot -> plot.isBasePlot() && plot.isOwner(uuid))
.collect(ImmutableSet.toImmutableSet());
}
@@ -616,7 +632,7 @@ public abstract class PlotArea {
return this.plots.values();
}
- public int getPlotCount(@NotNull final UUID uuid) {
+ public int getPlotCount(@Nonnull final UUID uuid) {
if (!Settings.Done.COUNTS_TOWARDS_LIMIT) {
return (int) getPlotsAbs(uuid).stream().filter(plot -> !DoneFlag.isDone(plot)).count();
}
@@ -628,21 +644,21 @@ public abstract class PlotArea {
*
* @deprecated Use {@link #getPlots(UUID)}
*/
- @Deprecated public Set getPlots(@NotNull final PlotPlayer player) {
+ @Deprecated public Set getPlots(@Nonnull final PlotPlayer player) {
return getPlots(player.getUUID());
}
- public boolean hasPlot(@NotNull final UUID uuid) {
+ public boolean hasPlot(@Nonnull final UUID uuid) {
return this.plots.entrySet().stream().anyMatch(entry -> entry.getValue().isOwner(uuid));
}
//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;
}
- @Nullable public Plot getPlotAbs(@NotNull final PlotId id) {
+ @Nullable public Plot getPlotAbs(@Nonnull final PlotId id) {
Plot plot = getOwnedPlotAbs(id);
if (plot == null) {
if (this.min != null && (id.x < this.min.x || id.x > this.max.x || id.y < this.min.y
@@ -654,7 +670,7 @@ public abstract class PlotArea {
return plot;
}
- @Nullable public Plot getPlot(@NotNull final PlotId id) {
+ @Nullable public Plot getPlot(@Nonnull final PlotId id) {
final Plot plot = getOwnedPlotAbs(id);
if (plot == null) {
if (this.min != null && (id.x < this.min.x || id.x > this.max.x || id.y < this.min.y
@@ -675,7 +691,7 @@ public abstract class PlotArea {
return this.plots.size();
}
- @Nullable public PlotCluster getCluster(@NotNull final Location location) {
+ @Nullable public PlotCluster getCluster(@Nonnull final Location location) {
final Plot plot = getPlot(location);
if (plot == null) {
return null;
@@ -684,8 +700,8 @@ public abstract class PlotArea {
}
@Nullable
- public PlotCluster getFirstIntersectingCluster(@NotNull final PlotId pos1,
- @NotNull final PlotId pos2) {
+ public PlotCluster getFirstIntersectingCluster(@Nonnull final PlotId pos1,
+ @Nonnull final PlotId pos2) {
if (this.clusters == null) {
return null;
}
@@ -697,7 +713,7 @@ public abstract class PlotArea {
return null;
}
- @Nullable PlotCluster getCluster(@NotNull final PlotId id) {
+ @Nullable PlotCluster getCluster(@Nonnull final PlotId id) {
return this.clusters != null ? this.clusters.get(id.x, id.y) : null;
}
@@ -706,14 +722,14 @@ public abstract class PlotArea {
*
* For persistent metadata use the flag system
*/
- public void setMeta(@NotNull final String key, @Nullable final Object value) {
+ public void setMeta(@Nonnull final String key, @Nullable final Object value) {
if (this.meta == null) {
this.meta = new ConcurrentHashMap<>();
}
this.meta.put(key, value);
}
- @NotNull public T getMeta(@NotNull final String key, @NotNull final T def) {
+ @Nonnull public T getMeta(@Nonnull final String key, @Nonnull final T def) {
final Object v = getMeta(key);
return v == null ? def : (T) v;
}
@@ -723,14 +739,14 @@ public abstract class PlotArea {
*
* For persistent metadata use the flag system
*/
- @Nullable public Object getMeta(@NotNull final String key) {
+ @Nullable public Object getMeta(@Nonnull final String key) {
if (this.meta != null) {
return this.meta.get(key);
}
return null;
}
- @SuppressWarnings("unused") @NotNull public Set getBasePlots() {
+ @SuppressWarnings("unused") @Nonnull public Set getBasePlots() {
final HashSet myPlots = new HashSet<>(getPlots());
myPlots.removeIf(plot -> !plot.isBasePlot());
return myPlots;
@@ -763,15 +779,15 @@ public abstract class PlotArea {
* @deprecated Use {@link #getPlotsMap()}
*/
//todo eventually remove
- @Deprecated @NotNull public Map getPlotsRaw() {
+ @Deprecated @Nonnull public Map getPlotsRaw() {
return ImmutableMap.copyOf(plots);
}
- @NotNull public Set> getPlotEntries() {
+ @Nonnull public Set> getPlotEntries() {
return this.plots.entrySet();
}
- public boolean addPlot(@NotNull final Plot plot) {
+ public boolean addPlot(@Nonnull final Plot plot) {
for (PlotPlayer pp : plot.getPlayersInPlot()) {
pp.setMeta(PlotPlayer.META_LAST_PLOT, plot);
}
@@ -809,7 +825,7 @@ public abstract class PlotArea {
return null;
}
- public boolean addPlotIfAbsent(@NotNull final Plot plot) {
+ public boolean addPlotIfAbsent(@Nonnull final Plot plot) {
if (this.plots.putIfAbsent(plot.getId(), plot) == null) {
for (PlotPlayer pp : plot.getPlayersInPlot()) {
pp.setMeta(PlotPlayer.META_LAST_PLOT, plot);
@@ -819,7 +835,7 @@ public abstract class PlotArea {
return false;
}
- public boolean addPlotAbs(@NotNull final Plot plot) {
+ public boolean addPlotAbs(@Nonnull final Plot plot) {
return this.plots.put(plot.getId(), plot) == null;
}
@@ -864,14 +880,14 @@ public abstract class PlotArea {
*
* @param key Meta data key
*/
- public void deleteMeta(@NotNull final String key) {
+ public void deleteMeta(@Nonnull final String key) {
if (this.meta != null) {
this.meta.remove(key);
}
}
- public boolean canClaim(@Nullable final PlotPlayer player, @NotNull final PlotId pos1,
- @NotNull final PlotId pos2) {
+ public boolean canClaim(@Nullable final PlotPlayer player, @Nonnull final PlotId pos1,
+ @Nonnull final PlotId pos2) {
if (pos1.x == pos2.x && pos1.y == pos2.y) {
if (getOwnedPlot(pos1) != null) {
return false;
@@ -897,11 +913,11 @@ public abstract class PlotArea {
return true;
}
- public boolean removePlot(@NotNull final PlotId id) {
+ public boolean removePlot(@Nonnull final PlotId id) {
return this.plots.remove(id) != null;
}
- public boolean mergePlots(@NotNull final List plotIds, final boolean removeRoads) {
+ public boolean mergePlots(@Nonnull final List plotIds, final boolean removeRoads) {
if (plotIds.size() < 2) {
return false;
}
@@ -974,7 +990,7 @@ public abstract class PlotArea {
* @param pos2 second corner of selection
* @return the plots in the selection which are owned
*/
- public Set getPlotSelectionOwned(@NotNull final PlotId pos1, @NotNull final PlotId pos2) {
+ public Set getPlotSelectionOwned(@Nonnull final PlotId pos1, @Nonnull final PlotId pos2) {
final int size = (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y);
final Set result = new HashSet<>();
if (size < 16 || size < getPlotCount()) {
@@ -1036,7 +1052,7 @@ public abstract class PlotArea {
* @param schematic the schematic to look for.
* @return true if the schematic exists, false otherwise.
*/
- public boolean hasSchematic(@NotNull String schematic) {
+ public boolean hasSchematic(@Nonnull String schematic) {
return getSchematics().contains(schematic.toLowerCase());
}
@@ -1101,10 +1117,12 @@ public abstract class PlotArea {
try {
flags.add(flagInstance.parse(split[1]));
} catch (final FlagParseException e) {
- PlotSquared.log(Captions.PREFIX.getTranslated() + String.format(
- "§cFailed to parse default flag with key §6'%s'§c and value: §6'%s'§c."
- + " Reason: %s. This flag will not be added as a default flag.",
- e.getFlag().getName(), e.getValue(), e.getErrorMessage()));
+ logger.warn("[P2] Failed to parse default flag with key '{}' and value '{}'. "
+ + "Reason: {}. This flag will not be added as a default flag.",
+ e.getFlag().getName(),
+ e.getValue(),
+ e.getErrorMessage());
+ e.printStackTrace();
}
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java b/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java
index c9de0e90c..ea7484129 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotCluster.java
@@ -31,6 +31,7 @@ import com.plotsquared.core.location.Location;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.RegionUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
+import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.UUID;
@@ -151,17 +152,17 @@ public class PlotCluster {
+ this.pos2.y;
}
- public void getHome(Consumer result) {
- BlockLoc home = this.settings.getPosition();
- Consumer locationConsumer = toReturn -> {
+ public void getHome(@Nonnull final Consumer result) {
+ final BlockLoc home = this.settings.getPosition();
+ Consumer locationConsumer = toReturn ->
MainUtil.getHighestBlock(this.area.getWorldName(), toReturn.getX(), toReturn.getZ(),
max -> {
if (max > toReturn.getY()) {
- toReturn.setY(1 + max);
+ result.accept(toReturn.withY(1 + max));
+ } else {
+ result.accept(toReturn);
}
- result.accept(toReturn);
- });
- };
+ });
if (home.getY() == 0) {
// default pos
Plot center = getCenterPlot();
@@ -170,7 +171,7 @@ public class PlotCluster {
if (toReturn.getY() == 0) {
PlotManager manager = this.area.getPlotManager();
Location locationSign = manager.getSignLoc(center);
- toReturn.setY(locationSign.getY());
+ toReturn = toReturn.withY(locationSign.getY());
}
locationConsumer.accept(toReturn);
});
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotId.java b/Core/src/main/java/com/plotsquared/core/plot/PlotId.java
index 41016da1f..3327c1473 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotId.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotId.java
@@ -26,8 +26,8 @@
package com.plotsquared.core.plot;
import com.plotsquared.core.location.Direction;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
public class PlotId {
@@ -53,14 +53,14 @@ public class PlotId {
* @return the PlotId representation of the arguement
* @throws IllegalArgumentException if the string does not contain a valid PlotId
*/
- @NotNull public static PlotId fromString(@NotNull String string) {
+ @Nonnull public static PlotId fromString(@Nonnull String string) {
PlotId plot = fromStringOrNull(string);
if (plot == null)
throw new IllegalArgumentException("Cannot create PlotID. String invalid.");
return plot;
}
- @Nullable public static PlotId fromStringOrNull(@NotNull String string) {
+ @Nullable public static PlotId fromStringOrNull(@Nonnull String string) {
String[] parts = string.split("[;,.]");
if (parts.length < 2) {
return null;
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java
index 88f9c100c..a810093b0 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotInventory.java
@@ -25,48 +25,48 @@
*/
package com.plotsquared.core.plot;
-import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.InventoryUtil;
-import lombok.NonNull;
+
+import javax.annotation.Nonnull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PlotInventory {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotInventory.class.getSimpleName());
+
private static final String META_KEY = "inventory";
public final PlotPlayer> player;
public final int size;
private final PlotItemStack[] items;
private String title;
private boolean open = false;
+ private final InventoryUtil inventoryUtil;
- 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) {
+ public PlotInventory(@Nonnull 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) {
+ public static boolean hasPlotInventoryOpen(@Nonnull final PlotPlayer> plotPlayer) {
return getOpenPlotInventory(plotPlayer) != null;
}
- public static PlotInventory getOpenPlotInventory(@NonNull final PlotPlayer> plotPlayer) {
+ public static PlotInventory getOpenPlotInventory(@Nonnull final PlotPlayer> plotPlayer) {
return plotPlayer.getMeta(META_KEY, null);
}
- public static void setPlotInventoryOpen(@NonNull final PlotPlayer> plotPlayer,
- @NonNull final PlotInventory plotInventory) {
+ public static void setPlotInventoryOpen(@Nonnull final PlotPlayer> plotPlayer,
+ @Nonnull final PlotInventory plotInventory) {
plotPlayer.setMeta(META_KEY, plotInventory);
}
- public static void removePlotInventoryOpen(@NonNull final PlotPlayer>plotPlayer) {
+ public static void removePlotInventoryOpen(@Nonnull final PlotPlayer>plotPlayer) {
plotPlayer.deleteMeta(META_KEY);
}
@@ -78,13 +78,10 @@ public class PlotInventory {
if (this.title == null) {
return;
}
- if (hasPlotInventoryOpen(player)) {
- PlotSquared.debug(String.format("Failed to open plot inventory for %s "
- + "because the player already has an open plot inventory", player.getName()));
- } else {
+ if (!hasPlotInventoryOpen(player)) {
this.open = true;
setPlotInventoryOpen(player, this);
- InventoryUtil.manager.open(this);
+ this.inventoryUtil.open(this);
}
}
@@ -93,13 +90,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) {
diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotWorld.java b/Core/src/main/java/com/plotsquared/core/plot/PlotWorld.java
index ed7b854c2..76f9d4c9f 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/PlotWorld.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/PlotWorld.java
@@ -28,8 +28,8 @@ package com.plotsquared.core.plot;
import com.plotsquared.core.location.Location;
import com.sk89q.worldedit.regions.CuboidRegion;
import lombok.EqualsAndHashCode;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.Collection;
@@ -46,7 +46,7 @@ public abstract class PlotWorld {
*
* @param world World name
*/
- protected PlotWorld(@NotNull final String world) {
+ protected PlotWorld(@Nonnull final String world) {
this.world = world;
}
@@ -57,14 +57,14 @@ public abstract class PlotWorld {
* @param location Location
* @return Containing plot area, or null
*/
- @Nullable public abstract PlotArea getArea(@NotNull final Location location);
+ @Nullable public abstract PlotArea getArea(@Nonnull final Location location);
/**
* Get all plot areas in the world
*
* @return All plot areas in the world
*/
- @NotNull public abstract Collection getAreas();
+ @Nonnull public abstract Collection getAreas();
/**
* Get all plot areas in a specified region
@@ -72,15 +72,15 @@ public abstract class PlotWorld {
* @param region Region
* @return All areas in the region
*/
- @NotNull public abstract Collection getAreasInRegion(
- @NotNull final CuboidRegion region);
+ @Nonnull public abstract Collection getAreasInRegion(
+ @Nonnull final CuboidRegion region);
/**
* Register a new area in the world
*
* @param area Plot area
*/
- public void addArea(@NotNull final PlotArea area) {
+ public void addArea(@Nonnull final PlotArea area) {
throw new UnsupportedOperationException("This world type does not allow adding new areas");
}
@@ -89,7 +89,7 @@ public abstract class PlotWorld {
*
* @param area Plot area
*/
- public void removeArea(@NotNull final PlotArea area) {
+ public void removeArea(@Nonnull final PlotArea area) {
throw new UnsupportedOperationException("This world type does not allow removing areas");
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java
index 532134536..e805ff87a 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java
@@ -31,7 +31,6 @@ import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotUnlinkEvent;
import com.plotsquared.core.events.Result;
-import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@@ -42,11 +41,16 @@ import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
import com.plotsquared.core.plot.flag.implementations.KeepFlag;
import com.plotsquared.core.plot.message.PlotMessage;
+import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.StringMan;
+import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.task.TaskManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
import java.util.ArrayDeque;
import java.util.ArrayList;
@@ -55,31 +59,34 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Objects;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
public class ExpireManager {
+ private final Logger logger = LoggerFactory.getLogger("P2/" + ExpireManager.class);
+
public static ExpireManager IMP;
private final ConcurrentHashMap dates_cache;
private final ConcurrentHashMap account_age_cache;
+ private final EventDispatcher eventDispatcher;
private volatile HashSet plotsToDelete;
private ArrayDeque tasks;
+
/**
* 0 = stopped, 1 = stopping, 2 = running
*/
private int running;
- public ExpireManager() {
- tasks = new ArrayDeque<>();
- dates_cache = new ConcurrentHashMap<>();
- account_age_cache = new ConcurrentHashMap<>();
+ public ExpireManager(@Nonnull final EventDispatcher eventDispatcher) {
+ this.tasks = new ArrayDeque<>();
+ this.dates_cache = new ConcurrentHashMap<>();
+ this.account_age_cache = new ConcurrentHashMap<>();
+ this.eventDispatcher = eventDispatcher;
}
public void addTask(ExpiryTask task) {
- PlotSquared.debug("Adding new expiry task!");
this.tasks.add(task);
}
@@ -295,7 +302,7 @@ public class ExpireManager {
}
this.running = 2;
final ConcurrentLinkedDeque plots =
- new ConcurrentLinkedDeque<>(PlotSquared.get().getPlots());
+ new ConcurrentLinkedDeque<>(PlotQuery.newQuery().allPlots().asList());
TaskManager.runTaskAsync(new Runnable() {
@Override public void run() {
final Runnable task = this;
@@ -319,7 +326,7 @@ public class ExpireManager {
}
for (ExpiryTask expiryTask : expired) {
if (!expiryTask.needsAnalysis()) {
- expiredTask.run(newPlot, () -> TaskManager.IMP.taskLaterAsync(task, 1),
+ expiredTask.run(newPlot, () -> TaskManager.getImplementation().taskLaterAsync(task, 1),
expiryTask.requiresConfirmation());
return;
}
@@ -330,7 +337,7 @@ public class ExpireManager {
passesComplexity(changed, expired, new RunnableVal() {
@Override public void run(Boolean confirmation) {
expiredTask.run(newPlot,
- () -> TaskManager.IMP.taskLaterAsync(task, 1),
+ () -> TaskManager.getImplementation().taskLaterAsync(task, 1),
confirmation);
}
}, () -> {
@@ -348,7 +355,7 @@ public class ExpireManager {
}
};
final Runnable doAnalysis =
- () -> HybridUtils.manager.analyzePlot(newPlot, handleAnalysis);
+ () -> PlotSquared.platform().getHybridUtils().analyzePlot(newPlot, handleAnalysis);
PlotAnalysis analysis = newPlot.getComplexity(null);
if (analysis != null) {
@@ -356,7 +363,7 @@ public class ExpireManager {
@Override public void run(Boolean value) {
doAnalysis.run();
}
- }, () -> TaskManager.IMP.taskLaterAsync(task, 1));
+ }, () -> TaskManager.getImplementation().taskLaterAsync(task, 1));
} else {
doAnalysis.run();
}
@@ -401,7 +408,7 @@ public class ExpireManager {
public void deleteWithMessage(Plot plot, Runnable whenDone) {
if (plot.isMerged()) {
- PlotUnlinkEvent event = PlotSquared.get().getEventDispatcher()
+ PlotUnlinkEvent event = this.eventDispatcher
.callUnlink(plot.getArea(), plot, true, false,
PlotUnlinkEvent.REASON.EXPIRE_DELETE);
if (event.getEventResult() != Result.DENY) {
@@ -409,41 +416,27 @@ public class ExpireManager {
}
}
for (UUID helper : plot.getTrusted()) {
- PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(helper);
+ PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
if (player != null) {
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
}
}
for (UUID helper : plot.getMembers()) {
- PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(helper);
+ PlotPlayer player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(helper);
if (player != null) {
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
}
}
- Set plots = plot.getConnectedPlots();
plot.deletePlot(whenDone);
- PlotAnalysis changed = plot.getComplexity(null);
- int changes = changed == null ? 0 : changed.changes_sd;
- int modified = changed == null ? 0 : changed.changes;
- PlotSquared.debug(
- "$2[&5Expire&dManager$2] &cDeleted expired plot: " + plot + " User:" + plot.getOwner()
- + " Delta:" + changes + "/" + modified + " Connected: " + StringMan
- .getString(plots));
- PlotSquared.debug("$4 - Area: " + plot.getArea());
- if (plot.hasOwner()) {
- PlotSquared.debug("$4 - Owner: " + plot.getOwner());
- } else {
- PlotSquared.debug("$4 - Owner: Unowned");
- }
}
public long getAge(UUID uuid) {
- if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid) != null) {
+ if (PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid) != null) {
return 0;
}
Long last = this.dates_cache.get(uuid);
if (last == null) {
- OfflinePlotPlayer opp = PlotSquared.imp().getPlayerManager().getOfflinePlayer(uuid);
+ OfflinePlotPlayer opp = PlotSquared.platform().getPlayerManager().getOfflinePlayer(uuid);
if (opp != null && (last = opp.getLastPlayed()) != 0) {
this.dates_cache.put(uuid, last);
} else {
@@ -458,7 +451,7 @@ public class ExpireManager {
public long getAge(Plot plot) {
if (!plot.hasOwner() || Objects.equals(DBFunc.EVERYONE, plot.getOwner())
- || PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwner()) != null || plot.getRunning() > 0) {
+ || PlotSquared.platform().getPlayerManager().getPlayerIfExists(plot.getOwner()) != null || plot.getRunning() > 0) {
return 0;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java
index a7cd1b86b..022a3dc93 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpiryTask.java
@@ -25,25 +25,31 @@
*/
package com.plotsquared.core.plot.expiration;
-import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
-import com.plotsquared.core.plot.PlotFilter;
+import com.plotsquared.core.plot.world.PlotAreaManager;
+import com.plotsquared.core.util.query.PlotQuery;
+import javax.annotation.Nonnull;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
public class ExpiryTask {
+
private final Settings.Auto_Clear settings;
+ private final PlotAreaManager plotAreaManager;
private long cutoffThreshold = Long.MIN_VALUE;
-
- public ExpiryTask(Settings.Auto_Clear settings) {
+
+ public ExpiryTask(final Settings.Auto_Clear settings, @Nonnull final PlotAreaManager plotAreaManager) {
this.settings = settings;
+ this.plotAreaManager = plotAreaManager;
}
public Settings.Auto_Clear getSettings() {
@@ -119,11 +125,13 @@ public class ExpiryTask {
}
public Set getPlotsToCheck() {
- return PlotSquared.get().getPlots(new PlotFilter() {
- @Override public boolean allowsArea(PlotArea area) {
- return ExpiryTask.this.allowsArea(area);
+ final Collection areas = new LinkedList<>();
+ for (final PlotArea plotArea : this.plotAreaManager.getAllPlotAreas()) {
+ if (this.allowsArea(plotArea)) {
+ areas.add(plotArea);
}
- });
+ }
+ return PlotQuery.newQuery().inAreas(areas).asSet();
}
public boolean applies(long diff) {
diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java
index f7d326411..49a202fcb 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/PlotAnalysis.java
@@ -31,8 +31,11 @@ import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.implementations.AnalysisFlag;
import com.plotsquared.core.util.MathMan;
+import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
@@ -43,6 +46,9 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
public class PlotAnalysis {
+
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotAnalysis.class.getSimpleName());
+
public static boolean running = false;
public int changes;
public int faces;
@@ -79,7 +85,7 @@ public class PlotAnalysis {
}
public static void analyzePlot(Plot plot, RunnableVal whenDone) {
- HybridUtils.manager.analyzePlot(plot, whenDone);
+ PlotSquared.platform().getInjector().getInstance(HybridUtils.class).analyzePlot(plot, whenDone);
}
/**
@@ -91,22 +97,26 @@ public class PlotAnalysis {
*/
public static void calcOptimalModifiers(final Runnable whenDone, final double threshold) {
if (running) {
- PlotSquared.debug("Calibration task already in progress!");
+ if (Settings.DEBUG) {
+ logger.info("[P2] Calibration task already in progress!");
+ }
return;
}
if (threshold <= 0 || threshold >= 1) {
- PlotSquared.debug(
- "Invalid threshold provided! (Cannot be 0 or 100 as then there's no point calibrating)");
+ if (Settings.DEBUG) {
+ logger.info(
+ "Invalid threshold provided! (Cannot be 0 or 100 as then there's no point in calibrating)");
+ }
return;
}
running = true;
- PlotSquared.debug(" - Fetching all plots");
- final ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots());
+ final List plots = PlotQuery.newQuery().allPlots().asList();
TaskManager.runTaskAsync(new Runnable() {
@Override public void run() {
Iterator iterator = plots.iterator();
- PlotSquared.debug(
- " - $1Reducing " + plots.size() + " plots to those with sufficient data");
+ if (Settings.DEBUG) {
+ logger.info("[P2] - Reducing {} plots to those with sufficient data", plots.size());
+ }
while (iterator.hasNext()) {
Plot plot = iterator.next();
if (plot.getSettings().getRatings() == null || plot.getSettings().getRatings()
@@ -116,11 +126,12 @@ public class PlotAnalysis {
plot.addRunning();
}
}
- PlotSquared.debug(" - | Reduced to " + plots.size() + " plots");
if (plots.size() < 3) {
- PlotSquared.debug(
- "Calibration cancelled due to insufficient comparison data, please try again later");
+ if (Settings.DEBUG) {
+ logger.info(
+ "Calibration cancelled due to insufficient comparison data, please try again later");
+ }
running = false;
for (Plot plot : plots) {
plot.removeRunning();
@@ -128,7 +139,9 @@ public class PlotAnalysis {
return;
}
- PlotSquared.debug(" - $1Analyzing plot contents (this may take a while)");
+ if (Settings.DEBUG) {
+ logger.info("[P2] - Analyzing plot contents (this may take a while)");
+ }
int[] changes = new int[plots.size()];
int[] faces = new int[plots.size()];
@@ -154,7 +167,9 @@ public class PlotAnalysis {
ratings[i] = (int) (
(plot.getAverageRating() + plot.getSettings().getRatings().size())
* 100);
- PlotSquared.debug(" | " + plot + " (rating) " + ratings[i]);
+ if (Settings.DEBUG) {
+ logger.info("[P2] | {} (rating) {}", plot, ratings[i]);
+ }
}
}
});
@@ -166,7 +181,9 @@ public class PlotAnalysis {
if (queuePlot == null) {
break;
}
- PlotSquared.debug(" | " + queuePlot);
+ if (Settings.DEBUG) {
+ logger.info("[P2] | {}", queuePlot);
+ }
final Object lock = new Object();
TaskManager.runTask(new Runnable() {
@Override public void run() {
@@ -196,20 +213,25 @@ public class PlotAnalysis {
}
}
- PlotSquared.debug(
- " - $1Waiting on plot rating thread: " + mi.intValue() * 100 / plots.size()
- + "%");
+ if (Settings.DEBUG) {
+ logger.info("[P2] - Waiting on plot rating thread: {}%", mi.intValue() * 100 / plots.size());
+ }
+
try {
ratingAnalysis.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
- PlotSquared
- .debug(" - $1Processing and grouping single plot analysis for bulk processing");
+ if (Settings.DEBUG) {
+ logger.info(
+ " - Processing and grouping single plot analysis for bulk processing");
+ }
for (int i = 0; i < plots.size(); i++) {
Plot plot = plots.get(i);
- PlotSquared.debug(" | " + plot);
+ if (Settings.DEBUG) {
+ logger.info("[P2] | {}", plot);
+ }
PlotAnalysis analysis = plot.getComplexity(null);
changes[i] = analysis.changes;
@@ -225,18 +247,22 @@ public class PlotAnalysis {
variety_sd[i] = analysis.variety_sd;
}
- PlotSquared.debug(" - $1Calculating rankings");
+ if (Settings.DEBUG) {
+ logger.info("[P2] - Calculating rankings");
+ }
int[] rankRatings = rank(ratings);
int n = rankRatings.length;
int optimalIndex = (int) Math.round((1 - threshold) * (n - 1));
- PlotSquared.debug(" - $1Calculating rank correlation: ");
- PlotSquared.debug(
- " - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking");
- PlotSquared.debug(
- " - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing");
+ if (Settings.DEBUG) {
+ logger.info("[P2] - Calculating rank correlation: ");
+ logger.info(
+ " - The analyzed plots which were processed and put into bulk data will be compared and correlated to the plot ranking");
+ logger.info(
+ " - The calculated correlation constant will then be used to calibrate the threshold for auto plot clearing");
+ }
Settings.Auto_Clear settings = new Settings.Auto_Clear();
@@ -248,7 +274,10 @@ public class PlotAnalysis {
settings.CALIBRATION.CHANGES = factorChanges == 1 ?
0 :
(int) (factorChanges * 1000 / MathMan.getMean(changes));
- PlotSquared.debug(" - | changes " + factorChanges);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | changes {}", factorChanges);
+ }
int[] rankFaces = rank(faces);
int[] sdFaces = getSD(rankFaces, rankRatings);
@@ -257,7 +286,10 @@ public class PlotAnalysis {
double factorFaces = getCC(n, sumFaces);
settings.CALIBRATION.FACES =
factorFaces == 1 ? 0 : (int) (factorFaces * 1000 / MathMan.getMean(faces));
- PlotSquared.debug(" - | faces " + factorFaces);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | faces {}", factorFaces);
+ }
int[] rankData = rank(data);
int[] sdData = getSD(rankData, rankRatings);
@@ -266,7 +298,10 @@ public class PlotAnalysis {
double factor_data = getCC(n, sum_data);
settings.CALIBRATION.DATA =
factor_data == 1 ? 0 : (int) (factor_data * 1000 / MathMan.getMean(data));
- PlotSquared.debug(" - | data " + factor_data);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | data {}", factor_data);
+ }
int[] rank_air = rank(air);
int[] sd_air = getSD(rank_air, rankRatings);
@@ -275,7 +310,10 @@ public class PlotAnalysis {
double factor_air = getCC(n, sum_air);
settings.CALIBRATION.AIR =
factor_air == 1 ? 0 : (int) (factor_air * 1000 / MathMan.getMean(air));
- PlotSquared.debug(" - | air " + factor_air);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | air {}", factor_air);
+ }
int[] rank_variety = rank(variety);
int[] sd_variety = getSD(rank_variety, rankRatings);
@@ -285,7 +323,10 @@ public class PlotAnalysis {
settings.CALIBRATION.VARIETY = factor_variety == 1 ?
0 :
(int) (factor_variety * 1000 / MathMan.getMean(variety));
- PlotSquared.debug(" - | variety " + factor_variety);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | variety {}", factor_variety);
+ }
int[] rank_changes_sd = rank(changes_sd);
int[] sd_changes_sd = getSD(rank_changes_sd, rankRatings);
@@ -295,7 +336,10 @@ public class PlotAnalysis {
settings.CALIBRATION.CHANGES_SD = factor_changes_sd == 1 ?
0 :
(int) (factor_changes_sd * 1000 / MathMan.getMean(changes_sd));
- PlotSquared.debug(" - | changes_sd " + factor_changes_sd);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | changed_sd {}", factor_changes_sd);
+ }
int[] rank_faces_sd = rank(faces_sd);
int[] sd_faces_sd = getSD(rank_faces_sd, rankRatings);
@@ -305,7 +349,10 @@ public class PlotAnalysis {
settings.CALIBRATION.FACES_SD = factor_faces_sd == 1 ?
0 :
(int) (factor_faces_sd * 1000 / MathMan.getMean(faces_sd));
- PlotSquared.debug(" - | faces_sd " + factor_faces_sd);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | faced_sd {}", factor_faces_sd);
+ }
int[] rank_data_sd = rank(data_sd);
int[] sd_data_sd = getSD(rank_data_sd, rankRatings);
@@ -315,7 +362,10 @@ public class PlotAnalysis {
settings.CALIBRATION.DATA_SD = factor_data_sd == 1 ?
0 :
(int) (factor_data_sd * 1000 / MathMan.getMean(data_sd));
- PlotSquared.debug(" - | data_sd " + factor_data_sd);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | data_sd {}", factor_data_sd);
+ }
int[] rank_air_sd = rank(air_sd);
int[] sd_air_sd = getSD(rank_air_sd, rankRatings);
@@ -324,7 +374,10 @@ public class PlotAnalysis {
double factor_air_sd = getCC(n, sum_air_sd);
settings.CALIBRATION.AIR_SD =
factor_air_sd == 1 ? 0 : (int) (factor_air_sd * 1000 / MathMan.getMean(air_sd));
- PlotSquared.debug(" - | air_sd " + factor_air_sd);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | air_sd {}", factor_air_sd);
+ }
int[] rank_variety_sd = rank(variety_sd);
int[] sd_variety_sd = getSD(rank_variety_sd, rankRatings);
@@ -334,11 +387,17 @@ public class PlotAnalysis {
settings.CALIBRATION.VARIETY_SD = factor_variety_sd == 1 ?
0 :
(int) (factor_variety_sd * 1000 / MathMan.getMean(variety_sd));
- PlotSquared.debug(" - | variety_sd " + factor_variety_sd);
+
+ if (Settings.DEBUG) {
+ logger.info("[P2] - | variety_sd {}", factor_variety_sd);
+ }
int[] complexity = new int[n];
- PlotSquared.debug(" $1Calculating threshold");
+ if (Settings.DEBUG) {
+ logger.info("[P2] Calculating threshold");
+ }
+
int max = 0;
int min = 0;
for (int i = 0; i < n; i++) {
@@ -367,9 +426,10 @@ public class PlotAnalysis {
logln("Correlation: ");
logln(getCC(n, sum(square(getSD(rankComplexity, rankRatings)))));
if (optimalComplexity == Integer.MAX_VALUE) {
- PlotSquared.debug(
- "Insufficient data to determine correlation! " + optimalIndex + " | "
- + n);
+ if (Settings.DEBUG) {
+ logger.info("[P2] Insufficient data to determine correlation! {} | {}",
+ optimalIndex, n);
+ }
running = false;
for (Plot plot : plots) {
plot.removeRunning();
@@ -387,21 +447,27 @@ public class PlotAnalysis {
}
// Save calibration
- PlotSquared.debug(" $1Saving calibration");
+ if (Settings.DEBUG) {
+ logger.info("[P2] Saving calibration");
+ }
Settings.AUTO_CLEAR.put("auto-calibrated", settings);
- Settings.save(PlotSquared.get().worldsFile);
- PlotSquared.debug("$1Done!");
+ Settings.save(PlotSquared.get().getWorldsFile());
running = false;
for (Plot plot : plots) {
plot.removeRunning();
}
+ if (Settings.DEBUG) {
+ logger.info("[P2] Done!");
+ }
whenDone.run();
}
});
}
public static void logln(Object obj) {
- PlotSquared.debug(log(obj));
+ if (Settings.DEBUG) {
+ logger.info("[P2] " + log(obj));
+ }
}
public static String log(Object obj) {
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java
index e0bb40fb8..b93d912c1 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java
@@ -27,11 +27,12 @@ package com.plotsquared.core.plot.flag;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
-import com.plotsquared.core.PlotSquared;
import lombok.EqualsAndHashCode;
import lombok.Setter;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,6 +45,8 @@ import java.util.Map;
*/
@EqualsAndHashCode(of = "flagMap") public class FlagContainer {
+ private static final Logger logger = LoggerFactory.getLogger("P2/" + FlagContainer.class.getSimpleName());
+
private final Map unknownFlags = new HashMap<>();
private final Map, PlotFlag, ?>> flagMap = new HashMap<>();
private final PlotFlagUpdateHandler plotFlagUpdateHandler;
@@ -145,11 +148,9 @@ import java.util.Map;
this.updateSubscribers
.forEach(subscriber -> subscriber.handle(flag, plotFlagUpdateType));
} catch (IllegalStateException e) {
- PlotSquared.log(String.format(
- "Flag '%s' (class: '%s') could not be added to the container"
- + " because the flag name exceeded the allowed limit of 64 characters."
- + " Please tell the developer of that flag to fix this.", flag.getName(),
- flag.getClass().getName()));
+ logger.info("[P2] Flag {} (class '{}') could not be added to the container because the "
+ + "flag name exceeded the allowed limit of 64 characters. Please tell the developer "
+ + "of the flag to fix this.", flag.getName(), flag.getClass().getName());
e.printStackTrace();
}
}
@@ -284,7 +285,7 @@ import java.util.Map;
* @param plotFlagUpdateHandler The update handler which will react to changes.
* @see PlotFlagUpdateType Plot flag update types
*/
- public void subscribe(@NotNull final PlotFlagUpdateHandler plotFlagUpdateHandler) {
+ public void subscribe(@Nonnull final PlotFlagUpdateHandler plotFlagUpdateHandler) {
this.updateSubscribers.add(plotFlagUpdateHandler);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/PlotFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/PlotFlag.java
index af3306b25..1007726df 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/PlotFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/PlotFlag.java
@@ -29,7 +29,7 @@ import com.google.common.base.Preconditions;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.Captions;
import lombok.EqualsAndHashCode;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
@@ -55,8 +55,8 @@ import java.util.Collections;
* @param flagCategory The flag category
* @param flagDescription A caption describing the flag functionality
*/
- protected PlotFlag(@NotNull final T value, @NotNull final Caption flagCategory,
- @NotNull final Caption flagDescription) {
+ protected PlotFlag(@Nonnull final T value, @Nonnull final Caption flagCategory,
+ @Nonnull final Caption flagDescription) {
this.value = Preconditions.checkNotNull(value, "flag value may not be null");
this.flagCategory =
Preconditions.checkNotNull(flagCategory, "flag category may not be null");
@@ -82,7 +82,7 @@ import java.util.Collections;
*
* @return Non-nullable flag value
*/
- @NotNull public final T getValue() {
+ @Nonnull public final T getValue() {
return this.value;
}
@@ -95,7 +95,7 @@ import java.util.Collections;
* @return Parsed value, if valid.
* @throws FlagParseException If the value could not be parsed.
*/
- public abstract F parse(@NotNull final String input) throws FlagParseException;
+ public abstract F parse(@Nonnull final String input) throws FlagParseException;
/**
* Merge this flag's value with another value and return an instance
@@ -104,7 +104,7 @@ import java.util.Collections;
* @param newValue New flag value.
* @return Flag containing parsed flag value.
*/
- public abstract F merge(@NotNull final T newValue);
+ public abstract F merge(@Nonnull final T newValue);
/**
* Returns a string representation of the flag instance, that when
@@ -154,7 +154,7 @@ import java.util.Collections;
*/
public abstract String getExample();
- protected abstract F flagOf(@NotNull T value);
+ protected abstract F flagOf(@Nonnull T value);
/**
* Create a new instance of the flag using a provided
@@ -163,7 +163,7 @@ import java.util.Collections;
* @param value The flag value
* @return The created flag instance
*/
- public final F createFlagInstance(@NotNull final T value) {
+ public final F createFlagInstance(@Nonnull final T value) {
return flagOf(Preconditions.checkNotNull(value));
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnalysisFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnalysisFlag.java
index 133f56df9..173d8caf2 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnalysisFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnalysisFlag.java
@@ -29,7 +29,7 @@ import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.InternalFlag;
import com.plotsquared.core.plot.flag.types.ListFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
@@ -40,7 +40,7 @@ public class AnalysisFlag extends ListFlag implements Int
super(valueList, Captions.NONE, Captions.NONE);
}
- @Override public AnalysisFlag parse(@NotNull String input) throws FlagParseException {
+ @Override public AnalysisFlag parse(@Nonnull String input) throws FlagParseException {
final String[] split = input.split(",");
final List numbers = new ArrayList<>();
for (final String element : split) {
@@ -53,7 +53,7 @@ public class AnalysisFlag extends ListFlag implements Int
return "";
}
- @Override protected AnalysisFlag flagOf(@NotNull List value) {
+ @Override protected AnalysisFlag flagOf(@Nonnull List value) {
return new AnalysisFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalAttackFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalAttackFlag.java
index 1ae0abc12..8eb750aa7 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalAttackFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalAttackFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class AnimalAttackFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class AnimalAttackFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_ANIMAL_ATTACK);
}
- @Override protected AnimalAttackFlag flagOf(@NotNull Boolean value) {
+ @Override protected AnimalAttackFlag flagOf(@Nonnull Boolean value) {
return value ? ANIMAL_ATTACK_TRUE : ANIMAL_ATTACK_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalCapFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalCapFlag.java
index 228ea94aa..78bdf65b2 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalCapFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalCapFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.NonNegativeIntegerFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class AnimalCapFlag extends NonNegativeIntegerFlag {
public static final AnimalCapFlag ANIMAL_CAP_UNLIMITED = new AnimalCapFlag(Integer.MAX_VALUE);
@@ -36,7 +36,7 @@ public class AnimalCapFlag extends NonNegativeIntegerFlag {
super(value, Captions.FLAG_DESCRIPTION_ANIMAL_CAP);
}
- @Override protected AnimalCapFlag flagOf(@NotNull Integer value) {
+ @Override protected AnimalCapFlag flagOf(@Nonnull Integer value) {
return new AnimalCapFlag(value);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalInteractFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalInteractFlag.java
index f19a479d3..00c854f88 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalInteractFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/AnimalInteractFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class AnimalInteractFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class AnimalInteractFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_ANIMAL_INTERACT);
}
- @Override protected AnimalInteractFlag flagOf(@NotNull Boolean value) {
+ @Override protected AnimalInteractFlag flagOf(@Nonnull Boolean value) {
return value ? ANIMAL_INTERACT_TRUE : ANIMAL_INTERACT_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockBurnFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockBurnFlag.java
index ac50b91b3..202513067 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockBurnFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockBurnFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class BlockBurnFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class BlockBurnFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_BLOCK_BURN);
}
- @Override protected BlockBurnFlag flagOf(@NotNull Boolean value) {
+ @Override protected BlockBurnFlag flagOf(@Nonnull Boolean value) {
return value ? BLOCK_BURN_TRUE : BLOCK_BURN_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockIgnitionFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockIgnitionFlag.java
index 4a2b7e205..add18aebf 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockIgnitionFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockIgnitionFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class BlockIgnitionFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class BlockIgnitionFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_BLOCK_IGNITION);
}
- @Override protected BlockIgnitionFlag flagOf(@NotNull Boolean value) {
+ @Override protected BlockIgnitionFlag flagOf(@Nonnull Boolean value) {
return value ? BLOCK_IGNITION_TRUE : BLOCK_IGNITION_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockedCmdsFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockedCmdsFlag.java
index d5b3eeca6..1bcdb39c2 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockedCmdsFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BlockedCmdsFlag.java
@@ -28,7 +28,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.types.ListFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collections;
@@ -44,7 +44,7 @@ public class BlockedCmdsFlag extends ListFlag {
Captions.FLAG_DESCRIPTION_BLOCKED_CMDS);
}
- @Override public BlockedCmdsFlag parse(@NotNull String input) throws FlagParseException {
+ @Override public BlockedCmdsFlag parse(@Nonnull String input) throws FlagParseException {
return flagOf(Arrays.asList(input.split(",")));
}
@@ -52,7 +52,7 @@ public class BlockedCmdsFlag extends ListFlag {
return "gamemode survival, spawn";
}
- @Override protected BlockedCmdsFlag flagOf(@NotNull List value) {
+ @Override protected BlockedCmdsFlag flagOf(@Nonnull List value) {
return new BlockedCmdsFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BreakFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BreakFlag.java
index 5acf7d489..c005efe5f 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BreakFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/BreakFlag.java
@@ -28,7 +28,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BlockTypeListFlag;
import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
@@ -41,7 +41,7 @@ public class BreakFlag extends BlockTypeListFlag {
super(blockTypeList, Captions.FLAG_DESCRIPTION_BREAK);
}
- @Override protected BreakFlag flagOf(@NotNull List value) {
+ @Override protected BreakFlag flagOf(@Nonnull List value) {
return new BreakFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ChatFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ChatFlag.java
index 81da5294a..8975375b0 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ChatFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ChatFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class ChatFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class ChatFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_CHAT);
}
- @Override protected ChatFlag flagOf(@NotNull Boolean value) {
+ @Override protected ChatFlag flagOf(@Nonnull Boolean value) {
return value ? CHAT_FLAG_TRUE : CHAT_FLAG_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CoralDryFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CoralDryFlag.java
index 84e98f9d6..da501eb6c 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CoralDryFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/CoralDryFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class CoralDryFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class CoralDryFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_CORAL_DRY);
}
- @Override protected CoralDryFlag flagOf(@NotNull Boolean value) {
+ @Override protected CoralDryFlag flagOf(@Nonnull Boolean value) {
return value ? CORAL_DRY_TRUE : CORAL_DRY_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyExitFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyExitFlag.java
index 17fe9f0e8..107cc360d 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyExitFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyExitFlag.java
@@ -27,7 +27,8 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+
+import javax.annotation.Nonnull;
public class DenyExitFlag extends BooleanFlag {
@@ -38,7 +39,7 @@ public class DenyExitFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_DENY_EXIT);
}
- @Override protected DenyExitFlag flagOf(@NotNull Boolean value) {
+ @Override protected DenyExitFlag flagOf(@Nonnull Boolean value) {
return value ? DENY_EXIT_FLAG_TRUE : DENY_EXIT_FLAG_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyTeleportFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyTeleportFlag.java
index ba923c396..e02a1b0e8 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyTeleportFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DenyTeleportFlag.java
@@ -30,8 +30,8 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
@@ -46,7 +46,7 @@ public class DenyTeleportFlag extends PlotFlag {
public static final DescriptionFlag DESCRIPTION_FLAG_EMPTY = new DescriptionFlag("");
- protected DescriptionFlag(@NotNull String value) {
+ protected DescriptionFlag(@Nonnull String value) {
super(value, Captions.FLAG_CATEGORY_STRING, Captions.FLAG_DESCRIPTION_DESCRIPTION);
}
- @Override public DescriptionFlag parse(@NotNull String input) {
+ @Override public DescriptionFlag parse(@Nonnull String input) {
return flagOf(input);
}
- @Override public DescriptionFlag merge(@NotNull String newValue) {
+ @Override public DescriptionFlag merge(@Nonnull String newValue) {
return flagOf(this.getValue() + " " + newValue);
}
@@ -53,7 +53,7 @@ public class DescriptionFlag extends PlotFlag {
return "&6This is my plot!";
}
- @Override protected DescriptionFlag flagOf(@NotNull String value) {
+ @Override protected DescriptionFlag flagOf(@Nonnull String value) {
return new DescriptionFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DeviceInteractFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DeviceInteractFlag.java
index f43e1e27a..981c4bfe4 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DeviceInteractFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DeviceInteractFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class DeviceInteractFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class DeviceInteractFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_DEVICE_INTERACT);
}
- @Override protected DeviceInteractFlag flagOf(@NotNull Boolean value) {
+ @Override protected DeviceInteractFlag flagOf(@Nonnull Boolean value) {
return value ? DEVICE_INTERACT_TRUE : DEVICE_INTERACT_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisablePhysicsFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisablePhysicsFlag.java
index f1d952260..a0578b1fe 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisablePhysicsFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DisablePhysicsFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class DisablePhysicsFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class DisablePhysicsFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_DISABLE_PHYSICS);
}
- @Override protected DisablePhysicsFlag flagOf(@NotNull Boolean value) {
+ @Override protected DisablePhysicsFlag flagOf(@Nonnull Boolean value) {
return value ? DISABLE_PHYSICS_TRUE : DISABLE_PHYSICS_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DoneFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DoneFlag.java
index 390ae4ba7..be94170fe 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DoneFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DoneFlag.java
@@ -29,7 +29,7 @@ import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.flag.InternalFlag;
import com.plotsquared.core.plot.flag.PlotFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class DoneFlag extends PlotFlag implements InternalFlag {
@@ -38,7 +38,7 @@ public class DoneFlag extends PlotFlag implements InternalFlag
*
* @param value Flag value
*/
- public DoneFlag(@NotNull String value) {
+ public DoneFlag(@Nonnull String value) {
super(value, Captions.NONE, Captions.NONE);
}
@@ -46,11 +46,11 @@ public class DoneFlag extends PlotFlag implements InternalFlag
return !plot.getFlag(DoneFlag.class).isEmpty();
}
- @Override public DoneFlag parse(@NotNull String input) {
+ @Override public DoneFlag parse(@Nonnull String input) {
return flagOf(input);
}
- @Override public DoneFlag merge(@NotNull String newValue) {
+ @Override public DoneFlag merge(@Nonnull String newValue) {
return flagOf(newValue);
}
@@ -62,7 +62,7 @@ public class DoneFlag extends PlotFlag implements InternalFlag
return "";
}
- @Override protected DoneFlag flagOf(@NotNull String value) {
+ @Override protected DoneFlag flagOf(@Nonnull String value) {
return new DoneFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DropProtectionFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DropProtectionFlag.java
index a210af66e..785d29b6e 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DropProtectionFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/DropProtectionFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class DropProtectionFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class DropProtectionFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_DROP_PROTECTION);
}
- @Override protected DropProtectionFlag flagOf(@NotNull Boolean value) {
+ @Override protected DropProtectionFlag flagOf(@Nonnull Boolean value) {
return value ? DROP_PROTECTION_TRUE : DROP_PROTECTION_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EntityCapFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EntityCapFlag.java
index e20e2dded..13b7b4d21 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EntityCapFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/EntityCapFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.NonNegativeIntegerFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class EntityCapFlag extends NonNegativeIntegerFlag {
public static final EntityCapFlag ENTITY_CAP_UNLIMITED = new EntityCapFlag(Integer.MAX_VALUE);
@@ -36,7 +36,7 @@ public class EntityCapFlag extends NonNegativeIntegerFlag {
super(value, Captions.FLAG_DESCRIPTION_ENTITY_CAP);
}
- @Override protected EntityCapFlag flagOf(@NotNull Integer value) {
+ @Override protected EntityCapFlag flagOf(@Nonnull Integer value) {
return new EntityCapFlag(value);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ExplosionFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ExplosionFlag.java
index 0f1f04a54..ed611d57d 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ExplosionFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ExplosionFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class ExplosionFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class ExplosionFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_EXPLOSION);
}
- @Override protected ExplosionFlag flagOf(@NotNull Boolean value) {
+ @Override protected ExplosionFlag flagOf(@Nonnull Boolean value) {
return value ? EXPLOSION_TRUE : EXPLOSION_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FarewellFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FarewellFlag.java
index 625f41cb8..1231d64a4 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FarewellFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FarewellFlag.java
@@ -27,21 +27,21 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.PlotFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class FarewellFlag extends PlotFlag {
public static final FarewellFlag FAREWELL_FLAG_EMPTY = new FarewellFlag("");
- protected FarewellFlag(@NotNull String value) {
+ protected FarewellFlag(@Nonnull String value) {
super(value, Captions.FLAG_CATEGORY_STRING, Captions.FLAG_DESCRIPTION_FAREWELL);
}
- @Override public FarewellFlag parse(@NotNull String input) {
+ @Override public FarewellFlag parse(@Nonnull String input) {
return flagOf(input);
}
- @Override public FarewellFlag merge(@NotNull String newValue) {
+ @Override public FarewellFlag merge(@Nonnull String newValue) {
return flagOf(this.getValue() + " " + newValue);
}
@@ -53,7 +53,7 @@ public class FarewellFlag extends PlotFlag {
return "&cBye :(";
}
- @Override protected FarewellFlag flagOf(@NotNull String value) {
+ @Override protected FarewellFlag flagOf(@Nonnull String value) {
return new FarewellFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java
index 11a0cac4a..05164b8d2 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FeedFlag.java
@@ -28,12 +28,12 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.types.TimedFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class FeedFlag extends TimedFlag {
public static final FeedFlag FEED_NOTHING = new FeedFlag(new Timed<>(0, 0));
- public FeedFlag(@NotNull Timed value) {
+ public FeedFlag(@Nonnull Timed value) {
super(value, 1, Captions.FLAG_DESCRIPTION_FEED);
}
@@ -58,7 +58,7 @@ public class FeedFlag extends TimedFlag {
return "10 5";
}
- @Override protected FeedFlag flagOf(@NotNull Timed value) {
+ @Override protected FeedFlag flagOf(@Nonnull Timed value) {
return new FeedFlag(value);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FlyFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FlyFlag.java
index ffe72a7b4..478e17858 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FlyFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/FlyFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.PlotFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
@@ -42,7 +42,7 @@ public class FlyFlag extends PlotFlag {
super(value, Captions.FLAG_CATEGORY_BOOLEAN, Captions.FLAG_DESCRIPTION_FLIGHT);
}
- @Override public FlyFlag parse(@NotNull final String input) {
+ @Override public FlyFlag parse(@Nonnull final String input) {
switch (input.toLowerCase()) {
case "true":
case "enabled":
@@ -57,7 +57,7 @@ public class FlyFlag extends PlotFlag {
}
}
- @Override public FlyFlag merge(@NotNull final FlyStatus newValue) {
+ @Override public FlyFlag merge(@Nonnull final FlyStatus newValue) {
if (newValue == FlyStatus.ENABLED || this.getValue() == FlyStatus.ENABLED) {
return FLIGHT_FLAG_ENABLED;
}
@@ -72,7 +72,7 @@ public class FlyFlag extends PlotFlag {
return "true";
}
- @Override protected FlyFlag flagOf(@NotNull final FlyStatus value) {
+ @Override protected FlyFlag flagOf(@Nonnull final FlyStatus value) {
switch (value) {
case ENABLED:
return FLIGHT_FLAG_ENABLED;
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ForcefieldFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ForcefieldFlag.java
index f8c985238..98136a7b3 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ForcefieldFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ForcefieldFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class ForcefieldFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class ForcefieldFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_FORCEFIELD);
}
- @Override protected ForcefieldFlag flagOf(@NotNull Boolean value) {
+ @Override protected ForcefieldFlag flagOf(@Nonnull Boolean value) {
return value ? FORCEFIELD_TRUE : FORCEFIELD_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GamemodeFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GamemodeFlag.java
index 60fdb4a0a..4c6b60020 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GamemodeFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GamemodeFlag.java
@@ -30,7 +30,7 @@ import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class GamemodeFlag extends PlotFlag {
@@ -52,11 +52,11 @@ public class GamemodeFlag extends PlotFlag {
*
* @param value Flag value
*/
- protected GamemodeFlag(@NotNull GameMode value) {
+ protected GamemodeFlag(@Nonnull GameMode value) {
super(value, Captions.FLAG_CATEGORY_GAMEMODE, Captions.FLAG_DESCRIPTION_GAMEMODE);
}
- @Override public GamemodeFlag parse(@NotNull String input) throws FlagParseException {
+ @Override public GamemodeFlag parse(@Nonnull String input) throws FlagParseException {
switch (input) {
case "creative":
case "c":
@@ -79,7 +79,7 @@ public class GamemodeFlag extends PlotFlag {
}
}
- @Override public GamemodeFlag merge(@NotNull GameMode newValue) {
+ @Override public GamemodeFlag merge(@Nonnull GameMode newValue) {
return flagOf(newValue);
}
@@ -91,7 +91,7 @@ public class GamemodeFlag extends PlotFlag {
return "survival";
}
- @Override protected GamemodeFlag flagOf(@NotNull GameMode value) {
+ @Override protected GamemodeFlag flagOf(@Nonnull GameMode value) {
switch (value.getId()) {
case "creative":
return GAMEMODE_FLAG_CREATIVE;
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GrassGrowFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GrassGrowFlag.java
index 7cb823667..ad63de5ee 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GrassGrowFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GrassGrowFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class GrassGrowFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class GrassGrowFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_GRASS_GROW);
}
- @Override protected GrassGrowFlag flagOf(@NotNull Boolean value) {
+ @Override protected GrassGrowFlag flagOf(@Nonnull Boolean value) {
return value ? GRASS_GROW_TRUE : GRASS_GROW_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GreetingFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GreetingFlag.java
index 0097defa8..3c6cc0163 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GreetingFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GreetingFlag.java
@@ -27,21 +27,21 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.PlotFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class GreetingFlag extends PlotFlag {
public static final GreetingFlag GREETING_FLAG_EMPTY = new GreetingFlag("");
- protected GreetingFlag(@NotNull String value) {
+ protected GreetingFlag(@Nonnull String value) {
super(value, Captions.FLAG_CATEGORY_STRING, Captions.FLAG_DESCRIPTION_GREETING);
}
- @Override public GreetingFlag parse(@NotNull String input) {
+ @Override public GreetingFlag parse(@Nonnull String input) {
return flagOf(input);
}
- @Override public GreetingFlag merge(@NotNull String newValue) {
+ @Override public GreetingFlag merge(@Nonnull String newValue) {
return flagOf(this.getValue() + " " + newValue);
}
@@ -53,7 +53,7 @@ public class GreetingFlag extends PlotFlag {
return "&6Welcome to my plot!";
}
- @Override protected GreetingFlag flagOf(@NotNull String value) {
+ @Override protected GreetingFlag flagOf(@Nonnull String value) {
return new GreetingFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GuestGamemodeFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GuestGamemodeFlag.java
index 8b320200e..090b056ea 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GuestGamemodeFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/GuestGamemodeFlag.java
@@ -30,7 +30,7 @@ import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class GuestGamemodeFlag extends PlotFlag {
@@ -50,11 +50,11 @@ public class GuestGamemodeFlag extends PlotFlag {
*
* @param value Flag value
*/
- protected GuestGamemodeFlag(@NotNull GameMode value) {
+ protected GuestGamemodeFlag(@Nonnull GameMode value) {
super(value, Captions.FLAG_CATEGORY_GAMEMODE, Captions.FLAG_DESCRIPTION_GUEST_GAMEMODE);
}
- @Override public GuestGamemodeFlag parse(@NotNull String input) throws FlagParseException {
+ @Override public GuestGamemodeFlag parse(@Nonnull String input) throws FlagParseException {
switch (input) {
case "creative":
case "c":
@@ -77,7 +77,7 @@ public class GuestGamemodeFlag extends PlotFlag {
}
}
- @Override public GuestGamemodeFlag merge(@NotNull GameMode newValue) {
+ @Override public GuestGamemodeFlag merge(@Nonnull GameMode newValue) {
return flagOf(newValue);
}
@@ -89,7 +89,7 @@ public class GuestGamemodeFlag extends PlotFlag {
return "survival";
}
- @Override protected GuestGamemodeFlag flagOf(@NotNull GameMode value) {
+ @Override protected GuestGamemodeFlag flagOf(@Nonnull GameMode value) {
switch (value.getId()) {
case "creative":
return GUEST_GAMEMODE_FLAG_CREATIVE;
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingBreakFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingBreakFlag.java
index f7a07a28a..ca7f1fb37 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingBreakFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingBreakFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HangingBreakFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class HangingBreakFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_HANGING_BREAK);
}
- @Override protected HangingBreakFlag flagOf(@NotNull Boolean value) {
+ @Override protected HangingBreakFlag flagOf(@Nonnull Boolean value) {
return value ? HANGING_BREAK_TRUE : HANGING_BREAK_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingPlaceFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingPlaceFlag.java
index 14923a319..eb3441ee1 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingPlaceFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HangingPlaceFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HangingPlaceFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class HangingPlaceFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_HANGING_PLACE);
}
- @Override protected HangingPlaceFlag flagOf(@NotNull Boolean value) {
+ @Override protected HangingPlaceFlag flagOf(@Nonnull Boolean value) {
return value ? HANGING_PLACE_TRUE : HANGING_PLACE_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java
index 90e5fbabb..e683b82a6 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HealFlag.java
@@ -28,12 +28,12 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.types.TimedFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HealFlag extends TimedFlag {
public static final HealFlag HEAL_NOTHING = new HealFlag(new Timed<>(0, 0));
- protected HealFlag(@NotNull Timed value) {
+ protected HealFlag(@Nonnull Timed value) {
super(value, 1, Captions.FLAG_DESCRIPTION_HEAL);
}
@@ -58,7 +58,7 @@ public class HealFlag extends TimedFlag {
return "20 2";
}
- @Override protected HealFlag flagOf(@NotNull Timed value) {
+ @Override protected HealFlag flagOf(@Nonnull Timed value) {
return new HealFlag(value);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HideInfoFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HideInfoFlag.java
index d382cac8f..81d85906f 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HideInfoFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HideInfoFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HideInfoFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class HideInfoFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_HIDE_INFO);
}
- @Override protected HideInfoFlag flagOf(@NotNull Boolean value) {
+ @Override protected HideInfoFlag flagOf(@Nonnull Boolean value) {
return value ? HIDE_INFO_TRUE : HIDE_INFO_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileAttackFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileAttackFlag.java
index 9ec805814..da5e8e4af 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileAttackFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileAttackFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HostileAttackFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class HostileAttackFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_HOSTILE_ATTACK);
}
- @Override protected HostileAttackFlag flagOf(@NotNull Boolean value) {
+ @Override protected HostileAttackFlag flagOf(@Nonnull Boolean value) {
return value ? HOSTILE_ATTACK_TRUE : HOSTILE_ATTACK_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileCapFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileCapFlag.java
index 017e3736a..9d442bb00 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileCapFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileCapFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.NonNegativeIntegerFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HostileCapFlag extends NonNegativeIntegerFlag {
public static final HostileCapFlag HOSTILE_CAP_UNLIMITED =
@@ -37,7 +37,7 @@ public class HostileCapFlag extends NonNegativeIntegerFlag {
super(value, Captions.FLAG_DESCRIPTION_HOSTILE_CAP);
}
- @Override protected HostileCapFlag flagOf(@NotNull Integer value) {
+ @Override protected HostileCapFlag flagOf(@Nonnull Integer value) {
return new HostileCapFlag(value);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileInteractFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileInteractFlag.java
index 96ce742b9..e903cd76c 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileInteractFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/HostileInteractFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class HostileInteractFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class HostileInteractFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_HOSTILE_INTERACT);
}
- @Override protected HostileInteractFlag flagOf(@NotNull Boolean value) {
+ @Override protected HostileInteractFlag flagOf(@Nonnull Boolean value) {
return value ? HOSTILE_INTERACT_TRUE : HOSTILE_INTERACT_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceFormFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceFormFlag.java
index a0f54097e..b380d0773 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceFormFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceFormFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class IceFormFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class IceFormFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_ICE_FORM);
}
- @Override protected IceFormFlag flagOf(@NotNull Boolean value) {
+ @Override protected IceFormFlag flagOf(@Nonnull Boolean value) {
return value ? ICE_FORM_TRUE : ICE_FORM_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceMeltFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceMeltFlag.java
index 0c1bf93a6..ef97c8964 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceMeltFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/IceMeltFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class IceMeltFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class IceMeltFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_ICE_MELT);
}
- @Override protected IceMeltFlag flagOf(@NotNull Boolean value) {
+ @Override protected IceMeltFlag flagOf(@Nonnull Boolean value) {
return value ? ICE_MELT_TRUE : ICE_MELT_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InstabreakFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InstabreakFlag.java
index 7c87fcff4..90d5632f1 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InstabreakFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InstabreakFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class InstabreakFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class InstabreakFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_INSTABREAK);
}
- @Override protected InstabreakFlag flagOf(@NotNull Boolean value) {
+ @Override protected InstabreakFlag flagOf(@Nonnull Boolean value) {
return value ? INSTABREAK_TRUE : INSTABREAK_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InvincibleFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InvincibleFlag.java
index b19e0d393..e3328a6a2 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InvincibleFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/InvincibleFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class InvincibleFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class InvincibleFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_INVINCIBLE);
}
- @Override protected InvincibleFlag flagOf(@NotNull Boolean value) {
+ @Override protected InvincibleFlag flagOf(@Nonnull Boolean value) {
return value ? INVINCIBLE_TRUE : INVINCIBLE_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ItemDropFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ItemDropFlag.java
index 1c71be3eb..654505a38 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ItemDropFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/ItemDropFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class ItemDropFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class ItemDropFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_ITEM_DROP);
}
- @Override protected ItemDropFlag flagOf(@NotNull Boolean value) {
+ @Override protected ItemDropFlag flagOf(@Nonnull Boolean value) {
return value ? ITEM_DROP_TRUE : ITEM_DROP_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepFlag.java
index ce23f2510..187237f2a 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepFlag.java
@@ -30,7 +30,7 @@ import com.plotsquared.core.plot.flag.FlagParseException;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class KeepFlag extends PlotFlag {
@@ -41,11 +41,11 @@ public class KeepFlag extends PlotFlag {
*
* @param value Flag value
*/
- protected KeepFlag(@NotNull Object value) {
+ protected KeepFlag(@Nonnull Object value) {
super(value, Captions.FLAG_CATEGORY_MIXED, Captions.FLAG_DESCRIPTION_KEEP);
}
- @Override public KeepFlag parse(@NotNull String input) throws FlagParseException {
+ @Override public KeepFlag parse(@Nonnull String input) throws FlagParseException {
if (MathMan.isInteger(input)) {
final long value = Long.parseLong(input);
if (value < 0) {
@@ -64,7 +64,7 @@ public class KeepFlag extends PlotFlag {
}
}
- @Override public KeepFlag merge(@NotNull Object newValue) {
+ @Override public KeepFlag merge(@Nonnull Object newValue) {
if (newValue.equals(true)) {
return flagOf(true);
} else if (newValue.equals(false)) {
@@ -93,7 +93,7 @@ public class KeepFlag extends PlotFlag {
return "3w 4d 2h";
}
- @Override protected KeepFlag flagOf(@NotNull Object value) {
+ @Override protected KeepFlag flagOf(@Nonnull Object value) {
return new KeepFlag(value);
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepInventoryFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepInventoryFlag.java
index 872c3157d..40592bfd3 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepInventoryFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KeepInventoryFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class KeepInventoryFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class KeepInventoryFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_KEEP_INVENTORY);
}
- @Override protected KeepInventoryFlag flagOf(@NotNull final Boolean value) {
+ @Override protected KeepInventoryFlag flagOf(@Nonnull final Boolean value) {
return value ? KEEP_INVENTORY_TRUE : KEEP_INVENTORY_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KelpGrowFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KelpGrowFlag.java
index 495db4160..43bcb5398 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KelpGrowFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/KelpGrowFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class KelpGrowFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class KelpGrowFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_KELP_GROW);
}
- @Override protected KelpGrowFlag flagOf(@NotNull Boolean value) {
+ @Override protected KelpGrowFlag flagOf(@Nonnull Boolean value) {
return value ? KELP_GROW_TRUE : KELP_GROW_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java
index c200ed6a9..c0c0e4f17 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/LiquidFlowFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.PlotFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collection;
@@ -43,7 +43,7 @@ public class LiquidFlowFlag extends PlotFlag {
@@ -38,7 +38,7 @@ public class MiscBreakFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_MISC_BREAK);
}
- @Override protected MiscBreakFlag flagOf(@NotNull Boolean value) {
+ @Override protected MiscBreakFlag flagOf(@Nonnull Boolean value) {
return value ? MISC_BREAK_TRUE : MISC_BREAK_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscCapFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscCapFlag.java
index 2291d6343..dfe55373e 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscCapFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscCapFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.NonNegativeIntegerFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class MiscCapFlag extends NonNegativeIntegerFlag {
public static final MiscCapFlag MISC_CAP_UNLIMITED = new MiscCapFlag(Integer.MAX_VALUE);
@@ -36,7 +36,7 @@ public class MiscCapFlag extends NonNegativeIntegerFlag {
super(value, Captions.FLAG_DESCRIPTION_MISC_CAP);
}
- @Override protected MiscCapFlag flagOf(@NotNull Integer value) {
+ @Override protected MiscCapFlag flagOf(@Nonnull Integer value) {
return new MiscCapFlag(value);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscInteractFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscInteractFlag.java
index a70191a9d..a64116119 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscInteractFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscInteractFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class MiscInteractFlag extends BooleanFlag {
@@ -38,7 +38,7 @@ public class MiscInteractFlag extends BooleanFlag {
super(value, Captions.FLAG_DESCRIPTION_MISC_INTERACT);
}
- @Override protected MiscInteractFlag flagOf(@NotNull Boolean value) {
+ @Override protected MiscInteractFlag flagOf(@Nonnull Boolean value) {
return value ? MISC_INTERACT_TRUE : MISC_INTERACT_FALSE;
}
diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscPlaceFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscPlaceFlag.java
index 8579d33df..2cf52f8e0 100644
--- a/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscPlaceFlag.java
+++ b/Core/src/main/java/com/plotsquared/core/plot/flag/implementations/MiscPlaceFlag.java
@@ -27,7 +27,7 @@ package com.plotsquared.core.plot.flag.implementations;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.plot.flag.types.BooleanFlag;
-import org.jetbrains.annotations.NotNull;
+import javax.annotation.Nonnull;
public class MiscPlaceFlag extends BooleanFlag