Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
792f16fadf
Commit
b1dcd6d57b
@ -60,6 +60,7 @@ public class Loader implements Listener {
|
|||||||
|
|
||||||
private List<LoaderElement> elements = new ArrayList<>();
|
private List<LoaderElement> elements = new ArrayList<>();
|
||||||
private int currentElement = 0;
|
private int currentElement = 0;
|
||||||
|
private long totalDelay = 0;
|
||||||
|
|
||||||
public Loader(Player p) {
|
public Loader(Player p) {
|
||||||
this.p = p;
|
this.p = p;
|
||||||
@ -71,9 +72,18 @@ public class Loader implements Listener {
|
|||||||
currentElement++;
|
currentElement++;
|
||||||
if (currentElement >= elements.size()) {
|
if (currentElement >= elements.size()) {
|
||||||
currentElement = 0;
|
currentElement = 0;
|
||||||
|
if (totalDelay == 0) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), this::next, 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
totalDelay = 0;
|
||||||
}
|
}
|
||||||
if (stage == Stage.RUNNING) {
|
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);
|
if (settingsSorting == SettingsSorting.WAIT) onlyWaitElements.setEnchanted(true);
|
||||||
swListInv.setItem(48, onlyWaitElements);
|
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);
|
settings(settingsSorting == SettingsSorting.INTERACTIONS ? null : SettingsSorting.INTERACTIONS);
|
||||||
});
|
});
|
||||||
if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true);
|
if (settingsSorting == SettingsSorting.INTERACTIONS) onlyInteractionsElements.setEnchanted(true);
|
||||||
@ -151,6 +161,10 @@ public class Loader implements Listener {
|
|||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProgress() {
|
||||||
|
return "§7" + (currentElement + 1) + "§8/§7" + elements.size();
|
||||||
|
}
|
||||||
|
|
||||||
public enum SettingsSorting {
|
public enum SettingsSorting {
|
||||||
WAIT,
|
WAIT,
|
||||||
INTERACTIONS,
|
INTERACTIONS,
|
||||||
|
@ -42,6 +42,10 @@ public class LoaderScoreboardElement implements ScoreboardElement {
|
|||||||
public String get(Region region, Player p) {
|
public String get(Region region, Player p) {
|
||||||
Loader loader = Loader.getLoader(p);
|
Loader loader = Loader.getLoader(p);
|
||||||
if (loader == null) return null;
|
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);
|
return "§e" + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader.getStage().getChatValue(), p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,10 +86,12 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
|||||||
listInv.open();
|
listInv.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void update(Block block) {
|
protected void update(BlockData blockData) {
|
||||||
Material material = block.getType();
|
Material material = blockData.getMaterial();
|
||||||
if (block.getBlockData() instanceof Switch) {
|
Block block = location.getBlock();
|
||||||
Switch sw = (Switch) block.getBlockData();
|
if (blockData instanceof Switch) {
|
||||||
|
Switch sw = (Switch) blockData;
|
||||||
|
updateBlock(block, sw);
|
||||||
FaceAttachable.AttachedFace face = sw.getAttachedFace();
|
FaceAttachable.AttachedFace face = sw.getAttachedFace();
|
||||||
if (face == FaceAttachable.AttachedFace.FLOOR) {
|
if (face == FaceAttachable.AttachedFace.FLOOR) {
|
||||||
updateBlock(block.getRelative(BlockFace.DOWN));
|
updateBlock(block.getRelative(BlockFace.DOWN));
|
||||||
@ -99,14 +101,17 @@ public abstract class LoaderInteractionElement<T extends ElementSettings> implem
|
|||||||
updateBlock(block.getRelative(sw.getFacing().getOppositeFace()));
|
updateBlock(block.getRelative(sw.getFacing().getOppositeFace()));
|
||||||
}
|
}
|
||||||
} else if (material == Material.TRIPWIRE) {
|
} else if (material == Material.TRIPWIRE) {
|
||||||
updateBlock(block);
|
updateBlock(block, blockData);
|
||||||
} else if (material.name().endsWith("_PLATE")) {
|
} else if (material.name().endsWith("_PLATE")) {
|
||||||
updateBlock(block.getRelative(BlockFace.DOWN));
|
updateBlock(block.getRelative(BlockFace.DOWN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateBlock(Block block) {
|
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.setType(Material.BARRIER, true);
|
||||||
block.setBlockData(data, true);
|
block.setBlockData(data, true);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class LoaderDaylightDetector extends LoaderInteractionElement<LoaderDayli
|
|||||||
}
|
}
|
||||||
daylightDetector.setPower(daylightDetector.isInverted() ? 15 - power : power);
|
daylightDetector.setPower(daylightDetector.isInverted() ? 15 - power : power);
|
||||||
location.getBlock().setBlockData(daylightDetector);
|
location.getBlock().setBlockData(daylightDetector);
|
||||||
update(location.getBlock().getRelative(0, -1, 0));
|
updateBlock(location.getBlock().getRelative(0, -1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,7 +73,7 @@ public class LoaderLever extends LoaderInteractionElement<LoaderLever.LeverSetti
|
|||||||
} else {
|
} else {
|
||||||
lever.setPowered(power);
|
lever.setPowered(power);
|
||||||
}
|
}
|
||||||
location.getBlock().setBlockData(lever);
|
location.getBlock().setBlockData(lever, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,8 +57,8 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
|||||||
public class MovementSettings implements ElementSettings {
|
public class MovementSettings implements ElementSettings {
|
||||||
|
|
||||||
private boolean noop = false;
|
private boolean noop = false;
|
||||||
private boolean waitFor = true;
|
private boolean waitFor = false;
|
||||||
private int power = 0;
|
private int power = 15;
|
||||||
private long ticks = 1;
|
private long ticks = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,6 +97,7 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
|||||||
if (blockData instanceof AnaloguePowerable) {
|
if (blockData instanceof AnaloguePowerable) {
|
||||||
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
|
AnaloguePowerable analoguePowerable = (AnaloguePowerable) location.getBlock().getBlockData();
|
||||||
analoguePowerable.setPower(power);
|
analoguePowerable.setPower(power);
|
||||||
|
location.getBlock().setBlockData(analoguePowerable, true);
|
||||||
} else if (blockData instanceof Powerable) {
|
} else if (blockData instanceof Powerable) {
|
||||||
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
||||||
if (ticks < 0) {
|
if (ticks < 0) {
|
||||||
@ -104,20 +105,21 @@ public class LoaderMovement extends LoaderInteractionElement<LoaderMovement.Move
|
|||||||
} else {
|
} else {
|
||||||
powerable.setPowered(true);
|
powerable.setPowered(true);
|
||||||
}
|
}
|
||||||
|
location.getBlock().setBlockData(powerable, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
location.getBlock().setBlockData(blockData);
|
|
||||||
update(location.getBlock());
|
|
||||||
if (ticks >= 0) {
|
if (ticks >= 0) {
|
||||||
boolean finalWaitFor = waitFor;
|
boolean finalWaitFor = waitFor;
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
if (blockData instanceof AnaloguePowerable) {
|
if (blockData instanceof AnaloguePowerable) {
|
||||||
((AnaloguePowerable) blockData).setPower(0);
|
AnaloguePowerable analoguePowerable = (AnaloguePowerable) blockData;
|
||||||
|
analoguePowerable.setPower(0);
|
||||||
|
location.getBlock().setBlockData(analoguePowerable, true);
|
||||||
} else {
|
} 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) {
|
if (finalWaitFor) {
|
||||||
nextAction.run();
|
nextAction.run();
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,6 @@ import de.steamwar.inventory.SWItem;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
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.block.data.Powerable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -39,22 +37,19 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private Material material;
|
private Material material;
|
||||||
private boolean analogue;
|
|
||||||
private int ticks;
|
private int ticks;
|
||||||
|
|
||||||
public LoaderTicks(Location location, String name, Material material, int ticks) {
|
public LoaderTicks(Location location, String name, Material material, int ticks) {
|
||||||
super(location);
|
super(location);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
this.analogue = location.getBlock().getBlockData() instanceof AnaloguePowerable;
|
|
||||||
this.ticks = ticks;
|
this.ticks = ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TicksSettings implements ElementSettings {
|
public class TicksSettings implements ElementSettings {
|
||||||
|
|
||||||
private boolean noop = false;
|
private boolean noop = false;
|
||||||
private boolean waitFor = true;
|
private boolean waitFor = false;
|
||||||
private int power = 0;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SWItem menu(Player player) {
|
public SWItem menu(Player player) {
|
||||||
@ -86,31 +81,14 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
|||||||
return;
|
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();
|
Powerable powerable = (Powerable) location.getBlock().getBlockData();
|
||||||
if (ticks < 0) {
|
|
||||||
powerable.setPowered(power > 0);
|
|
||||||
} else {
|
|
||||||
powerable.setPowered(true);
|
powerable.setPowered(true);
|
||||||
}
|
location.getBlock().setBlockData(powerable, true);
|
||||||
}
|
|
||||||
|
|
||||||
location.getBlock().setBlockData(blockData);
|
|
||||||
update(location.getBlock());
|
|
||||||
if (ticks >= 0) {
|
|
||||||
boolean finalWaitFor = waitFor;
|
boolean finalWaitFor = waitFor;
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
if (blockData instanceof AnaloguePowerable) {
|
powerable.setPowered(false);
|
||||||
((AnaloguePowerable) blockData).setPower(0);
|
location.getBlock().setBlockData(powerable, true);
|
||||||
} else {
|
|
||||||
((Powerable) blockData).setPowered(false);
|
|
||||||
}
|
|
||||||
location.getBlock().setBlockData(blockData);
|
|
||||||
update(location.getBlock());
|
|
||||||
if (finalWaitFor) {
|
if (finalWaitFor) {
|
||||||
nextAction.run();
|
nextAction.run();
|
||||||
}
|
}
|
||||||
@ -119,14 +97,13 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
|||||||
nextAction.run();
|
nextAction.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
public void click(Player player, Runnable backAction, Runnable deleteAction) {
|
||||||
SWInventory swInventory = new SWInventory(player, analogue ? 36 : 18, "Settings");
|
SWInventory swInventory = new SWInventory(player, 18, "Settings");
|
||||||
for (int i = analogue ? 27 : 9; i < (analogue ? 35 : 18); i++) swInventory.setItem(i, new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7"));
|
for (int i = 9; i < 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(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.setItem(17, new SWItem(Material.BARRIER, "§cDelete").getItemStack(), clickType -> deleteAction.run());
|
||||||
|
|
||||||
swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> {
|
swInventory.setItem(2, item(player, true, false).getItemStack(), clickType -> {
|
||||||
noop = true;
|
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();
|
swInventory.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,13 +133,6 @@ public class LoaderTicks extends LoaderInteractionElement<LoaderTicks.TicksSetti
|
|||||||
swItem.setLore(Collections.emptyList());
|
swItem.setLore(Collections.emptyList());
|
||||||
return swItem;
|
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
|
@Override
|
||||||
|
@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.loadern.elements.LoaderElement;
|
|||||||
import de.steamwar.inventory.SWAnvilInv;
|
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 lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -33,6 +34,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class LoaderWait implements LoaderElement, Listener {
|
public class LoaderWait implements LoaderElement, Listener {
|
||||||
|
|
||||||
|
@Getter
|
||||||
private long delay;
|
private long delay;
|
||||||
|
|
||||||
public LoaderWait(long delay) {
|
public LoaderWait(long delay) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren