Added some languages, a configurable cooldown and tab-completion.

This commit is contained in:
2025-09-01 06:20:01 +02:00
parent 70c91b4ad2
commit e37b176a3e
2 changed files with 49 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
@@ -14,13 +15,15 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
public class InfiniteHomes extends JavaPlugin {
public class InfiniteHomes extends JavaPlugin implements TabCompleter {
private Map<UUID, Map<String, Location>> homes;
private Map<UUID, Long> cooldowns;
@@ -45,6 +48,10 @@ public class InfiniteHomes extends JavaPlugin {
getConfig().options().copyDefaults(true);
saveConfig();
// TabCompleter registrieren
getCommand("home").setTabCompleter(this);
getCommand("delhome").setTabCompleter(this);
getLogger().info("InfiniteHomes plugin enabled!");
}
@@ -54,6 +61,43 @@ public class InfiniteHomes extends JavaPlugin {
getLogger().info("InfiniteHomes plugin disabled!");
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> completions = new ArrayList<>();
// Nur für Spieler und für die Befehle home und delhome
if (!(sender instanceof Player) || (!command.getName().equalsIgnoreCase("home") &&
!command.getName().equalsIgnoreCase("delhome"))) {
return completions;
}
Player player = (Player) sender;
UUID playerUuid = player.getUniqueId();
// Wenn der Spieler keine Homes hat, leere Liste zurückgeben
if (!homes.containsKey(playerUuid) || homes.get(playerUuid).isEmpty()) {
return completions;
}
// Home-Namen des Spielers holen
Set<String> homeNames = homes.get(playerUuid).keySet();
// Wenn kein Argument vorhanden ist, alle Home-Namen zurückgeben
if (args.length == 0 || args[0].isEmpty()) {
completions.addAll(homeNames);
} else {
// Home-Namen filtern, die mit dem eingegebenen Text beginnen
String input = args[0].toLowerCase();
for (String home : homeNames) {
if (home.toLowerCase().startsWith(input)) {
completions.add(home);
}
}
}
return completions;
}
private void setupHomesConfig() {
if (!getDataFolder().exists()) {
getDataFolder().mkdirs();

View File

@@ -10,12 +10,15 @@ commands:
delhome:
description: Delete a home with the given name.
usage: /delhome <name>
aliases: [deletehome]
home:
description: Teleport to a home with the given name.
usage: /home <name>
aliases: [h]
homes:
description: List all your homes.
usage: /homes
aliases: [listhomes]
homecount:
description: Set the global home limit (OP only).
usage: /homecount <number>