Add Region persistence
Dieser Commit ist enthalten in:
Ursprung
7c075b18d4
Commit
bc93d96787
@ -118,7 +118,7 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Region.saveColors();
|
||||
Region.save();
|
||||
}
|
||||
|
||||
public static BauSystem getPlugin() {
|
||||
|
@ -48,13 +48,13 @@ public class Region {
|
||||
private static final List<Region> regions = new ArrayList<>();
|
||||
private static boolean buildArea = false;
|
||||
private static boolean extensionArea = false;
|
||||
private static JsonObject colors = new JsonObject();
|
||||
private static JsonObject regionsObject = new JsonObject();
|
||||
|
||||
static {
|
||||
File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "colors.json");
|
||||
if (colorsFile.exists()) {
|
||||
File regionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.json");
|
||||
if (regionsFile.exists()) {
|
||||
try {
|
||||
colors = new JsonParser().parse(new FileReader(colorsFile)).getAsJsonObject();
|
||||
regionsObject = new JsonParser().parse(new FileReader(regionsFile)).getAsJsonObject();
|
||||
} catch (JsonSyntaxException | IOException e) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "Item JSON error");
|
||||
}
|
||||
@ -101,8 +101,8 @@ public class Region {
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveColors() {
|
||||
File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "colors.json");
|
||||
public static void save() {
|
||||
File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.json");
|
||||
if (!colorsFile.exists()) {
|
||||
try {
|
||||
colorsFile.createNewFile();
|
||||
@ -112,7 +112,7 @@ public class Region {
|
||||
}
|
||||
}
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(colorsFile)) {
|
||||
fileOutputStream.write(colors.toString().getBytes());
|
||||
fileOutputStream.write(regionsObject.toString().getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
// Ignored
|
||||
@ -129,6 +129,8 @@ public class Region {
|
||||
private SizedStack<EditSession> undosessions;
|
||||
private SizedStack<EditSession> redosessions;
|
||||
|
||||
private JsonObject regionOptions = new JsonObject();
|
||||
|
||||
private TNTMode tntMode = Region.buildAreaEnabled() ? TNTMode.ONLY_TB : TNTMode.OFF;
|
||||
private boolean freeze = false;
|
||||
private boolean fire = false;
|
||||
@ -137,16 +139,35 @@ public class Region {
|
||||
|
||||
private Region(ConfigurationSection config) {
|
||||
name = config.getName();
|
||||
if (colors.has(name)) {
|
||||
String colorName = colors.getAsJsonPrimitive(name).getAsString();
|
||||
try {
|
||||
color = Color.valueOf(colorName);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
if (regionsObject.has(name)) {
|
||||
regionOptions = regionsObject.getAsJsonObject(name);
|
||||
if (regionOptions.has("tnt")) {
|
||||
String tntName = regionsObject.getAsJsonObject(name).getAsJsonPrimitive("tnt").getAsString();
|
||||
try {
|
||||
tntMode = TNTMode.valueOf(tntName);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
if (color == null) {
|
||||
color = Color.YELLOW;
|
||||
|
||||
if (regionOptions.has("fire")) {
|
||||
fire = regionOptions.getAsJsonPrimitive("fire").getAsBoolean();
|
||||
}
|
||||
|
||||
if (regionOptions.has("freeze")) {
|
||||
freeze = regionOptions.getAsJsonPrimitive("freeze").getAsBoolean();
|
||||
}
|
||||
|
||||
if (regionOptions.has("color")) {
|
||||
String colorName = regionOptions.getAsJsonPrimitive("color").getAsString();
|
||||
try {
|
||||
color = Color.valueOf(colorName);
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
}
|
||||
} else {
|
||||
regionsObject.add(name, regionOptions);
|
||||
}
|
||||
|
||||
minX = config.getInt("minX");
|
||||
@ -174,7 +195,7 @@ public class Region {
|
||||
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
colors.add(name, new JsonPrimitive(color.name()));
|
||||
regionOptions.add("color", new JsonPrimitive(color.name()));
|
||||
}
|
||||
|
||||
private void setLinkedRegion(Consumer<Region> regionConsumer) {
|
||||
@ -201,6 +222,7 @@ public class Region {
|
||||
public void setTntMode(TNTMode tntMode) {
|
||||
this.tntMode = tntMode;
|
||||
setLinkedRegion(region -> region.tntMode = tntMode);
|
||||
regionOptions.add("tnt", new JsonPrimitive(tntMode.name()));
|
||||
}
|
||||
|
||||
public boolean isFreeze() {
|
||||
@ -210,6 +232,7 @@ public class Region {
|
||||
public void setFreeze(boolean freeze) {
|
||||
this.freeze = freeze;
|
||||
setLinkedRegion(region -> region.freeze = freeze);
|
||||
regionOptions.add("freeze", new JsonPrimitive(freeze));
|
||||
}
|
||||
|
||||
public boolean isFire() {
|
||||
@ -219,6 +242,7 @@ public class Region {
|
||||
public void setFire(boolean fire) {
|
||||
this.fire = fire;
|
||||
setLinkedRegion(region -> region.fire = fire);
|
||||
regionOptions.add("fire", new JsonPrimitive(fire));
|
||||
}
|
||||
|
||||
public boolean inRegion(Location l) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren