From d48d1451112f2a80657be6bcff99eb63f4b0b060 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Tue, 20 Dec 2016 06:33:49 -0500 Subject: [PATCH] More work on the Cannon Bow #37 Settings now savable TNT is now owned by a player --- config.yml | 6 ++++- pom.xml | 2 +- .../components/magic/MagicComponent.java | 2 +- .../magic/tricks/CannonBowListener.java | 25 ++++++++++++++++--- .../magic/tricks/CannonBowSettings.java | 12 ++++++--- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/config.yml b/config.yml index c3cfef7..9fd8419 100644 --- a/config.yml +++ b/config.yml @@ -1 +1,5 @@ -UHCMatchState: "IDLE" \ No newline at end of file +UHCMatchState: "IDLE" +magic: + cannonbow: + speedmultiplier: 1.5 + minforce: 0.2 \ No newline at end of file diff --git a/pom.xml b/pom.xml index ab68ed4..d21b76e 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ org.spigotmc - spigot-api + spigot 1.11-R0.1-SNAPSHOT diff --git a/src/buttondevteam/alipresents/components/magic/MagicComponent.java b/src/buttondevteam/alipresents/components/magic/MagicComponent.java index 228d82b..8aa4b27 100644 --- a/src/buttondevteam/alipresents/components/magic/MagicComponent.java +++ b/src/buttondevteam/alipresents/components/magic/MagicComponent.java @@ -10,7 +10,7 @@ import buttondevteam.alipresents.components.magic.tricks.CannonBowListener; import buttondevteam.alipresents.components.magic.tricks.CannonBowSettings; public class MagicComponent extends Component{ - + @Override public void register(JavaPlugin plugin) { registerCommand(plugin, new CannonBowSettings()); diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index 719f3fd..163e9b9 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -1,9 +1,13 @@ package buttondevteam.alipresents.components.magic.tricks; +import java.lang.reflect.Field; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.v1_11_R1.entity.CraftTNTPrimed; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Arrow; import org.bukkit.entity.EntityType; @@ -17,13 +21,16 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import net.minecraft.server.v1_11_R1.EntityLiving; +import net.minecraft.server.v1_11_R1.EntityTNTPrimed; + public class CannonBowListener implements Listener { public static double SpeedMultiplier = 1.5; public static double minforce = 0.2; public final static String launchedTNTName = "CANNON BOW TNT:42170"; - JavaPlugin plugin; public CannonBowListener(JavaPlugin plugin){ - this.plugin = plugin; + SpeedMultiplier = plugin.getConfig().getDouble("magic.cannonbow.speedmultiplier"); + minforce = plugin.getConfig().getDouble("magic.cannonbow.minforce"); } @EventHandler @@ -55,6 +62,18 @@ public class CannonBowListener implements Listener { }else{ TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); + + // Change via NMS the source of the TNT by the player + EntityLiving nmsPlayer = (EntityLiving) (((CraftLivingEntity) player).getHandle()); + EntityTNTPrimed nmsTNT = (EntityTNTPrimed) (((CraftTNTPrimed) tnt).getHandle()); + try { + Field sourceField = EntityTNTPrimed.class.getDeclaredField("source"); + sourceField.setAccessible(true); + sourceField.set(nmsTNT, nmsPlayer); + } catch (Exception ex) { + ex.printStackTrace(); + } + tnt.setVelocity(playerVector.multiply(SpeedMultiplier).multiply(event.getForce())); tnt.setCustomName(launchedTNTName); @@ -62,7 +81,7 @@ public class CannonBowListener implements Listener { //Player Recoil player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1)); - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2.0F, 0); + player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0); player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2); } diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java index e657375..d081bd3 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java @@ -6,15 +6,21 @@ import org.bukkit.entity.Player; import buttondevteam.alipresents.architecture.commands.ModCommand; public class CannonBowSettings extends ModCommand { - + @Override public boolean OnCommand(Player player, String alias, String[] args) { switch(args[0].toLowerCase()){ case "speedmultiplier": - CannonBowListener.SpeedMultiplier = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); + double speedMultiplier = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); + CannonBowListener.SpeedMultiplier = speedMultiplier; + this.getPlugin().getConfig().set("magic.cannonbow.speedmultiplier", speedMultiplier); + this.getPlugin().saveConfig(); break; case "minforce": - CannonBowListener.minforce = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); + double minforce = NumberUtils.toDouble(args[1], CannonBowListener.minforce); + CannonBowListener.minforce = minforce; + this.getPlugin().getConfig().set("magic.cannonbow.minforce", minforce); + this.getPlugin().saveConfig(); break; default: player.sendMessage("That isn't a valid setting!");