12
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
4 geänderte Dateien mit 120 neuen und 1 gelöschten Zeilen
Nur Änderungen aus Commit 090185558f werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -24,11 +24,22 @@ import org.bukkit.entity.Entity;
public interface RunnableScript {
enum LocationType {
STATIC,
DYNAMIC,
DEFAULT,
CUSTOM
}
class RunnableScriptEvent {
Review

Kann man dem nicht eine Eigene klasse geben?

Kann man dem nicht eine Eigene klasse geben?
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;
@ -37,6 +48,23 @@ public interface RunnableScript {
}
public Location getLocation() {
// Custom location
if (locationType == LocationType.CUSTOM && customLocation != null) {
Review

Warum kann hier kein Switch Statement sein? Wäre glaube ich schöner an der Stelle.

Warum kann hier kein Switch Statement sein? Wäre glaube ich schöner an der Stelle.
Review

Ich glaube dies nicht, weil es immer den Fallback auf Default geben soll. Somit ist es linearer

Ich glaube dies nicht, weil es immer den Fallback auf Default geben soll. Somit ist es linearer
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();
@ -44,6 +72,19 @@ public interface RunnableScript {
return location;
}
public void setLocationType(LocationType locationType) {
if (locationType == null) return;
Review

Dieser Check ist Doppelt, LocationScript z. 68.

Dieser Check ist Doppelt, LocationScript z. 68.
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);

Datei anzeigen

@ -49,6 +49,8 @@ public class ScriptParser {
return new RemoveScript(jsonObject);
case "launch":
return new LaunchScript(jsonObject);
case "location":
return new LocationScript(jsonObject);
case "paste":
return new PasteScript(jsonObject);
case "potion":

Datei anzeigen

@ -55,7 +55,7 @@ public class DelayScript implements RunnableScript {
default:
break;
}
} else {
} else if (jsonPrimitive.isNumber()) {
delayTime = jsonPrimitive.getAsInt();
}
}

Datei anzeigen

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

License Header Fehlt

License Header Fehlt
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript;
import org.bukkit.Location;
public class LocationScript implements RunnableScript {
private LocationType locationType = null;
private LocationExecutor locationExecutor = null;
private interface LocationExecutor {
void location(RunnableScriptEvent runnableScriptEvent);
}
public LocationScript(JsonObject location) {
if (location.has("location")) {
JsonObject jsonObject = location.getAsJsonObject("location");
double x = jsonObject.getAsJsonPrimitive("x").getAsDouble();
double y = jsonObject.getAsJsonPrimitive("y").getAsDouble();
double z = jsonObject.getAsJsonPrimitive("z").getAsDouble();
switch (jsonObject.getAsJsonPrimitive("type").getAsString().toLowerCase()) {
case "absolute":
case "fix":
case "fixed":
locationExecutor = runnableScriptEvent -> runnableScriptEvent.setCustomLocation(x, y, z);
break;
case "offsetEntity":
locationExecutor = runnableScriptEvent -> {
if (runnableScriptEvent.entity == null) {
return;
}
Location location1 = runnableScriptEvent.entity.getLocation();
runnableScriptEvent.setCustomLocation(location1.getX() + x, location1.getY() + y, location1.getZ() + z);
};
break;
case "offsetLocation":
locationExecutor = runnableScriptEvent -> {
Location location1 = runnableScriptEvent.getLocation();
runnableScriptEvent.setCustomLocation(location1.getX() + x, location1.getY() + y, location1.getZ() + z);
};
break;
}
locationType = LocationType.CUSTOM;
} else if (location.has("locationType")) {
switch (location.getAsJsonPrimitive("locationType").getAsString().toLowerCase()) {
case "static":
locationType = LocationType.STATIC;
break;
case "dynamic":
locationType = LocationType.DYNAMIC;
break;
case "custom":
locationType = LocationType.CUSTOM;
break;
case "default":
default:
locationType = LocationType.DEFAULT;
break;
}
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (locationType == null) return false;
runnableScriptEvent.setLocationType(locationType);
if (locationExecutor != null) {
locationExecutor.location(runnableScriptEvent);
}
return true;
}
}