Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/main/java/net/pikzstudios/LobbyCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import lombok.SneakyThrows;
import net.pikzstudios.command.DiscordCommand;
import net.pikzstudios.command.LobbyCommand;
import net.pikzstudios.command.LobbyCoreCommand;
import net.pikzstudios.command.StoreCommand;
import net.pikzstudios.command.admin.SetLobbyCommand;
import net.pikzstudios.manager.DiscordManager;
import net.pikzstudios.manager.LobbyManager;
import net.pikzstudios.utils.ConfigUtil;
import net.pikzstudios.utils.FileUtil;
import net.pikzstudios.utils.PlaceholderUtil;
Expand All @@ -31,14 +34,19 @@ public void onEnable() {
FileUtil.load("config.yml");
FileUtil.load("discord.yml");
FileUtil.load("lang.yml");
FileUtil.load("lobby.yml");

if (ConfigUtil.devMode()) {
getLogger().info("Developer mode is enabled!");
}

new LobbyManager();

this.foliaLib = new FoliaLib(this);
this.discordManager = new DiscordManager();

new LobbyCoreCommand();
new SetLobbyCommand();
new LobbyCommand();
new DiscordCommand();
new StoreCommand();
Expand Down
73 changes: 24 additions & 49 deletions src/main/java/net/pikzstudios/command/LobbyCommand.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,57 @@
package net.pikzstudios.command;

import net.pikzstudios.LobbyCore;
import net.pikzstudios.manager.LobbyManager;
import net.pikzstudios.utils.ConfigUtil;
import net.pikzstudios.utils.FileUtil;
import net.pikzstudios.utils.MessageUtil;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

public class LobbyCommand implements CommandExecutor, TabCompleter {
/**
* LobbyCommand
*
* @author Kai
* @since 5/23/2026
*/
public class LobbyCommand implements CommandExecutor {

private static final List<String> SUBCOMMANDS = List.of("reload");
private final LobbyManager lobbyManager = LobbyManager.getInstance();

public LobbyCommand() {
Objects.requireNonNull(LobbyCore.getInstance().getCommand("lobbycore")).setExecutor(this);
Objects.requireNonNull(LobbyCore.getInstance().getCommand("lobby")).setExecutor(this);
}

@Override
public boolean onCommand(final @NotNull CommandSender sender, final @NotNull Command command, final @NotNull String label, final @NotNull String[] args) {
if (!ConfigUtil.commandEnabled("lobbycore")) return true;
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String @NotNull [] args) {
if (!ConfigUtil.commandEnabled("lobby")) return true;
if (!(sender instanceof final Player player)) return false;

final String permission = ConfigUtil.commandPermission("lobbycore");
final String permission = ConfigUtil.commandPermission("lobby");
if (!permission.isEmpty() && !sender.hasPermission(permission)) {
MessageUtil.send(sender, "no-permission");
return true;
}

if (args.length == 0) {
MessageUtil.send(sender, "usage");
final Location lobbyLocation = lobbyManager.getLobbyLocation();

if (lobbyLocation == null) {
MessageUtil.send(sender, "no-lobby-location");
return true;
}

if (args[0].equalsIgnoreCase("reload")) {
handleReload(sender);
if (args.length == 0) {
player.teleport(lobbyLocation);
MessageUtil.send(player, "teleport-success");
return true;
}

MessageUtil.send(sender, "usage");
MessageUtil.send(player, "teleport-usage");
return true;
}

private void handleReload(final @NotNull CommandSender sender) {
final long start = System.currentTimeMillis();

try {
FileUtil.reloadAll();
LobbyCore.getInstance().getDiscordManager().reload();
} catch (Exception e) {
MessageUtil.send(sender, "reload-failed", Map.of("%error%", String.valueOf(e.getMessage())));
return;
}

final long took = System.currentTimeMillis() - start;
MessageUtil.send(sender, "reload-success", Map.of("%time%", String.valueOf(took)));
}

@Override
public @NotNull List<String> onTabComplete(final @NotNull CommandSender sender, final @NotNull Command command, final @NotNull String label, final @NotNull String[] args) {
final String permission = ConfigUtil.commandPermission("lobbycore");
if (!permission.isEmpty() && !sender.hasPermission(permission)) return List.of();

if (args.length == 1) {
final String partial = args[0].toLowerCase(Locale.ROOT);
final List<String> result = new ArrayList<>();
for (final String sub : SUBCOMMANDS) {
if (sub.startsWith(partial)) result.add(sub);
}
return result;
}

return List.of();
}
}
82 changes: 82 additions & 0 deletions src/main/java/net/pikzstudios/command/LobbyCoreCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package net.pikzstudios.command;

import net.pikzstudios.LobbyCore;
import net.pikzstudios.utils.ConfigUtil;
import net.pikzstudios.utils.FileUtil;
import net.pikzstudios.utils.MessageUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

public class LobbyCoreCommand implements CommandExecutor, TabCompleter {

private static final List<String> SUBCOMMANDS = List.of("reload");

public LobbyCoreCommand() {
Objects.requireNonNull(LobbyCore.getInstance().getCommand("lobbycore")).setExecutor(this);
}

@Override
public boolean onCommand(final @NotNull CommandSender sender, final @NotNull Command command, final @NotNull String label, final @NotNull String[] args) {
if (!ConfigUtil.commandEnabled("lobbycore")) return true;

final String permission = ConfigUtil.commandPermission("lobbycore");
if (!permission.isEmpty() && !sender.hasPermission(permission)) {
MessageUtil.send(sender, "no-permission");
return true;
}

if (args.length == 0) {
MessageUtil.send(sender, "usage");
return true;
}

if (args[0].equalsIgnoreCase("reload")) {
handleReload(sender);
return true;
}

MessageUtil.send(sender, "usage");
return true;
}

private void handleReload(final @NotNull CommandSender sender) {
final long start = System.currentTimeMillis();

try {
FileUtil.reloadAll();
LobbyCore.getInstance().getDiscordManager().reload();
} catch (Exception e) {
MessageUtil.send(sender, "reload-failed", Map.of("%error%", String.valueOf(e.getMessage())));
return;
}

final long took = System.currentTimeMillis() - start;
MessageUtil.send(sender, "reload-success", Map.of("%time%", String.valueOf(took)));
}

@Override
public @NotNull List<String> onTabComplete(final @NotNull CommandSender sender, final @NotNull Command command, final @NotNull String label, final @NotNull String[] args) {
final String permission = ConfigUtil.commandPermission("lobbycore");
if (!permission.isEmpty() && !sender.hasPermission(permission)) return List.of();

if (args.length == 1) {
final String partial = args[0].toLowerCase(Locale.ROOT);
final List<String> result = new ArrayList<>();
for (final String sub : SUBCOMMANDS) {
if (sub.startsWith(partial)) result.add(sub);
}
return result;
}

return List.of();
}
}
48 changes: 48 additions & 0 deletions src/main/java/net/pikzstudios/command/admin/SetLobbyCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.pikzstudios.command.admin;

import net.pikzstudios.LobbyCore;
import net.pikzstudios.manager.LobbyManager;
import net.pikzstudios.utils.ConfigUtil;
import net.pikzstudios.utils.MessageUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Objects;

/**
* SetLobbyCommand
*
* @author Kai
* @since 5/23/2026
*/
public class SetLobbyCommand implements CommandExecutor {

public SetLobbyCommand() {
Objects.requireNonNull(LobbyCore.getInstance().getCommand("setlobby")).setExecutor(this);
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String @NotNull [] args) {
if (!ConfigUtil.commandEnabled("setlobby")) return true;
if (!(sender instanceof final Player player)) return false;

final String permission = ConfigUtil.commandPermission("setlobby");
if (!permission.isEmpty() && !sender.hasPermission(permission)) {
MessageUtil.send(sender, "no-permission");
return true;
}

if (args.length == 0) {
LobbyManager.getInstance().saveLobby(player);
MessageUtil.send(sender, "lobby-set-success");
return true;
}

MessageUtil.send(sender, "setlobby-usage");
return true;
}
}
16 changes: 16 additions & 0 deletions src/main/java/net/pikzstudios/listener/PlayerJoinListener.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package net.pikzstudios.listener;

import net.kyori.adventure.text.Component;
import net.pikzstudios.utils.ConfigUtil;
import net.pikzstudios.utils.MessageUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.jetbrains.annotations.NotNull;

import net.pikzstudios.LobbyCore;

import java.util.Map;

public class PlayerJoinListener implements Listener {

public PlayerJoinListener() {
Expand All @@ -15,5 +22,14 @@ public PlayerJoinListener() {

@EventHandler
public void onPlayerJoin(final @NotNull PlayerJoinEvent event) {
final var player = event.getPlayer();

event.joinMessage(Component.empty());

if (ConfigUtil.joinEnabled()) {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
MessageUtil.send(onlinePlayer, "player-join", Map.of("%player%", player.getName()));
}
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/net/pikzstudios/listener/PlayerQuitListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package net.pikzstudios.listener;

import io.papermc.paper.event.player.AsyncChatEvent;
import net.pikzstudios.utils.ConfigUtil;
import net.pikzstudios.utils.MessageUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -9,6 +13,8 @@

import net.pikzstudios.LobbyCore;

import java.util.Map;

public class PlayerQuitListener implements Listener {

public PlayerQuitListener() {
Expand All @@ -17,6 +23,13 @@ public PlayerQuitListener() {

@EventHandler
public void onPlayerQuit(final @NotNull PlayerQuitEvent event) {
final var player = event.getPlayer();

if (ConfigUtil.leaveEnabled()) {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
MessageUtil.send(onlinePlayer, "player-quit", Map.of("%player%", player.getName()));
}
}
}

@EventHandler(priority = EventPriority.HIGHEST)
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/net/pikzstudios/manager/LobbyManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.pikzstudios.manager;

import lombok.Getter;
import net.pikzstudios.utils.FileUtil;
import net.pikzstudios.utils.LocationUtil;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

/**
* MapManager
*
* @author Kai
* @since 5/23/2026
*/
@Getter
public class LobbyManager {

@Getter
private static LobbyManager instance;
private Location lobbyLocation;

public LobbyManager() {
instance = this;
lobbyLocation = load("lobby");
}

private Location load(String path) {
final FileConfiguration spawnConfig = FileUtil.get("lobby.yml");
final String serialized = spawnConfig.getString(path);

if (serialized == null || serialized.isEmpty()) return null;
return LocationUtil.fromString(serialized);
}

public void saveLobby(Player player) {
lobbyLocation = player.getLocation();
save("lobby", lobbyLocation);
}

private void save(String path, Location loc) {
final FileConfiguration spawnConfig = FileUtil.get("lobby.yml");
spawnConfig.set(path, LocationUtil.toString(loc));
FileUtil.save("lobby.yml");
}
}
Loading