From 38f90d025ae0a27cdb02f4a2357661ceac144ad3 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 18 Oct 2020 00:50:18 +0200 Subject: [PATCH 1/4] 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 dbf27603..32086a5e 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 9382031e..64aec3e4 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 f3421aab..69cac56b 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(); From c3ff72373b20d10a2b2c80e6f424b1fc3e1aa5f4 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 20 Oct 2020 22:08:08 +0200 Subject: [PATCH 2/4] Fixing... --- pom.xml | 2 +- src/de/steamwar/bungeecore/commands/BanCommand.java | 2 +- src/de/steamwar/bungeecore/commands/MuteCommand.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 32086a5e..dbf27603 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 64aec3e4..03682560 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -38,7 +38,7 @@ public class BanCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { if(args.length < 4){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder perma] [hh:mm] [Grund]"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder perma] {hh:mm} [Grund]"); return; } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 69cac56b..57e6aff9 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -34,7 +34,7 @@ public class MuteCommand extends BasicCommand { @Override public void execute(CommandSender sender, String[] args) { if(args.length < 4){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder perma] [hh:mm] [Grund]"); + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder perma] {hh:mm} [Grund]"); return; } From a959b20370251bfd370c4b07e737cf3929616e91 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 20 Oct 2020 22:10:57 +0200 Subject: [PATCH 3/4] Fixing... --- src/de/steamwar/bungeecore/commands/BanCommand.java | 13 ++++++++++++- .../steamwar/bungeecore/commands/MuteCommand.java | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 03682560..9ab6cadd 100644 --- a/src/de/steamwar/bungeecore/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/commands/BanCommand.java @@ -51,7 +51,8 @@ public class BanCommand extends BasicCommand { return; StringBuilder banReason = new StringBuilder(); - for (int i = 3; i < args.length; i++){ + int start = hasTimestamp(args[2])?2:3; + for (int i = start; i < args.length; i++){ banReason.append(args[i]).append(" "); } String msg = banReason.toString(); @@ -79,4 +80,14 @@ public class BanCommand extends BasicCommand { } } } + + public static boolean hasTimestamp(String time) { + SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm"); + try{ + dateFormat.parse(time); + return true; + }catch(ParseException exception){ + return false; + } + } } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 57e6aff9..9cc0ca9a 100644 --- a/src/de/steamwar/bungeecore/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/commands/MuteCommand.java @@ -47,7 +47,8 @@ public class MuteCommand extends BasicCommand { return; StringBuilder muteReason = new StringBuilder(); - for (int i = 3; i < args.length; i++){ + int start = BanCommand.hasTimestamp(args[2])?2:3; + for (int i = start; i < args.length; i++){ muteReason.append(args[i]).append(" "); } String msg = muteReason.toString(); From 25ed4e7f00513101ee03567bd97083a190b0b614 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 20 Oct 2020 22:16:47 +0200 Subject: [PATCH 4/4] Fixing... --- .../bungeecore/commands/BanCommand.java | 23 +++++-------------- .../bungeecore/commands/MuteCommand.java | 9 ++++---- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BanCommand.java b/src/de/steamwar/bungeecore/commands/BanCommand.java index 9ab6cadd..9ac7ff89 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 < 4){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder perma] {hh:mm} [Grund]"); + if(args.length < 3){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/ban [Spieler] [dd.mm.yyyy oder dd.mm.yyyy_hh:mm oder perma] [Grund]"); return; } @@ -46,13 +46,12 @@ public class BanCommand extends BasicCommand { if(target == null) return; - Timestamp banTime = parseTime(sender, String.join(args[1], args[2])); + Timestamp banTime = parseTime(sender, args[1]); if(banTime == null) return; StringBuilder banReason = new StringBuilder(); - int start = hasTimestamp(args[2])?2:3; - for (int i = start; i < args.length; i++){ + for (int i = 2; i < args.length; i++){ banReason.append(args[i]).append(" "); } String msg = banReason.toString(); @@ -64,14 +63,14 @@ public class BanCommand extends BasicCommand { if(arg.equalsIgnoreCase("perma")) { return Timestamp.from(Instant.ofEpochSecond(946674800)); }else{ - SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + 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){ dateFormat = new SimpleDateFormat("dd.MM.yyyy"); try{ - Date parsedDate = dateFormat.parse(arg.split(" ")[0]); + 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."); @@ -80,14 +79,4 @@ public class BanCommand extends BasicCommand { } } } - - public static boolean hasTimestamp(String time) { - SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm"); - try{ - dateFormat.parse(time); - return true; - }catch(ParseException exception){ - return false; - } - } } diff --git a/src/de/steamwar/bungeecore/commands/MuteCommand.java b/src/de/steamwar/bungeecore/commands/MuteCommand.java index 9cc0ca9a..dc0d681e 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 < 4){ - BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder perma] {hh:mm} [Grund]"); + if(args.length < 3){ + BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "/mute [Spieler] [dd.mm.yyyy oder dd.mm.yyyy_hh:mm oder perma] [Grund]"); return; } @@ -42,13 +42,12 @@ public class MuteCommand extends BasicCommand { if(target == null) return; - Timestamp muteTime = BanCommand.parseTime(sender, String.join(args[1], args[2])); + Timestamp muteTime = BanCommand.parseTime(sender, args[1]); if(muteTime == null) return; StringBuilder muteReason = new StringBuilder(); - int start = BanCommand.hasTimestamp(args[2])?2:3; - for (int i = start; i < args.length; i++){ + for (int i = 2; i < args.length; i++){ muteReason.append(args[i]).append(" "); } String msg = muteReason.toString();