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

View file

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

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.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;
}
}