Solved Checking for unmute issue (time)

Discussion in 'Plugin Development' started by Loogeh, Jul 15, 2013.

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

    Loogeh

    Before I say anything I'd like to say that I've never done something like this before, so I was just kind of guessing. I'm making a timed mute plugin and my code doesn't work properly. I mute someone for 1 hour (atleast I think I do) and then after 1 minute the player is unmuted. In my main class I have a repeating task which starts in the onEnable() method that checks for players which need to be unmuted every minute. Here is my checkMute() method

    Code:
        public static void checkMute() {
            for(Entry<String, Double> muteEntry : muteMap.entrySet()) {
                String mutee = muteEntry.getKey();
                double dur = muteEntry.getValue();
                if((((System.currentTimeMillis() - dur) / 1000) > getDuration(mutee))) {
                    muteMap.remove(mutee);
                    mutetimeMap.remove(mutee);
                    MySQL.doUpdate("DELETE FROM player_mute WHERE player='" + mutee + "'");
                    Bukkit.broadcastMessage(ChatColor.GOLD + "Mute: " + ChatColor.YELLOW + mutee + ChatColor.WHITE + " was unmuted");
                } else {
                    return;
                }
            }
        }
    I'm pretty sure it's to do with the
    Code:
    if((((System.currentTimeMillis() - dur) / 1000) > getDuration(mutee))) {
    But I don't know what to change it to since I've never done this before.

    Here is my mute method:
    Code:
        public static void mute(String player, Player muter, double duration, String reason) {
            Player mutee = Bukkit.getServer().getPlayer(player);
            if(player == null) {
                muter.sendMessage(ChatColor.GOLD + "Mute: " + ChatColor.GRAY + "That player " + ChatColor.WHITE + "[" + ChatColor.YELLOW + player + ChatColor.WHITE + "]" + ChatColor.GRAY + " is offline");
                return;
            }
            if(isMuted(mutee)) {
                muter.sendMessage(ChatColor.GOLD + "Mute: " + ChatColor.GRAY + "The player " + ChatColor.WHITE + "[" + ChatColor.YELLOW + mutee.getName() + ChatColor.WHITE + "]" + ChatColor.GRAY + " is already muted for " + utilMath.round((getDuration(mutee) / 1000), 1));
                return;
            }
            if(!Permissions.isStaff(muter)) {
                utilPlayer.permMsg(muter);
                return;
            }
            if(!Permissions.outranks(muter, mutee)) {
                muter.sendMessage(ChatColor.GRAY + "You must outrank" + ChatColor.WHITE + " [" + ChatColor.YELLOW + mutee.getName() + ChatColor.WHITE + "]" + ChatColor.GRAY + " to mute them");
                return;
            }
     
            MySQL.doUpdate("INSERT INTO `player_mute`(`player`, `muter`, `rank`, `reason`, `hours`, `mutetime`, `systime`, `date`) VALUES ('" + mutee.getName() + "','" + muter.getName() + "','" + Permissions.getLevel(muter) + "','" + reason + "'," + duration + "," + (duration * 3600000.0) + "," + System.currentTimeMillis() + ",'" + utilTime.timeStr() + "')");
            mutetimeMap.put(mutee.getName(), duration * 3600000.0);
            muteMap.put(mutee.getName(), duration);
            Bukkit.broadcastMessage(ChatColor.GOLD + "Mute: " + ChatColor.YELLOW + muter.getName() + ChatColor.WHITE + " muted " + ChatColor.GREEN + mutee.getName() + ChatColor.WHITE + " for " + ChatColor.GREEN + duration + ChatColor.WHITE + " Hours");
            Bukkit.broadcastMessage(ChatColor.GOLD + "Reason:" + ChatColor.WHITE + reason);
        }
    Any help?
     
  2. Offline

    andf54

    The code seems more complicated than it needs to be. I cant really tell what's going on.

    You have a very powerful method at your disposal: System.out.println("message here " + someVariable + " message"). Just insert it where you guess the problem is and see if it works correctly.

    Also, it might be just me, but checkSomething should return a boolean. Maybe use handleSomething instead.
     
  3. Offline

    Loogeh

    andf54 Yes but I don't know what variable to put in there. Also, what's confusing you? and yeah I should change it to handleMute or something.

    Actually, I think I figured it out. Solved for now.

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

Share This Page