SteamWar/MissileWars
Archiviert
13
0
Dieser Commit ist enthalten in:
jojo 2020-12-04 22:42:04 +01:00
Ursprung 948d472f40
Commit ea3181cc03
23 geänderte Dateien mit 144 neuen und 176 gelöschten Zeilen

Datei anzeigen

@ -64,20 +64,15 @@ public class CustomItem extends SpecialItem {
public static void init() {
File itemsFolder = new File(MissileWars.getPlugin().getDataFolder(), "items");
if (!itemsFolder.exists() || !itemsFolder.canRead() || !itemsFolder.isDirectory()) {
throw new SecurityException("Items could not be loaded");
}
if (!itemsFolder.exists() || !itemsFolder.canRead() || !itemsFolder.isDirectory()) throw new SecurityException("Items could not be loaded");
for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
if (!itemFile.canRead() || !itemFile.isFile()) continue;
try {
JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
new CustomItem(new ScriptedItem(jsonObject));
} catch (JsonSyntaxException e) {
} catch (JsonSyntaxException | IOException e) {
e.printStackTrace();
throw new SecurityException("Item JSON error");
} catch (IOException e) {
e.printStackTrace();
throw new SecurityException("Corrupt Item");
throw new SecurityException("Item JSON error", e);
}
}
}

Datei anzeigen

