From ea551c54271db5c311642a762962133729d02ff5 Mon Sep 17 00:00:00 2001 From: Taah Date: Thu, 24 Aug 2023 02:43:16 -0700 Subject: [PATCH] Add slime world support for per player worlds Move package to dev.plex.extras to prevent any possible conflicts with main plugin --- build.gradle.kts | 6 + .../java/dev/plex/{ => extras}/TFMExtras.java | 33 ++- .../command/AdminInfoCommand.java | 5 +- .../command/AttributeListCommand.java | 3 +- .../command/AutoClearCommand.java | 5 +- .../command/AutoTeleportCommand.java | 5 +- .../{ => extras}/command/BanListCommand.java | 3 +- .../{ => extras}/command/CakeCommand.java | 3 +- .../{ => extras}/command/CartSitCommand.java | 3 +- .../command/ClearChatCommand.java | 3 +- .../command/CloudClearCommand.java | 3 +- .../{ => extras}/command/EjectCommand.java | 3 +- .../{ => extras}/command/EnchantCommand.java | 3 +- .../command/EnglishMfCommand.java | 3 +- .../{ => extras}/command/JumpPadsCommand.java | 9 +- .../command/RandomFishCommand.java | 5 +- src/main/java/dev/plex/extras/hook/IHook.java | 16 ++ .../dev/plex/extras/hook/SlimeWorldHook.java | 193 ++++++++++++++++++ .../plex/{ => extras}/jumppads/JumpPads.java | 4 +- .../dev/plex/{ => extras}/jumppads/Mode.java | 2 +- .../listener/JumpPadsListener.java | 9 +- .../{ => extras}/listener/PlayerListener.java | 20 +- src/main/resources/module.yml | 2 +- src/main/resources/tfmextras/config.yml | 4 +- 24 files changed, 302 insertions(+), 43 deletions(-) rename src/main/java/dev/plex/{ => extras}/TFMExtras.java (81%) rename src/main/java/dev/plex/{ => extras}/command/AdminInfoCommand.java (92%) rename src/main/java/dev/plex/{ => extras}/command/AttributeListCommand.java (93%) rename src/main/java/dev/plex/{ => extras}/command/AutoClearCommand.java (94%) rename src/main/java/dev/plex/{ => extras}/command/AutoTeleportCommand.java (95%) rename src/main/java/dev/plex/{ => extras}/command/BanListCommand.java (96%) rename src/main/java/dev/plex/{ => extras}/command/CakeCommand.java (95%) rename src/main/java/dev/plex/{ => extras}/command/CartSitCommand.java (97%) rename src/main/java/dev/plex/{ => extras}/command/ClearChatCommand.java (94%) rename src/main/java/dev/plex/{ => extras}/command/CloudClearCommand.java (95%) rename src/main/java/dev/plex/{ => extras}/command/EjectCommand.java (93%) rename src/main/java/dev/plex/{ => extras}/command/EnchantCommand.java (97%) rename src/main/java/dev/plex/{ => extras}/command/EnglishMfCommand.java (96%) rename src/main/java/dev/plex/{ => extras}/command/JumpPadsCommand.java (96%) rename src/main/java/dev/plex/{ => extras}/command/RandomFishCommand.java (92%) create mode 100644 src/main/java/dev/plex/extras/hook/IHook.java create mode 100644 src/main/java/dev/plex/extras/hook/SlimeWorldHook.java rename src/main/java/dev/plex/{ => extras}/jumppads/JumpPads.java (96%) rename src/main/java/dev/plex/{ => extras}/jumppads/Mode.java (68%) rename src/main/java/dev/plex/{ => extras}/listener/JumpPadsListener.java (96%) rename src/main/java/dev/plex/{ => extras}/listener/PlayerListener.java (63%) diff --git a/build.gradle.kts b/build.gradle.kts index 2316f34..f2f052f 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,9 @@ repositories { maven { url = uri("https://nexus.telesphoreo.me/repository/plex/") } + maven { + url = uri("https://repo.infernalsuite.com/repository/maven-snapshots/") + } mavenCentral() } @@ -21,6 +24,9 @@ dependencies { compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") implementation("org.apache.commons:commons-lang3:3.12.0") compileOnly("dev.plex:server:1.3") + compileOnly("com.infernalsuite.aswm:api:1.20-R0.1-SNAPSHOT") { + exclude(group="com.flowpowered") + } } group = "dev.plex" diff --git a/src/main/java/dev/plex/TFMExtras.java b/src/main/java/dev/plex/extras/TFMExtras.java similarity index 81% rename from src/main/java/dev/plex/TFMExtras.java rename to src/main/java/dev/plex/extras/TFMExtras.java index d1c3dc6..a3a44e3 100755 --- a/src/main/java/dev/plex/TFMExtras.java +++ b/src/main/java/dev/plex/extras/TFMExtras.java @@ -1,14 +1,15 @@ -package dev.plex; +package dev.plex.extras; import com.google.common.collect.ImmutableSet; import com.google.common.reflect.ClassPath; +import dev.plex.extras.hook.SlimeWorldHook; +import dev.plex.extras.listener.PlayerListener; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.config.ModuleConfig; -import dev.plex.jumppads.JumpPads; -import dev.plex.listener.JumpPadsListener; -import dev.plex.listener.PlayerListener; +import dev.plex.extras.jumppads.JumpPads; +import dev.plex.extras.listener.JumpPadsListener; import dev.plex.listener.PlexListener; import dev.plex.module.PlexModule; import dev.plex.util.PlexLog; @@ -33,6 +34,9 @@ public class TFMExtras extends PlexModule @Getter private ModuleConfig config; + @Getter + private final SlimeWorldHook slimeWorldHook = new SlimeWorldHook(); + @Override public void load() { @@ -46,12 +50,14 @@ public class TFMExtras extends PlexModule @Override public void enable() { - registerListener(new JumpPadsListener()); - registerListener(new PlayerListener()); - - getClassesFrom("dev.plex.command").forEach(aClass -> + if (slimeWorldHook.plugin() != null) { - if (aClass.getSuperclass() == PlexCommand.class && aClass.isAnnotationPresent(CommandParameters.class) && aClass.isAnnotationPresent(CommandPermissions.class)) + slimeWorldHook.onEnable(this); + } + + getClassesFrom("dev.plex.extras.command").forEach(aClass -> + { + if (PlexCommand.class.isAssignableFrom(aClass) && aClass.isAnnotationPresent(CommandParameters.class) && aClass.isAnnotationPresent(CommandPermissions.class)) { try { @@ -65,9 +71,9 @@ public class TFMExtras extends PlexModule } }); - getClassesFrom("dev.plex.listener").forEach(aClass -> + getClassesFrom("dev.plex.extras.listener").forEach(aClass -> { - if (aClass.getSuperclass() == PlexListener.class) + if (PlexListener.class.isAssignableFrom(aClass)) { try { @@ -88,12 +94,17 @@ public class TFMExtras extends PlexModule addDefaultMessage("attributeList", "All possible attributes: {0}", "0 - The attribute list, each split by a new line"); addDefaultMessage("modifiedAutoClear", "{0} will {1} have their inventory cleared when they join.", "0 - The player who will have their inventory cleared on join", "1 - Whether they had this option toggled (returns: 'no longer', 'now')"); addDefaultMessage("modifiedAutoTeleport", "{0} will {1} be teleported automatically when they join.", "0 - The player to be teleported automatically", "1 - Whether they had this option toggled (returns: 'no longer', 'now')"); + addDefaultMessage("createdPlayerWorld", "Welcome to the server! We've created you a new private world where you can invite your friends! View how to use this using /myworld!"); } @Override public void disable() { // Unregistering listeners / commands is handled by Plex + if (slimeWorldHook.plugin() != null) + { + slimeWorldHook.onDisable(this); + } } public static Location getRandomLocation(World world) diff --git a/src/main/java/dev/plex/command/AdminInfoCommand.java b/src/main/java/dev/plex/extras/command/AdminInfoCommand.java similarity index 92% rename from src/main/java/dev/plex/command/AdminInfoCommand.java rename to src/main/java/dev/plex/extras/command/AdminInfoCommand.java index f5a5aaa..0c54c2c 100755 --- a/src/main/java/dev/plex/command/AdminInfoCommand.java +++ b/src/main/java/dev/plex/extras/command/AdminInfoCommand.java @@ -1,6 +1,7 @@ -package dev.plex.command; +package dev.plex.extras.command; -import dev.plex.TFMExtras; +import dev.plex.extras.TFMExtras; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/AttributeListCommand.java b/src/main/java/dev/plex/extras/command/AttributeListCommand.java similarity index 93% rename from src/main/java/dev/plex/command/AttributeListCommand.java rename to src/main/java/dev/plex/extras/command/AttributeListCommand.java index 62816ce..5349451 100755 --- a/src/main/java/dev/plex/command/AttributeListCommand.java +++ b/src/main/java/dev/plex/extras/command/AttributeListCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/AutoClearCommand.java b/src/main/java/dev/plex/extras/command/AutoClearCommand.java similarity index 94% rename from src/main/java/dev/plex/command/AutoClearCommand.java rename to src/main/java/dev/plex/extras/command/AutoClearCommand.java index 33be783..265fd5e 100755 --- a/src/main/java/dev/plex/command/AutoClearCommand.java +++ b/src/main/java/dev/plex/extras/command/AutoClearCommand.java @@ -1,7 +1,8 @@ -package dev.plex.command; +package dev.plex.extras.command; -import dev.plex.TFMExtras; +import dev.plex.extras.TFMExtras; import dev.plex.cache.DataUtils; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; diff --git a/src/main/java/dev/plex/command/AutoTeleportCommand.java b/src/main/java/dev/plex/extras/command/AutoTeleportCommand.java similarity index 95% rename from src/main/java/dev/plex/command/AutoTeleportCommand.java rename to src/main/java/dev/plex/extras/command/AutoTeleportCommand.java index a986b59..ee9d44f 100755 --- a/src/main/java/dev/plex/command/AutoTeleportCommand.java +++ b/src/main/java/dev/plex/extras/command/AutoTeleportCommand.java @@ -1,7 +1,8 @@ -package dev.plex.command; +package dev.plex.extras.command; -import dev.plex.TFMExtras; +import dev.plex.extras.TFMExtras; import dev.plex.cache.DataUtils; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.exception.PlayerNotFoundException; diff --git a/src/main/java/dev/plex/command/BanListCommand.java b/src/main/java/dev/plex/extras/command/BanListCommand.java similarity index 96% rename from src/main/java/dev/plex/command/BanListCommand.java rename to src/main/java/dev/plex/extras/command/BanListCommand.java index 1fb5237..752a5cc 100755 --- a/src/main/java/dev/plex/command/BanListCommand.java +++ b/src/main/java/dev/plex/extras/command/BanListCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.punishment.Punishment; diff --git a/src/main/java/dev/plex/command/CakeCommand.java b/src/main/java/dev/plex/extras/command/CakeCommand.java similarity index 95% rename from src/main/java/dev/plex/command/CakeCommand.java rename to src/main/java/dev/plex/extras/command/CakeCommand.java index 35386d4..76c7af3 100755 --- a/src/main/java/dev/plex/command/CakeCommand.java +++ b/src/main/java/dev/plex/extras/command/CakeCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/CartSitCommand.java b/src/main/java/dev/plex/extras/command/CartSitCommand.java similarity index 97% rename from src/main/java/dev/plex/command/CartSitCommand.java rename to src/main/java/dev/plex/extras/command/CartSitCommand.java index a1f26a5..69411bf 100755 --- a/src/main/java/dev/plex/command/CartSitCommand.java +++ b/src/main/java/dev/plex/extras/command/CartSitCommand.java @@ -1,6 +1,7 @@ -package dev.plex.command; +package dev.plex.extras.command; import dev.plex.Plex; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/ClearChatCommand.java b/src/main/java/dev/plex/extras/command/ClearChatCommand.java similarity index 94% rename from src/main/java/dev/plex/command/ClearChatCommand.java rename to src/main/java/dev/plex/extras/command/ClearChatCommand.java index 03cb531..bab41da 100755 --- a/src/main/java/dev/plex/command/ClearChatCommand.java +++ b/src/main/java/dev/plex/extras/command/ClearChatCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/CloudClearCommand.java b/src/main/java/dev/plex/extras/command/CloudClearCommand.java similarity index 95% rename from src/main/java/dev/plex/command/CloudClearCommand.java rename to src/main/java/dev/plex/extras/command/CloudClearCommand.java index 40f4f33..745c975 100755 --- a/src/main/java/dev/plex/command/CloudClearCommand.java +++ b/src/main/java/dev/plex/extras/command/CloudClearCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/EjectCommand.java b/src/main/java/dev/plex/extras/command/EjectCommand.java similarity index 93% rename from src/main/java/dev/plex/command/EjectCommand.java rename to src/main/java/dev/plex/extras/command/EjectCommand.java index 6940441..6acf7b6 100755 --- a/src/main/java/dev/plex/command/EjectCommand.java +++ b/src/main/java/dev/plex/extras/command/EjectCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; diff --git a/src/main/java/dev/plex/command/EnchantCommand.java b/src/main/java/dev/plex/extras/command/EnchantCommand.java similarity index 97% rename from src/main/java/dev/plex/command/EnchantCommand.java rename to src/main/java/dev/plex/extras/command/EnchantCommand.java index ddd6f1e..eda7177 100755 --- a/src/main/java/dev/plex/command/EnchantCommand.java +++ b/src/main/java/dev/plex/extras/command/EnchantCommand.java @@ -1,6 +1,7 @@ -package dev.plex.command; +package dev.plex.extras.command; import com.google.common.collect.Lists; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; diff --git a/src/main/java/dev/plex/command/EnglishMfCommand.java b/src/main/java/dev/plex/extras/command/EnglishMfCommand.java similarity index 96% rename from src/main/java/dev/plex/command/EnglishMfCommand.java rename to src/main/java/dev/plex/extras/command/EnglishMfCommand.java index 1448110..f25c93d 100755 --- a/src/main/java/dev/plex/command/EnglishMfCommand.java +++ b/src/main/java/dev/plex/extras/command/EnglishMfCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.rank.enums.Rank; diff --git a/src/main/java/dev/plex/command/JumpPadsCommand.java b/src/main/java/dev/plex/extras/command/JumpPadsCommand.java similarity index 96% rename from src/main/java/dev/plex/command/JumpPadsCommand.java rename to src/main/java/dev/plex/extras/command/JumpPadsCommand.java index 29a615c..e5a6734 100755 --- a/src/main/java/dev/plex/command/JumpPadsCommand.java +++ b/src/main/java/dev/plex/extras/command/JumpPadsCommand.java @@ -1,11 +1,12 @@ -package dev.plex.command; +package dev.plex.extras.command; -import dev.plex.TFMExtras; +import dev.plex.extras.TFMExtras; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; -import dev.plex.jumppads.JumpPads; -import dev.plex.jumppads.Mode; +import dev.plex.extras.jumppads.JumpPads; +import dev.plex.extras.jumppads.Mode; import dev.plex.rank.enums.Rank; import dev.plex.util.PlexUtils; import net.kyori.adventure.text.Component; diff --git a/src/main/java/dev/plex/command/RandomFishCommand.java b/src/main/java/dev/plex/extras/command/RandomFishCommand.java similarity index 92% rename from src/main/java/dev/plex/command/RandomFishCommand.java rename to src/main/java/dev/plex/extras/command/RandomFishCommand.java index 8ac9e7f..ad0cb25 100755 --- a/src/main/java/dev/plex/command/RandomFishCommand.java +++ b/src/main/java/dev/plex/extras/command/RandomFishCommand.java @@ -1,5 +1,6 @@ -package dev.plex.command; +package dev.plex.extras.command; +import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.source.RequiredCommandSource; @@ -26,7 +27,7 @@ public class RandomFishCommand extends PlexCommand @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args) { - @Nullable Block block = player.getTargetBlock(15); + @Nullable Block block = player.getTargetBlockExact(15); if (block == null) { return MiniMessage.miniMessage().deserialize("There is no block within 15 blocks of you."); diff --git a/src/main/java/dev/plex/extras/hook/IHook.java b/src/main/java/dev/plex/extras/hook/IHook.java new file mode 100644 index 0000000..be073d2 --- /dev/null +++ b/src/main/java/dev/plex/extras/hook/IHook.java @@ -0,0 +1,16 @@ +package dev.plex.extras.hook; + +import dev.plex.extras.TFMExtras; + +/** + * @author Taah + * @since 2:16 PM [23-08-2023] + */ +public interface IHook { + + void onEnable(TFMExtras module); + + void onDisable(TFMExtras module); + + T plugin(); +} \ No newline at end of file diff --git a/src/main/java/dev/plex/extras/hook/SlimeWorldHook.java b/src/main/java/dev/plex/extras/hook/SlimeWorldHook.java new file mode 100644 index 0000000..5e3fabb --- /dev/null +++ b/src/main/java/dev/plex/extras/hook/SlimeWorldHook.java @@ -0,0 +1,193 @@ +package dev.plex.extras.hook; + +import com.google.common.collect.Sets; +import com.infernalsuite.aswm.api.SlimePlugin; +import com.infernalsuite.aswm.api.exceptions.*; +import com.infernalsuite.aswm.api.loaders.SlimeLoader; +import com.infernalsuite.aswm.api.world.SlimeWorld; +import com.infernalsuite.aswm.api.world.properties.SlimeProperties; +import com.infernalsuite.aswm.api.world.properties.SlimePropertyMap; +import dev.plex.extras.TFMExtras; +import dev.plex.util.PlexLog; +import org.apache.commons.lang3.tuple.Pair; +import org.bukkit.Bukkit; +import org.bukkit.GameRule; +import org.bukkit.Material; +import org.bukkit.World; + +import java.io.IOException; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author Taah + * @since 2:19 PM [23-08-2023] + */ +public class SlimeWorldHook implements IHook +{ + private static final String WORLD_NOT_FOUND = "This world could not be found!"; + private static final String STORAGE_FAILURE = "This world cannot be stored!"; + + private final Set LOADED_WORLDS = Sets.newHashSet(); + + private SlimeLoader loader; + + + @Override + public void onEnable(TFMExtras module) + { + if (plugin() == null) + { + PlexLog.error("Cannot find SlimeWorldManager plugin"); + return; + } + + PlexLog.log("Enabling SWM Hook"); + + this.loader = plugin().getLoader("mysql"); + this.loadAllWorlds(); + } + + @Override + public void onDisable(TFMExtras module) + { + PlexLog.log("Disabling SWM Hook"); + AtomicInteger i = new AtomicInteger(); + LOADED_WORLDS.forEach(s -> + { + final World world = Bukkit.getWorld(s); + if (world != null) + { + world.save(); + i.getAndIncrement(); + } + }); + PlexLog.log("SWM Hook saved " + i.get() + " worlds"); + } + + public void loadAllWorlds() + { + try + { + this.loader.listWorlds().forEach(s -> + { + final SlimePropertyMap slimePropertyMap = new SlimePropertyMap(); + slimePropertyMap.setValue(SlimeProperties.PVP, false); + + try + { + SlimeWorld world = this.plugin().loadWorld(this.loader, s, false, slimePropertyMap); + this.plugin().loadWorld(world); + this.loader.unlockWorld(s); + } + catch (UnknownWorldException | WorldLockedException | CorruptedWorldException | NewerFormatException | IllegalArgumentException ex) + { + PlexLog.error(ex.getMessage()); + } + catch (IOException e) + { + PlexLog.error(STORAGE_FAILURE); + return; + } + + final World world = Bukkit.getWorld(s); + if (world == null) + { + PlexLog.error(WORLD_NOT_FOUND); + return; + } + world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); + world.setGameRule(GameRule.DISABLE_RAIDS, true); + world.setGameRule(GameRule.DO_INSOMNIA, false); + world.setGameRule(GameRule.DO_FIRE_TICK, false); + world.setSpawnLocation(0, 130, 0); + world.setAutoSave(true); + + LOADED_WORLDS.add(s); + + double configuratedSize = TFMExtras.getModule().getConfig().getDouble("player-worlds.size"); + world.getWorldBorder().setCenter(world.getSpawnLocation()); + world.getWorldBorder().setSize(configuratedSize == 0 ? 500 : configuratedSize); + world.getWorldBorder().setDamageAmount(0); + world.getWorldBorder().setDamageBuffer(0); + PlexLog.debug("Loaded {0}", s); + }); + } + catch (IOException | IllegalArgumentException ex) + { + PlexLog.error(ex.getMessage()); + } + } + + public Pair createPlayerWorld(UUID uuid) + { + final SlimePropertyMap slimePropertyMap = new SlimePropertyMap(); + slimePropertyMap.setValue(SlimeProperties.PVP, false); + + boolean newWorld = false; + try + { + slimePropertyMap.setValue(SlimeProperties.SPAWN_X, 0); + slimePropertyMap.setValue(SlimeProperties.SPAWN_Y, 130); + slimePropertyMap.setValue(SlimeProperties.SPAWN_Z, 0); + final SlimeWorld slimeWorld = this.plugin().createEmptyWorld(this.loader, uuid.toString(), false, slimePropertyMap); + this.plugin().loadWorld(slimeWorld); + newWorld = true; + } + catch (WorldAlreadyExistsException e) + { + try + { + SlimeWorld world = this.plugin().loadWorld(this.loader, uuid.toString(), false, slimePropertyMap); + this.plugin().loadWorld(world); + this.loader.unlockWorld(uuid.toString()); + } + catch (WorldLockedException | CorruptedWorldException | NewerFormatException | UnknownWorldException | + IOException | IllegalArgumentException ex) + { + PlexLog.error(ex.getMessage()); + } + + } + catch (IOException e) + { + PlexLog.error(STORAGE_FAILURE); + } + + final World world = Bukkit.getWorld(uuid.toString()); + if (world == null) + { + PlexLog.error(WORLD_NOT_FOUND); + return null; + } + world.setGameRule(GameRule.DO_WEATHER_CYCLE, false); + world.setGameRule(GameRule.DISABLE_RAIDS, true); + world.setGameRule(GameRule.DO_INSOMNIA, false); + world.setGameRule(GameRule.DO_FIRE_TICK, false); + world.setSpawnLocation(0, 130, 0); + world.setAutoSave(true); + + if (newWorld) + { + world.getBlockAt(0, 128, 0).setType(Material.STONE); + } + + LOADED_WORLDS.add(uuid.toString()); + + double configuratedSize = TFMExtras.getModule().getConfig().getDouble("player-worlds.size"); + world.getWorldBorder().setCenter(world.getSpawnLocation()); + world.getWorldBorder().setSize(configuratedSize == 0 ? 500 : configuratedSize); + world.getWorldBorder().setDamageAmount(0); + world.getWorldBorder().setDamageBuffer(0); + + return Pair.of(world, newWorld); + } + + + @Override + public SlimePlugin plugin() + { + return (SlimePlugin) Bukkit.getPluginManager().getPlugin("SlimeWorldManager"); + } +} diff --git a/src/main/java/dev/plex/jumppads/JumpPads.java b/src/main/java/dev/plex/extras/jumppads/JumpPads.java similarity index 96% rename from src/main/java/dev/plex/jumppads/JumpPads.java rename to src/main/java/dev/plex/extras/jumppads/JumpPads.java index f36012e..22b6db3 100755 --- a/src/main/java/dev/plex/jumppads/JumpPads.java +++ b/src/main/java/dev/plex/extras/jumppads/JumpPads.java @@ -1,6 +1,6 @@ -package dev.plex.jumppads; +package dev.plex.extras.jumppads; -import dev.plex.TFMExtras; +import dev.plex.extras.TFMExtras; import org.bukkit.Material; import org.bukkit.Tag; import org.bukkit.block.Block; diff --git a/src/main/java/dev/plex/jumppads/Mode.java b/src/main/java/dev/plex/extras/jumppads/Mode.java similarity index 68% rename from src/main/java/dev/plex/jumppads/Mode.java rename to src/main/java/dev/plex/extras/jumppads/Mode.java index b5f2e4a..df23742 100755 --- a/src/main/java/dev/plex/jumppads/Mode.java +++ b/src/main/java/dev/plex/extras/jumppads/Mode.java @@ -1,4 +1,4 @@ -package dev.plex.jumppads; +package dev.plex.extras.jumppads; public enum Mode { diff --git a/src/main/java/dev/plex/listener/JumpPadsListener.java b/src/main/java/dev/plex/extras/listener/JumpPadsListener.java similarity index 96% rename from src/main/java/dev/plex/listener/JumpPadsListener.java rename to src/main/java/dev/plex/extras/listener/JumpPadsListener.java index f5c6e2e..10f31f5 100755 --- a/src/main/java/dev/plex/listener/JumpPadsListener.java +++ b/src/main/java/dev/plex/extras/listener/JumpPadsListener.java @@ -1,8 +1,9 @@ -package dev.plex.listener; +package dev.plex.extras.listener; -import dev.plex.TFMExtras; -import dev.plex.jumppads.JumpPads; -import dev.plex.jumppads.Mode; +import dev.plex.extras.TFMExtras; +import dev.plex.extras.jumppads.JumpPads; +import dev.plex.extras.jumppads.Mode; +import dev.plex.listener.PlexListener; import dev.plex.util.PlexLog; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; diff --git a/src/main/java/dev/plex/listener/PlayerListener.java b/src/main/java/dev/plex/extras/listener/PlayerListener.java similarity index 63% rename from src/main/java/dev/plex/listener/PlayerListener.java rename to src/main/java/dev/plex/extras/listener/PlayerListener.java index ee22701..bad68cc 100755 --- a/src/main/java/dev/plex/listener/PlayerListener.java +++ b/src/main/java/dev/plex/extras/listener/PlayerListener.java @@ -1,7 +1,12 @@ -package dev.plex.listener; +package dev.plex.extras.listener; import dev.plex.Plex; -import dev.plex.TFMExtras; +import dev.plex.extras.TFMExtras; +import dev.plex.listener.PlexListener; +import dev.plex.util.PlexUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.scheduler.BukkitRunnable; @@ -34,4 +39,15 @@ public class PlayerListener extends PlexListener }.runTaskLater(Plex.get(), 1); } } + + @EventHandler + public void createPlayerWorld(PlayerJoinEvent event) + { + final Player player = event.getPlayer(); + final Pair world = TFMExtras.getModule().getSlimeWorldHook().createPlayerWorld(player.getUniqueId()); + if (world.getRight()) + { + player.sendMessage(PlexUtils.messageComponent("createdPlayerWorld")); + } + } } diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml index ff3772f..8b01a40 100755 --- a/src/main/resources/module.yml +++ b/src/main/resources/module.yml @@ -1,4 +1,4 @@ name: Module-TFMExtras -main: dev.plex.TFMExtras +main: dev.plex.extras.TFMExtras description: TFM extras for Plex version: 1.3 \ No newline at end of file diff --git a/src/main/resources/tfmextras/config.yml b/src/main/resources/tfmextras/config.yml index bf4284c..705961d 100755 --- a/src/main/resources/tfmextras/config.yml +++ b/src/main/resources/tfmextras/config.yml @@ -11,4 +11,6 @@ server: - "Taahh" teleport-on-join: - "Taahh" - allow-unsafe-enchantments: true \ No newline at end of file + allow-unsafe-enchantments: true +player-worlds: + size: 500 \ No newline at end of file