Save word into Config file

Discussion in 'Plugin Development' started by sum_17427, Dec 15, 2014.

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

    sum_17427

    How i can save word into config file like this:
    Code:
    Code:
    - test 1
    - test 2
    and this my plugin idea, player used command /giftcode <code> then add item to player inv
    Code:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            String code = getConfig().getString("code");
            if(sender instanceof Player) {
                Player player = (Player) sender;
                if (commandLabel.equalsIgnoreCase("giftcode" + code)){
                    if (getConfig().getString("code.used").equals(true)){
                        player.sendMessage(ChatColor.DARK_AQUA + "Code has been used!");
                    }
                    player.sendMessage(ChatColor.DARK_AQUA + "Enter code successfully!");
                    player.sendMessage(ChatColor.DARK_AQUA + "Merry christmas!");
                    player.getLocation().getWorld().playEffect(player.getLocation(), Effect.GHAST_SHOOT, 10);
                }
            }
            return false;
        }
    How to make the code "test" just only use once?
     
  2. @sum_17427 Firstly, don't use the commandLabel, use the command's name - using the command's name will support aliases. Secondly, I don't know what you mean by only make it use once.
     
  3. Offline

    sum_17427

    @AdamQpzm
    Example: this code "WIUQOALSA" it's just allowed player use one time, if player use "WIUQOALSA" second time server sendMessage "Code has been used!" to player
     
  4. @sum_17427 You'll need to note down (probably in a config) of what codes have been used, and (if each player can use once), which players have used them. You then will need to check if the code being used is in this config place.
     
  5. Offline

    sum_17427

    @AdamQpzm
    Could make when player use code and that code remove from file config?
     
  6. @sum_17427 If you intend for codes to only ever be used once, then yes, that would work too.
     
Thread Status:
Not open for further replies.

Share This Page