diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 55524339..57f92a6e 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -271,6 +271,24 @@ SHIELD_PRINTING_DISALLOWED = §cYou are not allowed to use shield printing here. SHIELD_PRINTING_BOSSBAR = §fMovements: {0} SHIELD_PRINTING_BOSSBAR_COPIED = §fMovements: {0} Copied: {1} +SHIELD_PRINTING_GUI_NAME = §7Shield Printing +SHIELD_PRINTING_GUI_APPLY = §aApply +SHIELD_PRINTING_GUI_STATE_PREVIOUS = §7R-Click§8: §7Previous +SHIELD_PRINTING_GUI_STATE_NEXT = §7L-Click§8: §7Next +SHIELD_PRINTING_GUI_STATE_ACTIVE = §e> §7{0} +SHIELD_PRINTING_GUI_STATE_INACTIVE = §8> §7{0} +SHIELD_PRINTING_GUI_STATE_FROM_ORIGINAL = Original +SHIELD_PRINTING_GUI_STATE_FROM_COPY = Copy +SHIELD_PRINTING_GUI_STATE_ALWAYS_ON = On +SHIELD_PRINTING_GUI_STATE_ALWAYS_OFF = Off +SHIELD_PRINTING_GUI_STATE_ALWAYS_OPEN = Open +SHIELD_PRINTING_GUI_STATE_ALWAYS_CLOSED = Closed +SHIELD_PRINTING_GUI_STATE_FENCE = §7{0} §fFence Connections +SHIELD_PRINTING_GUI_STATE_OPENABLE = §7{0} §fOpened +SHIELD_PRINTING_GUI_STATE_PISTON = §7{0} §fExtended +SHIELD_PRINTING_GUI_STATE_POWERABLE = §7{0} §fPowered +SHIELD_PRINTING_GUI_STATE_WALL = §7{0} §fWall Connections + SHIELD_PRINTING_START = §aThe shield printing has been started. SHIELD_PRINTING_COPY = §aThe shield has been copied. SHIELD_PRINTING_APPLY = §aThe shield has been applied. diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index 1a9d86ec..b7496d63 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -261,6 +261,24 @@ SHIELD_PRINTING_DISALLOWED = §cDu darfst Shield printing nicht benutzen. SHIELD_PRINTING_BOSSBAR = §fBewegungen: {0} SHIELD_PRINTING_BOSSBAR_COPIED = §fBewegungen: {0} Kopiert: {1} +SHIELD_PRINTING_GUI_NAME = §7Schild Drucken +SHIELD_PRINTING_GUI_APPLY = §aAnwenden +SHIELD_PRINTING_GUI_STATE_PREVIOUS = §7R-Click§8: §7Vorherige +SHIELD_PRINTING_GUI_STATE_NEXT = §7L-Click§8: §7Nächste +SHIELD_PRINTING_GUI_STATE_ACTIVE = §e> §7{0} +SHIELD_PRINTING_GUI_STATE_INACTIVE = §8> §7{0} +SHIELD_PRINTING_GUI_STATE_FROM_ORIGINAL = Original +SHIELD_PRINTING_GUI_STATE_FROM_COPY = Kopie +SHIELD_PRINTING_GUI_STATE_ALWAYS_ON = An +SHIELD_PRINTING_GUI_STATE_ALWAYS_OFF = Aus +SHIELD_PRINTING_GUI_STATE_ALWAYS_OPEN = Offen +SHIELD_PRINTING_GUI_STATE_ALWAYS_CLOSED = Geschlossen +SHIELD_PRINTING_GUI_STATE_FENCE = §7{0} §fZaun Verbindungen +SHIELD_PRINTING_GUI_STATE_OPENABLE = §7{0} §fGeöffnet +SHIELD_PRINTING_GUI_STATE_PISTON = §7{0} §fAusgefahren +SHIELD_PRINTING_GUI_STATE_POWERABLE = §7{0} §fAktiviert +SHIELD_PRINTING_GUI_STATE_WALL = §7{0} §fWand Verbindungen + SHIELD_PRINTING_START = §aShield printing wurde gestartet. SHIELD_PRINTING_COPY = §aSchilde wurden kopiert. SHIELD_PRINTING_APPLY = §aSchilde wurden angewendet. diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/BlockDataConfiguration.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/BlockDataConfiguration.java new file mode 100644 index 00000000..e4b6d102 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/BlockDataConfiguration.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.features.shieldprinting; + +import de.steamwar.inventory.SWItem; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; + +public interface BlockDataConfiguration { + + void previous(); + void next(); + SWItem get(Player player); + + void apply(T copied, T worldOriginal); +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 2fdbd68c..197300d0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -20,9 +20,12 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.shieldprinting.impl.*; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; +import de.steamwar.inventory.SWItem; +import de.steamwar.inventory.SWListInv; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -31,6 +34,8 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.PistonMoveReaction; import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Powerable; +import org.bukkit.block.data.type.*; import org.bukkit.boss.BarColor; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -47,6 +52,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.util.Vector; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; public class ShieldPrinting implements Listener { @@ -84,9 +90,98 @@ public class ShieldPrinting implements Listener { updateBossbars(); } - public void apply() { + public void apply(Player player) { + Map[]> stateConfiguration = new HashMap<>(); for (Map.Entry entry : shieldData.entrySet()) { - entry.getKey().toLocation(WORLD).getBlock().setBlockData(entry.getValue(), false); + BlockData blockData = entry.getKey().toLocation(WORLD).getBlock().getBlockData(); + if (entry.getValue().getMaterial() != blockData.getMaterial()) { + continue; + } + if (entry.getValue().equals(blockData)) { + continue; + } + if (entry.getValue() instanceof Powerable) { + get(entry, stateConfiguration)[0] = new PowerableConfiguration(entry.getValue().getMaterial()); + } + if (entry.getValue() instanceof Piston) { + get(entry, stateConfiguration)[1] = new PistonConfiguration(entry.getValue().getMaterial()); + } + if (entry.getValue() instanceof Wall) { + get(entry, stateConfiguration)[2] = new WallConfiguration(entry.getValue().getMaterial()); + } + if (entry.getValue() instanceof Fence) { + get(entry, stateConfiguration)[3] = new FenceConfiguration(entry.getValue().getMaterial()); + } + if (entry.getValue() instanceof Gate || entry.getValue() instanceof TrapDoor) { + get(entry, stateConfiguration)[4] = new OpenableConfiguration(entry.getValue().getMaterial()); + } + } + if (!stateConfiguration.isEmpty()) { + List>> entries = new ArrayList<>(); + Runnable entriesUpdater = () -> { + entries.clear(); + + for (Map.Entry[]> entry : stateConfiguration.entrySet()) { + for (BlockDataConfiguration blockDataConfiguration : entry.getValue()) { + if (blockDataConfiguration == null) continue; + entries.add(new SWListInv.SWListEntry<>(blockDataConfiguration.get(player), blockDataConfiguration)); + } + } + }; + entriesUpdater.run(); + + AtomicReference>> invReference = new AtomicReference<>(); + SWListInv> inv = new SWListInv<>(player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_NAME", player), false, entries, (clickType, blockDataConfiguration) -> { + if (clickType.isRightClick()) { + blockDataConfiguration.previous(); + } else { + blockDataConfiguration.next(); + } + entriesUpdater.run(); + invReference.get().open(); + }); + invReference.set(inv); + + inv.setItem(49, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_APPLY", player), clickType -> { + paste(stateConfiguration); + player.getOpenInventory().close(); + BauSystem.MESSAGE.send("SHIELD_PRINTING_APPLY", player); + })); + inv.open(); + return; + } + paste(stateConfiguration); + BauSystem.MESSAGE.send("SHIELD_PRINTING_APPLY", player); + } + + private BlockDataConfiguration[] get(Map.Entry entry, Map[]> stateConfiguration) { + return stateConfiguration.computeIfAbsent(entry.getValue().getMaterial(), material -> new BlockDataConfiguration[5]); + } + + private void paste(Map[]> stateConfiguration) { + for (Map.Entry entry : shieldData.entrySet()) { + Block block = entry.getKey().toLocation(WORLD).getBlock(); + if (entry.getValue().getMaterial() != block.getType()) { + block.setBlockData(entry.getValue(), false); + continue; + } + if (entry.getValue().equals(block.getBlockData())) { + continue; + } + + BlockDataConfiguration[] stateConfigurations = stateConfiguration.get(entry.getValue().getMaterial()); + if (stateConfigurations == null) { + block.setBlockData(entry.getValue(), false); + continue; + } + + BlockData worldOriginal = block.getBlockData(); + BlockData copied = entry.getValue().clone(); + for (BlockDataConfiguration blockDataConfiguration : stateConfigurations) { + if (blockDataConfiguration == null) continue; + blockDataConfiguration.apply(copied, worldOriginal); + } + block.setBlockData(copied, false); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java index 34b912c2..d1b60349 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrintingCommand.java @@ -84,8 +84,7 @@ public class ShieldPrintingCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player); return; } - shieldPrinting.apply(); - BauSystem.MESSAGE.send("SHIELD_PRINTING_APPLY", player); + shieldPrinting.apply(player); break; } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/FenceConfiguration.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/FenceConfiguration.java new file mode 100644 index 00000000..c45ede3a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/FenceConfiguration.java @@ -0,0 +1,93 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.features.shieldprinting.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.shieldprinting.BlockDataConfiguration; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Fence; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class FenceConfiguration implements BlockDataConfiguration { + + private Material material; + private State state; + + public FenceConfiguration(Material material) { + this.material = material; + this.state = State.FROM_ORIGINAL; + } + + @Override + public void previous() { + switch (state) { + case FROM_ORIGINAL: + state = State.FROM_COPY; + break; + case FROM_COPY: + state = State.FROM_ORIGINAL; + break; + } + } + + @Override + public void next() { + previous(); + } + + @Override + public SWItem get(Player player) { + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_FENCE", player, material.name())); + List lore = new ArrayList<>(); + for (State value : State.values()) { + lore.add(BauSystem.MESSAGE.parse((value == state) ? "SHIELD_PRINTING_GUI_STATE_ACTIVE" : "SHIELD_PRINTING_GUI_STATE_INACTIVE", + player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_" + value.name(), player))); + } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PREVIOUS", player)); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_NEXT", player)); + swItem.setLore(lore); + return swItem; + } + + @Override + public void apply(Fence copied, Fence worldOriginal) { + switch (state) { + case FROM_ORIGINAL: + copied.setFace(BlockFace.NORTH, worldOriginal.hasFace(BlockFace.NORTH)); + copied.setFace(BlockFace.EAST, worldOriginal.hasFace(BlockFace.EAST)); + copied.setFace(BlockFace.SOUTH, worldOriginal.hasFace(BlockFace.SOUTH)); + copied.setFace(BlockFace.WEST, worldOriginal.hasFace(BlockFace.WEST)); + break; + case FROM_COPY: + break; + } + } + + private enum State { + FROM_COPY, + FROM_ORIGINAL + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/OpenableConfiguration.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/OpenableConfiguration.java new file mode 100644 index 00000000..2b444883 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/OpenableConfiguration.java @@ -0,0 +1,116 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.features.shieldprinting.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.shieldprinting.BlockDataConfiguration; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.block.data.Openable; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class OpenableConfiguration implements BlockDataConfiguration { + + private Material material; + private State state; + + public OpenableConfiguration(Material material) { + this.material = material; + this.state = State.FROM_COPY; + } + + @Override + public void previous() { + switch (state) { + case FROM_COPY: + state = State.ALWAYS_CLOSED; + break; + case FROM_ORIGINAL: + state = State.FROM_COPY; + break; + case ALWAYS_OPEN: + state = State.FROM_ORIGINAL; + break; + case ALWAYS_CLOSED: + state = State.ALWAYS_OPEN; + break; + } + } + + @Override + public void next() { + switch (state) { + case FROM_COPY: + state = State.FROM_ORIGINAL; + break; + case FROM_ORIGINAL: + state = State.ALWAYS_OPEN; + break; + case ALWAYS_OPEN: + state = State.ALWAYS_CLOSED; + break; + case ALWAYS_CLOSED: + state = State.FROM_COPY; + break; + } + } + + @Override + public SWItem get(Player player) { + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_OPENABLE", player, material.name())); + List lore = new ArrayList<>(); + for (State value : State.values()) { + lore.add(BauSystem.MESSAGE.parse((value == state) ? "SHIELD_PRINTING_GUI_STATE_ACTIVE" : "SHIELD_PRINTING_GUI_STATE_INACTIVE", + player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_" + value.name(), player))); + } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PREVIOUS", player)); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_NEXT", player)); + swItem.setLore(lore); + return swItem; + } + + @Override + public void apply(Openable copied, Openable worldOriginal) { + switch (state) { + case FROM_COPY: + break; + case FROM_ORIGINAL: + copied.setOpen(worldOriginal.isOpen()); + break; + case ALWAYS_OPEN: + copied.setOpen(true); + break; + case ALWAYS_CLOSED: + copied.setOpen(false); + break; + } + } + + private enum State { + FROM_COPY, + FROM_ORIGINAL, + ALWAYS_OPEN, + ALWAYS_CLOSED + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/PistonConfiguration.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/PistonConfiguration.java new file mode 100644 index 00000000..dab77b8e --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/PistonConfiguration.java @@ -0,0 +1,90 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.features.shieldprinting.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.shieldprinting.BlockDataConfiguration; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.type.Piston; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class PistonConfiguration implements BlockDataConfiguration { + + private Material material; + private State state; + + public PistonConfiguration(Material material) { + this.material = material; + this.state = State.FROM_ORIGINAL; + } + + @Override + public void previous() { + switch (state) { + case FROM_COPY: + state = State.FROM_ORIGINAL; + break; + case FROM_ORIGINAL: + state = State.FROM_COPY; + break; + } + } + + @Override + public void next() { + previous(); + } + + @Override + public SWItem get(Player player) { + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PISTON", player, material.name())); + List lore = new ArrayList<>(); + for (State value : State.values()) { + lore.add(BauSystem.MESSAGE.parse((value == state) ? "SHIELD_PRINTING_GUI_STATE_ACTIVE" : "SHIELD_PRINTING_GUI_STATE_INACTIVE", + player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_" + value.name(), player))); + } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PREVIOUS", player)); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_NEXT", player)); + swItem.setLore(lore); + return swItem; + } + + @Override + public void apply(Piston copied, Piston worldOriginal) { + switch (state) { + case FROM_COPY: + break; + case FROM_ORIGINAL: + copied.setExtended(worldOriginal.isExtended()); + break; + } + } + + private enum State { + FROM_COPY, + FROM_ORIGINAL + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/PowerableConfiguration.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/PowerableConfiguration.java new file mode 100644 index 00000000..3fa84f18 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/PowerableConfiguration.java @@ -0,0 +1,116 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.features.shieldprinting.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.shieldprinting.BlockDataConfiguration; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.block.data.Powerable; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class PowerableConfiguration implements BlockDataConfiguration { + + private Material material; + private State state; + + public PowerableConfiguration(Material material) { + this.material = material; + this.state = State.FROM_COPY; + } + + @Override + public void previous() { + switch (state) { + case FROM_COPY: + state = State.ALWAYS_OFF; + break; + case FROM_ORIGINAL: + state = State.FROM_COPY; + break; + case ALWAYS_ON: + state = State.FROM_ORIGINAL; + break; + case ALWAYS_OFF: + state = State.ALWAYS_ON; + break; + } + } + + @Override + public void next() { + switch (state) { + case FROM_COPY: + state = State.FROM_ORIGINAL; + break; + case FROM_ORIGINAL: + state = State.ALWAYS_ON; + break; + case ALWAYS_ON: + state = State.ALWAYS_OFF; + break; + case ALWAYS_OFF: + state = State.FROM_COPY; + break; + } + } + + @Override + public SWItem get(Player player) { + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_POWERABLE", player, material.name())); + List lore = new ArrayList<>(); + for (State value : State.values()) { + lore.add(BauSystem.MESSAGE.parse((value == state) ? "SHIELD_PRINTING_GUI_STATE_ACTIVE" : "SHIELD_PRINTING_GUI_STATE_INACTIVE", + player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_" + value.name(), player))); + } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PREVIOUS", player)); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_NEXT", player)); + swItem.setLore(lore); + return swItem; + } + + @Override + public void apply(Powerable copied, Powerable worldOriginal) { + switch (state) { + case FROM_COPY: + break; + case FROM_ORIGINAL: + copied.setPowered(worldOriginal.isPowered()); + break; + case ALWAYS_ON: + copied.setPowered(true); + break; + case ALWAYS_OFF: + copied.setPowered(false); + break; + } + } + + private enum State { + FROM_COPY, + FROM_ORIGINAL, + ALWAYS_ON, + ALWAYS_OFF + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/WallConfiguration.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/WallConfiguration.java new file mode 100644 index 00000000..00b57f92 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/impl/WallConfiguration.java @@ -0,0 +1,94 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 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.features.shieldprinting.impl; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.shieldprinting.BlockDataConfiguration; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.type.Wall; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class WallConfiguration implements BlockDataConfiguration { + + private Material material; + private State state; + + public WallConfiguration(Material material) { + this.material = material; + this.state = State.FROM_ORIGINAL; + } + + @Override + public void previous() { + switch (state) { + case FROM_ORIGINAL: + state = State.FROM_COPY; + break; + case FROM_COPY: + state = State.FROM_ORIGINAL; + break; + } + } + + @Override + public void next() { + previous(); + } + + @Override + public SWItem get(Player player) { + SWItem swItem = new SWItem(material, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_WALL", player, material.name())); + List lore = new ArrayList<>(); + for (State value : State.values()) { + lore.add(BauSystem.MESSAGE.parse((value == state) ? "SHIELD_PRINTING_GUI_STATE_ACTIVE" : "SHIELD_PRINTING_GUI_STATE_INACTIVE", + player, BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_" + value.name(), player))); + } + lore.add(""); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_PREVIOUS", player)); + lore.add(BauSystem.MESSAGE.parse("SHIELD_PRINTING_GUI_STATE_NEXT", player)); + swItem.setLore(lore); + return swItem; + } + + @Override + public void apply(Wall copied, Wall worldOriginal) { + switch (state) { + case FROM_ORIGINAL: + copied.setUp(worldOriginal.isUp()); + copied.setHeight(BlockFace.NORTH, worldOriginal.getHeight(BlockFace.NORTH)); + copied.setHeight(BlockFace.EAST, worldOriginal.getHeight(BlockFace.EAST)); + copied.setHeight(BlockFace.SOUTH, worldOriginal.getHeight(BlockFace.SOUTH)); + copied.setHeight(BlockFace.WEST, worldOriginal.getHeight(BlockFace.WEST)); + break; + case FROM_COPY: + break; + } + } + + private enum State { + FROM_COPY, + FROM_ORIGINAL + } +}