Fixed reloads; resolves #961; resolves #948; resolves #925

This commit is contained in:
Tim Daniel Saukel 2021-04-06 19:40:19 +02:00
parent a88c9ee778
commit 2aff9529bc
16 changed files with 433 additions and 333 deletions

View File

@ -6,9 +6,15 @@
package de.erethon.dungeonsxxl;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.DungeonModule;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.api.Reward;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.sign.DungeonSign;
import de.erethon.dungeonsxl.util.commons.compatibility.Internals;
import de.erethon.dungeonsxl.util.commons.javaplugin.DREPlugin;
import de.erethon.dungeonsxl.util.commons.javaplugin.DREPluginSettings;
import de.erethon.dungeonsxl.util.commons.misc.Registry;
import de.erethon.dungeonsxxl.requirement.*;
import de.erethon.dungeonsxxl.sign.*;
import de.erethon.dungeonsxxl.util.GlowUtil;
@ -16,7 +22,7 @@ import de.erethon.dungeonsxxl.util.GlowUtil;
/**
* @author Daniel Saukel
*/
public class DungeonsXXL extends DREPlugin {
public class DungeonsXXL extends DREPlugin implements DungeonModule {
private DungeonsXL dxl;
private GlowUtil glowUtil;
@ -33,13 +39,6 @@ public class DungeonsXXL extends DREPlugin {
public void onEnable() {
dxl = DungeonsXL.getInstance();
glowUtil = new GlowUtil(this);
dxl.getRequirementRegistry().add("feeItems", FeeItemsRequirement.class);
dxl.getSignRegistry().add("Firework", FireworkSign.class);
dxl.getSignRegistry().add("GlowingBlock", GlowingBlockSign.class);
dxl.getSignRegistry().add("InteractWall", InteractWallSign.class);
dxl.getSignRegistry().add("Particle", ParticleSign.class);
}
/**
@ -69,4 +68,25 @@ public class DungeonsXXL extends DREPlugin {
return glowUtil;
}
@Override
public void initRequirements(Registry<String, Class<? extends Requirement>> registry) {
registry.add("feeItems", FeeItemsRequirement.class);
}
@Override
public void initRewards(Registry<String, Class<? extends Reward>> registry) {
}
@Override
public void initSigns(Registry<String, Class<? extends DungeonSign>> registry) {
registry.add("FIREWORK", FireworkSign.class);
registry.add("GLOWINGBLOCK", GlowingBlockSign.class);
registry.add("INTERACTWALL", InteractWallSign.class);
registry.add("PARTICLE", ParticleSign.class);
}
@Override
public void initGameRules(Registry<String, GameRule> registry) {
}
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2014-2021 Daniel Saukel
*
* This library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 GNULesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.api;
import de.erethon.commons.misc.Registry;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.sign.DungeonSign;
/**
* Class that manages initialization of several registries.
* <p>
* Addons should implement this interface and add their feature implementations to the registry in the respective method.
*
* @author Daniel Saukel
*/
public interface DungeonModule {
/**
* Initializes the {@link de.erethon.dungeonsxl.api.Requirement requirement} registry.
*
* @param requirementRegistry the registry
*/
void initRequirements(Registry<String, Class<? extends Requirement>> requirementRegistry);
/**
* Initializes the {@link de.erethon.dungeonsxl.api.Reward reward} registry.
*
* @param rewardRegistry the registry
*/
void initRewards(Registry<String, Class<? extends Reward>> rewardRegistry);
/**
* Initializes the {@link de.erethon.dungeonsxl.api.sign.DungeonSign dungeon sign} registry.
*
* @param signRegistry the registry
*/
void initSigns(Registry<String, Class<? extends DungeonSign>> signRegistry);
/**
* Initializes the {@link de.erethon.dungeonsxl.api.dungeon.GameRule game rule} registry.
*
* @param gameRuleRegistry the registry
*/
void initGameRules(Registry<String, GameRule> gameRuleRegistry);
}

View File

@ -145,6 +145,13 @@ public interface DungeonsAPI extends Plugin {
*/
Registry<String, PlayerGroup> getGroupCache();
/**
* Registers a DungeonModule.
*
* @param module the module to register
*/
void registerModule(DungeonModule module);
/**
* Makes DungeonsXL track external group and synchronize them with its own groups.
*

View File

@ -0,0 +1,99 @@
/*
* Copyright (C) 2012-2021 Frank Baumann
*
* 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 de.erethon.dungeonsxl;
import de.erethon.dungeonsxl.api.DungeonModule;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.api.Reward;
import de.erethon.dungeonsxl.api.dungeon.GameRule;
import de.erethon.dungeonsxl.api.sign.DungeonSign;
import de.erethon.dungeonsxl.requirement.*;
import de.erethon.dungeonsxl.reward.*;
import de.erethon.dungeonsxl.sign.button.*;
import de.erethon.dungeonsxl.sign.passive.*;
import de.erethon.dungeonsxl.sign.rocker.*;
import de.erethon.dungeonsxl.sign.windup.*;
import de.erethon.dungeonsxl.util.commons.misc.Registry;
/**
* @author Daniel Saukel
*/
public class DXLModule implements DungeonModule {
@Override
public void initRequirements(Registry<String, Class<? extends Requirement>> requirementRegistry) {
requirementRegistry.add("feeLevel", FeeLevelRequirement.class);
requirementRegistry.add("feeMoney", FeeMoneyRequirement.class);
requirementRegistry.add("forbiddenItems", ForbiddenItemsRequirement.class);
requirementRegistry.add("groupSize", GroupSizeRequirement.class);
requirementRegistry.add("keyItems", KeyItemsRequirement.class);
requirementRegistry.add("permission", PermissionRequirement.class);
requirementRegistry.add("timeframe", TimeframeRequirement.class);
}
@Override
public void initRewards(Registry<String, Class<? extends Reward>> rewardRegistry) {
rewardRegistry.add("item", ItemReward.class);
rewardRegistry.add("money", MoneyReward.class);
rewardRegistry.add("level", LevelReward.class);
}
@Override
public void initSigns(Registry<String, Class<? extends DungeonSign>> signRegistry) {
signRegistry.add("ACTIONBAR", ActionBarSign.class);
signRegistry.add("BED", BedSign.class);
signRegistry.add("BLOCK", BlockSign.class);
signRegistry.add("BOSSSHOP", BossShopSign.class);
signRegistry.add("CHECKPOINT", CheckpointSign.class);
signRegistry.add("CLASSES", ClassesSign.class);
signRegistry.add("CMD", CommandSign.class);
signRegistry.add("DROP", DropSign.class);
signRegistry.add("DUNGEONCHEST", DungeonChestSign.class);
signRegistry.add("END", EndSign.class);
signRegistry.add("FLAG", FlagSign.class);
signRegistry.add("HOLOGRAM", HologramSign.class);
signRegistry.add("INTERACT", InteractSign.class);
signRegistry.add("LEAVE", LeaveSign.class);
signRegistry.add("LIVES", LivesModifierSign.class);
signRegistry.add("LOBBY", LobbySign.class);
signRegistry.add("MOB", MobSign.class);
signRegistry.add("MSG", ChatMessageSign.class);
signRegistry.add("NOTE", NoteSign.class);
signRegistry.add("DOOR", OpenDoorSign.class);
signRegistry.add("PLACE", PlaceSign.class);
signRegistry.add("PROTECTION", ProtectionSign.class);
signRegistry.add("READY", ReadySign.class);
signRegistry.add("REDSTONE", RedstoneSign.class);
signRegistry.add("RESOURCEPACK", ResourcePackSign.class);
signRegistry.add("REWARDCHEST", RewardChestSign.class);
signRegistry.add("SCRIPT", ScriptSign.class);
signRegistry.add("SOUNDMSG", SoundMessageSign.class);
signRegistry.add("START", StartSign.class);
signRegistry.add("TELEPORT", TeleportSign.class);
signRegistry.add("TITLE", TitleSign.class);
signRegistry.add("TRIGGER", TriggerSign.class);
signRegistry.add("WAVE", WaveSign.class);
}
@Override
public void initGameRules(Registry<String, GameRule> gameRuleRegistry) {
for (GameRule rule : GameRule.VALUES) {
gameRuleRegistry.add(rule.getKey(), rule);
}
}
}

View File

@ -22,6 +22,8 @@ import de.erethon.dungeonsxl.adapter.block.BlockAdapter;
import de.erethon.dungeonsxl.adapter.block.BlockAdapterBlockData;
import de.erethon.dungeonsxl.adapter.block.BlockAdapterMagicValues;
import de.erethon.dungeonsxl.announcer.AnnouncerCache;
import de.erethon.dungeonsxl.announcer.AnnouncerListener;
import de.erethon.dungeonsxl.api.DungeonModule;
import de.erethon.dungeonsxl.api.DungeonsAPI;
import de.erethon.dungeonsxl.api.Requirement;
import de.erethon.dungeonsxl.api.Reward;
@ -45,7 +47,6 @@ import de.erethon.dungeonsxl.command.DCommandCache;
import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.config.MainConfig.BackupMode;
import de.erethon.dungeonsxl.dungeon.DDungeon;
import de.erethon.dungeonsxl.global.GlobalData;
import de.erethon.dungeonsxl.global.GlobalProtectionCache;
import de.erethon.dungeonsxl.global.GlobalProtectionListener;
import de.erethon.dungeonsxl.mob.CitizensMobProvider;
@ -60,13 +61,13 @@ import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.player.DPlayerListener;
import de.erethon.dungeonsxl.player.SecureModeTask;
import de.erethon.dungeonsxl.player.groupadapter.*;
import de.erethon.dungeonsxl.requirement.*;
import de.erethon.dungeonsxl.reward.*;
import de.erethon.dungeonsxl.reward.RewardListener;
import de.erethon.dungeonsxl.sign.DSignListener;
import de.erethon.dungeonsxl.sign.button.*;
import de.erethon.dungeonsxl.sign.passive.*;
import de.erethon.dungeonsxl.sign.rocker.*;
import de.erethon.dungeonsxl.sign.windup.*;
import de.erethon.dungeonsxl.sign.button.EndSign;
import de.erethon.dungeonsxl.sign.passive.RewardChestSign;
import de.erethon.dungeonsxl.sign.passive.SignScript;
import de.erethon.dungeonsxl.sign.windup.CommandScript;
import de.erethon.dungeonsxl.sign.windup.MobSign;
import de.erethon.dungeonsxl.trigger.TriggerListener;
import de.erethon.dungeonsxl.trigger.TriggerTypeCache;
import de.erethon.dungeonsxl.util.LWCUtil;
@ -135,19 +136,20 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
}
/* Caches & registries */
private PlayerCache playerCache = new PlayerCache();
private Collection<Game> gameCache = new ArrayList<>();
private Registry<String, PlayerClass> classRegistry = new Registry<>();
private Registry<String, Class<? extends DungeonSign>> signRegistry = new SignRegistry();
private Registry<String, Class<? extends Requirement>> requirementRegistry = new Registry<>();
private Registry<String, Class<? extends Reward>> rewardRegistry = new Registry<>();
private Registry<String, Dungeon> dungeonRegistry = new Registry<>();
private Registry<String, ResourceWorld> mapRegistry = new Registry<>();
private Registry<Integer, InstanceWorld> instanceCache = new Registry<>();
private Registry<String, GameRule> gameRuleRegistry = new GameRuleRegistry();
private Registry<String, ExternalMobProvider> externalMobProviderRegistry = new Registry<>();
private Registry<String, PlayerGroup> playerGroupCache = new PlayerGroupCache();
private Collection<GroupAdapter> groupAdapters = new ArrayList<>();
private Set<DungeonModule> modules = new HashSet<>();
private Collection<GroupAdapter> groupAdapters = new HashSet<>();
private PlayerCache playerCache;
private Collection<Game> gameCache;
private Registry<String, PlayerClass> classRegistry;
private Registry<String, Class<? extends DungeonSign>> signRegistry;
private Registry<String, Class<? extends Requirement>> requirementRegistry;
private Registry<String, Class<? extends Reward>> rewardRegistry;
private Registry<String, Dungeon> dungeonRegistry;
private Registry<String, ResourceWorld> mapRegistry;
private Registry<Integer, InstanceWorld> instanceCache;
private Registry<String, GameRule> gameRuleRegistry;
private Registry<String, ExternalMobProvider> externalMobProviderRegistry;
private Registry<String, PlayerGroup> playerGroupCache;
@Deprecated
private class SignRegistry extends Registry<String, Class<? extends DungeonSign>> {
@ -208,7 +210,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
/* Global state variables */
private boolean loaded, loadingWorld;
private GlobalData globalData;
private MainConfig mainConfig;
/* Caches & registries of internal features */
@ -216,8 +217,8 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
private TriggerTypeCache triggers;
private GlobalProtectionCache protections;
private AnnouncerCache announcers;
private Registry<String, SignScript> signScriptRegistry = new Registry<>();
private Registry<String, CommandScript> commandScriptRegistry = new Registry<>();
private Registry<String, SignScript> signScriptRegistry;
private Registry<String, CommandScript> commandScriptRegistry;
public DungeonsXL() {
settings = DREPluginSettings.builder()
@ -250,6 +251,7 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
initFolders();
loadCaliburn();
DPermission.register();
registerModule(new DXLModule());
initCaches();
checkState();
if (manager.isPluginEnabled("PlaceholderAPI")) {
@ -301,72 +303,34 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
}
public void initCaches() {
/* Legacy caches */
triggers = new TriggerTypeCache();
protections = new GlobalProtectionCache(this);
announcers = new AnnouncerCache(this);
/* Add default values */
requirementRegistry.add("feeLevel", FeeLevelRequirement.class);
requirementRegistry.add("feeMoney", FeeMoneyRequirement.class);
requirementRegistry.add("forbiddenItems", ForbiddenItemsRequirement.class);
requirementRegistry.add("groupSize", GroupSizeRequirement.class);
requirementRegistry.add("keyItems", KeyItemsRequirement.class);
requirementRegistry.add("permission", PermissionRequirement.class);
requirementRegistry.add("timeframe", TimeframeRequirement.class);
requirementRegistry = new Registry<>();
modules.forEach(m -> m.initRequirements(requirementRegistry));
rewardRegistry.add("item", ItemReward.class);
rewardRegistry.add("money", MoneyReward.class);
rewardRegistry.add("level", LevelReward.class);
rewardRegistry = new Registry<>();
modules.forEach(m -> m.initRewards(rewardRegistry));
signRegistry.add("ACTIONBAR", ActionBarSign.class);
signRegistry.add("BED", BedSign.class);
signRegistry.add("BLOCK", BlockSign.class);
signRegistry.add("BOSSSHOP", BossShopSign.class);
signRegistry.add("CHECKPOINT", CheckpointSign.class);
signRegistry.add("CLASSES", ClassesSign.class);
signRegistry.add("CMD", CommandSign.class);
signRegistry.add("DROP", DropSign.class);
signRegistry.add("DUNGEONCHEST", DungeonChestSign.class);
signRegistry.add("END", EndSign.class);
signRegistry.add("FLAG", FlagSign.class);
signRegistry.add("HOLOGRAM", HologramSign.class);
signRegistry.add("INTERACT", InteractSign.class);
signRegistry.add("LEAVE", LeaveSign.class);
signRegistry.add("LIVES", LivesModifierSign.class);
signRegistry.add("LOBBY", LobbySign.class);
signRegistry.add("MOB", MobSign.class);
signRegistry.add("MSG", ChatMessageSign.class);
signRegistry.add("NOTE", NoteSign.class);
signRegistry.add("DOOR", OpenDoorSign.class);
signRegistry.add("PLACE", PlaceSign.class);
signRegistry.add("PROTECTION", ProtectionSign.class);
signRegistry.add("READY", ReadySign.class);
signRegistry.add("REDSTONE", RedstoneSign.class);
signRegistry.add("RESOURCEPACK", ResourcePackSign.class);
signRegistry.add("REWARDCHEST", RewardChestSign.class);
signRegistry.add("SCRIPT", ScriptSign.class);
signRegistry.add("SOUNDMSG", SoundMessageSign.class);
signRegistry.add("START", StartSign.class);
signRegistry.add("TELEPORT", TeleportSign.class);
signRegistry.add("TITLE", TitleSign.class);
signRegistry.add("TRIGGER", TriggerSign.class);
signRegistry.add("WAVE", WaveSign.class);
signRegistry = new SignRegistry();
modules.forEach(m -> m.initSigns(signRegistry));
for (GameRule rule : GameRule.VALUES) {
gameRuleRegistry.add(rule.getKey(), rule);
}
gameRuleRegistry = new GameRuleRegistry();
modules.forEach(m -> m.initGameRules(gameRuleRegistry));
triggers = new TriggerTypeCache();
// modules.forEach(m -> m.initTriggers(triggerRegistry));
mainConfig = new MainConfig(this, new File(getDataFolder(), "config.yml"));
/* Maps & dungeons */
// Maps
mapRegistry = new Registry<>();
for (File file : MAPS.listFiles()) {
if (file.isDirectory() && !file.getName().equals(".raw")) {
mapRegistry.add(file.getName(), new DResourceWorld(this, file));
}
}
// Dungeons - Map dungeons
dungeonRegistry = new Registry<>();
for (ResourceWorld resource : mapRegistry) {
dungeonRegistry.add(resource.getName(), new DDungeon(this, resource));
}
@ -387,27 +351,33 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
}
/* Scripts & global data */
announcers = new AnnouncerCache(this);
manager.registerEvents(new AnnouncerListener(this), this);
announcers.init(ANNOUNCERS);
classRegistry = new Registry<>();
for (File script : FileUtil.getFilesForFolder(CLASSES)) {
PlayerClass clss = new PlayerClass(caliburn, script);
classRegistry.add(clss.getName(), clss);
}
signScriptRegistry = new Registry<>();
for (File script : FileUtil.getFilesForFolder(SIGNS)) {
SignScript sign = new SignScript(script);
signScriptRegistry.add(sign.getName(), sign);
}
commandScriptRegistry = new Registry<>();
for (File script : FileUtil.getFilesForFolder(COMMANDS)) {
CommandScript cmd = new CommandScript(script);
commandScriptRegistry.add(cmd.getName(), cmd);
}
globalData = new GlobalData(this, new File(getDataFolder(), "data.yml"));
globalData.load();
protections = new GlobalProtectionCache(this);
/* Integrations */
if (LWCUtil.isLWCLoaded()) {
new LWCIntegration(this);
}
// Mobs - Supported providers
externalMobProviderRegistry = new Registry<>();
for (ExternalMobPlugin externalMobPlugin : ExternalMobPlugin.values()) {
externalMobProviderRegistry.add(externalMobPlugin.getIdentifier(), externalMobPlugin);
}
@ -423,26 +393,39 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
externalMobProviderRegistry.add(customExternalMobProvider.getKey(), new CustomExternalMobProvider(customExternalMobProvider));
}
/* Player tasks */
/* Players */
if (mainConfig.isSecureModeEnabled()) {
new SecureModeTask(this).runTaskTimer(this, mainConfig.getSecureModeCheckInterval(), mainConfig.getSecureModeCheckInterval());
}
new BukkitRunnable() {
@Override
public void run() {
playerCache.getAllGamePlayers().forEach(p -> ((DGamePlayer) p).update(false));
}
}.runTaskTimer(this, 2L, 2L);
new BukkitRunnable() {
@Override
public void run() {
playerCache.getAllGamePlayers().forEach(p -> ((DGamePlayer) p).update(true));
}
}.runTaskTimer(this, 20L, 20L);
playerCache = new PlayerCache();
playerGroupCache = new PlayerGroupCache();
/* Initialize commands & listeners */
gameCache = new ArrayList<>();
instanceCache = new Registry<>();
/* Initialize commands */
dCommands = new DCommandCache(this);
dCommands.register(this);
/* Following initializations are not to be repeated on reload */
if (loaded) {
return;
}
new BukkitRunnable() {
int i = 0;
@Override
public void run() {
boolean update = ++i == 10;
if (update) {
i = 0;
}
playerCache.getAllGamePlayers().forEach(p -> ((DGamePlayer) p).update(update));
}
}.runTaskTimer(this, 2L, 2L);
/* Initialize listeners */
manager.registerEvents(new DWorldListener(this), this);
manager.registerEvents(new GlobalProtectionListener(this), this);
manager.registerEvents(new RewardListener(this), this);
@ -568,6 +551,11 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
return playerGroupCache;
}
@Override
public void registerModule(DungeonModule module) {
modules.add(module);
}
@Override
public void registerGroupAdapter(GroupAdapter groupAdapter) {
if (mainConfig.areGroupAdaptersEnabled()) {
@ -617,13 +605,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
this.loadingWorld = loadingWorld;
}
/**
* @return the loaded instance of GlobalData
*/
public GlobalData getGlobalData() {
return globalData;
}
@Override
public DCommandCache getCommandCache() {
return dCommands;

View File

@ -20,7 +20,6 @@ import de.erethon.dungeonsxl.DungeonsXL;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.inventory.InventoryView;
@ -49,7 +48,6 @@ public class AnnouncerCache {
if (!announcers.isEmpty() && plugin.getMainConfig().getAnnouncmentInterval() > 0) {
new AnnouncerTask(plugin).runTaskTimer(plugin, plugin.getMainConfig().getAnnouncmentInterval(), plugin.getMainConfig().getAnnouncmentInterval());
}
Bukkit.getPluginManager().registerEvents(new AnnouncerListener(plugin), plugin);
}
/**

View File

@ -51,7 +51,6 @@ public class ReloadCommand extends DCommand {
@Override
public void onExecute(String[] args, CommandSender sender) {
sender.sendMessage("The reload command is disabled in this development build."); if (true) return;
if (args.length >= 2 && (args[1].equalsIgnoreCase("-caliburn") || args[1].equalsIgnoreCase("-c"))) {
plugin.getCaliburn().reload();
MessageUtil.sendCenteredMessage(sender, DMessage.CMD_RELOAD_SUCCESS.getMessage());
@ -97,7 +96,7 @@ public class ReloadCommand extends DCommand {
ixl = plugins.getPlugin("ItemsXL").getDescription().getVersion();
}
plugin.onDisable();
plugin.saveData();
plugin.initFolders();
plugin.initCaches();
plugin.checkState();

View File

@ -38,7 +38,6 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
/**
@ -283,24 +282,27 @@ public class DPortal extends GlobalProtection {
}
@Override
public void save(FileConfiguration configFile) {
public String getDataPath() {
return "protections.portals";
}
@Override
public void save(ConfigurationSection config) {
if (!active) {
return;
}
String preString = "protections.portals." + getWorld().getName() + "." + getId();
config.set("loc1.x", block1.getX());
config.set("loc1.y", block1.getY());
config.set("loc1.z", block1.getZ());
configFile.set(preString + ".loc1.x", block1.getX());
configFile.set(preString + ".loc1.y", block1.getY());
configFile.set(preString + ".loc1.z", block1.getZ());
config.set("loc2.x", block2.getX());
config.set("loc2.y", block2.getY());
config.set("loc2.z", block2.getZ());
configFile.set(preString + ".loc2.x", block2.getX());
configFile.set(preString + ".loc2.y", block2.getY());
configFile.set(preString + ".loc2.z", block2.getZ());
configFile.set(preString + ".material", material.getId());
config.set("material", material.getId());
if (material == VanillaItem.NETHER_PORTAL) {
configFile.set(preString + ".axis", zAxis ? "z" : "x");
config.set("axis", zAxis ? "z" : "x");
}
}

View File

@ -1,117 +0,0 @@
/*
* Copyright (C) 2012-2021 Frank Baumann
*
* 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 de.erethon.dungeonsxl.global;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.util.commons.config.DREConfig;
import de.erethon.dungeonsxl.util.commons.misc.NumberUtil;
import java.io.File;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
/**
* Represents the global data.yml.
*
* @author Daniel Saukel
*/
public class GlobalData extends DREConfig {
private DungeonsXL plugin;
public static final int CONFIG_VERSION = 2;
public GlobalData(DungeonsXL plugin, File file) {
super(file, CONFIG_VERSION);
this.plugin = plugin;
if (initialize) {
initialize();
}
}
@Override
public void initialize() {
save();
}
@Override
public void load() {
ConfigurationSection gameSigns = config.getConfigurationSection("protections.gameSigns");
ConfigurationSection groupSigns = config.getConfigurationSection("protections.groupSigns");
ConfigurationSection leaveSigns = config.getConfigurationSection("protections.leaveSigns");
ConfigurationSection portals = config.getConfigurationSection("protections.portals");
if (gameSigns != null) {
for (String worldName : gameSigns.getValues(false).keySet()) {
ConfigurationSection ws = gameSigns.getConfigurationSection(worldName);
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
new GameSign(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
} else {
new UnloadedProtection<>(plugin, GameSign.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
}
}
}
}
if (groupSigns != null) {
for (String worldName : groupSigns.getValues(false).keySet()) {
ConfigurationSection ws = groupSigns.getConfigurationSection(worldName);
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
new GroupSign(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
} else {
new UnloadedProtection<>(plugin, GroupSign.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
}
}
}
}
if (leaveSigns != null) {
for (String worldName : leaveSigns.getValues(false).keySet()) {
ConfigurationSection ws = leaveSigns.getConfigurationSection(worldName);
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
new LeaveSign(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
} else {
new UnloadedProtection<>(plugin, LeaveSign.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
}
}
}
}
if (portals != null) {
for (String worldName : portals.getValues(false).keySet()) {
ConfigurationSection ws = portals.getConfigurationSection(worldName);
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
new DPortal(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
} else {
new UnloadedProtection<>(plugin, DPortal.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey()));
}
}
}
}
}
}

View File

@ -20,13 +20,11 @@ import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGlobalPlayer;
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
import java.io.File;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.ConfigurationSection;
/**
* @author Daniel Saukel
@ -35,7 +33,6 @@ public abstract class GlobalProtection {
protected DungeonsXL plugin;
protected GlobalProtectionCache protections;
private FileConfiguration config;
public static final String SIGN_TAG = "[DXL]";
@ -45,12 +42,9 @@ public abstract class GlobalProtection {
protected GlobalProtection(DungeonsXL plugin, World world, int id) {
this.plugin = plugin;
protections = plugin.getGlobalProtectionCache();
config = plugin.getGlobalData().getConfig();
this.world = world.getName();
this.id = id;
protections.addProtection(this);
}
/**
@ -75,20 +69,6 @@ public abstract class GlobalProtection {
protections.removeProtection(this);
}
/**
* Save the data to the default file
*/
public void save() {
save(config);
}
/**
* @param file the file to save the protection to
*/
public void save(File file) {
save(YamlConfiguration.loadConfiguration(file));
}
public boolean onBreak(DGlobalPlayer dPlayer) {
if (dPlayer.isInBreakMode()) {
delete();
@ -104,9 +84,11 @@ public abstract class GlobalProtection {
/* Abstracts */
/**
* @param config the config to save the protection to
* @return the path in the global data file
*/
public abstract void save(FileConfiguration config);
public abstract String getDataPath();
public abstract void save(ConfigurationSection config);
/**
* @return a collection of all blocks covered by this protection

View File

@ -18,14 +18,19 @@ package de.erethon.dungeonsxl.global;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.util.commons.misc.NumberUtil;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@ -36,11 +41,24 @@ public class GlobalProtectionCache {
private DungeonsXL plugin;
private File file;
private FileConfiguration config;
private Set<GlobalProtection> protections = new HashSet<>();
private Map<UnloadedProtection, String> unloaded = new HashMap<>();
public GlobalProtectionCache(DungeonsXL plugin) {
this.plugin = plugin;
file = new File(plugin.getDataFolder(), "data.yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
}
}
config = YamlConfiguration.loadConfiguration(file);
loadAll();
}
/**
@ -107,30 +125,97 @@ public class GlobalProtectionCache {
protections.remove(protection);
}
/**
* Save all protections to the default file
*/
public void saveAll() {
saveAll(plugin.getGlobalData().getConfig());
}
/**
* @param file the file to save all protections to
*/
public void saveAll(File file) {
saveAll(YamlConfiguration.loadConfiguration(file));
}
/**
* @param config the config to save all protections to
*/
public void saveAll(FileConfiguration config) {
config.set("protections", null);
for (GlobalProtection protection : protections) {
protection.save(config);
public void loadAll() {
ConfigurationSection gameSigns = config.getConfigurationSection("protections.gameSigns");
ConfigurationSection groupSigns = config.getConfigurationSection("protections.groupSigns");
ConfigurationSection leaveSigns = config.getConfigurationSection("protections.leaveSigns");
ConfigurationSection portals = config.getConfigurationSection("protections.portals");
if (gameSigns != null) {
for (String worldName : gameSigns.getValues(false).keySet()) {
ConfigurationSection ws = gameSigns.getConfigurationSection(worldName);
if (ws == null) {
continue;
}
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
addProtection(new GameSign(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())));
} else {
unloaded.put(new UnloadedProtection<>(plugin, GameSign.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())), worldName);
}
}
}
}
plugin.getGlobalData().save();
if (groupSigns != null) {
for (String worldName : groupSigns.getValues(false).keySet()) {
ConfigurationSection ws = groupSigns.getConfigurationSection(worldName);
if (ws == null) {
continue;
}
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
addProtection(new GroupSign(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())));
} else {
unloaded.put(new UnloadedProtection<>(plugin, GroupSign.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())), worldName);
}
}
}
}
if (leaveSigns != null) {
for (String worldName : leaveSigns.getValues(false).keySet()) {
ConfigurationSection ws = leaveSigns.getConfigurationSection(worldName);
if (ws == null) {
continue;
}
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
addProtection(new LeaveSign(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())));
} else {
unloaded.put(new UnloadedProtection<>(plugin, LeaveSign.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())), worldName);
}
}
}
}
if (portals != null) {
for (String worldName : portals.getValues(false).keySet()) {
ConfigurationSection ws = portals.getConfigurationSection(worldName);
if (ws == null) {
continue;
}
for (Entry<String, Object> entry : ws.getValues(false).entrySet()) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
addProtection(new DPortal(plugin, world, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())));
} else {
unloaded.put(new UnloadedProtection<>(plugin, DPortal.class, worldName, NumberUtil.parseInt(entry.getKey()), ws.getConfigurationSection(entry.getKey())), worldName);
}
}
}
}
}
public void saveAll() {
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException exception) {
exception.printStackTrace();
}
}
config.set("protections", null);
for (GlobalProtection protection : protections) {
protection.save(config.createSection(protection.getDataPath() + "." + protection.getWorld().getName() + "." + protection.getId()));
}
try {
config.save(file);
} catch (IOException exception) {
exception.printStackTrace();
}
}
/**

View File

@ -27,7 +27,6 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.block.SignChangeEvent;
@ -127,10 +126,9 @@ public class GroupSign extends JoinSign {
}
@Override
public void save(FileConfiguration config) {
public void save(ConfigurationSection config) {
super.save(config);
String preString = getDataPath() + "." + getWorld().getName() + "." + getId();
config.set(preString + ".groupName", groupName);
config.set("groupName", groupName);
}
public void onPlayerInteract(Block block, Player player) {

View File

@ -27,7 +27,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
/**
* @author Daniel Saukel
@ -175,24 +174,17 @@ public abstract class JoinSign extends GlobalProtection {
}
}
/**
* @return the path in the global data file
*/
public abstract String getDataPath();
@Override
public void save(FileConfiguration config) {
String preString = getDataPath() + "." + getWorld().getName() + "." + getId();
config.set(preString + ".x", startSign.getX());
config.set(preString + ".y", startSign.getY());
config.set(preString + ".z", startSign.getZ());
public void save(ConfigurationSection config) {
config.set("x", startSign.getX());
config.set("y", startSign.getY());
config.set("z", startSign.getZ());
if (dungeon != null) {
config.set(preString + ".dungeon", dungeon.getName());
config.set("dungeon", dungeon.getName());
}
config.set(preString + ".maxElements", maxElements);
config.set("maxElements", maxElements);
if (startIfElementsAtLeast != -1) {
config.set(preString + ".startIfElementsAtLeast", startIfElementsAtLeast);
config.set("startIfElementsAtLeast", startIfElementsAtLeast);
}
}

View File

@ -31,7 +31,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
/**
@ -106,11 +105,15 @@ public class LeaveSign extends GlobalProtection {
}
@Override
public void save(FileConfiguration config) {
String preString = "protections.leaveSigns." + sign.getWorld().getName() + "." + getId();
config.set(preString + ".x", sign.getX());
config.set(preString + ".y", sign.getY());
config.set(preString + ".z", sign.getZ());
public String getDataPath() {
return "protections.leaveSigns";
}
@Override
public void save(ConfigurationSection config) {
config.set("x", sign.getX());
config.set("y", sign.getY());
config.set("z", sign.getZ());
}
/* Statics */

View File

@ -49,7 +49,6 @@ public class UnloadedProtection<T extends GlobalProtection> {
this.config = config;
cache = plugin.getGlobalProtectionCache();
cache.getUnloadedProtections().put(this, worldName);
}
public T load(World world) {

View File

@ -26,12 +26,10 @@ import de.erethon.dungeonsxl.api.player.EditPlayer;
import de.erethon.dungeonsxl.api.player.GamePlayer;
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
import de.erethon.dungeonsxl.api.player.InstancePlayer;
import de.erethon.dungeonsxl.api.player.PlayerCache;
import de.erethon.dungeonsxl.api.player.PlayerGroup;
import de.erethon.dungeonsxl.api.world.GameWorld;
import de.erethon.dungeonsxl.api.world.InstanceWorld;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.config.MainConfig;
import de.erethon.dungeonsxl.dungeon.DGame;
import de.erethon.dungeonsxl.util.ParsingUtil;
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
@ -73,15 +71,11 @@ import org.bukkit.projectiles.ProjectileSource;
public class DPlayerListener implements Listener {
private DungeonsXL plugin;
private MainConfig config;
private PlayerCache dPlayers;
public static final String ALL = "@all ";
public DPlayerListener(DungeonsXL plugin) {
this.plugin = plugin;
config = plugin.getMainConfig();
dPlayers = plugin.getPlayerCache();
}
@EventHandler
@ -206,7 +200,7 @@ public class DPlayerListener implements Listener {
// Check Dogs
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
for (GamePlayer player : dPlayers.getAllGamePlayersIf(p -> p.getGameWorld() == gameWorld)) {
for (GamePlayer player : plugin.getPlayerCache().getAllGamePlayersIf(p -> p.getGameWorld() == gameWorld)) {
if (player.getWolf() != null) {
if (attackerEntity == player.getWolf() || attackedEntity == player.getWolf()) {
event.setCancelled(true);
@ -216,7 +210,7 @@ public class DPlayerListener implements Listener {
}
}
for (GamePlayer dPlayer : dPlayers.getAllGamePlayersIf(p -> p.getGameWorld() == gameWorld)) {
for (GamePlayer dPlayer : plugin.getPlayerCache().getAllGamePlayersIf(p -> p.getGameWorld() == gameWorld)) {
if (dPlayer.getWolf() != null) {
if (attackerEntity instanceof Player || attackedEntity instanceof Player) {
if (attackerEntity == dPlayer.getWolf() || attackedEntity == dPlayer.getWolf()) {
@ -249,7 +243,7 @@ public class DPlayerListener implements Listener {
if (isCitizensNPC(player)) {
return;
}
GlobalPlayer dPlayer = dPlayers.get(player);
GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
if (dPlayer == null) {
return;
}
@ -273,7 +267,7 @@ public class DPlayerListener implements Listener {
if (game) {
((DInstancePlayer) dPlayer).chat(event.getMessage().substring(ALL.length()));
} else {
group.sendMessage(ParsingUtil.replaceChatPlaceholders(config.getChatFormatGroup(), dPlayer) + event.getMessage());
group.sendMessage(ParsingUtil.replaceChatPlaceholders(plugin.getMainConfig().getChatFormatGroup(), dPlayer) + event.getMessage());
}
}
@ -288,10 +282,10 @@ public class DPlayerListener implements Listener {
return;
}
if (!(dPlayers.get(player) instanceof DInstancePlayer)) {
if (!(plugin.getPlayerCache().get(player) instanceof DInstancePlayer)) {
return;
}
InstancePlayer dPlayer = dPlayers.getInstancePlayer(player);
InstancePlayer dPlayer = plugin.getPlayerCache().getInstancePlayer(player);
String command = event.getMessage().toLowerCase();
ArrayList<String> commandWhitelist = new ArrayList<>();
@ -301,7 +295,7 @@ public class DPlayerListener implements Listener {
return;
} else {
commandWhitelist.addAll(config.getEditCommandWhitelist());
commandWhitelist.addAll(plugin.getMainConfig().getEditCommandWhitelist());
}
} else {
@ -331,7 +325,7 @@ public class DPlayerListener implements Listener {
if (isCitizensNPC(player)) {
return;
}
DGamePlayer dPlayer = (DGamePlayer) dPlayers.getGamePlayer(player);
DGamePlayer dPlayer = (DGamePlayer) plugin.getPlayerCache().getGamePlayer(player);
if (dPlayer == null) {
return;
}
@ -345,12 +339,12 @@ public class DPlayerListener implements Listener {
return;
}
GlobalPlayer dPlayer = dPlayers.get(player);
GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
if (dPlayer == null) {
return;
}
if (dPlayer instanceof EditPlayer && !config.getDropItems() && !DPermission.hasPermission(player, DPermission.INSECURE)) {
if (dPlayer instanceof EditPlayer && !plugin.getMainConfig().getDropItems() && !DPermission.hasPermission(player, DPermission.INSECURE)) {
event.setCancelled(true);
}
@ -397,8 +391,8 @@ public class DPlayerListener implements Listener {
dPlayer.getData().getKeepInventoryAfterLogout());
}
if (!dPlayer.getData().hasFinishedTutorial() && config.isTutorialActivated()) {
if (plugin.getInstanceCache().size() < config.getMaxInstances()) {
if (!dPlayer.getData().hasFinishedTutorial() && plugin.getMainConfig().isTutorialActivated()) {
if (plugin.getInstanceCache().size() < plugin.getMainConfig().getMaxInstances()) {
dPlayer.startTutorial();
} else {
event.getPlayer().kickPlayer(DMessage.ERROR_TOO_MANY_TUTORIALS.getMessage());
@ -413,7 +407,7 @@ public class DPlayerListener implements Listener {
return;
}
DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld());
DGamePlayer gamePlayer = (DGamePlayer) dPlayers.getGamePlayer(player);
DGamePlayer gamePlayer = (DGamePlayer) plugin.getPlayerCache().getGamePlayer(player);
if (gameWorld != null && gamePlayer != null) {
if (gamePlayer.getDGroupTag() != null) {
gamePlayer.getDGroupTag().update();
@ -432,7 +426,7 @@ public class DPlayerListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
GlobalPlayer dPlayer = dPlayers.get(player);
GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
PlayerGroup dGroup = dPlayer.getGroup();
if (!(dPlayer instanceof InstancePlayer)) {
@ -460,7 +454,7 @@ public class DPlayerListener implements Listener {
((InstancePlayer) dPlayer).leave();
}
dPlayers.remove(dPlayer);
plugin.getPlayerCache().remove(dPlayer);
}
@EventHandler
@ -470,7 +464,7 @@ public class DPlayerListener implements Listener {
return;
}
InstancePlayer instancePlayer = dPlayers.getInstancePlayer(player);
InstancePlayer instancePlayer = plugin.getPlayerCache().getInstancePlayer(player);
if (instancePlayer == null) {
return;
}
@ -513,7 +507,7 @@ public class DPlayerListener implements Listener {
if (isCitizensNPC(player)) {
return;
}
GlobalPlayer dPlayer = dPlayers.get(player);
GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
World toWorld = event.getTo().getWorld();
@ -588,7 +582,7 @@ public class DPlayerListener implements Listener {
if (plugin.getEditWorld(player.getWorld()) != null) {
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (VanillaItem.STICK.is(item)) {
DEditPlayer editPlayer = (DEditPlayer) dPlayers.getEditPlayer(player);
DEditPlayer editPlayer = (DEditPlayer) plugin.getPlayerCache().getEditPlayer(player);
if (editPlayer != null) {
editPlayer.poke(clickedBlock);
event.setCancelled(true);