SteamWar/MissileWars
Archiviert
13
0

Update2.0 #22

Manuell gemergt
YoyoNow hat 32 Commits von Update2.0 nach master 2020-12-20 13:52:31 +01:00 zusammengeführt
7 geänderte Dateien mit 19 neuen und 19 gelöschten Zeilen
Nur Änderungen aus Commit cb3e1d5c71 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -19,10 +19,17 @@
package de.steamwar.misslewars.scripts; package de.steamwar.misslewars.scripts;
import java.util.function.UnaryOperator;
public interface RunnableScript { public interface RunnableScript {
boolean execute(RunnableScriptEvent runnableScriptEvent); boolean execute(RunnableScriptEvent runnableScriptEvent);
interface ScriptFunction { interface ScriptFunction {
boolean execute(RunnableScriptEvent runnableScriptEvent, double... doubles); boolean execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
} }
default boolean defaultExecution(ScriptFunction scriptFunction, boolean nullReturn, UnaryOperator<Boolean> returnValue, RunnableScriptEvent runnableScriptEvent, double... doubles) {
if (scriptFunction == null) return nullReturn;
return returnValue.apply(scriptFunction.execute(runnableScriptEvent, doubles));
}
} }

Datei anzeigen

@ -64,8 +64,7 @@ public class Script {
} }
private static RunnableScript parseScriptSnippet(JsonObject jsonObject) { private static RunnableScript parseScriptSnippet(JsonObject jsonObject) {
if (!jsonObject.has("type")) if (!jsonObject.has("type")) return null;
return null;
switch (jsonObject.getAsJsonPrimitive("type").getAsString().toLowerCase()) { switch (jsonObject.getAsJsonPrimitive("type").getAsString().toLowerCase()) {
case "delay": case "delay":
return new DelayScript(jsonObject); return new DelayScript(jsonObject);

Datei anzeigen

@ -62,8 +62,7 @@ public class FilterScript implements RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (filter == null) return true; return defaultExecution(filter, true, b -> b ^ inverted, runnableScriptEvent);
return filter.execute(runnableScriptEvent) ^ inverted;
} }
} }

Datei anzeigen

@ -44,10 +44,8 @@ public class LaunchScript implements RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (launch == null) return false;
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true; if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
launch.execute(runnableScriptEvent); return defaultExecution(launch, false, b -> true, runnableScriptEvent);
return true;
} }
} }

Datei anzeigen

@ -83,8 +83,7 @@ public class LocationScript implements RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
runnableScriptEvent.setLocationType(locationType); runnableScriptEvent.setLocationType(locationType);
if (locationExecutor != null) locationExecutor.execute(runnableScriptEvent, x, y, z); return defaultExecution(locationExecutor, true, b -> true, runnableScriptEvent, x, y, z);
return true;
} }
} }

Datei anzeigen

@ -23,9 +23,10 @@ import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript; import de.steamwar.misslewars.scripts.RunnableScript;
import de.steamwar.misslewars.scripts.RunnableScriptEvent; import de.steamwar.misslewars.scripts.RunnableScriptEvent;
import de.steamwar.misslewars.scripts.ScriptedItem; import de.steamwar.misslewars.scripts.ScriptedItem;
import de.steamwar.misslewars.scripts.utils.JsonUtils;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getFloat;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
public class SoundScript implements RunnableScript { public class SoundScript implements RunnableScript {
@ -34,17 +35,16 @@ public class SoundScript implements RunnableScript {
private float pitch; private float pitch;
public SoundScript(JsonObject sound) { public SoundScript(JsonObject sound) {
JsonUtils.getString(sound, "sound", value -> this.sound = Sound.valueOf(value)); getString(sound, "sound", value -> this.sound = Sound.valueOf(value));
volume = JsonUtils.getFloat(sound, "volume", 100); volume = getFloat(sound, "volume", 100);
pitch = JsonUtils.getFloat(sound, "pitch", 1); pitch = getFloat(sound, "pitch", 1);
} }
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (sound == null) return false; if (sound == null) return false;
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true; if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
Player player = runnableScriptEvent.getPlayer(); runnableScriptEvent.getPlayer().playSound(runnableScriptEvent.getPlayer().getLocation(), sound, volume, pitch);
player.playSound(player.getLocation(), sound, volume, pitch);
return true; return true;
} }

Datei anzeigen

@ -43,9 +43,7 @@ public class SummonScript implements RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (summon == null) return false; return defaultExecution(summon, false, b -> true, runnableScriptEvent);
summon.execute(runnableScriptEvent);
return true;
} }
} }