Remove dumdum static access

This commit is contained in:
Alexander Söderberg 2020-07-10 19:25:05 +02:00
parent 7687d7705b
commit 55bf41d2da
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
27 changed files with 453 additions and 401 deletions

View File

@ -70,6 +70,7 @@ import com.plotsquared.core.configuration.ChatFormatter;
import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.generator.HybridGen; import com.plotsquared.core.generator.HybridGen;
@ -188,6 +189,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
private PlotAreaManager plotAreaManager; private PlotAreaManager plotAreaManager;
private EventDispatcher eventDispatcher; private EventDispatcher eventDispatcher;
private PlotListener plotListener; private PlotListener plotListener;
private YamlConfiguration worldConfiguration;
private File worldfile;
@Override public int[] getServerVersion() { @Override public int[] getServerVersion() {
if (this.version == null) { if (this.version == null) {
@ -224,6 +227,8 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
this.eventDispatcher = plotSquared.getEventDispatcher(); this.eventDispatcher = plotSquared.getEventDispatcher();
this.plotListener = plotSquared.getPlotListener(); this.plotListener = plotSquared.getPlotListener();
this.playerManager = new BukkitPlayerManager(this.plotAreaManager, this.eventDispatcher); this.playerManager = new BukkitPlayerManager(this.plotAreaManager, this.eventDispatcher);
this.worldConfiguration = plotSquared.getWorldConfiguration();
this.worldfile = plotSquared.getWorldsFile();
if (PlotSquared.platform().getServerVersion()[1] < 13) { if (PlotSquared.platform().getServerVersion()[1] < 13) {
System.out.println( System.out.println(
@ -903,7 +908,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
} }
@Override public void registerPlayerEvents() { @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(main, this);
getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this);
if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { 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() { @Override public SetupUtils initSetupUtils() {
return new BukkitSetupUtils(this.plotAreaManager); return new BukkitSetupUtils(this.plotAreaManager, this.worldConfiguration, this.worldfile);
} }
@Override public void startMetrics() { @Override public void startMetrics() {
@ -1057,7 +1062,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
} }
@NotNull @Override public IndependentPlotGenerator getDefaultGenerator() { @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() { @Override public InventoryUtil initInventoryUtil() {
@ -1068,8 +1073,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
World world = BukkitUtil.getWorld(worldName); World world = BukkitUtil.getWorld(worldName);
if (world == null) { if (world == null) {
// create world // create world
ConfigurationSection worldConfig = ConfigurationSection worldConfig = this.worldConfiguration.getConfigurationSection("worlds." + worldName);
PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", getPluginName()); String manager = worldConfig.getString("generator.plugin", getPluginName());
PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager) PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager)
.generatorName(worldConfig.getString("generator.init", 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); PlotSquared.get().loadWorld(worldName, (BukkitPlotGenerator) gen);
} else if (gen != null) { } else if (gen != null) {
PlotSquared.get().loadWorld(worldName, new BukkitPlotGenerator(worldName, gen, this.plotAreaManager)); 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); PlotSquared.get().loadWorld(worldName, null);
} }
} }

View File

@ -109,6 +109,7 @@ import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.RegExUtil; import com.plotsquared.core.util.RegExUtil;
import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
@ -234,6 +235,7 @@ import java.util.regex.Pattern;
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final WorldEdit worldEdit;
private boolean pistonBlocks = true; private boolean pistonBlocks = true;
private float lastRadius; private float lastRadius;
@ -243,10 +245,13 @@ import java.util.regex.Pattern;
private PlayerMoveEvent moveTmp; private PlayerMoveEvent moveTmp;
private String internalVersion; 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); super(eventDispatcher);
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.worldEdit = worldEdit;
try { try {
fieldPlayer = PlayerEvent.class.getDeclaredField("player"); fieldPlayer = PlayerEvent.class.getDeclaredField("player");
fieldPlayer.setAccessible(true); fieldPlayer.setAccessible(true);
@ -1077,9 +1082,9 @@ import java.util.regex.Pattern;
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) { if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
return; return;
} }
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { if (this.worldEdit!= null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == Material if (player.getInventory().getItemInMainHand().getType() == Material
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) { .getMaterial(this.worldEdit.getConfiguration().wandItem)) {
return; return;
} }
} }
@ -1150,7 +1155,7 @@ import java.util.regex.Pattern;
if (plot != null) { if (plot != null) {
plotExit(pp, plot); plotExit(pp, plot);
} }
if (PlotSquared.get().worldedit != null) { if (this.worldEdit != null) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_WORLDEDIT_BYPASS)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_WORLDEDIT_BYPASS)) {
if (pp.getAttribute("worldedit")) { if (pp.getAttribute("worldedit")) {
pp.removeAttribute("worldedit"); pp.removeAttribute("worldedit");
@ -2114,9 +2119,9 @@ import java.util.regex.Pattern;
default: default:
return; return;
} }
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { if (this.worldEdit != null && pp.getAttribute("worldedit")) {
if (event.getMaterial() == Material if (event.getMaterial() == Material
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) { .getMaterial(this.worldEdit.getConfiguration().wandItem)) {
return; return;
} }
} }

View File

@ -27,8 +27,11 @@ package com.plotsquared.bukkit.util;
import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
import com.plotsquared.core.PlotSquared; 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.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotAreaType;
@ -45,6 +48,7 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -53,9 +57,15 @@ import java.util.Objects;
public class BukkitSetupUtils extends SetupUtils { public class BukkitSetupUtils extends SetupUtils {
private final PlotAreaManager plotAreaManager; 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.plotAreaManager = plotAreaManager;
this.worldConfiguration = worldConfiguration;
this.worldFile = worldFile;
} }
@Override public void updateGenerators() { @Override public void updateGenerators() {
@ -115,11 +125,10 @@ public class BukkitSetupUtils extends SetupUtils {
switch (type) { switch (type) {
case PARTIAL: { case PARTIAL: {
if (object.id != null) { if (object.id != null) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!this.worldConfiguration.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); this.worldConfiguration.createSection(worldPath);
} }
ConfigurationSection worldSection = ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath);
PlotSquared.get().worlds.getConfigurationSection(worldPath);
String areaName = object.id + "-" + object.min + "-" + object.max; String areaName = object.id + "-" + object.min + "-" + object.max;
String areaPath = "areas." + areaName; String areaPath = "areas." + areaName;
if (!worldSection.contains(areaPath)) { if (!worldSection.contains(areaPath)) {
@ -159,26 +168,21 @@ public class BukkitSetupUtils extends SetupUtils {
} }
case AUGMENTED: { case AUGMENTED: {
if (!object.plotManager.endsWith(":single")) { if (!object.plotManager.endsWith(":single")) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!this.worldConfiguration.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); this.worldConfiguration.createSection(worldPath);
} }
if (steps.length != 0) { if (steps.length != 0) {
ConfigurationSection worldSection = ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath);
PlotSquared.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) { for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue()); worldSection.set(step.getConstant(), step.getValue());
} }
} }
PlotSquared.get().worlds this.worldConfiguration.set("worlds." + world + ".generator.type", object.type.toString());
.set("worlds." + world + ".generator.type", object.type.toString()); this.worldConfiguration.set("worlds." + world + ".generator.terrain", object.terrain.toString());
PlotSquared.get().worlds this.worldConfiguration.set("worlds." + world + ".generator.plugin", object.plotManager);
.set("worlds." + world + ".generator.terrain", object.terrain.toString());
PlotSquared.get().worlds
.set("worlds." + world + ".generator.plugin", object.plotManager);
if (object.setupGenerator != null && !object.setupGenerator if (object.setupGenerator != null && !object.setupGenerator
.equals(object.plotManager)) { .equals(object.plotManager)) {
PlotSquared.get().worlds this.worldConfiguration.set("worlds." + world + ".generator.init", object.setupGenerator);
.set("worlds." + world + ".generator.init", object.setupGenerator);
} }
} }
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator); GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
@ -189,11 +193,10 @@ public class BukkitSetupUtils extends SetupUtils {
} }
case NORMAL: { case NORMAL: {
if (steps.length != 0) { if (steps.length != 0) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!this.worldConfiguration.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); this.worldConfiguration.createSection(worldPath);
} }
ConfigurationSection worldSection = ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(worldPath);
PlotSquared.get().worlds.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) { for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue()); worldSection.set(step.getConstant(), step.getValue());
} }
@ -203,7 +206,7 @@ public class BukkitSetupUtils extends SetupUtils {
} }
try { try {
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); this.worldConfiguration.save(this.worldFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -228,11 +231,11 @@ public class BukkitSetupUtils extends SetupUtils {
switch (type) { switch (type) {
case PARTIAL: { case PARTIAL: {
if (builder.areaName() != null) { if (builder.areaName() != null) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!this.worldConfiguration.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); this.worldConfiguration.createSection(worldPath);
} }
ConfigurationSection worldSection = ConfigurationSection worldSection =
PlotSquared.get().worlds.getConfigurationSection(worldPath); this.worldConfiguration.getConfigurationSection(worldPath);
String areaName = builder.areaName() + "-" + builder.minimumId() + "-" + builder.maximumId(); String areaName = builder.areaName() + "-" + builder.minimumId() + "-" + builder.maximumId();
String areaPath = "areas." + areaName; String areaPath = "areas." + areaName;
if (!worldSection.contains(areaPath)) { if (!worldSection.contains(areaPath)) {
@ -272,25 +275,25 @@ public class BukkitSetupUtils extends SetupUtils {
} }
case AUGMENTED: { case AUGMENTED: {
if (!builder.plotManager().endsWith(":single")) { if (!builder.plotManager().endsWith(":single")) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!this.worldConfiguration.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); this.worldConfiguration.createSection(worldPath);
} }
if (steps.length != 0) { if (steps.length != 0) {
ConfigurationSection worldSection = ConfigurationSection worldSection =
PlotSquared.get().worlds.getConfigurationSection(worldPath); this.worldConfiguration.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) { for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue()); worldSection.set(step.getConstant(), step.getValue());
} }
} }
PlotSquared.get().worlds this.worldConfiguration
.set("worlds." + world + ".generator.type", builder.plotAreaType().toString()); .set("worlds." + world + ".generator.type", builder.plotAreaType().toString());
PlotSquared.get().worlds this.worldConfiguration
.set("worlds." + world + ".generator.terrain", builder.terrainType().toString()); .set("worlds." + world + ".generator.terrain", builder.terrainType().toString());
PlotSquared.get().worlds this.worldConfiguration
.set("worlds." + world + ".generator.plugin", builder.plotManager()); .set("worlds." + world + ".generator.plugin", builder.plotManager());
if (builder.generatorName() != null && !builder.generatorName() if (builder.generatorName() != null && !builder.generatorName()
.equals(builder.plotManager())) { .equals(builder.plotManager())) {
PlotSquared.get().worlds this.worldConfiguration
.set("worlds." + world + ".generator.init", builder.generatorName()); .set("worlds." + world + ".generator.init", builder.generatorName());
} }
} }
@ -302,11 +305,11 @@ public class BukkitSetupUtils extends SetupUtils {
} }
case NORMAL: { case NORMAL: {
if (steps.length != 0) { if (steps.length != 0) {
if (!PlotSquared.get().worlds.contains(worldPath)) { if (!this.worldConfiguration.contains(worldPath)) {
PlotSquared.get().worlds.createSection(worldPath); this.worldConfiguration.createSection(worldPath);
} }
ConfigurationSection worldSection = ConfigurationSection worldSection =
PlotSquared.get().worlds.getConfigurationSection(worldPath); this.worldConfiguration.getConfigurationSection(worldPath);
for (ConfigurationNode step : steps) { for (ConfigurationNode step : steps) {
worldSection.set(step.getConstant(), step.getValue()); worldSection.set(step.getConstant(), step.getValue());
} }
@ -316,7 +319,7 @@ public class BukkitSetupUtils extends SetupUtils {
} }
try { try {
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); this.worldConfiguration.save(this.worldFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -27,7 +27,6 @@ package com.plotsquared.core;
import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
@ -89,26 +88,6 @@ import java.util.UUID;
PlotSquared.get().addPlotArea(plotArea); 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. * ChunkManager class contains several useful methods.
* <ul> * <ul>

View File

@ -144,16 +144,14 @@ public class PlotSquared {
@Getter private final UUIDPipeline backgroundUUIDPipeline = @Getter private final UUIDPipeline backgroundUUIDPipeline =
new UUIDPipeline(Executors.newSingleThreadExecutor()); new UUIDPipeline(Executors.newSingleThreadExecutor());
// WorldEdit instance // WorldEdit instance
public WorldEdit worldedit; @Getter private WorldEdit worldedit;
public File styleFile; @Getter private File configFile;
public File configFile; @Getter private File worldsFile;
public File worldsFile; public File translationFile; // TODO: REMOVE
public File translationFile; public YamlConfiguration style; // TODO: REMOVE
public YamlConfiguration style; @Getter private YamlConfiguration worldConfiguration;
public YamlConfiguration worlds;
public YamlConfiguration storage;
// Temporary hold the plots/clusters before the worlds load // Temporary hold the plots/clusters before the worlds load
public HashMap<String, Set<PlotCluster>> clusters_tmp; private HashMap<String, Set<PlotCluster>> clustersTmp;
public HashMap<String, HashMap<PlotId, Plot>> plots_tmp; public HashMap<String, HashMap<PlotId, Plot>> plots_tmp;
private YamlConfiguration config; private YamlConfiguration config;
// Implementation logger // Implementation logger
@ -217,14 +215,33 @@ public class PlotSquared {
+ ".use_THIS.yml"); + ".use_THIS.yml");
Captions.load(this.translationFile); Captions.load(this.translationFile);
// WorldEdit
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
if (this.platform.initWorldEdit()) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName()
+ " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber(this.plotAreaManager));
if (Settings.Enabled_Components.COMMANDS) {
new WE_Anywhere();
}
}
} catch (Throwable e) {
PlotSquared.debug(
"Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master");
}
}
// Create Event utility class // Create Event utility class
this.eventDispatcher = new EventDispatcher(); this.eventDispatcher = new EventDispatcher(this.worldedit);
// Create plot listener // Create plot listener
this.plotListener = new PlotListener(this.eventDispatcher); this.plotListener = new PlotListener(this.eventDispatcher);
// Setup plotAreaManager // Setup plotAreaManager
if (Settings.Enabled_Components.WORLDS) { if (Settings.Enabled_Components.WORLDS) {
this.plotAreaManager = new SinglePlotAreaManager(this.eventDispatcher, this.plotListener); this.plotAreaManager = new SinglePlotAreaManager(this.eventDispatcher, this.plotListener, this.worldConfiguration);
} else { } else {
this.plotAreaManager = new DefaultPlotAreaManager(); this.plotAreaManager = new DefaultPlotAreaManager();
} }
@ -281,24 +298,6 @@ public class PlotSquared {
if (Settings.Enabled_Components.COMMANDS) { if (Settings.Enabled_Components.COMMANDS) {
this.platform.registerCommands(); this.platform.registerCommands();
} }
// WorldEdit
if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) {
try {
if (this.platform.initWorldEdit()) {
PlotSquared.log(Captions.PREFIX.getTranslated() + "&6" + this.platform.getPluginName()
+ " hooked into WorldEdit.");
this.worldedit = WorldEdit.getInstance();
WorldEdit.getInstance().getEventBus().register(new WESubscriber(this.plotAreaManager));
if (Settings.Enabled_Components.COMMANDS) {
new WE_Anywhere();
}
}
} catch (Throwable e) {
PlotSquared.debug(
"Incompatible version of WorldEdit, please upgrade: http://builds.enginehub.org/job/worldedit?branch=master");
}
}
// Economy // Economy
if (Settings.Enabled_Components.ECONOMY) { if (Settings.Enabled_Components.ECONOMY) {
TaskManager.runTask(() -> EconHandler.initializeEconHandler()); TaskManager.runTask(() -> EconHandler.initializeEconHandler());
@ -314,7 +313,7 @@ public class PlotSquared {
} }
// World generators: // World generators:
final ConfigurationSection section = this.worlds.getConfigurationSection("worlds"); final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
if (section != null) { if (section != null) {
for (String world : section.getKeys(false)) { for (String world : section.getKeys(false)) {
if (world.equals("CheckingPlotSquaredGenerator")) { if (world.equals("CheckingPlotSquaredGenerator")) {
@ -505,10 +504,10 @@ public class PlotSquared {
} }
} }
Set<PlotCluster> clusters; Set<PlotCluster> 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) { if (plotArea.getType() == PlotAreaType.PARTIAL) {
clusters = this.clusters_tmp != null ? clusters = this.clustersTmp != null ?
this.clusters_tmp.get(plotArea.getWorldName()) : this.clustersTmp.get(plotArea.getWorldName()) :
null; null;
if (clusters != null) { if (clusters != null) {
Iterator<PlotCluster> iterator = clusters.iterator(); Iterator<PlotCluster> iterator = clusters.iterator();
@ -594,10 +593,10 @@ public class PlotSquared {
for (Plot plot : area.getPlots()) { for (Plot plot : area.getPlots()) {
map.put(plot.getId(), plot); map.put(plot.getId(), plot);
} }
if (this.clusters_tmp == null) { if (this.clustersTmp == null) {
this.clusters_tmp = new HashMap<>(); this.clustersTmp = new HashMap<>();
} }
this.clusters_tmp.put(area.toString(), area.getClusters()); this.clustersTmp.put(area.toString(), area.getClusters());
} }
public Set<PlotCluster> getClusters(@NotNull final String world) { public Set<PlotCluster> getClusters(@NotNull final String world) {
@ -932,13 +931,13 @@ public class PlotSquared {
} }
this.plotAreaManager.addWorld(world); this.plotAreaManager.addWorld(world);
Set<String> worlds; Set<String> worlds;
if (this.worlds.contains("worlds")) { if (this.worldConfiguration.contains("worlds")) {
worlds = this.worlds.getConfigurationSection("worlds").getKeys(false); worlds = this.worldConfiguration.getConfigurationSection("worlds").getKeys(false);
} else { } else {
worlds = new HashSet<>(); worlds = new HashSet<>();
} }
String path = "worlds." + world; String path = "worlds." + world;
ConfigurationSection worldSection = this.worlds.getConfigurationSection(path); ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection(path);
PlotAreaType type; PlotAreaType type;
if (worldSection != null) { if (worldSection != null) {
type = MainUtil.getType(worldSection); type = MainUtil.getType(worldSection);
@ -981,14 +980,14 @@ public class PlotSquared {
PlotSquared.log(Captions.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName()); PlotSquared.log(Captions.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName());
PlotSquared.log( PlotSquared.log(
Captions.PREFIX + "&3 - plotAreaManager: &7" + plotManager.getClass().getName()); Captions.PREFIX + "&3 - plotAreaManager: &7" + plotManager.getClass().getName());
if (!this.worlds.contains(path)) { if (!this.worldConfiguration.contains(path)) {
this.worlds.createSection(path); this.worldConfiguration.createSection(path);
worldSection = this.worlds.getConfigurationSection(path); worldSection = this.worldConfiguration.getConfigurationSection(path);
} }
plotArea.saveConfiguration(worldSection); plotArea.saveConfiguration(worldSection);
plotArea.loadDefaultConfiguration(worldSection); plotArea.loadDefaultConfiguration(worldSection);
try { try {
this.worlds.save(this.worldsFile); this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1009,7 +1008,7 @@ public class PlotSquared {
String gen_string = worldSection.getString("generator.plugin", platform.getPluginName()); String gen_string = worldSection.getString("generator.plugin", platform.getPluginName());
if (type == PlotAreaType.PARTIAL) { if (type == PlotAreaType.PARTIAL) {
Set<PlotCluster> clusters = Set<PlotCluster> clusters =
this.clusters_tmp != null ? this.clusters_tmp.get(world) : new HashSet<>(); this.clustersTmp != null ? this.clustersTmp.get(world) : new HashSet<>();
if (clusters == null) { if (clusters == null) {
throw new IllegalArgumentException("No cluster exists for world: " + world); throw new IllegalArgumentException("No cluster exists for world: " + world);
} }
@ -1032,7 +1031,7 @@ public class PlotSquared {
pa.saveConfiguration(worldSection); pa.saveConfiguration(worldSection);
pa.loadDefaultConfiguration(worldSection); pa.loadDefaultConfiguration(worldSection);
try { try {
this.worlds.save(this.worldsFile); this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1061,7 +1060,7 @@ public class PlotSquared {
pa.saveConfiguration(worldSection); pa.saveConfiguration(worldSection);
pa.loadDefaultConfiguration(worldSection); pa.loadDefaultConfiguration(worldSection);
try { try {
this.worlds.save(this.worldsFile); this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1138,7 +1137,7 @@ public class PlotSquared {
} }
pa.loadDefaultConfiguration(clone); pa.loadDefaultConfiguration(clone);
try { try {
this.worlds.save(this.worldsFile); this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1212,7 +1211,7 @@ public class PlotSquared {
} }
HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator, HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator,
null, null, this.eventDispatcher, this.plotListener); null, null, this.eventDispatcher, this.plotListener, this.worldConfiguration);
for (String element : split) { for (String element : split) {
String[] pair = element.split("="); String[] pair = element.split("=");
if (pair.length != 2) { if (pair.length != 2) {
@ -1226,41 +1225,41 @@ public class PlotSquared {
switch (key) { switch (key) {
case "s": case "s":
case "size": case "size":
this.worlds.set(base + "plot.size", this.worldConfiguration.set(base + "plot.size",
ConfigurationUtil.INTEGER.parseString(value).shortValue()); ConfigurationUtil.INTEGER.parseString(value).shortValue());
break; break;
case "g": case "g":
case "gap": case "gap":
this.worlds.set(base + "road.width", this.worldConfiguration.set(base + "road.width",
ConfigurationUtil.INTEGER.parseString(value).shortValue()); ConfigurationUtil.INTEGER.parseString(value).shortValue());
break; break;
case "h": case "h":
case "height": case "height":
this.worlds.set(base + "road.height", this.worldConfiguration.set(base + "road.height",
ConfigurationUtil.INTEGER.parseString(value).shortValue()); ConfigurationUtil.INTEGER.parseString(value).shortValue());
this.worlds.set(base + "plot.height", this.worldConfiguration.set(base + "plot.height",
ConfigurationUtil.INTEGER.parseString(value).shortValue()); ConfigurationUtil.INTEGER.parseString(value).shortValue());
this.worlds.set(base + "wall.height", this.worldConfiguration.set(base + "wall.height",
ConfigurationUtil.INTEGER.parseString(value).shortValue()); ConfigurationUtil.INTEGER.parseString(value).shortValue());
break; break;
case "f": case "f":
case "floor": case "floor":
this.worlds.set(base + "plot.floor", this.worldConfiguration.set(base + "plot.floor",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()); ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break; break;
case "m": case "m":
case "main": case "main":
this.worlds.set(base + "plot.filling", this.worldConfiguration.set(base + "plot.filling",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()); ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break; break;
case "w": case "w":
case "wall": case "wall":
this.worlds.set(base + "wall.filling", this.worldConfiguration.set(base + "wall.filling",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()); ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break; break;
case "b": case "b":
case "border": case "border":
this.worlds.set(base + "wall.block", this.worldConfiguration.set(base + "wall.block",
ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString()); ConfigurationUtil.BLOCK_BUCKET.parseString(value).toString());
break; break;
default: default:
@ -1275,10 +1274,10 @@ public class PlotSquared {
} }
try { try {
ConfigurationSection section = ConfigurationSection section =
this.worlds.getConfigurationSection("worlds." + world); this.worldConfiguration.getConfigurationSection("worlds." + world);
plotworld.saveConfiguration(section); plotworld.saveConfiguration(section);
plotworld.loadDefaultConfiguration(section); plotworld.loadDefaultConfiguration(section);
this.worlds.save(this.worldsFile); this.worldConfiguration.save(this.worldsFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -1425,19 +1424,19 @@ public class PlotSquared {
this.platform.shutdown(); //shutdown used instead of disable because no database is set this.platform.shutdown(); //shutdown used instead of disable because no database is set
return; return;
} }
DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, this.eventDispatcher, this.plotListener); DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, this.eventDispatcher, this.plotListener, this.worldConfiguration);
this.plots_tmp = DBFunc.getPlots(); this.plots_tmp = DBFunc.getPlots();
if (plotAreaManager instanceof SinglePlotAreaManager) { if (plotAreaManager instanceof SinglePlotAreaManager) {
SinglePlotArea area = ((SinglePlotAreaManager) plotAreaManager).getArea(); SinglePlotArea area = ((SinglePlotAreaManager) plotAreaManager).getArea();
addPlotArea(area); addPlotArea(area);
ConfigurationSection section = worlds.getConfigurationSection("worlds.*"); ConfigurationSection section = worldConfiguration.getConfigurationSection("worlds.*");
if (section == null) { if (section == null) {
section = worlds.createSection("worlds.*"); section = worldConfiguration.createSection("worlds.*");
} }
area.saveConfiguration(section); area.saveConfiguration(section);
area.loadDefaultConfiguration(section); area.loadDefaultConfiguration(section);
} }
this.clusters_tmp = DBFunc.getClusters(); this.clustersTmp = DBFunc.getClusters();
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {
PlotSquared.log(Captions.PREFIX PlotSquared.log(Captions.PREFIX
+ "&cFailed to open DATABASE connection. The plugin will disable itself."); + "&cFailed to open DATABASE connection. The plugin will disable itself.");
@ -1472,9 +1471,9 @@ public class PlotSquared {
if (getConfig().contains("worlds")) { if (getConfig().contains("worlds")) {
ConfigurationSection worldSection = ConfigurationSection worldSection =
getConfig().getConfigurationSection("worlds"); getConfig().getConfigurationSection("worlds");
worlds.set("worlds", worldSection); worldConfiguration.set("worlds", worldSection);
try { try {
worlds.save(worldsFile); worldConfiguration.save(worldsFile);
} catch (IOException e) { } catch (IOException e) {
PlotSquared.debug("Failed to save " + platform.getPluginName() + " worlds.yml"); PlotSquared.debug("Failed to save " + platform.getPluginName() + " worlds.yml");
e.printStackTrace(); e.printStackTrace();
@ -1518,12 +1517,12 @@ public class PlotSquared {
PlotSquared.log( PlotSquared.log(
"Could not create the worlds file, please create \"worlds.yml\" manually."); "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.worldConfiguration.contains("worlds")) {
if (!this.worlds.contains("configuration_version") || ( if (!this.worldConfiguration.contains("configuration_version") || (
!this.worlds.getString("configuration_version") !this.worldConfiguration.getString("configuration_version")
.equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worlds .equalsIgnoreCase(LegacyConverter.CONFIGURATION_VERSION) && !this.worldConfiguration
.getString("configuration_version").equalsIgnoreCase("v5"))) { .getString("configuration_version").equalsIgnoreCase("v5"))) {
// Conversion needed // Conversion needed
log(Captions.LEGACY_CONFIG_FOUND.getTranslated()); log(Captions.LEGACY_CONFIG_FOUND.getTranslated());
@ -1532,10 +1531,10 @@ public class PlotSquared {
.copy(this.worldsFile, new File(folder, "worlds.yml.old")); .copy(this.worldsFile, new File(folder, "worlds.yml.old"));
log(Captions.LEGACY_CONFIG_BACKUP.getTranslated()); log(Captions.LEGACY_CONFIG_BACKUP.getTranslated());
final ConfigurationSection worlds = final ConfigurationSection worlds =
this.worlds.getConfigurationSection("worlds"); this.worldConfiguration.getConfigurationSection("worlds");
final LegacyConverter converter = new LegacyConverter(worlds); final LegacyConverter converter = new LegacyConverter(worlds);
converter.convert(); converter.convert();
this.worlds.set("worlds", worlds); this.worldConfiguration.set("worlds", worlds);
this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION); this.setConfigurationVersion(LegacyConverter.CONFIGURATION_VERSION);
log(Captions.LEGACY_CONFIG_DONE.getTranslated()); log(Captions.LEGACY_CONFIG_DONE.getTranslated());
} catch (final Exception e) { } catch (final Exception e) {
@ -1547,7 +1546,7 @@ public class PlotSquared {
return false; return false;
} }
} else { } else {
this.worlds.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION); this.worldConfiguration.set("configuration_version", LegacyConverter.CONFIGURATION_VERSION);
} }
} catch (IOException ignored) { } catch (IOException ignored) {
PlotSquared.log("Failed to save settings.yml"); PlotSquared.log("Failed to save settings.yml");
@ -1564,20 +1563,21 @@ public class PlotSquared {
PlotSquared.log("Failed to save settings.yml"); PlotSquared.log("Failed to save settings.yml");
} }
try { try {
this.styleFile = MainUtil.getFile(platform.getDirectory(), // TODO: REMOVE
File styleFile = MainUtil.getFile(platform.getDirectory(),
Settings.Paths.TRANSLATIONS + File.separator + "style.yml"); Settings.Paths.TRANSLATIONS + File.separator + "style.yml");
if (!this.styleFile.exists()) { if (!styleFile.exists()) {
if (!this.styleFile.getParentFile().exists()) { if (!styleFile.getParentFile().exists()) {
this.styleFile.getParentFile().mkdirs(); styleFile.getParentFile().mkdirs();
} }
if (!this.styleFile.createNewFile()) { if (!styleFile.createNewFile()) {
PlotSquared.log( PlotSquared.log(
"Could not create the style file, please create \"translations/style.yml\" manually"); "Could not create the style file, please create \"translations/style.yml\" manually");
} }
} }
this.style = YamlConfiguration.loadConfiguration(this.styleFile); this.style = YamlConfiguration.loadConfiguration(styleFile);
setupStyle(); setupStyle();
this.style.save(this.styleFile); this.style.save(styleFile);
} catch (IOException err) { } catch (IOException err) {
err.printStackTrace(); err.printStackTrace();
PlotSquared.log("Failed to save style.yml"); PlotSquared.log("Failed to save style.yml");
@ -1588,7 +1588,7 @@ public class PlotSquared {
PlotSquared.log( PlotSquared.log(
"Could not the storage settings file, please create \"storage.yml\" manually."); "Could not the storage settings file, please create \"storage.yml\" manually.");
} }
this.storage = YamlConfiguration.loadConfiguration(this.storageFile); YamlConfiguration.loadConfiguration(this.storageFile);
setupStorage(); setupStorage();
} catch (IOException ignored) { } catch (IOException ignored) {
PlotSquared.log("Failed to save storage.yml"); PlotSquared.log("Failed to save storage.yml");
@ -1597,13 +1597,13 @@ public class PlotSquared {
} }
public String getConfigurationVersion() { public String getConfigurationVersion() {
return this.worlds.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION) return this.worldConfiguration.get("configuration_version", LegacyConverter.CONFIGURATION_VERSION)
.toString(); .toString();
} }
public void setConfigurationVersion(final String newVersion) throws IOException { public void setConfigurationVersion(final String newVersion) throws IOException {
this.worlds.set("configuration_version", newVersion); this.worldConfiguration.set("configuration_version", newVersion);
this.worlds.save(this.worldsFile); this.worldConfiguration.save(this.worldsFile);
} }
/** /**
@ -1612,7 +1612,7 @@ public class PlotSquared {
private void setupStorage() { private void setupStorage() {
Storage.load(storageFile); Storage.load(storageFile);
Storage.save(storageFile); Storage.save(storageFile);
storage = YamlConfiguration.loadConfiguration(storageFile); YamlConfiguration.loadConfiguration(storageFile);
} }
/** /**

View File

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

View File

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

View File

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

View File

@ -26,9 +26,12 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.AugmentedUtils; import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.generator.HybridPlotWorld;
@ -68,7 +71,6 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
@ -88,12 +90,25 @@ import java.util.Set;
aliases = "world", aliases = "world",
usage = "/plot area <create|info|list|tp|regen>", usage = "/plot area <create|info|list|tp|regen>",
confirmation = true) confirmation = true)
@RequiredArgsConstructor
public class Area extends SubCommand { public class Area extends SubCommand {
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final PlotListener plotListener; private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
private final File worldFile;
public Area(@NotNull final PlotAreaManager plotAreaManager,
@NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration,
@WorldFile @NotNull final File worldFile) {
this.plotAreaManager = plotAreaManager;
this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener;
this.worldConfiguration = worldConfiguration;
this.worldFile = worldFile;
}
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) { @Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) { if (args.length == 0) {
@ -150,7 +165,8 @@ public class Area extends SubCommand {
// There's only one plot in the area... // There's only one plot in the area...
final PlotId plotId = new PlotId(1, 1); final PlotId plotId = new PlotId(1, 1);
final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorldName(), args[1], final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorldName(), args[1],
Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId, this.eventDispatcher, this.plotListener); Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId,
this.eventDispatcher, this.plotListener, this.worldConfiguration);
// Plot size is the same as the region width // Plot size is the same as the region width
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
// We use a schematic generator // We use a schematic generator
@ -210,12 +226,10 @@ public class Area extends SubCommand {
final int offsetX = singlePos1.getX(); final int offsetX = singlePos1.getX();
final int offsetZ = singlePos1.getZ(); final int offsetZ = singlePos1.getZ();
if (offsetX != 0) { if (offsetX != 0) {
PlotSquared.get().worlds this.worldConfiguration.set(path + ".road.offset.x", offsetX);
.set(path + ".road.offset.x", offsetX);
} }
if (offsetZ != 0) { if (offsetZ != 0) {
PlotSquared.get().worlds this.worldConfiguration.set(path + ".road.offset.z", offsetZ);
.set(path + ".road.offset.z", offsetZ);
} }
final String world = SetupUtils.manager.setupWorld(singleBuilder); final String world = SetupUtils.manager.setupWorld(singleBuilder);
if (WorldUtil.IMP.isWorld(world)) { if (WorldUtil.IMP.isWorld(world)) {
@ -303,12 +317,10 @@ public class Area extends SubCommand {
+ builder.minimumId() + '-' + builder.maximumId(); + builder.minimumId() + '-' + builder.maximumId();
Runnable run = () -> { Runnable run = () -> {
if (offsetX != 0) { if (offsetX != 0) {
PlotSquared.get().worlds this.worldConfiguration.set(path + ".road.offset.x", offsetX);
.set(path + ".road.offset.x", offsetX);
} }
if (offsetZ != 0) { if (offsetZ != 0) {
PlotSquared.get().worlds this.worldConfiguration.set(path + ".road.offset.z", offsetZ);
.set(path + ".road.offset.z", offsetZ);
} }
final String world = SetupUtils.manager.setupWorld(builder); final String world = SetupUtils.manager.setupWorld(builder);
if (WorldUtil.IMP.isWorld(world)) { if (WorldUtil.IMP.isWorld(world)) {
@ -351,7 +363,8 @@ public class Area extends SubCommand {
PlotAreaBuilder builder = new PlotAreaBuilder(); PlotAreaBuilder builder = new PlotAreaBuilder();
builder.worldName(split[0]); builder.worldName(split[0]);
final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id, final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
PlotSquared.platform().getDefaultGenerator(), null, null, this.eventDispatcher, this.plotListener); PlotSquared.platform().getDefaultGenerator(), null, null, this.eventDispatcher,
this.plotListener, this.worldConfiguration);
PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id); PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
if (other != null && Objects.equals(pa.getId(), other.getId())) { if (other != null && Objects.equals(pa.getId(), other.getId())) {
Captions.SETUP_WORLD_TAKEN.send(player, pa.toString()); Captions.SETUP_WORLD_TAKEN.send(player, pa.toString());
@ -433,11 +446,10 @@ public class Area extends SubCommand {
} }
Runnable run = () -> { Runnable run = () -> {
String path = "worlds." + pa.getWorldName(); String path = "worlds." + pa.getWorldName();
if (!PlotSquared.get().worlds.contains(path)) { if (!this.worldConfiguration.contains(path)) {
PlotSquared.get().worlds.createSection(path); this.worldConfiguration.createSection(path);
} }
ConfigurationSection section = ConfigurationSection section = this.worldConfiguration.getConfigurationSection(path);
PlotSquared.get().worlds.getConfigurationSection(path);
pa.saveConfiguration(section); pa.saveConfiguration(section);
pa.loadConfiguration(section); pa.loadConfiguration(section);
builder.plotManager(PlotSquared.platform().getPluginName()); builder.plotManager(PlotSquared.platform().getPluginName());
@ -453,7 +465,7 @@ public class Area extends SubCommand {
.getWorldName()); .getWorldName());
} }
try { try {
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); this.worldConfiguration.save(this.worldFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -26,6 +26,8 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.database.Database; import com.plotsquared.core.database.Database;
import com.plotsquared.core.database.MySQL; import com.plotsquared.core.database.MySQL;
@ -64,12 +66,14 @@ public class DatabaseCommand extends SubCommand {
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final PlotListener plotListener; private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
public DatabaseCommand(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, public DatabaseCommand(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener) { @NotNull final PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener; this.plotListener = plotListener;
this.worldConfiguration = worldConfiguration;
} }
public static void insertPlots(final SQLManager manager, final List<Plot> plots, public static void insertPlots(final SQLManager manager, final List<Plot> plots,
@ -127,7 +131,7 @@ public class DatabaseCommand extends SubCommand {
MainUtil.sendMessage(player, "&6Starting..."); MainUtil.sendMessage(player, "&6Starting...");
implementation = new SQLite(file); implementation = new SQLite(file);
SQLManager manager = new SQLManager(implementation, args.length == 3 ? args[2] : "", SQLManager manager = new SQLManager(implementation, args.length == 3 ? args[2] : "",
this.eventDispatcher, this.plotListener); this.eventDispatcher, this.plotListener, this.worldConfiguration);
HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots(); HashMap<String, HashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<>(); plots = new ArrayList<>();
for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) { for (Entry<String, HashMap<PlotId, Plot>> entry : map.entrySet()) {
@ -202,7 +206,7 @@ public class DatabaseCommand extends SubCommand {
return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]"); return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]");
} }
try { try {
SQLManager manager = new SQLManager(implementation, prefix, this.eventDispatcher, this.plotListener); SQLManager manager = new SQLManager(implementation, prefix, this.eventDispatcher, this.plotListener, this.worldConfiguration);
DatabaseCommand.insertPlots(manager, plots, player); DatabaseCommand.insertPlots(manager, plots, player);
return true; return true;
} catch (ClassNotFoundException | SQLException e) { } catch (ClassNotFoundException | SQLException e) {

View File

@ -60,8 +60,10 @@ import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.script.Bindings; import javax.script.Bindings;
import javax.script.ScriptContext; import javax.script.ScriptContext;
@ -87,12 +89,15 @@ public class DebugExec extends SubCommand {
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final WorldEdit worldEdit;
private ScriptEngine engine; private ScriptEngine engine;
private Bindings scope; private Bindings scope;
public DebugExec(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { public DebugExec(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher,
@Nullable final WorldEdit worldEdit) {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.worldEdit = worldEdit;
init(); init();
/* /*
try { try {
@ -164,7 +169,7 @@ public class DebugExec extends SubCommand {
this.scope.put("PS", PlotSquared.get()); this.scope.put("PS", PlotSquared.get());
this.scope.put("GlobalBlockQueue", GlobalBlockQueue.IMP); this.scope.put("GlobalBlockQueue", GlobalBlockQueue.IMP);
this.scope.put("ExpireManager", ExpireManager.IMP); this.scope.put("ExpireManager", ExpireManager.IMP);
if (PlotSquared.get().worldedit != null) { if (this.worldEdit != null) {
this.scope.put("WEManager", new WEManager()); this.scope.put("WEManager", new WEManager());
} }
this.scope.put("TaskManager", TaskManager.IMP); this.scope.put("TaskManager", TaskManager.IMP);

View File

@ -28,6 +28,8 @@ package com.plotsquared.core.command;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.ConfigFile;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -36,6 +38,7 @@ import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.net.IncendoPaster; import com.plotsquared.core.util.net.IncendoPaster;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
import lombok.NonNull; import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -59,6 +62,15 @@ import java.util.stream.Collectors;
requiredType = RequiredType.NONE) requiredType = RequiredType.NONE)
public class DebugPaste extends SubCommand { public class DebugPaste extends SubCommand {
private final File configFile;
private final File worldfile;
public DebugPaste(@ConfigFile @NotNull final File configFile,
@WorldFile @NotNull final File worldFile) {
this.configFile = configFile;
this.worldfile = worldFile;
}
private static String readFile(@NonNull final File file) throws IOException { private static String readFile(@NonNull final File file) throws IOException {
final List<String> lines; final List<String> lines;
try (final BufferedReader reader = new BufferedReader(new FileReader(file))) { try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
@ -142,13 +154,13 @@ public class DebugPaste extends SubCommand {
try { try {
incendoPaster.addFile(new IncendoPaster.PasteFile("settings.yml", incendoPaster.addFile(new IncendoPaster.PasteFile("settings.yml",
readFile(PlotSquared.get().configFile))); readFile(this.configFile)));
} catch (final IllegalArgumentException ignored) { } catch (final IllegalArgumentException ignored) {
MainUtil.sendMessage(player, "&cSkipping settings.yml because it's empty"); MainUtil.sendMessage(player, "&cSkipping settings.yml because it's empty");
} }
try { try {
incendoPaster.addFile(new IncendoPaster.PasteFile("worlds.yml", incendoPaster.addFile(new IncendoPaster.PasteFile("worlds.yml",
readFile(PlotSquared.get().worldsFile))); readFile(this.worldfile)));
} catch (final IllegalArgumentException ignored) { } catch (final IllegalArgumentException ignored) {
MainUtil.sendMessage(player, "&cSkipping worlds.yml because it's empty"); MainUtil.sendMessage(player, "&cSkipping worlds.yml because it's empty");
} }

View File

@ -28,6 +28,7 @@ package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.ConsolePlayer;
@ -41,7 +42,9 @@ import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.RunnableVal3;
import com.sk89q.worldedit.WorldEdit;
import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -68,17 +71,20 @@ public class MainCommand extends Command {
final PlotAreaManager plotAreaManager = PlotSquared.get().getPlotAreaManager(); final PlotAreaManager plotAreaManager = PlotSquared.get().getPlotAreaManager();
final EventDispatcher eventDispatcher = PlotSquared.get().getEventDispatcher(); final EventDispatcher eventDispatcher = PlotSquared.get().getEventDispatcher();
final PlotListener plotListener = PlotSquared.get().getPlotListener(); final PlotListener plotListener = PlotSquared.get().getPlotListener();
final YamlConfiguration worldconfiguration = PlotSquared.get().getWorldConfiguration();
final File worldFile = PlotSquared.get().getWorldsFile();
final WorldEdit worldEdit = PlotSquared.get().getWorldedit();
new Caps(); new Caps();
new Buy(eventDispatcher); new Buy(eventDispatcher);
new Save(plotAreaManager); new Save(plotAreaManager);
new Load(plotAreaManager); new Load(plotAreaManager);
new Confirm(); new Confirm();
new Template(plotAreaManager); new Template(plotAreaManager, worldconfiguration, worldFile);
new Download(plotAreaManager); new Download(plotAreaManager);
new Template(plotAreaManager); new Template(plotAreaManager, worldconfiguration, worldFile);
new Setup(); new Setup();
new Area(plotAreaManager, eventDispatcher, plotListener); new Area(plotAreaManager, eventDispatcher, plotListener, worldconfiguration, worldFile);
new DebugSaveTest(); new DebugSaveTest();
new DebugLoadTest(); new DebugLoadTest();
new CreateRoadSchematic(); new CreateRoadSchematic();
@ -103,20 +109,20 @@ public class MainCommand extends Command {
new SchematicCmd(plotAreaManager); new SchematicCmd(plotAreaManager);
new PluginCmd(); new PluginCmd();
new Purge(plotAreaManager, plotListener); new Purge(plotAreaManager, plotListener);
new Reload(plotAreaManager); new Reload(plotAreaManager, worldconfiguration, worldFile);
new Relight(); new Relight();
new Merge(eventDispatcher); new Merge(eventDispatcher);
new DebugPaste(); new DebugPaste(PlotSquared.get().getConfigFile(), PlotSquared.get().getWorldsFile());
new Unlink(eventDispatcher); new Unlink(eventDispatcher);
new Kick(plotAreaManager); new Kick(plotAreaManager);
new Inbox(); new Inbox();
new Comment(); new Comment();
new DatabaseCommand(plotAreaManager, eventDispatcher, plotListener); new DatabaseCommand(plotAreaManager, eventDispatcher, plotListener, worldconfiguration);
new Swap(); new Swap();
new Music(); new Music();
new DebugRoadRegen(); new DebugRoadRegen();
new Trust(eventDispatcher); new Trust(eventDispatcher);
new DebugExec(plotAreaManager, eventDispatcher); new DebugExec(plotAreaManager, eventDispatcher, worldEdit);
new FlagCommand(); new FlagCommand();
new Target(); new Target();
new Move(plotAreaManager); new Move(plotAreaManager);

View File

@ -26,6 +26,8 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.MemorySection; import com.plotsquared.core.configuration.MemorySection;
@ -36,6 +38,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MainUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
@ -48,9 +51,15 @@ import java.util.Objects;
public class Reload extends SubCommand { public class Reload extends SubCommand {
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final YamlConfiguration worldConfiguration;
private final File worldFile;
public Reload(@NotNull final PlotAreaManager plotAreaManager) { public Reload(@NotNull final PlotAreaManager plotAreaManager,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration,
@WorldFile @NotNull final File worldFile) {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
this.worldConfiguration = worldConfiguration;
this.worldFile = worldFile;
} }
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) { @Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
@ -60,7 +69,7 @@ public class Reload extends SubCommand {
PlotSquared.get().setupConfigs(); PlotSquared.get().setupConfigs();
Captions.load(PlotSquared.get().translationFile); Captions.load(PlotSquared.get().translationFile);
this.plotAreaManager.forEachPlotArea(area -> { this.plotAreaManager.forEachPlotArea(area -> {
ConfigurationSection worldSection = PlotSquared.get().worlds ConfigurationSection worldSection = this.worldConfiguration
.getConfigurationSection("worlds." + area.getWorldName()); .getConfigurationSection("worlds." + area.getWorldName());
if (worldSection == null) { if (worldSection == null) {
return; return;
@ -106,7 +115,7 @@ public class Reload extends SubCommand {
area.loadDefaultConfiguration(clone); area.loadDefaultConfiguration(clone);
} }
}); });
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); this.worldConfiguration.save(this.worldFile);
MainUtil.sendMessage(player, Captions.RELOADED_CONFIGS); MainUtil.sendMessage(player, Captions.RELOADED_CONFIGS);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -26,6 +26,8 @@
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.annoations.WorldFile;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
@ -64,9 +66,15 @@ import java.util.zip.ZipOutputStream;
public class Template extends SubCommand { public class Template extends SubCommand {
private final PlotAreaManager plotAreaManager; private final PlotAreaManager plotAreaManager;
private final YamlConfiguration worldConfiguration;
private final File worldFile;
public Template(@NotNull final PlotAreaManager plotAreaManager) { public Template(@NotNull final PlotAreaManager plotAreaManager,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration,
@WorldFile @NotNull final File worldFile) {
this.plotAreaManager = plotAreaManager; this.plotAreaManager = plotAreaManager;
this.worldConfiguration = worldConfiguration;
this.worldFile = worldFile;
} }
public static boolean extractAllFiles(String world, String template) { public static boolean extractAllFiles(String world, String template) {
@ -113,8 +121,7 @@ public class Template extends SubCommand {
} }
public static byte[] getBytes(PlotArea plotArea) { public static byte[] getBytes(PlotArea plotArea) {
ConfigurationSection section = ConfigurationSection section = PlotSquared.get().getWorldConfiguration().getConfigurationSection("worlds." + plotArea.getWorldName());
PlotSquared.get().worlds.getConfigurationSection("worlds." + plotArea.getWorldName());
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
String generator = SetupUtils.manager.getGenerator(plotArea); String generator = SetupUtils.manager.getGenerator(plotArea);
if (generator != null) { if (generator != null) {
@ -180,10 +187,10 @@ public class Template extends SubCommand {
File worldFile = MainUtil.getFile(PlotSquared.platform().getDirectory(), File worldFile = MainUtil.getFile(PlotSquared.platform().getDirectory(),
Settings.Paths.TEMPLATES + File.separator + "tmp-data.yml"); Settings.Paths.TEMPLATES + File.separator + "tmp-data.yml");
YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile); YamlConfiguration worldConfig = YamlConfiguration.loadConfiguration(worldFile);
PlotSquared.get().worlds.set("worlds." + world, worldConfig.get("")); this.worldConfiguration.set("worlds." + world, worldConfig.get(""));
try { try {
PlotSquared.get().worlds.save(PlotSquared.get().worldsFile); this.worldConfiguration.save(this.worldFile);
PlotSquared.get().worlds.load(PlotSquared.get().worldsFile); this.worldConfiguration.load(this.worldFile);
} catch (InvalidConfigurationException | IOException e) { } catch (InvalidConfigurationException | IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -27,10 +27,12 @@ package com.plotsquared.core.database;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.Storage; import com.plotsquared.core.configuration.Storage;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.location.BlockLoc;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
@ -132,6 +134,7 @@ public class SQLManager implements AbstractDB {
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final PlotListener plotListener; private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
/** /**
* Constructor * Constructor
@ -141,12 +144,16 @@ public class SQLManager implements AbstractDB {
* @throws SQLException * @throws SQLException
* @throws ClassNotFoundException * @throws ClassNotFoundException
*/ */
public SQLManager(final Database database, String prefix, public SQLManager(@NotNull final Database database,
@NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) @NotNull final String prefix,
@NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration)
throws SQLException, ClassNotFoundException { throws SQLException, ClassNotFoundException {
// Private final // Private final
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener; this.plotListener = plotListener;
this.worldConfiguration = worldConfiguration;
this.database = database; this.database = database;
this.connection = database.openConnection(); this.connection = database.openConnection();
this.mySQL = database instanceof MySQL; this.mySQL = database instanceof MySQL;
@ -1750,9 +1757,8 @@ public class SQLManager implements AbstractDB {
HashMap<Integer, Plot> plots = new HashMap<>(); HashMap<Integer, Plot> plots = new HashMap<>();
try { try {
HashSet<String> areas = new HashSet<>(); HashSet<String> areas = new HashSet<>();
if (PlotSquared.get().worlds.contains("worlds")) { if (this.worldConfiguration.contains("worlds")) {
ConfigurationSection worldSection = ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection("worlds");
PlotSquared.get().worlds.getConfigurationSection("worlds");
if (worldSection != null) { if (worldSection != null) {
for (String worldKey : worldSection.getKeys(false)) { for (String worldKey : worldSection.getKeys(false)) {
areas.add(worldKey); areas.add(worldKey);
@ -2714,9 +2720,8 @@ public class SQLManager implements AbstractDB {
HashMap<Integer, PlotCluster> clusters = new HashMap<>(); HashMap<Integer, PlotCluster> clusters = new HashMap<>();
try { try {
HashSet<String> areas = new HashSet<>(); HashSet<String> areas = new HashSet<>();
if (PlotSquared.get().worlds.contains("worlds")) { if (this.worldConfiguration.contains("worlds")) {
ConfigurationSection worldSection = ConfigurationSection worldSection = this.worldConfiguration.getConfigurationSection("worlds");
PlotSquared.get().worlds.getConfigurationSection("worlds");
if (worldSection != null) { if (worldSection != null) {
for (String worldKey : worldSection.getKeys(false)) { for (String worldKey : worldSection.getKeys(false)) {
areas.add(worldKey); areas.add(worldKey);

View File

@ -25,15 +25,18 @@
*/ */
package com.plotsquared.core.generator; package com.plotsquared.core.generator;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.EventDispatcher;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public abstract class ClassicPlotWorld extends SquarePlotWorld { public abstract class ClassicPlotWorld extends SquarePlotWorld {
@ -55,10 +58,15 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
// BlockUtil.get((short) 155, (byte) 0); // BlockUtil.get((short) 155, (byte) 0);
public boolean PLOT_BEDROCK = true; public boolean PLOT_BEDROCK = true;
public ClassicPlotWorld(String worldName, String id, public ClassicPlotWorld(@NotNull final String worldName,
@NotNull IndependentPlotGenerator generator, PlotId min, PlotId max, @NotNull final @Nullable final String id,
EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { @NotNull final IndependentPlotGenerator generator,
super(worldName, id, generator, min, max, eventDispatcher, plotListener); @NotNull final PlotId min,
@NotNull final PlotId max,
@NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration);
} }
/** /**

View File

@ -25,6 +25,8 @@
*/ */
package com.plotsquared.core.generator; package com.plotsquared.core.generator;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
@ -37,7 +39,7 @@ public abstract class GridPlotWorld extends PlotArea {
public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final
PlotListener plotListener) { PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
super(worldName, id, generator, min, max, eventDispatcher, plotListener); super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration);
} }
} }

View File

@ -27,7 +27,9 @@ package com.plotsquared.core.generator;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotArea;
@ -38,13 +40,21 @@ import com.plotsquared.core.util.MathMan;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@RequiredArgsConstructor public class HybridGen extends IndependentPlotGenerator { public class HybridGen extends IndependentPlotGenerator {
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final PlotListener plotListener; private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
public HybridGen(@NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener;
this.worldConfiguration = worldConfiguration;
}
@Override public String getName() { @Override public String getName() {
return PlotSquared.platform().getPluginName(); return PlotSquared.platform().getPluginName();
@ -227,7 +237,8 @@ import org.jetbrains.annotations.NotNull;
} }
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) { @Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
return new HybridPlotWorld(world, id, this, min, max, this.eventDispatcher, this.plotListener); return new HybridPlotWorld(world, id, this, min, max, this.eventDispatcher,
this.plotListener, this.worldConfiguration);
} }
@Override public void initialize(PlotArea area) { @Override public void initialize(PlotArea area) {

View File

@ -26,9 +26,11 @@
package com.plotsquared.core.generator; package com.plotsquared.core.generator;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Plot;
@ -74,10 +76,15 @@ public class HybridPlotWorld extends ClassicPlotWorld {
private Location SIGN_LOCATION; private Location SIGN_LOCATION;
@Getter private File root = null; @Getter private File root = null;
public HybridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, public HybridPlotWorld(final String worldName,
PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final final String id,
PlotListener plotListener) { @NotNull final IndependentPlotGenerator generator,
super(worldName, id, generator, min, max, eventDispatcher, plotListener); final PlotId min,
final PlotId max,
@NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration);
} }
public static byte wrap(byte data, int start) { public static byte wrap(byte data, int start) {
@ -188,7 +195,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
} }
@Override public boolean isCompatible(PlotArea plotArea) { @Override public boolean isCompatible(@NotNull final PlotArea plotArea) {
if (!(plotArea instanceof SquarePlotWorld)) { if (!(plotArea instanceof SquarePlotWorld)) {
return false; return false;
} }

View File

@ -26,7 +26,9 @@
package com.plotsquared.core.generator; package com.plotsquared.core.generator;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.EventDispatcher;
@ -41,8 +43,8 @@ public abstract class SquarePlotWorld extends GridPlotWorld {
public SquarePlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, public SquarePlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator,
PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final
PlotListener plotListener) { PlotListener plotListener, @WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
super(worldName, id, generator, min, max, eventDispatcher, plotListener); super(worldName, id, generator, min, max, eventDispatcher, plotListener, worldConfiguration);
} }
@Override public void loadConfiguration(ConfigurationSection config) { @Override public void loadConfiguration(ConfigurationSection config) {

View File

@ -28,6 +28,7 @@ package com.plotsquared.core.plot;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.collection.QuadMap; import com.plotsquared.core.collection.QuadMap;
import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
@ -35,6 +36,7 @@ import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.generator.GridPlotWorld; import com.plotsquared.core.generator.GridPlotWorld;
import com.plotsquared.core.generator.IndependentPlotGenerator; import com.plotsquared.core.generator.IndependentPlotGenerator;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
@ -137,11 +139,12 @@ public abstract class PlotArea {
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final PlotListener plotListener; private final PlotListener plotListener;
private final YamlConfiguration worldConfiguration;
public PlotArea(@NotNull final String worldName, @Nullable final String id, public PlotArea(@NotNull final String worldName, @Nullable final String id,
@NotNull IndependentPlotGenerator generator, @Nullable final PlotId min, @NotNull IndependentPlotGenerator generator, @Nullable final PlotId min,
@Nullable final PlotId max, @NotNull final EventDispatcher eventDispatcher, @Nullable final PlotId max, @NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener) { @NotNull final PlotListener plotListener, @WorldConfig @Nullable final YamlConfiguration worldConfiguration) {
this.worldName = worldName; this.worldName = worldName;
this.id = id; this.id = id;
this.plotManager = createManager(); this.plotManager = createManager();
@ -160,6 +163,7 @@ public abstract class PlotArea {
this.worldHash = worldName.hashCode(); this.worldHash = worldName.hashCode();
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener; this.plotListener = plotListener;
this.worldConfiguration = worldConfiguration;
} }
@NotNull protected abstract PlotManager createManager(); @NotNull protected abstract PlotManager createManager();
@ -242,8 +246,8 @@ public abstract class PlotArea {
* @param plotArea the {@code PlotArea} to compare * @param plotArea the {@code PlotArea} to compare
* @return true if both areas are compatible * @return true if both areas are compatible
*/ */
public boolean isCompatible(PlotArea plotArea) { public boolean isCompatible(@NotNull final PlotArea plotArea) {
ConfigurationSection section = PlotSquared.get().worlds.getConfigurationSection("worlds"); final ConfigurationSection section = this.worldConfiguration.getConfigurationSection("worlds");
for (ConfigurationNode setting : plotArea.getSettingNodes()) { for (ConfigurationNode setting : plotArea.getSettingNodes()) {
Object constant = section.get(plotArea.worldName + '.' + setting.getConstant()); Object constant = section.get(plotArea.worldName + '.' + setting.getConstant());
if (constant == null || !constant if (constant == null || !constant

View File

@ -390,7 +390,7 @@ public class PlotAnalysis {
// Save calibration // Save calibration
PlotSquared.debug(" $1Saving calibration"); PlotSquared.debug(" $1Saving calibration");
Settings.AUTO_CLEAR.put("auto-calibrated", settings); Settings.AUTO_CLEAR.put("auto-calibrated", settings);
Settings.save(PlotSquared.get().worldsFile); Settings.save(PlotSquared.get().getWorldsFile());
PlotSquared.debug("$1Done!"); PlotSquared.debug("$1Done!");
running = false; running = false;
for (Plot plot : plots) { for (Plot plot : plots) {

View File

@ -26,9 +26,11 @@
package com.plotsquared.core.plot.world; package com.plotsquared.core.plot.world;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationSection;
import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.generator.GridPlotWorld; import com.plotsquared.core.generator.GridPlotWorld;
import com.plotsquared.core.generator.SingleWorldGenerator; import com.plotsquared.core.generator.SingleWorldGenerator;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
@ -61,8 +63,11 @@ public class SinglePlotArea extends GridPlotWorld {
private final EventDispatcher eventDispatcher; private final EventDispatcher eventDispatcher;
private final PlotListener plotListener; private final PlotListener plotListener;
public SinglePlotArea(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { public SinglePlotArea(@NotNull final PlotAreaManager plotAreaManager,
super("*", null, new SingleWorldGenerator(plotAreaManager), null, null, eventDispatcher, plotListener); @NotNull final EventDispatcher eventDispatcher,
@NotNull final PlotListener plotListener,
@WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
super("*", null, new SingleWorldGenerator(plotAreaManager), null, null, eventDispatcher, plotListener, worldConfiguration);
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.plotListener = plotListener; this.plotListener = plotListener;
this.setAllowSigns(false); this.setAllowSigns(false);

View File

@ -25,7 +25,9 @@
*/ */
package com.plotsquared.core.plot.world; package com.plotsquared.core.plot.world;
import com.plotsquared.core.annoations.WorldConfig;
import com.plotsquared.core.collection.ArrayUtil; import com.plotsquared.core.collection.ArrayUtil;
import com.plotsquared.core.configuration.file.YamlConfiguration;
import com.plotsquared.core.generator.SingleWorldGenerator; import com.plotsquared.core.generator.SingleWorldGenerator;
import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.PlotListener;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
@ -42,9 +44,10 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
private SinglePlotArea area; private SinglePlotArea area;
private PlotArea[] all; private PlotArea[] all;
public SinglePlotAreaManager(@NotNull final EventDispatcher eventDispatcher, @NotNull final public SinglePlotAreaManager(@NotNull final EventDispatcher eventDispatcher,
PlotListener plotListener) { @NotNull final PlotListener plotListener,
this.area = new SinglePlotArea(this, eventDispatcher, plotListener); @WorldConfig @NotNull final YamlConfiguration worldConfiguration) {
this.area = new SinglePlotArea(this, eventDispatcher, plotListener, worldConfiguration);
this.array = new SinglePlotArea[] {area}; this.array = new SinglePlotArea[] {area};
this.all = new PlotArea[] {area}; this.all = new PlotArea[] {area};
SetupUtils.generators.put("PlotSquared:single", SetupUtils.generators.put("PlotSquared:single",

View File

@ -26,7 +26,6 @@
package com.plotsquared.core.util; package com.plotsquared.core.util;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
@ -69,10 +68,12 @@ import com.plotsquared.core.plot.flag.implementations.VehiclePlaceFlag;
import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; import com.plotsquared.core.plot.flag.types.BlockTypeWrapper;
import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -80,9 +81,13 @@ import java.util.UUID;
public class EventDispatcher { public class EventDispatcher {
private EventBus eventBus = new EventBus("PlotSquaredEvents"); private final EventBus eventBus = new EventBus("PlotSquaredEvents");
private final List<Object> listeners = new ArrayList<>();
private final WorldEdit worldEdit;
private List<Object> listeners = new ArrayList<>(); public EventDispatcher(@Nullable final WorldEdit worldEdit) {
this.worldEdit = worldEdit;
}
public void registerListener(Object listener) { public void registerListener(Object listener) {
eventBus.register(listener); eventBus.register(listener);
@ -104,13 +109,13 @@ public class EventDispatcher {
eventBus.post(event); eventBus.post(event);
} }
public PlayerClaimPlotEvent callClaim(PlotPlayer player, Plot plot, String schematic) { public PlayerClaimPlotEvent callClaim(PlotPlayer<?> player, Plot plot, String schematic) {
PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, schematic); PlayerClaimPlotEvent event = new PlayerClaimPlotEvent(player, plot, schematic);
callEvent(event); callEvent(event);
return event; return event;
} }
public PlayerAutoPlotEvent callAuto(PlotPlayer player, PlotArea area, String schematic, public PlayerAutoPlotEvent callAuto(PlotPlayer<?> player, PlotArea area, String schematic,
int size_x, int size_z) { int size_x, int size_z) {
PlayerAutoPlotEvent event = PlayerAutoPlotEvent event =
new PlayerAutoPlotEvent(player, area, schematic, size_x, size_z); new PlayerAutoPlotEvent(player, area, schematic, size_x, size_z);
@ -118,7 +123,7 @@ public class EventDispatcher {
return event; return event;
} }
public PlayerTeleportToPlotEvent callTeleport(PlotPlayer player, Location from, Plot plot) { public PlayerTeleportToPlotEvent callTeleport(PlotPlayer<?> player, Location from, Plot plot) {
PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent(player, from, plot); PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent(player, from, plot);
callEvent(event); callEvent(event);
return event; return event;
@ -154,7 +159,7 @@ public class EventDispatcher {
return event; return event;
} }
public PlotMergeEvent callMerge(Plot plot, Direction dir, int max, PlotPlayer player) { public PlotMergeEvent callMerge(Plot plot, Direction dir, int max, PlotPlayer<?> player) {
PlotMergeEvent event = new PlotMergeEvent(plot.getWorldName(), plot, dir, max, player); PlotMergeEvent event = new PlotMergeEvent(plot.getWorldName(), plot, dir, max, player);
callEvent(event); callEvent(event);
return event; return event;
@ -173,40 +178,40 @@ public class EventDispatcher {
return event; return event;
} }
public PlayerEnterPlotEvent callEntry(PlotPlayer player, Plot plot) { public PlayerEnterPlotEvent callEntry(PlotPlayer<?> player, Plot plot) {
PlayerEnterPlotEvent event = new PlayerEnterPlotEvent(player, plot); PlayerEnterPlotEvent event = new PlayerEnterPlotEvent(player, plot);
callEvent(event); callEvent(event);
return event; return event;
} }
public PlayerLeavePlotEvent callLeave(PlotPlayer player, Plot plot) { public PlayerLeavePlotEvent callLeave(PlotPlayer<?> player, Plot plot) {
PlayerLeavePlotEvent event = new PlayerLeavePlotEvent(player, plot); PlayerLeavePlotEvent event = new PlayerLeavePlotEvent(player, plot);
callEvent(event); callEvent(event);
return event; return event;
} }
public PlayerPlotDeniedEvent callDenied(PlotPlayer initiator, Plot plot, UUID player, public PlayerPlotDeniedEvent callDenied(PlotPlayer<?> initiator, Plot plot, UUID player,
boolean added) { boolean added) {
PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(initiator, plot, player, added); PlayerPlotDeniedEvent event = new PlayerPlotDeniedEvent(initiator, plot, player, added);
callEvent(event); callEvent(event);
return event; return event;
} }
public PlayerPlotTrustedEvent callTrusted(PlotPlayer initiator, Plot plot, UUID player, public PlayerPlotTrustedEvent callTrusted(PlotPlayer<?> initiator, Plot plot, UUID player,
boolean added) { boolean added) {
PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(initiator, plot, player, added); PlayerPlotTrustedEvent event = new PlayerPlotTrustedEvent(initiator, plot, player, added);
callEvent(event); callEvent(event);
return event; return event;
} }
public PlayerPlotHelperEvent callMember(PlotPlayer initiator, Plot plot, UUID player, public PlayerPlotHelperEvent callMember(PlotPlayer<?> initiator, Plot plot, UUID player,
boolean added) { boolean added) {
PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(initiator, plot, player, added); PlayerPlotHelperEvent event = new PlayerPlotHelperEvent(initiator, plot, player, added);
callEvent(event); callEvent(event);
return event; return event;
} }
public PlotChangeOwnerEvent callOwnerChange(PlotPlayer initiator, Plot plot, UUID oldOwner, public PlotChangeOwnerEvent callOwnerChange(PlotPlayer<?> initiator, Plot plot, UUID oldOwner,
UUID newOwner, boolean hasOldOwner) { UUID newOwner, boolean hasOldOwner) {
PlotChangeOwnerEvent event = PlotChangeOwnerEvent event =
new PlotChangeOwnerEvent(initiator, plot, oldOwner, newOwner, hasOldOwner); new PlotChangeOwnerEvent(initiator, plot, oldOwner, newOwner, hasOldOwner);
@ -214,7 +219,7 @@ public class EventDispatcher {
return event; return event;
} }
public PlotRateEvent callRating(PlotPlayer player, Plot plot, Rating rating) { public PlotRateEvent callRating(PlotPlayer<?> player, Plot plot, Rating rating) {
PlotRateEvent event = new PlotRateEvent(player, rating, plot); PlotRateEvent event = new PlotRateEvent(player, rating, plot);
eventBus.post(event); eventBus.post(event);
return event; return event;
@ -226,14 +231,14 @@ public class EventDispatcher {
return event; return event;
} }
public void doJoinTask(final PlotPlayer player) { public void doJoinTask(final PlotPlayer<?> player) {
if (player == null) { if (player == null) {
return; //possible future warning message to figure out where we are retrieving null return; //possible future warning message to figure out where we are retrieving null
} }
if (ExpireManager.IMP != null) { if (ExpireManager.IMP != null) {
ExpireManager.IMP.handleJoin(player); ExpireManager.IMP.handleJoin(player);
} }
if (PlotSquared.get().worldedit != null) { if (this.worldEdit != null) {
if (player.getAttribute("worldedit")) { if (player.getAttribute("worldedit")) {
MainUtil.sendMessage(player, Captions.WORLDEDIT_BYPASSED); MainUtil.sendMessage(player, Captions.WORLDEDIT_BYPASSED);
} }
@ -249,7 +254,7 @@ public class EventDispatcher {
} }
} }
public void doRespawnTask(final PlotPlayer player) { public void doRespawnTask(final PlotPlayer<?> player) {
final Plot plot = player.getCurrentPlot(); final Plot plot = player.getCurrentPlot();
if (Settings.Teleport.ON_DEATH && plot != null) { if (Settings.Teleport.ON_DEATH && plot != null) {
TaskManager.runTask(() -> plot.teleportPlayer(player, result -> { TaskManager.runTask(() -> plot.teleportPlayer(player, result -> {
@ -258,7 +263,7 @@ public class EventDispatcher {
} }
} }
public boolean checkPlayerBlockEvent(PlotPlayer player, @NotNull PlayerBlockEventType type, public boolean checkPlayerBlockEvent(PlotPlayer<?> player, @NotNull PlayerBlockEventType type,
Location location, BlockType blockType, boolean notifyPerms) { Location location, BlockType blockType, boolean notifyPerms) {
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
assert area != null; assert area != null;

View File

@ -1,154 +0,0 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.plot.util;
import com.plotsquared.core.events.PlayerAutoPlotEvent;
import com.plotsquared.core.events.PlayerClaimPlotEvent;
import com.plotsquared.core.events.PlayerEnterPlotEvent;
import com.plotsquared.core.events.PlayerLeavePlotEvent;
import com.plotsquared.core.events.PlayerPlotDeniedEvent;
import com.plotsquared.core.events.PlayerPlotHelperEvent;
import com.plotsquared.core.events.PlayerPlotTrustedEvent;
import com.plotsquared.core.events.PlayerTeleportToPlotEvent;
import com.plotsquared.core.events.PlotAutoMergeEvent;
import com.plotsquared.core.events.PlotChangeOwnerEvent;
import com.plotsquared.core.events.PlotClearEvent;
import com.plotsquared.core.events.PlotComponentSetEvent;
import com.plotsquared.core.events.PlotDeleteEvent;
import com.plotsquared.core.events.PlotDoneEvent;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotFlagRemoveEvent;
import com.plotsquared.core.events.PlotMergeEvent;
import com.plotsquared.core.events.PlotRateEvent;
import com.plotsquared.core.events.PlotUnlinkEvent;
import com.plotsquared.core.location.Direction;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.flag.PlotFlag;
import com.plotsquared.core.util.EventDispatcher;
import com.sk89q.worldedit.function.pattern.Pattern;
import java.util.List;
import java.util.UUID;
public class EventDispatcherTest extends EventDispatcher {
@Override public PlotRateEvent callRating(PlotPlayer player, Plot plot, Rating rating) {
return null;
}
@Override
public PlayerClaimPlotEvent callClaim(PlotPlayer player, Plot plot, String schematic) {
return null;
}
@Override
public PlayerAutoPlotEvent callAuto(PlotPlayer player, PlotArea area, String schematic,
int size_x, int size_z) {
return null;
}
@Override
public PlayerTeleportToPlotEvent callTeleport(PlotPlayer player, Location from, Plot plot) {
return null;
}
@Override
public PlotComponentSetEvent callComponentSet(Plot plot, String component, Pattern pattern) {
return null;
}
@Override public PlotClearEvent callClear(Plot plot) {
return null;
}
@Override public PlotDeleteEvent callDelete(Plot plot) {
return null;
}
@Override public PlotFlagAddEvent callFlagAdd(PlotFlag<?, ?> flag, Plot plot) {
return null;
}
@Override public PlotFlagRemoveEvent callFlagRemove(PlotFlag<?, ?> flag, Plot plot) {
return null;
}
@Override
public PlotMergeEvent callMerge(Plot plot, Direction dir, int max, PlotPlayer player) {
return null;
}
@Override public PlotAutoMergeEvent callAutoMerge(Plot plot, List<PlotId> plots) {
return null;
}
@Override
public PlotUnlinkEvent callUnlink(PlotArea area, Plot plot, boolean createRoad,
boolean createSign, PlotUnlinkEvent.REASON reason) {
return null;
}
@Override public PlayerEnterPlotEvent callEntry(PlotPlayer player, Plot plot) {
return null;
}
@Override public PlayerLeavePlotEvent callLeave(PlotPlayer player, Plot plot) {
return null;
}
@Override
public PlayerPlotDeniedEvent callDenied(PlotPlayer initiator, Plot plot, UUID player,
boolean added) {
return null;
}
@Override
public PlayerPlotTrustedEvent callTrusted(PlotPlayer initiator, Plot plot, UUID player,
boolean added) {
return null;
}
@Override
public PlayerPlotHelperEvent callMember(PlotPlayer initiator, Plot plot, UUID player,
boolean added) {
return null;
}
@Override
public PlotChangeOwnerEvent callOwnerChange(PlotPlayer initiator, Plot plot, UUID newOwner,
UUID oldOwner, boolean hasOldOwner) {
return null;
}
@Override public PlotDoneEvent callDone(Plot plot) {
return null;
}
}