server.properties?

Discussion in 'Plugin Development' started by mkaltner, Feb 7, 2011.

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

    mkaltner

    Hey everyone,
    I'm trying to port my hMod/Android plugin (Minecraft Mobile Admin) over to Bukkit and I can't seem to wrap my head around two things, both related to server.properties.

    1) How can I get the current values and update them? Specifically items like spawn-monsters, spawn-animals, etc...
    2) What's the new style of storing plugin specific settings (in my case, username, password, port and chat color).

    I've looked through the forum a bit and haven't seen anything related to number 1 (unless I'm blind, it's quite possible).

    Regarding number 2, it seems the few plugins I've looked at the source code for all roll their own method.

    These are the two remaining items to getting the first iteration of Mobile Admin ported to Bukkit and I just can't seem to find the answer (or at least the right/standard one).

    Thanks!
    - Mike
     
  2. Offline

    c0mp

    Can't offer any assistance with your quandary, unfortunately. Just wanted to voice my support for getting this ported over to Bukkit. T'was a terrific hMod accessory and can't wait to see it working with Bukkit!
     
  3. Offline

    nickthemenace

    For the first one you can create 2 new functions like so:
    getString

    Code:
        public static String getString(String s, File f)
        {
            Properties pr = new Properties();
            try
            {
                FileInputStream in = new FileInputStream(f);
                pr.load(in);
                String string = pr.getProperty(s);
                return string;
            }
            catch (IOException e)
            {
    
            }
            return "";
        }
    and setString
    Code:
        public static void setString(String stringtochange, File f, String changeto )
        {
            Properties pr = new Properties();
            try
            {
                FileInputStream in = new FileInputStream(f);
                pr.load(in);
                pr.setProperty(stringtochange,changeto);
                pr.store(new FileOutputStream(f), null);
            }
            catch (IOException e)
            {
            }
        }
    And then use them like this:
    Code:
    File f = new File("server.properties");
    String ValueWas = getString("level-name", f);
    setString("level-name", f, "NewValue");
    
    For the 2nd one, I'm not sure. I just use text files similar to server.properties (although I stick them in their own folder), but I have no idea what other people do, or if that is good practice at all. The way I do it is explained in this tutorial (as well as the setString and getString functions): http://forums.bukkit.org/threads/intermediate-bukkit-plugin-tutorial.2548/

    Edit: Occurred to me that that tutorial is an hour long, so here's the general idea:
    Create a new file using the following code:
    Code:
    String propFile =  "FileNameHere.prop";
    PluginProperties prop = new PluginProperties(propFile);
    prop.load();
    prop.save("CommentAtTopOfFile");
    
    And you then use the getString and setString functions above to edit it. E.g.:
    Code:
    File f = new File("FileNameHere.prop");
    setString("VariableName", f, "ValueHere");
    
     
  4. Offline

    mkaltner

    I greatly appreciate the response but is the general consensus that these features are not yet supported in Bukkit?
    By that I mean, per plugin setting files and handling of the minecraft server.properties file...?
    Server.properties I could understand but per plugin settings seem to be a pretty standard requirement.
     
  5. Offline

    DerpinLlama

    Just add the PropertiesFile.java to your project.
     
  6. Offline

    mkaltner

    Thanks DerpinLlama, that took care of it.
    BTW, Minecraft Mobile Admin 2.0 with Bukkit support has been released (need to find out how to get permission to post to the Plugin Releases thread...).
    Visit http://www.kaltner.net for more information.
     
  7. Offline

    DerpinLlama

    Talk to EvilSeph.
     
Thread Status:
Not open for further replies.

Share This Page