Optimize CodeStyle
Dieser Commit ist enthalten in:
Ursprung
c15f4a90dc
Commit
cb3e1d5c71
@ -19,10 +19,17 @@
|
||||
|
||||
package de.steamwar.misslewars.scripts;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public interface RunnableScript {
|
||||
boolean execute(RunnableScriptEvent runnableScriptEvent);
|
||||
|
||||
interface ScriptFunction {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -64,8 +64,7 @@ public class Script {
|
||||
}
|
||||
|
||||
private static RunnableScript parseScriptSnippet(JsonObject jsonObject) {
|
||||
if (!jsonObject.has("type"))
|
||||
return null;
|
||||
if (!jsonObject.has("type")) return null;
|
||||
switch (jsonObject.getAsJsonPrimitive("type").getAsString().toLowerCase()) {
|
||||
case "delay":
|
||||
return new DelayScript(jsonObject);
|
||||
|
@ -62,8 +62,7 @@ public class FilterScript implements RunnableScript {
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (filter == null) return true;
|
||||
return filter.execute(runnableScriptEvent) ^ inverted;
|
||||
return defaultExecution(filter, true, b -> b ^ inverted, runnableScriptEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,10 +44,8 @@ public class LaunchScript implements RunnableScript {
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (launch == null) return false;
|
||||
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
|
||||
launch.execute(runnableScriptEvent);
|
||||
return true;
|
||||
return defaultExecution(launch, false, b -> true, runnableScriptEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,8 +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);
|
||||
return true;
|
||||
return defaultExecution(locationExecutor, true, b -> true, runnableScriptEvent, x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,9 +23,10 @@ import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.scripts.ScriptedItem;
|
||||
import de.steamwar.misslewars.scripts.utils.JsonUtils;
|
||||
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 {
|
||||
|
||||
@ -34,17 +35,16 @@ public class SoundScript implements RunnableScript {
|
||||
private float pitch;
|
||||
|
||||
public SoundScript(JsonObject sound) {
|
||||
JsonUtils.getString(sound, "sound", value -> this.sound = Sound.valueOf(value));
|
||||
volume = JsonUtils.getFloat(sound, "volume", 100);
|
||||
pitch = JsonUtils.getFloat(sound, "pitch", 1);
|
||||
getString(sound, "sound", value -> this.sound = Sound.valueOf(value));
|
||||
volume = getFloat(sound, "volume", 100);
|
||||
pitch = getFloat(sound, "pitch", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (sound == null) return false;
|
||||
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
|
||||
Player player = runnableScriptEvent.getPlayer();
|
||||
player.playSound(player.getLocation(), sound, volume, pitch);
|
||||
runnableScriptEvent.getPlayer().playSound(runnableScriptEvent.getPlayer().getLocation(), sound, volume, pitch);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -43,9 +43,7 @@ public class SummonScript implements RunnableScript {
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (summon == null) return false;
|
||||
summon.execute(runnableScriptEvent);
|
||||
return true;
|
||||
return defaultExecution(summon, false, b -> true, runnableScriptEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren