SteamWar/BauSystem2.0
Archiviert
12
0

Add LoaderTNT editing
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Add more filter options
Add remove loader element on break block

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-09-17 16:03:51 +02:00
Ursprung 13afc55b1f
Commit adc394e660
7 geänderte Dateien mit 251 neuen und 87 gelöschten Zeilen

Datei anzeigen

@ -544,6 +544,7 @@ LOADER_PAUSE = §7Pause
LOADER_END = §8Finished LOADER_END = §8Finished
LOADER_MESSAGE_INTERACT=§e{0} added {1} LOADER_MESSAGE_INTERACT=§e{0} added {1}
LOADER_MESSAGE_UNINTERACT=§eRemoved Element
LOADER_BUTTON_TNT=TNT LOADER_BUTTON_TNT=TNT
LOADER_BUTTON_SWITCH=Lever LOADER_BUTTON_SWITCH=Lever
LOADER_BUTTON_WOOD_BUTTON=Wooden Button LOADER_BUTTON_WOOD_BUTTON=Wooden Button
@ -576,9 +577,11 @@ LOADER_PERMS=§cYou are not allowed to use the Loader here
LOADER_NOTHING_RECORDED=§cYou have not recorded anything yet! LOADER_NOTHING_RECORDED=§cYou have not recorded anything yet!
LOADER_GUI_TITLE=Loader GUI LOADER_GUI_TITLE=Loader GUI
LOADER_GUI_SHOW_INTERACTIONS=§eShow only Interactions LOADER_GUI_SHOW_ALL=Show all
LOADER_GUI_SHOW_WAITS=§eShow only Waits LOADER_GUI_SHOW_INTERACTIONS=Show only Interactions
LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time between TNT LOADER_GUI_SHOW_WAITS=Show only Waits
LOADER_GUI_SHOW_WAITS_BETWEEN_TNT=Show only Waits between TNT
LOADER_GUI_SHOW_TNT=Show TNT
LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time all
LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time LOADER_GUI_SHOW_WAITS_TITLE=§7Wait Time
LOADER_GUI_SETTINGS_TITLE=Settings LOADER_GUI_SETTINGS_TITLE=Settings
@ -608,6 +611,7 @@ LOADER_SETTING_TNT_X=§7X§8: §e{0}
LOADER_SETTING_TNT_Y=§7Y§8: §e{0} LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
LOADER_SETTING_TNT_Z=§7Z§8: §e{0} LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
LOADER_INTERACTION_NOOP=NOOP LOADER_INTERACTION_NOOP=NOOP
LOADER_INTERACTION_PLACE=Place
LOADER_INTERACTION_INTERACT=Interact LOADER_INTERACTION_INTERACT=Interact
LOADER_INTERACTION_POWERED=Powered LOADER_INTERACTION_POWERED=Powered
LOADER_INTERACTION_UNPOWERED=Unpowered LOADER_INTERACTION_UNPOWERED=Unpowered

Datei anzeigen

@ -544,9 +544,11 @@ LOADER_PERMS=§cDu darfst hier nicht den Detonator nutzen
LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen! LOADER_NOTHING_RECORDED=§cEs wurden keine Elemente aufgenommen!
LOADER_GUI_TITLE=Loader Einstellungen LOADER_GUI_TITLE=Loader Einstellungen
LOADER_GUI_SHOW_INTERACTIONS=§eZeige Interaktionen LOADER_GUI_SHOW_ALL=Zeige alles
LOADER_GUI_SHOW_WAITS=§eZeige Wartezeiten LOADER_GUI_SHOW_INTERACTIONS=Zeige Interaktionen
LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT=§7Wait Time zwischen TNT LOADER_GUI_SHOW_WAITS=Zeige Wartezeiten
LOADER_GUI_SHOW_WAITS_BETWEEN_TNT=Zeige Wartezeiten zwischen TNT
LOADER_GUI_SHOW_TNT=Zeige TNT
LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle LOADER_GUI_SHOW_WAITS_SET_ALL=§7Wait Time alle
LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit LOADER_GUI_SHOW_WAITS_TITLE=§7Wartezeit
LOADER_GUI_SETTINGS_TITLE=Einstellungen LOADER_GUI_SETTINGS_TITLE=Einstellungen
@ -576,6 +578,7 @@ LOADER_SETTING_TNT_X=§7X§8: §e{0}
LOADER_SETTING_TNT_Y=§7Y§8: §e{0} LOADER_SETTING_TNT_Y=§7Y§8: §e{0}
LOADER_SETTING_TNT_Z=§7Z§8: §e{0} LOADER_SETTING_TNT_Z=§7Z§8: §e{0}
LOADER_INTERACTION_NOOP=NOOP LOADER_INTERACTION_NOOP=NOOP
LOADER_INTERACTION_PLACE=Platzieren
LOADER_INTERACTION_INTERACT=Interagiere LOADER_INTERACTION_INTERACT=Interagiere
LOADER_INTERACTION_POWERED=Aktiviert LOADER_INTERACTION_POWERED=Aktiviert
LOADER_INTERACTION_UNPOWERED=Deaktiviert LOADER_INTERACTION_UNPOWERED=Deaktiviert

