From 38f90d025ae0a27cdb02f4a2357661ceac144ad3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 18 Oct 2020 00:50:18 +0200 Subject: [PATCH] Allow HH:mm on /ban and /mute --- pom.xml | 2 +- .../bungeecore/commands/BanCommand.java | 20 ++++++++++++------- .../bungeecore/commands/MuteCommand.java | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index dbf2760..32086a5 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ - bungeecore + BungeeCore diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 9382031..64aec3e 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -37,8 +37,8 @@ public class BanCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { - if(args.length < 3){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder perma] [Grund]"); + if(args.length < 4){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder perma] [hh:mm] [Grund]"); return; } @@ -46,12 +46,12 @@ public class BanCommand extends BasicCommand { if(target == null) return; - Timestamp banTime = parseTime(sender, args[1]); + Timestamp banTime = parseTime(sender, String.join(args[1], args[2])); if(banTime == null) return; StringBuilder banReason = new StringBuilder(); - for (int i = 2; i < args.length; i++){ + for (int i = 3; i < args.length; i++){ banReason.append(args[i]).append(" "); } String msg = banReason.toString(); @@ -63,13 +63,19 @@ public class BanCommand extends BasicCommand { if(arg.equalsIgnoreCase("perma")) { return Timestamp.from(Instant.ofEpochSecond(946674800)); }else{ - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); try{ Date parsedDate = dateFormat.parse(arg); return new java.sql.Timestamp(parsedDate.getTime()); }catch(ParseException e){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUngültige Zeitangabe."); - return null; + dateFormat = new SimpleDateFormat("dd.MM.yyyy"); + try{ + Date parsedDate = dateFormat.parse(arg.split(" ")[0]); + return new java.sql.Timestamp(parsedDate.getTime()); + }catch(ParseException exception){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUngültige Zeitangabe."); + return null; + } } } } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index f3421aa..69cac56 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -33,8 +33,8 @@ public class MuteCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { - if(args.length < 3){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder perma] [Grund]"); + if(args.length < 4){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder perma] [hh:mm] [Grund]"); return; } @@ -42,12 +42,12 @@ public class MuteCommand extends BasicCommand { if(target == null) return; - Timestamp muteTime = BanCommand.parseTime(sender, args[1]); + Timestamp muteTime = BanCommand.parseTime(sender, String.join(args[1], args[2])); if(muteTime == null) return; StringBuilder muteReason = new StringBuilder(); - for (int i = 2; i < args.length; i++){ + for (int i = 3; i < args.length; i++){ muteReason.append(args[i]).append(" "); } String msg = muteReason.toString();