mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Fix custom name components in 1.8.8-1.12.2,
This commit is contained in:
parent
45d7a072a1
commit
4c958b5e7c
@ -54,6 +54,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@ -107,6 +108,7 @@ import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.ScoreboardTrait;
|
||||
import net.citizensnpcs.trait.ShopTrait;
|
||||
import net.citizensnpcs.trait.SitTrait;
|
||||
import net.citizensnpcs.util.ChunkCoord;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
@ -481,6 +483,9 @@ public class EventListen implements Listener {
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
|
||||
if (event.getHand() == EquipmentSlot.HAND && event.getPlayer().getItemInHand().getType() == Material.NAME_TAG) {
|
||||
rightClickEvent.setCancelled(npc.isProtected());
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(rightClickEvent);
|
||||
if (rightClickEvent.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
@ -548,9 +553,14 @@ public class EventListen implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getPlayer());
|
||||
if (event.getCause() == TeleportCause.PLUGIN && npc != null) {
|
||||
if (npc.hasTrait(SitTrait.class)) {
|
||||
npc.getOrAddTrait(SitTrait.class).setSitting(event.getTo());
|
||||
}
|
||||
}
|
||||
if (event.getCause() == TeleportCause.PLUGIN && !event.getPlayer().hasMetadata("citizens-force-teleporting")
|
||||
&& CitizensAPI.getNPCRegistry().getNPC(event.getPlayer()) != null
|
||||
&& Setting.PLAYER_TELEPORT_DELAY.asInt() > 0) {
|
||||
&& npc != null && Setting.PLAYER_TELEPORT_DELAY.asInt() > 0) {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
@ -667,7 +677,6 @@ public class EventListen implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWorldUnload(WorldUnloadEvent event) {
|
||||
System.out.println(event.getWorld());
|
||||
for (NPC npc : getAllNPCs()) {
|
||||
if (npc == null || !npc.isSpawned() || !npc.getEntity().getWorld().equals(event.getWorld()))
|
||||
continue;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
@ -16,7 +17,10 @@ import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
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.google.common.collect.Lists;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.npc.ai.NPCHolder;
|
||||
@ -34,7 +38,21 @@ public class ProtocolLibListener {
|
||||
flagsClass = MinecraftReflection.getMinecraftClass("EnumPlayerTeleportFlags",
|
||||
"PacketPlayOutPosition$EnumPlayerTeleportFlags",
|
||||
"network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags");
|
||||
|
||||
manager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.PLAYER_INFO) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().readSafely(0);
|
||||
if (list == null)
|
||||
return;
|
||||
for (PlayerInfoData data : Lists.newArrayList(list)) {
|
||||
if (data == null)
|
||||
continue;
|
||||
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(data.getProfile().getUUID());
|
||||
if (npc == null)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
});
|
||||
manager.addPacketListener(
|
||||
new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.ENTITY_HEAD_ROTATION, Server.ENTITY_LOOK) {
|
||||
@Override
|
||||
|
@ -517,8 +517,8 @@ public class CitizensNPC extends AbstractNPC {
|
||||
|
||||
@Override
|
||||
public void updateCustomName() {
|
||||
if (minecraftComponentCache != null) {
|
||||
NMS.setCustomName(getEntity(), minecraftComponentCache);
|
||||
if (nameComponentCache != null) {
|
||||
NMS.setCustomName(getEntity(), nameComponentCache, nameStringComponentCache);
|
||||
} else {
|
||||
super.updateCustomName();
|
||||
}
|
||||
|
@ -542,8 +542,8 @@ public class NMS {
|
||||
BRIDGE.setCamelPose(entity, pose);
|
||||
}
|
||||
|
||||
public static void setCustomName(Entity entity, Object component) {
|
||||
BRIDGE.setCustomName(entity, component);
|
||||
public static void setCustomName(Entity entity, Object component, String string) {
|
||||
BRIDGE.setCustomName(entity, component, string);
|
||||
}
|
||||
|
||||
public static void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) {
|
||||
|
@ -161,7 +161,7 @@ public interface NMSBridge {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setCustomName(Entity entity, Object component);
|
||||
public void setCustomName(Entity entity, Object component, String string);
|
||||
|
||||
public void setDestination(Entity entity, double x, double y, double z, float speed);
|
||||
|
||||
|
@ -269,7 +269,7 @@ public class Util {
|
||||
}
|
||||
|
||||
public static String listValuesPretty(Enum<?>[] values) {
|
||||
return "<e>" + Joiner.on("<a>, <e>").join(values).toLowerCase();
|
||||
return "<yellow>" + Joiner.on("<green>, <yellow>").join(values).toLowerCase();
|
||||
}
|
||||
|
||||
public static boolean locationWithinRange(Location current, Location target, double range) {
|
||||
|
@ -213,7 +213,6 @@ import net.minecraft.server.v1_10_R1.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_10_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_10_R1.EntityWither;
|
||||
import net.minecraft.server.v1_10_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_10_R1.IInventory;
|
||||
import net.minecraft.server.v1_10_R1.MathHelper;
|
||||
import net.minecraft.server.v1_10_R1.MinecraftKey;
|
||||
@ -1044,8 +1043,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText());
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,7 +233,6 @@ import net.minecraft.server.v1_11_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_11_R1.EntityWither;
|
||||
import net.minecraft.server.v1_11_R1.EnumMoveType;
|
||||
import net.minecraft.server.v1_11_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_11_R1.IInventory;
|
||||
import net.minecraft.server.v1_11_R1.MathHelper;
|
||||
import net.minecraft.server.v1_11_R1.MinecraftKey;
|
||||
@ -1103,8 +1102,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText());
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -237,7 +237,6 @@ import net.minecraft.server.v1_12_R1.EntityTypes;
|
||||
import net.minecraft.server.v1_12_R1.EntityWither;
|
||||
import net.minecraft.server.v1_12_R1.EnumMoveType;
|
||||
import net.minecraft.server.v1_12_R1.GenericAttributes;
|
||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_12_R1.IInventory;
|
||||
import net.minecraft.server.v1_12_R1.MathHelper;
|
||||
import net.minecraft.server.v1_12_R1.MinecraftKey;
|
||||
@ -1113,8 +1112,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText());
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1149,7 +1149,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((IChatBaseComponent) component);
|
||||
}
|
||||
|
||||
|
@ -1204,7 +1204,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((IChatBaseComponent) component);
|
||||
}
|
||||
|
||||
|
@ -1222,7 +1222,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((IChatBaseComponent) component);
|
||||
}
|
||||
|
||||
|
@ -1252,7 +1252,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((IChatBaseComponent) component);
|
||||
}
|
||||
|
||||
|
@ -1248,7 +1248,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((Component) component);
|
||||
}
|
||||
|
||||
|
@ -1255,7 +1255,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((Component) component);
|
||||
}
|
||||
|
||||
|
@ -1343,7 +1343,7 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName((Component) component);
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,6 @@ import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
|
||||
import net.minecraft.server.v1_8_R3.EntityTypes;
|
||||
import net.minecraft.server.v1_8_R3.EntityWither;
|
||||
import net.minecraft.server.v1_8_R3.GenericAttributes;
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.IInventory;
|
||||
import net.minecraft.server.v1_8_R3.MathHelper;
|
||||
import net.minecraft.server.v1_8_R3.Navigation;
|
||||
@ -980,8 +979,8 @@ public class NMSImpl implements NMSBridge {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component) {
|
||||
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText());
|
||||
public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
|
||||
getHandle(entity).setCustomName(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user