Creating a /<plugin> reload command

Discussion in 'Plugin Development' started by DeadlyScone, Apr 26, 2012.

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

    DeadlyScone

    i am completely stumped on this one. i have tried searching the forums and found a bunch of things that don't work :( basically i have a void called getConfiguration that handles getting and putting values into a hashmap with some help from another class that basically is a get return type thing.

    My question is that how can i do a /reload command that will just re-allocate the hashmap values? i tried calling the method and no dice. All it did was skip over the getting the config values part(atleast i think it did) and end.

    please help. i might loose my bukkit Q_Q
     
  2. Offline

    Nitnelave

    I... don't ... really get what you mean. You have to be more accurate. What exactly does you getConfiguration do? what do you want reassigned in the hashmap? what is stored exactly in the hashmap? If you have difficulty explaining, you could also (but you still have to explain) show some of your code.
     
  3. Offline

    DeadlyScone

    ill show a snippet since i need to condense the code still. basically whats stored in the maps are booleans, strings, integers, and doubles. There has to be some simple way to do this correct?

    Main class Method getConfiguration();

    gworld is an interger
    values is the other class
    Code:
    while (gworld < worldCount){
                worlds = getServer().getWorlds().get(gworld).getName();
               
                BooleanMap.put(worlds + "naturalspawnoverride", values.getBoolean(worlds, "Natural Spawn Properties.Natural Spawn Override"));
               
                BooleanMap.put(worlds + "naturalCHICKENspawn", values.getBoolean(worlds, "Natural Spawn Properties.Chicken.Spawn"));
                IntegerMap.put(worlds + "naturalCHICKENspawnamount", Integer.valueOf(values.getInt(worlds, "Natural Spawn Properties.Chicken.SpawnAmount")));
                DoubleMap.put(worlds + "naturalCHICKENspawnchance", values.getDouble(worlds, "Natural Spawn Properties.Chicken.SpawnChance"));
                IntegerMap.put(worlds + "naturalCHICKENhealth", values.getInt(worlds, "Natural Spawn Properties.Chicken.Health"));
                IntegerMap.put(worlds + "naturalCHICKENdamage", values.getInt(worlds, "Natural Spawn Properties.Chicken.Damage"));
                StringMap.put(worlds + "naturalCHICKENspawninstead", values.getString(worlds, "Natural Spawn Properties.Chicken.SpawnInstead"));
    gworld++;
            }
    Here is the class values returns
    Code:
    public boolean getBoolean(String world, String path) throws Exception{
            config = new YamlConfiguration();
            File file = new File(mainDirectory + "/worlds/" + world + ".yml");
            config.load(file);
            return config.getBoolean(path);
           
        }
     
  4. Offline

    Darq

    hashmap.clear(), run the method that loads it?
     
  5. Offline

    Nitnelave

    I would advise against loading the file (and config) every time you read a property... Unless the file is modified every instant by something you don't control, the whole loading and reading should be done only once when you (re)load the plugin.
     
  6. Offline

    DeadlyScone

    Like lets say i change some stuff in my config file. i want to reload the config(re-allocate the hashmap values) through a command. which i would guess would involve re-setting all the values for the hashmap.

    gives me nulls on my hashmaps which means its not reading it properly for some reason :/

    Its like it skips over the while statement...

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

    Double0negative

    whats your reload method look like, your probably not resting something that needs to be rested. If you think the loop isn't running, print something out every iteration to make sure that its running.
     
  8. Offline

    Nitnelave

    It might be a stupid question, but do you reset gworld to 0?
     
  9. Offline

    DeadlyScone

    I re initialized the values for both the getServer().getWorlds.size and set gworld to 0 and i end up getting a null on the getWorlds.size. here is the stack.
    where line 120 is worldCount = getServer().getWorlds().size(); in the main class
    and line 27 is <callclassmethod> mc.getConfiguration(); in the command handler class

    Code:
    [SEVERE] java.lang.NullPointerException
    2012-04-26 21:43:03 [SEVERE]    at me.deadlyscone.mobifier.mobifier.getConfiguration(mobifier.java:120)
    2012-04-26 21:43:03 [SEVERE]    at me.deadlyscone.mobifier.commandManager.onCommand(commandManager.java:27)
    2012-04-26 21:43:03 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    2012-04-26 21:43:03 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
    2012-04-26 21:43:03 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:473)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:821)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
    2012-04-26 21:43:03 [SEVERE]    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    2012-04-26 21:43:05
     
Thread Status:
Not open for further replies.

Share This Page