SteamWar/BauSystem2.0
Archiviert
12
0

Update loader and remove old one
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-05-01 16:59:06 +02:00
Ursprung 88c015f7f9
Commit 7e78c2890a
10 geänderte Dateien mit 17 neuen und 857 gelöschten Zeilen

Datei anzeigen

@ -1,244 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.loader.activations.AbstractLoaderActivation;
import de.steamwar.bausystem.features.loader.activations.BlockPlaceLoaderActivation;
import de.steamwar.bausystem.features.loader.activations.InteractionActivation;
import de.steamwar.bausystem.shared.EnumDisplay;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.scheduler.BukkitTask;
import java.util.*;
@Getter
@Setter
public class Loader implements Listener {
private static final Map<Player, Loader> LOADER_MAP = new HashMap<>();
private final Player p;
private final List<AbstractLoaderActivation> actions = new LinkedList<>();
private int ticksBetweenShots = 80;
private int ticksBetweenBlocks = 1;
private Stage stage;
private int lastActivation = -1;
private int countdown = 0;
@Getter(AccessLevel.PRIVATE)
private final BukkitTask task;
@Getter(AccessLevel.PRIVATE)
@Setter(AccessLevel.PRIVATE)
private AbstractLoaderActivation current;
@Getter(AccessLevel.PRIVATE)
@Setter(AccessLevel.PRIVATE)
private ListIterator<AbstractLoaderActivation> iterator;
private Loader(Player p) {
this.p = p;
stage = Stage.SETUP;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1);
}
public static Loader getLoader(Player p) {
return LOADER_MAP.getOrDefault(p, null);
}
public static Loader newLoader(Player p) {
return LOADER_MAP.put(p, new Loader(p));
}
public void start() {
if (stage != Stage.SETUP) return;
iterator = actions.listIterator();
countdown = 0;
current = null;
stage = Stage.RUNNING;
}
public void pause() {
if (stage == Stage.RUNNING) {
stage = Stage.PAUSE;
}
}
public void resume() {
if (stage == Stage.PAUSE) {
stage = Stage.RUNNING;
}
}
public void setup() {
stage = Stage.SETUP;
iterator = null;
current = null;
countdown = 0;
}
public void stop() {
stage = Stage.END;
task.cancel();
LOADER_MAP.remove(p, this);
}
public void clear() {
if (stage == Stage.SETUP) {
actions.clear();
BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR", p);
} else {
BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR_HELP", p);
}
}
public void single() {
if (stage != Stage.PAUSE && stage != Stage.SETUP) return;
if (iterator == null || !iterator.hasNext()) {
iterator = actions.listIterator();
countdown = 0;
current = null;
}
stage = Stage.SINGLE;
}
public void run() {
if (stage == Stage.SETUP && lastActivation >= 0)
lastActivation++;
if (stage != Stage.RUNNING && stage != Stage.SINGLE) {
return;
}
if (countdown-- > 0) {
return;
}
while (countdown <= 0) {
if (!iterator.hasNext()) {
countdown = getTicksBetweenShots();
iterator = actions.listIterator();
if (stage == Stage.SINGLE) stage = Stage.PAUSE;
return;
}
current = iterator.next();
if (current.execute()) {
countdown = current.delay(this);
} else {
countdown = 1;
iterator.previous();
}
}
}
public void undo() {
if (actions.isEmpty() || stage != Stage.SETUP) {
return;
}
actions.remove(actions.size() - 1);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer() != p) {
return;
}
if (stage != Stage.SETUP) {
return;
}
if (event.getBlock().getType() != Material.TNT) {
return;
}
actions.add(new BlockPlaceLoaderActivation(p, event.getBlock().getLocation(), Material.TNT));
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_TNT", p, actions.size()));
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer() != p) {
return;
}
if (stage != Stage.SETUP) {
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL)
return;
if (event.getClickedBlock().getType() == Material.OBSERVER)
return;
if (event.getHand() == EquipmentSlot.OFF_HAND) {
return;
}
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.TNT) {
return;
}
LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock());
if (button != LoaderButton.INVALID) {
actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this));
lastActivation = 0;
SWUtils.sendToActionbar(p, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", p, BauSystem.MESSAGE.parse(button.getName(), p), actions.size()));
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
if (event.getPlayer() != p) {
return;
}
stop();
}
@AllArgsConstructor
public enum Stage implements EnumDisplay {
SETUP("LOADER_SETUP"),
RUNNING("LOADER_RUNNING"),
SINGLE("LOADER_SINGLE_SIDEBAR"),
PAUSE("LOADER_PAUSE"),
END("LOADER_END");
@Getter
private String chatValue;
}
}

Datei anzeigen

