Tempban Problems

Discussion in 'Plugin Development' started by ZeusReksYou_, May 28, 2016.

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

    ZeusReksYou_

    Hello guys,

    I am trying to code a command for my BanManager to be able to ban players temporarily. I have tried some things and this is how my code is looking right now:

    Tempban-Code:

    Code:
    package banmanager.Commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import banmanager.Strings.Strings;
    
    
    public class TempbanCommand implements CommandExecutor {
    
        @Override
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player s = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("bmtban")){
                if (!(s.hasPermission("bm.mod"))){
                    s.sendMessage(Strings.NoPermMsg);
                    return true;
                }
                if (args.length < 4){
                    s.sendMessage(Strings.TempbanUsage);
                    s.sendMessage(Strings.TempbanExample);
                    return true;
                }
                Player target = Bukkit.getPlayer(args[0]);
                if (target == null){
                    s.sendMessage(Strings.SpecifyMsg);
                    return true;
                }
                if (target.isBanned()){
                    s.sendMessage(Strings.IsBannedMsg);
                    return true;
                }
                target.kickPlayer("");
              
            }
            return true;
            }
    }
    This is what I have tried to make the times, in another package called Strings:

    Code:
    public static long seconds = System.currentTimeMillis() * 1000L;
    public static long minutes = System.currentTimeMillis() * 1000L * 60;
    public static long hours = System.currentTimeMillis() * 1000L * 60 * 60;
    public static long days = System.currentTimeMillis() * 1000L * 60 * 60 * 24;
    public static long weeks = System.currentTimeMillis() * 1000L * 60 * 60 * 24 * 7;
    public static long months = System.currentTimeMillis() * 1000L * 60 * 60 * 24 * 4;
    Now there are 2 problems. I don't know if those time-formats are correct, and I also don't know how to make sure, I can use them in my command, so the correct time will be used in a command.

    So for example that /bmtban Peter 5 d will ban Peter for 5 days and not for 5 months.

    What should I do?

    Sincerely,

    ZeusReksYou_
     
    Last edited: May 28, 2016
  2. You will need to write your self a formatter. That formatter takes the input strings "5", "d" as input and calculates fromt hat, how much seconds match for the input. The result of the calculation will be returned as a long value. So you have 2 parameter String amount and String format. Your chatcommand will have multiple parameters, too. It should look like /bmtban Peter 4:5:10 d:m:s. This way your calculation method knows which value in 4:5:10 is for how much seconds. Sadly you can only go up to weeks like this, since months have different amounts of days.
     
Thread Status:
Not open for further replies.

Share This Page