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
15 geänderte Dateien mit 924 neuen und 18 gelöschten Zeilen
Nur Änderungen aus Commit 4f9078ab32 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -29,12 +29,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
import java.util.Random;
public class ItemCountdown extends StateDependent {
private BukkitTask task;
private Random random = new Random();
public ItemCountdown() {
super(EnumSet.of(FightState.FIGHTING));

Datei anzeigen

@ -20,13 +20,14 @@
package de.steamwar.misslewars.items;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public abstract class SpecialItem {

Datei anzeigen

@ -1,16 +1,68 @@
{
"type": "ARROW",
"name": "§ePfeil",
"lore": [],
"amount": 3,
"EVENT.onThrow": [
[
{
"type": "ARROW",
"name": "§ePfeil",
"lore": [],
"amount": 3,
"EVENT.onThrow": [
],
"EVENT.onHit": [
{"type": "delay", "time": 0},
{"type": "paste", "schem": ""}
],
"EVENT.onClick": [
],
"EVENT.onHit": [
]
}
],
"EVENT.onClick": [
]
},
{
"type": "SPECTRAL_ARROW",
"name": "§eExplodierender Pfeil",
"lore": [],
"amount": 1,
"EVENT.onHit": [
{"type": "summon", "entity": "TNTPrimed", "incendiary": false, "fuse": 0, "yield": 2.0}
]
},
{
"type": "FIRE_CHARGE",
"name": "§eFeuerball",
"lore": [],
"amount": 1,
"EVENT.onClick": [
{"type": "launch", "entity": "Fireball", "incendiary": false, "bounce": false, "yield": 3.0, "velocity": 2},
{"type": "sound", "sound": "ITEM_FIRECHARGE_USE", "volume": 100, "pitch": 1}
]
},
{
"type": "SLIME_BALL",
"name": "§aLanding Pad",
"lore": [],
"amount": 1,
"EVENT.onClick": [
{"type": "potion", "potion": "SLOW_FALLING", "duration": 2, "amplifier": 1, "ambient": false, "particles": false, "icon": false},
{"type": "paste", "schem": "landingPad.schem", "centered": true, "offset": [0, -5, 0], "ignoreAir": true}
]
},
{
"type": "EGG",
"name": "§eMine",
"lore": [],
"amount": 1,
"EVENT.onThrow": [
{"type": "delay", "time": "CONFIG.MineFlyTime"},
{"type": "filter", "filter": "nearPortal", "invert": true},
{"type": "paste", "schem": "mine.schem", "centered": true, "offset": [0, 0, 0], "ignoreAir": true}
]
},
{
"type": "SNOWBALL",
"name": "§aSchild",
"lore": [],
"amount": 1,
"EVENT.onThrow": [
{"type": "delay", "time": "CONFIG.ShieldFlyTime"},
{"type": "filter", "filter": "nearPortal", "invert": true},
{"type": "paste", "schem": "shield.schem", "centered": true, "offset": [0, 0, 0], "ignoreAir": true}
]
}
]

Datei anzeigen

@ -0,0 +1,40 @@
/*
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;
import org.bukkit.entity.Entity;
public interface RunnableScript {
class RunnableScriptEvent {
public final ScriptedItem.EventType eventType;
public final Entity entity;
public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity) {
this.eventType = eventType;
this.entity = entity;
}
}
Review

Kann man dem nicht eine Eigene klasse geben?

Kann man dem nicht eine Eigene klasse geben?
boolean execute(RunnableScriptEvent runnableScriptEvent);
}

Datei anzeigen

@ -0,0 +1,49 @@
/*
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;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class Script {
private List<RunnableScript> runnableScriptList = new ArrayList<>();
public void execute(RunnableScript.RunnableScriptEvent runnableScriptEvent) {
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> {
int i = 0;
while (i < runnableScriptList.size()) {
if (!runnableScriptList.get(i).execute(runnableScriptEvent)) {
break;
}
i++;
}
}, 0);
}
public void add(RunnableScript runnableScript) {
runnableScriptList.add(runnableScript);
}
Review

Wäre hier nicht eher eine For oder Foreach Schleife angebracht.
?

Wäre hier nicht eher eine For oder Foreach Schleife angebracht. ?
Review

Nein weil sie auch abgebrochen werden kann mit dem Delay und danach wieder angefangen wird. Somit ist beides keine Option.

Nein weil sie auch abgebrochen werden kann mit dem Delay und danach wieder angefangen wird. Somit ist beides keine Option.
}

Datei anzeigen

@ -0,0 +1,64 @@
/*
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;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.implemented.*;
public class ScriptParser {
public static Script parseScript(JsonArray jsonArray) {
Script script = new Script();
jsonArray.forEach(jsonElement -> {
if (!jsonArray.isJsonObject()) return;
RunnableScript runnableScript = parseScriptSnippet((JsonObject) jsonElement);
if (runnableScript == null) return;
script.add(runnableScript);
});
return script;
}
private static RunnableScript parseScriptSnippet(JsonObject jsonObject) {
if (!jsonObject.has("type")) {
return null;
}
String type = jsonObject.getAsJsonPrimitive("type").getAsString();
Review

Könnte man nicht einen Enum, welcher ein RunnableScript speichert, und da dann mit dem Enum Namen drüber Iteriert?

Könnte man nicht einen Enum, welcher ein RunnableScript speichert, und da dann mit dem Enum Namen drüber Iteriert?
Review

geht nicht, weil die dann statisch währen und man enum values nicht überschreiben sollte

geht nicht, weil die dann statisch währen und man enum values nicht überschreiben sollte
switch (type.toLowerCase()) {
case "delay":
return new DelayScript(jsonObject);
case "filter":
return new FilterScript(jsonObject);
case "launch":
return new LaunchScript(jsonObject);
case "paste":
return new PasteScript(jsonObject);
case "potion":
return new PotionScript(jsonObject);
case "sound":
return new SoundScript(jsonObject);
case "summon":
return new SummonScript(jsonObject);
default:
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,102 @@
/*
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;
import com.google.gson.JsonArray;
Review

Unnötiger Import

Unnötiger Import
import com.google.gson.JsonObject;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ScriptedItem {
// "type": Material name (STRING)
// "name": Item name (STRING)
// "lore": Lore array (OPTIONAL STRING.ARRAY)
// "amount": Item amount (OPTIONAL [default 1] INT)
// "EVENT.<eventName>": Event (OPTIONAL JSONobject.ARRAY)
// - onClick
// - onHit
// - onThrow
public enum EventType {
onHit("onHit"),
Review

Warum werden dieser String Parameter benötigt, und kann man das nicht name() machen?

Warum werden dieser String Parameter benötigt, und kann man das nicht ```name()``` machen?
Review

kann man, aber der Enum name muss nicht mit dem Event Namen übereinstimmen

kann man, aber der Enum name muss nicht mit dem Event Namen übereinstimmen
Review

Tut es doch jetzt schon.

Tut es doch jetzt schon.
onThrow("onThrow"),
onClick("onClick");
String name;
EventType(String name) {
this.name = name;
}
}
private Map<EventType, Script> scriptMap = new HashMap<>();
private ItemStack itemStack;
public ScriptedItem(JsonObject jsonObject) {
itemStack = createItemStack(jsonObject);
for (EventType eventType : EventType.values()) {
String eventString = "EVENT." + eventType.name();
if (!jsonObject.has(eventString)) continue;
if (!jsonObject.get(eventString).isJsonArray()) continue;
scriptMap.put(eventType, ScriptParser.parseScript(jsonObject.getAsJsonArray(eventString)));
}
}
private ItemStack createItemStack(JsonObject jsonObject) {
String type = jsonObject.getAsJsonPrimitive("type").getAsString();
String name = jsonObject.getAsJsonPrimitive("name").getAsString();
int amount = jsonObject.getAsJsonPrimitive("amount").getAsInt();
ItemStack itemStack = new ItemStack(Material.valueOf(type), amount);
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta == null) return itemStack;
itemMeta.setDisplayName(name);
if (jsonObject.has("lore")) {
List<String> lore = new ArrayList<>();
jsonObject.getAsJsonArray("lore").forEach(jsonElement -> {
if (!jsonElement.isJsonPrimitive()) {
return;
}
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);
}
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public void execute(EventType eventType, Entity entity) {
if (!scriptMap.containsKey(eventType)) return;
scriptMap.get(eventType).execute(new RunnableScript.RunnableScriptEvent(eventType, entity));
}
}

Datei anzeigen

@ -0,0 +1,73 @@
/*
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.implemented;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import de.steamwar.misslewars.Config;
import de.steamwar.misslewars.scripts.RunnableScript;
public class DelayScript implements RunnableScript {
private int delayTime = 0;
public DelayScript(JsonObject delay) {
JsonPrimitive jsonPrimitive = delay.getAsJsonPrimitive("time");
if (jsonPrimitive.isString()) {
switch (jsonPrimitive.getAsString().toLowerCase()) {
case "config.mineflytime":
case "config.shiledflytime":
delayTime = Config.ShieldFlyTime;
break;
case "config.endtime":
delayTime = Config.EndTime;
break;
case "config.waitingtime":
delayTime = Config.WaitingTime;
break;
case "config.itemtime":
delayTime = Config.ItemTime;
break;
case "config.platformtime":
delayTime = Config.PlatformTime;
break;
case "tick":
delayTime = 1;
break;
default:
break;
}
} else {
delayTime = jsonPrimitive.getAsInt();
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
try {
Thread.sleep(delayTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return true;
}
}

Datei anzeigen

@ -0,0 +1,82 @@
/*
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.implemented;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.scripts.RunnableScript;
import org.bukkit.Location;
public class FilterScript implements RunnableScript {
private interface Filter {
boolean filter(RunnableScriptEvent runnableScriptEvent);
}
private boolean inverted = false;
private Filter filter = null;
public FilterScript(JsonObject filter) {
switch (filter.getAsJsonPrimitive("filter").getAsString().toLowerCase()) {
case "nearportal":
this.filter = runnableScriptEvent -> {
Location location = runnableScriptEvent.entity.getLocation();
int bz = MissileWars.getBlueTeam().getPortalZ();
int rz = MissileWars.getRedTeam().getPortalZ();
int offset = sign(bz - rz) * 5;
int blockZ = location.getBlockZ();
if (offset > 0) {
if (blockZ > bz - offset) return false;
if (blockZ < rz + offset) return false;
} else {
Review

If Else oder ||?

If Else oder ||?
if (blockZ < bz - offset) return false;
if (blockZ > rz + offset) return false;
}
Review

Selbiges.

Selbiges.
return true;
};
break;
default:
break;
}
if (filter.has("invert")) {
inverted = filter.getAsJsonPrimitive("invert").getAsBoolean();
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (filter == null) return true;
if (inverted) {
return !filter.filter(runnableScriptEvent);
} else {
return filter.filter(runnableScriptEvent);
}
}
private int sign(int i) {
if (i < 0) return -1;
return i > 0 ? 1 : 0;
}
}

Datei anzeigen

@ -0,0 +1,79 @@
/*
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.implemented;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript;
import de.steamwar.misslewars.scripts.ScriptedItem;
import org.bukkit.entity.*;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
public class LaunchScript implements RunnableScript {
private interface Launch {
void launch(RunnableScriptEvent runnableScriptEvent);
}
private Launch launch = null;
public LaunchScript(JsonObject launch) {
switch (launch.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
case "fireball":
this.launch = runnableScriptEvent -> {
Player player = (Player) runnableScriptEvent.entity;
Fireball fireball = player.launchProjectile(Fireball.class);
setVelocity(fireball, launch);
setYield(fireball, launch);
setIncendiary(fireball, launch);
setBounce(fireball, launch);
setGlowing(fireball, launch);
setGravity(fireball, launch);
fireball.setDirection(player.getLocation().getDirection());
};
break;
case "arrow":
this.launch = runnableScriptEvent -> {
Player player = (Player) runnableScriptEvent.entity;
Arrow arrow = player.launchProjectile(Arrow.class);
setVelocity(arrow, launch);
setGlowing(arrow, launch);
setGravity(arrow, launch);
};
break;
default:
break;
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (launch == null) return false;
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
launch.launch(runnableScriptEvent);
return true;
}
}

Datei anzeigen

@ -0,0 +1,100 @@
/*
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.implemented;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.scripts.RunnableScript;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Objects;
public class PasteScript implements RunnableScript {
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
private final Clipboard clipboard;
private final BlockVector3 centeredOffset;
private boolean centered = false;
private boolean ignoreAir = false;
private int xOffset = 0;
private int yOffset = 0;
private int zOffset = 0;
public PasteScript(JsonObject paste) {
String schemFileName = paste.getAsJsonPrimitive("schem").getAsString();
if (!schemFileName.endsWith(".schem")) {
schemFileName += ".schem";
}
File schemFile = new File(MissileWars.getPlugin().getDataFolder(), schemFileName);
try {
clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(schemFile)).getReader(new FileInputStream(schemFile)).read();
} catch (IOException e) {
throw new SecurityException("Could not load shield", 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.
}
centeredOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2));
if (paste.has("centered")) {
centered = paste.getAsJsonPrimitive("centered").getAsBoolean();
}
if (paste.has("ignoreAir")) {
ignoreAir = paste.getAsJsonPrimitive("ignoreAir").getAsBoolean();
}
if (paste.has("offset")) {
JsonArray jsonArray = paste.getAsJsonArray("offset");
if (jsonArray.size() == 3) {
xOffset = jsonArray.get(0).getAsInt();
yOffset = jsonArray.get(1).getAsInt();
zOffset = jsonArray.get(2).getAsInt();
}
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
Location location = runnableScriptEvent.entity.getLocation();
BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
if (centered) {
paste = paste.subtract(centeredOffset);
}
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(ignoreAir).to(paste).build());
editSession.flushSession();
return true;
}
}

Datei anzeigen

@ -0,0 +1,72 @@
/*
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.implemented;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript;
import de.steamwar.misslewars.scripts.ScriptedItem;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class PotionScript implements RunnableScript {
private PotionEffect potionEffect = null;
public PotionScript(JsonObject potion) {
int duration = 1;
int amplifier = 1;
boolean ambient = true;
boolean particles = true;
boolean icon = true;
if (potion.has("duration")) {
duration = potion.getAsJsonPrimitive("duration").getAsInt();
}
if (potion.has("amplifier")) {
amplifier = potion.getAsJsonPrimitive("amplifier").getAsInt();
}
if (potion.has("ambient")) {
ambient = potion.getAsJsonPrimitive("ambient").getAsBoolean();
}
if (potion.has("particles")) {
particles = potion.getAsJsonPrimitive("particles").getAsBoolean();
}
if (potion.has("icon")) {
icon = potion.getAsJsonPrimitive("icon").getAsBoolean();
}
PotionEffectType potionEffectType = PotionEffectType.getByName(potion.getAsJsonPrimitive("potion").getAsString());
if (potionEffectType == null) {
return;
}
potionEffect = new PotionEffect(potionEffectType, duration, amplifier, ambient, particles, icon);
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (potionEffect == null) return false;
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
Player player = (Player) runnableScriptEvent.entity;
player.addPotionEffect(potionEffect);
return true;
}
}

Datei anzeigen

@ -0,0 +1,53 @@
/*
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.implemented;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript;
import de.steamwar.misslewars.scripts.ScriptedItem;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
public class SoundScript implements RunnableScript {
private Sound sound;
private float volume = 100;
private float pitch = 1;
public SoundScript(JsonObject sound) {
this.sound = Sound.valueOf(sound.getAsJsonPrimitive("sound").getAsString());
if (sound.has("volume")) {
volume = sound.getAsJsonPrimitive("volume").getAsFloat();
}
if (sound.has("pitch")) {
pitch = sound.getAsJsonPrimitive("pitch").getAsFloat();
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (sound == null) return false;
if (runnableScriptEvent.eventType != ScriptedItem.EventType.onClick) return true;
Player player = (Player) runnableScriptEvent.entity;
player.playSound(player.getLocation(), sound, volume, pitch);
return true;
}
}

Datei anzeigen

@ -0,0 +1,62 @@
/*
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.implemented;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TNTPrimed;
import static de.steamwar.misslewars.scripts.utils.EntityUtils.*;
public class SummonScript implements RunnableScript {
private interface Summon {
void summon(Entity entity);
}
private Summon summon = null;
public SummonScript(JsonObject summon) {
Review

Warum ist hier dann ein Switch und kein If?

Warum ist hier dann ein Switch und kein If?
Review

Um es später noch zu erweitern

Um es später noch zu erweitern
switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
case "tntprimed":
this.summon = entity -> {
TNTPrimed tnt = entity.getWorld().spawn(entity.getLocation(), TNTPrimed.class);
setYield(tnt, summon);
setIncendiary(tnt, summon);
setFuseTime(tnt, summon);
};
break;
default:
break;
}
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (summon == null) return false;
summon.summon(runnableScriptEvent.entity);
return true;
}
}

Datei anzeigen

@ -0,0 +1,79 @@
/*
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 org.bukkit.entity.Entity;
import org.bukkit.entity.Explosive;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
public class EntityUtils {
public static void setVelocity(Entity entity, JsonObject jsonObject) {
if (jsonObject.has("velocity")) {
double velocity = jsonObject.getAsJsonPrimitive("velocity").getAsDouble();
entity.setVelocity(entity.getVelocity().multiply(velocity));
}
}
public static void setGlowing(Entity entity, JsonObject jsonObject) {
if (jsonObject.has("glowing")) {
boolean incendiary = jsonObject.getAsJsonPrimitive("glowing").getAsBoolean();
entity.setGlowing(incendiary);
}
}
public static void setGravity(Entity entity, JsonObject jsonObject) {
if (jsonObject.has("gravity")) {
boolean incendiary = jsonObject.getAsJsonPrimitive("gravity").getAsBoolean();
entity.setGravity(incendiary);
}
}
public static void setYield(Explosive explosive, JsonObject jsonObject) {
if (jsonObject.has("yield")) {
float yield = jsonObject.getAsJsonPrimitive("yield").getAsFloat();
explosive.setYield(yield);
}
}
public static void setIncendiary(Explosive explosive, JsonObject jsonObject) {
if (jsonObject.has("incendiary")) {
boolean incendiary = jsonObject.getAsJsonPrimitive("incendiary").getAsBoolean();
explosive.setIsIncendiary(incendiary);
}
}
public static void setBounce(Projectile projectile, JsonObject jsonObject) {
if (jsonObject.has("bounce")) {
boolean bounce = jsonObject.getAsJsonPrimitive("bounce").getAsBoolean();
projectile.setBounce(bounce);
}
}
public static void setFuseTime(TNTPrimed tntPrimed, JsonObject jsonObject) {
if (jsonObject.has("fuse")) {
int fuseTime = jsonObject.getAsJsonPrimitive("fuse").getAsInt();
tntPrimed.setFuseTicks(fuseTime);
}
}
}