@ -96,9 +96,7 @@ public class Missile extends SpecialItem {
if (index > size) index = size;
StringBuilder st = new StringBuilder();
st.append("§8[§e");
if (index > 0) {
st.append(repeat(index));
}
if (index > 0) st.append(repeat(index));
st.append("§7");
st.append(repeat(size - index));
st.append("§8]");
@ -108,9 +106,7 @@ public class Missile extends SpecialItem {
private String repeat(int count) {
if (count == 0) return "";
StringBuilder st = new StringBuilder();
for (int i = 0; i < count; i++) {
st.append("=");
}
for (int i = 0; i < count; i++) st.append("=");
return st.toString();
}
@ -128,13 +124,9 @@ public class Missile extends SpecialItem {
AffineTransform aT = new AffineTransform();
double yaw = (p.getLocation().getYaw() + 360f) % 360;
if (yaw > 45 && yaw <= 135) {
aT = aT.rotateY(270);
} else if (yaw > 135 && yaw <= 225) {
aT = aT.rotateY(180);
} else if (yaw > 225 && yaw <= 315) {
aT = aT.rotateY(90);
}
if (yaw > 45 && yaw <= 135) aT = aT.rotateY(270);
else if (yaw > 135 && yaw <= 225) aT = aT.rotateY(180);
else if (yaw > 225 && yaw <= 315) aT = aT.rotateY(90);
v = v.subtract(dimensions.getX()/2, dimensions.getY() + 2, -2).subtract(offset);
v = aT.apply(v.toVector3()).toBlockPoint();
@ -155,9 +147,7 @@ public class Missile extends SpecialItem {
public static void init() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
throw new SecurityException("Missiles could not be loaded");
}
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) throw new SecurityException("Missiles could not be loaded");
for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) {
if (!missileFile.canRead() || !missileFile.isFile()) continue;
new Missile(missileFile);

Datei anzeigen

@ -42,11 +42,8 @@ public abstract class SpecialItem {
private static List<SpecialItem> missileItems = new ArrayList<>();
SpecialItem() {
if (this.isMissile()) {
missileItems.add(this);
} else {
supportItems.add(this);
}
if (this.isMissile()) missileItems.add(this);
else supportItems.add(this);
}
private String materialName = null;
@ -78,33 +75,27 @@ public abstract class SpecialItem {
}
private static boolean handleUse(ItemStack item, Player player, List<SpecialItem> items) {
for (SpecialItem specialItem : items) {
for (SpecialItem specialItem : items)
if (item.isSimilar(specialItem.getItem())) return specialItem.handleUse(player);
}
return false;
}
public static void handleThrow(ProjectileLaunchEvent e) {
String name = e.getEntity().getClass().getName().toLowerCase();
for (SpecialItem specialItem : supportItems) {
if (specialItem.materialName == null) {
if (specialItem.materialName == null)
specialItem.materialName = specialItem.getItem().getType().name().toLowerCase();
}
if (name.contains(specialItem.materialName)) {
if (name.contains(specialItem.materialName))
specialItem.handleThrow(e.getEntity());
}
}
}
public static void handleHit(ProjectileHitEvent e) {
String name = e.getEntity().getClass().getName().toLowerCase();
Location location = null;
if (e.getHitEntity() != null) {
location = e.getHitEntity().getLocation();
} else if (e.getHitBlock() != null) {
location = e.getHitBlock().getLocation();
}
if (e.getHitEntity() != null) location = e.getHitEntity().getLocation();
else if (e.getHitBlock() != null) location = e.getHitBlock().getLocation();
if (location == null) return;
for (SpecialItem specialItem : supportItems) {
@ -115,11 +106,8 @@ public abstract class SpecialItem {
}
public static ItemStack getRandomItem() {
if (random.nextDouble() > Config.MissileChance) {
return supportItems.get(random.nextInt(supportItems.size())).getItem();
} else {
return missileItems.get(random.nextInt(missileItems.size())).getItem();
}
if (random.nextDouble() > Config.MissileChance) return supportItems.get(random.nextInt(supportItems.size())).getItem();
else return missileItems.get(random.nextInt(missileItems.size())).getItem();
}
}

Datei anzeigen

@ -20,10 +20,8 @@
package de.steamwar.misslewars.scripts;
public enum LocationType {
STATIC,
DYNAMIC,
DEFAULT,
CUSTOM
}

Datei anzeigen

@ -20,7 +20,5 @@
package de.steamwar.misslewars.scripts;
public abstract class RunnableScript {
public abstract boolean execute(RunnableScriptEvent runnableScriptEvent);
}

Datei anzeigen

@ -39,14 +39,10 @@ public class RunnableScriptEvent {
public Location getLocation() {
// Custom location
if (locationType == LocationType.CUSTOM && customLocation != null) {
return customLocation;
}
if (locationType == LocationType.CUSTOM && customLocation != null) return customLocation;
// Static initial Location
if (locationType == LocationType.STATIC) {
return location;
}
if (locationType == LocationType.STATIC) return location;
// Dynamic Location if entity is not null
if (locationType == LocationType.DYNAMIC) {
@ -56,9 +52,7 @@ public class RunnableScriptEvent {
// Default Location is static if EventType is onClick otherwise dynamic
if (eventType == ScriptedItem.EventType.onClick) return location;
if (entity != null) {
return entity.getLocation();
}
if (entity != null) return entity.getLocation();
return location;
}

Datei anzeigen

@ -76,13 +76,6 @@ public class Script {
runnableScriptList.add(runnableScript);
}
@Override
public String toString() {
return "Script{" +
"runnableScriptList=" + runnableScriptList +
'}';
}
public static Script parseScript(JsonArray jsonArray) {
Script script = new Script();
jsonArray.forEach(jsonElement -> {
@ -94,11 +87,9 @@ public class Script {
}
private static RunnableScript parseScriptSnippet(JsonObject jsonObject) {
if (!jsonObject.has("type")) {
if (!jsonObject.has("type"))
return null;
}
String type = jsonObject.getAsJsonPrimitive("type").getAsString();
switch (type.toLowerCase()) {
switch (jsonObject.getAsJsonPrimitive("type").getAsString().toLowerCase()) {
case "delay":
return new DelayScript(jsonObject);
case "filter":

Datei anzeigen

@ -62,33 +62,25 @@ public class ScriptedItem {
public ScriptedItem(JsonObject jsonObject) {
itemStack = createItemStack(jsonObject);
if (jsonObject.has("entityName")) {
if (jsonObject.has("entityName"))
entityName = jsonObject.get("entityName").getAsString();
}
for (EventType eventType : EventType.values()) {
String eventString = "EVENT." + eventType.name();
if (!jsonObject.has(eventString)) continue;
if (!jsonObject.get(eventString).isJsonArray()) continue;
if (!jsonObject.has(eventString) || !jsonObject.get(eventString).isJsonArray()) continue;
scriptMap.put(eventType, Script.parseScript(jsonObject.getAsJsonArray(eventString)));
}
}
private ItemStack createItemStack(JsonObject jsonObject) {
String type = jsonObject.getAsJsonPrimitive("type").getAsString();
String name = jsonObject.getAsJsonPrimitive("name").getAsString();
int amount = jsonObject.getAsJsonPrimitive("amount").getAsInt();
ItemStack itemStack = new ItemStack(Material.valueOf(type), amount);
ItemStack itemStack = new ItemStack(Material.valueOf(jsonObject.getAsJsonPrimitive("type").getAsString()), jsonObject.getAsJsonPrimitive("amount").getAsInt());
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) return itemStack;
itemMeta.setDisplayName(name);
itemMeta.setDisplayName(jsonObject.getAsJsonPrimitive("name").getAsString());
if (jsonObject.has("lore")) {
List<String> lore = new ArrayList<>();
jsonObject.getAsJsonArray("lore").forEach(jsonElement -> {
lore.add(jsonElement.getAsString());
});
jsonObject.getAsJsonArray("lore").forEach(jsonElement -> lore.add(jsonElement.getAsString()));
itemMeta.setLore(lore);
}

Datei anzeigen

@ -22,7 +22,5 @@ package de.steamwar.misslewars.scripts.function;
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
public interface ScriptBooleanFunction {
boolean execute(RunnableScriptEvent runnableScriptEvent);
}

Datei anzeigen

@ -22,7 +22,5 @@ package de.steamwar.misslewars.scripts.function;
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
public interface ScriptVoidDoubleFunction {
void execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
}

Datei anzeigen

@ -22,7 +22,5 @@ package de.steamwar.misslewars.scripts.function;
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
public interface ScriptVoidFunction {
void execute(RunnableScriptEvent runnableScriptEvent);
}

Datei anzeigen

@ -47,11 +47,8 @@ public class DelayScript extends RunnableScript {
public DelayScript(JsonObject delay) {
JsonPrimitive jsonPrimitive = delay.getAsJsonPrimitive("time");
if (jsonPrimitive.isString()) {
delayTime = delayMap.getOrDefault(jsonPrimitive.getAsString().toLowerCase(), 0);
} else if (jsonPrimitive.isNumber()) {
delayTime = jsonPrimitive.getAsInt();
}
if (jsonPrimitive.isString()) delayTime = delayMap.getOrDefault(jsonPrimitive.getAsString().toLowerCase(), 0);
else if (jsonPrimitive.isNumber()) delayTime = jsonPrimitive.getAsInt();
}
@Override

Datei anzeigen

@ -40,15 +40,11 @@ public class FilterScript extends RunnableScript {
Location location = runnableScriptEvent.getLocation();
int bz = MissileWars.getBlueTeam().getPortalZ();
int rz = MissileWars.getRedTeam().getPortalZ();
int offset = sign(bz - rz) * 5;
int offset = (int) Math.signum(bz - rz) * 5;
int blockZ = location.getBlockZ();
if (offset > 0) {
return (blockZ > bz - offset) || (blockZ < rz + offset);
} else {
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);
});
filterMap.put("nearspawn", runnableScriptEvent -> {
Location location = runnableScriptEvent.getLocation();
@ -56,29 +52,19 @@ public class FilterScript extends RunnableScript {
});
}
private static int sign(int i) {
if (i < 0) return -1;
return i > 0 ? 1 : 0;
}
private boolean inverted = false;
private ScriptBooleanFunction filter;
public FilterScript(JsonObject filter) {
this.filter = filterMap.getOrDefault(getString(filter, "filter", "").toLowerCase(), null);
if (filter.has("invert")) {
inverted = filter.getAsJsonPrimitive("invert").getAsBoolean();
}
if (filter.has("invert")) inverted = filter.getAsJsonPrimitive("invert").getAsBoolean();
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (filter == null) return true;
if (inverted) {
return !filter.execute(runnableScriptEvent);
} else {
return filter.execute(runnableScriptEvent);
}
if (inverted) return !filter.execute(runnableScriptEvent);
else return filter.execute(runnableScriptEvent);
}
}

Datei anzeigen

@ -24,9 +24,10 @@ 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.utils.ScriptShortcut;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setFireballOptions;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setProjectileOptions;
@ -36,23 +37,26 @@ public class LaunchScript extends RunnableScript {
private ScriptVoidFunction launch = null;
public LaunchScript(JsonObject launch) {
switch (launch.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
case "fireball":
ScriptShortcut<Projectile> scriptShortcut = getEntity(launch.getAsJsonPrimitive("entity").getAsString());
if (scriptShortcut == null) return;
this.launch = runnableScriptEvent -> {
Fireball fireball = runnableScriptEvent.getPlayer().launchProjectile(Fireball.class);
setFireballOptions(fireball, launch);
fireball.setDirection(runnableScriptEvent.getLocation().getDirection());
Projectile projectile = runnableScriptEvent.getPlayer().launchProjectile(scriptShortcut.entityClass);
scriptShortcut.consumer.accept(launch, projectile, runnableScriptEvent);
};
break;
case "arrow":
this.launch = runnableScriptEvent -> {
Arrow arrow = runnableScriptEvent.getPlayer().launchProjectile(Arrow.class);
setProjectileOptions(arrow, launch);
};
break;
default:
break;
}
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

Datei anzeigen

@ -44,9 +44,7 @@ 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;
Location location1 = runnableScriptEvent.entity.getLocation();
runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2]);
});
@ -54,9 +52,7 @@ public class LocationScript extends RunnableScript {
Location location1 = runnableScriptEvent.getLocation();
runnableScriptEvent.setCustomLocation(location1.getX() + doubles[0], location1.getY() + doubles[1], location1.getZ() + doubles[2]);
});
ScriptVoidDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> {
runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]);
};
ScriptVoidDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]);
locationMap.put("absolut", absoluteLocation);
locationMap.put("fix", absoluteLocation);
locationMap.put("fixed", absoluteLocation);
@ -65,9 +61,7 @@ public class LocationScript extends RunnableScript {
private LocationType locationType = null;
private ScriptVoidDoubleFunction locationExecutor = null;
private double x = 0;
private double y = 0;
private double z = 0;
private double x, y, z = 0;
public LocationScript(JsonObject location) {
if (location.has("location")) {

Datei anzeigen

@ -50,11 +50,8 @@ public class PasteScript extends RunnableScript {
private final Clipboard clipboard;
private final BlockVector3 centeredOffset;
private boolean centered;
private boolean ignoreAir;
private int xOffset = 0;
private int yOffset = 0;
private int zOffset = 0;
private boolean centered, ignoreAir;
private int xOffset, yOffset, zOffset = 0;
public PasteScript(JsonObject paste) {
String schemFileName = paste.getAsJsonPrimitive("schem").getAsString();
@ -70,23 +67,21 @@ public class PasteScript extends RunnableScript {
centered = getBoolean(paste, "centered", false);
ignoreAir = getBoolean(paste, "ignoreAir", false);
if (paste.has("offset")) {
if (paste.has("offset"))
return;
JsonArray jsonArray = paste.getAsJsonArray("offset");
if (jsonArray.size() == 3) {
if (jsonArray.size() == 3)
return;
xOffset = jsonArray.get(0).getAsInt();
yOffset = jsonArray.get(1).getAsInt();
zOffset = jsonArray.get(2).getAsInt();
}
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
Location location = runnableScriptEvent.getLocation();
BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
if (centered) {
paste = paste.subtract(centeredOffset);
}
if (centered) paste = paste.subtract(centeredOffset);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(ignoreAir).to(paste).build());

Datei anzeigen

@ -41,9 +41,8 @@ public class PotionScript extends RunnableScript {
boolean icon = getBoolean(potion, "icon", true);
PotionEffectType potionEffectType = PotionEffectType.getByName(potion.getAsJsonPrimitive("potion").getAsString());
if (potionEffectType == null) {
if (potionEffectType == null)
return;
}
potionEffect = new PotionEffect(potionEffectType, duration, amplifier, ambient, particles, icon);
}

Datei anzeigen

@ -26,9 +26,7 @@ import org.bukkit.entity.Player;
public class RemoveScript extends RunnableScript {
public RemoveScript(JsonObject jsonObject) {
}
public RemoveScript(JsonObject jsonObject) {}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {

Datei anzeigen

@ -23,28 +23,32 @@ 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.utils.ScriptShortcut;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TNTPrimed;
import java.util.HashMap;
import java.util.Map;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setTNTPrimedOptions;
public class SummonScript extends RunnableScript {
private ScriptVoidFunction summon = null;
public SummonScript(JsonObject summon) {
switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
case "tntprimed":
ScriptShortcut<Entity> scriptShortcut = getEntity(summon.getAsJsonPrimitive("entity").getAsString());
if (scriptShortcut == null) return;
this.summon = runnableScriptEvent -> {
TNTPrimed tnt = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), TNTPrimed.class);
setTNTPrimedOptions(tnt, summon);
Entity entity = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), scriptShortcut.entityClass);
scriptShortcut.consumer.accept(summon, entity, runnableScriptEvent);
};
break;
default:
break;
}
private ScriptShortcut getEntity(String name) {
switch (name.toLowerCase()) {
case "tntprimed":
return new ScriptShortcut<>(TNTPrimed.class, (jsonObject, entity, runnableScriptEvent) -> setTNTPrimedOptions(entity, jsonObject));
}
return null;
}
@Override

Datei anzeigen

@ -47,7 +47,6 @@ public class EntityUtils {
setEntityOptions(explosive, jsonObject);
}
public static void setFireballOptions(Fireball fireball, JsonObject jsonObject) {
setProjectileOptions(fireball, jsonObject);
setExplosiveOptions(fireball, jsonObject);

Datei anzeigen

@ -22,11 +22,6 @@ public class JsonUtils {
return defaultValue;
}
public static double getDouble(JsonObject jsonObject, String key, double defaultValue) {
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsDouble();
return defaultValue;
}
public static float getFloat(JsonObject jsonObject, String key, float defaultValue) {
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsFloat();
return defaultValue;

Datei anzeigen

@ -0,0 +1,33 @@
/*
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

@ -0,0 +1,24 @@
/*
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);
}