Hotfix Loader Bau slowdowns and crashes
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
5f7f11bf87
Commit
27798df7ce
@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.loader;
|
||||
|
||||
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.impl.LoaderTNT;
|
||||
import de.steamwar.bausystem.features.loader.elements.impl.LoaderWait;
|
||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||
@ -58,31 +59,32 @@ public class Loader implements Listener {
|
||||
|
||||
private List<LoaderElement> elements = new ArrayList<>();
|
||||
private int currentElement = 0;
|
||||
private long totalDelay = 0;
|
||||
private long waitTime = 0;
|
||||
|
||||
public Loader(Player p) {
|
||||
this.p = p;
|
||||
this.recorder = new LoaderRecorder(p, elements);
|
||||
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
|
||||
}
|
||||
|
||||
private void next() {
|
||||
currentElement++;
|
||||
if (currentElement >= elements.size()) {
|
||||
currentElement = 0;
|
||||
if (totalDelay == 0) {
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), this::next, 1);
|
||||
BauSystem.runTaskTimer(BauSystem.getInstance(), () -> {
|
||||
if (stage != Stage.RUNNING) return;
|
||||
if (waitTime > 0) {
|
||||
waitTime--;
|
||||
return;
|
||||
}
|
||||
totalDelay = 0;
|
||||
}
|
||||
if (stage == Stage.RUNNING) {
|
||||
LoaderElement element = elements.get(currentElement);
|
||||
if (element instanceof LoaderWait) {
|
||||
totalDelay += ((LoaderWait) element).getDelay();
|
||||
|
||||
while (currentElement < elements.size()) {
|
||||
LoaderElement element = elements.get(currentElement);
|
||||
currentElement++;
|
||||
element.execute(delay -> waitTime = delay);
|
||||
if (waitTime > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
element.execute(this::next);
|
||||
}
|
||||
if (currentElement >= elements.size()) {
|
||||
currentElement = 0;
|
||||
}
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@ -96,9 +98,7 @@ public class Loader implements Listener {
|
||||
if (elements.isEmpty()) {
|
||||
BauSystem.MESSAGE.send("LOADER_NOTHING_RECORDED", p);
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
elements.get(currentElement).execute(this::next);
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
@ -133,7 +133,12 @@ public class Loader implements Listener {
|
||||
}
|
||||
}
|
||||
SWItem item = element.menu(p);
|
||||
item.setLore(Arrays.asList(BauSystem.MESSAGE.parse("LOADER_SETTING_MODES", p, elements.size()), "§8", BauSystem.MESSAGE.parse("LOADER_GUI_CLICK_TO_EDIT", 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));
|
||||
}
|
||||
SWListInv<LoaderElement> swListInv = new SWListInv<>(p, BauSystem.MESSAGE.parse("LOADER_GUI_TITLE", p), false, list, (clickType, loaderElement) -> {});
|
||||
|
@ -23,9 +23,11 @@ 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(Runnable nextAction);
|
||||
void execute(Consumer<Long> delay);
|
||||
void click(Player player, Runnable backAction, Runnable deleteAction);
|
||||
|
||||
default void playerInteract() {}
|
||||
|
@ -22,8 +22,10 @@ package de.steamwar.bausystem.features.loader.elements;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface LoaderElement {
|
||||
SWItem menu(Player player);
|
||||
void execute(Runnable nextAction);
|
||||
void execute(Consumer<Long> delay);
|
||||
void click(Player player, Runnable backAction);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class LoaderInteractionElement<T extends ElementSettings> implements LoaderElement {
|
||||
|
||||
@ -49,9 +50,9 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (currentShot >= elements.size()) currentShot = 0;
|
||||
elements.get(currentShot).execute(nextAction);
|
||||
elements.get(currentShot).execute(delay);
|
||||
currentShot++;
|
||||
if (currentShot >= elements.size()) currentShot = 0;
|
||||
}
|
||||
@ -122,4 +123,8 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
||||
protected final String translateItemName(String name, Player player) {
|
||||
return BauSystem.MESSAGE.parse("LOADER_SETTING_NAME", player, BauSystem.MESSAGE.parse(name, player));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return elements.size();
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ 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> {
|
||||
|
||||
@ -62,8 +63,7 @@ public class LoaderComparator extends LoaderInteractionElement<LoaderComparator.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != Material.COMPARATOR) return;
|
||||
Comparator comparator = (Comparator) location.getBlock().getBlockData();
|
||||
if (interact) {
|
||||
|
@ -31,6 +31,7 @@ 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> {
|
||||
|
||||
@ -64,8 +65,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDayli
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != Material.DAYLIGHT_DETECTOR) return;
|
||||
DaylightDetector daylightDetector = (DaylightDetector) location.getBlock().getBlockData();
|
||||
if (noop) {
|
||||
|
@ -32,6 +32,7 @@ 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> {
|
||||
|
||||
@ -68,8 +69,7 @@ public class LoaderLectern extends LoaderInteractionElement<LoaderLectern.Lecter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != Material.LECTERN) return;
|
||||
Lectern lectern = (Lectern) location.getBlock().getState();
|
||||
if (!((org.bukkit.block.data.type.Lectern) lectern.getBlockData()).hasBook()) return;
|
||||
|
@ -31,6 +31,7 @@ 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> {
|
||||
|
||||
@ -63,8 +64,7 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != Material.LEVER) return;
|
||||
if (noop) return;
|
||||
|
||||
|
@ -35,6 +35,7 @@ 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> {
|
||||
|
||||
@ -83,15 +84,9 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
if (!(material == Material.STRING && location.getBlock().getType() == Material.TRIPWIRE) && location.getBlock().getType() != material) {
|
||||
nextAction.run();
|
||||
return;
|
||||
}
|
||||
if (noop) {
|
||||
nextAction.run();
|
||||
return;
|
||||
}
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (!(material == Material.STRING && location.getBlock().getType() == Material.TRIPWIRE) && location.getBlock().getType() != material) return;
|
||||
if (noop) return;
|
||||
|
||||
BlockData blockData = location.getBlock().getBlockData();
|
||||
if (blockData instanceof AnaloguePowerable) {
|
||||
@ -111,7 +106,9 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
||||
}
|
||||
|
||||
if (ticks >= 0) {
|
||||
boolean finalWaitFor = waitFor;
|
||||
if (waitFor) {
|
||||
delay.accept(ticks);
|
||||
}
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
||||
if (blockData instanceof AnaloguePowerable) {
|
||||
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
|
||||
@ -124,13 +121,7 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
||||
location.getBlock().setBlockData(powerable, true);
|
||||
update(powerable);
|
||||
}
|
||||
if (finalWaitFor) {
|
||||
nextAction.run();
|
||||
}
|
||||
}, ticks);
|
||||
if (!finalWaitFor) {
|
||||
nextAction.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ 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> {
|
||||
|
||||
@ -60,8 +61,7 @@ public class LoaderNoteBlock extends LoaderInteractionElement<LoaderNoteBlock.No
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != Material.NOTE_BLOCK) return;
|
||||
NoteBlock noteBlock = (NoteBlock) location.getBlock().getBlockData();
|
||||
if (interact) {
|
||||
|
@ -31,6 +31,7 @@ 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> {
|
||||
|
||||
@ -68,8 +69,7 @@ public class LoaderOpenable extends LoaderInteractionElement<LoaderOpenable.Trap
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != material) return;
|
||||
Openable openable = (Openable) location.getBlock().getBlockData();
|
||||
if (noop) {
|
||||
|
@ -31,6 +31,7 @@ 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> {
|
||||
|
||||
@ -63,8 +64,7 @@ public class LoaderRepeater extends LoaderInteractionElement<LoaderRepeater.Repe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
nextAction.run();
|
||||
public void execute(Consumer<Long> __) {
|
||||
if (location.getBlock().getType() != Material.REPEATER) return;
|
||||
Repeater repeater = (Repeater) location.getBlock().getBlockData();
|
||||
if (interact) {
|
||||
|
@ -29,6 +29,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LoaderTNT implements LoaderElement {
|
||||
|
||||
@ -46,15 +47,14 @@ public class LoaderTNT implements LoaderElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
public void execute(Consumer<Long> delay) {
|
||||
Block block = location.getBlock();
|
||||
if (block.getType() != Material.AIR && block.getType() != Material.WATER) {
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> execute(nextAction), 1);
|
||||
delay.accept(1L);
|
||||
return;
|
||||
}
|
||||
|
||||
block.setType(Material.TNT, true);
|
||||
nextAction.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +32,7 @@ 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> {
|
||||
|
||||
@ -71,13 +72,11 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
public void execute(Consumer<Long> delay) {
|
||||
if (location.getBlock().getType() != material) {
|
||||
nextAction.run();
|
||||
return;
|
||||
}
|
||||
if (noop) {
|
||||
nextAction.run();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -86,18 +85,14 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
||||
location.getBlock().setBlockData(powerable, true);
|
||||
update(powerable);
|
||||
|
||||
boolean finalWaitFor = waitFor;
|
||||
if (waitFor) {
|
||||
delay.accept((long) ticks);
|
||||
}
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), () -> {
|
||||
powerable.setPowered(false);
|
||||
location.getBlock().setBlockData(powerable, true);
|
||||
update(powerable);
|
||||
if (finalWaitFor) {
|
||||
nextAction.run();
|
||||
}
|
||||
}, ticks);
|
||||
if (!finalWaitFor) {
|
||||
nextAction.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +32,7 @@ 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 {
|
||||
|
||||
@ -53,12 +54,8 @@ public class LoaderWait implements LoaderElement, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable nextAction) {
|
||||
if (delay == 0) {
|
||||
nextAction.run();
|
||||
return;
|
||||
}
|
||||
BauSystem.runTaskLater(BauSystem.getInstance(), nextAction, delay);
|
||||
public void execute(Consumer<Long> __) {
|
||||
__.accept(delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren