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
17 geänderte Dateien mit 98 neuen und 91 gelöschten Zeilen
Nur Änderungen aus Commit 99b2c64489 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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);
} }

Datei anzeigen

@ -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 {
} }
Review

Vielleicht sollte man hier einen Fehler werfen.

Vielleicht sollte man hier einen Fehler werfen.
Review

Ist bei den Missiles auch nicht, dies habe ich einfach kopiert

Ist bei den Missiles auch nicht, dies habe ich einfach kopiert
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");
}
} }
} }

Datei anzeigen

@ -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);
} }
} }

Datei anzeigen

@ -0,0 +1,10 @@
package de.steamwar.misslewars.scripts;
Review

License Header Fehlt

License Header Fehlt
public enum LocationType {
STATIC,
DYNAMIC,
DEFAULT,
CUSTOM
}

Datei anzeigen

@ -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);
} }

Datei anzeigen

@ -0,0 +1,58 @@
package de.steamwar.misslewars.scripts;
Review

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);
}
}

Datei anzeigen

@ -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();
} }

Datei anzeigen

@ -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());
Review

Warum ist dieser Check nötig?

Warum ist dieser Check nötig?
Review

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); 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;
} }

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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.*;

Datei anzeigen

@ -1,7 +1,9 @@
package de.steamwar.misslewars.scripts.implemented; package de.steamwar.misslewars.scripts.implemented;
Review

License Header Fehlt

License Header Fehlt
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);

Datei anzeigen

@ -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) {
Review

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)); centeredOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2));

Datei anzeigen

@ -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;

Datei anzeigen

@ -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 {

Datei anzeigen

@ -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;

Datei anzeigen

@ -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.*;