Update from Git Manager GUI
This commit is contained in:
@@ -3,18 +3,25 @@ package de.ticketsystem.model;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Ticket {
|
||||
|
||||
@SerializableAs("Ticket")
|
||||
public class Ticket implements ConfigurationSerializable {
|
||||
|
||||
private int id;
|
||||
private UUID creatorUUID;
|
||||
private String creatorName;
|
||||
private String message;
|
||||
|
||||
// Location-Felder (werden separat gespeichert)
|
||||
private String worldName;
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
@@ -27,9 +34,12 @@ public class Ticket {
|
||||
private Timestamp createdAt;
|
||||
private Timestamp claimedAt;
|
||||
private Timestamp closedAt;
|
||||
private String closeComment;
|
||||
|
||||
|
||||
public Ticket() {}
|
||||
|
||||
|
||||
public Ticket(UUID creatorUUID, String creatorName, String message, Location location) {
|
||||
this.creatorUUID = creatorUUID;
|
||||
this.creatorName = creatorName;
|
||||
@@ -44,6 +54,101 @@ public class Ticket {
|
||||
this.createdAt = new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
// --- NEU: Konstruktor zum Laden aus der YAML (Deserialisierung) ---
|
||||
public Ticket(Map<String, Object> map) {
|
||||
this.id = (int) map.get("id");
|
||||
|
||||
// UUIDs sicher aus String konvertieren
|
||||
Object creatorObj = map.get("creatorUUID");
|
||||
this.creatorUUID = creatorObj instanceof UUID ? (UUID) creatorObj : UUID.fromString((String) creatorObj);
|
||||
|
||||
this.creatorName = (String) map.get("creatorName");
|
||||
this.message = (String) map.get("message");
|
||||
this.worldName = (String) map.get("world");
|
||||
|
||||
// Koordinaten sicher parsen
|
||||
this.x = map.get("x") instanceof Double ? (Double) map.get("x") : ((Number) map.get("x")).doubleValue();
|
||||
this.y = map.get("y") instanceof Double ? (Double) map.get("y") : ((Number) map.get("y")).doubleValue();
|
||||
this.z = map.get("z") instanceof Double ? (Double) map.get("z") : ((Number) map.get("z")).doubleValue();
|
||||
|
||||
this.yaw = map.get("yaw") instanceof Float ? (Float) map.get("yaw") : ((Number) map.get("yaw")).floatValue();
|
||||
this.pitch = map.get("pitch") instanceof Float ? (Float) map.get("pitch") : ((Number) map.get("pitch")).floatValue();
|
||||
|
||||
this.status = TicketStatus.valueOf((String) map.get("status"));
|
||||
|
||||
// Timestamps aus Long (Millis) wieder zu Timestamp machen
|
||||
if (map.get("createdAt") != null) {
|
||||
this.createdAt = new Timestamp(((Number) map.get("createdAt")).longValue());
|
||||
}
|
||||
if (map.get("claimedAt") != null) {
|
||||
this.claimedAt = new Timestamp(((Number) map.get("claimedAt")).longValue());
|
||||
}
|
||||
if (map.get("closedAt") != null) {
|
||||
this.closedAt = new Timestamp(((Number) map.get("closedAt")).longValue());
|
||||
}
|
||||
|
||||
this.closeComment = (String) map.get("closeComment");
|
||||
|
||||
// Optionale Felder
|
||||
if (map.containsKey("claimerUUID") && map.get("claimerUUID") != null) {
|
||||
Object claimerObj = map.get("claimerUUID");
|
||||
this.claimerUUID = claimerObj instanceof UUID ? (UUID) claimerObj : UUID.fromString((String) claimerObj);
|
||||
this.claimerName = (String) map.get("claimerName");
|
||||
}
|
||||
|
||||
if (map.containsKey("forwardedToUUID") && map.get("forwardedToUUID") != null) {
|
||||
Object fwdObj = map.get("forwardedToUUID");
|
||||
this.forwardedToUUID = fwdObj instanceof UUID ? (UUID) fwdObj : UUID.fromString((String) fwdObj);
|
||||
this.forwardedToName = (String) map.get("forwardedToName");
|
||||
}
|
||||
}
|
||||
|
||||
// --- NEU: Methode zum Speichern in die YAML (Serialisierung) ---
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("id", id);
|
||||
// WICHTIG: UUID als String speichern, um !!java.util.UUID Tag zu vermeiden
|
||||
map.put("creatorUUID", creatorUUID.toString());
|
||||
map.put("creatorName", creatorName);
|
||||
map.put("message", message);
|
||||
map.put("world", worldName);
|
||||
|
||||
map.put("x", x);
|
||||
map.put("y", y);
|
||||
map.put("z", z);
|
||||
map.put("yaw", yaw);
|
||||
map.put("pitch", pitch);
|
||||
|
||||
map.put("status", status.name());
|
||||
|
||||
// Timestamps als Long speichern
|
||||
if (createdAt != null) map.put("createdAt", createdAt.getTime());
|
||||
if (claimedAt != null) map.put("claimedAt", claimedAt.getTime());
|
||||
if (closedAt != null) map.put("closedAt", closedAt.getTime());
|
||||
|
||||
if (closeComment != null) map.put("closeComment", closeComment);
|
||||
|
||||
if (claimerUUID != null) {
|
||||
map.put("claimerUUID", claimerUUID.toString());
|
||||
map.put("claimerName", claimerName);
|
||||
}
|
||||
|
||||
if (forwardedToUUID != null) {
|
||||
map.put("forwardedToUUID", forwardedToUUID.toString());
|
||||
map.put("forwardedToName", forwardedToName);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
// --- NEU: Registrierung ---
|
||||
public static void register() {
|
||||
ConfigurationSerialization.registerClass(Ticket.class, "Ticket");
|
||||
}
|
||||
|
||||
// --- Deine ursprüngliche getLocation Methode (beibehalten) ---
|
||||
public Location getLocation() {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) return null;
|
||||
@@ -105,4 +210,7 @@ public class Ticket {
|
||||
|
||||
public Timestamp getClosedAt() { return closedAt; }
|
||||
public void setClosedAt(Timestamp closedAt) { this.closedAt = closedAt; }
|
||||
}
|
||||
|
||||
public String getCloseComment() { return closeComment; }
|
||||
public void setCloseComment(String closeComment) { this.closeComment = closeComment; }
|
||||
}
|
||||
Reference in New Issue
Block a user