Merge pull request #3 from notsceptor/master

Added /orbit
This commit is contained in:
Telesphoreo 2024-02-04 03:54:58 -06:00 committed by GitHub
commit 310d2fd2de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 129 additions and 0 deletions

View file

@ -93,6 +93,8 @@ public class TFMExtras extends PlexModule
}
});
addDefaultMessage("playerOrbited", "<aqua>{0} - Orbiting {1}", "0 - The command sender, 1 - The person being orbited");
addDefaultMessage("stoppedOrbiting", "<aqua>No longer orbiting {0}", "0 - The person no longer being orbited");
addDefaultMessage("emptyAdminInfo", "<red>The admin information section of the config.yml file has not been configured.");
addDefaultMessage("cakeLyrics", "<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of cake.");
addDefaultMessage("areaEffectCloudClear", "<red>{0} - Removing all area effect clouds", "0 - The command sender");

View file

@ -0,0 +1,93 @@
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;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.UUID;
@CommandParameters(name = "orbit", description = "Accelerates the player at a super fast rate", usage = "/<command> <target> [<<power> | stop>]")
@CommandPermissions(permission = "plex.tfmextras.orbit")
public class OrbitCommand extends PlexCommand
{
private static final List<UUID> isOrbited = new ArrayList<>();
@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
{
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)
{
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)
{
player.removePotionEffect(PotionEffectType.LEVITATION);
isOrbited.remove(player.getUniqueId());
}
public static boolean isPlayerOrbited(UUID playerId)
{
return isOrbited.contains(playerId);
}
}

View file

@ -0,0 +1,34 @@
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)
{
Bukkit.getScheduler().runTaskLater(Plex.get(), () ->
{
if (OrbitCommand.isPlayerOrbited(player.getUniqueId()))
{
player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, Integer.MAX_VALUE, 100, false, false));
}
}, 2);
}
}
}
}