diff --git a/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java b/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java index f9a1d17..1a228ce 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/world/regions/Region_15.java @@ -21,15 +21,17 @@ package de.steamwar.bausystem.world.regions; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -42,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(); @@ -50,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); @@ -68,6 +72,121 @@ 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().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()); + } + } + } + } + + private static BlockType mapColor(BlockType original, Color color) { + if (original != BlockTypes.YELLOW_CONCRETE && original != BlockTypes.YELLOW_STAINED_GLASS) { + return original; + } + + switch (color) { + case WHITE: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.WHITE_CONCRETE; + } else { + return BlockTypes.WHITE_STAINED_GLASS; + } + case ORANGE: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.ORANGE_CONCRETE; + } else { + return BlockTypes.ORANGE_STAINED_GLASS; + } + case MAGENTA: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.MAGENTA_CONCRETE; + } else { + return BlockTypes.MAGENTA_STAINED_GLASS; + } + case LIGHT_BLUE: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.LIGHT_BLUE_CONCRETE; + } else { + return BlockTypes.LIGHT_BLUE_STAINED_GLASS; + } + case LIME: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.LIME_CONCRETE; + } else { + return BlockTypes.LIME_STAINED_GLASS; + } + case PINK: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.PINK_CONCRETE; + } else { + return BlockTypes.PINK_STAINED_GLASS; + } + case GRAY: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.GRAY_CONCRETE; + } else { + return BlockTypes.GRAY_STAINED_GLASS; + } + case LIGHT_GRAY: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.LIGHT_GRAY_CONCRETE; + } else { + return BlockTypes.LIGHT_GRAY_STAINED_GLASS; + } + case CYAN: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.CYAN_CONCRETE; + } else { + return BlockTypes.CYAN_STAINED_GLASS; + } + case PURPLE: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.PURPLE_CONCRETE; + } else { + return BlockTypes.PURPLE_STAINED_GLASS; + } + case BLUE: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.BLUE_CONCRETE; + } else { + return BlockTypes.BLUE_STAINED_GLASS; + } + case BROWN: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.BROWN_CONCRETE; + } else { + return BlockTypes.BROWN_STAINED_GLASS; + } + case GREEN: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.GREEN_CONCRETE; + } else { + return BlockTypes.GREEN_STAINED_GLASS; + } + case RED: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.RED_CONCRETE; + } else { + return BlockTypes.RED_STAINED_GLASS; + } + case BLACK: + if (original == BlockTypes.YELLOW_CONCRETE) { + return BlockTypes.BLACK_CONCRETE; + } else { + return BlockTypes.BLACK_STAINED_GLASS; + } + case YELLOW: + default: + return original; } } } diff --git a/BauSystem_API/src/de/steamwar/bausystem/world/Color.java b/BauSystem_API/src/de/steamwar/bausystem/world/Color.java new file mode 100644 index 0000000..2f06881 --- /dev/null +++ b/BauSystem_API/src/de/steamwar/bausystem/world/Color.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.world; + +public enum Color { + WHITE, + ORANGE, + MAGENTA, + LIGHT_BLUE, + YELLOW, + LIME, + PINK, + GRAY, + LIGHT_GRAY, + CYAN, + PURPLE, + BLUE, + BROWN, + GREEN, + RED, + BLACK; +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index be6011a..1d09ff1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -95,6 +95,12 @@ public class BauSystem extends JavaPlugin implements Listener { new CommandRegion(); new CommandSelect(); + 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); @@ -111,6 +117,11 @@ public class BauSystem extends JavaPlugin implements Listener { TPSUtils.init(); } + @Override + public void onDisable() { + Region.save(); + } + public static BauSystem getPlugin() { return plugin; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java new file mode 100644 index 0000000..09b25d7 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandColor.java @@ -0,0 +1,56 @@ +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.command.SWCommand; +import org.bukkit.entity.Player; + + +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