From c2389eb74c7c2a2f1f21c4728d6b543b6f36dace Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Tue, 20 Dec 2016 05:22:14 -0500 Subject: [PATCH 1/6] Adjusted Cannon Bow Made Draw Distance smaller Made TNT launch depending on draw Have launch settings be adjustable --- plugin.yml | 4 -- pom.xml | 2 +- .../components/magic/MagicComponent.java | 3 ++ .../components/magic/tricks/AliArrowTask.java | 4 +- .../magic/tricks/CannonBowListener.java | 52 ++++++++++++------- .../magic/tricks/CannonBowSettings.java | 32 ++++++++++++ 6 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java diff --git a/plugin.yml b/plugin.yml index 3e396be..32b153e 100644 --- a/plugin.yml +++ b/plugin.yml @@ -5,16 +5,12 @@ version: 2.0.2 commands: alilink: description: creates wireless redstone - cashmob: - description: creates mobs cb: description: creates creative boundaries debug: description: debug commands flaircolour: description: flaaairs - fruit: - description: fruits gpower: description: powerssss insurance: diff --git a/pom.xml b/pom.xml index fe6a070..ab68ed4 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,7 @@ org.apache.commons commons-lang3 - 3.4 + 3.5 com.github.TBMCPlugins.ButtonCore diff --git a/src/buttondevteam/alipresents/components/magic/MagicComponent.java b/src/buttondevteam/alipresents/components/magic/MagicComponent.java index 4dd2389..228d82b 100644 --- a/src/buttondevteam/alipresents/components/magic/MagicComponent.java +++ b/src/buttondevteam/alipresents/components/magic/MagicComponent.java @@ -7,11 +7,14 @@ import buttondevteam.alipresents.components.magic.tricks.AliArrowListener; import buttondevteam.alipresents.components.magic.tricks.BoomBowDeathListener; import buttondevteam.alipresents.components.magic.tricks.BoomBowListener; 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()); + registerListener(plugin, new AliArrowListener(plugin)); registerListener(plugin, new BoomBowDeathListener()); registerListener(plugin, new BoomBowListener(plugin)); diff --git a/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java b/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java index cd4dd0b..f607210 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java @@ -8,6 +8,7 @@ public class AliArrowTask extends BukkitRunnable { static String[] permittedUsers = {"alisolarflare", "Zanthr", "NorbiPeti"}; String name; Arrow arrow; + int count = 0; public AliArrowTask(Arrow arrow, String name) { this.name = name; @@ -16,7 +17,8 @@ public class AliArrowTask extends BukkitRunnable { @Override public void run() { - if (arrow.isOnGround() || arrow.isDead()) { + count++; + if (count > 400 ||arrow.isOnGround() || arrow.isDead()) { this.cancel(); } diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index 83eebb2..719f3fd 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -12,11 +12,14 @@ import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.Vector; 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){ @@ -24,35 +27,48 @@ public class CannonBowListener implements Listener { } @EventHandler - public void onProjectileLaunch(ProjectileLaunchEvent event){ - //ENTITY SANITATION - if(event.getEntity().getType() != EntityType.ARROW)return; + public void onProjectileLaunch(EntityShootBowEvent event){ + //Entity Sanitation + if(event.getProjectile().getType() != EntityType.ARROW)return; - //ARROW SANITATION - Arrow arrow = (Arrow) event.getEntity(); - if (!(arrow.isCritical()) || !(arrow.getShooter() instanceof Player))return; + //Arrow Sanitation + Arrow arrow = (Arrow) event.getProjectile(); + if (!(arrow.getShooter() instanceof Player))return; - //PLAYER SANITATION + //Player Sanitation Player player = (Player) arrow.getShooter(); if (!player.getInventory().contains(Material.TNT))return; - //BOW SANITATION + //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(); + if (event.getForce() < minforce){ - TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); - tnt.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(1.0)); - tnt.setCustomName(launchedTNTName); - tnt.setFuseTicks(40); - - player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1)); - player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2.0F, 0); - player.getWorld().spawnParticle(Particle.EXPLOSION_HUGE, player.getLocation(), 2); - + + + }else{ + TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); + + tnt.setVelocity(playerVector.multiply(SpeedMultiplier).multiply(event.getForce())); + tnt.setCustomName(launchedTNTName); + tnt.setFuseTicks(40); + + //Player Recoil + player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1)); + player.getWorld().playSound(player.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 2.0F, 0); + player.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, player.getLocation(), 2); + + } arrow.remove(); + + return; } diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java new file mode 100644 index 0000000..e657375 --- /dev/null +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java @@ -0,0 +1,32 @@ +package buttondevteam.alipresents.components.magic.tricks; + +import org.apache.commons.lang3.math.NumberUtils; +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); + break; + case "minforce": + CannonBowListener.minforce = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); + break; + default: + player.sendMessage("That isn't a valid setting!"); + player.sendMessage("Valid Settings are: "); + return false; + } + return true; + } + + @Override + public String GetCommandPath(){ + return "magic cannonbow"; + } + +} -- 2.30.2 From d48d1451112f2a80657be6bcff99eb63f4b0b060 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Tue, 20 Dec 2016 06:33:49 -0500 Subject: [PATCH 2/6] 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!"); -- 2.30.2 From bde22562622827d2b3c3e7bb6baf9f9eb3181e2d Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 21 Dec 2016 18:51:47 -0500 Subject: [PATCH 3/6] Added smoke to failed cannonbow shot --- .../alipresents/components/magic/tricks/CannonBowListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index 163e9b9..a266827 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -58,7 +58,8 @@ public class CannonBowListener implements Listener { Vector playerVector = player.getEyeLocation().getDirection().normalize(); if (event.getForce() < minforce){ - + arrow.getWorld().spawnParticle(Particle.SMOKE_NORMAL, player.getLocation(), 30); + arrow.getWorld().playSound(player.getLocation(), Sound.BLOCK_LADDER_BREAK, 1.0F, -14); }else{ TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); -- 2.30.2 From 4cf65fefa10035c0c32e601768cf4b6d97840b17 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 21 Dec 2016 19:02:48 -0500 Subject: [PATCH 4/6] Fully disabled Creative in World --- .../components/hotfix/HotfixComponent.java | 2 ++ .../hotfix/hotfixes/CreativeKillLoop.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java diff --git a/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java b/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java index 45e6a2a..abd2393 100644 --- a/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java +++ b/src/buttondevteam/alipresents/components/hotfix/HotfixComponent.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.Essentials; import buttondevteam.alipresents.architecture.Component; import buttondevteam.alipresents.components.hotfix.hotfixes.CowSpawnLoop; +import buttondevteam.alipresents.components.hotfix.hotfixes.CreativeKillLoop; import buttondevteam.alipresents.components.hotfix.hotfixes.GrassBreakListener; import buttondevteam.alipresents.components.hotfix.hotfixes.MobKillListener; import buttondevteam.alipresents.components.hotfix.hotfixes.NetherDisableListener; @@ -19,6 +20,7 @@ public class HotfixComponent extends Component { registerListener(plugin, new CowSpawnLoop(plugin)); registerListener(plugin, new MobKillListener((Essentials) Bukkit.getPluginManager().getPlugin("Essentials"))); registerListener(plugin, new GrassBreakListener()); + registerListener(plugin, new CreativeKillLoop(plugin)); } diff --git a/src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java b/src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java new file mode 100644 index 0000000..d127982 --- /dev/null +++ b/src/buttondevteam/alipresents/components/hotfix/hotfixes/CreativeKillLoop.java @@ -0,0 +1,28 @@ +package buttondevteam.alipresents.components.hotfix.hotfixes; + +import org.bukkit.GameMode; +import org.bukkit.Server; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +public class CreativeKillLoop extends BukkitRunnable implements Listener { + private Server server; + + public CreativeKillLoop(JavaPlugin plugin){ + this.server = plugin.getServer(); + this.runTaskTimer(plugin, 40, 40); + } + + @Override + public void run() { + for (Player player : server.getOnlinePlayers()){ + if(player.getGameMode() != GameMode.SURVIVAL && player.getWorld().getName() == "World" && player.isOp() == false){ + player.sendMessage("[Hotfix] Every Gamemode other than survival is disabled in the new world!"); + player.setGameMode(GameMode.SURVIVAL); + } + } + } + +} -- 2.30.2 From 52bb4658036ec9cb82ca2332f40c7922e85553fd Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 21 Dec 2016 21:14:38 -0500 Subject: [PATCH 5/6] #37 finished cannon bow adjustments --- .../magic/tricks/CannonBowListener.java | 16 ++++-- .../magic/tricks/CannonBowSettings.java | 50 ++++++++++++------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index a266827..6c04546 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -6,6 +6,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_11_R1.entity.CraftTNTPrimed; import org.bukkit.enchantments.Enchantment; @@ -27,10 +28,19 @@ 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 static int fuseticks = 40; public final static String launchedTNTName = "CANNON BOW TNT:42170"; public CannonBowListener(JavaPlugin plugin){ - SpeedMultiplier = plugin.getConfig().getDouble("magic.cannonbow.speedmultiplier"); - minforce = plugin.getConfig().getDouble("magic.cannonbow.minforce"); + FileConfiguration config = plugin.getConfig(); + + if (config.isDouble("magic.cannonbow.speedmultiplier")) + SpeedMultiplier = config.getDouble("magic.cannonbow.speedmultiplier"); + + if (config.isDouble("magic.cannonbow.minforce")) + minforce = config.getDouble("magic.cannonbow.minforce"); + + if (config.isInt("magic.cannonbow.fuseticks")) + fuseticks = config.getInt("magic.cannonbow.fuseticks"); } @EventHandler @@ -78,7 +88,7 @@ public class CannonBowListener implements Listener { tnt.setVelocity(playerVector.multiply(SpeedMultiplier).multiply(event.getForce())); tnt.setCustomName(launchedTNTName); - tnt.setFuseTicks(40); + tnt.setFuseTicks(fuseticks); //Player Recoil player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1)); diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java index d081bd3..c34641d 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java @@ -9,30 +9,42 @@ public class CannonBowSettings extends ModCommand { @Override public boolean OnCommand(Player player, String alias, String[] args) { - switch(args[0].toLowerCase()){ - case "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": - 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!"); - player.sendMessage("Valid Settings are: "); - return false; + if (args.length > 1){ + switch(args[0].toLowerCase()){ + case "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": + double minforce = NumberUtils.toDouble(args[1], CannonBowListener.minforce); + CannonBowListener.minforce = minforce; + this.getPlugin().getConfig().set("magic.cannonbow.minforce", minforce); + this.getPlugin().saveConfig(); + break; + case "fuseticks": + int fuseticks = NumberUtils.toInt(args[1], CannonBowListener.fuseticks); + CannonBowListener.fuseticks = fuseticks; + this.getPlugin().getConfig().set("magic.cannonbow.fuseticks", fuseticks); + this.getPlugin().saveConfig(); + break; + case "display": + player.sendMessage("Speed Multiplier: "+CannonBowListener.SpeedMultiplier); + player.sendMessage("Minimum Force : "+CannonBowListener.minforce); + break; + default: + player.sendMessage("That isn't a valid setting!"); + player.sendMessage("Valid Settings are: "); + return false; + } } return true; } - + @Override public String GetCommandPath(){ return "magic cannonbow"; } - + } -- 2.30.2 From 81b830e8055882f58fb59e87fc630732d7785373 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 21 Dec 2016 23:12:04 -0500 Subject: [PATCH 6/6] Added Maximum and minimum settings (Also gave kayla an arrow trail :D) --- .../components/magic/tricks/AliArrowTask.java | 4 ++ .../magic/tricks/CannonBowListener.java | 71 +++++++++++++++---- .../magic/tricks/CannonBowSettings.java | 26 +++---- 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java b/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java index f607210..05c5611 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/AliArrowTask.java @@ -35,6 +35,10 @@ public class AliArrowTask extends BukkitRunnable { case "norbipeti": arrow.getWorld().spawnParticle(Particle.LAVA, arrow.getLocation(), 1); break; + + case "mayskam1995": + arrow.getWorld().spawnParticle(Particle.DRIP_WATER, arrow.getLocation(), 2); + break; } } diff --git a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java index 6c04546..1dc1017 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowListener.java @@ -26,21 +26,25 @@ 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 static int fuseticks = 40; + private static double SpeedMultiplier = 1.5; + private static double minforce = 0.2; + private static int fuseticks = 40; + private static double recoil = 1; public final static String launchedTNTName = "CANNON BOW TNT:42170"; public CannonBowListener(JavaPlugin plugin){ FileConfiguration config = plugin.getConfig(); if (config.isDouble("magic.cannonbow.speedmultiplier")) - SpeedMultiplier = config.getDouble("magic.cannonbow.speedmultiplier"); + setSpeedMultiplier(config.getDouble("magic.cannonbow.speedmultiplier")); if (config.isDouble("magic.cannonbow.minforce")) - minforce = config.getDouble("magic.cannonbow.minforce"); + setMinforce(config.getDouble("magic.cannonbow.minforce")); if (config.isInt("magic.cannonbow.fuseticks")) - fuseticks = config.getInt("magic.cannonbow.fuseticks"); + setFuseticks(config.getInt("magic.cannonbow.fuseticks")); + + if (config.isDouble("magic.cannonbow.recoil")) + setRecoil(config.getDouble("magic.cannonbow.recoil")); } @EventHandler @@ -64,14 +68,15 @@ public class CannonBowListener implements Listener { if (!(bow.getItemMeta().getDisplayName().toUpperCase().contains("CANNON BOW")))return; //TNT Spawning - Vector playerVector = player.getEyeLocation().getDirection().normalize(); - if (event.getForce() < minforce){ + 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, -14); + arrow.getWorld().playSound(player.getLocation(), Sound.BLOCK_LADDER_BREAK, 1.0F, -7); }else{ + //Spawn TNT TNTPrimed tnt = (TNTPrimed) arrow.getWorld().spawnEntity(arrow.getLocation(), EntityType.PRIMED_TNT); // Change via NMS the source of the TNT by the player @@ -85,13 +90,13 @@ public class CannonBowListener implements Listener { ex.printStackTrace(); } - - tnt.setVelocity(playerVector.multiply(SpeedMultiplier).multiply(event.getForce())); + // + tnt.setVelocity(playerVector.multiply(getSpeedMultiplier()).multiply(event.getForce())); tnt.setCustomName(launchedTNTName); - tnt.setFuseTicks(fuseticks); + tnt.setFuseTicks(getFuseticks()); //Player Recoil - player.setVelocity(player.getEyeLocation().getDirection().normalize().multiply(-1)); + 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); @@ -114,4 +119,44 @@ public class CannonBowListener implements Listener { } + + public static double getSpeedMultiplier() { + return SpeedMultiplier; + } + + public static void setSpeedMultiplier(double speedMultiplier) { + if (speedMultiplier > 4) speedMultiplier = 4; + if (speedMultiplier < 0) speedMultiplier = 0; + SpeedMultiplier = speedMultiplier; + } + + public static double getMinforce() { + return 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; + } + + 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) { + if (recoil > 20) recoil = 20; + if (recoil < 0) recoil = 0; + CannonBowListener.recoil = recoil; + } } \ 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 c34641d..d781203 100644 --- a/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java +++ b/src/buttondevteam/alipresents/components/magic/tricks/CannonBowSettings.java @@ -12,26 +12,22 @@ public class CannonBowSettings extends ModCommand { if (args.length > 1){ switch(args[0].toLowerCase()){ case "speedmultiplier": - double speedMultiplier = NumberUtils.toDouble(args[1], CannonBowListener.SpeedMultiplier); - CannonBowListener.SpeedMultiplier = speedMultiplier; - this.getPlugin().getConfig().set("magic.cannonbow.speedmultiplier", speedMultiplier); - this.getPlugin().saveConfig(); + CannonBowListener.setSpeedMultiplier(NumberUtils.toDouble(args[1], CannonBowListener.getSpeedMultiplier())); break; case "minforce": - double minforce = NumberUtils.toDouble(args[1], CannonBowListener.minforce); - CannonBowListener.minforce = minforce; - this.getPlugin().getConfig().set("magic.cannonbow.minforce", minforce); - this.getPlugin().saveConfig(); + CannonBowListener.setMinforce(NumberUtils.toDouble(args[1], CannonBowListener.getMinforce())); break; case "fuseticks": - int fuseticks = NumberUtils.toInt(args[1], CannonBowListener.fuseticks); - CannonBowListener.fuseticks = fuseticks; - this.getPlugin().getConfig().set("magic.cannonbow.fuseticks", fuseticks); - this.getPlugin().saveConfig(); + CannonBowListener.setFuseticks(NumberUtils.toInt(args[1], CannonBowListener.getFuseticks())); + break; + case "recoil": + CannonBowListener.setRecoil(NumberUtils.toDouble((args[1]), CannonBowListener.getRecoil())); break; case "display": - player.sendMessage("Speed Multiplier: "+CannonBowListener.SpeedMultiplier); - player.sendMessage("Minimum Force : "+CannonBowListener.minforce); + player.sendMessage("Speed Multiplier: "+CannonBowListener.getSpeedMultiplier()); + player.sendMessage("Minimum Force: "+CannonBowListener.getMinforce()); + player.sendMessage("Fuseticks: " + CannonBowListener.getFuseticks()); + player.sendMessage("Recoil: " + CannonBowListener.getRecoil()); break; default: player.sendMessage("That isn't a valid setting!"); @@ -44,7 +40,7 @@ public class CannonBowSettings extends ModCommand { @Override public String GetCommandPath(){ - return "magic cannonbow"; + return "magic cannonbow settings"; } } -- 2.30.2