2024-02-02 17:23:43 +00:00
|
|
|
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.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;
|
|
|
|
|
2024-02-04 09:19:31 +00:00
|
|
|
import java.util.Collections;
|
2024-02-02 17:23:43 +00:00
|
|
|
import java.util.List;
|
2024-02-03 14:05:10 +00:00
|
|
|
import java.util.ArrayList;
|
2024-02-03 12:27:50 +00:00
|
|
|
import java.util.UUID;
|
2024-02-02 17:23:43 +00:00
|
|
|
|
2024-02-02 17:42:27 +00:00
|
|
|
@CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/<command> <target> [<<power> | stop>]")
|
2024-02-02 17:23:43 +00:00
|
|
|
@CommandPermissions(permission = "plex.tfmextras.orbit")
|
|
|
|
public class OrbitCommand extends PlexCommand
|
|
|
|
{
|
2024-02-03 14:05:10 +00:00
|
|
|
private static final List<UUID> isOrbited = new ArrayList<>();
|
2024-02-03 12:27:50 +00:00
|
|
|
|
2024-02-02 17:23:43 +00:00
|
|
|
@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<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
|
|
{
|
2024-02-04 09:19:31 +00:00
|
|
|
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();
|
2024-02-02 17:23:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 00:13:51 +00:00
|
|
|
private void startOrbiting(Player player, int strength)
|
|
|
|
{
|
2024-02-02 17:23:43 +00:00
|
|
|
player.setGameMode(org.bukkit.GameMode.SURVIVAL);
|
|
|
|
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, strength, false, false));
|
2024-02-03 14:05:10 +00:00
|
|
|
isOrbited.add(player.getUniqueId());
|
2024-02-02 17:23:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 00:13:51 +00:00
|
|
|
private void stopOrbiting(Player player)
|
|
|
|
{
|
2024-02-02 17:23:43 +00:00
|
|
|
player.removePotionEffect(PotionEffectType.LEVITATION);
|
2024-02-03 14:05:10 +00:00
|
|
|
isOrbited.remove(player.getUniqueId());
|
2024-02-03 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 00:13:51 +00:00
|
|
|
public static boolean isPlayerOrbited(UUID playerId)
|
|
|
|
{
|
2024-02-03 14:05:10 +00:00
|
|
|
return isOrbited.contains(playerId);
|
2024-02-02 17:23:43 +00:00
|
|
|
}
|
|
|
|
}
|