Config Help

Discussion in 'Plugin Development' started by bigboy2013, May 22, 2012.

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

    bigboy2013

    Right now I have my fully working plugin below. However, what I want instead is so that instead of just using like "/tut dungeons", I want it so you can do "/tut dungeons" to default to page 1, or "/tut dungeons 2" to go to page 2. So far, my config looks like this:

    Code:
    # CustomTut config. Place new tutorials in here.
    dungeons:
    - cCmcC8~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    - cC4cClMob Dungeons
    - cCmcC8~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    - cC6cCnIntroduction 1/3
    - cCmcC8~~~~~~~~~~~~~~~~~
    - In the mob dungeons, players can explore and fight
    - mobs. They can collect tons of exp and money, and even
    - some rare drops from mobs. Players must pay a fee, and
    - each dungeon difficulty has a different fee. Different
    - difficulties have different mobs,
    - cCmcC8~~~~~~~~~~~~~~~~~
    - cC6cCnDungeons 2/3
    - cCmcC8~~~~~~~~~~~~~~~~~
    - cCbCoal(Easy) cCa$500
    - ~Zombies, Spiders
    - cCbIron(Normal) cCa$2000
    - ~Zombies, Spiders, Skeletons, Silverfish, Endermen
    - cCbGold(Hard) cCa$5000
    - ~Zombies, Spiders, Skeletons, Silverfish, Creepers,
    - Cave Spiders, Zombie Pigmen
    - cCbLapis(Insane) cCa$10000
    - ~Zombies, Spiders, Skeletons, Silverfish, Creepers,
    - Cave Spiders, Zombie Pigmen, Blazes, Ghasts,
    - Endermen, Slimes, Magma Slimes
    - cCmcC8~~~~~~~~~~~~~~~~~
    - cC6cCnWarnings 3/3
    - cCmcC8~~~~~~~~~~~~~~~~~
    - No teleport-type commands are allowed. This includes
    - cCb/tpacCf, cCb/sethomecCf, cCb/homecCf, cCb/warpcCf, cCb/backcCf. PVP is also disabled.
    - It is recommended to go in groups, because it can get
    - quite dangerous.
    
    However, I want it more like the config below, due to the fact that after you say /tut dungeons, all you would see is the Warning part. So basically so you can seperate a tutorial into pages like this:

    Code:
    # CustomTut config. Place new tutorials in here.
    dungeons:
      1:
      - cCmcC8~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      - cC4cClMob Dungeons
      - cCmcC8~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      - cC6cCnIntroduction
      - cCmcC8~~~~~~~~~~~~~~~~~
      - In the mob dungeons, players can explore and fight
      - mobs. They can collect tons of exp and money, and even
      - some rare drops from mobs. Players must pay a fee, and
      - each dungeon difficulty has a different fee. Different
      - difficulties have different mobs,
      - cC4(p[1/3])
      2:
      - cCmcC8~~~~~~~~~~~~~~~~~
      - cC6cCnDungeons
      - cCmcC8~~~~~~~~~~~~~~~~~
      - cCbCoal(Easy) cCa$500
      - ~Zombies, Spiders
      - cCbIron(Normal) cCa$2000
      - ~Zombies, Spiders, Skeletons, Silverfish, Endermen
      - cCbGold(Hard) cCa$5000
      - ~Zombies, Spiders, Skeletons, Silverfish, Creepers,
      - Cave Spiders, Zombie Pigmen
      - cCbLapis(Insane) cCa$10000
      - ~Zombies, Spiders, Skeletons, Silverfish, Creepers,
      - Cave Spiders, Zombie Pigmen, Blazes, Ghasts,
      - Endermen, Slimes, Magma Slimes
        - cC4(p[1/3])
      3:
      - cCmcC8~~~~~~~~~~~~~~~~~
      - cC6cCnWarnings
      - cCmcC8~~~~~~~~~~~~~~~~~
      - No teleport-type commands are allowed. This includes
      - cCb/tpacCf, cCb/sethomecCf, cCb/homecCf, cCb/warpcCf, cCb/backcCf. PVP is also disabled.
      - It is recommended to go in groups, because it can get
      - quite dangerous.
        - cC4(p[3/3])
    
    Below is the main page CustomTut.java. However, on the line:
    List<String> tutorial = getConfig().getStringList(args[0]);
    I'm unsure of what to replace args[0] with, like args[0].getStringList(args[1]).
    Also if I can get that part to work, do I have the lines of config set up right, or do the pages
    numbers need a - before them, or does spacing need to be different?


    Code:
    package me.bigboy2013.CustomTut;
     
    import java.util.Iterator;
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CustomTut extends JavaPlugin {
        private CustomTutConfig ConfigLogger = new CustomTutConfig(this);
        public PluginManager pm;
       
        @Override
        public void onDisable() {
            ConfigLogger.enabled(false);
        }
       
        @Override
        public void onEnable() {
            ConfigLogger.enabled(true);
               
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        public String colorizeText(String string) {
                string = string.replaceAll("cC0", ""+ChatColor.BLACK+"");
                string = string.replaceAll("cC1", ""+ChatColor.DARK_BLUE+"");
                string = string.replaceAll("cC2", ""+ChatColor.DARK_GREEN+"");
                string = string.replaceAll("cC3", ""+ChatColor.DARK_AQUA+"");
                string = string.replaceAll("cC4", ""+ChatColor.DARK_RED+"");
                string = string.replaceAll("cC5", ""+ChatColor.DARK_PURPLE+"");
                string = string.replaceAll("cC6", ""+ChatColor.GOLD+"");
                string = string.replaceAll("cC7", ""+ChatColor.GRAY+"");
                string = string.replaceAll("cC8", ""+ChatColor.DARK_GRAY+"");
                string = string.replaceAll("cC9", ""+ChatColor.BLUE+"");
                string = string.replaceAll("cCa", ""+ChatColor.GREEN+"");
                string = string.replaceAll("cCb", ""+ChatColor.AQUA+"");
                string = string.replaceAll("cCc", ""+ChatColor.RED+"");
                string = string.replaceAll("cCd", ""+ChatColor.LIGHT_PURPLE+"");
                string = string.replaceAll("cCe", ""+ChatColor.YELLOW+"");
                string = string.replaceAll("cCf", ""+ChatColor.WHITE+"");
                string = string.replaceAll("cCl", ""+ChatColor.BOLD+"");
                string = string.replaceAll("cCm", ""+ChatColor.STRIKETHROUGH+"");
                string = string.replaceAll("cCn", ""+ChatColor.ITALIC+"");
                string = string.replaceAll("cCo", ""+ChatColor.UNDERLINE+"");
                return string;
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player player = (Player) sender;
           
            if(commandLabel.equalsIgnoreCase("tut")) {
                    if(!permCheck(player, "tut.use")) {
                        player.sendMessage(ChatColor.RED + "You do not have access to that command.");
                        return true;
                    }
                        if(args.length == 0) {
                            player.sendMessage(ChatColor.RED + "Usage is: " + ChatColor.WHITE + "/tut <tutorial> (section)");
                        } else if(args.length == 1) {
                            List<String> tutorial = getConfig().getStringList(args[0]);
                            Iterator<String> iterator = tutorial.iterator();
     
                            while(iterator.hasNext()) {
                                player.sendMessage(colorizeText(iterator.next()));
                            }
                        } else if(args.length == 2) {
                            List<String> tutorial = getConfig().getStringList(args[0]);
                            Iterator<String> iterator = tutorial.iterator();
     
                            while(iterator.hasNext()) {
                                player.sendMessage(colorizeText(iterator.next()));
                            }
                        }
                }
            return true;
        }
           
        private boolean permCheck(Player player, String permission) {
            if(player.isOp() || player.hasPermission(permission)) return true;
                return false;
        }
    }
    
     
  2. Offline

    r0306

    bigboy2013
    This is fairly easy. All you have to do is to change the node of the path that the plugin is reading from the config.yml. Since the number is args[1] we can use that to find the specified node. The config goes by sub-configs so specifying a path separated by a period will let the plugin know where to look.
    Code:
                        } else if(args.length == 2) {
                            List<String> tutorial = getConfig().getStringList(args[0] + "." + args[1]);
                            Iterator<String> iterator = tutorial.iterator();
     
                            while(iterator.hasNext()) {
                                player.sendMessage(colorizeText(iterator.next()));
                            }
     
Thread Status:
Not open for further replies.

Share This Page