From 8ce2d6256eff4b878f95a178905b9d402b4ef9cd Mon Sep 17 00:00:00 2001 From: james <75051061+notsceptor@users.noreply.github.com> Date: Wed, 29 May 2024 01:01:38 +0100 Subject: [PATCH 1/3] Implemented the /expel command --- .../dev/plex/extras/command/ExpelCommand.java | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/main/java/dev/plex/extras/command/ExpelCommand.java 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..e685315 --- /dev/null +++ b/src/main/java/dev/plex/extras/command/ExpelCommand.java @@ -0,0 +1,100 @@ +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 = Double.parseDouble(args[0]); + } + catch (NumberFormatException ignored) + { + return usage(); + } + } + + if (args.length > 1) + { + try + { + strength = Double.parseDouble(args[1]); + } + 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 MiniMessage.miniMessage().deserialize("Pushed away players: " + String.join(", ", pushedPlayers)); + } + + return null; + } + + @Override + public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) + { + if (args.length == 1) + { + return Collections.singletonList(""); + } + else if (args.length == 2) + { + return Collections.singletonList(""); + } + return Collections.emptyList(); + } +} From a78196d4d5257f2112570806f2f3435aaf23c5a8 Mon Sep 17 00:00:00 2001 From: james <75051061+notsceptor@users.noreply.github.com> Date: Wed, 29 May 2024 01:24:16 +0100 Subject: [PATCH 2/3] Limited the radius to 20 and the strength to 10 --- src/main/java/dev/plex/extras/command/ExpelCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/plex/extras/command/ExpelCommand.java b/src/main/java/dev/plex/extras/command/ExpelCommand.java index e685315..e18a89b 100644 --- a/src/main/java/dev/plex/extras/command/ExpelCommand.java +++ b/src/main/java/dev/plex/extras/command/ExpelCommand.java @@ -3,6 +3,7 @@ package dev.plex.extras.command; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; +import dev.plex.util.PlexLog; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Location; @@ -30,7 +31,7 @@ public class ExpelCommand extends PlexCommand { try { - radius = Double.parseDouble(args[0]); + radius = Math.min(Double.parseDouble(args[0]), 20.0); } catch (NumberFormatException ignored) { @@ -42,7 +43,7 @@ public class ExpelCommand extends PlexCommand { try { - strength = Double.parseDouble(args[1]); + strength = Math.min(Double.parseDouble(args[1]), 10.0); } catch (NumberFormatException ignored) { From 20da53789d3c7d10e79a0446dc59a389ddcd7197 Mon Sep 17 00:00:00 2001 From: james <75051061+notsceptor@users.noreply.github.com> Date: Fri, 31 May 2024 03:35:43 +0100 Subject: [PATCH 3/3] Moved into messages.yml --- src/main/java/dev/plex/extras/TFMExtras.java | 1 + .../java/dev/plex/extras/command/ExpelCommand.java | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) 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 index e18a89b..62bf8a6 100644 --- a/src/main/java/dev/plex/extras/command/ExpelCommand.java +++ b/src/main/java/dev/plex/extras/command/ExpelCommand.java @@ -3,7 +3,6 @@ package dev.plex.extras.command; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; -import dev.plex.util.PlexLog; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; import org.bukkit.Location; @@ -79,7 +78,7 @@ public class ExpelCommand extends PlexCommand if (!pushedPlayers.isEmpty()) { - return MiniMessage.miniMessage().deserialize("Pushed away players: " + String.join(", ", pushedPlayers)); + return messageComponent("playersExpelled", String.join(", ", pushedPlayers)); } return null; @@ -88,14 +87,6 @@ public class ExpelCommand extends PlexCommand @Override public @NotNull List smartTabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) { - if (args.length == 1) - { - return Collections.singletonList(""); - } - else if (args.length == 2) - { - return Collections.singletonList(""); - } return Collections.emptyList(); } }