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