From 0e720697bebc41fd018f051a50bb864640a591c3 Mon Sep 17 00:00:00 2001 From: plazmer <48393153+getplusm@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:49:33 +0500 Subject: [PATCH] v3.0.0 --- build.gradle | 18 +- .../p1azmer/plugin/dungeons/DungeonAPI.java | 18 +- .../plugin/dungeons/DungeonPlugin.java | 68 +-- .../t/me/p1azmer/plugin/dungeons/Keys.java | 1 + .../t/me/p1azmer/plugin/dungeons/Perms.java | 52 +- .../p1azmer/plugin/dungeons/Placeholders.java | 105 ---- .../dungeons/announce/Placeholders.java | 7 + .../announce/editor/AnnounceMainEditor.java | 10 +- .../dungeons/announce/impl/Announce.java | 75 +-- .../api/events/DungeonChangeStageEvent.java | 23 +- ...eteEvent.java => DungeonDespawnEvent.java} | 6 +- .../dungeons/api/events/DungeonEvent.java | 5 + .../api/events/DungeonSpawnEvent.java | 2 +- .../hologram/HologramHandler.java | 8 +- .../api/{ => handler}/party/PartyHandler.java | 2 +- .../{ => handler}/region/RegionHandler.java | 4 +- .../schematic/SchematicHandler.java | 5 +- .../plugin/dungeons/api/mob/MobFaction.java | 3 +- .../api/settings/AbstractSettings.java | 10 +- .../commands/dungeon/DeleteCommand.java | 23 +- .../commands/dungeon/SpawnCommand.java | 35 +- .../dungeons/commands/key/GiveAllCommand.java | 2 +- .../dungeons/commands/key/ManageCommand.java | 2 +- .../plugin/dungeons/config/Config.java | 53 +- .../dungeons/dungeon/DungeonManager.java | 129 +++-- .../plugin/dungeons/dungeon/Placeholders.java | 27 + .../dungeons/dungeon/chest/ChestBlock.java | 146 ++++++ .../dungeons/dungeon/chest/ChestMenu.java | 102 ++++ .../dungeon/chest/DungeonChestBlock.java | 171 ------- .../dungeon/chest/DungeonChestMenu.java | 112 ----- .../dungeons/dungeon/chest/Placeholders.java | 12 + .../ChestState.java} | 6 +- .../dungeon/editor/DungeonMainEditor.java | 20 +- .../effect/DungeonEffectListEditor.java | 2 +- .../region/DungeonRegionMainEditor.java | 8 +- .../reward/DungeonRewardListEditor.java | 6 +- .../reward/DungeonRewardMainEditor.java | 3 +- .../settings/AnnounceSettingsEditor.java | 5 +- .../editor/settings/ChestSettingsEditor.java | 16 +- .../settings/CommandsSettingsEditor.java | 7 +- .../settings/GenerationSettingsEditor.java | 78 +++ .../settings/HologramSettingsEditor.java | 18 +- .../editor/settings/MainSettingsEditor.java | 4 +- .../editor/settings/ModuleSettingsEditor.java | 35 +- .../editor/settings/PartySettingsEditor.java | 3 +- .../settings/SchematicsSettingsEditor.java | 2 +- .../editor/settings/StageSettingsEditor.java | 13 +- .../{categories => effect}/Effect.java | 32 +- .../dungeons/dungeon/effect/Placeholders.java | 7 + .../dungeon/generation/GenerationType.java | 64 +++ .../plugin/dungeons/dungeon/impl/Dungeon.java | 466 ++++++++---------- .../dungeon/listener/DungeonListener.java | 123 ++++- .../dungeon/modules/AbstractModule.java | 210 ++++---- .../dungeon/modules/ModuleManager.java | 29 +- .../dungeon/modules/Placeholders.java | 6 + .../dungeon/modules/impl/AnnounceModule.java | 58 ++- .../dungeon/modules/impl/BossBarModule.java | 59 --- .../dungeon/modules/impl/ChestModule.java | 195 ++++---- .../dungeon/modules/impl/CommandModule.java | 33 +- .../dungeon/modules/impl/HologramModule.java | 41 +- .../dungeon/modules/impl/MobModule.java | 62 ++- .../dungeon/modules/impl/SchematicModule.java | 86 ++-- .../dungeon/modules/impl/SpawnModule.java | 154 +++--- .../dungeons/dungeon/region/Placeholders.java | 8 + .../{categories => region}/Region.java | 70 +-- .../dungeons/dungeon/reward/Placeholders.java | 11 + .../{categories => reward}/Reward.java | 41 +- .../dungeon/settings/MainSettings.java | 123 ----- .../dungeon/settings/Placeholders.java | 18 + .../settings/{ => impl}/AnnounceSettings.java | 35 +- .../settings/{ => impl}/ChestSettings.java | 124 ++--- .../settings/{ => impl}/CommandsSettings.java | 28 +- .../settings/{ => impl}/EffectSettings.java | 42 +- .../settings/impl/GenerationSettings.java | 59 +++ .../settings/{ => impl}/HologramSettings.java | 62 +-- .../dungeon/settings/impl/MainSettings.java | 83 ++++ .../settings/{ => impl}/ModuleSettings.java | 26 +- .../settings/{ => impl}/PartySettings.java | 41 +- .../settings/{ => impl}/RewardSettings.java | 31 +- .../{ => impl}/SchematicSettings.java | 51 +- .../impl}/StageSettings.java | 30 +- .../dungeons/dungeon/stage/DungeonStage.java | 86 ++-- .../dungeons/dungeon/stage/Placeholders.java | 9 + .../dungeons/dungeon/stage/StageLang.java | 62 +++ .../plugin/dungeons/editor/EditorLocales.java | 178 ++++--- .../plugin/dungeons/generator/RangeInfo.java | 101 ++-- .../generator/config/GeneratorConfig.java | 4 +- .../holograms/HologramDecentHandler.java | 87 ++-- .../holograms/HologramDisplaysHandler.java | 60 ++- .../integration/party/PartyHandlerPaF.java | 39 +- .../integration/region/RegionHandlerGD.java | 92 ++-- .../integration/region/RegionHandlerGP.java | 53 +- .../region/RegionHandlerKingdoms.java | 56 +-- .../integration/region/RegionHandlerPB.java | 4 +- .../region/RegionHandlerTowny.java | 67 ++- .../integration/region/RegionHandlerWG.java | 31 +- .../schematics/SchematicFAWEHandler.java | 139 +++--- .../t/me/p1azmer/plugin/dungeons/key/Key.java | 22 +- .../plugin/dungeons/key/Placeholders.java | 7 + .../me/p1azmer/plugin/dungeons/lang/Lang.java | 300 +++++++---- .../plugin/dungeons/mob/MobListener.java | 6 +- .../plugin/dungeons/mob/MobManager.java | 24 +- .../plugin/dungeons/mob/Placeholders.java | 18 + .../plugin/dungeons/mob/config/MobConfig.java | 2 +- .../dungeons/mob/config/MobsConfig.java | 63 +-- .../dungeons/mob/editor/MobStylesEditor.java | 2 +- .../dungeon/LocationPlaceholder.java | 9 +- .../dungeon/NearLocationPlaceholder.java | 7 +- .../dungeon/NearOpenTimePlaceholder.java | 4 +- .../dungeon/OpenTimePlaceholder.java | 4 +- .../plugin/dungeons/task/DungeonTickTask.java | 7 +- .../p1azmer/plugin/dungeons/utils/Cuboid.java | 2 +- .../resources/announce/closed_default.yml | 1 - .../resources/announce/prepare_default.yml | 3 +- 114 files changed, 2932 insertions(+), 2587 deletions(-) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/announce/Placeholders.java rename src/main/java/t/me/p1azmer/plugin/dungeons/api/events/{DungeonDeleteEvent.java => DungeonDespawnEvent.java} (76%) rename src/main/java/t/me/p1azmer/plugin/dungeons/api/{ => handler}/hologram/HologramHandler.java (58%) rename src/main/java/t/me/p1azmer/plugin/dungeons/api/{ => handler}/party/PartyHandler.java (82%) rename src/main/java/t/me/p1azmer/plugin/dungeons/api/{ => handler}/region/RegionHandler.java (79%) rename src/main/java/t/me/p1azmer/plugin/dungeons/api/{ => handler}/schematic/SchematicHandler.java (69%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/Placeholders.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestBlock.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestMenu.java delete mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestBlock.java delete mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestMenu.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/Placeholders.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/{DungeonChestState.java => state/ChestState.java} (81%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/GenerationSettingsEditor.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/{categories => effect}/Effect.java (65%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Placeholders.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/generation/GenerationType.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/Placeholders.java delete mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/BossBarModule.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Placeholders.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/{categories => region}/Region.java (60%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Placeholders.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/{categories => reward}/Reward.java (80%) delete mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/MainSettings.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/Placeholders.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/AnnounceSettings.java (82%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/ChestSettings.java (56%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/CommandsSettings.java (72%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/EffectSettings.java (69%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/GenerationSettings.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/HologramSettings.java (58%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/MainSettings.java rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/ModuleSettings.java (77%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/PartySettings.java (62%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/RewardSettings.java (66%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/{ => impl}/SchematicSettings.java (65%) rename src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/{stage => settings/impl}/StageSettings.java (69%) create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/Placeholders.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageLang.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/key/Placeholders.java create mode 100644 src/main/java/t/me/p1azmer/plugin/dungeons/mob/Placeholders.java diff --git a/build.gradle b/build.gradle index d48e533..8aacddb 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,9 @@ plugins { id 'java' - id "com.github.johnrengelman.shadow" version "7.1.2" } group = 'plazmer' -version = '2.1.2' +version = '3.0.0' repositories { mavenCentral() @@ -70,7 +69,7 @@ dependencies { compileOnly group: 'com.griefdefender', name: 'api', version: '2.1.0-SNAPSHOT' compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.2-SNAPSHOT' compileOnly 'com.github.cryptomorin:kingdoms:1.16.8.1.1' - compileOnly 'com.github.getplusm:ProtectionBlocks:1.0.6R1' + compileOnly 'com.github.getplusm:ProtectionBlocks:1.0.7' compileOnly 'com.github.TechFortress:GriefPrevention:16.18' compileOnly 'com.github.angeschossen:LandsAPI:6.33.10' @@ -92,7 +91,12 @@ dependencies { // Vault compileOnly 'com.github.MilkBowl:VaultAPI:1.7' + // Engine compileOnly 'com.github.getplusm:Engine:2.4.4' + + // Libs + compileOnly 'org.projectlombok:lombok:1.18.22' + annotationProcessor 'org.projectlombok:lombok:1.18.22' } def targetJavaVersion = 17 @@ -119,11 +123,7 @@ processResources { expand props } } -shadowJar { - archivesBaseName = "TheDungeons" +jar{ archiveClassifier.set "" destinationDirectory.set(rootProject.buildDir) -} -assemble.dependsOn(shadowJar) -// you can change broadcast settings in editor -// all dungeons messages send only for world players \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonAPI.java b/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonAPI.java index 48b8e34..8bfdd0d 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonAPI.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonAPI.java @@ -1,22 +1,34 @@ package t.me.p1azmer.plugin.dungeons; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleManager; -public class DungeonAPI { +import java.util.Optional; +public class DungeonAPI { public static final DungeonPlugin PLUGIN = DungeonPlugin.getPlugin(DungeonPlugin.class); + @NotNull public static DungeonManager getDungeonManager(){ return PLUGIN.getDungeonManager(); } @NotNull - public static ModuleManager getDungeonModule(@NotNull Dungeon dungeon){ + public static ModuleManager getModuleManager(@NotNull Dungeon dungeon){ return dungeon.getModuleManager(); } + + public static Optional getModule(@NotNull Dungeon dungeon, @NotNull String name){ + ModuleManager moduleManager = getModuleManager(dungeon); + return Optional.ofNullable(moduleManager.getModule(name)); + } + + public static Optional getModule(@NotNull Dungeon dungeon, @NotNull Class clazz){ + ModuleManager moduleManager = getModuleManager(dungeon); + return moduleManager.getModule(clazz); + } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonPlugin.java b/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonPlugin.java index 89ecdac..2ead97b 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonPlugin.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/DungeonPlugin.java @@ -1,5 +1,6 @@ package t.me.p1azmer.plugin.dungeons; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.NexPlugin; @@ -7,18 +8,20 @@ import t.me.p1azmer.engine.command.list.ReloadSubCommand; import t.me.p1azmer.engine.utils.EngineUtils; import t.me.p1azmer.plugin.dungeons.announce.AnnounceManager; -import t.me.p1azmer.plugin.dungeons.api.hologram.HologramHandler; -import t.me.p1azmer.plugin.dungeons.api.party.PartyHandler; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; -import t.me.p1azmer.plugin.dungeons.api.schematic.SchematicHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.hologram.HologramHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.party.PartyHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.schematic.SchematicHandler; import t.me.p1azmer.plugin.dungeons.commands.EditorCommand; import t.me.p1azmer.plugin.dungeons.commands.dungeon.DeleteCommand; import t.me.p1azmer.plugin.dungeons.commands.dungeon.SpawnCommand; import t.me.p1azmer.plugin.dungeons.commands.key.KeyCommand; import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.StageLang; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.editor.EditorMainMenu; import t.me.p1azmer.plugin.dungeons.integration.holograms.HologramDecentHandler; @@ -33,6 +36,7 @@ import t.me.p1azmer.plugin.dungeons.placeholders.DungeonPlaceholder; import t.me.p1azmer.plugin.dungeons.utils.SessionConsole; +@Getter public final class DungeonPlugin extends NexPlugin { private DungeonManager dungeonManager; private KeyManager keyManager; @@ -41,6 +45,7 @@ public final class DungeonPlugin extends NexPlugin { private EditorMainMenu editor; private SessionConsole sessionConsole; + private HologramHandler hologramHandler; private SchematicHandler schematicHandler; private RegionHandler regionHandler; @@ -122,15 +127,21 @@ public void loadConfig() { @Override public void loadLang() { this.getLangManager().loadMissing(Lang.class); + this.getLangManager().loadMissing(StageLang.class); this.getLangManager().loadEditor(EditorLocales.class); this.getLangManager().loadEnum(MobStyleType.class); this.getLangManager().loadEnum(DungeonStage.class); - this.getLangManager().loadEnum(DungeonChestState.class); + this.getLangManager().loadEnum(ChestState.class); + this.getLangManager().loadEnum(GenerationType.class); this.getLang().saveChanges(); } @Override public void registerHooks() { + initialIntegrations(); + } + + private void initialIntegrations() { if (EngineUtils.hasPlugin("HolographicDisplays")) { this.hologramHandler = new HologramDisplaysHandler(this); this.hologramHandler.setup(); @@ -195,26 +206,6 @@ public void registerPermissions() { this.registerPermissions(Perms.class); } - @NotNull - public DungeonManager getDungeonManager() { - return dungeonManager; - } - - @NotNull - public KeyManager getKeyManager() { - return keyManager; - } - - @NotNull - public MobManager getMobManager() { - return mobManager; - } - - @NotNull - public AnnounceManager getAnnounceManager() { - return announceManager; - } - @NotNull public EditorMainMenu getEditor() { if (this.editor == null) { @@ -223,31 +214,6 @@ public EditorMainMenu getEditor() { return this.editor; } - @NotNull - public SessionConsole getSessionConsole() { - return sessionConsole; - } - - @Nullable - public HologramHandler getHologramHandler() { - return hologramHandler; - } - - @Nullable - public SchematicHandler getSchematicHandler() { - return schematicHandler; - } - - @Nullable - public RegionHandler getRegionHandler() { - return regionHandler; - } - - @Nullable - public PartyHandler getPartyHandler() { - return partyHandler; - } - public void sendDebug(@NotNull String text) { if (Config.DEBUG.get()) this.debug(text); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/Keys.java b/src/main/java/t/me/p1azmer/plugin/dungeons/Keys.java index d7cc115..245bbf6 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/Keys.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/Keys.java @@ -8,4 +8,5 @@ public class Keys { public static final NamespacedKey ENTITY_MOB_ID = new NamespacedKey(DungeonAPI.PLUGIN, "entity.mob_id"); public static final NamespacedKey ENTITY_MOB_LEVEL = new NamespacedKey(DungeonAPI.PLUGIN, "entity.mob_level"); + public static final NamespacedKey ENTITY_MOB_DUNGEON_ID = new NamespacedKey(DungeonAPI.PLUGIN, "entity.dungeon_id"); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/Perms.java b/src/main/java/t/me/p1azmer/plugin/dungeons/Perms.java index 049f85d..a64a52c 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/Perms.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/Perms.java @@ -3,20 +3,50 @@ import t.me.p1azmer.engine.api.server.JPermission; public class Perms { - private static final String PREFIX = "dungeons."; + private static final String PREFIX = "dungeons."; private static final String PREFIX_COMMAND = PREFIX + "command."; - public static final JPermission PLUGIN = new JPermission(PREFIX + Placeholders.WILDCARD, "Access to all the plugin functions."); - public static final JPermission COMMAND = new JPermission(PREFIX_COMMAND + Placeholders.WILDCARD, "Access to all the plugin commands."); + public static final JPermission PLUGIN = new JPermission( + PREFIX + Placeholders.WILDCARD, + "Access to all the plugin functions." + ); + public static final JPermission COMMAND = new JPermission( + PREFIX_COMMAND + Placeholders.WILDCARD, + "Access to all the plugin commands." + ); - public static final JPermission COMMAND_RELOAD = new JPermission(PREFIX_COMMAND + "reload", "Access to the 'reload' sub-command."); - public static final JPermission COMMAND_EDITOR = new JPermission(PREFIX_COMMAND + "editor", "Access to the 'editor' sub-command."); - public static final JPermission COMMAND_DROP = new JPermission(PREFIX_COMMAND + "drop", "Access to the 'drop' sub-command."); - public static final JPermission COMMAND_DESPAWN = new JPermission(PREFIX_COMMAND + "despawn", "Access to the 'despawn' sub-command."); - public static final JPermission COMMAND_KEY = new JPermission(PREFIX_COMMAND + "key", "Access to the 'key' sub-command (without sub-commands)."); - public static final JPermission COMMAND_KEY_GIVE = new JPermission(PREFIX_COMMAND + "key.give", "Access to the 'key give' command."); - public static final JPermission COMMAND_KEY_TAKE = new JPermission(PREFIX_COMMAND + "key.take", "Access to the 'key take' command."); - public static final JPermission COMMAND_KEY_SET = new JPermission(PREFIX_COMMAND + "key.set", "Access to the 'key set' command."); + public static final JPermission COMMAND_RELOAD = new JPermission( + PREFIX_COMMAND + "reload", + "Access to the 'reload' sub-command." + ); + public static final JPermission COMMAND_EDITOR = new JPermission( + PREFIX_COMMAND + "editor", + "Access to the 'editor' sub-command." + ); + public static final JPermission COMMAND_DROP = new JPermission( + PREFIX_COMMAND + "drop", + "Access to the 'drop' sub-command." + ); + public static final JPermission COMMAND_DESPAWN = new JPermission( + PREFIX_COMMAND + "despawn", + "Access to the 'despawn' sub-command." + ); + public static final JPermission COMMAND_KEY = new JPermission( + PREFIX_COMMAND + "key", + "Access to the 'key' sub-command (without sub-commands)." + ); + public static final JPermission COMMAND_KEY_GIVE = new JPermission( + PREFIX_COMMAND + "key.give", + "Access to the 'key give' command." + ); + public static final JPermission COMMAND_KEY_TAKE = new JPermission( + PREFIX_COMMAND + "key.take", + "Access to the 'key take' command." + ); + public static final JPermission COMMAND_KEY_SET = new JPermission( + PREFIX_COMMAND + "key.set", + "Access to the 'key set' command." + ); static { PLUGIN.addChildren(COMMAND); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/Placeholders.java index 8b08628..7b6468e 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/Placeholders.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/Placeholders.java @@ -1,110 +1,5 @@ package t.me.p1azmer.plugin.dungeons; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; - -import java.util.function.Function; - public class Placeholders extends t.me.p1azmer.engine.utils.Placeholders { - public static final String GENERIC_AMOUNT = "%amount%"; - public static final String GENERIC_TIME = "%time%"; - public static final String GENERIC_HANDLER = "%handler%"; - - public static final String DUNGEON_NAME = "%dungeon_name%"; - public static final String DUNGEON_ID = "%dungeon_id%"; - public static final String DUNGEON_WORLD = "%dungeon_world%"; - public static final String DUNGEON_KEY_IDS = "%dungeon_key_ids%"; - public static final String DUNGEON_KEY_NAMES = "%dungeon_key_names%"; - public static final String DUNGEON_NEXT_STAGE_IN = "%dungeon_next_stage_in%"; - public static final String EDITOR_HOLOGRAM_TEXT = "%dungeon_editor_hologram_text%"; - public static final Function DUNGEON_HOLOGRAM_MESSAGES = var -> "%dungeon_hologram_" + var + "_messages%"; - public static final String DUNGEON_HOLOGRAM_CHEST_OFFSET_Y = "%dungeon_hologram_chest_offset_y%"; - - // schematics - public static final String SCHEMATICS_LIST = "%schematics_list%"; - public static final String SCHEMATICS_IGNORE_AIR = "%schematics_ignore_air%"; - public static final String SCHEMATICS_UNDERGROUND = "%schematics_underground%"; - - // settings - public static final String DUNGEON_SETTINGS_ENABLED = "%dungeon_enabled%"; - public static final String DUNGEON_SETTINGS_MINIMAL_ONLINE = "%dungeon_minimal_online%"; - public static final String DUNGEON_SETTINGS_CLICK_TIMER = "%dungeon_click_timer%"; - public static final String DUNGEON_SETTINGS_BIG_CHEST = "%dungeon_big_chest%"; - public static final String DUNGEON_SETTINGS_CHEST_BLOCK_LIMIT = "%dungeon_chest_block_limit%"; - public static final String DUNGEON_SETTINGS_SEPARATE_CHEST_BLOCK = "%dungeon_separate_chest_block_gui%"; - public static final String DUNGEON_SETTINGS_RANDOM_SLOTS = "%dungeon_random_slots%"; - public static final String DUNGEON_SETTINGS_OPEN_TYPE = "%dungeon_open_type%"; - public static final String DUNGEON_SETTINGS_CHEST_MATERIAL = "%dungeon_chest_block%"; - public static final String DUNGEON_SETTINGS_LET_PLAYERS_WHEN_CLOSE = "%dungeon_let_players_when_close%"; - public static final String DUNGEON_SETTINGS_USE_ONE_KEY_FOR_CHEST = "%dungeon_use_one_key_for_chest%"; - public static final String DUNGEON_SETTINGS_MOBS = "%dungeon_settings_mobs%"; - - // chest states - public static final Function DUNGEON_CHEST_STATE_TIME = var -> "%dungeon_chest_state_" + var + "_time%"; - public static final String DUNGEON_CHEST_STATE_NAME = "%dungeon_state_name%"; - public static final String DUNGEON_CHEST_NEXT_STATE_IN = "%dungeon_chest_next_state_in%"; - public static final String EDITOR_STATE_TIME = "%dungeon_editor_state_time%"; - - // modules - public static final String MODULE_ID = "%module_id%"; - public static final String EDITOR_MODULE_ENABLED = "%editor_module_enabled%"; - - // stages - public static final String EDITOR_STAGE_COMMANDS = "%dungeon_editor_stage_commands%"; - public static final String EDITOR_STAGE_ANNOUNCES = "%dungeon_editor_stage_announces%"; - public static final String EDITOR_STAGE_TIME = "%dungeon_editor_stage_time%"; - public static final String EDITOR_STAGE_NAME = "%dungeon_editor_stage_name%"; - - // key - public static final String KEY_ID = "%key_id%"; - public static final String KEY_NAME = "%key_name%"; - public static final String KEY_ITEM_NAME = "%key_item_name%"; - - - // reward - public static final String REWARD_ID = "%reward_id%"; - public static final String REWARD_CHANCE = "%reward_chance%"; - public static final String REWARD_MAX_AMOUNT = "%reward_amount_max%"; - public static final String REWARD_MIN_AMOUNT = "%reward_amount_min%"; - public static final String REWARD_LIMIT_MAX = "%reward_limit_max%"; - public static final String REWARD_LIMIT_MIN = "%reward_limit_min%"; - public static final String REWARD_COMMANDS = "%reward_commands%"; - - - // region - public static final String REGION_ENABLED = "%region_enabled%"; - public static final String REGION_NAME = "%region_name%"; - public static final String REGION_RADIUS = "%region_radius%"; - public static final String REGION_FLAGS = "%region_flags%"; - - - // effect - public static final String EFFECT_NAME = "%effect_name%"; - public static final String EFFECT_DURATION = "%effect_duration%"; - public static final String EFFECT_AMPLIFIER = "%effect_amplifier%"; - - // mobs - public static final String MOB_ID = "%mob_id%"; - public static final String MOB_NAME = "%mob_name%"; - public static final String MOB_NAME_VISIBLE = "%mob_name_visible%"; - public static final String MOB_ENTITY_TYPE = "%mob_entity_type%"; - public static final String MOB_ATTRIBUTES_BASE = "%mob_attributes_base%"; - public static final String MOB_SPAWN_CHANCE = "%mob_spawn_chance%"; - public static final String MOB_ENABLED_SPAWN = "%mob_spawn_enabled%"; - public static final String MOB_SILENT = "%mob_silent%"; - public static final String MOB_RIDER_ID = "%mob_rider_id%"; - - public static final String MOB_POTION_EFFECT_VALUE = "%mob_potion_effect_value%"; - public static final String MOB_POTION_EFFECT_DURATION = "%mob_potion_effect_duration%"; - public static final String MOB_STYLE_TYPE = "%mob_style_type%"; - public static final String MOB_STYLE_VALUE = "%mob_style_value%"; - - // party - public static final String PARTY_ENABLED = "%party_enabled%"; - public static final String PARTY_SIZE = "%party_size%"; - - // announce - public static final String ANNOUNCE_ID = "%announce_id%"; - public static final String ANNOUNCE_MESSAGES = "%announce_messages%"; - public static final String ANNOUNCE_GLOBAL = "%announce_global%"; } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/announce/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/announce/Placeholders.java new file mode 100644 index 0000000..c688138 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/announce/Placeholders.java @@ -0,0 +1,7 @@ +package t.me.p1azmer.plugin.dungeons.announce; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.Placeholders { + public static final String ANNOUNCE_ID = "%announce_id%"; + public static final String ANNOUNCE_MESSAGES = "%announce_messages%"; + public static final String ANNOUNCE_GLOBAL = "%announce_global%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/announce/editor/AnnounceMainEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/announce/editor/AnnounceMainEditor.java index e9d8b61..2c2d6be 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/announce/editor/AnnounceMainEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/announce/editor/AnnounceMainEditor.java @@ -6,6 +6,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import t.me.p1azmer.engine.api.lang.LangMessage; import t.me.p1azmer.engine.api.menu.impl.EditorMenu; import t.me.p1azmer.engine.api.menu.impl.MenuViewer; import t.me.p1azmer.engine.utils.ItemReplacer; @@ -16,23 +17,20 @@ import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; -import java.util.List; - public class AnnounceMainEditor extends EditorMenu { public AnnounceMainEditor(@NotNull Announce announce) { super(announce.plugin(), announce, Config.EDITOR_TITLE_ANNOUNCE.get(), 9); this.addReturn(8).setClick((viewer, event) -> { - this.plugin.runTask(task -> announce.manager().getEditor().open(viewer.getPlayer(), 1)); + this.plugin.runTask(task -> announce.getManager().getEditor().open(viewer.getPlayer(), 1)); }); this.addItem(Material.COMPARATOR, EditorLocales.ANNOUNCE_MESSAGES, 0).setClick((viewer, event) -> { this.handleInput(viewer, Lang.EDITOR_REWARD_ENTER_CHANCE, wrapper -> { String text = wrapper.getText(); - List messages = announce.getMessagesRaw(); - messages.add(text); - announce.setMessages(messages); + LangMessage messages = announce.getMessage(); + announce.setMessage(new LangMessage(plugin(), messages.getRaw() + "\n" + text)); this.save(viewer); return true; }); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/announce/impl/Announce.java b/src/main/java/t/me/p1azmer/plugin/dungeons/announce/impl/Announce.java index 455edc7..86a7d27 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/announce/impl/Announce.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/announce/impl/Announce.java @@ -1,5 +1,7 @@ package t.me.p1azmer.plugin.dungeons.announce.impl; +import lombok.Getter; +import lombok.Setter; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; @@ -11,17 +13,16 @@ import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.announce.AnnounceManager; +import t.me.p1azmer.plugin.dungeons.announce.Placeholders; import t.me.p1azmer.plugin.dungeons.announce.editor.AnnounceMainEditor; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - +@Getter +@Setter public class Announce extends AbstractConfigHolder implements IPlaceholderMap { + private static final ItemStack defaultIcon = ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2I0MTk5NmZkMjBjYTIxZDc5YWRmYzBlMTIwNTdiMmYyY2VhZGY3YjNjZjViYjVmOGE5MmZlMzQ2MDE2MWFjZCJ9fX0="); private ItemStack icon; - private List messages; + private LangMessage message; private boolean global; private final PlaceholderMap placeholderMap; @@ -32,12 +33,12 @@ public Announce(@NotNull AnnounceManager manager, @NotNull JYML cfg) { super(manager.plugin(), cfg); this.manager = manager; - this.messages = new ArrayList<>(); - this.icon = ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2I0MTk5NmZkMjBjYTIxZDc5YWRmYzBlMTIwNTdiMmYyY2VhZGY3YjNjZjViYjVmOGE5MmZlMzQ2MDE2MWFjZCJ9fX0="); + this.message = new LangMessage(plugin(), ""); + this.icon = defaultIcon; this.placeholderMap = new PlaceholderMap() .add(Placeholders.ANNOUNCE_ID, this::getId) - .add(Placeholders.ANNOUNCE_MESSAGES, () -> Colorizer.apply(String.join("\n", this.getMessagesRaw()))) + .add(Placeholders.ANNOUNCE_MESSAGES, () -> Colorizer.apply(String.join("\n", this.getMessage().normalizeLines()))) .add(Placeholders.ANNOUNCE_GLOBAL, () -> LangManager.getBoolean(this.isGlobal())) ; } @@ -45,10 +46,10 @@ public Announce(@NotNull AnnounceManager manager, @NotNull JYML cfg) { @Override public boolean load() { ItemStack item = this.cfg.getItemEncoded("Icon"); - if (item == null) - item = ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2I0MTk5NmZkMjBjYTIxZDc5YWRmYzBlMTIwNTdiMmYyY2VhZGY3YjNjZjViYjVmOGE5MmZlMzQ2MDE2MWFjZCJ9fX0="); + if (item == null) item = defaultIcon; + this.setIcon(item); - this.setMessages(this.cfg.getStringList("Messages")); + this.setMessage(new LangMessage(plugin(), String.join("\n", this.cfg.getStringList("Messages")))); this.setGlobal(this.cfg.getBoolean("Global")); return true; } @@ -56,23 +57,10 @@ public boolean load() { @Override protected void onSave() { this.cfg.setItemEncoded("Icon", this.getIcon()); - this.cfg.set("Messages", this.getMessagesRaw()); + this.cfg.set("Messages", this.getMessage().asList()); this.cfg.set("Global", this.isGlobal()); } -// public static Announce read(@NotNull DungeonPlugin plugin, @NotNull JYML cfg, @NotNull String path) { -// List messages = cfg.getStringList(path + ".Messages").stream().map(message -> new LangMessage(plugin, message)).collect(Collectors.toList()); -// boolean global = cfg.getBoolean(path + ".Global"); -// int[] times = cfg.getIntArray(path + ".Times"); -// return new Announce(messages, global, times); -// } -// -// public void write(@NotNull JYML cfg, @NotNull String path) { -// cfg.set(path + ".Messages", this.getMessagesRaw()); -// cfg.set(path + ".Global", this.isGlobal()); -// cfg.setIntArray(path + ".Times", this.getTimes()); -// } - public void clear() { if (this.editor != null) { this.editor.clear(); @@ -94,43 +82,12 @@ public ItemStack getIcon() { } @NotNull - public List getMessagesRaw() { - return messages.stream().map(LangMessage::getRaw).collect(Collectors.toList()); - } - - @NotNull - public List getMessages() { - return messages; - } - - public boolean isGlobal() { - return global; - } - - @NotNull - public List getMessage() { - return getMessages(); + public LangMessage getMessageWithoutPrefix(){ + return new LangMessage(plugin(), "" + this.getMessage().getRaw()); } @Override public @NotNull PlaceholderMap getPlaceholders() { return this.placeholderMap; } - - @NotNull - public AnnounceManager manager() { - return this.manager; - } - - public void setIcon(@NotNull ItemStack icon) { - this.icon = icon; - } - - public void setMessages(@NotNull List messages) { - this.messages = new ArrayList<>(messages).stream().map(message -> new LangMessage(plugin, message)).collect(Collectors.toList()); - } - - public void setGlobal(boolean global) { - this.global = global; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonChangeStageEvent.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonChangeStageEvent.java index b69cb92..01e3bd7 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonChangeStageEvent.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonChangeStageEvent.java @@ -1,27 +1,24 @@ package t.me.p1azmer.plugin.dungeons.api.events; +import lombok.Getter; +import lombok.Setter; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; +@Getter +@Setter public class DungeonChangeStageEvent extends DungeonEvent{ private static final HandlerList handlerList = new HandlerList(); - private DungeonStage dungeonStage; + private DungeonStage stage; + private String changeFrom; - public DungeonChangeStageEvent(@NotNull Dungeon dungeon, @NotNull DungeonStage stage) { - super(dungeon); - this.dungeonStage = stage; - } - - @NotNull - public DungeonStage getDungeonStage() { - return dungeonStage; - } - - public void setDungeonStage(@NotNull DungeonStage dungeonStage) { - this.dungeonStage = dungeonStage; + public DungeonChangeStageEvent(@NotNull Dungeon dungeon, @NotNull DungeonStage stage, @NotNull String changeFrom) { + super(dungeon, true); + this.stage = stage; + this.changeFrom = changeFrom; } @NotNull diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonDeleteEvent.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonDespawnEvent.java similarity index 76% rename from src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonDeleteEvent.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonDespawnEvent.java index 9bbf664..5892363 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonDeleteEvent.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonDespawnEvent.java @@ -4,11 +4,11 @@ import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -public class DungeonDeleteEvent extends DungeonEvent{ +public class DungeonDespawnEvent extends DungeonEvent{ private static final HandlerList handlerList = new HandlerList(); - public DungeonDeleteEvent(@NotNull Dungeon dungeon) { - super(dungeon); + public DungeonDespawnEvent(@NotNull Dungeon dungeon) { + super(dungeon, true); } @NotNull diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonEvent.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonEvent.java index 833e802..4b82202 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonEvent.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonEvent.java @@ -12,6 +12,11 @@ public abstract class DungeonEvent extends Event implements Cancellable { public DungeonEvent(@NotNull Dungeon dungeon){ + super(false); + this.dungeon = dungeon; + } + public DungeonEvent(@NotNull Dungeon dungeon, boolean async){ + super(async); this.dungeon = dungeon; } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonSpawnEvent.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonSpawnEvent.java index 4595c4b..aa69a56 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonSpawnEvent.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/events/DungeonSpawnEvent.java @@ -10,7 +10,7 @@ public class DungeonSpawnEvent extends DungeonEvent{ private Location location; public DungeonSpawnEvent(@NotNull Dungeon dungeon, @NotNull Location location) { - super(dungeon); + super(dungeon, true); this.location = location; } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/hologram/HologramHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/hologram/HologramHandler.java similarity index 58% rename from src/main/java/t/me/p1azmer/plugin/dungeons/api/hologram/HologramHandler.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/hologram/HologramHandler.java index bb14a86..d9539ed 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/hologram/HologramHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/hologram/HologramHandler.java @@ -1,17 +1,17 @@ -package t.me.p1azmer.plugin.dungeons.api.hologram; +package t.me.p1azmer.plugin.dungeons.api.handler.hologram; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.manager.Loadable; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestBlock; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; public interface HologramHandler extends Loadable { - void create(@NotNull Dungeon dungeon, @Nullable ChestModule module); + void create(@NotNull Dungeon dungeon, @NotNull ChestModule module); void delete(@NotNull Dungeon dungeon); - void update(@NotNull DungeonChestBlock dungeonChestBlock); + void update(@NotNull ChestBlock chestBlock); } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/party/PartyHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/party/PartyHandler.java similarity index 82% rename from src/main/java/t/me/p1azmer/plugin/dungeons/api/party/PartyHandler.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/party/PartyHandler.java index a3877c1..c071337 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/party/PartyHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/party/PartyHandler.java @@ -1,4 +1,4 @@ -package t.me.p1azmer.plugin.dungeons.api.party; +package t.me.p1azmer.plugin.dungeons.api.handler.party; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/region/RegionHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/region/RegionHandler.java similarity index 79% rename from src/main/java/t/me/p1azmer/plugin/dungeons/api/region/RegionHandler.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/region/RegionHandler.java index d3e4b5f..ce3e24a 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/region/RegionHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/region/RegionHandler.java @@ -1,10 +1,10 @@ -package t.me.p1azmer.plugin.dungeons.api.region; +package t.me.p1azmer.plugin.dungeons.api.handler.region; import org.bukkit.Location; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.manager.Loadable; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; public interface RegionHandler extends Loadable { diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/schematic/SchematicHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/schematic/SchematicHandler.java similarity index 69% rename from src/main/java/t/me/p1azmer/plugin/dungeons/api/schematic/SchematicHandler.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/schematic/SchematicHandler.java index 6a2a67b..01589ae 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/schematic/SchematicHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/handler/schematic/SchematicHandler.java @@ -1,13 +1,14 @@ -package t.me.p1azmer.plugin.dungeons.api.schematic; +package t.me.p1azmer.plugin.dungeons.api.handler.schematic; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.manager.Loadable; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import java.io.File; +import java.util.concurrent.CompletableFuture; public interface SchematicHandler extends Loadable { - boolean paste(@NotNull Dungeon dungeon, @NotNull File schematicFile); + CompletableFuture paste(@NotNull Dungeon dungeon, @NotNull File schematicFile); boolean undo(@NotNull Dungeon dungeon); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/mob/MobFaction.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/mob/MobFaction.java index 4b09cee..bc0ef0e 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/mob/MobFaction.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/mob/MobFaction.java @@ -1,5 +1,6 @@ package t.me.p1azmer.plugin.dungeons.api.mob; public enum MobFaction { - ENEMY, ALLY//, NEUTRAL + ENEMY, + ALLY } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/api/settings/AbstractSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/api/settings/AbstractSettings.java index 950d5cd..8850251 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/api/settings/AbstractSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/api/settings/AbstractSettings.java @@ -1,11 +1,14 @@ package t.me.p1azmer.plugin.dungeons.api.settings; import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; +import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -public abstract class AbstractSettings { +public abstract class AbstractSettings implements IPlaceholderMap { protected Dungeon dungeon; + protected PlaceholderMap placeholderMap; public AbstractSettings(@NotNull Dungeon dungeon) { this.dungeon = dungeon; @@ -19,4 +22,9 @@ public Dungeon dungeon() { public DungeonPlugin plugin(){ return this.dungeon().plugin(); } + + @Override + public @NotNull PlaceholderMap getPlaceholders() { + return this.placeholderMap; + } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/DeleteCommand.java b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/DeleteCommand.java index 14666a0..e0ce207 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/DeleteCommand.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/DeleteCommand.java @@ -8,13 +8,14 @@ import t.me.p1azmer.engine.utils.Constants; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.Perms; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.SpawnModule; import t.me.p1azmer.plugin.dungeons.lang.Lang; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; public class DeleteCommand extends AbstractCommand { @@ -41,17 +42,25 @@ protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult r this.printUsage(sender); return; } + DungeonManager dungeonManager = plugin.getDungeonManager(); if (result.getArg(1).equalsIgnoreCase(Constants.MASK_ANY)) { - plugin.getDungeonManager().getDungeons().stream().filter(dungeon -> dungeon.getModuleManager().getModule(SpawnModule.class).isPresent() && dungeon.getModuleManager().getModule(SpawnModule.class).get().isSpawned()).forEach(f -> f.cancel(false)); - plugin.getMessage(Lang.COMMAND_DEL_DONE).replace(Placeholders.DUNGEON_NAME, Constants.MASK_ANY).send(sender); + dungeonManager.getDungeons() + .forEach(f -> f.cancel(false)); + plugin.getMessage(Lang.COMMAND_DEL_DONE) + .replace(Placeholders.DUNGEON_NAME, Constants.MASK_ANY) + .send(sender); return; } - Dungeon dungeon = plugin.getDungeonManager().getDungeonById(result.getArg(1)); + Dungeon dungeon = dungeonManager.getDungeonById(result.getArg(1)); if (dungeon == null) { - plugin.getMessage(Lang.DUNGEON_ERROR_INVALID).send(sender); + plugin.getMessage(Lang.DUNGEON_ERROR_INVALID) + .send(sender); return; } - plugin.getMessage(Lang.COMMAND_DEL_DONE).replace(dungeon.replacePlaceholders()).send(sender); + CompletableFuture.runAsync(() -> dungeon.cancel(false)); + plugin.getMessage(Lang.COMMAND_DEL_DONE) + .replace(dungeon.replacePlaceholders()) + .send(sender); } } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/SpawnCommand.java b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/SpawnCommand.java index 6f39ba7..2804339 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/SpawnCommand.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/dungeon/SpawnCommand.java @@ -10,7 +10,9 @@ import t.me.p1azmer.engine.utils.CollectionsUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.Perms; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.commands.CommandFlags; +import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -24,6 +26,7 @@ public SpawnCommand(@NotNull DungeonPlugin plugin) { this.setDescription(plugin.getMessage(Lang.COMMAND_DROP_DESC)); this.setUsage(plugin.getMessage(Lang.COMMAND_DROP_USAGE)); this.setPlayerOnly(false); + this.addFlag(CommandFlags.RANDOM); } @Override @@ -54,36 +57,20 @@ protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult r return; } - Dungeon dungeon = plugin.getDungeonManager().getDungeonById(result.getArg(1)); + DungeonManager dungeonManager = plugin.getDungeonManager(); + Dungeon dungeon = dungeonManager.getDungeonById(result.getArg(1)); if (dungeon == null) { - plugin.getMessage(Lang.DUNGEON_ERROR_INVALID).send(sender); + plugin.getMessage(Lang.DUNGEON_ERROR_INVALID) + .send(sender); return; } World world = plugin.getServer().getWorld(result.getArg(2)); if (world == null) { - plugin.getMessage(Lang.ERROR_WORLD_INVALID).send(sender); + plugin.getMessage(Lang.ERROR_WORLD_INVALID) + .send(sender); return; } -// if (result.hasFlag(RANDOM)) { -// DungeonStage.call(dungeon, DungeonStage.PREPARE, "spawn command"); -// plugin.runTaskLater(task -> { -// if (!plugin.getDungeonManager().spawnDungeon(dungeon)) { -// plugin.getMessage(Lang.ERROR_RANDOM_SPAWN).send(sender); -// return; -// } -// if (dungeon.getLocation() == null) { -// plugin.getMessage(Lang.ERROR_DUNGEON_LOCATION_IS_EMPTY).send(sender); -// return; -// } -// -// plugin.getMessage(Lang.COMMAND_DROP_DONE) -// .replace(dungeon.replacePlaceholders()) -// .replace(Placeholders.forLocation(dungeon.getLocation())) -// .send(sender); -// }, 40); -// return; -// } if (result.length() != 6) { this.printUsage(sender); @@ -95,7 +82,7 @@ protected void onExecute(@NotNull CommandSender sender, @NotNull CommandResult r double z = result.getDouble(5, 0); Location location = new Location(world, x, y, z); - if (!plugin.getDungeonManager().spawnDungeon(dungeon, location)) { + if (!dungeonManager.spawnDungeon(dungeon, location)) { plugin.getMessage(Lang.COMMAND_DROP_ERROR) .replace(dungeon.replacePlaceholders()) .send(sender); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/GiveAllCommand.java b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/GiveAllCommand.java index 40c139f..76ad8e1 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/GiveAllCommand.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/GiveAllCommand.java @@ -7,8 +7,8 @@ import t.me.p1azmer.engine.api.command.CommandResult; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.Perms; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.commands.CommandFlags; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.key.Key; import t.me.p1azmer.plugin.dungeons.lang.Lang; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/ManageCommand.java b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/ManageCommand.java index 7b9588f..567cf60 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/ManageCommand.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/commands/key/ManageCommand.java @@ -10,8 +10,8 @@ import t.me.p1azmer.engine.api.lang.LangMessage; import t.me.p1azmer.engine.utils.CollectionsUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.commands.CommandFlags; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.key.Key; import t.me.p1azmer.plugin.dungeons.lang.Lang; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/config/Config.java b/src/main/java/t/me/p1azmer/plugin/dungeons/config/Config.java index 91a42cc..f21e4dd 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/config/Config.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/config/Config.java @@ -9,18 +9,55 @@ public class Config { public static final String DIR_KEYS = "/keys/"; public static final String DIR_SCHEMATICS = "/schematics/"; - public static final JOption DUNGEON_HOLD_KEY_TO_OPEN = JOption.create("Settings.Dungeon.Hold_Key_To_Open", false, "Sets whether players need to hold the key in their main hand to open the dungeon."); - public static final JOption EDITOR_TITLE_ANNOUNCE = JOption.create("Editor.Title.Announce", "Announce Editor", "Title of the announce editor menu") + public static final JOption DUNGEON_HOLD_KEY_TO_OPEN = JOption.create( + "Settings.Dungeon.Hold_Key_To_Open", + false, + "Sets whether players need to hold the key in their main hand to open the dungeon." + ); + public static final JOption EDITOR_TITLE_ANNOUNCE = JOption.create( + "Editor.Title.Announce", + "Announce Editor", + "Title of the announce editor menu" + ) .mapReader(Colorizer::apply); - public static final JOption EDITOR_TITLE_DUNGEON = JOption.create("Editor.Title.Dungeon", "Dungeon Settings", "Title of the dungeon editor menu") + public static final JOption EDITOR_TITLE_DUNGEON = JOption.create( + "Editor.Title.Dungeon", + "Dungeon Settings", + "Title of the dungeon editor menu" + ) .mapReader(Colorizer::apply); - public static final JOption EDITOR_TITLE_MOB = JOption.create("Editor.Title.Mob", "Mobs Settings", "Title of the mobs editor menu") + public static final JOption EDITOR_TITLE_MOB = JOption.create( + "Editor.Title.Mob", + "Mobs Settings", + "Title of the mobs editor menu" + ) .mapReader(Colorizer::apply); - public static final JOption EDITOR_TITLE_KEY = JOption.create("Editor.Title.Key", "Key Settings", "Title of the key editor menu") + public static final JOption EDITOR_TITLE_KEY = JOption.create( + "Editor.Title.Key", + "Key Settings", + "Title of the key editor menu" + ) .mapReader(Colorizer::apply); - public static final JOption DEBUG = JOption.create("Settings.Debug.Other", false, "Enables plugin debugging"); - public static final JOption DEBUG_TICK = JOption.create("Settings.Debug.Tick", false, "Enables dungeon tick debugging"); - public static final JOption DEBUG_TICK_CHEST = JOption.create("Settings.Debug.Tick_Chest", false, "Enables dungeon chest tick debugging"); + public static final JOption DEBUG = JOption.create( + "Settings.Debug.Other", + false, + "Enables plugin debugging" + ); + public static final JOption TICK_DEBUG = JOption.create( + "Settings.Debug.Tick", + false, + "Enables dungeon tick debugging" + ); + public static final JOption TICK_CHEST_DEBUG = JOption.create( + "Settings.Debug.Tick_Chest", + false, + "Enables dungeon chest tick debugging" + ); + public static final JOption MODULE_DEBUG = JOption.create( + "Settings.Debug.Module", + false, + "Enables module debugging" + ); } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/DungeonManager.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/DungeonManager.java index bbd2426..137a409 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/DungeonManager.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/DungeonManager.java @@ -11,22 +11,29 @@ import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.Keys; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.listener.DungeonListener; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleManager; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.SpawnModule; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.SchematicSettings; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import t.me.p1azmer.plugin.dungeons.generator.config.GeneratorConfig; import t.me.p1azmer.plugin.dungeons.integration.region.RegionHandlerWG; import t.me.p1azmer.plugin.dungeons.task.DungeonTickTask; +import t.me.p1azmer.plugin.dungeons.utils.Cuboid; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; public class DungeonManager extends AbstractManager { - private Map dungeonMap; + private final Map dungeonMap = new ConcurrentHashMap<>(); private DungeonTickTask dungeonTickTask; public DungeonManager(@NotNull DungeonPlugin plugin) { @@ -35,20 +42,23 @@ public DungeonManager(@NotNull DungeonPlugin plugin) { @Override protected void onLoad() { - this.dungeonMap = new HashMap<>(); this.plugin.getConfig().initializeOptions(GeneratorConfig.class); this.plugin.getConfigManager().extractResources(Config.DIR_DUNGEONS); + RegionHandler regionHandler = plugin.getRegionHandler(); + for (JYML cfg : JYML.loadAll(plugin.getDataFolder() + Config.DIR_DUNGEONS, true)) { Dungeon dungeon = new Dungeon(this, cfg); if (dungeon.load()) { this.dungeonMap.put(dungeon.getId(), dungeon); - if (plugin.getRegionHandler() != null && plugin.getRegionHandler().getClass().equals(RegionHandlerWG.class)) { - if (dungeon.getSchematicSettings().isUnderground() && dungeon.getDungeonRegion().isEnabled() && !dungeon.getDungeonRegion().getFlags().contains("build")) { + if (regionHandler != null && regionHandler.getClass().equals(RegionHandlerWG.class)) { + SchematicSettings schematicSettings = dungeon.getSchematicSettings(); + Region dungeonRegion = dungeon.getRegion(); + + if (schematicSettings.isUnderground() && dungeonRegion.isEnabled() && !dungeonRegion.getFlags().contains("build")) { plugin.error("Please note that the dungeon '" + dungeon.getId() + "' is set to be underground, but its region does not have building rights!"); } } - // setup managers dungeon.getModuleManager().setup(); } else this.plugin.error("Dungeon not loaded: '" + cfg.getFile().getName() + "'."); } @@ -62,16 +72,13 @@ protected void onLoad() { @Override protected void onShutdown() { - if (this.dungeonMap != null) { - this.dungeonMap.values().forEach(dungeon -> { - dungeon.clear(); - if (dungeon.getModuleManager() != null) { - dungeon.getModuleManager().shutdown(); - dungeon.setModuleManager(null); - } - }); - this.dungeonMap = null; - } + this.dungeonMap.values().forEach(dungeon -> { + dungeon.clear(); + ModuleManager moduleManager = dungeon.getModuleManager(); + moduleManager.shutdown(); + dungeon.setModuleManager(null); + }); + this.dungeonMap.clear(); if (this.dungeonTickTask != null) { this.dungeonTickTask.stop(); this.dungeonTickTask = null; @@ -87,7 +94,11 @@ public boolean create(@NotNull String id) { JYML cfg = new JYML(this.plugin.getDataFolder() + Config.DIR_DUNGEONS, id + ".yml"); Dungeon dungeon = new Dungeon(this, cfg); dungeon.setName("&a&l" + StringUtil.capitalizeUnderscored(dungeon.getId()) + " Dungeon"); - dungeon.setWorld(plugin.getServer().getWorlds().stream().filter(f -> f.getEnvironment().equals(World.Environment.NORMAL)).findFirst().orElseThrow()); + dungeon.setWorld(plugin.getServer().getWorlds() + .stream() + .filter(f -> f.getEnvironment().equals(World.Environment.NORMAL)) + .findFirst() + .orElseThrow()); dungeon.save(); dungeon.load(); @@ -106,7 +117,11 @@ public boolean delete(@NotNull Dungeon dungeon) { @NotNull public List getDungeonIds(boolean keyOnly) { - return this.getDungeons().stream().filter(crate -> !crate.getKeyIds().isEmpty() || !keyOnly).map(Dungeon::getId).toList(); + return this.getDungeons() + .stream() + .filter(crate -> !crate.getKeyIds().isEmpty() || !keyOnly) + .map(Dungeon::getId) + .toList(); } @NotNull @@ -131,49 +146,68 @@ public Dungeon getDungeonByBlock(@NotNull Block block) { @Nullable public Dungeon getDungeonByLocation(@NotNull Location location, @NotNull Block block) { - return this.getDungeons().stream().filter(dungeon -> { - ChestModule module = dungeon.getModuleManager().getModule(ChestModule.class).orElse(null); - Block dungeonBlock = module != null ? module.getBlock(location) : null; - - return (dungeon.getDungeonCuboid() != null && dungeon.getDungeonCuboid().contains(location)) - || (dungeonBlock != null - && (dungeonBlock.hasMetadata(dungeon.getId()) - || dungeonBlock.equals(block) - || dungeonBlock.getLocation().equals(location) - || dungeonBlock.getLocation().distance(location) <= 1D)) - || (plugin.getRegionHandler() != null && dungeon.getDungeonRegion().isEnabled() - && plugin.getRegionHandler().isDungeonRegion(location, dungeon.getDungeonRegion())); - }).findFirst().orElse(null); + return this.getDungeons() + .stream() + .filter(dungeon -> { + ModuleManager moduleManager = dungeon.getModuleManager(); + ChestModule module = moduleManager.getModule(ChestModule.class).orElse(null); + Block dungeonBlock = module != null ? module.getBlock(location).orElse(null) : null; + + Cuboid dungeonCuboid = dungeon.getDungeonCuboid().orElse(null); + RegionHandler regionHandler = plugin.getRegionHandler(); + Region dungeonRegion = dungeon.getRegion(); + + return (dungeonCuboid != null && dungeonCuboid.contains(location)) + || (dungeonBlock != null + && (dungeonBlock.hasMetadata(dungeon.getId()) + || dungeonBlock.equals(block) + || dungeonBlock.getLocation().equals(location) + || dungeonBlock.getLocation().distance(location) <= 1D)) + || (regionHandler != null && dungeonRegion.isEnabled() + && regionHandler.isDungeonRegion(location, dungeonRegion)); + }) + .findFirst() + .orElse(null); } @NotNull public List getActiveDungeons() { - return this.getDungeons().stream() - .filter(dungeon -> dungeon.getModuleManager().getModule(SpawnModule.class).isPresent() && dungeon.getModuleManager().getModule(SpawnModule.class).get().isSpawned() && !dungeon.getStage().isCancelled() || !dungeon.getStage().isRebooted() || !dungeon.getStage().isFreeze()) + return this.getDungeons() + .stream() + .filter(dungeon -> { + Optional spawnModule = dungeon.getModuleManager().getModule(SpawnModule.class); + DungeonStage dungeonStage = dungeon.getStage(); + return spawnModule.isPresent() && spawnModule.get().isSpawned() && !dungeonStage.isCancelled() || !dungeonStage.isRebooted() || !dungeonStage.isFreeze(); + }) .collect(Collectors.toList()); } @Nullable public Dungeon getNearestDungeon() { - return this.getDungeonMap().values() - .stream(). - filter(f -> !f.getStage().isFreeze() && !f.getStage().isCancelled() && !f.getStage().isClosed()).min(Comparator.comparingInt(Dungeon::getNextStageTime)) + return this.getDungeonMap() + .values() + .stream() + .filter(f -> !f.getStage().isFreeze() && !f.getStage().isCancelled() && !f.getStage().isClosed()).min(Comparator.comparingInt(Dungeon::getNextStageTime)) .orElse(null); } public boolean spawnDungeon(@NotNull Dungeon dungeon, @NotNull Location location) { - SpawnModule module = dungeon.getModuleManager().getModule(SpawnModule.class).orElse(null); + ModuleManager moduleManager = dungeon.getModuleManager(); + SpawnModule module = moduleManager.getModule(SpawnModule.class).orElse(null); + if (module == null) { - plugin.error("Error spawning dungeon via command, because the dungeon spawning module is disabled or not loaded!"); + plugin.error("Error spawning dungeon '" + dungeon.getId() + "' via command, because the dungeon spawning module is disabled or not loaded!"); return false; } - dungeon.cancel(false); - plugin.runTaskLater(task -> { + + CompletableFuture.runAsync(()->{ + dungeon.cancel(false); dungeon.setLocation(location); module.spawn(location); - dungeon.getModuleManager().getModules().forEach(founder -> founder.activate(true)); - DungeonStage.call(dungeon, DungeonStage.OPENED, "Dungeon Manager with location"); - }, 5); + DungeonStage.call(dungeon, DungeonStage.OPENED, "Dungeon Manager via command"); + + moduleManager.getModules().forEach(founder -> founder.tryActive(AbstractModule.ActionType.FORCE)); + }); return true; } @@ -183,10 +217,9 @@ public void interactDungeon(@NotNull Player player, @NotNull Dungeon dungeon, @N } public void openDungeonChest(@NotNull Dungeon dungeon, @NotNull Block block, @NotNull Player player) { - dungeon.getModuleManager().getModule(ChestModule.class).ifPresent(module -> { - DungeonChestBlock chest = module.getChestByBlock(block); - if (chest != null) chest.click(player); - - }); + ModuleManager moduleManager = dungeon.getModuleManager(); + moduleManager.getModule(ChestModule.class) + .flatMap(module -> module.getChestByBlock(block)) + .ifPresent(chest -> chest.click(player)); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/Placeholders.java new file mode 100644 index 0000000..56e3fcf --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/Placeholders.java @@ -0,0 +1,27 @@ +package t.me.p1azmer.plugin.dungeons.dungeon; + +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; + +import java.util.function.Function; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.Placeholders { + + public static final String DUNGEON_NAME = "%dungeon_name%"; + public static final String DUNGEON_ID = "%dungeon_id%"; + public static final String DUNGEON_WORLD = "%dungeon_world%"; + public static final String DUNGEON_KEY_IDS = "%dungeon_key_ids%"; + public static final String DUNGEON_KEY_NAMES = "%dungeon_key_names%"; + public static final String DUNGEON_NEXT_STAGE_IN = "%dungeon_next_stage_in%"; + public static final String EDITOR_HOLOGRAM_TEXT = "%dungeon_editor_hologram_text%"; + public static final Function DUNGEON_HOLOGRAM_MESSAGES = var -> "%dungeon_hologram_" + var + "_messages%"; + public static final String DUNGEON_HOLOGRAM_CHEST_OFFSET_Y = "%dungeon_hologram_chest_offset_y%"; + + // party + public static final String PARTY_ENABLED = "%party_enabled%"; + public static final String PARTY_SIZE = "%party_size%"; + + // schematics + public static final String SCHEMATICS_LIST = "%schematics_list%"; + public static final String SCHEMATICS_IGNORE_AIR = "%schematics_ignore_air%"; + public static final String SCHEMATICS_UNDERGROUND = "%schematics_underground%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestBlock.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestBlock.java new file mode 100644 index 0000000..97f9b2a --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestBlock.java @@ -0,0 +1,146 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.chest; + +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.api.manager.ICleanable; +import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; +import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; +import t.me.p1azmer.engine.utils.TimeUtil; +import t.me.p1azmer.plugin.dungeons.DungeonPlugin; +import t.me.p1azmer.plugin.dungeons.Keys; +import t.me.p1azmer.plugin.dungeons.api.handler.hologram.HologramHandler; +import t.me.p1azmer.plugin.dungeons.config.Config; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.ChestSettings; +import t.me.p1azmer.plugin.dungeons.key.Key; +import t.me.p1azmer.plugin.dungeons.key.KeyManager; +import t.me.p1azmer.plugin.dungeons.lang.Lang; + +import java.util.Collection; +import java.util.HashSet; + +import static t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState.*; + +@Getter +@Setter +public class ChestBlock implements ICleanable, IPlaceholderMap { + + private final Dungeon dungeon; + private final Block block; + private final Location location; + private ChestMenu menu; + private ChestState state; + private final PlaceholderMap placeholderMap; + + // cache + private int currentTick; + private final Collection openedCache = new HashSet<>(); + + public ChestBlock(@NotNull Dungeon dungeon, @NotNull Block block, @NotNull Location location, @NotNull ChestMenu menu) { + this.dungeon = dungeon; + this.block = block; + this.location = location; + this.menu = menu; + this.state = WAITING; + + this.placeholderMap = new PlaceholderMap() + .add(Placeholders.DUNGEON_CHEST_NEXT_STATE_IN, () -> TimeUtil.formatTimeLeft(System.currentTimeMillis() + this.getNextStateTime() * 1000L)) + ; + } + + public int getNextStateTime() { + ChestSettings chestSettings = this.getDungeon().getChestSettings(); + return chestSettings.getTime(this.getState()) - this.getCurrentTick(); + } + + public void setCurrentTick(int tick) { + this.currentTick = Math.max(0, tick); + } + + public boolean isOpenFor(@NotNull Player player) { + ChestSettings chestSettings = this.getDungeon().getChestSettings(); + return chestSettings.isUseOneKeyForMenu() ? this.getState().isOpen() : this.openedCache.contains(player); + } + + public void setState(@NotNull ChestState state) { + this.setCurrentTick(0); + this.state = state; + } + + public void click(@NotNull Player player) { + Dungeon dungeon = this.getDungeon(); + DungeonPlugin plugin = dungeon.plugin(); + KeyManager keyManager = plugin.getKeyManager(); + ChestSettings chestSettings = dungeon.getChestSettings(); + ChestModule.OpenType openType = chestSettings.getOpenType(); + + if (openType.isClick() && this.getState().isWaiting()) { + this.setState(dungeon.getSettings().isClickTimer() ? COOLDOWN : OPENED); + return; + } + + if (!this.getState().isOpen()) return; + + Key key = keyManager.getKeys(player, dungeon).stream().findFirst().orElse(null); + + boolean allowed = !isOpenFor(player) && !dungeon.getKeyIds().isEmpty(); + if (allowed) { + if (key == null) { + plugin.getMessage(Lang.DUNGEON_OPEN_ERROR_NO_KEY) + .replace(dungeon.replacePlaceholders()) + .send(player); + return; + } + if (Config.DUNGEON_HOLD_KEY_TO_OPEN.get()) { + ItemStack main = player.getInventory().getItemInMainHand(); + if (!keyManager.isKey(main, key)) { + plugin.getMessage(Lang.DUNGEON_OPEN_ERROR_NO_HOLD_KEY) + .replace(dungeon.replacePlaceholders()) + .send(player); + return; + } + } + + keyManager.takeKey(player, key, 1); + if (chestSettings.isUseOneKeyForMenu()) this.setState(OPENED); + else this.openedCache.add(player); + + } else if (!this.getState().isOpen()) this.setState(OPENED); + + if (block.hasMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey())) this.getMenu().open(block, player); + } + + public void tick(@NotNull DungeonPlugin plugin, int tick) { + this.setCurrentTick(tick); + HologramHandler handler = plugin.getHologramHandler(); + if (handler != null) handler.update(this); + + if (Config.TICK_CHEST_DEBUG.get()) { + this.getDungeon().plugin().sendDebug("Tick the '" + this.getDungeon().getId() + "' dungeon chest with state = " + this.getState().name() + ", time=" + this.getCurrentTick() + ", coordinate=" + Placeholders.forLocation(this.getLocation()).apply("%location_x%, %location_z%") + ", next state in=" + this.getNextStateTime()); + } + } + + @Override + public void clear() { + if (!this.getState().isDeleted()) this.setState(DELETED); + + this.setCurrentTick(0); + if (this.menu != null) { + this.menu.clear(); + this.menu = null; + } + this.openedCache.clear(); + } + + @Override + public @NotNull PlaceholderMap getPlaceholders() { + return this.placeholderMap; + } +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestMenu.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestMenu.java new file mode 100644 index 0000000..c7454a7 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/ChestMenu.java @@ -0,0 +1,102 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.chest; + +import lombok.Getter; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.api.manager.AbstractListener; +import t.me.p1azmer.engine.api.manager.ICleanable; +import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; +import t.me.p1azmer.engine.utils.Colorizer; +import t.me.p1azmer.engine.utils.PlayerUtil; +import t.me.p1azmer.engine.utils.random.Rnd; +import t.me.p1azmer.plugin.dungeons.DungeonPlugin; +import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.reward.Reward; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.ChestSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.RewardSettings; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.UnaryOperator; + +@Getter +public class ChestMenu extends AbstractListener implements ICleanable { + private final Dungeon dungeon; + private final Inventory inventory; + private Block block; + private final Set cachedRewards; + private boolean fistOpen; + + public ChestMenu(@NotNull Block block, @NotNull Dungeon dungeon, @NotNull Map rewards) { + super(dungeon.plugin()); + this.dungeon = dungeon; + + this.cachedRewards = new HashSet<>(); + this.fistOpen = false; + this.block = block; + int menuSize = dungeon.getChestSettings().isBigMenu() ? 54 : 27; + this.inventory = Bukkit.createInventory(null, menuSize, Colorizer.apply(dungeon.getName())); + + this.initRewards(rewards, dungeon.getChestSettings(), dungeon.getRewardSettings()); + this.registerListeners(); + } + + public void initRewards(@NotNull Map rewards, @NotNull ChestSettings settings, @NotNull RewardSettings rewardSettings) { + for (int i = 0; i < rewardSettings.getLimit().roll(); i++) { + Reward reward = Rnd.getByWeight(rewards); + ItemStack item = reward.getItem(); + item.setAmount(reward.getAmount().roll()); + this.cachedRewards.add(reward); + + if (settings.isRandomSlots()) { + int slot = Rnd.get(0, this.inventory.getSize() - 1); + ItemStack currentItem = this.inventory.getItem(slot); + boolean allowed = currentItem == null || currentItem.getType().isAir(); + if (allowed) + this.inventory.setItem(slot, item); + else + this.inventory.addItem(reward.getItem()); + continue; + } + this.inventory.addItem(reward.getItem()); + } + } + + public void open(@NotNull Block block, @NotNull Player player) { + Location blockLocation = block.getLocation(); + Location menuBlockLocation = this.block.getLocation(); + + if (this.block.equals(block) || blockLocation.equals(menuBlockLocation)) { + player.openInventory(this.getInventory()); + + if (!this.fistOpen) { + PlaceholderMap dungeonPlaceholders = this.dungeon.getPlaceholders(); + this.cachedRewards.forEach(reward -> reward.getCommands() + .forEach(command -> { + UnaryOperator inter = PlaceholderMap.fusion(reward.getPlaceholders(), dungeonPlaceholders).replacer(); + PlayerUtil.dispatchCommand(player, inter.apply(command)); + }) + ); + this.fistOpen = true; + } + } + } + + @Override + public void clear() { + this.unregisterListeners(); + this.fistOpen = false; + this.block = null; + plugin.runTask(sync -> new HashSet<>(this.inventory.getViewers()).forEach(HumanEntity::closeInventory)); + + this.cachedRewards.clear(); + this.inventory.clear(); + } +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestBlock.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestBlock.java deleted file mode 100644 index 8be2cc8..0000000 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestBlock.java +++ /dev/null @@ -1,171 +0,0 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.chest; - -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.engine.api.manager.ICleanable; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; -import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; -import t.me.p1azmer.engine.utils.TimeUtil; -import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Keys; -import t.me.p1azmer.plugin.dungeons.Placeholders; -import t.me.p1azmer.plugin.dungeons.api.hologram.HologramHandler; -import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; -import t.me.p1azmer.plugin.dungeons.key.Key; -import t.me.p1azmer.plugin.dungeons.lang.Lang; - -import java.util.Collection; -import java.util.HashSet; - -import static t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState.*; - -public class DungeonChestBlock implements ICleanable, IPlaceholderMap { - - private final Dungeon dungeon; - private final Block block; - private final Location location; - private DungeonChestMenu gui; - private DungeonChestState chestState; - private final PlaceholderMap placeholderMap; - - // cache - private boolean playerClicked = false; - private int currentTick; - private Collection openedCache; - - public DungeonChestBlock(@NotNull Dungeon dungeon, @NotNull Block block, @NotNull Location location, @NotNull DungeonChestMenu gui) { - this.dungeon = dungeon; - this.block = block; - this.location = location; - this.gui = gui; - this.chestState = WAITING; - this.openedCache = new HashSet<>(); - - this.placeholderMap = new PlaceholderMap() - .add(Placeholders.DUNGEON_CHEST_NEXT_STATE_IN, () -> TimeUtil.formatTimeLeft(System.currentTimeMillis() + this.getNextStateTime() * 1000L)) - ; - } - - @NotNull - public Dungeon getDungeon() { - return dungeon; - } - - @NotNull - public Block getBlock() { - return block; - } - - @NotNull - public Location getLocation() { - return location; - } - - @NotNull - public DungeonChestMenu getGui() { - return gui; - } - - public boolean isPlayerClicked() { - return playerClicked; - } - - public int getCurrentTick() { - return this.currentTick; - } - - public int getNextStateTime() { - return this.getDungeon().getChestSettings().getTime(this.getState()) - this.getCurrentTick(); - } - - public void setCurrentTick(int tick) { - this.currentTick = Math.max(0, tick); - } - - @NotNull - public DungeonChestState getState() { - return chestState; - } - - public boolean isOpenFor(@NotNull Player player) { - return this.getDungeon().getChestSettings().isUseOneKeyForMenu() ? this.getState().isOpen() : this.openedCache.contains(player); - } - - public void setChestState(@NotNull DungeonChestState state) { - this.setCurrentTick(0); - this.chestState = state; - } - - public void click(@NotNull Player player) { - ChestModule.OpenType openType = this.getDungeon().getChestSettings().getOpenType(); - if (openType.isClick() && this.getState().isWaiting()) { - this.setChestState(this.getDungeon().getSettings().isClickTimer() ? COOLDOWN : OPENED); - return; - } - if (!this.getState().isOpen()) return; - - Key key = this.getDungeon().plugin().getKeyManager().getKeys(player, this.getDungeon()).stream().findFirst().orElse(null); - - if (!isOpenFor(player) && !this.getDungeon().getKeyIds().isEmpty()) { - if (key == null) { - this.getDungeon().plugin().getMessage(Lang.DUNGEON_OPEN_ERROR_NO_KEY).replace(this.getDungeon().replacePlaceholders()).send(player); - return; - } - if (Config.DUNGEON_HOLD_KEY_TO_OPEN.get()) { - ItemStack main = player.getInventory().getItemInMainHand(); - if (!this.getDungeon().plugin().getKeyManager().isKey(main, key)) { - this.getDungeon().plugin().getMessage(Lang.DUNGEON_OPEN_ERROR_NO_HOLD_KEY).replace(this.getDungeon().replacePlaceholders()).send(player); - return; - } - } - - this.getDungeon().plugin().getKeyManager().takeKey(player, key, 1); - if (dungeon.getChestSettings().isUseOneKeyForMenu()) - this.setChestState(OPENED); - else - this.openedCache.add(player); - } else if (!this.getState().isOpen()) - this.setChestState(OPENED); - - if (block.hasMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey())) { - this.getGui().open(block, player); - } - } - - public void tick(@NotNull DungeonPlugin plugin, int tick) { - this.setCurrentTick(tick); - HologramHandler handler = plugin.getHologramHandler(); - if (handler != null) { - handler.update(this); - } - if (Config.DEBUG_TICK_CHEST.get()) { - this.getDungeon().plugin().sendDebug("Tick the '" + this.getDungeon().getId() + "' dungeon chest with state = " + this.getState().name() + ", time=" + this.getCurrentTick() + ", coordinate=" + Placeholders.forLocation(this.getLocation()).apply("%location_x%, %location_z%") + ", next state in=" + this.getNextStateTime()); - } - } - - @Override - public void clear() { - if (!this.getState().isDeleted()) - this.setChestState(DELETED); - - this.setCurrentTick(0); - if (this.gui != null) { - this.gui.clear(); - this.gui = null; - } - if (this.openedCache != null) { - this.openedCache.clear(); - this.openedCache = null; - } - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } -} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestMenu.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestMenu.java deleted file mode 100644 index da612c0..0000000 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestMenu.java +++ /dev/null @@ -1,112 +0,0 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.chest; - -import org.bukkit.Bukkit; -import org.bukkit.block.Block; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.engine.api.manager.AbstractListener; -import t.me.p1azmer.engine.api.manager.ICleanable; -import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; -import t.me.p1azmer.engine.utils.Colorizer; -import t.me.p1azmer.engine.utils.PlayerUtil; -import t.me.p1azmer.engine.utils.random.Rnd; -import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Reward; -import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.ChestSettings; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.RewardSettings; - -import java.util.*; -import java.util.function.UnaryOperator; - -@Deprecated -public class DungeonChestMenu extends AbstractListener implements ICleanable { - private final Dungeon dungeon; - private Inventory inventory; - private Collection players; - private Block block; - private final Set cachedRewards; - private boolean commandsTriggered; - - public DungeonChestMenu(@NotNull Block block, @NotNull Dungeon dungeon, @NotNull Map rewards) { - super(dungeon.plugin()); - this.dungeon = dungeon; - - this.cachedRewards = new HashSet<>(); - this.commandsTriggered = false; - this.block = block; - this.players = new HashSet<>(); - this.inventory = Bukkit.createInventory(null, dungeon.getChestSettings().isBigMenu() ? 54 : 27, Colorizer.apply(dungeon.getName())); - - this.initRewards(rewards, dungeon.getChestSettings(), dungeon.getRewardSettings()); - this.registerListeners(); - } - - public void initRewards(@NotNull Map rewards, @NotNull ChestSettings settings, @NotNull RewardSettings rewardSettings) { - for (int i = 0; i < rewardSettings.getLimit().roll(); i++) { - Reward reward = Rnd.getByWeight(rewards); - ItemStack item = reward.getItem(); - item.setAmount(reward.getAmount().roll()); - this.cachedRewards.add(reward); - - if (settings.isRandomSlots()) { - int slot = Rnd.get(0, this.inventory.getSize()-1); - ItemStack currentItem = this.inventory.getItem(slot); - if (currentItem == null || currentItem.getType().isAir()) - this.inventory.setItem(slot, item); - continue; - } - this.inventory.addItem(reward.getItem()); - } - } - - public void open(@NotNull Block block, @NotNull Player player) { - if (this.block.equals(block) || block.getLocation().equals(this.block.getLocation())) { - this.players.add(player); - player.openInventory(this.getInventory()); - if (!this.commandsTriggered) { - this.cachedRewards.forEach(reward -> reward.getCommands().forEach(command -> { - UnaryOperator inter = PlaceholderMap.fusion(reward.getPlaceholders(), this.dungeon.getPlaceholders()).replacer(); - PlayerUtil.dispatchCommand(player, inter.apply(command)); - })); - this.commandsTriggered = true; - } - } - } - - public Inventory getInventory() { - return inventory; - } - - @EventHandler - public void onClose(InventoryCloseEvent event) { - if (event.getInventory().equals(this.inventory)) { - if (event.getPlayer() instanceof Player player) { - this.players.remove(player); - } - } - } - - @Override - public void clear() { - this.unregisterListeners(); - if (this.players != null) { - this.players.clear(); - this.players = null; - } - if (this.inventory != null) { - new HashSet<>(this.inventory.getViewers()).forEach(HumanEntity::closeInventory); - this.inventory.clear(); - this.inventory = null; - } - - this.cachedRewards.clear(); - this.commandsTriggered = false; - this.block = null; - } -} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/Placeholders.java new file mode 100644 index 0000000..e386d85 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/Placeholders.java @@ -0,0 +1,12 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.chest; + +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; + +import java.util.function.Function; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final Function DUNGEON_CHEST_STATE_TIME = var -> "%dungeon_chest_state_" + var + "_time%"; + public static final String DUNGEON_CHEST_STATE_NAME = "%dungeon_state_name%"; + public static final String DUNGEON_CHEST_NEXT_STATE_IN = "%dungeon_chest_next_state_in%"; + public static final String EDITOR_STATE_TIME = "%dungeon_editor_state_time%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestState.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/state/ChestState.java similarity index 81% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestState.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/state/ChestState.java index 3f0b05c..82cc6a1 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/DungeonChestState.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/chest/state/ChestState.java @@ -1,11 +1,11 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.chest; +package t.me.p1azmer.plugin.dungeons.dungeon.chest.state; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders; -public enum DungeonChestState implements IPlaceholderMap { +public enum ChestState implements IPlaceholderMap { WAITING, COOLDOWN, diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/DungeonMainEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/DungeonMainEditor.java index b9cb512..d3e5f88 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/DungeonMainEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/DungeonMainEditor.java @@ -42,13 +42,14 @@ public class DungeonMainEditor extends EditorMenu implem private DungeonRegionMainEditor regionMainEditor; private MainSettingsEditor settingsEditor; private PartySettingsEditor partySettingsEditor; + private GenerationSettingsEditor generationSettingsEditor; private final AutoRemovalCollection rebootCache = AutoRemovalCollection.newHashSet(1, TimeUnit.MINUTES); public DungeonMainEditor(@NotNull Dungeon dungeon) { super(dungeon.plugin(), dungeon, Config.EDITOR_TITLE_DUNGEON.get(), 54); - this.addReturn(49).setClick((viewer, event) -> { + this.addReturn(53).setClick((viewer, event) -> { this.plugin.runTask(task -> this.plugin.getEditor().getDungeonEditor().open(viewer.getPlayer(), 1)); }); @@ -126,6 +127,9 @@ public DungeonMainEditor(@NotNull Dungeon dungeon) { EditorLocales.COMMANDS_SETTINGS, 33).setClick((viewer, event) -> { this.getCommandsSettingsEditor().openNextTick(viewer.getPlayer(), 1); }); + this.addItem(ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTRlMDBhNjEyZGE2NDFmYWFjNzc4OWU3ZmZkZjRmZThjODY4ODQwZTc1MmUwYWFhNzc2ODYyMGFkOTkyN2U0MCJ9fX0="), + EditorLocales.GENERATION_SETTINGS, 40) + .setClick((viewer, event) -> this.getGenerationSettingsEditor().openNextTick(viewer.getPlayer(), 1)); this.addItem(ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjliMjg4OTAyMDU4MzU2NWY4OGQ1MDUzNzg3MGM1OWFhZDgwMjU5NGZhYmQ4MzdlMWQxNGY1YTA2YWUzNDUwOSJ9fX0="), EditorLocales.DUNGEON_WORLD, 4).setClick((viewer, event) -> { @@ -160,7 +164,7 @@ public DungeonMainEditor(@NotNull Dungeon dungeon) { dungeon.getModuleManager().getModules().forEach(module -> ItemReplacer.replace(item, module.replacePlaceholders())); ItemReplacer.replace(item, dungeon.replacePlaceholders()); ItemReplacer.replace(item, dungeon.getHologramSettings().replacePlaceholders()); - ItemReplacer.replace(item, dungeon.getDungeonRegion().replacePlaceholders()); + ItemReplacer.replace(item, dungeon.getRegion().replacePlaceholders()); ItemReplacer.replace(item, dungeon.getSettings().replacePlaceholders()); })); } @@ -242,7 +246,7 @@ public CommandsSettingsEditor getCommandsSettingsEditor() { @NotNull public StageSettingsEditor getStageSettingsEditor() { - if (this.stageSettingsEditor == null){ + if (this.stageSettingsEditor == null) { this.stageSettingsEditor = new StageSettingsEditor(this.object.getStageSettings()); } return stageSettingsEditor; @@ -259,7 +263,7 @@ public DungeonEffectListEditor getEffectEditor() { @NotNull public DungeonRegionMainEditor getRegionMainEditor() { if (this.regionMainEditor == null) { - this.regionMainEditor = new DungeonRegionMainEditor(this.object.getDungeonRegion()); + this.regionMainEditor = new DungeonRegionMainEditor(this.object.getRegion()); } return regionMainEditor; } @@ -280,6 +284,14 @@ public PartySettingsEditor getPartySettingsEditor() { return partySettingsEditor; } + @NotNull + public GenerationSettingsEditor getGenerationSettingsEditor() { + if (this.generationSettingsEditor == null) { + this.generationSettingsEditor = new GenerationSettingsEditor(this.object.getGenerationSettings()); + } + return generationSettingsEditor; + } + private void save(@NotNull MenuViewer viewer) { this.object.save(); this.plugin.runTask(task -> this.open(viewer.getPlayer(), viewer.getPage())); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/effect/DungeonEffectListEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/effect/DungeonEffectListEditor.java index b0599cb..b53a439 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/effect/DungeonEffectListEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/effect/DungeonEffectListEditor.java @@ -19,7 +19,7 @@ import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Effect; +import t.me.p1azmer.plugin.dungeons.dungeon.effect.Effect; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/region/DungeonRegionMainEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/region/DungeonRegionMainEditor.java index fe2f60e..d1f0dcf 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/region/DungeonRegionMainEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/region/DungeonRegionMainEditor.java @@ -8,7 +8,7 @@ import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -19,8 +19,8 @@ public class DungeonRegionMainEditor extends EditorMenu { public DungeonRegionMainEditor(@NotNull Region region) { - super(region.getDungeon().plugin(), region, Config.EDITOR_TITLE_DUNGEON.get(), 27); - Dungeon dungeon = region.getDungeon(); + super(region.dungeon().plugin(), region, Config.EDITOR_TITLE_DUNGEON.get(), 27); + Dungeon dungeon = region.dungeon(); this.addReturn(22).setClick((viewer, event) -> { this.plugin.runTask(task -> dungeon.getEditor().open(viewer.getPlayer(), 1)); @@ -91,7 +91,7 @@ else if (item.getType().equals(Material.REDSTONE_BLOCK) && region.isEnabled()) } private void save(@NotNull MenuViewer viewer) { - this.object.getDungeon().save(); + this.object.dungeon().save(); this.plugin.runTask(task -> this.open(viewer.getPlayer(), viewer.getPage())); } } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardListEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardListEditor.java index 2fbe6d8..1d9fdbb 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardListEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardListEditor.java @@ -18,7 +18,7 @@ import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Reward; +import t.me.p1azmer.plugin.dungeons.dungeon.reward.Reward; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -44,7 +44,7 @@ public DungeonRewardListEditor(@NotNull Dungeon dungeon) { if (cursor != null && !cursor.getType().isAir()) { String id = StringUtil.lowerCaseUnderscore(ItemUtil.getItemName(cursor)); int count = 0; - while (dungeon.getReward(count == 0 ? id : id + count) != null) { + while (dungeon.getReward(count == 0 ? id : id + count).orElse(null) != null) { count++; } Reward reward = new Reward(dungeon, count == 0 ? id : id + count); @@ -57,7 +57,7 @@ public DungeonRewardListEditor(@NotNull Dungeon dungeon) { this.handleInput(viewer, Lang.EDITOR_REWARD_ENTER_ID, wrapper -> { String id = StringUtil.lowerCaseUnderscore(wrapper.getTextRaw()); - if (dungeon.getReward(id) != null) { + if (dungeon.getReward(id).isPresent()) { EditorManager.error(viewer.getPlayer(), plugin.getMessage(Lang.EDITOR_REWARD_ERROR_CREATE_EXIST).getLocalized()); return false; } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardMainEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardMainEditor.java index f7bcb71..3128e70 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardMainEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/reward/DungeonRewardMainEditor.java @@ -8,14 +8,13 @@ import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.menu.impl.EditorMenu; import t.me.p1azmer.engine.api.menu.impl.MenuViewer; -import t.me.p1azmer.engine.editor.EditorManager; import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.engine.utils.PlayerUtil; import t.me.p1azmer.engine.utils.values.UniInt; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Reward; +import t.me.p1azmer.plugin.dungeons.dungeon.reward.Reward; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/AnnounceSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/AnnounceSettingsEditor.java index 7862e18..9bf2b1f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/AnnounceSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/AnnounceSettingsEditor.java @@ -16,11 +16,11 @@ import t.me.p1azmer.engine.utils.Colors; import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.announce.impl.Announce; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.AnnounceSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.AnnounceSettings; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -79,6 +79,7 @@ public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonStage st .readLocale(EditorLocales.ANNOUNCE_MODULE_OBJECT) .trimmed() .replace(Placeholders.EDITOR_STAGE_NAME, stage.name()) + .replace(Placeholders.EDITOR_STAGE_DESCRIPTION, stage.getDescription(plugin())) .hideFlags() .replace(Placeholders.EDITOR_STAGE_ANNOUNCES, Colorizer.apply(Colors.LIGHT_PURPLE + String.join("\n", map.entrySet().stream().map(pair -> Colors.LIGHT_PURPLE + pair.getKey().getId() + " " + Colors.PURPLE + Arrays.toString(pair.getValue())).toList()))) .replace(this.object.replacePlaceholders()) diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ChestSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ChestSettingsEditor.java index f8bae14..d20be3f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ChestSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ChestSettingsEditor.java @@ -18,10 +18,10 @@ import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.ChestSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.ChestSettings; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -34,7 +34,7 @@ import static t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule.OpenType.CLICK; import static t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule.OpenType.TIMER; -public class ChestSettingsEditor extends EditorMenu implements AutoPaged { +public class ChestSettingsEditor extends EditorMenu implements AutoPaged { public ChestSettingsEditor(@NotNull ChestSettings settings) { super(settings.dungeon().plugin(), settings, Config.EDITOR_TITLE_DUNGEON.get(), 36); @@ -149,13 +149,13 @@ public int[] getObjectSlots() { @Override @NotNull - public List getObjects(@NotNull Player player) { - return new ArrayList<>(Arrays.stream(DungeonChestState.values()).toList()); + public List getObjects(@NotNull Player player) { + return new ArrayList<>(Arrays.stream(ChestState.values()).toList()); } @Override @NotNull - public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonChestState state) { + public ItemStack getObjectStack(@NotNull Player player, @NotNull ChestState state) { ItemStack item = ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmNiOGYwNjg4NWQxZGFhZmQyNmNkOTViMzQ4MmNiNTI1ZDg4MWE2N2UwZDI0NzE2MWI5MDhkOTNkNTZkMTE0ZiJ9fX0="); ItemReplacer.create(item) .readLocale(EditorLocales.CHEST_BLOCK_STATE_OBJECT) @@ -172,7 +172,7 @@ public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonChestSta @Override @NotNull - public ItemClick getObjectClick(@NotNull DungeonChestState state) { + public ItemClick getObjectClick(@NotNull ChestState state) { return (viewer, event) -> { Player player = viewer.getPlayer(); if (event.getClick().equals(ClickType.LEFT)) { diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/CommandsSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/CommandsSettingsEditor.java index 4782b16..272147a 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/CommandsSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/CommandsSettingsEditor.java @@ -2,10 +2,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.menu.AutoPaged; import t.me.p1azmer.engine.api.menu.click.ItemClick; import t.me.p1azmer.engine.api.menu.impl.EditorMenu; @@ -17,10 +15,10 @@ import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.CommandsSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.CommandsSettings; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -82,6 +80,7 @@ public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonStage st .hideFlags() .replace(s -> s .replace(Placeholders.EDITOR_STAGE_NAME, stage.name()) + .replace(Placeholders.EDITOR_STAGE_DESCRIPTION, stage.getDescription(plugin())) .replace(Placeholders.EDITOR_STAGE_COMMANDS, Colors.LIGHT_PURPLE + String.join("\n", this.object.getCommands(stage))) ) .replace(this.object.replacePlaceholders()) diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/GenerationSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/GenerationSettingsEditor.java new file mode 100644 index 0000000..464232a --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/GenerationSettingsEditor.java @@ -0,0 +1,78 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.editor.settings; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.api.menu.impl.EditorMenu; +import t.me.p1azmer.engine.api.menu.impl.MenuViewer; +import t.me.p1azmer.engine.utils.CollectionsUtil; +import t.me.p1azmer.engine.utils.ItemReplacer; +import t.me.p1azmer.plugin.dungeons.DungeonPlugin; +import t.me.p1azmer.plugin.dungeons.config.Config; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; +import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.GenerationSettings; +import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; + +public class GenerationSettingsEditor extends EditorMenu { + + public GenerationSettingsEditor(@NotNull GenerationSettings settings) { + super(settings.dungeon().plugin(), settings, Config.EDITOR_TITLE_DUNGEON.get(), 9); + Dungeon dungeon = settings.dungeon(); + + this.addReturn(8).setClick((viewer, event) -> { + dungeon.getEditor().openNextTick(viewer.getPlayer(), 1); + }); + + + this.addItem(new ItemStack(Material.PLAYER_HEAD), EditorLocales.DUNGEON_SETTINGS_GENERATION_TYPE, 2) + .setClick((viewer, event) -> { + GenerationType generationType = CollectionsUtil.next(settings.getGenerationType()); + settings.setGenerationType(generationType); + this.save(viewer); + }).getOptions() + .setDisplayModifier((viewer, item) -> { + ItemStack replacer = new ItemStack(settings.getGenerationType().getIcon()); + item.setItemMeta(replacer.getItemMeta()); + ItemReplacer + .create(item) + .readLocale(EditorLocales.DUNGEON_SETTINGS_GENERATION_TYPE) + .writeMeta(); + }); + + this.addItem(new ItemStack(Material.DIRT), EditorLocales.DUNGEON_SETTINGS_GENERATION_LOCATION, 4) + .setClick((viewer, event) -> { + ClickType clickType = event.getClick(); + + if (clickType == ClickType.LEFT) { + Player player = viewer.getPlayer(); + Location location = player.getLocation(); + settings.setSpawnLocation(location); + }else if (clickType == ClickType.SHIFT_RIGHT){ + settings.setSpawnLocation(null); + } + + this.save(viewer); + }); + + this.getItems() + .forEach(menuItem -> menuItem + .getOptions() + .addDisplayModifier(((viewer, item) -> { + ItemReplacer + .replace(item, dungeon.replacePlaceholders()); + ItemReplacer + .replace(item, settings.replacePlaceholders()); + ItemReplacer + .replace(item, dungeon.getSettings().replacePlaceholders()); + }))); + } + + private void save(@NotNull MenuViewer viewer) { + this.object.dungeon().save(); + this.openNextTick(viewer.getPlayer(), viewer.getPage()); + } +} \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/HologramSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/HologramSettingsEditor.java index c7e6cb3..9beb43f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/HologramSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/HologramSettingsEditor.java @@ -3,10 +3,8 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.menu.AutoPaged; import t.me.p1azmer.engine.api.menu.click.ItemClick; import t.me.p1azmer.engine.api.menu.impl.EditorMenu; @@ -16,10 +14,10 @@ import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.HologramSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.HologramSettings; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -28,7 +26,7 @@ import java.util.List; import java.util.stream.IntStream; -public class HologramSettingsEditor extends EditorMenu implements AutoPaged { +public class HologramSettingsEditor extends EditorMenu implements AutoPaged { public HologramSettingsEditor(@NotNull HologramSettings settings) { @@ -74,13 +72,13 @@ public int[] getObjectSlots() { @Override @NotNull - public List getObjects(@NotNull Player player) { - return new ArrayList<>(Arrays.stream(DungeonChestState.values()).toList()); + public List getObjects(@NotNull Player player) { + return new ArrayList<>(Arrays.stream(ChestState.values()).toList()); } @Override @NotNull - public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonChestState state) { + public ItemStack getObjectStack(@NotNull Player player, @NotNull ChestState state) { ItemStack item = new ItemStack(Material.FLOWER_BANNER_PATTERN); ItemReplacer.create(item) .readLocale(EditorLocales.HOLOGRAM_OBJECT) @@ -97,7 +95,7 @@ public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonChestSta @Override @NotNull - public ItemClick getObjectClick(@NotNull DungeonChestState state) { + public ItemClick getObjectClick(@NotNull ChestState state) { return (viewer, event) -> { Player player = viewer.getPlayer(); if (event.getClick().equals(ClickType.SHIFT_RIGHT)) { diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/MainSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/MainSettingsEditor.java index b97f73d..4147c8b 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/MainSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/MainSettingsEditor.java @@ -12,7 +12,7 @@ import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.MainSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.MainSettings; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; @@ -89,7 +89,7 @@ public MainSettingsEditor(@NotNull MainSettings settings) { this.getItems().forEach(menuItem -> { menuItem.getOptions().addDisplayModifier(((viewer, item) -> { ItemReplacer.replace(item, dungeon.replacePlaceholders()); - ItemReplacer.replace(item, dungeon.getDungeonRegion().replacePlaceholders()); + ItemReplacer.replace(item, dungeon.getRegion().replacePlaceholders()); ItemReplacer.replace(item, dungeon.getSettings().replacePlaceholders()); })); }); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ModuleSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ModuleSettingsEditor.java index 374ab78..284e0cc 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ModuleSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/ModuleSettingsEditor.java @@ -2,10 +2,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.menu.AutoPaged; import t.me.p1azmer.engine.api.menu.click.ItemClick; import t.me.p1azmer.engine.api.menu.impl.EditorMenu; @@ -16,10 +14,14 @@ import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.config.Config; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; +import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleId; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.ModuleSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.GenerationSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.MainSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.ModuleSettings; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import java.util.List; @@ -64,16 +66,24 @@ public int[] getObjectSlots() { @Override @NotNull public List getObjects(@NotNull Player player) { - return List.of(ModuleId.ANNOUNCE, ModuleId.CHEST, ModuleId.COMMAND, ModuleId.SCHEMATIC, ModuleId.HOLOGRAM, ModuleId.SPAWN); + return List.of(ModuleId.ANNOUNCE, ModuleId.CHEST, ModuleId.COMMAND, ModuleId.SCHEMATIC, ModuleId.HOLOGRAM, ModuleId.SPAWN, ModuleId.MOBS); } @Override @NotNull public ItemStack getObjectStack(@NotNull Player player, @NotNull String moduleId) { boolean enabled = this.object.isEnabled(moduleId); - ItemStack item = enabled ? + Dungeon dungeon = this.object.dungeon(); + GenerationSettings settings = dungeon.getGenerationSettings(); + GenerationType generationType = settings.getGenerationType(); + List whitelist = generationType.getModuleWhitelist(); + boolean inWhitelist = whitelist.contains(moduleId); + ItemStack item = inWhitelist ? + ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTQ4ZDdkMWUwM2UxYWYxNDViMDEyNWFiODQxMjg1NjcyYjQyMTI2NWRhMmFiOTE1MDE1ZjkwNTg0MzhiYTJkOCJ9fX0=") : + enabled ? ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWMwMWY2Nzk2ZWI2M2QwZThhNzU5MjgxZDAzN2Y3YjM4NDMwOTBmOWE0NTZhNzRmNzg2ZDA0OTA2NWM5MTRjNyJ9fX0=") : ItemUtil.createCustomHead("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjI1NTRkZGE4MGVhNjRiMThiYzM3NWI4MWNlMWVkMTkwN2ZjODFhZWE2YjFjZjNjNGY3YWQzMTQ0Mzg5ZjY0YyJ9fX0="); + ItemReplacer.create(item) .readLocale(EditorLocales.MODULE_OBJECT) .trimmed() @@ -93,7 +103,18 @@ public ItemStack getObjectStack(@NotNull Player player, @NotNull String moduleId @NotNull public ItemClick getObjectClick(@NotNull String moduleId) { return (viewer, event) -> { - if (event.getClick().equals(ClickType.LEFT)) { + boolean isLeftClick = event.getClick().equals(ClickType.LEFT); + + if (isLeftClick) { + Dungeon dungeon = this.object.dungeon(); + GenerationType generationType = dungeon.getGenerationSettings().getGenerationType(); + + if (generationType.getModuleWhitelist().contains(moduleId)) { + if (!this.object.isEnabled(moduleId)) + this.object.setEnabled(moduleId, true); // always true + return; + } + this.object.setEnabled(moduleId, !this.object.isEnabled(moduleId)); this.save(viewer); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/PartySettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/PartySettingsEditor.java index 79f86ab..51f619f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/PartySettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/PartySettingsEditor.java @@ -6,11 +6,10 @@ import t.me.p1azmer.engine.api.menu.impl.MenuViewer; import t.me.p1azmer.engine.editor.EditorManager; import t.me.p1azmer.engine.utils.ItemReplacer; -import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.PartySettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.PartySettings; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/SchematicsSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/SchematicsSettingsEditor.java index c4d187b..5f3f829 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/SchematicsSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/SchematicsSettingsEditor.java @@ -12,7 +12,7 @@ import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.SchematicModule; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.SchematicSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.SchematicSettings; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/StageSettingsEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/StageSettingsEditor.java index 00a86cb..6acd56e 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/StageSettingsEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/editor/settings/StageSettingsEditor.java @@ -2,10 +2,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.menu.AutoPaged; import t.me.p1azmer.engine.api.menu.click.ItemClick; import t.me.p1azmer.engine.api.menu.impl.EditorMenu; @@ -13,22 +11,20 @@ import t.me.p1azmer.engine.api.menu.impl.MenuViewer; import t.me.p1azmer.engine.editor.EditorManager; import t.me.p1azmer.engine.utils.Colorizer; -import t.me.p1azmer.engine.utils.Colors; import t.me.p1azmer.engine.utils.ItemReplacer; import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.CommandsSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.StageSettings; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; -import t.me.p1azmer.plugin.dungeons.dungeon.stage.StageSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.stream.IntStream; public class StageSettingsEditor extends EditorMenu implements AutoPaged { @@ -53,7 +49,7 @@ public StageSettingsEditor(@NotNull StageSettings settings) { private void save(@NotNull MenuViewer viewer) { this.object.dungeon().save(); - DungeonStage.call(this.object.dungeon(), DungeonStage.CANCELLED, "stage editor need reboot"); + CompletableFuture.runAsync(() -> DungeonStage.call(this.object.dungeon(), DungeonStage.CANCELLED, "stage editor need reboot")); this.plugin.runTask(task -> this.open(viewer.getPlayer(), viewer.getPage())); } @@ -84,6 +80,7 @@ public ItemStack getObjectStack(@NotNull Player player, @NotNull DungeonStage st .hideFlags() .replace(s -> s .replace(Placeholders.EDITOR_STAGE_NAME, stage.name()) + .replace(Placeholders.EDITOR_STAGE_DESCRIPTION, stage.getDescription(plugin())) .replace(Placeholders.EDITOR_STAGE_TIME, String.valueOf(this.object.getTime(stage))) ) .replace(this.object.replacePlaceholders()) diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Effect.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Effect.java similarity index 65% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Effect.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Effect.java index 73b0c3e..b7797ed 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Effect.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Effect.java @@ -1,12 +1,15 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.categories; +package t.me.p1azmer.plugin.dungeons.dungeon.effect; +import lombok.Getter; +import lombok.Setter; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; -import t.me.p1azmer.plugin.dungeons.Placeholders; +@Getter +@Setter public class Effect implements IPlaceholderMap { private PotionEffectType potionEffectType; @@ -27,31 +30,6 @@ public Effect(@NotNull PotionEffectType potionEffectType, int duration, int ampl ; } - @NotNull - public PotionEffectType getPotionEffectType() { - return potionEffectType; - } - - public int getDuration() { - return duration; - } - - public int getAmplifier() { - return amplifier; - } - - public void setPotionEffectType(@NotNull PotionEffectType potionEffectType) { - this.potionEffectType = potionEffectType; - } - - public void setDuration(int duration) { - this.duration = duration; - } - - public void setAmplifier(int amplifier) { - this.amplifier = amplifier; - } - public PotionEffect build() { return this.potionEffectType.createEffect(this.duration, this.amplifier); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Placeholders.java new file mode 100644 index 0000000..b262b3e --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/effect/Placeholders.java @@ -0,0 +1,7 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.effect; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final String EFFECT_NAME = "%effect_name%"; + public static final String EFFECT_DURATION = "%effect_duration%"; + public static final String EFFECT_AMPLIFIER = "%effect_amplifier%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/generation/GenerationType.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/generation/GenerationType.java new file mode 100644 index 0000000..19b55a8 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/generation/GenerationType.java @@ -0,0 +1,64 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.generation; + +import lombok.Getter; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.utils.ItemUtil; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleId; + +import java.util.ArrayList; +import java.util.List; + +@Getter +public enum GenerationType { + /** + * Static - the position of this dungeon will always be the same + */ + STATIC( + ItemUtil.createCustomHead( + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWVmY2JlOTIxN2Y4OWYyYzEyNDcxNjQ5YTk1NDVhNzVhYjFiMDdiNzZmNWQ4NjlhYjM2NDUxYmEzOTczNzIyMCJ9fX0=" + ), + List.of(ModuleId.SPAWN, ModuleId.SCHEMATIC) + ), + /** + * Dynamic - the position of the dungeon will always be + * random based on the settings of the generator + */ + DYNAMIC( + ItemUtil.createCustomHead( + "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYWZlNmQxN2NlNDQyY2NlMzQ0YjBiZjU3MGI2YmZlNmEwYWRhZmFiZTZkMTE2ZDhiZjVkYTliNDA3NGM0MWExMSJ9fX0=" + ), + new ArrayList<>() + ); + /** + * Updatable - the position of the dungeon will be static, + * but its schematics will be created and deleted according to the timer settings + * 11.04.24 - not tested + */ +// UPDATABLE( +// ItemUtil.createCustomHead( +// "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODJlNjk2ZTc4MzcwMWIzYjVjOGE3MTkwMjJmZGFkMmRhMWE0YWRmMzM4YzA3NjM4ODIwMWU5MmE2NzA4NzAyYyJ9fX0=" +// ), +// new ArrayList<>() +// ); + + private final ItemStack icon; + private final List moduleWhitelist; + + GenerationType(@NotNull ItemStack icon, @NotNull List moduleWhitelist) { + this.icon = icon; + this.moduleWhitelist = moduleWhitelist; + } + + public boolean isStatic() { + return this == STATIC; + } + + public boolean isDynamic() { + return this == DYNAMIC; + } + +// public boolean isUpdatable() { +// return this == UPDATABLE; +// } +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/impl/Dungeon.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/impl/Dungeon.java index 6ae8a95..3f62a9f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/impl/Dungeon.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/impl/Dungeon.java @@ -1,11 +1,12 @@ package t.me.p1azmer.plugin.dungeons.dungeon.impl; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.manager.AbstractConfigHolder; import t.me.p1azmer.engine.api.manager.ICleanable; @@ -17,23 +18,30 @@ import t.me.p1azmer.engine.utils.TimeUtil; import t.me.p1azmer.engine.utils.values.UniInt; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.announce.AnnounceManager; +import t.me.p1azmer.plugin.dungeons.announce.impl.Announce; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Reward; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; import t.me.p1azmer.plugin.dungeons.dungeon.editor.DungeonMainEditor; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleId; import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleManager; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; -import t.me.p1azmer.plugin.dungeons.dungeon.settings.*; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.reward.Reward; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.*; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; -import t.me.p1azmer.plugin.dungeons.dungeon.stage.StageSettings; +import t.me.p1azmer.plugin.dungeons.generator.RangeInfo; +import t.me.p1azmer.plugin.dungeons.generator.config.GeneratorConfig; +import t.me.p1azmer.plugin.dungeons.key.KeyManager; import t.me.p1azmer.plugin.dungeons.utils.Cuboid; import t.me.p1azmer.plugin.dungeons.utils.ItemReader; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.function.Predicate; @@ -41,6 +49,8 @@ import static t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage.*; +@Getter +@Setter public class Dungeon extends AbstractConfigHolder implements ICleanable, IPlaceholderMap { private String name; @@ -50,6 +60,7 @@ public class Dungeon extends AbstractConfigHolder implements ICle private MainSettings settings; private HologramSettings hologramSettings; private PartySettings partySettings; + private GenerationSettings generationSettings; private ModuleSettings moduleSettings; private StageSettings stageSettings; private ChestSettings chestSettings; @@ -60,7 +71,7 @@ public class Dungeon extends AbstractConfigHolder implements ICle private RewardSettings rewardSettings; - private Map rewardMap; + private Map rewardsMap; private Set keyIds; private Cuboid cuboid; @@ -68,7 +79,7 @@ public class Dungeon extends AbstractConfigHolder implements ICle private ModuleManager moduleManager; private final PlaceholderMap placeholderMap; private World world; - private Location location; // add permanent dungeon loca + private Location location; // weak cache private AtomicInteger selfTick; private DungeonMainEditor editor; @@ -76,25 +87,122 @@ public class Dungeon extends AbstractConfigHolder implements ICle public Dungeon(@NotNull DungeonManager manager, @NotNull JYML cfg) { super(manager.plugin(), cfg); this.manager = manager; + + AnnounceManager announceManager = plugin().getAnnounceManager(); + Map> defaultAnnounceMap = Map.of( + PREPARE, Map.of(Objects.requireNonNull(announceManager.getAnnounce("prepare_default")), new int[]{26, 27, 28, 29, 30}), + CLOSED, Map.of(Objects.requireNonNull(announceManager.getAnnounce("closed_default")), new int[]{0}) + ); + this.setStage(FREEZE); - this.setPartySettings(new PartySettings(this, false, 2)); - this.setHologramSettings(new HologramSettings(this, 2, Map.of( - DungeonChestState.WAITING, List.of("#d8c2ffDungeon chest", "#dec1d2Status: #4dffc3Waiting you", "#FFC458Click me if you have key!"), - DungeonChestState.COOLDOWN, List.of("#d8c2ffDungeon chest", "#dec1d2Status: #db3251Closed", "&eOpening in: #99ff99" + Placeholders.DUNGEON_CHEST_NEXT_STATE_IN), - DungeonChestState.OPENED, List.of("#d8c2ffDungeon chest", "#dec1d2Status: #7fffd4Opened", "#dec1d2Closing in: #99ff99" + Placeholders.DUNGEON_CHEST_NEXT_STATE_IN)) - )); - this.setSettings(new MainSettings(this, false, false, false, 1, new HashMap<>())); - this.setDungeonRegion(new Region(this, true, this.getId(), 15, List.of("pistons deny", "pvp allow", "use allow", "chest-access allow"))); - this.setAnnounceSettings(new AnnounceSettings(this, Map.of( - PREPARE, Map.of(Objects.requireNonNull(plugin().getAnnounceManager().getAnnounce("prepare_default")), new int[]{26, 27, 28, 29, 30}), - DungeonStage.CLOSED, Map.of(Objects.requireNonNull(plugin().getAnnounceManager().getAnnounce("closed_default")), new int[]{0})))); - this.setSchematicSettings(new SchematicSettings(this, List.of("dungeon_rotten_mushroom"), true, false)); - this.setModuleSettings(new ModuleSettings(this, Map.of(ModuleId.SPAWN, true, ModuleId.ANNOUNCE, true, ModuleId.CHEST, true, ModuleId.COMMAND, true, ModuleId.HOLOGRAM, true, ModuleId.SCHEMATIC, true))); - this.setStageSettings(new StageSettings(this, Map.of(FREEZE, 5, CHECK, 3, PREPARE, 30, WAITING_PLAYERS, 10, OPENING, 5, OPENED, 60, CLOSED, 5, DELETING, 1, CANCELLED, 1, REBOOTED, 1))); - this.setChestSettings(new ChestSettings(this, Map.of(DungeonChestState.WAITING, 10, DungeonChestState.COOLDOWN, 5, DungeonChestState.OPENED, 10, DungeonChestState.CLOSED, 10, DungeonChestState.DELETED, 1), 3, false, false, false, false, ChestModule.OpenType.CLICK, Material.BARREL)); - this.setEffectSettings(new EffectSettings(this, false, new ArrayList<>())); - this.setCommandsSettings(new CommandsSettings(this, Map.of(FREEZE, new ArrayList<>(), CHECK, new ArrayList<>(), PREPARE, new ArrayList<>(), WAITING_PLAYERS, new ArrayList<>(), OPENING, new ArrayList<>(), OPENED, new ArrayList<>(), CLOSED, new ArrayList<>(), DELETING, new ArrayList<>(), CANCELLED, new ArrayList<>(), REBOOTED, new ArrayList<>()))); - this.setRewardSettings(new RewardSettings(this, UniInt.of(5, 15))); + this.setPartySettings( + new PartySettings( + this, + false, + 2 + ) + ); + this.setGenerationSettings( + new GenerationSettings( + this, + GenerationType.DYNAMIC, + null + ) + ); + this.setHologramSettings( + new HologramSettings( + this, + 2, + Map.of( + ChestState.WAITING, + List.of("#d8c2ffDungeon chest", "#dec1d2Status: #4dffc3Waiting you", "#FFC458Click me if you have key!"), + ChestState.COOLDOWN, + List.of("#d8c2ffDungeon chest", "#dec1d2Status: #db3251Closed", "&eOpening in: #99ff99" + Placeholders.DUNGEON_CHEST_NEXT_STATE_IN), + ChestState.OPENED, + List.of("#d8c2ffDungeon chest", "#dec1d2Status: #7fffd4Opened", "#dec1d2Closing in: #99ff99" + Placeholders.DUNGEON_CHEST_NEXT_STATE_IN)) + ) + ); + this.setSettings( + new MainSettings( + this, + false, + false, + false, + 1, + new HashMap<>() + ) + ); + this.setRegion( + new Region( + this, + true, + this.getId(), + 15, + List.of("pistons deny", "pvp allow", "use allow", "chest-access allow") + ) + ); + this.setAnnounceSettings( + new AnnounceSettings( + this, + defaultAnnounceMap + ) + ); + this.setSchematicSettings( + new SchematicSettings( + this, + List.of("dungeon_rotten_mushroom"), + true, + false + ) + ); + this.setModuleSettings( + new ModuleSettings( + this, + Map.of( + ModuleId.SPAWN, true, + ModuleId.ANNOUNCE, true, + ModuleId.CHEST, true, + ModuleId.COMMAND, true, + ModuleId.HOLOGRAM, true, + ModuleId.SCHEMATIC, true + ) + ) + ); + this.setStageSettings( + new StageSettings( + this, + Map.of( + FREEZE, 5, + CHECK, 3, + PREPARE, 30, + WAITING_PLAYERS, 10, + OPENING, 5, + OPENED, 60, + CLOSED, 5, + DELETING, 1, + CANCELLED, 1, + REBOOTED, 1 + ) + ) + ); + this.setChestSettings( + new ChestSettings( + this, + Map.of(ChestState.WAITING, 10, ChestState.COOLDOWN, 5, ChestState.OPENED, 10, ChestState.CLOSED, 10, ChestState.DELETED, 1), 3, false, false, false, false, ChestModule.OpenType.CLICK, Material.BARREL)); + this.setEffectSettings( + new EffectSettings( + this, + false, new ArrayList<>())); + this.setCommandsSettings( + new CommandsSettings( + this, + Map.of(FREEZE, new ArrayList<>(), CHECK, new ArrayList<>(), PREPARE, new ArrayList<>(), WAITING_PLAYERS, new ArrayList<>(), OPENING, new ArrayList<>(), OPENED, new ArrayList<>(), CLOSED, new ArrayList<>(), DELETING, new ArrayList<>(), CANCELLED, new ArrayList<>(), REBOOTED, new ArrayList<>()))); + this.setRewardSettings( + new RewardSettings( + this, + UniInt.of(1, 10) + ) + ); this.setModuleManager(new ModuleManager(this)); this.setKeyIds(new HashSet<>()); @@ -108,16 +216,23 @@ public Dungeon(@NotNull DungeonManager manager, @NotNull JYML cfg) { .add(Placeholders.DUNGEON_ID, this.getId()) .add(Placeholders.DUNGEON_KEY_IDS, () -> Colorizer.apply(Colors.LIGHT_PURPLE + String.join(Colors.GRAY + ", " + Colors.LIGHT_PURPLE, this.getKeyIds()))) .add(Placeholders.DUNGEON_NEXT_STAGE_IN, () -> TimeUtil.formatTimeLeft(System.currentTimeMillis() + this.getNextStageTime() * 1000L)) - .add(Placeholders.DUNGEON_KEY_NAMES, () -> Colorizer.apply(Colors.LIGHT_PURPLE + this.getKeyIds().stream().map(f -> - Objects.requireNonNull(plugin.getKeyManager().getKeyById(f)).getName()).collect(Collectors.joining(Colors.GRAY + ", " + Colors.LIGHT_PURPLE)))) + .add(Placeholders.DUNGEON_KEY_NAMES, () -> { + KeyManager keyManager = plugin.getKeyManager(); + return Colorizer.apply(Colors.LIGHT_PURPLE + this.getKeyIds() + .stream() + .filter(founder -> keyManager.getKeyById(founder) != null) + .map(f -> Objects.requireNonNull(keyManager.getKeyById(f)).getName()) + .collect(Collectors.joining(Colors.GRAY + ", " + Colors.LIGHT_PURPLE))); + }) ; } @Override public boolean load() { this.selfTick = new AtomicInteger(); - this.setSettings(MainSettings.read(this, cfg, "")); + this.setSettings(MainSettings.read(this, cfg, "Settings")); this.setPartySettings(PartySettings.read(this, cfg, "Party")); + this.setGenerationSettings(GenerationSettings.read(this, cfg, "Settings.Generation")); this.setModuleSettings(ModuleSettings.read(this, cfg, "Settings.Modules")); this.setStageSettings(StageSettings.read(this, cfg, "Settings.Stages")); this.setChestSettings(ChestSettings.read(this, cfg, "Settings.Chest")); @@ -134,6 +249,12 @@ public boolean load() { return false; } + RangeInfo rangeInfo = GeneratorConfig.LOCATION_SEARCH_RANGES.get().get(this.getWorld().getName()); + if (rangeInfo == null) { + plugin.error("Unable to load the dungeon '" + this.getId() + "' because you have not created a location generator with the world '" + this.getWorld().getName() + "'. Go to /plugins/TheDungeons/config.yml and setup the generator!"); + return false; + } + this.setKeyIds(cfg.getStringSet("Key.Ids")); this.setName(cfg.getString("Name", getId())); @@ -150,12 +271,12 @@ public boolean load() { if (item == null) item = new ItemStack(Material.DIAMOND); - if (cfg.contains(path + ".Max_Amount")){ + if (cfg.contains(path + ".Max_Amount")) { int maxAmount = cfg.getInt(path + ".Max_Amount", 3); int minAmount = cfg.getInt(path + ".Min_Amount", 1); UniInt amount = UniInt.of(minAmount, maxAmount); - cfg.remove(path+".Min_Amount"); - cfg.remove(path+".Max_Amount"); + cfg.remove(path + ".Min_Amount"); + cfg.remove(path + ".Max_Amount"); amount.write(cfg, ".Amount"); cfg.saveChanges(); } @@ -163,16 +284,30 @@ public boolean load() { List commands = cfg.getStringList(path + ".Commands"); Reward reward = new Reward(this, rewId, rewChance, amount, item, commands); - this.rewardMap.put(rewId, reward); + this.rewardsMap.put(rewId, reward); } - this.setDungeonRegion(Region.read(this, cfg, "Settings.Region")); + this.setRegion(Region.read(this, cfg, "Settings.Region")); this.setHologramSettings(HologramSettings.read(this, cfg, "Hologram.Chest")); - if (this.getDungeonRegion().isEnabled() && plugin.getRegionHandler() == null) { - this.plugin.error("Warning! Dungeon '" + getId() + "' wants to use the region system, but the Region handler is not installed!"); + if (this.getRegion().isEnabled() && plugin.getRegionHandler() == null) { + this.plugin().error("Warning! Dungeon '" + getId() + "' wants to use the region system, but the Region handler is not installed!"); } this.moduleManager = new ModuleManager(this); + + GenerationSettings generationSettings = this.getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + if (generationType.isStatic()) { + this.plugin().sendDebug("Prepare static generation settings for " + this.getId() + " dungeon"); + Location spawnLocation = generationSettings + .getSpawnLocation() + .orElse(null); + if (spawnLocation == null) { + this.plugin().error("It is impossible to load the dungeon '" + this.getId() + "', since the spawn location is not set, and the generation type is " + generationType.name()); + return false; + } + this.setLocation(spawnLocation); + } return true; } @@ -180,7 +315,7 @@ public boolean load() { public void onSave() { cfg.set("Name", getName()); - this.getDungeonRegion().write(cfg, "Settings.Region"); + this.getRegion().write(cfg, "Settings.Region"); this.getSettings().write(cfg, ""); this.getHologramSettings().write(cfg, "Hologram.Chest"); this.getPartySettings().write(cfg, "Party"); @@ -192,6 +327,7 @@ public void onSave() { this.getSchematicSettings().write(cfg, "Settings.Schematics"); this.getCommandsSettings().write(cfg, "Settings.Commands"); this.getRewardSettings().write(cfg, "Settings.Reward"); + this.getGenerationSettings().write(cfg, "Settings.Generation"); cfg.set("Rewards.List", null); for (Map.Entry e : this.getRewardsMap().entrySet()) { @@ -210,68 +346,23 @@ public void onSave() { @Override public void clear() { this.cancel(true); - this.getModuleManager().getModules().forEach(AbstractModule::shutdown); + this.getModuleManager() + .getModules() + .forEach(AbstractModule::shutdown); if (this.editor != null) { this.editor.clear(); this.editor = null; } - if (this.rewardMap != null) { - this.rewardMap.values().forEach(Reward::clear); - this.rewardMap.clear(); - this.rewardMap = null; + if (this.rewardsMap != null) { + this.rewardsMap + .values() + .forEach(Reward::clear); + this.rewardsMap.clear(); + this.rewardsMap = null; } this.selfTick.set(0); } - @NotNull - public DungeonManager getManager() { - return manager; - } - - @NotNull - public ModuleManager getModuleManager() { - return moduleManager; - } - - @NotNull - public ModuleSettings getModuleSettings() { - return moduleSettings; - } - - @NotNull - public StageSettings getStageSettings() { - return stageSettings; - } - - @NotNull - public ChestSettings getChestSettings() { - return chestSettings; - } - - @NotNull - public EffectSettings getEffectSettings() { - return effectSettings; - } - - @NotNull - public AnnounceSettings getAnnounceSettings() { - return announceSettings; - } - - @NotNull - public SchematicSettings getSchematicSettings() { - return schematicSettings; - } - - @NotNull - public CommandsSettings getCommandsSettings() { - return commandsSettings; - } - - public RewardSettings getRewardSettings() { - return rewardSettings; - } - @NotNull public DungeonMainEditor getEditor() { if (this.editor == null) { @@ -280,58 +371,16 @@ public DungeonMainEditor getEditor() { return this.editor; } - @NotNull - public Set getKeyIds() { - return keyIds; - } - - @Nullable - public Location getLocation() { - return location; - } - - @NotNull - public World getWorld() { - return world; - } - - public String getName() { - return name; - } - - @Nullable - public Cuboid getDungeonCuboid() { - return cuboid; - } - - @NotNull - public DungeonStage getStage() { - return stage; - } - - @NotNull - public MainSettings getSettings() { - return settings; - } - - @NotNull - public HologramSettings getHologramSettings() { - return hologramSettings; - } - - @NotNull - public PartySettings getPartySettings() { - return partySettings; + public Optional getLocation() { + return Optional.ofNullable(this.location); } - @NotNull - public Map getRewardsMap() { - return this.rewardMap; + public Optional getDungeonCuboid() { + return Optional.ofNullable(cuboid); } - @Nullable - public Reward getReward(@NotNull String id) { - return this.getRewardsMap().get(id.toLowerCase()); + public Optional getReward(@NotNull String id) { + return Optional.ofNullable(this.getRewardsMap().get(id.toLowerCase())); } @NotNull @@ -339,99 +388,26 @@ public Collection getRewards() { return this.getRewardsMap().values(); } - @NotNull - public AtomicInteger getSelfTick() { - return selfTick; - } - - @NotNull - public Region getDungeonRegion() { - return region; - } - public int getNextStageTime() { - return this.getStageSettings().getTime(this.getStage()) - this.getSelfTick().get(); + StageSettings settings = this.getStageSettings(); + return settings.getTime(this.getStage()) - this.getSelfTick().get(); } @Override public @NotNull PlaceholderMap getPlaceholders() { return placeholderMap; - } // - - public void setModuleManager(@Nullable ModuleManager moduleManager) { - this.moduleManager = moduleManager; } public void setKeyIds(@NotNull Set keyIds) { - this.keyIds = new HashSet<>(keyIds.stream().filter(Predicate.not(String::isEmpty)).map(String::toLowerCase).toList()); - } - - public void setWorld(@NotNull World world) { - this.world = world; + this.keyIds = keyIds + .stream() + .filter(Predicate.not(String::isEmpty)) + .map(String::toLowerCase) + .collect(Collectors.toSet()); } - public void setCuboid(@Nullable Cuboid cuboid) { - this.cuboid = cuboid; - } - - public void setStage(@NotNull DungeonStage stage) { - this.stage = stage; - } - - public void setSettings(@NotNull MainSettings settings) { - this.settings = settings; - } - - public void setHologramSettings(@NotNull HologramSettings hologramSettings) { - this.hologramSettings = hologramSettings; - } - - public void setPartySettings(@NotNull PartySettings partySettings) { - this.partySettings = partySettings; - } - - public void setLocation(@Nullable Location location) { - this.location = location; - } - - public void setName(@NotNull String name) { - this.name = name; - } - - public void setModuleSettings(@NotNull ModuleSettings moduleSettings) { - this.moduleSettings = moduleSettings; - } - - public void setStageSettings(@NotNull StageSettings stageSettings) { - this.stageSettings = stageSettings; - } - - public void setChestSettings(@NotNull ChestSettings chestSettings) { - this.chestSettings = chestSettings; - } - - public void setEffectSettings(@NotNull EffectSettings effectSettings) { - this.effectSettings = effectSettings; - } - - public void setAnnounceSettings(@NotNull AnnounceSettings announceSettings) { - this.announceSettings = announceSettings; - } - - public void setSchematicSettings(@NotNull SchematicSettings schematicSettings) { - this.schematicSettings = schematicSettings; - } - - public void setCommandsSettings(@NotNull CommandsSettings commandsSettings) { - this.commandsSettings = commandsSettings; - } - - public void setRewardSettings(RewardSettings rewardSettings) { - this.rewardSettings = rewardSettings; - } - - public void setRewardsMap(@NotNull Map rewards) { - this.rewardMap = rewards; + public void setSelfTick(int tick) { + this.selfTick.set(tick); } public void setRewards(@NotNull List rewards) { @@ -451,43 +427,39 @@ public void removeReward(@NotNull String id) { this.getRewardsMap().remove(id); } - public void setDungeonRegion(@NotNull Region region) { - this.region = region; - } - - public void setSelfTick(int tick) { - this.selfTick.set(tick); - } - public void reboot() { - this.plugin.warn("Starting the reboot '" + this.getId() + "' dungeon!"); - DungeonStage.call(this, REBOOTED, "Reboot from gui"); - DungeonStage.call(this, CANCELLED, "Reboot start"); + this.plugin().warn("Starting the reboot '" + this.getId() + "' dungeon!"); + + CompletableFuture.runAsync(() -> { + DungeonStage.call(this, REBOOTED, "Reboot from gui"); + DungeonStage.call(this, CANCELLED, "Reboot start"); + }); } public void cancel(boolean shutdown) { - if (this.getLocation() != null) { - if (plugin.getSchematicHandler() != null) { - this.plugin.getSchematicHandler().undo(this); - } - this.setLocation(null); - } + if (!shutdown) DungeonStage.call(this, FREEZE, "cancelled and refresh"); - this.setCuboid(null); + RegionHandler regionHandler = this.plugin().getRegionHandler(); + GenerationType generationType = this.getGenerationSettings().getGenerationType(); + AbstractModule.ActionType actionType = AbstractModule.ActionType.of(shutdown); - if (!shutdown) { - DungeonStage.call(this, FREEZE, "cancelled and refresh"); - } + this.getModuleManager() + .getModules() + .forEach(module -> module.tryDeactivate(actionType)); + if (regionHandler != null && this.getRegion().isCreated()) + regionHandler.delete(this); - if (plugin.getRegionHandler() != null) { - plugin.getRegionHandler().delete(this); + if (generationType.isDynamic()) { + this.setLocation(null); + this.setCuboid(null); } - this.getModuleManager().getModules().forEach(AbstractModule::deactivate); this.setSelfTick(0); } public void tick() { - this.getModuleManager().getModules().forEach(AbstractModule::update); + Collection modules = this.getModuleManager().getModules(); + modules.forEach(AbstractModule::update); + this.getStage().tick(this); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/listener/DungeonListener.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/listener/DungeonListener.java index c191afd..e114e2f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/listener/DungeonListener.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/listener/DungeonListener.java @@ -1,5 +1,6 @@ package t.me.p1azmer.plugin.dungeons.dungeon.listener; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -9,14 +10,28 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.manager.AbstractListener; import t.me.p1azmer.engine.utils.collections.AutoRemovalCollection; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; +import t.me.p1azmer.plugin.dungeons.api.events.DungeonChangeStageEvent; +import t.me.p1azmer.plugin.dungeons.api.events.DungeonDespawnEvent; +import t.me.p1azmer.plugin.dungeons.api.events.DungeonSpawnEvent; +import t.me.p1azmer.plugin.dungeons.api.handler.party.PartyHandler; import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.GenerationSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.MainSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.PartySettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import t.me.p1azmer.plugin.dungeons.lang.Lang; +import t.me.p1azmer.plugin.dungeons.utils.Cuboid; +import java.util.Collection; import java.util.concurrent.TimeUnit; public class DungeonListener extends AbstractListener { @@ -33,20 +48,14 @@ public DungeonListener(@NotNull DungeonManager manager) { public void onDungeonUse(PlayerInteractEvent event) { Player player = event.getPlayer(); Block block = event.getClickedBlock(); - if (block == null || (event.useInteractedBlock() == Event.Result.DENY && block.getType() != Material.BARRIER)) { - return; - } + if (block == null || (event.useInteractedBlock() == Event.Result.DENY && block.getType() != Material.BARRIER)) return; Dungeon dungeon = this.manager.getDungeonByBlock(block); - if (dungeon == null) { - return; - } + if (dungeon == null) return; event.setCancelled(true); - if (event.getHand() != EquipmentSlot.HAND) { - return; - } + if (event.getHand() != EquipmentSlot.HAND) return; this.manager.interactDungeon(player, dungeon, block); } @@ -54,29 +63,95 @@ public void onDungeonUse(PlayerInteractEvent event) { @EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (event.getTo() == null) { - return; - } + if (event.getTo() == null) return; + Dungeon dungeon = manager.getDungeonByLocation(event.getTo(), event.getTo().getBlock()); - if (dungeon == null) { - return; - } - if (dungeon.getSettings().isLetPlayersWhenClose()) { - return; - } - if (dungeon.getStage().isClosed() || dungeon.getStage().isPrepare()) { - player.setVelocity(player.getEyeLocation().getDirection().setY(-0.4D).multiply(-0.45D)); + if (dungeon == null) return; + + MainSettings mainSettings = dungeon.getSettings(); + if (mainSettings.isLetPlayersWhenClose()) return; + + Location eyeLocation = player.getEyeLocation(); + Vector direction = eyeLocation.getDirection(); + DungeonStage dungeonStage = dungeon.getStage(); + PartySettings partySettings = dungeon.getPartySettings(); + PartyHandler partyHandler = plugin.getPartyHandler(); + + if (dungeonStage.isClosed() || dungeonStage.isPrepare()) { + player.setVelocity(direction.setY(-0.4D).multiply(-0.45D)); if (messageCache.add(player)) plugin.getMessage(Lang.DUNGEON_BACKTRACK_PLAYER_WHEN_CLOSE).send(player); + return; } - if (plugin.getPartyHandler() != null && dungeon.getPartySettings().isEnabled()) { - if (!this.plugin.getPartyHandler().isInParty(player) || plugin.getPartyHandler().getPartySize(player) < dungeon.getPartySettings().getSize()) { - player.setVelocity(player.getEyeLocation().getDirection().setY(-0.4D).multiply(-0.45D)); + + if (partyHandler != null && partySettings.isEnabled()) { + boolean notAllowed = !partyHandler.isInParty(player) || partyHandler.getPartySize(player) < partySettings.getSize(); + if (notAllowed) { + player.setVelocity(direction.setY(-0.4D).multiply(-0.45D)); if (messageCache.add(player)) plugin.getMessage(Lang.DUNGEON_BACKTRACK_PLAYER_WHEN_NOT_PARTY) - .replace(dungeon.getPartySettings().replacePlaceholders()) + .replace(partySettings.replacePlaceholders()) .send(player); } } } + + @EventHandler + public void onSpawn(DungeonSpawnEvent event){ + Dungeon dungeon = event.getDungeon(); + Location result = event.getLocation(); + Region region = dungeon.getRegion(); + + dungeon.setLocation(result); + + Location lowerLocation = new Location(result.getWorld(), result.getBlockX(), result.getBlockY(), result.getBlockZ()); + Location upperLocation = new Location(result.getWorld(), result.getBlockX(), result.getBlockY(), result.getBlockZ()); + int size = region.getRadius(); + + lowerLocation.subtract(size, size, size); + upperLocation.add(size, size, size); + + if (lowerLocation.getY() > upperLocation.getY()) { + double temp = lowerLocation.getY(); + lowerLocation.setY(upperLocation.getY()); + upperLocation.setY(temp); + } + Cuboid cuboid = new Cuboid(lowerLocation, upperLocation); + dungeon.setCuboid(cuboid); + plugin.sendDebug(dungeon.getId() + ": Location & Cuboid success installed"); + } + + @EventHandler + public void onDespawn(DungeonDespawnEvent event){ + Dungeon dungeon = event.getDungeon(); + dungeon.setLocation(null); + dungeon.setCuboid(null); + plugin.sendDebug(dungeon.getId() + ": Location & Cuboid success removed"); + } + + @EventHandler + public void onStageChange(DungeonChangeStageEvent event){ + Dungeon dungeon = event.getDungeon(); + DungeonStage stage = event.getStage(); + String from = event.getChangeFrom(); + GenerationSettings generationSettings = dungeon.getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + + if (stage.isDeleting() || stage.isCancelled()) { + Collection modules = dungeon.getModuleManager().getModules(); + if (modules.stream() + .filter(module -> { + boolean generationAllowed = !generationType.isDynamic() && generationSettings.getSpawnLocation().isPresent(); + return !generationAllowed || !module.isImportantly(); + }) + .anyMatch(module -> !module.tryDeactivate(AbstractModule.ActionType.NATURAL))) return; + + dungeon.cancel(false); + return; + } + dungeon.setStage(stage); + dungeon.setSelfTick(0); + + plugin.sendDebug("Call the dungeon '" + dungeon.getId() + "' from " + from + ". Change stage to " + stage.name() + " from " + dungeon.getStage().name()); + } } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java index 8507a29..799182f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/AbstractModule.java @@ -1,55 +1,68 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.dungeon.DungeonManager; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.GenerationSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.ModuleSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; +import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; +@Getter public abstract class AbstractModule implements IPlaceholderMap { private final Dungeon dungeon; private final String id; private final String name; private final boolean updatable, importantly; - private final DungeonManager manager; + private final DungeonManager dungeonManager; + private final ModuleManager manager; + private final ModuleSettings settings; private Predicate canEnable; protected final JYML cfg; protected PlaceholderMap placeholderMap; // cache - private ActiveType activeType; - - public AbstractModule(@NotNull Dungeon dungeon, @NotNull String id, @NotNull Predicate canEnable, boolean updatable, boolean importantly) { + private ActionType actionType = ActionType.NATURAL; + private boolean activated; + + public AbstractModule( + @NotNull Dungeon dungeon, + @NotNull String id, + boolean updatable, + boolean importantly + ) { this.dungeon = dungeon; this.id = id; this.name = StringUtil.capitalizeUnderscored(id); this.updatable = updatable; this.importantly = importantly; - this.manager = dungeon.getManager(); - this.canEnable = canEnable; - this.cfg = dungeon().getConfig(); - this.setActiveType(ActiveType.NATURAL, false); + this.dungeonManager = dungeon.getManager(); + this.manager = dungeon.getModuleManager(); + this.settings = dungeon.getModuleSettings(); + this.cfg = getDungeon().getConfig(); + this.placeholderMap = new PlaceholderMap() .add(Placeholders.MODULE_ID, this::getId) ; } - public AbstractModule(@NotNull Dungeon dungeon, @NotNull String id, boolean updatable, boolean importantly) { - this(dungeon, id, aBoolean -> true, updatable, importantly); - } - - public AbstractModule(@NotNull Dungeon dungeon, @NotNull String id, boolean updatable, @NotNull Predicate canEnable) { - this(dungeon, id, canEnable, updatable, false); - } - - public AbstractModule(@NotNull Dungeon dungeon, @NotNull String id, boolean updatable) { - this(dungeon, id, aBoolean -> true, updatable, false); + public AbstractModule( + @NotNull Dungeon dungeon, + @NotNull String id, + boolean updatable + ) { + this(dungeon, id, updatable, false); } public void setup() { @@ -57,98 +70,81 @@ public void setup() { } public void shutdown() { - this.deactivate(); + CompletableFuture.runAsync(() -> this.tryDeactivate(ActionType.FORCE)); this.onShutdown(); } protected abstract Predicate onLoad(); - protected abstract void onShutdown(); - - public boolean activate(boolean force) { - if (!this.dungeon().getModuleSettings().isEnabled(this.getId())) { - return false; - } + protected abstract CompletableFuture onActivate(boolean force); - if (force) { - this.setActiveType(ActiveType.FORCE, true); - this.onActivate(true); - } else - this.setActiveType(ActiveType.NATURAL, this.canEnable.test(true)); - return force || this.getActiveType().isActive() && this.onActivate(false); - } + protected abstract boolean onDeactivate(boolean force); - public boolean deactivate() { - return !this.getActiveType().setActive(!this.onDeactivate()); - } + protected abstract void onShutdown(); - protected abstract boolean onActivate(boolean force); - protected abstract boolean onDeactivate(); + public CompletableFuture tryActive(@NotNull AbstractModule.ActionType actionType) { + if (!this.getSettings().isEnabled(this.getId())) return CompletableFuture.completedFuture(false); - public void update() { - if (isActive() && !isUpdatable()) return; - boolean canActivate = this.getActiveType().isForce() || canEnable.test(true); - if (canActivate && !isActive()) { - if (!activate(false) && isImportantly()) { - this.plugin().error("cannot continue this '" + this.dungeon().getId() + "' dungeon because an important module '" + this.getName() + "' failed to start!"); - this.dungeon().cancel(false); // TODO add cancelled all modules to cancel method + return switch (actionType) { + case FORCE -> { + this.actionType = actionType; + this.activated = true; + yield this.onActivate(true); } - } else if (!canActivate && isActive()) { - deactivate(); - } - } - - private void setActiveType(@NotNull ActiveType activeType, boolean active) { - activeType.setActive(active); - this.activeType = activeType; - } - - @NotNull - private ActiveType getActiveType() { - return activeType; - } - - @NotNull - public Dungeon dungeon() { - return dungeon; - } - - @NotNull - public String getId() { - return id; - } - - @NotNull - public final String getName() { - return this.name; + case NATURAL -> { + boolean active = this.activated = this.canEnable.test(true) && this.onActivate(false).join(); + this.actionType = actionType; + yield CompletableFuture.completedFuture(active); + } + case SHUTDOWN -> CompletableFuture.completedFuture(false); + }; } - @NotNull - public JYML getConfig() { - return cfg; - } + public boolean tryDeactivate(@NotNull AbstractModule.ActionType actionType) { + if (!this.isActivated()) return true; - public boolean isUpdatable() { - return updatable; - } + GenerationSettings generationSettings = this.getDungeon().getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + List moduleWhitelist = generationType.getModuleWhitelist(); - public boolean isImportantly() { - return importantly; - } + if (generationType.isStatic() && moduleWhitelist.contains(this.getId())) return false; - public boolean isActive() { - return this.getActiveType().isActive(); + return switch (actionType) { + case FORCE -> { + this.activated = false; + this.onDeactivate(true); + yield true; + } + case NATURAL -> { + this.activated = !this.onDeactivate(false); + yield !activated; + } + case SHUTDOWN -> true; + }; } - @NotNull - public DungeonManager dungeonManager() { - return manager; + public void update() { + if (isActivated() && !isUpdatable()) return; + boolean canActivate = this.getActionType().isForce() || canEnable.test(true); + + if (canActivate && !isActivated()) { + this.tryActive(this.getActionType()) + .thenAcceptAsync(aBoolean -> { + if (!aBoolean && isImportantly()) this.getDungeon().cancel(false); + }); + } else { + DungeonStage stage = this.getDungeon().getStage(); + boolean cancelled = stage.isDeleting() || stage.isCancelled(); + boolean deactivate = !canActivate && isActivated() && cancelled; + + if (deactivate) tryDeactivate(this.getActionType()); + } } @NotNull public DungeonPlugin plugin() { - return dungeon().plugin(); + return getDungeon().plugin(); } @Override @@ -157,37 +153,31 @@ public DungeonPlugin plugin() { } protected void error(@NotNull String message) { - this.plugin().error("[" + this.getName() + " Module of '" + this.dungeon().getId() + "']: " + message); + this.plugin().error("[" + this.getName() + " Module of '" + this.getDungeon().getId() + "']: " + message); } protected void warn(@NotNull String message) { - this.plugin().warn("[" + this.getName() + " Module of '" + this.dungeon().getId() + "']: " + message); + this.plugin().warn("[" + this.getName() + " Module of '" + this.getDungeon().getId() + "']: " + message); } - protected void debug(@NotNull String message) { - this.plugin().debug("[" + this.getName() + " Module of '" + this.dungeon().getId() + "']: " + message); + public void debug(@NotNull String message) { + if (Config.MODULE_DEBUG.get()) + this.plugin().debug("[" + this.getName() + " Module of '" + this.getDungeon().getId() + "']: " + message); } - private enum ActiveType { - NATURAL(false), - FORCE(false), - ; - private boolean active; - - ActiveType(boolean active) { - this.active = active; - } - - public boolean isActive() { - return active; - } - - public boolean setActive(boolean active) { - return this.active = active; - } + @Getter + public enum ActionType { + NATURAL, + FORCE, + SHUTDOWN; public boolean isForce() { return this.equals(FORCE); } + + @NotNull + public static ActionType of(boolean shutdown) { + return shutdown ? SHUTDOWN : FORCE; + } } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/ModuleManager.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/ModuleManager.java index 62fb93f..dcd5633 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/ModuleManager.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/ModuleManager.java @@ -8,14 +8,15 @@ import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.*; import java.util.Collection; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; +import java.util.stream.Collectors; public class ModuleManager extends AbstractManager { private final Dungeon dungeon; - private final Map modules = new LinkedHashMap<>(); + private final Map modules = new ConcurrentHashMap<>(); public ModuleManager(@NotNull Dungeon dungeon) { super(dungeon.plugin()); @@ -55,9 +56,7 @@ private void register(@NotNull String id, @NotNull Fu // Init module. T module = supplier.apply(id); - if (!this.getDungeon().getModuleSettings().isEnabled(id)) { - return; - } + if (!this.getDungeon().getModuleSettings().isEnabled(id)) return; module.setup(); this.modules.put(module.getId(), module); @@ -87,4 +86,24 @@ public AbstractModule getModule(@NotNull String id) { public Collection getModules() { return this.modules.values(); } + + @NotNull + public Collection getActive(){ + return this.modules + .values() + .stream() + .filter(AbstractModule::isActivated) + .collect(Collectors.toList()); + } + + public long getImportantActiveCount(){ + return this.getActive() + .stream() + .filter(AbstractModule::isImportantly) + .count(); + } + + public boolean allImportantActive(){ + return this.getImportantActiveCount() == this.getActive().size(); + } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/Placeholders.java new file mode 100644 index 0000000..5e23b2f --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/Placeholders.java @@ -0,0 +1,6 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.modules; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final String MODULE_ID = "%module_id%"; + public static final String EDITOR_MODULE_ENABLED = "%editor_module_enabled%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/AnnounceModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/AnnounceModule.java index 118301a..8cdf0d9 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/AnnounceModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/AnnounceModule.java @@ -1,20 +1,28 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; import org.bukkit.Location; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.lang.LangMessage; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.announce.impl.Announce; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.AnnounceSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; -import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; public class AnnounceModule extends AbstractModule { - public AnnounceModule(@NotNull Dungeon dungeon, @NotNull String id) { + public AnnounceModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { super(dungeon, id, true); } @@ -25,43 +33,43 @@ protected Predicate onLoad() { @Override protected void onShutdown() { - } @Override - public boolean onActivate(boolean force) { - return true; + public CompletableFuture onActivate(boolean force) { + return CompletableFuture.completedFuture(true); } @Override public void update() { - Location location = this.dungeon().getLocation(); - if (location == null || location.getWorld() == null) return; - - List announces = this.dungeon().getAnnounceSettings().getAnnounces(this.dungeon().getStage(), this.dungeon().getSelfTick().get()); + super.update(); + Location location = this.getDungeon().getLocation().orElse(null); + AnnounceSettings announceSettings = this.getDungeon().getAnnounceSettings(); + DungeonStage dungeonStage = this.getDungeon().getStage(); + int time = this.getDungeon().getSelfTick().get(); + Set announces = announceSettings.getAnnounces(dungeonStage, time); for (Announce announce : announces) { - List messages = new ArrayList<>(announce.getMessage()); - if (messages.isEmpty()) { - return; - } - messages = messages.stream().map(langMessage -> langMessage - .replace(this.dungeon().replacePlaceholders()) - .replace(this.replacePlaceholders()) - .replace(Placeholders.forLocation(location)) - ).toList(); + LangMessage langMessage = announce.getMessageWithoutPrefix() + .replace(this.getDungeon().replacePlaceholders()) + .replace(announce.replacePlaceholders()) + .replace(this.replacePlaceholders()); + + if (location != null) + langMessage = langMessage + .replace(Placeholders.forLocation(location)); - if (announce.isGlobal()) { - messages.forEach(LangMessage::broadcast); - } else { - messages.forEach(message -> location.getWorld().getPlayers().forEach(message::send)); + if (announce.isGlobal()) langMessage.broadcast(); + else if (location != null) { + List players = Objects.requireNonNull(location.getWorld()).getPlayers(); + players.forEach(langMessage::send); + debug("Message broadcasted: " + langMessage.getLocalized()); } } - super.update(); } @Override - public boolean onDeactivate() { + public boolean onDeactivate(boolean force) { return true; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/BossBarModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/BossBarModule.java deleted file mode 100644 index 5a71d45..0000000 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/BossBarModule.java +++ /dev/null @@ -1,59 +0,0 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; - -import org.bukkit.Bukkit; -import org.bukkit.boss.BossBar; -import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.engine.utils.Colorizer; -import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; - -import java.util.concurrent.CompletableFuture; -import java.util.function.Predicate; - -public class BossBarModule extends AbstractModule { - private BossBar bossBar; - - public BossBarModule(@NotNull Dungeon dungeon, @NotNull String id) { - super(dungeon, id, true); - } - - @Override - protected Predicate onLoad() { -// this.bossBar = Bukkit.createBossBar(Colorizer.apply(this.dungeon().replacePlaceholders().apply(Config.BOSSBAR_TITLE.get())), Config.BOSSBAR_COLOR.get(), Config.BOSSBAR_STYLE.get()); // rewrite for dungeon self bossbar - return aBoolean -> dungeon().getStage().isPrepare(); - } - - @Override - protected void onShutdown() { - if (this.bossBar != null) { - CompletableFuture.runAsync(this.bossBar::removeAll); - this.bossBar = null; - } - } - - @Override - public boolean onActivate(boolean force) { - if (this.bossBar == null) { - //if (!force)return false; - //this.bossBar = Bukkit.createBossBar(Colorizer.apply(this.dungeon().replacePlaceholders().apply(Config.BOSSBAR_TITLE.get())), Config.BOSSBAR_COLOR.get(), Config.BOSSBAR_STYLE.get()); // rewrite for dungeon self bossbar - return false; - } - - this.dungeon().getWorld().getPlayers().forEach(this.bossBar::addPlayer); - return true; - } - - @Override - public void update() { - if (this.bossBar == null) return; -// this.bossBar.setProgress(this.dungeon().getNextStageTime() / 100F); - - } - - @Override - public boolean onDeactivate() { - CompletableFuture.runAsync(this.bossBar::removeAll); - return true; - } -} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/ChestModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/ChestModule.java index 2cd4d1c..5fecf15 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/ChestModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/ChestModule.java @@ -1,214 +1,189 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; +import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.metadata.FixedMetadataValue; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import t.me.p1azmer.plugin.dungeons.Keys; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; -import t.me.p1azmer.plugin.dungeons.api.schematic.SchematicHandler; -import t.me.p1azmer.plugin.dungeons.config.Config; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Reward; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestMenu; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestBlock; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestMenu; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; -import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleId; +import t.me.p1azmer.plugin.dungeons.dungeon.reward.Reward; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.ChestSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import t.me.p1azmer.plugin.dungeons.utils.Cuboid; -import java.io.File; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import java.util.stream.Collectors; +@Getter public class ChestModule extends AbstractModule { - private Map chestMap; - private Map chestBlocksMap; + private Map chestMap; private List blocks; - public ChestModule(@NotNull Dungeon dungeon, @NotNull String id) { - super(dungeon, id, false); + public ChestModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { + super(dungeon, id, true); } @Override protected Predicate onLoad() { this.chestMap = new LinkedHashMap<>(); - this.chestBlocksMap = new LinkedHashMap<>(); this.blocks = new LinkedList<>(); return aBoolean -> { - SchematicModule schematicModule = dungeon().getModuleManager().getModule(SchematicModule.class).orElse(null); - if (schematicModule == null) { - this.error("The '" + this.getId() + "' module cannot be loaded because the '" + ModuleId.SCHEMATIC + "' module is disabled or not loaded!"); - return false; - } - - SchematicHandler handler = plugin().getSchematicHandler(); - if (handler == null) { - this.error("The '" + this.getId() + "' module cannot be loaded because the Schematic Handler not installed!"); - return false; - } - - for (File schematicFile : schematicModule.getSchematicFiles()) { - String schematicName = schematicFile.getName().replace(Config.DIR_SCHEMATICS, ""); - - if (!handler.containsChestBlock(dungeon(), schematicFile)) { - this.error("Schematic '" + schematicName + "' not contains Chest Material (" + dungeon().getChestSettings().getMaterial().name() + "). Removed from list"); - continue; - } - int chestBlocks = handler.getAmountOfChestBlocks(dungeon(), schematicFile); - if (chestBlocks == 0) { - plugin().warn("Attention! Schematics '" + schematicName + "' does not contain the blocks you specified as a chest!"); - continue; - } - this.chestBlocksMap.put(schematicName, chestBlocks); - } - return this.dungeon().getStage().isOpening() || this.dungeon().getStage().isOpened() || this.dungeon().getStage().isWaitingPlayers(); + DungeonStage dungeonStage = this.getDungeon().getStage(); + SpawnModule spawnModule = this.getManager().getModule(SpawnModule.class).orElse(null); + boolean spawnModuleAllowed = spawnModule != null && spawnModule.isSpawned(); + return dungeonStage.isOpening() && spawnModuleAllowed; }; } @Override - protected void onShutdown() { - - } + protected void onShutdown() {} @Override - public boolean onActivate(boolean force) { - Location location = dungeon().getLocation(); + public CompletableFuture onActivate(boolean force) { + Location location = getDungeon().getLocation().orElse(null); if (location == null) { - return false; + this.warn("Dungeon location is null"); + return CompletableFuture.completedFuture(false); } - Material material = dungeon().getChestSettings().getMaterial(); + ChestSettings chestSettings = this.getDungeon().getChestSettings(); + Material material = chestSettings.getMaterial(); if (material.isAir()) { - this.error("In the dungeon '" + dungeon().getId() + "' chest-block is set as air, change the settings!"); - return false; + this.warn("Chest material is air"); + return CompletableFuture.completedFuture(false); } - Cuboid cuboid = dungeon().getDungeonCuboid(); + Cuboid cuboid = getDungeon().getDungeonCuboid().orElse(null); if (cuboid == null) { - this.error("Dungeon cuboid is null!"); - return false; + this.warn("Dungeon cuboid is null"); + return CompletableFuture.completedFuture(false); } - this.blocks.addAll(cuboid.getBlocks().stream().filter(f -> f.getType().equals(material)).peek(block -> block.setMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey(), new FixedMetadataValue(plugin(), this.dungeon().getId()))).toList()); + FixedMetadataValue metadataValue = new FixedMetadataValue(plugin(), this.getDungeon().getId()); + this.blocks.addAll( + cuboid.getBlocks() + .stream() + .filter(f -> f.getType().equals(material)) + .peek(block -> block.setMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey(), metadataValue)) + .toList() + ); if (this.blocks.isEmpty()) { - this.error("Not found any Chest Block on dungeon location!"); - return false; + this.warn("No chest blocks found"); + return CompletableFuture.completedFuture(false); } - Map rewards = this.dungeon().getRewards().stream().collect(Collectors.toMap(reward -> reward, Reward::getChance)); + Map rewards = this.getDungeon() + .getRewards() + .stream() + .collect(Collectors.toMap(reward -> reward, Reward::getChance)); + + + for (Block block : this.blocks) this.setupMenu(block, rewards); - if (!rewards.isEmpty()) { - if (this.dungeon().getChestSettings().isSeparateMenu()) { - for (Block block : blocks) { - this.setupMenu(block, rewards); - } - } else { - blocks.forEach(block -> this.setupMenu(block, rewards)); - } - } RegionHandler regionHandler = plugin().getRegionHandler(); - if (regionHandler != null) { - regionHandler.create(dungeon()); - } + if (regionHandler != null) regionHandler.create(getDungeon()); - return true; + return CompletableFuture.completedFuture(true); } @Override - public boolean onDeactivate() { - if (this.getChests().stream().anyMatch(chest -> chest.getState().isOpen() || chest.getState().isCooldown())) + public boolean onDeactivate(boolean force) { + if (!force && this.getChests().stream().anyMatch(chest -> chest.getState().isOpen() || chest.getState().isCooldown())) return false; this.getChests() .stream() .filter(Objects::nonNull) - .forEach(DungeonChestBlock::clear); - this.getChestMap().clear(); - if (!this.getBlocks().isEmpty()) { - this.getBlocks() - .stream().filter(block -> block.hasMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey())) - .forEach(block -> block.removeMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey(), plugin())); - this.getBlocks().clear(); - } + .forEach(ChestBlock::clear); + this.getBlocks() + .stream().filter(block -> block.hasMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey())) + .forEach(block -> block.removeMetadata(Keys.DUNGEON_CHEST_BLOCK.getKey(), plugin())); + + this.getBlocks().clear(); + this.getChestMap().clear(); return true; } @Override public void update() { - for (DungeonChestBlock chest : new HashSet<>(this.getChests())) { + super.update(); + for (ChestBlock chest : new HashSet<>(this.getChests())) { if (chest.getState().isDeleted()) { chest.clear(); this.getChestMap().remove(chest.getBlock(), chest); continue; } int time = chest.getCurrentTick(); - DungeonChestState state = chest.getState(); + ChestState state = chest.getState(); if (state.isWaiting() && chest.getNextStateTime() == 0 || state.isCooldown() && chest.getNextStateTime() == 0) { - chest.setChestState(DungeonChestState.CLOSED); + chest.setState(ChestState.CLOSED); time = -1; } else if (state.isClosed() && chest.getNextStateTime() == 0) { - chest.setChestState(DungeonChestState.OPENED); + chest.setState(ChestState.OPENED); time = -1; } else if (state.isOpen() && chest.getNextStateTime() == 0) { - chest.setChestState(DungeonChestState.DELETED); + chest.setState(ChestState.DELETED); time = -1; this.getChestMap().remove(chest.getBlock(), chest); chest.clear(); } chest.tick(this.plugin(), ++time); } - super.update(); } @NotNull - public Map getChestBlocksMap() { - return chestBlocksMap; - } - - @NotNull - public Map getChestMap() { + public Map getChestMap() { return this.chestMap; } @NotNull - public Collection getChests() { + public Collection getChests() { return this.getChestMap().values(); } @NotNull - public Collection getActiveChests() { - return this.getChests().stream().filter(f -> f.getState().isOpen() || f.getState().isClosed()).collect(Collectors.toList()); - } - - @NotNull - public List getBlocks() { - return blocks; + public Collection getActiveChests() { + return this.getChests() + .stream() + .filter(f -> f.getState().isOpen() || f.getState().isClosed()) + .collect(Collectors.toList()); } - @Nullable - public DungeonChestBlock getChestByBlock(@NotNull Block block) { - return this.getChestMap().get(block); + public Optional getChestByBlock(@NotNull Block block) { + return Optional.ofNullable(this.getChestMap().get(block)); } - @Nullable - public Block getBlock(@NotNull Location location) { - return this.blocks.stream().filter(f -> f.getLocation().equals(location)).findFirst().orElse(null); + public Optional getBlock(@NotNull Location location) { + return this.blocks + .stream() + .filter(f -> f.getLocation().equals(location)) + .findFirst(); } public void setupMenu(@NotNull Block block, @NotNull Map rewards) { - DungeonChestMenu menu = new DungeonChestMenu(block, this.dungeon(), rewards); - DungeonChestBlock dungeonChestBlock = new DungeonChestBlock(this.dungeon(), block, block.getLocation(), menu); - this.getChestMap().put(block, dungeonChestBlock); + ChestMenu menu = new ChestMenu(block, this.getDungeon(), rewards); + ChestBlock chestBlock = new ChestBlock(this.getDungeon(), block, block.getLocation(), menu); + this.getChestMap().put(block, chestBlock); + this.debug("GUI for '" + block.getType() + "' installed"); } + // TODO: Change to a separate class to handle more actions public enum OpenType { CLICK, TIMER; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java index 96f0835..b8ecc0c 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/CommandModule.java @@ -9,53 +9,52 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; public class CommandModule extends AbstractModule { - private Set stagesCache; + private Set stagesCache = new LinkedHashSet<>(); - public CommandModule(@NotNull Dungeon dungeon, @NotNull String id) { + public CommandModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { super(dungeon, id, true); } @Override protected Predicate onLoad() { - this.stagesCache = new LinkedHashSet<>(); return aBoolean -> true; } @Override protected void onShutdown() { - if (this.stagesCache != null) { - this.stagesCache.clear(); - this.stagesCache = null; - } + this.stagesCache.clear(); } @Override - public boolean onActivate(boolean force) { - return true; + public CompletableFuture onActivate(boolean force) { + return CompletableFuture.completedFuture(true); } @Override public void update() { - List commands = this.dungeon().getCommandsSettings().getCommands(this.dungeon().getStage()); - if (!commands.isEmpty() && !this.stagesCache.contains(this.dungeon().getStage())) { + super.update(); + List commands = this.getDungeon().getCommandsSettings().getCommands(this.getDungeon().getStage()); + if (!commands.isEmpty() && !this.stagesCache.contains(this.getDungeon().getStage())) { if (this.stagesCache == null) this.stagesCache = new LinkedHashSet<>(); - stagesCache.add(this.dungeon().getStage()); + stagesCache.add(this.getDungeon().getStage()); commands.forEach(command -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)); + debug("Commands executed"); } - super.update(); } @Override - public boolean onDeactivate() { - if (this.stagesCache != null) { - this.stagesCache.clear(); - } + public boolean onDeactivate(boolean force) { + this.stagesCache.clear(); return true; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/HologramModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/HologramModule.java index 5b34265..c60d3f6 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/HologramModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/HologramModule.java @@ -1,49 +1,52 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; -import org.bukkit.Location; import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.plugin.dungeons.api.hologram.HologramHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.hologram.HologramHandler; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleManager; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; public class HologramModule extends AbstractModule { private ChestModule chestModule; private final HologramHandler handler; - public HologramModule(@NotNull Dungeon dungeon, @NotNull String id) { + + public HologramModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { super(dungeon, id, true); this.handler = plugin().getHologramHandler(); } @Override protected Predicate onLoad() { - this.chestModule = dungeon().getModuleManager().getModule(ChestModule.class).orElse(null); - return aBoolean -> (this.dungeon().getStage().isOpened() || this.dungeon().getStage().isOpening() || this.dungeon().getStage().isWaitingPlayers()) - && handler != null && this.chestModule != null && !this.chestModule.getChests().isEmpty() && dungeon().getLocation() != null; + return aBoolean -> { + Optional module = this.getManager().getModule(ChestModule.class); + this.chestModule = module.orElse(null); + return handler != null && this.chestModule != null && !this.chestModule.getChests().isEmpty(); + }; } @Override protected void onShutdown() { - if (this.chestModule != null){ - this.chestModule = null; - } + this.chestModule = null; } @Override - public boolean onActivate(boolean force) { - Location location = this.dungeon().getLocation(); - if (location == null || handler == null){ - return false; - } - handler.create(this.dungeon(), this.chestModule); - return true; + public CompletableFuture onActivate(boolean force) { + this.debug("Starting initialize holograms"); + handler.create(this.getDungeon(), this.chestModule); + + return CompletableFuture.completedFuture(true); } @Override - public boolean onDeactivate() { - if (handler == null) return true; - handler.delete(this.dungeon()); + public boolean onDeactivate(boolean force) { + if (handler != null) handler.delete(this.getDungeon()); return true; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/MobModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/MobModule.java index 029ea38..6557cdb 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/MobModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/MobModule.java @@ -1,24 +1,40 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; +import org.bukkit.Location; import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.utils.LocationUtil; import t.me.p1azmer.plugin.dungeons.api.mob.MobFaction; import t.me.p1azmer.plugin.dungeons.api.mob.MobList; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; +import t.me.p1azmer.plugin.dungeons.mob.MobManager; +import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; public class MobModule extends AbstractModule { private MobList mobList; + private MobManager manager; - public MobModule(@NotNull Dungeon dungeon, @NotNull String id) { - super(dungeon, id, false, false); + public MobModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { + super(dungeon, id, true); } @Override protected Predicate onLoad() { this.mobList = new MobList(); - return aBoolean -> dungeon().getStage().isOpened(); + this.manager = plugin().getMobManager(); + + return aBoolean -> { + DungeonStage stage = getDungeon().getStage(); + return stage.isOpened(); + }; } @Override @@ -30,19 +46,42 @@ protected void onShutdown() { } @Override - protected boolean onActivate(boolean force) { - if (!dungeon().getSettings().getMobMap().isEmpty()) { - dungeon().getSettings().getMobMap().forEach((mobId, amount) -> { + protected CompletableFuture onActivate(boolean force) { + Map mobMap = getDungeon().getSettings().getMobMap(); + MobManager mobManager = plugin().getMobManager(); + if (!mobMap.isEmpty()) { + mobMap.forEach((mobId, amount) -> { for (int i = 0; i < amount; i++) { - plugin().getMobManager().spawnMob(dungeon(), MobFaction.ENEMY, mobId, this.mobList); + plugin().runTask(sync -> mobManager.spawnMob(getDungeon(), MobFaction.ENEMY, mobId, this.mobList)); } }); - } - return true; + this.debug("Mob spawned"); + } else this.debug("No mobs to spawn"); + return CompletableFuture.completedFuture(true); + } + + @Override + public void update() { + this.getMobs() + .getAll() + .forEach(entity -> { + Location location = this.getDungeon().getLocation().orElse(null); + if (location == null) { + this.manager.killMob(entity); + return; + } + Region dungeonRegion = getDungeon().getRegion(); + Location entityLocation = entity.getLocation(); + + if (entityLocation.distance(location) > dungeonRegion.getRadius()) { // TODO: write safe damage with radius and target + Location groundBlock = LocationUtil.getFirstGroundBlock(location); + entity.teleport(groundBlock); + } + }); } @Override - protected boolean onDeactivate() { + protected boolean onDeactivate(boolean force) { this.killMobs(); return true; } @@ -62,7 +101,8 @@ public MobList getMobs() { if (this.mobList == null) this.mobList = new MobList(); - this.mobList.getEnemies().removeIf(mob -> !mob.isValid() || mob.isDead()); + this.mobList.getEnemies() + .removeIf(mob -> !mob.isValid() || mob.isDead()); return mobList; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SchematicModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SchematicModule.java index 963b59d..a4766d8 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SchematicModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SchematicModule.java @@ -1,29 +1,39 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; +import lombok.Getter; import org.bukkit.Location; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.utils.FileUtil; import t.me.p1azmer.engine.utils.random.Rnd; -import t.me.p1azmer.plugin.dungeons.api.schematic.SchematicHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.schematic.SchematicHandler; import t.me.p1azmer.plugin.dungeons.config.Config; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.GenerationSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import java.util.stream.Collectors; +@Getter public class SchematicModule extends AbstractModule { private boolean generated; private List schematicFiles; private List schematics; private File cachedSchematicFile; - private SchematicHandler handler; + private final SchematicHandler handler; - public SchematicModule(@NotNull Dungeon dungeon, @NotNull String id) { + public SchematicModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { super(dungeon, id, false, true); this.handler = plugin().getSchematicHandler(); } @@ -32,8 +42,12 @@ public SchematicModule(@NotNull Dungeon dungeon, @NotNull String id) { protected Predicate onLoad() { this.generated = false; this.schematicFiles = new ArrayList<>(); - this.schematics = this.dungeon().getSchematicSettings().getSchematics(); - this.setSchematicFiles(schematics.stream().map(this::getFileByName).collect(Collectors.toList())); + this.schematics = this.getDungeon().getSchematicSettings().getSchematics(); + this.setSchematicFiles( + schematics.stream() + .map(this::getFileByName) + .collect(Collectors.toList()) + ); for (File schematicFile : new ArrayList<>(this.getSchematicFiles())) { if (schematicFile != null && !schematicFile.exists()) { @@ -52,53 +66,64 @@ protected Predicate onLoad() { } } } - return aBoolean -> handler != null && !this.getSchematicFiles().isEmpty() && !this.schematics.isEmpty() - && (dungeon().getStage().isCheck() || dungeon().getStage().isPrepare()) && dungeon().getModuleManager().getModule(SpawnModule.class).isPresent() - && dungeon().getModuleManager().getModule(SpawnModule.class).get().isSpawned() && !isGenerated(); + + return aBoolean -> { + Optional spawnModule = this.getManager().getModule(SpawnModule.class); + DungeonStage dungeonStage = getDungeon().getStage(); + GenerationSettings generationSettings = this.getDungeon().getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + Optional spawnLocation = generationSettings.getSpawnLocation(); + + boolean allowedWithGeneration = !generationType.isDynamic() && spawnLocation.isPresent(); + boolean hasSchematic = handler != null && !this.getSchematicFiles().isEmpty() && !this.schematics.isEmpty(); + boolean stageAllowed = dungeonStage.isCheck() || dungeonStage.isPrepare(); + boolean spawnModuleIsReady = spawnModule.isPresent() && spawnModule.get().isSpawned(); + + if (allowedWithGeneration && hasSchematic) return true; + return hasSchematic && stageAllowed && spawnModuleIsReady && !isGenerated(); + + }; } @Override protected void onShutdown() { this.generated = false; - handler.undo(this.dungeon()); + handler.undo(this.getDungeon()); this.cachedSchematicFile = null; } @Override - public boolean onActivate(boolean force) { - Location location = dungeon().getLocation(); + public CompletableFuture onActivate(boolean force) { + Location location = this.getDungeon().getLocation().orElse(null); if (location == null) { this.error("Cannot found Dungeon Location!"); - return false; + return CompletableFuture.completedFuture(false); } this.cachedSchematicFile = Rnd.get(this.getSchematicFiles()); this.generated = true; - return handler.paste(this.dungeon(), this.cachedSchematicFile); + return handler.paste(this.getDungeon(), this.cachedSchematicFile); } @Override - public boolean onDeactivate() { - if (dungeon().getModuleManager().getModule(ChestModule.class).isPresent() && !dungeon().getModuleManager().getModule(ChestModule.class).get().onDeactivate()) - return false; + public boolean onDeactivate(boolean force) { + GenerationSettings generationSettings = this.getDungeon().getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + Optional spawnLocation = generationSettings.getSpawnLocation(); + Optional module = this.getManager().getModule(ChestModule.class); + + if (!generationType.isDynamic() && spawnLocation.isPresent()) return false; + if (module.isPresent() && !module.get().tryDeactivate(ActionType.FORCE)) return false; + + if (!this.generated) return true; - if (!this.generated) { - return true; // return true btw - } this.generated = false; - handler.undo(this.dungeon()); this.cachedSchematicFile = null; + + CompletableFuture.runAsync(() -> handler.undo(this.getDungeon())); return true; } - public boolean isGenerated() { - return generated; - } - - @NotNull - public List getSchematicFiles() { - return schematicFiles; - } public void setSchematicFiles(@NotNull List schematicFiles) { this.schematicFiles = schematicFiles; @@ -106,9 +131,8 @@ public void setSchematicFiles(@NotNull List schematicFiles) { @NotNull public File getFileByName(@NotNull String name) { - if (!name.endsWith(".schem")) { - name = name + ".schem"; - } + if (!name.endsWith(".schem")) name = name + ".schem"; + return new File(plugin().getDataFolder() + Config.DIR_SCHEMATICS + name); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java index 3cda125..cd68ce3 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/modules/impl/SpawnModule.java @@ -1,5 +1,7 @@ package t.me.p1azmer.plugin.dungeons.dungeon.modules.impl; +import lombok.Getter; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; @@ -8,53 +10,122 @@ import t.me.p1azmer.engine.Version; import t.me.p1azmer.engine.utils.LocationUtil; import t.me.p1azmer.engine.utils.random.Rnd; -import t.me.p1azmer.plugin.dungeons.api.events.DungeonDeleteEvent; +import t.me.p1azmer.plugin.dungeons.api.events.DungeonDespawnEvent; import t.me.p1azmer.plugin.dungeons.api.events.DungeonSpawnEvent; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.AbstractModule; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.GenerationSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import t.me.p1azmer.plugin.dungeons.generator.RangeInfo; import t.me.p1azmer.plugin.dungeons.generator.config.GeneratorConfig; -import t.me.p1azmer.plugin.dungeons.utils.Cuboid; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; /* Thank you very much for the code idea: discord: b3cksgold */ +@Getter public class SpawnModule extends AbstractModule { private boolean spawned; - public SpawnModule(@NotNull Dungeon dungeon, @NotNull String id) { + public SpawnModule( + @NotNull Dungeon dungeon, + @NotNull String id + ) { super(dungeon, id, false, true); } @Override protected Predicate onLoad() { this.spawned = false; - return aBoolean -> dungeon().getStage().isCheck() && !isSpawned(); + return aBoolean -> { + DungeonStage stage = getDungeon().getStage(); + GenerationSettings generationSettings = this.getDungeon().getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + Optional spawnLocation = generationSettings.getSpawnLocation(); + boolean allowedWithGeneration = !generationType.isDynamic() && spawnLocation.isPresent(); + + return stage.isCheck() && !isSpawned() || allowedWithGeneration; + }; } @Override protected void onShutdown() { + this.spawned = false; + } + + @Override + public CompletableFuture onActivate(boolean force) { + if (isSpawned()) { + this.debug("Dungeon is already spawned on world"); + return CompletableFuture.completedFuture(force); + } + + GenerationSettings generationSettings = this.getDungeon().getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + Optional spawnLocation = generationSettings.getSpawnLocation(); + if (!generationType.isDynamic()) { + if (spawnLocation.isPresent()) { + return CompletableFuture.completedFuture(this.spawn(spawnLocation.get())); + } + + this.error("The location of the dungeon is not set in the generation settings"); + return CompletableFuture.completedFuture(false); + } + + return CompletableFuture.completedFuture(foundedRandomLocation(force)); } @Override - public boolean onActivate(boolean force) { - if (isSpawned()) return force; + public boolean onDeactivate(boolean force) { + GenerationSettings generationSettings = this.getDungeon().getGenerationSettings(); + GenerationType generationType = generationSettings.getGenerationType(); + Optional spawnLocation = generationSettings.getSpawnLocation(); + Optional schematicModule = this.getManager().getModule(SchematicModule.class); + + if (!generationType.isDynamic() && spawnLocation.isPresent()) return false; + if (schematicModule.isPresent() && !schematicModule.get().tryDeactivate(ActionType.FORCE)) return false; + + DungeonDespawnEvent event = new DungeonDespawnEvent(this.getDungeon()); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + this.debug("Unable to deactivate the '" + this.getId() + "' module due to an Event"); + return false; + } + + this.spawned = false; + return true; + } + + public boolean spawn(@NotNull Location result) { + DungeonSpawnEvent event = new DungeonSpawnEvent(this.getDungeon(), result); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + this.debug("Unable to spawn the '" + this.getId() + "' module due to an Event"); + return false; + } + return this.spawned = true; + } - RangeInfo rangeInfo = GeneratorConfig.LOCATION_SEARCH_RANGES.get().get(dungeon().getWorld().getName()); + // TODO: rewrite with chunks for optimization + private boolean foundedRandomLocation(boolean force) { + RangeInfo rangeInfo = GeneratorConfig.LOCATION_SEARCH_RANGES.get().get(getDungeon().getWorld().getName()); if (rangeInfo == null) { - this.error("Unable to start dungeon spawn '" + dungeon().getId() + "' because the location generator for this '" + dungeon().getWorld().getName() + "' world is not set!"); + this.error("Unable to start dungeon spawn '" + getDungeon().getId() + "' because the location generator for this '" + getDungeon().getWorld().getName() + "' world is not set!"); return false; } - World world = this.dungeon().getWorld(); + World world = this.getDungeon().getWorld(); int originX = rangeInfo.getStartX(); - int originY = this.dungeon().getSchematicSettings().isUnderground() ? world.getMinHeight() : world.getMaxHeight(); + boolean underground = this.getDungeon().getSchematicSettings().isUnderground(); + int originY = underground ? world.getMinHeight() : world.getMaxHeight(); int originZ = rangeInfo.getStartZ(); int minOffset = -rangeInfo.getDistanceMin(); @@ -87,17 +158,20 @@ public boolean onActivate(boolean force) { // X and Z are randomized, now just an example for handling Y int modifiedY = originY; - if (this.dungeon().getSchematicSettings().isUnderground()) + if (underground) modifiedY += Rnd.get(Version.isAbove(Version.V1_18_R2) ? 30 : 10); - Location result = this.dungeon().getSchematicSettings().isUnderground() ? new Location(world, randomX, modifiedY, randomZ) : LocationUtil.getFirstGroundBlock(new Location(world, randomX, modifiedY, randomZ)); + Location possibleLoc = new Location(world, randomX, modifiedY, randomZ); + + Location groundBlock = LocationUtil.getFirstGroundBlock(possibleLoc); + Location result = underground ? possibleLoc : groundBlock; Block block = result.getBlock(); Biome biome = block.getBiome(); if (!force) { RegionHandler handler = plugin().getRegionHandler(); - if (handler != null){ - if (!handler.isValidLocation(result)){ + if (handler != null) { + if (!handler.isValidLocation(result)) { return false; } } @@ -120,55 +194,7 @@ public boolean onActivate(boolean force) { return false; } } - return this.spawn(result); - } - - @Override - public boolean onDeactivate() { - if (dungeon().getModuleManager().getModule(SchematicModule.class).isPresent() && !dungeon().getModuleManager().getModule(SchematicModule.class).get().onDeactivate()) return false; - - DungeonDeleteEvent event = new DungeonDeleteEvent(this.dungeon()); - plugin().getPluginManager().callEvent(event); - if (event.isCancelled()) { - this.debug("Unable to deactivate the '"+this.getId()+"' module due to an Event"); - return false; - } - this.spawned = false; - this.dungeon().setLocation(null); - this.dungeon().setCuboid(null); - return true; - } - - public boolean spawn(@NotNull Location result){ - DungeonSpawnEvent event = new DungeonSpawnEvent(this.dungeon(), result); - plugin().getPluginManager().callEvent(event); - if (event.isCancelled()){ - this.error("Cancelled by Event"); - return false; - } - result = event.getLocation(); - this.dungeon().setLocation(result); - - Location lowerLocation = new Location(result.getWorld(), result.getBlockX(), result.getBlockY(), result.getBlockZ()); - Location upperLocation = new Location(result.getWorld(), result.getBlockX(), result.getBlockY(), result.getBlockZ()); - int size = dungeon().getDungeonRegion().getRadius(); - - lowerLocation.subtract(size, size, size); - upperLocation.add(size, size, size); - - if (lowerLocation.getY() > upperLocation.getY()) { - double temp = lowerLocation.getY(); - lowerLocation.setY(upperLocation.getY()); - upperLocation.setY(temp); - } - Cuboid cuboid = new Cuboid(lowerLocation, upperLocation); - this.dungeon().setCuboid(cuboid); - this.spawned = true; - return true; - } - - public boolean isSpawned() { - return spawned; + return this.spawn(result); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Placeholders.java new file mode 100644 index 0000000..b3df942 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Placeholders.java @@ -0,0 +1,8 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.region; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final String REGION_ENABLED = "%region_enabled%"; + public static final String REGION_NAME = "%region_name%"; + public static final String REGION_RADIUS = "%region_radius%"; + public static final String REGION_FLAGS = "%region_flags%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Region.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Region.java similarity index 60% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Region.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Region.java index 5fd8d18..1cb757b 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Region.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/region/Region.java @@ -1,19 +1,21 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.categories; +package t.me.p1azmer.plugin.dungeons.dungeon.region; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.lang.LangManager; import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.Colors; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import java.util.List; -public class Region extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class Region extends AbstractSettings { private final PlaceholderMap placeholderMap; @@ -25,11 +27,13 @@ public class Region extends AbstractSettings implements IPlaceholderMap { // cache private boolean created = false; - public Region(@NotNull Dungeon dungeon, - boolean enabled, - @NotNull String name, - int radius, - @NotNull List flags) { + public Region( + @NotNull Dungeon dungeon, + boolean enabled, + @NotNull String name, + int radius, + @NotNull List flags + ) { super(dungeon); this.enabled = enabled; this.name = name; @@ -60,59 +64,13 @@ public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".Flags", this.getFlags()); } - @NotNull - public Dungeon getDungeon() { - return dungeon; - } - - public boolean isEnabled() { - return enabled; - } - - @NotNull - public String getName() { - return name; - } - @NotNull public String getNameRaw() { - return this.getDungeon().getId() + "_" + this.getName() + "_" + this.getDungeon().plugin().getName(); - } - - public int getRadius() { - return radius; - } - - @NotNull - public List getFlags() { - return flags; - } - public boolean isCreated() { - return created; + return this.dungeon().getId() + "_" + this.getName() + "_" + this.dungeon().plugin().getName(); } @Override public @NotNull PlaceholderMap getPlaceholders() { return this.placeholderMap; } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public void setName(@NotNull String name) { - this.name = name; - } - - public void setRadius(int radius) { - this.radius = radius; - } - - public void setFlags(@NotNull List flags) { - this.flags = flags; - } - - public void setCreated(boolean created) { - this.created = created; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Placeholders.java new file mode 100644 index 0000000..cbef9ab --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Placeholders.java @@ -0,0 +1,11 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.reward; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final String REWARD_ID = "%reward_id%"; + public static final String REWARD_CHANCE = "%reward_chance%"; + public static final String REWARD_MAX_AMOUNT = "%reward_amount_max%"; + public static final String REWARD_MIN_AMOUNT = "%reward_amount_min%"; + public static final String REWARD_LIMIT_MAX = "%reward_limit_max%"; + public static final String REWARD_LIMIT_MIN = "%reward_limit_min%"; + public static final String REWARD_COMMANDS = "%reward_commands%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Reward.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Reward.java similarity index 80% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Reward.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Reward.java index ed5c94c..f48559c 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/categories/Reward.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/reward/Reward.java @@ -1,5 +1,7 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.categories; +package t.me.p1azmer.plugin.dungeons.dungeon.reward; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -8,7 +10,6 @@ import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.utils.NumberUtil; import t.me.p1azmer.engine.utils.values.UniInt; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; import t.me.p1azmer.plugin.dungeons.dungeon.editor.reward.DungeonRewardMainEditor; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; @@ -16,6 +17,8 @@ import java.util.ArrayList; import java.util.List; +@Getter +@Setter public class Reward extends AbstractSettings implements ICleanable, IPlaceholderMap { private final String id; @@ -28,7 +31,8 @@ public class Reward extends AbstractSettings implements ICleanable, IPlaceholder private final PlaceholderMap placeholderMap; public Reward(@NotNull Dungeon dungeon, @NotNull String id) { - this(dungeon, + this( + dungeon, id, 25, UniInt.of(1, 3), @@ -80,48 +84,17 @@ public void clear() { } } - @NotNull - public String getId() { - return this.id; - } - - public double getChance() { - return this.chance; - } - - @NotNull - public UniInt getAmount() { - return amount; - } - @NotNull public ItemStack getItem() { return new ItemStack(item); } - @NotNull - public List getCommands() { - return commands; - } - @Override @NotNull public PlaceholderMap getPlaceholders() { return this.placeholderMap; } - public void setChance(double chance) { - this.chance = chance; - } - - public void setAmount(@NotNull UniInt amount) { - this.amount = amount; - } - - public void setItem(@NotNull ItemStack item) { - this.item = item; - } - public void setCommands(@NotNull List commands) { this.commands = new ArrayList<>(commands); this.commands.removeIf(String::isEmpty); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/MainSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/MainSettings.java deleted file mode 100644 index efad72c..0000000 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/MainSettings.java +++ /dev/null @@ -1,123 +0,0 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; - -import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.engine.api.config.JYML; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; -import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; -import t.me.p1azmer.engine.lang.LangManager; -import t.me.p1azmer.engine.utils.Colorizer; -import t.me.p1azmer.engine.utils.Colors; -import t.me.p1azmer.plugin.dungeons.Placeholders; -import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; -import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -public class MainSettings extends AbstractSettings implements IPlaceholderMap { - private boolean enabled; - private boolean clickTimer; - private boolean letPlayersWhenClose; - - private int minimalOnline; - private Map mobMap; - - private final PlaceholderMap placeholderMap; - - public MainSettings(@NotNull Dungeon dungeon, - boolean enabled, boolean clickTimer, boolean letPlayersWhenClose, - int minimalOnline, - @NotNull Map mobMap) { - super(dungeon); - this.dungeon = dungeon; - this.enabled = enabled; - this.clickTimer = clickTimer; - this.minimalOnline = minimalOnline; - this.letPlayersWhenClose = letPlayersWhenClose; - this.mobMap = mobMap; - - - this.placeholderMap = new PlaceholderMap() - .add(Placeholders.DUNGEON_SETTINGS_ENABLED, () -> LangManager.getBoolean(this.isEnabled())) - .add(Placeholders.DUNGEON_SETTINGS_CLICK_TIMER, () -> LangManager.getBoolean(this.isClickTimer())) - .add(Placeholders.DUNGEON_SETTINGS_MINIMAL_ONLINE, () -> String.valueOf(this.getMinimalOnline())) - .add(Placeholders.DUNGEON_SETTINGS_LET_PLAYERS_WHEN_CLOSE, () -> LangManager.getBoolean(this.isLetPlayersWhenClose())) - .add(Placeholders.DUNGEON_SETTINGS_MOBS, () -> this.getMobMap().entrySet().stream() - .map(entry -> Colorizer.apply(Colors.LIGHT_YELLOW + entry.getKey() + ": " + entry.getValue())).collect(Collectors.joining("\n"))) - ; - } - - @NotNull - public static MainSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { - boolean enabled = cfg.getBoolean(path + ".Enabled", true); // - boolean clickTimer = cfg.getBoolean(path + "Settings.Click_Timer"); - boolean letPlayersWhenClose = cfg.getBoolean(path + "Settings.Let_Players_When_Close", true); - - int minimalOnline = cfg.getInt(path + "Settings.Minimal_Online"); - - Map mobs = new HashMap<>(); - for (String mobId : cfg.getSection(path + "Mobs")) { - int amount = cfg.getInt(path + "Mobs." + mobId + ".Amount"); - mobs.put(mobId, amount); - } - - return new MainSettings(dungeon, enabled, clickTimer, letPlayersWhenClose, minimalOnline, mobs); - } - - public void write(@NotNull JYML cfg, @NotNull String path) { - cfg.set(path + "Enabled", this.isEnabled()); - cfg.set(path + "Settings.Minimal_Online", this.getMinimalOnline()); - cfg.set(path + "Settings.Click_Timer", this.isClickTimer()); - cfg.set(path + "Settings.Let_Players_When_Close", this.isLetPlayersWhenClose()); - - cfg.set(path + "Mobs", null); - this.getMobMap().forEach((mobId, amount) -> cfg.set(path + "Mobs." + mobId + ".Amount", amount)); - } - - public boolean isEnabled() { - return enabled; - } - - public boolean isClickTimer() { - return clickTimer; - } - - public int getMinimalOnline() { - return minimalOnline; - } - - public boolean isLetPlayersWhenClose() { - return letPlayersWhenClose; - } - - @NotNull - public Map getMobMap() { - return mobMap; - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - - public void setMobMap(@NotNull Map mobMap) { - this.mobMap = mobMap; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public void setClickTimer(boolean clickTimer) { - this.clickTimer = clickTimer; - } - - public void setMinimalOnline(int minimalOnline) { - this.minimalOnline = minimalOnline; - } - - public void setLetPlayersWhenClose(boolean letPlayersWhenClose) { - this.letPlayersWhenClose = letPlayersWhenClose; - } -} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/Placeholders.java new file mode 100644 index 0000000..cb502e9 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/Placeholders.java @@ -0,0 +1,18 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.settings; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final String DUNGEON_SETTINGS_ENABLED = "%dungeon_enabled%"; + public static final String DUNGEON_SETTINGS_MINIMAL_ONLINE = "%dungeon_minimal_online%"; + public static final String DUNGEON_SETTINGS_CLICK_TIMER = "%dungeon_click_timer%"; + public static final String DUNGEON_SETTINGS_BIG_CHEST = "%dungeon_big_chest%"; + public static final String DUNGEON_SETTINGS_CHEST_BLOCK_LIMIT = "%dungeon_chest_block_limit%"; + public static final String DUNGEON_SETTINGS_SEPARATE_CHEST_BLOCK = "%dungeon_separate_chest_block_gui%"; + public static final String DUNGEON_SETTINGS_RANDOM_SLOTS = "%dungeon_random_slots%"; + public static final String DUNGEON_SETTINGS_OPEN_TYPE = "%dungeon_open_type%"; + public static final String DUNGEON_SETTINGS_CHEST_MATERIAL = "%dungeon_chest_block%"; + public static final String DUNGEON_SETTINGS_LET_PLAYERS_WHEN_CLOSE = "%dungeon_let_players_when_close%"; + public static final String DUNGEON_SETTINGS_USE_ONE_KEY_FOR_CHEST = "%dungeon_use_one_key_for_chest%"; + public static final String DUNGEON_SETTINGS_GENERATION_TYPE = "%dungeon_generation_type%"; + public static final String DUNGEON_SETTINGS_GENERATION_LOCATION = "%dungeon_generation_location%"; + public static final String DUNGEON_SETTINGS_MOBS = "%dungeon_settings_mobs%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/AnnounceSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/AnnounceSettings.java similarity index 82% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/AnnounceSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/AnnounceSettings.java index f13bf28..db2a5c5 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/AnnounceSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/AnnounceSettings.java @@ -1,5 +1,7 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; @@ -12,16 +14,22 @@ import java.util.*; -public class AnnounceSettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class AnnounceSettings extends AbstractSettings { private final Map> announceMap; private final PlaceholderMap placeholderMap; - public AnnounceSettings(@NotNull Dungeon dungeon, @NotNull Map> announceMap) { + public AnnounceSettings( + @NotNull Dungeon dungeon, + @NotNull Map> announceMap + ) { super(dungeon); this.announceMap = announceMap; this.placeholderMap = new PlaceholderMap(); } + @NotNull public static AnnounceSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { Map> map = new HashMap<>(); for (String sId : cfg.getSection(path + ".Map")) { @@ -62,18 +70,16 @@ public void write(@NotNull JYML cfg, @NotNull String path) { } @NotNull - public Map> getAnnounceMap() { - return announceMap; - } - - @NotNull - public List getAnnounces(@NotNull DungeonStage stage, int time) { + public Set getAnnounces(@NotNull DungeonStage stage, int time) { return this.getAnnounceMap().entrySet().stream() - .filter(entry -> entry.getKey().equals(stage) && entry.getValue().entrySet().stream().anyMatch(f -> Arrays.stream(f.getValue()).anyMatch(i -> i == time))) + .filter(entry -> entry.getKey().equals(stage) && entry.getValue() + .entrySet() + .stream() + .anyMatch(f -> Arrays.stream(f.getValue()).anyMatch(i -> i == time))) .flatMap(founder -> founder.getValue().keySet().stream()) .findFirst() - .map(Collections::singletonList) - .orElse(Collections.emptyList()); + .map(Collections::singleton) + .orElse(Collections.emptySet()); } @NotNull @@ -81,11 +87,6 @@ public Map getAnnounceMap(@NotNull DungeonStage stage) { return new HashMap<>(this.getAnnounceMap().entrySet().stream().filter(entry -> entry.getKey().equals(stage)).map(Map.Entry::getValue).findFirst().orElse(Collections.emptyMap())); } - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - public void setAnnounce(@NotNull DungeonStage stage, @NotNull Map map) { this.getAnnounceMap().put(stage, map); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/ChestSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/ChestSettings.java similarity index 56% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/ChestSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/ChestSettings.java index b6b0504..0afa501 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/ChestSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/ChestSettings.java @@ -1,33 +1,42 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.lang.LangManager; import t.me.p1azmer.engine.utils.StringUtil; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders; import java.util.HashMap; import java.util.Map; -public class ChestSettings extends AbstractSettings implements IPlaceholderMap { - private final Map stateMap; +@Getter +@Setter +public class ChestSettings extends AbstractSettings { + private final Map stateMap; private int blockLimit; private ChestModule.OpenType openType; private Material material; private boolean bigMenu, separateMenu, randomSlots, useOneKeyForMenu; - private final PlaceholderMap placeholderMap; - public ChestSettings(@NotNull Dungeon dungeon, @NotNull Map stateMap, - int blockLimit, - boolean bigMenu, boolean separateMenu, boolean randomSlots, boolean useOneKeyForMenu, - @NotNull ChestModule.OpenType openType, @NotNull Material material) { + public ChestSettings( + @NotNull Dungeon dungeon, + @NotNull Map stateMap, + int blockLimit, + boolean bigMenu, + boolean separateMenu, + boolean randomSlots, + boolean useOneKeyForMenu, + @NotNull ChestModule.OpenType openType, + @NotNull Material material + ) { super(dungeon); this.blockLimit = blockLimit; @@ -50,22 +59,25 @@ public ChestSettings(@NotNull Dungeon dungeon, @NotNull Map LangManager.getBoolean(this.isSeparateMenu())) .add(Placeholders.DUNGEON_SETTINGS_USE_ONE_KEY_FOR_CHEST, () -> LangManager.getBoolean(this.isUseOneKeyForMenu())) ; - stateMap.forEach((state, time) -> this.placeholderMap.add(Placeholders.DUNGEON_CHEST_STATE_TIME.apply(state), () -> String.valueOf(time))); + stateMap.forEach((state, time) -> this.placeholderMap.add( + t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders.DUNGEON_CHEST_STATE_TIME + .apply(state), () -> String.valueOf(time))); } + @NotNull public static ChestSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { - Map map = new HashMap<>(); + Map map = new HashMap<>(); if (!cfg.contains(path + ".Map")) { map.putAll(Map.of( - DungeonChestState.WAITING, 10, - DungeonChestState.COOLDOWN, 5, - DungeonChestState.OPENED, 10, - DungeonChestState.CLOSED, 10, - DungeonChestState.DELETED, 1 + ChestState.WAITING, 10, + ChestState.COOLDOWN, 5, + ChestState.OPENED, 10, + ChestState.CLOSED, 10, + ChestState.DELETED, 1 )); } for (String sId : cfg.getSection(path + ".Map")) { - DungeonChestState stage = StringUtil.getEnum(sId, DungeonChestState.class).orElse(null); + ChestState stage = StringUtil.getEnum(sId, ChestState.class).orElse(null); if (stage == null) continue; int time = cfg.getInt(path + ".Map." + sId); map.put(stage, time); @@ -83,7 +95,7 @@ public static ChestSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @N } public void write(@NotNull JYML cfg, @NotNull String path) { - for (Map.Entry entry : this.getStateMap().entrySet()) { + for (Map.Entry entry : this.getStateMap().entrySet()) { cfg.set(path + ".Map." + entry.getKey().name(), entry.getValue()); } cfg.set(path + ".Block.Limit", this.getBlockLimit()); @@ -97,79 +109,11 @@ public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".Open_Type", this.getOpenType().name()); } - @NotNull - public Map getStateMap() { - return stateMap; - } - - public int getTime(@NotNull DungeonChestState state) { + public int getTime(@NotNull ChestState state) { return this.getStateMap().getOrDefault(state, -1); } - public int getBlockLimit() { - return blockLimit; - } - - public boolean isBigMenu() { - return bigMenu; - } - - public boolean isRandomSlots() { - return randomSlots; - } - - public boolean isSeparateMenu() { - return separateMenu; - } - - public boolean isUseOneKeyForMenu() { - return useOneKeyForMenu; - } - - @NotNull - public Material getMaterial() { - return material; - } - - @NotNull - public ChestModule.OpenType getOpenType() { - return openType; - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - - public void setStateTime(@NotNull DungeonChestState state, int time) { + public void setStateTime(@NotNull ChestState state, int time) { this.getStateMap().put(state, time); } - - public void setBlockLimit(int blockLimit) { - this.blockLimit = blockLimit; - } - - public void setOpenType(@NotNull ChestModule.OpenType openType) { - this.openType = openType; - } - - public void setMaterial(@NotNull Material material) { - this.material = material; - } - - public void setUseOneKeyForMenu(boolean useOneKeyForMenu) { - this.useOneKeyForMenu = useOneKeyForMenu; - } - - public void setBigMenu(boolean bigMenu) { - this.bigMenu = bigMenu; - } - - public void setSeparateMenu(boolean separateMenu) { - this.separateMenu = separateMenu; - } - - public void setRandomSlots(boolean randomSlots) { - this.randomSlots = randomSlots; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/CommandsSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/CommandsSettings.java similarity index 72% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/CommandsSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/CommandsSettings.java index 3a0a000..750fd97 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/CommandsSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/CommandsSettings.java @@ -1,8 +1,9 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; @@ -14,11 +15,15 @@ import java.util.List; import java.util.Map; -public class CommandsSettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class CommandsSettings extends AbstractSettings { private final Map> commandsMap; - private final PlaceholderMap placeholderMap; - public CommandsSettings(@NotNull Dungeon dungeon, @NotNull Map> commandsMap) { + public CommandsSettings( + @NotNull Dungeon dungeon, + @NotNull Map> commandsMap + ) { super(dungeon); this.commandsMap = commandsMap; @@ -26,12 +31,13 @@ public CommandsSettings(@NotNull Dungeon dungeon, @NotNull Map> map = new HashMap<>(); for (String sId : cfg.getSection(path + ".Map")) { DungeonStage stage = StringUtil.getEnum(sId, DungeonStage.class).orElse(null); if (stage == null) continue; - List commands = cfg.getStringList(path+".Map." + sId); + List commands = cfg.getStringList(path + ".Map." + sId); map.put(stage, commands); } return new CommandsSettings(dungeon, map); @@ -43,11 +49,6 @@ public void write(@NotNull JYML cfg, @NotNull String path) { } } - @NotNull - public Map> getCommandsMap() { - return commandsMap; - } - @NotNull public List getCommands(@NotNull DungeonStage stage) { return this.getCommandsMap().getOrDefault(stage, Collections.emptyList()); @@ -56,9 +57,4 @@ public List getCommands(@NotNull DungeonStage stage) { public void setCommands(@NotNull DungeonStage stage, @NotNull List commands) { this.getCommandsMap().put(stage, commands); } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/EffectSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/EffectSettings.java similarity index 69% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/EffectSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/EffectSettings.java index 8b76c64..70b0913 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/EffectSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/EffectSettings.java @@ -1,30 +1,37 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Effect; +import t.me.p1azmer.plugin.dungeons.dungeon.effect.Effect; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import java.util.ArrayList; import java.util.List; -public class EffectSettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class EffectSettings extends AbstractSettings { private boolean enabled; private List effects; - private final PlaceholderMap placeholderMap; - - public EffectSettings(@NotNull Dungeon dungeon, boolean enabled, @NotNull List effects) { + public EffectSettings( + @NotNull Dungeon dungeon, + boolean enabled, + @NotNull List effects + ) { super(dungeon); this.enabled = enabled; this.effects = effects; this.placeholderMap = new PlaceholderMap(); } + @NotNull public static EffectSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { boolean enabled = cfg.getBoolean(path + ".Enabled"); List effects = new ArrayList<>(); @@ -46,27 +53,4 @@ public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".List." + effect.getPotionEffectType().getName() + ".Amplifier", effect.getAmplifier()); } } - - public boolean isEnabled() { - return enabled; - } - - @NotNull - public List getEffects() { - return effects; - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public void setEffects(@NotNull List effects) { - this.effects = effects; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/GenerationSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/GenerationSettings.java new file mode 100644 index 0000000..ca15b05 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/GenerationSettings.java @@ -0,0 +1,59 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; + +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import t.me.p1azmer.engine.api.config.JYML; +import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; +import t.me.p1azmer.engine.utils.Colorizer; +import t.me.p1azmer.engine.utils.Colors2; +import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.generation.GenerationType; +import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders; + +import java.util.Optional; + +@Getter +@Setter +public class GenerationSettings extends AbstractSettings { + private GenerationType generationType; + private Location spawnLocation; + + public GenerationSettings( + @NotNull Dungeon dungeon, + @NotNull GenerationType generationType, + @Nullable Location spawnLocation + ) { + super(dungeon); + this.generationType = generationType; + this.spawnLocation = spawnLocation; + + this.placeholderMap = new PlaceholderMap() + .add(Placeholders.DUNGEON_SETTINGS_GENERATION_TYPE, () -> plugin().getLangManager().getEnum(this.getGenerationType())) + .add(Placeholders.DUNGEON_SETTINGS_GENERATION_LOCATION, () -> { + if (this.spawnLocation == null) return Colorizer.apply(Colors2.RED + "X"); + return Placeholders.forLocation(this.spawnLocation) + .apply("%location_world% - %location_x%, %location_y%, %location_z%"); + }) + ; + } + + @NotNull + public static GenerationSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { + GenerationType generationType = cfg.getEnum(path + ".Type", GenerationType.class, GenerationType.DYNAMIC); + Location location = cfg.getLocation(path + ".Location"); + return new GenerationSettings(dungeon, generationType, location); + } + + public void write(@NotNull JYML cfg, @NotNull String path) { + cfg.set(path + ".Type", this.getGenerationType().name()); + cfg.set(path + ".Location", this.getSpawnLocation().orElse(null)); + } + + public Optional getSpawnLocation() { + return Optional.ofNullable(this.spawnLocation); + } +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/HologramSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/HologramSettings.java similarity index 58% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/HologramSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/HologramSettings.java index 98f61d2..223b1ac 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/HologramSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/HologramSettings.java @@ -1,50 +1,54 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.NumberUtil; import t.me.p1azmer.engine.utils.StringUtil; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestState; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.state.ChestState; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -public class HologramSettings extends AbstractSettings implements IPlaceholderMap { - private final PlaceholderMap placeholderMap; - +@Getter +@Setter +public class HologramSettings extends AbstractSettings { private double offsetY; - private final Map> stateMessagesMap; + private final Map> stateMessagesMap; - public HologramSettings(@NotNull Dungeon dungeon, double offsetY, - @NotNull Map> stateMessagesMap + public HologramSettings( + @NotNull Dungeon dungeon, + double offsetY, + @NotNull Map> stateMessagesMap ) { super(dungeon); - this.dungeon = dungeon; this.offsetY = offsetY; this.stateMessagesMap = stateMessagesMap; this.placeholderMap = new PlaceholderMap() .add(Placeholders.DUNGEON_HOLOGRAM_CHEST_OFFSET_Y, () -> NumberUtil.format(this.getOffsetY())) ; - stateMessagesMap.forEach((state, strings) -> this.placeholderMap.add(Placeholders.DUNGEON_HOLOGRAM_MESSAGES.apply(state), () -> String.join("\n", Colorizer.apply(strings)))); + stateMessagesMap.forEach((state, strings) -> this.placeholderMap + .add(Placeholders.DUNGEON_HOLOGRAM_MESSAGES.apply(state), () -> String.join("\n", Colorizer.apply(strings)))); } @NotNull public static HologramSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { - Map> map = new HashMap<>(); + Map> map = new HashMap<>(); for (String stateId : cfg.getSection(path + ".Chest_Block.Messages.Map")) { - DungeonChestState state = StringUtil.getEnum(stateId, DungeonChestState.class).orElse(null); + ChestState state = StringUtil.getEnum(stateId, ChestState.class).orElse(null); if (state == null) continue; List messages = cfg.getStringList(path + ".Chest_Block.Messages.Map." + stateId); map.put(state, messages); } + // old convector List waitMessage = cfg.getStringList(path + ".Messages.Wait"); cfg.remove(path + ".Messages.Wait"); List openMessage = cfg.getStringList(path + ".Messages.Open"); @@ -52,11 +56,11 @@ public static HologramSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, List closeMessage = cfg.getStringList(path + ".Messages.Close"); cfg.remove(path + ".Messages.Close"); if (!waitMessage.isEmpty()) - map.put(DungeonChestState.WAITING, waitMessage); + map.put(ChestState.WAITING, waitMessage); if (!openMessage.isEmpty()) - map.put(DungeonChestState.CLOSED, openMessage); + map.put(ChestState.CLOSED, openMessage); if (!closeMessage.isEmpty()) - map.put(DungeonChestState.OPENED, closeMessage); + map.put(ChestState.OPENED, closeMessage); double oldOffsetY; if (cfg.contains(path + ".Offset.Y")) { @@ -70,35 +74,17 @@ public static HologramSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".Y_Offset", this.getOffsetY()); - for (Map.Entry> entry : this.getStateMessagesMap().entrySet()) { + for (Map.Entry> entry : this.getStateMessagesMap().entrySet()) { cfg.set(path + ".Chest_Block.Messages.Map." + entry.getKey(), entry.getValue()); } } - public double getOffsetY() { - return offsetY; - } - - @NotNull - public Map> getStateMessagesMap() { - return stateMessagesMap; - } - @NotNull - public List getMessages(@NotNull DungeonChestState state) { + public List getMessages(@NotNull ChestState state) { return this.getStateMessagesMap().getOrDefault(state, new ArrayList<>()); } - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - - public void setOffsetY(double offsetY) { - this.offsetY = offsetY; - } - - public void setStateMessages(@NotNull DungeonChestState state, @NotNull List messages) { + public void setStateMessages(@NotNull ChestState state, @NotNull List messages) { this.getStateMessagesMap().put(state, messages); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/MainSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/MainSettings.java new file mode 100644 index 0000000..9638c22 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/MainSettings.java @@ -0,0 +1,83 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; + +import lombok.Getter; +import lombok.Setter; +import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.api.config.JYML; +import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; +import t.me.p1azmer.engine.lang.LangManager; +import t.me.p1azmer.engine.utils.Colorizer; +import t.me.p1azmer.engine.utils.Colors; +import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +@Getter +@Setter +public class MainSettings extends AbstractSettings { + private boolean enabled, clickTimer, letPlayersWhenClose; + private int minimalOnline; + private Map mobMap; + + public MainSettings( + @NotNull Dungeon dungeon, + boolean enabled, + boolean clickTimer, + boolean letPlayersWhenClose, + int minimalOnline, + @NotNull Map mobMap + ) { + super(dungeon); + this.enabled = enabled; + this.clickTimer = clickTimer; + this.minimalOnline = minimalOnline; + this.letPlayersWhenClose = letPlayersWhenClose; + this.mobMap = mobMap; + + + this.placeholderMap = new PlaceholderMap() + .add(Placeholders.DUNGEON_SETTINGS_ENABLED, () -> LangManager.getBoolean(this.isEnabled())) + .add(Placeholders.DUNGEON_SETTINGS_CLICK_TIMER, () -> LangManager.getBoolean(this.isClickTimer())) + .add(Placeholders.DUNGEON_SETTINGS_MINIMAL_ONLINE, () -> String.valueOf(this.getMinimalOnline())) + .add(Placeholders.DUNGEON_SETTINGS_LET_PLAYERS_WHEN_CLOSE, () -> LangManager.getBoolean(this.isLetPlayersWhenClose())) + .add(Placeholders.DUNGEON_SETTINGS_MOBS, () -> + this.getMobMap() + .entrySet() + .stream() + .map(entry -> Colorizer.apply(Colors.LIGHT_YELLOW + entry.getKey() + ": " + entry.getValue())) + .collect(Collectors.joining("\n")) + ) + ; + } + + @NotNull + public static MainSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { + boolean enabled = cfg.getBoolean(path + ".Enabled", true); // + boolean clickTimer = cfg.getBoolean(path + ".Click_Timer"); + boolean letPlayersWhenClose = cfg.getBoolean(path + ".Let_Players_When_Close", true); + + int minimalOnline = cfg.getInt(path + ".Minimal_Online"); + + Map mobs = new HashMap<>(); + for (String mobId : cfg.getSection(path + ".Mobs")) { + int amount = cfg.getInt(path + ".Mobs." + mobId + ".Amount"); + mobs.put(mobId, amount); + } + + return new MainSettings(dungeon, enabled, clickTimer, letPlayersWhenClose, minimalOnline, mobs); + } + + public void write(@NotNull JYML cfg, @NotNull String path) { + cfg.set(path + ".Enabled", this.isEnabled()); + cfg.set(path + ".Minimal_Online", this.getMinimalOnline()); + cfg.set(path + ".Click_Timer", this.isClickTimer()); + cfg.set(path + ".Let_Players_When_Close", this.isLetPlayersWhenClose()); + + cfg.set(path + ".Mobs", null); + this.getMobMap().forEach((mobId, amount) -> cfg.set(path + ".Mobs." + mobId + ".Amount", amount)); + } +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/ModuleSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/ModuleSettings.java similarity index 77% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/ModuleSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/ModuleSettings.java index 16d7f3b..f07dc01 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/ModuleSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/ModuleSettings.java @@ -1,5 +1,7 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.checkerframework.checker.nullness.qual.NonNull; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; @@ -12,17 +14,21 @@ import java.util.HashMap; import java.util.Map; -public class ModuleSettings extends AbstractSettings implements IPlaceholderMap { - +@Getter +@Setter +public class ModuleSettings extends AbstractSettings { private final Map moduleSettingsMap; - private final PlaceholderMap placeholderMap; - public ModuleSettings(@NotNull Dungeon dungeon, @NonNull Map moduleSettingsMap) { + public ModuleSettings( + @NotNull Dungeon dungeon, + @NonNull Map moduleSettingsMap + ) { super(dungeon); this.moduleSettingsMap = moduleSettingsMap; this.placeholderMap = new PlaceholderMap(); } + @NotNull public static ModuleSettings read(@NotNull Dungeon dungeon, @NonNull JYML cfg, @NonNull String path) { Map settingMap = new HashMap<>(); for (String moduleId : cfg.getSection(path + ".Map")) { @@ -37,11 +43,6 @@ public void write(@NonNull JYML cfg, @NonNull String path) { } } - @NonNull - public Map getModuleSettingsMap() { - return moduleSettingsMap; - } - public void setEnabled(@NotNull String moduleId, boolean value){ this.getModuleSettingsMap().put(moduleId, value); } @@ -52,9 +53,4 @@ public boolean isEnabled(@NonNull String moduleId) { public boolean isEnabled(@NonNull AbstractModule module) { return this.isEnabled(module.getId()); } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/PartySettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/PartySettings.java similarity index 62% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/PartySettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/PartySettings.java index 261a2c9..9033cef 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/PartySettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/PartySettings.java @@ -1,23 +1,28 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.lang.LangManager; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -public class PartySettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class PartySettings extends AbstractSettings { private boolean enabled; private int size; - private final PlaceholderMap placeholderMap; - - public PartySettings(@NotNull Dungeon dungeon, boolean enabled, int size) { + public PartySettings( + @NotNull Dungeon dungeon, + boolean enabled, + int size + ) { super(dungeon); - this.dungeon = dungeon; this.enabled = enabled; this.size = size; this.placeholderMap = new PlaceholderMap() @@ -26,6 +31,7 @@ public PartySettings(@NotNull Dungeon dungeon, boolean enabled, int size) { ; } + @NotNull public static PartySettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { boolean enabled = cfg.getBoolean(path + ".Enabled"); int size = cfg.getInt(path + ".Size"); @@ -36,25 +42,4 @@ public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".Enabled", this.isEnabled()); cfg.set(path + ".Size", this.getSize()); } - - public boolean isEnabled() { - return enabled; - } - - public int getSize() { - return size; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public void setSize(int size) { - this.size = size; - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/RewardSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/RewardSettings.java similarity index 66% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/RewardSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/RewardSettings.java index e197ea9..20aefaf 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/RewardSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/RewardSettings.java @@ -1,19 +1,25 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.utils.values.UniInt; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders; -public class RewardSettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class RewardSettings extends AbstractSettings { private UniInt limit; - private final PlaceholderMap placeholderMap; - public RewardSettings(@NotNull Dungeon dungeon, UniInt limit) { + public RewardSettings( + @NotNull Dungeon dungeon, + @NotNull UniInt limit + ) { super(dungeon); this.limit = limit; @@ -23,6 +29,7 @@ public RewardSettings(@NotNull Dungeon dungeon, UniInt limit) { ; } + @NotNull public static RewardSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { UniInt limit = UniInt.read(cfg, path + ".Limit"); return new RewardSettings(dungeon, limit); @@ -31,18 +38,4 @@ public static RewardSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @ public void write(@NotNull JYML cfg, @NotNull String path) { this.getLimit().write(cfg, path + ".Limit"); } - - @NotNull - public UniInt getLimit() { - return limit; - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - - public void setLimit(@NotNull UniInt limit) { - this.limit = limit; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/SchematicSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/SchematicSettings.java similarity index 65% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/SchematicSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/SchematicSettings.java index 1fb37cd..50bd588 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/SchematicSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/SchematicSettings.java @@ -1,5 +1,7 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.settings; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; @@ -7,20 +9,26 @@ import t.me.p1azmer.engine.lang.LangManager; import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.Colors; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import java.util.List; import java.util.stream.Collectors; -public class SchematicSettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class SchematicSettings extends AbstractSettings { private List schematics; private boolean ignoreAirBlocks; private boolean underground; - private final PlaceholderMap placeholderMap; - public SchematicSettings(@NotNull Dungeon dungeon, @NotNull List schematics, boolean ignoreAirBlocks, boolean underground) { + public SchematicSettings( + @NotNull Dungeon dungeon, + @NotNull List schematics, + boolean ignoreAirBlocks, + boolean underground + ) { super(dungeon); this.setSchematics(schematics); this.ignoreAirBlocks = ignoreAirBlocks; @@ -31,9 +39,9 @@ public SchematicSettings(@NotNull Dungeon dungeon, @NotNull List schemat .add(Placeholders.SCHEMATICS_IGNORE_AIR, () -> LangManager.getBoolean(this.isIgnoreAirBlocks())) .add(Placeholders.SCHEMATICS_UNDERGROUND, () -> LangManager.getBoolean(this.isUnderground())) ; - } + @NotNull public static SchematicSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { List schematic = cfg.getStringList(path + ".List"); boolean ignoreAirBlocks = cfg.getBoolean(path + ".Ignore_Air_Blocks"); @@ -47,34 +55,11 @@ public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".Underground", this.isUnderground()); } - @NotNull - public List getSchematics() { - return schematics; - } - - public boolean isIgnoreAirBlocks() { - return ignoreAirBlocks; - } - - public boolean isUnderground() { - return underground; - } - - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - public void setSchematics(@NotNull List schematics) { - schematics = schematics.stream().map(founder -> !founder.endsWith(".schem") ? founder + ".schem" : founder).collect(Collectors.toList()); + schematics = schematics + .stream() + .map(founder -> !founder.endsWith(".schem") ? founder + ".schem" : founder) + .collect(Collectors.toList()); this.schematics = schematics; } - - public void setIgnoreAirBlocks(boolean ignoreAirBlocks) { - this.ignoreAirBlocks = ignoreAirBlocks; - } - - public void setUnderground(boolean underground) { - this.underground = underground; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageSettings.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/StageSettings.java similarity index 69% rename from src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageSettings.java rename to src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/StageSettings.java index 80bb77f..9ab6f1a 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageSettings.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/settings/impl/StageSettings.java @@ -1,28 +1,34 @@ -package t.me.p1azmer.plugin.dungeons.dungeon.stage; +package t.me.p1azmer.plugin.dungeons.dungeon.settings.impl; +import lombok.Getter; +import lombok.Setter; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.config.JYML; -import t.me.p1azmer.engine.api.placeholder.IPlaceholderMap; import t.me.p1azmer.engine.api.placeholder.PlaceholderMap; import t.me.p1azmer.engine.utils.StringUtil; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.settings.AbstractSettings; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import java.util.HashMap; import java.util.Map; -public class StageSettings extends AbstractSettings implements IPlaceholderMap { +@Getter +@Setter +public class StageSettings extends AbstractSettings { private final Map stageMap; - private final PlaceholderMap placeholderMap; - public StageSettings(@NotNull Dungeon dungeon, @NotNull Map stageMap) { + public StageSettings( + @NotNull Dungeon dungeon, + @NotNull Map stageMap + ) { super(dungeon); this.stageMap = stageMap; this.placeholderMap = new PlaceholderMap(); } + @NotNull public static StageSettings read(@NotNull Dungeon dungeon, @NotNull JYML cfg, @NotNull String path) { Map map = new HashMap<>(); for (String sId : cfg.getSection(path + ".Map")) { @@ -40,21 +46,11 @@ public void write(@NotNull JYML cfg, @NotNull String path) { } } - @NotNull - public Map getStageMap() { - return stageMap; - } - public int getTime(@NotNull DungeonStage stage) { return this.getStageMap().getOrDefault(stage, -1); } - @Override - public @NotNull PlaceholderMap getPlaceholders() { - return this.placeholderMap; - } - - public void setTime(@NotNull DungeonStage stage, int time){ + public void setTime(@NotNull DungeonStage stage, int time) { this.getStageMap().put(stage, time); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/DungeonStage.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/DungeonStage.java index 20cb603..be33cfa 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/DungeonStage.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/DungeonStage.java @@ -1,28 +1,45 @@ package t.me.p1azmer.plugin.dungeons.dungeon.stage; +import lombok.Getter; +import org.bukkit.Location; import org.jetbrains.annotations.NotNull; +import t.me.p1azmer.engine.api.lang.LangKey; +import t.me.p1azmer.engine.lang.LangManager; import t.me.p1azmer.engine.utils.CollectionsUtil; -import t.me.p1azmer.plugin.dungeons.DungeonAPI; +import t.me.p1azmer.engine.utils.Colorizer; +import t.me.p1azmer.engine.utils.Placeholders; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.api.events.DungeonChangeStageEvent; import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleManager; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.StageSettings; -import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; +@Getter public enum DungeonStage { - FREEZE, - CHECK, - PREPARE, - CLOSED, - WAITING_PLAYERS, - OPENING, - OPENED, - DELETING, - CANCELLED, - REBOOTED, - ; + FREEZE(StageLang.FREEZE), + CHECK(StageLang.CHECK), + PREPARE(StageLang.PREPARE), + CLOSED(StageLang.CLOSED), + WAITING_PLAYERS(StageLang.WAITING_PLAYERS), + OPENING(StageLang.OPENING), + OPENED(StageLang.OPENED), + DELETING(StageLang.DELETING), + CANCELLED(StageLang.CANCELLED), + REBOOTED(StageLang.REBOOTED); + + private final LangKey localization; + + DungeonStage(@NotNull LangKey localization) { + this.localization = localization; + } + + @NotNull + public String getDescription(@NotNull DungeonPlugin plugin) { + return plugin.getMessage(this.getLocalization()).normalizeLines(); + } public boolean isFreeze() { return this.equals(FREEZE); @@ -66,11 +83,29 @@ public boolean isRebooted() { public void tick(@NotNull Dungeon dungeon) { AtomicInteger timer = dungeon.getSelfTick(); - if (Config.DEBUG_TICK.get()) { - DungeonAPI.PLUGIN.warn("Tick the dungeon '" + dungeon.getId() + "'. Stage=" + this.name() + ", Tick=" + timer.get() + "/" + dungeon.getStageSettings().getTime(this)); + DungeonPlugin plugin = dungeon.plugin(); + StageSettings stageSettings = dungeon.getStageSettings(); + + if (Config.TICK_DEBUG.get()) { + ModuleManager moduleManager = dungeon.getModuleManager(); + Location location = dungeon.getLocation().orElse(null); + String locationText = location == null ? "empty" : Placeholders.forLocation(location) + .apply("%location_world% - %location_x%, %location_y%, %location_z%"); + String hasCuboid = Colorizer.strip(LangManager.getBoolean(dungeon.getDungeonCuboid().isPresent())); + + plugin.sendDebug( + "Dungeon '" + dungeon.getId() + "' | " + + "Stage=" + this.name() + " | " + + "Time=" + timer.get() + "/" + stageSettings.getTime(this) + " | " + + "Location=" + locationText + " | " + + "Cuboid=" + hasCuboid + " | " + + "Modules=" + moduleManager.getModules().size() + " | " + + "Active Modules=" + moduleManager.getActive().size() + ); } - if (timer.get() == dungeon.getStageSettings().getTime(this)) { - call(dungeon, CollectionsUtil.next(dungeon.getStage()), "self class"); + + if (timer.get() == stageSettings.getTime(this)) { + call(dungeon, CollectionsUtil.next(dungeon.getStage(), stage -> stage != dungeon.getStage()), "self class"); } else { timer.incrementAndGet(); } @@ -83,24 +118,13 @@ public void tick(@NotNull Dungeon dungeon) { * @param stage - called stage * @param from - for debug messages */ - public static boolean call(@NotNull Dungeon dungeon, @NotNull DungeonStage stage, @NotNull String from) { + public static void call(@NotNull Dungeon dungeon, @NotNull DungeonStage stage, @NotNull String from) { DungeonPlugin plugin = dungeon.plugin(); - DungeonChangeStageEvent calledEvent = new DungeonChangeStageEvent(dungeon, stage); + DungeonChangeStageEvent calledEvent = new DungeonChangeStageEvent(dungeon, stage, from); plugin.getPluginManager().callEvent(calledEvent); if (calledEvent.isCancelled()) { - return false; - } - - if (stage.isDeleting() || stage.isCancelled()) { - if (dungeon.getModuleManager().getModules().stream().anyMatch(module -> !module.deactivate())) { - return false; - } - dungeon.cancel(false); + plugin.sendDebug("It was not possible to change the state of the dungeon '" + dungeon.getId() + "' from \"" + from + "\", as the event was canceled"); } - plugin.sendDebug("Call the dungeon '" + dungeon.getId() + "' from " + from + ". Change stage to " + stage.name() + " from " + dungeon.getStage().name()); - dungeon.setStage(stage); - dungeon.setSelfTick(0); - return true; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/Placeholders.java new file mode 100644 index 0000000..460b215 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/Placeholders.java @@ -0,0 +1,9 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.stage; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.dungeon.Placeholders { + public static final String EDITOR_STAGE_COMMANDS = "%dungeon_editor_stage_commands%"; + public static final String EDITOR_STAGE_ANNOUNCES = "%dungeon_editor_stage_announces%"; + public static final String EDITOR_STAGE_TIME = "%dungeon_editor_stage_time%"; + public static final String EDITOR_STAGE_DESCRIPTION = "%dungeon_editor_stage_description%"; + public static final String EDITOR_STAGE_NAME = "%dungeon_editor_stage_name%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageLang.java b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageLang.java new file mode 100644 index 0000000..9b9724e --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/dungeon/stage/StageLang.java @@ -0,0 +1,62 @@ +package t.me.p1azmer.plugin.dungeons.dungeon.stage; + +import t.me.p1azmer.engine.api.lang.LangKey; +import t.me.p1azmer.plugin.dungeons.lang.Lang; + +import static t.me.p1azmer.engine.utils.Colors2.GRAY; + +public class StageLang extends Lang { + public static final LangKey FREEZE = LangKey.of( + "Stage.Freeze.Description", + GRAY + "The freezing stage.\n" + + GRAY + "All the dungeons that are\n" + + GRAY + "at this stage are waiting for their turn" + ); + public static final LangKey CHECK = LangKey.of( + "Stage.Check.Description", + GRAY + "The module check stage.\n" + + GRAY + "Location generation & etc." + ); + public static final LangKey PREPARE = LangKey.of( + "Stage.Preapre.Description", + GRAY + "The stage of preparation\n" + + GRAY + "for creation in the world.\n" + + GRAY + "Here you can notify players that\n" + + GRAY + "the dungeon will soon be available in the world" + ); + public static final LangKey CLOSED = LangKey.of( + "Stage.Closed.Description", + GRAY + "The stage when the dungeon\n" + + GRAY + "has just spawned and\n" + + GRAY + "is closed to entry" + ); + public static final LangKey WAITING_PLAYERS = LangKey.of( + "Stage.Waiting_Players.Description", + GRAY + "The waiting stage,\n" + + GRAY + "when players can enter and run around\n" + + GRAY + "the dungeon without additional modules" + ); + public static final LangKey OPENING = LangKey.of( + "Stage.Opening.Description", + GRAY + "The stage of the opening of the dungeon,\n" + + GRAY + "when the chests will be filled" + ); + public static final LangKey OPENED = LangKey.of( + "Stage.Opened.Description", + GRAY + "The dungeon is open,\n" + + GRAY + "the modules are activated,\n" + + GRAY + "we are playing" + ); + public static final LangKey DELETING = LangKey.of( + "Stage.Deleting.Description", + GRAY + "Module cleaning stage" + ); + public static final LangKey CANCELLED = LangKey.of( + "Stage.Cancelled.Description", + GRAY + "Called when something goes wrong" + ); + public static final LangKey REBOOTED = LangKey.of( + "Stage.Rebooted.Description", + GRAY + "Rebooting the dungeon" + ); +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/editor/EditorLocales.java b/src/main/java/t/me/p1azmer/plugin/dungeons/editor/EditorLocales.java index 0304290..722859e 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/editor/EditorLocales.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/editor/EditorLocales.java @@ -1,16 +1,20 @@ package t.me.p1azmer.plugin.dungeons.editor; import t.me.p1azmer.engine.api.editor.EditorLocale; -import t.me.p1azmer.engine.utils.Colors2; import t.me.p1azmer.engine.utils.EngineUtils; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; -import static t.me.p1azmer.engine.utils.Colors.*; +import static t.me.p1azmer.engine.utils.Colors.BLUE; +import static t.me.p1azmer.engine.utils.Colors.GREEN; +import static t.me.p1azmer.engine.utils.Colors.LIGHT_PURPLE; +import static t.me.p1azmer.engine.utils.Colors.ORANGE; +import static t.me.p1azmer.engine.utils.Colors.RED; import static t.me.p1azmer.engine.utils.Colors2.BOLD; import static t.me.p1azmer.engine.utils.Colors2.GRAY; import static t.me.p1azmer.engine.utils.Colors2.WHITE; import static t.me.p1azmer.engine.utils.Colors2.YELLOW; +import static t.me.p1azmer.engine.utils.Colors2.*; public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales { @@ -78,8 +82,8 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .build(); public static final EditorLocale DUNGEON_SETTINGS = builder(PREFIX + "Dungeon.Change.Settings") .name("Main Settings") - .current("Enabled", Placeholders.DUNGEON_SETTINGS_ENABLED) - .current("Minimal online", Placeholders.DUNGEON_SETTINGS_MINIMAL_ONLINE) + .current("Enabled", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_ENABLED) + .current("Minimal online", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_MINIMAL_ONLINE) .text(" and more in menu") .emptyLine() .click(LMB, "Navigate") @@ -110,42 +114,42 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .click(LMB, "Navigate") .build(); public static EditorLocale CHEST_BLOCK_STATE_OBJECT = builder(PREFIX + "Dungeon.Settings.Chest.Object") - .name(LIGHT_PURPLE + Placeholders.DUNGEON_CHEST_STATE_NAME) + .name(LIGHT_PURPLE + t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders.DUNGEON_CHEST_STATE_NAME) .text("Sets the duration of", "this state in seconds") .emptyLine() .currentHeader() - .text(Placeholders.EDITOR_STATE_TIME + GRAY + " (" + WHITE + LMB + GRAY + ")") + .text(t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders.EDITOR_STATE_TIME + GRAY + " (" + WHITE + LMB + GRAY + ")") .build(); public static final EditorLocale DUNGEON_SETTINGS_USE_ONE_KEY_TO_OPEN_CHEST = builder(PREFIX + "Dungeon.Settings.Chest.One_Key") .name("One key for chests") .text("Sets whether only one key per chest", "will be used to use it.", "&eIf yes, then the player activates the chest", "&ewill be counted for all subsequent players").emptyLine() .currentHeader() - .current("Value", Placeholders.DUNGEON_SETTINGS_USE_ONE_KEY_FOR_CHEST).emptyLine() + .current("Value", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_USE_ONE_KEY_FOR_CHEST).emptyLine() .click(LMB, "Change") .build(); public static final EditorLocale DUNGEON_SETTINGS_BIG_CHEST = builder(PREFIX + "Dungeon.Settings.Chest.Menu.Big") .name("Big Chest") .text("Sets the chest (rewards menu) will be big.", "The large has 54 slots,", "and the small one has 27.").emptyLine() .currentHeader() - .current("Big", Placeholders.DUNGEON_SETTINGS_BIG_CHEST).emptyLine() + .current("Big", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_BIG_CHEST).emptyLine() .click(LMB, "Change").build(); public static final EditorLocale DUNGEON_SETTINGS_RANDOM_SLOTS = builder(PREFIX + "Dungeon.Settings.Menu.Random_Slots") .name("Random Slots") .text("Sets whether the items in the dungeon", "chest will be in random slots", "or will be filled gradually").emptyLine() .currentHeader() - .current("Random", Placeholders.DUNGEON_SETTINGS_RANDOM_SLOTS).emptyLine() + .current("Random", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_RANDOM_SLOTS).emptyLine() .click(LMB, "Change").build(); public static final EditorLocale DUNGEON_SETTINGS_OPEN_TYPE = builder(PREFIX + "Dungeon.Settings.Chest.Open_Type") .name("Chest Opening Type") .text("Sets the type of opening for the dungeon", GREEN + ChestModule.OpenType.CLICK.name() + GRAY + " - Opens the dungeon on click", GREEN + ChestModule.OpenType.TIMER.name() + GRAY + " - Opens the dungeon based on a timer").emptyLine() .currentHeader() - .current("Type", Placeholders.DUNGEON_SETTINGS_OPEN_TYPE).emptyLine() + .current("Type", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_OPEN_TYPE).emptyLine() .click(LMB, "Change").build(); public static final EditorLocale DUNGEON_SETTINGS_SEPARATE_GUI = builder(PREFIX + "Dungeon.Settings.Chest.Menu.Separate") .name("Separate chest block gui") .text("Sets whether there will be a separate menu", "for each block of the chest or", "one menu for all blocks") .currentHeader() - .current("Value", Placeholders.DUNGEON_SETTINGS_SEPARATE_CHEST_BLOCK) + .current("Value", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_SEPARATE_CHEST_BLOCK) .emptyLine() .click(LMB, "Change") @@ -154,7 +158,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Chest block limit") .text("Sets a limit on the number of chest blocks") .currentHeader() - .current("Value", Placeholders.DUNGEON_SETTINGS_CHEST_BLOCK_LIMIT) + .current("Value", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_CHEST_BLOCK_LIMIT) .emptyLine() .click(LMB, "Change") .build(); @@ -162,7 +166,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Chest Block") .text("Sets what material will be used as a chest", "that players will activate and open").emptyLine() .currentHeader() - .current("Material", Placeholders.DUNGEON_SETTINGS_CHEST_MATERIAL).emptyLine() + .current("Material", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_CHEST_MATERIAL).emptyLine() .click(LMB, "Change") .click(DRAG_DROP, "Quick change") .build(); @@ -172,11 +176,17 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .click(LMB, "Navigate") .build(); public static EditorLocale MODULE_OBJECT = builder(PREFIX + "Dungeon.Module.Object") - .name(LIGHT_PURPLE + Placeholders.MODULE_ID) - .text("Sets whether this module is enabled/disabled") + .name(LIGHT_PURPLE + t.me.p1azmer.plugin.dungeons.dungeon.modules.Placeholders.MODULE_ID) + .text( + "Sets whether this module is enabled/disabled", + "", + "The RED item means that the module cannot be", + "enabled/disabled based on the", + "settings of your generation type" + ) .emptyLine() .currentHeader() - .current("Enabled", Placeholders.EDITOR_MODULE_ENABLED + GRAY + " (" + WHITE + LMB + GRAY + ")") + .current("Enabled", t.me.p1azmer.plugin.dungeons.dungeon.modules.Placeholders.EDITOR_MODULE_ENABLED + GRAY + " (" + WHITE + LMB + GRAY + ")") .build(); // commands public static final EditorLocale COMMANDS_SETTINGS = builder(PREFIX + "Dungeon.Modules.Commands.Settings") @@ -184,12 +194,12 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .click(LMB, "Navigate") .build(); public static EditorLocale COMMANDS_OBJECT = builder(PREFIX + "Dungeon.Modules.Commands.Object") - .name(LIGHT_PURPLE + Placeholders.EDITOR_STAGE_NAME) + .name(LIGHT_PURPLE + t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_NAME) .text("Sets the commands for the given stage,", "which will be executed as soon as the dungeon moves to it") .emptyLine() .currentHeader() - .text(Placeholders.EDITOR_STAGE_COMMANDS) + .text(t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_COMMANDS) .emptyLine() .click(LMB, "Add Command") .click(SHIFT_RMB, "Clear " + RED + "(No Undo)") @@ -200,11 +210,11 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .click(LMB, "Navigate") .build(); public static EditorLocale ANNOUNCE_MODULE_OBJECT = builder(PREFIX + "Dungeon.Modules.Announce.Object") - .name(LIGHT_PURPLE + Placeholders.EDITOR_STAGE_NAME) + .name(LIGHT_PURPLE + t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_NAME) .text( "Preview:", GRAY + "AnnounceId [Time]", - Placeholders.EDITOR_STAGE_ANNOUNCES) + t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_ANNOUNCES) .emptyLine() .click(LMB, "Add") .click(SHIFT_LMB, "Clear " + RED + "(No Undo)") @@ -216,7 +226,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .build(); public static EditorLocale HOLOGRAM_OBJECT = builder(PREFIX + "Dungeon.Modules.Holograms.Object") - .name(LIGHT_PURPLE + Placeholders.DUNGEON_CHEST_STATE_NAME) + .name(LIGHT_PURPLE + t.me.p1azmer.plugin.dungeons.dungeon.chest.Placeholders.DUNGEON_CHEST_STATE_NAME) .text("Sets the message that will be", "over the chest block in this state") .emptyLine() .currentHeader() @@ -241,11 +251,17 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .build(); public static EditorLocale STAGES_OBJECT = builder(PREFIX + "Dungeon.Stages.Object") - .name(LIGHT_PURPLE + Placeholders.EDITOR_STAGE_NAME) - .text("Sets the time period for", "this stage of the dungeon") + .name(LIGHT_PURPLE + t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_NAME) + .text( + "Sets the time period for", + "this stage of the dungeon", + "", + WHITE+"Description:", + t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_DESCRIPTION + ) .emptyLine() .currentHeader() - .text(Placeholders.EDITOR_STAGE_TIME) + .current("Time", t.me.p1azmer.plugin.dungeons.dungeon.stage.Placeholders.EDITOR_STAGE_TIME) .emptyLine() .click(LMB, "Change") .build(); @@ -286,7 +302,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Enabled dungeon") .text("Sets whether the", "dungeon is enabled or disabled") .currentHeader() - .current("Enabled", Placeholders.DUNGEON_SETTINGS_ENABLED) + .current("Enabled", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_ENABLED) .emptyLine() .click(LMB, "Change") .build(); @@ -294,13 +310,13 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Click Timer") .text("Sets whether the timer will be started", "when opening if the", "opening type is click").emptyLine() .currentHeader() - .current("Use", Placeholders.DUNGEON_SETTINGS_CLICK_TIMER).emptyLine() + .current("Use", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_CLICK_TIMER).emptyLine() .click(LMB, "Change").build(); public static final EditorLocale DUNGEON_SETTINGS_MINIMAL_ONLINE = builder(PREFIX + "Dungeon.Settings.Minimal_Online") .name("Minimal Online") .text("Sets the minimum allowed online", "players for spawn").emptyLine() .currentHeader() - .current("Value", Placeholders.DUNGEON_SETTINGS_MINIMAL_ONLINE).emptyLine() + .current("Value", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_MINIMAL_ONLINE).emptyLine() .click(LMB, "Change") .build(); @@ -308,7 +324,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Let players when close") .text("Sets whether the player will", "be able to enter the dungeon if it is still closed.", "&cBe careful with this setting,", "&cas if you set a 'false',", "&cthe plugin will push the player 3 blocks back").emptyLine() .currentHeader() - .current("Value", Placeholders.DUNGEON_SETTINGS_LET_PLAYERS_WHEN_CLOSE).emptyLine() + .current("Value", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_LET_PLAYERS_WHEN_CLOSE).emptyLine() .click(LMB, "Change") .build(); @@ -316,17 +332,50 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Dungeon Mobs") .text("Sets which mobs will be spawned in", "the dungeon when the dungeon appears") .currentHeader() - .text(GRAY + "(Mob Id: Mob count)", "", Placeholders.DUNGEON_SETTINGS_MOBS) + .text(GRAY + "(Mob Id: Mob count)", "", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_MOBS) .click(LMB, "Add") .click(SHIFT_RMB, "Clear") .build(); + // generation settings + public static final EditorLocale GENERATION_SETTINGS = builder(PREFIX + "Dungeon.Settings.Generation") + .name("Generation Settings") + .click(LMB, "Navigate") + .build(); + public static final EditorLocale DUNGEON_SETTINGS_GENERATION_TYPE = builder(PREFIX + "Dungeon.Settings.Generation.Type") + .name("Type of Generation") + .text("Sets what type of generation the dungeon will have") + .currentHeader() + .current("Type", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_GENERATION_TYPE) + .text( + "", + WHITE + "Static " + GRAY + "-" + LIGHT_GRAY + " the position of this dungeon will always be the same", + WHITE + "Dynamic " + GRAY + "-" + LIGHT_GRAY + " the position of the dungeon will always be", + LIGHT_GRAY + "random based on the settings of the generator", + WHITE + "Updatable " + GRAY + "-" + LIGHT_GRAY + " the position of the dungeon will be static,", + LIGHT_GRAY + "but its schematics will be created and deleted according to the timer settings" + ) + .emptyLine() + .click(LMB, "Change") + .build(); + public static final EditorLocale DUNGEON_SETTINGS_GENERATION_LOCATION = builder(PREFIX + "Dungeon.Settings.Generation.Location") + .name("Generation Location") + .text( + "Set the location to be used if", + "the generation type is " + YELLOW + "STATIC" + ) + .currentHeader() + .current("Location", t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_GENERATION_LOCATION) + .emptyLine() + .click(LMB, "Change to your location") + .click(SHIFT_RMB, "Clear") + .build(); // effect public static final EditorLocale EFFECT_OBJECT = builder(PREFIX + "Dungeon.Modules.Effects.Object") - .name(Placeholders.EFFECT_NAME) + .name(t.me.p1azmer.plugin.dungeons.dungeon.effect.Placeholders.EFFECT_NAME) .currentHeader() - .current("Duration", Placeholders.EFFECT_DURATION) - .current("Amplifier", Placeholders.EFFECT_AMPLIFIER) + .current("Duration", t.me.p1azmer.plugin.dungeons.dungeon.effect.Placeholders.EFFECT_DURATION) + .current("Amplifier", t.me.p1azmer.plugin.dungeons.dungeon.effect.Placeholders.EFFECT_AMPLIFIER) .emptyLine() .click(LMB, "Change duration") @@ -352,21 +401,21 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales public static final EditorLocale REGION_NAME = builder(PREFIX + "Dungeon.Modules.Region.Name") .name("Name") .currentHeader() - .current("", Placeholders.REGION_NAME) + .current("", t.me.p1azmer.plugin.dungeons.dungeon.region.Placeholders.REGION_NAME) .click(LMB, "Change") .emptyLine() .build(); public static final EditorLocale REGION_ENABLED = builder(PREFIX + "Dungeon.Modules.Region.Enabled") .name("Region status") .currentHeader() - .current("Enabled", Placeholders.REGION_ENABLED) + .current("Enabled", t.me.p1azmer.plugin.dungeons.dungeon.region.Placeholders.REGION_ENABLED) .click(LMB, "Change") .emptyLine() .build(); public static final EditorLocale REGION_RADIUS = builder(PREFIX + "Dungeon.Modules.Region.Radius") .name("Radius") .currentHeader() - .current("", Placeholders.REGION_RADIUS) + .current("", t.me.p1azmer.plugin.dungeons.dungeon.region.Placeholders.REGION_RADIUS) .click(LMB, "Change") .emptyLine() .build(); @@ -374,14 +423,14 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Flags") .currentHeader() .current("List", "") - .text(Placeholders.REGION_FLAGS) + .text(t.me.p1azmer.plugin.dungeons.dungeon.region.Placeholders.REGION_FLAGS) .emptyLine() .click(LMB, "Add") .click(SHIFT_RMB, "Clear").build(); // rewards public static final EditorLocale REWARD_OBJECT = builder(PREFIX + "Dungeon.Modules.Reward.Object") - .name(Placeholders.REWARD_ID) - .text("Chance: &f" + Placeholders.REWARD_CHANCE + "%") + .name(t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_ID) + .text("Chance: &f" + t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_CHANCE + "%") .emptyLine() .click(LMB, "Configure") .click(SHIFT_LMB, "Move Forward") @@ -413,30 +462,30 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Chance") .text("Sets the chance of adding this item to the chest") .currentHeader() - .current("Chance", Placeholders.REWARD_CHANCE + "%" + GRAY + " (" + WHITE + LMB + GRAY + ")") + .current("Chance", t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_CHANCE + "%" + GRAY + " (" + WHITE + LMB + GRAY + ")") .build(); public static final EditorLocale REWARD_AMOUNT = builder(PREFIX + "Dungeon.Modules.Reward.Amount") .name("Item Amount") .text("Sets the amount of the item.", "The final amount will be within these values") .currentHeader() - .current("Min", Placeholders.REWARD_MIN_AMOUNT + GRAY + " (" + WHITE + LMB + GRAY + ")") - .current("Max", Placeholders.REWARD_MAX_AMOUNT + GRAY + " (" + WHITE + LMB + GRAY + ")") + .current("Min", t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_MIN_AMOUNT + GRAY + " (" + WHITE + LMB + GRAY + ")") + .current("Max", t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_MAX_AMOUNT + GRAY + " (" + WHITE + LMB + GRAY + ")") .build(); public static final EditorLocale REWARDS_LIMITS = builder(PREFIX + "Dungeon.Modules.Rewards.Limits") .name("Reward Limit") .text("Sets limits on the amount of items in the chest.", "The final amount will be within these values") .currentHeader() - .current("Min", Placeholders.REWARD_LIMIT_MIN + GRAY + " (" + WHITE + LMB + GRAY + ")") - .current("Max", Placeholders.REWARD_LIMIT_MAX + GRAY + " (" + WHITE + LMB + GRAY + ")") + .current("Min", t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_LIMIT_MIN + GRAY + " (" + WHITE + LMB + GRAY + ")") + .current("Max", t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_LIMIT_MAX + GRAY + " (" + WHITE + LMB + GRAY + ")") .build(); public static final EditorLocale REWARD_COMMANDS = builder(PREFIX + "Reward.Commands") .name("Commands") - .text("All of the following commands will", "be executed from the "+WHITE+"console","when the chest is opened.") + .text("All of the following commands will", "be executed from the " + WHITE + "console", "when the chest is opened.") .emptyLine() .currentHeader() - .text(Placeholders.REWARD_COMMANDS) + .text(t.me.p1azmer.plugin.dungeons.dungeon.reward.Placeholders.REWARD_COMMANDS) .emptyLine() .text(YELLOW + BOLD + "Placeholders:") .current(EngineUtils.PLACEHOLDER_API, "All of them.") @@ -447,7 +496,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .build(); // keys public static final EditorLocale KEY_OBJECT = builder(PREFIX + "Dungeon.Modules.Key.Object") - .name(Placeholders.KEY_NAME + GRAY + " (ID: " + BLUE + Placeholders.KEY_ID + GRAY + ")") + .name(t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + " (ID: " + BLUE + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_ID + GRAY + ")") .click(LMB, "Change") .click(SHIFT_RMB, "Delete " + RED + "(No Undo)") .build(); @@ -462,7 +511,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Displayed Name") .text("Sets the displayed name of the key.", "Used in menus and messages.").emptyLine() .currentHeader() - .current("Displayed Name", Placeholders.KEY_NAME).emptyLine() + .current("Displayed Name", t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME).emptyLine() .warningHeader().warning("This is " + RED + "NOT" + GRAY + " the actual name of the key!").emptyLine() .click(LMB, "Change") .build(); @@ -476,7 +525,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales // mobs public static final EditorLocale MOB_OBJECT = builder(PREFIX + "Dungeon.Modules.Mobs.Object") - .name(Placeholders.MOB_NAME + GRAY + " (&f" + Placeholders.MOB_ID + GRAY + ")") + .name(t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_NAME + GRAY + " (&f" + t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_ID + GRAY + ")") .click(LMB, "Edit").click(RMB, "Delete " + RED + "(No Undo)") .build(); @@ -488,8 +537,8 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Display Name") .text("Sets mob display name and", "whether or not this name is", "always visible.").emptyLine() .currentHeader() - .current("Name", Placeholders.MOB_NAME) - .current("Is Visible", Placeholders.MOB_NAME_VISIBLE) + .current("Name", t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_NAME) + .current("Is Visible", t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_NAME_VISIBLE) .click(LMB, "Change Name") .click(RMB, "Toggle Visibility") @@ -499,7 +548,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Entity Type") .text("Sets mob entity type.").emptyLine() .currentHeader() - .current("Type", Placeholders.MOB_ENTITY_TYPE) + .current("Type", t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_ENTITY_TYPE) .emptyLine() .click(LMB, "Change") .build(); @@ -508,7 +557,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Mob Attributes") .text("Sets mob default attributes.").emptyLine() .currentHeader() - .text(Placeholders.MOB_ATTRIBUTES_BASE) + .text(t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_ATTRIBUTES_BASE) .emptyLine() .noteHeader().text("Base attribute with zero value means", "that default mob's attribute value", "won't be changed.") .emptyLine() @@ -521,8 +570,8 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales .name("Mob Potions") .text("Sets mob default potion effects.").emptyLine() .currentHeader() - .current("Duration", "").text(Placeholders.MOB_POTION_EFFECT_DURATION) - .current("Value", "").text(Placeholders.MOB_POTION_EFFECT_VALUE) + .current("Duration", "").text(t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_POTION_EFFECT_DURATION) + .current("Value", "").text(t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_POTION_EFFECT_VALUE) .emptyLine() .click(LMB, "Change Duration") .click(RMB, "Change Value") @@ -544,21 +593,21 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales public static final EditorLocale MOB_SILENT = builder(PREFIX + "Dungeon.Modules.Mobs.Silent") .name("Mob Silent") .currentHeader() - .current("Silent", Placeholders.MOB_SILENT) + .current("Silent", t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_SILENT) .click(LMB, "Change") .build(); public static final EditorLocale MOB_STYLE_OBJECT = builder(PREFIX + "Dungeon.Modules.Mobs.Style_Object") - .name("Style Type: " + GREEN + Placeholders.MOB_STYLE_TYPE) + .name("Style Type: " + GREEN + t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_STYLE_TYPE) .currentHeader() - .current("Value", Placeholders.MOB_STYLE_VALUE).emptyLine() + .current("Value", t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_STYLE_VALUE).emptyLine() .click(LMB, "Change").click(RMB, "Remove") .build(); public static final EditorLocale MOB_RIDER = builder(PREFIX + "Dungeon.Modules.Mobs.Rider") .name("Mob Rider") .currentHeader() - .current("Rider", Placeholders.MOB_RIDER_ID) + .current("Rider", t.me.p1azmer.plugin.dungeons.mob.Placeholders.MOB_RIDER_ID) .click(LMB, "Change") .click(RMB, "Clear") .build(); @@ -581,19 +630,16 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales // announce public static final EditorLocale ANNOUNCE_OBJECT = builder(PREFIX + "Announce.Object") - .name(Placeholders.ANNOUNCE_ID) + .name(t.me.p1azmer.plugin.dungeons.announce.Placeholders.ANNOUNCE_ID) .click(LMB, "Edit") .click(RMB, "Delete " + RED + "(No Undo)") .build(); public static final EditorLocale ANNOUNCE_MESSAGES = builder(PREFIX + "Announce.Messages") .name("Messages") - .text(WHITE + "Info:", - "Sets the text of the announcement.", - "Note: If you add " + YELLOW + "''" + Colors2.GRAY + ",", - "the message will be without the plugin prefix!") + .text("Sets the text of the announcement.") .currentHeader() - .text(Placeholders.ANNOUNCE_MESSAGES) + .text(t.me.p1azmer.plugin.dungeons.announce.Placeholders.ANNOUNCE_MESSAGES) .emptyLine() .click(LMB, "Add Line") .click(RMB, "Clear Lines " + RED + "(No Undo)") @@ -601,7 +647,7 @@ public class EditorLocales extends t.me.p1azmer.engine.api.editor.EditorLocales public static final EditorLocale ANNOUNCE_GLOBAL = builder(PREFIX + "Announce.Global") .name("Global Announce") .text("If false, then the announcement", "will be only in the world set in the dungeon") - .text(Placeholders.ANNOUNCE_GLOBAL + GRAY + " (" + WHITE + LMB + GRAY + ")") + .text(t.me.p1azmer.plugin.dungeons.announce.Placeholders.ANNOUNCE_GLOBAL + GRAY + " (" + WHITE + LMB + GRAY + ")") .build(); public static final EditorLocale ANNOUNCE_ICON = builder(PREFIX + "Announce.Icon") .name("Icon in List Menu") diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/generator/RangeInfo.java b/src/main/java/t/me/p1azmer/plugin/dungeons/generator/RangeInfo.java index 3abb88a..df86b21 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/generator/RangeInfo.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/generator/RangeInfo.java @@ -1,8 +1,11 @@ package t.me.p1azmer.plugin.dungeons.generator; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import t.me.p1azmer.engine.api.config.JYML; import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonAPI; @@ -12,6 +15,7 @@ import java.util.stream.Collectors; public class RangeInfo { + private final String world; private final int startX; private final int startZ; private final int distanceMin; @@ -20,11 +24,15 @@ public class RangeInfo { private final List biomes; private final boolean biomesAsBlack, materialsAsBlack; - public RangeInfo(int startX, int startZ, int distanceMin, int distanceMax, - @NotNull List materials, - @NotNull List biomes, - boolean biomesAsBlack, boolean materialsAsBlack - ) { + public RangeInfo( + @NotNull String world, + int startX, int startZ, int distanceMin, int distanceMax, + @NotNull List materials, + @NotNull List biomes, + boolean biomesAsBlack, boolean materialsAsBlack + ) { + this.world = world; + this.startX = startX; this.startZ = startZ; @@ -39,41 +47,51 @@ public RangeInfo(int startX, int startZ, int distanceMin, int distanceMax, } @NotNull - public static RangeInfo read(@NotNull JYML cfg, @NotNull String path) { + public static RangeInfo read(@NotNull JYML cfg, @NotNull String path, @NotNull String world) { int startX = cfg.getInt(path + ".Start_X"); int startZ = cfg.getInt(path + ".Start_Z"); int distanceMin = cfg.getInt(path + ".Distance_Min"); int distanceMax = cfg.getInt(path + ".Distance_Max"); - boolean materialsAsBlack = cfg.getBoolean(path+".Material.Use_As_Blacklist", true); - boolean biomesAsBlack = cfg.getBoolean(path+".Material.Use_As_Blacklist", true); + boolean materialsAsBlack = cfg.getBoolean(path + ".Material.Use_As_Blacklist", true); + boolean biomesAsBlack = cfg.getBoolean(path + ".Material.Use_As_Blacklist", true); AtomicInteger nullMaterial = new AtomicInteger(); AtomicInteger nullBiomes = new AtomicInteger(); - List materials = cfg.getStringList(path + ".Material.List").stream().map(sId -> StringUtil.getEnum(sId, Material.class).orElse(null)).filter(material -> { - if (material == null) { - nullMaterial.incrementAndGet(); - return false; - } - return true; - }).toList(); - List biomes = cfg.getStringList(path + ".Biome.List").stream().map(sId -> StringUtil.getEnum(sId, Biome.class).orElse(null)).filter(biome -> { - if (biome == null) { - nullBiomes.incrementAndGet(); - return false; - } - return true; - }).toList(); - - if (nullMaterial.get() > 0){ + List materialList = cfg.getStringList(path + ".Material.List"); + List materials = materialList + .stream() + .map(sId -> StringUtil.getEnum(sId, Material.class).orElse(null)) + .filter(material -> { + if (material == null) { + nullMaterial.incrementAndGet(); + return false; + } + return true; + }) + .toList(); + List biomeList = cfg.getStringList(path + ".Biome.List"); + List biomes = biomeList + .stream() + .map(sId -> StringUtil.getEnum(sId, Biome.class).orElse(null)) + .filter(biome -> { + if (biome == null) { + nullBiomes.incrementAndGet(); + return false; + } + return true; + }) + .toList(); + + if (nullMaterial.get() > 0) { DungeonAPI.PLUGIN.warn("Attention! The location generator has wrong materials in the configuration. Please note this and check it!"); } - if (nullBiomes.get() > 0){ + if (nullBiomes.get() > 0) { DungeonAPI.PLUGIN.warn("Attention! The location generator has wrong biomes in the configuration. Please note this and check it!"); } - return new RangeInfo(startX, startZ, distanceMin, distanceMax, materials, biomes, biomesAsBlack, materialsAsBlack); + return new RangeInfo(world, startX, startZ, distanceMin, distanceMax, materials, biomes, biomesAsBlack, materialsAsBlack); } public void write(@NotNull JYML cfg, @NotNull String path) { @@ -82,11 +100,21 @@ public void write(@NotNull JYML cfg, @NotNull String path) { cfg.set(path + ".Distance_Min", this.getDistanceMin()); cfg.set(path + ".Distance_Max", this.getDistanceMax()); - cfg.set(path+".Material.Use_As_Blacklist", this.isMaterialsAsBlack()); - cfg.set(path+".Biome.Use_As_Blacklist", this.isBiomesAsBlack()); + cfg.set(path + ".Material.Use_As_Blacklist", this.isMaterialsAsBlack()); + cfg.set(path + ".Biome.Use_As_Blacklist", this.isBiomesAsBlack()); + + cfg.set(path + ".Material.List", this.getMaterials().stream().map(Enum::name).collect(Collectors.toList())); + cfg.set(path + ".Biome.List", this.getBiomes().stream().map(Enum::name).collect(Collectors.toList())); + } + + @NotNull + public String getWorldRaw() { + return world; + } - cfg.set(path+".Material.List", this.getMaterials().stream().map(Enum::name).collect(Collectors.toList())); - cfg.set(path+".Biome.List", this.getBiomes().stream().map(Enum::name).collect(Collectors.toList())); + @Nullable + public World getWorld() { + return Bukkit.getWorld(this.getWorldRaw()); } public int getStartX() { @@ -118,8 +146,21 @@ public List getBiomes() { return biomes; } + @NotNull + public List getBiomesString() { + return this.getBiomes() + .stream() + .map(Enum::name) + .collect(Collectors.toList()); + } + @NotNull public List getMaterials() { return materials; } + + @NotNull + public List getMaterialsString() { + return this.getMaterials().stream().map(Enum::name).collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/generator/config/GeneratorConfig.java b/src/main/java/t/me/p1azmer/plugin/dungeons/generator/config/GeneratorConfig.java index 28ed6b3..691a1b1 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/generator/config/GeneratorConfig.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/generator/config/GeneratorConfig.java @@ -15,12 +15,12 @@ public class GeneratorConfig { (cfg, path, def) -> { Map map = new HashMap<>(); for (String world : cfg.getSection(path)) { - RangeInfo rangeInfo = RangeInfo.read(cfg, path + "." + world); + RangeInfo rangeInfo = RangeInfo.read(cfg, path + "." + world, world); map.put(world, rangeInfo); } return map; }, - Map.of("world", new RangeInfo(0, 0, -5000, 5000, List.of(Material.WATER, Material.LAVA), List.of(Biome.WARM_OCEAN), true, true)), + Map.of("world", new RangeInfo("world", 0, 0, -5000, 5000, List.of(Material.WATER, Material.LAVA), List.of(Biome.WARM_OCEAN), true, true)), "List of per-world range values to search location in.", "Put your ACTUAL worlds here, especially if your dungeon uses a different world than the default 'world'.", "Note:", diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDecentHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDecentHandler.java index 367a40f..2557d09 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDecentHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDecentHandler.java @@ -10,83 +10,100 @@ import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.LocationUtil; import t.me.p1azmer.engine.utils.Pair; -import t.me.p1azmer.plugin.dungeons.DungeonAPI; -import t.me.p1azmer.plugin.dungeons.api.hologram.HologramHandler; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; +import t.me.p1azmer.plugin.dungeons.api.handler.hologram.HologramHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestBlock; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleId; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.HologramSettings; +import t.me.p1azmer.plugin.dungeons.dungeon.settings.impl.MainSettings; import java.util.*; +import java.util.function.UnaryOperator; public class HologramDecentHandler implements HologramHandler { - private Map>> holoMap; + private final Map>> holoMap = new HashMap<>(); @Override public void setup() { - this.holoMap = new HashMap<>(); } @Override public void shutdown() { - if (this.holoMap != null) { - this.holoMap.values().forEach(set -> set.forEach(pair -> pair.getSecond().delete())); - this.holoMap = null; - } + this.holoMap.values() + .forEach(set -> set.forEach(pair -> pair.getSecond().delete())); + this.holoMap.clear(); } @Override - public void create(@NotNull Dungeon dungeon, @Nullable ChestModule module) { - if (module == null) return; - + public void create(@NotNull Dungeon dungeon, @NotNull ChestModule module) { + Set> holograms = this.holoMap.computeIfAbsent(dungeon.getId(), set -> new HashSet<>()); List messages; - Set> holograms = this.holoMap.computeIfAbsent(dungeon.getId(), set -> new HashSet<>()); - for (DungeonChestBlock dungeonChestBlock : module.getChests()) { - Block block = dungeonChestBlock.getBlock(); - messages = new ArrayList<>(dungeonChestBlock.getDungeon().getHologramSettings().getMessages(dungeonChestBlock.getState())); - messages.replaceAll(dungeonChestBlock.replacePlaceholders()); + for (ChestBlock chestBlock : module.getChests()) { + Block block = chestBlock.getBlock(); + HologramSettings hologramSettings = chestBlock.getDungeon().getHologramSettings(); + List messageList = hologramSettings.getMessages(chestBlock.getState()); + messages = new ArrayList<>(messageList); + messages.replaceAll(chestBlock.replacePlaceholders()); + + Location location = fineLocation(chestBlock, block.getLocation()); + Hologram hologram = DHAPI.createHologram(UUID.randomUUID().toString(), location, messages); - Hologram hologram = DHAPI.createHologram(UUID.randomUUID().toString(), fineLocation(dungeonChestBlock, block.getLocation()), Colorizer.apply(messages)); hologram.showAll(); - holograms.add(Pair.of(dungeonChestBlock, hologram)); + holograms.add(Pair.of(chestBlock, hologram)); } + module.debug("Installed " + holograms.size() + " holograms for "+ ModuleId.HOLOGRAM+" Module"); } @NotNull - private Location fineLocation(@NotNull DungeonChestBlock dungeonChestBlock, @NotNull Location location) { - return LocationUtil.getCenter(location.clone()).add(0D, dungeonChestBlock.getDungeon().getHologramSettings().getOffsetY(), 0D); + private Location fineLocation(@NotNull ChestBlock chestBlock, @NotNull Location location) { + Dungeon dungeon = chestBlock.getDungeon(); + HologramSettings hologramSettings = dungeon.getHologramSettings(); + return LocationUtil.getCenter(location).add(0D, hologramSettings.getOffsetY(), 0D); } @Override public void delete(@NotNull Dungeon dungeon) { - Set> set = this.holoMap.remove(dungeon.getId()); + Set> set = this.holoMap.remove(dungeon.getId()); if (set == null) return; set.forEach(pair -> pair.getSecond().delete()); } @Override - public void update(@NotNull DungeonChestBlock dungeonChestBlock) { - Set> holograms = this.holoMap.computeIfAbsent(dungeonChestBlock.getDungeon().getId(), set -> new HashSet<>()); - holograms.stream().filter(f -> f.getFirst().equals(dungeonChestBlock)).map(Pair::getSecond).toList().forEach(hologram -> { - List messages = new ArrayList<>(dungeonChestBlock.getDungeon().getHologramSettings().getMessages(dungeonChestBlock.getState())); - messages.replaceAll(dungeonChestBlock.replacePlaceholders()); - updateHologramLines(dungeonChestBlock, hologram, messages); - }); + public void update(@NotNull ChestBlock chestBlock) { + Dungeon dungeon = chestBlock.getDungeon(); + Set> holograms = this.holoMap.computeIfAbsent(dungeon.getId(), set -> new HashSet<>()); + HologramSettings hologramSettings = dungeon.getHologramSettings(); + holograms + .stream() + .filter(f -> f.getFirst().equals(chestBlock)) + .map(Pair::getSecond) + .forEach(hologram -> { + List messages = new ArrayList<>(hologramSettings.getMessages(chestBlock.getState())); + messages.replaceAll(chestBlock.replacePlaceholders()); + updateHologramLines(chestBlock, hologram, messages); + }); } - private void updateHologramLines(@NotNull DungeonChestBlock dungeonChestBlock, @NotNull Hologram hologram, @NotNull List message) { + private void updateHologramLines(@NotNull ChestBlock chestBlock, @NotNull Hologram hologram, @NotNull List message) { List lines = hologram.getPage(0).getLines(); int lineCount = lines.size(); + Dungeon dungeon = chestBlock.getDungeon(); + MainSettings mainSettings = dungeon.getSettings(); + UnaryOperator settingsPlaceholder = mainSettings.replacePlaceholders(); + UnaryOperator chestBlockPlaceholder = chestBlock.replacePlaceholders(); + UnaryOperator dungeonPlaceholder = dungeon.replacePlaceholders(); for (int i = 0; i < Math.min(message.size(), lineCount); i++) { HologramLine line = lines.get(i); String originalText = line.getText(); String newText = message.get(i); - newText = dungeonChestBlock.getDungeon().getSettings().replacePlaceholders().apply(newText); - newText = dungeonChestBlock.replacePlaceholders().apply(newText); - newText = dungeonChestBlock.getDungeon().replacePlaceholders().apply(newText); + newText = settingsPlaceholder.apply(newText); + newText = chestBlockPlaceholder.apply(newText); + newText = dungeonPlaceholder.apply(newText); if (originalText == null || originalText.isEmpty() || !originalText.equals(newText)) { line.setText(Colorizer.apply(newText)); @@ -99,8 +116,8 @@ private void updateHologramLines(@NotNull DungeonChestBlock dungeonChestBlock, @ } else if (message.size() > lineCount) { for (int i = lineCount; i < message.size(); i++) { String newText = message.get(i); - newText = dungeonChestBlock.getDungeon().getSettings().replacePlaceholders().apply(newText); - newText = dungeonChestBlock.getDungeon().replacePlaceholders().apply(newText); + newText = settingsPlaceholder.apply(newText); + newText = dungeonPlaceholder.apply(newText); DHAPI.addHologramLine(hologram, 0, Colorizer.apply(newText)); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDisplaysHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDisplaysHandler.java index 7880758..f58e1b7 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDisplaysHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/holograms/HologramDisplaysHandler.java @@ -13,17 +13,18 @@ import t.me.p1azmer.engine.utils.LocationUtil; import t.me.p1azmer.engine.utils.Pair; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.api.hologram.HologramHandler; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; +import t.me.p1azmer.plugin.dungeons.api.handler.hologram.HologramHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestBlock; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class HologramDisplaysHandler implements HologramHandler { private HolographicDisplaysAPI hologramAPI; - private Map>> holoMap; + private final Map>> holoMap = new ConcurrentHashMap<>(); private final DungeonPlugin plugin; @@ -34,15 +35,12 @@ public HologramDisplaysHandler(@NotNull DungeonPlugin plugin) { @Override public void setup() { - this.holoMap = new HashMap<>(); } @Override public void shutdown() { - if (this.holoMap != null) { - this.holoMap.values().forEach(set -> set.forEach(pair -> pair.getSecond().delete())); - this.holoMap = null; - } + this.holoMap.values().forEach(set -> set.forEach(pair -> pair.getSecond().delete())); + this.holoMap.clear(); if (this.hologramAPI != null) { this.hologramAPI = null; } @@ -53,56 +51,56 @@ public void create(@NotNull Dungeon dungeon, @Nullable ChestModule module) { if (module == null) return; plugin.runTask(sync -> { List messages; - Set> holograms = this.holoMap.computeIfAbsent(dungeon.getId(), set -> new HashSet<>()); - for (DungeonChestBlock dungeonChestBlock : module.getChests()) { - Block block = dungeonChestBlock.getBlock(); + Set> holograms = this.holoMap.computeIfAbsent(dungeon.getId(), set -> new HashSet<>()); + for (ChestBlock chestBlock : module.getChests()) { + Block block = chestBlock.getBlock(); - messages = new ArrayList<>(dungeonChestBlock.getDungeon().getHologramSettings().getMessages(dungeonChestBlock.getState())); - messages.replaceAll(dungeonChestBlock.replacePlaceholders()); - Hologram hologram = this.hologramAPI.createHologram(this.fineLocation(dungeonChestBlock, block.getLocation())); + messages = new ArrayList<>(chestBlock.getDungeon().getHologramSettings().getMessages(chestBlock.getState())); + messages.replaceAll(chestBlock.replacePlaceholders()); + Hologram hologram = this.hologramAPI.createHologram(this.fineLocation(chestBlock, block.getLocation())); for (String line : messages) { hologram.getLines().appendText(Colorizer.apply(line)); } - holograms.add(Pair.of(dungeonChestBlock, hologram)); + holograms.add(Pair.of(chestBlock, hologram)); } }); } @NotNull - private Location fineLocation(@NotNull DungeonChestBlock dungeonChestBlock, @NotNull Location location) { - return LocationUtil.getCenter(location.clone()).add(0D, dungeonChestBlock.getDungeon().getHologramSettings().getOffsetY(), 0D); + private Location fineLocation(@NotNull ChestBlock chestBlock, @NotNull Location location) { + return LocationUtil.getCenter(location.clone()).add(0D, chestBlock.getDungeon().getHologramSettings().getOffsetY(), 0D); } @Override public void delete(@NotNull Dungeon dungeon) { - Set> set = this.holoMap.remove(dungeon.getId()); + Set> set = this.holoMap.remove(dungeon.getId()); if (set == null) return; set.forEach(pair -> pair.getSecond().delete()); } @Override - public void update(@NotNull DungeonChestBlock dungeonChestBlock) { + public void update(@NotNull ChestBlock chestBlock) { plugin.runTask(sync -> { - Set> holograms = this.holoMap.computeIfAbsent(dungeonChestBlock.getDungeon().getId(), set -> new HashSet<>()); - holograms.stream().filter(f -> f.getFirst().equals(dungeonChestBlock)).map(Pair::getSecond).toList().forEach(hologram -> { - List messages = new ArrayList<>(dungeonChestBlock.getDungeon().getHologramSettings().getMessages(dungeonChestBlock.getState())); - messages.replaceAll(dungeonChestBlock.replacePlaceholders()); - updateHologramLines(dungeonChestBlock, hologram, messages); + Set> holograms = this.holoMap.computeIfAbsent(chestBlock.getDungeon().getId(), set -> new HashSet<>()); + holograms.stream().filter(f -> f.getFirst().equals(chestBlock)).map(Pair::getSecond).toList().forEach(hologram -> { + List messages = new ArrayList<>(chestBlock.getDungeon().getHologramSettings().getMessages(chestBlock.getState())); + messages.replaceAll(chestBlock.replacePlaceholders()); + updateHologramLines(chestBlock, hologram, messages); }); }); } - private void updateHologramLines(@NotNull DungeonChestBlock dungeonChestBlock, @NotNull Hologram hologram, @NotNull List message) { + private void updateHologramLines(@NotNull ChestBlock chestBlock, @NotNull Hologram hologram, @NotNull List message) { HologramLines lines = hologram.getLines(); int lineCount = lines.size(); for (int i = 0; i < Math.min(lineCount, message.size()); i++) { if (lines.get(i) instanceof TextHologramLine line) { String originalText = line.getText(); String newText = message.get(i); - newText = dungeonChestBlock.replacePlaceholders().apply(newText); - newText = dungeonChestBlock.getDungeon().getSettings().replacePlaceholders().apply(newText); - newText = dungeonChestBlock.getDungeon().replacePlaceholders().apply(newText); + newText = chestBlock.replacePlaceholders().apply(newText); + newText = chestBlock.getDungeon().getSettings().replacePlaceholders().apply(newText); + newText = chestBlock.getDungeon().replacePlaceholders().apply(newText); if (originalText == null || originalText.isEmpty() || !originalText.equals(newText)) { line.setText(Colorizer.apply(newText)); @@ -118,9 +116,9 @@ private void updateHologramLines(@NotNull DungeonChestBlock dungeonChestBlock, @ } else if (message.size() > lineCount) { for (int i = lineCount; i < message.size(); i++) { String newText = message.get(i); - newText = dungeonChestBlock.replacePlaceholders().apply(newText); - newText = dungeonChestBlock.getDungeon().getSettings().replacePlaceholders().apply(newText); - newText = dungeonChestBlock.getDungeon().replacePlaceholders().apply(newText); + newText = chestBlock.replacePlaceholders().apply(newText); + newText = chestBlock.getDungeon().getSettings().replacePlaceholders().apply(newText); + newText = chestBlock.getDungeon().replacePlaceholders().apply(newText); hologram.getLines().appendText(Colorizer.apply(newText)); } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/party/PartyHandlerPaF.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/party/PartyHandlerPaF.java index 74c1bfa..463aa12 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/party/PartyHandlerPaF.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/party/PartyHandlerPaF.java @@ -6,36 +6,41 @@ import de.simonsator.partyandfriends.spigot.api.party.PlayerParty; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.plugin.dungeons.api.party.PartyHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.party.PartyHandler; public class PartyHandlerPaF implements PartyHandler { - private PartyManager partyManager; @Override - public int getPartySize(@NotNull Player player) { - PAFPlayer pafPlayer= PAFPlayerManager.getInstance().getPlayer(player.getUniqueId()); - PlayerParty party=PartyManager.getInstance().getParty(pafPlayer); - if (party == null) return 0; - return party.getAllPlayers().size(); + public void setup() { + this.partyManager = PartyManager.getInstance(); } @Override - public boolean isInParty(@NotNull Player player) { - PAFPlayer pafPlayer= PAFPlayerManager.getInstance().getPlayer(player.getUniqueId()); - PlayerParty party=PartyManager.getInstance().getParty(pafPlayer); - return party!=null; + public void shutdown() { + if (this.partyManager != null) this.partyManager = null; } @Override - public void setup() { - this.partyManager = PartyManager.getInstance(); + public int getPartySize(@NotNull Player player) { + PartyManager manager = PartyManager.getInstance(); + PAFPlayerManager pafPlayerManager = PAFPlayerManager.getInstance(); + + PAFPlayer pafPlayer = pafPlayerManager.getPlayer(player.getUniqueId()); + PlayerParty party = manager.getParty(pafPlayer); + + if (party == null) return 0; + return party.getAllPlayers().size(); } @Override - public void shutdown() { - if (this.partyManager != null){ - this.partyManager = null; - } + public boolean isInParty(@NotNull Player player) { + PAFPlayerManager pafPlayerManager = PAFPlayerManager.getInstance(); + PartyManager manager = PartyManager.getInstance(); + + PAFPlayer pafPlayer = pafPlayerManager.getPlayer(player.getUniqueId()); + PlayerParty party = manager.getParty(pafPlayer); + + return party != null; } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGD.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGD.java index 8185dc4..9f12fa4 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGD.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGD.java @@ -10,22 +10,20 @@ import org.bukkit.World; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; -import java.util.HashMap; import java.util.Map; import java.util.Objects; -import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; public class RegionHandlerGD implements RegionHandler { - private Core griefDefender; - private final UUID ownerId = UUID.fromString("1492a9a4-4277-4eb6-897a-b346d76bc1e0"); - private DungeonPlugin plugin; - private Map claimMap; + private final DungeonPlugin plugin; + private final Map claimMap = new ConcurrentHashMap<>(); public RegionHandlerGD(@NotNull DungeonPlugin plugin) { this.plugin = plugin; @@ -34,67 +32,57 @@ public RegionHandlerGD(@NotNull DungeonPlugin plugin) { @Override public void setup() { this.griefDefender = GriefDefender.getCore(); - this.claimMap = new HashMap<>(); } @Override public void shutdown() { - if (this.claimMap != null) { - this.claimMap.values() - .stream().filter(Objects::nonNull) - .filter(Claim::isAdminClaim) - .forEach(f -> { - ClaimManager claimManager = this.griefDefender.getClaimManager(f.getWorldUniqueId()); - if (claimManager != null) - claimManager.deleteClaim(f); - }); - this.claimMap.clear(); - this.claimMap = null; - } - if (this.plugin != null) { - this.plugin = null; - } - if (this.griefDefender != null) { - this.griefDefender = null; - } + this.claimMap.values() + .stream().filter(Objects::nonNull) + .filter(Claim::isAdminClaim) + .forEach(f -> { + ClaimManager claimManager = this.griefDefender.getClaimManager(f.getWorldUniqueId()); + if (claimManager != null) + claimManager.deleteClaim(f); + }); + this.claimMap.clear(); } @Override public void create(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isEnabled()) return; double regionRadius = region.getRadius(); - Location location = dungeon.getLocation(); - if (location == null) return; - World world = dungeon.getWorld(); + dungeon.getLocation().ifPresent(location -> { + World world = dungeon.getWorld(); - ClaimManager claimManager = this.griefDefender.getClaimManager(world.getUID()); - if (claimManager == null) { - DungeonStage.call(dungeon, DungeonStage.CANCELLED, "GriefDefender not found the claim manager at this world"); - return; - } - Location first = location.clone().add(-regionRadius, regionRadius, regionRadius); - Location second = location.clone().add(regionRadius, -regionRadius, -regionRadius); - ClaimResult result = Claim.builder() - .world(world.getUID()) - .bounds(first.getBlockX(), first.getBlockX(), first.getBlockY(), second.getBlockY(), second.getBlockZ(), second.getBlockZ()) - .type(ClaimTypes.ADMIN) - .expire(false) - .denyMessages(false) - .inherit(false) - .build(); - if (!result.successful()) { - plugin.error("Plugin GriefDefender did not create a region on the location"); - } else { - this.claimMap.put(dungeon, result.getClaim()); - } + ClaimManager claimManager = this.griefDefender.getClaimManager(world.getUID()); + if (claimManager == null) { + CompletableFuture.runAsync(() -> DungeonStage.call(dungeon, DungeonStage.CANCELLED, "GriefDefender not found the claim manager at this world")); + return; + } + Location first = location.clone().add(-regionRadius, regionRadius, regionRadius); + Location second = location.clone().add(regionRadius, -regionRadius, -regionRadius); + ClaimResult result = Claim.builder() + .world(world.getUID()) + .bounds(first.getBlockX(), first.getBlockX(), first.getBlockY(), second.getBlockY(), second.getBlockZ(), second.getBlockZ()) + .type(ClaimTypes.ADMIN) + .expire(false) + .denyMessages(false) + .inherit(false) + .build(); + if (!result.successful()) { + plugin.error("Plugin GriefDefender did not create a region on the location"); + } else { + this.claimMap.put(dungeon, result.getClaim()); + } + }); //result.claim.setPermission(this.ownerId, ClaimPermission.Build); } @Override public void delete(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isCreated()) return; Claim claim = this.claimMap.get(dungeon); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGP.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGP.java index 37227d3..31f8995 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGP.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerGP.java @@ -6,18 +6,18 @@ import org.bukkit.Location; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class RegionHandlerGP implements RegionHandler { private GriefPrevention griefPrevention; - private DungeonPlugin plugin; - private Map claimMap; + private final DungeonPlugin plugin; + private final Map claimMap = new ConcurrentHashMap<>(); public RegionHandlerGP(@NotNull DungeonPlugin plugin) { this.plugin = plugin; @@ -26,49 +26,38 @@ public RegionHandlerGP(@NotNull DungeonPlugin plugin) { @Override public void setup() { this.griefPrevention = GriefPrevention.instance; - this.claimMap = new HashMap<>(); } @Override public void shutdown() { - if (this.claimMap != null) { - this.claimMap.values().forEach(f -> this.griefPrevention.dataStore.deleteClaim(f)); - this.claimMap.clear(); - this.claimMap = null; - } - if (this.plugin != null) { - this.plugin = null; - } - if (this.griefPrevention != null) { - this.griefPrevention = null; - } + this.claimMap.values().forEach(f -> this.griefPrevention.dataStore.deleteClaim(f)); + this.claimMap.clear(); } @Override public void create(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isEnabled()) return; double regionRadius = region.getRadius(); - Location location = dungeon.getLocation(); - if (location == null) return; - org.bukkit.World world = dungeon.getWorld(); + dungeon.getLocation().ifPresent(location -> { + org.bukkit.World world = dungeon.getWorld(); - Location first = location.clone().add(-regionRadius, regionRadius, regionRadius); - Location second = location.clone().add(regionRadius, -regionRadius, -regionRadius); - CreateClaimResult result = this.griefPrevention.dataStore.createClaim(world, first.getBlockX(), first.getBlockX(), first.getBlockY(), second.getBlockY(), second.getBlockZ(), second.getBlockZ(), null, null, (long) (new HashSet<>(this.griefPrevention.dataStore.getClaims()).size() + 1), null); - if (!result.succeeded) { - plugin.error("Plugin " + this.griefPrevention.getName() + " did not create a region on the location"); - } else { - this.claimMap.put(dungeon, result.claim); - - } + Location first = location.clone().add(-regionRadius, regionRadius, regionRadius); + Location second = location.clone().add(regionRadius, -regionRadius, -regionRadius); + CreateClaimResult result = this.griefPrevention.dataStore.createClaim(world, first.getBlockX(), first.getBlockX(), first.getBlockY(), second.getBlockY(), second.getBlockZ(), second.getBlockZ(), null, null, (long) (new HashSet<>(this.griefPrevention.dataStore.getClaims()).size() + 1), null); + if (!result.succeeded) { + plugin.error("Plugin " + this.griefPrevention.getName() + " did not create a region on the location"); + } else { + this.claimMap.put(dungeon, result.claim); + } + }); //result.claim.setPermission(this.ownerId, ClaimPermission.Build); } @Override public void delete(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isCreated()) return; Claim claim = this.claimMap.get(dungeon); @@ -82,7 +71,7 @@ public void delete(@NotNull Dungeon dungeon) { public boolean isValidLocation(@NotNull Location location) { long ms = System.currentTimeMillis(); Claim claim = this.griefPrevention.dataStore.getClaimAt(location, false, false, null); - plugin.error("Valid took " + (System.currentTimeMillis()-ms) + "ms"); + plugin.error("Valid took " + (System.currentTimeMillis() - ms) + "ms"); return claim == null; } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerKingdoms.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerKingdoms.java index c570f18..484f065 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerKingdoms.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerKingdoms.java @@ -12,11 +12,14 @@ import org.kingdoms.events.lands.ClaimLandEvent; import org.kingdoms.events.lands.UnclaimLandEvent; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; -import java.util.*; +import java.util.Map; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class RegionHandlerKingdoms implements RegionHandler { @@ -24,8 +27,8 @@ public class RegionHandlerKingdoms implements RegionHandler { private LandManager landManager; private final UUID ownerId = UUID.fromString("1492a9a4-4277-4eb6-897a-b346d76bc1e0"); private final UUID kdPlayer = UUID.fromString("1492a9a5-4277-4eb6-897b-b346d76bc1e0"); - private DungeonPlugin plugin; - private Map claimMap; + private final DungeonPlugin plugin; + private final Map claimMap = new ConcurrentHashMap<>(); public RegionHandlerKingdoms(@NotNull DungeonPlugin plugin) { this.plugin = plugin; @@ -40,46 +43,35 @@ public void setup() { this.kingdomPlayer.joinKingdom(new Kingdom(kdPlayer, "PLAZMER_DUNGEON_KINGDOM")); } this.landManager = KingdomsDataCenter.get().getLandManager(); - this.claimMap = new HashMap<>(); } @Override public void shutdown() { - if (this.claimMap != null) { - this.claimMap.entrySet() - .stream().filter(Objects::nonNull) - .filter(entry -> entry.getKey().getLocation() != null && this.landManager.isLoaded(SimpleChunkLocation.of(entry.getKey().getLocation()))) - .forEach(f -> { - this.landManager.delete(SimpleChunkLocation.of(f.getKey().getLocation())); - }); - this.claimMap.clear(); - this.claimMap = null; - } - if (this.plugin != null) { - this.plugin = null; - } - if (this.landManager != null) { - this.landManager = null; - } + this.claimMap.entrySet() + .stream().filter(Objects::nonNull) + .filter(entry -> entry.getKey().getLocation().isPresent() && this.landManager.isLoaded(SimpleChunkLocation.of(entry.getKey().getLocation().get()))) + .forEach(f -> { + this.landManager.delete(SimpleChunkLocation.of(f.getKey().getLocation().get())); + }); + this.claimMap.clear(); } @Override public void create(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); - if (!region.isEnabled()) return; - - Location location = dungeon.getLocation(); - if (location == null || kingdomPlayer.getKingdom() == null) return; - - kingdomPlayer.getKingdom().claim(SimpleChunkLocation.of(location), kingdomPlayer, ClaimLandEvent.Reason.ADMIN); - - this.claimMap.put(dungeon, this.landManager.getData(SimpleChunkLocation.of(location))); + Region region = dungeon.getRegion(); + Kingdom kingdom = kingdomPlayer.getKingdom(); + if (kingdom == null || kingdomPlayer == null || !region.isEnabled()) return; + + dungeon.getLocation().ifPresent(location -> { + kingdom.claim(SimpleChunkLocation.of(location), kingdomPlayer, ClaimLandEvent.Reason.ADMIN); + this.claimMap.put(dungeon, this.landManager.getData(SimpleChunkLocation.of(location))); + }); //result.claim.setPermission(this.ownerId, ClaimPermission.Build); } @Override public void delete(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isCreated()) return; Land land = this.claimMap.get(dungeon); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerPB.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerPB.java index 8048073..fd27b86 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerPB.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerPB.java @@ -4,8 +4,8 @@ import org.bukkit.World; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import t.me.p1azmer.plugin.protectionblocks.ProtectionAPI; import t.me.p1azmer.plugin.protectionblocks.region.RegionManager; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerTowny.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerTowny.java index ada8e79..e774682 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerTowny.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerTowny.java @@ -10,21 +10,21 @@ import org.bukkit.World; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; -import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class RegionHandlerTowny implements RegionHandler { private TownyAPI townyAPI; private final UUID ownerId = UUID.fromString("1492a9a4-4277-4eb6-897a-b346d76bc1e0"); - private DungeonPlugin plugin; - private Map claimMap; + private final DungeonPlugin plugin; + private final Map claimMap = new ConcurrentHashMap<>(); public RegionHandlerTowny(@NotNull DungeonPlugin plugin) { this.plugin = plugin; @@ -33,55 +33,44 @@ public RegionHandlerTowny(@NotNull DungeonPlugin plugin) { @Override public void setup() { this.townyAPI = TownyAPI.getInstance(); - this.claimMap = new HashMap<>(); } @Override public void shutdown() { - if (this.claimMap != null) { - this.claimMap.entrySet() - .stream().filter(Objects::nonNull) - .forEach(entry -> { - this.townyAPI.getDataSource().deleteTown(entry.getValue()); - try { - TownyUniverse.getInstance().unregisterTown(entry.getValue()); - } catch (NotRegisteredException ignored) { - } - }); - this.claimMap.clear(); - this.claimMap = null; - } - if (this.plugin != null) { - this.plugin = null; - } - if (this.townyAPI != null) { - this.townyAPI = null; - } + this.claimMap.entrySet() + .stream().filter(Objects::nonNull) + .forEach(entry -> { + this.townyAPI.getDataSource().deleteTown(entry.getValue()); + try { + TownyUniverse.getInstance().unregisterTown(entry.getValue()); + } catch (NotRegisteredException ignored) { + } + }); + this.claimMap.clear(); } @Override public void create(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isEnabled()) return; - Location location = dungeon.getLocation(); - if (location == null) return; - - Town town = new Town(region.getName(), ownerId); - - if (dungeon.getDungeonCuboid() != null) - dungeon.getDungeonCuboid().getBlocks().forEach(block -> { - TownBlock townBlock = new TownBlock(WorldCoord.parseWorldCoord(block)); - townBlock.setTown(town, false); - }); - - this.claimMap.put(dungeon, town); + dungeon.getLocation().ifPresent(location -> { + Town town = new Town(region.getName(), ownerId); + + dungeon.getDungeonCuboid().ifPresent(cuboid -> + cuboid.getBlocks().forEach(block -> { + TownBlock townBlock = new TownBlock(WorldCoord.parseWorldCoord(block)); + townBlock.setTown(town, false); + }) + ); + this.claimMap.put(dungeon, town); + }); //result.claim.setPermission(this.ownerId, ClaimPermission.Build); } @Override public void delete(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isCreated()) return; Town town = this.claimMap.get(dungeon); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerWG.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerWG.java index d01a1d6..f7f35d0 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerWG.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/region/RegionHandlerWG.java @@ -12,9 +12,9 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.jetbrains.annotations.NotNull; -import t.me.p1azmer.plugin.dungeons.api.region.RegionHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.region.RegionHandler; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.categories.Region; +import t.me.p1azmer.plugin.dungeons.dungeon.region.Region; import java.util.Comparator; import java.util.Objects; @@ -42,27 +42,26 @@ public void shutdown() { @Override public void create(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isEnabled()) return; double regionRadius = region.getRadius(); - Location location = dungeon.getLocation(); - if (location == null) return; - org.bukkit.World world = dungeon.getWorld(); - if (world == null) return; - String regionName = region.getNameRaw(); - - ProtectedRegion protectedRegion = new ProtectedCuboidRegion(regionName, convertToSk89qBV(location.clone().add(-regionRadius, regionRadius, regionRadius)), convertToSk89qBV(location.clone().add(regionRadius, -regionRadius, -regionRadius))); - Objects.requireNonNull(WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world))).addRegion(protectedRegion); - for (String flag : region.getFlags()) { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "region flag -w " + world.getName() + " " + regionName + " " + flag); - } - region.setCreated(true); + dungeon.getLocation().ifPresent(location -> { + org.bukkit.World world = dungeon.getWorld(); + String regionName = region.getNameRaw(); + + ProtectedRegion protectedRegion = new ProtectedCuboidRegion(regionName, convertToSk89qBV(location.clone().add(-regionRadius, regionRadius, regionRadius)), convertToSk89qBV(location.clone().add(regionRadius, -regionRadius, -regionRadius))); + Objects.requireNonNull(WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world))).addRegion(protectedRegion); + for (String flag : region.getFlags()) { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "region flag -w " + world.getName() + " " + regionName + " " + flag); + } + region.setCreated(true); + }); } @Override public void delete(@NotNull Dungeon dungeon) { - Region region = dungeon.getDungeonRegion(); + Region region = dungeon.getRegion(); if (!region.isCreated()) return; World world = BukkitAdapter.adapt(dungeon.getWorld()); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/schematics/SchematicFAWEHandler.java b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/schematics/SchematicFAWEHandler.java index 130dee3..b93c1f1 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/integration/schematics/SchematicFAWEHandler.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/integration/schematics/SchematicFAWEHandler.java @@ -1,9 +1,6 @@ package t.me.p1azmer.plugin.dungeons.integration.schematics; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.*; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -24,11 +21,12 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; -import t.me.p1azmer.plugin.dungeons.api.schematic.SchematicHandler; +import t.me.p1azmer.plugin.dungeons.api.handler.schematic.SchematicHandler; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; import java.io.BufferedInputStream; @@ -39,11 +37,12 @@ import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; public class SchematicFAWEHandler implements SchematicHandler { - private Map editSessionMap; - private Map placedMap; + private final Map editSessionMap = new HashMap<>(); + private final Map placedMap = new HashMap<>(); private final DungeonPlugin plugin; private WorldEdit worldEdit; @@ -53,35 +52,25 @@ public SchematicFAWEHandler(@NotNull DungeonPlugin plugin) { @Override public void setup() { - this.placedMap = new HashMap<>(); - this.editSessionMap = new HashMap<>(); this.worldEdit = WorldEdit.getInstance(); } @Override public void shutdown() { - if (this.placedMap != null) { - this.placedMap.forEach((dungeon, location) -> this.undo(dungeon)); - this.placedMap = null; - } - if (this.editSessionMap != null) { - this.editSessionMap = null; - } - if (this.worldEdit != null) { - this.worldEdit = null; - } + this.placedMap.forEach((dungeon, location) -> this.undo(dungeon)); + + this.editSessionMap.clear(); + this.placedMap.clear(); } @Override - public boolean paste(@NotNull Dungeon dungeon, @NotNull File schematicFile) { - Location location = dungeon.getLocation(); + public CompletableFuture paste(@NotNull Dungeon dungeon, @NotNull File schematicFile) { + Location location = dungeon.getLocation().orElse(null); if (location == null) { - return false; - } - - if (!this.undo(dungeon)) { - return false; + // TODO add debug message + return CompletableFuture.completedFuture(false); } + if (!this.undo(dungeon)) return CompletableFuture.completedFuture(false); World world = location.getWorld(); if (world == null) { @@ -108,35 +97,46 @@ public boolean paste(@NotNull Dungeon dungeon, @NotNull File schematicFile) { session.setClipboard(holder); BlockVector3 toVector = BlockVector3.at(location.getX(), location.getY(), location.getZ()); com.sk89q.worldedit.world.World weWorld = BukkitAdapter.adapt(world); + CompletableFuture future = new CompletableFuture<>(); + plugin.runTask(sync -> { + try (EditSession editSession = this.worldEdit.newEditSession(weWorld)) { + editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE); + + Operation operation = session.getClipboard() + .createPaste(editSession) + .to(toVector) + .ignoreAirBlocks(dungeon.getSchematicSettings().isIgnoreAirBlocks()) + .copyEntities(true) + .build(); + Operations.complete(operation); + Clipboard clipboard = session.getClipboard().getClipboard(); + Region region = clipboard.getRegion(); + + BlockVector3 minimumPoint = clipboard.getRegion().getMinimumPoint(); + BlockVector3 maximumPoint = region.getMaximumPoint(); + + BlockVector3 clipboardOffset = minimumPoint.subtract(clipboard.getOrigin()); + Vector3 realTo = toVector.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3())); + Vector3 max = realTo.add(holder.getTransform().apply(maximumPoint.subtract(region.getMinimumPoint()).toVector3())); + RegionSelector selector = new CuboidRegionSelector(weWorld, realTo.toBlockPoint(), max.toBlockPoint()); + + session.setRegionSelector(weWorld, selector); + selector.learnChanges(); + selector.explainRegionAdjust(actor, session); + + this.extracted(dungeon, location, editSession); + future.complete(true); + } catch (WorldEditException e) { + future.complete(false); + throw new RuntimeException("Reach limit of block change when paste the schematic at '" + dungeon.getId() + "' dungeon!"); + } + }); + return future; + } - try (EditSession editSession = this.worldEdit.newEditSession(weWorld)) { - editSession.setReorderMode(EditSession.ReorderMode.MULTI_STAGE); - - Operation operation = session.getClipboard() - .createPaste(editSession) - .to(toVector) - .ignoreAirBlocks(dungeon.getSchematicSettings().isIgnoreAirBlocks()) - .copyEntities(true) - .build(); - Operations.complete(operation); - Clipboard clipboard = session.getClipboard().getClipboard(); - Region region = clipboard.getRegion(); - - BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - Vector3 realTo = toVector.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3())); - Vector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())); - RegionSelector selector = new CuboidRegionSelector(weWorld, realTo.toBlockPoint(), max.toBlockPoint()); - - session.setRegionSelector(weWorld, selector); - selector.learnChanges(); - selector.explainRegionAdjust(actor, session); - - this.getEditSessionMap().put(location, editSession); - this.placedMap.put(dungeon, location); - return true; - } catch (WorldEditException e) { - throw new RuntimeException("Reach limit of block change when paste the schematic at '" + dungeon.getId() + "' dungeon!"); - } + private void extracted(@NotNull Dungeon dungeon, @NotNull Location location, @NotNull EditSession editSession) { + this.getEditSessionMap().put(location, editSession); + this.placedMap.put(dungeon, location); } @Override @@ -144,17 +144,20 @@ public boolean undo(@NotNull Dungeon dungeon) { if (!this.placedMap.containsKey(dungeon)) return true; Location location = this.placedMap.get(dungeon); if (location == null) return true; - if (!this.getEditSessionMap().containsKey(location)) return true; + boolean contained = this.getEditSessionMap().containsKey(location); + if (!contained) return true; try { Actor actor = this.plugin.getSessionConsole(); EditSession editSession = this.getEditSessionMap().get(location); + if (editSession == null) return false; BlockBag blockBag = editSession.getBlockBag(); LocalSession session = this.plugin.getSessionConsole(); session.setWorldOverride(editSession.getWorld()); - try (EditSession newEditSession = WorldEdit.getInstance().newEditSessionBuilder().blockBag(blockBag).actor(actor).world(editSession.getWorld()).build()) { + EditSessionBuilder sessionBuilder = WorldEdit.getInstance().newEditSessionBuilder(); + try (EditSession newEditSession = sessionBuilder.blockBag(blockBag).actor(actor).world(editSession.getWorld()).build()) { editSession.undo(newEditSession); } @@ -180,6 +183,10 @@ public boolean containsChestBlock(@NotNull Dungeon dungeon, @NotNull File schema return false; } Clipboard clipboard = holder.getClipboard(); + if (clipboard == null) { + this.plugin.error("The schematic module returned the following error: Clipboard for file not found or invalid"); + return false; + } BlockVector3 minPoint = clipboard.getMinimumPoint(); BlockVector3 maxPoint = clipboard.getMaximumPoint(); @@ -192,7 +199,11 @@ public boolean containsChestBlock(@NotNull Dungeon dungeon, @NotNull File schema if (block.getBlockType() == null) continue; if (block.getBlockType().getMaterial().isAir()) continue; - BlockType chestBlock = BlockTypes.get("minecraft:" + dungeon.getChestSettings().getMaterial().name().toLowerCase(Locale.ROOT)); + Material material = dungeon.getChestSettings().getMaterial(); + String materialName = material.name(); + String id = "minecraft:" + materialName.toLowerCase(Locale.ROOT); + + BlockType chestBlock = BlockTypes.get(id); if (block.getBlockType().equals(chestBlock)) { return true; } @@ -232,7 +243,11 @@ public int getAmountOfChestBlocks(@NotNull Dungeon dungeon, @NotNull File schema if (block.getBlockType() == null) continue; if (block.getBlockType().getMaterial().isAir()) continue; - BlockType chestBlock = BlockTypes.get("minecraft:" + dungeon.getChestSettings().getMaterial().name().toLowerCase(Locale.ROOT)); + Material material = dungeon.getChestSettings().getMaterial(); + String materialName = material.name(); + String id = "minecraft:" + materialName.toLowerCase(Locale.ROOT); + + BlockType chestBlock = BlockTypes.get(id); if (block.getBlockType().equals(chestBlock)) { amount++; } @@ -252,8 +267,10 @@ public Map getEditSessionMap() { return editSessionMap; } - private record SchematicLoadTask(@NotNull File file, - @NotNull ClipboardFormat format) implements Callable { + private record SchematicLoadTask( + @NotNull File file, + @NotNull ClipboardFormat format + ) implements Callable { private static final Map holderCache = new WeakHashMap<>(); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/key/Key.java b/src/main/java/t/me/p1azmer/plugin/dungeons/key/Key.java index 42399ce..5ad3e0e 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/key/Key.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/key/Key.java @@ -1,5 +1,7 @@ package t.me.p1azmer.plugin.dungeons.key; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; @@ -12,9 +14,10 @@ import t.me.p1azmer.engine.utils.PDCUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.Keys; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.key.editor.KeyMainEditor; +@Getter +@Setter public class Key extends AbstractConfigHolder implements IPlaceholderMap, ICleanable { private String name; @@ -24,7 +27,10 @@ public class Key extends AbstractConfigHolder implements IPlaceho private final PlaceholderMap placeholderMap; - public Key(@NotNull DungeonPlugin plugin, @NotNull JYML cfg) { + public Key( + @NotNull DungeonPlugin plugin, + @NotNull JYML cfg + ) { super(plugin, cfg); this.placeholderMap = new PlaceholderMap() @@ -73,10 +79,6 @@ public KeyMainEditor getEditor() { return this.editor; } - public String getName() { - return name; - } - @NotNull public ItemStack getRawItem() { return new ItemStack(item); @@ -88,12 +90,4 @@ public ItemStack getItem() { PDCUtil.set(item, Keys.DUNGEON_KEY_ID, this.getId()); return item; } - - public void setName(String name) { - this.name = name; - } - - public void setItem(ItemStack item) { - this.item = item; - } } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/key/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/key/Placeholders.java new file mode 100644 index 0000000..80d58d5 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/key/Placeholders.java @@ -0,0 +1,7 @@ +package t.me.p1azmer.plugin.dungeons.key; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.Placeholders { + public static final String KEY_ID = "%key_id%"; + public static final String KEY_NAME = "%key_name%"; + public static final String KEY_ITEM_NAME = "%key_item_name%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/lang/Lang.java b/src/main/java/t/me/p1azmer/plugin/dungeons/lang/Lang.java index d0f45e1..35724f0 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/lang/Lang.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/lang/Lang.java @@ -3,122 +3,210 @@ import org.bukkit.Sound; import t.me.p1azmer.engine.api.lang.LangKey; import t.me.p1azmer.engine.lang.EngineLang; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.engine.utils.Colors2; +import t.me.p1azmer.plugin.dungeons.dungeon.Placeholders; import static t.me.p1azmer.engine.utils.Colors.*; public class Lang extends EngineLang { - - public static final LangKey COMMAND_EDITOR_DESC = LangKey.of("Command.Editor.Desc", "Open the dungeon and key editor."); - - public static final LangKey COMMAND_DROP_USAGE = LangKey.of("Command.Drop.Usage", " "); - public static final LangKey COMMAND_DROP_DESC = LangKey.of("Command.Drop.Desc", "Place a dungeon at the specified location in the world."); - public static final LangKey COMMAND_DROP_DONE = LangKey.of("Command.Drop.Done", GRAY + "Dungeon " + YELLOW + Placeholders.DUNGEON_NAME + GRAY + " has been placed at coordinates " + YELLOW + Placeholders.LOCATION_X + ", " + Placeholders.LOCATION_Y + ", " + Placeholders.LOCATION_Z + GRAY + " in world " + YELLOW + Placeholders.LOCATION_WORLD + GRAY + "."); - public static final LangKey COMMAND_DROP_ERROR = LangKey.of("Command.Drop.Error", RED + "An error occurred while trying to spawn a " + LIGHT_PURPLE + Placeholders.DUNGEON_NAME + RED + "! See the error in the console"); - - public static final LangKey COMMAND_DEL_USAGE = LangKey.of("Command.Delete.Usage", ""); - public static final LangKey COMMAND_DEL_DESC = LangKey.of("Command.Delete.Desc", "Despawn a specific or all dungeon."); - public static final LangKey COMMAND_DEL_DONE = LangKey.of("Command.Delete.Done", GRAY + "Dungeon " + YELLOW + Placeholders.DUNGEON_NAME + GRAY + " has been despawned"); - public static final LangKey COMMAND_KEY_DESC = LangKey.of("Command.Key.Desc", "Manage player keys."); - public static final LangKey COMMAND_KEY_USAGE = LangKey.of("Command.Key.Usage", "[help]"); - - public static final LangKey COMMAND_KEY_GIVE_USAGE = LangKey.of("Command.Key.Give.Usage", " [-s]"); - public static final LangKey COMMAND_KEY_GIVE_DESC = LangKey.of("Command.Key.Give.Desc", "Give a key to a player."); - public static final LangKey COMMAND_KEY_GIVE_DONE = LangKey.of("Command.Key.Give.Done", GRAY + "Given " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + Placeholders.KEY_NAME + GRAY + " to player " + YELLOW + Placeholders.PLAYER_NAME + GRAY + "."); - public static final LangKey COMMAND_KEY_GIVE_NOTIFY = LangKey.of("Command.Key.Give.Notify", GRAY + "You have received " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + Placeholders.KEY_NAME + GRAY + "!"); - - public static final LangKey COMMAND_KEY_GIVE_ALL_USAGE = LangKey.of("Command.Key.GiveAll.Usage", " [-s]"); - public static final LangKey COMMAND_KEY_GIVE_ALL_DESC = LangKey.of("Command.Key.GiveAll.Desc", "Give a key to all online players."); - public static final LangKey COMMAND_KEY_GIVE_ALL_DONE = LangKey.of("Command.Key.GiveAll.Done", GRAY + "Given " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + Placeholders.KEY_NAME + GRAY + " to all players."); - - public static final LangKey COMMAND_KEY_TAKE_USAGE = LangKey.of("Command.Key.Take.Usage", " [-s]"); - public static final LangKey COMMAND_KEY_TAKE_DESC = LangKey.of("Command.Key.Take.Desc", "Take a key from a player."); - public static final LangKey COMMAND_KEY_TAKE_DONE = LangKey.of("Command.Key.Take.Done", GRAY + "Taken " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + Placeholders.KEY_NAME + GRAY + " from player " + YELLOW + Placeholders.PLAYER_NAME + GRAY + "."); - public static final LangKey COMMAND_KEY_TAKE_NOTIFY = LangKey.of("Command.Key.Take.Notify", GRAY + "You have lost #fd5e5ex" + Placeholders.GENERIC_AMOUNT + " " + Placeholders.KEY_NAME + GRAY + "."); - - public static final LangKey COMMAND_KEY_SET_USAGE = LangKey.of("Command.Key.Set.Usage", " [-s]"); - public static final LangKey COMMAND_KEY_SET_DESC = LangKey.of("Command.Key.Set.Desc", "Set the number of keys for a player."); - public static final LangKey COMMAND_KEY_SET_DONE = LangKey.of("Command.Key.Set.Done", GRAY + "The number of keys of type " + YELLOW + Placeholders.KEY_NAME + GRAY + " for player " + YELLOW + Placeholders.PLAYER_NAME + GRAY + " has been changed to " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + "."); - public static final LangKey COMMAND_KEY_SET_NOTIFY = LangKey.of("Command.Key.Set.Notify", GRAY + "The number of your keys of type " + YELLOW + Placeholders.KEY_NAME + GRAY + " has been changed to " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + "."); - - public static final LangKey DUNGEON_ERROR_INVALID = LangKey.of("Dungeon.Error.Invalid", RED + "Invalid dungeon!"); - public static final LangKey DUNGEON_ERROR_EXISTS = LangKey.of("Dungeon.Error.Exists", RED + "A dungeon with that ID already exists!"); - - public static final LangKey DUNGEON_KEY_ERROR_INVALID = LangKey.of("Dungeon.Key.Error.Invalid", RED + "Invalid key!"); - public static final LangKey DUNGEON_KEY_ERROR_EXISTS = LangKey.of("Dungeon.Key.Error.Exists", RED + "A key with that ID already exists!"); + public static final LangKey COMMAND_EDITOR_DESC = LangKey.of("Command.Editor.Desc", + "Open the dungeon and key editor."); + + + public static final LangKey COMMAND_DROP_USAGE = LangKey.of("Command.Drop.Usage", + " "); + public static final LangKey COMMAND_DROP_DESC = LangKey.of("Command.Drop.Desc", + "Place a dungeon at the specified location in the world."); + public static final LangKey COMMAND_DROP_DONE = LangKey.of("Command.Drop.Done", + GRAY + "Dungeon " + YELLOW + Placeholders.DUNGEON_NAME + GRAY + " has been placed at coordinates " + YELLOW + Placeholders.LOCATION_X + "," + + " " + Placeholders.LOCATION_Y + "," + + " " + Placeholders.LOCATION_Z + GRAY + " in world " + YELLOW + Placeholders.LOCATION_WORLD + GRAY + "."); + public static final LangKey COMMAND_DROP_RANDOM_SUCCESS = LangKey.of("Command.Drop.Random.Success", + GRAY + "The dungeon '" + YELLOW + Placeholders.DUNGEON_NAME + GRAY + "' has a location generation stage started\n" + + "after which it will be spawned according to the usual procedure"); + public static final LangKey COMMAND_DROP_ERROR = LangKey.of("Command.Drop.Error", + RED + "An error occurred while trying to spawn a " + LIGHT_PURPLE + Placeholders.DUNGEON_NAME + RED + "! See the error in the console"); + + + public static final LangKey COMMAND_DEL_USAGE = LangKey.of("Command.Delete.Usage", + ""); + public static final LangKey COMMAND_DEL_DESC = LangKey.of("Command.Delete.Desc", + "Despawn a specific or all dungeon."); + public static final LangKey COMMAND_DEL_DONE = LangKey.of("Command.Delete.Done", + GRAY + "Dungeon " + YELLOW + Placeholders.DUNGEON_NAME + GRAY + " has been despawned"); + public static final LangKey COMMAND_KEY_DESC = LangKey.of("Command.Key.Desc", + "Manage player keys."); + public static final LangKey COMMAND_KEY_USAGE = LangKey.of("Command.Key.Usage", + "[help]"); + + + public static final LangKey COMMAND_KEY_GIVE_USAGE = LangKey.of("Command.Key.Give.Usage", + " [-s]"); + public static final LangKey COMMAND_KEY_GIVE_DESC = LangKey.of("Command.Key.Give.Desc", + "Give a key to a player."); + public static final LangKey COMMAND_KEY_GIVE_DONE = LangKey.of("Command.Key.Give.Done", + GRAY + "Given " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + " to player " + YELLOW + Placeholders.PLAYER_NAME + GRAY + "."); + public static final LangKey COMMAND_KEY_GIVE_NOTIFY = LangKey.of("Command.Key.Give.Notify", + GRAY + "You have received " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + "!"); + public static final LangKey COMMAND_KEY_GIVE_ALL_USAGE = LangKey.of("Command.Key.GiveAll.Usage", + " [-s]"); + public static final LangKey COMMAND_KEY_GIVE_ALL_DESC = LangKey.of("Command.Key.GiveAll.Desc", + "Give a key to all online players."); + public static final LangKey COMMAND_KEY_GIVE_ALL_DONE = LangKey.of("Command.Key.GiveAll.Done", + GRAY + "Given " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + " to all players."); + + + public static final LangKey COMMAND_KEY_TAKE_USAGE = LangKey.of("Command.Key.Take.Usage", + " [-s]"); + public static final LangKey COMMAND_KEY_TAKE_DESC = LangKey.of("Command.Key.Take.Desc", + "Take a key from a player."); + public static final LangKey COMMAND_KEY_TAKE_DONE = LangKey.of("Command.Key.Take.Done", + GRAY + "Taken " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + " keys of type " + YELLOW + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + " from player " + YELLOW + Placeholders.PLAYER_NAME + GRAY + "."); + public static final LangKey COMMAND_KEY_TAKE_NOTIFY = LangKey.of("Command.Key.Take.Notify", + GRAY + "You have lost #fd5e5ex" + Placeholders.GENERIC_AMOUNT + " " + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + "."); + + + public static final LangKey COMMAND_KEY_SET_USAGE = LangKey.of("Command.Key.Set.Usage", + " [-s]"); + public static final LangKey COMMAND_KEY_SET_DESC = LangKey.of("Command.Key.Set.Desc", + "Set the number of keys for a player."); + public static final LangKey COMMAND_KEY_SET_DONE = LangKey.of("Command.Key.Set.Done", + GRAY + "The number of keys of type " + YELLOW + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + " for player " + YELLOW + Placeholders.PLAYER_NAME + GRAY + " has been changed to " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + "."); + public static final LangKey COMMAND_KEY_SET_NOTIFY = LangKey.of("Command.Key.Set.Notify", + GRAY + "The number of your keys of type " + YELLOW + t.me.p1azmer.plugin.dungeons.key.Placeholders.KEY_NAME + GRAY + " has been changed to " + YELLOW + "x" + Placeholders.GENERIC_AMOUNT + GRAY + "."); + + + public static final LangKey DUNGEON_ERROR_INVALID = LangKey.of("Dungeon.Error.Invalid", + RED + "Invalid dungeon!"); + public static final LangKey DUNGEON_ERROR_EXISTS = LangKey.of("Dungeon.Error.Exists", + RED + "A dungeon with that ID already exists!"); + + + public static final LangKey DUNGEON_KEY_ERROR_INVALID = LangKey.of("Dungeon.Key.Error.Invalid", + RED + "Invalid key!"); + public static final LangKey DUNGEON_KEY_ERROR_EXISTS = LangKey.of("Dungeon.Key.Error.Exists", + RED + "A key with that ID already exists!"); public static final LangKey DUNGEON_OPEN_ERROR_NO_KEY = LangKey.of("Dungeon.Open.Error.NoKey", "" + - "\n#fd5e5e&lOops!" + - "\n#d4d9d8You don't have the key for this Dungeon!"); + Colors2.RED + BOLD + "\nOops!" + + Colors2.GRAY + "\nYou don't have the key for this Dungeon!"); public static final LangKey DUNGEON_OPEN_ERROR_NO_HOLD_KEY = LangKey.of("Dungeon.Open.Error.NoHoldKey", "" + - "\n#fd5e5e&lOops!" + - "\n#d4d9d8You must be holding the key to open the Dungeon!"); - + Colors2.RED + BOLD + "\nOops!" + + Colors2.GRAY + "\nYou must be holding the key to open the Dungeon!"); // editor - public static final LangKey EDITOR_GENERIC_ENTER_CURRENCY = LangKey.of("Editor.Generic.Enter.Currency", GRAY + "Enter " + GREEN + "[Currency]"); - public static final LangKey EDITOR_GENERIC_ENTER_NAME = LangKey.of("Editor.Generic.Enter.Name", GRAY + "Enter " + GREEN + "[Display Name]"); - public static final LangKey EDITOR_GENERIC_ENTER_DESCRIPTION = LangKey.of("Editor.Generic.Enter.Description", GRAY + "Enter " + GREEN + "[Description]"); - public static final LangKey EDITOR_GENERIC_ENTER_COMMAND = LangKey.of("Editor.Generic.Enter.Command", GRAY + "Enter " + GREEN + "[Command]"); - public static final LangKey EDITOR_GENERIC_ENTER_NUMBER = LangKey.of("Editor.Generic.Enter.Number", GRAY + "Enter " + GREEN + "[Number]"); - public static final LangKey EDITOR_GENERIC_ENTER_PERCENT = LangKey.of("Editor.Generic.Enter.Percent", GRAY + "Enter " + GREEN + "[Percent Amount]"); - public static final LangKey EDITOR_GENERIC_ENTER_SECONDS = LangKey.of("Editor.Generic.Enter.Seconds", GRAY + "Enter " + GREEN + "[Seconds Amount]"); - public static final LangKey EDITOR_ENTER_DISPLAY_NAME = LangKey.of("Editor.Enter.DisplayName", GRAY + "Enter " + GREEN + "[Displayed Name]"); - public static final LangKey EDITOR_ENTER_SCHEMATIC = LangKey.of("Editor.Enter.Schematic", GRAY + "Enter " + GREEN + "[Dungeon Schematic]"); - public static final LangKey EDITOR_DUNGEON_ENTER_HOLOGRAM_TEXT = LangKey.of("Editor.Dungeon.Enter.Hologram.Text", GRAY + "Enter " + GREEN + "[Text]"); - public static final LangKey EDITOR_DUNGEON_ENTER_HOLOGRAM_OFFSET = LangKey.of("Editor.Crate.Enter.Hologram.Offset", GRAY + "Enter " + GREEN + "[Offset Value]"); - public static final LangKey EDITOR_DUNGEON_ENTER_MINIMAL_ONLINE = LangKey.of("Editor.Crate.Enter.Minimal_Online", GRAY + "Enter " + GREEN + "[Online Value]"); - - public static final LangKey EDITOR_DUNGEON_ENTER_ID = LangKey.of("Editor.Dungeon.Enter.Id", GRAY + "Enter " + GREEN + "[Dungeon ID]"); - public static final LangKey EDITOR_DUNGEON_ENTER_KEY_ID = LangKey.of("Editor.Dungeon.Enter.KeyId", GRAY + "Enter " + GREEN + "[Key Identifier]"); - - public static final LangKey EDITOR_REWARD_ENTER_ID = LangKey.of("Editor.Reward.Enter.Id", GRAY + "Enter " + GREEN + "[Reward Identifier]"); - public static final LangKey EDITOR_REWARD_ENTER_CHANCE = LangKey.of("Editor.Reward.Enter.Chance", GRAY + "Enter " + GREEN + "[Chance]"); - public static final LangKey EDITOR_REWARD_ENTER_UNI_LIMIT = LangKey.of("Editor.Reward.Enter.UniLimit", GRAY + "Enter " + GREEN + "[Min] [Max]"); - public static final LangKey EDITOR_REWARD_ENTER_UNI_AMOUNT = LangKey.of("Editor.Reward.Enter.UniAmount", GRAY + "Enter " + GREEN + "[Min] [Max]"); - public static final LangKey EDITOR_REWARD_ERROR_CREATE_EXIST = LangKey.of("Editor.Reward.Error.Create.Exist", RED + "A reward with this identifier already exists!"); - public static final LangKey EDITOR_DUNGEON_ERROR_MATERIAL_NOT_FOUND = LangKey.of("Editor.Dungeon.Error.Blocks.Material.Not_Found", RED + "Material not found, try again!"); - public static final LangKey EDITOR_REWARD_ENTER_COMMAND = LangKey.of("Editor.Reward.Enter.Command", GRAY + "Enter " + GREEN + "[Command]"); - - public static final LangKey EDITOR_DUNGEON_ENTER_FLAG = LangKey.of("Editor.Dungeon.Enter.Region.Flag", GRAY + "Enter " + GREEN + "[Flag allow/deny]"); - - public static final LangKey EDITOR_EFFECT_ENTER_TYPE = LangKey.of("Editor.Effect.Enter.Type", GRAY + "Enter " + GREEN + "[PotionEffect Type]"); - public static final LangKey EDITOR_EFFECT_ENTER_DURATION = LangKey.of("Editor.Effect.Enter.Duration", GRAY + "Enter " + GREEN + "[Duration]"); - public static final LangKey EDITOR_EFFECT_ENTER_AMPLIFIER = LangKey.of("Editor.Effect.Enter.Amplifier", GRAY + "Enter " + GREEN + "[Amplifier]"); - - public static final LangKey EDITOR_DUNGEON_WRITE_BLOCKS_AMOUNT = LangKey.of("Editor.Dungeon.Enter.Blocks.Amount", GRAY + "Enter " + GREEN + "[Blocks Amount]"); - public static final LangKey EDITOR_DUNGEON_WRITE_CHEST_BLOCK_MATERIAL = LangKey.of("Editor.Dungeon.Enter.Blocks.Material", GRAY + "Enter " + GREEN + "[Chest-Block Material]"); - public static final LangKey EDITOR_DUNGEON_WRITE_POSITIVE_VALUE = LangKey.of("Editor.Dungeon.Write.Positive_Value", GREEN + "Write positive value!"); - public static final LangKey EDITOR_DUNGEON_WRITE_VALUE = LangKey.of("Editor.Dungeon.Write.Value", GREEN + GRAY + "Enter " + GREEN + "value" + GRAY + "..."); - - public static final LangKey ERROR_GENERATOR_LOCATION_NOT_FOUND = LangKey.of("Messages.Error.Generator.Location.Not_Found", RED + "Location cannot generate for '%dungeon_id%'!"); - public static final LangKey ERROR_RANDOM_SPAWN = LangKey.of("Messages.Error.Dungeon.Spawn.Random", RED + "Dungeon cannot spawn, see error in console!"); - public static final LangKey ERROR_DUNGEON_LOCATION_IS_EMPTY = LangKey.of("Messages.Error.Dungeon.Location.Empty", RED + "The dungeon location is empty or has not been created"); - public static final LangKey EDITOR_DUNGEON_ERROR_VALUE_IS_NOT_CORRECT = LangKey.of("Messages.Error.Dungeon.Editor.Value.Not_Correct", RED + "Value is not correct!"); - public static final LangKey DUNGEON_BACKTRACK_PLAYER_WHEN_CLOSE = LangKey.of("Messages.Dungeon.Backtrack_When_Close", RED + "You cannot enter the dungeon while it is closed!"); - public static final LangKey DUNGEON_BACKTRACK_PLAYER_WHEN_NOT_PARTY = LangKey.of("Messages.Dungeon.Backtrack_Not_Party", RED + "To enter this dungeon, you need to be " + GREEN + Placeholders.PARTY_SIZE + RED + " players or more" + BOLD + "!"); - public static final LangKey EDITOR_DUNGEON_ERROR_SCHEMATIC_NOT_VALID = LangKey.of("Messages.Error.Dungeon.Editor.Schematic.Not_Valid", RED + "The schematic you specified does not contain a chest block!"); - public static final LangKey EDITOR_DUNGEON_ERROR_SCHEMATIC_NOT_CONTAINS_CHEST = LangKey.of("Messages.Error.Dungeon.Editor.Schematic.Not_Contains_Chest", RED + "The schematic you specified has empty Chest Material (" + Placeholders.DUNGEON_SETTINGS_CHEST_MATERIAL + ")"); - public static final LangKey Editor_Dungeon_Enter_World = new LangKey("Editor.Dungeon.Enter.World", GRAY + "Enter " + GREEN + "world name" + GRAY + "..."); - public static final LangKey Editor_Dungeon_World_Not_Found = new LangKey("Editor.Dungeon.Error.World.Not_Found", RED+"World not found!"); - - public static final LangKey Editor_Mob_Enter_Create = new LangKey("Editor.Mob.Enter.Create", GRAY + "Enter " + GREEN + "unique " + GRAY + "mob " + GREEN + "identifier" + GRAY + "..."); - public static final LangKey Editor_Mob_Enter_Type = new LangKey("Editor.Mob.Enter.Type", GRAY + "Enter " + GREEN + "entity type" + GRAY + "..."); - public static final LangKey Editor_Mob_Enter_Attribute = new LangKey("Editor.Mob.Enter.Attribute", GRAY + "Enter " + GREEN + "attribute " + GRAY + "and " + GREEN + "value" + GRAY + "..."); - public static final LangKey Editor_Mob_Enter_Id = new LangKey("Editor.Mob.Enter.Id", GRAY + "Enter " + GREEN + "mob id " + GRAY + "and" + GREEN + "amount of" + GRAY + "..."); - public static final LangKey Editor_Mob_Enter_Potion = new LangKey("Editor.Mob.Enter.Potion", GRAY + "Enter " + GREEN + "potion " + GRAY + "and " + GREEN + "value" + GRAY + "..."); - public static final LangKey Editor_Mov_Enter_Style = new LangKey("Editor.Mob.Enter.Style", GRAY + "Enter " + GREEN + "value" + GRAY + "..."); - public static final LangKey Editor_Mob_Error_Exist = new LangKey("Editor.Mob.Error.Exist", RED+"Mob already exists!"); - - public static final LangKey Editor_Announce_Enter_Create = new LangKey("Editor.Announce.Enter.Create", GRAY + "Enter " + GREEN + "unique " + GRAY + "announce " + GREEN + "identifier" + GRAY + "..."); - public static final LangKey Editor_Announce_Error_Exist = new LangKey("Editor.Announce.Error.Exist", RED+"Announce already exists!"); - - public static final LangKey Editor_Enter_Text = LangKey.of("Editor.Enter.Text", GRAY + "Enter " + GREEN + "text " + GRAY + "or " + GREEN + "leave empty" + GRAY + "..."); - public static final LangKey Editor_Enter_Announce_And_Time = LangKey.of("Editor.Announce_And_Time.Enter", GRAY + "Enter " + GREEN + "announce id " + GRAY + "and " + GREEN + "time [1,2,..]" + GRAY + "..."); - public static final LangKey Editor_Announce_And_Time_Error = new LangKey("Editor.Announce_And_Time.Error", RED+"Announce not found!"); -// public static final LangKey Editor_Enter_Array_Integers = LangKey.of("Editor.Enter.Array_Integers", GRAY + "Enter " + GREEN + "values" + GRAY + " like " + GREEN + "[1,2,..]" + GRAY + "..."); -// public static final LangKey Editor_Error_Handler_Not_Installed = LangKey.of("Editor.Error.Handler.Not_Installed", RED+"The '"+Placeholders.GENERIC_HANDLER+"' handler is not installed and cannot be configured!"); + public static final LangKey EDITOR_GENERIC_ENTER_CURRENCY = LangKey.of("Editor.Generic.Enter.Currency", + GRAY + "Enter " + GREEN + "[Currency]"); + public static final LangKey EDITOR_GENERIC_ENTER_NAME = LangKey.of("Editor.Generic.Enter.Name", + GRAY + "Enter " + GREEN + "[Display Name]"); + public static final LangKey EDITOR_GENERIC_ENTER_DESCRIPTION = LangKey.of("Editor.Generic.Enter.Description", + GRAY + "Enter " + GREEN + "[Description]"); + public static final LangKey EDITOR_GENERIC_ENTER_COMMAND = LangKey.of("Editor.Generic.Enter.Command", + GRAY + "Enter " + GREEN + "[Command]"); + public static final LangKey EDITOR_GENERIC_ENTER_NUMBER = LangKey.of("Editor.Generic.Enter.Number", + GRAY + "Enter " + GREEN + "[Number]"); + public static final LangKey EDITOR_GENERIC_ENTER_PERCENT = LangKey.of("Editor.Generic.Enter.Percent", + GRAY + "Enter " + GREEN + "[Percent Amount]"); + public static final LangKey EDITOR_GENERIC_ENTER_SECONDS = LangKey.of("Editor.Generic.Enter.Seconds", + GRAY + "Enter " + GREEN + "[Seconds Amount]"); + public static final LangKey EDITOR_ENTER_DISPLAY_NAME = LangKey.of("Editor.Enter.DisplayName", + GRAY + "Enter " + GREEN + "[Displayed Name]"); + public static final LangKey EDITOR_ENTER_SCHEMATIC = LangKey.of("Editor.Enter.Schematic", + GRAY + "Enter " + GREEN + "[Dungeon Schematic]"); + public static final LangKey EDITOR_DUNGEON_ENTER_HOLOGRAM_TEXT = LangKey.of("Editor.Dungeon.Enter.Hologram.Text", + GRAY + "Enter " + GREEN + "[Text]"); + public static final LangKey EDITOR_DUNGEON_ENTER_HOLOGRAM_OFFSET = LangKey.of("Editor.Crate.Enter.Hologram.Offset", + GRAY + "Enter " + GREEN + "[Offset Value]"); + public static final LangKey EDITOR_DUNGEON_ENTER_MINIMAL_ONLINE = LangKey.of("Editor.Crate.Enter.Minimal_Online", + GRAY + "Enter " + GREEN + "[Online Value]"); + + public static final LangKey EDITOR_DUNGEON_ENTER_ID = LangKey.of("Editor.Dungeon.Enter.Id", + GRAY + "Enter " + GREEN + "[Dungeon ID]"); + public static final LangKey EDITOR_DUNGEON_ENTER_KEY_ID = LangKey.of("Editor.Dungeon.Enter.KeyId", + GRAY + "Enter " + GREEN + "[Key Identifier]"); + + public static final LangKey EDITOR_REWARD_ENTER_ID = LangKey.of("Editor.Reward.Enter.Id", + GRAY + "Enter " + GREEN + "[Reward Identifier]"); + public static final LangKey EDITOR_REWARD_ENTER_CHANCE = LangKey.of("Editor.Reward.Enter.Chance", + GRAY + "Enter " + GREEN + "[Chance]"); + public static final LangKey EDITOR_REWARD_ENTER_UNI_LIMIT = LangKey.of("Editor.Reward.Enter.UniLimit", + GRAY + "Enter " + GREEN + "[Min] [Max]"); + public static final LangKey EDITOR_REWARD_ENTER_UNI_AMOUNT = LangKey.of("Editor.Reward.Enter.UniAmount", + GRAY + "Enter " + GREEN + "[Min] [Max]"); + public static final LangKey EDITOR_REWARD_ERROR_CREATE_EXIST = LangKey.of("Editor.Reward.Error.Create.Exist", + RED + "A reward with this identifier already exists!"); + public static final LangKey EDITOR_DUNGEON_ERROR_MATERIAL_NOT_FOUND = LangKey.of("Editor.Dungeon.Error.Blocks.Material.Not_Found", + RED + "Material not found, try again!"); + public static final LangKey EDITOR_REWARD_ENTER_COMMAND = LangKey.of("Editor.Reward.Enter.Command", + GRAY + "Enter " + GREEN + "[Command]"); + + public static final LangKey EDITOR_DUNGEON_ENTER_FLAG = LangKey.of("Editor.Dungeon.Enter.Region.Flag", + GRAY + "Enter " + GREEN + "[Flag allow/deny]"); + + public static final LangKey EDITOR_EFFECT_ENTER_TYPE = LangKey.of("Editor.Effect.Enter.Type", + GRAY + "Enter " + GREEN + "[PotionEffect Type]"); + public static final LangKey EDITOR_EFFECT_ENTER_DURATION = LangKey.of("Editor.Effect.Enter.Duration", + GRAY + "Enter " + GREEN + "[Duration]"); + public static final LangKey EDITOR_EFFECT_ENTER_AMPLIFIER = LangKey.of("Editor.Effect.Enter.Amplifier", + GRAY + "Enter " + GREEN + "[Amplifier]"); + + public static final LangKey EDITOR_DUNGEON_WRITE_BLOCKS_AMOUNT = LangKey.of("Editor.Dungeon.Enter.Blocks.Amount", + GRAY + "Enter " + GREEN + "[Blocks Amount]"); + public static final LangKey EDITOR_DUNGEON_WRITE_CHEST_BLOCK_MATERIAL = LangKey.of("Editor.Dungeon.Enter.Blocks.Material", + GRAY + "Enter " + GREEN + "[Chest-Block Material]"); + public static final LangKey EDITOR_DUNGEON_WRITE_POSITIVE_VALUE = LangKey.of("Editor.Dungeon.Write.Positive_Value", + GREEN + "Write positive value!"); + public static final LangKey EDITOR_DUNGEON_WRITE_VALUE = LangKey.of("Editor.Dungeon.Write.Value", + GREEN + GRAY + "Enter " + GREEN + "value" + GRAY + "..."); + + public static final LangKey ERROR_GENERATOR_LOCATION_NOT_FOUND = LangKey.of("Messages.Error.Generator.Location.Not_Found", + RED + "Location cannot generate for '%dungeon_id%'!"); + public static final LangKey ERROR_RANDOM_SPAWN = LangKey.of("Messages.Error.Dungeon.Spawn.Random", + RED + "Dungeon cannot spawn, see error in console!"); + public static final LangKey ERROR_DUNGEON_LOCATION_IS_EMPTY = LangKey.of("Messages.Error.Dungeon.Location.Empty", + RED + "The dungeon location is empty or has not been created"); + public static final LangKey EDITOR_DUNGEON_ERROR_VALUE_IS_NOT_CORRECT = LangKey.of("Messages.Error.Dungeon.Editor.Value.Not_Correct", + RED + "Value is not correct!"); + public static final LangKey DUNGEON_BACKTRACK_PLAYER_WHEN_CLOSE = LangKey.of("Messages.Dungeon.Backtrack_When_Close", + RED + "You cannot enter the dungeon while it is closed!"); + public static final LangKey DUNGEON_BACKTRACK_PLAYER_WHEN_NOT_PARTY = LangKey.of("Messages.Dungeon.Backtrack_Not_Party", + RED + "To enter this dungeon, you need to be " + GREEN + Placeholders.PARTY_SIZE + RED + " players or more" + BOLD + "!"); + public static final LangKey EDITOR_DUNGEON_ERROR_SCHEMATIC_NOT_VALID = LangKey.of("Messages.Error.Dungeon.Editor.Schematic.Not_Valid", + RED + "The schematic you specified does not contain a chest block!"); + public static final LangKey EDITOR_DUNGEON_ERROR_SCHEMATIC_NOT_CONTAINS_CHEST = LangKey.of("Messages.Error.Dungeon.Editor.Schematic.Not_Contains_Chest", + RED + "The schematic you specified has empty Chest Material (" + t.me.p1azmer.plugin.dungeons.dungeon.settings.Placeholders.DUNGEON_SETTINGS_CHEST_MATERIAL + ")"); + public static final LangKey Editor_Dungeon_Enter_World = new LangKey("Editor.Dungeon.Enter.World", + GRAY + "Enter " + GREEN + "world name" + GRAY + "..."); + public static final LangKey Editor_Dungeon_World_Not_Found = new LangKey("Editor.Dungeon.Error.World.Not_Found", + RED + "World not found!"); + + public static final LangKey Editor_Mob_Enter_Create = new LangKey("Editor.Mob.Enter.Create", + GRAY + "Enter " + GREEN + "unique " + GRAY + "mob " + GREEN + "identifier" + GRAY + "..."); + public static final LangKey Editor_Mob_Enter_Type = new LangKey("Editor.Mob.Enter.Type", + GRAY + "Enter " + GREEN + "entity type" + GRAY + "..."); + public static final LangKey Editor_Mob_Enter_Attribute = new LangKey("Editor.Mob.Enter.Attribute", + GRAY + "Enter " + GREEN + "attribute " + GRAY + "and " + GREEN + "value" + GRAY + "..."); + public static final LangKey Editor_Mob_Enter_Id = new LangKey("Editor.Mob.Enter.Id", + GRAY + "Enter " + GREEN + "mob id " + GRAY + "and" + GREEN + "amount of" + GRAY + "..."); + public static final LangKey Editor_Mob_Enter_Potion = new LangKey("Editor.Mob.Enter.Potion", + GRAY + "Enter " + GREEN + "potion " + GRAY + "and " + GREEN + "value" + GRAY + "..."); + public static final LangKey Editor_Mov_Enter_Style = new LangKey("Editor.Mob.Enter.Style", + GRAY + "Enter " + GREEN + "value" + GRAY + "..."); + public static final LangKey Editor_Mob_Error_Exist = new LangKey("Editor.Mob.Error.Exist", + RED + "Mob already exists!"); + + public static final LangKey Editor_Announce_Enter_Create = new LangKey("Editor.Announce.Enter.Create", + GRAY + "Enter " + GREEN + "unique " + GRAY + "announce " + GREEN + "identifier" + GRAY + "..."); + public static final LangKey Editor_Announce_Error_Exist = new LangKey("Editor.Announce.Error.Exist", + RED + "Announce already exists!"); + + public static final LangKey Editor_Enter_Text = LangKey.of("Editor.Enter.Text", + GRAY + "Enter " + GREEN + "text " + GRAY + "or " + GREEN + "leave empty" + GRAY + "..."); + public static final LangKey Editor_Enter_Announce_And_Time = LangKey.of("Editor.Announce_And_Time.Enter", + GRAY + "Enter " + GREEN + "announce id " + GRAY + "and " + GREEN + "time [1,2,..]" + GRAY + "..."); + public static final LangKey Editor_Announce_And_Time_Error = new LangKey("Editor.Announce_And_Time.Error", + RED + "Announce not found!"); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobListener.java b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobListener.java index 6f36132..c751beb 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobListener.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobListener.java @@ -46,7 +46,7 @@ public void onMobDeath(EntityDeathEvent e) { } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onArenaMobCombust(EntityCombustEvent e) { + public void onMobCombust(EntityCombustEvent e) { Entity entity = e.getEntity(); if (this.manager.isCustomMob(entity)) { if (e instanceof EntityCombustByEntityEvent ec) { @@ -60,12 +60,12 @@ public void onArenaMobCombust(EntityCombustEvent e) { } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onArenaPlayerInteractEntity(PlayerInteractEntityEvent e) { + public void onPlayerInteractEntity(PlayerInteractEntityEvent e) { e.setCancelled(!this.canInteract(e)); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onArenaPlayerInteractEntity2(PlayerInteractAtEntityEvent e) { + public void onPlayerInteractEntity2(PlayerInteractAtEntityEvent e) { e.setCancelled(!this.canInteract(e)); } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobManager.java b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobManager.java index 7d2c908..1d0038f 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobManager.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/MobManager.java @@ -16,10 +16,10 @@ import t.me.p1azmer.engine.utils.random.Rnd; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.Keys; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.api.mob.MobFaction; import t.me.p1azmer.plugin.dungeons.api.mob.MobList; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import t.me.p1azmer.plugin.dungeons.dungeon.modules.ModuleManager; import t.me.p1azmer.plugin.dungeons.dungeon.modules.impl.ChestModule; import t.me.p1azmer.plugin.dungeons.mob.config.MobConfig; import t.me.p1azmer.plugin.dungeons.mob.config.MobsConfig; @@ -80,6 +80,11 @@ public void killMobs(@NotNull MobFaction faction) { this.getMobs().removeAll(faction); } + public void killMob(@NotNull LivingEntity entity){ + entity.remove(); + this.getMobs().removeInvalid(); + } + public boolean createMobConfig(@NotNull String id) { id = StringUtil.lowerCaseUnderscore(id); if (this.getMobConfigById(id) != null) return false; @@ -124,8 +129,10 @@ public LivingEntity spawnMob(@NotNull Dungeon dungeon, @NotNull MobFaction facti if (customMob == null) { return null; } - Location location = dungeon.getLocation(); - ChestModule module = dungeon.getModuleManager().getModule(ChestModule.class).orElse(null); + Location location = dungeon.getLocation().orElse(null); + ModuleManager moduleManager = dungeon.getModuleManager(); + + ChestModule module = moduleManager.getModule(ChestModule.class).orElse(null); if (module != null) { if (module.getBlocks().isEmpty()) return null; location = Rnd.get(module.getBlocks()).getLocation(); @@ -153,6 +160,7 @@ public LivingEntity spawnMob(@NotNull Dungeon dungeon, @NotNull MobFaction facti rider.applyAttributes(riderEntity); rider.applyPotionEffects(riderEntity); this.setMobConfig(riderEntity, rider); + this.setMobDungeon(riderEntity, dungeon); mobList.getEnemies().add(riderEntity); } } @@ -162,6 +170,7 @@ public LivingEntity spawnMob(@NotNull Dungeon dungeon, @NotNull MobFaction facti customMob.applyAttributes(entity); customMob.applyPotionEffects(entity); this.setMobConfig(entity, customMob); + this.setMobDungeon(entity, dungeon); mobList.getEnemies().add(entity); return entity; } @@ -183,10 +192,19 @@ private void setMobConfig(@NotNull LivingEntity entity, @NotNull MobConfig custo PDCUtil.set(entity, Keys.ENTITY_MOB_ID, customMob.getId()); } + private void setMobDungeon(@NotNull LivingEntity entity, @NotNull Dungeon dungeon){ + PDCUtil.set(entity, Keys.DUNGEON_KEY_ID, dungeon.getId()); + } + public static void setLevel(@NotNull LivingEntity entity, int level) { PDCUtil.set(entity, Keys.ENTITY_MOB_LEVEL, level); } + @Nullable + public static String getMobDungeonId(@NotNull LivingEntity entity){ + return PDCUtil.getString(entity, Keys.ENTITY_MOB_DUNGEON_ID).orElse(null); + } + @NotNull public static String getMobIdProvider(@NotNull LivingEntity entity) { return PDCUtil.getString(entity, Keys.ENTITY_MOB_ID).orElse(""); diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/Placeholders.java b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/Placeholders.java new file mode 100644 index 0000000..df0ad58 --- /dev/null +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/Placeholders.java @@ -0,0 +1,18 @@ +package t.me.p1azmer.plugin.dungeons.mob; + +public class Placeholders extends t.me.p1azmer.plugin.dungeons.Placeholders { + public static final String MOB_ID = "%mob_id%"; + public static final String MOB_NAME = "%mob_name%"; + public static final String MOB_NAME_VISIBLE = "%mob_name_visible%"; + public static final String MOB_ENTITY_TYPE = "%mob_entity_type%"; + public static final String MOB_ATTRIBUTES_BASE = "%mob_attributes_base%"; + public static final String MOB_SPAWN_CHANCE = "%mob_spawn_chance%"; + public static final String MOB_ENABLED_SPAWN = "%mob_spawn_enabled%"; + public static final String MOB_SILENT = "%mob_silent%"; + public static final String MOB_RIDER_ID = "%mob_rider_id%"; + + public static final String MOB_POTION_EFFECT_VALUE = "%mob_potion_effect_value%"; + public static final String MOB_POTION_EFFECT_DURATION = "%mob_potion_effect_duration%"; + public static final String MOB_STYLE_TYPE = "%mob_style_type%"; + public static final String MOB_STYLE_VALUE = "%mob_style_value%"; +} diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobConfig.java b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobConfig.java index 8765338..dc81d25 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobConfig.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobConfig.java @@ -18,7 +18,7 @@ import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.StringUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.mob.Placeholders; import t.me.p1azmer.plugin.dungeons.mob.editor.MobMainEditor; import t.me.p1azmer.plugin.dungeons.mob.style.MobStyleType; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobsConfig.java b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobsConfig.java index 6d03001..064f413 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobsConfig.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/config/MobsConfig.java @@ -5,48 +5,51 @@ import t.me.p1azmer.engine.api.config.JOption; import t.me.p1azmer.engine.utils.Colorizer; import t.me.p1azmer.engine.utils.ItemReplacer; -import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.engine.utils.Pair; -import t.me.p1azmer.plugin.dungeons.Placeholders; +import t.me.p1azmer.plugin.dungeons.mob.Placeholders; import t.me.p1azmer.plugin.dungeons.mob.kill.MobKillReward; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import static t.me.p1azmer.engine.utils.Colors.*; +import static t.me.p1azmer.engine.utils.Colors.LIGHT_YELLOW; public class MobsConfig { - public static final JOption NAME_FORMAT = JOption.create("Mobs.DisplayName_Format", - LIGHT_YELLOW + Placeholders.MOB_NAME, - "Sets entity display name format for internal AMA mobs.", - "Placeholders: " + Placeholders.MOB_NAME - ).mapReader(Colorizer::apply); - - public static final JOption KILL_REWARD_ENABLED = JOption.create("Mobs.Kill_Rewards.Enabled", + public static final JOption NAME_FORMAT = JOption.create( + "Mobs.DisplayName_Format", + LIGHT_YELLOW + Placeholders.MOB_NAME, + "Sets entity display name format for internal AMA mobs.", + "Placeholders: " + Placeholders.MOB_NAME + ) + .mapReader(Colorizer::apply); + + public static final JOption KILL_REWARD_ENABLED = JOption.create( + "Mobs.Kill_Rewards.Enabled", true, "Enables/Disables the Mob Kill Rewards feature." ); - public static final JOption> KILL_REWARD_VALUES = JOption.forMap("Mobs.Kill_Rewards.Table", - (cfg, path, key) -> MobKillReward.read(cfg, path + "." + key, key), - () -> { - Map map = new HashMap<>(); - Map> items = new HashMap<>(); - ItemStack defaultItem = new ItemStack(Material.GOLD_NUGGET); - ItemReplacer.create(defaultItem) - .setDisplayName("&6Default item") - .replace(Colorizer::apply) - .writeMeta(); - items.put("default", Pair.of(defaultItem, 50D)); - - map.put(Placeholders.DEFAULT, new MobKillReward(Placeholders.DEFAULT, new ArrayList<>(), items)); - map.put("default_skeleton", new MobKillReward("default_skeleton", new ArrayList<>(), items)); - return map; - }, - "Here you can create custom rewards for mob kills on the dungeon.", - "For commands, use '" + Placeholders.PLAYER_NAME + "' placehodler for a player name." - ).setWriter((cfg, path, map) -> map.forEach((id, reward) -> reward.write(cfg, path + "." + id))); + public static final JOption> KILL_REWARD_VALUES = JOption.forMap( + "Mobs.Kill_Rewards.Table", + (cfg, path, key) -> MobKillReward.read(cfg, path + "." + key, key), + () -> { + Map map = new HashMap<>(); + Map> items = new HashMap<>(); + ItemStack defaultItem = new ItemStack(Material.GOLD_NUGGET); + ItemReplacer.create(defaultItem) + .setDisplayName("&6Default item") + .replace(Colorizer::apply) + .writeMeta(); + items.put("default", Pair.of(defaultItem, 50D)); + + map.put(Placeholders.DEFAULT, new MobKillReward(Placeholders.DEFAULT, new ArrayList<>(), items)); + map.put("default_skeleton", new MobKillReward("default_skeleton", new ArrayList<>(), items)); + return map; + }, + "Here you can create custom rewards for mob kills on the dungeon.", + "For commands, use '" + Placeholders.PLAYER_NAME + "' placehodler for a player name." + ) + .setWriter((cfg, path, map) -> map.forEach((id, reward) -> reward.write(cfg, path + "." + id))); } \ No newline at end of file diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/editor/MobStylesEditor.java b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/editor/MobStylesEditor.java index 49aa8be..0f7ff7c 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/mob/editor/MobStylesEditor.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/mob/editor/MobStylesEditor.java @@ -13,10 +13,10 @@ import t.me.p1azmer.engine.editor.EditorManager; import t.me.p1azmer.engine.utils.ItemUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; -import t.me.p1azmer.plugin.dungeons.Placeholders; import t.me.p1azmer.plugin.dungeons.config.Config; import t.me.p1azmer.plugin.dungeons.editor.EditorLocales; import t.me.p1azmer.plugin.dungeons.lang.Lang; +import t.me.p1azmer.plugin.dungeons.mob.Placeholders; import t.me.p1azmer.plugin.dungeons.mob.config.MobConfig; import t.me.p1azmer.plugin.dungeons.mob.style.MobStyleType; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/LocationPlaceholder.java b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/LocationPlaceholder.java index 4e16545..7c960cb 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/LocationPlaceholder.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/LocationPlaceholder.java @@ -1,5 +1,6 @@ package t.me.p1azmer.plugin.dungeons.placeholders.dungeon; +import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.placeholder.AbstractPlaceholder; @@ -8,6 +9,7 @@ import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import java.util.Optional; import java.util.regex.Matcher; public class LocationPlaceholder extends AbstractPlaceholder { @@ -19,11 +21,14 @@ public LocationPlaceholder(@NotNull PlaceholderExpansion expansio @Override public String parse(@NotNull Matcher matcher, @NotNull OfflinePlayer player) { String dungeonId = matcher.group(1); + Dungeon dungeon = plugin.getDungeonManager().getDungeonById(dungeonId); if (dungeon == null) return ""; - if (dungeon.getLocation() == null) return ""; - return Placeholders.forLocation(dungeon.getLocation()).apply("%location_world% ⚊ %location_x%, %location_y%, %location_z%"); + Location location = dungeon.getLocation().orElse(null); + if (location == null) return ""; + + return Placeholders.forLocation(location).apply("%location_world% ⚊ %location_x%, %location_y%, %location_z%"); } @Override diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearLocationPlaceholder.java b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearLocationPlaceholder.java index 0060c04..4a3eef0 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearLocationPlaceholder.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearLocationPlaceholder.java @@ -1,5 +1,6 @@ package t.me.p1azmer.plugin.dungeons.placeholders.dungeon; +import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.jetbrains.annotations.NotNull; import t.me.p1azmer.engine.api.placeholder.AbstractPlaceholder; @@ -8,6 +9,7 @@ import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; +import java.util.Optional; import java.util.regex.Matcher; public class NearLocationPlaceholder extends AbstractPlaceholder { @@ -20,9 +22,10 @@ public NearLocationPlaceholder(@NotNull PlaceholderExpansion expa public String parse(@NotNull Matcher matcher, @NotNull OfflinePlayer player) { Dungeon dungeon = plugin.getDungeonManager().getNearestDungeon(); if (dungeon == null) return ""; - if (dungeon.getLocation() == null) return ""; + Location location = dungeon.getLocation().orElse(null); + if (location == null) return ""; - return Placeholders.forLocation(dungeon.getLocation()).apply("%location_world% ⚊ %location_x%, %location_y%, %location_z%"); + return Placeholders.forLocation(location).apply("%location_world% ⚊ %location_x%, %location_y%, %location_z%"); } @Override diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearOpenTimePlaceholder.java b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearOpenTimePlaceholder.java index 44aef52..4428c84 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearOpenTimePlaceholder.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/NearOpenTimePlaceholder.java @@ -7,7 +7,7 @@ import t.me.p1azmer.engine.utils.NumberUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestBlock; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import java.util.regex.Matcher; @@ -23,7 +23,7 @@ public NearOpenTimePlaceholder(@NotNull PlaceholderExpansion expa public String parse(@NotNull Matcher matcher, @NotNull OfflinePlayer player) { Dungeon dungeon = plugin.getDungeonManager().getNearestDungeon(); if (dungeon == null) return ""; - DungeonChestBlock chest = null;//dungeon.getNearestChest(); + ChestBlock chest = null;//dungeon.getNearestChest(); if (chest != null) return NumberUtil.format( (int) dungeon.getStageSettings().getTime(DungeonStage.OPENED) - chest.getCurrentTick()); return ""; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/OpenTimePlaceholder.java b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/OpenTimePlaceholder.java index 4f45d76..2e21c22 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/OpenTimePlaceholder.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/placeholders/dungeon/OpenTimePlaceholder.java @@ -7,7 +7,7 @@ import t.me.p1azmer.engine.utils.NumberUtil; import t.me.p1azmer.plugin.dungeons.DungeonPlugin; import t.me.p1azmer.plugin.dungeons.dungeon.impl.Dungeon; -import t.me.p1azmer.plugin.dungeons.dungeon.chest.DungeonChestBlock; +import t.me.p1azmer.plugin.dungeons.dungeon.chest.ChestBlock; import t.me.p1azmer.plugin.dungeons.dungeon.stage.DungeonStage; import java.util.regex.Matcher; @@ -23,7 +23,7 @@ public String parse(@NotNull Matcher matcher, @NotNull OfflinePlayer player) { String dungeonId = matcher.group(1); Dungeon dungeon = plugin.getDungeonManager().getDungeonById(dungeonId); if (dungeon == null) return ""; - DungeonChestBlock chest = null;//dungeon.getNearestChest(); + ChestBlock chest = null;//dungeon.getNearestChest(); if (chest != null) return NumberUtil.format( (int) dungeon.getStageSettings().getTime(DungeonStage.OPENED) - chest.getCurrentTick()); return ""; diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/task/DungeonTickTask.java b/src/main/java/t/me/p1azmer/plugin/dungeons/task/DungeonTickTask.java index d7aeb0d..0766a15 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/task/DungeonTickTask.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/task/DungeonTickTask.java @@ -11,14 +11,17 @@ public class DungeonTickTask extends AbstractTask { private final DungeonManager manager; public DungeonTickTask(@NotNull DungeonManager manager) { - super(manager.plugin(), 1, false); + super(manager.plugin(), 1, true); this.manager = manager; } @Override public void action() { + int online = plugin.getServer().getOnlinePlayers().size(); + for (Dungeon dungeon : this.manager.getDungeons()) { - if ((plugin.getServer().getOnlinePlayers().size() < dungeon.getSettings().getMinimalOnline() || !dungeon.getSettings().isEnabled()) && !dungeon.getStage().isOpened()) { + boolean allowed = online >= dungeon.getSettings().getMinimalOnline() && dungeon.getSettings().isEnabled(); + if (!allowed) { dungeon.cancel(false); continue; } diff --git a/src/main/java/t/me/p1azmer/plugin/dungeons/utils/Cuboid.java b/src/main/java/t/me/p1azmer/plugin/dungeons/utils/Cuboid.java index 9ac3ed5..22745eb 100644 --- a/src/main/java/t/me/p1azmer/plugin/dungeons/utils/Cuboid.java +++ b/src/main/java/t/me/p1azmer/plugin/dungeons/utils/Cuboid.java @@ -37,7 +37,7 @@ public Cuboid(@NotNull Location loc1, @NotNull Location loc2) { } public static Cuboid of(@NotNull Dungeon dungeon, @NotNull Location center) { - int radius = dungeon.getDungeonRegion().getRadius(); + int radius = dungeon.getRegion().getRadius(); int minX = center.getBlockX() - radius; int minY = center.getBlockY() - radius; int minZ = center.getBlockZ() - radius; diff --git a/src/main/resources/announce/closed_default.yml b/src/main/resources/announce/closed_default.yml index 465efbf..e64afac 100644 --- a/src/main/resources/announce/closed_default.yml +++ b/src/main/resources/announce/closed_default.yml @@ -1,5 +1,4 @@ Messages: - - '' - '#c71585Attention ❗' - '#fcf2f8At the coordinates: #ffb6ad⚐ %location_world%, %location_x%, %location_y%, %location_z%' - '#fcf2f8A dungeon has appeared #ffb6ad%dungeon_name%' diff --git a/src/main/resources/announce/prepare_default.yml b/src/main/resources/announce/prepare_default.yml index 8811b12..f33ba1b 100644 --- a/src/main/resources/announce/prepare_default.yml +++ b/src/main/resources/announce/prepare_default.yml @@ -1,6 +1,5 @@ Messages: - - '' - '#fd5e5e&lNOTE:' - '#e39fffUntil the new dungeon is spawned:' - - '#fdba5e%dungeon_next_stage_in% sec.' + - '#fdba5e%dungeon_next_stage_in%' Global: true \ No newline at end of file