Error With My Reading of Config.Yml

Discussion in 'Plugin Development' started by pdkkid188, Jul 2, 2013.

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

    pdkkid188

    Hello Everyone! I have a ok knowledge of java programming for bukkit, but every time i try and receive an integer or string from a config.yml file that i generated, i can never get it to work, any ideas on what im doing wrong?
     
  2. Offline

    MP5K

    Hello pdkkid188,
    there could be a may possible reasons, but it would be easier for us if you could post some code.
    And did you try take a look at the Bukkit Configuration Tutorial?
     
  3. Offline

    pdkkid188

    sure

    Startup
    Code:
        public void onEnable() {
            try {
                Metrics metrics = new Metrics(this);
                metrics.start();
            } catch (IOException e) {
                // Failed to submit the stats :-(
            }
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(this.bl, this);
            pm.addPermission(new Permissions().canExplode);
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled. Created By Pdkkid");
            this.getServer().getConsoleSender().sendMessage(ChatColor.RED  + "Need To Advertise Your Server?" + ChatColor.GOLD + " Http://MajorMcServers.Net");
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    Code Trying To Grab From Config
    Code:
        if (e.getEntity() instanceof Player){
            World deathWorld = player.getWorld();
            Location playerspot = player.getLocation();
                if(player.hasPermission(new Permissions().canExplode)) {
                    deathWorld.createExplosion(playerspot.getX(), playerspot.getY(), playerspot.getZ(), plugin.getConfig().getInt("ExplosionPower"), false, false);
                }
            }
        }   
    }
    Config
    Code:
    # Default Configuration file.
    # Explosion Power is the power when a player dies, and he creates an explosion
    ExplosionPower: 3
     
  4. Offline

    MP5K

    and what exactly is the problem with your code?
    is it throwing exceptions or what is it doing?

    edit:
    try replace "getConfig().options().copyDefaults(true);"
    with "saveDefaultConfig();"
    that usually work's for me :D
     
  5. Offline

    pdkkid188

    in game when i die, it should take the value in the config, which is set to 3 and create and explosion where the player was standing, but instead, i receive this error on death
    Code:
    12:42:31 [SEVERE] Could not pass event PlayerDeathEvent to DeathExplode v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        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 org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:344)
        at net.minecraft.server.v1_5_R3.EntityPlayer.die(EntityPlayer.java:293)
        at org.bukkit.craftbukkit.v1_5_R3.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:77)
        at org.bukkit.command.defaults.KillCommand.execute(KillCommand.java:33)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerConnection.java:971)
        at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.java:889)
        at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:846)
        at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:115)
        at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at net.emazingcraft.pdkkid.deathexplode.DeathListener.Playerdeath(DeathListener.java:23)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 22 more
    2013-07-02 12:42:31 [INFO] pdkkid died
    
    Edit:
    when i remove the plugin.getConfig().getInt("ExplodePower") and replace it with 3, which is the value in the config.yml it works perfectly
     
  6. Offline

    MP5K

    make sure that "plugin" is not null and "ExplodePower" exists in your config
     
  7. Offline

    pdkkid188

    Code:
    public static DeathExplode plugin;
    Code:
    # Default Configuration file.
    # Explosion Power is the power when a player dies, and he creates an explosion
    ExplosionPower: 3
     
  8. Offline

    MP5K

    then don't forget to call "plugin = this;" in your onEnable method
     
  9. Offline

    pdkkid188

    Still getting that error:/

    this is the line of code which is trying to grab from the config
    Code:
    deathWorld.createExplosion(playerspot.getX(), playerspot.getY(), playerspot.getZ(), plugin.getConfig().getInt("ExplosionPower"), false, false);
    Edit:
    This is the part of the line, that should work, but gives me huge error codes when i die in game
    plugin.getConfig().getInt("ExplosionPower")

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

    callum.thepro

    remove the caps in your getInt and your config, i think that will fix it but I am really unsure, i remember before i came across a similar problem and I asked a friend and that is what I believe he said.
     
  11. Offline

    pdkkid188

    wait i think i know what im doing wrong and its not my grabbing from the config, that works fine, but how would i change an integer value into a float value?
     
  12. Offline

    callum.thepro

    put the integer name and put F at the end of it
     
  13. Offline

    pdkkid188

    what do you mean by that? Im trying to take getConfig().getInt("power") and turn it from an integer to a float, so i could just define it as
    Code:
    Int power = getConfig().getInt("power");
    Where would i put an F in that?
     
  14. Offline

    callum.thepro

    Oh, i got the wrong idea, you would just need to cast it to a float
     
  15. Offline

    pdkkid188

    ): im still getting an error, am i doing anything wrong?
    Code:
    deathWorld.createExplosion(playerspot.getX(), playerspot.getY(), playerspot.getZ(), (float) plugin.getConfig().getInt("power"), false, false);
     
Thread Status:
Not open for further replies.

Share This Page