SteamWar/BauSystem2.0
Archiviert
12
0

Fix Loader convenience with creating NOOP's

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-08-27 12:54:04 +02:00
Ursprung 8e4b383655
Commit 56f7fddb0e
13 geänderte Dateien mit 114 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -123,6 +123,8 @@ public class Loader implements Listener {
public void gui(SettingsSorting settingsSorting) {
List<SWListInv.SWListEntry<LoaderElement>> list = new ArrayList<>();
Runnable updateRunnable = () -> {
list.clear();
for (LoaderElement element : elements) {
if (settingsSorting != null) {
if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) {
@ -141,8 +143,14 @@ public class Loader implements Listener {
}
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);

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -120,6 +120,12 @@ public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.
interact = true;
mode = null;
}
@Override
public void noop() {
interact = false;
mode = null;
}
}
@Override

Datei anzeigen

@ -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

Datei anzeigen

@ -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 {

Datei anzeigen

@ -117,6 +117,11 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
swItem.setLore(Collections.emptyList());
return swItem;
}
@Override
public void noop() {
noop = true;
}
}
@Override

Datei anzeigen

@ -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

Datei anzeigen

@ -100,6 +100,11 @@ public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.No
swItem.setLore(Collections.emptyList());
return swItem;
}
@Override
public void noop() {
interact = false;
}
}
@Override

Datei anzeigen

@ -122,6 +122,11 @@ public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.Trap
swItem.setLore(Collections.emptyList());
return swItem;
}
@Override
public void noop() {
noop = true;
}
}
@Override

Datei anzeigen

@ -134,6 +134,12 @@ public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.Repe
interact = true;
delay = 0;
}
@Override
public void noop() {
interact = false;
delay = 0;
}
}
@Override

Datei anzeigen

@ -130,6 +130,11 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
swItem.setLore(Collections.emptyList());
return swItem;
}
@Override
public void noop() {
noop = true;
}
}
@Override

Datei anzeigen

@ -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