more lore help =)

Discussion in 'Plugin Development' started by noraver, Apr 4, 2013.

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

    noraver

    hey guys i need a hand and some input on how to change this.

    Where it's looking for LEATHER_LEGGINGS in the config i need it to look for a Lore
    That is defined in the config and not the Material.

    So if the item has the lore lets say ("exa") the plugin respond to that and not the Material




    Main.java
    Code:java
    1. private void loadArmor() {
    2. ConfigurationSection section = getConfig().getConfigurationSection("armor");
    3. for(String s : section.getKeys(false)){
    4. ConfigurationSection sub = section.getConfigurationSection(s);
    5. World w = (s.equals("default")) ? null : getServer().getWorld(s);
    6. System.out.println("[" + getDescription().getName() + "] Loading armor modifications for world " + ((w == null) ? "default" : w.getName()));
    7. for(String str : sub.getKeys(false)){
    8. try{
    9. int i;
    10. try{
    11. i = Integer.parseInt(str);
    12. } catch (NumberFormatException ex){
    13. i = Material.getMaterial(str).getId();
    14. }
    15. armorHook.modifyArmorValue(i, sub.getInt(str));
    16. } catch (Exception ex){
    17. ex.printStackTrace();
    18. System.out.println("[" + getDescription().getName() + "] Configuration node armor." + s + "." + str + " is causing an issue.");
    19. }
    20. }
    21. }
    22. System.out.println("[" + getDescription().getName() + "] Successfully loaded armor modifications!");
    23. }

    Config.yml
    Code:java
    1.  
    2. armor:
    3. default:
    4. LEATHER_LEGGINGS: 6
    5.  

    how it should be
    want it to look for the lore ("exa")
    Config.yml
    Code:java
    1.  
    2. armor:
    3. default:
    4. exa : 6
    5.  

    [​IMG]
    And thanks in-advance alot of you guys helped me on my other post in the last following weeks
     
  2. Offline

    CreeperShift

    Uhm,

    take the ItemStack, do something like this:

    Code:
                   
     
      ItemMeta data = i.getItemMeta();
    ArrayList<String> desc = new ArrayList<String>();
    Desc.add("lore here");
    Data.setLore(arrowDesc);
    i.setItemMeta(data);
    and then simply:

    Code:
    i.getItemMeta().hasLore()
    Code:
    i.getItemMeta().getLore()
    returns a List of Strings, that you can check/edit freely.
     
  3. Offline

    ZeusAllMighty11

  4. Offline

    CreeperShift

    Autocorrect on my iPhone >_>

    EDIT:
    However it's complete bullshit that you can't use capital letters, sure not AT THE START of the word, but after it doesn't really matter and helps readability.
     
  5. Offline

    noraver

    thanks CreeperShift thats not really what im looking for , wanting to alter this code to work as stated above not sure all of it can be seen on a iphone hehe :)
     
  6. Offline

    CreeperShift

    What do you want me to rewrite it for you lol?

    If it's your own code you can easily rewrite it with the second part of what I said, just check for lore instead, it's not that hard.

    On the list (or array, I forgot what it was) you can easily check .contains("bla bla")

    noraver

    Your post isn't really structured very well nor is the grammar very readable so let me just ask you if this is correct:

    You are trying to identify an item by it's lore, because obviously using the name can be changed via an anvil. Correct?
    Further, you are trying to get a value from your lore and applying bonuses to according to lore? Yes? No?

    If so, you might want to look at this (ignore it if you are not actually trying to do this :p )

    This is from one of my plugins, which checks the item for lore, then scans through it if it contains a int.
    Code:
            if (damager instanceof Player){
               
                ItemStack i = ((Player)damager).getItemInHand();
               
                if(i.hasItemMeta() == true){
                   
                List<String> lore = i.getItemMeta().getLore();
               
                String damage = "damage";
                String looree = lore.toString();
               
                if (looree.toLowerCase().contains(damage)){
                   
               
               
            Scanner s = new Scanner(looree).useDelimiter("[^0-9]+");
                   
                    int damagevalue = s.nextInt();
                   
                    event.setDamage(damagevalue);
                }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. Offline

    noraver

    CreeperShift nope never asked for anyone to rewrite it, also it's not my code i'm trying to adapt it to my plugin that's in development, NBT is still new to me and how they have it, why i asked kind of pointers on where to look and what i may need to edit not asking for whole thing.
     
  8. Offline

    CreeperShift

    lol! You still didn't tell me what exactly you are trying to do ._.
     
  9. Offline

    noraver

    no im not trying to get any bonuses or apply anything i just wish to change so where it's looking for LEATHER_LEGGINGS it checks for a lore instead
     
  10. Offline

    CreeperShift

    Then I don't understand why my example is not what you are looking for. It does exactly what you just said. It checks for lore!

    Code:
    //You need an itemstack, lets call it i!
     
             
                if(i.hasItemMeta() == true){
    //check if i has any meta, if it has lore it also has metadata, meaning it wont give us a nullpointer when we try to call it on an item without lore
     
    List<String> lore = i.getItemMeta().getLore();
    //this creates a list of strings with ANY LORE the item may contain
     
    Alternatively you could also just convert it to a string, makes it easier for searching:
    String lore = i.getItemMeta().getLore().toString();
     
    now you can easily do
    if (lore.toLowerCase().contains("any lore you might have added"){
     
    //do something in here
     
    }
     
     
    
    It's really easy, this is basically how you check if an item has lore and WHICH lore.

    You should be able to include that in your plugin easily.
     
  11. Offline

    ohtwo

    It's stylistic. Camel-case seems to be the norm for Java, anyway. It's for quicker readability when you need to be more descriptive with your variables.
     
  12. Offline

    ZeusAllMighty11

    I hope you're talking about the iPhone, sorry if you misinterpreted what I said, I meant that you shouldn't start variables with a capital for the sake that it's what classes start with
     
    ohtwo likes this.
Thread Status:
Not open for further replies.

Share This Page