Upload folder via GUI - src
This commit is contained in:
191
src/main/java/dev/viper/eventengine/model/EventDefinition.java
Normal file
191
src/main/java/dev/viper/eventengine/model/EventDefinition.java
Normal file
@@ -0,0 +1,191 @@
|
||||
package dev.viper.eventengine.model;
|
||||
|
||||
import dev.viper.eventengine.util.ColorUtil;
|
||||
import dev.viper.eventengine.model.EventRegion;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Repräsentiert ein einzelnes Event — sowohl eingebaute als auch Custom-Events.
|
||||
* Custom-Events werden in custom_events.yml gespeichert.
|
||||
*/
|
||||
public class EventDefinition {
|
||||
|
||||
private final String id;
|
||||
private String displayName;
|
||||
private String description;
|
||||
private EventType type;
|
||||
private EventCategory category;
|
||||
|
||||
// Zeitlimit in Sekunden (0 = unbegrenzt)
|
||||
private int durationSeconds;
|
||||
// Mindest-/Höchst-Spielerzahl
|
||||
private int minPlayers;
|
||||
private int maxPlayers;
|
||||
// Befehle die beim Start/Ende ausgeführt werden
|
||||
private List<String> startCommands;
|
||||
private List<String> endCommands;
|
||||
// Belohnungen
|
||||
private List<String> rewards;
|
||||
// Ankündigungs-Text
|
||||
private String announcement;
|
||||
// Ob das Event in der Rotation ist
|
||||
private boolean inRotation;
|
||||
// Gewichtung in der Rotation
|
||||
private int weight;
|
||||
// Custom-Einstellungen (Key-Value)
|
||||
private Map<String, Object> customSettings;
|
||||
// Ist es ein benutzerdefiniertes Event?
|
||||
private boolean isCustom;
|
||||
// Optionale Event-Region (null = gesamte Welt)
|
||||
private EventRegion region;
|
||||
|
||||
// ─── Konstruktor für builtin Events ────────────────────────────────────
|
||||
public EventDefinition(EventType type) {
|
||||
this.id = type.name().toLowerCase();
|
||||
this.type = type;
|
||||
this.category = type.getCategory();
|
||||
this.displayName = type.getDisplayName();
|
||||
this.description = "Ein " + type.getDisplayName() + " Event.";
|
||||
this.durationSeconds = 300;
|
||||
this.minPlayers = 2;
|
||||
this.maxPlayers = 50;
|
||||
this.startCommands = new ArrayList<>();
|
||||
this.endCommands = new ArrayList<>();
|
||||
this.rewards = new ArrayList<>();
|
||||
this.announcement = ColorUtil.color("&6✦ &e" + displayName + " &6startet jetzt!");
|
||||
this.inRotation = true;
|
||||
this.weight = 1;
|
||||
this.customSettings = new HashMap<>();
|
||||
this.isCustom = false;
|
||||
}
|
||||
|
||||
// ─── Konstruktor für Custom Events ─────────────────────────────────────
|
||||
public EventDefinition(String id) {
|
||||
this.id = id;
|
||||
this.type = EventType.CUSTOM;
|
||||
this.category = EventCategory.CUSTOM;
|
||||
this.displayName = id;
|
||||
this.description = "Benutzerdefiniertes Event.";
|
||||
this.durationSeconds = 300;
|
||||
this.minPlayers = 1;
|
||||
this.maxPlayers = 50;
|
||||
this.startCommands = new ArrayList<>();
|
||||
this.endCommands = new ArrayList<>();
|
||||
this.rewards = new ArrayList<>();
|
||||
this.announcement = ColorUtil.color("&6✦ &e" + id + " &6startet jetzt!");
|
||||
this.inRotation = true;
|
||||
this.weight = 1;
|
||||
this.customSettings = new HashMap<>();
|
||||
this.isCustom = true;
|
||||
}
|
||||
|
||||
// ─── Laden aus ConfigurationSection ────────────────────────────────────
|
||||
public static EventDefinition fromConfig(String id, ConfigurationSection sec) {
|
||||
EventDefinition def = new EventDefinition(id);
|
||||
def.displayName = sec.getString("display-name", id);
|
||||
def.description = sec.getString("description", "Kein Beschreibungstext.");
|
||||
def.durationSeconds = sec.getInt("duration-seconds", 300);
|
||||
def.minPlayers = sec.getInt("min-players", 1);
|
||||
def.maxPlayers = sec.getInt("max-players", 50);
|
||||
def.startCommands = sec.getStringList("start-commands");
|
||||
def.endCommands = sec.getStringList("end-commands");
|
||||
def.rewards = sec.getStringList("rewards");
|
||||
def.announcement = ColorUtil.color(sec.getString("announcement",
|
||||
"&6✦ &e" + def.displayName + " &6startet jetzt!"));
|
||||
def.inRotation = sec.getBoolean("in-rotation", true);
|
||||
def.weight = sec.getInt("weight", 1);
|
||||
String catStr = sec.getString("category", "CUSTOM");
|
||||
try { def.category = EventCategory.valueOf(catStr); }
|
||||
catch (Exception e) { def.category = EventCategory.CUSTOM; }
|
||||
|
||||
ConfigurationSection cs = sec.getConfigurationSection("settings");
|
||||
if (cs != null) {
|
||||
for (String key : cs.getKeys(false)) {
|
||||
def.customSettings.put(key, cs.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
// Region laden
|
||||
if (sec.contains("region.world")) {
|
||||
try {
|
||||
String w = sec.getString("region.world");
|
||||
int minX = sec.getInt("region.min-x");
|
||||
int minY = sec.getInt("region.min-y");
|
||||
int minZ = sec.getInt("region.min-z");
|
||||
int maxX = sec.getInt("region.max-x");
|
||||
int maxY = sec.getInt("region.max-y");
|
||||
int maxZ = sec.getInt("region.max-z");
|
||||
def.region = new EventRegion(w, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
// ─── Speichern in ConfigurationSection ─────────────────────────────────
|
||||
public void saveToConfig(ConfigurationSection sec) {
|
||||
sec.set("display-name", displayName);
|
||||
sec.set("description", description);
|
||||
sec.set("duration-seconds", durationSeconds);
|
||||
sec.set("min-players", minPlayers);
|
||||
sec.set("max-players", maxPlayers);
|
||||
sec.set("start-commands", startCommands);
|
||||
sec.set("end-commands", endCommands);
|
||||
sec.set("rewards", rewards);
|
||||
sec.set("announcement", announcement);
|
||||
sec.set("in-rotation", inRotation);
|
||||
sec.set("weight", weight);
|
||||
sec.set("category", category.name());
|
||||
if (region != null) {
|
||||
sec.set("region.world", region.getWorldName());
|
||||
sec.set("region.min-x", region.getMinX());
|
||||
sec.set("region.min-y", region.getMinY());
|
||||
sec.set("region.min-z", region.getMinZ());
|
||||
sec.set("region.max-x", region.getMaxX());
|
||||
sec.set("region.max-y", region.getMaxY());
|
||||
sec.set("region.max-z", region.getMaxZ());
|
||||
}
|
||||
if (!customSettings.isEmpty()) {
|
||||
for (Map.Entry<String, Object> entry : customSettings.entrySet()) {
|
||||
sec.set("settings." + entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Getter/Setter ──────────────────────────────────────────────────────
|
||||
public String getId() { return id; }
|
||||
public String getDisplayName() { return displayName; }
|
||||
public void setDisplayName(String n) { this.displayName = n; }
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String d) { this.description = d; }
|
||||
public EventType getType() { return type; }
|
||||
public EventCategory getCategory() { return category; }
|
||||
public void setCategory(EventCategory c) { this.category = c; }
|
||||
public int getDurationSeconds() { return durationSeconds; }
|
||||
public void setDurationSeconds(int s) { this.durationSeconds = s; }
|
||||
public int getMinPlayers() { return minPlayers; }
|
||||
public void setMinPlayers(int n) { this.minPlayers = n; }
|
||||
public int getMaxPlayers() { return maxPlayers; }
|
||||
public void setMaxPlayers(int n) { this.maxPlayers = n; }
|
||||
public List<String> getStartCommands() { return startCommands; }
|
||||
public void setStartCommands(List<String> l) { this.startCommands = l; }
|
||||
public List<String> getEndCommands() { return endCommands; }
|
||||
public void setEndCommands(List<String> l) { this.endCommands = l; }
|
||||
public List<String> getRewards() { return rewards; }
|
||||
public void setRewards(List<String> l) { this.rewards = l; }
|
||||
public String getAnnouncement() { return announcement; }
|
||||
public void setAnnouncement(String a) { this.announcement = ColorUtil.color(a); }
|
||||
public boolean isInRotation() { return inRotation; }
|
||||
public void setInRotation(boolean b) { this.inRotation = b; }
|
||||
public int getWeight() { return weight; }
|
||||
public void setWeight(int w) { this.weight = w; }
|
||||
public Map<String, Object> getCustomSettings() { return customSettings; }
|
||||
public boolean isCustom() { return isCustom; }
|
||||
public EventRegion getRegion() { return region; }
|
||||
public void setRegion(EventRegion r) { this.region = r; }
|
||||
public boolean hasRegion() { return region != null; }
|
||||
public Object getSetting(String key) { return customSettings.get(key); }
|
||||
public void setSetting(String key, Object val) { customSettings.put(key, val); }
|
||||
}
|
||||
// Wird unten in der Klasse ergänzt — separate Patch-Datei
|
||||
Reference in New Issue
Block a user