SteamWar/BauSystem2.0
Archiviert
12
0

QOL #203

Zusammengeführt
YoyoNow hat 44 Commits von QOL nach master 2023-10-06 14:59:48 +02:00 zusammengeführt
16 geänderte Dateien mit 1291 neuen und 1009 gelöschten Zeilen
Nur Änderungen aus Commit 8ecb6e173f werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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_TITLE=§7Wait Time
LOADER_GUI_SETTINGS_TITLE=Settings
LOADER_GUI_COPY_TITLE=Copy amount
LOADER_GUI_SETTINGS_BACK=§8Back
LOADER_GUI_SETTINGS_COPY=§7Copy
LOADER_GUI_SETTINGS_DELETE=§cDelete
LOADER_GUI_WAIT_TITLE=Settings
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_SETTING_NAME=§7{0}
LOADER_SETTING_MODES=§7Modi§8: §e{0}
LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0}
LOADER_SETTING_MODES=§7Modes§8: §e{0}
LOADER_SETTING_POWER=§7Power§8: §e{0}
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s)
LOADER_SETTING_WAIT_NAME=Wartezeit
LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s)
LOADER_SETTING_WAIT_NAME=Wait
LOADER_SETTING_TICKS_NAME=Ticks
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
@ -606,18 +608,18 @@ LOADER_SETTING_TNT_X=§7X§8: §e{0}
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
LOADER_INTERACTION_NOOP=NOOP
LOADER_INTERACTION_INTERACT=Interagiere
LOADER_INTERACTION_POWERED=Aktiviert
LOADER_INTERACTION_UNPOWERED=Deaktiviert
LOADER_INTERACTION_PAGE_PREV=Vorherige Seite
LOADER_INTERACTION_PAGE_NEXT=Nächste Seite
LOADER_INTERACTION_PAGE=Seite {0}
LOADER_INTERACTION_ACTIVE=Aktiviert
LOADER_INTERACTION_INACTIVE=Deaktiviert
LOADER_INTERACTION_WAIT_FOR=Darauf warten
LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten
LOADER_INTERACTION_OPEN=Geöffnet
LOADER_INTERACTION_CLOSED=Geschlossen
LOADER_INTERACTION_INTERACT=Interact
LOADER_INTERACTION_POWERED=Powered
LOADER_INTERACTION_UNPOWERED=Unpowered
LOADER_INTERACTION_PAGE_PREV=Previous Page
LOADER_INTERACTION_PAGE_NEXT=Next Page
LOADER_INTERACTION_PAGE=Page {0}
LOADER_INTERACTION_ACTIVE=Active
LOADER_INTERACTION_INACTIVE=Inactive
LOADER_INTERACTION_WAIT_FOR=Wait for
LOADER_INTERACTION_NO_WAIT_FOR=No wait for
LOADER_INTERACTION_OPEN=Open
LOADER_INTERACTION_CLOSED=Closed
# Loadtimer
LOADTIMER_HELP_OVERVIEW=§7Compete with your friends loading your cannon and get information about the cannon

Datei anzeigen

