Update from Git Manager GUI
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
package de.ticketsystem.commands;
|
||||
|
||||
import de.ticketsystem.TicketPlugin;
|
||||
@@ -9,19 +8,259 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
// Platzhalter für Admin-Kommandos
|
||||
|
||||
private final TicketPlugin plugin;
|
||||
|
||||
public TicketCommand(TicketPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage("Dieser Befehl kann nur von Spielern ausgeführt werden.");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
plugin.getTicketManager().sendHelpMessage(player);
|
||||
return true;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create" -> handleCreate(player, args);
|
||||
case "list" -> handleList(player);
|
||||
case "claim" -> handleClaim(player, args);
|
||||
case "close" -> handleClose(player, args);
|
||||
case "forward" -> handleForward(player, args);
|
||||
case "reload" -> handleReload(player);
|
||||
case "migrate" -> handleMigrate(player, args);
|
||||
case "export" -> handleExport(player, args);
|
||||
case "import" -> handleImport(player, args);
|
||||
case "stats" -> handleStats(player);
|
||||
case "archive" -> handleArchive(player);
|
||||
default -> plugin.getTicketManager().sendHelpMessage(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket create ────────────────────────────
|
||||
|
||||
private void handleCreate(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.create")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket create <Beschreibung>"));
|
||||
return;
|
||||
}
|
||||
if (plugin.getTicketManager().hasCooldown(player.getUniqueId())) {
|
||||
long remaining = plugin.getTicketManager().getRemainingCooldown(player.getUniqueId());
|
||||
player.sendMessage(plugin.formatMessage("messages.cooldown")
|
||||
.replace("{seconds}", String.valueOf(remaining)));
|
||||
return;
|
||||
}
|
||||
if (plugin.getTicketManager().hasReachedTicketLimit(player.getUniqueId())) {
|
||||
int max = plugin.getConfig().getInt("max-open-tickets-per-player", 2);
|
||||
player.sendMessage(plugin.color("&cDu hast bereits &e" + max
|
||||
+ " &coffene Ticket(s). Bitte warte, bis dein Ticket bearbeitet wurde."));
|
||||
return;
|
||||
}
|
||||
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||
int maxLen = plugin.getConfig().getInt("max-description-length", 100);
|
||||
if (message.length() > maxLen) {
|
||||
player.sendMessage(plugin.color("&cDeine Beschreibung ist zu lang! Maximal " + maxLen + " Zeichen."));
|
||||
return;
|
||||
}
|
||||
Ticket ticket = new Ticket(player.getUniqueId(), player.getName(), message, player.getLocation());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
int id = plugin.getDatabaseManager().createTicket(ticket);
|
||||
if (id == -1) {
|
||||
player.sendMessage(plugin.color("&cFehler beim Erstellen des Tickets!"));
|
||||
return;
|
||||
}
|
||||
ticket.setId(id);
|
||||
plugin.getTicketManager().setCooldown(player.getUniqueId());
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-created")
|
||||
.replace("{id}", String.valueOf(id)));
|
||||
plugin.getTicketManager().notifyTeam(ticket); // ruft auch Discord-Webhook auf
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket list ──────────────────────────────
|
||||
|
||||
private void handleList(Player player) {
|
||||
if (player.hasPermission("ticket.support") || player.hasPermission("ticket.admin")) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () ->
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
plugin.getTicketGUI().openGUI(player)));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () ->
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
plugin.getTicketGUI().openPlayerGUI(player)));
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket claim ─────────────────────────────
|
||||
|
||||
private void handleClaim(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.support") && !player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket claim <ID>"));
|
||||
return;
|
||||
}
|
||||
int id;
|
||||
try { id = Integer.parseInt(args[1]); }
|
||||
catch (NumberFormatException e) { player.sendMessage(plugin.color("&cUngültige ID!")); return; }
|
||||
|
||||
final int ticketId = id;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = plugin.getDatabaseManager().claimTicket(ticketId, player.getUniqueId(), player.getName());
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!success) { player.sendMessage(plugin.formatMessage("messages.already-claimed")); return; }
|
||||
Ticket ticket = plugin.getDatabaseManager().getTicketById(ticketId);
|
||||
if (ticket == null) return;
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-claimed")
|
||||
.replace("{id}", String.valueOf(ticketId))
|
||||
.replace("{player}", ticket.getCreatorName()));
|
||||
plugin.getTicketManager().notifyCreatorClaimed(ticket);
|
||||
if (ticket.getLocation() != null) player.teleport(ticket.getLocation());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket close ─────────────────────────────
|
||||
|
||||
private void handleClose(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.support") && !player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket close <ID> [Kommentar]"));
|
||||
return;
|
||||
}
|
||||
int id;
|
||||
try { id = Integer.parseInt(args[1]); }
|
||||
catch (NumberFormatException e) { player.sendMessage(plugin.color("&cUngültige ID!")); return; }
|
||||
|
||||
String closeComment = args.length > 2
|
||||
? String.join(" ", Arrays.copyOfRange(args, 2, args.length)) : "";
|
||||
|
||||
final int ticketId = id;
|
||||
final String comment = closeComment;
|
||||
final String closer = player.getName();
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = plugin.getDatabaseManager().closeTicket(ticketId, comment);
|
||||
if (success) {
|
||||
Ticket ticket = plugin.getDatabaseManager().getTicketById(ticketId);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-closed")
|
||||
.replace("{id}", String.valueOf(ticketId)));
|
||||
if (ticket != null) {
|
||||
ticket.setCloseComment(comment);
|
||||
// closerName für Discord-Nachricht mitgeben
|
||||
plugin.getTicketManager().notifyCreatorClosed(ticket, closer);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-not-found")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket forward ───────────────────────────
|
||||
|
||||
private void handleForward(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket forward <ID> <Spieler>"));
|
||||
return;
|
||||
}
|
||||
int id;
|
||||
try { id = Integer.parseInt(args[1]); }
|
||||
catch (NumberFormatException e) { player.sendMessage(plugin.color("&cUngültige ID!")); return; }
|
||||
|
||||
Player target = Bukkit.getPlayer(args[2]);
|
||||
if (target == null || !target.isOnline()) {
|
||||
player.sendMessage(plugin.color("&cSpieler &e" + args[2] + " &cist nicht online!"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int ticketId = id;
|
||||
final Player finalTarget = target;
|
||||
final String fromName = player.getName();
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = plugin.getDatabaseManager()
|
||||
.forwardTicket(ticketId, finalTarget.getUniqueId(), finalTarget.getName());
|
||||
if (success) {
|
||||
Ticket ticket = plugin.getDatabaseManager().getTicketById(ticketId);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-forwarded")
|
||||
.replace("{id}", String.valueOf(ticketId))
|
||||
.replace("{player}", finalTarget.getName()));
|
||||
if (ticket != null) {
|
||||
// fromName für Discord mitgeben
|
||||
plugin.getTicketManager().notifyForwardedTo(ticket, fromName);
|
||||
plugin.getTicketManager().notifyCreatorForwarded(ticket);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-not-found")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket reload ────────────────────────────
|
||||
|
||||
private void handleReload(Player player) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
plugin.reloadConfig();
|
||||
player.sendMessage(plugin.color("&aKonfiguration wurde neu geladen."));
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket archive ───────────────────────────
|
||||
|
||||
private void handleArchive(Player player) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
int count = plugin.getDatabaseManager().archiveClosedTickets();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (count > 0) {
|
||||
player.sendMessage(plugin.formatMessage("messages.archive-success")
|
||||
.replace("{count}", String.valueOf(count)));
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.archive-fail"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket migrate ───────────────────────────
|
||||
|
||||
private void handleMigrate(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
@@ -34,19 +273,14 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
int migrated = 0;
|
||||
String mode = args[1].toLowerCase();
|
||||
if (mode.equals("tomysql")) {
|
||||
migrated = plugin.getDatabaseManager().migrateToMySQL();
|
||||
} else if (mode.equals("tofile")) {
|
||||
migrated = plugin.getDatabaseManager().migrateToFile();
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.unknown-mode"));
|
||||
return;
|
||||
}
|
||||
if (mode.equals("tomysql")) migrated = plugin.getDatabaseManager().migrateToMySQL();
|
||||
else if (mode.equals("tofile")) migrated = plugin.getDatabaseManager().migrateToFile();
|
||||
else { player.sendMessage(plugin.formatMessage("messages.unknown-mode")); return; }
|
||||
int finalMigrated = migrated;
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (finalMigrated > 0) {
|
||||
player.sendMessage(plugin.formatMessage("messages.migration-success")
|
||||
.replace("{count}", String.valueOf(finalMigrated)));
|
||||
.replace("{count}", String.valueOf(finalMigrated)));
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.migration-fail"));
|
||||
}
|
||||
@@ -54,6 +288,8 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket export ────────────────────────────
|
||||
|
||||
private void handleExport(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
@@ -70,7 +306,7 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (count > 0) {
|
||||
player.sendMessage(plugin.formatMessage("messages.export-success")
|
||||
.replace("{count}", String.valueOf(count)).replace("{file}", filename));
|
||||
.replace("{count}", String.valueOf(count)).replace("{file}", filename));
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.export-fail"));
|
||||
}
|
||||
@@ -78,6 +314,8 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket import ────────────────────────────
|
||||
|
||||
private void handleImport(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
@@ -98,7 +336,7 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (count > 0) {
|
||||
player.sendMessage(plugin.formatMessage("messages.import-success")
|
||||
.replace("{count}", String.valueOf(count)));
|
||||
.replace("{count}", String.valueOf(count)));
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.import-fail"));
|
||||
}
|
||||
@@ -106,6 +344,8 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket stats ─────────────────────────────
|
||||
|
||||
private void handleStats(Player player) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
@@ -114,309 +354,38 @@ public class TicketCommand implements CommandExecutor, TabCompleter {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
var stats = plugin.getDatabaseManager().getTicketStats();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.sendMessage("§6--- Ticket Statistik ---");
|
||||
player.sendMessage("§eGesamt: §a" + stats.total + " §7| §eOffen: §a" + stats.open + " §7| §eGeschlossen: §a" + stats.closed + " §7| §eWeitergeleitet: §a" + stats.forwarded);
|
||||
player.sendMessage("§6Top Ersteller:");
|
||||
stats.byPlayer.entrySet().stream().sorted((a,b)->b.getValue()-a.getValue()).limit(5).forEach(e ->
|
||||
player.sendMessage("§e" + e.getKey() + ": §a" + e.getValue())
|
||||
);
|
||||
player.sendMessage(plugin.color("&6--- Ticket Statistik ---"));
|
||||
player.sendMessage(plugin.color("&eGesamt: &a" + stats.total
|
||||
+ " &7| &eOffen: &a" + stats.open
|
||||
+ " &7| &eGeschlossen: &a" + stats.closed
|
||||
+ " &7| &eWeitergeleitet: &a" + stats.forwarded));
|
||||
player.sendMessage(plugin.color("&6Top Ersteller:"));
|
||||
stats.byPlayer.entrySet().stream()
|
||||
.sorted((a, b) -> b.getValue() - a.getValue())
|
||||
.limit(5)
|
||||
.forEach(e -> player.sendMessage(plugin.color("&e" + e.getKey() + ": &a" + e.getValue())));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket archive ────────────────────────────
|
||||
private void handleArchive(Player player) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
int count = plugin.getDatabaseManager().archiveClosedTickets();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (count > 0) {
|
||||
player.sendMessage(plugin.formatMessage("messages.archive-success")
|
||||
.replace("{count}", String.valueOf(count)));
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.archive-fail"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private final TicketPlugin plugin;
|
||||
|
||||
public TicketCommand(TicketPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command,
|
||||
String label, String[] args) {
|
||||
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage("Dieser Befehl kann nur von Spielern ausgeführt werden.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
plugin.getTicketManager().sendHelpMessage(player);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create" -> handleCreate(player, args);
|
||||
case "list" -> handleList(player);
|
||||
case "claim" -> handleClaim(player, args);
|
||||
case "close" -> handleClose(player, args);
|
||||
case "forward" -> handleForward(player, args);
|
||||
case "reload" -> handleReload(player);
|
||||
case "migrate" -> handleMigrate(player, args);
|
||||
case "export" -> handleExport(player, args);
|
||||
case "import" -> handleImport(player, args);
|
||||
case "stats" -> handleStats(player);
|
||||
case "archive" -> handleArchive(player);
|
||||
default -> plugin.getTicketManager().sendHelpMessage(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Methoden wie handleMigrate, handleCreate, handleList, handleClaim, handleClose, handleForward, handleReload, handleStats müssen auf Klassenebene stehen und dürfen nicht innerhalb von onCommand oder anderen Methoden verschachtelt sein.
|
||||
// Entferne alle verschachtelten Methoden und stelle sicher, dass jede Methode nur einmal und auf Klassenebene existiert.
|
||||
|
||||
// ─────────────────────────── /ticket create ────────────────────────────
|
||||
|
||||
private void handleCreate(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.create")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket create <Beschreibung>"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Cooldown-Check
|
||||
if (plugin.getTicketManager().hasCooldown(player.getUniqueId())) {
|
||||
long remaining = plugin.getTicketManager().getRemainingCooldown(player.getUniqueId());
|
||||
player.sendMessage(plugin.formatMessage("messages.cooldown")
|
||||
.replace("{seconds}", String.valueOf(remaining)));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ticket-Limit-Check
|
||||
if (plugin.getTicketManager().hasReachedTicketLimit(player.getUniqueId())) {
|
||||
int max = plugin.getConfig().getInt("max-open-tickets-per-player", 2);
|
||||
player.sendMessage(plugin.color("&cDu hast bereits &e" + max + " &coffene Ticket(s). Bitte warte, bis dein Ticket bearbeitet wurde."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Nachricht zusammenbauen
|
||||
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
|
||||
int maxLen = plugin.getConfig().getInt("max-description-length", 100);
|
||||
if (message.length() > maxLen) {
|
||||
player.sendMessage(plugin.color("&cDeine Beschreibung ist zu lang! Maximal " + maxLen + " Zeichen."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ticket asynchron in DB speichern
|
||||
Ticket ticket = new Ticket(player.getUniqueId(), player.getName(), message, player.getLocation());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
int id = plugin.getDatabaseManager().createTicket(ticket);
|
||||
if (id == -1) {
|
||||
player.sendMessage(plugin.color("&cFehler beim Erstellen des Tickets! Bitte wende dich an einen Admin."));
|
||||
return;
|
||||
}
|
||||
ticket.setId(id);
|
||||
plugin.getTicketManager().setCooldown(player.getUniqueId());
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-created")
|
||||
.replace("{id}", String.valueOf(id)));
|
||||
|
||||
// Team benachrichtigen
|
||||
plugin.getTicketManager().notifyTeam(ticket);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket list ──────────────────────────────
|
||||
|
||||
private void handleList(Player player) {
|
||||
if (!player.hasPermission("ticket.support") && !player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
// GUI öffnen (synchron, Datenbankabfrage läuft darin async)
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () ->
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
plugin.getTicketGUI().openGUI(player)));
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket claim ─────────────────────────────
|
||||
|
||||
private void handleClaim(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.support") && !player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket claim <ID>"));
|
||||
return;
|
||||
}
|
||||
|
||||
int id;
|
||||
try { id = Integer.parseInt(args[1]); }
|
||||
catch (NumberFormatException e) {
|
||||
player.sendMessage(plugin.color("&cUngültige ID!"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int ticketId = id;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = plugin.getDatabaseManager().claimTicket(
|
||||
ticketId, player.getUniqueId(), player.getName());
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!success) {
|
||||
player.sendMessage(plugin.formatMessage("messages.already-claimed"));
|
||||
return;
|
||||
}
|
||||
Ticket ticket = plugin.getDatabaseManager().getTicketById(ticketId);
|
||||
if (ticket == null) return;
|
||||
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-claimed")
|
||||
.replace("{id}", String.valueOf(ticketId))
|
||||
.replace("{player}", ticket.getCreatorName()));
|
||||
|
||||
plugin.getTicketManager().notifyCreatorClaimed(ticket);
|
||||
|
||||
// Zur Ticket-Position teleportieren
|
||||
if (ticket.getLocation() != null) {
|
||||
player.teleport(ticket.getLocation());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket close ─────────────────────────────
|
||||
|
||||
private void handleClose(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.support") && !player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket close <ID>"));
|
||||
return;
|
||||
}
|
||||
|
||||
int id;
|
||||
try { id = Integer.parseInt(args[1]); }
|
||||
catch (NumberFormatException e) {
|
||||
player.sendMessage(plugin.color("&cUngültige ID!"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int ticketId = id;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = plugin.getDatabaseManager().closeTicket(ticketId);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (success) {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-closed")
|
||||
.replace("{id}", String.valueOf(ticketId)));
|
||||
} else {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-not-found"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket forward ───────────────────────────
|
||||
|
||||
private void handleForward(Player player, String[] args) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
if (args.length < 3) {
|
||||
player.sendMessage(plugin.color("&cBenutzung: /ticket forward <ID> <Spieler>"));
|
||||
return;
|
||||
}
|
||||
|
||||
int id;
|
||||
try { id = Integer.parseInt(args[1]); }
|
||||
catch (NumberFormatException e) {
|
||||
player.sendMessage(plugin.color("&cUngültige ID!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[2]);
|
||||
if (target == null || !target.isOnline()) {
|
||||
player.sendMessage(plugin.color("&cSpieler &e" + args[2] + " &cist nicht online!"));
|
||||
return;
|
||||
}
|
||||
|
||||
final int ticketId = id;
|
||||
final Player finalTarget = target;
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
boolean success = plugin.getDatabaseManager().forwardTicket(
|
||||
ticketId, finalTarget.getUniqueId(), finalTarget.getName());
|
||||
|
||||
if (success) {
|
||||
Ticket ticket = plugin.getDatabaseManager().getTicketById(ticketId);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-forwarded")
|
||||
.replace("{id}", String.valueOf(ticketId))
|
||||
.replace("{player}", finalTarget.getName()));
|
||||
if (ticket != null) plugin.getTicketManager().notifyForwardedTo(ticket);
|
||||
});
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
player.sendMessage(plugin.formatMessage("messages.ticket-not-found")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ─────────────────────────── /ticket reload ────────────────────────────
|
||||
|
||||
private void handleReload(Player player) {
|
||||
if (!player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.formatMessage("messages.no-permission"));
|
||||
return;
|
||||
}
|
||||
plugin.reloadConfig();
|
||||
player.sendMessage(plugin.color("&aKonfiguration wurde neu geladen."));
|
||||
}
|
||||
|
||||
// ─────────────────────────── Tab-Completion ────────────────────────────
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command,
|
||||
String label, String[] args) {
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
if (!(sender instanceof Player player)) return completions;
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> subs = new ArrayList<>();
|
||||
subs.add("create");
|
||||
if (player.hasPermission("ticket.support") || player.hasPermission("ticket.admin")) {
|
||||
subs.addAll(List.of("list", "claim", "close"));
|
||||
}
|
||||
if (player.hasPermission("ticket.admin")) {
|
||||
subs.addAll(List.of("forward", "reload"));
|
||||
}
|
||||
for (String s : subs) {
|
||||
List<String> subs = new ArrayList<>(List.of("create", "list"));
|
||||
if (player.hasPermission("ticket.support") || player.hasPermission("ticket.admin"))
|
||||
subs.addAll(List.of("claim", "close"));
|
||||
if (player.hasPermission("ticket.admin"))
|
||||
subs.addAll(List.of("forward", "reload", "stats", "archive", "migrate", "export", "import"));
|
||||
for (String s : subs)
|
||||
if (s.startsWith(args[0].toLowerCase())) completions.add(s);
|
||||
}
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("forward")) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.getName().toLowerCase().startsWith(args[2].toLowerCase()))
|
||||
completions.add(p.getName());
|
||||
}
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
if (p.getName().toLowerCase().startsWith(args[2].toLowerCase())) completions.add(p.getName());
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user