From cdacf05871461008ae62b3143e7a5cddfeb6f9d5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 5 Apr 2021 12:32:36 +0200 Subject: [PATCH] Add CommandColor Fix Region_15 region size --- .../steamwar/bausystem/world/Region_15.java | 14 ++++-- .../src/de/steamwar/bausystem/BauSystem.java | 7 ++- .../bausystem/commands/CommandColor.java | 50 ++++++++++++++++++- .../de/steamwar/bausystem/world/Region.java | 33 +++++++----- 4 files changed, 83 insertions(+), 21 deletions(-) diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java index 8b29993..8751c47 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/Region_15.java @@ -44,7 +44,7 @@ class 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; try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { clipboard = reader.read(); @@ -52,11 +52,13 @@ class Region_15 { 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)) { + changeColor(clipboard, color); + ClipboardHolder ch = new ClipboardHolder(clipboard); BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v = BlockVector3.at(x, y, z); @@ -70,13 +72,15 @@ class Region_15 { Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(ignoreAir).build()); return e; + } catch (WorldEditException e) { + throw new SecurityException(e.getMessage(), e); } } static void changeColor(Clipboard clipboard, Color color) throws WorldEditException { for (int x = 0; x < clipboard.getDimensions().getX(); x++) { - for (int y = 0; y < clipboard.getDimensions().getX(); y++) { - for (int z = 0; z < clipboard.getDimensions().getX(); z++) { + for (int y = 0; y < clipboard.getDimensions().getY(); y++) { + for (int z = 0; z < clipboard.getDimensions().getZ(); z++) { BlockVector3 blockPointer = clipboard.getMinimumPoint().add(x, y, z); clipboard.setBlock(blockPointer, mapColor(clipboard.getFullBlock(blockPointer).getBlockType(), color).getDefaultState().toBaseBlock()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index a3207a2..4dc7e86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -94,6 +94,12 @@ public class BauSystem extends JavaPlugin implements Listener { new CommandWorldSpawn(); new CommandRegion(); + VersionedRunnable.call(new VersionedRunnable(() -> { + if (Region.buildAreaEnabled()) { + new CommandColor(); + } + }, 15)); + Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(new RegionListener(), this); Bukkit.getPluginManager().registerEvents(new ScriptListener(), this); @@ -159,7 +165,6 @@ public class BauSystem extends JavaPlugin implements Listener { autoShutdown.cancel(); } CommandTPSLimiter.setTPS(20.0); - System.out.println("SAVING colors"); Region.saveColors(); autoShutdown = Bukkit.getScheduler().runTaskTimer(this, new Runnable() { int count = 0; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java index c0a124b..09b25d7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java @@ -1,10 +1,56 @@ 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 + } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java index de4dd49..b42b11d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/Region.java @@ -31,6 +31,7 @@ import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import java.io.*; import java.util.*; @@ -88,6 +89,12 @@ public class Region { } return GlobalRegion.getInstance(); } + + public static void setGlobalColor(Color color) { + for (Region region : regions) { + region.setColor(color); + } + } public static void saveColors() { 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 { initSessions(); - undosessions.push(prototype.reset(this, schem, ignoreAir)); + undosessions.push(prototype.reset(this, schem, ignoreAir, color)); } public boolean hasTestblock() { @@ -240,7 +247,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() { @@ -418,14 +425,14 @@ public class Region { 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 y = region.minY + offsetY; int z = region.minZ + 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); } public boolean hasProtection() { @@ -437,31 +444,31 @@ public class Region { int y = region.minY + testblock.offsetY - 1; int z = region.minZ + 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); } public boolean hasTestblock() { 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)); } } }