Fix Loader convenience with creating NOOP's
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
8e4b383655
Commit
56f7fddb0e
@ -123,26 +123,34 @@ public class Loader implements Listener {
|
||||
|
||||
public void gui(SettingsSorting settingsSorting) {
|
||||
List<SWListInv.SWListEntry<LoaderElement>> list = new ArrayList<>();
|
||||
for (LoaderElement element : elements) {
|
||||
if (settingsSorting != null) {
|
||||
if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) {
|
||||
continue;
|
||||
Runnable updateRunnable = () -> {
|
||||
list.clear();
|
||||
for (LoaderElement element : elements) {
|
||||
if (settingsSorting != null) {
|
||||
if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) {
|
||||
continue;
|
||||
}
|
||||
if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) {
|
||||
continue;
|
||||
SWItem item = element.menu(p);
|
||||
if (element instanceof LoaderInteractionElement<?>) {
|
||||
LoaderInteractionElement<?> interactionElement = (LoaderInteractionElement<?>) element;
|
||||
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p)));
|
||||
} else {
|
||||
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p)));
|
||||
}
|
||||
list.add(new SWListInv.SWListEntry<>(item, element));
|
||||
}
|
||||
SWItem item = element.menu(p);
|
||||
if (element instanceof LoaderInteractionElement<?>) {
|
||||
LoaderInteractionElement<?> interactionElement = (LoaderInteractionElement<?>) element;
|
||||
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p)));
|
||||
} else {
|
||||
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p)));
|
||||
}
|
||||
list.add(new SWListInv.SWListEntry<>(item, element));
|
||||
}
|
||||
};
|
||||
updateRunnable.run();
|
||||
|
||||
SWListInv<LoaderElement> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {});
|
||||
swListInv.setCallback((clickType, entry) -> entry.click(p, swListInv::open));
|
||||
swListInv.setCallback((clickType, entry) -> entry.click(p, () -> {
|
||||
updateRunnable.run();
|
||||
swListInv.open();
|
||||
}));
|
||||
|
||||
SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_INTERACTIONS", p), clickType -> {
|
||||
gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS);
|
||||
@ -173,6 +181,7 @@ public class Loader implements Listener {
|
||||
}
|
||||
gui(settingsSorting);
|
||||
});
|
||||
updateRunnable.run();
|
||||
swAnvilInv.open();
|
||||
});
|
||||
swListInv.setItem(50, waitBetweenTNT);
|
||||
@ -192,6 +201,7 @@ public class Loader implements Listener {
|
||||
}
|
||||
gui(settingsSorting);
|
||||
});
|
||||
updateRunnable.run();
|
||||
swAnvilInv.open();
|
||||
});
|
||||
swListInv.setItem(51, waitTime);
|
||||
|
@ -31,6 +31,7 @@ public interface ElementSettings {
|
||||
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));
|
||||
|
@ -20,6 +20,7 @@
|
||||
package de.steamwar.bausystem.features.loader.elements;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import org.bukkit.Location;
|
||||
@ -60,13 +61,19 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
||||
@Override
|
||||
public void click(Player player, Runnable backAction) {
|
||||
List<SWListInv.SWListEntry<T>> entries = new ArrayList<>();
|
||||
for (T element : elements) {
|
||||
entries.add(new SWListInv.SWListEntry<>(element.menu(player), element));
|
||||
}
|
||||
Runnable updateRunnable = () -> {
|
||||
entries.clear();
|
||||
for (T element : elements) {
|
||||
entries.add(new SWListInv.SWListEntry<>(element.menu(player), element));
|
||||
}
|
||||
};
|
||||
updateRunnable.run();
|
||||
|
||||
SWListInv<T> listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> {
|
||||
SWListInv<T> listInv = new SWListInv<>(player, "Interaction Settings", false, entries, (clickType, entry) -> {});
|
||||
listInv.setCallback((clickType, entry) -> {
|
||||
entry.click(player, () -> {
|
||||
click(player, backAction);
|
||||
updateRunnable.run();
|
||||
listInv.open();
|
||||
}, () -> {
|
||||
if (elements.size() == 1) return;
|
||||
elements.remove(entry);
|
||||
@ -79,12 +86,33 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
||||
listInv.setItem(50, new SWItem(Material.GHAST_SPAWN_EGG, "§7Insert another Setting", clickType -> {
|
||||
T element = createNewElement();
|
||||
elements.add(element);
|
||||
element.click(player, () -> click(player, backAction), () -> {
|
||||
element.click(player, () -> {
|
||||
updateRunnable.run();
|
||||
listInv.open();
|
||||
}, () -> {
|
||||
if (elements.size() == 1) return;
|
||||
elements.remove(element);
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -120,6 +120,12 @@ public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.
|
||||
interact = true;
|
||||
mode = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
interact = false;
|
||||
mode = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,6 +144,13 @@ public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDayli
|
||||
interact = true;
|
||||
inverted = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
noop = true;
|
||||
interact = false;
|
||||
inverted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,6 +134,11 @@ public class LoaderLectern extends LoaderInteractionElement<LoaderLectern.Lecter
|
||||
swItem.setLore(Collections.emptyList());
|
||||
return swItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
noop = true;
|
||||
}
|
||||
}
|
||||
|
||||
public enum LecternAction {
|
||||
|
@ -117,6 +117,11 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
|
||||
swItem.setLore(Collections.emptyList());
|
||||
return swItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
noop = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -208,6 +208,12 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
||||
swItem.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", player)));
|
||||
return swItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
noop = true;
|
||||
waitFor = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -100,6 +100,11 @@ public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.No
|
||||
swItem.setLore(Collections.emptyList());
|
||||
return swItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
interact = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,6 +122,11 @@ public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.Trap
|
||||
swItem.setLore(Collections.emptyList());
|
||||
return swItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
noop = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,6 +134,12 @@ public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.Repe
|
||||
interact = true;
|
||||
delay = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
interact = false;
|
||||
delay = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,6 +130,11 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
||||
swItem.setLore(Collections.emptyList());
|
||||
return swItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void noop() {
|
||||
noop = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,15 +26,13 @@ import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LoaderWait implements LoaderElement, Listener {
|
||||
public class LoaderWait implements LoaderElement {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ -54,8 +52,8 @@ public class LoaderWait implements LoaderElement, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Consumer<Long> __) {
|
||||
__.accept(delay);
|
||||
public void execute(Consumer<Long> wait) {
|
||||
wait.accept(delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren