commands: Add headstone list subcommand

This commit is contained in:
Sebastian Beckmann
2025-11-12 12:22:06 +01:00
parent 7057b03c68
commit f092dd61b6
2 changed files with 33 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import tk.alex3025.headstones.commands.HeadstonesCommand; import tk.alex3025.headstones.commands.HeadstonesCommand;
import tk.alex3025.headstones.commands.subcommands.ClearDatabaseCommand; import tk.alex3025.headstones.commands.subcommands.ClearDatabaseCommand;
import tk.alex3025.headstones.commands.subcommands.ListHeadstonesCommand;
import tk.alex3025.headstones.commands.subcommands.ReloadConfigCommand; import tk.alex3025.headstones.commands.subcommands.ReloadConfigCommand;
import tk.alex3025.headstones.listeners.BlockBreakListener; import tk.alex3025.headstones.listeners.BlockBreakListener;
import tk.alex3025.headstones.listeners.PlayerDeathListener; import tk.alex3025.headstones.listeners.PlayerDeathListener;
@@ -50,6 +51,7 @@ public final class Headstones extends JavaPlugin {
// Subcommands // Subcommands
new ClearDatabaseCommand(); new ClearDatabaseCommand();
new ReloadConfigCommand(); new ReloadConfigCommand();
new ListHeadstonesCommand();
} }
public static Headstones getInstance() { public static Headstones getInstance() {

View File

@@ -0,0 +1,31 @@
package tk.alex3025.headstones.commands.subcommands;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import tk.alex3025.headstones.Headstones;
import tk.alex3025.headstones.utils.ConfigFile;
import tk.alex3025.headstones.utils.Message;
import java.util.UUID;
public class ListHeadstonesCommand extends SubcommandBase {
public ListHeadstonesCommand() {
super("list", "headstones.list", false);
}
@Override
public boolean onCommand(CommandSender sender, String[] args) {
ConfigFile config = Headstones.getInstance().getDatabase();
ConfigurationSection headstones = config.getConfigurationSection("headstones");
Message.sendPrefixedMessage(sender, "&a All headstones:");
headstones.getKeys(false).forEach(headstoneUUID -> {
ConfigurationSection headstone = headstones.getConfigurationSection(headstoneUUID);
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(headstone.getString("owner")));
Message.sendMessage(sender, "&a " + player.getName() + ": " + headstone.getInt("x") + " " + headstone.getInt("y") + " " + headstone.getInt("z") + " (in world \"" + headstone.getString("world") + "\")");
});
return true;
}
}