diff --git a/build.gradle.kts b/build.gradle.kts index 44ec280..d7e4d0f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,11 +12,14 @@ repositories { maven("https://oss.sonatype.org/content/groups/public/") maven("https://oss.sonatype.org/content/repositories/snapshots/") maven("https://repo.extendedclip.com/releases/") + maven("https://repo.okaeri.cloud/releases") } dependencies { implementation(libs.minimessage) implementation(libs.minimessage.legacy) + implementation(libs.okaeri) + implementation(libs.okaeri.serdes) implementation(libs.bstats) compileOnly(libs.spigot) @@ -48,6 +51,7 @@ tasks { } shade("net.kyori.adventure", "adventure") + shade("eu.okaeri", "okaeri") shade("org.bstats", "bstats") } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ea9d297..fbbad77 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,6 +5,7 @@ papi = "2.11.6" minimessage = "4.25.0" minimessage-legacy = "4.25.0" +okaeri = "5.0.13" bstats = "3.2.1" shadow = "9.3.0" @@ -17,6 +18,8 @@ papi = { module = "me.clip:placeholderapi", version.ref = "papi" } minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "minimessage" } minimessage-legacy = { module = "net.kyori:adventure-text-serializer-legacy", version.ref = "minimessage-legacy" } +okaeri = { module = "eu.okaeri:okaeri-configs-yaml-bukkit", version.ref = "okaeri" } +okaeri-serdes = { module = "eu.okaeri:okaeri-configs-serdes-bukkit", version.ref = "okaeri" } bstats = { module = "org.bstats:bstats-bukkit", version.ref = "bstats" } [plugins ] diff --git a/src/main/java/top/vulpine/simpleLobby/SimpleLobby.java b/src/main/java/top/vulpine/simpleLobby/SimpleLobby.java index 4f6b09c..aa9f554 100644 --- a/src/main/java/top/vulpine/simpleLobby/SimpleLobby.java +++ b/src/main/java/top/vulpine/simpleLobby/SimpleLobby.java @@ -1,10 +1,14 @@ package top.vulpine.simpleLobby; +import eu.okaeri.configs.ConfigManager; +import eu.okaeri.configs.yaml.bukkit.YamlBukkitConfigurer; +import eu.okaeri.configs.yaml.bukkit.serdes.SerdesBukkit; import lombok.Getter; import org.bstats.bukkit.Metrics; import org.bukkit.plugin.java.JavaPlugin; import top.vulpine.simpleLobby.command.SimpleLobbyCommand; import top.vulpine.simpleLobby.command.SpawnCommand; +import top.vulpine.simpleLobby.config.Config; import top.vulpine.simpleLobby.listener.PlayerListener; import top.vulpine.simpleLobby.listener.WorldListener; import top.vulpine.simpleLobby.scheduler.BukkitSchedulerAdapter; @@ -14,6 +18,8 @@ import top.vulpine.simpleLobby.utils.logger.LogLevel; import top.vulpine.simpleLobby.utils.logger.Logger; +import java.io.File; + /** * Main class for the SimpleLobby plugin. * This class initializes the plugin, sets up logging, and registers commands and event listeners. @@ -22,6 +28,8 @@ @Getter public final class SimpleLobby extends JavaPlugin { + private Config configuration; + private ActionParser actionParser; private SchedulerAdapter scheduler; @@ -30,11 +38,23 @@ public final class SimpleLobby extends JavaPlugin { @Override public void onEnable() { - saveDefaultConfig(); + try { + configuration = ConfigManager.create(Config.class, (it) -> { + it.withConfigurer(new YamlBukkitConfigurer(), new SerdesBukkit()); + it.withBindFile(new File(this.getDataFolder(), "config.yml")); + it.saveDefaults(); + it.load(true); + }); + } catch (Exception e) { + Logger.error("Failed to load configuration: " + e.getMessage()); + e.printStackTrace(); + getServer().getPluginManager().disablePlugin(this); + return; + } LogLevel logLevel; try { - logLevel = LogLevel.valueOf(getConfig().getString("log_level")); + logLevel = configuration.logLevel; } catch (IllegalArgumentException e) { Logger.warn("Invalid log level in config, defaulting to INFO"); logLevel = LogLevel.INFO; diff --git a/src/main/java/top/vulpine/simpleLobby/command/SimpleLobbyCommand.java b/src/main/java/top/vulpine/simpleLobby/command/SimpleLobbyCommand.java index 998d3a9..6ac1b12 100644 --- a/src/main/java/top/vulpine/simpleLobby/command/SimpleLobbyCommand.java +++ b/src/main/java/top/vulpine/simpleLobby/command/SimpleLobbyCommand.java @@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; import top.vulpine.simpleLobby.SimpleLobby; import top.vulpine.simpleLobby.command.subCommands.ReloadSubCommand; import top.vulpine.simpleLobby.command.subCommands.SetSpawnSubCommand; @@ -30,7 +31,7 @@ public SimpleLobbyCommand(SimpleLobby plugin) { } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { executeSubCommand(sender, args); return false; @@ -53,7 +54,7 @@ private void executeSubCommand(CommandSender sender, String[] args) { if (!PermissionChecker.hasPermission(sender, "command." + args[0].toLowerCase())) { sender.sendMessage(Colorize.color( - plugin.getConfig().getString("messages.no_permission") + plugin.getConfiguration().messages.noPermission )); return; @@ -69,7 +70,7 @@ private void executeSubCommand(CommandSender sender, String[] args) { } else { sender.sendMessage(Colorize.color( - plugin.getConfig().getString("messages.unknown_command") + plugin.getConfiguration().messages.unknownCommand )); } @@ -77,7 +78,7 @@ private void executeSubCommand(CommandSender sender, String[] args) { } @Override - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { if (args.length == 0) { return Collections.emptyList(); } diff --git a/src/main/java/top/vulpine/simpleLobby/command/SpawnCommand.java b/src/main/java/top/vulpine/simpleLobby/command/SpawnCommand.java index 7a4f3df..37aaa6a 100644 --- a/src/main/java/top/vulpine/simpleLobby/command/SpawnCommand.java +++ b/src/main/java/top/vulpine/simpleLobby/command/SpawnCommand.java @@ -6,11 +6,11 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; import top.vulpine.simpleLobby.SimpleLobby; import top.vulpine.simpleLobby.scheduler.Cancellable; import top.vulpine.simpleLobby.utils.ActionParser; @@ -39,36 +39,39 @@ public SpawnCommand(SimpleLobby plugin) { } @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { if (!PermissionChecker.hasPermission(sender, "command.spawn")) { - sender.sendMessage(Colorize.color(plugin.getConfig().getString("messages.no_permission"))); + sender.sendMessage(Colorize.color(plugin.getConfiguration().messages.noPermission)); return true; } if (!(sender instanceof Player player)) { - sender.sendMessage(Colorize.color(plugin.getConfig().getString("messages.only_players"))); + sender.sendMessage(Colorize.color(plugin.getConfiguration().messages.onlyPlayers)); return true; } - if (!plugin.getConfig().getBoolean("spawn.command.enabled")) { + if (!plugin.getConfiguration().spawn.command.enabled) { return true; } + Location spawn = plugin.getConfiguration().spawn.location; + if (spawn == null || spawn.getWorld() == null) { + player.sendMessage(Colorize.color(plugin.getConfiguration().messages.spawnNotSet)); + return true; + } - FileConfiguration config = plugin.getConfig(); - boolean delayEnabled = config.getBoolean("spawn.command.delay.enabled"); - if (delayEnabled) { + if (plugin.getConfiguration().spawn.command.delay.enabled) { - int seconds = config.getInt("spawn.command.delay.time"); - boolean requireStill = config.getBoolean("spawn.command.delay.require_player_still"); + int seconds = plugin.getConfiguration().spawn.command.delay.time; + boolean requireStill = plugin.getConfiguration().spawn.command.delay.requirePlayerStill; Map placeholders = new HashMap<>(); placeholders.put("time", String.valueOf(seconds)); List actions = requireStill ? - config.getStringList("spawn.actions.delay_started_still") : - config.getStringList("spawn.actions.delay_started"); + plugin.getConfiguration().spawn.actions.delayStartedStill : + plugin.getConfiguration().spawn.actions.delayStarted; actionParser.executeActions(actions, player, 0, placeholders); @@ -82,7 +85,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String tasks.remove(uuid); locations.remove(uuid); - List teleportActions = plugin.getConfig().getStringList("spawn.actions.teleported"); + List teleportActions = plugin.getConfiguration().spawn.actions.teleported; actionParser.executeActions(teleportActions, player, 0, new HashMap<>()); }, seconds * 20L); @@ -100,7 +103,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String PlayerUtils.teleportPlayer(plugin, player); - List teleportActions = config.getStringList("spawn.actions.teleported"); + List teleportActions = plugin.getConfiguration().spawn.actions.teleported; actionParser.executeActions(teleportActions, player, 0, new HashMap<>()); } @@ -109,14 +112,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String } @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { + public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { return List.of(); } @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - if (!plugin.getConfig().getBoolean("spawn.command.delay.require_player_still")) return; + if (!plugin.getConfiguration().spawn.command.delay.requirePlayerStill) return; Player player = event.getPlayer(); UUID uuid = player.getUniqueId(); @@ -131,7 +134,7 @@ public void onPlayerMove(PlayerMoveEvent event) { if (task != null) task.cancel(); locations.remove(uuid); - List cancelActions = plugin.getConfig().getStringList("spawn.actions.teleport_canceled"); + List cancelActions = plugin.getConfiguration().spawn.actions.teleportCanceled; actionParser.executeActions(cancelActions, player, 0, new HashMap<>()); Logger.debug("Player " + player.getName() + " moved while waiting for spawn teleport, teleport canceled."); diff --git a/src/main/java/top/vulpine/simpleLobby/command/subCommands/ReloadSubCommand.java b/src/main/java/top/vulpine/simpleLobby/command/subCommands/ReloadSubCommand.java index b1b4dd1..ae21d7c 100644 --- a/src/main/java/top/vulpine/simpleLobby/command/subCommands/ReloadSubCommand.java +++ b/src/main/java/top/vulpine/simpleLobby/command/subCommands/ReloadSubCommand.java @@ -3,6 +3,7 @@ import lombok.Getter; import org.bukkit.command.CommandSender; import top.vulpine.simpleLobby.command.SimpleLobbyCommand; +import top.vulpine.simpleLobby.config.Config; import top.vulpine.simpleLobby.instance.SubCommand; import top.vulpine.simpleLobby.utils.Colorize; @@ -20,14 +21,14 @@ public ReloadSubCommand(SimpleLobbyCommand command) { @Override public void execute(CommandSender sender, String[] args) { + Config config = command.getPlugin().getConfiguration(); + long startTime = System.currentTimeMillis(); - command.getPlugin().reloadConfig(); - long endTime = System.currentTimeMillis(); - long duration = endTime - startTime; + config.load(); + long duration = System.currentTimeMillis() - startTime; sender.sendMessage(Colorize.color( - command.getPlugin().getConfig().getString("messages.reloaded") - .replace("%time%", String.valueOf(duration)) + config.messages.reloaded.replace("%time%", String.valueOf(duration)) )); } diff --git a/src/main/java/top/vulpine/simpleLobby/command/subCommands/SetSpawnSubCommand.java b/src/main/java/top/vulpine/simpleLobby/command/subCommands/SetSpawnSubCommand.java index fa48de6..5ebca0e 100644 --- a/src/main/java/top/vulpine/simpleLobby/command/subCommands/SetSpawnSubCommand.java +++ b/src/main/java/top/vulpine/simpleLobby/command/subCommands/SetSpawnSubCommand.java @@ -3,9 +3,10 @@ import lombok.Getter; import org.bukkit.Location; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import top.vulpine.simpleLobby.SimpleLobby; import top.vulpine.simpleLobby.command.SimpleLobbyCommand; +import top.vulpine.simpleLobby.config.Config; import top.vulpine.simpleLobby.instance.SubCommand; import top.vulpine.simpleLobby.utils.Colorize; @@ -23,40 +24,27 @@ public SetSpawnSubCommand(SimpleLobbyCommand command) { @Override public void execute(CommandSender sender, String[] args) { + SimpleLobby plugin = command.getPlugin(); + Config config = plugin.getConfiguration(); + if (!(sender instanceof Player player)) { - sender.sendMessage(Colorize.color( - "&7[&f&lS&a&lL&7] &cThis command can only be executed by a player." - )); + sender.sendMessage(Colorize.color(config.messages.onlyPlayers)); return; } Location location = player.getLocation(); - FileConfiguration config = command.getPlugin().getConfig(); - - String world = location.getWorld().getName(); - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - float yaw = location.getYaw(); - float pitch = location.getPitch(); - - config.set("spawn.location.world", world); - config.set("spawn.location.x", x); - config.set("spawn.location.y", y); - config.set("spawn.location.z", z); - config.set("spawn.location.yaw", yaw); - config.set("spawn.location.pitch", pitch); - command.getPlugin().saveConfig(); + config.spawn.location = location; + config.save(); player.sendMessage(Colorize.color( - command.getPlugin().getConfig().getString("messages.spawn_set") - .replace("%world%", world) - .replace("%x%", String.valueOf(x)) - .replace("%y%", String.valueOf(y)) - .replace("%z%", String.valueOf(z)) - .replace("%yaw%", String.valueOf(yaw)) - .replace("%pitch%", String.valueOf(pitch)) + config.messages.spawnSet + .replace("%world%", location.getWorld().getName()) + .replace("%x%", String.valueOf(location.getX())) + .replace("%y%", String.valueOf(location.getY())) + .replace("%z%", String.valueOf(location.getZ())) + .replace("%yaw%", String.valueOf(location.getYaw())) + .replace("%pitch%", String.valueOf(location.getPitch())) )); } diff --git a/src/main/java/top/vulpine/simpleLobby/config/Config.java b/src/main/java/top/vulpine/simpleLobby/config/Config.java new file mode 100644 index 0000000..723c9c9 --- /dev/null +++ b/src/main/java/top/vulpine/simpleLobby/config/Config.java @@ -0,0 +1,368 @@ +package top.vulpine.simpleLobby.config; + +import eu.okaeri.configs.OkaeriConfig; +import eu.okaeri.configs.annotation.Comment; +import eu.okaeri.configs.annotation.CustomKey; +import eu.okaeri.configs.annotation.Header; +import org.bukkit.Location; +import top.vulpine.simpleLobby.utils.logger.LogLevel; + +import java.util.ArrayList; +import java.util.List; + +@Header("SimpleLobby Configuration - By Vulpine (https://vulpine.top)") +@Header("") +@Header("Wherever you see the [actions] tag, you can put in a list all the actions you want to perform in order.") +@Header("These are the actions you can use:") +@Header("") +@Header(" [optional]") +@Header("") +@Header("- \"[COMMAND] ; \"") +@Header("- \"[GAMEMODE] ; \"") +@Header("- \"[TITLE] ; ; [subtitle]; [fadeIn]; [stay]; [fadeOut]\"") +@Header("- \"[ACTIONBAR] <global/player>; <message>\"") +@Header("- \"[MESSAGE] <global/player>; <message>\"") +@Header("- \"[SOUND] <global/player>; <sound>; [volume]; [pitch]\"") +@Header("- \"[DELAY] <milliseconds>\"") +@Header("") +public class Config extends OkaeriConfig { + + @CustomKey("spawn") + public Spawn spawn = new Spawn(); + + public static class Spawn extends OkaeriConfig { + + @CustomKey("command") + public Command command = new Command(); + + public static class Command extends OkaeriConfig { + + @Comment("If enabled, players can use the '/spawn' command to teleport to spawn") + @CustomKey("enabled") + public boolean enabled = true; + + @Comment("If enabled, players will have to wait a certain amount of time before being teleported to spawn") + @CustomKey("delay") + public Delay delay = new Delay(); + + public static class Delay extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + + @Comment("Time in seconds") + @CustomKey("time") + public int time = 3; + + @Comment("If true, the player must not move during the delay time, or else the teleport will be canceled") + @CustomKey("require_player_still") + public boolean requirePlayerStill = true; + + } + + } + + @Comment("If true, players will be teleported to spawn when they join the server") + @CustomKey("tp_on_join") + public boolean tpOnJoin = false; + + @Comment("Can be set using the '/sl setspawn' command in-game") + @CustomKey("location") + public Location location = null; + + @Comment("Placeholders: any PlaceholderAPI placeholder (if installed)") + @CustomKey("actions") + public Actions actions = new Actions(); + + public static class Actions extends OkaeriConfig { + + @Comment("[actions] Placeholders: %time%; requires spawn command delay to be enabled") + @CustomKey("delay_started") + public List<String> delayStarted = new ArrayList<>(List.of( + "[MESSAGE] player; &7[&f&lS&a&lL&7] &aYou will be teleported to spawn in %time% second(s)" + )); + + @Comment("[actions] Placeholders: %time%; requires spawn command delay to be enabled and require_player_still to be true") + @CustomKey("delay_started_still") + public List<String> delayStartedStill = new ArrayList<>(List.of( + "[MESSAGE] player; &7[&f&lS&a&lL&7] &aYou will be teleported to spawn in %time% second(s). Do not move." + )); + + @Comment("[actions] Requires spawn command delay to be enabled and require_player_still to be true") + @CustomKey("teleport_canceled") + public List<String> teleportCanceled = new ArrayList<>(List.of( + "[MESSAGE] player; &7[&f&lS&a&lL&7] &cTeleport to spawn canceled, you moved." + )); + + @Comment("[actions]") + @CustomKey("teleported") + public List<String> teleported = new ArrayList<>(List.of( + "[MESSAGE] player; &7[&f&lS&a&lL&7] &aYou have been teleported to spawn." + )); + + } + + } + + @CustomKey("actions") + public Actions actions = new Actions(); + + public static class Actions extends OkaeriConfig { + + @CustomKey("join") + public Join join = new Join(); + + public static class Join extends OkaeriConfig { + + @Comment("If true, the default join message will not be shown") + @CustomKey("suppress_default_message") + public boolean suppressDefaultMessage = true; + + @CustomKey("enabled") + public boolean enabled = true; + + @Comment("[actions] Placeholders: %player%, any PlaceholderAPI placeholder (if installed)") + @CustomKey("actions") + public List<String> actions = new ArrayList<>(List.of( + "[TITLE] player; &bWelcome to the server!; &7Enjoy your stay!; 20; 60; 20", + "[MESSAGE] global; &b%player% &7has joined the server.", + "[GAMEMODE] player; adventure" + )); + + } + + @CustomKey("quit") + public Quit quit = new Quit(); + + public static class Quit extends OkaeriConfig { + + @Comment("If true, the default quit message will not be shown") + @CustomKey("suppress_default_message") + public boolean suppressDefaultMessage = true; + + @CustomKey("enabled") + public boolean enabled = true; + + @Comment("[actions] Placeholders: %player%, any PlaceholderAPI placeholder (if installed)") + @CustomKey("actions") + public List<String> actions = new ArrayList<>(List.of( + "[MESSAGE] global; &b%player% &7has left the server." + )); + + } + + } + + @Comment("General world options") + @CustomKey("options") + public Options options = new Options(); + + public static class Options extends OkaeriConfig { + + @CustomKey("disable_hunger_loss") + public DisableHungerLoss disableHungerLoss = new DisableHungerLoss(); + + public static class DisableHungerLoss extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = true; + + @CustomKey("whitelist") + public Whitelist whitelist = new Whitelist(); + + public static class Whitelist extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + + @Comment("List of worlds where hunger loss is disabled") + @CustomKey("worlds") + public List<String> worlds = new ArrayList<>(); + + } + + } + + @CustomKey("disable_mob_spawning") + public DisableMobSpawning disableMobSpawning = new DisableMobSpawning(); + + public static class DisableMobSpawning extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = true; + + @CustomKey("whitelist") + public Whitelist whitelist = new Whitelist(); + + public static class Whitelist extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + + @Comment("List of worlds where mob spawning is disabled") + @CustomKey("worlds") + public List<String> worlds = new ArrayList<>(); + + } + + } + + @CustomKey("disable_damage") + public DisableDamage disableDamage = new DisableDamage(); + + public static class DisableDamage extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = true; + + @CustomKey("whitelist") + public Whitelist whitelist = new Whitelist(); + + public static class Whitelist extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + @Comment("List of worlds where damage is disabled") + + @CustomKey("worlds") + public List<String> worlds = new ArrayList<>(); + + } + + } + + @CustomKey("clear_inventory_on_join") + public ClearInventoryOnJoin clearInventoryOnJoin = new ClearInventoryOnJoin(); + + public static class ClearInventoryOnJoin extends OkaeriConfig { + @CustomKey("enabled") + public boolean enabled = true; + } + + @CustomKey("clear_effects_on_join") + public ClearEffectsOnJoin clearEffectsOnJoin = new ClearEffectsOnJoin(); + + public static class ClearEffectsOnJoin extends OkaeriConfig { + @CustomKey("enabled") + public boolean enabled = false; + } + + @CustomKey("disable_block_placing") + public DisableBlockPlacing disableBlockPlacing = new DisableBlockPlacing(); + + public static class DisableBlockPlacing extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = true; + + @Comment("If true, players in creative mode can place blocks") + @CustomKey("creative_bypass") + public boolean creativeBypass = true; + + @CustomKey("whitelist") + public Whitelist whitelist = new Whitelist(); + + public static class Whitelist extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + + @Comment("List of worlds where block placing is disabled") + @CustomKey("worlds") + public List<String> worlds = new ArrayList<>(); + + } + + } + + @CustomKey("disable_block_breaking") + public DisableBlockBreaking disableBlockBreaking = new DisableBlockBreaking(); + + public static class DisableBlockBreaking extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = true; + + @Comment("If true, players in creative mode can break blocks") + @CustomKey("creative_bypass") + public boolean creativeBypass = true; + + @CustomKey("whitelist") + public Whitelist whitelist = new Whitelist(); + + public static class Whitelist extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + + @Comment("List of worlds where block breaking is disabled") + @CustomKey("worlds") + public List<String> worlds = new ArrayList<>(); + + } + + } + + @CustomKey("disable_block_interaction") + public DisableBlockInteraction disableBlockInteraction = new DisableBlockInteraction(); + + public static class DisableBlockInteraction extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = true; + + @Comment("If true, players in creative mode can interact with blocks") + @CustomKey("creative_bypass") + public boolean creativeBypass = true; + + @CustomKey("whitelist") + public Whitelist whitelist = new Whitelist(); + + public static class Whitelist extends OkaeriConfig { + + @CustomKey("enabled") + public boolean enabled = false; + + @Comment("List of worlds where block interaction is disabled") + @CustomKey("worlds") + public List<String> worlds = new ArrayList<>(); + + } + + } + + } + + @CustomKey("messages") + public Messages messages = new Messages(); + + public static class Messages extends OkaeriConfig { + + @CustomKey("no_permission") + public String noPermission = "&7[&f&lS&a&lL&7] &cMissing permission!"; + + @CustomKey("only_players") + public String onlyPlayers = "&7[&f&lS&a&lL&7] &cThis command can only be executed by players."; + + @Comment("Placeholders: %time%") + @CustomKey("reloaded") + public String reloaded = "&7[&f&lS&a&lL&7] &aConfiguration reloaded in &f%time%ms&a."; + + @Comment("Placeholders: %world%, %x%, %y%, %z%, %yaw%, %pitch%") + @CustomKey("spawn_set") + public String spawnSet = "&7[&f&lS&a&lL&7] &aSuccessfully set the spawn in &f%world%&a at &f%x%&a, &f%y%&a, &f%z%&a, &fyaw:%yaw%&a, &fpitch:%pitch%&a."; + + @CustomKey("spawn_not_set") + public String spawnNotSet = "&7[&f&lS&a&lL&7] &cThe spawn has not been set yet. Contact an administrator."; + + @CustomKey("unknown_command") + public String unknownCommand = "&7[&f&lS&a&lL&7] &cUnknown command!"; + + } + + @Comment("Log level for the plugin. Can be: DEBUG, INFO, WARN, ERROR.") + @Comment("Leave as it is if you don't know what to choose.") + @CustomKey("log_level") + public LogLevel logLevel = LogLevel.INFO; + +} diff --git a/src/main/java/top/vulpine/simpleLobby/listener/PlayerListener.java b/src/main/java/top/vulpine/simpleLobby/listener/PlayerListener.java index 4d2d20c..cf2c9d8 100644 --- a/src/main/java/top/vulpine/simpleLobby/listener/PlayerListener.java +++ b/src/main/java/top/vulpine/simpleLobby/listener/PlayerListener.java @@ -1,7 +1,5 @@ package top.vulpine.simpleLobby.listener; -import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -29,29 +27,29 @@ public PlayerListener(SimpleLobby plugin) { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - if (plugin.getConfig().getBoolean("actions.join.suppress_default_message")) { + if (plugin.getConfiguration().actions.join.suppressDefaultMessage) { event.setJoinMessage(null); Logger.debug("Join message suppressed for player: " + event.getPlayer().getName()); } - if (plugin.getConfig().getBoolean("options.clear_inventory_on_join.enabled")) { + if (plugin.getConfiguration().options.clearInventoryOnJoin.enabled) { event.getPlayer().getInventory().clear(); Logger.debug("Inventory cleared for player: " + event.getPlayer().getName()); } - if (plugin.getConfig().getBoolean("options.clear_effects_on_join.enabled")) { + if (plugin.getConfiguration().options.clearEffectsOnJoin.enabled) { event.getPlayer().getActivePotionEffects().forEach(effect -> event.getPlayer().removePotionEffect(effect.getType()) ); Logger.debug("Potion effects cleared for player: " + event.getPlayer().getName()); } - if (plugin.getConfig().getBoolean("actions.join.enabled")) { + if (plugin.getConfiguration().actions.join.enabled) { Map<String, String> placeholders = new HashMap<>(); placeholders.put("%player%", event.getPlayer().getName()); - plugin.getActionParser().executeActions(plugin.getConfig().getStringList("actions.join.actions"), + plugin.getActionParser().executeActions(plugin.getConfiguration().actions.join.actions, event.getPlayer(), 0, placeholders @@ -59,12 +57,12 @@ public void onPlayerJoin(PlayerJoinEvent event) { } - if (plugin.getConfig().getBoolean("spawn.tp_on_join")) { + if (plugin.getConfiguration().spawn.tpOnJoin) { - String world = plugin.getConfig().getString("spawn.location.world"); - World worldObj = Bukkit.getWorld(world); - if (worldObj == null) { - Logger.warn("World '" + world + "' not found. Cannot teleport player to spawn."); + org.bukkit.Location spawn = plugin.getConfiguration().spawn.location; + if (spawn == null || spawn.getWorld() == null) { + Logger.warn("tp_on_join is enabled but the spawn location is not set. Skipping teleport for " + + event.getPlayer().getName() + "."); } else { PlayerUtils.teleportPlayer(plugin, event.getPlayer()); } @@ -76,17 +74,17 @@ public void onPlayerJoin(PlayerJoinEvent event) { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - if (plugin.getConfig().getBoolean("actions.quit.suppress_default_message")) { + if (plugin.getConfiguration().actions.quit.suppressDefaultMessage) { event.setQuitMessage(null); Logger.debug("Quit message suppressed for player: " + event.getPlayer().getName()); } - if (plugin.getConfig().getBoolean("actions.quit.enabled")) { + if (plugin.getConfiguration().actions.quit.enabled) { Map<String, String> placeholders = new HashMap<>(); placeholders.put("%player%", event.getPlayer().getName()); - plugin.getActionParser().executeActions(plugin.getConfig().getStringList("actions.quit.actions"), + plugin.getActionParser().executeActions(plugin.getConfiguration().actions.quit.actions, event.getPlayer(), 0, placeholders diff --git a/src/main/java/top/vulpine/simpleLobby/listener/WorldListener.java b/src/main/java/top/vulpine/simpleLobby/listener/WorldListener.java index 4572353..c99017f 100644 --- a/src/main/java/top/vulpine/simpleLobby/listener/WorldListener.java +++ b/src/main/java/top/vulpine/simpleLobby/listener/WorldListener.java @@ -38,9 +38,9 @@ public void onLungerLoss(FoodLevelChangeEvent event) { return; } - boolean enabled = plugin.getConfig().getBoolean("options.disable_hunger_loss.enabled"); - boolean whitelistEnabled = plugin.getConfig().getBoolean("options.disable_hunger_loss.whitelist.enabled"); - List<String> whitelistedWorlds = plugin.getConfig().getStringList("options.disable_hunger_loss.whitelist.worlds"); + boolean enabled = plugin.getConfiguration().options.disableHungerLoss.enabled; + boolean whitelistEnabled = plugin.getConfiguration().options.disableHungerLoss.whitelist.enabled; + List<String> whitelistedWorlds = plugin.getConfiguration().options.disableHungerLoss.whitelist.worlds; String world = player.getWorld().getName(); if (enabled && (!whitelistEnabled || whitelistedWorlds.contains(world))) { event.setCancelled(true); @@ -52,9 +52,9 @@ public void onLungerLoss(FoodLevelChangeEvent event) { @EventHandler public void onMobSpawn(CreatureSpawnEvent event) { - boolean enabled = plugin.getConfig().getBoolean("options.disable_mob_spawning.enabled"); - boolean whitelistEnabled = plugin.getConfig().getBoolean("options.disable_mob_spawning.whitelist.enabled"); - List<String> whitelistedWorlds = plugin.getConfig().getStringList("options.disable_mob_spawning.whitelist.worlds"); + boolean enabled = plugin.getConfiguration().options.disableMobSpawning.enabled; + boolean whitelistEnabled = plugin.getConfiguration().options.disableMobSpawning.whitelist.enabled; + List<String> whitelistedWorlds = plugin.getConfiguration().options.disableMobSpawning.whitelist.worlds; String world = event.getLocation().getWorld().getName(); if (enabled && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && (!whitelistEnabled || whitelistedWorlds.contains(world))) { @@ -71,9 +71,9 @@ public void onDamage(EntityDamageEvent event) { return; } - boolean enabled = plugin.getConfig().getBoolean("options.disable_damage.enabled"); - boolean whitelistEnabled = plugin.getConfig().getBoolean("options.disable_damage.whitelist.enabled"); - List<String> whitelistedWorlds = plugin.getConfig().getStringList("options.disable_damage.whitelist.worlds"); + boolean enabled = plugin.getConfiguration().options.disableDamage.enabled; + boolean whitelistEnabled = plugin.getConfiguration().options.disableDamage.whitelist.enabled; + List<String> whitelistedWorlds = plugin.getConfiguration().options.disableDamage.whitelist.worlds; String world = player.getWorld().getName(); if (enabled && (!whitelistEnabled || whitelistedWorlds.contains(world))) { event.setCancelled(true); @@ -85,12 +85,12 @@ public void onDamage(EntityDamageEvent event) { @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - boolean enabled = plugin.getConfig().getBoolean("options.disable_block_placing.enabled"); + boolean enabled = plugin.getConfiguration().options.disableBlockPlacing.enabled; if (enabled) { - boolean creativeBypass = plugin.getConfig().getBoolean("options.disable_block_placing.creative_bypass"); + boolean creativeBypass = plugin.getConfiguration().options.disableBlockPlacing.creativeBypass; if (!(event.getPlayer().getGameMode() == GameMode.CREATIVE && creativeBypass)) { - boolean whitelistEnabled = plugin.getConfig().getBoolean("options.disable_block_placing.whitelist.enabled"); - List<String> whitelistedWorlds = plugin.getConfig().getStringList("options.disable_block_placing.whitelist.worlds"); + boolean whitelistEnabled = plugin.getConfiguration().options.disableBlockPlacing.whitelist.enabled; + List<String> whitelistedWorlds = plugin.getConfiguration().options.disableBlockPlacing.whitelist.worlds; String world = event.getPlayer().getWorld().getName(); if (!whitelistEnabled || whitelistedWorlds.contains(world)) { event.setCancelled(true); @@ -104,12 +104,12 @@ public void onBlockPlace(BlockPlaceEvent event) { @EventHandler public void onBlockBreak(BlockBreakEvent event) { - boolean enabled = plugin.getConfig().getBoolean("options.disable_block_breaking.enabled"); + boolean enabled = plugin.getConfiguration().options.disableBlockBreaking.enabled; if (enabled) { - boolean creativeBypass = plugin.getConfig().getBoolean("options.disable_block_breaking.creative_bypass"); + boolean creativeBypass = plugin.getConfiguration().options.disableBlockBreaking.creativeBypass; if (!(event.getPlayer().getGameMode() == GameMode.CREATIVE && creativeBypass)) { - boolean whitelistEnabled = plugin.getConfig().getBoolean("options.disable_block_breaking.whitelist.enabled"); - List<String> whitelistedWorlds = plugin.getConfig().getStringList("options.disable_block_breaking.whitelist.worlds"); + boolean whitelistEnabled = plugin.getConfiguration().options.disableBlockBreaking.whitelist.enabled; + List<String> whitelistedWorlds = plugin.getConfiguration().options.disableBlockBreaking.whitelist.worlds; String world = event.getPlayer().getWorld().getName(); if (!whitelistEnabled || whitelistedWorlds.contains(world)) { event.setCancelled(true); @@ -123,12 +123,12 @@ public void onBlockBreak(BlockBreakEvent event) { @EventHandler(priority = EventPriority.LOWEST) public void onBlockInteraction(PlayerInteractEvent event) { - boolean enabled = plugin.getConfig().getBoolean("options.disable_block_interaction.enabled"); + boolean enabled = plugin.getConfiguration().options.disableBlockInteraction.enabled; if (enabled) { - boolean creativeBypass = plugin.getConfig().getBoolean("options.disable_block_interaction.creative_bypass"); + boolean creativeBypass = plugin.getConfiguration().options.disableBlockInteraction.creativeBypass; if (!(event.getPlayer().getGameMode() == GameMode.CREATIVE && creativeBypass)) { - boolean whitelistEnabled = plugin.getConfig().getBoolean("options.disable_block_interaction.whitelist.enabled"); - List<String> whitelistedWorlds = plugin.getConfig().getStringList("options.disable_block_interaction.whitelist.worlds"); + boolean whitelistEnabled = plugin.getConfiguration().options.disableBlockInteraction.whitelist.enabled; + List<String> whitelistedWorlds = plugin.getConfiguration().options.disableBlockInteraction.whitelist.worlds; String world = event.getPlayer().getWorld().getName(); if (!whitelistEnabled || whitelistedWorlds.contains(world)) { diff --git a/src/main/java/top/vulpine/simpleLobby/utils/PlayerUtils.java b/src/main/java/top/vulpine/simpleLobby/utils/PlayerUtils.java index df76bd1..732541d 100644 --- a/src/main/java/top/vulpine/simpleLobby/utils/PlayerUtils.java +++ b/src/main/java/top/vulpine/simpleLobby/utils/PlayerUtils.java @@ -1,9 +1,5 @@ package top.vulpine.simpleLobby.utils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import top.vulpine.simpleLobby.SimpleLobby; import top.vulpine.simpleLobby.utils.logger.Logger; @@ -21,23 +17,12 @@ public class PlayerUtils { */ public static void teleportPlayer(SimpleLobby plugin, Player player) { - FileConfiguration config = plugin.getConfig(); + plugin.getScheduler().teleport(player, plugin.getConfiguration().spawn.location); - World world = Bukkit.getWorld(config.getString("spawn.location.world")); - if (world == null) { - Logger.warn("World does not exist"); - return; - } - - double x = config.getDouble("spawn.location.x"); - double y = config.getDouble("spawn.location.y"); - double z = config.getDouble("spawn.location.z"); - float yaw = (float) config.getDouble("spawn.location.yaw"); - float pitch = (float) config.getDouble("spawn.location.pitch"); - - plugin.getScheduler().teleport(player, new Location(world, x, y, z, yaw, pitch)); - - Logger.debug("Teleported player " + player.getName() + " to spawn at " + world + " (" + x + ", " + y + ", " + z + ")"); + Logger.debug("Teleported player " + player.getName() + " to spawn at " + plugin.getConfiguration().spawn.location.getWorld() + " (" + + plugin.getConfiguration().spawn.location.getX() + ", " + + plugin.getConfiguration().spawn.location.getY() + ", " + + plugin.getConfiguration().spawn.location.getZ() + ")"); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index f722ce0..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,103 +0,0 @@ -# Simple Lobby Configuration - By Vulpine (https://vulpine.top) - -# Wherever you see the [actions] tag, you can put in a list all the actions you want to perform in order. -# These are the actions you can use: -# -# <required> [optional] -# -# - "[COMMAND] <console/player>; <command without slash>" -# - "[GAMEMODE] <global/player>; <gamemode>" -# - "[TITLE] <global/player>; <title>; [subtitle]; [fadeIn]; [stay]; [fadeOut]" -# - "[ACTIONBAR] <global/player>; <message>" -# - "[MESSAGE] <global/player>; <message>" -# - "[SOUND] <global/player>; <sound>; [volume]; [pitch]" -# - "[DELAY] <milliseconds>" - -spawn: - command: # If enabled, players can use the '/spawn' command to teleport to spawn - enabled: true - delay: # If enabled, players will have to wait a certain amount of time before being teleported to spawn - enabled: false - time: 3 # Time in seconds - require_player_still: true # If true, the player must not move during the delay time, or else the teleport will be canceled - tp_on_join: false # If true, players will be teleported to spawn when they join the server - location: # Can be set using the '/sl setspawn' command in-game - world: world - x: 0 - y: 0 - z: 0 - yaw: 0 - pitch: 0 - actions: # Placeholders: any PlaceholderAPI placeholder (if installed) - delay_started: # [actions] Placeholders: %time%; requires spawn command delay to be enabled - - "[MESSAGE] player; &7[&f&lS&a&lL&7] &aYou will be teleported to spawn in %time% second(s)" - delay_started_still: # [actions] Placeholders: %time%; requires spawn command delay to be enabled and require_player_still to be true - - "[MESSAGE] player; &7[&f&lS&a&lL&7] &aYou will be teleported to spawn in %time% second(s). Do not move." - teleport_canceled: # [actions] Requires spawn command delay to be enabled and require_player_still to be true - - "[MESSAGE] player; &7[&f&lS&a&lL&7] &cTeleport to spawn canceled, you moved." - teleported: # [actions] - - "[MESSAGE] player; &7[&f&lS&a&lL&7] &aYou have been teleported to spawn." - -actions: - join: - suppress_default_message: true # If true, the default join message will not be shown - enabled: true - actions: # [actions] Placeholders: %player%, any PlaceholderAPI placeholder (if installed) - - "[TITLE] player; &bWelcome to the server!; &7Enjoy your stay!; 20; 60; 20" - - "[MESSAGE] global; &b%player% &7has joined the server." - - "[GAMEMODE] player; adventure" - quit: - suppress_default_message: true # If true, the default quit message will not be shown - enabled: true - actions: # [actions] Placeholders: %player%, any PlaceholderAPI placeholder (if installed) - - "[MESSAGE] global; &b%player% &7has left the server." - -options: # General world options - disable_hunger_loss: - enabled: true - whitelist: - enabled: false - worlds: [] # List of worlds where hunger loss is disabled - disable_mob_spawning: - enabled: true - whitelist: - enabled: false - worlds: [] # List of worlds where mob spawning is disabled - disable_damage: - enabled: true - whitelist: - enabled: false - worlds: [] # List of worlds where damage is disabled - clear_inventory_on_join: - enabled: true - clear_effects_on_join: - enabled: false - disable_block_placing: - enabled: true - creative_bypass: true # If true, players in creative mode can place blocks - whitelist: - enabled: false - worlds: [] # List of worlds where block placing is disabled - disable_block_breaking: - enabled: true - creative_bypass: true # If true, players in creative mode can break blocks - whitelist: - enabled: false - worlds: [] # List of worlds where block breaking is disabled - disable_block_interaction: - enabled: true - creative_bypass: true # If true, players in creative mode can interact with blocks - whitelist: - enabled: false - worlds: [] # List of worlds where block interaction is disabled - -messages: - no_permission: "&7[&f&lS&a&lL&7] &cMissing permission!" - only_players: "&7[&f&lS&a&lL&7] &cThis command can only be executed by players." - reloaded: "&7[&f&lS&a&lL&7] &aConfiguration reloaded in &f%time%ms&a." # Placeholders: %time% - spawn_set: "&7[&f&lS&a&lL&7] &aSuccessfully set the spawn in &f%world%&a at &f%x%&a, &f%y%&a, &f%z%&a, &fyaw:%yaw%&a, &fpitch:%pitch%&a." # Placeholders: %world%, %x%, %y%, %z%, %yaw%, %pitch% - unknown_command: "&7[&f&lS&a&lL&7] &cUnknown command!" - -# Log level for the plugin. Can be: DEBUG, INFO, WARN, ERROR. -# Leave as it is if you don't know what to choose. -log_level: INFO \ No newline at end of file