Add an event item to a kit?

Discussion in 'Plugin Development' started by PolarCraft, Jan 2, 2014.

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

    PolarCraft

    Okay so i am making a kitpvp that when you right click with a stick it shoots arrows for now. But I am unable to import the variable ems from the event that handles the stick.

    This is the weapon itself.
    Code:java
    1. @EventHandler
    2. public void PlayerInteractEvent(PlayerInteractEvent event){
    3. ItemStack ems = new ItemStack(Material.STICK);
    4. Player player = event.getPlayer();
    5. if(player.hasPermission("kitpvp.ems")) {
    6. if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || (event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
    7. player.launchProjectile(Arrow.class);
    8. }
    9. }
    10. }
    11. }


    This is the event for the kit.
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("earthmage")) {
    2. if(sender.hasPermission("kitpvp.em")) {
    3. p.getInventory().clear();
    4. ItemStack ws = (new ItemStack(ems));
    5.  
    6. ItemMeta m = ws.getItemMeta();
    7. m.setDisplayName(ChatColor.GREEN +"Earth-Mage");
    8. ws.setItemMeta(m);
    9.  
    10. p.getInventory().addItem(ws);


    I am just unable to add the stick to the players inventory. Well it will not take the variable from the event that handles the stick.
     
  2. Offline

    xTigerRebornx

    PolarCraft Put the ItemStack outside of your method. You can't access it as it is now because its a method-specific variable
     
  3. Offline

    PolarCraft

    xTigerRebornx Okay I changed the event up.
    Code:java
    1. ItemStack ems = new ItemStack(Material.STICK);
    2.  
    3. @EventHandler
    4. public void PlayerInteractEvent(PlayerInteractEvent event){
    5. Player player = event.getPlayer();
    6. if(player.hasPermission("kitpvp.ems")) {
    7. if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || (event.getAction().equals(Action.RIGHT_CLICK_BLOCK))) {
    8. if(event.getMaterial() == Material.STICK){
    9. player.launchProjectile(Arrow.class);
    10. }
    11. }
    12. }
    13. }
    14. }
     
  4. Offline

    Aqua

    After p.getInventory().addItem(...); do p.updateInventory(). It is deprecated but still working.
     
  5. Offline

    PolarCraft

    Aqua Already have that on the sign event. And your name looks very familiar. Hmm. mcserver.
     
  6. Offline

    Aqua

    Code:
    p.getInventory().clear();
                          //ItemStack ws = (new ItemStack(ems)); //What are you doing here?
                          ItemStack ws = new ItemStack(Material.STICK);
     
                          ItemMeta m = ws.getItemMeta();
                          m.setDisplayName(ChatColor.GREEN +"Earth-Mage");
                          ws.setItemMeta(m);
     
                          p.getInventory().addItem(ws);
    PolarCraft Forgot to tahg... Try that ^
    And yes. mcserver

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    PolarCraft

    Aqua It is supposed to get the variable for the stick. Well than you would not guess who i am.
     
Thread Status:
Not open for further replies.

Share This Page