I need a bit of plugin development help!

Discussion in 'Plugin Development' started by xXRobbie21Xx, May 4, 2014.

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

    xXRobbie21Xx

    Hey guys, i am attempting to make a plugin and im getting an error.
    First here is my code:
    @EventHandler
    public void toggle(PlayerInteractEvent event){
    Player player = event.getPlayer();

    if(player.getInventory().getItemInhand().getItemMeta().getDisplayName() == "MobWand"){
    if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
    Player p = event.getPlayer();
    Snowball snowball = p.getWorld().spawn(p.getEyeLocation(), Snowball.class);
    snowball.setVelocity(p.getLocation().getDirection().multiply(1.5));
    snowball.setShooter(p);
    This code is suppose to allow a player to shoot a snowball if they interact with an item called "mobwand" in there inventory.

    Everything works untill you move the item (mobwand) elseware in the inventory.
    For example, i type a command to recieve the item and it works if i click it when it is in the slot that it apears in but the second i move it over a few slots it will stop shooting snowballs!


    I understand this is random and specific but if there is anyone out there that can help a noob out i would greatly appreciate it! Thanks in advance!
     
  2. Offline

    Drkmaster83

    Well, for one, you're creating two "player" variables that have the same data.You should rename "player" to "p" and delete "Player p = event.getPlayer();"

    Secondly, with Java, you always compare Strings using methods, not primitive boolean/bit comparisons. So, instead of "player.getItemInHand().getItemMeta().getDisplayName() == "MobWand"", try "player.getItemInHand().getItemMeta().getDisplayName().contains("MobWand")", although could could also replace ".contains()" with ".equalsIgnoreCase()", which I recommend.

    I suppose I could help you here and there, all's you need to do is send me a message on Bukkit here and there.

    Edit: Sorry about that really messed up post, Bukkit loves messing with me in terms of text formatting.
     
  3. Offline

    xXRobbie21Xx

    Hey thanks so much you really helped me out!! I truly appreciate the fact that you put time into replying to my post!

    And sure that would be great, it would be nice to have someone there for me when i get stuck in these situations :p
     
Thread Status:
Not open for further replies.

Share This Page