From 4e6863caebb35612fa403e8f9c3a9a8291b84b83 Mon Sep 17 00:00:00 2001 From: Tofpu <47629321+Tofpu@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:31:00 +0200 Subject: [PATCH] v1.0.8 (#20) - refactored SchematicManager - renamed NullIsland to EmptyIsland & refactored IslandSetup - got rid of the unnecessary map in GamePlayer class - cleanup - added items to island setup - added items to regular games - version bump - made the items configurable - moved over the config.conf, and data.db to their own folders - complete migration to Lamp command framework - package refactor * javadocs improvement - The player now immediately gets teleported to the island setup when the island has been created to make the process much simpler and faster - Added additional debug messages, and made the messages more precise - improved codebase practices - locked behind some left out debugging messages - changed `/sb select`, to `/sb modify` as it's more accurate - changed `speedbridge.island.island.select` to `speedbridge.island.modify` --- README.md | 6 + build.gradle.kts | 21 +- .../io/tofpu/speedbridge2/SpeedBridge.java | 49 +- .../command/AbstractLampRegistry.java | 18 + .../speedbridge2/command/CommandManager.java | 163 +++-- .../AbstractCommandConditionWrapper.java | 44 ++ .../condition/LampConditionRegistry.java | 10 + .../condition/RestrictConsoleCondition.java | 31 + .../RestrictDummyModelCondition.java | 38 ++ .../condition/RestrictSetupCondition.java | 45 ++ .../annotation/RestrictConsole.java} | 4 +- .../annotation/RestrictDummyModel.java} | 4 +- .../annotation/RestrictSetup.java} | 6 +- .../command/context/AbstractLampContext.java | 21 + .../command/context/GameIslandContext.java | 32 + .../command/context/LampContextRegistry.java | 8 + .../command/parser/AbstractLampParser.java | 23 + .../command/parser/GameIslandParser.java | 20 - .../command/parser/GamePlayerParser.java | 20 - .../command/parser/IslandParser.java | 64 +- .../command/parser/LampParseRegistry.java | 8 + .../command/subcommand/CommandCompletion.java | 23 + .../subcommand/HelpCommandGenerator.java | 70 +- .../subcommand/SpeedBridgeCommand.java | 608 ++++++++---------- .../config/manager/ConfigurationManager.java | 137 ---- .../domain/island/IslandHandler.java | 126 ---- .../island/schematic/IslandSchematic.java | 76 --- .../game/GameInteractionListener.java | 18 +- .../listener/game/GameProtectionListener.java | 4 +- .../general/PlayerConnectionListener.java | 12 +- .../island/IslandProtectionListener.java | 8 +- .../listener/island/IslandRegionListener.java | 10 +- .../listener/wrapper/EventWrapper.java | 6 +- .../wrappers/BlockBreakEventWrapper.java | 2 +- .../wrappers/BlockPlaceEventWrapper.java | 2 +- .../wrappers/PlayerInteractEventWrapper.java | 2 +- .../blockmenu/BlockMenuManager.java | 10 +- .../blockmenu/holder/BlockMenuHolder.java | 2 +- .../blockmenu/listener/BlockMenuListener.java | 10 +- .../{domain => model}/common/Message.java | 10 +- .../common/PlayerNameCache.java | 4 +- .../common/PluginExecutor.java | 2 +- .../common/config/ItemConfiguration.java | 15 + .../common/config/PluginConfiguration.java | 7 +- .../config/category/BlockMenuCategory.java | 2 +- .../common/config/category/GameCategory.java | 32 + .../config/category/GeneralCategory.java | 2 +- .../config/category/LeaderboardCategory.java | 2 +- .../common/config/category/LobbyCategory.java | 4 +- .../config/manager/ConfigurationManager.java | 93 +++ .../AbstractItemActionSerializer.java | 34 + .../config/serializer/ItemMetaSerializer.java | 84 +++ .../serializer/ItemStackSerializer.java | 35 + .../config/serializer/LocationSerializer.java | 2 +- .../config/serializer/MaterialSerializer.java | 2 +- .../serializer/UmbrellaItemSerializer.java | 42 ++ .../common/database/DatabaseManager.java | 40 +- .../common/database/Databases.java | 12 +- .../common/database/wrapper/Database.java | 4 +- .../database/wrapper/DatabaseQuery.java | 4 +- .../common/database/wrapper/DatabaseSet.java | 2 +- .../database/wrapper/DatabaseTable.java | 4 +- .../common/umbrella/RunCommandItemAction.java | 33 + .../umbrella/SerializableUmbrellaItem.java | 44 ++ .../common/util/BridgeUtil.java | 22 +- .../common/util/DatabaseUtil.java | 20 +- .../common/util/FileUtil.java | 2 +- .../common/util/IgnoreMessage.java | 2 +- .../common/util/MessageUtil.java | 2 +- .../common/util/ReflectionUtil.java | 4 +- .../model/common/util/UmbrellaUtil.java | 48 ++ .../common/util/UpdateChecker.java | 2 +- .../model/common/wrapper/ConfigurateFile.java | 147 +++++ .../common/wrapper/FileConfigurationType.java | 5 + .../island/IslandDatabase.java | 29 +- .../model/island/IslandHandler.java | 212 ++++++ .../island/IslandRepository.java | 10 +- .../island/IslandService.java | 28 +- .../IslandDatabaseExceptionWrapper.java | 8 + .../exception/IslandLoadFailureException.java | 7 + .../island/object/Island.java | 85 ++- .../island/object/IslandBoard.java | 10 +- .../island/object/extra/EmptyIsland.java} | 16 +- .../island/object/extra/GameIsland.java | 54 +- .../island/object/extra/IslandCreation.java | 42 ++ .../object/umbrella/GameIslandUmbrella.java | 29 + .../island/plot/IslandPlot.java | 29 +- .../island/plot/PlotState.java | 4 +- .../island/schematic/IslandSchematic.java | 104 +++ .../island/schematic/SchematicManager.java | 85 ++- .../island/setup/IslandCreationSetup.java | 30 + .../island/setup/IslandSetup.java | 72 ++- .../island/setup/IslandSetupManager.java | 58 +- .../setup/umbrella/IslandSetupUmbrella.java | 59 ++ .../leaderboard/Leaderboard.java | 24 +- .../leaderboard/LeaderboardMap.java | 10 +- .../leaderboard/loader/IslandLoader.java | 8 +- .../loader/PersonalBoardLoader.java | 26 +- .../leaderboard/meta/BoardRetrieve.java | 2 +- .../leaderboard/wrapper/BoardPlayer.java | 4 +- .../wrapper/IslandBoardPlayer.java | 10 +- .../player/PlayerDatabase.java | 70 +- .../player/PlayerHandler.java | 14 +- .../player/PlayerService.java | 10 +- .../PlayerDatabaseExceptionWrapper.java | 10 + .../PlayerDeletionFailureException.java | 9 + .../exception/PlayerLoadFailureException.java | 9 + .../PlayerUpdateFailureException.java | 9 + .../PlayerUpdateNameFailureException.java | 9 + .../player/loader/PlayerLoader.java | 22 +- .../player/misc/block/BlockChoice.java | 2 +- .../player/misc/block/BlockDatabase.java | 31 +- .../player/misc/score/Score.java | 4 +- .../player/misc/score/ScoreDatabase.java | 26 +- .../player/misc/session/SessionScore.java | 4 +- .../player/misc/setup/SetupMeta.java | 2 +- .../player/misc/stat/PlayerStat.java | 2 +- .../player/misc/stat/PlayerStatType.java | 4 +- .../player/misc/stat/StatsDatabase.java | 26 +- .../misc/stat/type/SimplePlayerStat.java | 6 +- .../player/object/BridgePlayer.java | 36 +- .../player/object/GamePlayer.java | 19 +- .../object/extra/CommonBridgePlayer.java | 2 +- .../object/extra/DummyBridgePlayer.java | 4 +- .../object/extra/SenderBridgePlayer.java | 2 +- .../placeholderapi/PluginExpansion.java | 8 +- .../expansion/AbstractExpansion.java | 6 +- .../expansion/ExpansionHandler.java | 6 +- .../expansions/BestScoreExpansion.java | 16 +- .../expansion/expansions/BlocksExpansion.java | 8 +- .../expansions/IslandSlotExpansion.java | 10 +- .../expansions/LeaderboardExpansion.java | 26 +- .../expansions/PositionExpansion.java | 16 +- .../expansion/expansions/TimerExpansion.java | 10 +- .../expansions/TotalStatsExpansion.java | 10 +- .../support/worldedit/CuboidRegion.java | 2 +- .../{ => model}/support/worldedit/Vector.java | 2 +- 137 files changed, 2625 insertions(+), 1412 deletions(-) create mode 100644 src/main/java/io/tofpu/speedbridge2/command/AbstractLampRegistry.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/condition/AbstractCommandConditionWrapper.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/condition/LampConditionRegistry.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/condition/RestrictConsoleCondition.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/condition/RestrictDummyModelCondition.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/condition/RestrictSetupCondition.java rename src/main/java/io/tofpu/speedbridge2/command/{parser/GameIslandArgument.java => condition/annotation/RestrictConsole.java} (70%) rename src/main/java/io/tofpu/speedbridge2/command/{parser/IslandArgument.java => condition/annotation/RestrictDummyModel.java} (69%) rename src/main/java/io/tofpu/speedbridge2/command/{parser/GamePlayerArgument.java => condition/annotation/RestrictSetup.java} (62%) create mode 100644 src/main/java/io/tofpu/speedbridge2/command/context/AbstractLampContext.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/context/GameIslandContext.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/context/LampContextRegistry.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/parser/AbstractLampParser.java delete mode 100644 src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandParser.java delete mode 100644 src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerParser.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/parser/LampParseRegistry.java create mode 100644 src/main/java/io/tofpu/speedbridge2/command/subcommand/CommandCompletion.java delete mode 100644 src/main/java/io/tofpu/speedbridge2/domain/common/config/manager/ConfigurationManager.java delete mode 100644 src/main/java/io/tofpu/speedbridge2/domain/island/IslandHandler.java delete mode 100644 src/main/java/io/tofpu/speedbridge2/domain/island/schematic/IslandSchematic.java rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/blockmenu/BlockMenuManager.java (93%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/blockmenu/holder/BlockMenuHolder.java (90%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/blockmenu/listener/BlockMenuListener.java (79%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/Message.java (97%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/PlayerNameCache.java (95%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/PluginExecutor.java (96%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/ItemConfiguration.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/PluginConfiguration.java (72%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/category/BlockMenuCategory.java (94%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/category/GameCategory.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/category/GeneralCategory.java (92%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/category/LeaderboardCategory.java (94%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/category/LobbyCategory.java (89%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/manager/ConfigurationManager.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/AbstractItemActionSerializer.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemMetaSerializer.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemStackSerializer.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/serializer/LocationSerializer.java (97%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/config/serializer/MaterialSerializer.java (94%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/UmbrellaItemSerializer.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/database/DatabaseManager.java (67%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/database/Databases.java (63%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/database/wrapper/Database.java (73%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/database/wrapper/DatabaseQuery.java (95%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/database/wrapper/DatabaseSet.java (96%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/database/wrapper/DatabaseTable.java (92%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/umbrella/RunCommandItemAction.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/umbrella/SerializableUmbrellaItem.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/BridgeUtil.java (91%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/DatabaseUtil.java (76%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/FileUtil.java (97%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/IgnoreMessage.java (84%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/MessageUtil.java (97%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/ReflectionUtil.java (90%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/util/UmbrellaUtil.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/common/util/UpdateChecker.java (99%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/wrapper/ConfigurateFile.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/common/wrapper/FileConfigurationType.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/IslandDatabase.java (78%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/IslandHandler.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/IslandRepository.java (77%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/IslandService.java (75%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandDatabaseExceptionWrapper.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandLoadFailureException.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/object/Island.java (74%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/object/IslandBoard.java (92%) rename src/main/java/io/tofpu/speedbridge2/{domain/island/object/extra/NullIsland.java => model/island/object/extra/EmptyIsland.java} (66%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/object/extra/GameIsland.java (65%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/object/extra/IslandCreation.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/object/umbrella/GameIslandUmbrella.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/plot/IslandPlot.java (84%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/plot/PlotState.java (84%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/schematic/IslandSchematic.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/schematic/SchematicManager.java (67%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandCreationSetup.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/setup/IslandSetup.java (73%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/island/setup/IslandSetupManager.java (60%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/island/setup/umbrella/IslandSetupUmbrella.java rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/Leaderboard.java (91%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/LeaderboardMap.java (92%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/loader/IslandLoader.java (82%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/loader/PersonalBoardLoader.java (82%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/meta/BoardRetrieve.java (85%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/wrapper/BoardPlayer.java (89%) rename src/main/java/io/tofpu/speedbridge2/{domain/extra => model}/leaderboard/wrapper/IslandBoardPlayer.java (91%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/PlayerDatabase.java (68%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/PlayerHandler.java (91%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/PlayerService.java (91%) create mode 100644 src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDatabaseExceptionWrapper.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDeletionFailureException.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerLoadFailureException.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateFailureException.java create mode 100644 src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateNameFailureException.java rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/loader/PlayerLoader.java (77%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/block/BlockChoice.java (89%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/block/BlockDatabase.java (65%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/score/Score.java (92%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/score/ScoreDatabase.java (79%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/session/SessionScore.java (72%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/setup/SetupMeta.java (85%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/stat/PlayerStat.java (90%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/stat/PlayerStatType.java (88%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/stat/StatsDatabase.java (76%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/misc/stat/type/SimplePlayerStat.java (89%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/object/BridgePlayer.java (91%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/object/GamePlayer.java (87%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/object/extra/CommonBridgePlayer.java (87%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/object/extra/DummyBridgePlayer.java (69%) rename src/main/java/io/tofpu/speedbridge2/{domain => model}/player/object/extra/SenderBridgePlayer.java (89%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/PluginExpansion.java (85%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/AbstractExpansion.java (71%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/ExpansionHandler.java (90%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/BestScoreExpansion.java (63%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/BlocksExpansion.java (70%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java (69%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java (73%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/PositionExpansion.java (81%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/TimerExpansion.java (69%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java (72%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/worldedit/CuboidRegion.java (96%) rename src/main/java/io/tofpu/speedbridge2/{ => model}/support/worldedit/Vector.java (91%) diff --git a/README.md b/README.md index 32501aad..6b2f9325 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,9 @@ __Features__ __Dependencies__ - WorldEdit (Required) - PlaceholderAPI (Optional) + +__Thanks to__ +- [GitBook](https://gitbook.com) +- [JProfiler](https://www.ej-technologies.com/products/jprofiler/overview.html) + +For providing us with an open-source licence! <3 diff --git a/build.gradle.kts b/build.gradle.kts index 62fa7a66..0ffc480b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,11 +5,13 @@ plugins { } group = "io.tofpu.speedbridge2" -version = "1.0.7" +version = "1.0.8" tasks { compileJava { options.encoding = "UTF-8" + options.compilerArgs.plusAssign("-parameters") + sourceCompatibility = "11" } named("shadowJar") { @@ -26,6 +28,8 @@ tasks { relocate("org.bstats", "io.tofpu.speedbridge2.lib.bstats") relocate("com.github.benmanes.caffeine", "io.tofpu.speedbridge2.lib.caffeine") relocate("org.apache.commons", "io.tofpu.speedbridge2.lib.commons") + relocate("org.yaml.snakeyaml", "io.tofpu.speedbridge2.lib.snakeyml") + relocate("revxrsal", "io.tofpu.speedbridge2.lib.lamp") } exclude("META-INF/**") @@ -47,13 +51,15 @@ publishing { } repositories { - mavenCentral() mavenLocal() + mavenCentral() maven("https://jitpack.io") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") maven("https://maven.enginehub.org/repo/") maven("https://oss.sonatype.org/content/groups/public/") + maven("https://repo.codemc.org/repository/maven-public/") + maven("https://libraries.minecraft.net") } dependencies { @@ -63,17 +69,18 @@ dependencies { compileOnly("com.sk89q:worldedit:6.0.0-SNAPSHOT") - implementation("cloud.commandframework:cloud-bukkit:1.6.2") - implementation("cloud.commandframework:cloud-annotations:1.6.1") + implementation("com.github.Revxrsal.Lamp:common:b3af8b94a0") + implementation("com.github.Revxrsal.Lamp:bukkit:b3af8b94a0") implementation("net.kyori:adventure-api:4.10.1") implementation("net.kyori:adventure-platform-bukkit:4.0.1") implementation("net.kyori:adventure-text-minimessage:4.10.1") - implementation("com.github.tofpu:DynamicClass:fdc123593b") { + implementation("com.github.tofpu:DynamicClass:1.1") { exclude("com.google.guava", "guava") } + implementation("org.spongepowered:configurate-yaml:4.1.2") implementation("org.spongepowered:configurate-hocon:4.1.2") implementation("commons-lang:commons-lang:2.6") implementation("commons-io:commons-io:2.11.0") @@ -85,9 +92,11 @@ dependencies { implementation("com.github.ben-manes.caffeine:caffeine:3.0.5") implementation("com.github.cryptomorin:XSeries:8.6.1") - implementation("com.github.tofpu.MultiWorldEdit:multiworldedit-api:f9ad4ce832") { + implementation("com.github.tofpu.MultiWorldEdit:multiworldedit-api:0eb85d6cbd") { exclude("de.schlichtherle", "truezip") exclude("rhino", "js") exclude("com.sk89q", "worldedit") } + + implementation("com.github.tofpu:umbrella:1ce46ae04a") } diff --git a/src/main/java/io/tofpu/speedbridge2/SpeedBridge.java b/src/main/java/io/tofpu/speedbridge2/SpeedBridge.java index 4e80880b..51f3eef0 100644 --- a/src/main/java/io/tofpu/speedbridge2/SpeedBridge.java +++ b/src/main/java/io/tofpu/speedbridge2/SpeedBridge.java @@ -4,21 +4,22 @@ import io.tofpu.multiworldedit.MultiWorldEditAPI; import io.tofpu.speedbridge2.command.CommandManager; import io.tofpu.speedbridge2.command.subcommand.HelpCommandGenerator; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.database.DatabaseManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.UpdateChecker; -import io.tofpu.speedbridge2.domain.extra.blockmenu.BlockMenuManager; -import io.tofpu.speedbridge2.domain.extra.leaderboard.Leaderboard; -import io.tofpu.speedbridge2.domain.island.IslandService; -import io.tofpu.speedbridge2.domain.island.object.IslandBoard; -import io.tofpu.speedbridge2.domain.island.schematic.SchematicManager; -import io.tofpu.speedbridge2.domain.island.setup.IslandSetupManager; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.support.placeholderapi.PluginExpansion; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.ExpansionHandler; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.database.DatabaseManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.UpdateChecker; +import io.tofpu.speedbridge2.model.blockmenu.BlockMenuManager; +import io.tofpu.speedbridge2.model.leaderboard.Leaderboard; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.island.object.IslandBoard; +import io.tofpu.speedbridge2.model.island.schematic.SchematicManager; +import io.tofpu.speedbridge2.model.island.setup.IslandSetupManager; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.support.placeholderapi.PluginExpansion; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.ExpansionHandler; +import io.tofpu.umbrella.UmbrellaAPI; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; @@ -37,17 +38,20 @@ public SpeedBridge(final JavaPlugin javaPlugin) { public void load() { // reset the world, in-case it does exist - SchematicManager.INSTANCE.resetWorld(); + SchematicManager.resetWorld(); } public void enable() { adventure = BukkitAudiences.create(javaPlugin); + new UmbrellaAPI(javaPlugin) + .enable(); + new Metrics(javaPlugin, 14597); MultiWorldEditAPI.load(javaPlugin); - log("Loading the `config.yml`..."); + log("Loading the `config.conf` & 'items.yml'..."); ConfigurationManager.INSTANCE.load(javaPlugin); try { @@ -66,7 +70,7 @@ public void enable() { } log("Loading the `speedbridge2` world..."); - SchematicManager.INSTANCE.load(); + SchematicManager.load(); IslandSetupManager.INSTANCE.load(); @@ -137,8 +141,13 @@ public void shutdown() { PlayerService.INSTANCE.shutdown(); log("Unloading the `speedbridge2` world..."); - SchematicManager.INSTANCE.unloadWorld(); - SchematicManager.INSTANCE.resetWorld(); + SchematicManager.unloadWorld(); + SchematicManager.resetWorld(); + + final UmbrellaAPI umbrellaAPI = UmbrellaAPI.getInstance(); + if (umbrellaAPI != null) { + umbrellaAPI.disable(); + } log("Complete."); } diff --git a/src/main/java/io/tofpu/speedbridge2/command/AbstractLampRegistry.java b/src/main/java/io/tofpu/speedbridge2/command/AbstractLampRegistry.java new file mode 100644 index 00000000..6276ad22 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/AbstractLampRegistry.java @@ -0,0 +1,18 @@ +package io.tofpu.speedbridge2.command; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public abstract class AbstractLampRegistry { + private final Map parserMap = new HashMap<>(); + + public void register(final K key, final V value) { + this.parserMap.put(key, value); + } + + public Collection values() { + return Collections.unmodifiableCollection(parserMap.values()); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/CommandManager.java b/src/main/java/io/tofpu/speedbridge2/command/CommandManager.java index f9ccfabf..e046a4da 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/CommandManager.java +++ b/src/main/java/io/tofpu/speedbridge2/command/CommandManager.java @@ -1,82 +1,133 @@ package io.tofpu.speedbridge2.command; -import cloud.commandframework.CommandTree; -import cloud.commandframework.annotations.AnnotationParser; -import cloud.commandframework.arguments.parser.ParserParameters; -import cloud.commandframework.arguments.parser.StandardParameters; -import cloud.commandframework.bukkit.BukkitCommandManager; -import cloud.commandframework.execution.CommandExecutionCoordinator; -import cloud.commandframework.meta.CommandMeta; -import io.tofpu.speedbridge2.command.parser.GameIslandParser; -import io.tofpu.speedbridge2.command.parser.IslandParser; +import io.tofpu.dynamicclass.DynamicClass; +import io.tofpu.speedbridge2.command.condition.AbstractCommandConditionWrapper; +import io.tofpu.speedbridge2.command.condition.LampConditionRegistry; +import io.tofpu.speedbridge2.command.context.AbstractLampContext; +import io.tofpu.speedbridge2.command.context.LampContextRegistry; +import io.tofpu.speedbridge2.command.parser.AbstractLampParser; +import io.tofpu.speedbridge2.command.parser.LampParseRegistry; +import io.tofpu.speedbridge2.command.subcommand.CommandCompletion; import io.tofpu.speedbridge2.command.subcommand.SpeedBridgeCommand; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.CommonBridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.DummyBridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.SenderBridgePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.CommonBridgePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.DummyBridgePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.SenderBridgePlayer; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import revxrsal.commands.bukkit.BukkitCommandActor; +import revxrsal.commands.bukkit.BukkitCommandHandler; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; +import revxrsal.commands.process.SenderResolver; +import java.util.Objects; import java.util.UUID; -import java.util.function.Function; public final class CommandManager { - private static BukkitCommandManager manager; + private static BukkitCommandHandler commandHandler; public static void load(final @NotNull Plugin plugin) { - final Function, CommandExecutionCoordinator> executionCoordinatorFunction = CommandExecutionCoordinator.SimpleCoordinator - .simpleCoordinator(); + commandHandler = BukkitCommandHandler.create(plugin); - final Function bridgePlayerFunction = sender -> { - if (sender instanceof ConsoleCommandSender) { - return new SenderBridgePlayer(sender); + commandHandler.registerResponseHandler(String.class, (response, actor, command) -> { + if (response.isEmpty()) { + return; } - final Player player = (Player) sender; - final UUID uniqueId = player.getUniqueId(); - final BridgePlayer bridgePlayer = PlayerService.INSTANCE.get(uniqueId); + actor.reply(BridgeUtil.miniMessageToLegacy(response)); + }); - // if the bridge player is null, return a dummy instance - if (bridgePlayer == null) { - return DummyBridgePlayer.of(uniqueId); + commandHandler.registerSenderResolver(new SenderResolver() { + @Override + public boolean isCustomType(final Class type) { + return CommonBridgePlayer.class.isAssignableFrom(type); } - return bridgePlayer; - }; + @Override + public @NotNull Object getSender( + @NotNull final Class customSenderType, + @NotNull final CommandActor actor, + @NotNull final ExecutableCommand command) { + final BukkitCommandActor commandActor = (BukkitCommandActor) actor; - final Function senderToBridgePlayerFunction = CommonBridgePlayer::getPlayer; + if (commandActor.isConsole()) { + return new SenderBridgePlayer(commandActor.requireConsole()); + } - try { - manager = new BukkitCommandManager<>(plugin, executionCoordinatorFunction, bridgePlayerFunction, senderToBridgePlayerFunction); - } catch (Exception exception) { - exception.printStackTrace(); + final UUID uniqueId = commandActor.requirePlayer().getUniqueId(); + final BridgePlayer bridgePlayer = PlayerService.INSTANCE.get(uniqueId); + return Objects.requireNonNullElseGet(bridgePlayer, () -> DummyBridgePlayer.of(uniqueId)); + } + }); + + + commandHandler.setHelpWriter((command, actor) -> String.format( + "- /%s " + "%s - %s", command.getPath() + .toRealString(), command.getUsage(), command.getDescription())); + + constructTabCompleter(); + constructContext(); + constructParsers(); + constructCommandConditions(); + + commandHandler.register(new SpeedBridgeCommand()); + } + + private static void constructTabCompleter() { + BridgeUtil.debug("Constructing tab completer..."); + + commandHandler.getAutoCompleter() + .registerParameterSuggestions(Island.class, CommandCompletion::islands); + } + + private static void constructContext() { + final AbstractLampRegistry> registry = + DynamicClass.getInstance(LampContextRegistry.class); + if (registry == null) { + return; + } + + BridgeUtil.debug("Constructing contexts..."); + + for (final AbstractLampContext parser : registry.values()) { + parser.register(commandHandler); + + BridgeUtil.debug("Registered context: " + parser.getClass() + .getName()); } + } - final Function commandMetaFunction = p -> CommandMeta - .simple() - // This will allow you to decorate commands with descriptions - .with(CommandMeta.DESCRIPTION, p.get(StandardParameters.DESCRIPTION, "No description")) - .build(); + private static void constructParsers() { + final AbstractLampRegistry> lampParseRegistry = DynamicClass.getInstance(LampParseRegistry.class); + if (lampParseRegistry == null) { + return; + } - final AnnotationParser annotationParser = new AnnotationParser<>( - /* Manager */ manager, - /* Command sender type */ CommonBridgePlayer.class, - /* Mapper for command meta instances */ commandMetaFunction); + BridgeUtil.debug("Constructing parsers..."); - annotationParser.getParameterInjectorRegistry() - .registerInjector(Island.class, (context, annotationAccessor) -> { - return new IslandParser<>().parse(context, annotationAccessor); - }); + for (final AbstractLampParser parser : lampParseRegistry.values()) { + parser.register(commandHandler); - annotationParser.getParameterInjectorRegistry() - .registerInjector(GameIsland.class, (context, annotationAccessor) -> new GameIslandParser() - .parse(context, annotationAccessor)); + BridgeUtil.debug("Registered parser: " + parser.getClass() + .getName()); + } + } + + private static void constructCommandConditions() { + final AbstractLampRegistry registry = DynamicClass.getInstance(LampConditionRegistry.class); + if (registry == null) { + return; + } - annotationParser.parse(new SpeedBridgeCommand()); + BridgeUtil.debug("Constructing command conditions..."); + + for (final AbstractCommandConditionWrapper condition : registry.values()) { + condition.register(commandHandler); + BridgeUtil.debug("Registered command condition: " + condition.getClass() + .getName()); + } } } diff --git a/src/main/java/io/tofpu/speedbridge2/command/condition/AbstractCommandConditionWrapper.java b/src/main/java/io/tofpu/speedbridge2/command/condition/AbstractCommandConditionWrapper.java new file mode 100644 index 00000000..7e1401d6 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/AbstractCommandConditionWrapper.java @@ -0,0 +1,44 @@ +package io.tofpu.speedbridge2.command.condition; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; +import revxrsal.commands.CommandHandler; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; +import revxrsal.commands.process.CommandCondition; + +import java.lang.annotation.Annotation; +import java.util.List; + +public abstract class AbstractCommandConditionWrapper implements CommandCondition { + private final Class type; + + public AbstractCommandConditionWrapper(final Class type, + final LampConditionRegistry registry) { + this.type = type; + registry.register(type, this); + } + + public void register(final CommandHandler handler) { + handler.registerCondition(this); + } + + @Override + public final void test( + @NotNull final CommandActor actor, + @NotNull final ExecutableCommand command, + @NotNull @Unmodifiable final List arguments) { + if (!command.hasAnnotation(type)) { + return; + } + execute(actor, command, arguments); + } + + abstract void execute(@NotNull CommandActor actor, + @NotNull ExecutableCommand command, + @NotNull @Unmodifiable List arguments); + + public Class getType() { + return type; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/condition/LampConditionRegistry.java b/src/main/java/io/tofpu/speedbridge2/command/condition/LampConditionRegistry.java new file mode 100644 index 00000000..ffd31bf1 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/LampConditionRegistry.java @@ -0,0 +1,10 @@ +package io.tofpu.speedbridge2.command.condition; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.command.AbstractLampRegistry; + +import java.lang.annotation.Annotation; + +@AutoRegister +public final class LampConditionRegistry extends AbstractLampRegistry, AbstractCommandConditionWrapper> {} diff --git a/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictConsoleCondition.java b/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictConsoleCondition.java new file mode 100644 index 00000000..b2ed67b7 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictConsoleCondition.java @@ -0,0 +1,31 @@ +package io.tofpu.speedbridge2.command.condition; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.command.condition.annotation.RestrictConsole; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; +import revxrsal.commands.bukkit.BukkitCommandActor; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; +import revxrsal.commands.exception.CommandErrorException; + +import java.util.List; + +@AutoRegister +public final class RestrictConsoleCondition extends AbstractCommandConditionWrapper { + public RestrictConsoleCondition(final LampConditionRegistry registry) { + super(RestrictConsole.class, registry); + } + + @Override + void execute( + @NotNull final CommandActor actor, + @NotNull final ExecutableCommand command, + @NotNull @Unmodifiable final List arguments) { + final BukkitCommandActor commandActor = (BukkitCommandActor) actor; + + if (commandActor.isConsole()) { + throw new CommandErrorException("Console is not allowed to execute this command."); + } + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictDummyModelCondition.java b/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictDummyModelCondition.java new file mode 100644 index 00000000..c9de46c0 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictDummyModelCondition.java @@ -0,0 +1,38 @@ +package io.tofpu.speedbridge2.command.condition; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.command.condition.annotation.RestrictSetup; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.DummyBridgePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; +import revxrsal.commands.exception.CommandErrorException; + +import java.util.List; + +@AutoRegister +public final class RestrictDummyModelCondition extends AbstractCommandConditionWrapper { + public RestrictDummyModelCondition(final LampConditionRegistry registry) { + super(RestrictSetup.class, registry); + } + + @Override + public void execute( + @NotNull final CommandActor actor, + @NotNull final ExecutableCommand command, + @NotNull @Unmodifiable final List arguments) { + final BridgePlayer player = PlayerService.INSTANCE.get(actor.getUniqueId()); + if (player == null) { + return; + } + + if (player instanceof DummyBridgePlayer) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(Message.INSTANCE.notLoaded)); + } + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictSetupCondition.java b/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictSetupCondition.java new file mode 100644 index 00000000..d53f29f6 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/RestrictSetupCondition.java @@ -0,0 +1,45 @@ +package io.tofpu.speedbridge2.command.condition; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.command.condition.annotation.RestrictSetup; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; +import revxrsal.commands.exception.CommandErrorException; + +import java.util.List; + +@AutoRegister +public final class RestrictSetupCondition extends AbstractCommandConditionWrapper { + public RestrictSetupCondition(final LampConditionRegistry registry) { + super(RestrictSetup.class, registry); + } + + @Override + public void execute( + @NotNull final CommandActor actor, + @NotNull final ExecutableCommand command, + @NotNull @Unmodifiable final List arguments) { + final BridgePlayer player = PlayerService.INSTANCE.get(actor.getUniqueId()); + if (player == null) { + return; + } + + final RestrictSetup annotation = command.getAnnotation(RestrictSetup.class); + if (annotation.opposite()) { + if (!player.isInSetup()) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(Message.INSTANCE.notInASetup)); + } + return; + } + + if (player.isInSetup()) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(Message.INSTANCE.inASetup)); + } + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandArgument.java b/src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictConsole.java similarity index 70% rename from src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandArgument.java rename to src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictConsole.java index a1a33726..d897cd47 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandArgument.java +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictConsole.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.command.parser; +package io.tofpu.speedbridge2.command.condition.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -7,4 +7,4 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -public @interface GameIslandArgument {} +public @interface RestrictConsole {} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/IslandArgument.java b/src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictDummyModel.java similarity index 69% rename from src/main/java/io/tofpu/speedbridge2/command/parser/IslandArgument.java rename to src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictDummyModel.java index bf06ff07..6dbe5cdd 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/parser/IslandArgument.java +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictDummyModel.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.command.parser; +package io.tofpu.speedbridge2.command.condition.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -7,4 +7,4 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -public @interface IslandArgument {} +public @interface RestrictDummyModel {} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerArgument.java b/src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictSetup.java similarity index 62% rename from src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerArgument.java rename to src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictSetup.java index f063a46f..d8836ede 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerArgument.java +++ b/src/main/java/io/tofpu/speedbridge2/command/condition/annotation/RestrictSetup.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.command.parser; +package io.tofpu.speedbridge2.command.condition.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -7,4 +7,6 @@ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) -public @interface GamePlayerArgument {} +public @interface RestrictSetup { + boolean opposite() default false; +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/context/AbstractLampContext.java b/src/main/java/io/tofpu/speedbridge2/command/context/AbstractLampContext.java new file mode 100644 index 00000000..d7f6cdad --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/context/AbstractLampContext.java @@ -0,0 +1,21 @@ +package io.tofpu.speedbridge2.command.context; + +import revxrsal.commands.CommandHandler; +import revxrsal.commands.process.ContextResolver; + +public abstract class AbstractLampContext implements ContextResolver { + private final Class type; + + public AbstractLampContext(final Class type, final LampContextRegistry registry) { + this.type = type; + registry.register(type, this); + } + + public void register(final CommandHandler commandHandler) { + commandHandler.registerContextResolver(type, this); + } + + public Class getType() { + return type; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/context/GameIslandContext.java b/src/main/java/io/tofpu/speedbridge2/command/context/GameIslandContext.java new file mode 100644 index 00000000..0da118ef --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/context/GameIslandContext.java @@ -0,0 +1,32 @@ +package io.tofpu.speedbridge2.command.context; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import revxrsal.commands.exception.CommandErrorException; +import revxrsal.commands.process.ContextResolver; + +import static io.tofpu.speedbridge2.model.common.Message.INSTANCE; + +@AutoRegister +public final class GameIslandContext extends AbstractLampContext { + public GameIslandContext(final LampContextRegistry registry) { + super(GameIsland.class, registry); + } + + @Override + public GameIsland resolve(final ContextResolver.ContextResolverContext context) { + final BridgePlayer player = PlayerService.INSTANCE.get(context.actor().getUniqueId()); + if (player == null) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(INSTANCE.notLoaded)); + } + final GameIsland currentGame = player.getCurrentGame(); + if (currentGame == null) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(INSTANCE.notInAIsland)); + } + + return currentGame; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/context/LampContextRegistry.java b/src/main/java/io/tofpu/speedbridge2/command/context/LampContextRegistry.java new file mode 100644 index 00000000..24e7a403 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/context/LampContextRegistry.java @@ -0,0 +1,8 @@ +package io.tofpu.speedbridge2.command.context; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.command.AbstractLampRegistry; + +@AutoRegister +public final class LampContextRegistry extends AbstractLampRegistry, + AbstractLampContext> {} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/AbstractLampParser.java b/src/main/java/io/tofpu/speedbridge2/command/parser/AbstractLampParser.java new file mode 100644 index 00000000..af2458e6 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/parser/AbstractLampParser.java @@ -0,0 +1,23 @@ +package io.tofpu.speedbridge2.command.parser; + +import revxrsal.commands.CommandHandler; +import revxrsal.commands.process.ValueResolver; + +public abstract class AbstractLampParser { + private final Class type; + + public AbstractLampParser(final Class type, final LampParseRegistry registry) { + this.type = type; + registry.register(type, this); + } + + public void register(final CommandHandler commandHandler) { + commandHandler.registerValueResolver(type, this::parse); + } + + abstract T parse(ValueResolver.ValueResolverContext context); + + public Class getType() { + return type; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandParser.java b/src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandParser.java deleted file mode 100644 index cbcf4a95..00000000 --- a/src/main/java/io/tofpu/speedbridge2/command/parser/GameIslandParser.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.tofpu.speedbridge2.command.parser; - -import cloud.commandframework.annotations.AnnotationAccessor; -import cloud.commandframework.context.CommandContext; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import org.checkerframework.checker.nullness.qual.NonNull; - -//@AutoRegister -public final class GameIslandParser { - public GameIsland parse(@NonNull CommandContext context, - @NonNull AnnotationAccessor annotationAccessor) { - if (annotationAccessor.annotation(GameIslandArgument.class) == null) { - return null; - } - - final BridgePlayer bridgePlayer = (BridgePlayer) context.getSender(); - return bridgePlayer.getCurrentGame(); - } -} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerParser.java b/src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerParser.java deleted file mode 100644 index 1d305837..00000000 --- a/src/main/java/io/tofpu/speedbridge2/command/parser/GamePlayerParser.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.tofpu.speedbridge2.command.parser; - -import cloud.commandframework.annotations.AnnotationAccessor; -import cloud.commandframework.context.CommandContext; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import org.checkerframework.checker.nullness.qual.NonNull; - -public final class GamePlayerParser { - public GamePlayer parse(@NonNull CommandContext context, - @NonNull AnnotationAccessor annotationAccessor) { - if (annotationAccessor.annotation(GamePlayerArgument.class) == null) { - return null; - } - - final BridgePlayer bridgePlayer = (BridgePlayer) context.getSender(); - - return bridgePlayer.getGamePlayer(); - } -} diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/IslandParser.java b/src/main/java/io/tofpu/speedbridge2/command/parser/IslandParser.java index 7244bc7f..8e376a28 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/parser/IslandParser.java +++ b/src/main/java/io/tofpu/speedbridge2/command/parser/IslandParser.java @@ -1,30 +1,54 @@ package io.tofpu.speedbridge2.command.parser; -import cloud.commandframework.annotations.AnnotationAccessor; -import cloud.commandframework.context.CommandContext; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.CommonBridgePlayer; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.extra.NullIsland; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import org.checkerframework.checker.nullness.qual.NonNull; - -public final class IslandParser { - public Island parse(@NonNull CommandContext context, @NonNull AnnotationAccessor annotationAccessor) { - if (annotationAccessor.annotation(IslandArgument.class) == null) { - return null; +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import revxrsal.commands.exception.CommandErrorException; +import revxrsal.commands.process.ValueResolver; + +import static io.tofpu.speedbridge2.model.common.Message.INSTANCE; + +@AutoRegister +public final class IslandParser extends AbstractLampParser { + public IslandParser(final LampParseRegistry registry) { + super(Island.class, registry); + } + + @Override + Island parse(final ValueResolver.ValueResolverContext context) { + final BridgePlayer player = PlayerService.INSTANCE.get(context.actor().getUniqueId()); + + final String input = context.pop(); + if (player == null) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(INSTANCE.notLoaded)); } - final BridgePlayer bridgePlayer = (BridgePlayer) context.getSender(); - final GamePlayer gamePlayer = bridgePlayer.getGamePlayer(); + final IslandService islandService = IslandService.INSTANCE; + + int slot; + try { + slot = Integer.parseInt(input); + } catch (NumberFormatException exception) { + slot = -1; + } - if (gamePlayer == null) { - return new NullIsland(); + Island island = null; + if (slot != -1) { + island = islandService.findIslandBy(slot); + } else if (input != null && !input.isEmpty()) { + island = islandService.findIslandBy(input); } - final GameIsland gameIsland = gamePlayer.getCurrentGame(); + if (island == null) { + if (slot == -1) { + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(INSTANCE.invalidIslandArgument)); + } + throw new CommandErrorException(BridgeUtil.miniMessageToLegacy(String.format(INSTANCE.invalidIsland, slot + ""))); + } - return gameIsland.getIsland(); + return island; } } diff --git a/src/main/java/io/tofpu/speedbridge2/command/parser/LampParseRegistry.java b/src/main/java/io/tofpu/speedbridge2/command/parser/LampParseRegistry.java new file mode 100644 index 00000000..326bc9ea --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/parser/LampParseRegistry.java @@ -0,0 +1,8 @@ +package io.tofpu.speedbridge2.command.parser; + +import io.tofpu.dynamicclass.meta.AutoRegister; +import io.tofpu.speedbridge2.command.AbstractLampRegistry; + +@AutoRegister +public final class LampParseRegistry extends AbstractLampRegistry, + AbstractLampParser> {} diff --git a/src/main/java/io/tofpu/speedbridge2/command/subcommand/CommandCompletion.java b/src/main/java/io/tofpu/speedbridge2/command/subcommand/CommandCompletion.java new file mode 100644 index 00000000..ee76fbaf --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/command/subcommand/CommandCompletion.java @@ -0,0 +1,23 @@ +package io.tofpu.speedbridge2.command.subcommand; + +import io.tofpu.speedbridge2.model.island.IslandService; +import revxrsal.commands.command.CommandActor; +import revxrsal.commands.command.ExecutableCommand; + +import java.util.ArrayList; +import java.util.List; + +public final class CommandCompletion { + public static List islands(final List args, final CommandActor actor, + final ExecutableCommand command) { + final List suggestions = new ArrayList<>(); + + final IslandService islandService = IslandService.INSTANCE; + for (final Integer integer : islandService.getIntegerIslands()) { + suggestions.add(integer + ""); + } + System.out.println("CommandCompletion#islands: suggestions - " + suggestions); + + return suggestions; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/command/subcommand/HelpCommandGenerator.java b/src/main/java/io/tofpu/speedbridge2/command/subcommand/HelpCommandGenerator.java index 1a566002..7296c70f 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/subcommand/HelpCommandGenerator.java +++ b/src/main/java/io/tofpu/speedbridge2/command/subcommand/HelpCommandGenerator.java @@ -1,15 +1,19 @@ package io.tofpu.speedbridge2.command.subcommand; -import cloud.commandframework.annotations.CommandDescription; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.Hidden; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.object.extra.CommonBridgePlayer; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; +import revxrsal.commands.annotation.Description; +import revxrsal.commands.annotation.Flag; +import revxrsal.commands.annotation.Optional; +import revxrsal.commands.annotation.Subcommand; +import revxrsal.commands.annotation.Usage; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.List; @@ -21,7 +25,7 @@ public final class HelpCommandGenerator { private static final String HEADER = FIRST_CHARACTER + "<-> SpeedBridge V2"; - private static final String COMMAND_FORMAT = String.format(SUBTITLE, "/%s " + + private static final String COMMAND_FORMAT = String.format(SUBTITLE, "/sb %s %s" + "- %s"); private static Component helpMessageComponent = null; @@ -41,14 +45,15 @@ public static void generateHelpCommand(final @NotNull Plugin plugin) { messages.add(String.format(TITLE, "Commands")); for (final Method method : declaredMethods) { - final CommandMethod commandMethod = method.getAnnotation(CommandMethod.class); - final CommandDescription commandDescription = method.getAnnotation(CommandDescription.class); - if (commandMethod == null || method.isAnnotationPresent(Hidden.class)) { + final Subcommand commandMethod = method.getAnnotation(Subcommand.class); + final Description commandDescription = method.getAnnotation(Description.class); + if (commandMethod == null) { continue; } + final String usage = generateUsageOfMethod(commandMethod, method); - messages.add(String.format(COMMAND_FORMAT, commandMethod.value() - .replace("speedbridge|sb", "sb"), commandDescription.value())); + messages.add(String.format(COMMAND_FORMAT, commandMethod.value()[0], + usage, commandDescription.value())); } messages.add(""); @@ -67,6 +72,51 @@ public static void generateHelpCommand(final @NotNull Plugin plugin) { helpMessageComponent = BridgeUtil.translateMiniMessage(builder.toString()); } + public static String generateUsageOfMethod(final Subcommand subcommand, + final Method method) { + final StringBuilder builder = new StringBuilder(); + + if (method.isAnnotationPresent(Usage.class)) { + return method.getAnnotation(Usage.class).value().replace(subcommand.value()[0] + " ", "") + " "; + } + + for (final Parameter parameter : method.getParameters()) { + if (CommonBridgePlayer.class.isAssignableFrom(parameter.getType())) { + continue; + } + + if (builder.length() != 0) { + builder.append(" "); + } + + final String name; + switch (parameter.getType().getSimpleName()) { + case "Island": + name = "slot"; + break; + default: + name = parameter.getName(); + } + + String startingTag = "<"; + String closingTag = ">"; + if (parameter.isAnnotationPresent(Optional.class)) { + startingTag = "["; + closingTag = "]"; + } + + String flag = ""; + if (parameter.isAnnotationPresent(Flag.class)) { + final Flag flagAnnotation = parameter.getAnnotation(Flag.class); + flag = "-" + flagAnnotation.value() + " "; + } + + builder.append(startingTag).append(flag).append(name).append(closingTag).append(" "); + } + + return builder.toString(); + } + public static void showHelpMessage(final CommandSender sender) { BridgeUtil.sendMessage(sender, helpMessageComponent); } diff --git a/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java b/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java index 8bf1df2f..38813fc0 100644 --- a/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java +++ b/src/main/java/io/tofpu/speedbridge2/command/subcommand/SpeedBridgeCommand.java @@ -1,31 +1,34 @@ package io.tofpu.speedbridge2.command.subcommand; - -import cloud.commandframework.annotations.*; -import com.sk89q.minecraft.util.commands.CommandAlias; -import io.tofpu.speedbridge2.command.parser.IslandArgument; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.MessageUtil; -import io.tofpu.speedbridge2.domain.extra.blockmenu.BlockMenuManager; -import io.tofpu.speedbridge2.domain.island.IslandHandler; -import io.tofpu.speedbridge2.domain.island.IslandService; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.setup.IslandSetup; -import io.tofpu.speedbridge2.domain.island.setup.IslandSetupManager; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.CommonBridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.DummyBridgePlayer; +import io.tofpu.speedbridge2.command.condition.annotation.RestrictConsole; +import io.tofpu.speedbridge2.command.condition.annotation.RestrictDummyModel; +import io.tofpu.speedbridge2.command.condition.annotation.RestrictSetup; +import io.tofpu.speedbridge2.model.blockmenu.BlockMenuManager; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.IslandHandler; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.island.setup.IslandSetup; +import io.tofpu.speedbridge2.model.island.setup.IslandSetupManager; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.CommonBridgePlayer; import io.tofpu.speedbridge2.plugin.SpeedBridgePlugin; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.NotNull; +import revxrsal.commands.annotation.Command; +import revxrsal.commands.annotation.Default; +import revxrsal.commands.annotation.Description; +import revxrsal.commands.annotation.Flag; +import revxrsal.commands.annotation.Subcommand; +import revxrsal.commands.annotation.Usage; +import revxrsal.commands.bukkit.annotation.CommandPermission; import java.util.ArrayList; import java.util.List; @@ -34,223 +37,155 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import static io.tofpu.speedbridge2.domain.common.Message.INSTANCE; -import static io.tofpu.speedbridge2.domain.common.util.MessageUtil.Symbols.ARROW_RIGHT; -import static io.tofpu.speedbridge2.domain.common.util.MessageUtil.Symbols.CROSS; +import static io.tofpu.speedbridge2.model.common.Message.INSTANCE; +import static io.tofpu.speedbridge2.model.common.util.MessageUtil.Symbols.ARROW_RIGHT; +import static io.tofpu.speedbridge2.model.common.util.MessageUtil.Symbols.CROSS; +@Command({"sb", "speedbridge"}) public final class SpeedBridgeCommand { + private static final String EMPTY_SCORE = "You haven't scored anything yet"; + private static final String FORMATTED_SCORE = + " " + CROSS.getSymbol() + " " + "Island " + + "%s" + " " + ARROW_RIGHT.getSymbol() + + " %s seconds"; + private final IslandService islandService = IslandService.INSTANCE; - @CommandMethod("speedbridge|sb setlobby") - @CommandDescription("Sets the lobby location") + @Default + @Description("The Main Command") + public String defaultCommand() { + return INSTANCE.noArgument; + } + + @Subcommand("setlobby") + @Description("Sets the lobby location") @CommandPermission("speedbridge.lobby.set") + @RestrictSetup + @RestrictConsole public void onLobbySet(final BridgePlayer bridgePlayer) { - if (bridgePlayer.isInSetup()) { - BridgeUtil.sendMessage(bridgePlayer, INSTANCE.inASetup); - } - - ConfigurationManager.INSTANCE.getLobbyCategory().setLobbyLocation(bridgePlayer.getPlayer().getLocation()).whenComplete((unused, throwable) -> { - BridgeUtil.sendMessage(bridgePlayer, INSTANCE.lobbySetLocation); - }); + ConfigurationManager.INSTANCE.getLobbyCategory() + .setLobbyLocation(bridgePlayer.getPlayer() + .getLocation()) + .whenComplete((unused, throwable) -> { + BridgeUtil.sendMessage(bridgePlayer, INSTANCE.lobbySetLocation); + }); } - @CommandMethod("speedbridge|sb create ") - @CommandDescription("Create an island with a defined slot") + @Subcommand("create") + @Usage("create [-c category]") + @Description("Create an island") @CommandPermission("speedbridge.island.create") - public void onIslandCreate(final CommonBridgePlayer player, final @Argument("slot") - int slot, final @Argument("schematic") String schematic, - @Flag("c") String category) { - final CommandSender sender = player.getPlayer(); - + @RestrictSetup + @RestrictDummyModel + @RestrictConsole + public String onIslandCreate(final BridgePlayer player, final int slot, final String schematic, + @revxrsal.commands.annotation.Optional @Flag("c") String category) { if (category == null || category.isEmpty()) { category = ConfigurationManager.INSTANCE.getGeneralCategory() .getDefaultIslandCategory(); } final IslandHandler.IslandCreationResult result = islandService.createIsland(slot, category, schematic); - if (result == IslandHandler.IslandCreationResult.ISLAND_ALREADY_EXISTS) { - BridgeUtil.sendMessage(sender, String.format(INSTANCE.islandAlreadyExists, - slot + "")); - return; - } - - final String message; - if (result == IslandHandler.IslandCreationResult.UNKNOWN_SCHEMATIC) { - message = String.format(INSTANCE.unknownSchematic, schematic); - } else { - message = String.format(INSTANCE.islandHasBeenCreatedSchematic, - slot + "", schematic) + "\n" + INSTANCE.islandSetupNotification.replace("%slot%", slot + ""); - } - BridgeUtil.sendMessage(sender, message); - } + final IslandHandler.IslandCreationResultType resultType = result.getResult(); - @CommandMethod("speedbridge|sb delete ") - @CommandDescription("Delete an island") - @CommandPermission("speedbridge.island.delete") - public void onIslandDelete(final CommonBridgePlayer player, final @Argument( - "slot") int slot) { - final Island island = islandService.deleteIsland(slot); + BridgeUtil.debug("SpeedBridgeCommand#onIslandCreate(): resultType: " + resultType.name()); - final String message; - if (island == null) { - message = String.format(INSTANCE.invalidIsland, slot + ""); - } else { - message = String.format(INSTANCE.deletedAnIsland, slot); + if (resultType == IslandHandler.IslandCreationResultType.ISLAND_ALREADY_EXISTS) { + return String.format(INSTANCE.islandAlreadyExists, slot + ""); } - BridgeUtil.sendMessage(player, message); - } - - @CommandMethod("speedbridge|sb reset ") - @CommandDescription("Wipes the player's data") - @CommandPermission("speedbridge.player.reset") - public void onPlayerReset(final CommonBridgePlayer bridgePlayer, final @Argument("name") - String playerName) { - Bukkit.getScheduler() - .runTaskAsynchronously(JavaPlugin.getPlugin(SpeedBridgePlugin.class), () -> { - final CommandSender sender = bridgePlayer.getPlayer(); - if (sender == null) { - return; - } - - final UUID uuidResult = BridgeUtil.findUUIDBy(playerName); - if (uuidResult == null) { - BridgeUtil.sendMessage(bridgePlayer, String.format(INSTANCE.playerDoesntExist, playerName)); - return; - } - BridgePlayer target = PlayerService.INSTANCE.get(uuidResult); - if (target == null) { - try { - PlayerService.INSTANCE.loadAsync(uuidResult) - .get(); - } catch (InterruptedException | ExecutionException e) { - BridgeUtil.sendMessage(bridgePlayer, INSTANCE.somethingWentWrong); - throw new IllegalStateException(e); - } - } + if (resultType == IslandHandler.IslandCreationResultType.UNKNOWN_SCHEMATIC) { + return String.format(INSTANCE.unknownSchematic, schematic); + } - if (target == null) { - BridgeUtil.sendMessage(bridgePlayer, - String.format(INSTANCE.playerDoesntExist, playerName)); - return; - } + // initiate the creation setup process + IslandSetupManager.INSTANCE.initiate(player, result.getIsland()); - try { - target.reset() - .get(); - } catch (InterruptedException | ExecutionException e) { - BridgeUtil.sendMessage(bridgePlayer, INSTANCE.somethingWentWrong); - throw new IllegalStateException(e); - } + // notify the player about the setup + BridgeUtil.sendMessage(player, Message.INSTANCE.startingSetupProcess); - BridgeUtil.sendMessage(bridgePlayer, String.format(INSTANCE.playerWiped, playerName)); - }); + return String.format(INSTANCE.islandSetupNotification.replace("%slot%", + slot + "")); } - @CommandMethod("speedbridge|sb select ") - @CommandDescription("Select an island to modify their properties") - @CommandPermission("speedbridge.island.island.select") - public void onIslandSelect(final CommonBridgePlayer commonBridgePlayer, final @Argument("slot") - int slot, final @Flag(value = "c", description = "category") - String category, final @Flag(value = "s", description = "schematic") - String schematic) { - final CommandSender sender = commonBridgePlayer.getPlayer(); - final Island island = islandService.findIslandBy(slot); - - String message = INSTANCE.emptySelect; - boolean successful = false; - if (island == null) { - message = String.format(INSTANCE.invalidIsland, slot + ""); - } else { - String selectType = ""; - if (category != null && !category.isEmpty()) { - selectType = "category"; + @Subcommand("delete") + @Description("Delete an island") + @CommandPermission("speedbridge.island.delete") + public String onIslandDelete(final Island target) { + target.delete(); - island.setCategory(category); - } else if (schematic != null && !schematic.isEmpty()) { - selectType = "schematic"; + return String.format(INSTANCE.deletedAnIsland, target.getSlot()); + } - successful = island.selectSchematic(schematic); + @Subcommand("reset") + @Description("Wipes the player's data") + @CommandPermission("speedbridge.player.reset") + public void onPlayerReset(final CommonBridgePlayer bridgePlayer, final String name) { + BridgeUtil.runBukkitAsync(() -> { + final CommandSender sender = bridgePlayer.getPlayer(); + if (sender == null) { + return; } - switch (selectType) { - case "category": - message = String.format(INSTANCE.validSelect, - slot + "", category, selectType); - break; - case "schematic": - if (successful) { - message = String.format(INSTANCE.validSelect, - slot + "", schematic, selectType); - break; - } - message = String.format(INSTANCE.unknownSchematic, schematic); - break; + final UUID uuidResult = BridgeUtil.findUUIDBy(name); + if (uuidResult == null) { + BridgeUtil.sendMessage(bridgePlayer, String.format(INSTANCE.playerDoesntExist, name)); + return; } - } - - if (!message.isEmpty()) { - BridgeUtil.sendMessage(sender, message); - } - } - @ProxiedBy("join") - @CommandMethod("speedbridge|sb join [island]") - @CommandDescription("Join an island") - public void onIslandJoin(final BridgePlayer bridgePlayer, final @Argument("island") - String category) { - if (!isGeneralSetupComplete(bridgePlayer)) { - return; - } - if (isDummy(bridgePlayer)) { - return; - } + BridgePlayer target = PlayerService.INSTANCE.get(uuidResult); + if (target == null) { + try { + PlayerService.INSTANCE.loadAsync(uuidResult) + .get(); + } catch (InterruptedException | ExecutionException e) { + BridgeUtil.sendMessage(bridgePlayer, INSTANCE.somethingWentWrong); + throw new IllegalStateException(e); + } + } - if (bridgePlayer.isInSetup()) { - BridgeUtil.sendMessage(bridgePlayer, INSTANCE.inASetup); - return; - } + if (target == null) { + BridgeUtil.sendMessage(bridgePlayer, String.format(INSTANCE.playerDoesntExist, name)); + return; + } - // /join 2 - // /join default + try { + target.reset() + .get(); + } catch (InterruptedException | ExecutionException e) { + BridgeUtil.sendMessage(bridgePlayer, INSTANCE.somethingWentWrong); + throw new IllegalStateException(e); + } - // /randomjoin + BridgeUtil.sendMessage(bridgePlayer, String.format(INSTANCE.playerWiped, name)); + }); + } - int slot; - try { - slot = Integer.parseInt(category); - } catch (NumberFormatException exception) { - slot = -1; - } + @Subcommand("modify") + @Usage("modify [-c category|-s schematic]") + @Description("Modify an island properties") + @CommandPermission("speedbridge.island.modify") + public String onIslandSelect(final Island island, final @revxrsal.commands.annotation.Optional + @Flag(value = "c") @Default("") + String category, final @revxrsal.commands.annotation.Optional + @Flag(value = "s") @Default("") String schematic) { + final int slot = island.getSlot(); - Island island = null; - if (slot != -1) { - island = islandService.findIslandBy(slot); - } else if (category != null && !category.isEmpty()) { - island = islandService.findIslandBy(category); - } + if (!category.isEmpty()) { + island.setCategory(category); - if (island != null) { - slot = island.getSlot(); + return String.format(INSTANCE.validSelect, slot + "", category, "category"); } - final String message; - if (island == null || !island.isReady()) { - if (slot == -1) { - message = INSTANCE.invalidIslandArgument; - } else { - message = String.format(INSTANCE.invalidIsland, slot + ""); + if (!schematic.isEmpty()) { + if (island.selectSchematic(schematic)) { + return String.format(INSTANCE.validSelect, + slot + "", schematic, "schematic"); } - } else if (bridgePlayer.isPlaying()) { - message = INSTANCE.alreadyInAIsland; - } else { - message = String.format(INSTANCE.joinedAnIsland, slot + ""); - island.join(bridgePlayer); - } - if (!message.isEmpty()) { - BridgeUtil.sendMessage(bridgePlayer, message); + return String.format(INSTANCE.unknownSchematic, schematic); } + return INSTANCE.emptySelect; } private boolean isGeneralSetupComplete(final BridgePlayer bridgePlayer) { @@ -277,229 +212,192 @@ private boolean isGeneralSetupComplete(final BridgePlayer bridgePlayer) { return false; } - @ProxiedBy("leave") - @CommandMethod("speedbridge|sb leave") - @CommandDescription("Leave an island") - @IslandArgument - public void onIslandLeave(final BridgePlayer bridgePlayer, final @NotNull Island island) { - island.leaveGame(bridgePlayer); + @Command({"sb join", "speedbridge join" ,"join"}) + @Usage("join ") + @Description("Join an island") + @RestrictDummyModel + @RestrictConsole + public String onIslandJoin(final BridgePlayer bridgePlayer, final Island island) { + if (!isGeneralSetupComplete(bridgePlayer)) { + return ""; + } + + if (bridgePlayer.isPlaying()) { + return INSTANCE.alreadyInAIsland; + } + + if (!island.isReady()) { + return String.format(INSTANCE.invalidIsland, island.getSlot()); + } + + island.join(bridgePlayer); + return String.format(INSTANCE.joinedAnIsland, island.getSlot() + ""); + } + + @Command({"sb leave", "speedbridge leave" ,"leave"}) + @Description("Leave an island") + public void onIslandLeave(final GameIsland gameIsland) { + gameIsland.stopGame(); } - @ProxiedBy("score") - @CommandMethod("speedbridge|sb score") - @CommandAlias("speedbridge|sb score") - @CommandDescription("Shows a list of your scores") - public void onScore(final BridgePlayer bridgePlayer) { - final Player player = bridgePlayer.getPlayer(); + @Command({"sb score", "speedbridge score" ,"score"}) + @Description("Shows a list of your scores") + @RestrictConsole + public String onScore(final BridgePlayer bridgePlayer) { final List scoreList = new ArrayList<>(); - final String message; for (final Score score : bridgePlayer.getScores()) { if (scoreList.isEmpty()) { scoreList.add(INSTANCE.scoreTitle); } - // Your scores: - // Island X scored X seconds; - final String formattedScore = " " + CROSS.getSymbol() + " " + "Island " + "%s" + " " + ARROW_RIGHT - .getSymbol() + " %s seconds"; - scoreList.add(String.format(formattedScore, score.getScoredOn(), BridgeUtil.formatNumber(score - .getScore()))); + + scoreList.add(String.format(FORMATTED_SCORE, score.getScoredOn(), BridgeUtil.formatNumber(score.getScore()))); } if (scoreList.isEmpty()) { - message = "You haven't scored anything yet"; - } else { - scoreList.add(MessageUtil.MENU_BAR); - - message = String.join("\n", scoreList); + return EMPTY_SCORE; } - BridgeUtil.sendMessage(player, message); + scoreList.add("\n"); + return String.join("\n", scoreList); } - @ProxiedBy("choose") - @CommandMethod("speedbridge|sb choose") - @CommandAlias("speedbridge|sb choose") - @CommandDescription("Lets you choose a block") + @Command({"sb choose", "speedbridge choose" ,"choose"}) + @Description("Lets you choose a block") + @RestrictDummyModel + @RestrictConsole public void chooseBlock(final BridgePlayer bridgePlayer) { - if (isDummy(bridgePlayer)) { - return; - } - BlockMenuManager.INSTANCE.showInventory(bridgePlayer); } - @CommandMethod("speedbridge|sb reload") - @CommandDescription("Reloads the config") + @Subcommand("reload") + @Description("Reloads the config") @CommandPermission("speedbridge.reload") public void pluginReload(final CommonBridgePlayer player) { final CompletableFuture[] completableFutures = new CompletableFuture[2]; - completableFutures[0] = Message.load(SpeedBridgePlugin.getPlugin(SpeedBridgePlugin.class).getDataFolder()); + completableFutures[0] = Message.load(SpeedBridgePlugin.getPlugin(SpeedBridgePlugin.class) + .getDataFolder()); completableFutures[1] = ConfigurationManager.INSTANCE.reload(); - CompletableFuture.allOf(completableFutures).whenComplete((unused, throwable) -> { - // reloading the blocks - BlockMenuManager.INSTANCE.reload(); - - if (player.getPlayer() != null) { - BridgeUtil.sendMessage(player, INSTANCE.reloaded); - } - }); - } + CompletableFuture.allOf(completableFutures) + .whenComplete((unused, throwable) -> { + // reloading the blocks + BlockMenuManager.INSTANCE.reload(); - @CommandMethod("speedbridge|sb") - @CommandDescription("Shows a list of commands") - @Hidden - public void onNoArgument(final CommonBridgePlayer bridgePlayer) { - final CommandSender player = bridgePlayer.getPlayer(); - BridgeUtil.sendMessage(player, INSTANCE.noArgument); + if (player.getPlayer() != null) { + BridgeUtil.sendMessage(player, INSTANCE.reloaded); + } + }); } - @CommandMethod("speedbridge|sb help") + @Subcommand("help") @CommandPermission("speedbridge.help") - @CommandDescription("Shows a list of commands") + @Description("Shows a list of commands") public void onHelpCommand(final CommonBridgePlayer bridgePlayer) { final CommandSender player = bridgePlayer.getPlayer(); HelpCommandGenerator.showHelpMessage(player); } - @ProxiedBy("randomjoin") - @CommandMethod("speedbridge|sb randomjoin") - @CommandDescription("Chooses a random island for you") - public void onRandomJoin(final BridgePlayer bridgePlayer) { + @Command({"sb randomjoin", "speedbridge randomjoin" ,"randomjoin"}) + @Description("Chooses a random island for you") + @RestrictSetup + @RestrictDummyModel + @RestrictConsole + public String onRandomJoin(final BridgePlayer bridgePlayer) { if (!isGeneralSetupComplete(bridgePlayer)) { - return; + return ""; } - if (isDummy(bridgePlayer)) { - return; + + if (bridgePlayer.isPlaying()) { + return INSTANCE.alreadyInAIsland; } - final String message; - if (bridgePlayer.isInSetup()) { - message = INSTANCE.inASetup; - } else if (bridgePlayer.isPlaying()) { - message = INSTANCE.alreadyInAIsland; - } else { - final Optional optionalIsland = islandService.getAllIslands() - .stream() - .parallel() - .filter(Island::isReady) - .findAny(); - - if (!optionalIsland.isPresent()) { - message = INSTANCE.noAvailableIsland; - } else { - final Island island = optionalIsland.get(); - island.join(bridgePlayer); - - message = String.format(INSTANCE.joinedAnIsland, island.getSlot() + ""); - } + final Optional optionalIsland = islandService.getAllIslands() + .stream() + .parallel() + .filter(Island::isReady) + .findAny(); + + if (!optionalIsland.isPresent()) { + return INSTANCE.noAvailableIsland; } - BridgeUtil.sendMessage(bridgePlayer, message); + final Island island = optionalIsland.get(); + island.join(bridgePlayer); + + return String.format(INSTANCE.joinedAnIsland, island.getSlot() + ""); } - @CommandMethod("speedbridge|sb setup ") - @CommandDescription("Creates an island setup") + @Subcommand("setup") + @Description("Create an island setup") @CommandPermission("speedbridge.setup.admin") - public void onStartSetup(final BridgePlayer bridgePlayer, - final @Argument("slot") int slot) { + @RestrictDummyModel + @RestrictSetup + @RestrictConsole + @Default + public String onStartSetup(final BridgePlayer bridgePlayer, final Island island) { if (!isGeneralSetupComplete(bridgePlayer)) { - return; + return ""; } - if (isDummy(bridgePlayer)) { - return; - } - - final Island island = IslandService.INSTANCE.findIslandBy(slot); + final int slot = island.getSlot(); - final String message; if (bridgePlayer.isPlaying()) { - message = INSTANCE.inAGame; + return INSTANCE.inAGame; } else if (island == null) { - message = String.format(INSTANCE.invalidIsland, slot); - } else { - if (bridgePlayer.isInSetup()) { - message = INSTANCE.inASetup; - } else { - message = String.format(INSTANCE.startingSetupProcess, slot); - IslandSetupManager.INSTANCE.startSetup(bridgePlayer, island); - } + return String.format(INSTANCE.invalidIsland, slot); } - BridgeUtil.sendMessage(bridgePlayer, message); - } - - @CommandMethod("speedbridge|sb setup setspawn") - @CommandDescription("Sets the island's spawnpoint") - @CommandPermission("speedbridge.setup.admin") - public void setupSetSpawn(final BridgePlayer bridgePlayer) { - final IslandSetup islandSetup = - IslandSetupManager.INSTANCE.findSetupBy(bridgePlayer.getPlayerUid()); - final String message; - if (!bridgePlayer.isInSetup()) { - message = INSTANCE.notInASetup; - } else { - final Location playerLocation = bridgePlayer.getPlayer() - .getLocation(); - - // if the location given was not valid - if (!islandSetup.isLocationValid(playerLocation)) { - message = INSTANCE.invalidSpawnPoint; - } else { - // otherwise, set the location point - message = - INSTANCE.setSpawnPoint + "\n" + INSTANCE.completeNotification; - - islandSetup.setPlayerSpawnPoint(playerLocation); - } - } - BridgeUtil.sendMessage(bridgePlayer, message); + IslandSetupManager.INSTANCE.initiate(bridgePlayer, island); + return String.format(INSTANCE.startingSetupProcess, slot); } - @CommandMethod("speedbridge|sb setup finish") - @CommandDescription("Completes the island's setup") + @Subcommand("setup setspawn") + @Description("Sets the island's spawnpoint") @CommandPermission("speedbridge.setup.admin") - public void setupFinish(final BridgePlayer bridgePlayer) { + @RestrictSetup(opposite = true) + @RestrictConsole + public String setupSetSpawn(final BridgePlayer bridgePlayer) { final IslandSetup islandSetup = IslandSetupManager.INSTANCE.findSetupBy(bridgePlayer.getPlayerUid()); - final String message; - if (!bridgePlayer.isInSetup()) { - message = INSTANCE.notInASetup; - } else if (!islandSetup.isReady()) { - message = INSTANCE.setupIncomplete; - } else { - message = INSTANCE.setupComplete; - islandSetup.finish(); + final Location playerLocation = bridgePlayer.getPlayer() + .getLocation(); + + // if the location given was not valid + if (!islandSetup.isLocationValid(playerLocation)) { + return INSTANCE.invalidSpawnPoint; } - BridgeUtil.sendMessage(bridgePlayer, message); + // otherwise, set the location point + islandSetup.setPlayerSpawnPoint(playerLocation); + + return INSTANCE.setSpawnPoint + "\n" + INSTANCE.completeNotification; } - @CommandMethod("speedbridge|sb setup cancel") - @CommandDescription("Cancels the island's setup") + @Subcommand("setup finish") + @Description("Completes the island's setup") @CommandPermission("speedbridge.setup.admin") - public void cancelSetup(final BridgePlayer bridgePlayer) { + @RestrictSetup(opposite = true) + @RestrictConsole + public String setupFinish(final BridgePlayer bridgePlayer) { final IslandSetup islandSetup = IslandSetupManager.INSTANCE.findSetupBy(bridgePlayer.getPlayerUid()); - final String message; - if (!bridgePlayer.isInSetup()) { - message = INSTANCE.notInASetup; - } else { - message = INSTANCE.setupCancelled; - - islandSetup.cancel(); + if (!islandSetup.isReady()) { + return INSTANCE.setupIncomplete; } - BridgeUtil.sendMessage(bridgePlayer, message); + islandSetup.finish(); + return INSTANCE.setupComplete; } - private boolean isDummy(final BridgePlayer bridgePlayer) { - final boolean dummy = bridgePlayer instanceof DummyBridgePlayer; + @Subcommand("setup cancel") + @Description("Cancels the island's setup") + @CommandPermission("speedbridge.setup.admin") + @RestrictSetup(opposite = true) + @RestrictConsole + public String cancelSetup(final BridgePlayer bridgePlayer) { + final IslandSetup islandSetup = IslandSetupManager.INSTANCE.findSetupBy(bridgePlayer.getPlayerUid()); - if (dummy) { - BridgeUtil.sendMessage(bridgePlayer, INSTANCE.notLoaded); - } - return dummy; + islandSetup.cancel(); + return INSTANCE.setupCancelled; } } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/manager/ConfigurationManager.java b/src/main/java/io/tofpu/speedbridge2/domain/common/config/manager/ConfigurationManager.java deleted file mode 100644 index 33fde683..00000000 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/manager/ConfigurationManager.java +++ /dev/null @@ -1,137 +0,0 @@ -package io.tofpu.speedbridge2.domain.common.config.manager; - -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.config.PluginConfiguration; -import io.tofpu.speedbridge2.domain.common.config.category.BlockMenuCategory; -import io.tofpu.speedbridge2.domain.common.config.category.GeneralCategory; -import io.tofpu.speedbridge2.domain.common.config.category.LeaderboardCategory; -import io.tofpu.speedbridge2.domain.common.config.category.LobbyCategory; -import io.tofpu.speedbridge2.domain.common.config.serializer.LocationSerializer; -import io.tofpu.speedbridge2.domain.common.config.serializer.MaterialSerializer; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.plugin.Plugin; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.ConfigurateException; -import org.spongepowered.configurate.hocon.HoconConfigurationLoader; -import org.spongepowered.configurate.serialize.SerializationException; - -import java.util.concurrent.CompletableFuture; - -public final class ConfigurationManager { - public static final ConfigurationManager INSTANCE = new ConfigurationManager(); - - private HoconConfigurationLoader loader; - private CommentedConfigurationNode node; - private PluginConfiguration configuration; - - private Plugin plugin; - - private ConfigurationManager() {} - - public void load(final Plugin plugin) { - this.plugin = plugin; - - this.loader = HoconConfigurationLoader.builder() - .path(plugin.getDataFolder() - .toPath() - .resolve("config.conf")) - .defaultOptions(configurationOptions -> configurationOptions.shouldCopyDefaults(true) - .serializers(builder -> builder.register(Location.class, - LocationSerializer.INSTANCE).register(Material.class, - MaterialSerializer.INSTANCE))) - .build(); - - try { - this.node = loader.load(); - } catch (ConfigurateException e) { - plugin.getLogger() - .warning("An error occurred while loading this configuration:" + " " + - e.getMessage()); - if (e.getCause() != null) { - e.printStackTrace(); - } - return; - } - - try { - this.configuration = node.get(PluginConfiguration.class); - } catch (SerializationException e) { - plugin.getLogger() - .warning("An error occurred while converting MyConfiguration: " + - e.getMessage()); - if (e.getCause() != null) { - e.printStackTrace(); - } - } - - // in-case the file doesn't exist, this will generate one for us - this.save(); - } - - public CompletableFuture reload() { - return CompletableFuture.runAsync(() -> { - try { - this.node = loader.load(); - this.configuration = node.get(PluginConfiguration.class); - } catch (ConfigurateException e) { - plugin.getLogger() - .warning("An error occurred while converting MyConfiguration: " + - e.getMessage()); - if (e.getCause() != null) { - e.printStackTrace(); - } - } - }); - } - - public void save() { - if (this.node == null) { - plugin.getLogger() - .warning("Configuration cannot be saved due to the node " + - "being null"); - return; - } - try { - this.loader.save(node); - } catch (ConfigurateException e) { - plugin.getLogger() - .warning("An error occurred while saving this configuration: " + - e.getMessage()); - if (e.getCause() != null) { - e.printStackTrace(); - } - } - } - - public GeneralCategory getGeneralCategory() { - return configuration.getGeneralCategory(); - } - - public LeaderboardCategory getLeaderboardCategory() { - return configuration.getLeaderboardCategory(); - } - - public BlockMenuCategory getBlockMenuCategory() { - return configuration.getBlockMenuCategory(); - } - - public LobbyCategory getLobbyCategory() { - return configuration.getLobbyCategory(); - } - - public PluginConfiguration getConfiguration() { - return configuration; - } - - public CompletableFuture update() { - return PluginExecutor.runAsync(() -> { - try { - node.set(PluginConfiguration.class, configuration); - loader.save(node); - } catch (ConfigurateException e) { - e.printStackTrace(); - } - }); - } -} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandHandler.java b/src/main/java/io/tofpu/speedbridge2/domain/island/IslandHandler.java deleted file mode 100644 index 9e512402..00000000 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandHandler.java +++ /dev/null @@ -1,126 +0,0 @@ -package io.tofpu.speedbridge2.domain.island; - -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.IslandBoard; -import io.tofpu.speedbridge2.domain.island.schematic.SchematicManager; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public final class IslandHandler { - private final @NotNull Map islands = new HashMap<>(); - - /** - * Loads the islands from the map of islands - * - * @param loadedIslands A map of island ids to island objects. - */ - public void load(final @NotNull Map loadedIslands) { - for (final Island island : loadedIslands.values()) { - IslandBoard.add(island); - } - this.islands.putAll(loadedIslands); - } - - public @NotNull IslandCreationResult createIsland(final int slot, - final @NotNull String category) { - return createIsland(slot, category, ""); - } - - /** - * If the island doesn't exist, create it - * - * @param slot The island's slot. - * @param category The category of the island. - * @param schematic The name of the schematic to load. If it's empty, the island will be - * empty. - * @return The IslandCreationResult enum. - */ - public @NotNull IslandCreationResult createIsland(final int slot, - final @NotNull String category, - final String schematic) { - final Island island = new Island(slot, category); - - // if the schematic is not empty, and it doesn't exist, return UNKNOWN_SCHEMATIC! - if (!schematic.isEmpty() && !island.selectSchematic(schematic)) { - return IslandCreationResult.UNKNOWN_SCHEMATIC; - } - final Island previousIsland = this.islands.putIfAbsent(slot, island); - - // if the island didn't exist beforehand, insert the object - if (previousIsland == null) { - Databases.ISLAND_DATABASE.insert(island); - IslandBoard.add(island); - - return IslandCreationResult.SUCCESS; - } else { - // otherwise, return ISLAND_ALREADY_EXISTS - return IslandCreationResult.ISLAND_ALREADY_EXISTS; - } - } - - /** - * Return the island at the given slot. - * - * @param slot The slot number of the island. - * @return The Island object that is stored in the slot that is passed in. - */ - public @Nullable Island findIslandBy(final int slot) { - return this.islands.get(slot); - } - - /** - * Find an island by its category. - * - * @param category The category of the island to find. - * @return The Island object that matches the category. - */ - public @Nullable Island findIslandBy(final String category) { - for (final Island island : this.islands.values()) { - if (island.getCategory().equals(category)) { - return island; - } - } - return null; - } - - /** - * This function deletes an island from the database and removes it from the island board - * - * @param slot The slot of the island you want to delete. - * @return The Island that was deleted. - */ - public @Nullable Island deleteIsland(final int slot) { - final Island island = this.islands.remove(slot); - - // if the island is not null, wipe said island & return deleted island! - if (island != null) { - Databases.ISLAND_DATABASE.delete(slot); - IslandBoard.remove(island); - - SchematicManager.INSTANCE.clearPlot(slot); - - return island; - } - return null; - } - - /** - * Return a collection of all the islands in the map - * - * @return The unmodifiable collection of all the islands in the world. - */ - public @NotNull Collection getIslands() { - return Collections.unmodifiableCollection(this.islands.values()); - } - - // This is a Java enum. It's a way to create a set of constants. - public enum IslandCreationResult { - UNKNOWN_SCHEMATIC, ISLAND_ALREADY_EXISTS, SUCCESS - } -} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/IslandSchematic.java b/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/IslandSchematic.java deleted file mode 100644 index e44bfa2a..00000000 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/IslandSchematic.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.tofpu.speedbridge2.domain.island.schematic; - -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import io.tofpu.multiworldedit.MultiWorldEditAPI; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import org.bukkit.Bukkit; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.nio.file.Path; - -public class IslandSchematic { - private static final String[] SCHEMATIC_TYPES = {"schematic", "schem"}; - - private @Nullable String schematicName = ""; - private @Nullable Clipboard schematicClipboard; - - public IslandSchematic() {} - - public boolean selectSchematic(final @NotNull String schematicName) { - final File directory = Bukkit.getPluginManager() - .getPlugin("WorldEdit") - .getDataFolder() - .toPath() - .resolve("schematics") - .toFile(); - - BridgeUtil.debug("worldedit's directory: " + directory); - - final File file = findSchematicFile(directory, schematicName); - if (file != null && file.exists()) { - this.schematicClipboard = MultiWorldEditAPI.getMultiWorldEdit() - .read(file); - - BridgeUtil.debug("successfully set the island's schematic"); - - this.schematicName = schematicName; - return true; - } else { - BridgeUtil.debug(schematicName + " cannot be found as a schematic"); - } - return false; - } - - private File findSchematicFile(final @NotNull File directory, final @NotNull String name) { - final Path directoryPath = directory.toPath(); - File file = null; - for (final String schematicType : SCHEMATIC_TYPES) { - file = directoryPath.resolve(name + "." + schematicType) - .toFile(); - - if (file.exists()) { - break; - } - } - return file; - } - - public @Nullable String getSchematicName() { - return schematicName; - } - - public @Nullable Clipboard getSchematicClipboard() { - return this.schematicClipboard; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("IslandSchematic{"); - sb.append("schematicName='").append(schematicName).append('\''); - sb.append(", schematicClipboard=").append(schematicClipboard); - sb.append('}'); - return sb.toString(); - } -} diff --git a/src/main/java/io/tofpu/speedbridge2/listener/game/GameInteractionListener.java b/src/main/java/io/tofpu/speedbridge2/listener/game/GameInteractionListener.java index e974f169..d6038a3c 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/game/GameInteractionListener.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/game/GameInteractionListener.java @@ -1,14 +1,14 @@ package io.tofpu.speedbridge2.listener.game; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStatType; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStatType; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; import io.tofpu.speedbridge2.listener.GameListener; import io.tofpu.speedbridge2.listener.wrapper.wrappers.BlockPlaceEventWrapper; import io.tofpu.speedbridge2.listener.wrapper.wrappers.PlayerInteractEventWrapper; @@ -48,7 +48,7 @@ private void whenPlayerScore(final @NotNull PlayerInteractEventWrapper eventWrap final long startedAt = player.getTimer(); final double seconds = BridgeUtil.nanoToSeconds(startedAt); - final Score score = new Score(island.getSlot(), seconds); + final Score score = Score.of(island.getSlot(), seconds); player.setScoreIfLower(island.getSlot(), score.getScore()); player.increment(PlayerStatType.TOTAL_WINS); diff --git a/src/main/java/io/tofpu/speedbridge2/listener/game/GameProtectionListener.java b/src/main/java/io/tofpu/speedbridge2/listener/game/GameProtectionListener.java index d4584c21..3e385c44 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/game/GameProtectionListener.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/game/GameProtectionListener.java @@ -1,8 +1,8 @@ package io.tofpu.speedbridge2.listener.game; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.PlayerService; import io.tofpu.speedbridge2.listener.GameListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java b/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java index b952e54d..44abb26c 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/general/PlayerConnectionListener.java @@ -1,12 +1,12 @@ package io.tofpu.speedbridge2.listener.general; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.config.category.LobbyCategory; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.UpdateChecker; -import io.tofpu.speedbridge2.domain.player.PlayerService; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.config.category.LobbyCategory; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.UpdateChecker; +import io.tofpu.speedbridge2.model.player.PlayerService; import io.tofpu.speedbridge2.listener.GameListener; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/island/IslandProtectionListener.java b/src/main/java/io/tofpu/speedbridge2/listener/island/IslandProtectionListener.java index 262cd563..9a04c46a 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/island/IslandProtectionListener.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/island/IslandProtectionListener.java @@ -1,13 +1,13 @@ package io.tofpu.speedbridge2.listener.island; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; import io.tofpu.speedbridge2.listener.GameListener; import io.tofpu.speedbridge2.listener.wrapper.wrappers.BlockBreakEventWrapper; import io.tofpu.speedbridge2.listener.wrapper.wrappers.BlockPlaceEventWrapper; -import io.tofpu.speedbridge2.support.worldedit.CuboidRegion; -import io.tofpu.speedbridge2.support.worldedit.Vector; +import io.tofpu.speedbridge2.model.support.worldedit.CuboidRegion; +import io.tofpu.speedbridge2.model.support.worldedit.Vector; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/island/IslandRegionListener.java b/src/main/java/io/tofpu/speedbridge2/listener/island/IslandRegionListener.java index aa1e4f74..75e65c1e 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/island/IslandRegionListener.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/island/IslandRegionListener.java @@ -1,12 +1,12 @@ package io.tofpu.speedbridge2.listener.island; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import io.tofpu.speedbridge2.listener.GameListener; -import io.tofpu.speedbridge2.support.worldedit.CuboidRegion; -import io.tofpu.speedbridge2.support.worldedit.Vector; +import io.tofpu.speedbridge2.model.support.worldedit.CuboidRegion; +import io.tofpu.speedbridge2.model.support.worldedit.Vector; import org.bukkit.Location; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerMoveEvent; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/EventWrapper.java b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/EventWrapper.java index 43eb0071..34d513bd 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/EventWrapper.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/EventWrapper.java @@ -1,8 +1,8 @@ package io.tofpu.speedbridge2.listener.wrapper; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockBreakEventWrapper.java b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockBreakEventWrapper.java index 6d93e6dc..ffb2d337 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockBreakEventWrapper.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockBreakEventWrapper.java @@ -1,6 +1,6 @@ package io.tofpu.speedbridge2.listener.wrapper.wrappers; -import io.tofpu.speedbridge2.domain.player.PlayerService; +import io.tofpu.speedbridge2.model.player.PlayerService; import io.tofpu.speedbridge2.listener.wrapper.EventWrapper; import org.bukkit.event.block.BlockBreakEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockPlaceEventWrapper.java b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockPlaceEventWrapper.java index cc59f82d..90117f57 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockPlaceEventWrapper.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/BlockPlaceEventWrapper.java @@ -1,6 +1,6 @@ package io.tofpu.speedbridge2.listener.wrapper.wrappers; -import io.tofpu.speedbridge2.domain.player.PlayerService; +import io.tofpu.speedbridge2.model.player.PlayerService; import io.tofpu.speedbridge2.listener.wrapper.EventWrapper; import org.bukkit.event.block.BlockPlaceEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/PlayerInteractEventWrapper.java b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/PlayerInteractEventWrapper.java index 8b16efd2..1a208d86 100644 --- a/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/PlayerInteractEventWrapper.java +++ b/src/main/java/io/tofpu/speedbridge2/listener/wrapper/wrappers/PlayerInteractEventWrapper.java @@ -1,6 +1,6 @@ package io.tofpu.speedbridge2.listener.wrapper.wrappers; -import io.tofpu.speedbridge2.domain.player.PlayerService; +import io.tofpu.speedbridge2.model.player.PlayerService; import io.tofpu.speedbridge2.listener.wrapper.EventWrapper; import org.bukkit.event.player.PlayerInteractEvent; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/BlockMenuManager.java b/src/main/java/io/tofpu/speedbridge2/model/blockmenu/BlockMenuManager.java similarity index 93% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/BlockMenuManager.java rename to src/main/java/io/tofpu/speedbridge2/model/blockmenu/BlockMenuManager.java index ca0335b2..498e475c 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/BlockMenuManager.java +++ b/src/main/java/io/tofpu/speedbridge2/model/blockmenu/BlockMenuManager.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.domain.extra.blockmenu; +package io.tofpu.speedbridge2.model.blockmenu; -import io.tofpu.speedbridge2.domain.extra.blockmenu.holder.BlockMenuHolder; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.blockmenu.holder.BlockMenuHolder; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/holder/BlockMenuHolder.java b/src/main/java/io/tofpu/speedbridge2/model/blockmenu/holder/BlockMenuHolder.java similarity index 90% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/holder/BlockMenuHolder.java rename to src/main/java/io/tofpu/speedbridge2/model/blockmenu/holder/BlockMenuHolder.java index 7713cb34..53f532e1 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/holder/BlockMenuHolder.java +++ b/src/main/java/io/tofpu/speedbridge2/model/blockmenu/holder/BlockMenuHolder.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.extra.blockmenu.holder; +package io.tofpu.speedbridge2.model.blockmenu.holder; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryType; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/listener/BlockMenuListener.java b/src/main/java/io/tofpu/speedbridge2/model/blockmenu/listener/BlockMenuListener.java similarity index 79% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/listener/BlockMenuListener.java rename to src/main/java/io/tofpu/speedbridge2/model/blockmenu/listener/BlockMenuListener.java index ffc371a7..28b584e3 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/blockmenu/listener/BlockMenuListener.java +++ b/src/main/java/io/tofpu/speedbridge2/model/blockmenu/listener/BlockMenuListener.java @@ -1,10 +1,10 @@ -package io.tofpu.speedbridge2.domain.extra.blockmenu.listener; +package io.tofpu.speedbridge2.model.blockmenu.listener; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.extra.blockmenu.BlockMenuManager; -import io.tofpu.speedbridge2.domain.extra.blockmenu.holder.BlockMenuHolder; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.blockmenu.BlockMenuManager; +import io.tofpu.speedbridge2.model.blockmenu.holder.BlockMenuHolder; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import io.tofpu.speedbridge2.listener.GameListener; import org.bukkit.Material; import org.bukkit.event.EventHandler; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/Message.java b/src/main/java/io/tofpu/speedbridge2/model/common/Message.java similarity index 97% rename from src/main/java/io/tofpu/speedbridge2/domain/common/Message.java rename to src/main/java/io/tofpu/speedbridge2/model/common/Message.java index 7d52d7fb..39bda5df 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/Message.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/Message.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common; +package io.tofpu.speedbridge2.model.common; -import io.tofpu.speedbridge2.domain.common.util.*; +import io.tofpu.speedbridge2.model.common.util.*; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -37,10 +37,10 @@ public final class Message { "information."; public final String islandAlreadyExists = error + "Island %s already exists!"; public final String islandHasBeenCreatedSchematic = - SUCCESS + "Island %s has been created with '%s' chosen as a " + "schematic!"; + SUCCESS + "Island %s has been created with '%s' chosen as the " + + "schematic!"; public final String islandSetupNotification = - SUCCESS + "You can complete your %slot% island setup by running " + - runCommand("/sb setup %slot%") + ", and setting up the spawn point."; + SUCCESS + "You can complete your %slot% island setup by setting up the spawn point."; public final String validSelect = SUCCESS + "Island %s has selected" + " \"%s\" " + "as a " + "%s!"; public final String unknownSchematic = error + "Schematic \"%s\" cannot be found"; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/PlayerNameCache.java b/src/main/java/io/tofpu/speedbridge2/model/common/PlayerNameCache.java similarity index 95% rename from src/main/java/io/tofpu/speedbridge2/domain/common/PlayerNameCache.java rename to src/main/java/io/tofpu/speedbridge2/model/common/PlayerNameCache.java index 43bb47ac..c594590e 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/PlayerNameCache.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/PlayerNameCache.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common; +package io.tofpu.speedbridge2.model.common; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/PluginExecutor.java b/src/main/java/io/tofpu/speedbridge2/model/common/PluginExecutor.java similarity index 96% rename from src/main/java/io/tofpu/speedbridge2/domain/common/PluginExecutor.java rename to src/main/java/io/tofpu/speedbridge2/model/common/PluginExecutor.java index 2e9a7de6..e4697c27 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/PluginExecutor.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/PluginExecutor.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common; +package io.tofpu.speedbridge2.model.common; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/ItemConfiguration.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/ItemConfiguration.java new file mode 100644 index 00000000..89aecf3b --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/ItemConfiguration.java @@ -0,0 +1,15 @@ +package io.tofpu.speedbridge2.model.common.config; + +import io.tofpu.speedbridge2.model.common.config.category.GameCategory; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Setting; + +@ConfigSerializable +public final class ItemConfiguration { + @Setting("join-game") + private final GameCategory gameCategory = new GameCategory(); + + public GameCategory getGameCategory() { + return gameCategory; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/PluginConfiguration.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/PluginConfiguration.java similarity index 72% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/PluginConfiguration.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/PluginConfiguration.java index 8bbaf9a8..4d63d5e7 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/PluginConfiguration.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/PluginConfiguration.java @@ -1,9 +1,6 @@ -package io.tofpu.speedbridge2.domain.common.config; +package io.tofpu.speedbridge2.model.common.config; -import io.tofpu.speedbridge2.domain.common.config.category.BlockMenuCategory; -import io.tofpu.speedbridge2.domain.common.config.category.GeneralCategory; -import io.tofpu.speedbridge2.domain.common.config.category.LeaderboardCategory; -import io.tofpu.speedbridge2.domain.common.config.category.LobbyCategory; +import io.tofpu.speedbridge2.model.common.config.category.*; import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.meta.Setting; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/BlockMenuCategory.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/BlockMenuCategory.java similarity index 94% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/category/BlockMenuCategory.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/category/BlockMenuCategory.java index 84637491..ac6d04d7 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/BlockMenuCategory.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/BlockMenuCategory.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.config.category; +package io.tofpu.speedbridge2.model.common.config.category; import com.cryptomorin.xseries.XMaterial; import org.bukkit.Material; diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/category/GameCategory.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/GameCategory.java new file mode 100644 index 00000000..6d6406d8 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/GameCategory.java @@ -0,0 +1,32 @@ +package io.tofpu.speedbridge2.model.common.config.category; + +import com.cryptomorin.xseries.XMaterial; +import io.tofpu.speedbridge2.model.common.umbrella.RunCommandItemAction; +import io.tofpu.speedbridge2.model.common.umbrella.SerializableUmbrellaItem; +import io.tofpu.speedbridge2.model.common.util.UmbrellaUtil; +import org.bukkit.inventory.ItemStack; +import org.spongepowered.configurate.objectmapping.ConfigSerializable; +import org.spongepowered.configurate.objectmapping.meta.Setting; + +import java.util.ArrayList; +import java.util.List; + +@ConfigSerializable +public final class GameCategory { + @Setting("items") + private List umbrellaItems = new ArrayList<>() {{ + final ItemStack resetItem = UmbrellaUtil.create(XMaterial.RED_DYE, "Reset", "reset the game!"); + final ItemStack leaveItem = UmbrellaUtil.create(XMaterial.RED_BED, "Leave", "leave the game!"); + + add(createDefault("reset", resetItem, 7, "RESET_ISLAND")); + add(createDefault("leave", leaveItem, 8, "sb leave")); + }}; + + public List getUmbrellaItems() { + return umbrellaItems; + } + + SerializableUmbrellaItem createDefault(final String itemIdentifier, final ItemStack item, final int index, final String command) { + return new SerializableUmbrellaItem(itemIdentifier, index, item, new RunCommandItemAction(command, null)); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/GeneralCategory.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/GeneralCategory.java similarity index 92% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/category/GeneralCategory.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/category/GeneralCategory.java index 214fbf30..205a84f0 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/GeneralCategory.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/GeneralCategory.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.config.category; +package io.tofpu.speedbridge2.model.common.config.category; import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.meta.Comment; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/LeaderboardCategory.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/LeaderboardCategory.java similarity index 94% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/category/LeaderboardCategory.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/category/LeaderboardCategory.java index e0d1e651..b3f599ff 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/LeaderboardCategory.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/LeaderboardCategory.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.config.category; +package io.tofpu.speedbridge2.model.common.config.category; import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.meta.Comment; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/LobbyCategory.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/LobbyCategory.java similarity index 89% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/category/LobbyCategory.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/category/LobbyCategory.java index b8250f9e..77520d99 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/category/LobbyCategory.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/category/LobbyCategory.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common.config.category; +package io.tofpu.speedbridge2.model.common.config.category; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; import org.bukkit.Location; import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.meta.Comment; diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/manager/ConfigurationManager.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/manager/ConfigurationManager.java new file mode 100644 index 00000000..283a225a --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/manager/ConfigurationManager.java @@ -0,0 +1,93 @@ +package io.tofpu.speedbridge2.model.common.config.manager; + +import com.google.common.io.Files; +import io.tofpu.speedbridge2.model.common.config.ItemConfiguration; +import io.tofpu.speedbridge2.model.common.config.PluginConfiguration; +import io.tofpu.speedbridge2.model.common.config.category.*; +import io.tofpu.speedbridge2.model.common.wrapper.ConfigurateFile; +import io.tofpu.speedbridge2.model.common.wrapper.FileConfigurationType; +import org.bukkit.plugin.Plugin; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.CompletableFuture; + +public final class ConfigurationManager { + public static final ConfigurationManager INSTANCE = new ConfigurationManager(); + + private ConfigurateFile pluginConfiguration; + private ConfigurateFile itemConfiguration; + + private ConfigurationManager() { + // preventing direct initialization of ConfigurationManager + } + + public void load(final Plugin plugin) { + final File directory = new File(plugin.getDataFolder(), "configurations"); + if (!directory.exists()) { + directory.mkdir(); + } + + // if the server used a version anything lower + // than 1.0.8, then the migration process will be executed + oldConfigMigration(plugin.getDataFolder(), directory); + + this.pluginConfiguration = new ConfigurateFile<>(plugin, directory, "config.conf"); + this.itemConfiguration = new ConfigurateFile<>(plugin, directory, "items.yml"); + + this.pluginConfiguration.load(PluginConfiguration.class, FileConfigurationType.HOCON); + this.itemConfiguration.load(ItemConfiguration.class, FileConfigurationType.YAML); + } + + public void oldConfigMigration(final File fromDirectory, final File toDirectory) { + final File oldConfig = new File(fromDirectory, "config.conf"); + if (oldConfig.exists()) { + try { + final File to = new File(toDirectory, "config.conf"); + Files.move(oldConfig, to); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + } + + public CompletableFuture reload() { + final CompletableFuture[] futures = new CompletableFuture[2]; + futures[0] = pluginConfiguration.reload(); + futures[1] = itemConfiguration.reload(); + + return CompletableFuture.allOf(futures); + } + + public GeneralCategory getGeneralCategory() { + return getPluginConfiguration().getGeneralCategory(); + } + + public PluginConfiguration getPluginConfiguration() { + return pluginConfiguration.getConfiguration(); + } + + public ItemConfiguration getConfiguration() { + return itemConfiguration.getConfiguration(); + } + + public LeaderboardCategory getLeaderboardCategory() { + return getPluginConfiguration().getLeaderboardCategory(); + } + + public BlockMenuCategory getBlockMenuCategory() { + return getPluginConfiguration().getBlockMenuCategory(); + } + + public LobbyCategory getLobbyCategory() { + return getPluginConfiguration().getLobbyCategory(); + } + + public GameCategory getGameCategory() { + return getConfiguration().getGameCategory(); + } + + public CompletableFuture update() { + return pluginConfiguration.update(); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/AbstractItemActionSerializer.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/AbstractItemActionSerializer.java new file mode 100644 index 00000000..de61a0cd --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/AbstractItemActionSerializer.java @@ -0,0 +1,34 @@ +package io.tofpu.speedbridge2.model.common.config.serializer; + +import io.tofpu.speedbridge2.model.common.umbrella.RunCommandItemAction; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.SerializationException; +import org.spongepowered.configurate.serialize.TypeSerializer; + +import java.lang.reflect.Type; + +public final class AbstractItemActionSerializer implements TypeSerializer { + public static final AbstractItemActionSerializer INSTANCE = new AbstractItemActionSerializer(); + + @Override + public AbstractItemAction deserialize(final Type type, final ConfigurationNode node) throws SerializationException { + final String command = node.node("run_command").getString(""); + + return new RunCommandItemAction(command, null); + } + + @Override + public void serialize(final Type type, @Nullable + final AbstractItemAction obj, final ConfigurationNode node) throws SerializationException { + if (!(obj instanceof RunCommandItemAction)) { + return; + } + final RunCommandItemAction commandItemAction = (RunCommandItemAction) obj; + + // TODO: HAVE THIS CUSTOMIZABLE LATER + node.node("type").set("PERFORM_COMMAND"); + node.node("run_command").set(commandItemAction.getCommand()); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemMetaSerializer.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemMetaSerializer.java new file mode 100644 index 00000000..9ae026a7 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemMetaSerializer.java @@ -0,0 +1,84 @@ +package io.tofpu.speedbridge2.model.common.config.serializer; + +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.inventory.meta.ItemMeta; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.SerializationException; +import org.spongepowered.configurate.serialize.TypeSerializer; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public final class ItemMetaSerializer implements TypeSerializer { + public static final ItemMetaSerializer INSTANCE = new ItemMetaSerializer(); + private static final ItemMeta ITEM_META = Bukkit.getItemFactory() + .getItemMeta(Material.DIAMOND_BLOCK); + + @Override + public ItemMeta deserialize(final Type type, final ConfigurationNode node) throws SerializationException { + final ItemMeta itemMeta = ITEM_META.clone(); + + final String displayName = node.node("display_name").getString(""); + final @Nullable List lore = node.node("lore").getList(String.class); + + final Component deserialize = BridgeUtil.translateMiniMessage(displayName); + + itemMeta.setDisplayName(BukkitComponentSerializer.legacy().serialize(deserialize)); + itemMeta.setLore(serializeListAdventure(lore)); + return itemMeta; + } + + @Override + public void serialize(final Type type, @Nullable + final ItemMeta obj, final ConfigurationNode node) throws SerializationException { + if (obj == null) { + node.raw(); + return; + } + + final TextComponent textComponent = deserialize(obj.getDisplayName()); + + node.node("display_name").set(MiniMessage.miniMessage().serialize(textComponent)); + node.node("lore").set(serializeListLegacy(obj.getLore())); + } + + public List serializeListLegacy(final List list) { + final List newList = new ArrayList<>(); + for (final String lore : list) { + newList.add(serialize(deserialize(lore))); + } + return newList; + } + + public TextComponent deserialize(final String input) { + return LegacyComponentSerializer.legacySection() + .deserializeOrNull(input); + } + + public String serialize(final TextComponent component) { + return MiniMessage.miniMessage().serialize(component); + } + + public List serializeListAdventure(final List list) { + if (list == null) { + return Collections.emptyList(); + } + + final List newList = new ArrayList<>(); + for (final String lore : list) { + final Component component = BridgeUtil.translateMiniMessage(lore); + newList.add(BukkitComponentSerializer.legacy().serialize(component)); + } + return newList; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemStackSerializer.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemStackSerializer.java new file mode 100644 index 00000000..9fabf706 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/ItemStackSerializer.java @@ -0,0 +1,35 @@ +package io.tofpu.speedbridge2.model.common.config.serializer; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.SerializationException; +import org.spongepowered.configurate.serialize.TypeSerializer; + +import java.lang.reflect.Type; + +public final class ItemStackSerializer implements TypeSerializer { + public static final ItemStackSerializer INSTANCE = new ItemStackSerializer(); + + @Override + public ItemStack deserialize(final Type type, final ConfigurationNode node) throws SerializationException { + final Material material = node.node("material").get(Material.class, Material.AIR); + final short durability = (short) node.node("durability").getInt(0); + final ItemMeta itemMeta = node.node("meta").get(ItemMeta.class); + + final ItemStack itemStack = new ItemStack(material, 1, durability); + itemStack.setItemMeta(itemMeta); + + return itemStack; + } + + @Override + public void serialize(final Type type, @Nullable + final ItemStack obj, final ConfigurationNode node) throws SerializationException { + node.node("material").set(obj.getType()); + node.node("durability").set(obj.getDurability()); + node.node("meta").set(obj.getItemMeta()); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/serializer/LocationSerializer.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/LocationSerializer.java similarity index 97% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/serializer/LocationSerializer.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/LocationSerializer.java index 4756c636..d87bef7c 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/serializer/LocationSerializer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/LocationSerializer.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.config.serializer; +package io.tofpu.speedbridge2.model.common.config.serializer; import org.bukkit.Bukkit; import org.bukkit.Location; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/config/serializer/MaterialSerializer.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/MaterialSerializer.java similarity index 94% rename from src/main/java/io/tofpu/speedbridge2/domain/common/config/serializer/MaterialSerializer.java rename to src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/MaterialSerializer.java index b9246957..3125ad1f 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/config/serializer/MaterialSerializer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/MaterialSerializer.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.config.serializer; +package io.tofpu.speedbridge2.model.common.config.serializer; import com.cryptomorin.xseries.XMaterial; import org.bukkit.Material; diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/UmbrellaItemSerializer.java b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/UmbrellaItemSerializer.java new file mode 100644 index 00000000..52da5912 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/config/serializer/UmbrellaItemSerializer.java @@ -0,0 +1,42 @@ +package io.tofpu.speedbridge2.model.common.config.serializer; + +import io.tofpu.speedbridge2.model.common.umbrella.SerializableUmbrellaItem; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.SerializationException; +import org.spongepowered.configurate.serialize.TypeSerializer; + +import java.lang.reflect.Type; +import java.util.UUID; + +public final class UmbrellaItemSerializer implements TypeSerializer { + public static final UmbrellaItemSerializer INSTANCE = new UmbrellaItemSerializer(); + + private static final ItemStack EMPTY_ITEM = new ItemStack(Material.AIR); + + @Override + public SerializableUmbrellaItem deserialize(final Type type, final ConfigurationNode node) throws SerializationException { + final int index = node.node("index") + .getInt(-1); + final ItemStack itemStack = node.node("item") + .get(ItemStack.class, EMPTY_ITEM); + final AbstractItemAction itemAction = node.node("action") + .get(AbstractItemAction.class); + + return new SerializableUmbrellaItem(UUID.randomUUID() + .toString(), index, itemStack, itemAction); + } + + @Override + public void serialize(final Type type, @Nullable + final SerializableUmbrellaItem obj, final ConfigurationNode node) throws SerializationException { + final ItemStack itemStack = obj.getItemStack(); + + node.node("index").set(obj.getIndex()); + node.node("item").set(itemStack); + node.node("action").set(obj.getItemAction()); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/database/DatabaseManager.java b/src/main/java/io/tofpu/speedbridge2/model/common/database/DatabaseManager.java similarity index 67% rename from src/main/java/io/tofpu/speedbridge2/domain/common/database/DatabaseManager.java rename to src/main/java/io/tofpu/speedbridge2/model/common/database/DatabaseManager.java index 71cff465..9b7e6cf0 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/database/DatabaseManager.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/database/DatabaseManager.java @@ -1,9 +1,10 @@ -package io.tofpu.speedbridge2.domain.common.database; +package io.tofpu.speedbridge2.model.common.database; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseTable; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; +import com.google.common.io.Files; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseTable; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,7 +20,7 @@ public final class DatabaseManager { private static final @NotNull Queue TABLE_QUEUE = new LinkedList<>(); - private static File databaseFile; + private static File storageFile; private static Connection connection; public static CompletableFuture load(final @NotNull Plugin plugin) { @@ -30,16 +31,20 @@ public static CompletableFuture load(final @NotNull Plugin plugin) { e.printStackTrace(); } - final File parentFolder = plugin.getDataFolder(); + final File parentFolder = new File(plugin.getDataFolder(), "data"); + storageFile = new File(parentFolder, "storage.db"); if (!parentFolder.exists()) { - parentFolder.mkdir(); + parentFolder.mkdirs(); } - databaseFile = new File(plugin.getDataFolder(), "data.db"); + // if the server used a version anything lower + // than 1.0.8, then the migration process will be executed + migrateDataFile(plugin.getDataFolder(), storageFile); + try { - databaseFile.createNewFile(); + storageFile.createNewFile(); } catch (IOException e) { - e.printStackTrace(); + throw new IllegalStateException(e); } connection = getConnection(); @@ -48,6 +53,17 @@ public static CompletableFuture load(final @NotNull Plugin plugin) { }); } + private static void migrateDataFile(final File fromDirectory, final File toFile) { + final File previousFile = new File(fromDirectory, "data.db"); + if (previousFile.exists()) { + try { + Files.move(previousFile, toFile); + } catch (IOException e) { + throw new IllegalStateException(e); + } + } + } + private static void loadTables() { while (getConnection() == null) { try { @@ -91,7 +107,7 @@ public static void appendTable(final @NotNull DatabaseTable table) { if (connection != null && !connection.isClosed()) { return connection; } - return DriverManager.getConnection("jdbc:sqlite:" + databaseFile); + return DriverManager.getConnection("jdbc:sqlite:" + storageFile); } catch (SQLException exception) { throw new IllegalStateException(exception); } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/database/Databases.java b/src/main/java/io/tofpu/speedbridge2/model/common/database/Databases.java similarity index 63% rename from src/main/java/io/tofpu/speedbridge2/domain/common/database/Databases.java rename to src/main/java/io/tofpu/speedbridge2/model/common/database/Databases.java index 2bd17feb..304b464e 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/database/Databases.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/database/Databases.java @@ -1,10 +1,10 @@ -package io.tofpu.speedbridge2.domain.common.database; +package io.tofpu.speedbridge2.model.common.database; -import io.tofpu.speedbridge2.domain.island.IslandDatabase; -import io.tofpu.speedbridge2.domain.player.PlayerDatabase; -import io.tofpu.speedbridge2.domain.player.misc.block.BlockDatabase; -import io.tofpu.speedbridge2.domain.player.misc.score.ScoreDatabase; -import io.tofpu.speedbridge2.domain.player.misc.stat.StatsDatabase; +import io.tofpu.speedbridge2.model.island.IslandDatabase; +import io.tofpu.speedbridge2.model.player.PlayerDatabase; +import io.tofpu.speedbridge2.model.player.misc.block.BlockDatabase; +import io.tofpu.speedbridge2.model.player.misc.score.ScoreDatabase; +import io.tofpu.speedbridge2.model.player.misc.stat.StatsDatabase; import org.jetbrains.annotations.NotNull; public final class Databases { diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/Database.java b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/Database.java similarity index 73% rename from src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/Database.java rename to src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/Database.java index b6bc1d20..5b0c577e 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/Database.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/Database.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common.database.wrapper; +package io.tofpu.speedbridge2.model.common.database.wrapper; -import io.tofpu.speedbridge2.domain.common.database.DatabaseManager; +import io.tofpu.speedbridge2.model.common.database.DatabaseManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseQuery.java b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseQuery.java similarity index 95% rename from src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseQuery.java rename to src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseQuery.java index 9ebb8ae0..4428952c 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseQuery.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseQuery.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common.database.wrapper; +package io.tofpu.speedbridge2.model.common.database.wrapper; -import io.tofpu.speedbridge2.domain.common.database.DatabaseManager; +import io.tofpu.speedbridge2.model.common.database.DatabaseManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseSet.java b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseSet.java similarity index 96% rename from src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseSet.java rename to src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseSet.java index ac90afea..2ee4168c 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseSet.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseSet.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.database.wrapper; +package io.tofpu.speedbridge2.model.common.database.wrapper; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseTable.java b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseTable.java similarity index 92% rename from src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseTable.java rename to src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseTable.java index 0ef6c37b..f21a6c84 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/database/wrapper/DatabaseTable.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/database/wrapper/DatabaseTable.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common.database.wrapper; +package io.tofpu.speedbridge2.model.common.database.wrapper; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; import org.jetbrains.annotations.NotNull; public class DatabaseTable { diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/umbrella/RunCommandItemAction.java b/src/main/java/io/tofpu/speedbridge2/model/common/umbrella/RunCommandItemAction.java new file mode 100644 index 00000000..fee1c368 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/umbrella/RunCommandItemAction.java @@ -0,0 +1,33 @@ +package io.tofpu.speedbridge2.model.common.umbrella; + +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.umbrella.domain.Umbrella; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import org.bukkit.event.player.PlayerInteractEvent; + +public class RunCommandItemAction extends AbstractItemAction { + private final String command; + private final GameIsland gameIsland; + + public RunCommandItemAction(final String command, final GameIsland gameIsland) { + this.command = command; + this.gameIsland = gameIsland; + } + + @Override + public void trigger(final Umbrella umbrella, final PlayerInteractEvent event) { + if (!command.equalsIgnoreCase("RESET_ISLAND")) { + event.getPlayer().performCommand(command); + return; + } + + if (gameIsland == null) { + return; + } + gameIsland.resetGame(); + } + + public String getCommand() { + return command; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/umbrella/SerializableUmbrellaItem.java b/src/main/java/io/tofpu/speedbridge2/model/common/umbrella/SerializableUmbrellaItem.java new file mode 100644 index 00000000..4bd1479a --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/umbrella/SerializableUmbrellaItem.java @@ -0,0 +1,44 @@ +package io.tofpu.speedbridge2.model.common.umbrella; + +import io.tofpu.umbrella.domain.item.UmbrellaItem; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import org.bukkit.inventory.ItemStack; + +public final class SerializableUmbrellaItem { + private final String identifier; + private final int index; + + private final ItemStack itemStack; + private final AbstractItemAction itemAction; + + public SerializableUmbrellaItem(final String identifier, final int index, final ItemStack itemStack, final AbstractItemAction itemAction) { + this.identifier = identifier; + this.index = index; + this.itemStack = itemStack; + this.itemAction = itemAction; + } + + public SerializableUmbrellaItem(final UmbrellaItem umbrellaItem) { + this.identifier = umbrellaItem.getItemIdentifier(); + this.index = umbrellaItem.getInventoryIndex(); + + this.itemAction = umbrellaItem.getItemAction(); + this.itemStack = umbrellaItem.getCopyOfItem(); + } + + public String getIdentifier() { + return identifier; + } + + public int getIndex() { + return index; + } + + public ItemStack getItemStack() { + return itemStack; + } + + public AbstractItemAction getItemAction() { + return itemAction; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java index 80996855..57a7d584 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/BridgeUtil.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/BridgeUtil.java @@ -1,15 +1,15 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; import io.tofpu.speedbridge2.SpeedBridge; -import io.tofpu.speedbridge2.domain.common.PlayerNameCache; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseSet; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.CommonBridgePlayer; +import io.tofpu.speedbridge2.model.common.PlayerNameCache; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseSet; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.CommonBridgePlayer; import io.tofpu.speedbridge2.plugin.SpeedBridgePlugin; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; @@ -54,7 +54,7 @@ public static String formatNumber(final double score) { * @param content The content of the message. * @return The translated message. */ - public static String translateMiniMessageLegacy(final String content) { + public static String miniMessageToLegacy(final String content) { return BukkitComponentSerializer.legacy().serialize(translateMiniMessage(content)); } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/DatabaseUtil.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/DatabaseUtil.java similarity index 76% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/DatabaseUtil.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/DatabaseUtil.java index 69d6db5a..482f0fe1 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/DatabaseUtil.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/DatabaseUtil.java @@ -1,8 +1,8 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseSet; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseSet; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; @@ -18,13 +18,13 @@ public class DatabaseUtil { * @param databaseQueryConsumer A Consumer that takes a DatabaseQuery. * @return Nothing. */ - public static CompletableFuture databaseQueryExecute(final String sql, final Consumer databaseQueryConsumer) { + public static CompletableFuture databaseExecute(final String sql, final Consumer databaseQueryConsumer) { return runAsync(() -> { try (final DatabaseQuery query = DatabaseQuery.query(sql)) { databaseQueryConsumer.accept(query); query.execute(); - } catch (Exception exception) { - exception.printStackTrace(); + } catch (final Exception e) { + throw new IllegalStateException(e); } }); } @@ -46,13 +46,13 @@ public static CompletableFuture runAsync(final Runnable runnable) { * @param databaseQueryConsumer A consumer that will be called for each row of the query. * @return Nothing. */ - public static CompletableFuture databaseQuery(final String sql, + public static CompletableFuture databaseQueryExecute(final String sql, final Consumer databaseQueryConsumer) { return runAsync(() -> { try (final DatabaseQuery query = DatabaseQuery.query(sql)) { query.executeQuery(databaseQueryConsumer); - } catch (Exception exception) { - exception.printStackTrace(); + } catch (Exception e) { + throw new IllegalStateException(e); } }); } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/FileUtil.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/FileUtil.java similarity index 97% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/FileUtil.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/FileUtil.java index 620f650f..69203f2b 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/FileUtil.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/FileUtil.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; import java.io.*; import java.nio.charset.StandardCharsets; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/IgnoreMessage.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/IgnoreMessage.java similarity index 84% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/IgnoreMessage.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/IgnoreMessage.java index 2e83ea45..c915d5f1 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/IgnoreMessage.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/IgnoreMessage.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/MessageUtil.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/MessageUtil.java similarity index 97% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/MessageUtil.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/MessageUtil.java index 60428137..fb3bb831 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/MessageUtil.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/MessageUtil.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; import org.apache.commons.lang.StringEscapeUtils; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/ReflectionUtil.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/ReflectionUtil.java similarity index 90% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/ReflectionUtil.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/ReflectionUtil.java index 4150f1d9..173ba3d1 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/ReflectionUtil.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/ReflectionUtil.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; -import io.tofpu.speedbridge2.domain.common.Message; +import io.tofpu.speedbridge2.model.common.Message; import java.lang.reflect.Field; import java.util.*; diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/util/UmbrellaUtil.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/UmbrellaUtil.java new file mode 100644 index 00000000..38e657e2 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/UmbrellaUtil.java @@ -0,0 +1,48 @@ +package io.tofpu.speedbridge2.model.common.util; + +import com.cryptomorin.xseries.XMaterial; +import io.tofpu.speedbridge2.model.common.umbrella.RunCommandItemAction; +import io.tofpu.speedbridge2.model.common.umbrella.SerializableUmbrellaItem; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.umbrella.UmbrellaAPI; +import io.tofpu.umbrella.domain.Umbrella; +import io.tofpu.umbrella.domain.item.UmbrellaItem; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Collections; + +public class UmbrellaUtil { + public static ItemStack create(final XMaterial material, final String displayName, + final String lore) { + final ItemStack itemStack = material.parseItem(); + final ItemMeta meta = itemStack.getItemMeta(); + + meta.setDisplayName(BridgeUtil.miniMessageToLegacy( + "" + displayName)); + meta.setLore(Collections.singletonList(BridgeUtil.miniMessageToLegacy( + "Click to " + lore))); + + itemStack.setItemMeta(meta); + + return itemStack; + } + + public static UmbrellaItem toUmbrellaItem(final Umbrella umbrella, final GameIsland gameIsland, final SerializableUmbrellaItem serializableUmbrellaItem) { + final String identifier = serializableUmbrellaItem.getIdentifier(); + final ItemStack itemStack = serializableUmbrellaItem.getItemStack(); + final int index = serializableUmbrellaItem.getIndex(); + AbstractItemAction itemAction = serializableUmbrellaItem.getItemAction(); + + if (itemAction instanceof RunCommandItemAction) { + final RunCommandItemAction commandItemAction = (RunCommandItemAction) itemAction; + itemAction = new RunCommandItemAction(commandItemAction.getCommand(), gameIsland); + } + + return UmbrellaAPI.getInstance() + .getUmbrellaService() + .getUmbrellaItemFactory() + .create(umbrella, identifier, itemStack, index, itemAction); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/common/util/UpdateChecker.java b/src/main/java/io/tofpu/speedbridge2/model/common/util/UpdateChecker.java similarity index 99% rename from src/main/java/io/tofpu/speedbridge2/domain/common/util/UpdateChecker.java rename to src/main/java/io/tofpu/speedbridge2/model/common/util/UpdateChecker.java index 3ba774a4..1b877c94 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/common/util/UpdateChecker.java +++ b/src/main/java/io/tofpu/speedbridge2/model/common/util/UpdateChecker.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.common.util; +package io.tofpu.speedbridge2.model.common.util; import com.google.common.base.Preconditions; import com.google.gson.JsonElement; diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/wrapper/ConfigurateFile.java b/src/main/java/io/tofpu/speedbridge2/model/common/wrapper/ConfigurateFile.java new file mode 100644 index 00000000..61bf887a --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/wrapper/ConfigurateFile.java @@ -0,0 +1,147 @@ +package io.tofpu.speedbridge2.model.common.wrapper; + +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.config.serializer.*; +import io.tofpu.speedbridge2.model.common.umbrella.SerializableUmbrellaItem; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.plugin.Plugin; +import org.spongepowered.configurate.ConfigurateException; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.ConfigurationOptions; +import org.spongepowered.configurate.hocon.HoconConfigurationLoader; +import org.spongepowered.configurate.loader.ConfigurationLoader; +import org.spongepowered.configurate.serialize.SerializationException; +import org.spongepowered.configurate.yaml.NodeStyle; +import org.spongepowered.configurate.yaml.YamlConfigurationLoader; + +import java.io.File; +import java.util.concurrent.CompletableFuture; +import java.util.function.UnaryOperator; + +public class ConfigurateFile { + private final Plugin plugin; + private final File file; + private ConfigurationLoader loader; + private ConfigurationNode node; + + private Class bindTo; + private T configuration; + + public ConfigurateFile(final Plugin plugin, final File targetFile) { + this.plugin = plugin; + this.file = targetFile; + } + + public ConfigurateFile(final Plugin plugin, final File file, final String name) { + this(plugin, new File(file, name)); + } + + public void load(final Class bindTo, final FileConfigurationType type) { + this.bindTo = bindTo; + + final UnaryOperator configurationOptions = options -> options.shouldCopyDefaults(true) + .serializers(builder -> builder.register(Location.class, LocationSerializer.INSTANCE) + .register(Material.class, MaterialSerializer.INSTANCE) + .register(SerializableUmbrellaItem.class, UmbrellaItemSerializer.INSTANCE) + .register(ItemStack.class, ItemStackSerializer.INSTANCE) + .register(ItemMeta.class, ItemMetaSerializer.INSTANCE) + .register(AbstractItemAction.class, + AbstractItemActionSerializer.INSTANCE)); + + switch (type) { + case YAML: + this.loader = YamlConfigurationLoader.builder() + .path(file.toPath()) + .nodeStyle(NodeStyle.BLOCK) + .defaultOptions(configurationOptions) + .build(); + break; + case HOCON: + this.loader = HoconConfigurationLoader.builder() + .path(file.toPath()) + .defaultOptions(configurationOptions) + .build(); + break; + } + + try { + this.node = loader.load(); + } catch (ConfigurateException e) { + plugin.getLogger() + .warning("An error occurred while loading this configuration:" + " " + + e.getMessage()); + if (e.getCause() != null) { + e.printStackTrace(); + } + return; + } + + try { + this.configuration = node.get(bindTo); + } catch (SerializationException e) { + plugin.getLogger() + .warning("An error occurred while converting MyConfiguration: " + + e.getMessage()); + if (e.getCause() != null) { + e.printStackTrace(); + } + } + + // in-case the file doesn't exist, this will generate one for us + this.save(); + } + + public CompletableFuture reload() { + return CompletableFuture.runAsync(() -> { + try { + this.node = loader.load(); + this.configuration = (T) node.get(bindTo); + } catch (ConfigurateException e) { + plugin.getLogger() + .warning("An error occurred while converting MyConfiguration: " + + e.getMessage()); + if (e.getCause() != null) { + e.printStackTrace(); + } + } + }); + } + + public void save() { + if (this.node == null) { + plugin.getLogger() + .warning("Configuration cannot be saved due to the node " + + "being null"); + return; + } + try { + this.loader.save(node); + } catch (ConfigurateException e) { + plugin.getLogger() + .warning("An error occurred while saving this configuration: " + + e.getMessage()); + if (e.getCause() != null) { + e.printStackTrace(); + } + } + } + + public CompletableFuture update() { + return PluginExecutor.runAsync(() -> { + try { + node.set(bindTo, configuration); + loader.save(node); + } catch (ConfigurateException e) { + e.printStackTrace(); + } + }); + } + + public T getConfiguration() { + return configuration; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/common/wrapper/FileConfigurationType.java b/src/main/java/io/tofpu/speedbridge2/model/common/wrapper/FileConfigurationType.java new file mode 100644 index 00000000..f8924904 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/common/wrapper/FileConfigurationType.java @@ -0,0 +1,5 @@ +package io.tofpu.speedbridge2.model.common.wrapper; + +public enum FileConfigurationType { + YAML, HOCON; +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandDatabase.java b/src/main/java/io/tofpu/speedbridge2/model/island/IslandDatabase.java similarity index 78% rename from src/main/java/io/tofpu/speedbridge2/domain/island/IslandDatabase.java rename to src/main/java/io/tofpu/speedbridge2/model/island/IslandDatabase.java index a4e68a51..717c8389 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandDatabase.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/IslandDatabase.java @@ -1,10 +1,11 @@ -package io.tofpu.speedbridge2.domain.island; - -import io.tofpu.speedbridge2.domain.common.database.wrapper.Database; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseTable; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.DatabaseUtil; -import io.tofpu.speedbridge2.domain.island.object.Island; +package io.tofpu.speedbridge2.model.island; + +import io.tofpu.speedbridge2.model.common.database.wrapper.Database; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseTable; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.DatabaseUtil; +import io.tofpu.speedbridge2.model.island.exception.IslandLoadFailureException; +import io.tofpu.speedbridge2.model.island.object.Island; import org.bukkit.Bukkit; import org.bukkit.Location; import org.jetbrains.annotations.NotNull; @@ -14,7 +15,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import static io.tofpu.speedbridge2.domain.common.util.DatabaseUtil.runAsync; +import static io.tofpu.speedbridge2.model.common.util.DatabaseUtil.runAsync; public final class IslandDatabase extends Database { public IslandDatabase() { @@ -22,8 +23,8 @@ public IslandDatabase() { } public @NotNull CompletableFuture insert(final Island island) { - return DatabaseUtil.databaseQueryExecute("INSERT OR IGNORE INTO islands VALUES " + - "(?, ?, ?, ?)", databaseQuery -> { + return DatabaseUtil.databaseExecute("INSERT OR IGNORE INTO islands VALUES " + + "(?, ?, ?, ?)", databaseQuery -> { databaseQuery.setInt(island.getSlot()); databaseQuery.setString(island.getCategory()); databaseQuery.setString(island.getSchematicName()); @@ -32,7 +33,7 @@ public IslandDatabase() { } public @NotNull CompletableFuture update(final Island island) { - return DatabaseUtil.databaseQueryExecute( + return DatabaseUtil.databaseExecute( "UPDATE islands SET category = ?, schematic_name = " + "?, spawn_point = ? WHERE slot = ?", databaseQuery -> { BridgeUtil.debug("island category: " + island.getCategory()); @@ -53,7 +54,7 @@ public IslandDatabase() { } public @NotNull CompletableFuture delete(final int slot) { - return DatabaseUtil.databaseQueryExecute("DELETE FROM islands WHERE slot = ?", databaseQuery -> { + return DatabaseUtil.databaseExecute("DELETE FROM islands WHERE slot = ?", databaseQuery -> { databaseQuery.setInt(slot); }); } @@ -63,7 +64,7 @@ public IslandDatabase() { final List islands = new ArrayList<>(); try { - DatabaseUtil.databaseQuery("SELECT * FROM islands", resultSet -> { + DatabaseUtil.databaseQueryExecute("SELECT * FROM islands", resultSet -> { while (resultSet.next()) { final Island island = new Island(resultSet.getInt("slot"), resultSet.getString("category")); island.selectSchematic(resultSet.getString("schematic_name")); @@ -85,7 +86,7 @@ public IslandDatabase() { }) .get(); } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + throw new IslandLoadFailureException(e); } return islands; diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/IslandHandler.java b/src/main/java/io/tofpu/speedbridge2/model/island/IslandHandler.java new file mode 100644 index 00000000..85e0ea94 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/IslandHandler.java @@ -0,0 +1,212 @@ +package io.tofpu.speedbridge2.model.island; + +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.IslandBoard; +import io.tofpu.speedbridge2.model.island.object.extra.IslandCreation; +import io.tofpu.speedbridge2.model.island.schematic.SchematicManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public final class IslandHandler { + private final @NotNull Map islandMap = new HashMap<>(); + + /** + * Loads the islands from the map of islands + * + * @param loadedIslands A map of island ids to island objects. + */ + public void load(final @NotNull Map loadedIslands) { + for (final Island island : loadedIslands.values()) { + IslandBoard.add(island); + } + this.islandMap.putAll(loadedIslands); + } + + /** + * Creates an island + * + * @param slot The island's slot. + * @param category The category of the island. + * @param schematic The name of the schematic to load. It cannot be null nor empty. + * @return The {@link IslandHandler.IslandCreationResult} enum. + */ + public @NotNull IslandHandler.IslandCreationResult createIsland(final int slot, + final @NotNull String category, final @NotNull String schematic) { + // if the island does exist, return ALREADY_EXISTS! + if (islandMap.containsKey(slot)) { + return IslandCreationResultType.ISLAND_ALREADY_EXISTS.empty(); + } + + final Island island = new IslandCreation(slot, category); + + BridgeUtil.debug("IslandHandler#createIsland(): before: " + island); + + // if the schematic is empty, or it doesn't exist, return UNKNOWN_SCHEMATIC! + if (schematic.isEmpty() || !island.selectSchematic(schematic)) { + return IslandCreationResultType.UNKNOWN_SCHEMATIC.empty(); + } + + BridgeUtil.debug("IslandHandler#createIsland(): after: " + island); + + // otherwise, return ISLAND_SUCCESS + return IslandCreationResultType.SUCCESS.create(island); + } + + /** + * Return the island at the given slot. + * + * @param slot The slot number of the island. + * @return The Island object that is stored in the slot that is passed in. + */ + public @Nullable Island findIslandBy(final int slot) { + return this.islandMap.get(slot); + } + + /** + * Find an island by its category. + * + * @param category The category of the island to find. + * @return The Island object that matches the category. + */ + public @Nullable Island findIslandBy(final String category) { + for (final Island island : this.islandMap.values()) { + if (island.getCategory() + .equals(category)) { + return island; + } + } + return null; + } + + /** + * This function deletes an island from the database and removes it from the island board + * + * @param slot The slot of the island you want to delete. + * @return The Island that was deleted. + */ + public @Nullable Island deleteIsland(final int slot) { + final Island island = this.islandMap.remove(slot); + + // if the island is not null, wipe said island & return deleted island! + if (island != null) { + Databases.ISLAND_DATABASE.delete(slot); + IslandBoard.remove(island); + + SchematicManager.clearPlot(slot); + + return island; + } + return null; + } + + /** + * Return a collection of all the islands in the map + * + * @return The unmodifiable collection of all the islands in the world. + */ + public @NotNull Collection getIslandMap() { + return Collections.unmodifiableCollection(this.islandMap.values()); + } + + /** + * Return a collection of all the islands integers in the map + * + * @return The unmodifiable collection of all the islands integers in the world. + */ + public @NotNull Collection getIntegerIslands() { + return Collections.unmodifiableCollection(this.islandMap.keySet()); + } + + /** + * @param island The island to register. + * + * @return The registration result. + */ + public IslandRegistrationResultType registerIsland(Island island) { + if (islandMap.containsKey(island.getSlot())) { + return IslandRegistrationResultType.ISLAND_ALREADY_EXISTS; + } + + if (island.getSchematicClipboard() == null) { + return IslandRegistrationResultType.UNKNOWN_SCHEMATIC; + } + + // print the island with BridgeUtil.debug + BridgeUtil.debug("IslandHandler#registerIsland(): island: " + island); + + if (island instanceof IslandCreation) { + final IslandCreation islandCreation = (IslandCreation) island; + island = islandCreation.toRegularIsland(); + } + + islandMap.put(island.getSlot(), island); + Databases.ISLAND_DATABASE.insert(island); + IslandBoard.add(island); + + return IslandRegistrationResultType.SUCCESS; + } + + public enum IslandCreationResultType { + /** + * The island had an unknown schematic. + */ + UNKNOWN_SCHEMATIC, + /** + * The island was already registered. + */ + ISLAND_ALREADY_EXISTS, + /** + * The island was successfully registered. + */ + SUCCESS; + + public IslandCreationResult empty() { + return create(null); + } + + public IslandCreationResult create(final Island + island) { + return new IslandCreationResult(this, island); + } + } + + public enum IslandRegistrationResultType { + /** + * The island had an unknown schematic. + */ + UNKNOWN_SCHEMATIC, + /** + * The island was already registered. + */ + ISLAND_ALREADY_EXISTS, + /** + * The island was successfully registered. + */ + SUCCESS; + } + + public static class IslandCreationResult { + private final IslandCreationResultType result; + private final Island island; + + public IslandCreationResult(final IslandCreationResultType result, final Island island) { + this.result = result; + this.island = island; + } + + public IslandCreationResultType getResult() { + return result; + } + + public Island getIsland() { + return island; + } + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandRepository.java b/src/main/java/io/tofpu/speedbridge2/model/island/IslandRepository.java similarity index 77% rename from src/main/java/io/tofpu/speedbridge2/domain/island/IslandRepository.java rename to src/main/java/io/tofpu/speedbridge2/model/island/IslandRepository.java index ac78da8a..18505581 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandRepository.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/IslandRepository.java @@ -1,8 +1,8 @@ -package io.tofpu.speedbridge2.domain.island; +package io.tofpu.speedbridge2.model.island; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.island.object.Island; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -12,7 +12,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import static io.tofpu.speedbridge2.domain.common.util.DatabaseUtil.runAsync; +import static io.tofpu.speedbridge2.model.common.util.DatabaseUtil.runAsync; public final class IslandRepository { public @NotNull CompletableFuture> loadIslands() { diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandService.java b/src/main/java/io/tofpu/speedbridge2/model/island/IslandService.java similarity index 75% rename from src/main/java/io/tofpu/speedbridge2/domain/island/IslandService.java rename to src/main/java/io/tofpu/speedbridge2/model/island/IslandService.java index 34915fdf..f8919576 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/IslandService.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/IslandService.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.island; +package io.tofpu.speedbridge2.model.island; -import io.tofpu.speedbridge2.domain.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.Island; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,17 +29,16 @@ public CompletableFuture> load() { } /** - * If the island doesn't exist, create it + * Creates an island * * @param slot The island's slot. * @param category The category of the island. - * @param schematic The name of the schematic to load. If it's empty, the island will be - * empty. - * @return The IslandCreationResult enum. + * @param schematic The name of the schematic to load. It cannot be null nor empty. + * @return The {@link IslandHandler.IslandCreationResult} enum. */ public @NotNull IslandHandler.IslandCreationResult createIsland(final int slot, final @NotNull String category, - final String schematic) { + final @NotNull String schematic) { return this.islandHandler.createIsland(slot, category, schematic); } @@ -79,6 +78,19 @@ public CompletableFuture> load() { * @return The unmodifiable collection of all the islands in the world. */ public @NotNull Collection getAllIslands() { - return this.islandHandler.getIslands(); + return this.islandHandler.getIslandMap(); + } + + /** + * Return a collection of all the islands integers in the map + * + * @return The unmodifiable collection of all the islands integers in the world. + */ + public @NotNull Collection getIntegerIslands() { + return this.islandHandler.getIntegerIslands(); + } + + public void registerIsland(final Island island) { + this.islandHandler.registerIsland(island); } } diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandDatabaseExceptionWrapper.java b/src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandDatabaseExceptionWrapper.java new file mode 100644 index 00000000..10469263 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandDatabaseExceptionWrapper.java @@ -0,0 +1,8 @@ +package io.tofpu.speedbridge2.model.island.exception; + +public class IslandDatabaseExceptionWrapper extends RuntimeException { + public IslandDatabaseExceptionWrapper(final String message, final int slot, + final Throwable e) { + super(message + (slot == -1 ? "" : ": " + slot), e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandLoadFailureException.java b/src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandLoadFailureException.java new file mode 100644 index 00000000..0b38b5ee --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/exception/IslandLoadFailureException.java @@ -0,0 +1,7 @@ +package io.tofpu.speedbridge2.model.island.exception; + +public final class IslandLoadFailureException extends IslandDatabaseExceptionWrapper { + public IslandLoadFailureException(final Throwable e) { + super("Failed to load the island data", -1, e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/object/Island.java b/src/main/java/io/tofpu/speedbridge2/model/island/object/Island.java similarity index 74% rename from src/main/java/io/tofpu/speedbridge2/domain/island/object/Island.java rename to src/main/java/io/tofpu/speedbridge2/model/island/object/Island.java index 7d447e56..cbe8f1a0 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/object/Island.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/object/Island.java @@ -1,16 +1,18 @@ -package io.tofpu.speedbridge2.domain.island.object; +package io.tofpu.speedbridge2.model.island.object; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.LeaderboardMap; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.island.schematic.IslandSchematic; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.multiworldedit.ClipboardWrapper; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.leaderboard.LeaderboardMap; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.island.schematic.IslandSchematic; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; import org.bukkit.Location; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -22,16 +24,21 @@ public class Island { private final int slot; - private final Map islandMap = new HashMap<>(); + private final Map islandMap; private String category; - private final LeaderboardMap leaderboardMap = new LeaderboardMap(); - private final IslandSchematic islandSchematic = new IslandSchematic(); - private Location absoluteLocation = null; + private final LeaderboardMap leaderboardMap; + private final IslandSchematic islandSchematic; + private Location absoluteLocation; public Island(final int slot, final String category) { this.slot = slot; + this.islandMap = new HashMap<>(); this.category = category; + + this.leaderboardMap = new LeaderboardMap(); + this.islandSchematic = new IslandSchematic(this); + this.absoluteLocation = null; } /** @@ -74,6 +81,10 @@ public Map.Entry join(final BridgePlayer player) { */ public void leaveGame(final BridgePlayer bridgePlayer) { final GamePlayer gamePlayer = bridgePlayer.getGamePlayer(); + if (gamePlayer == null) { + return; + } + final GameIsland gameIsland = this.islandMap.remove(gamePlayer); if (gameIsland == null) { return; @@ -88,8 +99,6 @@ public void leaveGame(final BridgePlayer bridgePlayer) { BridgeUtil.sendMessage(player, String.format(Message.INSTANCE.leftAnIsland, slot)); bridgePlayer.setGamePlayer(null); - // remove the game player - gamePlayer.remove(); // reset the game island gameIsland.remove(); } @@ -149,7 +158,7 @@ public Location getAbsoluteLocation() { } /** - * This function checks to see if the island schematic is ready to be copied + * This function checks to see if the island schematic is ready to be used. * * @return A boolean value. */ @@ -161,23 +170,19 @@ public boolean isReady() { /** * This function updates the database with the current values of the object */ - private void update() { + protected void update() { Databases.ISLAND_DATABASE.update(this); } /** - * Returns the slot number of the given item - * - * @return The slot number of the item. + * @return The slot number of the island. */ public int getSlot() { return slot; } /** - * It returns the category of the question. - * - * @return The category of the question. + * @return The category of the island. */ public String getCategory() { return category; @@ -186,24 +191,24 @@ public String getCategory() { /** * Load the leaderboard map with the given map * - * @param boardMap The map of player IDs to BoardPlayer objects. + * @param boardMap The map to load into the leaderboard map. */ public void loadBoard(final Map boardMap) { this.leaderboardMap.load(boardMap); } /** - * Add a score to the leaderboard for a given player + * Add a score to the leaderboard for the given player * - * @param bridgePlayer The player who's score is being added to the leaderboard. - * @param score The score to add to the leaderboard. + * @param bridgePlayer The bridge player to add the score to. + * @param score The score to add. */ public void addLeaderboardScore(final BridgePlayer bridgePlayer, final Score score) { leaderboardMap.append(bridgePlayer, score); } /** - * Update the leaderboard map + * Forces the leaderboard to be updated */ public void updateLeaderboard() { this.leaderboardMap.updateLeaderboard(); @@ -228,7 +233,7 @@ public String toString() { /** * Reset the player's score to 0 * - * @param uuid The UUID of the player to reset. + * @param uuid The uuid of the player to reset. */ public void resetPlayer(final UUID uuid) { this.leaderboardMap.reset(uuid); @@ -237,12 +242,21 @@ public void resetPlayer(final UUID uuid) { /** * Returns the clipboard of the island schematic * - * @return A Clipboard object. + * @return The Clipboard object. */ public Clipboard getSchematicClipboard() { return islandSchematic.getSchematicClipboard(); } + /** + * Returns the clipboard of the island schematic + * + * @return The Clipboard object. + */ + public ClipboardWrapper getSchematicClipboardWrapper() { + return islandSchematic.getSchematicClipboardWrapper(); + } + /** * Returns the name of the schematic * @@ -251,4 +265,11 @@ public Clipboard getSchematicClipboard() { public String getSchematicName() { return islandSchematic.getSchematicName(); } + + /** + * Delete the island from the database and memory + */ + public void delete() { + IslandService.INSTANCE.deleteIsland(getSlot()); + } } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/object/IslandBoard.java b/src/main/java/io/tofpu/speedbridge2/model/island/object/IslandBoard.java similarity index 92% rename from src/main/java/io/tofpu/speedbridge2/domain/island/object/IslandBoard.java rename to src/main/java/io/tofpu/speedbridge2/model/island/object/IslandBoard.java index 67f13d47..e53bd280 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/object/IslandBoard.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/object/IslandBoard.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.domain.island.object; +package io.tofpu.speedbridge2.model.island.object; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/NullIsland.java b/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/EmptyIsland.java similarity index 66% rename from src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/NullIsland.java rename to src/main/java/io/tofpu/speedbridge2/model/island/object/extra/EmptyIsland.java index 4e9bd159..f2e4ef6a 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/NullIsland.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/EmptyIsland.java @@ -1,17 +1,17 @@ -package io.tofpu.speedbridge2.domain.island.object.extra; +package io.tofpu.speedbridge2.model.island.object.extra; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; import org.jetbrains.annotations.NotNull; import java.util.AbstractMap; import java.util.Map; -public class NullIsland extends Island { - public NullIsland() { +public class EmptyIsland extends Island { + public EmptyIsland() { super(-1, "null"); } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java b/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/GameIsland.java similarity index 65% rename from src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java rename to src/main/java/io/tofpu/speedbridge2/model/island/object/extra/GameIsland.java index 0ec237a0..27c96305 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/object/extra/GameIsland.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/GameIsland.java @@ -1,23 +1,24 @@ -package io.tofpu.speedbridge2.domain.island.object.extra; - -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.config.category.LobbyCategory; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.MessageUtil; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.plot.IslandPlot; -import io.tofpu.speedbridge2.domain.island.schematic.SchematicManager; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStatType; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.worldedit.CuboidRegion; +package io.tofpu.speedbridge2.model.island.object.extra; + +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.config.category.LobbyCategory; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.umbrella.GameIslandUmbrella; +import io.tofpu.speedbridge2.model.island.plot.IslandPlot; +import io.tofpu.speedbridge2.model.island.schematic.SchematicManager; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStatType; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.worldedit.CuboidRegion; +import io.tofpu.umbrella.domain.Umbrella; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public final class GameIsland { + private final Umbrella umbrella; private final Island island; private final GamePlayer gamePlayer; private IslandPlot islandPlot; @@ -27,6 +28,7 @@ public static GameIsland of(final Island island, final GamePlayer gamePlayer) { } private GameIsland(final Island island, final GamePlayer gamePlayer) { + this.umbrella = new GameIslandUmbrella(this).getUmbrella(); this.island = island; this.gamePlayer = gamePlayer; } @@ -35,9 +37,14 @@ public void start() { // setting the player's queue to true this.gamePlayer.startQueue(); + // binding the game player instance to bridge player this.gamePlayer.getBridgePlayer().setGamePlayer(gamePlayer); - this.islandPlot = SchematicManager.INSTANCE.reservePlot(this); + // reverse an island plot for this game + this.islandPlot = SchematicManager.reservePlot(this); + + // execute the on join method on game island + onJoin(); // reset the player's queue this.gamePlayer.resetQueue(); @@ -46,7 +53,18 @@ public void start() { public void onJoin() { final Player player = gamePlayer.getBridgePlayer().getPlayer(); + // setting the player island slot + gamePlayer.setCurrentGame(this); + // teleport the player to the island plot + gamePlayer.teleport(islandPlot); + + // clears the player's inventory player.getInventory().clear(); + + // active the game umbrella + umbrella.activate(player); + + // add the block player.getInventory() .setItem(0, new ItemStack(gamePlayer.getBridgePlayer() .getChoseMaterial(), 64)); @@ -90,6 +108,8 @@ public void remove() { final LobbyCategory lobbyCategory = ConfigurationManager.INSTANCE.getLobbyCategory(); + umbrella.inactivate(player); + // teleport the player to the lobby location final Location location = lobbyCategory.getLobbyLocation(); if (location != null) { @@ -127,7 +147,7 @@ public IslandPlot getIslandPlot() { return islandPlot; } - public void leave(final BridgePlayer bridgePlayer) { - getIsland().leaveGame(bridgePlayer); + public void stopGame() { + getIsland().leaveGame(getGamePlayer().getBridgePlayer()); } } diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/IslandCreation.java b/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/IslandCreation.java new file mode 100644 index 00000000..ecdc5919 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/object/extra/IslandCreation.java @@ -0,0 +1,42 @@ +package io.tofpu.speedbridge2.model.island.object.extra; + +import io.tofpu.speedbridge2.model.island.object.Island; + +public class IslandCreation extends Island { + public IslandCreation(final int slot, final String category) { + super(slot, category); + } + + @Override + public boolean isReady() { + // return false since this is a creation island + return false; + } + + @Override + public void updateLeaderboard() { + // do nothing here since this is a creation island + } + + @Override + public void delete() { + // do nothing here since this is a creation island + } + + @Override + protected void update() { + // do nothing here since this is a creation island + } + + public Island toRegularIsland() { + final Island island = new Island(this.getSlot(), this.getCategory()); + island.selectSchematic(getSchematicName()); + island.setAbsoluteLocation(getAbsoluteLocation()); + return island; + } + + @Override + public String toString() { + return "IslandCreation: " + this.getSlot() + " " + this.getCategory() + " " + getSchematicName(); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/object/umbrella/GameIslandUmbrella.java b/src/main/java/io/tofpu/speedbridge2/model/island/object/umbrella/GameIslandUmbrella.java new file mode 100644 index 00000000..0c11c61b --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/object/umbrella/GameIslandUmbrella.java @@ -0,0 +1,29 @@ +package io.tofpu.speedbridge2.model.island.object.umbrella; + +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.umbrella.SerializableUmbrellaItem; +import io.tofpu.speedbridge2.model.common.util.UmbrellaUtil; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.umbrella.UmbrellaAPI; +import io.tofpu.umbrella.domain.Umbrella; + +public final class GameIslandUmbrella { + private final Umbrella umbrella; + + public GameIslandUmbrella(final GameIsland gameIsland) { + this.umbrella = UmbrellaAPI.getInstance() + .getUmbrellaService() + .getUmbrellaFactory() + .create("island"); + + for (final SerializableUmbrellaItem serializableUmbrellaItem : ConfigurationManager + .INSTANCE.getGameCategory().getUmbrellaItems()) { + // serializing SerializableUmbrellaItem to UmbrellaItem + UmbrellaUtil.toUmbrellaItem(umbrella, gameIsland, serializableUmbrellaItem); + } + } + + public Umbrella getUmbrella() { + return umbrella; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/plot/IslandPlot.java b/src/main/java/io/tofpu/speedbridge2/model/island/plot/IslandPlot.java similarity index 84% rename from src/main/java/io/tofpu/speedbridge2/domain/island/plot/IslandPlot.java rename to src/main/java/io/tofpu/speedbridge2/model/island/plot/IslandPlot.java index 78b20042..2df7af1a 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/plot/IslandPlot.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/plot/IslandPlot.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.island.plot; +package io.tofpu.speedbridge2.model.island.plot; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; @@ -6,11 +6,15 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; -import io.tofpu.multiworldedit.*; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.support.worldedit.CuboidRegion; -import org.bukkit.Bukkit; +import io.tofpu.multiworldedit.ClipboardWrapper; +import io.tofpu.multiworldedit.EditSessionWrapper; +import io.tofpu.multiworldedit.MultiWorldEditAPI; +import io.tofpu.multiworldedit.RegionWrapper; +import io.tofpu.multiworldedit.VectorWrapper; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.support.worldedit.CuboidRegion; import org.bukkit.Location; import org.bukkit.World; @@ -40,14 +44,11 @@ public IslandPlot(final Island island, final World world, double[] positions) { this.y = positions[1]; this.z = positions[2]; - final MultiWorldEdit worldEdit = MultiWorldEditAPI.getMultiWorldEdit(); - final ClipboardWrapper schematicPlot = worldEdit.create(island.getSchematicClipboard()); + final ClipboardWrapper schematicPlot = island.getSchematicClipboardWrapper(); - final RegionWrapper regionWrapper = worldEdit.create(schematicPlot.to() - .getRegion()); + final RegionWrapper regionWrapper = schematicPlot.region(); final VectorWrapper origin = schematicPlot.getOrigin(); - // TODO: setup this this.yaw = 0f; this.pitch = 0f; @@ -64,9 +65,9 @@ public IslandPlot(final Island island, final World world, double[] positions) { } public void generatePlot() throws WorldEditException { - // possibly make this operation async? - Bukkit.getLogger() - .info("generating plot!"); + // TODO: Make this generation operation async + BridgeUtil.debug("Generating plot at " + this.location.toString() + " for " + + "island " + this.island.getSlot()); final BukkitWorld bukkitWorld = new BukkitWorld(world); diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/plot/PlotState.java b/src/main/java/io/tofpu/speedbridge2/model/island/plot/PlotState.java similarity index 84% rename from src/main/java/io/tofpu/speedbridge2/domain/island/plot/PlotState.java rename to src/main/java/io/tofpu/speedbridge2/model/island/plot/PlotState.java index 4d27eca0..4d9042b2 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/plot/PlotState.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/plot/PlotState.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.island.plot; +package io.tofpu.speedbridge2.model.island.plot; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; public final class PlotState { private GameIsland gameIsland; diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/schematic/IslandSchematic.java b/src/main/java/io/tofpu/speedbridge2/model/island/schematic/IslandSchematic.java new file mode 100644 index 00000000..2ad174f6 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/schematic/IslandSchematic.java @@ -0,0 +1,104 @@ +package io.tofpu.speedbridge2.model.island.schematic; + +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import io.tofpu.multiworldedit.ClipboardWrapper; +import io.tofpu.multiworldedit.MultiWorldEditAPI; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.nio.file.Path; + +public class IslandSchematic { + private static final String[] SCHEMATIC_TYPES = {"schematic", "schem"}; + + private final Island island; + private final File schematicdirectory; + + private @NotNull String schematicName = ""; + private @Nullable ClipboardWrapper schematicClipboard; + + public IslandSchematic(final Island island) { + this.island = island; + schematicdirectory = Bukkit.getPluginManager() + .getPlugin("WorldEdit") + .getDataFolder() + .toPath() + .resolve("schematics") + .toFile(); + } + + public boolean selectSchematic(final @NotNull String schematicName) { + BridgeUtil.debug( + "Loading schematic '" + schematicName + "' for " + island.getSlot() + + "..."); + BridgeUtil.debug("IslandSchematic#selectSchematic(): WorldEdit Directory: " + + schematicdirectory); + + final File file = findSchematicFile(schematicdirectory, schematicName); + if (file != null && file.exists()) { + this.schematicClipboard = MultiWorldEditAPI.getMultiWorldEdit() + .read(file); + + BridgeUtil.debug( + "IslandSchematic#selectSchematic(): Successfully loaded schematic: " + + schematicName); + + this.schematicName = schematicName; + return true; + } + + BridgeUtil.debug("IslandSchematic#selectSchematic(): Failed to load schematic: " + + schematicName); + return false; + } + + private File findSchematicFile(final @NotNull File directory, final @NotNull String name) { + final Path directoryPath = directory.toPath(); + + File file = null; + for (final String schematicType : SCHEMATIC_TYPES) { + file = directoryPath.resolve(name + "." + schematicType) + .toFile(); + + if (file.exists()) { + break; + } + } + return file; + } + + public @NotNull String getSchematicName() { + return schematicName; + } + + public @Nullable Clipboard getSchematicClipboard() { + if (this.schematicClipboard == null) { + return null; + } + return this.schematicClipboard.to(); + } + + public @Nullable ClipboardWrapper getSchematicClipboardWrapper() { + return this.schematicClipboard; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("IslandSchematic{"); + sb.append("islandSlot=") + .append(island.getSlot()); + sb.append(", schematicdirectory=") + .append(schematicdirectory); + sb.append(", schematicName='") + .append(schematicName) + .append('\''); + sb.append(", schematicClipboard=") + .append(schematicClipboard); + sb.append('}'); + return sb.toString(); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java b/src/main/java/io/tofpu/speedbridge2/model/island/schematic/SchematicManager.java similarity index 67% rename from src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java rename to src/main/java/io/tofpu/speedbridge2/model/island/schematic/SchematicManager.java index dc3fbf68..807a11da 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/schematic/SchematicManager.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/schematic/SchematicManager.java @@ -1,12 +1,11 @@ -package io.tofpu.speedbridge2.domain.island.schematic; +package io.tofpu.speedbridge2.model.island.schematic; import com.sk89q.worldedit.WorldEditException; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.island.plot.IslandPlot; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.island.plot.IslandPlot; import org.apache.commons.io.FileUtils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -23,30 +22,26 @@ import java.util.concurrent.atomic.AtomicInteger; public final class SchematicManager { - public static final @NotNull SchematicManager INSTANCE = new SchematicManager(); - private static final @NotNull Map> ISLAND_PLOTS = new HashMap<>(); private static final AtomicInteger COUNTER = new AtomicInteger(); - private File worldDirectory; - private @Nullable World world; - - private SchematicManager() {} + private static File worldDirectory; + private static @Nullable World world; - public void load() { + public static void load() { World world = Bukkit.getWorld("speedbridge2"); if (world == null) { world = Bukkit.createWorld(WorldCreator.name("speedbridge2") .generator(new EmptyChunkGenerator())); } - this.world = world; + SchematicManager.world = world; protectWorld(world); } - private void protectWorld(final @NotNull World world) { + private static void protectWorld(final @NotNull World world) { world.setFullTime(1000); world.setWeatherDuration(0); world.setStorm(false); @@ -58,7 +53,7 @@ private void protectWorld(final @NotNull World world) { world.setGameRuleValue("doDaylightCycle", "false"); } - public @Nullable IslandPlot reservePlot(final GameIsland gameIsland) { + public static @Nullable IslandPlot reservePlot(final GameIsland gameIsland) { if (world == null) { Bukkit.getLogger() .severe("The SpeedBridge2 world cannot be found! cancelled player's request to reserve a plot."); @@ -66,47 +61,47 @@ private void protectWorld(final @NotNull World world) { } final Island island = gameIsland.getIsland(); + + // return the available plot + return getPlot(island, gameIsland); + } + + private static IslandPlot getPlot(final Island island, final GameIsland gameIsland) { final int islandSlot = island.getSlot(); + + // retrieving a collection of plots that is associated with the given island slot final Collection islandPlots = retrieve(islandSlot); - IslandPlot availablePlot = getAvailablePlot(islandPlots, islandSlot); + + // attempt to get an available plot with the given island slot + IslandPlot islandPlot = getAvailablePlot(islandPlots, islandSlot); // if we found an available plot, start reserving the plot - if (availablePlot != null) { - availablePlot.reservePlot(gameIsland); + if (islandPlot != null) { + islandPlot.reservePlot(gameIsland); } else { // otherwise, create our own island plot - availablePlot = createIslandPlot(islandPlots, island, gameIsland); + islandPlot = createIslandPlot(islandPlots, island, gameIsland); } - - final GamePlayer gamePlayer = gameIsland.getGamePlayer(); - - // setting the player island slot - gamePlayer.setCurrentGame(gameIsland); - // teleport the player to the island plot - gamePlayer.teleport(availablePlot); - - // execute the on join method on game island - gameIsland.onJoin(); - - // return the available plot - return availablePlot; + return islandPlot; } - private IslandPlot getAvailablePlot(final Collection islandPlots, final int slot) { + private static IslandPlot getAvailablePlot(final Collection islandPlots, + final int slot) { for (final IslandPlot islandPlot : islandPlots) { // if it's not the same island plot, or the plot is not free; continue if (islandPlot.getIsland().getSlot() != slot || !islandPlot.isPlotFree()) { continue; } - BridgeUtil.debug("found an available plot!"); + BridgeUtil.debug("SchematicManager#getAvailablePlot: Found a free plot for " + slot + " slot!"); return islandPlot; } return null; } - private IslandPlot createIslandPlot(final Collection islandPlots, final Island target, final GameIsland gameIsland) { - BridgeUtil.debug("no free plot available, creating our own plot!"); + private static IslandPlot createIslandPlot(final Collection islandPlots + , final Island target, final GameIsland gameIsland) { + BridgeUtil.debug("SchematicManager#createIslandPlot: Creating a new island plot for " + target.getSlot() + " slot!"); final double[] positions = {100 * (COUNTER.getAndIncrement() + 100), 100, 100}; @@ -130,7 +125,7 @@ private IslandPlot createIslandPlot(final Collection islandPlots, fi return islandPlot; } - public void resetWorld() { + public static void resetWorld() { final File worldFile = getWorldDirectory(); if (worldFile != null && worldFile.exists()) { try { @@ -142,22 +137,22 @@ public void resetWorld() { } } - public Collection retrieve(final int slot) { + public static Collection retrieve(final int slot) { return ISLAND_PLOTS.getOrDefault(slot, new ArrayList<>()); } - public void clearPlot(final int slot) { + public static void clearPlot(final int slot) { ISLAND_PLOTS.remove(slot); } - public File getWorldDirectory() { + public static File getWorldDirectory() { if (worldDirectory == null || !worldDirectory.exists()) { - this.worldDirectory = new File( "speedbridge2"); + worldDirectory = new File( "speedbridge2"); } return worldDirectory; } - public void unloadWorld() { + public static void unloadWorld() { if (world == null) { return; } @@ -167,7 +162,7 @@ public void unloadWorld() { Bukkit.unloadWorld(world, false); } - private void movePlayersFromIslandWorld() { + private static void movePlayersFromIslandWorld() { for (final Player player : Bukkit.getOnlinePlayers()) { if (!player.getWorld() .getName() diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandCreationSetup.java b/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandCreationSetup.java new file mode 100644 index 00000000..5a125d3e --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandCreationSetup.java @@ -0,0 +1,30 @@ +package io.tofpu.speedbridge2.model.island.setup; + +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.plot.IslandPlot; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.umbrella.domain.Umbrella; + +public final class IslandCreationSetup extends IslandSetup { + public IslandCreationSetup(final Umbrella umbrella, final BridgePlayer player, final Island island, final IslandPlot islandPlot) { + super(umbrella, player, island, islandPlot); + } + + @Override + public boolean finish() { + final boolean result = super.finish(); + if (!result) { + return false; + } + + IslandService.INSTANCE.registerIsland(getIsland()); + BridgeUtil.sendMessage(getPlayer(), + String.format(Message.INSTANCE.islandHasBeenCreatedSchematic, + getIsland().getSlot(), getIsland().getSchematicName())); + + return true; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/setup/IslandSetup.java b/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandSetup.java similarity index 73% rename from src/main/java/io/tofpu/speedbridge2/domain/island/setup/IslandSetup.java rename to src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandSetup.java index b3946e32..2f000a53 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/setup/IslandSetup.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandSetup.java @@ -1,21 +1,24 @@ -package io.tofpu.speedbridge2.domain.island.setup; +package io.tofpu.speedbridge2.model.island.setup; +import com.sk89q.worldedit.WorldEditException; import io.tofpu.multiworldedit.ClipboardWrapper; import io.tofpu.multiworldedit.MultiWorldEditAPI; import io.tofpu.multiworldedit.VectorWrapper; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.plot.IslandPlot; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.support.worldedit.CuboidRegion; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.plot.IslandPlot; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.support.worldedit.CuboidRegion; +import io.tofpu.umbrella.domain.Umbrella; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import java.util.UUID; -public final class IslandSetup { - private final BridgePlayer playerEditor; +public class IslandSetup { + private final Umbrella umbrella; + private final BridgePlayer player; private final Island island; private final IslandPlot islandPlot; private final CuboidRegion cuboidRegion; @@ -23,13 +26,36 @@ public final class IslandSetup { private boolean removed = false; - public IslandSetup(final BridgePlayer playerEditor, final Island island, final IslandPlot islandPlot) { - this.playerEditor = playerEditor; + public IslandSetup(final Umbrella umbrella, final BridgePlayer player, final Island island, final IslandPlot islandPlot) { + this.umbrella = umbrella; + this.player = player; this.island = island; this.islandPlot = islandPlot; this.cuboidRegion = islandPlot.region(); } + /** + * This function starts the island setup process + */ + public void start() { + player.toggleSetup(); + player.getPlayer().setGameMode(GameMode.CREATIVE); + + final IslandPlot islandPlot = getIslandPlot(); + try { + islandPlot.generatePlot(); + } catch (WorldEditException e) { + throw new IllegalStateException(e); + } + + // teleporting the player to the setup location + player.getPlayer() + .teleport(islandPlot.getPlotLocation()); + + // activate the player umbrella + umbrella.activate(player.getPlayer()); + } + /** * This function sets the player spawn point to the given location * @@ -70,7 +96,7 @@ public boolean finish() { resetState(); // teleporting the player to the lobby location - playerEditor.getPlayer() + player.getPlayer() .teleport(ConfigurationManager.INSTANCE.getLobbyCategory() .getLobbyLocation()); @@ -144,7 +170,7 @@ public void cancel() { resetState(); // teleporting the player to the lobby location - playerEditor.getPlayer() + player.getPlayer() .teleport(ConfigurationManager.INSTANCE.getLobbyCategory() .getLobbyLocation()); @@ -152,19 +178,29 @@ public void cancel() { } private void resetState() { - playerEditor.toggleSetup(); + player.toggleSetup(); + + // inactivate the setup umbrella + umbrella.inactivate(player.getPlayer()); // setting the player's gamemode back to survival - playerEditor.getPlayer().setGameMode(GameMode.SURVIVAL); + player.getPlayer().setGameMode(GameMode.SURVIVAL); } /** - * Returns the UUID of the player that is currently editing this object + * Returns the UUID of the player that is currently editing the island * - * @return The UUID of the player that is currently editing the object. + * @return The UUID of the player that is currently editing the island. */ - public UUID getEditorUid() { - return playerEditor.getPlayerUid(); + public UUID getPlayerUid() { + return player.getPlayerUid(); + } + + /** + * @return The player that is currently editing the island. + */ + public BridgePlayer getPlayer() { + return player; } /** diff --git a/src/main/java/io/tofpu/speedbridge2/domain/island/setup/IslandSetupManager.java b/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandSetupManager.java similarity index 60% rename from src/main/java/io/tofpu/speedbridge2/domain/island/setup/IslandSetupManager.java rename to src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandSetupManager.java index c1e6e09e..3fde0303 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/island/setup/IslandSetupManager.java +++ b/src/main/java/io/tofpu/speedbridge2/model/island/setup/IslandSetupManager.java @@ -1,11 +1,14 @@ -package io.tofpu.speedbridge2.domain.island.setup; - -import com.sk89q.worldedit.WorldEditException; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.plot.IslandPlot; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +package io.tofpu.speedbridge2.model.island.setup; + +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.extra.IslandCreation; +import io.tofpu.speedbridge2.model.island.plot.IslandPlot; +import io.tofpu.speedbridge2.model.island.setup.umbrella.IslandSetupUmbrella; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.umbrella.domain.Umbrella; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.World; import java.util.HashMap; @@ -15,8 +18,13 @@ public final class IslandSetupManager { public static final IslandSetupManager INSTANCE = new IslandSetupManager(); + private final Umbrella umbrella; private final Map islandSetupMap = new HashMap<>(); + private IslandSetupManager() { + this.umbrella = new IslandSetupUmbrella().getUmbrella(); + } + private World world; /** @@ -26,27 +34,12 @@ public void load() { this.world = Bukkit.getWorld("speedbridge2"); } - public boolean startSetup(final BridgePlayer bridgePlayer, final Island island) { - final UUID playerUid = bridgePlayer.getPlayerUid(); - - if (islandSetupMap.get(playerUid) != null) { - return false; + public boolean initiate(final BridgePlayer player, final Island island) { + if (!islandSetupMap.containsKey(player.getPlayerUid())) { + create(player, island).start(); + return true; } - bridgePlayer.toggleSetup(); - bridgePlayer.getPlayer().setGameMode(GameMode.CREATIVE); - - final IslandSetup islandSetup = create(bridgePlayer, island); - final IslandPlot islandPlot = islandSetup.getIslandPlot(); - try { - islandPlot.generatePlot(); - } catch (WorldEditException e) { - throw new IllegalStateException(e); - } - - // teleporting the player to the setup location - bridgePlayer.getPlayer() - .teleport(islandPlot.getPlotLocation()); - return true; + return false; } /** @@ -59,7 +52,14 @@ public boolean startSetup(final BridgePlayer bridgePlayer, final Island island) private IslandSetup create(final BridgePlayer player, final Island target) { final double[] positions = {100 * (islandSetupMap.size() + 100), 100, 0}; - final IslandSetup islandSetup = new IslandSetup(player, target, new IslandPlot(target, world, positions)); + final IslandSetup islandSetup; + + final IslandPlot islandPlot = new IslandPlot(target, world, positions); + if (target instanceof IslandCreation) { + islandSetup = new IslandCreationSetup(umbrella, player, target, islandPlot); + } else { + islandSetup = new IslandSetup(umbrella, player, target, islandPlot); + } islandSetupMap.put(player.getPlayerUid(), islandSetup); return islandSetup; @@ -81,7 +81,7 @@ public IslandSetup findSetupBy(final UUID uuid) { * @param islandSetup The island setup that is being invalidated. */ public void invalidate(final IslandSetup islandSetup) { - islandSetupMap.remove(islandSetup.getEditorUid()); + islandSetupMap.remove(islandSetup.getPlayerUid()); } /** diff --git a/src/main/java/io/tofpu/speedbridge2/model/island/setup/umbrella/IslandSetupUmbrella.java b/src/main/java/io/tofpu/speedbridge2/model/island/setup/umbrella/IslandSetupUmbrella.java new file mode 100644 index 00000000..14c019e7 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/island/setup/umbrella/IslandSetupUmbrella.java @@ -0,0 +1,59 @@ +package io.tofpu.speedbridge2.model.island.setup.umbrella; + +import com.cryptomorin.xseries.XMaterial; +import io.tofpu.speedbridge2.model.common.util.UmbrellaUtil; +import io.tofpu.umbrella.UmbrellaAPI; +import io.tofpu.umbrella.domain.Umbrella; +import io.tofpu.umbrella.domain.item.action.AbstractItemAction; +import io.tofpu.umbrella.domain.item.factory.UmbrellaItemFactory; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public final class IslandSetupUmbrella { + private final Umbrella umbrella; + + public IslandSetupUmbrella() { + this.umbrella = UmbrellaAPI.getInstance() + .getUmbrellaService() + .getUmbrellaFactory() + .create("island_setup"); + + final UmbrellaItemFactory umbrellaItemFactory = UmbrellaAPI.getInstance() + .getUmbrellaService() + .getUmbrellaItemFactory(); + + final ItemStack finishItem = UmbrellaUtil.create(XMaterial.GREEN_DYE, + "Complete the " + "Island Setup", "complete the island setup!"); + umbrellaItemFactory.create(umbrella, "finish", finishItem, 3, new AbstractItemAction() { + @Override + public void trigger(final Umbrella umbrella, final PlayerInteractEvent event) { + event.getPlayer() + .performCommand("sb setup finish"); + } + }); + + final ItemStack setSpawnItem = UmbrellaUtil.create(XMaterial.LIGHT_WEIGHTED_PRESSURE_PLATE, + "Set the Island Spawnpoint", "set the island spawn-point!"); + umbrellaItemFactory.create(umbrella, "set_spawn", setSpawnItem, 4, new AbstractItemAction() { + @Override + public void trigger(final Umbrella umbrella, final PlayerInteractEvent event) { + event.getPlayer() + .performCommand("sb setup setspawn"); + } + }); + + final ItemStack cancelItem = UmbrellaUtil.create(XMaterial.RED_DYE, + "Cancel the " + "Island Setup", "cancel the island setup!"); + umbrellaItemFactory.create(umbrella, "cancel", cancelItem, 5, new AbstractItemAction() { + @Override + public void trigger(final Umbrella umbrella, final PlayerInteractEvent event) { + event.getPlayer() + .performCommand("sb setup cancel"); + } + }); + } + + public Umbrella getUmbrella() { + return umbrella; + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/Leaderboard.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/Leaderboard.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/Leaderboard.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/Leaderboard.java index 308288a6..30440d4b 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/Leaderboard.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/Leaderboard.java @@ -1,18 +1,18 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard; +package io.tofpu.speedbridge2.model.leaderboard; import com.github.benmanes.caffeine.cache.AsyncLoadingCache; import com.github.benmanes.caffeine.cache.Caffeine; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.loader.IslandLoader; -import io.tofpu.speedbridge2.domain.extra.leaderboard.loader.PersonalBoardLoader; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.IslandBoardPlayer; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.loader.IslandLoader; +import io.tofpu.speedbridge2.model.leaderboard.loader.PersonalBoardLoader; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.IslandBoardPlayer; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import java.util.*; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/LeaderboardMap.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/LeaderboardMap.java similarity index 92% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/LeaderboardMap.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/LeaderboardMap.java index f403f42c..ca0d22a2 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/LeaderboardMap.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/LeaderboardMap.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard; +package io.tofpu.speedbridge2.model.leaderboard; -import io.tofpu.speedbridge2.domain.common.PlayerNameCache; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.common.PlayerNameCache; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/loader/IslandLoader.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/loader/IslandLoader.java similarity index 82% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/loader/IslandLoader.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/loader/IslandLoader.java index 1acd64ff..82a73b79 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/loader/IslandLoader.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/loader/IslandLoader.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard.loader; +package io.tofpu.speedbridge2.model.leaderboard.loader; import com.github.benmanes.caffeine.cache.CacheLoader; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.meta.BoardRetrieve; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.IslandBoardPlayer; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.meta.BoardRetrieve; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.IslandBoardPlayer; import org.jetbrains.annotations.NotNull; import java.util.UUID; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/loader/PersonalBoardLoader.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/loader/PersonalBoardLoader.java similarity index 82% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/loader/PersonalBoardLoader.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/loader/PersonalBoardLoader.java index b1e0128d..13760db8 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/loader/PersonalBoardLoader.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/loader/PersonalBoardLoader.java @@ -1,16 +1,16 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard.loader; +package io.tofpu.speedbridge2.model.leaderboard.loader; import com.github.benmanes.caffeine.cache.CacheLoader; -import io.tofpu.speedbridge2.domain.common.PlayerNameCache; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseSet; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.meta.BoardRetrieve; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.common.PlayerNameCache; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseSet; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.meta.BoardRetrieve; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -88,7 +88,7 @@ public BoardPlayer retrieve(final @NotNull UUID uniqueId) { BridgeUtil.debug("PersonalBoardLoader#retrieve(): player: " + player); if (player == null) { return new BoardPlayer(PlayerNameCache.INSTANCE.getOrDefault(key), - 0, key, new Score(-1, -1)); + 0, key, Score.of(-1, -1)); } return player; } catch (final Exception e) { @@ -100,6 +100,6 @@ public BoardPlayer retrieve(final @NotNull UUID uniqueId) { public BoardPlayer toBoardPlayer(final UUID uid, final DatabaseSet databaseSet) { return new BoardPlayer(PlayerNameCache.INSTANCE.getOrDefault(uid), databaseSet.getInt("position"), uid, - new Score(-1, -1)); + Score.of(-1, -1)); } } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/meta/BoardRetrieve.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/meta/BoardRetrieve.java similarity index 85% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/meta/BoardRetrieve.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/meta/BoardRetrieve.java index df3a26a0..efd80401 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/meta/BoardRetrieve.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/meta/BoardRetrieve.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard.meta; +package io.tofpu.speedbridge2.model.leaderboard.meta; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/wrapper/BoardPlayer.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/wrapper/BoardPlayer.java similarity index 89% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/wrapper/BoardPlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/wrapper/BoardPlayer.java index b61aff4e..6b884173 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/wrapper/BoardPlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/wrapper/BoardPlayer.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper; +package io.tofpu.speedbridge2.model.leaderboard.wrapper; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.misc.score.Score; import java.util.UUID; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/wrapper/IslandBoardPlayer.java b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/wrapper/IslandBoardPlayer.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/wrapper/IslandBoardPlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/leaderboard/wrapper/IslandBoardPlayer.java index 401d4553..beeba68c 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/extra/leaderboard/wrapper/IslandBoardPlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/leaderboard/wrapper/IslandBoardPlayer.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper; +package io.tofpu.speedbridge2.model.leaderboard.wrapper; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/PlayerDatabase.java b/src/main/java/io/tofpu/speedbridge2/model/player/PlayerDatabase.java similarity index 68% rename from src/main/java/io/tofpu/speedbridge2/domain/player/PlayerDatabase.java rename to src/main/java/io/tofpu/speedbridge2/model/player/PlayerDatabase.java index 23d56128..4d934ac1 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/PlayerDatabase.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/PlayerDatabase.java @@ -1,16 +1,19 @@ -package io.tofpu.speedbridge2.domain.player; - -import io.tofpu.speedbridge2.domain.common.PlayerNameCache; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.common.database.wrapper.Database; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseTable; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.DatabaseUtil; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStat; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +package io.tofpu.speedbridge2.model.player; + +import io.tofpu.speedbridge2.model.common.PlayerNameCache; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.common.database.wrapper.Database; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseTable; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.DatabaseUtil; +import io.tofpu.speedbridge2.model.player.exception.PlayerDeletionFailureException; +import io.tofpu.speedbridge2.model.player.exception.PlayerLoadFailureException; +import io.tofpu.speedbridge2.model.player.exception.PlayerUpdateNameFailureException; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStat; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; @@ -22,7 +25,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; -import static io.tofpu.speedbridge2.domain.common.util.DatabaseUtil.runAsync; +import static io.tofpu.speedbridge2.model.common.util.DatabaseUtil.runAsync; public final class PlayerDatabase extends Database { public PlayerDatabase() { @@ -32,7 +35,7 @@ public PlayerDatabase() { public @NotNull CompletableFuture insert(final @NotNull BridgePlayer player) { final CompletableFuture[] completableFutures = new CompletableFuture[2]; - completableFutures[0] = DatabaseUtil.databaseQueryExecute( + completableFutures[0] = DatabaseUtil.databaseExecute( "INSERT OR IGNORE " + "INTO players VALUES (?, " + "?)", databaseQuery -> { databaseQuery.setString(player.getPlayerUid() @@ -48,27 +51,33 @@ public PlayerDatabase() { public @NotNull CompletableFuture update(final @NotNull BridgePlayer player) { final List> completableFutures = new ArrayList<>(); - BridgeUtil.debug("player uid: " + player.getPlayerUid()); + final UUID playerUid = player.getPlayerUid(); + + BridgeUtil.debug("PlayerDatabase#update(): Player: " + playerUid); completableFutures.add(updateName(player.getPlayer() .getName(), player)); completableFutures.add(Databases.BLOCK_DATABASE.update(player)); for (final Score score : player.getScores()) { - completableFutures.add(Databases.SCORE_DATABASE.update(player.getPlayerUid(), score)); + completableFutures.add(Databases.SCORE_DATABASE.update(playerUid, score)); } - return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])); + + return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])) + .exceptionally(throwable -> { + throw new PlayerUpdateNameFailureException(playerUid, throwable); + }); } public CompletableFuture updateName(final String newName, final BridgePlayer bridgePlayer) { return runAsync(() -> { + final UUID playerUid = bridgePlayer.getPlayerUid(); try (final DatabaseQuery databaseQuery = DatabaseQuery.query( "UPDATE players SET name = ? WHERE uid" + " = ?")) { databaseQuery.setString(newName); - databaseQuery.setString(bridgePlayer.getPlayerUid() - .toString()); - } catch (Exception e) { - e.printStackTrace(); + databaseQuery.setString(playerUid.toString()); + } catch (final Exception e) { + throw new PlayerUpdateNameFailureException(playerUid, e); } }); } @@ -76,7 +85,7 @@ public CompletableFuture updateName(final String newName, final BridgePlay public @NotNull CompletableFuture delete(final @NotNull UUID uuid) { final List completableFutures = new ArrayList<>(); - completableFutures.add(DatabaseUtil.databaseQueryExecute( + completableFutures.add(DatabaseUtil.databaseExecute( "DELETE FROM players " + "WHERE uid = ?", databaseQuery -> { databaseQuery.setString(uuid.toString()); })); @@ -85,7 +94,10 @@ public CompletableFuture updateName(final String newName, final BridgePlay completableFutures.add(Databases.BLOCK_DATABASE.delete(uuid)); completableFutures.add(Databases.STATS_DATABASE.delete(uuid)); - return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])); + return CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])) + .exceptionally(throwable -> { + throw new PlayerDeletionFailureException(uuid, throwable); + }); } public @NotNull CompletableFuture getStoredPlayer(final @NotNull UUID uniqueId) { @@ -116,8 +128,8 @@ public CompletableFuture updateName(final String newName, final BridgePlay if (pause.get()) { return bridgePlayer; } - } catch (Exception e) { - e.printStackTrace(); + } catch (final Exception e) { + throw new PlayerLoadFailureException(uniqueId, e); } try { @@ -147,11 +159,11 @@ public CompletableFuture updateName(final String newName, final BridgePlay } bridgePlayer.setIntervalMaterial(material); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + } catch (final InterruptedException | ExecutionException e) { + throw new PlayerLoadFailureException(uniqueId, e); } - BridgeUtil.debug("successfully loaded " + uniqueId + " player's data!"); + BridgeUtil.debug("PlayerDatabase#getStoredPlayer: Successfully retrieved player " + uniqueId); return bridgePlayer; }); diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/PlayerHandler.java b/src/main/java/io/tofpu/speedbridge2/model/player/PlayerHandler.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/domain/player/PlayerHandler.java rename to src/main/java/io/tofpu/speedbridge2/model/player/PlayerHandler.java index cb63ee9a..15533205 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/PlayerHandler.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/PlayerHandler.java @@ -1,13 +1,13 @@ -package io.tofpu.speedbridge2.domain.player; +package io.tofpu.speedbridge2.model.player; import com.github.benmanes.caffeine.cache.AsyncLoadingCache; import com.github.benmanes.caffeine.cache.Caffeine; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.island.setup.IslandSetupManager; -import io.tofpu.speedbridge2.domain.player.loader.PlayerLoader; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.domain.player.object.extra.DummyBridgePlayer; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.island.setup.IslandSetupManager; +import io.tofpu.speedbridge2.model.player.loader.PlayerLoader; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.player.object.extra.DummyBridgePlayer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/PlayerService.java b/src/main/java/io/tofpu/speedbridge2/model/player/PlayerService.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/domain/player/PlayerService.java rename to src/main/java/io/tofpu/speedbridge2/model/player/PlayerService.java index 21f2c430..eb33b9d9 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/PlayerService.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/PlayerService.java @@ -1,6 +1,7 @@ -package io.tofpu.speedbridge2.domain.player; +package io.tofpu.speedbridge2.model.player; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,8 +63,7 @@ public void remove(final @NotNull UUID uniqueId) { * If the player is in the * database, update the name and refresh the player instance * - * @param name The name of the player. - * @param uniqueId The unique ID of the player. + * @param player The player to refresh */ public void internalRefresh(final @NotNull Player player) { playerHandler.internalRefresh(player.getName(), player.getUniqueId()); @@ -73,7 +73,7 @@ public void internalRefresh(final @NotNull Player player) { * This function invalidates a player by removing them from the bridge and the island * setup manager * - * @param uniqueId The unique ID of the player to invalidate. + * @param player The player to invalidate * @return The bridge player that was invalidated. */ public @Nullable BridgePlayer invalidate(final @NotNull Player player) { diff --git a/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDatabaseExceptionWrapper.java b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDatabaseExceptionWrapper.java new file mode 100644 index 00000000..9d03f692 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDatabaseExceptionWrapper.java @@ -0,0 +1,10 @@ +package io.tofpu.speedbridge2.model.player.exception; + +import java.util.UUID; + +public class PlayerDatabaseExceptionWrapper extends RuntimeException { + public PlayerDatabaseExceptionWrapper(final String message, final UUID uniqueId, + final Throwable e) { + super(message + ": " + uniqueId.toString(), e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDeletionFailureException.java b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDeletionFailureException.java new file mode 100644 index 00000000..c3ccc3fc --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerDeletionFailureException.java @@ -0,0 +1,9 @@ +package io.tofpu.speedbridge2.model.player.exception; + +import java.util.UUID; + +public final class PlayerDeletionFailureException extends PlayerDatabaseExceptionWrapper { + public PlayerDeletionFailureException(final UUID uniqueId, final Throwable e) { + super("Failed to delete the player data", uniqueId, e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerLoadFailureException.java b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerLoadFailureException.java new file mode 100644 index 00000000..226c3f38 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerLoadFailureException.java @@ -0,0 +1,9 @@ +package io.tofpu.speedbridge2.model.player.exception; + +import java.util.UUID; + +public final class PlayerLoadFailureException extends PlayerDatabaseExceptionWrapper { + public PlayerLoadFailureException(final UUID uniqueId, final Throwable e) { + super("Failed to load the player data", uniqueId, e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateFailureException.java b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateFailureException.java new file mode 100644 index 00000000..a17dfbc8 --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateFailureException.java @@ -0,0 +1,9 @@ +package io.tofpu.speedbridge2.model.player.exception; + +import java.util.UUID; + +public final class PlayerUpdateFailureException extends PlayerDatabaseExceptionWrapper { + public PlayerUpdateFailureException(final UUID uniqueId, final Throwable e) { + super("Failed to update the player data", uniqueId, e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateNameFailureException.java b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateNameFailureException.java new file mode 100644 index 00000000..b88d027f --- /dev/null +++ b/src/main/java/io/tofpu/speedbridge2/model/player/exception/PlayerUpdateNameFailureException.java @@ -0,0 +1,9 @@ +package io.tofpu.speedbridge2.model.player.exception; + +import java.util.UUID; + +public final class PlayerUpdateNameFailureException extends PlayerDatabaseExceptionWrapper { + public PlayerUpdateNameFailureException(final UUID uniqueId, final Throwable e) { + super("Failed to update the player name", uniqueId, e); + } +} diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/loader/PlayerLoader.java b/src/main/java/io/tofpu/speedbridge2/model/player/loader/PlayerLoader.java similarity index 77% rename from src/main/java/io/tofpu/speedbridge2/domain/player/loader/PlayerLoader.java rename to src/main/java/io/tofpu/speedbridge2/model/player/loader/PlayerLoader.java index c09ad88f..c90d17a5 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/loader/PlayerLoader.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/loader/PlayerLoader.java @@ -1,12 +1,12 @@ -package io.tofpu.speedbridge2.domain.player.loader; +package io.tofpu.speedbridge2.model.player.loader; import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Expiry; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.meta.BoardRetrieve; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.meta.BoardRetrieve; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.checkerframework.checker.index.qual.NonNegative; import org.jetbrains.annotations.NotNull; @@ -27,7 +27,6 @@ public BridgePlayer load(final @NotNull UUID key) throws Exception { @Override public CompletableFuture asyncLoad(final UUID key, final Executor executor) { - // TODO: maybe pass down the executor return retrieveAsync(key, executor); } @@ -36,7 +35,8 @@ public BridgePlayer retrieve(final @NotNull UUID uniqueId) { BridgePlayer bridgePlayer; try { - BridgeUtil.debug("attempting to load " + uniqueId + " player's data!"); + BridgeUtil.debug("PlayerLoader#retrieve: Attempting to load " + uniqueId + + " player data!"); bridgePlayer = retrieveAsync(uniqueId, PluginExecutor.INSTANCE).get(); } catch (InterruptedException | ExecutionException e) { @@ -67,13 +67,11 @@ public long expireAfterCreate(final UUID key, final BridgePlayer value, final lo @Override public long expireAfterUpdate(final UUID key, final BridgePlayer value, final long currentTime, @NonNegative final long currentDuration) { - System.out.println("expireAfterUpdate - Start"); - System.out.println(Duration.ofNanos(currentDuration).getSeconds()); + BridgeUtil.debug("PlayerRemovalListener#expireAfterUpdate: Start: " + Duration.ofNanos(currentDuration).getSeconds()); if (value.getPlayer() == null) { - System.out.println("expiring the bridge player after 5 minutes"); + BridgeUtil.debug("PlayerRemovalListener#expireAfterUpdate: Expiring " + key + " player data after 5 minutes!"); return EXPIRY_DURATION; } - System.out.println("expireAfterUpdate - End"); return Long.MAX_VALUE; } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/block/BlockChoice.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/block/BlockChoice.java similarity index 89% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/block/BlockChoice.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/block/BlockChoice.java index 73556a43..286f5d95 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/block/BlockChoice.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/block/BlockChoice.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.player.misc.block; +package io.tofpu.speedbridge2.model.player.misc.block; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/block/BlockDatabase.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/block/BlockDatabase.java similarity index 65% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/block/BlockDatabase.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/block/BlockDatabase.java index 60c27e39..a6543829 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/block/BlockDatabase.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/block/BlockDatabase.java @@ -1,11 +1,10 @@ -package io.tofpu.speedbridge2.domain.player.misc.block; +package io.tofpu.speedbridge2.model.player.misc.block; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.wrapper.Database; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseTable; -import io.tofpu.speedbridge2.domain.common.util.DatabaseUtil; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.common.database.wrapper.Database; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseTable; +import io.tofpu.speedbridge2.model.common.util.DatabaseUtil; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; @@ -19,7 +18,7 @@ public BlockDatabase() { } public CompletableFuture insert(final @NotNull BridgePlayer player) { - return DatabaseUtil.databaseQueryExecute("INSERT OR IGNORE INTO blocks VALUES (?, ?)", databaseQuery -> { + return DatabaseUtil.databaseExecute("INSERT OR IGNORE INTO blocks VALUES (?, ?)", databaseQuery -> { databaseQuery.setString(player.getPlayerUid() .toString()); databaseQuery.setString(player.getChoseMaterial() @@ -28,8 +27,8 @@ public CompletableFuture insert(final @NotNull BridgePlayer player) { } public CompletableFuture update(final @NotNull BridgePlayer player) { - return DatabaseUtil.databaseQueryExecute("UPDATE blocks SET chosen_block = ? " + - "WHERE uid = ?", databaseQuery -> { + return DatabaseUtil.databaseExecute("UPDATE blocks SET chosen_block = ? " + + "WHERE uid = ?", databaseQuery -> { databaseQuery.setString(player.getChoseMaterial() .name()); databaseQuery.setString(player.getPlayerUid() @@ -58,21 +57,15 @@ public CompletableFuture getStoredMaterial(final @NotNull UUID uniqueI material.set(Material.matchMaterial(name)); }); } catch (Exception e) { - e.printStackTrace(); + throw new IllegalStateException(e); } return material.get(); }); } public CompletableFuture delete(final UUID uuid) { - return PluginExecutor.runAsync(() -> { - try (final DatabaseQuery query = DatabaseQuery.query( - "SELECT * FROM blocks WHERE " + "uid = ?")) { - query.setString(uuid.toString()); - query.execute(); - } catch (Exception e) { - throw new IllegalStateException(e); - } + return DatabaseUtil.databaseExecute("DELETE FROM blocks WHERE uid = ?", query -> { + query.setString(uuid.toString()); }); } } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/score/Score.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/score/Score.java similarity index 92% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/score/Score.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/score/Score.java index 3ea13608..64f22747 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/score/Score.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/score/Score.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.player.misc.score; +package io.tofpu.speedbridge2.model.player.misc.score; import org.jetbrains.annotations.NotNull; @@ -17,7 +17,7 @@ public static Score of(final int islandSlot, final double score) { return new Score(islandSlot, score); } - public Score(final int scoredOn, final double score) { + private Score(final int scoredOn, final double score) { this.scoredOn = scoredOn; this.score = score; } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/score/ScoreDatabase.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/score/ScoreDatabase.java similarity index 79% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/score/ScoreDatabase.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/score/ScoreDatabase.java index 39b9eea1..01d45706 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/score/ScoreDatabase.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/score/ScoreDatabase.java @@ -1,11 +1,11 @@ -package io.tofpu.speedbridge2.domain.player.misc.score; - -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.wrapper.Database; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseTable; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.DatabaseUtil; +package io.tofpu.speedbridge2.model.player.misc.score; + +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.database.wrapper.Database; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseTable; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.DatabaseUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -22,7 +22,7 @@ public ScoreDatabase() { public @NotNull CompletableFuture insert(final @NotNull UUID uuid, final @NotNull Score score) { - return DatabaseUtil.databaseQueryExecute( + return DatabaseUtil.databaseExecute( "INSERT OR IGNORE INTO scores (uid, island_slot, score) VALUES " + "(?, ?, ?)", databaseQuery -> { BridgeUtil.debug("player uid: " + uuid); @@ -39,8 +39,8 @@ public ScoreDatabase() { public @NotNull CompletableFuture update(final @NotNull UUID uuid, final @NotNull Score score) { - return DatabaseUtil.databaseQueryExecute("UPDATE scores SET island_slot = ?, " + - "score = ? WHERE uid = ?", databaseQuery -> { + return DatabaseUtil.databaseExecute("UPDATE scores SET island_slot = ?, " + + "score = ? WHERE uid = ?", databaseQuery -> { BridgeUtil.debug("player uid: " + uuid); BridgeUtil.debug("player score island: " + score.getScoredOn()); @@ -67,8 +67,8 @@ public ScoreDatabase() { scores.add(score); } }); - } catch (Exception exception) { - exception.printStackTrace(); + } catch (Exception e) { + throw new IllegalStateException(e); } return scores; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/session/SessionScore.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/session/SessionScore.java similarity index 72% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/session/SessionScore.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/session/SessionScore.java index 09a93635..184e4163 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/session/SessionScore.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/session/SessionScore.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.player.misc.session; +package io.tofpu.speedbridge2.model.player.misc.session; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.misc.score.Score; import java.util.Collection; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/setup/SetupMeta.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/setup/SetupMeta.java similarity index 85% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/setup/SetupMeta.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/setup/SetupMeta.java index 0f7b856e..b8ebe945 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/setup/SetupMeta.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/setup/SetupMeta.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.player.misc.setup; +package io.tofpu.speedbridge2.model.player.misc.setup; public interface SetupMeta { /** diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/PlayerStat.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/PlayerStat.java similarity index 90% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/PlayerStat.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/PlayerStat.java index df162e6a..96e51664 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/PlayerStat.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/PlayerStat.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.player.misc.stat; +package io.tofpu.speedbridge2.model.player.misc.stat; import java.util.UUID; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/PlayerStatType.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/PlayerStatType.java similarity index 88% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/PlayerStatType.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/PlayerStatType.java index 631b65d7..0728c155 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/PlayerStatType.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/PlayerStatType.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.player.misc.stat; +package io.tofpu.speedbridge2.model.player.misc.stat; -import io.tofpu.speedbridge2.domain.player.misc.stat.type.SimplePlayerStat; +import io.tofpu.speedbridge2.model.player.misc.stat.type.SimplePlayerStat; import java.util.Locale; import java.util.UUID; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/StatsDatabase.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/StatsDatabase.java similarity index 76% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/StatsDatabase.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/StatsDatabase.java index c646516a..b39d190c 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/StatsDatabase.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/StatsDatabase.java @@ -1,11 +1,11 @@ -package io.tofpu.speedbridge2.domain.player.misc.stat; +package io.tofpu.speedbridge2.model.player.misc.stat; -import io.tofpu.speedbridge2.domain.common.PluginExecutor; -import io.tofpu.speedbridge2.domain.common.database.wrapper.Database; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseQuery; -import io.tofpu.speedbridge2.domain.common.database.wrapper.DatabaseTable; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.common.util.DatabaseUtil; +import io.tofpu.speedbridge2.model.common.PluginExecutor; +import io.tofpu.speedbridge2.model.common.database.wrapper.Database; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseQuery; +import io.tofpu.speedbridge2.model.common.database.wrapper.DatabaseTable; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.common.util.DatabaseUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -15,7 +15,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import static io.tofpu.speedbridge2.domain.common.util.DatabaseUtil.runAsync; +import static io.tofpu.speedbridge2.model.common.util.DatabaseUtil.runAsync; public final class StatsDatabase extends Database { public StatsDatabase() { @@ -23,7 +23,7 @@ public StatsDatabase() { } public @NotNull CompletableFuture insert(final @NotNull PlayerStat playerStat) { - return DatabaseUtil.databaseQueryExecute( + return DatabaseUtil.databaseExecute( "INSERT OR IGNORE INTO stats (uid, key, value) VALUES " + "(?, ?, ?)", databaseQuery -> { databaseQuery.setString(playerStat.getOwner() @@ -34,8 +34,8 @@ public StatsDatabase() { } public @NotNull CompletableFuture update(final @NotNull PlayerStat playerStat) { - return DatabaseUtil.databaseQueryExecute("UPDATE stats SET value = ? WHERE " + - "uid = ? AND key = ?", databaseQuery -> { + return DatabaseUtil.databaseExecute("UPDATE stats SET value = ? WHERE " + + "uid = ? AND key = ?", databaseQuery -> { databaseQuery.setString(playerStat.getValue()); databaseQuery.setString(playerStat.getOwner() @@ -49,7 +49,7 @@ public StatsDatabase() { final List playerStats = new ArrayList<>(); try { - DatabaseUtil.databaseQueryExecute("SELECT * FROM stats WHERE uid = ?", databaseQuery -> { + DatabaseUtil.databaseExecute("SELECT * FROM stats WHERE uid = ?", databaseQuery -> { databaseQuery.setString(owner.toString()); databaseQuery.executeQuery(resultSet -> { @@ -68,7 +68,7 @@ public StatsDatabase() { }) .get(); } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + throw new IllegalStateException(e); } return playerStats; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/type/SimplePlayerStat.java b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/type/SimplePlayerStat.java similarity index 89% rename from src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/type/SimplePlayerStat.java rename to src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/type/SimplePlayerStat.java index 6d2bc4db..3aa0b0c1 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/misc/stat/type/SimplePlayerStat.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/misc/stat/type/SimplePlayerStat.java @@ -1,8 +1,8 @@ -package io.tofpu.speedbridge2.domain.player.misc.stat.type; +package io.tofpu.speedbridge2.model.player.misc.stat.type; import com.google.common.base.Objects; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStat; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStat; import java.util.UUID; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/object/BridgePlayer.java b/src/main/java/io/tofpu/speedbridge2/model/player/object/BridgePlayer.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/domain/player/object/BridgePlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/player/object/BridgePlayer.java index e7d76926..454f96fd 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/object/BridgePlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/object/BridgePlayer.java @@ -1,19 +1,19 @@ -package io.tofpu.speedbridge2.domain.player.object; - -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.database.Databases; -import io.tofpu.speedbridge2.domain.extra.leaderboard.Leaderboard; -import io.tofpu.speedbridge2.domain.island.IslandService; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.island.object.IslandBoard; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.misc.block.BlockChoice; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.misc.session.SessionScore; -import io.tofpu.speedbridge2.domain.player.misc.setup.SetupMeta; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStat; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStatType; -import io.tofpu.speedbridge2.domain.player.object.extra.CommonBridgePlayer; +package io.tofpu.speedbridge2.model.player.object; + +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.database.Databases; +import io.tofpu.speedbridge2.model.leaderboard.Leaderboard; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.island.object.IslandBoard; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.misc.block.BlockChoice; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.misc.session.SessionScore; +import io.tofpu.speedbridge2.model.player.misc.setup.SetupMeta; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStat; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStatType; +import io.tofpu.speedbridge2.model.player.object.extra.CommonBridgePlayer; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -233,7 +233,7 @@ public PlayerStat findStatBy(final PlayerStatType playerStatType) { /** * This function resets the player's stats, score, and session data * - * @return Nothing. + * @return a completable future when the player is wiped from the database */ public CompletableFuture reset() { this.scoreMap.clear(); @@ -380,7 +380,7 @@ public void leaveGame() { if (currentGame == null) { return; } - currentGame.leave(this); + currentGame.stopGame(); } /** diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java b/src/main/java/io/tofpu/speedbridge2/model/player/object/GamePlayer.java similarity index 87% rename from src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/player/object/GamePlayer.java index 0025139d..5776caab 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/object/GamePlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/object/GamePlayer.java @@ -1,8 +1,8 @@ -package io.tofpu.speedbridge2.domain.player.object; +package io.tofpu.speedbridge2.model.player.object; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.island.plot.IslandPlot; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.island.plot.IslandPlot; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -10,7 +10,6 @@ import java.util.*; public final class GamePlayer { - private static final Map GAME_PLAYER_MAP = new HashMap<>(); private final BridgePlayer player; private final List blockLocations; @@ -25,8 +24,7 @@ public final class GamePlayer { * @return A GamePlayer object. */ public static GamePlayer of(final BridgePlayer player) { - return GAME_PLAYER_MAP.computeIfAbsent(player.getPlayerUid(), - uuid -> new GamePlayer(player)); + return new GamePlayer(player); } private GamePlayer(final BridgePlayer player) { @@ -171,13 +169,6 @@ public boolean hasTimerStarted() { return this.timer != -1; } - /** - * Remove the player from the game - */ - public void remove() { - GAME_PLAYER_MAP.remove(this.getBridgePlayer().getPlayerUid()); - } - public Collection getPlacedBlocks() { return Collections.unmodifiableCollection(blockLocations); } diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/CommonBridgePlayer.java b/src/main/java/io/tofpu/speedbridge2/model/player/object/extra/CommonBridgePlayer.java similarity index 87% rename from src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/CommonBridgePlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/player/object/extra/CommonBridgePlayer.java index 1acc5970..8fb769e0 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/CommonBridgePlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/object/extra/CommonBridgePlayer.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.player.object.extra; +package io.tofpu.speedbridge2.model.player.object.extra; import org.bukkit.command.CommandSender; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/DummyBridgePlayer.java b/src/main/java/io/tofpu/speedbridge2/model/player/object/extra/DummyBridgePlayer.java similarity index 69% rename from src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/DummyBridgePlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/player/object/extra/DummyBridgePlayer.java index 8958c4bd..50685515 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/DummyBridgePlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/object/extra/DummyBridgePlayer.java @@ -1,6 +1,6 @@ -package io.tofpu.speedbridge2.domain.player.object.extra; +package io.tofpu.speedbridge2.model.player.object.extra; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; import java.util.UUID; diff --git a/src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/SenderBridgePlayer.java b/src/main/java/io/tofpu/speedbridge2/model/player/object/extra/SenderBridgePlayer.java similarity index 89% rename from src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/SenderBridgePlayer.java rename to src/main/java/io/tofpu/speedbridge2/model/player/object/extra/SenderBridgePlayer.java index 93a97ed4..7d913cd6 100644 --- a/src/main/java/io/tofpu/speedbridge2/domain/player/object/extra/SenderBridgePlayer.java +++ b/src/main/java/io/tofpu/speedbridge2/model/player/object/extra/SenderBridgePlayer.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.domain.player.object.extra; +package io.tofpu.speedbridge2.model.player.object.extra; import org.bukkit.command.CommandSender; diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/PluginExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/PluginExpansion.java similarity index 85% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/PluginExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/PluginExpansion.java index f850be34..c6d8aaa3 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/PluginExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/PluginExpansion.java @@ -1,8 +1,8 @@ -package io.tofpu.speedbridge2.support.placeholderapi; +package io.tofpu.speedbridge2.model.support.placeholderapi; -import io.tofpu.speedbridge2.domain.player.PlayerService; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.ExpansionHandler; +import io.tofpu.speedbridge2.model.player.PlayerService; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.ExpansionHandler; import me.clip.placeholderapi.expansion.PlaceholderExpansion; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/AbstractExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/AbstractExpansion.java similarity index 71% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/AbstractExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/AbstractExpansion.java index b744a228..d0e68c08 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/AbstractExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/AbstractExpansion.java @@ -1,7 +1,7 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; public abstract class AbstractExpansion { public AbstractExpansion() { diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/ExpansionHandler.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/ExpansionHandler.java similarity index 90% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/ExpansionHandler.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/ExpansionHandler.java index c9872968..ae8bba1a 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/ExpansionHandler.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/ExpansionHandler.java @@ -1,7 +1,7 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions.TotalStatsExpansion; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions.TotalStatsExpansion; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/BestScoreExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/BestScoreExpansion.java similarity index 63% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/BestScoreExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/BestScoreExpansion.java index 2c232345..48579fdc 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/BestScoreExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/BestScoreExpansion.java @@ -1,12 +1,12 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; @AutoRegister public final class BestScoreExpansion extends AbstractExpansion { @@ -17,7 +17,7 @@ public String getIdentifier() { @Override public String getDefaultAction(final BridgePlayer bridgePlayer) { - return BridgeUtil.translateMiniMessageLegacy(Message.INSTANCE.emptyScoreFormat); + return BridgeUtil.miniMessageToLegacy(Message.INSTANCE.emptyScoreFormat); } @Override diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/BlocksExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/BlocksExpansion.java similarity index 70% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/BlocksExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/BlocksExpansion.java index 7ed3a31f..72e79220 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/BlocksExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/BlocksExpansion.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; @AutoRegister public final class BlocksExpansion extends AbstractExpansion { diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java similarity index 69% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java index ffdb4325..6cab0d21 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/IslandSlotExpansion.java @@ -1,10 +1,10 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.island.object.extra.GameIsland; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.island.object.extra.GameIsland; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; @AutoRegister public final class IslandSlotExpansion extends AbstractExpansion { diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java similarity index 73% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java index 88ab68c6..cd84b97c 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/LeaderboardExpansion.java @@ -1,17 +1,17 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.common.Message; -import io.tofpu.speedbridge2.domain.common.config.manager.ConfigurationManager; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.Leaderboard; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.island.IslandService; -import io.tofpu.speedbridge2.domain.island.object.Island; -import io.tofpu.speedbridge2.domain.player.misc.score.Score; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.common.Message; +import io.tofpu.speedbridge2.model.common.config.manager.ConfigurationManager; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.Leaderboard; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.island.IslandService; +import io.tofpu.speedbridge2.model.island.object.Island; +import io.tofpu.speedbridge2.model.player.misc.score.Score; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; @AutoRegister public final class LeaderboardExpansion extends AbstractExpansion { @@ -48,7 +48,7 @@ public String runAction(final BridgePlayer bridgePlayer, // if board player is null, return the empty session leaderboard message if (boardPlayer == null) { - return BridgeUtil.translateMiniMessageLegacy(Message.INSTANCE.emptySessionLeaderboard); + return BridgeUtil.miniMessageToLegacy(Message.INSTANCE.emptySessionLeaderboard); } } else { final int slot = parse(args, 1); diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/PositionExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/PositionExpansion.java similarity index 81% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/PositionExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/PositionExpansion.java index eaba2e4f..d378fa34 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/PositionExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/PositionExpansion.java @@ -1,13 +1,13 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.extra.leaderboard.Leaderboard; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.BoardPlayer; -import io.tofpu.speedbridge2.domain.extra.leaderboard.wrapper.IslandBoardPlayer; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.leaderboard.Leaderboard; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.BoardPlayer; +import io.tofpu.speedbridge2.model.leaderboard.wrapper.IslandBoardPlayer; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/TimerExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/TimerExpansion.java similarity index 69% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/TimerExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/TimerExpansion.java index 32568bbb..be018025 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/TimerExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/TimerExpansion.java @@ -1,10 +1,10 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; import io.tofpu.dynamicclass.meta.AutoRegister; -import io.tofpu.speedbridge2.domain.common.util.BridgeUtil; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.common.util.BridgeUtil; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; @AutoRegister public final class TimerExpansion extends AbstractExpansion { diff --git a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java similarity index 72% rename from src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java index 4fd76d45..36fd908b 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/placeholderapi/expansion/expansions/TotalStatsExpansion.java @@ -1,9 +1,9 @@ -package io.tofpu.speedbridge2.support.placeholderapi.expansion.expansions; +package io.tofpu.speedbridge2.model.support.placeholderapi.expansion.expansions; -import io.tofpu.speedbridge2.domain.player.misc.stat.PlayerStatType; -import io.tofpu.speedbridge2.domain.player.object.BridgePlayer; -import io.tofpu.speedbridge2.domain.player.object.GamePlayer; -import io.tofpu.speedbridge2.support.placeholderapi.expansion.AbstractExpansion; +import io.tofpu.speedbridge2.model.player.misc.stat.PlayerStatType; +import io.tofpu.speedbridge2.model.player.object.BridgePlayer; +import io.tofpu.speedbridge2.model.player.object.GamePlayer; +import io.tofpu.speedbridge2.model.support.placeholderapi.expansion.AbstractExpansion; public final class TotalStatsExpansion extends AbstractExpansion { private final String identifier; diff --git a/src/main/java/io/tofpu/speedbridge2/support/worldedit/CuboidRegion.java b/src/main/java/io/tofpu/speedbridge2/model/support/worldedit/CuboidRegion.java similarity index 96% rename from src/main/java/io/tofpu/speedbridge2/support/worldedit/CuboidRegion.java rename to src/main/java/io/tofpu/speedbridge2/model/support/worldedit/CuboidRegion.java index 91d4f707..0fee5742 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/worldedit/CuboidRegion.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/worldedit/CuboidRegion.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.support.worldedit; +package io.tofpu.speedbridge2.model.support.worldedit; import io.tofpu.multiworldedit.VectorWrapper; diff --git a/src/main/java/io/tofpu/speedbridge2/support/worldedit/Vector.java b/src/main/java/io/tofpu/speedbridge2/model/support/worldedit/Vector.java similarity index 91% rename from src/main/java/io/tofpu/speedbridge2/support/worldedit/Vector.java rename to src/main/java/io/tofpu/speedbridge2/model/support/worldedit/Vector.java index a19f6c37..c4895ab1 100644 --- a/src/main/java/io/tofpu/speedbridge2/support/worldedit/Vector.java +++ b/src/main/java/io/tofpu/speedbridge2/model/support/worldedit/Vector.java @@ -1,4 +1,4 @@ -package io.tofpu.speedbridge2.support.worldedit; +package io.tofpu.speedbridge2.model.support.worldedit; public class Vector { private final double x, y, z;