Solved [Help] Getting Code From Config.

Discussion in 'Plugin Development' started by DeluXeNationMC, May 8, 2014.

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

    DeluXeNationMC

    - Code removed.
     
  2. Offline

    Condolent

    If you're asking what the code is to get something from the config it'd be:
    Code:java
    1. getConfig().getString("LaunchBlock");


    If the eventhandler is in a seperate file, then you need to add this to the event-file:
    Code:java
    1. MAINCLASS plugin;
    2.  
    3. public Events(MAINCLASS instance) {
    4. plugin = instance;
    5. }
    6.  
    7. public FileConfiguration getConfig() {
    8. return plugin.getConfig();
    9. }
     
  3. Offline

    DeluXeNationMC

    I understand the
    Code:java
    1. getConfig().getString("LaunchBlock");

    but how would i use this to change
    Code:java
    1. Material.GOLD_PLATE

    in the config.yml ?
     
  4. Offline

    minoneer

    Material.valueOf(String) :)
     
  5. Offline

    DeluXeNationMC

    minoneer This is spewing out errors in the console and it will not launch me. I will post the error give me a second :)

    Code:
    [syntax=java][19:10:59 ERROR]: Could not pass event PlayerMoveEvent to DeluXeLaunchPads v2.0
     
    org.bukkit.event.EventException
     
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
     
    va:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
     
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at me.Incomprehendable.WorldPlugins.FakePluginManager.fireEvent(FakePlug
     
    inManager.java:138) [PerWorldPlugins.jar:?]
     
    at me.Incomprehendable.WorldPlugins.FakePluginManager.callEvent(FakePlug
     
    inManager.java:124) [PerWorldPlugins.jar:?]
     
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
     
    :234) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [cr
     
    aftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.PacketPlayInPosition.handle(SourceFile:6
     
    3) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
     
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
     
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
     
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
     
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
     
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
     
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
     
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    Caused by: java.lang.IllegalArgumentException: No enum constant org.bukkit.Mater
     
    ial.LaunchBlock
     
    at java.lang.Enum.valueOf(Unknown Source) ~[?:1.7.0_55]
     
    at org.bukkit.Material.valueOf(Material.java:64) ~[craftbukkit.jar:git-B
     
    ukkit-1.7.2-R0.3-b3020jnks]
     
    at me.DeluXeNationMC.DeluXeLaunchPads.Main.onPlayer(Main.java:66) ~[?:?]
     
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source) ~[?:?]
     
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
     
    .7.0_55]
     
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
     
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
     
    va:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
     
    ... 13 more[/syntax]
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    werter318

    DeluXeNationMC Enum#valueOf() doesn't need the name so only GOLD_PLATE
     
  7. Offline

    1Achmed1

    Code:java
    1. // put this above your onEnable
    2. public static String launchBlock;
    3. // in onEnable
    4. launchBlock = getConfig().get("LaunchBlock");
    5. // and use launchBlock instead of GOLD_BLOCK
     
  8. Offline

    DeluXeNationMC

    This is my code currently:
    Code:java
    1. public static String launchBlock;
    2.  
    3. @Override
    4. public void onEnable(){
    5. getConfig().options().copyDefaults(true);
    6. saveConfig();
    7. launchBlock = (String) getConfig().get("LaunchBlock");
    8. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    9. this.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[DeluXeLaunchPads] Is Now Enabled!");

    My config.yml file:
    Code:
    # Default Configuration File
    LaunchBlock: GOLD_PLATE
    It does nothing when i step over a GOLD_PLATE am i missing something ?
    EDIT: I get a startup error invalid plugin.yml weird...
    This is my plugin.yml:
    Code:
    name: DeluXeLaunchPads
    main: me.DeluXeNationMC.DeluXeLaunchPads.Main
    version: 2.5
    author: DeluXeNationMC
     
    permissions:
        DeluXe.Launch:
            description: Allows The Player To Get Launched
            default: op
        DeluXe.NoFall:
            description: Stops FallDamage When Launched
            default: op
        DeluXe.DoubleJump:
            description: Allows The Player To Use DoubleJump
            default: op
        DeluXe.*:
            description: Allows All The Permissions To Be Used
            children:
                DeluXe.Launch: true
                DeluXe.NoFall: true
            default: op
           
            
    This is really strange... and this is the error:
    Code:
    [12:52:26 ERROR]: Could not load 'plugins\DeluXeLaunchPads.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
        at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:186) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:350) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:312) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token; found character    '\t' that cannot start any token
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:358) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:563) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:230) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:123) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.yaml.snakeyaml.constructor.BaseC
    Never had this error before... Help please ?

    werter318 I thought so. Thanks for the reply

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

    TGRHavoc

    The error has occured because of the character "\t". You're not using Tabs in the "plugin.yml" are you? If you are... Then there's your problem....
     
  10. Offline

    DeluXeNationMC

    Still the same problem... https://forums.bukkit.org/threads/p...annot-start-any-token-in-reader-line-49.7712/ so people are having the same problem :( i replaced all the spaces with a TAB with no succes and then with just SPACES still no succes. :(
    EDIT: Turns out i has a couple of spaces after my plugin.yml "code" this fixed it :) :D
     
  11. Offline

    minoneer

    As TGRHavoc already pointed out, you seem to have a Tab (\t) in your config somewhere. Since this is an invalid character for the .yml-Format, you should never use them. Always user spaces.

    Most Editors have an option to replace Tabs by a certain number of spaces - very helpful when dealing with config and plugin files.

    There are four things you can try:

    * Manually look for all those white spaces and check if there is a tab somewhere (a lot of work and you may not find it)
    * Use the serach/replace function of your editor
    * Check your File with an yml parser (i.e. http://wiki.ess3.net/yaml/ )
    * If everything fails, rewrite the plugin.yml (NOT with Copy & Paste). In my experience, this is often faster than to find the error.

    Did you reload your Server/Plugin/Config after changing it?

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

    DeluXeNationMC

    This is my code:
    - Code removed.

    @Override
    public void onEnable(){
    getConfig().options().copyDefaults(true);
    saveConfig();
    launchBlock = (String) getConfig().get("launchBlock");
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    this.getServer().getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[DeluXeLaunchPads] Is Now Enabled!");[/syntax]
    This is my config.yml file:
    Code:
    # Default Configuration File
    LaunchBlock: GOLD_PLATE
    But i get this error:
    HTML:
    [16:38:09 ERROR]: Could not pass event PlayerMoveEvent to DeluXeLaunchPads v2.5
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:320) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:471) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :234) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [cr
    aftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInLook.handle(SourceFile:98) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.IllegalArgumentException: No enum constant org.bukkit.Mater
    ial.Launchblock
            at java.lang.Enum.valueOf(Unknown Source) ~[?:1.7.0_55]
            at org.bukkit.Material.valueOf(Material.java:64) ~[craftbukkit.jar:git-B
    ukkit-1.7.2-R0.3-b3020jnks]
            at me.DeluXeNationMC.DeluXeLaunchPads.Main.onPlayer(Main.java:67) ~[?:?]
     
            at sun.reflect.GeneratedMethodAccessor26.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_55]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_55]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:318) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            ... 13 more
    >
    I really don't what i am doing wrong....
     
  13. Offline

    minoneer

    Material.valueOf("LaunchBlock")

    There is your Problem. You are trying to receive the Enum Constant called "LaunchBlock". Since this does not exist in Material, it throws an exception.
    You should instead use the String you get from your config, which is "GOLD_PLATE".

    By the way: config hast a Method getString(path) - if you are loading a String value, it's better to use then the general .get() method and then cast.
     
  14. Offline

    DeluXeNationMC

    But if the "player" changes the GOLD_PLATE to something else wont the plugin not find the string?
    By the way i really appreciate the help but i dont really understand what you mean by "it's better to use then the general .get() method and then cast." (i am dutch)
     
  15. Offline

    minoneer

    That's the whole point of using a config value, isn't it? You need to replace the
    Material.valueOf("LaunchBlock")
    with something like Material.valueOf(plugin.getConfig().getString("LaunchBlock")) (like you did in your onenable)

    It's the other Way Around :) It's better NOT to use the general one, but the .getString() :) (see above)
     
  16. Offline

    DeluXeNationMC

    minoneer I never though this would be so hard, but nothing is easy.
    Could you maybe give me some example code so i can understand better ?

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

    TGRHavoc

     
  18. Offline

    1Achmed1

    You cannot use String like that. It would be
    getConfig().getString("launchBlock");

    Sorry, my bad.

    EDIT: And that returns \t, which is a tab.
     
  19. Offline

    Opacification

    DeluXeNationMC, I Would also change

    Code:java
    1. saveConfig();


    to

    Code:java
    1. saveDefaultConfig();
     
  20. Offline

    minoneer

    I already gave you everything you need, including examples and detailed descriptions. Please reread the posts and maybe use a translater if you are having trouble with the language.

    There is also a verx helpful article about configurations on the bukkit wiki:
    http://wiki.bukkit.org/Configuration_API_Reference
     
  21. Offline

    DeluXeNationMC

    Condolent likes this.
Thread Status:
Not open for further replies.

Share This Page