Add BauSystem module

Fix ci java version
Fix LinkageProcessor
This commit is contained in:
2024-08-05 13:28:50 +02:00
parent 41d31e6c9c
commit 3366a30b0c
526 changed files with 43550 additions and 149479 deletions
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<T extends BlockData> {
void previous();
void next();
SWItem get(Player player);
void apply(T copied, T worldOriginal);
}
@@ -0,0 +1,283 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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.BauMemberUpdateEvent;
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;
import org.bukkit.World;
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;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
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 {
private static final World WORLD = Bukkit.getWorlds().get(0);
static {
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
ShieldPrintingCommand.SHIELD_PRINTING_MAP.values().forEach(shieldPrinting -> {
shieldPrinting.fallingBlocks.replaceAll((entity, location) -> {
if (entity.isDead()) return null;
return location;
});
});
}, 1, 1);
}
/**
* Vector of current position, Vector of origin
*/
private Map<Vector, Vector> shieldMap = new HashMap<>();
private Map<Vector, BlockData> shieldData = new HashMap<>();
private final Region region;
public ShieldPrinting(Region region) {
this.region = region;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
updateBossbars();
}
public void copy() {
for (Map.Entry<Vector, Vector> entry : shieldMap.entrySet()) {
shieldData.put(entry.getValue(), entry.getKey().toLocation(WORLD).getBlock().getBlockData());
}
updateBossbars();
}
public void apply(Player player) {
Map<Material, BlockDataConfiguration<?>[]> stateConfiguration = new HashMap<>();
for (Map.Entry<Vector, BlockData> entry : shieldData.entrySet()) {
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<SWListInv.SWListEntry<BlockDataConfiguration<?>>> entries = new ArrayList<>();
Runnable entriesUpdater = () -> {
entries.clear();
for (Map.Entry<Material, BlockDataConfiguration<?>[]> entry : stateConfiguration.entrySet()) {
for (BlockDataConfiguration<?> blockDataConfiguration : entry.getValue()) {
if (blockDataConfiguration == null) continue;
entries.add(new SWListInv.SWListEntry<>(blockDataConfiguration.get(player), blockDataConfiguration));
}
}
};
entriesUpdater.run();
AtomicReference<SWListInv<BlockDataConfiguration<?>>> invReference = new AtomicReference<>();
SWListInv<BlockDataConfiguration<?>> 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<Vector, BlockData> entry, Map<Material, BlockDataConfiguration<?>[]> stateConfiguration) {
return stateConfiguration.computeIfAbsent(entry.getValue().getMaterial(), material -> new BlockDataConfiguration[5]);
}
private void paste(Map<Material, BlockDataConfiguration<?>[]> stateConfiguration) {
for (Map.Entry<Vector, BlockData> 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);
}
}
public void disable() {
HandlerList.unregisterAll(this);
shieldMap.clear();
shieldData.clear();
for (Player player : Bukkit.getOnlinePlayers()) {
BossBarService.instance.remove(player, region, "shieldprinting");
}
}
@EventHandler
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
update(event.getDirection(), event.getBlocks());
}
@EventHandler
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
update(event.getDirection(), event.getBlocks());
}
private void update(BlockFace direction, List<Block> blockList) {
Set<Vector> toRemove = new HashSet<>();
Map<Vector, Vector> temp = new HashMap<>();
for (Block block : blockList) {
if (Region.getRegion(block.getLocation()) != region) continue;
if (block.getPistonMoveReaction() == PistonMoveReaction.BREAK) continue;
Vector vector = block.getLocation().toVector();
Vector origin = vector.clone();
vector = vector.add(direction.getDirection());
if (shieldMap.containsKey(origin)) {
toRemove.add(origin);
temp.put(vector, shieldMap.get(origin));
} else {
temp.put(vector, origin);
}
}
shieldMap.keySet().removeAll(toRemove);
shieldMap.putAll(temp);
toRemove.clear();
for (Map.Entry<Vector, Vector> entry : shieldMap.entrySet()) {
if (entry.getKey().equals(entry.getValue())) {
toRemove.add(entry.getKey());
}
}
shieldMap.keySet().removeAll(toRemove);
updateBossbars();
}
private Map<Entity, Location> fallingBlocks = new HashMap<>();
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.FALLING_BLOCK) return;
if (Region.getRegion(event.getLocation()) != region) return;
fallingBlocks.put(event.getEntity(), event.getLocation().getBlock().getLocation());
}
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
if (!event.getBlock().getType().isAir()) return;
if (event.getEntityType() != EntityType.FALLING_BLOCK) return;
if (Region.getRegion(event.getBlock().getLocation()) != region) return;
Location origin = fallingBlocks.remove(event.getEntity());
if (origin == null) return;
Location destination = event.getBlock().getLocation();
Vector originOrigin = shieldMap.remove(origin.toVector());
shieldMap.put(destination.toVector(), originOrigin != null ? originOrigin : origin.toVector());
updateBossbars();
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
updateBossbar(event.getPlayer());
}
@EventHandler
public void onBauMemberUpdate(BauMemberUpdateEvent event) {
event.getNewSpectator().forEach(player -> BossBarService.instance.remove(player, region, "shieldprinting"));
event.getNewBuilder().forEach(this::updateBossbar);
}
private void updateBossbars() {
for (Player player : Bukkit.getOnlinePlayers()) {
updateBossbar(player);
}
}
private void updateBossbar(Player player) {
BauSystemBossbar bossbar = BossBarService.instance.get(player, region, "shieldprinting");
bossbar.setColor(BarColor.YELLOW);
bossbar.setTitle(BauSystem.MESSAGE.parse(shieldData.isEmpty() ? "SHIELD_PRINTING_BOSSBAR" : "SHIELD_PRINTING_BOSSBAR_COPIED", player, shieldMap.size(), shieldData.size()));
}
}
@@ -0,0 +1,121 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.shieldprinting;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.region.Region;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import java.util.HashMap;
import java.util.Map;
@Linked
public class ShieldPrintingCommand extends SWCommand implements Listener {
public ShieldPrintingCommand() {
super("shieldprinting");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_START");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_COPY");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_APPLY");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STOP");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_1");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_2");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_3");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_4");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_5");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_6");
addDefaultHelpMessage("SHIELD_PRINTING_HELP_STEP_7");
}
static final Map<Region, ShieldPrinting> SHIELD_PRINTING_MAP = new HashMap<>();
@Register
public void genericCommand(@Validator Player player, ShieldPrintingState shieldPrintingState) {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player);
return;
}
ShieldPrinting shieldPrinting;
switch (shieldPrintingState) {
case START:
shieldPrinting = SHIELD_PRINTING_MAP.put(region, new ShieldPrinting(region));
if (shieldPrinting != null) {
shieldPrinting.disable();
}
BauSystem.MESSAGE.send("SHIELD_PRINTING_START", player);
break;
case COPY:
shieldPrinting = SHIELD_PRINTING_MAP.get(region);
if (shieldPrinting == null) {
BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player);
return;
}
shieldPrinting.copy();
BauSystem.MESSAGE.send("SHIELD_PRINTING_COPY", player);
break;
case APPLY:
shieldPrinting = SHIELD_PRINTING_MAP.get(region);
if (shieldPrinting == null) {
BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player);
return;
}
shieldPrinting.apply(player);
break;
}
}
@Register("stop")
public void stopCommand(@Validator Player player) {
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
BauSystem.MESSAGE.send("SHIELD_PRINTING_NO_REGION", player);
return;
}
ShieldPrinting shieldPrinting = SHIELD_PRINTING_MAP.remove(region);
if (shieldPrinting == null) {
BauSystem.MESSAGE.send("SHIELD_PRINTING_NOT_RUNNING", player);
return;
}
shieldPrinting.disable();
BauSystem.MESSAGE.send("SHIELD_PRINTING_STOP", player);
}
@ClassValidator(value = Player.class, local = true)
public TypeValidator<Player> validator() {
return (commandSender, player, messageSender) -> {
if (!Permission.BUILD.hasPermission(player)) {
messageSender.send("NO_PERMISSION", player);
return false;
}
Region region = Region.getRegion(player.getLocation());
if (region.isGlobal()) {
messageSender.send("SHIELD_PRINTING_NO_REGION", player);
return false;
}
return true;
};
}
}
@@ -0,0 +1,27 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.shieldprinting;
public enum ShieldPrintingState {
START,
COPY,
APPLY
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Fence> {
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<String> 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
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Openable> {
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<String> 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
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Piston> {
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<String> 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
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Powerable> {
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<String> 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
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Wall> {
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<String> 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
}
}