Merge pull request #6 from notsceptor/master

Implemented /expel from TFM
This commit is contained in:
Telesphoreo 2024-05-31 15:42:25 -05:00 committed by GitHub
commit f0aadea9e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 93 additions and 0 deletions

View File

@ -121,6 +121,7 @@ public class TFMExtras extends PlexModule
addDefaultMessage("cantVisitIsland", "<red>You can't visit this player's island!"); addDefaultMessage("cantVisitIsland", "<red>You can't visit this player's island!");
addDefaultMessage("islandMemberExists", "<red>This player is already a member of your island!"); addDefaultMessage("islandMemberExists", "<red>This player is already a member of your island!");
addDefaultMessage("receivedInviteForIsland", "<green>You have been invited to join "); //TODO: Finish this message... my laptop isn't liking minecraft so I can't do formatting for it, and do receivedInviteForIsland message addDefaultMessage("receivedInviteForIsland", "<green>You have been invited to join "); //TODO: Finish this message... my laptop isn't liking minecraft so I can't do formatting for it, and do receivedInviteForIsland message
addDefaultMessage("playersExpelled", "<gray>Pushed away players: <white><em>{0}", "0 - The list of players");
} }
@Override @Override

View File

@ -0,0 +1,92 @@
package dev.plex.extras.command;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@CommandParameters(name = "expel", description = "Pushes away nearby players", usage = "/expel <radius> <strength>", aliases = "push")
@CommandPermissions(permission = "plex.tfmextras.expel")
public class ExpelCommand extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player player, @NotNull String[] args)
{
double radius = 20.0;
double strength = 5.0;
if (args.length > 0)
{
try
{
radius = Math.min(Double.parseDouble(args[0]), 20.0);
}
catch (NumberFormatException ignored)
{
return usage();
}
}
if (args.length > 1)
{
try
{
strength = Math.min(Double.parseDouble(args[1]), 10.0);
}
catch (NumberFormatException ignored)
{
return usage();
}
}
List<String> pushedPlayers = new ArrayList<>();
final Vector senderPos = player.getLocation().toVector();
final List<Player> players = player.getWorld().getPlayers();
for (final Player target : players)
{
if (target.equals(player))
{
continue;
}
final Location targetPos = target.getLocation();
final Vector targetPosVec = targetPos.toVector();
if (targetPosVec.distanceSquared(senderPos) < (radius * radius))
{
target.setFlying(false);
target.getWorld().createExplosion(targetPos, 0.0f, false);
target.setVelocity(targetPosVec.subtract(senderPos).normalize().multiply(strength));
pushedPlayers.add(target.getName());
}
}
if (!pushedPlayers.isEmpty())
{
return messageComponent("playersExpelled", String.join("<reset><gray>, <white><em>", pushedPlayers));
}
return null;
}
@Override
public @NotNull List<String> smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args)
{
return Collections.emptyList();
}
}