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
21 geänderte Dateien mit 95 neuen und 200 gelöschten Zeilen
Nur Änderungen aus Commit 01a422f96d werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -1,27 +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;
public enum LocationType {
STATIC,
DYNAMIC,
DEFAULT,
CUSTOM
}

Datei anzeigen

@ -19,6 +19,6 @@
package de.steamwar.misslewars.scripts; package de.steamwar.misslewars.scripts;
public abstract class RunnableScript { public interface RunnableScript {
public abstract boolean execute(RunnableScriptEvent runnableScriptEvent); boolean execute(RunnableScriptEvent runnableScriptEvent);
} }

Datei anzeigen

@ -25,6 +25,13 @@ import org.bukkit.entity.Player;
public class RunnableScriptEvent { public class RunnableScriptEvent {
public enum LocationType {
STATIC,
DYNAMIC,
DEFAULT,
CUSTOM
}
public final ScriptedItem.EventType eventType; public final ScriptedItem.EventType eventType;
public final Entity entity; public final Entity entity;
private final Location location; private final Location location;
@ -61,10 +68,6 @@ public class RunnableScriptEvent {
this.locationType = locationType; this.locationType = locationType;
} }
public void setCustomLocation(double x, double y, double z) {
setCustomLocation(x, y, z, 0, 0);
}
public void setCustomLocation(double x, double y, double z, float pitch, float yaw) { public void setCustomLocation(double x, double y, double z, float pitch, float yaw) {
this.customLocation = new Location(location.getWorld(), x, y, z, yaw, pitch); this.customLocation = new Location(location.getWorld(), x, y, z, yaw, pitch);
} }

Datei anzeigen

@ -62,16 +62,12 @@ public class Script {
new ScriptExecutor(runnableScriptEvent); new ScriptExecutor(runnableScriptEvent);
} }
private void add(RunnableScript runnableScript) {
runnableScriptList.add(runnableScript);
}
public static Script parseScript(JsonArray jsonArray) { public static Script parseScript(JsonArray jsonArray) {
Script script = new Script(); Script script = new Script();
jsonArray.forEach(jsonElement -> { jsonArray.forEach(jsonElement -> {
RunnableScript runnableScript = parseScriptSnippet((JsonObject) jsonElement); RunnableScript runnableScript = parseScriptSnippet((JsonObject) jsonElement);
if (runnableScript == null) return; if (runnableScript == null) return;
script.add(runnableScript); script.runnableScriptList.add(runnableScript);
}); });
return script; return script;
} }

Datei anzeigen

