mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 21:29:14 +01:00
Fix waypoints (an issue with the Goal, not pathing) and make entity type use the bukkit naming scheme
This commit is contained in:
parent
4cf071bf4b
commit
54c80aaa08
@ -59,7 +59,8 @@ public class CommandManager {
|
||||
* Attempt to execute a command. This version takes a separate command name
|
||||
* (for the root command) and then a list of following arguments.
|
||||
*/
|
||||
public void execute(String cmd, String[] args, CommandSender sender, Object... methodArgs) throws CommandException {
|
||||
public void execute(String cmd, String[] args, CommandSender sender, Object... methodArgs)
|
||||
throws CommandException {
|
||||
String[] newArgs = new String[args.length + 1];
|
||||
System.arraycopy(args, 0, newArgs, 1, args.length);
|
||||
newArgs[0] = cmd;
|
||||
@ -77,7 +78,7 @@ public class CommandManager {
|
||||
}
|
||||
|
||||
// Attempt to execute a command.
|
||||
public void executeMethod(Method parent, String[] args, CommandSender sender, Object[] methodArgs)
|
||||
private void executeMethod(Method parent, String[] args, CommandSender sender, Object[] methodArgs)
|
||||
throws CommandException {
|
||||
String cmdName = args[0];
|
||||
String modifier = args.length > 1 ? args[1] : "";
|
||||
@ -101,22 +102,25 @@ public class CommandManager {
|
||||
|
||||
// Requirements
|
||||
if (cmdRequirements.selected() && npc == null)
|
||||
throw new RequirementMissingException("You must have an NPC selected to execute that command.");
|
||||
throw new RequirementMissingException(
|
||||
"You must have an NPC selected to execute that command.");
|
||||
|
||||
if (cmdRequirements.ownership() && npc != null && !sender.hasPermission("citizens.admin")
|
||||
&& !npc.getTrait(Owner.class).isOwnedBy(sender))
|
||||
throw new RequirementMissingException("You must be the owner of this NPC to execute that command.");
|
||||
throw new RequirementMissingException(
|
||||
"You must be the owner of this NPC to execute that command.");
|
||||
|
||||
if (npc != null) {
|
||||
Set<EntityType> types = Sets.newEnumSet(Arrays.asList(cmdRequirements.types()), EntityType.class);
|
||||
Set<EntityType> types = Sets.newEnumSet(Arrays.asList(cmdRequirements.types()),
|
||||
EntityType.class);
|
||||
if (types.contains(EntityType.UNKNOWN))
|
||||
types = EnumSet.allOf(EntityType.class);
|
||||
types.removeAll(Sets.newHashSet(cmdRequirements.excludedTypes()));
|
||||
|
||||
EntityType type = EntityType.valueOf(npc.getTrait(MobType.class).getType());
|
||||
if (!types.contains(type)) {
|
||||
throw new RequirementMissingException("The NPC cannot be the mob type '"
|
||||
+ type.name().toLowerCase().replace('_', '-') + "' to use that command.");
|
||||
throw new RequirementMissingException("The NPC cannot be the mob type '" + type.getName()
|
||||
+ "' to use that command.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -206,7 +210,8 @@ public class CommandManager {
|
||||
// Returns whether a player has access to a command.
|
||||
private boolean hasPermission(Method method, CommandSender sender) {
|
||||
Command cmd = method.getAnnotation(Command.class);
|
||||
if (cmd.permission().isEmpty() || hasPermission(sender, cmd.permission()) || hasPermission(sender, "admin"))
|
||||
if (cmd.permission().isEmpty() || hasPermission(sender, cmd.permission())
|
||||
|| hasPermission(sender, "admin"))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.trait.waypoint;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
@ -125,8 +126,10 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable<Waypoi
|
||||
@Override
|
||||
public void onSpawn(NPC npc) {
|
||||
this.npc = npc;
|
||||
if (currentGoal == null)
|
||||
if (currentGoal == null) {
|
||||
currentGoal = new WaypointGoal(this, npc.getNavigator());
|
||||
CitizensAPI.registerEvents(currentGoal);
|
||||
}
|
||||
npc.getDefaultGoalController().addGoal(currentGoal, 1);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import net.citizensnpcs.api.ai.Goal;
|
||||
import net.citizensnpcs.api.ai.GoalSelector;
|
||||
import net.citizensnpcs.api.ai.Navigator;
|
||||
import net.citizensnpcs.api.ai.event.NavigationCancelEvent;
|
||||
import net.citizensnpcs.npc.ai.NavigationCompleteEvent;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -30,7 +31,15 @@ public class WaypointGoal implements Goal {
|
||||
|
||||
@EventHandler
|
||||
public void onNavigationCancel(NavigationCancelEvent event) {
|
||||
if (!event.getNavigator().equals(navigator) || currentDestination == null)
|
||||
if (currentDestination == null || !event.getNavigator().equals(navigator))
|
||||
return;
|
||||
if (currentDestination.equals(event.getNavigator().getTargetAsLocation()))
|
||||
selector.finish();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNavigationComplete(NavigationCompleteEvent event) {
|
||||
if (currentDestination == null || !event.getNavigator().equals(navigator))
|
||||
return;
|
||||
if (currentDestination.equals(event.getNavigator().getTargetAsLocation()))
|
||||
selector.finish();
|
||||
@ -55,7 +64,7 @@ public class WaypointGoal implements Goal {
|
||||
@Override
|
||||
public boolean shouldExecute(GoalSelector selector) {
|
||||
ensureItr();
|
||||
boolean shouldExecute = itr.hasNext();
|
||||
boolean shouldExecute = currentDestination == null && itr.hasNext();
|
||||
if (shouldExecute) {
|
||||
this.selector = selector;
|
||||
currentDestination = itr.next().getLocation();
|
||||
|
Loading…
Reference in New Issue
Block a user