Add /npc allay

This commit is contained in:
fullwall 2022-07-28 06:36:51 +08:00
parent 2aa6b860c4
commit 7b3c0c8126
16 changed files with 136 additions and 11 deletions

View File

@ -0,0 +1,68 @@
package net.citizensnpcs.trait.versioned;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Allay;
import org.bukkit.entity.EntityType;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.command.exception.CommandUsageException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS;
@TraitName("allaytrait")
public class AllayTrait extends Trait {
@Persist
private boolean dancing = false;
public AllayTrait() {
super("allaytrait");
}
public boolean isDancing() {
return dancing;
}
@Override
public void run() {
if (!npc.isSpawned() || !(npc.getEntity() instanceof Allay))
return;
NMS.setAllayDancing(npc.getEntity(), dancing);
}
public void setDancing(boolean dance) {
this.dancing = dance;
}
@Command(
aliases = { "npc" },
usage = "allay (-d(ancing))",
desc = "Sets allay modifiers",
modifiers = { "allay" },
min = 1,
max = 1,
flags = "d",
permission = "citizens.npc.allay")
@Requirements(selected = true, ownership = true, types = EntityType.ALLAY)
public static void allay(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
AllayTrait trait = npc.getOrAddTrait(AllayTrait.class);
String output = "";
if (args.hasFlag('d')) {
trait.setDancing(!trait.isDancing());
output += ' ' + (trait.isDancing() ? Messaging.tr(Messages.ALLAY_DANCING_SET, npc.getName())
: Messaging.tr(Messages.ALLAY_DANCING_UNSET, npc.getName()));
}
if (!output.isEmpty()) {
Messaging.send(sender, output.trim());
} else {
throw new CommandUsageException();
}
}
}

View File

@ -9,6 +9,8 @@ public class Messages {
public static final String AGE_SET_NORMAL = "citizens.commands.npc.age.set-normal";
public static final String AGE_TRAIT_DESCRIPTION = "citizens.traits.age-description";
public static final String AGE_UNLOCKED = "citizens.commands.npc.age.unlocked";
public static final String ALLAY_DANCING_SET = "citizens.commands.npc.allay.dancing-set";
public static final String ALLAY_DANCING_UNSET = "citizens.commands.npc.allay.dancing-unset";
public static final String ALREADY_IN_EDITOR = "citizens.editors.already-in-editor";
public static final String ALREADY_OWNER = "citizens.commands.npc.owner.already-owner";
public static final String ANCHOR_ADDED = "citizens.commands.npc.anchor.added";

View File

@ -515,6 +515,10 @@ public class NMS {
BRIDGE.sendTeamPacket(recipient, team, mode);
}
public static void setAllayDancing(Entity entity, boolean dancing) {
BRIDGE.setAllayDancing(entity, dancing);
}
public static void setBodyYaw(Entity entity, float yaw) {
BRIDGE.setBodyYaw(entity, yaw);
}

View File

@ -139,6 +139,8 @@ public interface NMSBridge {
public void sendTeamPacket(Player recipient, Team team, int mode);
public void setAllayDancing(Entity entity, boolean dancing);
public void setBodyYaw(Entity entity, float yaw);
public void setDestination(Entity entity, double x, double y, double z, float speed);

View File

@ -11,6 +11,8 @@ citizens.commands.invalid-mobtype=[[{0}]] is not a valid mobtype.
citizens.commands.invalid-number=That is not a valid number.
citizens.commands.npc.ai.started=Now using Minecraft AI.
citizens.commands.npc.ai.stopped=No longer using Minecraft AI.
citizens.commands.npc.allay.dancing-set=[[{0}]] is now dancing.
citizens.commands.npc.allay.dancing-unset=[[{0}]] is no longer dancing.
citizens.commands.npc.age.cannot-be-aged=The mob type {0} cannot be aged.
citizens.commands.npc.age.help=Can only be used on entities that can become babies. Use the [[-l]] flag to lock age over time (note: relogs may be required to see this).
citizens.commands.npc.age.invalid-age=Invalid age. Valid ages are adult, baby, number between -24000 and 0

View File

@ -1001,6 +1001,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -1691,7 +1695,6 @@ public class NMSImpl implements NMSBridge {
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
EntityType.HORSE, EntityType.GHAST);
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
@ -1713,6 +1716,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "g");
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "h");
private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");

View File

@ -1057,6 +1057,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -1754,7 +1758,6 @@ public class NMSImpl implements NMSBridge {
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE,
EntityType.HORSE, EntityType.GHAST);
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c");
@ -1775,6 +1778,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "g");
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "h");
private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");

View File

@ -1067,6 +1067,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -1738,11 +1742,11 @@ public class NMSImpl implements NMSBridge {
if ((entity.width > f2) && (!justCreated) && (!entity.world.isClientSide))
entity.move(EnumMoveType.SELF, (f2 - entity.width) / 2, 0.0D, (f2 - entity.width) / 2);
}
}
};
public static void stopNavigation(NavigationAbstract navigation) {
navigation.p();
};
}
public static void updateAI(EntityLiving entity) {
if (entity instanceof EntityInsentient) {
@ -1762,7 +1766,6 @@ public class NMSImpl implements NMSBridge {
}
private static MethodHandle ADVANCEMENT_PLAYER_FIELD = NMS.getFinalSetter(EntityPlayer.class, "bY");
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.POLAR_BEAR, EntityType.SILVERFISH,
EntityType.SHULKER, EntityType.ENDERMITE, EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME,
EntityType.MAGMA_CUBE, EntityType.HORSE, EntityType.GHAST);
@ -1786,6 +1789,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "g");
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "h");
private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");

View File

@ -1103,6 +1103,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -1901,7 +1905,6 @@ public class NMSImpl implements NMSBridge {
double.class, double.class, double.class);
private static final Field CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getField(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;
private static final Field ENDERDRAGON_BATTLE_BAR_FIELD = NMS.getField(EnderDragonBattle.class, "c", false);
private static final Field ENDERDRAGON_BATTLE_FIELD = NMS.getField(EntityEnderDragon.class, "bR");
@ -1924,6 +1927,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "resultInventory");
private static Field SKULL_PROFILE_FIELD;
private static MethodHandle TEAM_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bL", false);

View File

@ -1162,6 +1162,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -2071,7 +2075,6 @@ public class NMSImpl implements NMSBridge {
EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "c");
private static final MethodHandle BLOCK_POSITION_B_D = NMS.getMethodHandle(BlockPosition.PooledBlockPosition.class,
"c", false, double.class, double.class, double.class);
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
@ -2116,6 +2119,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle REPAIR_INVENTORY = NMS.getGetter(ContainerAnvil.class, "repairInventory");
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "resultInventory");
private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size");
private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size");
private static Field SKULL_PROFILE_FIELD;

View File

@ -1174,6 +1174,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -2151,7 +2155,6 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(PlayerChunkMap.class, "a",
true, EntityPlayer.class, boolean.class);
private static final Map<Class<?>, EntityTypes<?>> CITIZENS_ENTITY_TYPES = Maps.newHashMap();
private static final MethodHandle CRAFT_BOSSBAR_HANDLE_FIELD = NMS.getSetter(CraftBossBar.class, "handle");
private static final float DEFAULT_SPEED = 1F;
@ -2194,6 +2197,7 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle RESULT_INVENTORY = NMS.getGetter(ContainerAnvil.class, "resultInventory");
private static final MethodHandle SET_POSE = NMS.getMethodHandle(Entity.class, "setPose", true, EntityPose.class);
private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size");
private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size");
private static Field SKULL_PROFILE_FIELD;

View File

