commands: Print custom message if there are no headstones

This commit is contained in:
Sebastian Beckmann
2025-11-12 18:14:23 +01:00
parent 4f28d526c6
commit 83983d6dd7

View File

@@ -8,6 +8,7 @@ import tk.alex3025.headstones.Headstones;
import tk.alex3025.headstones.utils.ConfigFile; import tk.alex3025.headstones.utils.ConfigFile;
import tk.alex3025.headstones.utils.Message; import tk.alex3025.headstones.utils.Message;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class ListHeadstonesCommand extends SubcommandBase { public class ListHeadstonesCommand extends SubcommandBase {
@@ -19,12 +20,17 @@ public class ListHeadstonesCommand extends SubcommandBase {
public boolean onCommand(CommandSender sender, String[] args) { public boolean onCommand(CommandSender sender, String[] args) {
ConfigFile config = Headstones.getInstance().getDatabase(); ConfigFile config = Headstones.getInstance().getDatabase();
ConfigurationSection headstones = config.getConfigurationSection("headstones"); ConfigurationSection headstones = config.getConfigurationSection("headstones");
Set<String> keys = headstones.getKeys(false);
if (keys.isEmpty()) {
Message.sendPrefixedMessage(sender, "&a There are no headstones.");
} else {
Message.sendPrefixedMessage(sender, "&a All headstones:"); Message.sendPrefixedMessage(sender, "&a All headstones:");
headstones.getKeys(false).forEach(headstoneUUID -> { headstones.getKeys(false).forEach(headstoneUUID -> {
ConfigurationSection headstone = headstones.getConfigurationSection(headstoneUUID); ConfigurationSection headstone = headstones.getConfigurationSection(headstoneUUID);
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(headstone.getString("owner"))); 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") + "\")"); Message.sendMessage(sender, "&a " + player.getName() + ": " + headstone.getInt("x") + " " + headstone.getInt("y") + " " + headstone.getInt("z") + " (in world \"" + headstone.getString("world") + "\")");
}); });
}
return true; return true;
} }