Update from Git Manager GUI
This commit is contained in:
116
src/main/java/de/ticketsystem/manager/TicketManager.java
Normal file
116
src/main/java/de/ticketsystem/manager/TicketManager.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package de.ticketsystem.manager;
|
||||
|
||||
import de.ticketsystem.TicketPlugin;
|
||||
import de.ticketsystem.model.Ticket;
|
||||
import de.ticketsystem.model.TicketStatus;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TicketManager {
|
||||
|
||||
private final TicketPlugin plugin;
|
||||
|
||||
// Cooldown Map: UUID → Zeit in Millis, wann das letzte Ticket erstellt wurde
|
||||
private final Map<UUID, Long> cooldowns = new HashMap<>();
|
||||
|
||||
public TicketManager(TicketPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// ─────────────────────────── Cooldown ──────────────────────────────────
|
||||
|
||||
public boolean hasCooldown(UUID uuid) {
|
||||
if (!cooldowns.containsKey(uuid)) return false;
|
||||
long cooldownSeconds = plugin.getConfig().getLong("ticket-cooldown", 60) * 1000L;
|
||||
return (System.currentTimeMillis() - cooldowns.get(uuid)) < cooldownSeconds;
|
||||
}
|
||||
|
||||
public long getRemainingCooldown(UUID uuid) {
|
||||
long cooldownMillis = plugin.getConfig().getLong("ticket-cooldown", 60) * 1000L;
|
||||
long elapsed = System.currentTimeMillis() - cooldowns.getOrDefault(uuid, 0L);
|
||||
return Math.max(0, (cooldownMillis - elapsed) / 1000);
|
||||
}
|
||||
|
||||
public void setCooldown(UUID uuid) {
|
||||
cooldowns.put(uuid, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
// ─────────────────────────── Benachrichtigungen ────────────────────────
|
||||
|
||||
/**
|
||||
* Benachrichtigt alle Online-Supporter und Admins über ein neues Ticket.
|
||||
*/
|
||||
public void notifyTeam(Ticket ticket) {
|
||||
String msg = plugin.formatMessage("messages.new-ticket-notify")
|
||||
.replace("{player}", ticket.getCreatorName())
|
||||
.replace("{message}", ticket.getMessage())
|
||||
.replace("{id}", String.valueOf(ticket.getId()));
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.hasPermission("ticket.support") || p.hasPermission("ticket.admin")) {
|
||||
p.sendMessage(msg);
|
||||
|
||||
// Klickbaren Hinweis senden (Bukkit Chat-Component)
|
||||
p.sendMessage(plugin.color("&7» Klicke &e/ticket list &7um die GUI zu öffnen."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Benachrichtigt den Ersteller des Tickets, wenn es geclaimt wurde.
|
||||
*/
|
||||
public void notifyCreatorClaimed(Ticket ticket) {
|
||||
Player creator = Bukkit.getPlayer(ticket.getCreatorUUID());
|
||||
if (creator != null && creator.isOnline()) {
|
||||
String msg = plugin.formatMessage("messages.ticket-claimed-notify")
|
||||
.replace("{id}", String.valueOf(ticket.getId()))
|
||||
.replace("{claimer}", ticket.getClaimerName());
|
||||
creator.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sendet dem weitergeleiteten Supporter eine Benachrichtigung.
|
||||
*/
|
||||
public void notifyForwardedTo(Ticket ticket) {
|
||||
Player target = Bukkit.getPlayer(ticket.getForwardedToUUID());
|
||||
if (target != null && target.isOnline()) {
|
||||
String msg = plugin.formatMessage("messages.ticket-forwarded-notify")
|
||||
.replace("{player}", ticket.getCreatorName())
|
||||
.replace("{id}", String.valueOf(ticket.getId()));
|
||||
target.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────── Hilfsmethoden ─────────────────────────────
|
||||
|
||||
/**
|
||||
* Prüft, ob ein Spieler zu viele offene Tickets hat.
|
||||
*/
|
||||
public boolean hasReachedTicketLimit(UUID uuid) {
|
||||
int max = plugin.getConfig().getInt("max-open-tickets-per-player", 2);
|
||||
if (max <= 0) return false;
|
||||
return plugin.getDatabaseManager().countOpenTicketsByPlayer(uuid) >= max;
|
||||
}
|
||||
|
||||
public void sendHelpMessage(Player player) {
|
||||
player.sendMessage(plugin.color("&8&m "));
|
||||
player.sendMessage(plugin.color("&6TicketSystem &7– Befehle"));
|
||||
player.sendMessage(plugin.color("&8&m "));
|
||||
player.sendMessage(plugin.color("&e/ticket create <Text> &7– Neues Ticket erstellen"));
|
||||
if (player.hasPermission("ticket.support") || player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.color("&e/ticket list &7– Ticket-Übersicht (GUI)"));
|
||||
player.sendMessage(plugin.color("&e/ticket claim <ID> &7– Ticket annehmen"));
|
||||
player.sendMessage(plugin.color("&e/ticket close <ID> &7– Ticket schließen"));
|
||||
}
|
||||
if (player.hasPermission("ticket.admin")) {
|
||||
player.sendMessage(plugin.color("&e/ticket forward <ID> <Spieler> &7– Ticket weiterleiten"));
|
||||
player.sendMessage(plugin.color("&e/ticket reload &7– Konfiguration neu laden"));
|
||||
}
|
||||
player.sendMessage(plugin.color("&8&m "));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user