From 80cf8d329039a3547268f9fefb729b76a78078cc Mon Sep 17 00:00:00 2001 From: Soper Date: Mon, 10 May 2021 10:16:20 -0400 Subject: [PATCH] added explosion testing --- src/xyz/soper/arty/debug/DebugCommand.java | 11 ++++++++++- .../soper/arty/event/Listener/MortarInteract.java | 15 +++++++++++++++ src/xyz/soper/arty/item/Shell.java | 2 +- src/xyz/soper/arty/util/MortarHandler.java | 6 ++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/xyz/soper/arty/debug/DebugCommand.java b/src/xyz/soper/arty/debug/DebugCommand.java index 225c8b3..06aa6f3 100644 --- a/src/xyz/soper/arty/debug/DebugCommand.java +++ b/src/xyz/soper/arty/debug/DebugCommand.java @@ -36,6 +36,15 @@ public class DebugCommand implements TabExecutor, Listener { } else if(args[0].equalsIgnoreCase("getVector")){ player.sendMessage(ChatColor.GOLD + "Your current facing vector is: " + player.getLocation().getDirection()); + return true; + } + else if(args[0].equalsIgnoreCase("explode")){ + player.getWorld().createExplosion(player.getLocation(), + (float)Double.parseDouble(args[1]), + false, + Boolean.parseBoolean(args[2]), + player); + return true; } else player.sendMessage(ChatColor.RED + "Incorrect usage. This command does not exist."); } @@ -45,7 +54,7 @@ public class DebugCommand implements TabExecutor, Listener { @Override public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { if(args.length != 1) return null; - return Arrays.asList("fire", "getVector"); + return Arrays.asList("fire", "getVector", "explode"); } @EventHandler diff --git a/src/xyz/soper/arty/event/Listener/MortarInteract.java b/src/xyz/soper/arty/event/Listener/MortarInteract.java index 87af679..697a94b 100644 --- a/src/xyz/soper/arty/event/Listener/MortarInteract.java +++ b/src/xyz/soper/arty/event/Listener/MortarInteract.java @@ -4,10 +4,12 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Nameable; import org.bukkit.block.Block; +import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -48,4 +50,17 @@ public class MortarInteract implements Listener { } } } + + public void onShellLand(ProjectileHitEvent event){ + if(event.getEntity() instanceof Arrow + && event.getEntity().getCustomName() != null + && event.getEntity().getCustomName().equals("shell")){ + if(event.getHitBlock() != null){ + event.getHitBlock().getWorld().createExplosion(event.getHitBlock().getLocation(), 2.5F, false, true); + } + else if(event.getHitEntity() != null){ + + } + } + } } diff --git a/src/xyz/soper/arty/item/Shell.java b/src/xyz/soper/arty/item/Shell.java index 4acc69c..c765c0b 100644 --- a/src/xyz/soper/arty/item/Shell.java +++ b/src/xyz/soper/arty/item/Shell.java @@ -15,7 +15,7 @@ public class Shell { public double failChance = .01; public Shell(){ - + //TODO: Create default constructor } public Shell(ItemStack shell){ diff --git a/src/xyz/soper/arty/util/MortarHandler.java b/src/xyz/soper/arty/util/MortarHandler.java index 318cb84..a9b5b3a 100644 --- a/src/xyz/soper/arty/util/MortarHandler.java +++ b/src/xyz/soper/arty/util/MortarHandler.java @@ -1,5 +1,6 @@ package xyz.soper.arty.util; +import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; @@ -19,11 +20,12 @@ public class MortarHandler { public void fireShell(Shell shell, ProjectileSource shooter){ Vector debugVector = new Vector(1, 1, 0).normalize(); mortar.getBlock().getWorld().playSound(mortar.location, "entity.generic.explode", 1, 1.5F); - Arrow shellProjectile = mortar.getBlock().getWorld().spawn(mortar.getBlock().getLocation(), Arrow.class); + Location mortarLocation = mortar.getBlock().getLocation().add(.5, 1, .5); + Arrow shellProjectile = mortar.getBlock().getWorld().spawn(mortarLocation, Arrow.class); shellProjectile.setVelocity(debugVector.multiply(shell.baseVelocity)); shellProjectile.setShooter(shooter); shellProjectile.setCustomName("shell"); - mortar.getBlock().getWorld().spawnParticle(Particle.SMOKE_NORMAL, mortar.location, 500, 0, 0, 0, .5); + mortar.getBlock().getWorld().spawnParticle(Particle.SMOKE_NORMAL, mortarLocation, 500, 0, 0, 0, .5); if(shooter instanceof Player) ((Player) shooter).sendMessage("Shell fired with a velocity " + shell.baseVelocity); } } \ No newline at end of file