Getting string from config

Discussion in 'Plugin Development' started by CactusComboPvP, Aug 11, 2016.

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

    CactusComboPvP

    So I am using this:

    Code:
        public String getReason() {
            return this.config.getString("MuteReason");
        }
    and in my player yml file it says this:

    Code:
    Muted: true
    EndOfMute: 1470905323137
    Permanent: false
    MuteReason: Testing
    
    but when I do

    Code:
                    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Mute> " + ChatColor.GRAY
                                            + "Reason: " + pData.getReason().toString());
    It just says in-game: "Mute> Reason: " - nothing... it's clearly there.

    what am I doing wrong?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @CactusComboPvP 1. No need to call toString on a string.
    2. Could you show where you set config?
     
  3. Offline

    CactusComboPvP

    @timtower

    Code:
    public void createPlayerDef() {
            if (this.file.length() <= 0L) {
                this.config.set("Muted", false);
                this.config.set("EndOfMute", Long.valueOf(0));
                this.config.set("MuteReason", "");
                this.config.set("Permanent", false);
                this.savePlayerConf();
            }
        }
    Code:
    public void setMuted(long endOfMute, String reason) {
            this.config.set("Muted", true);
            this.config.set("EndOfMute", endOfMute);
            this.config.set("MuteReason", reason);
            this.config.set("Permanent", false);
            this.savePlayerConf();
        }
    Code:
        public void mutePlayer(Player p, String reason, int time, int multi) {
            PunishData mData = new PunishData(p.getUniqueId());
            long current = System.currentTimeMillis();
            long millis = time * multi;
            long endOfMute = current + millis;
    
            if (!mData.isMuted()) {
                mData.setMuted(Long.valueOf(endOfMute), reason);
                mData.savePlayerConf();
    
            }
    
        }
    Code:
    mutePlayer(target, args[2], time, 60000);
     
  4. Make sure in your config.yml you're using:

    Code:
    mystringhere: "My String!"
    
    instead of:

    Code:
    mystringhere: 'My String!'
    
    When exporting the plugin it will change it to ' '. But use " " when editing Eclipse.
     
  5. Offline

    MineStein

    Can I see the PunishData#savePlayerConf method? Make sure that you are actually saving the correct file.
     
  6. Offline

    CactusComboPvP

    @MineStein
    Code:
        public void savePlayerConf() {
            try {
                getPlayerConf().save(this.file);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    @AlvinB
    mutePlayer(target, args[2], time, 60000); args[2] is the reason

    if (unit.equalsIgnoreCase("h")) {
    mutePlayer(target, args[2], time, 3600000);
    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Mute> " + ChatColor.GRAY + "'"
    + target.getName() + "' has been muted.");
    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Mute> " + ChatColor.GRAY + "Time: "
    + time + " minute(s)");
    target.sendMessage(" ");
    target.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Mute> " + ChatColor.GRAY
    + "You have been muted by " + p.getName());
    target.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Mute> " + ChatColor.GRAY
    + "Time: " + time + " minute(s)");
    target.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Mute> " + ChatColor.GRAY
    + "Reason: " + pData.getReason());
    target.sendMessage(" ");
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 12, 2016
Thread Status:
Not open for further replies.

Share This Page