From 71adc98de13bfc029f9b92af27d7d339f576c8b2 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Fri, 2 Feb 2024 17:23:43 +0000 Subject: [PATCH 1/7] Added the /orbit command --- src/main/java/dev/plex/extras/TFMExtras.java | 2 + .../dev/plex/extras/command/OrbitCommand.java | 72 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/main/java/dev/plex/extras/command/OrbitCommand.java diff --git a/src/main/java/dev/plex/extras/TFMExtras.java b/src/main/java/dev/plex/extras/TFMExtras.java index d9a553e..3ab0ade 100755 --- a/src/main/java/dev/plex/extras/TFMExtras.java +++ b/src/main/java/dev/plex/extras/TFMExtras.java @@ -93,6 +93,8 @@ 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("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 new file mode 100644 index 0000000..e69d0a5 --- /dev/null +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -0,0 +1,72 @@ +package dev.plex.extras.command; + +import com.google.common.collect.ImmutableList; +import dev.plex.command.PlexCommand; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.source.RequiredCommandSource; +import dev.plex.util.PlexUtils; +import net.kyori.adventure.text.Component; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@CommandParameters(name = "orbit", description = "Accelerates the player at a fast rate", usage = "/ [< | stop>]") +@CommandPermissions(permission = "plex.tfmextras.orbit") +public class OrbitCommand extends PlexCommand +{ + @Override + protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) + { + if (args.length == 0) + { + return usage(); + } + + Player targetPlayer = getNonNullPlayer(args[0]); + + int strength = 100; + + if (args.length >= 2) + { + if (args[1].equalsIgnoreCase("stop")) + { + stopOrbiting(targetPlayer); + return messageComponent("stoppedOrbiting", targetPlayer.getName()); + } + + try + { + strength = Math.max(1, Math.min(150, Integer.parseInt(args[1]))); + } + catch (NumberFormatException ex) + { + return null; + } + } + + startOrbiting(targetPlayer, strength); + PlexUtils.broadcast(messageComponent("playerOrbited", sender.getName(), targetPlayer.getName())); + return null; + } + + @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(); + } + + private void startOrbiting(Player player, int strength) { + player.setGameMode(org.bukkit.GameMode.SURVIVAL); + player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); + } + + private void stopOrbiting(Player player) { + player.removePotionEffect(PotionEffectType.LEVITATION); + } +} From bfefc13738ffe7ef65e13fef766a238115baa051 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Fri, 2 Feb 2024 17:24:13 +0000 Subject: [PATCH 2/7] Added the /orbit command --- src/main/java/dev/plex/extras/command/OrbitCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/dev/plex/extras/command/OrbitCommand.java b/src/main/java/dev/plex/extras/command/OrbitCommand.java index e69d0a5..5ed3959 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; -import dev.plex.command.source.RequiredCommandSource; import dev.plex.util.PlexUtils; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; From 477cf483444c0b92eec424fb454a0b9a33c2a95a Mon Sep 17 00:00:00 2001 From: Sczptor Date: Fri, 2 Feb 2024 17:42:27 +0000 Subject: [PATCH 3/7] Added the /orbit command --- src/main/java/dev/plex/extras/command/OrbitCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/dev/plex/extras/command/OrbitCommand.java b/src/main/java/dev/plex/extras/command/OrbitCommand.java index 5ed3959..22f4fd2 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; -@CommandParameters(name = "orbit", description = "Accelerates the player at a fast rate", usage = "/ [< | stop>]") +@CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/ [< | stop>]") @CommandPermissions(permission = "plex.tfmextras.orbit") public class OrbitCommand extends PlexCommand { From 7f9c8d217ed3c795156c7cd5a481078a907d42e3 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Sat, 3 Feb 2024 12:27:50 +0000 Subject: [PATCH 4/7] Implemented an event listener that reapplies the effect if the player is orbited and tries to remove it. --- .../dev/plex/extras/command/OrbitCommand.java | 12 +++++++ .../extras/listener/OrbitEffectListener.java | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/main/java/dev/plex/extras/listener/OrbitEffectListener.java diff --git a/src/main/java/dev/plex/extras/command/OrbitCommand.java b/src/main/java/dev/plex/extras/command/OrbitCommand.java index 22f4fd2..83e9405 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -13,12 +13,18 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.List; +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 Map isOrbitedMap = new HashMap<>(); + @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { @@ -63,9 +69,15 @@ public class OrbitCommand extends PlexCommand private void startOrbiting(Player player, int strength) { player.setGameMode(org.bukkit.GameMode.SURVIVAL); player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); + isOrbitedMap.put(player.getUniqueId(), true); } private void stopOrbiting(Player player) { player.removePotionEffect(PotionEffectType.LEVITATION); + isOrbitedMap.remove(player.getUniqueId()); + } + + public static boolean isPlayerOrbited(UUID playerId) { + return isOrbitedMap.getOrDefault(playerId, false); } } diff --git a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java new file mode 100644 index 0000000..fbb1e8d --- /dev/null +++ b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java @@ -0,0 +1,31 @@ +package dev.plex.extras.listener; + +import dev.plex.Plex; +import dev.plex.extras.command.OrbitCommand; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import dev.plex.listener.PlexListener; +import org.bukkit.event.entity.EntityPotionEffectEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class OrbitEffectListener extends PlexListener +{ + @EventHandler(priority = EventPriority.LOWEST) + public void onPotionEffectRemove(EntityPotionEffectEvent event) + { + if (event.getEntity() instanceof Player player) + { + 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(), () -> + player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, 100, false, false)), 2); + } + } + } + } +} \ No newline at end of file From 441e9b5679cf7bb5a7be7a040a0abc4eb3d169cb Mon Sep 17 00:00:00 2001 From: Sczptor Date: Sat, 3 Feb 2024 14:05:10 +0000 Subject: [PATCH 5/7] Made relevant changes (Blame drunk me) --- .../java/dev/plex/extras/command/OrbitCommand.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/dev/plex/extras/command/OrbitCommand.java b/src/main/java/dev/plex/extras/command/OrbitCommand.java index 83e9405..643d5ce 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -13,9 +13,8 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.ArrayList; import java.util.UUID; @CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/ [< | stop>]") @@ -23,7 +22,7 @@ import java.util.UUID; public class OrbitCommand extends PlexCommand { - private static final Map isOrbitedMap = new HashMap<>(); + private static final List isOrbited = new ArrayList<>(); @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) @@ -69,15 +68,15 @@ public class OrbitCommand extends PlexCommand private void startOrbiting(Player player, int strength) { player.setGameMode(org.bukkit.GameMode.SURVIVAL); player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); - isOrbitedMap.put(player.getUniqueId(), true); + isOrbited.add(player.getUniqueId()); } private void stopOrbiting(Player player) { player.removePotionEffect(PotionEffectType.LEVITATION); - isOrbitedMap.remove(player.getUniqueId()); + isOrbited.remove(player.getUniqueId()); } public static boolean isPlayerOrbited(UUID playerId) { - return isOrbitedMap.getOrDefault(playerId, false); + return isOrbited.contains(playerId); } } From 7d1698c1da5ff43362e26bbec4c5ca84cde4fa85 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Sun, 4 Feb 2024 00:13:51 +0000 Subject: [PATCH 6/7] Formatting changes --- .../java/dev/plex/extras/command/OrbitCommand.java | 10 ++++++---- .../dev/plex/extras/listener/OrbitEffectListener.java | 3 ++- 2 files changed, 8 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 643d5ce..591751c 100644 --- a/src/main/java/dev/plex/extras/command/OrbitCommand.java +++ b/src/main/java/dev/plex/extras/command/OrbitCommand.java @@ -21,7 +21,6 @@ import java.util.UUID; @CommandPermissions(permission = "plex.tfmextras.orbit") public class OrbitCommand extends PlexCommand { - private static final List isOrbited = new ArrayList<>(); @Override @@ -65,18 +64,21 @@ public class OrbitCommand extends PlexCommand return args.length == 1 && silentCheckPermission(sender, this.getPermission()) ? PlexUtils.getPlayerNameList() : ImmutableList.of(); } - private void startOrbiting(Player player, int strength) { + private void startOrbiting(Player player, int strength) + { player.setGameMode(org.bukkit.GameMode.SURVIVAL); player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false)); isOrbited.add(player.getUniqueId()); } - private void stopOrbiting(Player player) { + private void stopOrbiting(Player player) + { player.removePotionEffect(PotionEffectType.LEVITATION); isOrbited.remove(player.getUniqueId()); } - public static boolean isPlayerOrbited(UUID playerId) { + public static boolean isPlayerOrbited(UUID playerId) + { return isOrbited.contains(playerId); } } diff --git a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java index fbb1e8d..b7f40cb 100644 --- a/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java +++ b/src/main/java/dev/plex/extras/listener/OrbitEffectListener.java @@ -19,7 +19,8 @@ public class OrbitEffectListener extends PlexListener if (event.getEntity() instanceof Player player) { if ((event.getAction() == EntityPotionEffectEvent.Action.CLEARED || event.getAction() == EntityPotionEffectEvent.Action.REMOVED) - && event.getModifiedType() == PotionEffectType.LEVITATION) { + && event.getModifiedType() == PotionEffectType.LEVITATION) + { if (OrbitCommand.isPlayerOrbited(player.getUniqueId())) { Bukkit.getScheduler().runTaskLater(Plex.get(), () -> From 6a854287249f77281661f1f59057f14817a21251 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Sun, 4 Feb 2024 09:19:31 +0000 Subject: [PATCH 7/7] 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); } } }