Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -48,6 +51,7 @@ tasks {
}

shade("net.kyori.adventure", "adventure")
shade("eu.okaeri", "okaeri")
shade("org.bstats", "bstats")
}

Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 ]
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/top/vulpine/simpleLobby/SimpleLobby.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand All @@ -22,6 +28,8 @@
@Getter
public final class SimpleLobby extends JavaPlugin {

private Config configuration;

private ActionParser actionParser;
private SchedulerAdapter scheduler;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -69,15 +70,15 @@ private void executeSubCommand(CommandSender sender, String[] args) {
} else {

sender.sendMessage(Colorize.color(
plugin.getConfig().getString("messages.unknown_command")
plugin.getConfiguration().messages.unknownCommand
));

}

}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 0) {
return Collections.emptyList();
}
Expand Down
37 changes: 20 additions & 17 deletions src/main/java/top/vulpine/simpleLobby/command/SpawnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> placeholders = new HashMap<>();
placeholders.put("time", String.valueOf(seconds));

List<String> 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);

Expand All @@ -82,7 +85,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
tasks.remove(uuid);
locations.remove(uuid);

List<String> teleportActions = plugin.getConfig().getStringList("spawn.actions.teleported");
List<String> teleportActions = plugin.getConfiguration().spawn.actions.teleported;
actionParser.executeActions(teleportActions, player, 0, new HashMap<>());
}, seconds * 20L);

Expand All @@ -100,7 +103,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

PlayerUtils.teleportPlayer(plugin, player);

List<String> teleportActions = config.getStringList("spawn.actions.teleported");
List<String> teleportActions = plugin.getConfiguration().spawn.actions.teleported;
actionParser.executeActions(teleportActions, player, 0, new HashMap<>());

}
Expand All @@ -109,14 +112,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}

@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
public List<String> 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();
Expand All @@ -131,7 +134,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
if (task != null) task.cancel();
locations.remove(uuid);

List<String> cancelActions = plugin.getConfig().getStringList("spawn.actions.teleport_canceled");
List<String> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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))
));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()))
));

}
Expand Down
Loading
Loading