From 71adc98de13bfc029f9b92af27d7d339f576c8b2 Mon Sep 17 00:00:00 2001 From: Sczptor Date: Fri, 2 Feb 2024 17:23:43 +0000 Subject: [PATCH] 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); + } +}