Added some languages, a configurable cooldown and tab-completion.
This commit is contained in:
@@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -14,13 +15,15 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
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, Map<String, Location>> homes;
|
||||||
private Map<UUID, Long> cooldowns;
|
private Map<UUID, Long> cooldowns;
|
||||||
@@ -45,6 +48,10 @@ public class InfiniteHomes extends JavaPlugin {
|
|||||||
getConfig().options().copyDefaults(true);
|
getConfig().options().copyDefaults(true);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
|
// TabCompleter registrieren
|
||||||
|
getCommand("home").setTabCompleter(this);
|
||||||
|
getCommand("delhome").setTabCompleter(this);
|
||||||
|
|
||||||
getLogger().info("InfiniteHomes plugin enabled!");
|
getLogger().info("InfiniteHomes plugin enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,6 +61,43 @@ public class InfiniteHomes extends JavaPlugin {
|
|||||||
getLogger().info("InfiniteHomes plugin disabled!");
|
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() {
|
private void setupHomesConfig() {
|
||||||
if (!getDataFolder().exists()) {
|
if (!getDataFolder().exists()) {
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
|
|||||||
@@ -10,15 +10,18 @@ commands:
|
|||||||
delhome:
|
delhome:
|
||||||
description: Delete a home with the given name.
|
description: Delete a home with the given name.
|
||||||
usage: /delhome <name>
|
usage: /delhome <name>
|
||||||
|
aliases: [deletehome]
|
||||||
home:
|
home:
|
||||||
description: Teleport to a home with the given name.
|
description: Teleport to a home with the given name.
|
||||||
usage: /home <name>
|
usage: /home <name>
|
||||||
|
aliases: [h]
|
||||||
homes:
|
homes:
|
||||||
description: List all your homes.
|
description: List all your homes.
|
||||||
usage: /homes
|
usage: /homes
|
||||||
|
aliases: [listhomes]
|
||||||
homecount:
|
homecount:
|
||||||
description: Set the global home limit (OP only).
|
description: Set the global home limit (OP only).
|
||||||
usage: /homecount <number>
|
usage: /homecount <number>
|
||||||
homecooldown:
|
homecooldown:
|
||||||
description: Set the global home cooldown (OP only).
|
description: Set the global home cooldown (OP only).
|
||||||
usage: /homecooldown <seconds>
|
usage: /homecooldown <seconds>
|
||||||
|
|||||||
Reference in New Issue
Block a user