New to coding, kit plugin bug

Discussion in 'Plugin Development' started by celmore123, Nov 29, 2017.

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

    celmore123

    I am new to coding. When someone types /kit it says "specify a kit" as intended. However, when someone types /kit pvp or /kit archer, nothing happens. I fooled around with it for about an hour. I am using mc 1.8.8 and using the latest build of eclipse oxygen to code. If there is a simple mistake im making could you please point it out. There are no "yellow" or "red" errors.
    kit.java
    https://pastebin.com/aqttipac
    plugin.yml
    https://pastebin.com/SYcncqeH
     
  2. Online

    timtower Administrator Administrator Moderator

    @celmore123 Strings are compared with equals and equalsIgnoreCase, not with ==
     
  3. Offline

    celmore123

    Thank you so much!
     
  4. Building on this, all objects are compared with .equals()
    If the data type starts with a capital letter, use equals, if not, use ==. Most of the time.

    Sent from my SM-G903F using Tapatalk
     
  5. Not really...

    If you're dealing with primitive data types (chars, ints, booleans) use '=='. If you're dealing with anything else the general good practice is equals() or equalsIgnoreCase() for a String.
     
  6. That's essentially what I said. It's convention to name anything that should typically be compared with .equals() (classes, enums, etc) with a capital letter at the start. I was simply making iteasier for someone who is clearly a newbie to understand.

    Sent from my SM-G903F using Tapatalk
     
  7. String Example = “hi”

    If Example.equals();

    That’s not convention .-.
     
  8. That's why I put most of the time. And equals can be used for comparing strings if you are case sensitive.

    Sent from my SM-G903F using Tapatalk
     
  9. @TheMinecraftKnight

    Why (open)

    Use the String.equals(String otherString) function to compare strings, not the == operator.

    The reason is that == just compares object references.

    where as .equals() of String class checks equality, because

    String classes equals method ovveridden in such a way that the passed String objects values is same as current Object

    equals() method from Source code of String:

    Code:
     public boolean equals(Object anObject) {
    1013        if (this == anObject) {
    1014            return true;
    1015        }
    1016        if (anObject instanceof String) {
    1017            String anotherString = (String)anObject;
    1018            int n = count;
    1019            if (n == anotherString.count) {
    1020                char v1[] = value;
    1021                char v2[] = anotherString.value;
    1022                int i = offset;
    1023                int j = anotherString.offset;
    1024                while (n-- != 0) {
    1025                    if (v1[i++] != v2[j++])
    1026                        return false;
    1027                }
    1028                return true;
    1029            }
    1030        }
    1031        return false;
    1032    }
    So you should write

    Code:
    if(gender.equals("boy")){
    
    }
    or to comapre with regardless of case
    
    if(gender.equalsIgnoreCase("boy")){
    
    }
    and for null safety
    
    if("boy".equals(gender)){
    
    }
    Future reference:

    Code:
    String s1 = "Hello";              // String literal
    String s2 = "Hello";              // String literal
    String s3 = s1;                   // same reference
    String s4 = new String("Hello");  // String object
    String s5 = new String("Hello");  // String object
    Here  s1 == s2 == s3 but s4 != s5


    Taken from top anwser: https://stackoverflow.com/questions/17443201/why-doesn-t-work-on-string
     
  10. That's what I said earlier. Use .equals() to compare case sensitive strings.

    Sent from my SM-G903F using Tapatalk
     
  11. Offline

    celmore123

    How do i enchant an item greater than the allowed maximum without getting an error (like an itemstack)
     
  12. Online

    timtower Administrator Administrator Moderator

  13. Offline

    celmore123

    Code:
    ItemStack sword = new ItemStack(Material.STONE_SWORD, 1);
                     sword.addEnchantment(Enchantment.KNOCKBACK, 1);
                     ItemMeta swordmeta = sword.getItemMeta();
                     swordmeta.setDisplayName(ChatColor.RED + "Blade Of Pain");
                    pi.addItem(sword);
     
    just gives me a normal stone sword, no name. Why? Also, should I start new threads for every question.
     
  14. Online

    timtower Administrator Administrator Moderator

    @celmore123 You never set the itemmeta on the item again.
    And if it is very different from the first question, which isn't the case yet.
     
  15. Offline

    celmore123

    Code:
    ItemStack sword = new ItemStack(Material.STONE_SWORD, 1);
                    sword.addEnchantment(Enchantment.KNOCKBACK, 1);
                    sword.setDisplayName(ChatColor.RED + "Blade Of Pain");              
                    pi.addItem(sword); 
    doesnt work, nor does 
    ItemStack sword = new ItemStack(Material.STONE_SWORD, 1);
                    sword.addEnchantment(Enchantment.KNOCKBACK, 1);
    swordmeta = sword.getItemMeta();
    Code:
       sword.addEnchantment(Enchantment.KNOCKBACK, 1);
                    ItemMeta swordmeta = sword.getItemMeta();
                    swordmeta.setDisplayName(ChatColor.RED + "Blade Of Pain");
                    ItemMeta swordmeta1 = sword.getItemMeta();
                    pi.addItem(sword);
                   
     
     
  16. Online

    timtower Administrator Administrator Moderator

    @celmore123 Because you never set the itemmeta back to the item.
    ItemStack#setItemMeta
     
Thread Status:
Not open for further replies.

Share This Page