From 6a854287249f77281661f1f59057f14817a21251 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Sun, 4 Feb 2024 09:19:31 +0000 Subject: [PATCH] Altered tab completion to include "stop" argument. Included the isPlayerOrbited check inside the scheduler to fix premature checking --- .../java/dev/plex/extras/command/OrbitCommand.java | 11 ++++++++++- .../dev/plex/extras/listener/OrbitEffectListener.java | 10 ++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/plex/extras/command/OrbitCommand.java b/src/main/java/dev/plex/extras/command/OrbitCommand.java index 591751c..d9f1140 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -13,6 +13,7 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.List; import java.util.ArrayList; import java.util.UUID; @@ -61,7 +62,15 @@ public class OrbitCommand extends PlexCommand @Override public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException { - return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); + if (args.length == 1 && silentCheckPermission(sender, this.getPermission())) + { + return PlexUtils.getPlayerNameList(); + } + else if (args.length == 2 && silentCheckPermission(sender, this.getPermission())) + { + return Collections.singletonList("stop"); + } + return ImmutableList.of(); } private void startOrbiting(Player player, int strength) diff --git a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java index b7f40cb..836c6a2 100644 --- a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java +++ b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java @@ -21,11 +21,13 @@ public class OrbitEffectListener extends PlexListener if ((event.getAction() == EntityPotionEffectEvent.Action.CLEARED || event.getAction() == EntityPotionEffectEvent.Action.REMOVED) && event.getModifiedType() == PotionEffectType.LEVITATION) { - if (OrbitCommand.isPlayerOrbited(player.getUniqueId())) + Bukkit.getScheduler().runTaskLater(Plex.get(), () -> { - Bukkit.getScheduler().runTaskLater(Plex.get(), () -> - player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, 100, false, false)), 2); - } + if (OrbitCommand.isPlayerOrbited(player.getUniqueId())) + { + player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, 100, false, false)); + } + }, 2); } } }