-
Notifications
You must be signed in to change notification settings - Fork 6
Feat : New command and button to teleport to a random warp #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
98fb94f
bed7335
d5f8dfc
cd0749f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import net.buildtheearth.buildteamtools.modules.network.NetworkModule; | ||
| import net.buildtheearth.buildteamtools.modules.network.model.BuildTeam; | ||
| import net.buildtheearth.buildteamtools.modules.network.model.Permissions; | ||
| import net.buildtheearth.buildteamtools.utils.Utils; | ||
| import org.bukkit.command.Command; | ||
| import org.bukkit.command.CommandExecutor; | ||
| import org.bukkit.command.CommandSender; | ||
|
|
@@ -18,6 +19,7 @@ | |
| import org.jetbrains.annotations.Nullable; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
@@ -51,6 +53,10 @@ public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command | |
| return handleMigrateCommand(player, args); | ||
| } | ||
|
|
||
| if (args[0].equalsIgnoreCase("random")) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The random subcommand doesn't show up in auto completion + all the other commands also not. Would probably make sense to fix that here |
||
| return handleRandomWarpCommand(player, args); | ||
| } | ||
|
|
||
| return handleWarpTeleport(player, args); | ||
| } | ||
|
|
||
|
|
@@ -100,6 +106,39 @@ private boolean handleMigrateCommand(@NonNull Player player, String @NonNull [] | |
| return true; | ||
| } | ||
|
|
||
| private boolean handleRandomWarpCommand(@NonNull Player player, String @NonNull [] args) { | ||
|
|
||
| if (!player.hasPermission(Permissions.WARP_RANDOM)) { | ||
| player.sendMessage(ChatHelper.getErrorString("You don't have the required %s to %s warps.", "permission", | ||
| "random")); | ||
| return true; | ||
| } | ||
|
|
||
| if (args.length > 1) { | ||
| player.sendMessage(ChatHelper.getErrorComponent("Usage: /warp random")); | ||
| return true; | ||
| } | ||
|
|
||
| BuildTeam buildTeam = NetworkModule.getInstance().getBuildTeam(); | ||
| if (buildTeam == null) { | ||
| return true; | ||
| } | ||
|
|
||
| List<Warp> warps = buildTeam.getWarpGroups().stream() | ||
| .flatMap(group -> group.getWarps().stream()) | ||
| .toList(); | ||
|
|
||
| Warp warp = Utils.pickRandom(warps); | ||
| if (warp == null) { | ||
| player.sendMessage("No warp found"); | ||
| return true; | ||
| } | ||
|
|
||
| NavigationModule.getInstance().getWarpsComponent().warpPlayer(player, warp); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| private void handleMigrationResult(@NonNull Player player, @NonNull MigrationResult result, @Nullable Throwable throwable) { | ||
| if (throwable != null) { | ||
| player.sendMessage(ChatHelper.getErrorComponent("Something went wrong while migrating the warps: %s", | ||
|
|
@@ -152,14 +191,25 @@ private static boolean checkForWarpUsePermissionAndMessage(@NonNull Player playe | |
| @Override | ||
| public @Nullable List<String> onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String @NonNull [] args) { | ||
| if (args.length == 1) { | ||
| List<String> list = new ArrayList<>(); | ||
| if (sender.hasPermission(Permissions.WARP_CREATE)) list.add("create"); | ||
| if (sender.hasPermission(Permissions.WARP_MIGRATE)) list.add("migrate"); | ||
| if (sender.hasPermission(Permissions.WARP_RANDOM)) list.add("random"); | ||
|
|
||
| String partial = args[0].toLowerCase(); | ||
| BuildTeam buildTeam = NetworkModule.getInstance().getBuildTeam(); | ||
| if (buildTeam != null && buildTeam.getWarpGroups() != null) { | ||
| return buildTeam.getWarpGroups().stream() | ||
| List<String> warps = buildTeam.getWarpGroups().stream() | ||
| .flatMap(gr -> gr.getWarps().stream().map(Warp::getName)) | ||
| .filter(s -> s.toLowerCase().startsWith(partial)) | ||
| .toList(); | ||
|
|
||
| list.addAll(warps); | ||
| } | ||
|
|
||
| return list.stream() | ||
| .filter(s -> s.toLowerCase().startsWith(partial)) | ||
| .toList(); | ||
| } | ||
| return Collections.emptyList(); | ||
|
|
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of introducing a subpermission for random warps? and if the user doesn't have the permission the button + subcommand are not shown / executable |
Uh oh!
There was an error while loading. Please reload this page.