[Help Needed] getLogger not showing up (Read comments)

Discussion in 'Plugin Development' started by XXLuigiMario, Jul 2, 2014.

Thread Status:
Not open for further replies.
  1. I have this:

    Code:java
    1. public void checkConfig(){
    2. if (getConfig().getConfigurationSection("Settings") == null){
    3. errorConfig("configuration section","Settings");
    4. }else if (getConfig().getString("Settings.Enabled") != null){
    5. errorConfig("boolean","Enabled");
    6. }else if (getConfig().getString("Settings.PrefixEnabled") != null){
    7. errorConfig("boolean","Enabled");
    8. }else if (getConfig().getString("Settings.Prefix") != null){
    9. errorConfig("boolean","Prefix");
    10. }else if (getConfig().getString("Settings.Message") != null){
    11. errorConfig("string","Settings.Message");
    12. }else if (getConfig().getString("Settings.AlternativeMessage") != null){
    13. errorConfig("string","Settings.AlternativeMessage");
    14. }else if (getConfig().contains("List") == false){
    15. errorConfig("configuration section","List");
    16. }else{
    17. if (this.Reloading == true){
    18. return;
    19. }else{
    20. getLogger().info("Config loaded successfully!");
    21. }
    22. }
    23. }


    and this:

    Code:java
    1. public void errorConfig(String reason, String value) {
    2. if (this.Reloading == true){
    3. Player player = Bukkit.getPlayer(this.Player);
    4. player.sendMessage(ChatColor.DARK_RED + "Error trying to read the config! Missing " + reason + "(" + value + "). Disabling plugin...");
    5. }
    6. getLogger().log(Level.SEVERE, "Error trying to read the config! Missing " + reason + "(" + value + "). Disabling plugin...");
    7. Bukkit.getPluginManager().disablePlugin(this);
    8. }


    I use it to avoid NullPointerExceptions while using the plugin, and I want to know if there's a better way to do this... Oh and the other reason on why am I creating this thread is that, in the errorConfig() method, the last getLogger() doesn't run... it gets disabled before the plugin prints that in the console, is there any way to fix it?
     
  2. Offline

    jollie000l

    Try using a try catch statement.

    i.e.

    Code:java
    1. try{
    2. // Your methods here
    3. // Handle the exception or return, or leave it and be lazy
    4. }
     
  3. jollie000l I know, I was going to use them in the first place, but...
    It didn't look very well, and there were try/catches everywhere.

    I forgot to mention that the checkConfig() gets called in the onEnable() and when the plugin gets reloaded.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    xTigerRebornx

    XXLuigiMario I see you are using a Player of sorts in the code, where are you getting this Player from?
     
  5. if (player instanceof Player) this.Player = ((Player) player).getUniqueId();
     
  6. Offline

    xTigerRebornx

  7. Offline

    AoH_Ruthless

    XXLuigiMario
    What is Player, anyways? .. you should not be naming your field starting with uppercase letters (to make sure it is not confused with a class) if Player is not a UUID you will probably get ClassCastExceptions..

    Can we see your full main class? It would greatly help us find your issue faster, along with the full stacktrace so we can quickly guide you in the right direction.
     
  8. There isn't any stacktrace, the only issue I have is that this:
    Code:java
    1. Bukkit.getPluginManager().disablePlugin(this);

    Runs before this:
    Code:java
    1. getLogger().log(Level.SEVERE, "Error trying to read the config! Missing " + reason + "(" + value + "). Disabling plugin...");


    Inside a command.

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

    xTigerRebornx

    XXLuigiMario Yet you are trying to use this Player onEnable(), when the command is never called? Drop the whole 'messaging the Player', simply use the logger.
     
  10. Offline

    Necrodoom

  11. xTigerRebornx Ok, I removed the message to player thing. But how do I fix this?
     
  12. Offline

    Necrodoom

     
  13. Offline

    Gater12

  14. Offline

    micrlink

    Try setting defaults for values that don't exist
     
  15. Yes, I may do that, but my biggest issue now is this:

    Look, try this example code I wrote:

    Code:java
    1. package me.Someone.Main;
    2.  
    3. import java.util.logging.Level;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class Main extends JavaPlugin{
    9.  
    10. public static TestPlugin plugin;
    11.  
    12. public void onEnable() {
    13. getLogger().info("TestPlugin by XXLuigiMario has been enabled.");
    14. getLogger().log(Level.SEVERE, "A random error has occurred!");
    15. Bukkit.getPluginManager().disablePlugin(plugin);
    16. }
    17.  
    18. public void onDisable() {
    19. getLogger().info("TestPlugin by XXLuigiMario has been disabled.");
    20. }
    21. }


    The getLogger() saying "A random error has occurred!" won't be shown in the console, and the plugin will be disabled. How do I fix it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  16. Offline

    xTigerRebornx

    XXLuigiMario Plugin wouldn't be disabled in example as you never initialize the instance,
    As said multiple times, post your full code. Not an example, not a snippet, your full code.
     
  17. Offline

    MCMastery

    XXLuigiMario Just a tip, use comments a lot, or if you ever go back to the program, it would be very hard to understand and edit
     
  18. Offline

    xTigerRebornx

    XXLuigiMario Mind pointing out the current problem with the code?
     
  19. xTigerRebornx this ^
    Yeah, I'll do it before releasing the first version.
     
  20. Offline

    xTigerRebornx

    XXLuigiMario Doesn't exactly give the problem. What happens, what is the expected behavior, where does "this" run before "this" in the code?
     
  21. xTigerRebornx
    I always forget to Tahg x_x
    And I can't edit my older posts because the formatting gets messed up.
     
  22. Offline

    xTigerRebornx

    XXLuigiMario
    Code:
    @Override
        public void onEnable(){
            this.getLogger().log(Level.SEVERE, "Error");
            Bukkit.getPluginManager().disablePlugin(this);
        }
    Works fine for me. Debug to see if errorConfig() is actually being invoked.
     
  23. Umm... wtf... it's working now :confused:
     
Thread Status:
Not open for further replies.

Share This Page