SteamWar/BauSystem2.0
Archiviert
12
0

Update Loader and fix many things
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-05-01 18:00:54 +02:00
Ursprung 792f16fadf
Commit b1dcd6d57b
8 geänderte Dateien mit 62 neuen und 77 gelöschten Zeilen

Datei anzeigen

@ -60,6 +60,7 @@ public class Loader implements Listener {
private List<LoaderElement> elements = new ArrayList<>();
private int currentElement = 0;
private long totalDelay = 0;
public Loader(Player p) {
this.p = p;
@ -71,9 +72,18 @@ public class Loader implements Listener {
currentElement++;
if (currentElement >= elements.size()) {
currentElement = 0;
if (totalDelay == 0) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1);
return;
}
totalDelay = 0;
}
if (stage == Stage.RUNNING) {
elements.get(currentElement).execute(this::next);
LoaderElement element = elements.get(currentElement);
if (element instanceof LoaderWait) {
totalDelay += ((LoaderWait) element).getDelay();
}
element.execute(this::next);
}
}
@ -136,7 +146,7 @@ public class Loader implements Listener {
if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true);
swListInv.setItem(48, onlyWaitElements);
SWItem onlyInteractionsElements = new SWItem(Material.TNT, "§eNur Interaktionen", clickType -> {
SWItem onlyInteractionsElements = new SWItem(Material.REPEATER, "§eNur Interaktionen", clickType -> {
settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS);
});
if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true);
@ -151,6 +161,10 @@ public class Loader implements Listener {
stop();
}
public String getProgress() {
return "§7" + (currentElement + 1) + "§8/§7" + elements.size();
}
public enum SettingsSorting {
WAIT,
INTERACTIONS,

Datei anzeigen

@ -42,6 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement {
public String get(Region region, Player p) {
Loader loader = Loader.getLoader(p);
if (loader == null) return null;
if (loader.getStage() == Loader.Stage.RUNNING || loader.getStage() == Loader.Stage.PAUSE) {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p) + " §8(" + loader.getProgress() + "§8)";
} else {
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p);
}
}
}

Datei anzeigen

@ -86,10 +86,12 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
listInv.open();
}
protected void update(Block block) {
Material material = block.getType();
if (block.getBlockData() instanceof Switch) {
Switch sw = (Switch) block.getBlockData();
protected void update(BlockData blockData) {
Material material = blockData.getMaterial();
Block block = location.getBlock();
if (blockData instanceof Switch) {
Switch sw = (Switch) blockData;
updateBlock(block, sw);
FaceAttachable.AttachedFace face = sw.getAttachedFace();
if (face == FaceAttachable.AttachedFace.FLOOR) {
updateBlock(block.getRelative(BlockFace.DOWN));
@ -99,14 +101,17 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
updateBlock(block.getRelative(sw.getFacing().getOppositeFace()));
}
} else if (material == Material.TRIPWIRE) {
updateBlock(block);
updateBlock(block, blockData);
} else if (material.name().endsWith("_PLATE")) {
updateBlock(block.getRelative(BlockFace.DOWN));
}
}
protected void updateBlock(Block block) {
BlockData data = block.getBlockData();
updateBlock(block, block.getBlockData());
}
protected void updateBlock(Block block, BlockData data) {
block.setType(Material.BARRIER, true);
block.setBlockData(data, true);
}

Datei anzeigen

@ -76,7 +76,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDayli
}
daylightDetector.setPower(daylightDetector.isInverted() ? 15 - power : power);
location.getBlock().setBlockData(daylightDetector);
update(location.getBlock().getRelative(0, -1, 0));
updateBlock(location.getBlock().getRelative(0, -1, 0));
}
@Override

Datei anzeigen

@ -73,7 +73,7 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
} else {
lever.setPowered(power);
}
location.getBlock().setBlockData(lever);
location.getBlock().setBlockData(lever, true);
}
@Override

Datei anzeigen