@ -1,107 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
@Linked
public class LoaderBauGuiItem extends BauGuiItem {
public LoaderBauGuiItem() {
super(9);
}
@Override
public ItemStack getItem(Player player) {
return SWUtils.setCustomModelData(new SWItem(Material.FLINT_AND_STEEL, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", player)), 1).getItemStack();
}
@Override
public boolean click(ClickType click, Player p) {
p.closeInventory();
openLoaderGui(p);
return false;
}
private void openLoaderGui(Player p) {
SWInventory inv = new SWInventory(p, 9, BauSystem.MESSAGE.parse("LOADER_GUI_NAME", p));
if (Loader.getLoader(p) == null) {
inv.setItem(4, new SWItem(Material.SCUTE, BauSystem.MESSAGE.parse("LOADER_GUI_NEW", p), clickType -> {
p.closeInventory();
p.performCommand("loader setup");
}));
} else {
Loader loader = Loader.getLoader(p);
if (loader.getStage() != Loader.Stage.RUNNING) {
inv.setItem(0, new SWItem(Material.GREEN_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_START", p), clickType -> {
p.closeInventory();
p.performCommand("loader start");
}));
} else {
inv.setItem(0, new SWItem(Material.RED_DYE, BauSystem.MESSAGE.parse("LOADER_GUI_PAUSE", p), clickType -> {
p.closeInventory();
p.performCommand("loader pause");
}));
}
inv.setItem(2, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_UNDO", p), clickType -> {
p.closeInventory();
p.performCommand("loader undo");
}));
inv.setItem(4, new SWItem(Material.COMPASS, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_LORE", p, loader.getTicksBetweenShots())), false, clickType -> {
p.closeInventory();
SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", p));
anvilInv.setItem(Material.CLOCK);
anvilInv.setCallback(s -> p.performCommand("loader delay " + s));
anvilInv.open();
}));
inv.setItem(6, new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED", p), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_LORE", p, loader.getTicksBetweenBlocks())), false, clickType -> {
p.closeInventory();
SWAnvilInv anvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SPEED_TITLE", p));
anvilInv.setItem(Material.CLOCK);
anvilInv.setCallback(s -> p.performCommand("loader speed " + s));
anvilInv.open();
}));
inv.setItem(8, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_STOP", p), clickType -> {
p.closeInventory();
p.performCommand("loader stop");
}));
}
inv.open();
}
@Override
public Permission permission() {
return Permission.WORLD;
}
}

Datei anzeigen

@ -1,71 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.bukkit.block.Block;
@AllArgsConstructor
@RequiredArgsConstructor
@Getter
public enum LoaderButton {
SWITCH(0, true, "LOADER_BUTTON_SWITCH"),
WOOD_BUTTON(30, "LOADER_BUTTON_WOOD_BUTTON"),
STONE_BUTTON(20, "LOADER_BUTTON_STONE_BUTTON"),
PRESSURE_PLATE(30, "LOADER_BUTTON_PRESSURE_PLATE"),
WEIGHTED_PRESSURE_PLATE(20, "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE"),
TRIPWIRE(30, "LOADER_BUTTON_TRIPWIRE"),
NOTEBLOCK(1, "LOADER_BUTTON_NOTEBLOCK"),
DAYLIGHTSENSOR(0, true, "LOADER_BUTTON_DAYLIGHTSENSOR"),
INVALID(-1, "LOADER_BUTTON_INVALID");
private final int time;
private boolean toggle;
private final String name;
public static LoaderButton fromBlock(Block block) {
switch (block.getType()) {
case LEVER:
return LoaderButton.SWITCH;
case TRIPWIRE:
return LoaderButton.TRIPWIRE;
case NOTE_BLOCK:
return LoaderButton.NOTEBLOCK;
case DAYLIGHT_DETECTOR:
return LoaderButton.DAYLIGHTSENSOR;
case HEAVY_WEIGHTED_PRESSURE_PLATE:
case LIGHT_WEIGHTED_PRESSURE_PLATE:
return LoaderButton.WEIGHTED_PRESSURE_PLATE;
default:
if (block.getType().name().contains("STONE_BUTTON")) {
return LoaderButton.STONE_BUTTON;
} else if (block.getType().name().contains("BUTTON")) {
return LoaderButton.WOOD_BUTTON;
} else if (block.getType().name().contains("PRESSURE_PLATE")) {
return LoaderButton.PRESSURE_PLATE;
} else {
return LoaderButton.INVALID;
}
}
}
}

Datei anzeigen