@ -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_TITLE=§7Wartezeit
LOADER_GUI_SETTINGS_TITLE=Einstellungen
LOADER_GUI_COPY_TITLE=Anzahl Kopien
LOADER_GUI_SETTINGS_BACK=§8Zurück
LOADER_GUI_SETTINGS_COPY=§7Kopieren
LOADER_GUI_SETTINGS_DELETE=§cLöschen
LOADER_GUI_WAIT_TITLE=Wartezeit
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_SETTING_NAME=§7{0}
LOADER_SETTING_MODES=§7Modes§8: §e{0}
LOADER_SETTING_POWER=§7Power§8: §e{0}
LOADER_SETTING_MODES=§7Modi§8: §e{0}
LOADER_SETTING_POWER=§7Redstone Stärke§8: §e{0}
LOADER_SETTING_TICKS=§7Ticks§8: §e{0}
LOADER_SETTING_REPEATER=§7Repeater§8: §e{0}
LOADER_SETTING_WAIT=§7Wait§8: §e{0} Tick(s)
LOADER_SETTING_WAIT_NAME=Wait
LOADER_SETTING_WAIT=§7Wartezeit§8: §e{0} Tick(s)
LOADER_SETTING_WAIT_NAME=Wartezeit
LOADER_SETTING_TICKS_NAME=Ticks
LOADER_SETTING_TICKS_REMOVE_ONE=§c-1
LOADER_SETTING_TICKS_REMOVE_ONE_SHIFT=§7Shift§8: §c-5
@ -574,18 +576,18 @@ LOADER_SETTING_TNT_X=§7X§8: §e{0}
LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
LOADER_INTERACTION_NOOP=NOOP
LOADER_INTERACTION_INTERACT=Interact
LOADER_INTERACTION_POWERED=Powered
LOADER_INTERACTION_UNPOWERED=Unpowered
LOADER_INTERACTION_PAGE_PREV=Previous Page
LOADER_INTERACTION_PAGE_NEXT=Next Page
LOADER_INTERACTION_PAGE=Page {0}
LOADER_INTERACTION_ACTIVE=Active
LOADER_INTERACTION_INACTIVE=Inactive
LOADER_INTERACTION_WAIT_FOR=Wait for
LOADER_INTERACTION_NO_WAIT_FOR=No wait for
LOADER_INTERACTION_OPEN=Open
LOADER_INTERACTION_CLOSED=Closed
LOADER_INTERACTION_INTERACT=Interagiere
LOADER_INTERACTION_POWERED=Aktiviert
LOADER_INTERACTION_UNPOWERED=Deaktiviert
LOADER_INTERACTION_PAGE_PREV=Vorherige Seite
LOADER_INTERACTION_PAGE_NEXT=Nächste Seite
LOADER_INTERACTION_PAGE=Seite {0}
LOADER_INTERACTION_ACTIVE=Aktiviert
LOADER_INTERACTION_INACTIVE=Deaktiviert
LOADER_INTERACTION_WAIT_FOR=Darauf warten
LOADER_INTERACTION_NO_WAIT_FOR=Nicht darauf warten
LOADER_INTERACTION_OPEN=Geöffnet
LOADER_INTERACTION_CLOSED=Geschlossen
# Loadtimer
LOADTIMER_HELP_OVERVIEW=§7Messe dich und deine Freunde beim Beladen einer Kanone und bekomme informationen über die Kanone

Datei anzeigen

@ -72,18 +72,19 @@ public class Loader implements Listener {
waitTime--;
return;
}
if (currentElement >= elements.size()) {
currentElement = 0;
}
while (currentElement < elements.size()) {
LoaderElement element = elements.get(currentElement);
currentElement++;
element.execute(delay -> waitTime = delay);
if (waitTime > 0) {
break;
if (element instanceof LoaderTNT) currentElement--;
return;
}
}
if (currentElement >= elements.size()) {
currentElement = 0;
}
}, 0, 1);
}
@ -221,7 +222,7 @@ public class Loader implements Listener {
}
public String getProgress() {
return (currentElement + 1) + "§8/§7" + elements.size();
return Math.max(currentElement, 1) + "§8/§7" + elements.size();
}
public enum SettingsSorting {

Datei anzeigen

@ -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));
}
}

Datei anzeigen

