Help checking lore on when wearing armor?

Discussion in 'Plugin Development' started by isleepzzz, May 18, 2014.

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

    isleepzzz

    Hey guys!
    So I'm currently building a MMORPG minecraft server and attempting to add something to where I can add a lore in armor such as "Level Req: 10" so your level must be level 10 otherwise it will return the item and not wear it.
    My code so far:
    Code:java
    1. @EventHandler
    2. public void InventoryClickEvent(InventoryClickEvent event) {
    3. HumanEntity p = event.getWhoClicked();
    4. Player player = (Player) p;
    5. ItemStack i = ((Player) p).getPlayer().getItemOnCursor();
    6.  
    7. if (event.getSlotType() == SlotType.ARMOR) {
    8.  
    9.  
    10. if (i != null && i.hasItemMeta()) {
    11. for(String s : i.getItemMeta().getLore()) {
    12.  
    13.  
    14. if(s.contains("Level Req:")) {
    15. String lvStr = s.substring(13);
    16. if (player.getLevel() < Integer.parseInt(lvStr)) {
    17. player.sendMessage(ChatColor.RED + "You need to be level " + lvStr + " to wear this.");
    18. event.setCancelled(true);
    19. return;
    20. }
    21. }
    22. }
    23. }
    24.  
    25.  
    26. }
    27.  
    28.  
    29. }



    So, by reading the code you see I'm checking the item that my mouse is over (which is the item we are attempting to wear) so thats good! However... lets say I click it to wear and rapidly move my mouse not over the item which will skip the checking for Required Level.

    So can someone please help me fix this?
    I need to change the getItemOnCursor to something around getItemWearing?
     
  2. isleepzzz I think that comparing the actual slot ID is better than SlotType.ARMOR, I would add another check that if the player press on armor that not for his level it would remove the item or drop it.
     
  3. Offline

    isleepzzz


    Yeeahh I understand you, but don't know how to code that :L
     
  4. isleepzzz code what? to compare the slot id? or the other thing?
     
  5. Offline

    tommyhoogstra

    You could loop through every 5 seconds or so to check the requirements
     
Thread Status:
Not open for further replies.

Share This Page