src/main/java/TpPlugin.java aktualisiert
This commit is contained in:
@@ -18,6 +18,8 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.ChatColor;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
// NEU: bStats
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@@ -30,7 +32,7 @@ import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.json.JSONObject; // Wichtig für JSON Parsing
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -57,6 +59,12 @@ public class TpPlugin extends JavaPlugin implements Listener {
|
||||
private static final String CONFIG_VERSION = "1.3.3";
|
||||
private static final String PLUGIN_AUTHOR = "M_Viper";
|
||||
|
||||
// NEU: Für seitenbasierte GUI
|
||||
private Map<UUID, Integer> playerPage = new HashMap<>();
|
||||
private static final int TP_PER_PAGE = 21;
|
||||
|
||||
|
||||
|
||||
// NEU: bStats & Updater
|
||||
private Metrics metrics;
|
||||
private String latestVersion = null;
|
||||
@@ -181,7 +189,7 @@ public class UpdateNotifyListener implements Listener {
|
||||
getLogger().info("config.yml wurde erstellt.");
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
prefix = config.getString("prefix", "tp");
|
||||
prefix = config.getString("prefix", "tpp");
|
||||
String itemName = config.getString("default-item", "OAK_SIGN");
|
||||
signLine1Color = config.getString("sign.line1-color", "&1");
|
||||
signLine2Color = config.getString("sign.line2-color", "&6");
|
||||
@@ -315,29 +323,49 @@ public class UpdateNotifyListener implements Listener {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (command.getName().equalsIgnoreCase("tp")) {
|
||||
if (!player.hasPermission("tpplugin.use")) {
|
||||
player.sendMessage(getMessage("no-permission-use"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
openTpGUI(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
String tpName = args[0];
|
||||
if (tps.containsKey(tpName)) {
|
||||
player.teleport(tps.get(tpName));
|
||||
player.sendMessage(getMessage("teleport-success").replace("%tp%", tpName));
|
||||
} else {
|
||||
player.sendMessage(getMessage("tp-not-found").replace("%tp%", tpName));
|
||||
}
|
||||
// NEU: Spieler-Befehl /tpp
|
||||
if (command.getName().equalsIgnoreCase("tpp")) {
|
||||
if (!player.hasPermission("tpplugin.use")) {
|
||||
player.sendMessage(getMessage("no-permission-use"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
// Spieler-GUI öffnen
|
||||
openTpGUI(player, 0, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
String tpName = args[0];
|
||||
if (tps.containsKey(tpName)) {
|
||||
player.teleport(tps.get(tpName));
|
||||
player.sendMessage(getMessage("teleport-success").replace("%tp%", tpName));
|
||||
} else {
|
||||
player.sendMessage(getMessage("tp-not-found").replace("%tp%", tpName));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// NEU: Admin-Befehl /tppadmin gui
|
||||
if (command.getName().equalsIgnoreCase("tppadmin")) {
|
||||
if (!player.hasPermission("tpplugin.admin")) {
|
||||
player.sendMessage(getMessage("no-permission-admin"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("gui")) {
|
||||
openTpGUI(player, 0, true); // Admin-Ansicht
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(ChatColor.RED + "Usage: /tppadmin gui");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (command.getName().equalsIgnoreCase("settp")) {
|
||||
if (!player.hasPermission("tpplugin.admin")) {
|
||||
player.sendMessage(getMessage("no-permission-admin"));
|
||||
@@ -459,42 +487,106 @@ public class UpdateNotifyListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void openTpGUI(Player player) {
|
||||
Inventory gui = getServer().createInventory(null, 27, getMessage("gui-title"));
|
||||
|
||||
for (Map.Entry<String, Location> entry : tps.entrySet()) {
|
||||
String tpName = entry.getKey();
|
||||
ItemStack savedItem = (ItemStack) tpConfig.get("tps." + tpName + ".item");
|
||||
if (savedItem != null) {
|
||||
ItemStack guiItem = new ItemStack(savedItem.getType());
|
||||
ItemMeta meta = guiItem.getItemMeta();
|
||||
if (meta != null) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7TP: &6" + tpName));
|
||||
meta.setLore(lore);
|
||||
guiItem.setItemMeta(meta);
|
||||
gui.addItem(guiItem);
|
||||
}
|
||||
}
|
||||
// NEU: Seitenbasierte GUI mit Admin/Spieler-Ansicht
|
||||
private void openTpGUI(Player player, int page, boolean adminView) {
|
||||
List<String> tpList = new ArrayList<>(tps.keySet());
|
||||
|
||||
// Falls später Filter nötig: bei Nicht-Admin nur eigene / öffentliche TPs
|
||||
if (!adminView) {
|
||||
// aktuell keine Filterung nötig
|
||||
}
|
||||
|
||||
|
||||
int totalPages = (int) Math.ceil((double) tpList.size() / TP_PER_PAGE);
|
||||
if (page >= totalPages) page = totalPages - 1;
|
||||
if (page < 0) page = 0;
|
||||
|
||||
playerPage.put(player.getUniqueId(), page);
|
||||
|
||||
String title = (adminView ? ChatColor.RED + "[Admin] " : "") + getMessage("gui-title") +
|
||||
" §7[Seite " + (page + 1) + "/" + (totalPages == 0 ? 1 : totalPages) + "]";
|
||||
|
||||
Inventory gui = getServer().createInventory(null, 27, title);
|
||||
|
||||
// Items für Teleports
|
||||
int startIndex = page * TP_PER_PAGE;
|
||||
int endIndex = Math.min(startIndex + TP_PER_PAGE, tpList.size());
|
||||
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
String tpName = tpList.get(i);
|
||||
ItemStack savedItem = (ItemStack) tpConfig.get("tps." + tpName + ".item");
|
||||
if (savedItem == null) savedItem = new ItemStack(defaultItem);
|
||||
|
||||
ItemMeta meta = savedItem.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(ChatColor.GOLD + tpName);
|
||||
meta.setLore(List.of(ChatColor.translateAlternateColorCodes('&', "&7TP: &6" + tpName)));
|
||||
savedItem.setItemMeta(meta);
|
||||
}
|
||||
gui.addItem(savedItem);
|
||||
}
|
||||
|
||||
// Navigation Links
|
||||
if (page > 0) {
|
||||
ItemStack prev = new ItemStack(Material.ARROW);
|
||||
ItemMeta meta = prev.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.YELLOW + "Zurück");
|
||||
prev.setItemMeta(meta);
|
||||
gui.setItem(21, prev);
|
||||
}
|
||||
|
||||
// Navigation Rechts
|
||||
if (page < totalPages - 1) {
|
||||
ItemStack next = new ItemStack(Material.ARROW);
|
||||
ItemMeta meta = next.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.YELLOW + "Weiter");
|
||||
next.setItemMeta(meta);
|
||||
gui.setItem(23, next);
|
||||
}
|
||||
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!event.getView().getTitle().equals(getMessage("gui-title"))) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
String rawTitle = ChatColor.stripColor(event.getView().getTitle());
|
||||
String baseTitle = ChatColor.stripColor(getMessage("gui-title"));
|
||||
|
||||
// GUI-Titel muss Basis enthalten (auch wenn [Admin] oder Seitenzahl davor/dahinter steht)
|
||||
if (!rawTitle.contains(baseTitle)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
if (clickedItem == null || !clickedItem.hasItemMeta() || !clickedItem.getItemMeta().hasLore()) return;
|
||||
|
||||
if (clickedItem == null || !clickedItem.hasItemMeta()) return;
|
||||
|
||||
String displayName = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
|
||||
// Prüfen, ob es eine Admin-Ansicht ist
|
||||
boolean adminView = rawTitle.startsWith("[Admin]");
|
||||
|
||||
// Navigation zurück
|
||||
if (displayName.equalsIgnoreCase("Zurück")) {
|
||||
int currentPage = playerPage.getOrDefault(player.getUniqueId(), 0);
|
||||
openTpGUI(player, currentPage - 1, adminView);
|
||||
return;
|
||||
}
|
||||
|
||||
// Navigation weiter
|
||||
if (displayName.equalsIgnoreCase("Weiter")) {
|
||||
int currentPage = playerPage.getOrDefault(player.getUniqueId(), 0);
|
||||
openTpGUI(player, currentPage + 1, adminView);
|
||||
return;
|
||||
}
|
||||
|
||||
// Teleport-Click anhand Lore
|
||||
if (!clickedItem.getItemMeta().hasLore()) return;
|
||||
List<String> lore = clickedItem.getItemMeta().getLore();
|
||||
for (String line : lore) {
|
||||
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7TP: &6"))) {
|
||||
if (ChatColor.stripColor(line).startsWith("TP: ")) {
|
||||
String tpName = ChatColor.stripColor(line).replace("TP: ", "");
|
||||
if (tps.containsKey(tpName)) {
|
||||
player.teleport(tps.get(tpName));
|
||||
@@ -506,6 +598,7 @@ public class UpdateNotifyListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (!event.getPlayer().hasPermission("tpplugin.admin")) return;
|
||||
|
Reference in New Issue
Block a user