SteamWar/BauSystem
Archiviert
13
0

Fix CommandColor

Dieser Commit ist enthalten in:
yoyosource 2021-04-05 13:21:57 +02:00
Ursprung 4542ff608d
Commit 485efedcfc
5 geänderte Dateien mit 111 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -36,6 +36,8 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
import de.steamwar.bausystem.world.Color;
import org.bukkit.Bukkit;

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem;
import de.steamwar.bausystem.commands.*;
import de.steamwar.bausystem.world.*;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.scoreboard.SWScoreboard;

Datei anzeigen

@ -2,7 +2,8 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Color;
import de.steamwar.bausystem.world.Region;
import de.steamwar.bausystem.world.regions.GlobalRegion;
import de.steamwar.bausystem.world.regions.Region;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
@ -35,6 +36,10 @@ public class CommandColor extends SWCommand {
return;
}
Region region = Region.getRegion(p.getLocation());
if (GlobalRegion.isGlobalRegion(region)) {
p.sendMessage(BauSystem.PREFIX + "§cDu befindest dich derzeit in keiner Region");
return;
}
region.setColor(color);
p.sendMessage(BauSystem.PREFIX + "Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt");
}

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem.world.regions;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.world.Color;
import de.steamwar.core.VersionedCallable;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
@ -143,14 +144,14 @@ public class Prototype {
}
}
public EditSession reset(Region region, Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException {
public EditSession reset(Region region, Schematic schem, boolean ignoreAir, Color color) throws IOException, NoClipboardException {
int x = region.minPoint.getX() + offsetX + sizeX / 2;
int y = region.minPoint.getY() + offsetY;
int z = region.minPoint.getZ() + offsetZ + sizeZ / 2;
if (schem == null) {
return paste(new File(schematic), x, y, z, rotate, ignoreAir);
return paste(new File(schematic), x, y, z, rotate, ignoreAir, color);
} else {
return paste(schem.load(), x, y, z, rotate, ignoreAir);
return paste(schem.load(), x, y, z, rotate, ignoreAir, color);
}
}
@ -163,9 +164,9 @@ public class Prototype {
int y = region.minPoint.getY() + testblock.offsetY - 1;
int z = region.minPoint.getZ() + offsetZ + sizeZ / 2;
if (schem == null) {
return paste(new File(protectSchematic), x, y, z, rotate, false);
return paste(new File(protectSchematic), x, y, z, rotate, false, Color.YELLOW);
} else {
return paste(schem.load(), x, y, z, rotate, false);
return paste(schem.load(), x, y, z, rotate, false, Color.YELLOW);
}
}
@ -173,21 +174,21 @@ public class Prototype {
return testblock != null;
}
public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException {
return testblock.reset(region, schem, false);
public EditSession resetTestblock(Region region, Schematic schem, Color color) throws IOException, NoClipboardException {
return testblock.reset(region, schem, false, color);
}
private static boolean inRange(double l, int min, int size) {
return min <= l && l < min + size;
}
private static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { //Type of protect
private static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) { //Type of protect
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(file, x, y, z, rotate, ignoreAir), 8),
new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate, ignoreAir), 15));
new VersionedCallable(() -> Region_15.paste(file, x, y, z, rotate, ignoreAir, color), 15));
}
private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) {
private static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) {
return (EditSession) VersionedCallable.call(new VersionedCallable(() -> Region_12.paste(clipboard, x, y, z, rotate, ignoreAir), 8),
new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate, ignoreAir), 15));
new VersionedCallable(() -> Region_15.paste(clipboard, x, y, z, rotate, ignoreAir, color), 15));
}
}

Datei anzeigen

@ -19,8 +19,13 @@
package de.steamwar.bausystem.world.regions;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.commands.CommandTNT.TNTMode;
import de.steamwar.bausystem.world.Color;
import de.steamwar.bausystem.world.SizedStack;
import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.Schematic;
@ -31,6 +36,8 @@ import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -43,8 +50,18 @@ public class Region {
private static final List<Region> regions = new ArrayList<>();
static boolean buildArea = false;
static boolean extensionArea = false;
private static JsonObject regionsObject = new JsonObject();
static {
File regionsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.json");
if (regionsFile.exists()) {
try {
regionsObject = new JsonParser().parse(new FileReader(regionsFile)).getAsJsonObject();
} catch (JsonSyntaxException | IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Item JSON error");
}
}
YamlConfiguration config = new YamlConfiguration();
try {
config.load(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections.yml"));
@ -82,6 +99,30 @@ public class Region {
return GlobalRegion.getInstance();
}
public static void setGlobalColor(Color color) {
for (Region region : regions) {
region.setColor(color);
}
}
public static void save() {
File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.json");
if (!colorsFile.exists()) {
try {
colorsFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return;
}
}
try (FileOutputStream fileOutputStream = new FileOutputStream(colorsFile)) {
fileOutputStream.write(regionsObject.toString().getBytes());
} catch (IOException e) {
e.printStackTrace();
// Ignored
}
}
private final String name;
final Point minPoint;
private final Prototype prototype;
@ -90,12 +131,47 @@ 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;
private Color color = Color.YELLOW;
private Region(ConfigurationSection config) {
name = config.getName();
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 (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);
}
minPoint = new Point(config.getInt("minX"), config.getInt("minY"), config.getInt("minZ"));
prototype = Prototype.prototypes.get(config.getString("prototype"));
optionsLinkedWith = config.getString("optionsLinkedWith", null);
@ -111,6 +187,15 @@ public class Region {
tntMode = TNTMode.OFF;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
regionOptions.add("color", new JsonPrimitive(color.name()));
}
private void setLinkedRegion(Consumer<Region> regionConsumer) {
if (optionsLinkedWith == null) {
return;
@ -135,6 +220,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() {
@ -144,6 +230,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() {
@ -153,6 +240,7 @@ public class Region {
public void setFire(boolean fire) {
this.fire = fire;
setLinkedRegion(region -> region.fire = fire);
regionOptions.add("fire", new JsonPrimitive(fire));
}
public Point getMinPoint(RegionType regionType, RegionExtensionType regionExtensionType) {
@ -197,7 +285,7 @@ public class Region {
public void reset(Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.reset(this, schem, ignoreAir));
undosessions.push(prototype.reset(this, schem, ignoreAir, color));
}
public boolean hasTestblock() {
@ -206,7 +294,7 @@ public class Region {
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException {
initSessions();
undosessions.push(prototype.resetTestblock(this, schem));
undosessions.push(prototype.resetTestblock(this, schem, color));
}
public boolean hasProtection() {