From 1ddcc54c0eccd2a8739f6616b37c03cec2239c94 Mon Sep 17 00:00:00 2001 From: Sceptor Date: Tue, 13 Feb 2024 08:05:12 +0000 Subject: [PATCH 1/2] Fixed the ability to stack orbits. Retained the strength value to be reused in the listener --- src/main/java/dev/plex/extras/TFMExtras.java | 1 + .../dev/plex/extras/command/OrbitCommand.java | 19 +++++++++++++++---- .../extras/listener/OrbitEffectListener.java | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/plex/extras/TFMExtras.java b/src/main/java/dev/plex/extras/TFMExtras.java index 3ab0ade..7c90dc0 100755 --- a/src/main/java/dev/plex/extras/TFMExtras.java +++ b/src/main/java/dev/plex/extras/TFMExtras.java @@ -95,6 +95,7 @@ public class TFMExtras extends PlexModule addDefaultMessage("playerOrbited", "{0} - Orbiting {1}", "0 - The command sender, 1 - The person being orbited"); addDefaultMessage("stoppedOrbiting", "No longer orbiting {0}", "0 - The person no longer being orbited"); + addDefaultMessage("alreadyOrbited", "This player is already being orbited!"); addDefaultMessage("emptyAdminInfo", "The admin information section of the config.yml file has not been configured."); addDefaultMessage("cakeLyrics", "But there's no sense crying over every mistake. You just keep on trying till you run out of cake."); addDefaultMessage("areaEffectCloudClear", "{0} - Removing all area effect clouds", "0 - The command sender"); diff --git a/src/main/java/dev/plex/extras/command/OrbitCommand.java b/src/main/java/dev/plex/extras/command/OrbitCommand.java index d9f1140..be9808a 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -15,14 +15,15 @@ import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; -import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; @CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/ [< | stop>]") @CommandPermissions(permission = "plex.tfmextras.orbit") public class OrbitCommand extends PlexCommand { - private static final List isOrbited = new ArrayList<>(); + private static final Map isOrbited = new HashMap<>(); @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) @@ -54,6 +55,11 @@ public class OrbitCommand extends PlexCommand } } + if (isPlayerOrbited(targetPlayer.getUniqueId())) + { + return messageComponent("alreadyOrbited", targetPlayer.getName()); + } + startOrbiting(targetPlayer, strength); PlexUtils.broadcast(messageComponent("playerOrbited", sender.getName(), targetPlayer.getName())); return null; @@ -77,7 +83,7 @@ public class OrbitCommand extends PlexCommand { player.setGameMode(org.bukkit.GameMode.SURVIVAL); player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); - isOrbited.add(player.getUniqueId()); + isOrbited.put(player.getUniqueId(), strength); } private void stopOrbiting(Player player) @@ -88,6 +94,11 @@ public class OrbitCommand extends PlexCommand public static boolean isPlayerOrbited(UUID playerId) { - return isOrbited.contains(playerId); + return isOrbited.containsKey(playerId); + } + + public static Integer getOrbitStrength(UUID playerId) + { + return isOrbited.get(playerId); } } diff --git a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java index 836c6a2..037dae9 100644 --- a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java +++ b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java @@ -25,7 +25,8 @@ public class OrbitEffectListener extends PlexListener { if (OrbitCommand.isPlayerOrbited(player.getUniqueId())) { - player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, 100, false, false)); + Integer strength = OrbitCommand.getOrbitStrength(player.getUniqueId()); + player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); } }, 2); } From 1656e40cf71ac8fbd40377e53db10436d81bdff3 Mon Sep 17 00:00:00 2001 From: james <75051061+notsceptor@users.noreply.github.com> Date: Tue, 13 Feb 2024 08:12:54 +0000 Subject: [PATCH 2/2] defaultMessage (didn't push properly) --- src/main/java/dev/plex/extras/TFMExtras.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/plex/extras/TFMExtras.java b/src/main/java/dev/plex/extras/TFMExtras.java index 7c90dc0..b49c867 100755 --- a/src/main/java/dev/plex/extras/TFMExtras.java +++ b/src/main/java/dev/plex/extras/TFMExtras.java @@ -95,7 +95,7 @@ public class TFMExtras extends PlexModule addDefaultMessage("playerOrbited", "{0} - Orbiting {1}", "0 - The command sender, 1 - The person being orbited"); addDefaultMessage("stoppedOrbiting", "No longer orbiting {0}", "0 - The person no longer being orbited"); - addDefaultMessage("alreadyOrbited", "This player is already being orbited!"); + addDefaultMessage("alreadyOrbited", "{0} is already being orbited!", "0 - The person that is already orbited"); addDefaultMessage("emptyAdminInfo", "The admin information section of the config.yml file has not been configured."); addDefaultMessage("cakeLyrics", "But there's no sense crying over every mistake. You just keep on trying till you run out of cake."); addDefaultMessage("areaEffectCloudClear", "{0} - Removing all area effect clouds", "0 - The command sender"); @@ -171,4 +171,4 @@ public class TFMExtras extends PlexModule } return true; } -} \ No newline at end of file +}