@ -1,160 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.linkage.Linked;
import org.bukkit.entity.Player;
// @Linked
public class LoaderCommand extends SWCommand {
public LoaderCommand() {
super("loader", "autoloader", "al");
addDefaultHelpMessage("LOADER_HELP_OTHER");
}
private boolean loaderNullCheck(Loader loader, Player p) {
if (loader == null) {
BauSystem.MESSAGE.send("LOADER_NO_LOADER", p);
return true;
}
return false;
}
@Register(value = "setup", description = "LOADER_HELP_SETUP")
public void setupLoader(@Validator Player p) {
if (Loader.getLoader(p) != null) {
Loader.getLoader(p).setup();
BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p);
} else {
Loader.newLoader(p);
BauSystem.MESSAGE.send("LOADER_NEW", p);
BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p);
}
}
@Register(value = "start", description = "LOADER_HELP_START")
public void startLoader(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
loader.start();
BauSystem.MESSAGE.send("LOADER_ACTIVE", p);
}
@Register(value = "stop", description = "LOADER_HELP_STOP")
public void stopLoader(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
loader.stop();
BauSystem.MESSAGE.send("LOADER_STOP", p);
}
@Register(value = "pause", description = "LOADER_HELP_PAUSE")
public void pauseLoader(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
loader.pause();
BauSystem.MESSAGE.send("LOADER_PAUSED", p);
}
@Register(value = "resume", description = "LOADER_HELP_RESUME")
public void resumeLoader(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
loader.resume();
BauSystem.MESSAGE.send("LOADER_RESUME", p);
}
@Register(value = "wait", description = "LOADER_HELP_WAIT")
public void shotDelayLoader(@Validator Player p, int delay) {
if (delay < 1) {
BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p);
return;
}
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
BauSystem.MESSAGE.send("LOADER_NEW_TIME", p, delay, loader.getTicksBetweenShots());
loader.setTicksBetweenShots(delay);
}
@Register(value = "speed", description = "LOADER_HELP_SPEED")
public void speedLoader(@Validator Player p, int delay) {
if (delay < 0) {
BauSystem.MESSAGE.send("LOADER_SMALL_TIME", p);
return;
}
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay, loader.getTicksBetweenBlocks());
loader.setTicksBetweenBlocks(delay);
}
@Register(value = "undo", description = "LOADER_HELP_UNDO")
public void undoLast(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
BauSystem.MESSAGE.send("LOADER_UNDO", p);
loader.undo();
}
@Register(value = "clear", description = "LOADER_HELP_CLEAR")
public void clearLoader(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
loader.clear();
}
@Register(value = "single", description = "LOADER_HELP_SINGLE")
public void singleLoader(@Validator Player p) {
Loader loader = Loader.getLoader(p);
if (loaderNullCheck(loader, p)) {
return;
}
loader.single();
BauSystem.MESSAGE.send("LOADER_SINGLE", p);
}
@ClassValidator(value = Player.class, local = true)
public TypeValidator<Player> loaderValidator() {
return (commandSender, player, messageSender) -> {
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "LOADER_PERMS");
};
}
}

Datei anzeigen

@ -1,36 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader.activations;
import de.steamwar.bausystem.features.loader.Loader;
import org.bukkit.entity.Player;
public abstract class AbstractLoaderActivation {
Player p;
public AbstractLoaderActivation(Player p) {
this.p = p;
}
public abstract boolean execute();
public abstract int delay(Loader loader);
}

Datei anzeigen

@ -1,57 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader.activations;
import de.steamwar.bausystem.features.loader.Loader;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
public class BlockPlaceLoaderActivation extends AbstractLoaderActivation {
private final Location location;
private final Material material;
public BlockPlaceLoaderActivation(Player p, Location location, Material material) {
super(p);
this.location = location;
if (!material.isBlock()) {
throw new IllegalStateException("Only Blocks, " + material.name() + " is not a Block");
}
this.material = material;
}
@Override
public boolean execute() {
Block currBlock = location.getBlock();
if (currBlock.getType() != Material.AIR && currBlock.getType() != Material.WATER) {
return false;
}
currBlock.setType(material, true);
return true;
}
@Override
public int delay(Loader loader) {
return loader.getTicksBetweenBlocks();
}
}

Datei anzeigen

