SteamWar/BauSystem
Archiviert
13
0

Add CommandColor

Fix Region_15 region size
Dieser Commit ist enthalten in:
yoyosource 2021-04-05 12:32:36 +02:00
Ursprung 3e9a103018
Commit cdacf05871
4 geänderte Dateien mit 83 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -44,7 +44,7 @@ class Region_15 {
private Region_15() { private Region_15() {
} }
static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir) { static EditSession paste(File file, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) {
Clipboard clipboard; Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read(); clipboard = reader.read();
@ -52,11 +52,13 @@ class Region_15 {
throw new SecurityException("Bausystem schematic not found", e); throw new SecurityException("Bausystem schematic not found", e);
} }
return paste(clipboard, x, y, z, rotate, ignoreAir); return paste(clipboard, x, y, z, rotate, ignoreAir, color);
} }
static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir) { static EditSession paste(Clipboard clipboard, int x, int y, int z, boolean rotate, boolean ignoreAir, Color color) {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
changeColor(clipboard, color);
ClipboardHolder ch = new ClipboardHolder(clipboard); ClipboardHolder ch = new ClipboardHolder(clipboard);
BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 v = BlockVector3.at(x, y, z);
@ -70,13 +72,15 @@ class Region_15 {
Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build()); Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build());
return e; return e;
} catch (WorldEditException e) {
throw new SecurityException(e.getMessage(), e);
} }
} }
static void changeColor(Clipboard clipboard, Color color) throws WorldEditException { static void changeColor(Clipboard clipboard, Color color) throws WorldEditException {
for (int x = 0; x < clipboard.getDimensions().getX(); x++) { for (int x = 0; x < clipboard.getDimensions().getX(); x++) {
for (int y = 0; y < clipboard.getDimensions().getX(); y++) { for (int y = 0; y < clipboard.getDimensions().getY(); y++) {
for (int z = 0; z < clipboard.getDimensions().getX(); z++) { for (int z = 0; z < clipboard.getDimensions().getZ(); z++) {
BlockVector3 blockPointer = clipboard.getMinimumPoint().add(x, y, z); BlockVector3 blockPointer = clipboard.getMinimumPoint().add(x, y, z);
clipboard.setBlock(blockPointer, mapColor(clipboard.getFullBlock(blockPointer).getBlockType(), color).getDefaultState().toBaseBlock()); clipboard.setBlock(blockPointer, mapColor(clipboard.getFullBlock(blockPointer).getBlockType(), color).getDefaultState().toBaseBlock());
} }

Datei anzeigen

@ -94,6 +94,12 @@ public class BauSystem extends JavaPlugin implements Listener {
new CommandWorldSpawn(); new CommandWorldSpawn();
new CommandRegion(); new CommandRegion();
VersionedRunnable.call(new VersionedRunnable(() -> {
if (Region.buildAreaEnabled()) {
new CommandColor();
}
}, 15));
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this);
Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); Bukkit.getPluginManager().registerEvents(new ScriptListener(), this);
@ -159,7 +165,6 @@ public class BauSystem extends JavaPlugin implements Listener {
autoShutdown.cancel(); autoShutdown.cancel();
} }
CommandTPSLimiter.setTPS(20.0); CommandTPSLimiter.setTPS(20.0);
System.out.println("SAVING colors");
Region.saveColors(); Region.saveColors();
autoShutdown = Bukkit.getScheduler().runTaskTimer(this, new Runnable() { autoShutdown = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
int count = 0; int count = 0;

Datei anzeigen

@ -1,10 +1,56 @@
package de.steamwar.bausystem.commands; package de.steamwar.bausystem.commands;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.Color;
import de.steamwar.bausystem.world.Region;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;
public class CommandColor { public class CommandColor extends SWCommand {
public CommandColor() {
super("color");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
p.sendMessage("§8/§ecolor §8[§7Color§8] §8- §7Setze die Farbe der Region");
p.sendMessage("§8/§ecolor §8[§7Color§8] §8[§7Type§8] §8- §7Setze die Farbe der Region oder Global");
}
@Register
public void genericColor(Player p, Color color) {
genericColorSet(p, color, ColorizationType.LOCAL);
}
@Register
public void genericColorSet(Player p, Color color, ColorizationType colorizationType) {
if (!permissionCheck(p)) {
return;
}
if (colorizationType == ColorizationType.GLOBAL) {
Region.setGlobalColor(color);
p.sendMessage(BauSystem.PREFIX + "Alle Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt");
return;
}
Region region = Region.getRegion(p.getLocation());
region.setColor(color);
p.sendMessage(BauSystem.PREFIX + "Regions farben auf §e" + color.name().toLowerCase() + "§7 gesetzt");
}
private boolean permissionCheck(Player p) {
if (!BauSystem.getOwner().equals(p.getUniqueId())) {
p.sendMessage(BauSystem.PREFIX + "§cDies ist nicht deine Welt!");
return false;
} else {
return true;
}
}
public enum ColorizationType {
LOCAL,
GLOBAL
}
} }

Datei anzeigen

@ -31,6 +31,7 @@ import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -88,6 +89,12 @@ public class Region {
} }
return GlobalRegion.getInstance(); return GlobalRegion.getInstance();
} }
public static void setGlobalColor(Color color) {
for (Region region : regions) {
region.setColor(color);
}
}
public static void saveColors() { public static void saveColors() {
File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "colors.json"); File colorsFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "colors.json");
@ -231,7 +238,7 @@ public class Region {
public void reset(Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException { public void reset(Schematic schem, boolean ignoreAir) throws IOException, NoClipboardException {
initSessions(); initSessions();
undosessions.push(prototype.reset(this, schem, ignoreAir)); undosessions.push(prototype.reset(this, schem, ignoreAir, color));
} }
public boolean hasTestblock() { public boolean hasTestblock() {
@ -240,7 +247,7 @@ public class Region {
public void resetTestblock(Schematic schem) throws IOException, NoClipboardException { public void resetTestblock(Schematic schem) throws IOException, NoClipboardException {
initSessions(); initSessions();
undosessions.push(prototype.resetTestblock(this, schem)); undosessions.push(prototype.resetTestblock(this, schem, color));
} }
public boolean hasProtection() { public boolean hasProtection() {
@ -418,14 +425,14 @@ public class Region {
inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ); inRange(l.getZ(), region.minZ + offsetZ - extensionNegativeZ, sizeZ + extensionNegativeZ + extensionPositiveZ);
} }
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.minX + offsetX + sizeX / 2; int x = region.minX + offsetX + sizeX / 2;
int y = region.minY + offsetY; int y = region.minY + offsetY;
int z = region.minZ + offsetZ + sizeZ / 2; int z = region.minZ + offsetZ + sizeZ / 2;
if (schem == null) 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 else
return paste(schem.load(), x, y, z, rotate, ignoreAir); return paste(schem.load(), x, y, z, rotate, ignoreAir, color);
} }
public boolean hasProtection() { public boolean hasProtection() {
@ -437,31 +444,31 @@ public class Region {
int y = region.minY + testblock.offsetY - 1; int y = region.minY + testblock.offsetY - 1;
int z = region.minZ + offsetZ + sizeZ / 2; int z = region.minZ + offsetZ + sizeZ / 2;
if (schem == null) 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 else
return paste(schem.load(), x, y, z, rotate, false); return paste(schem.load(), x, y, z, rotate, false, Color.YELLOW);
} }
public boolean hasTestblock() { public boolean hasTestblock() {
return testblock != null; return testblock != null;
} }
public EditSession resetTestblock(Region region, Schematic schem) throws IOException, NoClipboardException { public EditSession resetTestblock(Region region, Schematic schem, Color color) throws IOException, NoClipboardException {
return testblock.reset(region, schem, false); return testblock.reset(region, schem, false, color);
} }
private static boolean inRange(double l, int min, int size) { private static boolean inRange(double l, int min, int size) {
return min <= l && l < min + 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), 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), 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));
} }
} }
} }