From 70fbc1a66921d5738f772f4a30863a83fcd46b9b Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 11 Jan 2021 09:00:19 -0500 Subject: [PATCH 1/2] Validate jail before calling event --- .../essentials/commands/Commandtogglejail.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java index 25b43ea88a0..dca5ebdc405 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java @@ -44,6 +44,10 @@ public void run(final Server server, final CommandSource sender, final String co return; } + final String jailName = args[1]; + // Check if jail exists + ess.getJails().getJail(jailName); + final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, true); ess.getServer().getPluginManager().callEvent(event); @@ -63,7 +67,7 @@ public void run(final Server server, final CommandSource sender, final String co player.setJailed(true); player.sendMessage(tl("userJailed")); player.setJail(null); - player.setJail(args[1]); + player.setJail(jailName); if (args.length > 2) { player.setJailTimeout(timeDiff); player.setOnlineJailedTime(ess.getSettings().isJailOnlineTime() ? ((player.getBase().getStatistic(PLAY_ONE_TICK)) + (timeDiff / 50)) : 0); @@ -72,10 +76,8 @@ public void run(final Server server, final CommandSource sender, final String co } }); if (player.getBase().isOnline()) { - ess.getJails().sendToJail(player, args[1], future); + ess.getJails().sendToJail(player, jailName, future); } else { - // Check if jail exists - ess.getJails().getJail(args[1]); future.complete(true); } } From 0afa6ccbe9c5fa2bb100cd5a6d9f005bdc5627ff Mon Sep 17 00:00:00 2001 From: JRoy Date: Mon, 11 Jan 2021 09:10:38 -0500 Subject: [PATCH 2/2] Infer jailname when there is only one jail --- .../essentials/commands/Commandtogglejail.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java index dca5ebdc405..21513c547bf 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.EnumUtil; +import com.google.common.collect.Iterables; import net.ess3.api.events.JailStatusChangeEvent; import org.bukkit.Server; import org.bukkit.Statistic; @@ -31,7 +32,8 @@ public void run(final Server server, final CommandSource sender, final String co final User player = getPlayer(server, args, 0, true, true); - if (args.length >= 2 && !player.isJailed()) { + mainCommand: + if (!player.isJailed()) { if (!player.getBase().isOnline()) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) { sender.sendMessage(tl("mayNotJailOffline")); @@ -44,7 +46,14 @@ public void run(final Server server, final CommandSource sender, final String co return; } - final String jailName = args[1]; + final String jailName; + if (args.length > 1) { + jailName = args[1]; + } else if (ess.getJails().getCount() == 1) { + jailName = Iterables.get(ess.getJails().getList(), 0); + } else { + break mainCommand; + } // Check if jail exists ess.getJails().getJail(jailName);