@ -57,8 +57,8 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
public class MovementSettings implements ElementSettings {
private boolean noop = false;
private boolean waitFor = true;
private int power = 0;
private boolean waitFor = false;
private int power = 15;
private long ticks = 1;
@Override
@ -97,6 +97,7 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
if (blockData instanceof AnaloguePowerable) {
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
analoguePowerable.setPower(power);
location.getBlock().setBlockData(analoguePowerable, true);
} else if (blockData instanceof Powerable) {
Powerable powerable = (Powerable) location.getBlock().getBlockData();
if (ticks < 0) {
@ -104,20 +105,21 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
} else {
powerable.setPowered(true);
}
location.getBlock().setBlockData(powerable, true);
}
location.getBlock().setBlockData(blockData);
update(location.getBlock());
if (ticks >= 0) {
boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
if (blockData instanceof AnaloguePowerable) {
((AnaloguePowerable) blockData).setPower(0);
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
analoguePowerable.setPower(0);
location.getBlock().setBlockData(analoguePowerable, true);
} else {
((Powerable) blockData).setPowered(false);
Powerable powerable = (Powerable) blockData;
powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true);
}
location.getBlock().setBlockData(blockData);
update(location.getBlock());
if (finalWaitFor) {
nextAction.run();
}

Datei anzeigen

@ -27,8 +27,6 @@ import de.steamwar.inventory.SWItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.AnaloguePowerable;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Powerable;
import org.bukkit.entity.Player;
@ -39,22 +37,19 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
private String name;
private Material material;
private boolean analogue;
private int ticks;
public LoaderTicks(Location location, String name, Material material, int ticks) {
super(location);
this.name = name;
this.material = material;
this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable;
this.ticks = ticks;
}
public class TicksSettings implements ElementSettings {
private boolean noop = false;
private boolean waitFor = true;
private int power = 0;
private boolean waitFor = false;
@Override
public SWItem menu(Player player) {
@ -86,31 +81,14 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
return;
}
BlockData blockData = location.getBlock().getBlockData();
if (blockData instanceof AnaloguePowerable) {
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
analoguePowerable.setPower(power);
} else if (blockData instanceof Powerable) {
Powerable powerable = (Powerable) location.getBlock().getBlockData();
if (ticks < 0) {
powerable.setPowered(power > 0);
} else {
powerable.setPowered(true);
}
}
location.getBlock().setBlockData(powerable, true);
location.getBlock().setBlockData(blockData);
update(location.getBlock());
if (ticks >= 0) {
boolean finalWaitFor = waitFor;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
if (blockData instanceof AnaloguePowerable) {
((AnaloguePowerable) blockData).setPower(0);
} else {
((Powerable) blockData).setPowered(false);
}
location.getBlock().setBlockData(blockData);
update(location.getBlock());
powerable.setPowered(false);
location.getBlock().setBlockData(powerable, true);
if (finalWaitFor) {
nextAction.run();
}
@ -119,14 +97,13 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
nextAction.run();
}
}
}
@Override
public void click(Player player, Runnable backAction, Runnable deleteAction) {
SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings");
for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(analogue ? 27 : 9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run());
swInventory.setItem(analogue ? 35 : 17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run());
SWInventory swInventory = new SWInventory(player, 18, "Settings");
for (int i = 9; i < 18; i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
swInventory.setItem(9, new SWItem(Material.ARROW, "§8Back").getItemStack(), clickType -> backAction.run());
swInventory.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run());
swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> {
noop = true;
@ -145,18 +122,6 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
});
}
if (analogue) {
for (int i = 0; i < 16; i++) {
int finalI = i;
int finalI2 = i;
if (i >= 9) finalI2++;
swInventory.setItem(finalI2 + 9, item(player, finalI).getItemStack(), clickType -> {
power = finalI;
click(player, backAction, deleteAction);
});
}
}
swInventory.open();
}
@ -168,13 +133,6 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
swItem.setLore(Collections.emptyList());
return swItem;
}
private SWItem item(Player player, int power) {
SWItem swItem = new SWItem(power == 0 ? Material.GUNPOWDER : Material.REDSTONE, "§7Power §8:§e " + power);
swItem.getItemStack().setAmount(power == 0 ? 1 : power);
if (!this.noop && this.power == power) swItem.setEnchanted(true);
return swItem;
}
}
@Override

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.loadern.elements.LoaderElement;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -33,6 +34,7 @@ import java.util.Arrays;
public class LoaderWait implements LoaderElement, Listener {
@Getter
private long delay;
public LoaderWait(long delay) {