@ -0,0 +1,26 @@
/*
*
* 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;
public interface ScriptFunction {
boolean execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.misslewars.scripts; package de.steamwar.misslewars.scripts;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
Review

Unnötiger Import

Unnötiger Import
import de.steamwar.misslewars.scripts.utils.JsonUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -31,6 +32,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
public class ScriptedItem { public class ScriptedItem {
// "type": Material name (STRING) // "type": Material name (STRING)
@ -43,27 +46,20 @@ public class ScriptedItem {
// - onThrow // - onThrow
Review

Warum werden dieser String Parameter benötigt, und kann man das nicht name() machen?

Warum werden dieser String Parameter benötigt, und kann man das nicht ```name()``` machen?
Review

kann man, aber der Enum name muss nicht mit dem Event Namen übereinstimmen

kann man, aber der Enum name muss nicht mit dem Event Namen übereinstimmen
Review

Tut es doch jetzt schon.

Tut es doch jetzt schon.
public enum EventType { public enum EventType {
onHit("onHit"), onHit,
onThrow("onThrow"), onThrow,
onClick("onClick"); onClick
String name;
EventType(String name) {
this.name = name;
}
} }
private Map<EventType, Script> scriptMap = new HashMap<>(); private Map<EventType, Script> scriptMap = new HashMap<>();
private String entityName = "---"; private String entityName = "";
private ItemStack itemStack; private ItemStack itemStack;
public ScriptedItem(JsonObject jsonObject) { public ScriptedItem(JsonObject jsonObject) {
itemStack = createItemStack(jsonObject); itemStack = createItemStack(jsonObject);
if (jsonObject.has("entityName")) getString(jsonObject, "entityName", string -> entityName = string);
entityName = jsonObject.get("entityName").getAsString();
for (EventType eventType : EventType.values()) { for (EventType eventType : EventType.values()) {
String eventString = "EVENT." + eventType.name(); String eventString = "EVENT." + eventType.name();
@ -72,11 +68,11 @@ public class ScriptedItem {
} }
} }
private ItemStack createItemStack(JsonObject jsonObject) { private static ItemStack createItemStack(JsonObject jsonObject) {
ItemStack itemStack = new ItemStack(Material.valueOf(jsonObject.getAsJsonPrimitive("type").getAsString()), jsonObject.getAsJsonPrimitive("amount").getAsInt()); ItemStack itemStack = new ItemStack(Material.valueOf(getString(jsonObject, "type", "")), JsonUtils.getInt(jsonObject, "amount", 1));
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) return itemStack; if (itemMeta == null) return itemStack;
itemMeta.setDisplayName(jsonObject.getAsJsonPrimitive("name").getAsString()); getString(jsonObject, "name", itemMeta::setDisplayName);
if (jsonObject.has("lore")) { if (jsonObject.has("lore")) {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();

Datei anzeigen

@ -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 ScriptDoubleFunction {
boolean execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
}

Datei anzeigen

@ -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 ScriptFunction {
boolean execute(RunnableScriptEvent runnableScriptEvent);
}

Datei anzeigen

@ -28,7 +28,7 @@ import de.steamwar.misslewars.scripts.RunnableScriptEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class DelayScript extends RunnableScript { public class DelayScript implements RunnableScript {
private static final Map<String, Integer> delayMap = new HashMap<>(); private static final Map<String, Integer> delayMap = new HashMap<>();

Datei anzeigen

@ -23,8 +23,7 @@ import com.google.gson.JsonObject;
import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.MissileWars;
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.function.ScriptFunction; import de.steamwar.misslewars.scripts.ScriptFunction;
import de.steamwar.misslewars.scripts.utils.JsonUtils;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.HashMap; import java.util.HashMap;
@ -33,12 +32,12 @@ import java.util.Map;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
public class FilterScript extends RunnableScript { public class FilterScript implements RunnableScript {
private static final Map<String, ScriptFunction> filterMap = new HashMap<>(); private static final Map<String, ScriptFunction> filterMap = new HashMap<>();
static { static {
filterMap.put("nearportal", runnableScriptEvent -> { filterMap.put("nearportal", (runnableScriptEvent, doubles) -> {
Location location = runnableScriptEvent.getLocation(); Location location = runnableScriptEvent.getLocation();
int bz = MissileWars.getBlueTeam().getPortalZ(); int bz = MissileWars.getBlueTeam().getPortalZ();
int rz = MissileWars.getRedTeam().getPortalZ(); int rz = MissileWars.getRedTeam().getPortalZ();
@ -48,7 +47,7 @@ public class FilterScript extends RunnableScript {
if (offset > 0) return (blockZ > bz - offset) || (blockZ < rz + offset); if (offset > 0) return (blockZ > bz - offset) || (blockZ < rz + offset);
else return (blockZ < bz - offset) || (blockZ > rz + offset); else return (blockZ < bz - offset) || (blockZ > rz + offset);
}); });
filterMap.put("nearspawn", runnableScriptEvent -> { filterMap.put("nearspawn", (runnableScriptEvent, doubles) -> {
Location location = runnableScriptEvent.getLocation(); Location location = runnableScriptEvent.getLocation();
return MissileWars.getBlueTeam().getSpawn().distance(location) < 3 || MissileWars.getRedTeam().getSpawn().distance(location) < 3; return MissileWars.getBlueTeam().getSpawn().distance(location) < 3 || MissileWars.getRedTeam().getSpawn().distance(location) < 3;
Review

If Else oder ||?

If Else oder ||?
}); });
@ -65,8 +64,7 @@ public class FilterScript extends RunnableScript {
@Override @Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) { public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (filter == null) return true; if (filter == null) return true;
if (inverted) return !filter.execute(runnableScriptEvent); return filter.execute(runnableScriptEvent) ^ inverted;
else return filter.execute(runnableScriptEvent);
} }
} }

Datei anzeigen

@ -23,12 +23,12 @@ 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.function.ScriptFunction; import de.steamwar.misslewars.scripts.ScriptFunction;
import de.steamwar.misslewars.scripts.utils.EntityUtils; import de.steamwar.misslewars.scripts.utils.EntityUtils;
import de.steamwar.misslewars.scripts.utils.ScriptShortcut; import de.steamwar.misslewars.scripts.utils.EntityUtils.ScriptShortcut;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
public class LaunchScript extends RunnableScript { public class LaunchScript implements RunnableScript {
private ScriptFunction launch = null; private ScriptFunction launch = null;
@ -36,7 +36,7 @@ public class LaunchScript extends RunnableScript {
ScriptShortcut<Projectile> scriptShortcut = EntityUtils.getEntity(launch.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Projectile); ScriptShortcut<Projectile> scriptShortcut = EntityUtils.getEntity(launch.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Projectile);
if (scriptShortcut == null) return; if (scriptShortcut == null) return;
this.launch = runnableScriptEvent -> { this.launch = (runnableScriptEvent, doubles) -> {
Projectile projectile = runnableScriptEvent.getPlayer().launchProjectile(scriptShortcut.entityClass); Projectile projectile = runnableScriptEvent.getPlayer().launchProjectile(scriptShortcut.entityClass);
scriptShortcut.consumer.accept(launch, projectile, runnableScriptEvent); scriptShortcut.consumer.accept(launch, projectile, runnableScriptEvent);
return false; return false;

Datei anzeigen

@ -20,11 +20,10 @@
package de.steamwar.misslewars.scripts.implemented; package de.steamwar.misslewars.scripts.implemented;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.LocationType;
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.function.ScriptDoubleFunction; import de.steamwar.misslewars.scripts.RunnableScriptEvent.LocationType;
import de.steamwar.misslewars.scripts.utils.JsonUtils; import de.steamwar.misslewars.scripts.ScriptFunction;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.HashMap; import java.util.HashMap;
@ -33,10 +32,10 @@ import java.util.Map;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getDouble; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getDouble;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getString;
public class LocationScript extends RunnableScript { public class LocationScript implements RunnableScript {
private static final Map<String, LocationType> locationTypeMap = new HashMap<>(); private static final Map<String, LocationType> locationTypeMap = new HashMap<>();
private static final Map<String, ScriptDoubleFunction> locationMap = new HashMap<>(); private static final Map<String, ScriptFunction> locationMap = new HashMap<>();
static { static {
locationTypeMap.put("static", LocationType.STATIC); locationTypeMap.put("static", LocationType.STATIC);
@ -47,16 +46,16 @@ public class LocationScript extends RunnableScript {
locationMap.put("offsetentity", (runnableScriptEvent, doubles) -> { locationMap.put("offsetentity", (runnableScriptEvent, doubles) -> {
if (runnableScriptEvent.entity == null) return false; if (runnableScriptEvent.entity == null) return false;
Location location1 = runnableScriptEvent.entity.getLocation(); Location location1 = runnableScriptEvent.entity.getLocation();
runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2]); runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2], 0, 0);
return false; return false;
}); });
locationMap.put("offsetlocation", (runnableScriptEvent, doubles) -> { locationMap.put("offsetlocation", (runnableScriptEvent, doubles) -> {
Location location1 = runnableScriptEvent.getLocation(); Location location1 = runnableScriptEvent.getLocation();
runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2]); runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2], 0, 0);
return false; return false;
}); });
ScriptDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> { ScriptFunction absoluteLocation = (runnableScriptEvent, doubles) -> {
runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]); runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2], 0, 0);
return false; return false;
}; };
locationMap.put("absolute", absoluteLocation); locationMap.put("absolute", absoluteLocation);
@ -65,7 +64,7 @@ public class LocationScript extends RunnableScript {
} }
private LocationType locationType = null; private LocationType locationType = null;
private ScriptDoubleFunction locationExecutor = null; private ScriptFunction locationExecutor = null;
private double x, y, z = 0; private double x, y, z = 0;

Datei anzeigen

@ -43,7 +43,7 @@ import java.util.Objects;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
public class PasteScript extends RunnableScript { public class PasteScript implements RunnableScript {
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));

Datei anzeigen

@ -29,7 +29,7 @@ import org.bukkit.potion.PotionEffectType;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getBoolean;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.getInt; import static de.steamwar.misslewars.scripts.utils.JsonUtils.getInt;
public class PotionScript extends RunnableScript { public class PotionScript implements RunnableScript {
private PotionEffect potionEffect = null; private PotionEffect potionEffect = null;

Datei anzeigen

@ -24,7 +24,7 @@ import de.steamwar.misslewars.scripts.RunnableScript;
import de.steamwar.misslewars.scripts.RunnableScriptEvent; import de.steamwar.misslewars.scripts.RunnableScriptEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class RemoveScript extends RunnableScript { public class RemoveScript implements RunnableScript {
public RemoveScript(JsonObject jsonObject) {} public RemoveScript(JsonObject jsonObject) {}

Datei anzeigen

@ -27,7 +27,7 @@ import de.steamwar.misslewars.scripts.utils.JsonUtils;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class SoundScript extends RunnableScript { public class SoundScript implements RunnableScript {
private Sound sound; private Sound sound;
private float volume; private float volume;

Datei anzeigen

@ -22,12 +22,12 @@ package de.steamwar.misslewars.scripts.implemented;
import com.google.gson.JsonObject; 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.function.ScriptFunction; import de.steamwar.misslewars.scripts.ScriptFunction;
import de.steamwar.misslewars.scripts.utils.EntityUtils; import de.steamwar.misslewars.scripts.utils.EntityUtils;
import de.steamwar.misslewars.scripts.utils.ScriptShortcut; import de.steamwar.misslewars.scripts.utils.EntityUtils.ScriptShortcut;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
public class SummonScript extends RunnableScript { public class SummonScript implements RunnableScript {
private ScriptFunction summon = null; private ScriptFunction summon = null;
@ -35,7 +35,7 @@ public class SummonScript extends RunnableScript {
ScriptShortcut<Entity> scriptShortcut = EntityUtils.getEntity(summon.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Normal); ScriptShortcut<Entity> scriptShortcut = EntityUtils.getEntity(summon.getAsJsonPrimitive("entity").getAsString(), EntityUtils.EntityType.Normal);
if (scriptShortcut == null) return; if (scriptShortcut == null) return;
this.summon = runnableScriptEvent -> { this.summon = (runnableScriptEvent, doubles) -> {
Entity entity = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), scriptShortcut.entityClass); Entity entity = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), scriptShortcut.entityClass);
Review

Warum ist hier dann ein Switch und kein If?

Warum ist hier dann ein Switch und kein If?
Review

Um es später noch zu erweitern

Um es später noch zu erweitern
scriptShortcut.consumer.accept(summon, entity, runnableScriptEvent); scriptShortcut.consumer.accept(summon, entity, runnableScriptEvent);
return false; return false;

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.misslewars.scripts.utils; package de.steamwar.misslewars.scripts.utils;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import static de.steamwar.misslewars.scripts.utils.JsonUtils.*; import static de.steamwar.misslewars.scripts.utils.JsonUtils.*;
@ -79,4 +80,20 @@ public class EntityUtils {
return null; return null;
} }
public static class ScriptShortcut<T> {
public Class<T> entityClass;
public TriConsumer<JsonObject, T, RunnableScriptEvent> consumer;
public ScriptShortcut(Class<T> entityClass, TriConsumer<JsonObject, T, RunnableScriptEvent> consumer) {
this.entityClass = entityClass;
this.consumer = consumer;
}
}
public interface TriConsumer<T, R, K> {
void accept(T t, R r, K k);
}
} }

Datei anzeigen

@ -13,23 +13,19 @@ public class JsonUtils {
} }
public static boolean getBoolean(JsonObject jsonObject, String key, boolean defaultValue) { public static boolean getBoolean(JsonObject jsonObject, String key, boolean defaultValue) {
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsBoolean(); return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsBoolean() : defaultValue;
return defaultValue;
} }
public static int getInt(JsonObject jsonObject, String key, int defaultValue) { public static int getInt(JsonObject jsonObject, String key, int defaultValue) {
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsInt(); return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsInt() : defaultValue;
return defaultValue;
} }
public static float getFloat(JsonObject jsonObject, String key, float defaultValue) { public static float getFloat(JsonObject jsonObject, String key, float defaultValue) {
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsFloat(); return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsFloat() : defaultValue;
return defaultValue;
} }
public static String getString(JsonObject jsonObject, String key, String defaultValue) { public static String getString(JsonObject jsonObject, String key, String defaultValue) {
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsString(); return jsonObject.has(key) ? jsonObject.getAsJsonPrimitive(key).getAsString() : defaultValue;
return defaultValue;
} }
public static void getBoolean(JsonObject jsonObject, String key, Consumer<Boolean> booleanConsumer) { public static void getBoolean(JsonObject jsonObject, String key, Consumer<Boolean> booleanConsumer) {

Datei anzeigen

@ -1,33 +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.utils;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
public class ScriptShortcut<T> {
public Class<T> entityClass;
public TriConsumer<JsonObject, T, RunnableScriptEvent> consumer;
public ScriptShortcut(Class<T> entityClass, TriConsumer<JsonObject, T, RunnableScriptEvent> consumer) {
this.entityClass = entityClass;
this.consumer = consumer;
}
}

Datei anzeigen

@ -1,24 +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.utils;
public interface TriConsumer<T, R, K> {
void accept(T t, R r, K k);
}