Datei anzeigen

@ -35,9 +35,11 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class Loader implements Listener { public class Loader implements Listener {
@ -124,25 +126,46 @@ 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<>();
AtomicBoolean allWait = new AtomicBoolean(true);
Runnable updateRunnable = () -> { Runnable updateRunnable = () -> {
list.clear(); list.clear();
for (LoaderElement element : elements) { for (int i = 0; i < elements.size(); i++) {
if (settingsSorting != null) { LoaderElement previous = i > 0 ? elements.get(i - 1) : null;
if (settingsSorting == SettingsSorting.WAIT && !(element instanceof LoaderWait)) { LoaderElement current = elements.get(i);
continue; LoaderElement next = i < elements.size() - 1 ? elements.get(i + 1) : null;
}
if (settingsSorting == SettingsSorting.INTERACTIONS && (element instanceof LoaderWait || element instanceof LoaderTNT)) { if (!settingsSorting.shouldShow(previous, current, next)) {
continue; continue;
}
} }
SWItem item = element.menu(p);
if (element instanceof LoaderInteractionElement<?>) { if ((!(current instanceof LoaderWait))) {
LoaderInteractionElement<?> interactionElement = (LoaderInteractionElement<?>) element; allWait.set(false);
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); }
SWItem item = current.menu(p);
if (current instanceof LoaderInteractionElement<?>) {
LoaderInteractionElement<?> interactionElement = (LoaderInteractionElement<?>) current;
List<String> lore = new ArrayList<>();
if (item.getItemMeta() != null && item.getItemMeta().getLore() != null) {
lore.addAll(item.getItemMeta().getLore());
lore.add("§8");
}
lore.add(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, interactionElement.size()));
lore.add(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p));
item.setLore(lore);
} else { } else {
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p))); List<String> lore = new ArrayList<>();
if (item.getItemMeta() != null && item.getItemMeta().getLore() != null) {
lore.addAll(item.getItemMeta().getLore());
lore.add("§8");
}
lore.add(BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", p));
item.setLore(lore);
} }
list.add(new SWListInv.SWListEntry<>(item, element)); list.add(new SWListInv.SWListEntry<>(item, current));
}
if (list.isEmpty()) {
allWait.set(false);
} }
}; };
updateRunnable.run(); updateRunnable.run();
@ -153,65 +176,51 @@ public class Loader implements Listener {
swListInv.open(); swListInv.open();
})); }));
SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_INTERACTIONS", p), clickType -> { SWItem settingItem = new SWItem(settingsSorting.getMaterial(), "§e" + BauSystem.MESSAGE.parse(settingsSorting.getName(), p), clickType -> {
gui(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS); if (clickType == ClickType.LEFT) {
int index = settingsSorting.ordinal() + 1;
if (index >= SettingsSorting.LENGTH) {
index = 0;
}
gui(SettingsSorting.values()[index]);
} else if (clickType == ClickType.RIGHT) {
int index = settingsSorting.ordinal() - 1;
if (index < 0) {
index = SettingsSorting.LENGTH - 1;
}
gui(SettingsSorting.values()[index]);
}
}); });
if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true); List<String> strings = new ArrayList<>();
swListInv.setItem(47, onlyInteractionsElements); for (SettingsSorting setting : SettingsSorting.values()) {
if (setting == settingsSorting) {
SWItem onlyWaitElements = new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS", p), clickType -> { strings.add("§e> §7" + BauSystem.MESSAGE.parse(setting.getName(), p));
gui(settingsSorting == SettingsSorting.WAIT ? null : SettingsSorting.WAIT); } else {
}); strings.add("§8> §7" + BauSystem.MESSAGE.parse(setting.getName(), p));
if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true); }
swListInv.setItem(48, onlyWaitElements);
if (settingsSorting == SettingsSorting.WAIT) {
SWItem waitBetweenTNT = new SWItem(Material.TNT, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_BETWEEN_TNT", p), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), "");
swAnvilInv.setCallback(s -> {
try {
long delay = Long.parseLong(s);
if (delay < 0) delay = 0;
for (int i = 1; i < elements.size() - 1; i++) {
if (!(elements.get(i - 1) instanceof LoaderTNT)) continue;
if (!(elements.get(i + 1) instanceof LoaderTNT)) continue;
if (!(elements.get(i) instanceof LoaderWait)) continue;
((LoaderWait) elements.get(i)).setDelay(delay);
}
} catch (NumberFormatException ignored) {
}
gui(settingsSorting);
});
updateRunnable.run();
swAnvilInv.open();
});
swListInv.setItem(50, waitBetweenTNT);
SWItem waitTime = new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_ALL", p), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), "");
swAnvilInv.setCallback(s -> {
try {
long delay = Long.parseLong(s);
if (delay < 0) delay = 0;
long finalDelay = delay;
elements.stream()
.filter(LoaderWait.class::isInstance)
.map(LoaderWait.class::cast)
.forEach(loaderWait -> loaderWait.setDelay(finalDelay));
} catch (NumberFormatException ignored) {
}
gui(settingsSorting);
});
updateRunnable.run();
swAnvilInv.open();
});
swListInv.setItem(51, waitTime);
} else {
SWItem empty = new SWItem(Material.STRUCTURE_VOID, "§7", clickType -> {});
swListInv.setItem(50, empty);
swListInv.setItem(51, empty);
} }
settingItem.setLore(strings);
swListInv.setItem(48, settingItem);
if (allWait.get()) {
SWItem setWait = new SWItem(Material.PAPER, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_SET_ALL", p), clickType -> {
SWAnvilInv swAnvilInv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("LOADER_GUI_SHOW_WAITS_TITLE", p), "");
swAnvilInv.setCallback(s -> {
try {
long delay = Math.max(Long.parseLong(s), 0);
list.forEach(loaderElementSWListEntry -> {
((LoaderWait) loaderElementSWListEntry.getObject()).setDelay(delay);
});
} catch (NumberFormatException ignored) {
}
gui(settingsSorting);
});
swAnvilInv.open();
});
swListInv.setItem(50, setWait);
} else {
swListInv.setItem(50, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§8"));
}
swListInv.open(); swListInv.open();
} }
@ -226,8 +235,93 @@ public class Loader implements Listener {
} }
public enum SettingsSorting { public enum SettingsSorting {
WAIT, ALL {
INTERACTIONS, @Override
public Material getMaterial() {
return Material.STRUCTURE_VOID;
}
@Override
public String getName() {
return "LOADER_GUI_SHOW_ALL";
}
@Override
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
return true;
}
},
WAIT {
@Override
public Material getMaterial() {
return Material.CLOCK;
}
@Override
public String getName() {
return "LOADER_GUI_SHOW_WAITS";
}
@Override
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
return current instanceof LoaderWait;
}
},
WAIT_BETWEEN_TNT {
@Override
public Material getMaterial() {
return Material.REDSTONE_BLOCK;
}
@Override
public String getName() {
return "LOADER_GUI_SHOW_WAITS_BETWEEN_TNT";
}
@Override
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
return previous instanceof LoaderTNT && current instanceof LoaderWait && next instanceof LoaderTNT;
}
},
INTERACTIONS {
@Override
public Material getMaterial() {
return Material.REPEATER;
}
@Override
public String getName() {
return "LOADER_GUI_SHOW_INTERACTIONS";
}
@Override
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
return current instanceof LoaderInteractionElement && !(current instanceof LoaderTNT);
}
},
TNT {
@Override
public Material getMaterial() {
return Material.TNT;
}
@Override
public String getName() {
return "LOADER_GUI_SHOW_TNT";
}
@Override
public boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next) {
return current instanceof LoaderTNT;
}
},
;
public static int LENGTH = SettingsSorting.values().length;
public abstract Material getMaterial();
public abstract String getName();
public abstract boolean shouldShow(LoaderElement previous, LoaderElement current, LoaderElement next);
} }
@AllArgsConstructor @AllArgsConstructor

