[SOLVED] Mapping Values Are Not Allowed Here: Configuration Issues

Discussion in 'Plugin Development' started by np98765, Sep 4, 2012.

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

    np98765

    Lovely -- Once again, I'm having issues with configuration.

    Code:
    Caused by: java.lang.NullPointerException
    at com.lavacraftserver.UltimateGrenades.EggListener.onProjectileHit(EggListener.java:44)
    
    Code:
    private Grenade plugin;
    //Grenade is the name of my main class
     
    if (plugin.getConfig().getString("grenades.egg.grenade-effect").equals("confusion")) {
    //Line 44 ^^
    
    This is the relevant portion in the config:
    Code:
    grenades:
        egg:
            grenade-effect: 'real-explosion'
    
    Since I get the error on that specific line, I'm assuming it's how I got the config. Was I not supposed to use 'plugin'? Did I not use correct YAML syntax? I tried with and without the apostrophes; I was getting kind of desperate...

    Any help is much appreciated. I've been promising releases for this plugin for a while now, and haven't managed to because of this error.

    Thanks!
     
  2. Offline

    CRAZYxMUNK3Y

    .equals() is used to compare objects. Try if (plugin.getConfig().getString("grenades.egg.grenade-effect") == plugin.getConfig().getString("confusion"))
     
  3. Offline

    np98765

    Sometimes I make myself wonder.

    Thanks; I'll be sure to fix that tomorrow. :)
     
  4. Offline

    theguynextdoor

    I would recommend you google comparing strings. http://stackoverflow.com/a/513839

    I would say here, have you initialised your plugin variable?
     
    mavis likes this.
  5. Offline

    np98765

    Could you give me an example? I've tried 2-3 things already; none worked.

    Also, thanks for the helpful link. :)
     
  6. Offline

    calebbfmv

    Well, you are trying to read from the config right?
    If so, the code you have should work. only if you have a "plugin" variable :p
    this.plugin = plugin;
     
  7. Offline

    np98765

    This is in my Listener...

    Code:
    public EggListener(Grenade instance) {
    this.plugin = instance;
    }
    
    I've just been toying around with different ways, but it doesn't seem like anything is working. Still getting an NPE. -_-
     
  8. Offline

    calebbfmv

    NP, come on man, then you need to do [code[ instance.getConfig()//w/e goes here)[/code]
    Silly!
     
  9. Offline

    np98765

    Ugh, I'm not getting some alerts. -_-

    And... No? Just passing it as an instance or whatever (excuse my lack of terminology). I don't think that would work; shall I go test it? :p

    EDIT: Yep, "instance cannot be resolved". Anyways, my eyes are drooping and I have still homework to do... So I'll -- zzzzzzz....
     
  10. Offline

    calebbfmv

    lol never mind, I shall show you later, have fun doing HW at 10 PM! or whatever time it is.

    ALSO offtpoic: Creating the CoreProtect hook for HarryPotterSpells, if you want.
     
  11. Offline

    np98765

    Ah, awesome. :) Saw that comment, but I haven't actually remembered to respond to any of them... :confused:

    Well, I won't continue to derail the thread -- Once you start, it's hard to end. :3

    I'm sure this'll be resolved in the morning (I know I'm missing one simple thing... Just don't know what), so I can finally release this plugin (about a week late...).
     
  12. Offline

    calebbfmv

    lol I shall rewrite the entire thingg for you. Wait then you won't learn. Eh do HW
     
  13. Offline

    np98765

    theguynextdoor: I've different ways, and I'm not quite sure why it's not working. I've been searching through this forum again, and it seems like this (below) is what the issue was for most people.


    Main class: Grenade
    Listener: EggListener

    Code:
    public Grenade plugin;
     
    public EggListener(Grenade instance) {
    plugin = instance;
    }
    
    Do I need to do something in the main class about this? Is the above code wrong? Is my migraine affecting how my brain functions? Am I going insane?

    Thanks!
     
  14. Offline

    calebbfmv

    You are going insane. You will die in 30 seconds. Good bye
     
  15. Offline

    bobacadodl

    private Grenade plugin;
    public EggListener(Grenade instance){plugin = instance;}

    EDIT:
    and this should be in your grenade class's onEnable…:
    getServer().getPluginManager().registerEvents(new EggListener(this), this);


    and NOW you should be able to do plugin.getConfig().getString("grenades.egg.grenade-effect").equals("confusion")
     
  16. Offline

    calebbfmv

    Dont confuse the lad, his bonkers I tell yah, bonkers in his wee little 'ead
     
  17. Offline

    bobacadodl

    I'm pretty sure that's right? Did I do something wrong?
     
  18. Offline

    np98765

    Maybe you're the one going insane and will die in 30 seconds, given the fact that I am still here. :3

    Still getting it... Let me post the code, my eyes are getting fuzzy so I probably missed something.

    Main class:
    Code:
    public void onEnable() {
    getServer().getPluginManager().registerEvents(new EggListener(this), this);
    
    EggListener:
    Code:
    public class EggListener implements Listener {
     
    private Grenade plugin;
     
    public EggListener(Grenade instance) {
    plugin = instance;
    }
    
    I know that the events are registered correctly, because my debug messages show up. The major issue is when I get to the config getting. Is this incorrect?
    Code:
    if (plugin.getConfig()....
    
     
  19. Offline

    bobacadodl

    Umm, I don't know if I missed something while learning java, but I thought the more proper way to compare 2 strings was string.equals(another string)

    http://www.devdaily.com/java/edu/qanda/pjqa00001.shtml

    Could you post your error log? (in a spoiler :p)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  20. Offline

    np98765

    Oh yeah, sorry -- That was from my test line. :3

    They truly look like:
    if (plugin.getConfig().getString("grenades.egg.grenade-effect").equals("blindness")) {
     
  21. Offline

    calebbfmv

    I keep getting 505 bad gateway errors, anyway going sleepy time now night
     
  22. Offline

    np98765

    Show Spoiler

    Code:
    [SEVERE] Could not pass event ProjectileHitEvent to UltimateGrenades
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:332)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.EntityProjectile.h_(EntityProjectile.java:159)
        at net.minecraft.server.World.entityJoinedWorld(World.java:1239)
        at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:498)
        at net.minecraft.server.World.playerJoinedWorld(World.java:1221)
        at net.minecraft.server.World.tickEntities(World.java:1119)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:567)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
        at com.lavacraftserver.UltimateGrenades.EggListener.onProjectileHit(EggListener.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:330)
        ... 13 more


    Corresponding line:
    Code:
    if (plugin.getConfig().getString("grenades.egg.grenade-effect").equals("blindness")) {
    
    Hey, apparently
    Code:
    if (plugin.getConfig().getString("grenades.egg.grenade-effect") == "confusion") {
    is correct?

    I'll test this...
     
  23. Offline

    bobacadodl

    I keep getting 502 bad gateway on dev.bukkit.org… I'm trying to create a new project but can't
     
  24. Offline

    np98765

    Apparently, it seems like
    Code:
    if (plugin.getConfig().getString("grenades.egg.grenade-effect") == "confusion")
    
    will not generate an error, while

    Code:
    if (plugin.getConfig().getString("grenades.egg.grenade-effect").equals("confusion"))
    
    does.
     
  25. Offline

    bobacadodl

    Ok that's really weird. I always used .equals(anotherstirng) and I never have any errors. I was taught that == with strings was incorrect.
     
  26. Offline

    np98765

    bobacadodl

    I'm going to put my config here, because I have a feeling that this is what's causing the issue.

    Code:
    grenades:
        egg:
            grenade-radius: 10
            grenade-effect: 'confusion'
                confusion-duration: 10
                blindness-duration: 10
                burn-time: 10
    
    EDIT: Apparently, mapping values aren't allowed on the ":" after confusion-duration. Did I not space this correctly or something?

    I was told that above as well...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  27. Offline

    calebbfmv

    odd bukkit dev must be being redone
     
  28. Offline

    np98765

    bobacadodl
    Any more ideas on how to fix this? I'm lost and very confused.
     
  29. Offline

    Sagacious_Zed Bukkit Docs

    This becomes obvious when you consider what kind of equality you are testing for.
    Are you testing for logical equality, that the two objects have the same information.
    Are you testing for instance equality, that the two objects are in fact the same object.
     
  30. Offline

    PandazNWafflez

    For people that don't understand your fancy stuff :p, that means
    Code:
    stringObject == "String"
    will always be false because while they have the same string data they are different objects so use equals or equalsIgnoreCase or your code will be as obsolete as if you did
    Code:
    if (false)
     
Thread Status:
Not open for further replies.

Share This Page