mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 01:27:33 +01:00
Fix /npc mirror with uuid change
This commit is contained in:
parent
142931a86d
commit
b0a2c51883
@ -19,6 +19,8 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@ -57,24 +59,31 @@ public class ProtocolLibListener {
|
||||
return;
|
||||
boolean changed = false;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
PlayerInfoData data = list.get(i);
|
||||
if (data == null)
|
||||
PlayerInfoData info = list.get(i);
|
||||
if (info == null)
|
||||
continue;
|
||||
if (data.getProfile().getUUID().version() != 2)
|
||||
continue;
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(data.getProfile().getUUID());
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(info.getProfile().getUUID());
|
||||
if (npc == null || !npc.isSpawned())
|
||||
continue;
|
||||
MirrorTrait trait = npc.getTraitNullable(MirrorTrait.class);
|
||||
if (trait == null || !trait.isMirroring(event.getPlayer()))
|
||||
continue;
|
||||
GameProfile profile = NMS.getProfile(event.getPlayer());
|
||||
if (trait.mirrorName()) {
|
||||
list.set(i,
|
||||
new PlayerInfoData(
|
||||
WrappedGameProfile.fromPlayer(event.getPlayer()).withId(
|
||||
info.getProfile().getId()),
|
||||
info.getLatency(), info.getGameMode(),
|
||||
WrappedChatComponent.fromText(event.getPlayer().getDisplayName())));
|
||||
continue;
|
||||
}
|
||||
Collection<Property> textures = profile.getProperties().get("textures");
|
||||
if (textures == null || textures.size() == 0)
|
||||
continue;
|
||||
data.getProfile().getProperties().clear();
|
||||
info.getProfile().getProperties().clear();
|
||||
for (String key : profile.getProperties().keySet()) {
|
||||
data.getProfile().getProperties().putAll(key,
|
||||
info.getProfile().getProperties().putAll(key,
|
||||
Iterables.transform(profile.getProperties().get(key),
|
||||
skin -> new WrappedSignedProperty(skin.getName(), skin.getValue(),
|
||||
skin.getSignature())));
|
||||
|
@ -1638,17 +1638,23 @@ public class NPCCommands {
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
modifiers = { "mirror" },
|
||||
usage = "mirror",
|
||||
usage = "mirror --name [true|false]",
|
||||
desc = "Controls mirroring of NPC skins and more",
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.mirror")
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public void mirror(CommandContext args, CommandSender sender, NPC npc) {
|
||||
public void mirror(CommandContext args, CommandSender sender, NPC npc, @Flag("name") Boolean name) {
|
||||
MirrorTrait trait = npc.getOrAddTrait(MirrorTrait.class);
|
||||
boolean enabled = !trait.isEnabled();
|
||||
trait.setEnabled(enabled);
|
||||
Messaging.sendTr(sender, enabled ? Messages.MIRROR_SET : Messages.MIRROR_UNSET, npc.getName());
|
||||
if (name != null) {
|
||||
trait.setEnabled(true);
|
||||
trait.setMirrorName(name);
|
||||
Messaging.sendTr(sender, name ? Messages.MIRROR_NAME_SET : Messages.MIRROR_NAME_UNSET, npc.getName());
|
||||
} else {
|
||||
boolean enabled = !trait.isEnabled();
|
||||
trait.setEnabled(enabled);
|
||||
Messaging.sendTr(sender, enabled ? Messages.MIRROR_SET : Messages.MIRROR_UNSET, npc.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -12,6 +12,8 @@ import net.citizensnpcs.api.trait.TraitName;
|
||||
public class MirrorTrait extends Trait {
|
||||
@Persist
|
||||
private boolean enabled;
|
||||
@Persist
|
||||
private boolean mirrorName;
|
||||
|
||||
public MirrorTrait() {
|
||||
super("mirrortrait");
|
||||
@ -25,6 +27,10 @@ public class MirrorTrait extends Trait {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public boolean mirrorName() {
|
||||
return mirrorName;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
if (npc.isSpawned()) {
|
||||
@ -32,4 +38,8 @@ public class MirrorTrait extends Trait {
|
||||
npc.spawn(npc.getStoredLocation(), SpawnReason.RESPAWN);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMirrorName(boolean mirror) {
|
||||
mirrorName = mirror;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package net.citizensnpcs.trait.versioned;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
import org.bukkit.entity.EnderDragon.Phase;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Flag;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
|
||||
@TraitName("enderdragontrait")
|
||||
public class EnderDragonTrait extends Trait {
|
||||
@Persist
|
||||
private EnderDragon.Phase phase;
|
||||
|
||||
public EnderDragonTrait() {
|
||||
super("enderdragontrait");
|
||||
}
|
||||
|
||||
public Phase getPhase() {
|
||||
return phase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
updateModifiers();
|
||||
}
|
||||
|
||||
public void setPhase(Phase phase) {
|
||||
this.phase = phase;
|
||||
updateModifiers();
|
||||
}
|
||||
|
||||
private void updateModifiers() {
|
||||
if (!(npc.getEntity() instanceof EnderDragon))
|
||||
return;
|
||||
EnderDragon dragon = (EnderDragon) npc.getEntity();
|
||||
if (phase != null) {
|
||||
dragon.setPhase(phase);
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "enderdragon --phase [phase]",
|
||||
desc = "Control enderdragon modifiers",
|
||||
modifiers = { "enderdragon" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.enderdragon")
|
||||
@Requirements(ownership = true, selected = true, types = EntityType.ENDER_DRAGON)
|
||||
public static void enderdragon(CommandContext args, CommandSender sender, NPC npc,
|
||||
@Flag("phase") EnderDragon.Phase phase) throws CommandException {
|
||||
EnderDragonTrait trait = npc.getOrAddTrait(EnderDragonTrait.class);
|
||||
if (phase != null) {
|
||||
trait.setPhase(phase);
|
||||
}
|
||||
}
|
||||
}
|
@ -240,6 +240,8 @@ public class Messages {
|
||||
public static final String METRICS_ERROR_NOTIFICATION = "citizens.notifications.metrics-load-error";
|
||||
public static final String MINECART_SET = "citizens.commands.npc.minecart.set";
|
||||
public static final String MINIMUM_COST_REQUIRED = "citizens.economy.minimum-cost-required";
|
||||
public static final String MIRROR_NAME_SET = "citizens.commands.npc.mirror.namemirror-set";
|
||||
public static final String MIRROR_NAME_UNSET = "citizens.commands.npc.mirror.namemirror-unset";
|
||||
public static final String MIRROR_SET = "citizens.commands.npc.mirror.set";
|
||||
public static final String MIRROR_UNSET = "citizens.commands.npc.mirror.unset";
|
||||
public static final String MISSING_TP_CURSOR_BLOCK = "citizens.commands.npc.tphere.missing-cursor-block";
|
||||
|
@ -171,6 +171,8 @@ citizens.commands.npc.lookclose.stopped=[[{0}]] will no longer rotate when playe
|
||||
citizens.commands.npc.metadata.set=[[{0}]] set to [[{1}]].
|
||||
citizens.commands.npc.metadata.unset=Removed [[{0}]] from [[{1}]].
|
||||
citizens.commands.npc.minecart.set=[[{0}]] now has item [[{1}]]:[[{2}]] with offset [[{3}]].
|
||||
citizens.commands.npc.mirror.namemirror-set=[[{0}]] will now mirror player names.
|
||||
citizens.commands.npc.mirror.namemirror-unset=[[{0}]] will no longer mirror player names.
|
||||
citizens.commands.npc.mirror.set=[[{0}]] is now mirroring player skins.
|
||||
citizens.commands.npc.mirror.unset=[[{0}]] is no longer mirroring player skins.
|
||||
citizens.commands.npc.mount.failed=Couldn''t mount [[{0}]].
|
||||
|
@ -174,6 +174,7 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.PacketNPC.EntityPacketTracker;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.PolarBearTrait;
|
||||
import net.citizensnpcs.trait.versioned.ShulkerTrait;
|
||||
import net.citizensnpcs.trait.versioned.SnowmanTrait;
|
||||
@ -706,6 +707,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, PolarBearTrait.class);
|
||||
registerTraitWithCommand(manager, ShulkerTrait.class);
|
||||
|
@ -189,6 +189,7 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.PacketNPC.EntityPacketTracker;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.PolarBearTrait;
|
||||
import net.citizensnpcs.trait.versioned.ShulkerTrait;
|
||||
@ -746,6 +747,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, LlamaTrait.class);
|
||||
registerTraitWithCommand(manager, PolarBearTrait.class);
|
||||
|
@ -191,6 +191,7 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.PacketNPC.EntityPacketTracker;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.ParrotTrait;
|
||||
import net.citizensnpcs.trait.versioned.PolarBearTrait;
|
||||
@ -747,6 +748,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, LlamaTrait.class);
|
||||
registerTraitWithCommand(manager, ParrotTrait.class);
|
||||
|
@ -202,6 +202,7 @@ import net.citizensnpcs.npc.skin.SkinnableEntity;
|
||||
import net.citizensnpcs.trait.PacketNPC.EntityPacketTracker;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.ParrotTrait;
|
||||
import net.citizensnpcs.trait.versioned.PhantomTrait;
|
||||
@ -778,6 +779,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, LlamaTrait.class);
|
||||
registerTraitWithCommand(manager, ParrotTrait.class);
|
||||
|
@ -208,6 +208,7 @@ import net.citizensnpcs.trait.PacketNPC.EntityPacketTracker;
|
||||
import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.CatTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.FoxTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.MushroomCowTrait;
|
||||
@ -829,6 +830,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, CatTrait.class);
|
||||
registerTraitWithCommand(manager, FoxTrait.class);
|
||||
|
@ -210,6 +210,7 @@ import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BeeTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.CatTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.FoxTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.MushroomCowTrait;
|
||||
@ -845,6 +846,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BeeTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, CatTrait.class);
|
||||
|
@ -216,6 +216,7 @@ import net.citizensnpcs.trait.RotationTrait;
|
||||
import net.citizensnpcs.trait.versioned.BeeTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.CatTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.FoxTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.MushroomCowTrait;
|
||||
@ -863,6 +864,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, BeeTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
registerTraitWithCommand(manager, CatTrait.class);
|
||||
|
@ -219,6 +219,7 @@ import net.citizensnpcs.trait.versioned.AxolotlTrait;
|
||||
import net.citizensnpcs.trait.versioned.BeeTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.CatTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.FoxTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.MushroomCowTrait;
|
||||
@ -863,6 +864,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, AxolotlTrait.class);
|
||||
registerTraitWithCommand(manager, BeeTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
|
@ -220,6 +220,7 @@ import net.citizensnpcs.trait.versioned.AxolotlTrait;
|
||||
import net.citizensnpcs.trait.versioned.BeeTrait;
|
||||
import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.CatTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.FoxTrait;
|
||||
import net.citizensnpcs.trait.versioned.LlamaTrait;
|
||||
import net.citizensnpcs.trait.versioned.MushroomCowTrait;
|
||||
@ -869,6 +870,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, AxolotlTrait.class);
|
||||
registerTraitWithCommand(manager, BeeTrait.class);
|
||||
registerTraitWithCommand(manager, BossBarTrait.class);
|
||||
|
@ -233,6 +233,7 @@ import net.citizensnpcs.trait.versioned.BossBarTrait;
|
||||
import net.citizensnpcs.trait.versioned.CamelTrait;
|
||||
import net.citizensnpcs.trait.versioned.CamelTrait.CamelPose;
|
||||
import net.citizensnpcs.trait.versioned.CatTrait;
|
||||
import net.citizensnpcs.trait.versioned.EnderDragonTrait;
|
||||
import net.citizensnpcs.trait.versioned.FoxTrait;
|
||||
import net.citizensnpcs.trait.versioned.FrogTrait;
|
||||
import net.citizensnpcs.trait.versioned.GoatTrait;
|
||||
@ -889,6 +890,7 @@ public class NMSImpl implements NMSBridge {
|
||||
|
||||
@Override
|
||||
public void load(CommandManager manager) {
|
||||
registerTraitWithCommand(manager, EnderDragonTrait.class);
|
||||
registerTraitWithCommand(manager, AllayTrait.class);
|
||||
registerTraitWithCommand(manager, AxolotlTrait.class);
|
||||
registerTraitWithCommand(manager, BeeTrait.class);
|
||||
@ -1143,32 +1145,38 @@ public class NMSImpl implements NMSBridge {
|
||||
List<ClientboundPlayerInfoUpdatePacket.Entry> list = Lists.newArrayList(packet.entries());
|
||||
boolean changed = false;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ClientboundPlayerInfoUpdatePacket.Entry data = list.get(i);
|
||||
if (data == null)
|
||||
ClientboundPlayerInfoUpdatePacket.Entry info = list.get(i);
|
||||
if (info == null)
|
||||
continue;
|
||||
if (data.profileId().version() != 2)
|
||||
continue;
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(data.profileId());
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueIdGlobal(info.profileId());
|
||||
if (npc == null || !npc.isSpawned())
|
||||
continue;
|
||||
if (Setting.DISABLE_TABLIST.asBoolean() != data.listed()) {
|
||||
if (Setting.DISABLE_TABLIST.asBoolean() != info.listed()) {
|
||||
list.set(i,
|
||||
new ClientboundPlayerInfoUpdatePacket.Entry(data.profileId(), data.profile(),
|
||||
!Setting.DISABLE_TABLIST.asBoolean(), data.latency(), data.gameMode(),
|
||||
!Setting.DISABLE_TABLIST.asBoolean() ? data.displayName() : Component.empty(),
|
||||
data.chatSession()));
|
||||
new ClientboundPlayerInfoUpdatePacket.Entry(info.profileId(), info.profile(),
|
||||
!Setting.DISABLE_TABLIST.asBoolean(), info.latency(), info.gameMode(),
|
||||
!Setting.DISABLE_TABLIST.asBoolean() ? info.displayName() : Component.empty(),
|
||||
info.chatSession()));
|
||||
changed = true;
|
||||
}
|
||||
MirrorTrait trait = npc.getTraitNullable(MirrorTrait.class);
|
||||
if (trait == null || !trait.isMirroring(player))
|
||||
continue;
|
||||
GameProfile profile = NMS.getProfile(player);
|
||||
if (trait.mirrorName()) {
|
||||
list.set(i,
|
||||
new ClientboundPlayerInfoUpdatePacket.Entry(info.profileId(), profile,
|
||||
!Setting.DISABLE_TABLIST.asBoolean(), info.latency(), info.gameMode(),
|
||||
Component.literal(profile.getName()), info.chatSession()));
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
Collection<Property> textures = profile.getProperties().get("textures");
|
||||
if (textures == null || textures.size() == 0)
|
||||
continue;
|
||||
data.profile().getProperties().clear();
|
||||
info.profile().getProperties().clear();
|
||||
for (String key : profile.getProperties().keySet()) {
|
||||
data.profile().getProperties().putAll(key, profile.getProperties().get(key));
|
||||
info.profile().getProperties().putAll(key, profile.getProperties().get(key));
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user