@ -1,174 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.loader.activations;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.Loader;
import de.steamwar.bausystem.features.loader.LoaderButton;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.*;
import org.bukkit.block.data.type.DaylightDetector;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.Player;
public abstract class InteractionActivation extends AbstractLoaderActivation {
Location location;
LoaderButton button;
InteractionActivation(Player p, Location location, LoaderButton button) {
super(p);
this.location = location;
this.button = button;
}
public static InteractionActivation construct(Player p, Location location, Loader loader) {
LoaderButton button = LoaderButton.fromBlock(location.getBlock());
if (button.isToggle()) {
return new ToggleActivation(p, location, button, loader.getLastActivation());
} else {
return new TimedActivation(p, location, button);
}
}
void updateButton() {
Block block = location.getBlock();
if (block.getBlockData() instanceof Switch) {
Switch sw = (Switch) block.getBlockData();
FaceAttachable.AttachedFace face = sw.getAttachedFace();
if (face == FaceAttachable.AttachedFace.FLOOR) {
update(block.getRelative(BlockFace.DOWN));
} else if (face == FaceAttachable.AttachedFace.CEILING) {
update(block.getRelative(BlockFace.UP));
} else {
update(block.getRelative(sw.getFacing().getOppositeFace()));
}
} else if (button == LoaderButton.TRIPWIRE) {
update(block);
} else if (button == LoaderButton.PRESSURE_PLATE || button == LoaderButton.WEIGHTED_PRESSURE_PLATE) {
update(block.getRelative(BlockFace.DOWN));
}
}
void update(Block block) {
BlockData data = block.getBlockData();
block.setType(Material.BARRIER, true);
block.setBlockData(data, true);
}
boolean getBlockPower() {
Block block = location.getBlock();
BlockData data = block.getBlockData();
if (data instanceof Powerable) {
Powerable pow = (Powerable) data;
return pow.isPowered();
}
if (data instanceof DaylightDetector) {
DaylightDetector detector = (DaylightDetector) data;
return detector.isInverted();
}
if (data instanceof AnaloguePowerable) {
AnaloguePowerable powerable = (AnaloguePowerable) data;
return powerable.getPower() > 0;
}
return false;
}
void setBlockPower(boolean state) {
Block block = location.getBlock();
BlockData data = block.getBlockData();
if (data instanceof Powerable) {
Powerable pow = (Powerable) data;
pow.setPowered(state);
}
if (data instanceof Openable) {
Openable openable = (Openable) data;
openable.setOpen(state);
}
if (data instanceof DaylightDetector) {
DaylightDetector detector = (DaylightDetector) data;
detector.setInverted(state);
}
if (data instanceof AnaloguePowerable) {
AnaloguePowerable powerable = (AnaloguePowerable) data;
if (block.getType() == Material.REDSTONE_WIRE) {
powerable.setPower(state ? 15 : 0);
} else {
powerable.setPower(state ? 1 : 0);
}
}
block.setBlockData(data);
}
public static class ToggleActivation extends InteractionActivation {
private final int delay;
public ToggleActivation(Player p, Location location, LoaderButton button, int delay) {
super(p, location, button);
this.delay = Math.max(delay, 0);
}
@Override
public boolean execute() {
if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID)
return false;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
setBlockPower(!getBlockPower());
updateButton();
}, delay);
return true;
}
@Override
public int delay(Loader loader) {
return delay;
}
}
public static class TimedActivation extends InteractionActivation {
public TimedActivation(Player p, Location location, LoaderButton button) {
super(p, location, button);
}
@Override
public boolean execute() {
if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID)
return false;
setBlockPower(true);
updateButton();
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
setBlockPower(false);
updateButton();
}, button.getTime());
return true;
}
@Override
public int delay(Loader loader) {
return button.getTime();
}
}
}

Datei anzeigen

@ -21,7 +21,10 @@ package de.steamwar.bausystem.features.loadern;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loadern.elements.LoaderElement; import de.steamwar.bausystem.features.loadern.elements.LoaderElement;
import de.steamwar.bausystem.shared.EnumDisplay;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -47,6 +50,7 @@ public class Loader implements Listener {
private final Player p; private final Player p;
@Getter
private Stage stage = Stage.SETUP; private Stage stage = Stage.SETUP;
private LoaderRecorder recorder; private LoaderRecorder recorder;
@ -121,10 +125,14 @@ public class Loader implements Listener {
stop(); stop();
} }
public enum Stage { @AllArgsConstructor
SETUP, public enum Stage implements EnumDisplay {
RUNNING, SETUP("LOADER_SETUP"),
PAUSE, RUNNING("LOADER_RUNNING"),
END PAUSE("LOADER_PAUSE"),
END("LOADER_END");
@Getter
private String chatValue;
} }
} }

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.features.loader; package de.steamwar.bausystem.features.loadern;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;

Datei anzeigen

@ -59,8 +59,9 @@ public class LoaderWait implements LoaderElement, Listener {
@Override @Override
public void click(Player player, Runnable backAction) { public void click(Player player, Runnable backAction) {
SWInventory swInventory = new SWInventory(player, 9, "Wartezeit"); SWInventory swInventory = new SWInventory(player, 18, "Wartezeit");
swInventory.setItem(0, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run()); for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run());
swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> { swInventory.setItem(3, new SWItem(SWItem.getDye(1), "§c-1").getItemStack(), clickType -> {
delay -= clickType.isShiftClick() ? 5 : 1; delay -= clickType.isShiftClick() ? 5 : 1;