Update Projekt - ohne .zip und target
This commit is contained in:
193
src/main/java/de/viper/survivalplus/Manager/CommandBlocker.java
Normal file
193
src/main/java/de/viper/survivalplus/Manager/CommandBlocker.java
Normal file
@@ -0,0 +1,193 @@
|
||||
package de.viper.survivalplus.Manager;
|
||||
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBlocker implements Listener, CommandExecutor {
|
||||
|
||||
private final SurvivalPlus plugin;
|
||||
private FileConfiguration blockedCommandsConfig;
|
||||
private File blockedCommandsFile;
|
||||
private List<String> blockedCommands;
|
||||
|
||||
public CommandBlocker(SurvivalPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
// Lade blockedcommands.yml
|
||||
try {
|
||||
blockedCommandsFile = new File(plugin.getDataFolder(), "blockedcommands.yml");
|
||||
if (!blockedCommandsFile.exists()) {
|
||||
plugin.saveResource("blockedcommands.yml", false);
|
||||
}
|
||||
blockedCommandsConfig = YamlConfiguration.loadConfiguration(blockedCommandsFile);
|
||||
blockedCommands = blockedCommandsConfig.getStringList("blocked-commands");
|
||||
if (blockedCommands == null) {
|
||||
blockedCommands = new ArrayList<>();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
blockedCommands = new ArrayList<>();
|
||||
}
|
||||
|
||||
// Registriere Listener und Command
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
plugin.getCommand("sp").setExecutor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verarbeitet /sp cb Befehle
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length < 2 || !args[0].equalsIgnoreCase("cb")) {
|
||||
return false; // Wird von anderen /sp Subcommands behandelt
|
||||
}
|
||||
|
||||
String subCommand = args[1].toLowerCase();
|
||||
|
||||
switch (subCommand) {
|
||||
case "add":
|
||||
return handleAddCommand(sender, args);
|
||||
case "remove":
|
||||
return handleRemoveCommand(sender, args);
|
||||
case "list":
|
||||
return handleListCommand(sender);
|
||||
default:
|
||||
sender.sendMessage("§cUnbekannter Subcommand! Verfügbare Subcommands: add, remove, list");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /sp cb add <command>
|
||||
*/
|
||||
private boolean handleAddCommand(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("survivalplus.commandblocker.add")) {
|
||||
sender.sendMessage("§cDu hast keine Berechtigung für diesen Befehl!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage("§eBenutzung: /sp cb add <command>");
|
||||
return true;
|
||||
}
|
||||
|
||||
String commandToBlock = args[2].toLowerCase().replaceFirst("^/", "").trim();
|
||||
if (commandToBlock.isEmpty()) {
|
||||
sender.sendMessage("§cBitte gib einen gültigen Befehl an!");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (blockedCommands.contains(commandToBlock)) {
|
||||
sender.sendMessage("§cDer Befehl §e/" + commandToBlock + "§c ist bereits blockiert!");
|
||||
return true;
|
||||
}
|
||||
|
||||
blockedCommands.add(commandToBlock);
|
||||
blockedCommandsConfig.set("blocked-commands", blockedCommands);
|
||||
blockedCommandsConfig.save(blockedCommandsFile);
|
||||
sender.sendMessage("§aDer Befehl §e/" + commandToBlock + "§a wurde zur Blockierliste hinzugefügt.");
|
||||
} catch (Exception ignored) {
|
||||
sender.sendMessage("§cFehler beim Hinzufügen des Befehls!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* /sp cb remove <command>
|
||||
*/
|
||||
private boolean handleRemoveCommand(CommandSender sender, String[] args) {
|
||||
if (!sender.hasPermission("survivalplus.commandblocker.remove")) {
|
||||
sender.sendMessage("§cDu hast keine Berechtigung für diesen Befehl!");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 3) {
|
||||
sender.sendMessage("§eBenutzung: /sp cb remove <command>");
|
||||
return true;
|
||||
}
|
||||
|
||||
String commandToUnblock = args[2].toLowerCase().replaceFirst("^/", "").trim();
|
||||
if (commandToUnblock.isEmpty()) {
|
||||
sender.sendMessage("§cBitte gib einen gültigen Befehl an!");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!blockedCommands.contains(commandToUnblock)) {
|
||||
sender.sendMessage("§cDer Befehl §e/" + commandToUnblock + "§c ist nicht blockiert!");
|
||||
return true;
|
||||
}
|
||||
|
||||
blockedCommands.remove(commandToUnblock);
|
||||
blockedCommandsConfig.set("blocked-commands", blockedCommands);
|
||||
blockedCommandsConfig.save(blockedCommandsFile);
|
||||
sender.sendMessage("§aDer Befehl §e/" + commandToUnblock + "§a wurde aus der Blockierliste entfernt.");
|
||||
} catch (Exception ignored) {
|
||||
sender.sendMessage("§cFehler beim Entfernen des Befehls!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* /sp cb list
|
||||
*/
|
||||
private boolean handleListCommand(CommandSender sender) {
|
||||
if (!sender.hasPermission("survivalplus.commandblocker.list")) {
|
||||
sender.sendMessage("§cDu hast keine Berechtigung für diesen Befehl!");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (blockedCommands.isEmpty()) {
|
||||
sender.sendMessage("§eEs sind keine Befehle blockiert.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("§6=== Blockierte Befehle ===");
|
||||
for (String cmd : blockedCommands) {
|
||||
sender.sendMessage("§e- /" + cmd);
|
||||
}
|
||||
sender.sendMessage("§6=====================");
|
||||
} catch (Exception ignored) {
|
||||
sender.sendMessage("§cFehler beim Abrufen der Blockierliste!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blockiere Befehle, wenn sie in der Liste sind
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("survivalplus.commandblocker.bypass")) {
|
||||
return; // Spieler mit Bypass-Berechtigung ignorieren
|
||||
}
|
||||
|
||||
try {
|
||||
String command = event.getMessage().toLowerCase().replaceFirst("^/", "").trim();
|
||||
// Extrahiere den Hauptbefehl (ohne Argumente)
|
||||
String mainCommand = command.split("\\s+")[0];
|
||||
|
||||
if (blockedCommands.contains(mainCommand)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage("§cDieser Befehl ist blockiert!");
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,21 +3,30 @@ package de.viper.survivalplus.Manager;
|
||||
import de.viper.survivalplus.SurvivalPlus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.ScoreboardManager;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.user.User;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Map;
|
||||
|
||||
public class TablistManager {
|
||||
public class TablistManager implements Listener {
|
||||
|
||||
private final SurvivalPlus plugin;
|
||||
private final List<String> headerAnim = new ArrayList<>();
|
||||
@@ -34,15 +43,39 @@ public class TablistManager {
|
||||
private String staffPermission;
|
||||
private String separatorLine;
|
||||
private LuckPerms luckPerms;
|
||||
private boolean hasPlaceholderAPI;
|
||||
private final Scoreboard scoreboard;
|
||||
private final Map<String, Team> prefixTeams;
|
||||
private FileConfiguration nicknameConfig;
|
||||
|
||||
public TablistManager(SurvivalPlus plugin) {
|
||||
this.plugin = plugin;
|
||||
this.prefixTeams = new HashMap<>();
|
||||
|
||||
// Scoreboard initialisieren
|
||||
ScoreboardManager scoreboardManager = Bukkit.getScoreboardManager();
|
||||
this.scoreboard = scoreboardManager != null ? scoreboardManager.getMainScoreboard() : null;
|
||||
|
||||
// Resource sicherstellen, Config laden
|
||||
try { plugin.saveResource("tablist.yml", false); } catch (Exception ignored) {}
|
||||
try { plugin.reloadTablistConfig(); } catch (Throwable ignored) {}
|
||||
try {
|
||||
plugin.saveResource("tablist.yml", false);
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
plugin.reloadTablistConfig();
|
||||
} catch (Exception ignored) {}
|
||||
FileConfiguration config = plugin.getTablistConfig();
|
||||
|
||||
// Nicknames.yml laden
|
||||
try {
|
||||
File nicknameFile = new File(plugin.getDataFolder(), "nicknames.yml");
|
||||
if (!nicknameFile.exists()) {
|
||||
plugin.saveResource("nicknames.yml", false);
|
||||
}
|
||||
this.nicknameConfig = YamlConfiguration.loadConfiguration(nicknameFile);
|
||||
} catch (Exception ignored) {
|
||||
this.nicknameConfig = null; // Keine Konsolenausgabe
|
||||
}
|
||||
|
||||
// Konfigurationswerte laden
|
||||
this.enabled = config.getBoolean("enabled", true);
|
||||
this.serverName = config.getString("server-name", "SurvivalPlus");
|
||||
@@ -57,13 +90,16 @@ public class TablistManager {
|
||||
// LuckPerms API initialisieren
|
||||
try {
|
||||
this.luckPerms = LuckPermsProvider.get();
|
||||
} catch (IllegalStateException e) {
|
||||
plugin.getLogger().warning("LuckPerms nicht gefunden! Versuche Fallback auf PlaceholderAPI.");
|
||||
} catch (Throwable e) {
|
||||
luckPerms = null; // Keine Konsolenausgabe
|
||||
}
|
||||
|
||||
// Prüfen, ob PlaceholderAPI verfügbar ist
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
plugin.getLogger().warning("PlaceholderAPI nicht gefunden! Verwende Standard-Prefix als Fallback.");
|
||||
this.hasPlaceholderAPI = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
|
||||
// Chat-Listener registrieren
|
||||
if (enabled) {
|
||||
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
@@ -112,17 +148,29 @@ public class TablistManager {
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
// Spieler-Prefix abrufen (LuckPerms primär, PlaceholderAPI als Fallback)
|
||||
String prefix = getPlayerPrefix(player);
|
||||
int ping = getPlayerPing(player);
|
||||
// Korrigierte Formatierung: Gesamten String durch color-Methode leiten
|
||||
String prefixedName = color(prefix + player.getName() + "&8 | &e" + ping + "ms");
|
||||
player.setPlayerListName(prefixedName);
|
||||
// Nickname oder Spielername verwenden
|
||||
String displayName = getNickname(player);
|
||||
if (displayName == null || displayName.trim().isEmpty()) {
|
||||
displayName = player.getName();
|
||||
}
|
||||
|
||||
// Header mit Spielername und Statistiken
|
||||
// Spielername für die Tablist setzen
|
||||
String playerListName;
|
||||
String prefix = getPlayerPrefix(player);
|
||||
if (luckPerms == null && !hasPlaceholderAPI) {
|
||||
playerListName = displayName;
|
||||
updateNametag(player, "", displayName);
|
||||
} else {
|
||||
int ping = getPlayerPing(player);
|
||||
playerListName = color(prefix + displayName + (ping >= 0 ? "&8 | &e" + ping + "ms" : ""));
|
||||
updateNametag(player, prefix, displayName);
|
||||
}
|
||||
player.setPlayerListName(playerListName);
|
||||
|
||||
// Header mit Spielername/Nickname und Statistiken
|
||||
String headerRaw = headerAnim.get(headerIndex)
|
||||
.replace("{server}", serverName)
|
||||
.replace("{player}", player.getName())
|
||||
.replace("{player}", displayName)
|
||||
.replace("{online}", String.valueOf(onlinePlayers))
|
||||
.replace("{staff}", String.valueOf(onlineStaff));
|
||||
String footerRaw = footerAnim.get(footerIndex);
|
||||
@@ -131,7 +179,7 @@ public class TablistManager {
|
||||
StringBuilder footerBuilder = new StringBuilder();
|
||||
footerBuilder.append("\n"); // Extra Abstand
|
||||
footerBuilder.append(color(footerRaw)).append("\n");
|
||||
|
||||
|
||||
footerBuilder.append(color(separatorLine)).append("\n");
|
||||
if (showTeamspeak || showDiscord) {
|
||||
StringBuilder socialLine = new StringBuilder();
|
||||
@@ -161,12 +209,9 @@ public class TablistManager {
|
||||
done = tryStringMethod(player, header, footer);
|
||||
}
|
||||
|
||||
// 3) Wenn alles fehlschlägt -> Log
|
||||
if (!done) {
|
||||
plugin.getLogger().warning("Tablist: Keine geeignete Methode gefunden für Spieler " + player.getName());
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger().log(Level.FINE, "Fehler beim Setzen der Tablist für Spieler " + player.getName(), t);
|
||||
// 3) Keine Warnung bei Fehlschlag, da dies normal sein kann
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe für Fehler bei der Tablist
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,28 +221,170 @@ public class TablistManager {
|
||||
}.runTaskTimer(plugin, 0L, interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nickname aus nicknames.yml abrufen
|
||||
*/
|
||||
private String getNickname(Player player) {
|
||||
if (nicknameConfig == null) return null;
|
||||
try {
|
||||
String uuid = player.getUniqueId().toString();
|
||||
String nickname = nicknameConfig.getString(uuid);
|
||||
if (nickname != null && !nickname.trim().isEmpty()) {
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".nickname", nickname);
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
return nickname;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nametag über dem Kopf aktualisieren
|
||||
*/
|
||||
private void updateNametag(Player player, String prefix, String displayName) {
|
||||
if (scoreboard == null) return;
|
||||
|
||||
try {
|
||||
String teamName = generateTeamName(player, prefix);
|
||||
Team team = scoreboard.getTeam(teamName);
|
||||
|
||||
// Team erstellen oder aktualisieren
|
||||
if (team == null) {
|
||||
team = scoreboard.registerNewTeam(teamName);
|
||||
}
|
||||
|
||||
// Prefix zwingend setzen, wenn LuckPerms installiert ist
|
||||
String coloredPrefix = color(prefix != null && !prefix.trim().isEmpty() ? prefix : (luckPerms != null ? "&7[Spieler] " : ""));
|
||||
team.setPrefix(coloredPrefix);
|
||||
|
||||
// Spieler dem Team hinzufügen
|
||||
String entry = displayName != null && !displayName.trim().isEmpty() ? displayName : player.getName();
|
||||
if (!team.hasEntry(entry)) {
|
||||
// Spieler aus anderen Teams entfernen, um Konflikte zu vermeiden
|
||||
for (Team existingTeam : scoreboard.getTeams()) {
|
||||
if (!existingTeam.getName().equals(teamName)) {
|
||||
existingTeam.removeEntry(entry);
|
||||
existingTeam.removeEntry(player.getName());
|
||||
}
|
||||
}
|
||||
team.addEntry(entry);
|
||||
}
|
||||
|
||||
// Team für alle Spieler sichtbar machen
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.getScoreboard() != scoreboard) {
|
||||
onlinePlayer.setScoreboard(scoreboard);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug-Ausgabe für Nametag
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".nametag_prefix", coloredPrefix);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".nametag_entry", entry);
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Eindeutigen Teamnamen generieren
|
||||
*/
|
||||
private String generateTeamName(Player player, String prefix) {
|
||||
// Verwende UUID für eindeutige Teamnamen, falls kein Prefix vorhanden
|
||||
if (prefix == null || prefix.trim().isEmpty()) {
|
||||
return "nametag_" + player.getUniqueId().toString().substring(0, 8);
|
||||
}
|
||||
// Verwende Prefix für Teamnamen, max 16 Zeichen (Bukkit-Beschränkung)
|
||||
String sanitizedPrefix = prefix.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
|
||||
return "prefix_" + sanitizedPrefix.substring(0, Math.min(sanitizedPrefix.length(), 12));
|
||||
}
|
||||
|
||||
/**
|
||||
* Spieler-Prefix abrufen (LuckPerms primär, PlaceholderAPI als Fallback)
|
||||
*/
|
||||
private String getPlayerPrefix(Player player) {
|
||||
// Versuche LuckPerms-API zuerst
|
||||
// Wenn LuckPerms installiert ist, Prefix zwingend abrufen
|
||||
if (luckPerms != null) {
|
||||
// Versuche LuckPerms-API zuerst
|
||||
try {
|
||||
User user = luckPerms.getPlayerAdapter(Player.class).getUser(player);
|
||||
String prefix = user.getCachedData().getMetaData().getPrefix();
|
||||
return (prefix == null || prefix.isEmpty()) ? "&7[Spieler] " : prefix + " ";
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.FINE, "Fehler beim Abrufen des Prefix aus LuckPerms für Spieler " + player.getName(), e);
|
||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".prefix", prefix);
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
return prefix + " ";
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
|
||||
// Fallback auf PlaceholderAPI, wenn LuckPerms installiert ist
|
||||
if (hasPlaceholderAPI) {
|
||||
try {
|
||||
String prefix = PlaceholderAPI.setPlaceholders(player, "%luckperms_prefix%");
|
||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".prefix", prefix);
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
return prefix + " ";
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
}
|
||||
|
||||
// Standard-Prefix, wenn LuckPerms installiert ist, aber kein Prefix definiert
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".prefix", "&7[Spieler]");
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
return "&7[Spieler] ";
|
||||
}
|
||||
|
||||
// Wenn LuckPerms nicht installiert ist, aber PlaceholderAPI vorhanden ist
|
||||
if (hasPlaceholderAPI) {
|
||||
try {
|
||||
String prefix = PlaceholderAPI.setPlaceholders(player, "%luckperms_prefix%");
|
||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".prefix", prefix);
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
return prefix + " ";
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback auf PlaceholderAPI
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
String prefix = PlaceholderAPI.setPlaceholders(player, "%luckperms_prefix%");
|
||||
return (prefix == null || prefix.isEmpty()) ? "&7[Spieler] " : prefix + " ";
|
||||
}
|
||||
|
||||
// Letzter Fallback: Standard-Prefix
|
||||
// Standard-Prefix, wenn weder LuckPerms noch PlaceholderAPI einen Prefix liefern
|
||||
try {
|
||||
File debugFile = new File(plugin.getDataFolder(), "debug.yml");
|
||||
FileConfiguration debugConfig = YamlConfiguration.loadConfiguration(debugFile);
|
||||
debugConfig.set(player.getUniqueId().toString() + ".prefix", "&7[Spieler]");
|
||||
debugConfig.save(debugFile);
|
||||
} catch (Exception ignored) {}
|
||||
return "&7[Spieler] ";
|
||||
}
|
||||
|
||||
@@ -209,9 +396,28 @@ public class TablistManager {
|
||||
Method getHandle = player.getClass().getMethod("getHandle");
|
||||
Object entityPlayer = getHandle.invoke(player);
|
||||
return entityPlayer.getClass().getField("ping").getInt(entityPlayer);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.FINE, "Fehler beim Abrufen des Pings für Spieler " + player.getName(), e);
|
||||
return -1;
|
||||
} catch (Exception ignored) {
|
||||
return -1; // Keine Konsolenausgabe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chat-Format modifizieren
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
try {
|
||||
Player player = event.getPlayer();
|
||||
String displayName = getNickname(player);
|
||||
if (displayName == null || displayName.trim().isEmpty()) {
|
||||
displayName = player.getName();
|
||||
}
|
||||
|
||||
String prefix = getPlayerPrefix(player);
|
||||
String format = color(prefix + displayName + "&7: &f") + "%2$s";
|
||||
event.setFormat(format);
|
||||
} catch (Exception ignored) {
|
||||
// Keine Konsolenausgabe
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +431,9 @@ public class TablistManager {
|
||||
try {
|
||||
textMethod = compClass.getMethod("text", CharSequence.class);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
try { textMethod = compClass.getMethod("text", String.class); } catch (NoSuchMethodException ignored2) {}
|
||||
try {
|
||||
textMethod = compClass.getMethod("text", String.class);
|
||||
} catch (NoSuchMethodException ignored2) {}
|
||||
}
|
||||
|
||||
Object headerComp = null;
|
||||
@@ -243,8 +451,8 @@ public class TablistManager {
|
||||
Method deserialize = miniMsgClass.getMethod("deserialize", String.class);
|
||||
headerComp = deserialize.invoke(miniMsg, headerRaw);
|
||||
footerComp = deserialize.invoke(miniMsg, footerRaw);
|
||||
} catch (Throwable t) {
|
||||
// kein MiniMessage
|
||||
} catch (Exception ignored) {
|
||||
// Kein MiniMessage
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,10 +473,7 @@ public class TablistManager {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException cnf) {
|
||||
return false;
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger().log(Level.FINER, "Adventure-Variante fehlgeschlagen: " + t.getMessage());
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -295,8 +500,7 @@ public class TablistManager {
|
||||
mf.invoke(player, footer);
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger().log(Level.FINER, "String-Variante fehlgeschlagen: " + t.getMessage());
|
||||
} catch (Exception ignored) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
@@ -311,7 +515,7 @@ public class TablistManager {
|
||||
try {
|
||||
Method m = current.getMethod(name, paramTypes);
|
||||
if (m != null) return m;
|
||||
} catch (NoSuchMethodException ignored) { }
|
||||
} catch (NoSuchMethodException ignored) {}
|
||||
current = current.getSuperclass();
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -34,7 +34,7 @@ import de.viper.survivalplus.commands.ReportCommand;
|
||||
import de.viper.survivalplus.Manager.ShopManager;
|
||||
import de.viper.survivalplus.commands.HealCommand;
|
||||
import de.viper.survivalplus.Manager.TablistManager;
|
||||
|
||||
import de.viper.survivalplus.Manager.CommandBlocker;
|
||||
import de.viper.survivalplus.Manager.WarpManager;
|
||||
import de.viper.survivalplus.commands.SetWarpCommand;
|
||||
import de.viper.survivalplus.commands.WarpsCommand;
|
||||
@@ -65,7 +65,9 @@ import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class SurvivalPlus extends JavaPlugin {
|
||||
|
||||
@@ -114,6 +116,13 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
// FunChallengeManager als Feld
|
||||
private FunChallengeManager funChallengeManager;
|
||||
|
||||
private File blockedCommandsFile;
|
||||
private FileConfiguration blockedCommandsConfig;
|
||||
|
||||
// Felder für Executor-Instanzen
|
||||
private LockSystem lockSystem;
|
||||
private PluginCommand pluginCommand;
|
||||
|
||||
// ------------------- Tablist Config -------------------
|
||||
public void reloadTablistConfig() {
|
||||
// Lädt die tablist.yml aus dem Plugin-Ordner neu
|
||||
@@ -132,6 +141,38 @@ public class SurvivalPlus extends JavaPlugin {
|
||||
return tablistConfig;
|
||||
}
|
||||
|
||||
public void reloadBlockedCommandsConfig() {
|
||||
if (blockedCommandsFile == null) blockedCommandsFile = new File(getDataFolder(), "blockedcommands.yml");
|
||||
if (!blockedCommandsFile.exists()) {
|
||||
try {
|
||||
saveResource("blockedcommands.yml", false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
getLogger().warning("Die Ressource 'blockedcommands.yml' wurde nicht gefunden. Erstelle eine leere Konfiguration.");
|
||||
blockedCommandsConfig = new YamlConfiguration();
|
||||
blockedCommandsConfig.createSection("blocked-commands");
|
||||
try {
|
||||
blockedCommandsConfig.save(blockedCommandsFile);
|
||||
} catch (IOException ex) {
|
||||
getLogger().log(Level.SEVERE, "Fehler beim Speichern der blockedcommands.yml", ex);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
blockedCommandsConfig = YamlConfiguration.loadConfiguration(blockedCommandsFile);
|
||||
}
|
||||
|
||||
public FileConfiguration getBlockedCommandsConfig() {
|
||||
if (blockedCommandsConfig == null) {
|
||||
reloadBlockedCommandsConfig();
|
||||
}
|
||||
return blockedCommandsConfig;
|
||||
}
|
||||
|
||||
public void saveBlockedCommandsConfig() {
|
||||
try {
|
||||
blockedCommandsConfig.save(blockedCommandsFile);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -164,6 +205,7 @@ public void onEnable() {
|
||||
createLeashesFile();
|
||||
createMobCapFile();
|
||||
createNicknamesFile();
|
||||
reloadBlockedCommandsConfig();
|
||||
|
||||
// PluginManager holen (vor Listener-Registrierung!)
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
@@ -196,6 +238,10 @@ public void onEnable() {
|
||||
getCommand("day").setExecutor(new DayCommand(this));
|
||||
getCommand("night").setExecutor(new NightCommand(this));
|
||||
|
||||
CommandBlocker commandBlocker = new CommandBlocker(this);
|
||||
pluginCommand = new PluginCommand(this);
|
||||
getCommand("sp").setExecutor(pluginCommand);
|
||||
|
||||
// TradeManager und ReportManager initialisieren
|
||||
TradeManager tradeManager = new TradeManager(this);
|
||||
ReportManager reportManager = new ReportManager(this);
|
||||
@@ -262,6 +308,7 @@ public void onEnable() {
|
||||
getCommand("startchallenge").setExecutor(new StartFunChallengeCommand(this, funChallengeManager));
|
||||
getCommand("kit").setExecutor(new KitCommand(this));
|
||||
getCommand("heal").setExecutor(new HealCommand(this));
|
||||
getCommand("sp").setExecutor(commandBlocker);
|
||||
|
||||
// LootChestManager + Befehle
|
||||
LootChestManager lootChestManager = new LootChestManager(this);
|
||||
@@ -298,10 +345,30 @@ public void onEnable() {
|
||||
pluginManager.registerEvents(new ChallengeSmeltListener(funChallengeManager), this);
|
||||
pluginManager.registerEvents(new BlockDetectionListener(this), this);
|
||||
|
||||
LockSystem lockSystem = new LockSystem(this);
|
||||
lockSystem = new LockSystem(this);
|
||||
pluginManager.registerEvents(lockSystem, this);
|
||||
getCommand("sp").setExecutor(lockSystem);
|
||||
|
||||
// Kombinierter Executor für /sp, um alle Subcommands zu handhaben
|
||||
getCommand("sp").setExecutor(new CommandExecutor() {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase("sp")) {
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return pluginCommand.onCommand(sender, command, label, args);
|
||||
}
|
||||
String subCommand = args[0].toLowerCase();
|
||||
if (subCommand.equals("cb")) {
|
||||
return commandBlocker.onCommand(sender, command, label, args);
|
||||
} else if (subCommand.equals("lock") || subCommand.equals("unlock") ||
|
||||
subCommand.equals("friendadd") || subCommand.equals("friendremove")) {
|
||||
return lockSystem.onCommand(sender, command, label, args);
|
||||
}
|
||||
return pluginCommand.onCommand(sender, command, label, args);
|
||||
}
|
||||
});
|
||||
|
||||
pluginManager.registerEvents(new RepairSignListener(getConfig(), getLangConfig()), this);
|
||||
pluginManager.registerEvents(new ToolUpgradeListener(this), this);
|
||||
|
||||
Reference in New Issue
Block a user