Solved Need help nothing in console

Discussion in 'Plugin Development' started by dbaum102, May 28, 2016.

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

    dbaum102

    Code:
    public void placeChestToWorld(BlockPlaceEvent e){
            Player p = e.getPlayer();
            if(main.plugin.getConfig().getBoolean("currentEditing."+p.getName()+".placingChest.vote")){
                if(e.getBlock().getType()==Material.CHEST){
                    Location loc = e.getBlockPlaced().getLocation();
                    List<String> temp = (List<String>) main.plugin.getConfig().getList("crates.vote.location");
                    temp.add(loc.getWorld().getName()+" "+loc.getX()+" "+loc.getY()+" "+loc.getZ());
                    main.plugin.getConfig().set("currentEditing."+p.getName()+".placingChest.vote", false);
                    main.plugin.saveConfig();
                    p.sendMessage(ChatColor.GREEN+"Vote crate successfully placed and saved!");
                }
            }
            else if(main.plugin.getConfig().getBoolean("currentEditing."+p.getName()+".placingChest.myth")){
                if(e.getBlock().getType()==Material.CHEST){
                    Location loc = e.getBlockPlaced().getLocation();
                    List<String> temp = (List<String>) main.plugin.getConfig().getList("crates.myth.location");
                    temp.add(loc.getWorld().getName()+" "+loc.getX()+" "+loc.getY()+" "+loc.getZ());
                    main.plugin.getConfig().set("currentEditing."+p.getName()+".placingChest.myth", false);
                    main.plugin.saveConfig();
                    p.sendMessage(ChatColor.GREEN+"Myth crate successfully placed and saved!");
                }
            }   
        }
    Not sending message on place.... config looks good tho
    Code:
    currentEditing:
      dbaum:
        placingChest:
          vote: true
    

    Edit: lol i was missing the @EventHandler... but now i get an npe with this code, same but modified:
    Code:
    @EventHandler
        public void placeChestToWorld(BlockPlaceEvent e){
            Player p = e.getPlayer();
            if(main.plugin.getConfig().getBoolean("currentEditing."+p.getName()+".placingChest."+crateType.toLowerCase())){
                if(e.getBlock().getType()==Material.CHEST){
                    Location loc = e.getBlockPlaced().getLocation();
                    List<String> temp = (List<String>) main.plugin.getConfig().getList("crates."+crateType+".location");
                    temp.add(loc.getWorld().getName()+" "+loc.getX()+" "+loc.getY()+" "+loc.getZ());
                    main.plugin.getConfig().set("currentEditing."+p.getName()+".placingChest."+crateType.toLowerCase(), false);
                    main.plugin.saveConfig();
                    p.sendMessage(ChatColor.GREEN+crateType.toUpperCase()+" successfully placed and saved!");
                }
            }
        
        }
    There currently is no locations in the config so it is probably coming from there, it is trying to get the list when the list is not there / null would i just add if(list!=null) or list == null?

    Update:
    Code:
    @EventHandler
        public void placeChestToWorld(BlockPlaceEvent e){
            Player p = e.getPlayer();
            if(main.plugin.getConfig().getBoolean("currentEditing."+p.getName()+".placingChest."+crateType.toLowerCase())){
                if(e.getBlock().getType()==Material.CHEST){
                    Location loc = e.getBlockPlaced().getLocation();
                    List<String> temp = (List<String>) main.plugin.getConfig().getList("crates."+crateType+".location");
                    if(temp!=null){
                        temp.add(loc.getWorld().getName()+" "+loc.getX()+" "+loc.getY()+" "+loc.getZ());
                        main.plugin.getConfig().set("currentEditing."+p.getName()+".placingChest."+crateType.toLowerCase(), false);
                        main.plugin.saveConfig();
                        p.sendMessage(ChatColor.GREEN+crateType.toUpperCase()+" successfully placed and saved!");   
                    }
                    else{
                        main.plugin.getConfig().set("crates."+crateType+".location", loc.getWorld().getName()+" "+loc.getX()+" "+loc.getY()+" "+loc.getZ());
                        main.plugin.getConfig().set("currentEditing."+p.getName()+".placingChest."+crateType.toLowerCase(), false);
                        main.plugin.saveConfig();
                        p.sendMessage(ChatColor.GREEN+crateType.toUpperCase()+" successfully placed and saved!");   
                    }
                }
            }
           
        }
    This works saves the location but does not change the value of the boolean and doesnt send the message idk why :p
     
    Last edited: May 28, 2016
  2. Offline

    Zombie_Striker

    @dbaum102
    NPEs are caused when something is null. Check if the following objects are null:
    1. main
    2. main.plugin
    3. main.plugin.getConfig()
    4. .... .getConfig().getBoolean("currentEditing."+p.getName()+".placingChest."+crateType.toLowerCase())
    5. e.getBlock()
    6. loc
    7. crateType
     
  3. Offline

    dbaum102

    i can confirm 1-4 arent null and 7 ill check 5 and 6

    also i didnt get an npe i am getting nothing in console it just does the seting of the location but doesnt return to the user the message i have it send
    @Zombie_Striker
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    Fixed
     
    Last edited: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page