Fix Design
Dieser Commit ist enthalten in:
Ursprung
090185558f
Commit
99b2c64489
@ -70,7 +70,7 @@ public class MissileWars extends JavaPlugin {
|
|||||||
FightScoreboard.init();
|
FightScoreboard.init();
|
||||||
|
|
||||||
Missile.init();
|
Missile.init();
|
||||||
Item.init();
|
CustomItem.init();
|
||||||
|
|
||||||
StateDependent.setupState(fightState);
|
StateDependent.setupState(fightState);
|
||||||
}
|
}
|
||||||
|
@ -34,22 +34,12 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Item extends SpecialItem {
|
public class CustomItem extends SpecialItem {
|
||||||
|
|
||||||
private ScriptedItem scriptedItem;
|
private ScriptedItem scriptedItem;
|
||||||
|
|
||||||
public Item(File item) {
|
public CustomItem(ScriptedItem scriptedItem) {
|
||||||
try {
|
this.scriptedItem = scriptedItem;
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,7 +69,16 @@ public class Item extends SpecialItem {
|
|||||||
}
|
}
|
||||||
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;
|
||||||
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;
|
if (location == null) return;
|
||||||
|
|
||||||
for (SpecialItem specialItem : supportItems) {
|
for (SpecialItem specialItem : supportItems) {
|
||||||
if (name.contains(((Item) specialItem).getScriptedItem().getEntityName())) {
|
if (name.contains(((CustomItem) specialItem).getScriptedItem().getEntityName())) {
|
||||||
specialItem.handleHit(e.getEntity(), location);
|
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;
|
||||||
|
|
||||||
|
public enum LocationType {
|
||||||
|
|
||||||
|
STATIC,
|
||||||
|
DYNAMIC,
|
||||||
|
DEFAULT,
|
||||||
|
CUSTOM
|
||||||
|
|
||||||
|
}
|
@ -19,74 +19,8 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars.scripts;
|
package de.steamwar.misslewars.scripts;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
|
|
||||||
public interface RunnableScript {
|
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);
|
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;
|
||||||
|
|
||||||
|
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 int index = 0;
|
||||||
|
|
||||||
private final RunnableScript.RunnableScriptEvent runnableScriptEvent;
|
private final RunnableScriptEvent runnableScriptEvent;
|
||||||
|
|
||||||
public ScriptExecutor(RunnableScript.RunnableScriptEvent runnableScriptEvent) {
|
public ScriptExecutor(RunnableScriptEvent runnableScriptEvent) {
|
||||||
this.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();
|
new ScriptExecutor(runnableScriptEvent).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +85,6 @@ public class ScriptedItem {
|
|||||||
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 -> {
|
||||||
if (!jsonElement.isJsonPrimitive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lore.add(jsonElement.getAsString());
|
lore.add(jsonElement.getAsString());
|
||||||
});
|
});
|
||||||
itemMeta.setLore(lore);
|
itemMeta.setLore(lore);
|
||||||
@ -99,7 +96,7 @@ public class ScriptedItem {
|
|||||||
|
|
||||||
public boolean execute(EventType eventType, Entity entity, Location location) {
|
public boolean execute(EventType eventType, Entity entity, Location location) {
|
||||||
if (!scriptMap.containsKey(eventType)) return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
import de.steamwar.misslewars.Config;
|
import de.steamwar.misslewars.Config;
|
||||||
import de.steamwar.misslewars.scripts.RunnableScript;
|
import de.steamwar.misslewars.scripts.RunnableScript;
|
||||||
|
import de.steamwar.misslewars.scripts.RunnableScriptEvent;
|
||||||
|
|
||||||
public class DelayScript implements RunnableScript {
|
public class DelayScript implements RunnableScript {
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ package de.steamwar.misslewars.scripts.implemented;
|
|||||||
import com.google.gson.JsonObject;
|
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 org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public class FilterScript implements RunnableScript {
|
public class FilterScript implements RunnableScript {
|
||||||
|
@ -21,6 +21,7 @@ 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.ScriptedItem;
|
import de.steamwar.misslewars.scripts.ScriptedItem;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
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 org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
public class LocationScript implements RunnableScript {
|
public class LocationScript implements RunnableScript {
|
||||||
@ -65,7 +67,6 @@ public class LocationScript implements RunnableScript {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
|
||||||
if (locationType == null) return false;
|
|
||||||
runnableScriptEvent.setLocationType(locationType);
|
runnableScriptEvent.setLocationType(locationType);
|
||||||
if (locationExecutor != null) {
|
if (locationExecutor != null) {
|
||||||
locationExecutor.location(runnableScriptEvent);
|
locationExecutor.location(runnableScriptEvent);
|
||||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.session.ClipboardHolder;
|
|||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
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 org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ public class PasteScript implements RunnableScript {
|
|||||||
try {
|
try {
|
||||||
clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(schemFile)).getReader(new FileInputStream(schemFile)).read();
|
clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(schemFile)).getReader(new FileInputStream(schemFile)).read();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
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));
|
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 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.ScriptedItem;
|
import de.steamwar.misslewars.scripts.ScriptedItem;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
@ -21,6 +21,7 @@ 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 org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class RemoveScript implements RunnableScript {
|
public class RemoveScript implements RunnableScript {
|
||||||
|
@ -21,6 +21,7 @@ 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.ScriptedItem;
|
import de.steamwar.misslewars.scripts.ScriptedItem;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -21,6 +21,7 @@ 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 org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
|
|
||||||
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
|
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren