(Deprecated) Bukkit's Standard Configuration Tutorial

Discussion in 'Resources' started by captainawesome7, Jul 11, 2011.

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

    Fabis94

    Everything has a reason :p
    Anyway, I tried using the code in your original post, when I build the JAR file, run the server and even use the configs in the game, they don't appear. Am I supposed to do something to make 'em appear?

    EDIT: Never mind, fixed it.
     
  2. Offline

    djrenzo

    Is there supposed to be a folder made if it isnt there with the .yml file in it?
    If so, then its not working to me, not creating the folder and the file

    EDIT**: fixed it
     
  3. Offline

    kaiser_czar

    Might I ask what you did to fix this? I've been having some trouble with this also.
     
  4. Offline

    captainawesome7

    try config.save()?
     
  5. Offline

    kaiser_czar

    Good call... missed that somehow.
     
  6. Offline

    flAked

    I have a slight glitch with the config file header. In my saveConfig() which get's called on every OP-command, I just use
    Code:
    config.setHeader()
    config.save()
    But the file now has two headers on row 1 & 2. Any ideas?
     
  7. Offline

    MuisYa

    When putting this all into my Main class, and in onEnable.
    The server creates the Config correctly first time, but the second time it announces that the ":" is not allowed inside the config file, So what i got is Brackets: "Test" Set as a string, than the server announces : is not allowed...
    Can you please help me a bit?

    EDIT: I fixed it already :)
    Can you please give me some tips on how to do colour codes, a config to change chat colors...

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

    captainawesome7

    Just add replaceAll("(&([a-f0-9]))", "\u00A7$2"); to any string and it will make &a-f and &1-9 show up as colors. (&4 Will make the text afterwards dark red)
     
  9. Offline

    MuisYa

    Thanks alot!, still got one question.
    If i want to import the colors (Im getting them from my Main) to another class as Main.
    So at the CommandHandler class, i need to edit the colors. How to make him understand the strings of my Main class.

    EDIT: @captainawesome7

    @captainawesome7
    You know how to get around that problem...?
    I just cant get it fixed, its more JAVA knowledge though...

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

    captainawesome7

    What?
     
  11. Offline

    MuisYa

    @captainawesome7
    Im loading the color in the Main class. Lets say its &9 so thats blue.
    When i am in my CommandHandler class, and im using the string name of that color, so for instance ''Prefix-Color'' (Whats listed in the config) when i type in as string Prefix-Color, it wont load it, because i imported the color in my Main.
    Do you know how to get around it?...
    I hope this is explained better..
     
  12. Offline

    captainawesome7

    Um, you should have instances set up correctly, so that to make a new CommandHandler class you have to use CommandHandler(Main) so that you can use public variables from Main in your CommandHandler class
     
  13. Offline

    MuisYa

    @captainawesome7
    I dont get it fully...
    Can you please explain it a bit better? :3

    Main class:
    Show Spoiler

    Code:
    package me.muisya.pistonalert;
    
    import java.util.logging.Logger;
    
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.util.config.Configuration;
    
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    
    public class Main extends JavaPlugin{
        public static PermissionHandler permissionHandler;
        public static DataHandler datawriter;
        public Configuration config;
    
        public String configMessage;
        public String configBrackets;
        public static String configPrefix;
    
        private final Logger log = Logger.getLogger("Minecraft");
        private final PistonBlockBreak bListener2 = new PistonBlockBreak();
        private final PistonBlockPlace bListener1 = new PistonBlockPlace(this);
    
        public void onDisable() {
            String Version = (getDescription().getVersion());
            log.info("[PistonAlert]" + Version + "Has been disabled.");
            }
    
        public void onEnable() {
            String Version = (getDescription().getVersion());
            String Stripes = ("----------------------------------------------------------");
            String ConfigHeader = ("--PistonAlert \"Version " + Version + "\" config file for editing chat colors--\nThanks to MuisYa for developing. And Jeroende2e for this idea.\n\n" + Stripes);
    
            config = getConfiguration();
            configMessage = config.getString("Message-Color", "&f").replaceAll("(&([a-f0-9]))", "\u00A7$2");
            configBrackets = config.getString("Brackets-Color", "&f").replaceAll("(&([a-f0-9]))", "\u00A7$2");
            configPrefix = config.getString("Prefix-Color", "&9").replaceAll("(&([a-f0-9]))", "\u00A7$2");
            config.setHeader(ConfigHeader);
            config.save();
    
            PluginManager pm = getServer().getPluginManager();
            datawriter = new DataHandler(this);
    
            pm.registerEvent(Event.Type.BLOCK_BREAK, bListener2, Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACE, bListener1, Priority.Normal, this);
            getCommand("PistonAlert").setExecutor(new CommandHandler(this));
    
            setupPermissions();
    
            log.info("[PistonAlert] Version " + Version + " by MuisYa has been enabled.");
    
        }
    
        private void setupPermissions() {
            if (permissionHandler != null) {
                return;
            }
            Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
            if (permissionsPlugin == null) {
                log.info("[PistonAlert] No permissions system found! No messages to admins!");
                return;
            }
            permissionHandler = ((Permissions) permissionsPlugin).getHandler();
            log.info("[PistonAlert] Permissions system found: "+((Permissions)permissionsPlugin).getDescription().getFullName() + "!");
        }
    }
    



    CommandHandler Class:
    Show Spoiler

    Code:
    package me.muisya.pistonalert;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class CommandHandler implements CommandExecutor {
        private final Main plugin;
        public CommandHandler(Main plugin) {
            this.plugin = plugin;
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            String[] split = args;
            String VersionMessage = ("[" + ChatColor.BLUE + "PistonAlert" + ChatColor.WHITE + "] For help go to to the forum post.");
            String Permissions = (configMessage + "[" + ChatColor.BLUE + "PistonAlert" + ChatColor.WHITE + "] You do not have enough permissions.");
    
            if (cmd.getName().compareToIgnoreCase("PistonAlert") == 0) {
                if (split.length == 0) {
                    for (Player p : sender.getServer().getOnlinePlayers()) {
                        if (Main.permissionHandler.has(p,"PistonAlert.version")) p.sendMessage(VersionMessage);
                        else p.sendMessage(Permissions);
                    }
                }
    
            }
            return true;
        }
    
    }


    Thanks alot!

    @captainawesome7 I fixed it already, thanks!

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

    ben657

    Hey, is there any way to get this to work using a HashMap?

    for example, i'm making an economy plugin for my server (no real reason) and i'm saving the players balances using a HashMap to compare <Player, double> double being the balance obviously, any ideas how i can save the player and value to a config for a person to edit? i'd rather keep it in flatfile if possible, dont really mind how many players end up in it :p
     
  15. Offline

    Pencil

    Weird, I followed the instructions for the basic thing, and it works. It creates the config file and loads the values correctly, now the problem is whenever I reload/stop & start my server, it throws an error on the not changed config file!

    Code:
    Code:
    package net.creepcraft.iPencil;
    
    import java.util.logging.Logger;
    
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
    import org.bukkit.util.config.Configuration;
    
    public class MobMounts extends JavaPlugin{
    
          private final MobMountsPlayerListener playerListener = new MobMountsPlayerListener(this);
          private final MobMountsEntityListener entityListener = new MobMountsEntityListener(this);
          public static final Logger log = Logger.getLogger("Minecraft");
    
            public Configuration config;
            public Integer Zombietame;
            public Integer Creepertame;
            public Integer Skeletontame;
            public Integer Spidertame;
            public Integer Pigtame;
            public Integer Sheeptame;
            public Integer Cowtame;
            public Integer Chickentame;
            public Integer Squidtame;
    
            public void onDisable() {
                log.info("[MobMounts]" + "version" + getDescription().getVersion() +" by iPencil" + " disabled!");
     
            }
    
            public void onEnable() {
    
                log.info("[MobMounts]" + " version " + getDescription().getVersion() +" by iPencil" + " enabled!");
                PluginManager pm = getServer().getPluginManager();
                pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, playerListener, Event.Priority.Highest, this);
                pm.registerEvent(Event.Type.ENTITY_TARGET, entityListener, Event.Priority.Highest, this);
                config = getConfiguration();
                config.setHeader("Here you can define the items that are required to mount the mobs onto you.");
                Zombietame = config.getInt("Zombie tame item", 268);
                Creepertame = config.getInt("Creeper tame item", 289);
                Skeletontame = config.getInt("Skeleton tame item", 262);
                Spidertame = config.getInt("Spider tame item", 287);
                Pigtame = config.getInt("Pig tame item", 296);
                Sheeptame = config.getInt("Sheep tame item", 296);
                Cowtame = config.getInt("Cow tame item", 296);
                Chickentame = config.getInt("Chicken tame item", 295);
                Squidtame = config.getInt("Squid tame item", 338);
                config.save();
    
            }
    I didn't modify anything in the config yet it throws this error:
    Code:
    16:09:50 [SEVERE] Could not load 'plugins\MobMount.jar' in folder 'plugins':
    mapping values are not allowed here
     in "<reader>", line 2, column 16:
        Squid tame item: 338
                       ^
    
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:74
    5)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.ja
    va:307)
            at org.yaml.snakeyaml.scanner.ScannerImpl.peekToken(ScannerImpl.java:204
    )
            at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentEnd.produce(ParserI
    mpl.java:267)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:163)
            at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:173)
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    4)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
    
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:124)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:264)
            at org.bukkit.util.config.Configuration.load(Configuration.java:82)
            at org.bukkit.plugin.java.JavaPlugin.initialize(JavaPlugin.java:157)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:175)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:199)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:122)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:118)
            at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:356)
            at org.bukkit.command.SimpleCommandMap$ReloadCommand.execute(SimpleComma
    ndMap.java:281)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:12
    9)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:2
    90)
            at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:486)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:471)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:367)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:422)
    And it only happens when I reload/stop & start the server again. On the first time it works flawless, I even tested it ingame.
     
  16. Offline

    sddddgjd

    Thanks for the tutorial,really easy!
     
  17. Offline

    chernobyl360

    for some reason every time i go to reload the server my blacklung's plugin config keeps reseting back to defaults.
     
  18. Offline

    xGhOsTkiLLeRx

    Hey,

    thank you!
    I was just searching for this, because it's the first time I want to use a config! :)
     
  19. Offline

    kaiser_czar

    Just came here to ask about the very same problem. Has anyone had experience in fixing this?
     
  20. Offline

    captainawesome7

    Don't put spaces in the path! Use ZombieTameItem: 123 etc.
     
    Pencil likes this.
  21. Offline

    Pencil

    Alright! THANKS :D
     
  22. Offline

    xGhOsTkiLLeRx

  23. Offline

    Pencil

    dont use config.getBoolean("test", false)

    use

    plugin.test == true

    on enable you make the plugin read the value of test and store it in

    public Boolean test;

    now whenver you want to get the value of test you simply take that boolean, because it's not in the same class you have to use plugin.test :)
     
    xGhOsTkiLLeRx likes this.
  24. Offline

    Unlucky4ever

    I have my config loading in a seperate file so I can keep it nice and organized, I have no problems, I was just reading for you comments, but I did the setHeader thing and it kept putting it at the top, what if I wanted it like this?

    (This is the Config.yml is generates for me)
    Code:
    # This is the configuration file for Dynamic Graylist
    System:
        Database:
            Port: '3306'
            Database: forum
            Password: ''
            Username: root
            Hostname: localhost
    
    I want it too look like this:
    Code:
    # This is the configuration file for Dynamic Graylist
    System:
        Database:
            Port: '3306' # MySQL Port
            Database: forum # Forum database
            Password: '' # MySQL Password
            Username: root # MySQL Username
            Hostname: localhost # MySQL Host
    
    How do I do it?
     
  25. Offline

    xGhOsTkiLLeRx

    You are my hero. Now I hope I understood configuration to 100%
    Will test it tomorrow after school :)
     
  26. Offline

    Pencil

    Kein Problem :)
     
  27. Offline

    thehutch

    Yes same here now I understand how to get a value from the config :) Thank you @Pencil
     
    Pencil likes this.
  28. Offline

    xGhOsTkiLLeRx

    Funktioniert wunderbar, kann endlich weitermachen zu arbeiten :)

    //

    All is working!
     
    Pencil likes this.
  29. Offline

    Perdog

    @captainawesome7
    1 question.. Do I use the Saving/Loading method instead of the first basic example? Or do I use them both?
     
  30. Offline

    captainawesome7

    You use one or the other.
     
Thread Status:
Not open for further replies.

Share This Page