Update2.0 #22
@ -37,6 +37,7 @@ public class RunnableScriptEvent {
|
||||
private final Location location;
|
||||
private Location customLocation;
|
||||
private LocationType locationType = LocationType.DEFAULT;
|
||||
Script.ScriptExecutor scriptExecutor = null;
|
||||
|
||||
public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) {
|
||||
this.eventType = eventType;
|
||||
@ -73,4 +74,9 @@ public class RunnableScriptEvent {
|
||||
return (Player) entity;
|
||||
}
|
||||
|
||||
public void resumeScriptExecution() {
|
||||
if (scriptExecutor == null) return;
|
||||
scriptExecutor.resume();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ package de.steamwar.misslewars.scripts;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.implemented.*;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -32,27 +30,20 @@ public class Script {
|
||||
|
||||
private List<RunnableScript> runnableScriptList = new ArrayList<>();
|
||||
|
||||
private class ScriptExecutor {
|
||||
class ScriptExecutor {
|
||||
|
||||
private int index = 0;
|
||||
private final RunnableScriptEvent runnableScriptEvent;
|
||||
|
||||
public ScriptExecutor(RunnableScriptEvent runnableScriptEvent) {
|
||||
this.runnableScriptEvent = runnableScriptEvent;
|
||||
runnableScriptEvent.scriptExecutor = this;
|
||||
resume();
|
||||
}
|
||||
|
||||
private void resume() {
|
||||
void resume() {
|
||||
while (index < runnableScriptList.size()) {
|
||||
RunnableScript runnableScript = runnableScriptList.get(index++);
|
||||
if (runnableScript instanceof DelayScript) {
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::resume, ((DelayScript) runnableScript).getDelayTime());
|
||||
return;
|
||||
}
|
||||
if (!runnableScript.execute(runnableScriptEvent)) {
|
||||
index = runnableScriptList.size();
|
||||
return;
|
||||
}
|
||||
if (!runnableScriptList.get(index++).execute(runnableScriptEvent)) return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,8 +22,11 @@ package de.steamwar.misslewars.scripts.implemented;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -53,11 +56,8 @@ public class DelayScript implements RunnableScript {
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getDelayTime() {
|
||||
return delayTime;
|
||||
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), runnableScriptEvent::resumeScriptExecution, delayTime);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,9 +83,7 @@ public class LocationScript implements RunnableScript {
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
runnableScriptEvent.setLocationType(locationType);
|
||||
if (locationExecutor != null) {
|
||||
locationExecutor.execute(runnableScriptEvent, x, y, z);
|
||||
}
|
||||
if (locationExecutor != null) locationExecutor.execute(runnableScriptEvent, x, y, z);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Wäre hier nicht eher eine For oder Foreach Schleife angebracht.
?
Nein weil sie auch abgebrochen werden kann mit dem Delay und danach wieder angefangen wird. Somit ist beides keine Option.