mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-14 12:11:30 +01:00
Implement run callbacks and fix /npc skeletontype requiring uppercase input
This commit is contained in:
parent
993d2fe017
commit
da2bf551bc
@ -39,6 +39,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityCombustByEntityEvent;
|
||||
@ -50,6 +51,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
@ -254,6 +256,15 @@ public class EventListen implements Listener {
|
||||
checkCreationEvent(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
for (NPC npc : CitizensAPI.getNPCRegistry()) {
|
||||
npc.getNavigator().setTarget(event.getClickedBlock().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
NPC npc = npcRegistry.getNPC(event.getRightClicked());
|
||||
|
@ -265,7 +265,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, copy)
|
||||
: new CommandSenderCreateNPCEvent(sender, copy);
|
||||
: new CommandSenderCreateNPCEvent(sender, copy);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
event.getNPC().destroy();
|
||||
@ -337,7 +337,7 @@ public class NPCCommands {
|
||||
spawnLoc = args.getSenderLocation();
|
||||
}
|
||||
CommandSenderCreateNPCEvent event = sender instanceof Player ? new PlayerCreateNPCEvent((Player) sender, npc)
|
||||
: new CommandSenderCreateNPCEvent(sender, npc);
|
||||
: new CommandSenderCreateNPCEvent(sender, npc);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
npc.destroy();
|
||||
@ -969,7 +969,7 @@ public class NPCCommands {
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
|
||||
public void power(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging
|
||||
.sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED);
|
||||
.sendTr(sender, npc.getTrait(Powered.class).toggle() ? Messages.POWERED_SET : Messages.POWERED_STOPPED);
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -1112,7 +1112,7 @@ public class NPCCommands {
|
||||
"skeletontype", "sktype" }, min = 2, max = 2, permission = "citizens.npc.skeletontype")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.SKELETON)
|
||||
public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
SkeletonType type = SkeletonType.valueOf(args.getString(1));
|
||||
SkeletonType type = SkeletonType.valueOf(args.getString(1).toUpperCase());
|
||||
if (type == null)
|
||||
throw new CommandException(Messages.INVALID_SKELETON_TYPE);
|
||||
npc.getTrait(NPCSkeletonType.class).setType(type);
|
||||
|
@ -76,6 +76,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
|
||||
NMS.setShouldJump(npc.getEntity());
|
||||
}
|
||||
NMS.setDestination(npc.getEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed());
|
||||
params.tick();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -121,8 +121,9 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
return;
|
||||
updatePathfindingRange();
|
||||
boolean finished = executing.update();
|
||||
if (!finished)
|
||||
if (!finished) {
|
||||
return;
|
||||
}
|
||||
if (executing.getCancelReason() != null) {
|
||||
stopNavigating(executing.getCancelReason());
|
||||
} else {
|
||||
|
@ -80,6 +80,7 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
|
||||
|
||||
NMS.setVerticalMovement(npc.getEntity(), 0.5);
|
||||
NMS.setHeadYaw(NMS.getHandle(npc.getEntity()), current.getYaw() + normalisedTargetYaw);
|
||||
parameters.tick();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,7 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
|
||||
return true;
|
||||
navigation.a(parameters.avoidWater());
|
||||
navigation.a(parameters.speed());
|
||||
parameters.tick();
|
||||
return NMS.isNavigationFinished(navigation);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user