Minor DT Stuff and Fixes in Loader
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
10b5d9d3c1
Commit
47e6a8bbcd
@ -32,6 +32,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -48,9 +49,11 @@ public class Loader implements Listener {
|
||||
private final List<AbstractLoaderActivation> actions = new LinkedList<>();
|
||||
private final BukkitTask task;
|
||||
@Getter
|
||||
private final int ticksBetweenShots = 80;
|
||||
@Setter
|
||||
private int ticksBetweenShots = 80;
|
||||
@Getter
|
||||
private final int ticksBetweenBlocks = 1;
|
||||
@Setter
|
||||
private int ticksBetweenBlocks = 1;
|
||||
@Getter
|
||||
private Stage stage;
|
||||
@Getter
|
||||
@ -84,16 +87,16 @@ public class Loader implements Listener {
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
if (stage == Stage.PAUSE) {
|
||||
resume();
|
||||
return;
|
||||
}
|
||||
if (stage == Stage.RUNNING) {
|
||||
stage = Stage.PAUSE;
|
||||
}
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
if (stage == Stage.PAUSE) {
|
||||
stage = Stage.RUNNING;
|
||||
}
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
stage = Stage.SETUP;
|
||||
@ -109,7 +112,12 @@ public class Loader implements Listener {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (stage == Stage.SETUP) {
|
||||
actions.clear();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Loader gecleart");
|
||||
} else {
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Du must im Setup-Modus sein um den Loader zu clearen");
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@ -132,15 +140,21 @@ public class Loader implements Listener {
|
||||
|
||||
current = iterator.next();
|
||||
|
||||
try {
|
||||
current.execute();
|
||||
if (current.execute()) {
|
||||
countdown = current.delay(this);
|
||||
} catch (Exception e) {
|
||||
pause();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Ein Fehler beim ausführen ist passiert, Autoloader wurde pausiert.");
|
||||
} else {
|
||||
countdown = 1;
|
||||
iterator.previous();
|
||||
}
|
||||
}
|
||||
|
||||
public void undo() {
|
||||
if (actions.isEmpty() || stage != Stage.SETUP) {
|
||||
return;
|
||||
}
|
||||
actions.remove(actions.size() - 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.getPlayer() != p) {
|
||||
@ -169,8 +183,15 @@ public class Loader implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (LoaderButton.fromBlock(event.getClickedBlock()) != LoaderButton.INVALID) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL)
|
||||
return;
|
||||
if (event.getClickedBlock().getType() == Material.OBSERVER)
|
||||
return;
|
||||
LoaderButton button = LoaderButton.fromBlock(event.getClickedBlock());
|
||||
if (button != LoaderButton.INVALID) {
|
||||
actions.add(InteractionActivation.construct(p, event.getClickedBlock().getLocation(), this));
|
||||
lastActivation = 0;
|
||||
SWUtils.sendToActionbar(p, ColorConfig.HIGHLIGHT + button.getName() + " hinzugefügt " + actions.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,16 @@ public class LoaderCommand extends SWCommand {
|
||||
|
||||
@Register(help = true)
|
||||
public void genericHelp(Player p, String... args) {
|
||||
p.sendMessage("@Help@");
|
||||
p.sendMessage(ColorConfig.BASE + "---=== (" + ColorConfig.HIGHLIGHT + "Loader" + ColorConfig.BASE + ") ===---");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "loader setup " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Startet die Aufnahme der Aktionen");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader undo " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Entfernt die zuletzt aufgenommene Aktion");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "loader start " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Spielt die zuvor aufgenommenen Aktionen ab");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader wait " + ColorConfig.OTHER + "[" + ColorConfig.BASE + "Ticks" + ColorConfig.OTHER + "] - " + ColorConfig.BASE + "Setzt die Wartezeit zwischen Schüssen");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader speed " + ColorConfig.OTHER + "[" + ColorConfig.BASE + "Ticks" + ColorConfig.OTHER + "] - " + ColorConfig.BASE + "Setzt die Wartezeit zwischen Aktionen");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader pause " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Pausiert das Abspielen");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.BASE + "loader resume " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Spielt den Loader weiter ab");
|
||||
p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "loader stop " + ColorConfig.OTHER + "- " + ColorConfig.BASE + "Stoppt die Aufnahme bzw. das Abspielen");
|
||||
p.sendMessage(ColorConfig.BASE + "Der Loader arbeitet mit " + ColorConfig.HIGHLIGHT + "Ingame" + ColorConfig.OTHER + "-" + ColorConfig.HIGHLIGHT + "Ticks " + ColorConfig.OTHER + "(20 Ticks pro Sekunde)");
|
||||
}
|
||||
|
||||
private boolean loaderNullCheck(Loader loader, Player p) {
|
||||
@ -51,28 +60,98 @@ public class LoaderCommand extends SWCommand {
|
||||
public void setupLoader(Player p) {
|
||||
if (Loader.getLoader(p) != null) {
|
||||
Loader.getLoader(p).setup();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Dein Loader ist nun wieder im Setup");
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Dein Loader ist nun wieder im Setup");
|
||||
} else {
|
||||
Loader.newLoader(p);
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren.");
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Belade und feuer einmal die Kanone ab, um den Loader zu initialisieren.");
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Führe dann /" + ColorConfig.HIGHLIGHT + "loader start" + ColorConfig.BASE + " um den Loader zu starten");
|
||||
}
|
||||
}
|
||||
|
||||
@Register("start")
|
||||
public void startLoader(Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p))
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
loader.start();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Der Loader ist nun aktiviert.");
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader ist nun aktiviert.");
|
||||
}
|
||||
|
||||
@Register("stop")
|
||||
public void stopLoader(Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p))
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
loader.stop();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.HIGHLIGHT + "Der Loader ist nun gestoppt.");
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader ist nun gestoppt.");
|
||||
}
|
||||
|
||||
@Register("pause")
|
||||
public void pauseLoader(Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
loader.pause();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader ist nun pausiert.");
|
||||
}
|
||||
|
||||
@Register("resume")
|
||||
public void resumeLoader(Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
loader.resume();
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Der Loader läuft nun weiter.");
|
||||
}
|
||||
|
||||
@Register("wait")
|
||||
public void shotDelayLoader(Player p, int delay) {
|
||||
if (delay < 1) {
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Die Wartezeit ist zu klein");
|
||||
return;
|
||||
}
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Die Schusswartezeit ist nun: " + delay + ", zuvor " + loader.getTicksBetweenShots());
|
||||
loader.setTicksBetweenShots(delay);
|
||||
}
|
||||
|
||||
@Register("speed")
|
||||
public void speedLoader(Player p, int delay) {
|
||||
if (delay < 1) {
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.ERROR + "Die Wartezeit ist zu klein");
|
||||
return;
|
||||
}
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "die Setzwartezeit ist nun: " + delay + ", zuvor " + loader.getTicksBetweenBlocks());
|
||||
loader.setTicksBetweenShots(delay);
|
||||
}
|
||||
|
||||
@Register("undo")
|
||||
public void undoLast(Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
p.sendMessage(BauSystem.PREFIX + ColorConfig.BASE + "Undo erfolgreich.");
|
||||
loader.undo();
|
||||
}
|
||||
|
||||
@Register("clear")
|
||||
public void clearLoader(Player p) {
|
||||
Loader loader = Loader.getLoader(p);
|
||||
if (loaderNullCheck(loader, p)) {
|
||||
return;
|
||||
}
|
||||
loader.clear();
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public abstract class AbstractLoaderActivation {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
public abstract boolean execute();
|
||||
|
||||
public abstract int delay(Loader loader);
|
||||
}
|
||||
|
@ -40,13 +40,14 @@ public class BlockPlaceLoaderActivation extends AbstractLoaderActivation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
public boolean execute() {
|
||||
Block currBlock = location.getBlock();
|
||||
if (currBlock.getType() != Material.AIR && currBlock.getType() != Material.WATER) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
currBlock.setType(material, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,11 +131,14 @@ public abstract class InteractionActivation extends AbstractLoaderActivation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
public boolean execute() {
|
||||
if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID)
|
||||
return false;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
setBlockPower(getBlockPower());
|
||||
setBlockPower(!getBlockPower());
|
||||
updateButton();
|
||||
}, delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,13 +154,16 @@ public abstract class InteractionActivation extends AbstractLoaderActivation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
public boolean execute() {
|
||||
if (LoaderButton.fromBlock(location.getBlock()) == LoaderButton.INVALID)
|
||||
return false;
|
||||
setBlockPower(true);
|
||||
updateButton();
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
setBlockPower(getBlockPower());
|
||||
setBlockPower(false);
|
||||
updateButton();
|
||||
}, button.getTime());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren