Skip to content

Commit

Permalink
navigate command
Browse files Browse the repository at this point in the history
  • Loading branch information
CubBossa committed Jun 5, 2024
1 parent b3f572c commit 9c156fb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ java {
}

group = "de.cubbossa"
version = "5.1.2"
version = "5.2.0"

subprojects {

Expand All @@ -21,6 +21,7 @@ subprojects {

repositories {
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
Expand Down
3 changes: 2 additions & 1 deletion pathfinder-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repositories {
maven("https://libraries.minecraft.net/")
maven("https://repo.codemc.org/repository/maven-snapshots/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
Expand All @@ -44,7 +45,7 @@ dependencies {
testImplementation("com.mojang:brigadier:1.0.18")

// Commands
api("dev.jorel:commandapi-bukkit-shade:9.4.2")
api("dev.jorel:commandapi-bukkit-shade:9.5.0-SNAPSHOT")

// Statistics
implementation("org.bstats:bstats-bukkit:3.0.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.cubbossa.pathfinder.command.impl.ListGroupsCmd;
import de.cubbossa.pathfinder.command.impl.ListNodesCmd;
import de.cubbossa.pathfinder.command.impl.ListVisualizersCmd;
import de.cubbossa.pathfinder.command.impl.NavigateCmd;
import de.cubbossa.pathfinder.command.impl.NodesCmd;
import de.cubbossa.pathfinder.command.impl.VisualizerCmd;
import de.cubbossa.pathfinder.discovery.AbstractDiscoveryModule;
Expand Down Expand Up @@ -65,6 +66,8 @@ public PathFinderCommand(PathFinder pathFinder) {

withAliases("pf");

then(new NavigateCmd(pathFinder));

then(new NodesCmd(pathFinder));
NodeType<?> type = pathFinder.getNodeTypeRegistry().getType(AbstractPathFinder.pathfinder("waypoint"));
then(new CreateNodeCmd(pathFinder, () -> type));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.cubbossa.pathfinder.command.impl;

import de.cubbossa.pathfinder.PathFinder;
import de.cubbossa.pathfinder.PathPerms;
import de.cubbossa.pathfinder.command.Arguments;
import de.cubbossa.pathfinder.command.PathFinderSubCommand;
import de.cubbossa.pathfinder.graph.GraphEntryNotEstablishedException;
import de.cubbossa.pathfinder.graph.NoPathFoundException;
import de.cubbossa.pathfinder.messages.Messages;
import de.cubbossa.pathfinder.misc.PathPlayer;
import de.cubbossa.pathfinder.navigation.NavigationLocation;
import de.cubbossa.pathfinder.navigation.NavigationModule;
import de.cubbossa.pathfinder.navigation.Route;
import de.cubbossa.pathfinder.node.NodeSelection;
import de.cubbossa.pathfinder.node.implementation.PlayerNode;
import java.util.Collection;
import java.util.concurrent.CompletionException;
import java.util.logging.Level;
import org.bukkit.entity.Player;

public class NavigateCmd extends PathFinderSubCommand {

public NavigateCmd(PathFinder pathFinder) {
super(pathFinder, "navigate");

withPermission(PathPerms.PERM_CMD_NAVIGATE);

then(Arguments.pathPlayers("players")
.then(Arguments.navigateSelectionArgument("to")
.executes((sender, args) -> {
PathPlayer<?> pathSender = PathPlayer.wrap(sender);
Collection<PathPlayer<Player>> players = args.getUnchecked(0);
NodeSelection target = args.getUnchecked(1);

NavigationModule<Player> navigationModule = NavigationModule.get();
for (PathPlayer<Player> player : players) {
navigationModule.navigate(player, Route
.from(NavigationLocation.movingExternalNode(new PlayerNode(player)))
.to(target))
.whenComplete((path, throwable) -> {
if (throwable != null) {
if (throwable instanceof CompletionException) {
throwable = throwable.getCause();
}
if (throwable instanceof NoPathFoundException) {
pathSender.sendMessage(Messages.CMD_FIND_BLOCKED);
} else if (throwable instanceof GraphEntryNotEstablishedException) {
pathSender.sendMessage(Messages.CMD_FIND_TOO_FAR);
} else {
pathSender.sendMessage(Messages.CMD_FIND_UNKNOWN);
PathFinder.get().getLogger().log(Level.SEVERE, "Unknown error while finding path.", throwable);
}
return;
}
navigationModule.cancelPathWhenTargetReached(path);
});
;
}
})
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PathPerms {
public static final String PERM_CMD_FIND_PLAYER_ACCEPT = "pathfinder.command.findplayer.accept";
public static final String PERM_CMD_FIND_PLAYER_DECLINE = "pathfinder.command.findplayer.decline";
public static final String PERM_CMD_CANCELPATH = "pathfinder.command.cancel_path";
public static final String PERM_CMD_NAVIGATE = "pathfinder.command.navigate";
public static final String PERM_CMD_NG_INFO = "pathfinder.command.nodegroup.info";
public static final String PERM_CMD_NG_LIST = "pathfinder.command.nodegroup.list";
public static final String PERM_CMD_NG_CREATE = "pathfinder.command.nodegroup.create";
Expand Down

0 comments on commit 9c156fb

Please sign in to comment.