From 55bf41d2da0fc2c23f24d814abdc7692209d764b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Jul 2020 19:25:05 +0200 Subject: [PATCH] Remove dumdum static access --- .../plotsquared/bukkit/BukkitPlatform.java | 18 +- .../bukkit/listener/PlayerEvents.java | 17 +- .../bukkit/util/BukkitSetupUtils.java | 75 ++++---- .../java/com/plotsquared/core/PlotAPI.java | 21 --- .../com/plotsquared/core/PlotSquared.java | 170 +++++++++--------- .../core/annoations/ConfigFile.java | 36 ++++ .../core/annoations/WorldConfig.java | 36 ++++ .../core/annoations/WorldFile.java | 36 ++++ .../com/plotsquared/core/command/Area.java | 48 +++-- .../core/command/DatabaseCommand.java | 10 +- .../plotsquared/core/command/DebugExec.java | 9 +- .../plotsquared/core/command/DebugPaste.java | 16 +- .../plotsquared/core/command/MainCommand.java | 20 ++- .../com/plotsquared/core/command/Reload.java | 15 +- .../plotsquared/core/command/Template.java | 19 +- .../plotsquared/core/database/SQLManager.java | 21 ++- .../core/generator/ClassicPlotWorld.java | 16 +- .../core/generator/GridPlotWorld.java | 6 +- .../plotsquared/core/generator/HybridGen.java | 17 +- .../core/generator/HybridPlotWorld.java | 17 +- .../core/generator/SquarePlotWorld.java | 6 +- .../com/plotsquared/core/plot/PlotArea.java | 10 +- .../core/plot/expiration/PlotAnalysis.java | 2 +- .../core/plot/world/SinglePlotArea.java | 9 +- .../plot/world/SinglePlotAreaManager.java | 9 +- .../core/util/EventDispatcher.java | 41 +++-- .../core/plot/util/EventDispatcherTest.java | 154 ---------------- 27 files changed, 453 insertions(+), 401 deletions(-) create mode 100644 Core/src/main/java/com/plotsquared/core/annoations/ConfigFile.java create mode 100644 Core/src/main/java/com/plotsquared/core/annoations/WorldConfig.java create mode 100644 Core/src/main/java/com/plotsquared/core/annoations/WorldFile.java delete mode 100644 Core/src/test/java/com/plotsquared/core/plot/util/EventDispatcherTest.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index 11fdea5e3..90fbec806 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -70,6 +70,7 @@ 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; @@ -188,7 +189,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl private PlotAreaManager plotAreaManager; private EventDispatcher eventDispatcher; private PlotListener plotListener; - + private YamlConfiguration worldConfiguration; + private File worldfile; + @Override public int[] getServerVersion() { if (this.version == null) { try { @@ -224,6 +227,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl this.eventDispatcher = plotSquared.getEventDispatcher(); this.plotListener = plotSquared.getPlotListener(); this.playerManager = new BukkitPlayerManager(this.plotAreaManager, this.eventDispatcher); + this.worldConfiguration = plotSquared.getWorldConfiguration(); + this.worldfile = plotSquared.getWorldsFile(); if (PlotSquared.platform().getServerVersion()[1] < 13) { System.out.println( @@ -903,7 +908,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @Override public void registerPlayerEvents() { - final PlayerEvents main = new PlayerEvents(this.plotAreaManager, this.eventDispatcher); + final PlayerEvents main = new PlayerEvents(this.plotAreaManager, this.eventDispatcher, worldEdit); getServer().getPluginManager().registerEvents(main, this); getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { @@ -1002,7 +1007,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @Override public SetupUtils initSetupUtils() { - return new BukkitSetupUtils(this.plotAreaManager); + return new BukkitSetupUtils(this.plotAreaManager, this.worldConfiguration, this.worldfile); } @Override public void startMetrics() { @@ -1057,7 +1062,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() { - return new HybridGen(this.eventDispatcher, this.plotListener); + return new HybridGen(this.eventDispatcher, this.plotListener, this.worldConfiguration); } @Override public InventoryUtil initInventoryUtil() { @@ -1068,8 +1073,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl 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) .generatorName(worldConfig.getString("generator.init", manager)) @@ -1096,7 +1100,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen); } else if (gen != null) { PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager)); - } else if (PlotSquared.get().worlds.contains("worlds." + worldName)) { + } else if (this.worldConfiguration.contains("worlds." + worldName)) { PlotSquared.get().loadWorld(worldName, null); } } 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 a758387bf..37b73bdf4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -109,6 +109,7 @@ import com.plotsquared.core.util.PremiumVerification; import com.plotsquared.core.util.RegExUtil; 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; @@ -234,6 +235,7 @@ import java.util.regex.Pattern; private final PlotAreaManager plotAreaManager; private final EventDispatcher eventDispatcher; + private final WorldEdit worldEdit; private boolean pistonBlocks = true; private float lastRadius; @@ -243,10 +245,13 @@ import java.util.regex.Pattern; private PlayerMoveEvent moveTmp; private String internalVersion; - public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { + public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager, + @NotNull final EventDispatcher eventDispatcher, + @NotNull final WorldEdit worldEdit) { super(eventDispatcher); this.plotAreaManager = plotAreaManager; this.eventDispatcher = eventDispatcher; + this.worldEdit = worldEdit; try { fieldPlayer = PlayerEvent.class.getDeclaredField("player"); fieldPlayer.setAccessible(true); @@ -1077,9 +1082,9 @@ import java.util.regex.Pattern; 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; } } @@ -1150,7 +1155,7 @@ import java.util.regex.Pattern; 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"); @@ -2114,9 +2119,9 @@ import java.util.regex.Pattern; 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; } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index 809a93c72..838b620c5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -27,8 +27,11 @@ package com.plotsquared.bukkit.util; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.core.PlotSquared; +import com.plotsquared.core.annoations.WorldConfig; +import com.plotsquared.core.annoations.WorldFile; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; +import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotAreaType; @@ -45,6 +48,7 @@ import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map.Entry; @@ -53,9 +57,15 @@ import java.util.Objects; public class BukkitSetupUtils extends SetupUtils { private final PlotAreaManager plotAreaManager; + private final YamlConfiguration worldConfiguration; + private final File worldFile; - public BukkitSetupUtils(@NotNull final PlotAreaManager plotAreaManager) { + public BukkitSetupUtils(@NotNull final PlotAreaManager plotAreaManager, + @WorldConfig @NotNull final YamlConfiguration worldConfiguration, + @WorldFile @NotNull final File worldFile) { this.plotAreaManager = plotAreaManager; + this.worldConfiguration = worldConfiguration; + this.worldFile = worldFile; } @Override public void updateGenerators() { @@ -115,11 +125,10 @@ public class BukkitSetupUtils extends SetupUtils { switch (type) { case PARTIAL: { if (object.id != null) { - if (!PlotSquared.get().worlds.contains(worldPath)) { - PlotSquared.get().worlds.createSection(worldPath); + if (!this.worldConfiguration.contains(worldPath)) { + this.worldConfiguration.createSection(worldPath); } - ConfigurationSection worldSection = - PlotSquared.get().worlds.getConfigurationSection(worldPath); + ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath); String areaName = object.id + "-" + object.min + "-" + object.max; String areaPath = "areas." + areaName; if (!worldSection.contains(areaPath)) { @@ -159,26 +168,21 @@ public class BukkitSetupUtils extends SetupUtils { } case AUGMENTED: { if (!object.plotManager.endsWith(":single")) { - if (!PlotSquared.get().worlds.contains(worldPath)) { - PlotSquared.get().worlds.createSection(worldPath); + if (!this.worldConfiguration.contains(worldPath)) { + this.worldConfiguration.createSection(worldPath); } if (steps.length != 0) { - ConfigurationSection worldSection = - PlotSquared.get().worlds.getConfigurationSection(worldPath); + ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath); for (ConfigurationNode step : steps) { worldSection.set(step.getConstant(), step.getValue()); } } - PlotSquared.get().worlds - .set("worlds." + world + ".generator.type", object.type.toString()); - PlotSquared.get().worlds - .set("worlds." + world + ".generator.terrain", object.terrain.toString()); - PlotSquared.get().worlds - .set("worlds." + world + ".generator.plugin", object.plotManager); + this.worldConfiguration.set("worlds." + world + ".generator.type", object.type.toString()); + this.worldConfiguration.set("worlds." + world + ".generator.terrain", object.terrain.toString()); + this.worldConfiguration.set("worlds." + world + ".generator.plugin", object.plotManager); if (object.setupGenerator != null && !object.setupGenerator .equals(object.plotManager)) { - PlotSquared.get().worlds - .set("worlds." + world + ".generator.init", object.setupGenerator); + this.worldConfiguration.set("worlds." + world + ".generator.init", object.setupGenerator); } } GeneratorWrapper gen = SetupUtils.generators.get(object.setupGenerator); @@ -189,11 +193,10 @@ public class BukkitSetupUtils extends SetupUtils { } case NORMAL: { if (steps.length != 0) { - if (!PlotSquared.get().worlds.contains(worldPath)) { - PlotSquared.get().worlds.createSection(worldPath); + if (!this.worldConfiguration.contains(worldPath)) { + this.worldConfiguration.createSection(worldPath); } - ConfigurationSection worldSection = - PlotSquared.get().worlds.getConfigurationSection(worldPath); + ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath); for (ConfigurationNode step : steps) { worldSection.set(step.getConstant(), step.getValue()); } @@ -203,7 +206,7 @@ public class BukkitSetupUtils extends SetupUtils { } try { - PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); + this.worldConfiguration.save(this.worldFile); } catch (IOException e) { e.printStackTrace(); } @@ -228,11 +231,11 @@ public class BukkitSetupUtils extends SetupUtils { switch (type) { case PARTIAL: { if (builder.areaName() != null) { - if (!PlotSquared.get().worlds.contains(worldPath)) { - PlotSquared.get().worlds.createSection(worldPath); + if (!this.worldConfiguration.contains(worldPath)) { + this.worldConfiguration.createSection(worldPath); } ConfigurationSection worldSection = - PlotSquared.get().worlds.getConfigurationSection(worldPath); + this.worldConfiguration.getConfigurationSection(worldPath); String areaName = builder.areaName() + "-" + builder.minimumId() + "-" + builder.maximumId(); String areaPath = "areas." + areaName; if (!worldSection.contains(areaPath)) { @@ -272,25 +275,25 @@ public class BukkitSetupUtils extends SetupUtils { } case AUGMENTED: { if (!builder.plotManager().endsWith(":single")) { - if (!PlotSquared.get().worlds.contains(worldPath)) { - PlotSquared.get().worlds.createSection(worldPath); + if (!this.worldConfiguration.contains(worldPath)) { + this.worldConfiguration.createSection(worldPath); } if (steps.length != 0) { ConfigurationSection worldSection = - PlotSquared.get().worlds.getConfigurationSection(worldPath); + this.worldConfiguration.getConfigurationSection(worldPath); for (ConfigurationNode step : steps) { worldSection.set(step.getConstant(), step.getValue()); } } - PlotSquared.get().worlds + this.worldConfiguration .set("worlds." + world + ".generator.type", builder.plotAreaType().toString()); - PlotSquared.get().worlds + this.worldConfiguration .set("worlds." + world + ".generator.terrain", builder.terrainType().toString()); - PlotSquared.get().worlds + this.worldConfiguration .set("worlds." + world + ".generator.plugin", builder.plotManager()); if (builder.generatorName() != null && !builder.generatorName() .equals(builder.plotManager())) { - PlotSquared.get().worlds + this.worldConfiguration .set("worlds." + world + ".generator.init", builder.generatorName()); } } @@ -302,11 +305,11 @@ public class BukkitSetupUtils extends SetupUtils { } case NORMAL: { if (steps.length != 0) { - if (!PlotSquared.get().worlds.contains(worldPath)) { - PlotSquared.get().worlds.createSection(worldPath); + if (!this.worldConfiguration.contains(worldPath)) { + this.worldConfiguration.createSection(worldPath); } ConfigurationSection worldSection = - PlotSquared.get().worlds.getConfigurationSection(worldPath); + this.worldConfiguration.getConfigurationSection(worldPath); for (ConfigurationNode step : steps) { worldSection.set(step.getConstant(), step.getValue()); } @@ -316,7 +319,7 @@ public class BukkitSetupUtils extends SetupUtils { } try { - PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); + this.worldConfiguration.save(this.worldFile); } catch (IOException e) { e.printStackTrace(); } diff --git a/Core/src/main/java/com/plotsquared/core/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/PlotAPI.java index eb1c99607..ff4101a5c 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotAPI.java +++ b/Core/src/main/java/com/plotsquared/core/PlotAPI.java @@ -27,7 +27,6 @@ package com.plotsquared.core; import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.Captions; -import com.plotsquared.core.configuration.file.YamlConfiguration; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; @@ -89,26 +88,6 @@ import java.util.UUID; PlotSquared.get().addPlotArea(plotArea); } - /** - * Gets the configuration file for this plugin. - * - * @return the configuration file for PlotSquared - * = - */ - public YamlConfiguration getConfig() { - return PlotSquared.get().getConfig(); - } - - /** - * Gets the PlotSquared storage file. - * - * @return storage configuration - * @see PlotSquared#storage - */ - public YamlConfiguration getStorage() { - return PlotSquared.get().storage; - } - /** * ChunkManager class contains several useful methods. *