mirror of
https://github.com/Xiao-MoMi/Custom-Nameplates.git
synced 2025-12-25 18:09:20 +00:00
folia fix
This commit is contained in:
@@ -22,25 +22,30 @@ import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.helper.VersionHelper;
|
||||
import net.momirealms.customnameplates.api.network.PacketEvent;
|
||||
import net.momirealms.customnameplates.api.network.PacketSender;
|
||||
import net.momirealms.customnameplates.api.network.PipelineInjector;
|
||||
import net.momirealms.customnameplates.api.util.Vector3;
|
||||
import net.momirealms.customnameplates.bukkit.util.ListMonitor;
|
||||
import net.momirealms.customnameplates.bukkit.util.Reflections;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class BukkitNetworkManager implements PacketSender, PipelineInjector {
|
||||
|
||||
private final BiConsumer<CNPlayer, List<Object>> packetsConsumer;
|
||||
private final CustomNameplates plugin;
|
||||
private final BiConsumer<CNPlayer, Object> packetConsumer;
|
||||
private final BukkitCustomNameplates plugin;
|
||||
private static final String NAMEPLATES_CONNECTION_HANDLER_NAME = "nameplates_connection_handler";
|
||||
private static final String NAMEPLATES_SERVER_CHANNEL_HANDLER_NAME = "nameplates_server_channel_handler";
|
||||
private static final String NAMEPLATES_PACKET_HANDLER_NAME = "nameplates_packet_handler";
|
||||
@@ -49,7 +54,7 @@ public class BukkitNetworkManager implements PacketSender, PipelineInjector {
|
||||
private boolean active;
|
||||
private boolean init;
|
||||
|
||||
public BukkitNetworkManager(CustomNameplates plugin) {
|
||||
public BukkitNetworkManager(BukkitCustomNameplates plugin) {
|
||||
this.plugin = plugin;
|
||||
this.packetsConsumer = ((player, objects) -> {
|
||||
try {
|
||||
@@ -59,6 +64,31 @@ public class BukkitNetworkManager implements PacketSender, PipelineInjector {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
if (!VersionHelper.isFolia()) {
|
||||
packetConsumer = (player, packet) -> {
|
||||
try {
|
||||
Reflections.method$SendPacket.invoke(
|
||||
Reflections.field$PlayerConnection.get(
|
||||
Reflections.method$CraftPlayer$getHandle.invoke(player.player())), packet);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
packetConsumer = (player, packet) -> {
|
||||
Vector3 vector3 = player.position();
|
||||
Location location = new Location(Bukkit.getWorld(player.world()), vector3.x(), vector3.y(), vector3.z());
|
||||
plugin.getScheduler().executeSync(() -> {
|
||||
try {
|
||||
Reflections.method$SendPacket.invoke(
|
||||
Reflections.field$PlayerConnection.get(
|
||||
Reflections.method$CraftPlayer$getHandle.invoke(player.player())), packet);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, location);
|
||||
};
|
||||
}
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
@@ -148,13 +178,7 @@ public class BukkitNetworkManager implements PacketSender, PipelineInjector {
|
||||
|
||||
@Override
|
||||
public void sendPacket(@NotNull CNPlayer player, Object packet) {
|
||||
try {
|
||||
Reflections.method$SendPacket.invoke(
|
||||
Reflections.field$PlayerConnection.get(
|
||||
Reflections.method$CraftPlayer$getHandle.invoke(player.player())), packet);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
packetConsumer.accept(player, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
|
||||
package net.momirealms.customnameplates.bukkit.compatibility.chat;
|
||||
|
||||
import net.essentialsx.api.v2.ChatType;
|
||||
import net.essentialsx.api.v2.events.chat.ChatEvent;
|
||||
import net.essentialsx.api.v2.events.chat.GlobalChatEvent;
|
||||
import net.essentialsx.api.v2.events.chat.LocalChatEvent;
|
||||
import net.momirealms.customnameplates.api.CNPlayer;
|
||||
import net.momirealms.customnameplates.api.CustomNameplates;
|
||||
import net.momirealms.customnameplates.api.feature.chat.AbstractChatMessageProvider;
|
||||
@@ -27,6 +30,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -52,15 +56,24 @@ public class EssentialsChatProvider extends AbstractChatMessageProvider implemen
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEssChat(ChatEvent event) {
|
||||
String channel = event.getChatType().key();
|
||||
Player player = Bukkit.getPlayer(event.getPlayer().getUniqueId());
|
||||
public void onEssChat(LocalChatEvent event) {
|
||||
onChat(event.getChatType(), event.getPlayer(), event.getMessage());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onEssChat(GlobalChatEvent event) {
|
||||
onChat(event.getChatType(), event.getPlayer(), event.getMessage());
|
||||
}
|
||||
|
||||
private void onChat(ChatType chatType, Player player2, String message) {
|
||||
String channel = chatType.key();
|
||||
Player player = Bukkit.getPlayer(player2.getUniqueId());
|
||||
if (player == null || !player.isOnline())
|
||||
return;
|
||||
CNPlayer cnPlayer = plugin.getPlayer(player.getUniqueId());
|
||||
if (cnPlayer == null)
|
||||
return;
|
||||
plugin.getScheduler().async().execute(() -> manager.onChat(cnPlayer, event.getMessage(), channel));
|
||||
plugin.getScheduler().async().execute(() -> manager.onChat(cnPlayer, message, channel));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=3.0.3
|
||||
project_version=3.0.4
|
||||
config_version=31
|
||||
project_group=net.momirealms
|
||||
|
||||
|
||||
Reference in New Issue
Block a user