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