QOL #203
@ -582,20 +582,22 @@ LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT
|
|||||||
LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all
|
LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all
|
||||||
LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time
|
LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time
|
||||||
LOADER_GUI_SETTINGS_TITLE=Settings
|
LOADER_GUI_SETTINGS_TITLE=Settings
|
||||||
|
LOADER_GUI_COPY_TITLE=Copy amount
|
||||||
LOADER_GUI_SETTINGS_BACK=§8Back
|
LOADER_GUI_SETTINGS_BACK=§8Back
|
||||||
|
LOADER_GUI_SETTINGS_COPY=§7Copy
|
||||||
LOADER_GUI_SETTINGS_DELETE=§cDelete
|
LOADER_GUI_SETTINGS_DELETE=§cDelete
|
||||||
LOADER_GUI_WAIT_TITLE=Settings
|
LOADER_GUI_WAIT_TITLE=Settings
|
||||||
LOADER_GUI_WAIT_BACK=§8Back
|
LOADER_GUI_WAIT_BACK=§8Back
|
||||||
|
|
||||||
LOADER_GUI_CLICK_TO_EDIT=§7Klicke zum editieren
|
LOADER_GUI_CLICK_TO_EDIT=§7Click to edit
|
||||||
LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1}
|
LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1}
|
||||||
LOADER_SETTING_NAME=§7{0}
|
LOADER_SETTING_NAME=§7{0}
|
||||||
LOADER_SETTING_MODES=§7Modi§8: §e{0}
|
LOADER_SETTING_MODES=§7Modes§8: §e{0}
|
||||||
LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0}
|
LOADER_SETTING_POWER=§7Power§8: §e{0}
|
||||||
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
|
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
|
||||||
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
|
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
|
||||||
LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s)
|
LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s)
|
||||||
LOADER_SETTING_WAIT_NAME=Wartezeit
|
LOADER_SETTING_WAIT_NAME=Wait
|
||||||
LOADER_SETTING_TICKS_NAME=Ticks
|
LOADER_SETTING_TICKS_NAME=Ticks
|
||||||
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
|
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
|
||||||
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
|
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
|
||||||
@ -606,18 +608,18 @@ LOADER_SETTING_TNT_X=§7X§8: §e{0}
|
|||||||
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
|
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
|
||||||
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
|
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
|
||||||
LOADER_INTERACTION_NOOP=NOOP
|
LOADER_INTERACTION_NOOP=NOOP
|
||||||
LOADER_INTERACTION_INTERACT=Interagiere
|
LOADER_INTERACTION_INTERACT=Interact
|
||||||
LOADER_INTERACTION_POWERED=Aktiviert
|
LOADER_INTERACTION_POWERED=Powered
|
||||||
LOADER_INTERACTION_UNPOWERED=Deaktiviert
|
LOADER_INTERACTION_UNPOWERED=Unpowered
|
||||||
LOADER_INTERACTION_PAGE_PREV=Vorherige Seite
|
LOADER_INTERACTION_PAGE_PREV=Previous Page
|
||||||
LOADER_INTERACTION_PAGE_NEXT=Nächste Seite
|
LOADER_INTERACTION_PAGE_NEXT=Next Page
|
||||||
LOADER_INTERACTION_PAGE=Seite {0}
|
LOADER_INTERACTION_PAGE=Page {0}
|
||||||
LOADER_INTERACTION_ACTIVE=Aktiviert
|
LOADER_INTERACTION_ACTIVE=Active
|
||||||
LOADER_INTERACTION_INACTIVE=Deaktiviert
|
LOADER_INTERACTION_INACTIVE=Inactive
|
||||||
LOADER_INTERACTION_WAIT_FOR=Darauf warten
|
LOADER_INTERACTION_WAIT_FOR=Wait for
|
||||||
LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten
|
LOADER_INTERACTION_NO_WAIT_FOR=No wait for
|
||||||
LOADER_INTERACTION_OPEN=Geöffnet
|
LOADER_INTERACTION_OPEN=Open
|
||||||
LOADER_INTERACTION_CLOSED=Geschlossen
|
LOADER_INTERACTION_CLOSED=Closed
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -550,20 +550,22 @@ LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT
|
|||||||
LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle
|
LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle
|
||||||
LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit
|
LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit
|
||||||
LOADER_GUI_SETTINGS_TITLE=Einstellungen
|
LOADER_GUI_SETTINGS_TITLE=Einstellungen
|
||||||
|
LOADER_GUI_COPY_TITLE=Anzahl Kopien
|
||||||
LOADER_GUI_SETTINGS_BACK=§8Zurück
|
LOADER_GUI_SETTINGS_BACK=§8Zurück
|
||||||
|
LOADER_GUI_SETTINGS_COPY=§7Kopieren
|
||||||
LOADER_GUI_SETTINGS_DELETE=§cLöschen
|
LOADER_GUI_SETTINGS_DELETE=§cLöschen
|
||||||
LOADER_GUI_WAIT_TITLE=Wartezeit
|
LOADER_GUI_WAIT_TITLE=Wartezeit
|
||||||
LOADER_GUI_WAIT_BACK=§8Zurück
|
LOADER_GUI_WAIT_BACK=§8Zurück
|
||||||
|
|
||||||
LOADER_GUI_CLICK_TO_EDIT=§7Click to edit
|
LOADER_GUI_CLICK_TO_EDIT=§7Klicke zum editieren
|
||||||
LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1}
|
LOADER_GUI_ITEM_NAME=§7{0}§8: §e{1}
|
||||||
LOADER_SETTING_NAME=§7{0}
|
LOADER_SETTING_NAME=§7{0}
|
||||||
LOADER_SETTING_MODES=§7Modes§8: §e{0}
|
LOADER_SETTING_MODES=§7Modi§8: §e{0}
|
||||||
LOADER_SETTING_POWER=§7Power§8: §e{0}
|
LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0}
|
||||||
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
|
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
|
||||||
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
|
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
|
||||||
LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s)
|
LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s)
|
||||||
LOADER_SETTING_WAIT_NAME=Wait
|
LOADER_SETTING_WAIT_NAME=Wartezeit
|
||||||
LOADER_SETTING_TICKS_NAME=Ticks
|
LOADER_SETTING_TICKS_NAME=Ticks
|
||||||
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
|
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
|
||||||
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
|
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
|
||||||
@ -574,18 +576,18 @@ LOADER_SETTING_TNT_X=§7X§8: §e{0}
|
|||||||
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
|
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
|
||||||
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
|
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
|
||||||
LOADER_INTERACTION_NOOP=NOOP
|
LOADER_INTERACTION_NOOP=NOOP
|
||||||
LOADER_INTERACTION_INTERACT=Interact
|
LOADER_INTERACTION_INTERACT=Interagiere
|
||||||
LOADER_INTERACTION_POWERED=Powered
|
LOADER_INTERACTION_POWERED=Aktiviert
|
||||||
LOADER_INTERACTION_UNPOWERED=Unpowered
|
LOADER_INTERACTION_UNPOWERED=Deaktiviert
|
||||||
LOADER_INTERACTION_PAGE_PREV=Previous Page
|
LOADER_INTERACTION_PAGE_PREV=Vorherige Seite
|
||||||
LOADER_INTERACTION_PAGE_NEXT=Next Page
|
LOADER_INTERACTION_PAGE_NEXT=Nächste Seite
|
||||||
LOADER_INTERACTION_PAGE=Page {0}
|
LOADER_INTERACTION_PAGE=Seite {0}
|
||||||
LOADER_INTERACTION_ACTIVE=Active
|
LOADER_INTERACTION_ACTIVE=Aktiviert
|
||||||
LOADER_INTERACTION_INACTIVE=Inactive
|
LOADER_INTERACTION_INACTIVE=Deaktiviert
|
||||||
LOADER_INTERACTION_WAIT_FOR=Wait for
|
LOADER_INTERACTION_WAIT_FOR=Darauf warten
|
||||||
LOADER_INTERACTION_NO_WAIT_FOR=No wait for
|
LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten
|
||||||
LOADER_INTERACTION_OPEN=Open
|
LOADER_INTERACTION_OPEN=Geöffnet
|
||||||
LOADER_INTERACTION_CLOSED=Closed
|
LOADER_INTERACTION_CLOSED=Geschlossen
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -72,18 +72,19 @@ public class Loader implements Listener {
|
|||||||
waitTime--;
|
waitTime--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (currentElement >= elements.size()) {
|
||||||
|
currentElement = 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (currentElement < elements.size()) {
|
while (currentElement < elements.size()) {
|
||||||
LoaderElement element = elements.get(currentElement);
|
LoaderElement element = elements.get(currentElement);
|
||||||
currentElement++;
|
currentElement++;
|
||||||
element.execute(delay -> waitTime = delay);
|
element.execute(delay -> waitTime = delay);
|
||||||
if (waitTime > 0) {
|
if (waitTime > 0) {
|
||||||
break;
|
if (element instanceof LoaderTNT) currentElement--;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (currentElement >= elements.size()) {
|
|
||||||
currentElement = 0;
|
|
||||||
}
|
|
||||||
}, 0, 1);
|
}, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +222,7 @@ public class Loader implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getProgress() {
|
public String getProgress() {
|
||||||
return (currentElement + 1) + "§8/§7" + elements.size();
|
return Math.max(currentElement, 1) + "§8/§7" + elements.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SettingsSorting {
|
public enum SettingsSorting {
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public interface ElementSettings {
|
|
||||||
SWItem menu(Player player);
|
|
||||||
void execute(Consumer<Long> delay);
|
|
||||||
void click(Player player, Runnable backAction, Runnable deleteAction);
|
|
||||||
|
|
||||||
default void playerInteract() {}
|
|
||||||
void noop();
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,62 +21,91 @@ package de.steamwar.bausystem.features.loader.elements;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.*;
|
||||||
import org.bukkit.block.data.FaceAttachable;
|
import org.bukkit.block.data.type.Door;
|
||||||
import org.bukkit.block.data.type.Switch;
|
import org.bukkit.block.data.type.Switch;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public abstract class LoaderInteractionElement<T extends ElementSettings> implements LoaderElement {
|
public abstract class LoaderInteractionElement<T extends Enum<T> & LoaderSettingsEnum> implements LoaderElement {
|
||||||
|
|
||||||
protected final Location location;
|
protected final Location location;
|
||||||
protected int currentShot = 0;
|
protected int currentShot = 0;
|
||||||
|
protected T defaultSetting;
|
||||||
|
protected T newSetting;
|
||||||
|
protected T[] allSettings;
|
||||||
protected List<T> elements = new ArrayList<>();
|
protected List<T> elements = new ArrayList<>();
|
||||||
|
protected List<Integer> extraPower = new ArrayList<>();
|
||||||
|
protected List<Long> extraTicks = new ArrayList<>();
|
||||||
|
protected int settingsGuiSize = 0;
|
||||||
|
|
||||||
protected LoaderInteractionElement(Location location) {
|
protected LoaderInteractionElement(Location location, T defaultSetting, T newSetting, T[] allSettings) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
|
||||||
T element = createNewElement();
|
this.defaultSetting = defaultSetting;
|
||||||
element.playerInteract();
|
this.newSetting = newSetting;
|
||||||
elements.add(element);
|
this.allSettings = allSettings;
|
||||||
|
|
||||||
|
elements.add(defaultSetting);
|
||||||
|
extraPower.add(0);
|
||||||
|
extraTicks.add(0L);
|
||||||
|
|
||||||
|
for (T element : allSettings) {
|
||||||
|
settingsGuiSize = Math.max(element.getPos(), settingsGuiSize);
|
||||||
|
}
|
||||||
|
while (settingsGuiSize % 9 != 0) settingsGuiSize++;
|
||||||
|
settingsGuiSize += 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public void execute(Consumer<Long> delay) {
|
||||||
if (currentShot >= elements.size()) currentShot = 0;
|
if (currentShot >= elements.size()) currentShot = 0;
|
||||||
elements.get(currentShot).execute(delay);
|
if (checkBlockInWorld()) {
|
||||||
|
BlockData blockData = location.getBlock().getBlockData();
|
||||||
|
elements.get(currentShot).execute(location, blockData, this, extraPower.get(currentShot), extraTicks.get(currentShot), delay);
|
||||||
|
}
|
||||||
currentShot++;
|
currentShot++;
|
||||||
if (currentShot >= elements.size()) currentShot = 0;
|
if (currentShot >= elements.size()) currentShot = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(Player player, Runnable backAction) {
|
public void click(Player player, Runnable backAction) {
|
||||||
List<SWListInv.SWListEntry<T>> entries = new ArrayList<>();
|
List<SWListInv.SWListEntry<Integer>> entries = new ArrayList<>();
|
||||||
Runnable updateRunnable = () -> {
|
Runnable updateRunnable = () -> {
|
||||||
entries.clear();
|
entries.clear();
|
||||||
for (T element : elements) {
|
for (int i = 0; i < elements.size(); i++) {
|
||||||
entries.add(new SWListInv.SWListEntry<>(element.menu(player), element));
|
SWItem swItem = elements.get(i).menu(player, this, extraPower.get(i), extraTicks.get(i));
|
||||||
|
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
|
||||||
|
entries.add(new SWListInv.SWListEntry<>(swItem, i));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
updateRunnable.run();
|
updateRunnable.run();
|
||||||
|
|
||||||
SWListInv<T> listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> {});
|
SWListInv<Integer> listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> {});
|
||||||
listInv.setCallback((clickType, entry) -> {
|
listInv.setCallback((clickType, entry) -> {
|
||||||
entry.click(player, () -> {
|
openIndividualSettingsMenu(player, entry, () -> {
|
||||||
updateRunnable.run();
|
updateRunnable.run();
|
||||||
listInv.open();
|
listInv.open();
|
||||||
}, () -> {
|
}, () -> {
|
||||||
if (elements.size() == 1) return;
|
elements.remove((int) entry);
|
||||||
elements.remove(entry);
|
extraPower.remove((int) entry);
|
||||||
|
extraTicks.remove((int) entry);
|
||||||
|
if (elements.isEmpty()) {
|
||||||
|
elements.add(newSetting);
|
||||||
|
extraPower.add(0);
|
||||||
|
extraTicks.add(1L);
|
||||||
|
}
|
||||||
click(player, backAction);
|
click(player, backAction);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -84,69 +113,190 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
|||||||
backAction.run();
|
backAction.run();
|
||||||
}));
|
}));
|
||||||
listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> {
|
listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> {
|
||||||
T element = createNewElement();
|
elements.add(defaultSetting);
|
||||||
elements.add(element);
|
extraPower.add(0);
|
||||||
element.click(player, () -> {
|
extraTicks.add(1L);
|
||||||
|
openIndividualSettingsMenu(player, elements.size() - 1, () -> {
|
||||||
updateRunnable.run();
|
updateRunnable.run();
|
||||||
listInv.open();
|
listInv.open();
|
||||||
}, () -> {
|
}, () -> {
|
||||||
if (elements.size() == 1) return;
|
elements.remove(elements.size() - 1);
|
||||||
elements.remove(element);
|
extraPower.remove(extraPower.size() - 1);
|
||||||
|
extraTicks.remove(extraTicks.size() - 1);
|
||||||
|
if (elements.isEmpty()) {
|
||||||
|
elements.add(newSetting);
|
||||||
|
extraPower.add(0);
|
||||||
|
extraTicks.add(1L);
|
||||||
|
}
|
||||||
click(player, backAction);
|
click(player, backAction);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
listInv.setItem(51, new SWItem(Material.STRUCTURE_VOID, "§7Insert NOOP's", clickType -> {
|
|
||||||
SWAnvilInv anvilInv = new SWAnvilInv(player, "§7NOOP Count", "1");
|
|
||||||
anvilInv.setCallback(s -> {
|
|
||||||
try {
|
|
||||||
int count = Integer.parseInt(s);
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
T element = createNewElement();
|
|
||||||
element.noop();
|
|
||||||
elements.add(element);
|
|
||||||
}
|
|
||||||
updateRunnable.run();
|
|
||||||
listInv.open();
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
player.sendMessage("§cInvalid Number");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
anvilInv.open();
|
|
||||||
}));
|
|
||||||
listInv.open();
|
listInv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openIndividualSettingsMenu(Player player, int index, Runnable back, Runnable delete) {
|
||||||
|
T currentElement = elements.get(index);
|
||||||
|
int guiSize = settingsGuiSize;
|
||||||
|
int powerStart = guiSize - 9;
|
||||||
|
if (currentElement.hasPower(this)) {
|
||||||
|
guiSize += 18;
|
||||||
|
}
|
||||||
|
int ticksStart = guiSize - 9;
|
||||||
|
if (currentElement.hasTicks(this)) {
|
||||||
|
guiSize += 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
SWInventory swInventory = new SWInventory(player, guiSize, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
|
||||||
|
for (int i = guiSize - 9; i < guiSize; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", clickType -> {}));
|
||||||
|
swInventory.setItem(guiSize - 9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> back.run());
|
||||||
|
swInventory.setItem(guiSize - 5, new SWItem(Material.WOODEN_AXE, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_COPY", player)).getItemStack(), clickType -> {
|
||||||
|
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_GUI_COPY_TITLE", player), "1");
|
||||||
|
swAnvilInv.setCallback(s -> {
|
||||||
|
try {
|
||||||
|
int count = Integer.parseInt(s);
|
||||||
|
if (count < 1) count = 1;
|
||||||
|
if (count > 65536) count = 65536;
|
||||||
|
|
||||||
|
int power = extraPower.get(index);
|
||||||
|
long ticks = extraTicks.get(index);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
elements.add(currentElement);
|
||||||
|
extraPower.add(power);
|
||||||
|
extraTicks.add(ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 1) {
|
||||||
|
openIndividualSettingsMenu(player, elements.size() - 1, back, delete);
|
||||||
|
} else {
|
||||||
|
back.run();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
back.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
swAnvilInv.open();
|
||||||
|
});
|
||||||
|
swInventory.setItem(guiSize - 1, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> delete.run());
|
||||||
|
|
||||||
|
for (T element : allSettings) {
|
||||||
|
SWItem item = element.menu(player, this, extraPower.get(index), extraTicks.get(index));
|
||||||
|
if (element == currentElement) {
|
||||||
|
item.setEnchanted(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
swInventory.setItem(element.getPos(), item.getItemStack(), clickType -> {
|
||||||
|
elements.set(index, element);
|
||||||
|
openIndividualSettingsMenu(player, index, back, delete);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentElement.hasPower(this)) {
|
||||||
|
for (int power = 0; power < 16; power++) {
|
||||||
|
int finalPowerPosition = power;
|
||||||
|
if (power >= 9) finalPowerPosition++;
|
||||||
|
SWItem powerItem = new SWItem(Material.REDSTONE, BauSystem.MESSAGE.parse("LOADER_SETTING_POWER", player, power), Arrays.asList(), false, clickType -> {});
|
||||||
|
powerItem.getItemStack().setAmount(Math.max(power, 1));
|
||||||
|
if (extraPower.get(index) == power) powerItem.setEnchanted(true);
|
||||||
|
|
||||||
|
int finalPower = power;
|
||||||
|
swInventory.setItem(finalPowerPosition + powerStart, powerItem.getItemStack(), clickType -> {
|
||||||
|
extraPower.set(index, finalPower);
|
||||||
|
openIndividualSettingsMenu(player, index, back, delete);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentElement.hasTicks(this)) {
|
||||||
|
swInventory.setItem(ticksStart + 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 -> {
|
||||||
|
long ticks = extraTicks.get(index);
|
||||||
|
ticks -= clickType.isShiftClick() ? 5 : 1;
|
||||||
|
if (ticks < 1) ticks = 1;
|
||||||
|
extraTicks.set(index, ticks);
|
||||||
|
openIndividualSettingsMenu(player, index, back, delete);
|
||||||
|
});
|
||||||
|
|
||||||
|
SWItem ticksItem = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS", player, extraTicks.get(index)), Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)), false, clickType -> {});
|
||||||
|
ticksItem.getItemStack().setAmount((int) Math.min(extraTicks.get(index), 64));
|
||||||
|
swInventory.setItem(ticksStart + 4, ticksItem.getItemStack(), clickType -> {
|
||||||
|
SWAnvilInv swAnvilInv = new SWAnvilInv(player, BauSystem.MESSAGE.parse("LOADER_SETTING_TICKS_NAME", player), extraTicks.get(index) + "");
|
||||||
|
swAnvilInv.setCallback(s -> {
|
||||||
|
try {
|
||||||
|
long ticks = Long.parseLong(s);
|
||||||
|
if (ticks < 1) ticks = 1;
|
||||||
|
extraTicks.set(index, ticks);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
openIndividualSettingsMenu(player, index, back, delete);
|
||||||
|
});
|
||||||
|
swAnvilInv.open();
|
||||||
|
});
|
||||||
|
|
||||||
|
swInventory.setItem(ticksStart + 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 -> {
|
||||||
|
long ticks = extraTicks.get(index);
|
||||||
|
ticks += clickType.isShiftClick() ? 5 : 1;
|
||||||
|
extraTicks.set(index, ticks);
|
||||||
|
openIndividualSettingsMenu(player, index, back, delete);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
swInventory.open();
|
||||||
|
}
|
||||||
|
|
||||||
protected void update(BlockData blockData) {
|
protected void update(BlockData blockData) {
|
||||||
Material material = blockData.getMaterial();
|
|
||||||
Block block = location.getBlock();
|
Block block = location.getBlock();
|
||||||
if (blockData instanceof Switch) {
|
if (blockData instanceof Door) {
|
||||||
|
Door door = (Door) blockData;
|
||||||
|
block.setBlockData(door);
|
||||||
|
if (door.getHalf() == Bisected.Half.BOTTOM) {
|
||||||
|
updateBlock(block.getRelative(BlockFace.UP), door.isOpen() ? 15 : 0);
|
||||||
|
} else {
|
||||||
|
updateBlock(block.getRelative(BlockFace.DOWN), door.isOpen() ? 15 : 0);
|
||||||
|
}
|
||||||
|
} else if (blockData instanceof Switch) {
|
||||||
Switch sw = (Switch) blockData;
|
Switch sw = (Switch) blockData;
|
||||||
updateBlock(block, sw);
|
updateBlock(block, sw);
|
||||||
FaceAttachable.AttachedFace face = sw.getAttachedFace();
|
FaceAttachable.AttachedFace face = sw.getAttachedFace();
|
||||||
if (face == FaceAttachable.AttachedFace.FLOOR) {
|
if (face == FaceAttachable.AttachedFace.FLOOR) {
|
||||||
updateBlock(block.getRelative(BlockFace.DOWN));
|
updateBlock(block.getRelative(BlockFace.DOWN), sw.isPowered() ? 15 : 0);
|
||||||
} else if (face == FaceAttachable.AttachedFace.CEILING) {
|
} else if (face == FaceAttachable.AttachedFace.CEILING) {
|
||||||
updateBlock(block.getRelative(BlockFace.UP));
|
updateBlock(block.getRelative(BlockFace.UP), sw.isPowered() ? 15 : 0);
|
||||||
} else {
|
} else {
|
||||||
updateBlock(block.getRelative(sw.getFacing().getOppositeFace()));
|
updateBlock(block.getRelative(sw.getFacing().getOppositeFace()), sw.isPowered() ? 15 : 0);
|
||||||
}
|
}
|
||||||
} else if (material == Material.TRIPWIRE) {
|
} else if (blockData instanceof Powerable) {
|
||||||
|
updateBlock(block, blockData);
|
||||||
|
updateBlock(block.getRelative(BlockFace.DOWN), ((Powerable) blockData).isPowered() ? 15 : 0);
|
||||||
|
} else if (blockData instanceof AnaloguePowerable) {
|
||||||
|
updateBlock(block, blockData);
|
||||||
|
updateBlock(block.getRelative(BlockFace.DOWN), ((AnaloguePowerable) blockData).getPower());
|
||||||
|
} else {
|
||||||
updateBlock(block, blockData);
|
updateBlock(block, blockData);
|
||||||
} else if (material.name().endsWith("_PLATE")) {
|
|
||||||
updateBlock(block.getRelative(BlockFace.DOWN));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateBlock(Block block) {
|
private void updateBlock(Block block, int powered) {
|
||||||
updateBlock(block, block.getBlockData());
|
BlockData data = block.getBlockData();
|
||||||
|
if (data instanceof Door) {
|
||||||
|
Door door = (Door) data;
|
||||||
|
door.setOpen(powered > 0);
|
||||||
|
block.setBlockData(door);
|
||||||
|
return;
|
||||||
|
} else if (data instanceof Powerable) {
|
||||||
|
Powerable powerable = (Powerable) data;
|
||||||
|
powerable.setPowered(powered > 0);
|
||||||
|
} else if (data instanceof AnaloguePowerable) {
|
||||||
|
AnaloguePowerable analoguePowerable = (AnaloguePowerable) data;
|
||||||
|
analoguePowerable.setPower(powered);
|
||||||
|
}
|
||||||
|
updateBlock(block, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateBlock(Block block, BlockData data) {
|
private void updateBlock(Block block, BlockData data) {
|
||||||
block.setType(Material.BARRIER, true);
|
block.setType(Material.BARRIER);
|
||||||
block.setBlockData(data, true);
|
block.setBlockData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract T createNewElement();
|
public abstract boolean checkBlockInWorld();
|
||||||
|
|
||||||
protected final String translateItemName(String name, Player player) {
|
protected final String translateItemName(String name, Player player) {
|
||||||
return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player));
|
return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player));
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* 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.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface LoaderSettingsEnum<T, P extends LoaderInteractionElement<E>, E extends Enum<E> & LoaderSettingsEnum<T, P, E>> {
|
||||||
|
int getPos();
|
||||||
|
SWItem menu(Player player, P parent, int power, long ticks);
|
||||||
|
default boolean hasPower(P parent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default boolean hasTicks(P parent) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute(Location location, T blockData, P parent, int power, long ticks, Consumer<Long> delay);
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
@ -19,10 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
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.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -30,101 +28,83 @@ import org.bukkit.block.data.type.Comparator;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.ComparatorSettings> {
|
public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.ComparatorSettingsEnum> {
|
||||||
|
|
||||||
public LoaderComparator(Location location) {
|
public LoaderComparator(Location location) {
|
||||||
super(location);
|
super(location, ComparatorSettingsEnum.INTERACT, ComparatorSettingsEnum.NOOP, ComparatorSettingsEnum.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ComparatorSettings implements ElementSettings {
|
public enum ComparatorSettingsEnum implements LoaderSettingsEnum<Comparator, LoaderComparator, ComparatorSettingsEnum> {
|
||||||
|
NOOP {
|
||||||
private boolean interact = false;
|
|
||||||
private Comparator.Mode mode = Comparator.Mode.COMPARE;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, interact, mode);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderComparator parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != Material.COMPARATOR) return;
|
return new SWItem(Material.STRUCTURE_VOID, "§7Comparator§8: §eNOOP");
|
||||||
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
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public void execute(Location location, Comparator blockData, LoaderComparator parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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) {
|
INTERACT {
|
||||||
SWItem swItem = menu(player, interact, mode);
|
@Override
|
||||||
if (swItem.getItemStack().equals(menu(player, this.interact, this.mode).getItemStack())) {
|
public int getPos() {
|
||||||
swItem.setEnchanted(true);
|
return 3;
|
||||||
}
|
|
||||||
swItem.setLore(Collections.emptyList());
|
|
||||||
return swItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerInteract() {
|
public SWItem menu(Player player, LoaderComparator parent, int power, long ticks) {
|
||||||
interact = true;
|
return new SWItem(Material.STICK, "§7Comparator§8: §eInteract");
|
||||||
mode = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public void execute(Location location, Comparator blockData, LoaderComparator parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
interact = false;
|
blockData.setMode(blockData.getMode() == Comparator.Mode.COMPARE ? Comparator.Mode.SUBTRACT : Comparator.Mode.COMPARE);
|
||||||
mode = null;
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
COMPARE {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderComparator parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.COMPARATOR, "§7Comparator§8: §eCompare");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Comparator blockData, LoaderComparator parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setMode(Comparator.Mode.COMPARE);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
SUBTRACT {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderComparator parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.COMPARATOR, "§7Comparator§8: §eSubtract");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Comparator blockData, LoaderComparator parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setMode(Comparator.Mode.SUBTRACT);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +116,7 @@ public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ComparatorSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new ComparatorSettings();
|
return location.getBlock().getType() == Material.COMPARATOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,137 +19,98 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
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.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.type.DaylightDetector;
|
import org.bukkit.block.data.type.DaylightDetector;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDaylightDetector.DaylightDetectorSettings> {
|
public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDaylightDetector.DaylightSettingsEnum> {
|
||||||
|
|
||||||
public LoaderDaylightDetector(Location location) {
|
public LoaderDaylightDetector(Location location) {
|
||||||
super(location);
|
super(location, DaylightSettingsEnum.INTERACT, DaylightSettingsEnum.NOOP, DaylightSettingsEnum.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DaylightDetectorSettings implements ElementSettings {
|
public enum DaylightSettingsEnum implements LoaderSettingsEnum<DaylightDetector, LoaderDaylightDetector, DaylightSettingsEnum> {
|
||||||
|
NOOP {
|
||||||
private boolean noop = false;
|
|
||||||
private boolean interact = false;
|
|
||||||
private boolean inverted = true;
|
|
||||||
private int power = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, noop, interact, inverted);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderDaylightDetector parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != Material.DAYLIGHT_DETECTOR) return;
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", "LOADER_INTERACTION_NOOP", player));
|
||||||
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
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public void execute(Location location, DaylightDetector blockData, LoaderDaylightDetector parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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();
|
INTERACT {
|
||||||
}
|
@Override
|
||||||
|
public int getPos() {
|
||||||
private SWItem item(Player player, boolean noop, boolean interact, boolean inverted) {
|
return 3;
|
||||||
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
|
@Override
|
||||||
public void playerInteract() {
|
public SWItem menu(Player player, LoaderDaylightDetector parent, int power, long ticks) {
|
||||||
noop = false;
|
return new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", "LOADER_INTERACTION_INTERACT", player));
|
||||||
interact = true;
|
|
||||||
inverted = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public void execute(Location location, DaylightDetector blockData, LoaderDaylightDetector parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
noop = true;
|
blockData.setInverted(!blockData.isInverted());
|
||||||
interact = false;
|
blockData.setPower(15 - blockData.getPower());
|
||||||
inverted = false;
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
DAY_MODE {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderDaylightDetector parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.DAYLIGHT_DETECTOR, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", "LOADER_INTERACTION_UNPOWERED", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, DaylightDetector blockData, LoaderDaylightDetector parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (blockData.isInverted()) {
|
||||||
|
blockData.setInverted(false);
|
||||||
|
blockData.setPower(15 - blockData.getPower());
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
NIGHT_MODE {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderDaylightDetector parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.DAYLIGHT_DETECTOR, translateItemName("LOADER_BUTTON_DAYLIGHT_DETECTOR", "LOADER_INTERACTION_POWERED", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, DaylightDetector blockData, LoaderDaylightDetector parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.isInverted()) {
|
||||||
|
blockData.setInverted(true);
|
||||||
|
blockData.setPower(15 - blockData.getPower());
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,7 +120,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDayli
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DaylightDetectorSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new DaylightDetectorSettings();
|
return location.getBlock().getType() == Material.DAYLIGHT_DETECTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
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.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -30,121 +28,451 @@ import org.bukkit.block.Lectern;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.meta.BookMeta;
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderLectern extends LoaderInteractionElement<LoaderLectern.LecternSettings> {
|
public class LoaderLectern extends LoaderInteractionElement<LoaderLectern.LecternSettingsEnum> {
|
||||||
|
|
||||||
|
|
||||||
public LoaderLectern(Location location) {
|
public LoaderLectern(Location location) {
|
||||||
super(location);
|
super(location, LecternSettingsEnum.NEXT_PAGE, LecternSettingsEnum.NOOP, LecternSettingsEnum.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LecternSettings implements ElementSettings {
|
public enum LecternSettingsEnum implements LoaderSettingsEnum<org.bukkit.block.data.type.Lectern, LoaderLectern, LecternSettingsEnum> {
|
||||||
|
NOOP {
|
||||||
private boolean noop = true;
|
|
||||||
private LecternAction action = LecternAction.PAGE_NEXT;
|
|
||||||
private int page = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, noop, action, page);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != Material.LECTERN) return;
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_NOOP", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PREVIOUS_PAGE {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE_PREV", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
Lectern lectern = (Lectern) location.getBlock().getState();
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
if (!((org.bukkit.block.data.type.Lectern) lectern.getBlockData()).hasBook()) return;
|
if (lectern.getPage() > 0) {
|
||||||
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
lectern.setPage(lectern.getPage() - 1);
|
||||||
if (noop) {
|
parent.update(blockData);
|
||||||
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);
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
NEXT_PAGE {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
SWInventory swInventory = new SWInventory(player, 36, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
|
return new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE_NEXT", 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();
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (lectern.getPage() < pages) {
|
||||||
|
lectern.setPage(lectern.getPage() + 1);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_1 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SWItem item(Player player, boolean noop, LecternAction action, int page) {
|
@Override
|
||||||
SWItem swItem = menu(player, noop, action, page);
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
if (swItem.getItemStack().equals(menu(player, this.noop, this.action, this.page).getItemStack())) {
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 1));
|
||||||
swItem.setEnchanted(true);
|
swItem.getItemStack().setAmount(1);
|
||||||
}
|
|
||||||
swItem.setLore(Collections.emptyList());
|
|
||||||
return swItem;
|
return swItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
noop = true;
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (1 <= pages) {
|
||||||
|
lectern.setPage(1);
|
||||||
|
parent.update(blockData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_2 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
public enum LecternAction {
|
@Override
|
||||||
PAGE_NEXT,
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
PAGE_PREV,
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 2));
|
||||||
PAGE_SET
|
swItem.getItemStack().setAmount(2);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (2 <= pages) {
|
||||||
|
lectern.setPage(2);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_3 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 3));
|
||||||
|
swItem.getItemStack().setAmount(3);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (3 <= pages) {
|
||||||
|
lectern.setPage(3);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_4 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 4));
|
||||||
|
swItem.getItemStack().setAmount(4);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (4 <= pages) {
|
||||||
|
lectern.setPage(4);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_5 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 13;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 5));
|
||||||
|
swItem.getItemStack().setAmount(5);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (5 <= pages) {
|
||||||
|
lectern.setPage(5);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_6 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 6));
|
||||||
|
swItem.getItemStack().setAmount(6);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (6 <= pages) {
|
||||||
|
lectern.setPage(6);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_7 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 7));
|
||||||
|
swItem.getItemStack().setAmount(7);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (7 <= pages) {
|
||||||
|
lectern.setPage(7);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_8 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 8));
|
||||||
|
swItem.getItemStack().setAmount(8);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (8 <= pages) {
|
||||||
|
lectern.setPage(8);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_9 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 17;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 9));
|
||||||
|
swItem.getItemStack().setAmount(9);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (9 <= pages) {
|
||||||
|
lectern.setPage(9);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_10 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 19;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 10));
|
||||||
|
swItem.getItemStack().setAmount(10);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (10 <= pages) {
|
||||||
|
lectern.setPage(10);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_11 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 11));
|
||||||
|
swItem.getItemStack().setAmount(11);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (11 <= pages) {
|
||||||
|
lectern.setPage(11);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_12 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 21;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 12));
|
||||||
|
swItem.getItemStack().setAmount(12);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (12 <= pages) {
|
||||||
|
lectern.setPage(12);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_13 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 23;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 13));
|
||||||
|
swItem.getItemStack().setAmount(13);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (13 <= pages) {
|
||||||
|
lectern.setPage(13);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_14 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 14));
|
||||||
|
swItem.getItemStack().setAmount(14);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (14 <= pages) {
|
||||||
|
lectern.setPage(14);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
PAGE_15 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLectern parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.LECTERN, translateItemName("LOADER_BUTTON_LECTERN", "LOADER_INTERACTION_PAGE", player, 15));
|
||||||
|
swItem.getItemStack().setAmount(15);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, org.bukkit.block.data.type.Lectern blockData, LoaderLectern parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (!blockData.hasBook()) return;
|
||||||
|
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||||
|
int pages = ((BookMeta) lectern.getInventory().getItem(0).getItemMeta()).getPages().size();
|
||||||
|
if (15 <= pages) {
|
||||||
|
lectern.setPage(15);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,7 +481,7 @@ public class LoaderLectern extends LoaderInteractionElement<LoaderLectern.Lecter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LecternSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new LecternSettings();
|
return location.getBlock().getType() == Material.LECTERN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,108 +19,91 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
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.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.type.Switch;
|
import org.bukkit.block.data.type.Switch;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSettings> {
|
public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSettingsEnum> {
|
||||||
|
|
||||||
public LoaderLever(Location location) {
|
public LoaderLever(Location location) {
|
||||||
super(location);
|
super(location, LeverSettingsEnum.INTERACT, LeverSettingsEnum.NOOP, LeverSettingsEnum.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LeverSettings implements ElementSettings {
|
public enum LeverSettingsEnum implements LoaderSettingsEnum<Switch, LoaderLever, LeverSettingsEnum> {
|
||||||
|
|
||||||
private boolean noop = false;
|
|
||||||
private boolean interact = true;
|
|
||||||
private boolean power = false;
|
|
||||||
|
|
||||||
|
NOOP {
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, noop, interact, power);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
private SWItem menu(Player player, boolean noop, boolean interact, boolean power) {
|
|
||||||
SWItem swItem;
|
|
||||||
if (noop) {
|
|
||||||
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_NOOP", player));
|
|
||||||
} else if (interact) {
|
|
||||||
swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_INTERACT", player));
|
|
||||||
} else {
|
|
||||||
swItem = new SWItem(Material.LEVER, translateItemName("LOADER_BUTTON_SWITCH", power ? "LOADER_INTERACTION_ACTIVE" : "LOADER_INTERACTION_INACTIVE", player));
|
|
||||||
}
|
|
||||||
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
|
|
||||||
return swItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderLever parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != Material.LEVER) return;
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_NOOP", player));
|
||||||
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
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public void execute(Location location, Switch blockData, LoaderLever parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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) {
|
INTERACT {
|
||||||
SWItem swItem = menu(player, noop, interact, power);
|
@Override
|
||||||
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.power).getItemStack())) {
|
public int getPos() {
|
||||||
swItem.setEnchanted(true);
|
return 3;
|
||||||
}
|
|
||||||
swItem.setLore(Collections.emptyList());
|
|
||||||
return swItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public SWItem menu(Player player, LoaderLever parent, int power, long ticks) {
|
||||||
noop = true;
|
return new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_INTERACT", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Switch blockData, LoaderLever parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setPowered(!blockData.isPowered());
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
POWER_OFF {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLever parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.LEVER, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_INACTIVE", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Switch blockData, LoaderLever parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setPowered(false);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
POWER_ON {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderLever parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.LEVER, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_ACTIVE", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Switch blockData, LoaderLever parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setPowered(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +113,7 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LeverSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new LeverSettings();
|
return location.getBlock().getType() == Material.LEVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,9 @@
|
|||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
package de.steamwar.bausystem.features.loader.elements.impl;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
|
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWInventory;
|
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.AnaloguePowerable;
|
import org.bukkit.block.data.AnaloguePowerable;
|
||||||
@ -33,18 +30,16 @@ import org.bukkit.block.data.BlockData;
|
|||||||
import org.bukkit.block.data.Powerable;
|
import org.bukkit.block.data.Powerable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.MovementSettings> {
|
public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.MovementSettingsEnum> {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Material material;
|
private Material material;
|
||||||
private boolean analogue;
|
private boolean analogue;
|
||||||
|
|
||||||
public LoaderMovement(Location location, String name, Material material) {
|
public LoaderMovement(Location location, String name, Material material) {
|
||||||
super(location);
|
super(location, MovementSettingsEnum.NO_WAIT_FOR, MovementSettingsEnum.NOOP, MovementSettingsEnum.values());
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable;
|
this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable;
|
||||||
@ -52,48 +47,56 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
|||||||
|
|
||||||
public void setInitialTicks(long ticks) {
|
public void setInitialTicks(long ticks) {
|
||||||
if (ticks < 1) ticks = 1;
|
if (ticks < 1) ticks = 1;
|
||||||
elements.get(currentShot).ticks = ticks;
|
extraTicks.set(currentShot, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MovementSettings implements ElementSettings {
|
public enum MovementSettingsEnum implements LoaderSettingsEnum<BlockData, LoaderMovement, MovementSettingsEnum> {
|
||||||
|
|
||||||
private boolean noop = false;
|
NOOP {
|
||||||
private boolean waitFor = false;
|
@Override
|
||||||
private int power = 15;
|
public int getPos() {
|
||||||
private long ticks = 1;
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public SWItem menu(Player player, LoaderMovement parent, int power, long ticks) {
|
||||||
return menu(player, noop, waitFor);
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName(parent.name, "LOADER_INTERACTION_NOOP", player));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SWItem menu(Player player, boolean noop, boolean waitFor) {
|
@Override
|
||||||
SWItem swItem;
|
public void execute(Location location, BlockData blockData, LoaderMovement parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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)));
|
},
|
||||||
|
|
||||||
|
NO_WAIT_FOR {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderMovement parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_WAIT_FOR", player));
|
||||||
|
swItem.getItemStack().setAmount((int) Math.min(ticks, 64));
|
||||||
return swItem;
|
return swItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public boolean hasPower(LoaderMovement parent) {
|
||||||
if (!(material == Material.STRING && location.getBlock().getType() == Material.TRIPWIRE) && location.getBlock().getType() != material) return;
|
return parent.analogue;
|
||||||
if (noop) return;
|
}
|
||||||
|
|
||||||
BlockData blockData = location.getBlock().getBlockData();
|
@Override
|
||||||
|
public boolean hasTicks(LoaderMovement parent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, BlockData blockData, LoaderMovement parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
if (blockData instanceof AnaloguePowerable) {
|
if (blockData instanceof AnaloguePowerable) {
|
||||||
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
|
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
|
||||||
analoguePowerable.setPower(power);
|
analoguePowerable.setPower(power);
|
||||||
location.getBlock().setBlockData(analoguePowerable, true);
|
parent.update(analoguePowerable);
|
||||||
update(analoguePowerable);
|
|
||||||
} else if (blockData instanceof Powerable) {
|
} else if (blockData instanceof Powerable) {
|
||||||
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
||||||
if (ticks < 0) {
|
if (ticks < 0) {
|
||||||
@ -101,118 +104,51 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
|||||||
} else {
|
} else {
|
||||||
powerable.setPowered(true);
|
powerable.setPowered(true);
|
||||||
}
|
}
|
||||||
location.getBlock().setBlockData(powerable, true);
|
parent.update(powerable);
|
||||||
update(powerable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticks >= 0) {
|
|
||||||
if (waitFor) {
|
|
||||||
delay.accept(ticks);
|
|
||||||
}
|
|
||||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
if (blockData instanceof AnaloguePowerable) {
|
if (blockData instanceof AnaloguePowerable) {
|
||||||
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
|
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
|
||||||
analoguePowerable.setPower(0);
|
analoguePowerable.setPower(0);
|
||||||
location.getBlock().setBlockData(analoguePowerable, true);
|
parent.update(analoguePowerable);
|
||||||
update(analoguePowerable);
|
|
||||||
} else {
|
} else {
|
||||||
Powerable powerable = (Powerable) blockData;
|
Powerable powerable = (Powerable) blockData;
|
||||||
powerable.setPowered(false);
|
powerable.setPowered(false);
|
||||||
location.getBlock().setBlockData(powerable, true);
|
parent.update(powerable);
|
||||||
update(powerable);
|
|
||||||
}
|
}
|
||||||
}, ticks);
|
}, ticks);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
WAIT_FOR {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public SWItem menu(Player player, LoaderMovement parent, int power, long ticks) {
|
||||||
SWInventory swInventory = new SWInventory(player, analogue ? 45 : 27, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
|
SWItem swItem = new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_NO_WAIT_FOR", 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.getItemStack().setAmount((int) Math.min(ticks, 64));
|
||||||
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
|
|
||||||
return swItem;
|
return swItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public boolean hasPower(LoaderMovement parent) {
|
||||||
noop = true;
|
return parent.analogue;
|
||||||
waitFor = false;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasTicks(LoaderMovement parent) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, BlockData blockData, LoaderMovement parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
NO_WAIT_FOR.execute(location, blockData, parent, power, ticks, delay);
|
||||||
|
delay.accept(ticks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +158,8 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovementSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new MovementSettings();
|
if (material == Material.STRING && location.getBlock().getType() == Material.TRIPWIRE) return true;
|
||||||
|
return location.getBlock().getType() == material;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
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.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Instrument;
|
import org.bukkit.Instrument;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -30,80 +28,50 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.data.type.NoteBlock;
|
import org.bukkit.block.data.type.NoteBlock;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.NoteBlockSettings> {
|
public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.NoteBlockSettingsEnum> {
|
||||||
|
|
||||||
public LoaderNoteBlock(Location location) {
|
public LoaderNoteBlock(Location location) {
|
||||||
super(location);
|
super(location, NoteBlockSettingsEnum.INTERACT, NoteBlockSettingsEnum.NOOP, NoteBlockSettingsEnum.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NoteBlockSettings implements ElementSettings {
|
public enum NoteBlockSettingsEnum implements LoaderSettingsEnum<NoteBlock, LoaderNoteBlock, NoteBlockSettingsEnum> {
|
||||||
|
|
||||||
private boolean interact = true;
|
|
||||||
|
|
||||||
|
NOOP {
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, interact);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderNoteBlock parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != Material.NOTE_BLOCK) return;
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_NOOP", player));
|
||||||
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
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public void execute(Location location, NoteBlock blockData, LoaderNoteBlock parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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) {
|
INTERACT {
|
||||||
SWItem swItem = menu(player, interact);
|
@Override
|
||||||
if (swItem.getItemStack().equals(menu(player, this.interact).getItemStack())) {
|
public int getPos() {
|
||||||
swItem.setEnchanted(true);
|
return 3;
|
||||||
}
|
|
||||||
swItem.setLore(Collections.emptyList());
|
|
||||||
return swItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public SWItem menu(Player player, LoaderNoteBlock parent, int power, long ticks) {
|
||||||
interact = false;
|
return new SWItem(Material.NOTE_BLOCK, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_INTERACT", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, NoteBlock blockData, LoaderNoteBlock parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
if (blockData.getInstrument() == Instrument.BANJO) blockData.setInstrument(Instrument.BIT);
|
||||||
|
else blockData.setInstrument(Instrument.BANJO);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +81,7 @@ public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.No
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NoteBlockSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new NoteBlockSettings();
|
return location.getBlock().getType() == Material.NOTE_BLOCK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,113 +19,97 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
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.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.Openable;
|
import org.bukkit.block.data.Openable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.TrapdoorSettings> {
|
public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.OpenableSettingsEnum> {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Material material;
|
private Material material;
|
||||||
|
|
||||||
public LoaderOpenable(Location location, String name, Material material) {
|
public LoaderOpenable(Location location, String name, Material material) {
|
||||||
super(location);
|
super(location, OpenableSettingsEnum.INTERACT, OpenableSettingsEnum.NOOP, OpenableSettingsEnum.values());
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TrapdoorSettings implements ElementSettings {
|
public enum OpenableSettingsEnum implements LoaderSettingsEnum<Openable, LoaderOpenable, OpenableSettingsEnum> {
|
||||||
|
|
||||||
private boolean noop = false;
|
|
||||||
private boolean interact = true;
|
|
||||||
private boolean open = false;
|
|
||||||
|
|
||||||
|
NOOP {
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, noop, interact, open);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderOpenable parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != material) return;
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName(parent.name, "LOADER_INTERACTION_NOOP", player));
|
||||||
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
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public void execute(Location location, Openable blockData, LoaderOpenable parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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) {
|
INTERACT {
|
||||||
SWItem swItem = menu(player, noop, interact, open);
|
@Override
|
||||||
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.open).getItemStack())) {
|
public int getPos() {
|
||||||
swItem.setEnchanted(true);
|
return 3;
|
||||||
}
|
|
||||||
swItem.setLore(Collections.emptyList());
|
|
||||||
return swItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public SWItem menu(Player player, LoaderOpenable parent, int power, long ticks) {
|
||||||
noop = true;
|
return new SWItem(Material.STICK, translateItemName(parent.name, "LOADER_INTERACTION_INTERACT", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Openable blockData, LoaderOpenable parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setOpen(!blockData.isOpen());
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
CLOSED {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderOpenable parent, int power, long ticks) {
|
||||||
|
return new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_CLOSED", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Openable blockData, LoaderOpenable parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setOpen(false);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
OPEN {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderOpenable parent, int power, long ticks) {
|
||||||
|
return new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_OPEN", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Openable blockData, LoaderOpenable parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setOpen(true);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +119,7 @@ public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.Trap
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TrapdoorSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new TrapdoorSettings();
|
return location.getBlock().getType() == material;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,125 +20,140 @@
|
|||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
package de.steamwar.bausystem.features.loader.elements.impl;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
|
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.type.Repeater;
|
import org.bukkit.block.data.type.Repeater;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.RepeaterSettings> {
|
public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.RepeaterSettingsEnum> {
|
||||||
|
|
||||||
public LoaderRepeater(Location location) {
|
public LoaderRepeater(Location location) {
|
||||||
super(location);
|
super(location, RepeaterSettingsEnum.INTERACT, RepeaterSettingsEnum.NOOP, RepeaterSettingsEnum.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RepeaterSettings implements ElementSettings {
|
public enum RepeaterSettingsEnum implements LoaderSettingsEnum<Repeater, LoaderRepeater, RepeaterSettingsEnum> {
|
||||||
|
|
||||||
private boolean interact = false;
|
NOOP {
|
||||||
private int delay = 1;
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
|
||||||
return menu(player, interact, delay);
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_NOOP", player));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SWItem menu(Player player, boolean interact, int delay) {
|
@Override
|
||||||
SWItem swItem;
|
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
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)));
|
},
|
||||||
|
|
||||||
|
INTERACT {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
|
||||||
|
return new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_INTERACT", player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
int repeaterDelay = blockData.getDelay();
|
||||||
|
repeaterDelay++;
|
||||||
|
if (repeaterDelay > 4) repeaterDelay = 1;
|
||||||
|
blockData.setDelay(repeaterDelay);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
DELAY_1 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, 1));
|
||||||
|
swItem.getItemStack().setAmount(1);
|
||||||
return swItem;
|
return swItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Consumer<Long> __) {
|
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
if (location.getBlock().getType() != Material.REPEATER) return;
|
blockData.setDelay(1);
|
||||||
Repeater repeater = (Repeater) location.getBlock().getBlockData();
|
parent.update(blockData);
|
||||||
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);
|
},
|
||||||
|
|
||||||
|
DELAY_2 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
|
||||||
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
|
SWItem swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, 2));
|
||||||
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
|
swItem.getItemStack().setAmount(2);
|
||||||
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;
|
return swItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerInteract() {
|
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
interact = true;
|
blockData.setDelay(2);
|
||||||
delay = 0;
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
DELAY_3 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noop() {
|
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
|
||||||
interact = false;
|
SWItem swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, 3));
|
||||||
delay = 0;
|
swItem.getItemStack().setAmount(3);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setDelay(3);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
DELAY_4 {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
|
||||||
|
SWItem swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, 4));
|
||||||
|
swItem.getItemStack().setAmount(4);
|
||||||
|
return swItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
blockData.setDelay(4);
|
||||||
|
parent.update(blockData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +163,7 @@ public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.Repe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RepeaterSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new RepeaterSettings();
|
return location.getBlock().getType() == Material.REPEATER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ package de.steamwar.bausystem.features.loader.elements.impl;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
|
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -54,7 +53,7 @@ public class LoaderTNT implements LoaderElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
block.setType(Material.TNT, true);
|
block.setType(Material.TNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,120 +20,87 @@
|
|||||||
package de.steamwar.bausystem.features.loader.elements.impl;
|
package de.steamwar.bausystem.features.loader.elements.impl;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
|
|
||||||
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
|
||||||
import de.steamwar.inventory.SWInventory;
|
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.data.Powerable;
|
import org.bukkit.block.data.Powerable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSettings> {
|
public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSettingsEnum> {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Material material;
|
private Material material;
|
||||||
private int ticks;
|
private int ticks;
|
||||||
|
|
||||||
public LoaderTicks(Location location, String name, Material material, int ticks) {
|
public LoaderTicks(Location location, String name, Material material, int ticks) {
|
||||||
super(location);
|
super(location, TicksSettingsEnum.NO_WAIT_FOR, TicksSettingsEnum.NOOP, TicksSettingsEnum.values());
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.ticks = ticks;
|
this.ticks = ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TicksSettings implements ElementSettings {
|
public enum TicksSettingsEnum implements LoaderSettingsEnum<Powerable, LoaderTicks, TicksSettingsEnum> {
|
||||||
|
|
||||||
private boolean noop = false;
|
|
||||||
private boolean waitFor = false;
|
|
||||||
|
|
||||||
|
NOOP {
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public int getPos() {
|
||||||
return menu(player, noop, waitFor);
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void execute(Consumer<Long> delay) {
|
public SWItem menu(Player player, LoaderTicks parent, int power, long ticks) {
|
||||||
if (location.getBlock().getType() != material) {
|
return new SWItem(Material.STRUCTURE_VOID, translateItemName(parent.name, "LOADER_INTERACTION_NOOP", player));
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (noop) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Powerable blockData, LoaderTicks parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
NO_WAIT_FOR {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SWItem menu(Player player, LoaderTicks parent, int power, long ticks) {
|
||||||
|
return new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_NO_WAIT_FOR", player, ticks));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Location location, Powerable blockData, LoaderTicks parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
||||||
powerable.setPowered(true);
|
powerable.setPowered(true);
|
||||||
location.getBlock().setBlockData(powerable, true);
|
parent.update(powerable);
|
||||||
update(powerable);
|
|
||||||
|
|
||||||
if (waitFor) {
|
|
||||||
delay.accept((long) ticks);
|
|
||||||
}
|
|
||||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
powerable.setPowered(false);
|
powerable.setPowered(false);
|
||||||
location.getBlock().setBlockData(powerable, true);
|
parent.update(powerable);
|
||||||
update(powerable);
|
}, parent.ticks);
|
||||||
}, ticks);
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
WAIT_FOR {
|
||||||
|
@Override
|
||||||
|
public int getPos() {
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public SWItem menu(Player player, LoaderTicks parent, int power, long ticks) {
|
||||||
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
|
return new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_WAIT_FOR", player, ticks));
|
||||||
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
|
@Override
|
||||||
public void noop() {
|
public void execute(Location location, Powerable blockData, LoaderTicks parent, int power, long ticks, Consumer<Long> delay) {
|
||||||
noop = true;
|
NO_WAIT_FOR.execute(location, blockData, parent, power, ticks, delay);
|
||||||
|
delay.accept((long) parent.ticks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +110,7 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TicksSettings createNewElement() {
|
public boolean checkBlockInWorld() {
|
||||||
return new TicksSettings();
|
return location.getBlock().getType() == material;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren