SteamWar/MissileWars
Archiviert
13
0

Add Support Item softcoded

Dieser Commit ist enthalten in:
jojo 2020-10-31 21:57:03 +01:00
Ursprung e8d3974b81
Commit 6f1ab2be8b
16 geänderte Dateien mit 111 neuen und 206 gelöschten Zeilen

Datei anzeigen

@ -60,7 +60,6 @@ public class MissileWars extends JavaPlugin {
new PortalDestructListener();
new WaitingListener();
new FightListener();
new ArrowListener();
new ChatListener();
getCommand("spectate").setExecutor(new CommandSpectate());

Datei anzeigen

@ -41,10 +41,13 @@ public class Item extends SpecialItem {
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");
}
}
@ -80,4 +83,8 @@ public class Item extends SpecialItem {
}
}
public ScriptedItem getScriptedItem() {
return scriptedItem;
}
}

Datei anzeigen

@ -45,12 +45,11 @@ public abstract class SpecialItem {
if (this.isMissile()) {
missileItems.add(this);
} else {
materialName = getItem().getType().name().toLowerCase();
supportItems.add(this);
}
}
private String materialName = "";
private String materialName = null;
public abstract ItemStack getItem();
public abstract boolean handleUse(Player p);
public void handleThrow(Entity e) {}
@ -88,6 +87,9 @@ public abstract class SpecialItem {
public static void handleThrow(ProjectileLaunchEvent e) {
String name = e.getEntity().getClass().getName().toLowerCase();
for (SpecialItem specialItem : supportItems) {
if (specialItem.materialName == null) {
specialItem.materialName = specialItem.getItem().getType().name().toLowerCase();
}
if (name.contains(specialItem.materialName)) {
specialItem.handleThrow(e.getEntity());
}
@ -96,6 +98,7 @@ public abstract class SpecialItem {
public static void handleHit(ProjectileHitEvent e) {
String name = e.getEntity().getClass().getName().toLowerCase();
Location location = null;
if (e.getHitEntity() != null) {
location = e.getHitEntity().getLocation();
@ -103,8 +106,9 @@ public abstract class SpecialItem {
location = e.getHitBlock().getLocation();
}
if (location == null) return;
for (SpecialItem specialItem : supportItems) {
if (name.contains(specialItem.materialName)) {
if (name.contains(((Item) specialItem).getScriptedItem().getEntityName())) {
specialItem.handleHit(e.getEntity(), location);
}
}

Datei anzeigen

@ -1,68 +0,0 @@
[
{
"type": "ARROW",
"name": "§ePfeil",
"lore": [],
"amount": 3,
"EVENT.onThrow": [
],
"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

@ -1,64 +0,0 @@
/*
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.listener;
import de.steamwar.misslewars.FightState;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.ProjectileHitEvent;
import java.util.EnumSet;
public class ArrowListener extends BasicListener {
public ArrowListener() {
super(EnumSet.of(FightState.FIGHTING));
}
@EventHandler
public void onHit(ProjectileHitEvent e) {
Projectile projectile = e.getEntity();
if (projectile.getType() != EntityType.SPECTRAL_ARROW) {
return;
}
Location location = getLocation(e);
if (location == null) return;
TNTPrimed tnt = e.getEntity().getWorld().spawn(location, TNTPrimed.class);
tnt.setYield(2.0F);
tnt.setIsIncendiary(false);
tnt.setFuseTicks(0);
}
private Location getLocation(ProjectileHitEvent e) {
if (e.getHitEntity() != null) {
return e.getHitEntity().getLocation();
}
if (e.getHitBlock() != null) {
return e.getHitBlock().getLocation();
}
return null;
}
}

Datei anzeigen

@ -19,23 +19,8 @@
package de.steamwar.misslewars.listener;
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.Config;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.items.SpecialItem;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Egg;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileHitEvent;
@ -43,40 +28,10 @@ import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.EnumSet;
import java.util.Objects;
public class ItemListener extends BasicListener {
private static final File shield = new File(MissileWars.getPlugin().getDataFolder(), "shield.schem");
private static final File mine = new File(MissileWars.getPlugin().getDataFolder(), "mine.schem");
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
private static final Clipboard clipboardShield;
private static final BlockVector3 offsetShield;
private static final Clipboard clipboardMine;
private static final BlockVector3 offsetMine;
static {
try {
clipboardShield = Objects.requireNonNull(ClipboardFormats.findByFile(shield)).getReader(new FileInputStream(shield)).read();
} catch (IOException e) {
throw new SecurityException("Could not load shield", e);
}
try {
clipboardMine = Objects.requireNonNull(ClipboardFormats.findByFile(mine)).getReader(new FileInputStream(mine)).read();
} catch (IOException e) {
throw new SecurityException("Could not load mine", e);
}
offsetShield = clipboardShield.getRegion().getMinimumPoint().subtract(clipboardShield.getOrigin()).add(clipboardShield.getDimensions().divide(2));
offsetMine = clipboardMine.getRegion().getMinimumPoint().subtract(clipboardMine.getOrigin()).add(clipboardMine.getDimensions().divide(2));
}
public ItemListener() {
super(EnumSet.of(FightState.FIGHTING));
}

Datei anzeigen

@ -28,7 +28,7 @@ public interface RunnableScript {
public final ScriptedItem.EventType eventType;
public final Entity entity;
public final Location location;
private final Location location;
public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) {
this.eventType = eventType;
@ -36,6 +36,14 @@ public interface RunnableScript {
this.location = location;
}
public Location getLocation() {
if (eventType == ScriptedItem.EventType.onClick) return location;
if (entity != null) {
return entity.getLocation();
}
return location;
}
}
boolean execute(RunnableScriptEvent runnableScriptEvent);

Datei anzeigen

@ -20,8 +20,8 @@
package de.steamwar.misslewars.scripts;
import de.steamwar.misslewars.MissileWars;
import de.steamwar.misslewars.scripts.implemented.DelayScript;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
@ -30,20 +30,55 @@ 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)) {
private class ScriptExecutor {
private int index = 0;
private final RunnableScript.RunnableScriptEvent runnableScriptEvent;
public ScriptExecutor(RunnableScript.RunnableScriptEvent runnableScriptEvent) {
this.runnableScriptEvent = runnableScriptEvent;
}
public void start() {
resume();
}
private void resume() {
while (index < runnableScriptList.size()) {
RunnableScript runnableScript = runnableScriptList.get(index);
if (runnableScript instanceof DelayScript) {
index++;
resumeLater(((DelayScript) runnableScript).getDelayTime());
break;
}
i++;
if (!runnableScript.execute(runnableScriptEvent)) {
index = runnableScriptList.size();
return;
}
index++;
}
}, 0);
}
private void resumeLater(int delayTime) {
Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::resume, delayTime);
}
}
public void execute(RunnableScript.RunnableScriptEvent runnableScriptEvent) {
new ScriptExecutor(runnableScriptEvent).start();
}
public void add(RunnableScript runnableScript) {
runnableScriptList.add(runnableScript);
}
@Override
public String toString() {
return "Script{" +
"runnableScriptList=" + runnableScriptList +
'}';
}
}

Datei anzeigen

@ -28,7 +28,6 @@ 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);
@ -46,6 +45,8 @@ public class ScriptParser {
return new DelayScript(jsonObject);
case "filter":
return new FilterScript(jsonObject);
case "remove":
return new RemoveScript(jsonObject);
case "launch":
return new LaunchScript(jsonObject);
case "paste":

Datei anzeigen

@ -53,12 +53,17 @@ public class ScriptedItem {
}
private Map<EventType, Script> scriptMap = new HashMap<>();
private String entityName = "---";
private ItemStack itemStack;
public ScriptedItem(JsonObject jsonObject) {
itemStack = createItemStack(jsonObject);
if (jsonObject.has("entityName")) {
entityName = jsonObject.get("entityName").getAsString();
}
for (EventType eventType : EventType.values()) {
String eventString = "EVENT." + eventType.name();
if (!jsonObject.has(eventString)) continue;
@ -102,4 +107,8 @@ public class ScriptedItem {
return itemStack;
}
public String getEntityName() {
return entityName;
}
}

Datei anzeigen

@ -33,7 +33,7 @@ public class DelayScript implements RunnableScript {
if (jsonPrimitive.isString()) {
switch (jsonPrimitive.getAsString().toLowerCase()) {
case "config.mineflytime":
case "config.shiledflytime":
case "config.shieldflytime":
delayTime = Config.ShieldFlyTime;
break;
case "config.endtime":
@ -62,12 +62,11 @@ public class DelayScript implements RunnableScript {
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
try {
Thread.sleep(delayTime);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return true;
}
public int getDelayTime() {
return delayTime;
}
}

Datei anzeigen

@ -39,7 +39,7 @@ public class FilterScript implements RunnableScript {
switch (filter.getAsJsonPrimitive("filter").getAsString().toLowerCase()) {
case "nearportal":
this.filter = runnableScriptEvent -> {
Location location = runnableScriptEvent.location;
Location location = runnableScriptEvent.getLocation();
int bz = MissileWars.getBlueTeam().getPortalZ();
int rz = MissileWars.getRedTeam().getPortalZ();
@ -47,13 +47,13 @@ public class FilterScript implements RunnableScript {
int blockZ = location.getBlockZ();
if (offset > 0) {
if (blockZ > bz - offset) return false;
if (blockZ < rz + offset) return false;
if (blockZ > bz - offset) return true;
if (blockZ < rz + offset) return true;
} else {
if (blockZ < bz - offset) return false;
if (blockZ > rz + offset) return false;
if (blockZ < bz - offset) return true;
if (blockZ > rz + offset) return true;
}
return true;
return false;
};
break;
default:

Datei anzeigen

@ -50,7 +50,7 @@ public class LaunchScript implements RunnableScript {
setGlowing(fireball, launch);
setGravity(fireball, launch);
fireball.setDirection(runnableScriptEvent.location.getDirection());
fireball.setDirection(runnableScriptEvent.getLocation().getDirection());
};
break;
case "arrow":

Datei anzeigen

@ -85,7 +85,7 @@ public class PasteScript implements RunnableScript {
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
Location location = runnableScriptEvent.location;
Location location = runnableScriptEvent.getLocation();
BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset);
if (centered) {
paste = paste.subtract(centeredOffset);

Datei anzeigen

@ -0,0 +1,20 @@
package de.steamwar.misslewars.scripts.implemented;
import com.google.gson.JsonObject;
import de.steamwar.misslewars.scripts.RunnableScript;
import org.bukkit.entity.Player;
public class RemoveScript implements RunnableScript {
public RemoveScript(JsonObject jsonObject) {
}
@Override
public boolean execute(RunnableScriptEvent runnableScriptEvent) {
if (runnableScriptEvent.entity instanceof Player) return true;
runnableScriptEvent.entity.remove();
return true;
}
}

Datei anzeigen

@ -39,7 +39,7 @@ public class SummonScript implements RunnableScript {
switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) {
case "tntprimed":
this.summon = runnableScriptEvent -> {
TNTPrimed tnt = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.location, TNTPrimed.class);
TNTPrimed tnt = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.getLocation(), TNTPrimed.class);
setYield(tnt, summon);
setIncendiary(tnt, summon);