Optimized AliArrow code

This commit is contained in:
alisolarflare 2016-11-03 02:56:29 -04:00
parent d0a7e5ecb7
commit 28877a9bfa
4 changed files with 32 additions and 51 deletions

View file

@ -11,7 +11,7 @@ import alisolarflare.modules.components.gpowers.GPowerModule;
import alisolarflare.modules.components.links.AliLinkModule; import alisolarflare.modules.components.links.AliLinkModule;
import alisolarflare.modules.components.shulker.AliShulkerModule; import alisolarflare.modules.components.shulker.AliShulkerModule;
import alisolarflare.modules.events.uhc.UHCModule; import alisolarflare.modules.events.uhc.UHCModule;
import alisolarflare.modules.magictrick.aliarrow.AliArrowModule; import alisolarflare.modules.magictrick.MagicModule;
public class AliPresents extends JavaPlugin{ public class AliPresents extends JavaPlugin{
public void onEnable(){ public void onEnable(){
@ -33,6 +33,6 @@ public class AliPresents extends JavaPlugin{
new AliLinkModule().register(this); new AliLinkModule().register(this);
new AliShulkerModule().register(this); new AliShulkerModule().register(this);
new UHCModule().register(this); new UHCModule().register(this);
new AliArrowModule().register(this); new MagicModule().register(this);
} }
} }

View file

@ -2,7 +2,7 @@ package alisolarflare.modules.magictrick.aliarrow;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
@ -15,31 +15,25 @@ public class AliArrowListener implements Listener {
this.plugin = plugin; this.plugin = plugin;
} }
@SuppressWarnings("deprecation")
@EventHandler @EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event){ public void onProjectileLaunch(ProjectileLaunchEvent event){
try{ if(event.getEntity().getType() != EntityType.ARROW){
if(!(event.getEntity().getType() == EntityType.ARROW)){
return; return;
} }
Projectile projectile = event.getEntity(); Arrow arrow = (Arrow) event.getEntity();
Arrow arrow = (Arrow) projectile; if (!(arrow.isCritical()) || !(arrow.getShooter() instanceof Player)){
if (!(arrow.isCritical())){
return; return;
} }
if (projectile.getShooter().equals(plugin.getServer().getPlayer("alisolarflare"))){
AliArrowTask aliArrowTask = new AliArrowTask(plugin,arrow,"alisolarflare"); String user = ((Player) arrow.getShooter()).getName();
aliArrowTask.runTaskTimer(plugin, 2, 1);
return; for (String permittedUser : AliArrowTask.permittedUsers){
}else if (projectile.getShooter().equals(plugin.getServer().getPlayer("Zanthr"))){ if(permittedUser.equalsIgnoreCase(user)){
AliArrowTask aliArrowTask = new AliArrowTask(plugin,arrow,"zanthr"); new AliArrowTask(arrow,user).runTaskTimer(plugin, 2, 1);
aliArrowTask.runTaskTimer(plugin, 2, 1); break;
return; }
} }
return; return;
}catch(Exception e){
return;
}
} }
} }

View file

@ -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);
}
}

View file

@ -2,17 +2,15 @@ package alisolarflare.modules.magictrick.aliarrow;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class AliArrowTask extends BukkitRunnable { public class AliArrowTask extends BukkitRunnable {
JavaPlugin plugin; static String[] permittedUsers = {"alisolarflare", "Zanthr", "NorbiPeti"};
String name; String name;
Arrow arrow; Arrow arrow;
public AliArrowTask(JavaPlugin plugin, Arrow arrow, String name) { public AliArrowTask(Arrow arrow, String name) {
this.name = name; this.name = name;
this.plugin = plugin;
this.arrow = arrow; this.arrow = arrow;
} }
@ -21,16 +19,21 @@ public class AliArrowTask extends BukkitRunnable {
if (arrow.isOnGround() || arrow.isDead()) { if (arrow.isOnGround() || arrow.isDead()) {
this.cancel(); this.cancel();
} }
if (name.equalsIgnoreCase("alisolarflare")) {
switch(name.toLowerCase()){
case "alisolarflare":
arrow.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, arrow.getLocation(), 1); arrow.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, arrow.getLocation(), 1);
} break;
if (name.equalsIgnoreCase("Zanthr")) {
case "zanthr":
arrow.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, arrow.getLocation(), 1); arrow.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, arrow.getLocation(), 1);
arrow.getWorld().spawnParticle(Particle.FLAME, arrow.getLocation(), 1); arrow.getWorld().spawnParticle(Particle.FLAME, arrow.getLocation(), 1);
break;
} case "norbipeti":
if (name.equals("NorbiPeti"))
arrow.getWorld().spawnParticle(Particle.LAVA, arrow.getLocation(), 1); arrow.getWorld().spawnParticle(Particle.LAVA, arrow.getLocation(), 1);
break;
}
} }