Update2.0 #22
@ -64,20 +64,15 @@ public class CustomItem extends SpecialItem {
|
|||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
File itemsFolder = new File(MissileWars.getPlugin().getDataFolder(), "items");
|
File itemsFolder = new File(MissileWars.getPlugin().getDataFolder(), "items");
|
||||||
|
|||||||
if (!itemsFolder.exists() || !itemsFolder.canRead() || !itemsFolder.isDirectory()) {
|
if (!itemsFolder.exists() || !itemsFolder.canRead() || !itemsFolder.isDirectory()) throw new SecurityException("Items could not be loaded");
|
||||||
throw new SecurityException("Items could not be loaded");
|
|
||||||
}
|
|
||||||
for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
|
for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
|
||||||
if (!itemFile.canRead() || !itemFile.isFile()) continue;
|
if (!itemFile.canRead() || !itemFile.isFile()) continue;
|
||||||
Chaoscaot
hat
Vielleicht sollte man hier einen Fehler werfen. Vielleicht sollte man hier einen Fehler werfen.
YoyoNow
hat
Ist bei den Missiles auch nicht, dies habe ich einfach kopiert Ist bei den Missiles auch nicht, dies habe ich einfach kopiert
|
|||||||
try {
|
try {
|
||||||
JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
|
JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
|
||||||
new CustomItem(new ScriptedItem(jsonObject));
|
new CustomItem(new ScriptedItem(jsonObject));
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new SecurityException("Item JSON error");
|
throw new SecurityException("Item JSON error", e);
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new SecurityException("Corrupt Item");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,9 +96,7 @@ public class Missile extends SpecialItem {
|
|||||||
if (index > size) index = size;
|
if (index > size) index = size;
|
||||||
StringBuilder st = new StringBuilder();
|
StringBuilder st = new StringBuilder();
|
||||||
st.append("§8[§e");
|
st.append("§8[§e");
|
||||||
if (index > 0) {
|
if (index > 0) st.append(repeat(index));
|
||||||
st.append(repeat(index));
|
|
||||||
}
|
|
||||||
st.append("§7");
|
st.append("§7");
|
||||||
st.append(repeat(size - index));
|
st.append(repeat(size - index));
|
||||||
st.append("§8]");
|
st.append("§8]");
|
||||||
@ -108,9 +106,7 @@ public class Missile extends SpecialItem {
|
|||||||
private String repeat(int count) {
|
private String repeat(int count) {
|
||||||
if (count == 0) return "";
|
if (count == 0) return "";
|
||||||
StringBuilder st = new StringBuilder();
|
StringBuilder st = new StringBuilder();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) st.append("=");
|
||||||
st.append("=");
|
|
||||||
}
|
|
||||||
return st.toString();
|
return st.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,13 +124,9 @@ public class Missile extends SpecialItem {
|
|||||||
AffineTransform aT = new AffineTransform();
|
AffineTransform aT = new AffineTransform();
|
||||||
|
|
||||||
double yaw = (p.getLocation().getYaw() + 360f) % 360;
|
double yaw = (p.getLocation().getYaw() + 360f) % 360;
|
||||||
if (yaw > 45 && yaw <= 135) {
|
if (yaw > 45 && yaw <= 135) aT = aT.rotateY(270);
|
||||||
aT = aT.rotateY(270);
|
else if (yaw > 135 && yaw <= 225) aT = aT.rotateY(180);
|
||||||
} else if (yaw > 135 && yaw <= 225) {
|
else if (yaw > 225 && yaw <= 315) aT = aT.rotateY(90);
|
||||||
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 = v.subtract(dimensions.getX()/2, dimensions.getY() + 2, -2).subtract(offset);
|
||||||
v = aT.apply(v.toVector3()).toBlockPoint();
|
v = aT.apply(v.toVector3()).toBlockPoint();
|
||||||
@ -155,9 +147,7 @@ public class Missile extends SpecialItem {
|
|||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
|
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
|
||||||
Chaoscaot
hat
Sollte auch /configs liegen Sollte auch /configs liegen
YoyoNow
hat
Siehe Oben nein. War schon immer so. Und Außerdem ist auch dort liegen auch die Shield Schem und so. Deswegen sollte das wohl einfach so bleiben! Siehe Oben nein. War schon immer so. Und Außerdem ist auch dort liegen auch die Shield Schem und so. Deswegen sollte das wohl einfach so bleiben!
Lixfel
hat
Das wird wenn versymlinkt (sobald mehrere Configs gleich sind). Da kann man auch mal umbauen, aber das Plugin sollte nix mit /configs zu tun haben. Das wird wenn versymlinkt (sobald mehrere Configs gleich sind). Da kann man auch mal umbauen, aber das Plugin sollte nix mit /configs zu tun haben.
|
|||||||
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
|
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) throw new SecurityException("Missiles could not be loaded");
|
||||||
throw new SecurityException("Missiles could not be loaded");
|
|
||||||
}
|
|
||||||
for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) {
|
for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) {
|
||||||
if (!missileFile.canRead() || !missileFile.isFile()) continue;
|
if (!missileFile.canRead() || !missileFile.isFile()) continue;
|
||||||
new Missile(missileFile);
|
new Missile(missileFile);
|
||||||
|
@ -42,11 +42,8 @@ public abstract class SpecialItem {
|
|||||||
private static List<SpecialItem> missileItems = new ArrayList<>();
|
private static List<SpecialItem> missileItems = new ArrayList<>();
|
||||||
|
|
||||||
SpecialItem() {
|
SpecialItem() {
|
||||||
if (this.isMissile()) {
|
if (this.isMissile()) missileItems.add(this);
|
||||||
missileItems.add(this);
|
else supportItems.add(this);
|
||||||
} else {
|
|
||||||
supportItems.add(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String materialName = null;
|
private String materialName = null;
|
||||||
@ -78,33 +75,27 @@ public abstract class SpecialItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean handleUse(ItemStack item, Player player, List<SpecialItem> items) {
|
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);
|
if (item.isSimilar(specialItem.getItem())) return specialItem.handleUse(player);
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleThrow(ProjectileLaunchEvent e) {
|
public static void handleThrow(ProjectileLaunchEvent e) {
|
||||||
String name = e.getEntity().getClass().getName().toLowerCase();
|
String name = e.getEntity().getClass().getName().toLowerCase();
|
||||||
for (SpecialItem specialItem : supportItems) {
|
for (SpecialItem specialItem : supportItems) {
|
||||||
if (specialItem.materialName == null) {
|
if (specialItem.materialName == null)
|
||||||
specialItem.materialName = specialItem.getItem().getType().name().toLowerCase();
|
specialItem.materialName = specialItem.getItem().getType().name().toLowerCase();
|
||||||
}
|
if (name.contains(specialItem.materialName))
|
||||||
if (name.contains(specialItem.materialName)) {
|
|
||||||
specialItem.handleThrow(e.getEntity());
|
specialItem.handleThrow(e.getEntity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void handleHit(ProjectileHitEvent e) {
|
public static void handleHit(ProjectileHitEvent e) {
|
||||||
String name = e.getEntity().getClass().getName().toLowerCase();
|
String name = e.getEntity().getClass().getName().toLowerCase();
|
||||||
|
|
||||||
Location location = null;
|
Location location = null;
|
||||||
if (e.getHitEntity() != null) {
|
if (e.getHitEntity() != null) location = e.getHitEntity().getLocation();
|
||||||
location = e.getHitEntity().getLocation();
|
else if (e.getHitBlock() != null) location = e.getHitBlock().getLocation();
|
||||||
} else if (e.getHitBlock() != null) {
|
|
||||||
location = e.getHitBlock().getLocation();
|
|
||||||
}
|
|
||||||
if (location == null) return;
|
if (location == null) return;
|
||||||
|
|
||||||
for (SpecialItem specialItem : supportItems) {
|
for (SpecialItem specialItem : supportItems) {
|
||||||
@ -115,11 +106,8 @@ public abstract class SpecialItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getRandomItem() {
|
public static ItemStack getRandomItem() {
|
||||||
if (random.nextDouble() > Config.MissileChance) {
|
if (random.nextDouble() > Config.MissileChance) return supportItems.get(random.nextInt(supportItems.size())).getItem();
|
||||||
return supportItems.get(random.nextInt(supportItems.size())).getItem();
|
else return missileItems.get(random.nextInt(missileItems.size())).getItem();
|
||||||
} else {
|
|
||||||
return missileItems.get(random.nextInt(missileItems.size())).getItem();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,8 @@
|
|||||||
package de.steamwar.misslewars.scripts;
|
package de.steamwar.misslewars.scripts;
|
||||||
|
|
||||||
public enum LocationType {
|
public enum LocationType {
|
||||||
|
|
||||||
STATIC,
|
STATIC,
|
||||||
DYNAMIC,
|
DYNAMIC,
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
CUSTOM
|
CUSTOM
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,5 @@
|
|||||||
package de.steamwar.misslewars.scripts;
|
package de.steamwar.misslewars.scripts;
|
||||||
|
|
||||||
public abstract class RunnableScript {
|
public abstract class RunnableScript {
|
||||||
|
|
||||||
public abstract boolean execute(RunnableScriptEvent runnableScriptEvent);
|
public abstract boolean execute(RunnableScriptEvent runnableScriptEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,14 +39,10 @@ public class RunnableScriptEvent {
|
|||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
// Custom location
|
// Custom location
|
||||||
if (locationType == LocationType.CUSTOM && customLocation != null) {
|
if (locationType == LocationType.CUSTOM && customLocation != null) return customLocation;
|
||||||
return customLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Static initial Location
|
// Static initial Location
|
||||||
if (locationType == LocationType.STATIC) {
|
if (locationType == LocationType.STATIC) return location;
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dynamic Location if entity is not null
|
// Dynamic Location if entity is not null
|
||||||
if (locationType == LocationType.DYNAMIC) {
|
if (locationType == LocationType.DYNAMIC) {
|
||||||
@ -56,9 +52,7 @@ public class RunnableScriptEvent {
|
|||||||
|
|
||||||
// Default Location is static if EventType is onClick otherwise dynamic
|
// Default Location is static if EventType is onClick otherwise dynamic
|
||||||
if (eventType == ScriptedItem.EventType.onClick) return location;
|
if (eventType == ScriptedItem.EventType.onClick) return location;
|
||||||
if (entity != null) {
|
if (entity != null) return entity.getLocation();
|
||||||
return entity.getLocation();
|
|
||||||
}
|
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,13 +76,6 @@ public class Script {
|
|||||||
runnableScriptList.add(runnableScript);
|
runnableScriptList.add(runnableScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Script{" +
|
|
||||||
"runnableScriptList=" + runnableScriptList +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
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 -> {
|
||||||
@ -94,11 +87,9 @@ 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()) {
|
||||||
String type = jsonObject.getAsJsonPrimitive("type").getAsString();
|
|
||||||
switch (type.toLowerCase()) {
|
|
||||||
case "delay":
|
case "delay":
|
||||||
return new DelayScript(jsonObject);
|
return new DelayScript(jsonObject);
|
||||||
case "filter":
|
case "filter":
|
||||||
|
@ -62,33 +62,25 @@ public class ScriptedItem {
|
|||||||
public ScriptedItem(JsonObject jsonObject) {
|
public ScriptedItem(JsonObject jsonObject) {
|
||||||
itemStack = createItemStack(jsonObject);
|
itemStack = createItemStack(jsonObject);
|
||||||
|
|
||||||
if (jsonObject.has("entityName")) {
|
if (jsonObject.has("entityName"))
|
||||||
entityName = jsonObject.get("entityName").getAsString();
|
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();
|
||||||
if (!jsonObject.has(eventString)) continue;
|
if (!jsonObject.has(eventString) || !jsonObject.get(eventString).isJsonArray()) continue;
|
||||||
if (!jsonObject.get(eventString).isJsonArray()) continue;
|
|
||||||
scriptMap.put(eventType, Script.parseScript(jsonObject.getAsJsonArray(eventString)));
|
scriptMap.put(eventType, Script.parseScript(jsonObject.getAsJsonArray(eventString)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack createItemStack(JsonObject jsonObject) {
|
private ItemStack createItemStack(JsonObject jsonObject) {
|
||||||
String type = jsonObject.getAsJsonPrimitive("type").getAsString();
|
ItemStack itemStack = new ItemStack(Material.valueOf(jsonObject.getAsJsonPrimitive("type").getAsString()), jsonObject.getAsJsonPrimitive("amount").getAsInt());
|
||||||
String name = jsonObject.getAsJsonPrimitive("name").getAsString();
|
|
||||||
int amount = jsonObject.getAsJsonPrimitive("amount").getAsInt();
|
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(Material.valueOf(type), amount);
|
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
if (itemMeta == null) return itemStack;
|
if (itemMeta == null) return itemStack;
|
||||||
itemMeta.setDisplayName(name);
|
itemMeta.setDisplayName(jsonObject.getAsJsonPrimitive("name").getAsString());
|
||||||
|
|
||||||
if (jsonObject.has("lore")) {
|
if (jsonObject.has("lore")) {
|
||||||
List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
jsonObject.getAsJsonArray("lore").forEach(jsonElement -> {
|
jsonObject.getAsJsonArray("lore").forEach(jsonElement -> lore.add(jsonElement.getAsString()));
|
||||||
lore.add(jsonElement.getAsString());
|
|
||||||
});
|
|
||||||
itemMeta.setLore(lore);
|
itemMeta.setLore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,5 @@ package de.steamwar.misslewars.scripts.function;
|
|||||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||||
|
|
||||||
public interface ScriptBooleanFunction {
|
public interface ScriptBooleanFunction {
|
||||||
|
|
||||||
boolean execute(RunnableScriptEvent runnableScriptEvent);
|
boolean execute(RunnableScriptEvent runnableScriptEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,5 @@ package de.steamwar.misslewars.scripts.function;
|
|||||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||||
|
|
||||||
public interface ScriptVoidDoubleFunction {
|
public interface ScriptVoidDoubleFunction {
|
||||||
|
|
||||||
void execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
|
void execute(RunnableScriptEvent runnableScriptEvent, double... doubles);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,5 @@ package de.steamwar.misslewars.scripts.function;
|
|||||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||||
|
|
||||||
public interface ScriptVoidFunction {
|
public interface ScriptVoidFunction {
|
||||||
|
|
||||||
void execute(RunnableScriptEvent runnableScriptEvent);
|
void execute(RunnableScriptEvent runnableScriptEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,8 @@ public class DelayScript extends RunnableScript {
|
|||||||
|
|
||||||
public DelayScript(JsonObject delay) {
|
public DelayScript(JsonObject delay) {
|
||||||
JsonPrimitive jsonPrimitive = delay.getAsJsonPrimitive("time");
|
JsonPrimitive jsonPrimitive = delay.getAsJsonPrimitive("time");
|
||||||
if (jsonPrimitive.isString()) {
|
if (jsonPrimitive.isString()) delayTime = delayMap.getOrDefault(jsonPrimitive.getAsString().toLowerCase(), 0);
|
||||||
delayTime = delayMap.getOrDefault(jsonPrimitive.getAsString().toLowerCase(), 0);
|
else if (jsonPrimitive.isNumber()) delayTime = jsonPrimitive.getAsInt();
|
||||||
} else if (jsonPrimitive.isNumber()) {
|
|
||||||
delayTime = jsonPrimitive.getAsInt();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,15 +40,11 @@ public class FilterScript extends RunnableScript {
|
|||||||
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();
|
||||||
|
int offset = (int) Math.signum(bz - rz) * 5;
|
||||||
int offset = sign(bz - rz) * 5;
|
|
||||||
|
|
||||||
int blockZ = location.getBlockZ();
|
int blockZ = location.getBlockZ();
|
||||||
if (offset > 0) {
|
if (offset > 0) return (blockZ > bz - offset) || (blockZ < rz + offset);
|
||||||
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 -> {
|
||||||
Location location = runnableScriptEvent.getLocation();
|
Location location = runnableScriptEvent.getLocation();
|
||||||
@ -56,29 +52,19 @@ public class FilterScript extends RunnableScript {
|
|||||||
});
|
});
|
||||||
Chaoscaot
hat
If Else oder ||? If Else oder ||?
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int sign(int i) {
|
|
||||||
if (i < 0) return -1;
|
|
||||||
return i > 0 ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean inverted = false;
|
private boolean inverted = false;
|
||||||
Chaoscaot
hat
Selbiges. Selbiges.
|
|||||||
private ScriptBooleanFunction filter;
|
private ScriptBooleanFunction filter;
|
||||||
|
|
||||||
public FilterScript(JsonObject filter) {
|
public FilterScript(JsonObject filter) {
|
||||||
this.filter = filterMap.getOrDefault(getString(filter, "filter", "").toLowerCase(), null);
|
this.filter = filterMap.getOrDefault(getString(filter, "filter", "").toLowerCase(), null);
|
||||||
if (filter.has("invert")) {
|
if (filter.has("invert")) inverted = filter.getAsJsonPrimitive("invert").getAsBoolean();
|
||||||
inverted = filter.getAsJsonPrimitive("invert").getAsBoolean();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||||
if (filter == null) return true;
|
if (filter == null) return true;
|
||||||
if (inverted) {
|
if (inverted) return !filter.execute(runnableScriptEvent);
|
||||||
return !filter.execute(runnableScriptEvent);
|
else return filter.execute(runnableScriptEvent);
|
||||||
} else {
|
|
||||||
return filter.execute(runnableScriptEvent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,10 @@ 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.ScriptVoidFunction;
|
import de.steamwar.misslewars.scripts.function.ScriptVoidFunction;
|
||||||
|
import de.steamwar.misslewars.scripts.utils.ScriptShortcut;
|
||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.Fireball;
|
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.setFireballOptions;
|
||||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setProjectileOptions;
|
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setProjectileOptions;
|
||||||
@ -36,23 +37,26 @@ public class LaunchScript extends RunnableScript {
|
|||||||
private ScriptVoidFunction launch = null;
|
private ScriptVoidFunction launch = null;
|
||||||
|
|
||||||
public LaunchScript(JsonObject launch) {
|
public LaunchScript(JsonObject launch) {
|
||||||
switch (launch.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
|
ScriptShortcut<Projectile> scriptShortcut = getEntity(launch.getAsJsonPrimitive("entity").getAsString());
|
||||||
case "fireball":
|
if (scriptShortcut == null) return;
|
||||||
|
|
||||||
this.launch = runnableScriptEvent -> {
|
this.launch = runnableScriptEvent -> {
|
||||||
Fireball fireball = runnableScriptEvent.getPlayer().launchProjectile(Fireball.class);
|
Projectile projectile = runnableScriptEvent.getPlayer().launchProjectile(scriptShortcut.entityClass);
|
||||||
setFireballOptions(fireball, launch);
|
scriptShortcut.consumer.accept(launch, projectile, runnableScriptEvent);
|
||||||
fireball.setDirection(runnableScriptEvent.getLocation().getDirection());
|
|
||||||
};
|
};
|
||||||
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
|
@Override
|
||||||
|
@ -44,9 +44,7 @@ public class LocationScript extends RunnableScript {
|
|||||||
locationTypeMap.put("default", LocationType.DEFAULT);
|
locationTypeMap.put("default", LocationType.DEFAULT);
|
||||||
|
|
||||||
locationMap.put("offsetentity", (runnableScriptEvent, doubles) -> {
|
locationMap.put("offsetentity", (runnableScriptEvent, doubles) -> {
|
||||||
if (runnableScriptEvent.entity == null) {
|
if (runnableScriptEvent.entity == null) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
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]);
|
||||||
});
|
});
|
||||||
@ -54,9 +52,7 @@ public class LocationScript extends RunnableScript {
|
|||||||
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]);
|
||||||
});
|
});
|
||||||
ScriptVoidDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> {
|
ScriptVoidDoubleFunction absoluteLocation = (runnableScriptEvent, doubles) -> runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]);
|
||||||
runnableScriptEvent.setCustomLocation(doubles[0], doubles[1], doubles[2]);
|
|
||||||
};
|
|
||||||
locationMap.put("absolut", absoluteLocation);
|
locationMap.put("absolut", absoluteLocation);
|
||||||
locationMap.put("fix", absoluteLocation);
|
locationMap.put("fix", absoluteLocation);
|
||||||
locationMap.put("fixed", absoluteLocation);
|
locationMap.put("fixed", absoluteLocation);
|
||||||
@ -65,9 +61,7 @@ public class LocationScript extends RunnableScript {
|
|||||||
private LocationType locationType = null;
|
private LocationType locationType = null;
|
||||||
private ScriptVoidDoubleFunction locationExecutor = null;
|
private ScriptVoidDoubleFunction locationExecutor = null;
|
||||||
|
|
||||||
private double x = 0;
|
private double x, y, z = 0;
|
||||||
private double y = 0;
|
|
||||||
private double z = 0;
|
|
||||||
|
|
||||||
public LocationScript(JsonObject location) {
|
public LocationScript(JsonObject location) {
|
||||||
if (location.has("location")) {
|
if (location.has("location")) {
|
||||||
|
@ -50,11 +50,8 @@ public class PasteScript extends RunnableScript {
|
|||||||
private final Clipboard clipboard;
|
private final Clipboard clipboard;
|
||||||
private final BlockVector3 centeredOffset;
|
private final BlockVector3 centeredOffset;
|
||||||
|
|
||||||
private boolean centered;
|
private boolean centered, ignoreAir;
|
||||||
private boolean ignoreAir;
|
private int xOffset, yOffset, zOffset = 0;
|
||||||
private int xOffset = 0;
|
|
||||||
private int yOffset = 0;
|
|
||||||
private int zOffset = 0;
|
|
||||||
|
|
||||||
public PasteScript(JsonObject paste) {
|
public PasteScript(JsonObject paste) {
|
||||||
String schemFileName = paste.getAsJsonPrimitive("schem").getAsString();
|
String schemFileName = paste.getAsJsonPrimitive("schem").getAsString();
|
||||||
@ -70,23 +67,21 @@ public class PasteScript extends RunnableScript {
|
|||||||
|
|
||||||
centered = getBoolean(paste, "centered", false);
|
centered = getBoolean(paste, "centered", false);
|
||||||
ignoreAir = getBoolean(paste, "ignoreAir", false);
|
ignoreAir = getBoolean(paste, "ignoreAir", false);
|
||||||
if (paste.has("offset")) {
|
if (paste.has("offset"))
|
||||||
|
return;
|
||||||
JsonArray jsonArray = paste.getAsJsonArray("offset");
|
JsonArray jsonArray = paste.getAsJsonArray("offset");
|
||||||
if (jsonArray.size() == 3) {
|
if (jsonArray.size() == 3)
|
||||||
|
return;
|
||||||
xOffset = jsonArray.get(0).getAsInt();
|
xOffset = jsonArray.get(0).getAsInt();
|
||||||
yOffset = jsonArray.get(1).getAsInt();
|
yOffset = jsonArray.get(1).getAsInt();
|
||||||
zOffset = jsonArray.get(2).getAsInt();
|
zOffset = jsonArray.get(2).getAsInt();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||||
Location location = runnableScriptEvent.getLocation();
|
Location location = runnableScriptEvent.getLocation();
|
||||||
BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
|
BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
|
||||||
if (centered) {
|
if (centered) paste = paste.subtract(centeredOffset);
|
||||||
paste = paste.subtract(centeredOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
|
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
|
||||||
Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(ignoreAir).to(paste).build());
|
Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(ignoreAir).to(paste).build());
|
||||||
|
@ -41,9 +41,8 @@ public class PotionScript extends RunnableScript {
|
|||||||
boolean icon = getBoolean(potion, "icon", true);
|
boolean icon = getBoolean(potion, "icon", true);
|
||||||
|
|
||||||
PotionEffectType potionEffectType = PotionEffectType.getByName(potion.getAsJsonPrimitive("potion").getAsString());
|
PotionEffectType potionEffectType = PotionEffectType.getByName(potion.getAsJsonPrimitive("potion").getAsString());
|
||||||
if (potionEffectType == null) {
|
if (potionEffectType == null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
potionEffect = new PotionEffect(potionEffectType, duration, amplifier, ambient, particles, icon);
|
potionEffect = new PotionEffect(potionEffectType, duration, amplifier, ambient, particles, icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,9 +26,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public class RemoveScript extends RunnableScript {
|
public class RemoveScript extends RunnableScript {
|
||||||
|
|
||||||
public RemoveScript(JsonObject jsonObject) {
|
public RemoveScript(JsonObject jsonObject) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||||
|
@ -23,28 +23,32 @@ 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.ScriptVoidFunction;
|
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 org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import static de.steamwar.misslewars.scripts.utils.EntityUtils.setTNTPrimedOptions;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
|
|
||||||
|
|
||||||
public class SummonScript extends RunnableScript {
|
public class SummonScript extends RunnableScript {
|
||||||
|
|
||||||
private ScriptVoidFunction summon = null;
|
private ScriptVoidFunction summon = null;
|
||||||
|
|
||||||
public SummonScript(JsonObject summon) {
|
public SummonScript(JsonObject summon) {
|
||||||
switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
|
ScriptShortcut<Entity> scriptShortcut = getEntity(summon.getAsJsonPrimitive("entity").getAsString());
|
||||||
case "tntprimed":
|
if (scriptShortcut == null) return;
|
||||||
|
|
||||||
Chaoscaot
hat
Warum ist hier dann ein Switch und kein If? Warum ist hier dann ein Switch und kein If?
YoyoNow
hat
Um es später noch zu erweitern Um es später noch zu erweitern
|
|||||||
this.summon = runnableScriptEvent -> {
|
this.summon = runnableScriptEvent -> {
|
||||||
TNTPrimed tnt = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), TNTPrimed.class);
|
Entity entity = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), scriptShortcut.entityClass);
|
||||||
setTNTPrimedOptions(tnt, summon);
|
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
|
@Override
|
||||||
|
@ -47,7 +47,6 @@ public class EntityUtils {
|
|||||||
setEntityOptions(explosive, jsonObject);
|
setEntityOptions(explosive, jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setFireballOptions(Fireball fireball, JsonObject jsonObject) {
|
public static void setFireballOptions(Fireball fireball, JsonObject jsonObject) {
|
||||||
setProjectileOptions(fireball, jsonObject);
|
setProjectileOptions(fireball, jsonObject);
|
||||||
setExplosiveOptions(fireball, jsonObject);
|
setExplosiveOptions(fireball, jsonObject);
|
||||||
|
@ -22,11 +22,6 @@ public class JsonUtils {
|
|||||||
return defaultValue;
|
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) {
|
public static float getFloat(JsonObject jsonObject, String key, float defaultValue) {
|
||||||
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsFloat();
|
if (jsonObject.has(key)) return jsonObject.getAsJsonPrimitive(key).getAsFloat();
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
33
src/de/steamwar/misslewars/scripts/utils/ScriptShortcut.java
Normale Datei
33
src/de/steamwar/misslewars/scripts/utils/ScriptShortcut.java
Normale Datei
@ -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;
|
||||||
|
}
|
||||||
|
}
|
24
src/de/steamwar/misslewars/scripts/utils/TriConsumer.java
Normale Datei
24
src/de/steamwar/misslewars/scripts/utils/TriConsumer.java
Normale Datei
@ -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);
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren
Sollte in /configs liegen
Liegen die Missiles auch nicht. Also nein!