Need help with Join/Respawn Effects

Discussion in 'Plugin Development' started by DerFreakey, Aug 14, 2014.

Thread Status:
Not open for further replies.
  1. Hello Guys,
    i need help. I'm writing a bukkit plugin, but there is a bug i can't solve. The plugin works fine, but when i respawn/join on the server it doesn't give me the potion effects I need. I am making an RPG Classes plugin, and on Respawn/Join it reads your class out of an file and gives you the potion effects that i specified for this class. but on respawn/join it doesnt give you any effects! How can i solve this?

    My respawn event:
     
  2. Offline

    fireblast709

    DerFreakey you misplaced some parenthesis. Currently you are checking if
    Code:
    cfgplayer.getString(p.getName()) + "."+"class:"
                                    ^ Note, we actually get the config string and concatenate .class
    matches null, which it will never do (it will throw a NullPointerException if the player doesn't exist)
     
  3. Offline

    GameplayJDK

  4. Of course i have GameplayJDK

    @firestblast709
    I'm new in bukkit programming
    so how can i fix this?
     
  5. Offline

    ZodiacTheories

    DerFreakey

    Code:java
    1. if(cfgplayers.getString(p.getName()) + "." + "class:" == "assassin") {


    Like fireblast709 said, you are misplacing parantheses. You also cannot use == to compare strings, use .equals() or .equalsIgnoreCase()
     
  6. ZodiacTheories
    How can i fix this?
    Im from austria so my english is not so good.
    Can you send me the right code?
     
  7. Offline

    ZodiacTheories

    DerFreakey
    Code:java
    1. if(cfgplayers.getString(p.getName() + "." + "class:").equals("assassin")) {


    You cannot use == for comparing strings, you used parentheses completely wrong. I give you permission to use the code only if you understand the changes, ok? (lolz custom copyright)
     
  8. Offline

    fireblast709

    DerFreakey you will find that this is more of a Java thing. You need to do
    Code:
    getString(p.getName()+".class")
    to get the class. To prevent NullPointerExceptions, make that
    Code:
    getString(p.getName()+".class", "")
    where the second parameter is the default (so where the value normally returns null, it will return "").

    Secondly, you need to use equals() to compare Strings, not ==.

    [Attempted translation - partially google and partially me]
    Es ist etwas von Java, nicht Bukkit alleine. Zum erste musst du die Parenthese nach links setzen.
    Code:
    getString(p.getName()+".class")
    . Um eine NullPointerException zu verhindern, kannst du ein Standard hinzufügen (zweite Parameter)
    Code:
    getString(p.getName()+".class", "" <- dies ist der Standard, ein leer String)
    Zweitens, du kannst nicht == verwenden Strings zu vergleichen, du benötigst equals() zu benutzen. == prüft Referenz, nicht die Wert (was du söllst prüfen)
     
  9. Thank you @firestblast709 =)

    Your german is pretty good :)
     
Thread Status:
Not open for further replies.

Share This Page