Added sitting flag to /npc panda

This commit is contained in:
fullwall 2020-02-21 20:28:57 +08:00
parent fca5dc21e0
commit e52f616a4b
15 changed files with 77 additions and 25 deletions

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Panda;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.util.NMS;
@TraitName("pandatrait")
public class PandaTrait extends Trait {
@ -12,6 +13,8 @@ public class PandaTrait extends Trait {
private Panda.Gene hiddenGene;
@Persist
private Panda.Gene mainGene = Panda.Gene.NORMAL;
@Persist
private boolean sitting;
public PandaTrait() {
super("pandatrait");
@ -22,6 +25,7 @@ public class PandaTrait extends Trait {
if (npc.isSpawned() && npc.getEntity() instanceof Panda) {
Panda panda = (Panda) npc.getEntity();
panda.setMainGene(mainGene);
NMS.setPandaSitting(npc.getEntity(), sitting);
if (hiddenGene != null) {
panda.setHiddenGene(hiddenGene);
}
@ -36,4 +40,8 @@ public class PandaTrait extends Trait {
this.mainGene = gene;
}
public boolean toggleSitting() {
return sitting = !sitting;
}
}

View File

@ -224,6 +224,8 @@ public class Messages {
public static final String OWNER_SET_SERVER = "citizens.commands.npc.owner.set-server";
public static final String PANDA_HIDDEN_GENE_SET = "citizens.commands.npc.panda.hidden-gene-set";
public static final String PANDA_MAIN_GENE_SET = "citizens.commands.npc.panda.main-gene-set";
public static final String PANDA_SITTING = "citizens.commands.npc.panda.sitting";
public static final String PANDA_STOPPED_SITTING = "citizens.commands.npc.panda.stopped-sitting";
public static final String PARROT_VARIANT_SET = "citizens.commands.npc.parrot.variant-set";
public static final String PASSIVE_SET = "citizens.commands.npc.passive.set";
public static final String PASSIVE_UNSET = "citizens.commands.npc.passive.unset";

View File

@ -383,6 +383,10 @@ public class NMS {
BRIDGE.setNavigationTarget(handle, target, speed);
}
public static void setPandaSitting(Entity entity, boolean sitting) {
BRIDGE.setPandaSitting(entity, sitting);
}
public static void setPeekShulker(org.bukkit.entity.Entity entity, int peek) {
if (!entity.getType().name().equals("SHULKER")) {
throw new IllegalArgumentException("entity must be a shulker");

View File

@ -127,6 +127,8 @@ public interface NMSBridge {
public void setNavigationTarget(Entity handle, Entity target, float speed);
public void setPandaSitting(Entity entity, boolean sitting);
public void setPeekShulker(Entity entity, int peek);
public void setProfile(SkullMeta meta, GameProfile profile);

View File

@ -120,6 +120,8 @@ citizens.commands.npc.owner.owner=[[{0}]]''s owner is [[{1}]].
citizens.commands.npc.owner.set-server=[[The server]] is now the owner of [[{0}]].
citizens.commands.npc.owner.set=[[{1}]] is now the owner of [[{0}]].
citizens.commands.npc.panda.invalid-gene=Invalid gene. Valid genes are [[{0}]].
citizens.commands.npc.panda.sitting=Started sitting.
citizens.commands.npc.panda.stopped-sitting=Stopped sitting.
citizens.commands.npc.panda.main-gene-set=Main gene set to [[{0}]].
citizens.commands.npc.panda.hidden-gene-set=Hidden gene set to [[{0}]].
citizens.commands.npc.passive.set=[[{0}]] will no longer damage entities.

View File

@ -882,6 +882,10 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);
@ -1472,6 +1476,7 @@ public class NMSImpl implements NMSBridge {
private static final Random RANDOM = Util.getFastRandom();
private static Field SKULL_PROFILE_FIELD;
private static Field TRACKED_ENTITY_SET = NMS.getField(EntityTracker.class, "c");
private static final Field WITHER_BOSS_BAR_FIELD = NMS.getField(EntityWither.class, "bG");
static {

View File

@ -941,6 +941,10 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);

View File

@ -953,6 +953,10 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);

View File

@ -988,6 +988,10 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);

View File

@ -1037,6 +1037,10 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);

View File

@ -1,7 +1,5 @@
package net.citizensnpcs.nms.v1_15_R1.entity;
import net.minecraft.server.v1_15_R1.Vec3D;
import java.util.UUID;
import org.bukkit.Bukkit;

View File

@ -121,28 +121,6 @@ public class PandaController extends MobEntityController {
}
}
@Override
public void h(double x, double y, double z) {
if (npc == null) {
super.h(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
super.h(x, y, z);
return;
}
Vector vector = new Vector(x, y, z);
NPCPushEvent event = Util.callPushEvent(npc, vector);
if (!event.isCancelled()) {
vector = event.getCollisionVector();
super.h(vector.getX(), vector.getY(), vector.getZ());
}
// when another entity collides, this method is called to push the
// NPC so we prevent it from doing anything if the event is
// cancelled.
}
@Override
public CraftEntity getBukkitEntity() {
if (npc != null && !(super.getBukkitEntity() instanceof NPCHolder)) {
@ -171,6 +149,28 @@ public class PandaController extends MobEntityController {
return NMSImpl.getSoundEffect(npc, super.getSoundHurt(damagesource), NPC.HURT_SOUND_METADATA);
}
@Override
public void h(double x, double y, double z) {
if (npc == null) {
super.h(x, y, z);
return;
}
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
if (!npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true))
super.h(x, y, z);
return;
}
Vector vector = new Vector(x, y, z);
NPCPushEvent event = Util.callPushEvent(npc, vector);
if (!event.isCancelled()) {
vector = event.getCollisionVector();
super.h(vector.getX(), vector.getY(), vector.getZ());
}
// when another entity collides, this method is called to push the
// NPC so we prevent it from doing anything if the event is
// cancelled.
}
@Override
public boolean isClimbing() {
if (npc == null || !npc.isFlyable()) {

View File

@ -270,9 +270,10 @@ public class Commands {
@Command(
aliases = { "npc" },
usage = "panda --gene (main gene) --hgene (hidden gene)",
usage = "panda --gene (main gene) --hgene (hidden gene) -s(itting)",
desc = "Sets panda modifiers",
modifiers = { "panda" },
flags = "s",
min = 1,
max = 1,
permission = "citizens.npc.panda")
@ -298,6 +299,10 @@ public class Commands {
trait.setHiddenGene(gene);
output += ' ' + Messaging.tr(Messages.PANDA_HIDDEN_GENE_SET, args.getFlag("hgene"));
}
if (args.hasFlag('s')) {
boolean isSitting = trait.toggleSitting();
output += ' ' + Messaging.tr(isSitting ? Messages.PANDA_SITTING : Messages.PANDA_STOPPED_SITTING);
}
if (!output.isEmpty()) {
Messaging.send(sender, output.trim());
} else {

View File

@ -229,6 +229,7 @@ import net.minecraft.server.v1_15_R1.EntityHuman;
import net.minecraft.server.v1_15_R1.EntityInsentient;
import net.minecraft.server.v1_15_R1.EntityLiving;
import net.minecraft.server.v1_15_R1.EntityMinecartAbstract;
import net.minecraft.server.v1_15_R1.EntityPanda;
import net.minecraft.server.v1_15_R1.EntityPlayer;
import net.minecraft.server.v1_15_R1.EntityPose;
import net.minecraft.server.v1_15_R1.EntityPufferFish;
@ -1040,6 +1041,11 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
((EntityPanda) getHandle(entity)).r(sitting);
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
((EntityShulker) getHandle(shulker)).a((byte) peek);

View File

@ -820,6 +820,10 @@ public class NMSImpl implements NMSBridge {
NMSImpl.getNavigation(handle).a(NMSImpl.getHandle(target), speed);
}
@Override
public void setPandaSitting(org.bukkit.entity.Entity entity, boolean sitting) {
}
@Override
public void setPeekShulker(org.bukkit.entity.Entity shulker, int peek) {
throw new UnsupportedOperationException();