From e8d3974b81944b28ddc11a756cabd1c9c87ded5a Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 31 Oct 2020 17:59:41 +0100 Subject: [PATCH] Add Support Item softcoded --- src/de/steamwar/misslewars/MissileWars.java | 6 +- src/de/steamwar/misslewars/items/Arrows.java | 39 --------- .../misslewars/items/ExplodingArrows.java | 40 --------- .../steamwar/misslewars/items/Fireball.java | 47 ----------- src/de/steamwar/misslewars/items/Item.java | 83 +++++++++++++++++++ .../steamwar/misslewars/items/LandingPad.java | 79 ------------------ src/de/steamwar/misslewars/items/Mine.java | 39 --------- src/de/steamwar/misslewars/items/Shield.java | 39 --------- .../misslewars/items/SpecialItem.java | 33 ++++++++ .../misslewars/listener/ItemListener.java | 51 ++---------- .../misslewars/scripts/RunnableScript.java | 5 +- .../misslewars/scripts/ScriptedItem.java | 17 ++-- .../scripts/implemented/FilterScript.java | 2 +- .../scripts/implemented/LaunchScript.java | 2 +- .../scripts/implemented/PasteScript.java | 2 +- .../scripts/implemented/SummonScript.java | 9 +- 16 files changed, 145 insertions(+), 348 deletions(-) delete mode 100644 src/de/steamwar/misslewars/items/Arrows.java delete mode 100644 src/de/steamwar/misslewars/items/ExplodingArrows.java delete mode 100644 src/de/steamwar/misslewars/items/Fireball.java create mode 100644 src/de/steamwar/misslewars/items/Item.java delete mode 100644 src/de/steamwar/misslewars/items/LandingPad.java delete mode 100644 src/de/steamwar/misslewars/items/Mine.java delete mode 100644 src/de/steamwar/misslewars/items/Shield.java diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 9cf4913..bd1c699 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -71,11 +71,7 @@ public class MissileWars extends JavaPlugin { FightScoreboard.init(); Missile.init(); - new Arrows(); - new Fireball(); - new Shield(); - new Mine(); - new LandingPad(); + Item.init(); StateDependent.setupState(fightState); } diff --git a/src/de/steamwar/misslewars/items/Arrows.java b/src/de/steamwar/misslewars/items/Arrows.java deleted file mode 100644 index 5b3bdfc..0000000 --- a/src/de/steamwar/misslewars/items/Arrows.java +++ /dev/null @@ -1,39 +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 . -*/ - -package de.steamwar.misslewars.items; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class Arrows extends SpecialItem { - - private final ItemStack item = createItem(Material.ARROW, "§ePfeil", 3); - - @Override - public ItemStack getItem() { - return item; - } - - @Override - public boolean handleUse(Player p) { - return false; - } -} diff --git a/src/de/steamwar/misslewars/items/ExplodingArrows.java b/src/de/steamwar/misslewars/items/ExplodingArrows.java deleted file mode 100644 index ebabcfa..0000000 --- a/src/de/steamwar/misslewars/items/ExplodingArrows.java +++ /dev/null @@ -1,40 +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 . -*/ - -package de.steamwar.misslewars.items; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class ExplodingArrows extends SpecialItem { - - private final ItemStack item = createItem(Material.SPECTRAL_ARROW, "§eExplodierender Pfeil", 1); - - @Override - public ItemStack getItem() { - return item; - } - - @Override - public boolean handleUse(Player p) { - return false; - } - -} diff --git a/src/de/steamwar/misslewars/items/Fireball.java b/src/de/steamwar/misslewars/items/Fireball.java deleted file mode 100644 index 2fb7d75..0000000 --- a/src/de/steamwar/misslewars/items/Fireball.java +++ /dev/null @@ -1,47 +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 . -*/ - -package de.steamwar.misslewars.items; - -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class Fireball extends SpecialItem { - - private final ItemStack item = createItem(Material.FIRE_CHARGE, "§eFeuerball", 1); - - @Override - public ItemStack getItem() { - return item; - } - - @Override - public boolean handleUse(Player p) { - org.bukkit.entity.Fireball fb = p.launchProjectile(org.bukkit.entity.Fireball.class); - fb.setVelocity(fb.getVelocity().multiply(2)); - fb.setDirection(p.getLocation().getDirection()); - p.playSound(p.getLocation(), Sound.ITEM_FIRECHARGE_USE, 100, 1); - fb.setIsIncendiary(true); - fb.setBounce(false); - fb.setYield(3f); - return true; - } -} diff --git a/src/de/steamwar/misslewars/items/Item.java b/src/de/steamwar/misslewars/items/Item.java new file mode 100644 index 0000000..513913a --- /dev/null +++ b/src/de/steamwar/misslewars/items/Item.java @@ -0,0 +1,83 @@ +/* + 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 . +*/ + +package de.steamwar.misslewars.items; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; +import de.steamwar.misslewars.MissileWars; +import de.steamwar.misslewars.scripts.ScriptedItem; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Objects; + +public class Item extends SpecialItem { + + private ScriptedItem scriptedItem; + + public Item(File item) { + try { + JsonObject jsonObject = new JsonParser().parse(new FileReader(item)).getAsJsonObject(); + scriptedItem = new ScriptedItem(jsonObject); + } catch (JsonSyntaxException e) { + throw new SecurityException("Item JSON error"); + } catch (IOException e) { + throw new SecurityException("Corrupt Item"); + } + } + + @Override + public ItemStack getItem() { + return scriptedItem.getItemStack(); + } + + @Override + public boolean handleUse(Player p) { + return scriptedItem.execute(ScriptedItem.EventType.onClick, p, p.getLocation()); + } + + @Override + public void handleThrow(Entity e) { + scriptedItem.execute(ScriptedItem.EventType.onThrow, e, e.getLocation()); + } + + @Override + public void handleHit(Entity e, Location l) { + scriptedItem.execute(ScriptedItem.EventType.onHit, e, l); + } + + public static void init() { + File itemsFolder = new File(MissileWars.getPlugin().getDataFolder(), "items"); + if (!itemsFolder.exists() || !itemsFolder.canRead() || !itemsFolder.isDirectory()) { + throw new SecurityException("Items could not be loaded"); + } + for (File itemFile : Objects.requireNonNull(itemsFolder.listFiles())) { + if (!itemFile.canRead() || !itemFile.isFile()) continue; + new Item(itemFile); + } + } + +} diff --git a/src/de/steamwar/misslewars/items/LandingPad.java b/src/de/steamwar/misslewars/items/LandingPad.java deleted file mode 100644 index db7e781..0000000 --- a/src/de/steamwar/misslewars/items/LandingPad.java +++ /dev/null @@ -1,79 +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 . -*/ - -package de.steamwar.misslewars.items; - -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 org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Objects; - -public class LandingPad extends SpecialItem { - - private final ItemStack item = createItem(Material.SLIME_BALL, "§aLanding Pad", 1); - private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); - private static final File landingPad = new File(MissileWars.getPlugin().getDataFolder(), "landingPad.schem"); - private final Clipboard clipboard; - private final BlockVector3 offset; - - { - try { - clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(landingPad)).getReader(new FileInputStream(landingPad)).read(); - } catch (IOException e) { - throw new SecurityException("Could not load landingPad", e); - } - - offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2)); - } - - @Override - public ItemStack getItem() { - return item; - } - - @Override - public boolean handleUse(Player p) { - p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 2, 1, false, false, false)); - Location l = p.getLocation(); - BlockVector3 paste = BlockVector3.at(l.getX(), l.getY() - 5, l.getZ()).subtract(offset); - - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); - Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); - editSession.flushSession(); - return true; - } -} diff --git a/src/de/steamwar/misslewars/items/Mine.java b/src/de/steamwar/misslewars/items/Mine.java deleted file mode 100644 index f87d9a1..0000000 --- a/src/de/steamwar/misslewars/items/Mine.java +++ /dev/null @@ -1,39 +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 . -*/ - -package de.steamwar.misslewars.items; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class Mine extends SpecialItem { - - private final ItemStack item = createItem(Material.EGG, "§eMine", 1); - - @Override - public ItemStack getItem() { - return item; - } - - @Override - public boolean handleUse(Player p) { - return false; - } -} diff --git a/src/de/steamwar/misslewars/items/Shield.java b/src/de/steamwar/misslewars/items/Shield.java deleted file mode 100644 index b954660..0000000 --- a/src/de/steamwar/misslewars/items/Shield.java +++ /dev/null @@ -1,39 +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 . -*/ - -package de.steamwar.misslewars.items; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -public class Shield extends SpecialItem { - - private final ItemStack item = createItem(Material.SNOWBALL, "§aSchild", 1); - - @Override - public ItemStack getItem() { - return item; - } - - @Override - public boolean handleUse(Player p) { - return false; - } -} diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index d32fdae..24ad493 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -20,8 +20,12 @@ package de.steamwar.misslewars.items; import de.steamwar.misslewars.Config; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -41,12 +45,16 @@ public abstract class SpecialItem { if (this.isMissile()) { missileItems.add(this); } else { + materialName = getItem().getType().name().toLowerCase(); supportItems.add(this); } } + private String materialName = ""; public abstract ItemStack getItem(); public abstract boolean handleUse(Player p); + public void handleThrow(Entity e) {} + public void handleHit(Entity e, Location l) {} public boolean isMissile() { return false; } @@ -77,6 +85,31 @@ public abstract class SpecialItem { return false; } + public static void handleThrow(ProjectileLaunchEvent e) { + String name = e.getEntity().getClass().getName().toLowerCase(); + for (SpecialItem specialItem : supportItems) { + if (name.contains(specialItem.materialName)) { + specialItem.handleThrow(e.getEntity()); + } + } + } + + public static void handleHit(ProjectileHitEvent e) { + String name = e.getEntity().getClass().getName().toLowerCase(); + Location location = null; + if (e.getHitEntity() != null) { + location = e.getHitEntity().getLocation(); + } else if (e.getHitBlock() != null) { + location = e.getHitBlock().getLocation(); + } + if (location == null) return; + for (SpecialItem specialItem : supportItems) { + if (name.contains(specialItem.materialName)) { + specialItem.handleHit(e.getEntity(), location); + } + } + } + public static ItemStack getRandomItem() { if (random.nextDouble() > Config.MissileChance) { return supportItems.get(random.nextInt(supportItems.size())).getItem(); diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java index bb9032a..0545df2 100644 --- a/src/de/steamwar/misslewars/listener/ItemListener.java +++ b/src/de/steamwar/misslewars/listener/ItemListener.java @@ -38,6 +38,7 @@ 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; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; @@ -86,10 +87,10 @@ public class ItemListener extends BasicListener { if (item == null) return; - if(e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) + if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return; - if(SpecialItem.handleUse(item, e.getPlayer())){ + if (SpecialItem.handleUse(item, e.getPlayer())){ item.setAmount(item.getAmount()-1); e.getPlayer().updateInventory(); e.setCancelled(true); @@ -98,50 +99,12 @@ public class ItemListener extends BasicListener { @EventHandler public void onThrow(ProjectileLaunchEvent e) { - if (e.getEntity() instanceof Snowball) { - Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> { - Location l = e.getEntity().getLocation(); - if (!validSpawn(l)) return; - BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetShield); - - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); - Operations.completeBlindly(new ClipboardHolder(clipboardShield).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); - editSession.flushSession(); - }, Config.ShieldFlyTime); - } - if (e.getEntity() instanceof Egg) { - Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> { - Location l = e.getEntity().getLocation(); - if (!validSpawn(l)) return; - BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetMine); - - EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); - Operations.completeBlindly(new ClipboardHolder(clipboardMine).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); - editSession.flushSession(); - }, Config.ShieldFlyTime); - } + SpecialItem.handleThrow(e); } - private boolean validSpawn(Location location) { - 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 { - if (blockZ < bz - offset) return false; - if (blockZ > rz + offset) return false; - } - return true; - } - - private int sign(int i) { - if (i < 0) return -1; - return i > 0 ? 1 : 0; + @EventHandler + public void onHit(ProjectileHitEvent e) { + SpecialItem.handleHit(e); } } diff --git a/src/de/steamwar/misslewars/scripts/RunnableScript.java b/src/de/steamwar/misslewars/scripts/RunnableScript.java index 1ae8fd2..ca4e4ee 100644 --- a/src/de/steamwar/misslewars/scripts/RunnableScript.java +++ b/src/de/steamwar/misslewars/scripts/RunnableScript.java @@ -19,6 +19,7 @@ package de.steamwar.misslewars.scripts; +import org.bukkit.Location; import org.bukkit.entity.Entity; public interface RunnableScript { @@ -27,10 +28,12 @@ public interface RunnableScript { public final ScriptedItem.EventType eventType; public final Entity entity; + public final Location location; - public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity) { + public RunnableScriptEvent(ScriptedItem.EventType eventType, Entity entity, Location location) { this.eventType = eventType; this.entity = entity; + this.location = location; } } diff --git a/src/de/steamwar/misslewars/scripts/ScriptedItem.java b/src/de/steamwar/misslewars/scripts/ScriptedItem.java index c256c04..6c13ac6 100644 --- a/src/de/steamwar/misslewars/scripts/ScriptedItem.java +++ b/src/de/steamwar/misslewars/scripts/ScriptedItem.java @@ -21,15 +21,13 @@ package de.steamwar.misslewars.scripts; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import org.bukkit.Location; 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; +import java.util.*; public class ScriptedItem { @@ -94,9 +92,14 @@ public class ScriptedItem { return itemStack; } - public void execute(EventType eventType, Entity entity) { - if (!scriptMap.containsKey(eventType)) return; - scriptMap.get(eventType).execute(new RunnableScript.RunnableScriptEvent(eventType, entity)); + public boolean execute(EventType eventType, Entity entity, Location location) { + if (!scriptMap.containsKey(eventType)) return false; + scriptMap.get(eventType).execute(new RunnableScript.RunnableScriptEvent(eventType, entity, location)); + return true; + } + + public ItemStack getItemStack() { + return itemStack; } } diff --git a/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java b/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java index 50246d5..f0a80a7 100644 --- a/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java +++ b/src/de/steamwar/misslewars/scripts/implemented/FilterScript.java @@ -39,7 +39,7 @@ public class FilterScript implements RunnableScript { switch (filter.getAsJsonPrimitive("filter").getAsString().toLowerCase()) { case "nearportal": this.filter = runnableScriptEvent -> { - Location location = runnableScriptEvent.entity.getLocation(); + Location location = runnableScriptEvent.location; int bz = MissileWars.getBlueTeam().getPortalZ(); int rz = MissileWars.getRedTeam().getPortalZ(); diff --git a/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java b/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java index 1af6fe4..3215f30 100644 --- a/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java +++ b/src/de/steamwar/misslewars/scripts/implemented/LaunchScript.java @@ -50,7 +50,7 @@ public class LaunchScript implements RunnableScript { setGlowing(fireball, launch); setGravity(fireball, launch); - fireball.setDirection(player.getLocation().getDirection()); + fireball.setDirection(runnableScriptEvent.location.getDirection()); }; break; case "arrow": diff --git a/src/de/steamwar/misslewars/scripts/implemented/PasteScript.java b/src/de/steamwar/misslewars/scripts/implemented/PasteScript.java index 742d0a4..92d7fa7 100644 --- a/src/de/steamwar/misslewars/scripts/implemented/PasteScript.java +++ b/src/de/steamwar/misslewars/scripts/implemented/PasteScript.java @@ -85,7 +85,7 @@ public class PasteScript implements RunnableScript { @Override public boolean execute(RunnableScriptEvent runnableScriptEvent) { - Location location = runnableScriptEvent.entity.getLocation(); + Location location = runnableScriptEvent.location; BlockVector3 paste = BlockVector3.at(location.getX() + xOffset, location.getY() + yOffset, location.getZ() + zOffset); if (centered) { paste = paste.subtract(centeredOffset); diff --git a/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java b/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java index 7af36af..c650ce5 100644 --- a/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java +++ b/src/de/steamwar/misslewars/scripts/implemented/SummonScript.java @@ -21,7 +21,6 @@ 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.*; @@ -30,7 +29,7 @@ public class SummonScript implements RunnableScript { private interface Summon { - void summon(Entity entity); + void summon(RunnableScriptEvent event); } @@ -39,8 +38,8 @@ public class SummonScript implements RunnableScript { public SummonScript(JsonObject summon) { switch (summon.getAsJsonPrimitive("entity").getAsString().toLowerCase()) { case "tntprimed": - this.summon = entity -> { - TNTPrimed tnt = entity.getWorld().spawn(entity.getLocation(), TNTPrimed.class); + this.summon = runnableScriptEvent -> { + TNTPrimed tnt = runnableScriptEvent.entity.getWorld().spawn(runnableScriptEvent.location, TNTPrimed.class); setYield(tnt, summon); setIncendiary(tnt, summon); @@ -55,7 +54,7 @@ public class SummonScript implements RunnableScript { @Override public boolean execute(RunnableScriptEvent runnableScriptEvent) { if (summon == null) return false; - summon.summon(runnableScriptEvent.entity); + summon.summon(runnableScriptEvent); return true; }