fix skin layers & some adventure warnings
This commit is contained in:
parent
02b6d1fb4c
commit
9b71d532f6
3 changed files with 11 additions and 10 deletions
|
@ -3,16 +3,14 @@ package io.github.znetworkw.znpcservers.commands;
|
|||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import io.github.znetworkw.znpcservers.utility.Utils;
|
||||
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CommandSender {
|
||||
static final Joiner LINE_SEPARATOR_JOINER = Joiner.on("\n");
|
||||
|
||||
|
@ -40,10 +38,10 @@ public class CommandSender {
|
|||
}
|
||||
|
||||
public void sendMessage(String message, Iterable<String> hover) {
|
||||
TextComponent textComponent = Component.text(Utils.toColor(message));
|
||||
if (hover != null)
|
||||
textComponent = textComponent.hoverEvent(Component.text(Utils.toColor(LINE_SEPARATOR_JOINER
|
||||
.join(Iterables.concat(HELP_PREFIX, hover)))));
|
||||
message = message.replace(LegacyComponentSerializer.SECTION_CHAR, LegacyComponentSerializer.AMPERSAND_CHAR);
|
||||
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacyAmpersand();
|
||||
TextComponent textComponent = serializer.deserialize(message);
|
||||
if (hover != null) textComponent = textComponent.hoverEvent(serializer.deserialize(LINE_SEPARATOR_JOINER.join(Iterables.concat(HELP_PREFIX, hover))));
|
||||
ZNPCsPlus.ADVENTURE.player(getPlayer()).sendMessage(textComponent);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ public class DefaultCommand extends Command {
|
|||
.append(Component.text(" " + npcModel.getHologramLines().toString() +
|
||||
" (" + npcModel.getLocation().getWorldName() + " " + (int) npcModel.getLocation().getX() + " " +
|
||||
(int) npcModel.getLocation().getY() + " " + (int) npcModel.getLocation().getZ() + ") ", NamedTextColor.GREEN))
|
||||
.append(Component.text("[TELEPORT]", NamedTextColor.GREEN, TextDecoration.BOLD)
|
||||
.append(Component.text("[TELEPORT]", NamedTextColor.DARK_GREEN, TextDecoration.BOLD)
|
||||
.clickEvent(ClickEvent.runCommand("/znpcs teleport " + npcModel.getId()))
|
||||
.hoverEvent(HoverEvent.showText(Component.text("Click to teleport to this NPC."))))
|
||||
.append(Component.text(" [DELETE]", NamedTextColor.RED, TextDecoration.BOLD)
|
||||
|
|
|
@ -2,6 +2,8 @@ package io.github.znetworkw.znpcservers.npc;
|
|||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
|
||||
import com.github.retrooper.packetevents.protocol.player.Equipment;
|
||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||
|
@ -179,8 +181,7 @@ public class NPC {
|
|||
try {
|
||||
Object dataWatcherObject = Reflections.GET_DATA_WATCHER_METHOD.get().invoke(this.nmsEntity);
|
||||
if (Utils.versionNewer(9)) {
|
||||
Reflections.SET_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject,
|
||||
Reflections.DATA_WATCHER_OBJECT_CONSTRUCTOR.get()
|
||||
Reflections.SET_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject, Reflections.DATA_WATCHER_OBJECT_CONSTRUCTOR.get()
|
||||
.newInstance(this.npcSkin.getLayerIndex(), Reflections.DATA_WATCHER_REGISTER_FIELD.get()), (byte) 127);
|
||||
} else {
|
||||
Reflections.WATCH_DATA_WATCHER_METHOD.get().invoke(dataWatcherObject, 10, (byte) 127);
|
||||
|
@ -242,6 +243,8 @@ public class NPC {
|
|||
ZNPCsPlus.SCHEDULER.runTask(() -> {
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerSpawnPlayer(entityID,
|
||||
this.gameProfile.getId(), SpigotConversionUtil.fromBukkitLocation(location.toBukkitLocation())));
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityMetadata(entityID,
|
||||
List.of(new EntityData(17, EntityDataTypes.BYTE, Byte.MAX_VALUE))));
|
||||
PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerEntityHeadLook(entityID, location.getYaw()));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue