SteamWar/BauSystem2.0
Archiviert
12
0

Merge pull request 'LoaderRework' (#175) from LoaderRework into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #175
Dieser Commit ist enthalten in:
YoyoNow 2023-05-09 18:31:41 +02:00
Commit a573836bd6
24 geänderte Dateien mit 2186 neuen und 753 gelöschten Zeilen

Datei anzeigen

@ -788,60 +788,85 @@ TRACE_GUI_POSITION_EXPLODED = §7Exploded§8: §e{0}
# Loader # Loader
LOADER_SETUP = §eSetup LOADER_SETUP = §eSetup
LOADER_RUNNING = §aRunning LOADER_RUNNING = §aRunning
LOADER_SINGLE_SIDEBAR = §aSingle
LOADER_PAUSE = §7Pause LOADER_PAUSE = §7Pause
LOADER_END = §8Finished LOADER_END = §8Finished
LOADER_MESSAGE_CLEAR = §7Loader cleared
LOADER_MESSAGE_CLEAR_HELP = §cYou have to be in Setup-Mode to clear the Loader
LOADER_MESSAGE_TNT = §eTNT added {0}
LOADER_MESSAGE_INTERACT=§e{0} added {1} LOADER_MESSAGE_INTERACT=§e{0} added {1}
LOADER_BUTTON_TNT=TNT
LOADER_BUTTON_SWITCH=Lever LOADER_BUTTON_SWITCH=Lever
LOADER_BUTTON_WOOD_BUTTON=Button LOADER_BUTTON_WOOD_BUTTON=Wooden Button
LOADER_BUTTON_STONE_BUTTON=Button LOADER_BUTTON_STONE_BUTTON=Stone Button
LOADER_BUTTON_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_PRESSURE_PLATE=Pressure plate
LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Pressure plate LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Pressure plate
LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_TRIPWIRE=Tripwire
LOADER_BUTTON_NOTEBLOCK=Noteblock LOADER_BUTTON_NOTEBLOCK=Noteblock
LOADER_BUTTON_DAYLIGHTSENSOR=Daylightsensor LOADER_BUTTON_DAYLIGHT_DETECTOR=Daylight Detector
LOADER_BUTTON_INVALID=Invalid LOADER_BUTTON_COMPARATOR=Comparator
LOADER_BUTTON_REPEATER=Repeater
LOADER_BUTTON_LECTERN=Lectern
LOADER_BUTTON_TRAPDOOR=Trapdoor
LOADER_BUTTON_DOOR=Door
LOADER_BUTTON_FENCEGATE=Fencegate
LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions LOADER_HELP_SETUP=§8/§eloader setup §8- §7Starts recording actions
LOADER_HELP_UNDO=§8/§7loader undo §8- §7Removes last recorded action LOADER_SETUP_STOP_FIRST=§cPlease stop the current loader first!
LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action LOADER_HELP_START=§8/§eloader start §8- §7Playback of previously recorded action
LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Sets wait time between shots
LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Sets wait time between actions
LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pauses Loader
LOADER_HELP_RESUME=§8/§7loader resume §8- §7Resumes Loader LOADER_HELP_GUI=§8/§7loader gui §8- §7Shows Loader gui
LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback LOADER_HELP_STOP=§8/§eloader stop §8- §7Stops recording/playback
LOADER_HELP_CLEAR=§8/§eloader clear §8- §7Clears recording
LOADER_HELP_SINGLE=§8/§eloader single §8- §7Starts a single shot
LOADER_HELP_OTHER=§7The loader works with §eIngame§8-§eTicks §7(20 ticks per Second)
LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup LOADER_NO_LOADER=§cYou have no Laoder. Create one with /loader setup
LOADER_BACK_SETUP=§7DYour Loader is in Setup again
LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader. LOADER_NEW=§7Load your cannon and fire it once, to initialise the loader.
LOADER_HOW_TO_START=§7Then, execute /§eloader start§7 to start the Loader LOADER_HOW_TO_START=§7Then, execute /§eloader start§7 to start the Loader
LOADER_ACTIVE=§7The Loader is now active. LOADER_ACTIVE=§7The Loader is now active.
LOADER_STOP=§7The Loader has been stopped. LOADER_STOP=§7The Loader has been stopped.
LOADER_PAUSED=§7The Loader is now paused. LOADER_PAUSED=§7The Loader is now paused.
LOADER_RESUME=§7The Loader is resuming.
LOADER_SINGLE=§7The Loader is shooting once.
LOADER_SMALL_TIME=§cThe wait time is too small
LOADER_NEW_TIME=§7The wait time is now: {0}, before {1}
LOADER_NEW_LOAD_TIME=§7The action wait time is now: {0}, before {1}
LOADER_UNDO=§7Undo succesful.
LOADER_PERMS=§cYou are not allowed to use the Loader here LOADER_PERMS=§cYou are not allowed to use the Loader here
LOADER_GUI_NAME=§eLoader
LOADER_GUI_NEW=§eNew Loader LOADER_NOTHING_RECORDED=§cYou have not recorded anything yet!
LOADER_GUI_START=§eStart Loader LOADER_GUI_TITLE=Loader GUI
LOADER_GUI_PAUSE=§7pause Loader LOADER_GUI_SHOW_INTERACTIONS=§eShow only Interactions
LOADER_GUI_UNDO=§7Undo last action LOADER_GUI_SHOW_WAITS=§eShow only Waits
LOADER_GUI_WAIT=§7Shot delay LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT
LOADER_GUI_WAIT_LORE=§7Currently: §e{0} LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all
LOADER_GUI_WAIT_TITLE=§7Shot delay LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time
LOADER_GUI_SPEED=§eSpeed LOADER_GUI_SETTINGS_TITLE=Settings
LOADER_GUI_SPEED_LORE=§7Currently: §e{0} LOADER_GUI_SETTINGS_BACK=§8Back
LOADER_GUI_SPEED_TITLE=§7Block placing speed LOADER_GUI_SETTINGS_DELETE=§cDelete
LOADER_GUI_STOP=§eStop Loader LOADER_GUI_WAIT_TITLE=Settings
LOADER_GUI_WAIT_BACK=§8Back
LOADER_GUI_CLICK_TO_EDIT=§7Klicke zum editieren
LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1}
LOADER_SETTING_NAME=§7{0}
LOADER_SETTING_MODES=§7Modi§8: §e{0}
LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0}
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s)
LOADER_SETTING_WAIT_NAME=Wartezeit
LOADER_SETTING_TICKS_NAME=Ticks
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
LOADER_SETTING_TICKS_ADD_ONE=§a+1
LOADER_SETTING_TICKS_ADD_ONE_SHIFT=§7Shift§8: §a+5
LOADER_SETTING_TNT_NAME=§cTNT
LOADER_SETTING_TNT_X=§7X§8: §e{0}
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
LOADER_INTERACTION_NOOP=NOOP
LOADER_INTERACTION_INTERACT=Interagiere
LOADER_INTERACTION_POWERED=Aktiviert
LOADER_INTERACTION_UNPOWERED=Deaktiviert
LOADER_INTERACTION_PAGE_PREV=Vorherige Seite
LOADER_INTERACTION_PAGE_NEXT=Nächste Seite
LOADER_INTERACTION_PAGE=Seite {0}
LOADER_INTERACTION_ACTIVE=Aktiviert
LOADER_INTERACTION_INACTIVE=Deaktiviert
LOADER_INTERACTION_WAIT_FOR=Darauf warten
LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten
LOADER_INTERACTION_OPEN=Geöffnet
LOADER_INTERACTION_CLOSED=Geschlossen
# Loadtimer # Loadtimer
LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon
LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Starts the simple Loadtimer

Datei anzeigen

@ -761,60 +761,85 @@ TRACE_GUI_POSITION_EXPLODED = §7Explodiert§8: §e{0}
# Loader # Loader
LOADER_SETUP = §eEinrichtung LOADER_SETUP = §eEinrichtung
LOADER_RUNNING = §aLaufend LOADER_RUNNING = §aLaufend
LOADER_SINGLE_SIDEBAR = §aEiner
LOADER_PAUSE = §7Pausiert LOADER_PAUSE = §7Pausiert
LOADER_END = §8Beendet LOADER_END = §8Beendet
LOADER_MESSAGE_CLEAR = §7Loader gecleart
LOADER_MESSAGE_CLEAR_HELP = §cDu must im Setup-Modus sein um den Loader zu clearen
LOADER_MESSAGE_TNT = §eTNT hinzugefügt {0}
LOADER_MESSAGE_INTERACT = §e{0} hinzugefügt {1} LOADER_MESSAGE_INTERACT = §e{0} hinzugefügt {1}
LOADER_BUTTON_TNT = TNT
LOADER_BUTTON_SWITCH=Hebel LOADER_BUTTON_SWITCH=Hebel
LOADER_BUTTON_WOOD_BUTTON=Knopf LOADER_BUTTON_WOOD_BUTTON=Holzknopf
LOADER_BUTTON_STONE_BUTTON=Knopf LOADER_BUTTON_STONE_BUTTON=Steinknopf
LOADER_BUTTON_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_PRESSURE_PLATE=Druckplatte
LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Druckplatte LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE=Druckplatte
LOADER_BUTTON_TRIPWIRE=Tripwire LOADER_BUTTON_TRIPWIRE=Tripwire
LOADER_BUTTON_NOTEBLOCK=Noteblock LOADER_BUTTON_NOTEBLOCK=Noteblock
LOADER_BUTTON_DAYLIGHTSENSOR=Tageslichtsensor LOADER_BUTTON_DAYLIGHT_DETECTOR=Tageslichtsensor
LOADER_BUTTON_INVALID=Invalider LOADER_BUTTON_COMPARATOR=Comparator
LOADER_BUTTON_REPEATER=Repeater
LOADER_BUTTON_LECTERN=Lectern
LOADER_BUTTON_TRAPDOOR=Trapdoor
LOADER_BUTTON_DOOR=Door
LOADER_BUTTON_FENCEGATE=Fencegate
LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen LOADER_HELP_SETUP=§8/§eloader setup §8- §7Startet die Aufnahme der Aktionen
LOADER_HELP_UNDO=§8/§7loader undo §8- §7Entfernt die zuletzt aufgenommene Aktion LOADER_SETUP_STOP_FIRST=§cBitte stoppe zuerst den Loader
LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab LOADER_HELP_START=§8/§eloader start §8- §7Spielt die zuvor aufgenommenen Aktionen ab
LOADER_HELP_WAIT=§8/§7loader wait §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Schüssen
LOADER_HELP_SPEED=§8/§7loader speed §8[§7Ticks§8] - §7Setzt die Wartezeit zwischen Aktionen
LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen LOADER_HELP_PAUSE=§8/§7loader pause §8- §7Pausiert das Abspielen
LOADER_HELP_RESUME=§8/§7loader resume §8- §7Spielt den Loader weiter ab LOADER_HELP_GUI=§8/§7loader settings §8- §7Zeigt die Einstellungen an
LOADER_HELP_STOP=§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen LOADER_HELP_STOP=§8/§eloader stop §8- §7Stoppt die Aufnahme bzw. das Abspielen
LOADER_HELP_CLEAR=§8/§eloader clear §8- §7Cleart die Aufnahme
LOADER_HELP_SINGLE=§8/§eloader single §8- §7Spielt die Aufnahme einmal ab
LOADER_HELP_OTHER=§7Der Loader arbeitet mit §eIngame§8-§eTicks §7(20 Ticks pro Sekunde)
LOADER_NO_LOADER=§cDu hast noch keinen Loader. Erstelle dir einen mit /loader setup LOADER_NO_LOADER=§cDu hast noch keinen Loader. Erstelle dir einen mit /loader setup
LOADER_BACK_SETUP=§7Dein Loader ist nun wieder im Setup
LOADER_NEW=§7Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren. LOADER_NEW=§7Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren.
LOADER_HOW_TO_START=§7Führe dann /§eloader start§7 um den Loader zu starten LOADER_HOW_TO_START=§7Führe dann /§eloader start§7 um den Loader zu starten
LOADER_ACTIVE=§7Der Loader ist nun aktiviert. LOADER_ACTIVE=§7Der Loader ist nun aktiviert.
LOADER_STOP=§7Der Loader ist nun gestoppt. LOADER_STOP=§7Der Loader ist nun gestoppt.
LOADER_PAUSED=§7Der Loader ist nun pausiert. LOADER_PAUSED=§7Der Loader ist nun pausiert.
LOADER_RESUME=§7Der Loader läuft nun weiter.
LOADER_SINGLE=§7Der Loader schießt einmal.
LOADER_SMALL_TIME=§cDie Wartezeit ist zu klein
LOADER_NEW_TIME=§7Die Schusswartezeit ist nun: {0}, zuvor {1}
LOADER_NEW_LOAD_TIME=§7Die Setzwartezeit ist nun: {0}, zuvor {1}
LOADER_UNDO=§7Undo erfolgreich.
LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen
LOADER_GUI_NAME=§eLoader
LOADER_GUI_NEW=§eNeuer Loader LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen!
LOADER_GUI_START=§eLoader starten LOADER_GUI_TITLE=Loader Einstellungen
LOADER_GUI_PAUSE=§7Loader pausieren LOADER_GUI_SHOW_INTERACTIONS=§eZeige Interaktionen
LOADER_GUI_UNDO=§7Letzte Aktion Rückgängig machen LOADER_GUI_SHOW_WAITS=§eZeige Wartezeiten
LOADER_GUI_WAIT=§7Schuss Delay LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT
LOADER_GUI_WAIT_LORE=§7Aktuell: §e{0} LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle
LOADER_GUI_WAIT_TITLE=§7Schuss Delay LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit
LOADER_GUI_SPEED=§eGeschwindigkeit LOADER_GUI_SETTINGS_TITLE=Einstellungen
LOADER_GUI_SPEED_LORE=§7Aktuell: §e{0} LOADER_GUI_SETTINGS_BACK=§8Zurück
LOADER_GUI_SPEED_TITLE=§7Block Platzier Geschwindigkeit LOADER_GUI_SETTINGS_DELETE=§cLöschen
LOADER_GUI_STOP=§eLoader Stoppen LOADER_GUI_WAIT_TITLE=Wartezeit
LOADER_GUI_WAIT_BACK=§8Zurück
LOADER_GUI_CLICK_TO_EDIT=§7Click to edit
LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1}
LOADER_SETTING_NAME=§7{0}
LOADER_SETTING_MODES=§7Modes§8: §e{0}
LOADER_SETTING_POWER=§7Power§8: §e{0}
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s)
LOADER_SETTING_WAIT_NAME=Wait
LOADER_SETTING_TICKS_NAME=Ticks
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
LOADER_SETTING_TICKS_ADD_ONE=§a+1
LOADER_SETTING_TICKS_ADD_ONE_SHIFT=§7Shift§8: §a+5
LOADER_SETTING_TNT_NAME=§cTNT
LOADER_SETTING_TNT_X=§7X§8: §e{0}
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
LOADER_INTERACTION_NOOP=NOOP
LOADER_INTERACTION_INTERACT=Interact
LOADER_INTERACTION_POWERED=Powered
LOADER_INTERACTION_UNPOWERED=Unpowered
LOADER_INTERACTION_PAGE_PREV=Previous Page
LOADER_INTERACTION_PAGE_NEXT=Next Page
LOADER_INTERACTION_PAGE=Page {0}
LOADER_INTERACTION_ACTIVE=Active
LOADER_INTERACTION_INACTIVE=Inactive
LOADER_INTERACTION_WAIT_FOR=Wait for
LOADER_INTERACTION_NO_WAIT_FOR=No wait for
LOADER_INTERACTION_OPEN=Open
LOADER_INTERACTION_CLOSED=Closed
# Loadtimer # Loadtimer
LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone
LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer LOADTIMER_HELP_START_1=§8/§eloadtimer start §8-§7 Startet den einfachen Loadtimer

Datei anzeigen

@ -1,7 +1,7 @@
/* /*
* This file is a part of the SteamWar software. * This file is a part of the SteamWar software.
* *
* Copyright (C) 2021 SteamWar.de-Serverteam * Copyright (C) 2023 SteamWar.de-Serverteam
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -20,225 +20,208 @@
package de.steamwar.bausystem.features.loader; package de.steamwar.bausystem.features.loader;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.loader.elements.LoaderElement;
import de.steamwar.bausystem.features.loader.activations.AbstractLoaderActivation; import de.steamwar.bausystem.features.loader.elements.impl.LoaderTNT;
import de.steamwar.bausystem.features.loader.activations.BlockPlaceLoaderActivation; import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait;
import de.steamwar.bausystem.features.loader.activations.InteractionActivation;
import de.steamwar.bausystem.shared.EnumDisplay; import de.steamwar.bausystem.shared.EnumDisplay;
import lombok.AccessLevel; import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; 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.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.scheduler.BukkitTask;
import java.util.*; import java.util.*;
@Getter
@Setter
public class Loader implements Listener { public class Loader implements Listener {
private static final Map<Player, Loader> LOADER_MAP = new HashMap<>(); private static final Map<Player, Loader> LOADER_MAP = new HashMap<>();
public static Loader getLoader(Player player) {
return LOADER_MAP.get(player);
}
public static void newLoader(Player player) {
LOADER_MAP.put(player, new Loader(player));
}
private final Player p; 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) @Getter
private final BukkitTask task; private Stage stage = Stage.SETUP;
private LoaderRecorder recorder;
@Getter(AccessLevel.PRIVATE) private List<LoaderElement> elements = new ArrayList<>();
@Setter(AccessLevel.PRIVATE) private int currentElement = 0;
private AbstractLoaderActivation current; private long totalDelay = 0;
@Getter(AccessLevel.PRIVATE) public Loader(Player p) {
@Setter(AccessLevel.PRIVATE)
private ListIterator<AbstractLoaderActivation> iterator;
private Loader(Player p) {
this.p = p; this.p = p;
stage = Stage.SETUP; this.recorder = new LoaderRecorder(p, elements);
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::run, 1, 1);
} }
public static Loader getLoader(Player p) { private void next() {
return LOADER_MAP.getOrDefault(p, null); currentElement++;
if (currentElement >= elements.size()) {
currentElement = 0;
if (totalDelay == 0) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1);
return;
}
totalDelay = 0;
}
if (stage == Stage.RUNNING) {
LoaderElement element = elements.get(currentElement);
if (element instanceof LoaderWait) {
totalDelay += ((LoaderWait) element).getDelay();
}
element.execute(this::next);
} }
public static Loader newLoader(Player p) {
return LOADER_MAP.put(p, new Loader(p));
} }
public void start() { public void start() {
if (stage != Stage.SETUP) return; if (stage == Stage.END) return;
iterator = actions.listIterator(); if (stage == Stage.RUNNING) return;
countdown = 0;
current = null;
stage = Stage.RUNNING; stage = Stage.RUNNING;
if (recorder != null) {
recorder.stop();
recorder = null;
}
if (elements.isEmpty()) {
BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p);
stop();
return;
}
elements.get(currentElement).execute(this::next);
} }
public void pause() { public void pause() {
if (stage == Stage.RUNNING) { if (stage == Stage.END) return;
if (stage == Stage.PAUSE) return;
stage = Stage.PAUSE; stage = Stage.PAUSE;
if (recorder != null) {
recorder.stop();
recorder = null;
} }
} }
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() { public void stop() {
stage = Stage.END; stage = Stage.END;
task.cancel(); if (recorder != null) {
LOADER_MAP.remove(p, this); recorder.stop();
recorder = null;
}
elements.clear();
LOADER_MAP.remove(p);
} }
public void clear() { public void gui(SettingsSorting settingsSorting) {
if (stage == Stage.SETUP) { List<SWListInv.SWListEntry<LoaderElement>> list = new ArrayList<>();
actions.clear(); for (LoaderElement element : elements) {
BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR", p); if (settingsSorting != null) {
if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) {
continue;
}
if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) {
continue;
}
}
SWItem item = element.menu(p);
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, elements.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p)));
list.add(new SWListInv.SWListEntry<>(item, element));
}
SWListInv<LoaderElement> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {});
swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open));
SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_INTERACTIONS", p), clickType -> {
gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS);
});
if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true);
swListInv.setItem(47, onlyInteractionsElements);
SWItem onlyWaitElements = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS", p), clickType -> {
gui(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT);
});
if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true);
swListInv.setItem(48, onlyWaitElements);
if (settingsSorting == SettingsSorting.WAIT) {
SWItem waitBetweenTNT = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT", p), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), "");
swAnvilInv.setCallback(s -> {
try {
long delay = Long.parseLong(s);
if (delay < 0) delay = 0;
for (int i = 1; i < elements.size() - 1; i++) {
if (!(elements.get(i - 1) instanceof LoaderTNT)) continue;
if (!(elements.get(i + 1) instanceof LoaderTNT)) continue;
if (!(elements.get(i) instanceof LoaderWait)) continue;
((LoaderWait) elements.get(i)).setDelay(delay);
}
} catch (NumberFormatException ignored) {
}
gui(settingsSorting);
});
swAnvilInv.open();
});
swListInv.setItem(50, waitBetweenTNT);
SWItem waitTime = new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_ALL", p), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), "");
swAnvilInv.setCallback(s -> {
try {
long delay = Long.parseLong(s);
if (delay < 0) delay = 0;
long finalDelay = delay;
elements.stream()
.filter(LoaderWait.class::isInstance)
.map(LoaderWait.class::cast)
.forEach(loaderWait -> loaderWait.setDelay(finalDelay));
} catch (NumberFormatException ignored) {
}
gui(settingsSorting);
});
swAnvilInv.open();
});
swListInv.setItem(51, waitTime);
} else { } else {
BauSystem.MESSAGE.send("LOADER_MESSAGE_CLEAR_HELP", p); SWItem empty = new SWItem(Material.STRUCTURE_VOID, "§7", clickType -> {});
} swListInv.setItem(50, empty);
swListInv.setItem(51, empty);
} }
public void single() { swListInv.open();
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 @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (event.getPlayer() != p) { if (event.getPlayer() != p) return;
return;
}
stop(); stop();
} }
public String getProgress() {
return (currentElement + 1) + "§8/§7" + elements.size();
}
public enum SettingsSorting {
WAIT,
INTERACTIONS,
}
@AllArgsConstructor @AllArgsConstructor
public enum Stage implements EnumDisplay { public enum Stage implements EnumDisplay {
SETUP("LOADER_SETUP"), SETUP("LOADER_SETUP"),
RUNNING("LOADER_RUNNING"), RUNNING("LOADER_RUNNING"),
SINGLE("LOADER_SINGLE_SIDEBAR"),
PAUSE("LOADER_PAUSE"), PAUSE("LOADER_PAUSE"),
END("LOADER_END"); END("LOADER_END");
@Getter @Getter
private String chatValue; private final 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,7 +1,7 @@
/* /*
* This file is a part of the SteamWar software. * This file is a part of the SteamWar software.
* *
* Copyright (C) 2021 SteamWar.de-Serverteam * Copyright (C) 2023 SteamWar.de-Serverteam
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -30,8 +30,7 @@ import org.bukkit.entity.Player;
public class LoaderCommand extends SWCommand { public class LoaderCommand extends SWCommand {
public LoaderCommand() { public LoaderCommand() {
super("loader", "autoloader", "al"); super("loader");
addDefaultHelpMessage("LOADER_HELP_OTHER");
} }
private boolean loaderNullCheck(Loader loader, Player p) { private boolean loaderNullCheck(Loader loader, Player p) {
@ -43,112 +42,45 @@ public class LoaderCommand extends SWCommand {
} }
@Register(value = "setup", description = "LOADER_HELP_SETUP") @Register(value = "setup", description = "LOADER_HELP_SETUP")
public void setupLoader(@Validator Player p) { public void setupLoader(@Validator Player player) {
if (Loader.getLoader(p) != null) { if (Loader.getLoader(player) != null) {
Loader.getLoader(p).setup(); BauSystem.MESSAGE.send("LOADER_SETUP_STOP_FIRST", player);
BauSystem.MESSAGE.send("LOADER_BACK_SETUP", p); return;
} else {
Loader.newLoader(p);
BauSystem.MESSAGE.send("LOADER_NEW", p);
BauSystem.MESSAGE.send("LOADER_HOW_TO_START", p);
} }
Loader.newLoader(player);
BauSystem.MESSAGE.send("LOADER_NEW", player);
BauSystem.MESSAGE.send("LOADER_HOW_TO_START", player);
} }
@Register(value = "start", description = "LOADER_HELP_START") @Register(value = "start", description = "LOADER_HELP_START")
public void startLoader(@Validator Player p) { public void startLoader(@Validator Player player) {
Loader loader = Loader.getLoader(p); Loader loader = Loader.getLoader(player);
if (loaderNullCheck(loader, p)) { if (loaderNullCheck(loader, player)) return;
return;
}
loader.start(); loader.start();
BauSystem.MESSAGE.send("LOADER_ACTIVE", p); BauSystem.MESSAGE.send("LOADER_ACTIVE", player);
} }
@Register(value = "stop", description = "LOADER_HELP_STOP") @Register(value = "stop", description = "LOADER_HELP_STOP")
public void stopLoader(@Validator Player p) { public void stopLoader(@Validator Player player) {
Loader loader = Loader.getLoader(p); Loader loader = Loader.getLoader(player);
if (loaderNullCheck(loader, p)) { if (loaderNullCheck(loader, player)) return;
return;
}
loader.stop(); loader.stop();
BauSystem.MESSAGE.send("LOADER_STOP", p); BauSystem.MESSAGE.send("LOADER_STOP", player);
} }
@Register(value = "pause", description = "LOADER_HELP_PAUSE") @Register(value = "pause", description = "LOADER_HELP_PAUSE")
public void pauseLoader(@Validator Player p) { public void pauseLoader(@Validator Player player) {
Loader loader = Loader.getLoader(p); Loader loader = Loader.getLoader(player);
if (loaderNullCheck(loader, p)) { if (loaderNullCheck(loader, player)) return;
return;
}
loader.pause(); loader.pause();
BauSystem.MESSAGE.send("LOADER_PAUSED", p); BauSystem.MESSAGE.send("LOADER_PAUSED", player);
} }
@Register(value = "resume", description = "LOADER_HELP_RESUME") @Register(value = "gui", description = "LOADER_HELP_GUI")
public void resumeLoader(@Validator Player p) { public void guiLoader(@Validator Player player) {
Loader loader = Loader.getLoader(p); Loader loader = Loader.getLoader(player);
if (loaderNullCheck(loader, p)) { if (loaderNullCheck(loader, player)) return;
return; loader.gui(null);
}
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) @ClassValidator(value = Player.class, local = true)

Datei anzeigen

@ -0,0 +1,203 @@
/*
* 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.loader;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
import de.steamwar.bausystem.features.loader.elements.impl.*;
import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
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.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.EquipmentSlot;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LoaderRecorder implements Listener {
private Player player;
private List<LoaderElement> loaderElementList;
private long lastInteraction = TPSUtils.currentTick.get();
public LoaderRecorder(Player player, List<LoaderElement> loaderElementList) {
this.player = player;
this.loaderElementList = loaderElementList;
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
}
public void stop() {
addWaitTime(true);
HandlerList.unregisterAll(this);
player = null;
blockSet.clear();
}
private void addWaitTime(boolean last) {
if (loaderElementList.isEmpty()) {
lastInteraction = TPSUtils.currentTick.get();
return;
}
if (loaderElementList.get(loaderElementList.size() - 1) instanceof LoaderWait) {
return;
}
long diff = TPSUtils.currentTick.get() - lastInteraction;
if (last && diff > 160) diff = 160;
lastInteraction = TPSUtils.currentTick.get();
loaderElementList.add(new LoaderWait(diff));
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer() != player) return;
if (event.getBlock().getType() != Material.TNT) return;
addWaitTime(false);
loaderElementList.add(new LoaderTNT(event.getBlock().getLocation()));
message("LOADER_BUTTON_TNT");
}
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEvent event) {
if (event.getPlayer() != player) return;
if (player.isSneaking()) 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;
addWaitTime(false);
Block block = event.getClickedBlock();
Material type = block.getType();
switch (type) {
case COMPARATOR:
loaderElementList.add(new LoaderComparator(block.getLocation()));
message("LOADER_BUTTON_COMPARATOR");
break;
case REPEATER:
loaderElementList.add(new LoaderRepeater(block.getLocation()));
message("LOADER_BUTTON_REPEATER");
break;
case NOTE_BLOCK:
loaderElementList.add(new LoaderNoteBlock(block.getLocation()));
message("LOADER_BUTTON_NOTEBLOCK");
break;
case LEVER:
loaderElementList.add(new LoaderLever(block.getLocation()));
message("LOADER_BUTTON_SWITCH");
break;
case DAYLIGHT_DETECTOR:
loaderElementList.add(new LoaderDaylightDetector(block.getLocation()));
message("LOADER_BUTTON_DAYLIGHT_DETECTOR");
break;
case LECTERN:
loaderElementList.add(new LoaderLectern(block.getLocation()));
message("LOADER_BUTTON_LECTERN");
break;
case IRON_TRAPDOOR:
break;
default:
if (type.name().endsWith("_TRAPDOOR")) {
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_TRAPDOOR", type));
message("LOADER_BUTTON_TRAPDOOR");
} else if (type.name().endsWith("_DOOR")) {
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_DOOR", type));
message("LOADER_BUTTON_DOOR");
} else if (type.name().endsWith("FENCE_GATE")) {
loaderElementList.add(new LoaderOpenable(block.getLocation(), "LOADER_BUTTON_FENCEGATE", type));
message("LOADER_BUTTON_FENCEGATE");
} else if (type.name().endsWith("STONE_BUTTON")) {
loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_STONE_BUTTON", type, 20));
message("LOADER_BUTTON_STONE_BUTTON");
} else if (type.name().endsWith("BUTTON")) {
loaderElementList.add(new LoaderTicks(block.getLocation(), "LOADER_BUTTON_WOOD_BUTTON", type, 30));
message("LOADER_BUTTON_WOOD_BUTTON");
}
break;
}
}
private Map<Location, Long> blockSet = new HashMap<>();
private Map<Location, LoaderMovement> movementSet = new HashMap<>();
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (event.getPlayer() != player) return;
Block fromBlock = event.getFrom().getBlock();
Block toBlock = event.getTo().getBlock();
calcMovementBlocks(fromBlock, toBlock);
fromBlock = fromBlock.getRelative(0, 1, 0);
toBlock = toBlock.getRelative(0, 1, 0);
calcMovementBlocks(fromBlock, toBlock);
}
private void calcMovementBlocks(Block fromBlock, Block toBlock) {
if (!blockSet.containsKey(toBlock.getLocation())) {
Long startTime = blockSet.remove(fromBlock.getLocation());
LoaderMovement loaderMovement = movementSet.remove(fromBlock.getLocation());
if (loaderMovement != null && startTime != null) {
loaderMovement.setInitialTicks(TPSUtils.currentTick.get() - startTime);
}
blockSet.put(toBlock.getLocation(), TPSUtils.currentTick.get());
addWaitTime(false);
loaderMovement = null;
Material type = toBlock.getType();
switch (type) {
case TRIPWIRE:
loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_TRIPWIRE", Material.STRING);
message("LOADER_BUTTON_TRIPWIRE");
break;
case LIGHT_WEIGHTED_PRESSURE_PLATE:
case HEAVY_WEIGHTED_PRESSURE_PLATE:
loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE", type);
message("LOADER_BUTTON_WEIGHTED_PRESSURE_PLATE");
break;
default:
if (type.name().endsWith("PRESSURE_PLATE")) {
loaderMovement = new LoaderMovement(toBlock.getLocation(), "LOADER_BUTTON_PRESSURE_PLATE", type);
message("LOADER_BUTTON_PRESSURE_PLATE");
}
break;
}
if (loaderMovement != null) {
movementSet.put(toBlock.getLocation(), loaderMovement);
loaderElementList.add(loaderMovement);
}
}
}
private void message(String type) {
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_INTERACT", player, BauSystem.MESSAGE.parse(type, player), loaderElementList.size()));
}
}

Datei anzeigen

@ -42,6 +42,12 @@ public class LoaderScoreboardElement implements ScoreboardElement {
public String get(Region region, Player p) { public String get(Region region, Player p) {
Loader loader = Loader.getLoader(p); Loader loader = Loader.getLoader(p);
if (loader == null) return null; if (loader == null) return null;
if (loader.getStage() == Loader.Stage.RUNNING) {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §a" + loader.getProgress();
} else if (loader.getStage() == Loader.Stage.PAUSE) {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: §c" + loader.getProgress();
} else {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p); return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p);
} }
} }
}

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

@ -0,0 +1,36 @@
/*
* 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.loader.elements;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Player;
public interface ElementSettings {
SWItem menu(Player player);
void execute(Runnable nextAction);
void click(Player player, Runnable backAction, Runnable deleteAction);
default void playerInteract() {}
default String translateItemName(String name, String mode, Player player, Object... args) {
return BauSystem.MESSAGE.parse("LOADER_GUI_ITEM_NAME", player, BauSystem.MESSAGE.parse(name, player), BauSystem.MESSAGE.parse(mode, player, args));
}
}

Datei anzeigen

@ -1,7 +1,7 @@
/* /*
* This file is a part of the SteamWar software. * This file is a part of the SteamWar software.
* *
* Copyright (C) 2021 SteamWar.de-Serverteam * Copyright (C) 2023 SteamWar.de-Serverteam
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Affero General Public License as published by
@ -17,20 +17,13 @@
* 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.activations; package de.steamwar.bausystem.features.loader.elements;
import de.steamwar.bausystem.features.loader.Loader; import de.steamwar.inventory.SWItem;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public abstract class AbstractLoaderActivation { public interface LoaderElement {
SWItem menu(Player player);
Player p; void execute(Runnable nextAction);
void click(Player player, Runnable backAction);
public AbstractLoaderActivation(Player p) {
this.p = p;
}
public abstract boolean execute();
public abstract int delay(Loader loader);
} }

Datei anzeigen

@ -0,0 +1,125 @@
/*
* 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.loader.elements;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.FaceAttachable;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public abstract class LoaderInteractionElement<T extends ElementSettings> implements LoaderElement {
protected final Location location;
protected int currentShot = 0;
protected List<T> elements = new ArrayList<>();
protected LoaderInteractionElement(Location location) {
this.location = location;
T element = createNewElement();
element.playerInteract();
elements.add(element);
}
@Override
public void execute(Runnable nextAction) {
if (currentShot >= elements.size()) currentShot = 0;
elements.get(currentShot).execute(nextAction);
currentShot++;
if (currentShot >= elements.size()) currentShot = 0;
}
@Override
public void click(Player player, Runnable backAction) {
List<SWListInv.SWListEntry<T>> entries = new ArrayList<>();
for (T element : elements) {
entries.add(new SWListInv.SWListEntry<>(element.menu(player), element));
}
SWListInv<T> listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> {
entry.click(player, () -> {
click(player, backAction);
}, () -> {
if (elements.size() == 1) return;
elements.remove(entry);
click(player, backAction);
});
});
listInv.setItem(48, new SWItem(Material.ARROW, "§7Back", clickType -> {
backAction.run();
}));
listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> {
T element = createNewElement();
elements.add(element);
element.click(player, () -> click(player, backAction), () -> {
if (elements.size() == 1) return;
elements.remove(element);
click(player, backAction);
});
}));
listInv.open();
}
protected void update(BlockData blockData) {
Material material = blockData.getMaterial();
Block block = location.getBlock();
if (blockData instanceof Switch) {
Switch sw = (Switch) blockData;
updateBlock(block, sw);
FaceAttachable.AttachedFace face = sw.getAttachedFace();
if (face == FaceAttachable.AttachedFace.FLOOR) {
updateBlock(block.getRelative(BlockFace.DOWN));
} else if (face == FaceAttachable.AttachedFace.CEILING) {
updateBlock(block.getRelative(BlockFace.UP));
} else {
updateBlock(block.getRelative(sw.getFacing().getOppositeFace()));
}
} else if (material == Material.TRIPWIRE) {
updateBlock(block, blockData);
} else if (material.name().endsWith("_PLATE")) {
updateBlock(block.getRelative(BlockFace.DOWN));
}
}
protected void updateBlock(Block block) {
updateBlock(block, block.getBlockData());
}
protected void updateBlock(Block block, BlockData data) {
block.setType(Material.BARRIER, true);
block.setBlockData(data, true);
}
public abstract T createNewElement();
protected final String translateItemName(String name, Player player) {
return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player));
}
}

Datei anzeigen

@ -0,0 +1,136 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.Comparator;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.ComparatorSettings> {
public LoaderComparator(Location location) {
super(location);
}
public class ComparatorSettings implements ElementSettings {
private boolean interact = false;
private Comparator.Mode mode = Comparator.Mode.COMPARE;
@Override
public SWItem menu(Player player) {
return menu(player, interact, mode);
}
private SWItem menu(Player player, boolean interact, Comparator.Mode mode) {
SWItem swItem;
if (interact) {
swItem = new SWItem(Material.STICK, "§7Comparator§8: §eInteract");
} else if (mode == null) {
swItem = new SWItem(Material.STRUCTURE_VOID, "§7Comparator§8: §eNOOP");
} else {
swItem = new SWItem(Material.COMPARATOR, "§7Comparator§8: §e" + mode.name());
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != Material.COMPARATOR) return;
Comparator comparator = (Comparator) location.getBlock().getBlockData();
if (interact) {
comparator.setMode(comparator.getMode() == Comparator.Mode.COMPARE ? Comparator.Mode.SUBTRACT : Comparator.Mode.COMPARE);
} else if (mode == null) {
return;
} else {
comparator.setMode(mode);
}
location.getBlock().setBlockData(comparator, true);
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, false, null).getItemStack(), clickType -> {
interact = false;
mode = null;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, true, null).getItemStack(), clickType -> {
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, Comparator.Mode.COMPARE).getItemStack(), clickType -> {
interact = false;
mode = Comparator.Mode.COMPARE;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, Comparator.Mode.SUBTRACT).getItemStack(), clickType -> {
interact = false;
mode = Comparator.Mode.SUBTRACT;
click(player, backAction, deleteAction);
});
swInventory.open();
}
private SWItem item(Player player, boolean interact, Comparator.Mode mode) {
SWItem swItem = menu(player, interact, mode);
if (swItem.getItemStack().equals(menu(player, this.interact, this.mode).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
@Override
public void playerInteract() {
interact = true;
mode = null;
}
}
@Override
public SWItem menu(Player player) {
SWItem swItem = new SWItem(Material.COMPARATOR, "§7Comparator");
swItem.setLore(Arrays.asList("§7Modes§8: §e" + elements.size(), "§8", "§7Click to edit"));
return swItem;
}
@Override
public ComparatorSettings createNewElement() {
return new ComparatorSettings();
}
}

Datei anzeigen

@ -0,0 +1,158 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.DaylightDetector;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDaylightDetector.DaylightDetectorSettings> {
public LoaderDaylightDetector(Location location) {
super(location);
}
public class DaylightDetectorSettings implements ElementSettings {
private boolean noop = false;
private boolean interact = false;
private boolean inverted = true;
private int power = 0;
@Override
public SWItem menu(Player player) {
return menu(player, noop, interact, inverted);
}
private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", "LOADER_INTERACTION_NOOP", player));
} else if (interact) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", "LOADER_INTERACTION_INTERACT", player));
} else {
swItem = new SWItem(Material.DAYLIGHT_DETECTOR, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", powered ? "LOADER_INTERACTION_POWERED": "LOADER_INTERACTION_UNPOWERED", player));
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != Material.DAYLIGHT_DETECTOR) return;
DaylightDetector daylightDetector = (DaylightDetector) location.getBlock().getBlockData();
if (noop) {
return;
} else if (interact) {
daylightDetector.setInverted(!daylightDetector.isInverted());
} else {
daylightDetector.setInverted(inverted);
}
daylightDetector.setPower(daylightDetector.isInverted() ? 15 - power : power);
location.getBlock().setBlockData(daylightDetector);
updateBlock(location.getBlock().getRelative(0, -1, 0));
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 36, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 27; i < 35; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(27, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(35, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> {
noop = false;
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> {
noop = false;
interact = false;
inverted = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> {
noop = false;
interact = false;
inverted = true;
click(player, backAction, deleteAction);
});
for (int i = 0; i < 16; i++) {
int finalI = i;
int finalI2 = i;
if (i >= 9) finalI2++;
swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> {
power = finalI;
click(player, backAction, deleteAction);
});
}
swInventory.open();
}
private SWItem item(Player player, boolean noop, boolean interact, boolean inverted) {
SWItem swItem = menu(player, noop, interact, inverted);
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.inverted).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
private SWItem item(Player player, int power) {
SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, BauSystem.MESSAGE.parse("LOADER_SETTING_POWER", player, power));
swItem.getItemStack().setAmount(power == 0 ? 1 : power);
if (!this.noop && this.power == power) swItem.setEnchanted(true);
return swItem;
}
@Override
public void playerInteract() {
noop = false;
interact = true;
inverted = false;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(Material.DAYLIGHT_DETECTOR, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", player));
}
@Override
public DaylightDetectorSettings createNewElement() {
return new DaylightDetectorSettings();
}
}

Datei anzeigen

@ -0,0 +1,154 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Lectern;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.BookMeta;
import java.util.Arrays;
import java.util.Collections;
public class LoaderLectern extends LoaderInteractionElement<LoaderLectern.LecternSettings> {
public LoaderLectern(Location location) {
super(location);
}
public class LecternSettings implements ElementSettings {
private boolean noop = true;
private LecternAction action = LecternAction.PAGE_NEXT;
private int page = 0;
@Override
public SWItem menu(Player player) {
return menu(player, noop, action, page);
}
private SWItem menu(Player player, boolean noop, LecternAction action, int page) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_NOOP", player));
} else if (action == LecternAction.PAGE_PREV) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE_PREV", player));
} else if (action == LecternAction.PAGE_NEXT) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE_NEXT", player));
} else {
swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, page));
swItem.getItemStack().setAmount(page);
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != Material.LECTERN) return;
Lectern lectern = (Lectern) location.getBlock().getState();
if (!((org.bukkit.block.data.type.Lectern) lectern.getBlockData()).hasBook()) return;
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
if (noop) {
return;
} else if (action == LecternAction.PAGE_PREV) {
int page = lectern.getPage();
if (page > 1) lectern.setPage(page - 1);
} else if (action == LecternAction.PAGE_NEXT) {
int page = lectern.getPage();
if (page < pages) lectern.setPage(page + 1);
} else if (action == LecternAction.PAGE_SET) {
if (page <= pages) lectern.setPage(page);
}
lectern.update(false, true);
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 36, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 27; i < 35; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(27, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(35, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, LecternAction.PAGE_SET, 0).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, LecternAction.PAGE_PREV, 0).getItemStack(), clickType -> {
noop = false;
action = LecternAction.PAGE_PREV;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, LecternAction.PAGE_NEXT, 0).getItemStack(), clickType -> {
noop = false;
action = LecternAction.PAGE_NEXT;
click(player, backAction, deleteAction);
});
for (int i = 0; i < 15; i++) {
int finalI = i;
int finalI2 = i;
if (i >= 9) finalI2++;
if (i >= 12) finalI2++;
swInventory.setItem(finalI2 + 9, item(player, false, LecternAction.PAGE_SET, finalI + 1).getItemStack(), clickType -> {
noop = false;
action = LecternAction.PAGE_SET;
page = finalI + 1;
click(player, backAction, deleteAction);
});
}
swInventory.open();
}
private SWItem item(Player player, boolean noop, LecternAction action, int page) {
SWItem swItem = menu(player, noop, action, page);
if (swItem.getItemStack().equals(menu(player, this.noop, this.action, this.page).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
}
public enum LecternAction {
PAGE_NEXT,
PAGE_PREV,
PAGE_SET
}
@Override
public SWItem menu(Player player) {
return new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", player));
}
@Override
public LecternSettings createNewElement() {
return new LecternSettings();
}
}

Datei anzeigen

@ -0,0 +1,131 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSettings> {
public LoaderLever(Location location) {
super(location);
}
public class LeverSettings implements ElementSettings {
private boolean noop = false;
private boolean interact = false;
private boolean power = false;
@Override
public SWItem menu(Player player) {
return menu(player, noop, interact, power);
}
private SWItem menu(Player player, boolean noop, boolean interact, boolean power) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_LEVER", "LOADER_INTERACTION_NOOP", player));
} else if (interact) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_LEVER", "LOADER_INTERACTION_INTERACT", player));
} else {
swItem = new SWItem(Material.LEVER, translateItemName("LOADER_LEVER", power ? "LOADER_INTERACTION_ACTIVE" : "LOADER_INTERACTION_INACTIVE", player));
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != Material.LEVER) return;
if (noop) return;
Switch lever = (Switch) location.getBlock().getBlockData();
if (interact) {
lever.setPowered(!lever.isPowered());
} else {
lever.setPowered(power);
}
location.getBlock().setBlockData(lever, true);
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> {
noop = false;
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> {
noop = false;
interact = false;
power = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> {
noop = false;
interact = false;
power = true;
click(player, backAction, deleteAction);
});
swInventory.open();
}
private SWItem item(Player player, boolean noop, boolean interact, boolean power) {
SWItem swItem = menu(player, noop, interact, power);
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.power).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(Material.LEVER, translateItemName("LOADER_BUTTON_LECTERN", player));
}
@Override
public LeverSettings createNewElement() {
return new LeverSettings();
}
}

Datei anzeigen

@ -0,0 +1,231 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.AnaloguePowerable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Powerable;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.MovementSettings> {
private String name;
private Material material;
private boolean analogue;
public LoaderMovement(Location location, String name, Material material) {
super(location);
this.name = name;
this.material = material;
this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable;
}
public void setInitialTicks(long ticks) {
if (ticks < 1) ticks = 1;
elements.get(currentShot).ticks = ticks;
}
public class MovementSettings implements ElementSettings {
private boolean noop = false;
private boolean waitFor = false;
private int power = 15;
private long ticks = 1;
@Override
public SWItem menu(Player player) {
return menu(player, noop, waitFor);
}
private SWItem menu(Player player, boolean noop, boolean waitFor) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName(name, "LOADER_INTERACTION_NOOP", player));
} else if (waitFor) {
swItem = new SWItem(material, translateItemName(name, "LOADER_INTERACTION_WAIT_FOR", player));
swItem.getItemStack().setAmount((int) Math.min(ticks, 64));
} else {
swItem = new SWItem(material, translateItemName(name, "LOADER_INTERACTION_NO_WAIT_FOR", player));
swItem.getItemStack().setAmount((int) Math.min(ticks, 64));
swItem.setEnchanted(true);
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
if (!(material == Material.STRING && location.getBlock().getType() == Material.TRIPWIRE) && location.getBlock().getType() != material) {
nextAction.run();
return;
}
if (noop) {
nextAction.run();
return;
}
BlockData blockData = location.getBlock().getBlockData();
if (blockData instanceof AnaloguePowerable) {
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
analoguePowerable.setPower(power);
location.getBlock().setBlockData(analoguePowerable, true);
update(analoguePowerable);
} else if (blockData instanceof Powerable) {
Powerable powerable = (Powerable) location.getBlock().getBlockData();
if (ticks < 0) {
powerable.setPowered(power > 0);
} else {
powerable.setPowered(true);
}
location.getBlock().setBlockData(powerable, true);
update(powerable);
}
if (ticks >= 0) {
boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
if (blockData instanceof AnaloguePowerable) {
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
analoguePowerable.setPower(0);
location.getBlock().setBlockData(analoguePowerable, true);
update(analoguePowerable);
} else {
Powerable powerable = (Powerable) blockData;
powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true);
update(powerable);
}
if (finalWaitFor) {
nextAction.run();
}
}, ticks);
if (!finalWaitFor) {
nextAction.run();
}
}
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, analogue ? 45 : 27, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = analogue ? 36 : 18; i < (analogue ? 44 : 26); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(analogue ? 36 : 18, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(analogue ? 44 : 26, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
if (ticks >= 0) {
swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> {
noop = false;
waitFor = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> {
noop = false;
waitFor = true;
click(player, backAction, deleteAction);
});
}
swInventory.setItem(12, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> {
ticks -= clickType.isShiftClick() ? 5 : 1;
if (ticks < 1) ticks = 1;
swInventory.setItem(13, item(player));
});
swInventory.setItem(13, item(player).getItemStack(), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_NAME", player), ticks + "");
swAnvilInv.setCallback(s -> {
try {
ticks = Long.parseLong(s);
if (ticks < 1) ticks = 1;
} catch (NumberFormatException ignored) {
}
click(player, backAction, deleteAction);
});
swAnvilInv.open();
});
swInventory.setItem(14, new SWItem(SWItem.getDye(10), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> {
ticks += clickType.isShiftClick() ? 5 : 1;
swInventory.setItem(13, item(player));
});
if (analogue) {
for (int i = 0; i < 16; i++) {
int finalI = i;
int finalI2 = i;
if (i >= 9) finalI2++;
swInventory.setItem(finalI2 + 18, item(player, finalI).getItemStack(), clickType -> {
power = finalI;
click(player, backAction, deleteAction);
});
}
}
swInventory.open();
}
private SWItem item(Player player, boolean noop, boolean waitFor) {
SWItem swItem = menu(player, noop, waitFor);
if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
private SWItem item(Player player, int power) {
SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, BauSystem.MESSAGE.parse("LOADER_SETTING_POWER", player, power));
swItem.getItemStack().setAmount(power == 0 ? 1 : power);
if (!this.noop && this.power == power) swItem.setEnchanted(true);
return swItem;
}
private SWItem item(Player player) {
SWItem swItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS", player, ticks));
swItem.getItemStack().setAmount((int) Math.min(ticks, 64));
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(material, translateItemName(name, player));
}
@Override
public MovementSettings createNewElement() {
return new MovementSettings();
}
}

Datei anzeigen

@ -0,0 +1,114 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Instrument;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.NoteBlock;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.NoteBlockSettings> {
public LoaderNoteBlock(Location location) {
super(location);
}
public class NoteBlockSettings implements ElementSettings {
private boolean interact = true;
@Override
public SWItem menu(Player player) {
return menu(player, interact);
}
private SWItem menu(Player player, boolean interact) {
SWItem swItem;
if (interact) {
swItem = new SWItem(Material.NOTE_BLOCK, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_INTERACT", player));
} else {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_NOOP", player));
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != Material.NOTE_BLOCK) return;
NoteBlock noteBlock = (NoteBlock) location.getBlock().getBlockData();
if (interact) {
if (noteBlock.getInstrument() == Instrument.BANJO) noteBlock.setInstrument(Instrument.BIT);
else noteBlock.setInstrument(Instrument.BANJO);
} else {
return;
}
location.getBlock().setBlockData(noteBlock);
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, false).getItemStack(), clickType -> {
interact = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, true).getItemStack(), clickType -> {
interact = true;
click(player, backAction, deleteAction);
});
swInventory.open();
}
private SWItem item(Player player, boolean interact) {
SWItem swItem = menu(player, interact);
if (swItem.getItemStack().equals(menu(player, this.interact).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(Material.NOTE_BLOCK, translateItemName("LOADER_BUTTON_NOTEBLOCK", player));
}
@Override
public NoteBlockSettings createNewElement() {
return new NoteBlockSettings();
}
}

Datei anzeigen

@ -0,0 +1,136 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.Openable;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.TrapdoorSettings> {
private String name;
private Material material;
public LoaderOpenable(Location location, String name, Material material) {
super(location);
this.name = name;
this.material = material;
}
public class TrapdoorSettings implements ElementSettings {
private boolean noop = false;
private boolean interact = true;
private boolean open = false;
@Override
public SWItem menu(Player player) {
return menu(player, noop, interact, open);
}
private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName(name, "LOADER_INTERACTION_NOOP", player));
} else if (interact) {
swItem = new SWItem(Material.STICK, translateItemName(name, "LOADER_INTERACTION_INTERACT", player));
} else {
swItem = new SWItem(material, translateItemName(name, open ? "LOADER_INTERACTION_OPEN" : "LOADER_INTERACTION_CLOSED", player));
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != material) return;
Openable openable = (Openable) location.getBlock().getBlockData();
if (noop) {
return;
} else if (interact) {
openable.setOpen(!openable.isOpen());
} else {
openable.setOpen(open);
}
location.getBlock().setBlockData(openable);
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> {
noop = false;
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> {
noop = false;
interact = false;
open = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> {
noop = false;
interact = false;
open = true;
click(player, backAction, deleteAction);
});
swInventory.open();
}
private SWItem item(Player player, boolean noop, boolean interact, boolean open) {
SWItem swItem = menu(player, noop, interact, open);
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.open).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(material, translateItemName(name, player));
}
@Override
public TrapdoorSettings createNewElement() {
return new TrapdoorSettings();
}
}

Datei anzeigen

@ -0,0 +1,148 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.Repeater;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.RepeaterSettings> {
public LoaderRepeater(Location location) {
super(location);
}
public class RepeaterSettings implements ElementSettings {
private boolean interact = false;
private int delay = 1;
@Override
public SWItem menu(Player player) {
return menu(player, interact, delay);
}
private SWItem menu(Player player, boolean interact, int delay) {
SWItem swItem;
if (interact) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_INTERACT", player));
} else if (delay == 0) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_NOOP", player));
} else {
swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, delay));
swItem.getItemStack().setAmount(delay);
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
nextAction.run();
if (location.getBlock().getType() != Material.REPEATER) return;
Repeater repeater = (Repeater) location.getBlock().getBlockData();
if (interact) {
int delay = repeater.getDelay();
delay++;
if (delay > 4) delay = 1;
repeater.setDelay(delay);
} else if (delay == 0) {
return;
} else {
repeater.setDelay(delay);
}
location.getBlock().setBlockData(repeater, true);
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(1, item(player, false, 0).getItemStack(), clickType -> {
interact = false;
delay = 0;
click(player, backAction, deleteAction);
});
swInventory.setItem(2, item(player, true, -1).getItemStack(), clickType -> {
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(4, item(player, false, 1).getItemStack(), clickType -> {
interact = false;
delay = 1;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, 2).getItemStack(), clickType -> {
interact = false;
delay = 2;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, 3).getItemStack(), clickType -> {
interact = false;
delay = 3;
click(player, backAction, deleteAction);
});
swInventory.setItem(7, item(player, false, 4).getItemStack(), clickType -> {
interact = false;
delay = 4;
click(player, backAction, deleteAction);
});
swInventory.open();
}
private SWItem item(Player player, boolean interact, int delay) {
SWItem swItem = menu(player, interact, delay);
if (swItem.getItemStack().equals(menu(player, this.interact, this.delay).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
@Override
public void playerInteract() {
interact = true;
delay = 0;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(Material.REPEATER, translateItemName("LOADER_BUTTON_REPEATER", player));
}
@Override
public RepeaterSettings createNewElement() {
return new RepeaterSettings();
}
}

Datei anzeigen

@ -0,0 +1,63 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.Arrays;
public class LoaderTNT implements LoaderElement {
private Location location;
public LoaderTNT(Location location) {
this.location = location;
}
@Override
public SWItem menu(Player player) {
SWItem item = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("LOADER_SETTING_TNT_NAME", player));
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TNT_X", player, location.getBlockX()), BauSystem.MESSAGE.parse("LOADER_SETTING_TNT_Y", player, location.getBlockY()), BauSystem.MESSAGE.parse("LOADER_SETTING_TNT_Z", player, location.getBlockZ())));
return item;
}
@Override
public void execute(Runnable nextAction) {
Block block = location.getBlock();
if (block.getType() != Material.AIR && block.getType() != Material.WATER) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1);
return;
}
block.setType(Material.TNT, true);
nextAction.run();
}
@Override
public void click(Player player, Runnable backAction) {
}
}

Datei anzeigen

@ -0,0 +1,149 @@
/*
* 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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.Powerable;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSettings> {
private String name;
private Material material;
private int ticks;
public LoaderTicks(Location location, String name, Material material, int ticks) {
super(location);
this.name = name;
this.material = material;
this.ticks = ticks;
}
public class TicksSettings implements ElementSettings {
private boolean noop = false;
private boolean waitFor = false;
@Override
public SWItem menu(Player player) {
return menu(player, noop, waitFor);
}
private SWItem menu(Player player, boolean noop, boolean waitFor) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName(name, "LOADER_INTERACTION_NOOP", player));
} else if (waitFor) {
swItem = new SWItem(material, translateItemName(name, "LOADER_INTERACTION_WAIT_FOR", player, ticks));
} else {
swItem = new SWItem(material, translateItemName(name, "LOADER_INTERACTION_NO_WAIT_FOR", player, ticks));
swItem.setEnchanted(true);
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
if (location.getBlock().getType() != material) {
nextAction.run();
return;
}
if (noop) {
nextAction.run();
return;
}
Powerable powerable = (Powerable) location.getBlock().getBlockData();
powerable.setPowered(true);
location.getBlock().setBlockData(powerable, true);
update(powerable);
boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true);
update(powerable);
if (finalWaitFor) {
nextAction.run();
}
}, ticks);
if (!finalWaitFor) {
nextAction.run();
}
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
if (ticks >= 0) {
swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> {
noop = false;
waitFor = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> {
noop = false;
waitFor = true;
click(player, backAction, deleteAction);
});
}
swInventory.open();
}
private SWItem item(Player player, boolean noop, boolean waitFor) {
SWItem swItem = menu(player, noop, waitFor);
if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
}
}
@Override
public SWItem menu(Player player) {
return new SWItem(material, translateItemName(name, player));
}
@Override
public TicksSettings createNewElement() {
return new TicksSettings();
}
}

Datei anzeigen

@ -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.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import java.util.Arrays;
public class LoaderWait implements LoaderElement, Listener {
@Getter
@Setter
private long delay;
public LoaderWait(long delay) {
this.delay = delay;
}
@Override
public SWItem menu(Player player) {
SWItem swItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_SETTING_WAIT", player, delay));
swItem.getItemStack().setAmount((int) Math.max(Math.min(delay, 64), 1));
if (delay == 0) swItem.setEnchanted(true);
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
}
@Override
public void execute(Runnable nextAction) {
if (delay == 0) {
nextAction.run();
return;
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), nextAction, delay);
}
@Override
public void click(Player player, Runnable backAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_TITLE", player));
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, BauSystem.MESSAGE.parse("LOADER_GUI_WAIT_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(3, new SWItem(SWItem.getDye(1), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> {
delay -= clickType.isShiftClick() ? 5 : 1;
if (delay < 0) delay = 0;
swInventory.setItem(4, menu(player));
});
swInventory.setItem(4, menu(player).getItemStack(), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_WAIT_NAME", player), delay + "");
swAnvilInv.setCallback(s -> {
try {
delay = Long.parseLong(s);
if (delay < 0) delay = 0;
} catch (NumberFormatException ignored) {
}
click(player, backAction);
});
swAnvilInv.open();
});
swInventory.setItem(5, new SWItem(SWItem.getDye(10), BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE", player), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_ADD_ONE_SHIFT", player)), false, clickType -> {}).getItemStack(), clickType -> {
delay += clickType.isShiftClick() ? 5 : 1;
swInventory.setItem(4, menu(player));
});
swInventory.open();
}
}