@ -21,62 +21,91 @@ package de.steamwar.bausystem.features.loader.elements;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.FaceAttachable;
import org.bukkit.block.data.*;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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 int currentShot = 0;
protected T defaultSetting;
protected T newSetting;
protected T[] allSettings;
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;
T element = createNewElement();
element.playerInteract();
elements.add(element);
this.defaultSetting = defaultSetting;
this.newSetting = newSetting;
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
public void execute(Consumer<Long> delay) {
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++;
if (currentShot >= elements.size()) currentShot = 0;
}
@Override
public void click(Player player, Runnable backAction) {
List<SWListInv.SWListEntry<T>> entries = new ArrayList<>();
List<SWListInv.SWListEntry<Integer>> entries = new ArrayList<>();
Runnable updateRunnable = () -> {
entries.clear();
for (T element : elements) {
entries.add(new SWListInv.SWListEntry<>(element.menu(player), element));
for (int i = 0; i < elements.size(); i++) {
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();
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) -> {
entry.click(player, () -> {
openIndividualSettingsMenu(player, entry, () -> {
updateRunnable.run();
listInv.open();
}, () -> {
if (elements.size() == 1) return;
elements.remove(entry);
elements.remove((int) entry);
extraPower.remove((int) entry);
extraTicks.remove((int) entry);
if (elements.isEmpty()) {
elements.add(newSetting);
extraPower.add(0);
extraTicks.add(1L);
}
click(player, backAction);
});
});
@ -84,69 +113,190 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
backAction.run();
}));
listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> {
T element = createNewElement();
elements.add(element);
element.click(player, () -> {
elements.add(defaultSetting);
extraPower.add(0);
extraTicks.add(1L);
openIndividualSettingsMenu(player, elements.size() - 1, () -> {
updateRunnable.run();
listInv.open();
}, () -> {
if (elements.size() == 1) return;
elements.remove(element);
elements.remove(elements.size() - 1);
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);
});
}));
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();
}
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) {
Material material = blockData.getMaterial();
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;
updateBlock(block, sw);
FaceAttachable.AttachedFace face = sw.getAttachedFace();
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) {
updateBlock(block.getRelative(BlockFace.UP));
updateBlock(block.getRelative(BlockFace.UP), sw.isPowered() ? 15 : 0);
} 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);
} else if (material.name().endsWith("_PLATE")) {
updateBlock(block.getRelative(BlockFace.DOWN));
}
}
protected void updateBlock(Block block) {
updateBlock(block, block.getBlockData());
private void updateBlock(Block block, int powered) {
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) {
block.setType(Material.BARRIER, true);
block.setBlockData(data, true);
private void updateBlock(Block block, BlockData data) {
block.setType(Material.BARRIER);
block.setBlockData(data);
}
public abstract T createNewElement();
public abstract boolean checkBlockInWorld();
protected final String translateItemName(String name, Player player) {
return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player));

Datei anzeigen

@ -0,0 +1,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));
}
}

Datei anzeigen