@ -1204,6 +1204,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -2128,7 +2132,6 @@ public class NMSImpl implements NMSBridge {
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(BehaviorController.class, "e");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(PlayerChunkMap.class, "a",
true, EntityPlayer.class, boolean.class);
private static final Map<Class<?>, EntityTypes<?>> CITIZENS_ENTITY_TYPES = Maps.newHashMap();
@ -2172,6 +2175,7 @@ public class NMSImpl implements NMSBridge {
private static final Random RANDOM = Util.getFastRandom();
private static final MethodHandle SIZE_FIELD_GETTER = NMS.getGetter(Entity.class, "size");
private static final MethodHandle SIZE_FIELD_SETTER = NMS.getSetter(Entity.class, "size");
private static Field SKULL_PROFILE_FIELD;
private static MethodHandle SOUNDEFFECT_KEY = NMS.getGetter(SoundEffect.class, "b");

View File

@ -1200,6 +1200,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).setYRot(yaw);
@ -2123,7 +2127,6 @@ public class NMSImpl implements NMSBridge {
EntityType.SHULKER, EntityType.PHANTOM);
private static final MethodHandle BEHAVIOR_MAP = NMS.getGetter(Brain.class, "f");
private static final MethodHandle BUKKITENTITY_FIELD_SETTER = NMS.getSetter(Entity.class, "bukkitEntity");
private static final MethodHandle CHUNKMAP_UPDATE_PLAYER_STATUS = NMS.getMethodHandle(ChunkMap.class, "a", true,
ServerPlayer.class, boolean.class);

View File

@ -1207,6 +1207,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).setYRot(yaw);

View File

@ -202,6 +202,7 @@ import net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.SmoothRotationTrait;
import net.citizensnpcs.trait.versioned.AllayTrait;
import net.citizensnpcs.trait.versioned.AxolotlTrait;
import net.citizensnpcs.trait.versioned.BeeTrait;
import net.citizensnpcs.trait.versioned.BossBarTrait;
@ -280,6 +281,7 @@ import net.minecraft.world.entity.animal.PolarBear;
import net.minecraft.world.entity.animal.Pufferfish;
import net.minecraft.world.entity.animal.Rabbit;
import net.minecraft.world.entity.animal.Turtle;
import net.minecraft.world.entity.animal.allay.Allay;
import net.minecraft.world.entity.animal.axolotl.Axolotl;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
@ -790,6 +792,7 @@ public class NMSImpl implements NMSBridge {
@Override
public void load(CommandManager manager) {
registerTraitWithCommand(manager, AllayTrait.class);
registerTraitWithCommand(manager, AxolotlTrait.class);
registerTraitWithCommand(manager, BeeTrait.class);
registerTraitWithCommand(manager, BossBarTrait.class);
@ -1221,6 +1224,12 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
Allay allay = (Allay) getHandle(entity);
allay.setDancing(dancing);
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).setYRot(yaw);

View File

@ -942,6 +942,10 @@ public class NMSImpl implements NMSBridge {
}
}
@Override
public void setAllayDancing(org.bukkit.entity.Entity entity, boolean dancing) {
}
@Override
public void setBodyYaw(org.bukkit.entity.Entity entity, float yaw) {
getHandle(entity).yaw = yaw;
@ -1573,7 +1577,6 @@ public class NMSImpl implements NMSBridge {
private static final Set<EntityType> BAD_CONTROLLER_LOOK = EnumSet.of(EntityType.SILVERFISH, EntityType.ENDERMITE,
EntityType.ENDER_DRAGON, EntityType.BAT, EntityType.SLIME, EntityType.MAGMA_CUBE, EntityType.HORSE,
EntityType.GHAST);
private static final float DEFAULT_SPEED = 1F;
private static Method ENTITY_ATTACK_A = NMS.getMethod(Entity.class, "a", true, EntityLiving.class, Entity.class);
private static Map<Class<?>, Integer> ENTITY_CLASS_TO_INT;