From 28877a9bfa303f96497c00dbbb26d3c767a49b35 Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Thu, 3 Nov 2016 02:56:29 -0400 Subject: [PATCH] Optimized AliArrow code --- src/alisolarflare/AliPresents.java | 4 +- .../magictrick/aliarrow/AliArrowListener.java | 40 ++++++++----------- .../magictrick/aliarrow/AliArrowModule.java | 16 -------- .../magictrick/aliarrow/AliArrowTask.java | 23 ++++++----- 4 files changed, 32 insertions(+), 51 deletions(-) delete mode 100644 src/alisolarflare/modules/magictrick/aliarrow/AliArrowModule.java diff --git a/src/alisolarflare/AliPresents.java b/src/alisolarflare/AliPresents.java index 64f614a..228fcee 100644 --- a/src/alisolarflare/AliPresents.java +++ b/src/alisolarflare/AliPresents.java @@ -11,7 +11,7 @@ import alisolarflare.modules.components.gpowers.GPowerModule; import alisolarflare.modules.components.links.AliLinkModule; import alisolarflare.modules.components.shulker.AliShulkerModule; import alisolarflare.modules.events.uhc.UHCModule; -import alisolarflare.modules.magictrick.aliarrow.AliArrowModule; +import alisolarflare.modules.magictrick.MagicModule; public class AliPresents extends JavaPlugin{ public void onEnable(){ @@ -33,6 +33,6 @@ public class AliPresents extends JavaPlugin{ new AliLinkModule().register(this); new AliShulkerModule().register(this); new UHCModule().register(this); - new AliArrowModule().register(this); + new MagicModule().register(this); } } diff --git a/src/alisolarflare/modules/magictrick/aliarrow/AliArrowListener.java b/src/alisolarflare/modules/magictrick/aliarrow/AliArrowListener.java index bcdc62f..038b148 100644 --- a/src/alisolarflare/modules/magictrick/aliarrow/AliArrowListener.java +++ b/src/alisolarflare/modules/magictrick/aliarrow/AliArrowListener.java @@ -2,7 +2,7 @@ package alisolarflare.modules.magictrick.aliarrow; import org.bukkit.entity.Arrow; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Projectile; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.ProjectileLaunchEvent; @@ -15,31 +15,25 @@ public class AliArrowListener implements Listener { this.plugin = plugin; } - @SuppressWarnings("deprecation") @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event){ - try{ - if(!(event.getEntity().getType() == EntityType.ARROW)){ - return; - } - Projectile projectile = event.getEntity(); - Arrow arrow = (Arrow) projectile; - if (!(arrow.isCritical())){ - return; - } - if (projectile.getShooter().equals(plugin.getServer().getPlayer("alisolarflare"))){ - AliArrowTask aliArrowTask = new AliArrowTask(plugin,arrow,"alisolarflare"); - aliArrowTask.runTaskTimer(plugin, 2, 1); - return; - }else if (projectile.getShooter().equals(plugin.getServer().getPlayer("Zanthr"))){ - AliArrowTask aliArrowTask = new AliArrowTask(plugin,arrow,"zanthr"); - aliArrowTask.runTaskTimer(plugin, 2, 1); - return; - } - return; - - }catch(Exception e){ + if(event.getEntity().getType() != EntityType.ARROW){ return; } + Arrow arrow = (Arrow) event.getEntity(); + if (!(arrow.isCritical()) || !(arrow.getShooter() instanceof Player)){ + return; + } + + String user = ((Player) arrow.getShooter()).getName(); + + for (String permittedUser : AliArrowTask.permittedUsers){ + if(permittedUser.equalsIgnoreCase(user)){ + new AliArrowTask(arrow,user).runTaskTimer(plugin, 2, 1); + break; + } + } + return; + } } \ No newline at end of file diff --git a/src/alisolarflare/modules/magictrick/aliarrow/AliArrowModule.java b/src/alisolarflare/modules/magictrick/aliarrow/AliArrowModule.java deleted file mode 100644 index b73167f..0000000 --- a/src/alisolarflare/modules/magictrick/aliarrow/AliArrowModule.java +++ /dev/null @@ -1,16 +0,0 @@ -package alisolarflare.modules.magictrick.aliarrow; - -import org.bukkit.plugin.java.JavaPlugin; -import alisolarflare.modules.Module; -import buttondevteam.lib.TBMCCoreAPI; - -public class AliArrowModule extends Module { - /** - * Registers the plugin, activating listeners, commands, and events - */ - @Override - public void register(JavaPlugin plugin) { - TBMCCoreAPI.RegisterEventsForExceptions(new AliArrowListener(plugin), plugin); - - } -} diff --git a/src/alisolarflare/modules/magictrick/aliarrow/AliArrowTask.java b/src/alisolarflare/modules/magictrick/aliarrow/AliArrowTask.java index 1904830..603567d 100644 --- a/src/alisolarflare/modules/magictrick/aliarrow/AliArrowTask.java +++ b/src/alisolarflare/modules/magictrick/aliarrow/AliArrowTask.java @@ -2,17 +2,15 @@ package alisolarflare.modules.magictrick.aliarrow; import org.bukkit.Particle; import org.bukkit.entity.Arrow; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class AliArrowTask extends BukkitRunnable { - JavaPlugin plugin; + static String[] permittedUsers = {"alisolarflare", "Zanthr", "NorbiPeti"}; String name; Arrow arrow; - public AliArrowTask(JavaPlugin plugin, Arrow arrow, String name) { + public AliArrowTask(Arrow arrow, String name) { this.name = name; - this.plugin = plugin; this.arrow = arrow; } @@ -21,16 +19,21 @@ public class AliArrowTask extends BukkitRunnable { if (arrow.isOnGround() || arrow.isDead()) { this.cancel(); } - if (name.equalsIgnoreCase("alisolarflare")) { + + switch(name.toLowerCase()){ + case "alisolarflare": arrow.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, arrow.getLocation(), 1); - } - if (name.equalsIgnoreCase("Zanthr")) { + break; + + case "zanthr": arrow.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, arrow.getLocation(), 1); arrow.getWorld().spawnParticle(Particle.FLAME, arrow.getLocation(), 1); - - } - if (name.equals("NorbiPeti")) + break; + + case "norbipeti": arrow.getWorld().spawnParticle(Particle.LAVA, arrow.getLocation(), 1); + break; + } }