mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 13:15:33 +01:00
Add some arguments to the /npc path command allowing for pausing and immediate waypoint placing
This commit is contained in:
parent
0e4a85bc4a
commit
9797d4cdeb
@ -35,11 +35,12 @@ public class EditorCommands {
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
flags = "*",
|
||||
permission = "citizens.npc.edit.path")
|
||||
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BLAZE, EntityType.ENDER_DRAGON,
|
||||
EntityType.GHAST, EntityType.BAT, EntityType.WITHER, EntityType.SQUID })
|
||||
public void path(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player));
|
||||
Editor.enterOrLeave(player, npc.getTrait(Waypoints.class).getEditor(player, args));
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -334,37 +334,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
if (args.hasValueFlag("at")) {
|
||||
String[] parts = Iterables.toArray(Splitter.on(':').split(args.getFlag("at")), String.class);
|
||||
if (parts.length > 0) {
|
||||
String worldName = args.getSenderLocation() != null ? args.getSenderLocation().getWorld().getName()
|
||||
: "";
|
||||
int x = 0, y = 0, z = 0;
|
||||
float yaw = 0F, pitch = 0F;
|
||||
switch (parts.length) {
|
||||
case 6:
|
||||
pitch = Float.parseFloat(parts[5]);
|
||||
case 5:
|
||||
yaw = Float.parseFloat(parts[4]);
|
||||
case 4:
|
||||
worldName = parts[3];
|
||||
case 3:
|
||||
x = Integer.parseInt(parts[0]);
|
||||
y = Integer.parseInt(parts[1]);
|
||||
z = Integer.parseInt(parts[2]);
|
||||
break;
|
||||
default:
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
}
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null)
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
spawnLoc = new Location(world, x, y, z, yaw, pitch);
|
||||
} else {
|
||||
Player search = Bukkit.getPlayerExact(args.getFlag("at"));
|
||||
if (search == null)
|
||||
throw new CommandException(Messages.PLAYER_NOT_FOUND_FOR_SPAWN);
|
||||
spawnLoc = search.getLocation();
|
||||
}
|
||||
spawnLoc = Util.parseLocation(args.getSenderLocation(), args.getFlag("at"));
|
||||
}
|
||||
if (spawnLoc == null) {
|
||||
npc.destroy();
|
||||
|
@ -26,6 +26,8 @@ public abstract class Editor implements Listener {
|
||||
}
|
||||
|
||||
public static void enterOrLeave(Player player, Editor editor) {
|
||||
if (editor == null)
|
||||
return;
|
||||
Editor edit = EDITING.get(player.getName());
|
||||
if (edit == null)
|
||||
enter(player, editor);
|
||||
|
@ -12,6 +12,8 @@ import net.citizensnpcs.api.ai.GoalSelector;
|
||||
import net.citizensnpcs.api.ai.Navigator;
|
||||
import net.citizensnpcs.api.ai.event.CancelReason;
|
||||
import net.citizensnpcs.api.ai.event.NavigatorCallback;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||
import net.citizensnpcs.api.event.NPCRemoveEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -22,6 +24,7 @@ import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.trait.waypoint.triggers.TriggerEditPrompt;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -48,7 +51,24 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
private final List<Waypoint> waypoints = Lists.newArrayList();
|
||||
|
||||
@Override
|
||||
public WaypointEditor createEditor(Player player) {
|
||||
public WaypointEditor createEditor(Player player, CommandContext args) {
|
||||
if (args.hasFlag('h')) {
|
||||
waypoints.add(new Waypoint(player.getLocation()));
|
||||
return null;
|
||||
}
|
||||
if (args.hasValueFlag("at")) {
|
||||
try {
|
||||
Location location = Util.parseLocation(player.getLocation(), args.getFlag("at"));
|
||||
waypoints.add(new Waypoint(location));
|
||||
} catch (CommandException e) {
|
||||
Messaging.sendError(player, e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (args.hasFlag('p')) {
|
||||
setPaused(!isPaused());
|
||||
return null;
|
||||
}
|
||||
return new LinearWaypointEditor(player);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.trait.waypoint;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.ai.Goal;
|
||||
import net.citizensnpcs.api.ai.goals.WanderGoal;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
@ -18,7 +19,7 @@ public class WanderWaypointProvider implements WaypointProvider {
|
||||
private final int yrange = DEFAULT_YRANGE;
|
||||
|
||||
@Override
|
||||
public WaypointEditor createEditor(Player player) {
|
||||
public WaypointEditor createEditor(Player player, CommandContext args) {
|
||||
return new WaypointEditor() {
|
||||
@Override
|
||||
public void begin() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs.trait.waypoint;
|
||||
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
|
||||
@ -12,9 +13,10 @@ public interface WaypointProvider {
|
||||
*
|
||||
* @param player
|
||||
* The player to link the editor with
|
||||
* @param args
|
||||
* @return The editor
|
||||
*/
|
||||
public WaypointEditor createEditor(Player player);
|
||||
public WaypointEditor createEditor(Player player, CommandContext args);
|
||||
|
||||
/**
|
||||
* Returns whether this provider has paused execution of waypoints.
|
||||
|
@ -3,6 +3,7 @@ package net.citizensnpcs.trait.waypoint;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
@ -57,8 +58,8 @@ public class Waypoints extends Trait {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
public Editor getEditor(Player player) {
|
||||
return provider.createEditor(player);
|
||||
public Editor getEditor(Player player, CommandContext args) {
|
||||
return provider.createEditor(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.citizensnpcs.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.event.NPCCollisionEvent;
|
||||
import net.citizensnpcs.api.event.NPCPushEvent;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -9,6 +10,7 @@ import net.citizensnpcs.api.npc.NPC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -16,6 +18,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
public class Util {
|
||||
// Static class for small (emphasis small) utility methods
|
||||
@ -117,4 +120,37 @@ public class Util {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Location parseLocation(Location currentLocation, String flag) throws CommandException {
|
||||
String[] parts = Iterables.toArray(Splitter.on(':').split(flag), String.class);
|
||||
if (parts.length > 0) {
|
||||
String worldName = currentLocation != null ? currentLocation.getWorld().getName() : "";
|
||||
int x = 0, y = 0, z = 0;
|
||||
float yaw = 0F, pitch = 0F;
|
||||
switch (parts.length) {
|
||||
case 6:
|
||||
pitch = Float.parseFloat(parts[5]);
|
||||
case 5:
|
||||
yaw = Float.parseFloat(parts[4]);
|
||||
case 4:
|
||||
worldName = parts[3];
|
||||
case 3:
|
||||
x = Integer.parseInt(parts[0]);
|
||||
y = Integer.parseInt(parts[1]);
|
||||
z = Integer.parseInt(parts[2]);
|
||||
break;
|
||||
default:
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
}
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null)
|
||||
throw new CommandException(Messages.INVALID_SPAWN_LOCATION);
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
} else {
|
||||
Player search = Bukkit.getPlayerExact(flag);
|
||||
if (search == null)
|
||||
throw new CommandException(Messages.PLAYER_NOT_FOUND_FOR_SPAWN);
|
||||
return search.getLocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user