Timestamp Help

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

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

    CactusComboPvP

    Hey, I am trying to code a /tempmute <player> <time> plugin, here is what i have so far:

    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() == false) {
                mData.setMuted(endOfMute, reason);
                try {
                    mData.savePlayerConf();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
    
        }
    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String str, String[] args) {
            Player p = (Player) sender;
            if (cmd.getName().equals("mute")) {
                if (args.length < 2) {
                    p.sendMessage(ChatColor.RED + "Command usage: /mute <player> <time> <reason>");
                } else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    if (target == null) {
                        p.sendMessage(ChatColor.RED + "Player '" + args[0] + "' not found.");
                        return true;
                    } else {
                        if ((args[1].endsWith("m")) || (args[1].endsWith("h")) || (args[1].endsWith("d"))) {
                            String unit = args[1].substring(args[1].length() - 1);
                            int time = Integer.parseInt(args[1].substring(0, args[1].length() - 1));
                          
                            if (unit.equalsIgnoreCase("m")) {
                                mutePlayer(target, args[2], time, 60000);
                              
                            }
                            if (unit.equalsIgnoreCase("h")) {
                                mutePlayer(target, args[2], time, 3600000);
                            }
                            if (unit.equalsIgnoreCase("d")) {
                                mutePlayer(target, args[2], time, 86400000);
                            }
                        }
                    }
                }
            }
            return false;
        }
    But the problem is, how do I use this with the AsyncPlayerChatEvent?

    Code:
    @EventHandler
        public void onChat(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            PunishData pData = new PunishData(p.getUniqueId());
            long current = System.currentTimeMillis();
            long end = pData.config.getInt("MuteTime");
         //What do I do here??
        }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @CactusComboPvP You compare his time with the current time, if current time past his time: unmute, else: cancel event.
     
  3. Offline

    ArsenArsen

    also I would like to point out that you check if boolean == false, that exoression itself returns a boolean. Just use the NOT operator on the boolean, like !isMuted()
     
  4. Offline

    CactusComboPvP

Thread Status:
Not open for further replies.

Share This Page