Easy tiny problem

Discussion in 'Plugin Development' started by CraftBang, Nov 1, 2013.

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

    CraftBang

    Hey there!
    I've got a little problem.
    So I'm checking like on command /test what the players item name is. So like you have wood sword in your hand it will check for wood sword, and set it to Blue sword.

    So this is what I have :
    Code:
      if(meta.getDisplayName().contains("Wood sword")){
    meta.setDisplayName(ChatColor.BLUE + "Blue sword");
    player.getItemInHand().setItemMeta(meta);
      }
     
      if(meta.getDisplayName().contains(ChatColor.BLUE + "Blue sword")){
    meta.setDisplayName(ChatColor.RED+ "Red sword");
    player.getItemInHand().setItemMeta(meta);
      }
    
    Problem is, code will see Wood sword.
    Will set it to Blue sword, and boom it will see Blue sword again.
    I want to use this with 4 colors, red blue yellow and green, but they need to stop "looping"
    Can anyone tell me just like to cancel to go further?


    EDIT : SECOND THING
    So if you switch to a weapon, you see the weapons name above your XP bar.
    How can I make it that it will stay there forever. Or make it LOOK like it stays there forever.
    So that if they've got item in their hand the name of it will be shown the whole time instead of going away.


    Thanks in advance,
    CB
     
  2. Offline

    amhokies

    Just change your second if statement to else if
    Edit: It will only execute if the first if statement is false and the condition in it is true.
     
  3. Offline

    Hugs

    add return true; when you want to stop it.
     
    CraftBang likes this.
  4. Offline

    amhokies

    I think that's one of those things that is purely client side and that can't be changed without modifying the client itself.
     
  5. Offline

    whitehooder

    amhokies is right in that it is client side, but, there MIGHT be a workaround. Try having a scheduled repeating task setting the item in his hand to the blue sword, if he is holding the sword. It should display the text for another 2 seconds every time the code is executed.

    Good luck :)
     
    CraftBang likes this.
  6. Offline

    CraftBang

    whitehooder that's a kinda good idea, but the problem is I want the impossible XD.
    I want to make it like a distance to spawnpoint so he NEEDS the compass in hes hands or it won't be shown.
    And otherwhise the other items will be renamed :(.

    Hugs going to try that now it'll probably work, thanks a lot everyone

    Wow wait, I've got an problem myself sorry hugs, I'll need to try that first to fix it. And than your code will probably work
     
  7. Offline

    whitehooder

    CraftBang So you mean the compass would point at the sword, and the client will display the name of it from a distance? That would be impossible as you say (when having to hold the compass)

    Wait wait wait... waaait.. Just simply rename the compass instead then ;)
     
  8. Offline

    CraftBang

    whitehooder I want like that it doesnt matter what item you have in your hand, it will show distance to somewhere (I've got an auto updater if you walk so that works fine )
    Just a problem, if I'll do this to all items, all item names are "Distance to spawn" xD

    Lol ofcourse I failed so big, I forgot to add @EventHandler.
    Thanks a lot already guys :p

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

    whitehooder

    CraftBang There are ugly workarounds for that as well, so if you'd like to get this done (or just simply want to see how I'd do it) check out the spoiler below...

    Ugly Workaround (open)
    Create a hashmap and store all the items slot ids with their names, then simply change the names you have to change to the distance (in your updating event or whatever) and simply set the names back when the player opens up their inventory, to check the names of their items. This would be quite efficient I believe, as there are only nine slots you'd have to keep track of for every player. :)
    Good luck
     
  10. Offline

    CraftBang

    whitehooder thanks a lot, but this will cause problems by dropping and switching new items?
    but it's a very good idea, I thought well lets don't do it, but I'm just going to do it :D.
    Good idea, just need to figure out.
    Is it very unefficient to create like 9 hashmaps xD : slot1 ,slot2,slot3..... slot9 ?
    It's easier than I guess xD
    And one thing I'm thinking more off is the trouble that if a player picks up a new item, or if he opens hes inventory, so all item names back to normal, and than he got hit or something, you know so it changed back again because he moved.
     
  11. Offline

    whitehooder

    Well, the more you think of it, the more problems you can come up with, but again, you can simply handle them. Also, I don't see why you'd need 9 hashmaps (if you are not monitoring nine players ofc). Use a single hashmap, with the player as the key, and a list of ItemStacks as the value (or an array, preferably with assigned slot ids). Feel free to PM me if you need any help, or if you'd like me to code you an example of it :)
     
  12. Offline

    CraftBang

    whitehooder this idea is kinda good but its not going to work, because of the empty spaces in hand.
    They don't have a DisplayName, so does no other item.
    None if the items has a DisplayName, just a name not using meta, but a empty slot will cause problems and I don't know any invisible item ID.
    So I might need to think for something else, if I can make a custom event or something that triggers the DefaultName showup.
     
Thread Status:
Not open for further replies.

Share This Page