From 7d012bb9ec1a8a746465fe18cda6d6ee5acfad7f Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Sat, 24 Dec 2016 02:15:02 -0500 Subject: [PATCH] Added isDestructive setting --- .../magic/tricks/CannonBowListener.java | 214 +++++++++++++----- .../magic/tricks/CannonBowSettings.java | 11 +- 2 files changed, 164 insertions(+), 61 deletions(-) diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index 3bf6f60..85dbd81 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -4,6 +4,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Arrow; @@ -19,55 +20,87 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; public class CannonBowListener implements Listener { - private static double SpeedMultiplier = 1.5; - private static double minforce = 0.2; - private static int fuseticks = 40; - private static double recoil = 1; + + private static double maxSpeedMultiplier = 4; + private static double minSpeedMultiplier = 0; + private static double defaultSpeedMultiplier = 1; + private static String speedMultiplierPath = "magic.cannonbow.speedmultiplier"; + + private static int maxFuseTicks = 400; + private static int minFuseTicks = 0; + private static int defaultFuseTicks = 30; + private static String fuseTicksPath = "magic.cannonbow.fuseticks"; + + private static double maxMinForce = 1; + private static double minMinForce = 0; + private static double defaultMinForce = 0.2; + private static String minForcePath = "magic.cannonbow.minforce"; + + private static double maxRecoil = 20; + private static double minRecoil = -5; + private static double defaultRecoil = 1; + private static String recoilPath = "magic.cannonbow.recoil"; + + private static boolean defaultIsDestructive = false; + private static String isDestructivePath = "magic.cannonbow.isdestructive"; + + private static double speedMultiplier = defaultSpeedMultiplier; + private static double minForce = defaultMinForce; + private static int fuseTicks = defaultFuseTicks; + private static double recoil = defaultRecoil; + private static boolean isDestructive = defaultIsDestructive; + public final static String launchedTNTName = "CANNON BOW TNT:42170"; + + static FileConfiguration config; public CannonBowListener(JavaPlugin plugin){ - FileConfiguration config = plugin.getConfig(); - - if (config.isDouble("magic.cannonbow.speedmultiplier")) - setSpeedMultiplier(config.getDouble("magic.cannonbow.speedmultiplier")); - - if (config.isDouble("magic.cannonbow.minforce")) - setMinforce(config.getDouble("magic.cannonbow.minforce")); - - if (config.isInt("magic.cannonbow.fuseticks")) - setFuseticks(config.getInt("magic.cannonbow.fuseticks")); - - if (config.isDouble("magic.cannonbow.recoil")) - setRecoil(config.getDouble("magic.cannonbow.recoil")); + config = plugin.getConfig(); + + if (config.isDouble(speedMultiplierPath)) + setSpeedMultiplier(config.getDouble(speedMultiplierPath)); + + if (config.isDouble(minForcePath)) + setMinforce(config.getDouble(minForcePath)); + + if (config.isInt(fuseTicksPath)) + setFuseticks(config.getInt(fuseTicksPath)); + + if (config.isDouble(recoilPath)) + setRecoil(config.getDouble(recoilPath)); + + if (config.isBoolean(isDestructivePath)) + setIsDestructive(config.getBoolean(isDestructivePath)); } - + @EventHandler public void onProjectileLaunch(EntityShootBowEvent event){ //Entity Sanitation if(event.getProjectile().getType() != EntityType.ARROW)return; - + //Arrow Sanitation Arrow arrow = (Arrow) event.getProjectile(); if (!(arrow.getShooter() instanceof Player))return; - + //Player Sanitation Player player = (Player) arrow.getShooter(); if (!player.getInventory().contains(Material.TNT))return; - + //Bow Sanitation ItemStack bow; if (!((bow = player.getInventory().getItemInMainHand()).getType() == Material.BOW))return; if (!(bow.containsEnchantment(Enchantment.PROTECTION_EXPLOSIONS)))return; if (!(bow.getEnchantmentLevel(Enchantment.PROTECTION_EXPLOSIONS) == 10))return; if (!(bow.getItemMeta().getDisplayName().toUpperCase().contains("CANNON BOW")))return; - + //TNT Spawning Vector playerVector = player.getEyeLocation().getDirection().normalize(); + Location playerLocation = player.getLocation(); if (event.getForce() < getMinforce()){ - + //Smoke cloud if draw is too low - arrow.getWorld().spawnParticle(Particle.SMOKE_NORMAL, player.getLocation(), 30); - arrow.getWorld().playSound(player.getLocation(), Sound.BLOCK_LADDER_BREAK, 1.0F, -7); - + arrow.getWorld().spawnParticle(Particle.SMOKE_NORMAL, playerLocation, 30); + arrow.getWorld().playSound(playerLocation, Sound.BLOCK_LADDER_BREAK, 1.0F, -7); + }else{ //Spawn TNT TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); @@ -82,74 +115,135 @@ public class CannonBowListener implements Listener { } catch (Exception ex) { ex.printStackTrace(); }*/ - + // tnt.setVelocity(playerVector.multiply(getSpeedMultiplier()).multiply(event.getForce())); tnt.setCustomName(launchedTNTName); tnt.setFuseTicks(getFuseticks()); - + //Player Recoil - player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1).multiply(getRecoil())); - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0); - player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2); - + player.setVelocity(playerVector.multiply(-1).multiply(getRecoil())); + player.getWorld().playSound(playerLocation, Sound.ENTITY_GENERIC_EXPLODE, 1.0F, 0); + player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, playerLocation, 2); + } arrow.remove(); - - + + return; - + } @EventHandler public void onTnTExplode(EntityExplodeEvent event) { if (event.getEntityType() != EntityType.PRIMED_TNT) return; if (event.getEntity().getCustomName() != "CANNON BOW TNT:42170") return; - - Location loc = event.getEntity().getLocation(); - event.getEntity().getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 3, false, false); - event.setCancelled(true); - - + + if (isDestructive == true){ + Location loc = event.getEntity().getLocation(); + event.getEntity().getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 3, false, false); + event.setCancelled(true); + } + + } + public static double getSpeedMultiplier() { - return SpeedMultiplier; + return speedMultiplier; } - public static void setSpeedMultiplier(double speedMultiplier) { - if (speedMultiplier > 4) speedMultiplier = 4; - if (speedMultiplier < 0) speedMultiplier = 0; - SpeedMultiplier = speedMultiplier; + public static void setSpeedMultiplier(double multiplier, CommandSender sender){ + + if (multiplier > maxSpeedMultiplier) sender.sendMessage("SpeedMultiplier is too Large! Setting multiplier to "+ maxSpeedMultiplier); + if (multiplier < maxSpeedMultiplier) sender.sendMessage("SpeedMultiplier is too Small! Setting multiplier to "+ minSpeedMultiplier); + + setSpeedMultiplier(multiplier, sender); + sender.sendMessage("SpeedMultiplier set to " + getSpeedMultiplier()); } + public static void setSpeedMultiplier(double multiplier) { + + if (multiplier > maxSpeedMultiplier) multiplier = maxSpeedMultiplier; + if (multiplier < minSpeedMultiplier) multiplier = minSpeedMultiplier; + config.set(speedMultiplierPath, multiplier); + speedMultiplier = multiplier; + + } + + public static double getMinforce() { - return minforce; + return minForce; + } + public static void setMinForce(double minforce, CommandSender sender){ + + if (minforce > maxMinForce) sender.sendMessage("MinForce is too large! Setting it to " + maxMinForce); + if (minforce < minMinForce) sender.sendMessage("MinForce is too small! Setting it to " + minMinForce); + setMinforce(minforce); + sender.sendMessage("MinForce set to " + getMinforce()); + + } + public static void setMinforce(double minforce) { + + if (minforce > maxMinForce) minforce = maxMinForce; + if (minforce < minMinForce) minforce = minMinForce; + config.set(minForcePath, minforce); + CannonBowListener.minForce = minforce; } - public static void setMinforce(double minforce) { - if (minforce > 1) minforce = 1; - if (minforce < 0) minforce = 0; - CannonBowListener.minforce = minforce; - } public static int getFuseticks() { - return fuseticks; + return fuseTicks; + } + public static void setFuseticks(int fuseticks, CommandSender sender){ + + if (fuseticks > maxFuseTicks) sender.sendMessage("Fuseticks is too large! Setting it to " + maxFuseTicks); + if (fuseticks < minFuseTicks) sender.sendMessage("Fuseticks is too small! Setting it to " + minFuseTicks); + setFuseticks(fuseticks); + sender.sendMessage("FuseTicks set to " + getFuseticks()); + + } + public static void setFuseticks(int fuseticks) { + + if (fuseticks > maxFuseTicks) fuseticks = maxFuseTicks; + if (fuseticks < minFuseTicks) fuseticks = minFuseTicks; + config.set(fuseTicksPath, fuseticks); + CannonBowListener.fuseTicks = fuseticks; + } - public static void setFuseticks(int fuseticks) { - if (fuseticks > 400) fuseticks = 400; - if (fuseticks < 0) fuseticks = 0; - CannonBowListener.fuseticks = fuseticks; - } public static double getRecoil() { return recoil; } + public static void setRecoil(double recoil, CommandSender sender){ + if (recoil > maxRecoil) sender.sendMessage("Recoil is too large! Setting it to " + maxRecoil); + if (recoil < maxRecoil) sender.sendMessage("Recoil is too small! Setting it to " + minRecoil); + setRecoil(recoil); + sender.sendMessage("Recoil set to " + getRecoil()); + + } public static void setRecoil(double recoil) { - if (recoil > 20) recoil = 20; - if (recoil < 0) recoil = 0; + + if (recoil > maxRecoil) recoil = maxRecoil; + if (recoil < minRecoil) recoil = minRecoil; + config.set(recoilPath, recoil); CannonBowListener.recoil = recoil; + + } + + + public static boolean getIsDestructive(){ + return isDestructive; + } + public static void setIsDestructive(String input){ + if(input.startsWith("T") || input.startsWith("t")) setIsDestructive(true); + if(input.startsWith("F") || input.startsWith("f")) setIsDestructive(false); + + } + public static void setIsDestructive(boolean isDestructive){ + CannonBowListener.isDestructive = isDestructive; + config.set(speedMultiplierPath, isDestructive); } } \ No newline at end of file diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java index 8aa8655..cbd7df4 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java @@ -9,25 +9,34 @@ public class CannonBowSettings extends ModCommand { @Override public boolean OnCommand(Player player, String alias, String[] args) { - if (args.length > 1){ + if (args.length > 1 && args[0] == "display"){ switch(args[0].toLowerCase()){ + case "force": case "speedmultiplier": CannonBowListener.setSpeedMultiplier(NumberUtils.toDouble(args[1], CannonBowListener.getSpeedMultiplier())); break; + case "minimumforce": case "minforce": + case "minimumdraw": + case "mindraw": CannonBowListener.setMinforce(NumberUtils.toDouble(args[1], CannonBowListener.getMinforce())); break; + case "fuse": + case "fusetick": case "fuseticks": CannonBowListener.setFuseticks(NumberUtils.toInt(args[1], CannonBowListener.getFuseticks())); break; case "recoil": CannonBowListener.setRecoil(NumberUtils.toDouble((args[1]), CannonBowListener.getRecoil())); break; + case "isDestructive": + CannonBowListener.setIsDestructive(args[1]); case "display": player.sendMessage("Speed Multiplier: "+CannonBowListener.getSpeedMultiplier()); player.sendMessage("Minimum Force: "+CannonBowListener.getMinforce()); player.sendMessage("Fuseticks: " + CannonBowListener.getFuseticks()); player.sendMessage("Recoil: " + CannonBowListener.getRecoil()); + player.sendMessage("isDestructive: " + CannonBowListener.getIsDestructive()); break; default: player.sendMessage("That isn't a valid setting!");