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.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
// NEU: bStats
|
// NEU: bStats
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
@@ -30,7 +32,7 @@ import java.net.URL;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.function.Consumer;
|
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.File;
|
||||||
import java.io.IOException;
|
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 CONFIG_VERSION = "1.3.3";
|
||||||
private static final String PLUGIN_AUTHOR = "M_Viper";
|
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
|
// NEU: bStats & Updater
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
private String latestVersion = null;
|
private String latestVersion = null;
|
||||||
@@ -181,7 +189,7 @@ public class UpdateNotifyListener implements Listener {
|
|||||||
getLogger().info("config.yml wurde erstellt.");
|
getLogger().info("config.yml wurde erstellt.");
|
||||||
}
|
}
|
||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
prefix = config.getString("prefix", "tp");
|
prefix = config.getString("prefix", "tpp");
|
||||||
String itemName = config.getString("default-item", "OAK_SIGN");
|
String itemName = config.getString("default-item", "OAK_SIGN");
|
||||||
signLine1Color = config.getString("sign.line1-color", "&1");
|
signLine1Color = config.getString("sign.line1-color", "&1");
|
||||||
signLine2Color = config.getString("sign.line2-color", "&6");
|
signLine2Color = config.getString("sign.line2-color", "&6");
|
||||||
@@ -315,16 +323,19 @@ public class UpdateNotifyListener implements Listener {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
if (command.getName().equalsIgnoreCase("tp")) {
|
// NEU: Spieler-Befehl /tpp
|
||||||
|
if (command.getName().equalsIgnoreCase("tpp")) {
|
||||||
if (!player.hasPermission("tpplugin.use")) {
|
if (!player.hasPermission("tpplugin.use")) {
|
||||||
player.sendMessage(getMessage("no-permission-use"));
|
player.sendMessage(getMessage("no-permission-use"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
openTpGUI(player);
|
// Spieler-GUI öffnen
|
||||||
|
openTpGUI(player, 0, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,6 +349,23 @@ public class UpdateNotifyListener implements Listener {
|
|||||||
return true;
|
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 (command.getName().equalsIgnoreCase("settp")) {
|
||||||
if (!player.hasPermission("tpplugin.admin")) {
|
if (!player.hasPermission("tpplugin.admin")) {
|
||||||
player.sendMessage(getMessage("no-permission-admin"));
|
player.sendMessage(getMessage("no-permission-admin"));
|
||||||
@@ -459,42 +487,106 @@ public class UpdateNotifyListener implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openTpGUI(Player player) {
|
// NEU: Seitenbasierte GUI mit Admin/Spieler-Ansicht
|
||||||
Inventory gui = getServer().createInventory(null, 27, getMessage("gui-title"));
|
private void openTpGUI(Player player, int page, boolean adminView) {
|
||||||
|
List<String> tpList = new ArrayList<>(tps.keySet());
|
||||||
|
|
||||||
for (Map.Entry<String, Location> entry : tps.entrySet()) {
|
// Falls später Filter nötig: bei Nicht-Admin nur eigene / öffentliche TPs
|
||||||
String tpName = entry.getKey();
|
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");
|
ItemStack savedItem = (ItemStack) tpConfig.get("tps." + tpName + ".item");
|
||||||
if (savedItem != null) {
|
if (savedItem == null) savedItem = new ItemStack(defaultItem);
|
||||||
ItemStack guiItem = new ItemStack(savedItem.getType());
|
|
||||||
ItemMeta meta = guiItem.getItemMeta();
|
ItemMeta meta = savedItem.getItemMeta();
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
List<String> lore = new ArrayList<>();
|
meta.setDisplayName(ChatColor.GOLD + tpName);
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', "&7TP: &6" + tpName));
|
meta.setLore(List.of(ChatColor.translateAlternateColorCodes('&', "&7TP: &6" + tpName)));
|
||||||
meta.setLore(lore);
|
savedItem.setItemMeta(meta);
|
||||||
guiItem.setItemMeta(meta);
|
|
||||||
gui.addItem(guiItem);
|
|
||||||
}
|
}
|
||||||
|
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);
|
player.openInventory(gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (!event.getView().getTitle().equals(getMessage("gui-title"))) return;
|
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);
|
event.setCancelled(true);
|
||||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
|
||||||
|
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
ItemStack clickedItem = event.getCurrentItem();
|
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();
|
List<String> lore = clickedItem.getItemMeta().getLore();
|
||||||
for (String line : lore) {
|
for (String line : lore) {
|
||||||
if (line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7TP: &6"))) {
|
if (ChatColor.stripColor(line).startsWith("TP: ")) {
|
||||||
String tpName = ChatColor.stripColor(line).replace("TP: ", "");
|
String tpName = ChatColor.stripColor(line).replace("TP: ", "");
|
||||||
if (tps.containsKey(tpName)) {
|
if (tps.containsKey(tpName)) {
|
||||||
player.teleport(tps.get(tpName));
|
player.teleport(tps.get(tpName));
|
||||||
@@ -506,6 +598,7 @@ public class UpdateNotifyListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSignChange(SignChangeEvent event) {
|
public void onSignChange(SignChangeEvent event) {
|
||||||
if (!event.getPlayer().hasPermission("tpplugin.admin")) return;
|
if (!event.getPlayer().hasPermission("tpplugin.admin")) return;
|
||||||
|
Reference in New Issue
Block a user