diff --git a/src/main/java/dev/plex/extras/TFMExtras.java b/src/main/java/dev/plex/extras/TFMExtras.java index 734ca22..41b396d 100755 --- a/src/main/java/dev/plex/extras/TFMExtras.java +++ b/src/main/java/dev/plex/extras/TFMExtras.java @@ -121,6 +121,7 @@ public class TFMExtras extends PlexModule addDefaultMessage("cantVisitIsland", "You can't visit this player's island!"); addDefaultMessage("islandMemberExists", "This player is already a member of your island!"); addDefaultMessage("receivedInviteForIsland", "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", "Pushed away players: {0}", "0 - The list of players"); } @Override diff --git a/src/main/java/dev/plex/extras/command/ExpelCommand.java b/src/main/java/dev/plex/extras/command/ExpelCommand.java new file mode 100644 index 0000000..62bf8a6 --- /dev/null +++ b/src/main/java/dev/plex/extras/command/ExpelCommand.java @@ -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 ", 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 pushedPlayers = new ArrayList<>(); + + final Vector senderPos = player.getLocation().toVector(); + final List 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(", ", pushedPlayers)); + } + + return null; + } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) + { + return Collections.emptyList(); + } +}