@ -19,10 +19,8 @@
package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
@ -30,101 +28,83 @@ import org.bukkit.block.data.type.Comparator;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.ComparatorSettings> {
public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.ComparatorSettingsEnum> {
public LoaderComparator(Location location) {
super(location);
super(location, ComparatorSettingsEnum.INTERACT, ComparatorSettingsEnum.NOOP, ComparatorSettingsEnum.values());
}
public class ComparatorSettings implements ElementSettings {
private boolean interact = false;
private Comparator.Mode mode = Comparator.Mode.COMPARE;
public enum ComparatorSettingsEnum implements LoaderSettingsEnum<Comparator, LoaderComparator, ComparatorSettingsEnum> {
NOOP {
@Override
public SWItem menu(Player player) {
return menu(player, interact, mode);
}
private SWItem menu(Player player, boolean interact, Comparator.Mode mode) {
SWItem swItem;
if (interact) {
swItem = new SWItem(Material.STICK, "§7Comparator§8: §eInteract");
} else if (mode == null) {
swItem = new SWItem(Material.STRUCTURE_VOID, "§7Comparator§8: §eNOOP");
} else {
swItem = new SWItem(Material.COMPARATOR, "§7Comparator§8: §e" + mode.name());
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
public int getPos() {
return 2;
}
@Override
public void execute(Consumer<Long> delay) {
if (location.getBlock().getType() != Material.COMPARATOR) return;
Comparator comparator = (Comparator) location.getBlock().getBlockData();
if (interact) {
comparator.setMode(comparator.getMode() == Comparator.Mode.COMPARE ? Comparator.Mode.SUBTRACT : Comparator.Mode.COMPARE);
} else if (mode == null) {
return;
} else {
comparator.setMode(mode);
}
location.getBlock().setBlockData(comparator, true);
public SWItem menu(Player player, LoaderComparator parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, "§7Comparator§8: §eNOOP");
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, false, null).getItemStack(), clickType -> {
interact = false;
mode = null;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, true, null).getItemStack(), clickType -> {
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, Comparator.Mode.COMPARE).getItemStack(), clickType -> {
interact = false;
mode = Comparator.Mode.COMPARE;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, Comparator.Mode.SUBTRACT).getItemStack(), clickType -> {
interact = false;
mode = Comparator.Mode.SUBTRACT;
click(player, backAction, deleteAction);
});
swInventory.open();
public void execute(Location location, Comparator blockData, LoaderComparator parent, int power, long ticks, Consumer<Long> delay) {
}
},
private SWItem item(Player player, boolean interact, Comparator.Mode mode) {
SWItem swItem = menu(player, interact, mode);
if (swItem.getItemStack().equals(menu(player, this.interact, this.mode).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
INTERACT {
@Override
public int getPos() {
return 3;
}
@Override
public void playerInteract() {
interact = true;
mode = null;
public SWItem menu(Player player, LoaderComparator parent, int power, long ticks) {
return new SWItem(Material.STICK, "§7Comparator§8: §eInteract");
}
@Override
public void noop() {
interact = false;
mode = null;
public void execute(Location location, Comparator blockData, LoaderComparator parent, int power, long ticks, Consumer<Long> delay) {
blockData.setMode(blockData.getMode() == Comparator.Mode.COMPARE ? Comparator.Mode.SUBTRACT : Comparator.Mode.COMPARE);
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
public ComparatorSettings createNewElement() {
return new ComparatorSettings();
public boolean checkBlockInWorld() {
return location.getBlock().getType() == Material.COMPARATOR;
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -19,108 +19,91 @@
package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSettings> {
public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSettingsEnum> {
public LoaderLever(Location location) {
super(location);
super(location, LeverSettingsEnum.INTERACT, LeverSettingsEnum.NOOP, LeverSettingsEnum.values());
}
public class LeverSettings implements ElementSettings {
private boolean noop = false;
private boolean interact = true;
private boolean power = false;
public enum LeverSettingsEnum implements LoaderSettingsEnum<Switch, LoaderLever, LeverSettingsEnum> {
NOOP {
@Override
public SWItem menu(Player player) {
return menu(player, noop, interact, power);
}
private SWItem menu(Player player, boolean noop, boolean interact, boolean power) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_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;
public int getPos() {
return 2;
}
@Override
public void execute(Consumer<Long> delay) {
if (location.getBlock().getType() != Material.LEVER) return;
if (noop) return;
Switch lever = (Switch) location.getBlock().getBlockData();
if (interact) {
lever.setPowered(!lever.isPowered());
} else {
lever.setPowered(power);
}
location.getBlock().setBlockData(lever, true);
public SWItem menu(Player player, LoaderLever parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_SWITCH", "LOADER_INTERACTION_NOOP", player));
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> {
noop = false;
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> {
noop = false;
interact = false;
power = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> {
noop = false;
interact = false;
power = true;
click(player, backAction, deleteAction);
});
swInventory.open();
public void execute(Location location, Switch blockData, LoaderLever parent, int power, long ticks, Consumer<Long> delay) {
}
},
private SWItem item(Player player, boolean noop, boolean interact, boolean power) {
SWItem swItem = menu(player, noop, interact, power);
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.power).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
INTERACT {
@Override
public int getPos() {
return 3;
}
@Override
public void noop() {
noop = true;
public SWItem menu(Player player, LoaderLever parent, int power, long ticks) {
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
public LeverSettings createNewElement() {
return new LeverSettings();
public boolean checkBlockInWorld() {
return location.getBlock().getType() == Material.LEVER;
}
}

Datei anzeigen

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

Datei anzeigen

@ -19,10 +19,8 @@
package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem;
import org.bukkit.Instrument;
import org.bukkit.Location;
@ -30,80 +28,50 @@ import org.bukkit.Material;
import org.bukkit.block.data.type.NoteBlock;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.NoteBlockSettings> {
public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.NoteBlockSettingsEnum> {
public LoaderNoteBlock(Location location) {
super(location);
super(location, NoteBlockSettingsEnum.INTERACT, NoteBlockSettingsEnum.NOOP, NoteBlockSettingsEnum.values());
}
public class NoteBlockSettings implements ElementSettings {
private boolean interact = true;
public enum NoteBlockSettingsEnum implements LoaderSettingsEnum<NoteBlock, LoaderNoteBlock, NoteBlockSettingsEnum> {
NOOP {
@Override
public SWItem menu(Player player) {
return menu(player, interact);
}
private SWItem menu(Player player, boolean interact) {
SWItem swItem;
if (interact) {
swItem = new SWItem(Material.NOTE_BLOCK, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_INTERACT", player));
} else {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_NOOP", player));
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
public int getPos() {
return 2;
}
@Override
public void execute(Consumer<Long> delay) {
if (location.getBlock().getType() != Material.NOTE_BLOCK) return;
NoteBlock noteBlock = (NoteBlock) location.getBlock().getBlockData();
if (interact) {
if (noteBlock.getInstrument() == Instrument.BANJO) noteBlock.setInstrument(Instrument.BIT);
else noteBlock.setInstrument(Instrument.BANJO);
} else {
return;
}
location.getBlock().setBlockData(noteBlock);
public SWItem menu(Player player, LoaderNoteBlock parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_NOTEBLOCK", "LOADER_INTERACTION_NOOP", player));
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
public void execute(Location location, NoteBlock blockData, LoaderNoteBlock parent, int power, long ticks, Consumer<Long> delay) {
swInventory.setItem(2, item(player, false).getItemStack(), clickType -> {
interact = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, true).getItemStack(), clickType -> {
interact = true;
click(player, backAction, deleteAction);
});
swInventory.open();
}
},
private SWItem item(Player player, boolean interact) {
SWItem swItem = menu(player, interact);
if (swItem.getItemStack().equals(menu(player, this.interact).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
INTERACT {
@Override
public int getPos() {
return 3;
}
@Override
public void noop() {
interact = false;
public SWItem menu(Player player, LoaderNoteBlock parent, int power, long ticks) {
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
public NoteBlockSettings createNewElement() {
return new NoteBlockSettings();
public boolean checkBlockInWorld() {
return location.getBlock().getType() == Material.NOTE_BLOCK;
}
}

Datei anzeigen

@ -19,113 +19,97 @@
package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.Openable;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.TrapdoorSettings> {
public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.OpenableSettingsEnum> {
private String name;
private Material material;
public LoaderOpenable(Location location, String name, Material material) {
super(location);
super(location, OpenableSettingsEnum.INTERACT, OpenableSettingsEnum.NOOP, OpenableSettingsEnum.values());
this.name = name;
this.material = material;
}
public class TrapdoorSettings implements ElementSettings {
private boolean noop = false;
private boolean interact = true;
private boolean open = false;
public enum OpenableSettingsEnum implements LoaderSettingsEnum<Openable, LoaderOpenable, OpenableSettingsEnum> {
NOOP {
@Override
public SWItem menu(Player player) {
return menu(player, noop, interact, open);
}
private SWItem menu(Player player, boolean noop, boolean interact, boolean powered) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName(name, "LOADER_INTERACTION_NOOP", player));
} else if (interact) {
swItem = new SWItem(Material.STICK, translateItemName(name, "LOADER_INTERACTION_INTERACT", player));
} else {
swItem = new SWItem(material, translateItemName(name, open ? "LOADER_INTERACTION_OPEN" : "LOADER_INTERACTION_CLOSED", player));
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
public int getPos() {
return 2;
}
@Override
public void execute(Consumer<Long> delay) {
if (location.getBlock().getType() != material) return;
Openable openable = (Openable) location.getBlock().getBlockData();
if (noop) {
return;
} else if (interact) {
openable.setOpen(!openable.isOpen());
} else {
openable.setOpen(open);
}
location.getBlock().setBlockData(openable);
public SWItem menu(Player player, LoaderOpenable parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, translateItemName(parent.name, "LOADER_INTERACTION_NOOP", player));
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(3, item(player, false, true, false).getItemStack(), clickType -> {
noop = false;
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, false, false).getItemStack(), clickType -> {
noop = false;
interact = false;
open = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, false, true).getItemStack(), clickType -> {
noop = false;
interact = false;
open = true;
click(player, backAction, deleteAction);
});
swInventory.open();
public void execute(Location location, Openable blockData, LoaderOpenable parent, int power, long ticks, Consumer<Long> delay) {
}
},
private SWItem item(Player player, boolean noop, boolean interact, boolean open) {
SWItem swItem = menu(player, noop, interact, open);
if (swItem.getItemStack().equals(menu(player, this.noop, this.interact, this.open).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
INTERACT {
@Override
public int getPos() {
return 3;
}
@Override
public void noop() {
noop = true;
public SWItem menu(Player player, LoaderOpenable parent, int power, long ticks) {
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
public TrapdoorSettings createNewElement() {
return new TrapdoorSettings();
public boolean checkBlockInWorld() {
return location.getBlock().getType() == material;
}
}

Datei anzeigen

@ -20,125 +20,140 @@
package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.type.Repeater;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.RepeaterSettings> {
public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.RepeaterSettingsEnum> {
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;
private int delay = 1;
NOOP {
@Override
public int getPos() {
return 1;
}
@Override
public SWItem menu(Player player) {
return menu(player, interact, delay);
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_NOOP", player));
}
private SWItem menu(Player player, boolean interact, int delay) {
SWItem swItem;
if (interact) {
swItem = new SWItem(Material.STICK, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_INTERACT", player));
} else if (delay == 0) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_REPEATER", "LOADER_INTERACTION_NOOP", player));
} else {
swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, delay));
swItem.getItemStack().setAmount(delay);
@Override
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> 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;
}
@Override
public void execute(Consumer<Long> __) {
if (location.getBlock().getType() != Material.REPEATER) return;
Repeater repeater = (Repeater) location.getBlock().getBlockData();
if (interact) {
int delay = repeater.getDelay();
delay++;
if (delay > 4) delay = 1;
repeater.setDelay(delay);
} else if (delay == 0) {
return;
} else {
repeater.setDelay(delay);
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
blockData.setDelay(1);
parent.update(blockData);
}
location.getBlock().setBlockData(repeater, true);
},
DELAY_2 {
@Override
public int getPos() {
return 5;
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(1, item(player, false, 0).getItemStack(), clickType -> {
interact = false;
delay = 0;
click(player, backAction, deleteAction);
});
swInventory.setItem(2, item(player, true, -1).getItemStack(), clickType -> {
interact = true;
click(player, backAction, deleteAction);
});
swInventory.setItem(4, item(player, false, 1).getItemStack(), clickType -> {
interact = false;
delay = 1;
click(player, backAction, deleteAction);
});
swInventory.setItem(5, item(player, false, 2).getItemStack(), clickType -> {
interact = false;
delay = 2;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, 3).getItemStack(), clickType -> {
interact = false;
delay = 3;
click(player, backAction, deleteAction);
});
swInventory.setItem(7, item(player, false, 4).getItemStack(), clickType -> {
interact = false;
delay = 4;
click(player, backAction, deleteAction);
});
swInventory.open();
}
private SWItem item(Player player, boolean interact, int delay) {
SWItem swItem = menu(player, interact, delay);
if (swItem.getItemStack().equals(menu(player, this.interact, this.delay).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
SWItem swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, 2));
swItem.getItemStack().setAmount(2);
return swItem;
}
@Override
public void playerInteract() {
interact = true;
delay = 0;
public void execute(Location location, Repeater blockData, LoaderRepeater parent, int power, long ticks, Consumer<Long> delay) {
blockData.setDelay(2);
parent.update(blockData);
}
},
DELAY_3 {
@Override
public int getPos() {
return 6;
}
@Override
public void noop() {
interact = false;
delay = 0;
public SWItem menu(Player player, LoaderRepeater parent, int power, long ticks) {
SWItem swItem = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_SETTING_REPEATER", player, 3));
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
public RepeaterSettings createNewElement() {
return new RepeaterSettings();
public boolean checkBlockInWorld() {
return location.getBlock().getType() == Material.REPEATER;
}
}

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.LoaderElement;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -54,7 +53,7 @@ public class LoaderTNT implements LoaderElement {
return;
}
block.setType(Material.TNT, true);
block.setType(Material.TNT);
}
@Override

Datei anzeigen

@ -20,120 +20,87 @@
package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.ElementSettings;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.inventory.SWInventory;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.Powerable;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Consumer;
public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSettings> {
public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSettingsEnum> {
private String name;
private Material material;
private 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.material = material;
this.ticks = ticks;
}
public class TicksSettings implements ElementSettings {
private boolean noop = false;
private boolean waitFor = false;
public enum TicksSettingsEnum implements LoaderSettingsEnum<Powerable, LoaderTicks, TicksSettingsEnum> {
NOOP {
@Override
public SWItem menu(Player player) {
return menu(player, noop, waitFor);
}
private SWItem menu(Player player, boolean noop, boolean waitFor) {
SWItem swItem;
if (noop) {
swItem = new SWItem(Material.STRUCTURE_VOID, translateItemName(name, "LOADER_INTERACTION_NOOP", player));
} else if (waitFor) {
swItem = new SWItem(material, translateItemName(name, "LOADER_INTERACTION_WAIT_FOR", player, ticks));
} else {
swItem = new SWItem(material, translateItemName(name, "LOADER_INTERACTION_NO_WAIT_FOR", player, ticks));
swItem.setEnchanted(true);
}
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
return swItem;
public int getPos() {
return 2;
}
@Override
public void execute(Consumer<Long> delay) {
if (location.getBlock().getType() != material) {
return;
}
if (noop) {
return;
public SWItem menu(Player player, LoaderTicks parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, translateItemName(parent.name, "LOADER_INTERACTION_NOOP", player));
}
@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.setPowered(true);
location.getBlock().setBlockData(powerable, true);
update(powerable);
parent.update(powerable);
if (waitFor) {
delay.accept((long) ticks);
}
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true);
update(powerable);
}, ticks);
parent.update(powerable);
}, parent.ticks);
}
},
WAIT_FOR {
@Override
public int getPos() {
return 6;
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, 18, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_TITLE", player));
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_BACK", player)).getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, BauSystem.MESSAGE.parse("LOADER_GUI_SETTINGS_DELETE", player)).getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> {
noop = true;
click(player, backAction, deleteAction);
});
if (ticks >= 0) {
swInventory.setItem(5, item(player, false, false).getItemStack(), clickType -> {
noop = false;
waitFor = false;
click(player, backAction, deleteAction);
});
swInventory.setItem(6, item(player, false, true).getItemStack(), clickType -> {
noop = false;
waitFor = true;
click(player, backAction, deleteAction);
});
}
swInventory.open();
}
private SWItem item(Player player, boolean noop, boolean waitFor) {
SWItem swItem = menu(player, noop, waitFor);
if (swItem.getItemStack().equals(menu(player, this.noop, this.waitFor).getItemStack())) {
swItem.setEnchanted(true);
}
swItem.setLore(Collections.emptyList());
return swItem;
public SWItem menu(Player player, LoaderTicks parent, int power, long ticks) {
return new SWItem(parent.material, translateItemName(parent.name, "LOADER_INTERACTION_WAIT_FOR", player, ticks));
}
@Override
public void noop() {
noop = true;
public void execute(Location location, Powerable blockData, LoaderTicks parent, int power, long ticks, Consumer<Long> delay) {
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
public TicksSettings createNewElement() {
return new TicksSettings();
public boolean checkBlockInWorld() {
return location.getBlock().getType() == material;
}
}