Improve Code Style
Dieser Commit ist enthalten in:
Ursprung
828406220f
Commit
c720e463f9
@ -21,6 +21,6 @@ package de.steamwar.misslewars.scripts.function;
|
||||
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
|
||||
public interface ScriptVoidFunction {
|
||||
void execute(RunnableScriptEvent runnableScriptEvent);
|
||||
public interface ScriptDoubleFunction {
|
||||
boolean execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
|
||||
}
|
@ -21,6 +21,6 @@ package de.steamwar.misslewars.scripts.function;
|
||||
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
|
||||
public interface ScriptBooleanFunction {
|
||||
public interface ScriptFunction {
|
||||
boolean execute(RunnableScriptEvent runnableScriptEvent);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
This file is a part of the SteamWar software.
|
||||
|
||||
Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.misslewars.scripts.function;
|
||||
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
|
||||
public interface ScriptVoidDoubleFunction {
|
||||
void execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
|
||||
}
|
@ -30,7 +30,7 @@ import java.util.Map;
|
||||
|
||||
public class DelayScript extends RunnableScript {
|
||||
|
||||
private static Map<String, Integer> delayMap = new HashMap<>();
|
||||
private static final Map<String, Integer> delayMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
delayMap.put("config.mineflytime", Config.ShieldFlyTime);
|
||||
|
@ -23,17 +23,19 @@ import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptBooleanFunction;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptFunction;
|
||||
import de.steamwar.misslewars.scripts.utils.JsonUtils;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
|
||||
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
|
||||
|
||||
public class FilterScript extends RunnableScript {
|
||||
|
||||
private static Map<String, ScriptBooleanFunction> filterMap = new HashMap<>();
|
||||
private static final Map<String, ScriptFunction> filterMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
filterMap.put("nearportal", runnableScriptEvent -> {
|
||||
@ -52,12 +54,12 @@ public class FilterScript extends RunnableScript {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean inverted = false;
|
||||
private ScriptBooleanFunction filter;
|
||||
private boolean inverted;
|
||||
private ScriptFunction filter;
|
||||
|
||||
public FilterScript(JsonObject filter) {
|
||||
this.filter = filterMap.getOrDefault(getString(filter, "filter", "").toLowerCase(), null);
|
||||
if (filter.has("invert")) inverted = filter.getAsJsonPrimitive("invert").getAsBoolean();
|
||||
inverted = getBoolean(filter, "invert", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,42 +23,26 @@ 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.function.ScriptVoidFunction;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptFunction;
|
||||
import de.steamwar.misslewars.scripts.utils.EntityUtils;
|
||||
import de.steamwar.misslewars.scripts.utils.ScriptShortcut;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.Projectile;
|
||||
|
||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setFireballOptions;
|
||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setProjectileOptions;
|
||||
|
||||
public class LaunchScript extends RunnableScript {
|
||||
|
||||
private ScriptVoidFunction launch = null;
|
||||
private ScriptFunction launch = null;
|
||||
|
||||
public LaunchScript(JsonObject launch) {
|
||||
ScriptShortcut<Projectile> scriptShortcut = getEntity(launch.getAsJsonPrimitive("entity").getAsString());
|
||||
ScriptShortcut<Projectile> scriptShortcut = EntityUtils.getEntity(launch.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Projectile);
|
||||
if (scriptShortcut == null) return;
|
||||
|
||||
this.launch = runnableScriptEvent -> {
|
||||
Projectile projectile = runnableScriptEvent.getPlayer().launchProjectile(scriptShortcut.entityClass);
|
||||
scriptShortcut.consumer.accept(launch, projectile, runnableScriptEvent);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
private ScriptShortcut getEntity(String name) {
|
||||
switch (name.toLowerCase()) {
|
||||
case "fireball":
|
||||
return new ScriptShortcut<>(Fireball.class, (jsonObject, entity, runnableScriptEvent) -> {
|
||||
setFireballOptions(entity, jsonObject);
|
||||
entity.setDirection(runnableScriptEvent.getLocation().getDirection());
|
||||
});
|
||||
case "arrow":
|
||||
return new ScriptShortcut<>(Arrow.class, (jsonObject, entity, runnableScriptEvent) -> setProjectileOptions(entity, jsonObject));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (launch == null) return false;
|
||||
|
@ -23,19 +23,20 @@ import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.LocationType;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptVoidDoubleFunction;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptDoubleFunction;
|
||||
import de.steamwar.misslewars.scripts.utils.JsonUtils;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getDouble;
|
||||
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
|
||||
|
||||
public class LocationScript extends RunnableScript {
|
||||
|
||||
private static Map<String, LocationType> locationTypeMap = new HashMap<>();
|
||||
private static Map<String, ScriptVoidDoubleFunction> locationMap = new HashMap<>();
|
||||
private static final Map<String, LocationType> locationTypeMap = new HashMap<>();
|
||||
private static final Map<String, ScriptDoubleFunction> locationMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
locationTypeMap.put("static", LocationType.STATIC);
|
||||
@ -44,31 +45,36 @@ public class LocationScript extends RunnableScript {
|
||||
locationTypeMap.put("default", LocationType.DEFAULT);
|
||||
|
||||
locationMap.put("offsetentity", (runnableScriptEvent, doubles) -> {
|
||||
if (runnableScriptEvent.entity == null) return;
|
||||
if (runnableScriptEvent.entity == null) return false;
|
||||
Location location1 = runnableScriptEvent.entity.getLocation();
|
||||
runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2]);
|
||||
return false;
|
||||
});
|
||||
locationMap.put("offsetlocation", (runnableScriptEvent, doubles) -> {
|
||||
Location location1 = runnableScriptEvent.getLocation();
|
||||
runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2]);
|
||||
return false;
|
||||
});
|
||||
ScriptVoidDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]);
|
||||
locationMap.put("absolut", absoluteLocation);
|
||||
ScriptDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> {
|
||||
runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]);
|
||||
return false;
|
||||
};
|
||||
locationMap.put("absolute", absoluteLocation);
|
||||
locationMap.put("fix", absoluteLocation);
|
||||
locationMap.put("fixed", absoluteLocation);
|
||||
}
|
||||
|
||||
private LocationType locationType = null;
|
||||
private ScriptVoidDoubleFunction locationExecutor = null;
|
||||
private ScriptDoubleFunction locationExecutor = null;
|
||||
|
||||
private double x, y, z = 0;
|
||||
|
||||
public LocationScript(JsonObject location) {
|
||||
if (location.has("location")) {
|
||||
JsonObject jsonObject = location.getAsJsonObject("location");
|
||||
JsonUtils.getDouble(jsonObject, "x", value -> x = value);
|
||||
JsonUtils.getDouble(jsonObject, "y", value -> y = value);
|
||||
JsonUtils.getDouble(jsonObject, "z", value -> z = value);
|
||||
getDouble(jsonObject, "x", value -> x = value);
|
||||
getDouble(jsonObject, "y", value -> y = value);
|
||||
getDouble(jsonObject, "z", value -> z = value);
|
||||
locationExecutor = locationMap.getOrDefault(getString(jsonObject, "type", "").toLowerCase(), null);
|
||||
locationType = LocationType.CUSTOM;
|
||||
} else if (location.has("locationType")) {
|
||||
|
@ -41,8 +41,7 @@ public class PotionScript extends RunnableScript {
|
||||
boolean icon = getBoolean(potion, "icon", true);
|
||||
|
||||
PotionEffectType potionEffectType = PotionEffectType.getByName(potion.getAsJsonPrimitive("potion").getAsString());
|
||||
if (potionEffectType == null)
|
||||
return;
|
||||
if (potionEffectType == null) return;
|
||||
potionEffect = new PotionEffect(potionEffectType, duration, amplifier, ambient, particles, icon);
|
||||
}
|
||||
|
||||
|
@ -22,35 +22,26 @@ package de.steamwar.misslewars.scripts.implemented;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptVoidFunction;
|
||||
import de.steamwar.misslewars.scripts.function.ScriptFunction;
|
||||
import de.steamwar.misslewars.scripts.utils.EntityUtils;
|
||||
import de.steamwar.misslewars.scripts.utils.ScriptShortcut;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setTNTPrimedOptions;
|
||||
|
||||
public class SummonScript extends RunnableScript {
|
||||
|
||||
private ScriptVoidFunction summon = null;
|
||||
private ScriptFunction summon = null;
|
||||
|
||||
public SummonScript(JsonObject summon) {
|
||||
ScriptShortcut<Entity> scriptShortcut = getEntity(summon.getAsJsonPrimitive("entity").getAsString());
|
||||
ScriptShortcut<Entity> scriptShortcut = EntityUtils.getEntity(summon.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Normal);
|
||||
if (scriptShortcut == null) return;
|
||||
|
||||
this.summon = runnableScriptEvent -> {
|
||||
Entity entity = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), scriptShortcut.entityClass);
|
||||
scriptShortcut.consumer.accept(summon, entity, runnableScriptEvent);
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
private ScriptShortcut getEntity(String name) {
|
||||
switch (name.toLowerCase()) {
|
||||
case "tntprimed":
|
||||
return new ScriptShortcut<>(TNTPrimed.class, (jsonObject, entity, runnableScriptEvent) -> setTNTPrimedOptions(entity, jsonObject));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (summon == null) return false;
|
||||
|
@ -57,4 +57,26 @@ public class EntityUtils {
|
||||
setExplosiveOptions(tntPrimed, jsonObject);
|
||||
}
|
||||
|
||||
public enum EntityType {
|
||||
Projectile,
|
||||
Normal
|
||||
}
|
||||
|
||||
public static ScriptShortcut getEntity(String name, EntityType entityType) {
|
||||
switch (name.toLowerCase()) {
|
||||
case "tntprimed":
|
||||
if (entityType != EntityType.Normal) return null;
|
||||
return new ScriptShortcut<>(TNTPrimed.class, (jsonObject, entity, runnableScriptEvent) -> setTNTPrimedOptions(entity, jsonObject));
|
||||
|
||||
case "fireball":
|
||||
return new ScriptShortcut<>(Fireball.class, (jsonObject, entity, runnableScriptEvent) -> {
|
||||
setFireballOptions(entity, jsonObject);
|
||||
entity.setDirection(runnableScriptEvent.getLocation().getDirection());
|
||||
});
|
||||
case "arrow":
|
||||
return new ScriptShortcut<>(Arrow.class, (jsonObject, entity, runnableScriptEvent) -> setProjectileOptions(entity, jsonObject));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren