Help me please

Discussion in 'Plugin Development' started by TheL0w3R, Sep 24, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    TheL0w3R

    Hi, im making a Quake Plugin and i've coded a Railgun that instant kills the target entity...

    The problem is that I'd like to have a CommandManager class (i've already coded it) and another packet wich contains the classes of the commands.. I want to check if the player had executed the command "/gun", i've coded it but in the RailGun class..

    Now I want to make the Gun command class and i can't do it.. Sorry for my bad english and hope u understood it..

    Here is the RailGun Class code:

    Code:java
    1. package me.TheL0w3R.MGQuake.Guns;
    2.  
    3. import java.lang.reflect.Method;
    4. import java.util.Random;
    5.  
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.block.Block;
    9. import org.bukkit.entity.Entity;
    10. import org.bukkit.entity.Firework;
    11. import org.bukkit.entity.LivingEntity;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.player.PlayerInteractEvent;
    16.  
    17. public class RailGun {
    18. int timer,id = 0;
    19. Random gen = new Random();
    20. @SuppressWarnings("deprecation")
    21. @EventHandler
    22. public void onS(PlayerInteractEvent event){
    23. if (event.getAction() != Action.RIGHT_CLICK_AIR) return;
    24. Player p = event.getPlayer();
    25. if (p.getItemInHand()==null) return;
    26. if (p.getItemInHand().getType()!= Material.DIAMOND_HOE) return;
    27. try {
    28. for(Block loc:event.getPlayer().getLineOfSight(null, 100)){
    29. playFirework(loc.getLocation());
    30. for (Entity e : loc.getChunk().getEntities()){
    31. if (!(e instanceof LivingEntity)) continue;
    32. Location l = p.getEyeLocation();
    33. LivingEntity le = (LivingEntity) e;
    34. if (le.getLocation().distance(l)<=1.5) le.damage(100000);
    35. }
    36. }
    37. } catch (Exception e) {
    38. // TODO Auto-generated catch block
    39. e.printStackTrace();
    40. }
    41. }
    42. private Object[] dataStore = new Object[5];
    43. public void playFirework(Location loc) throws Exception {
    44. Firework fw = (Firework) loc.getWorld().spawn(loc, Firework.class);
    45. if(dataStore[0] == null) dataStore[0] = getMethod(loc.getWorld().getClass(), "getHandle");
    46. if(dataStore[2] == null) dataStore[2] = getMethod(fw.getClass(), "getHandle");
    47. dataStore[3] = ((Method) dataStore[0]).invoke(loc.getWorld(), (Object[]) null);
    48. dataStore[4] = ((Method) dataStore[2]).invoke(fw, (Object[]) null);
    49. if(dataStore[1] == null) dataStore[1] = getMethod(dataStore[3].getClass(), "addParticle");
    50. ((Method) dataStore[1]).invoke(dataStore[3], new Object[] {"fireworksSpark", loc.getX(),loc.getY(),loc.getZ(),gen.nextGaussian() * 0.05D, -(loc.getZ()* 1.15D) * 0.5D, gen.nextGaussian() * 0.05D});
    51. fw.remove();
    52. }
    53. private Method getMethod(Class<?> cl, String method) {
    54. for(Method m : cl.getMethods()) if(m.getName().equals(method)) return m;
    55. return null;
    56. }
    57. }
    58.  


    And here is the Gun command class code:

    Code:java
    1. package me.TheL0w3R.MGQuake.cmds;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.inventory.ItemStack;
    10.  
    11. import me.TheL0w3R.MGQuake.GameCommand;
    12.  
    13. [USER=90791533]me.[/USER]TheL0w3R.MGQuake.CommandInfo(description = "Give the player a Gun.", aliases = {"gun"}, usage = "")
    14. public class Gun extends GameCommand{
    15.  
    16. ArrayList<Player> playerGunner = new ArrayList<Player>();
    17.  
    18. @Override
    19. public void onCommand(CommandSender sender, Player p, String[] args) {
    20. p = (Player) sender;
    21. playerGunner.add(p);
    22. p.sendMessage(ChatColor.GREEN + "Here is your RailGun!");
    23. p.getInventory().addItem(new ItemStack(Material.DIAMOND_HOE));
    24. }
    25.  
    26.  
    27. }


    I'd like to check if they had used the command by adding this:
    Code:java
    1. if (!(playerGunner.contains(p)));


    But i can't use playerGunner ArrayList because it's on the Gun command class..
     
    Skionz likes this.
  2. Use
    Code:java
    1. if (!(Gun.playerGunner.contains(p)));

    I was too lazy to read all the stuff.
     
  3. Offline

    TheL0w3R


    Thanks a lot!
    It worked :)
     
Thread Status:
Not open for further replies.

Share This Page