Strange Null Error

Discussion in 'Plugin Development' started by Hex_27, Jun 30, 2015.

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


    I have 2 pieces of code
                        if(selectone.get(p.getName()) != null){
                            if(selecttwo.get(p.getName()) != null){
                            if(args.length == 2){
                            if(plugin.getConfig().isSet("regions." + args[1])){
                                p.sendMessage(ChatColor.GREEN + "Replaced old region " + args[1] + " with new one");
                            plugin.getConfig().set("regions." + args[1] + ".select1", locationToString(selectone.get(p.getName())));
                            plugin.getConfig().set("regions." + args[1] + ".select2", locationToString(selecttwo.get(p.getName())));
                        p.sendMessage(ChatColor.GREEN + "Region " + args[1] + " added");
                            p.sendMessage(ChatColor.RED + "Selection 2 with /sc wand must be set before using this command.");
                            p.sendMessage(ChatColor.RED + "Selection 1 with /sc wand must be set before using this command.");

        public void onPlayerInteract(PlayerInteractEvent event){
            if(event.getPlayer().getItemInHand() != null){
                if(event.getPlayer().getItemInHand().getItemMeta() != null){
                    if(event.getPlayer().getItemInHand().getItemMeta().getDisplayName() != null){
                        if(event.getPlayer().getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Grey Territory Wand")){
                            if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
                                this.selecttwo.put(event.getPlayer().getName(), event.getClickedBlock().getLocation());
                                event.getPlayer().sendMessage(ChatColor.GREEN + "Selection 2 selected at " + locationToString(selecttwo.get(event.getPlayer().getName())));
                            }else if(event.getAction() == Action.LEFT_CLICK_BLOCK){
                                this.selectone.put(event.getPlayer().getName(), event.getClickedBlock().getLocation());
                                event.getPlayer().sendMessage(ChatColor.GREEN + "Selection 1 selected at " + locationToString(selectone.get(event.getPlayer().getName())));
    This second code will send me the selection messages, but the command /sc newregion tells me that select1.get(p.getName()) is null. I did this all using the same player.
  2. Stack trace?
  3. Offline


    Is Select1 null? Is p null? Did you null check?
  4. Offline


    @Zombie_Striker At later parts, I checked both selects. Both are null.

    It won't help. It just points to select1 or 2 .get(p.getUniqueId); being null
  5. @Hex_27
    I can't really find your issue, but I did notice something else. You called saveDefaultConfig() when setting the paths, that has to be saveConfig() or else your data won't get saved
  6. Offline


    @megamichiel But my comments...
    Besides that, the program doesn't really reach that part. The error just decides to come out
  7. This is strange... Where are you storing selectone and selecttwo?
  8. Offline


    @megamichiel Sorry if I'm reluctant to, but this is a paid plugin, so I'm not ready to release large parts of the code publicly. Besides, what does onEnable have to do with this? The plugin can enable itself fine, and the other listeners in the problematic class work fine. (Except the selections being null.)

    @CodePlaysMinecraft In instantiated hashmaps. <UUID, Location>
    Last edited: Jul 2, 2015
  9. Offline


    @Hex_27 You charge a person to develop a plugin for someone and you can't handle to finish that task.

    Now these people here are trying to help you as best as they possibly can. If you don't want to show some code or at least post a stacktrace, then I guess you've come to the wrong place.
  10. Print out the Map when a player uses the command.

    I.e. After:

    If it's empty, it means something is clearing the Map or removing it.

    By the way, I'd recommend using a custom made class, e.g. called Selection, that contains two int arrays and the string (world name). The int arrays having a size of 3, and the xyz coords are put in there. It's easier to manage one Map than two.
  11. @Hex_27
    I wanted to know if you may have registered the command in another instance as the listener
  12. Offline


    @megamichiel Yes I have, and the other listeners work fine. That listener works too, but select1 and 2 just become null
  13. Offline


    @Hex_27, let's start here.

    First of all, stop using player names. I don't know how many times we will have to say this. Names break plugins. Tons of servers advocate not changing names for this exact reason- tons of devs refuse to switch to UUID. Please don't contribute. I know those hashmaps aren't set with the generic type of UUID. If they are, you need a better IDE that will warn you to unchecked cast errors.

    Denying us the stack trace is going to make this hard, but what I think is happening is that you have several instances of the same class. Each listener is registered differently, (The amount of people who don't understand Java's memory practices drive me insane). This is a temp fix, but set the hashmaps as final and static. DON'T LEAVE THEM THIS WAY. If it suddenly works, come back and post your listener declarations. If you get a syntax error, you screwed up bad somewhere.
    Last edited: Jul 3, 2015
    CodePlaysMinecraft and Synapz like this.
  14. Offline


    @Tecno_Wizard It was UUID, I changed it to names cos I wanted to see if it worked. I'll try the static thing.
Thread Status:
Not open for further replies.

Share This Page