Datei anzeigen

@ -80,7 +80,7 @@ public class LoaderCommand extends SWCommand {
public void guiLoader(@Validator Player player) { public void guiLoader(@Validator Player player) {
Loader loader = Loader.getLoader(player); Loader loader = Loader.getLoader(player);
if (loaderNullCheck(loader, player)) return; if (loaderNullCheck(loader, player)) return;
loader.gui(null); loader.gui(Loader.SettingsSorting.ALL);
} }
@ClassValidator(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.loader;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.bausystem.features.loader.elements.LoaderElement;
import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.bausystem.features.loader.elements.impl.*; import de.steamwar.bausystem.features.loader.elements.impl.*;
import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -33,6 +34,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
@ -86,7 +88,30 @@ public class LoaderRecorder implements Listener {
} }
@EventHandler @EventHandler
public void onPlayerInteractEntity(PlayerInteractEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (event.getPlayer() != player) return;
if (event.getBlock().getType() != Material.TNT) {
event.setCancelled(true);
}
for (int i = 0; i < loaderElementList.size(); i++) {
LoaderElement element = loaderElementList.get(i);
if (!(element instanceof LoaderInteractionElement)) continue;
LoaderInteractionElement interactionElement = (LoaderInteractionElement) element;
if (interactionElement.getLocation().equals(event.getBlock().getLocation())) {
loaderElementList.remove(i);
if (i > 0) {
loaderElementList.remove(i - 1);
}
break;
}
}
SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("LOADER_MESSAGE_UNINTERACT", player));
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getPlayer() != player) return; if (event.getPlayer() != player) return;
if (player.isSneaking()) return; if (player.isSneaking()) return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) return;

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -40,6 +41,7 @@ import java.util.function.Consumer;
public abstract class LoaderInteractionElement<T extends Enum<T> & LoaderSettingsEnum> implements LoaderElement { public abstract class LoaderInteractionElement<T extends Enum<T> & LoaderSettingsEnum> implements LoaderElement {
@Getter
protected final Location location; protected final Location location;
protected int currentShot = 0; protected int currentShot = 0;
protected T defaultSetting; protected T defaultSetting;

Datei anzeigen

@ -20,22 +20,57 @@
package de.steamwar.bausystem.features.loader.elements.impl; package de.steamwar.bausystem.features.loader.elements.impl;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.loader.elements.LoaderElement; import de.steamwar.bausystem.features.loader.elements.LoaderInteractionElement;
import de.steamwar.bausystem.features.loader.elements.LoaderSettingsEnum;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.Arrays;
import java.util.function.Consumer; import java.util.function.Consumer;
public class LoaderTNT implements LoaderElement { public class LoaderTNT extends LoaderInteractionElement<LoaderTNT.TNTSettingsEnum> {
private Location location;
public LoaderTNT(Location location) { public LoaderTNT(Location location) {
this.location = location; super(location, TNTSettingsEnum.PLACE, TNTSettingsEnum.NOOP, TNTSettingsEnum.values());
}
public enum TNTSettingsEnum implements LoaderSettingsEnum<BlockData, LoaderTNT, TNTSettingsEnum> {
NOOP {
@Override
public int getPos() {
return 2;
}
@Override
public SWItem menu(Player player, LoaderTNT parent, int power, long ticks) {
return new SWItem(Material.STRUCTURE_VOID, translateItemName("LOADER_BUTTON_TNT", "LOADER_INTERACTION_NOOP", player));
}
@Override
public void execute(Location location, BlockData blockData, LoaderTNT parent, int power, long ticks, Consumer<Long> delay) {
}
},
PLACE {
@Override
public int getPos() {
return 3;
}
@Override
public SWItem menu(Player player, LoaderTNT parent, int power, long ticks) {
return new SWItem(Material.TNT, translateItemName("LOADER_BUTTON_TNT", "LOADER_INTERACTION_PLACE", player));
}
@Override
public void execute(Location location, BlockData blockData, LoaderTNT parent, int power, long ticks, Consumer<Long> delay) {
location.getBlock().setType(Material.TNT);
}
}
} }
@Override @Override
@ -53,10 +88,11 @@ public class LoaderTNT implements LoaderElement {
return; return;
} }
block.setType(Material.TNT); super.execute(delay);
} }
@Override @Override
public void click(Player player, Runnable backAction) { public boolean checkBlockInWorld() {
return true;
} }
} }