Update2.0 #22
@ -70,7 +70,7 @@ public class MissileWars extends JavaPlugin {
|
||||
FightScoreboard.init();
|
||||
|
||||
Missile.init();
|
||||
Item.init();
|
||||
CustomItem.init();
|
||||
|
||||
StateDependent.setupState(fightState);
|
||||
}
|
||||
|
@ -34,22 +34,12 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Item extends SpecialItem {
|
||||
public class CustomItem extends SpecialItem {
|
||||
|
||||
private ScriptedItem scriptedItem;
|
||||
|
||||
public Item(File item) {
|
||||
try {
|
||||
JsonObject jsonObject = new JsonParser().parse(new FileReader(item)).getAsJsonObject();
|
||||
System.out.println(jsonObject);
|
||||
scriptedItem = new ScriptedItem(jsonObject);
|
||||
} catch (JsonSyntaxException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Item JSON error");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Corrupt Item");
|
||||
}
|
||||
public CustomItem(ScriptedItem scriptedItem) {
|
||||
this.scriptedItem = scriptedItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,7 +69,16 @@ public class Item extends SpecialItem {
|
||||
}
|
||||
|
||||
for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) {
|
||||
if (!itemFile.canRead() || !itemFile.isFile()) continue;
|
||||
new Item(itemFile);
|
||||
try {
|
||||
JsonObject jsonObject = new JsonParser().parse(new FileReader(itemFile)).getAsJsonObject();
|
||||
new CustomItem(new ScriptedItem(jsonObject));
|
||||
} catch (JsonSyntaxException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Item JSON error");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new SecurityException("Corrupt Item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ public abstract class SpecialItem {
|
||||
if (location == null) return;
|
||||
|
||||
for (SpecialItem specialItem : supportItems) {
|
||||
if (name.contains(((Item) specialItem).getScriptedItem().getEntityName())) {
|
||||
if (name.contains(((CustomItem) specialItem).getScriptedItem().getEntityName())) {
|
||||
specialItem.handleHit(e.getEntity(), location);
|
||||
}
|
||||
}
|
||||
|
10
src/de/steamwar/misslewars/scripts/LocationType.java
Normale Datei
10
src/de/steamwar/misslewars/scripts/LocationType.java
Normale Datei
@ -0,0 +1,10 @@
|
||||
package de.steamwar.misslewars.scripts;
|
||||
Chaoscaot
hat
License Header Fehlt License Header Fehlt
|
||||
|
||||
public enum LocationType {
|
||||
|
||||
STATIC,
|
||||
DYNAMIC,
|
||||
DEFAULT,
|
||||
CUSTOM
|
||||
|
||||
}
|
@ -19,74 +19,8 @@
|
||||
|
||||
package de.steamwar.misslewars.scripts;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public interface RunnableScript {
|
||||
|
||||
enum LocationType {
|
||||
|
||||
STATIC,
|
||||
DYNAMIC,
|
||||
DEFAULT,
|
||||
CUSTOM
|
||||
|
||||
}
|
||||
|
||||
class RunnableScriptEvent {
|
||||
|
||||
public final ScriptedItem.EventType eventType;
|
||||
public final Entity entity;
|
||||
private final Location location;
|
||||
private Location customLocation;
|
||||
private LocationType locationType = LocationType.DEFAULT;
|
||||
|
||||
public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) {
|
||||
this.eventType = eventType;
|
||||
this.entity = entity;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
// Custom location
|
||||
if (locationType == LocationType.CUSTOM && customLocation != null) {
|
||||
return customLocation;
|
||||
}
|
||||
|
||||
// Static initial Location
|
||||
if (locationType == LocationType.STATIC) {
|
||||
return location;
|
||||
}
|
||||
|
||||
// Dynamic Location if entity is not null
|
||||
if (locationType == LocationType.DYNAMIC) {
|
||||
if (entity != null) return entity.getLocation();
|
||||
return location;
|
||||
}
|
||||
|
||||
// Default Location is static if EventType is onClick otherwise dynamic
|
||||
if (eventType == ScriptedItem.EventType.onClick) return location;
|
||||
if (entity != null) {
|
||||
return entity.getLocation();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocationType(LocationType locationType) {
|
||||
if (locationType == null) return;
|
||||
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) {
|
||||
this.customLocation = new Location(location.getWorld(), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean execute(RunnableScriptEvent runnableScriptEvent);
|
||||
|
||||
}
|
||||
|
58
src/de/steamwar/misslewars/scripts/RunnableScriptEvent.java
Normale Datei
58
src/de/steamwar/misslewars/scripts/RunnableScriptEvent.java
Normale Datei
@ -0,0 +1,58 @@
|
||||
package de.steamwar.misslewars.scripts;
|
||||
Chaoscaot
hat
License Header Fehlt License Header Fehlt
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class RunnableScriptEvent {
|
||||
|
||||
public final ScriptedItem.EventType eventType;
|
||||
public final Entity entity;
|
||||
private final Location location;
|
||||
private Location customLocation;
|
||||
private LocationType locationType = LocationType.DEFAULT;
|
||||
|
||||
public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) {
|
||||
this.eventType = eventType;
|
||||
this.entity = entity;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
// Custom location
|
||||
if (locationType == LocationType.CUSTOM && customLocation != null) {
|
||||
return customLocation;
|
||||
}
|
||||
|
||||
// Static initial Location
|
||||
if (locationType == LocationType.STATIC) {
|
||||
return location;
|
||||
}
|
||||
|
||||
// Dynamic Location if entity is not null
|
||||
if (locationType == LocationType.DYNAMIC) {
|
||||
if (entity != null) return entity.getLocation();
|
||||
return location;
|
||||
}
|
||||
|
||||
// Default Location is static if EventType is onClick otherwise dynamic
|
||||
if (eventType == ScriptedItem.EventType.onClick) return location;
|
||||
if (entity != null) {
|
||||
return entity.getLocation();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocationType(LocationType locationType) {
|
||||
if (locationType == null) return;
|
||||
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) {
|
||||
this.customLocation = new Location(location.getWorld(), x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
}
|
@ -34,9 +34,9 @@ public class Script {
|
||||
|
||||
private int index = 0;
|
||||
|
||||
private final RunnableScript.RunnableScriptEvent runnableScriptEvent;
|
||||
private final RunnableScriptEvent runnableScriptEvent;
|
||||
|
||||
public ScriptExecutor(RunnableScript.RunnableScriptEvent runnableScriptEvent) {
|
||||
public ScriptExecutor(RunnableScriptEvent runnableScriptEvent) {
|
||||
this.runnableScriptEvent = runnableScriptEvent;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class Script {
|
||||
|
||||
}
|
||||
|
||||
public void execute(RunnableScript.RunnableScriptEvent runnableScriptEvent) {
|
||||
public void execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
new ScriptExecutor(runnableScriptEvent).start();
|
||||
}
|
||||
|
||||
|
@ -85,9 +85,6 @@ public class ScriptedItem {
|
||||
if (jsonObject.has("lore")) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
jsonObject.getAsJsonArray("lore").forEach(jsonElement -> {
|
||||
if (!jsonElement.isJsonPrimitive()) {
|
||||
return;
|
||||
}
|
||||
lore.add(jsonElement.getAsString());
|
||||
Chaoscaot
hat
Warum ist dieser Check nötig? Warum ist dieser Check nötig?
YoyoNow
hat
Weil man auch die Lore weglassen kann, diese ist somit optional Weil man auch die Lore weglassen kann, diese ist somit optional
|
||||
});
|
||||
itemMeta.setLore(lore);
|
||||
@ -99,7 +96,7 @@ public class ScriptedItem {
|
||||
|
||||
public boolean execute(EventType eventType, Entity entity, Location location) {
|
||||
if (!scriptMap.containsKey(eventType)) return false;
|
||||
scriptMap.get(eventType).execute(new RunnableScript.RunnableScriptEvent(eventType, entity, location));
|
||||
scriptMap.get(eventType).execute(new RunnableScriptEvent(eventType, entity, location));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import de.steamwar.misslewars.Config;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
|
||||
public class DelayScript implements RunnableScript {
|
||||
|
||||
|
@ -22,6 +22,7 @@ package de.steamwar.misslewars.scripts.implemented;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class FilterScript implements RunnableScript {
|
||||
|
@ -21,6 +21,7 @@ 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.ScriptedItem;
|
||||
import org.bukkit.entity.*;
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
package de.steamwar.misslewars.scripts.implemented;
|
||||
Chaoscaot
hat
License Header Fehlt License Header Fehlt
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.LocationType;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class LocationScript implements RunnableScript {
|
||||
@ -65,7 +67,6 @@ public class LocationScript implements RunnableScript {
|
||||
|
||||
@Override
|
||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||
if (locationType == null) return false;
|
||||
runnableScriptEvent.setLocationType(locationType);
|
||||
if (locationExecutor != null) {
|
||||
locationExecutor.location(runnableScriptEvent);
|
||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@ -63,7 +64,7 @@ public class PasteScript implements RunnableScript {
|
||||
try {
|
||||
clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(schemFile)).getReader(new FileInputStream(schemFile)).read();
|
||||
} catch (IOException e) {
|
||||
Chaoscaot
hat
Warum konnte er da das Schild nicht laden? Das wird doch von mehr Sachen als nur das Schild was etwas Pastet. Warum konnte er da das Schild nicht laden? Das wird doch von mehr Sachen als nur das Schild was etwas Pastet.
|
||||
throw new SecurityException("Could not load shield", e);
|
||||
throw new SecurityException("Could not load " + schemFileName, e);
|
||||
}
|
||||
centeredOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2));
|
||||
|
||||
|
@ -21,6 +21,7 @@ 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.ScriptedItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.misslewars.scripts.implemented;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RemoveScript implements RunnableScript {
|
||||
|
@ -21,6 +21,7 @@ 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.ScriptedItem;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.misslewars.scripts.implemented;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
|
||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Vielleicht sollte man hier einen Fehler werfen.
Ist bei den Missiles auch nicht, dies habe ich einfach kopiert