fix client side desync when interacting with allays
This commit is contained in:
parent
7607541583
commit
64d6fc900b
2 changed files with 25 additions and 4 deletions
|
@ -138,7 +138,7 @@ public class ZNpcsPlus {
|
||||||
|
|
||||||
typeRegistry.registerDefault(packetEvents, propertyRegistry);
|
typeRegistry.registerDefault(packetEvents, propertyRegistry);
|
||||||
actionRegistry.registerTypes(scheduler, adventure, textSerializer, bungeeConnector);
|
actionRegistry.registerTypes(scheduler, adventure, textSerializer, bungeeConnector);
|
||||||
packetEvents.getEventManager().registerListener(new InteractionPacketListener(userManager, npcRegistry, scheduler), PacketListenerPriority.MONITOR);
|
packetEvents.getEventManager().registerListener(new InteractionPacketListener(userManager, npcRegistry, typeRegistry, scheduler), PacketListenerPriority.MONITOR);
|
||||||
new Metrics(bootstrap, 18244);
|
new Metrics(bootstrap, 18244);
|
||||||
pluginManager.registerEvents(new UserListener(userManager), bootstrap);
|
pluginManager.registerEvents(new UserListener(userManager), bootstrap);
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,39 @@
|
||||||
package lol.pyr.znpcsplus.interaction;
|
package lol.pyr.znpcsplus.interaction;
|
||||||
|
|
||||||
|
import com.github.retrooper.packetevents.PacketEvents;
|
||||||
import com.github.retrooper.packetevents.event.PacketListener;
|
import com.github.retrooper.packetevents.event.PacketListener;
|
||||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||||
|
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||||
|
import com.github.retrooper.packetevents.protocol.player.Equipment;
|
||||||
|
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
|
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
|
||||||
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEquipment;
|
||||||
import lol.pyr.znpcsplus.api.event.NpcInteractEvent;
|
import lol.pyr.znpcsplus.api.event.NpcInteractEvent;
|
||||||
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
|
import lol.pyr.znpcsplus.api.interaction.InteractionAction;
|
||||||
import lol.pyr.znpcsplus.api.interaction.InteractionType;
|
import lol.pyr.znpcsplus.api.interaction.InteractionType;
|
||||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||||
import lol.pyr.znpcsplus.npc.NpcImpl;
|
import lol.pyr.znpcsplus.npc.NpcImpl;
|
||||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||||
|
import lol.pyr.znpcsplus.npc.NpcTypeRegistryImpl;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
import lol.pyr.znpcsplus.user.User;
|
import lol.pyr.znpcsplus.user.User;
|
||||||
import lol.pyr.znpcsplus.user.UserManager;
|
import lol.pyr.znpcsplus.user.UserManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class InteractionPacketListener implements PacketListener {
|
public class InteractionPacketListener implements PacketListener {
|
||||||
private final UserManager userManager;
|
private final UserManager userManager;
|
||||||
private final NpcRegistryImpl npcRegistry;
|
private final NpcRegistryImpl npcRegistry;
|
||||||
|
private final NpcTypeRegistryImpl typeRegistry;
|
||||||
private final TaskScheduler scheduler;
|
private final TaskScheduler scheduler;
|
||||||
|
|
||||||
public InteractionPacketListener(UserManager userManager, NpcRegistryImpl npcRegistry, TaskScheduler scheduler) {
|
public InteractionPacketListener(UserManager userManager, NpcRegistryImpl npcRegistry, NpcTypeRegistryImpl typeRegistry, TaskScheduler scheduler) {
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
this.npcRegistry = npcRegistry;
|
this.npcRegistry = npcRegistry;
|
||||||
|
this.typeRegistry = typeRegistry;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,14 +44,25 @@ public class InteractionPacketListener implements PacketListener {
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
|
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
|
||||||
User user = userManager.get(player);
|
|
||||||
if (!user.canInteract()) return;
|
|
||||||
|
|
||||||
NpcEntryImpl entry = npcRegistry.getByEntityId(packet.getEntityId());
|
NpcEntryImpl entry = npcRegistry.getByEntityId(packet.getEntityId());
|
||||||
if (entry == null || !entry.isProcessed()) return;
|
if (entry == null || !entry.isProcessed()) return;
|
||||||
NpcImpl npc = entry.getNpc();
|
NpcImpl npc = entry.getNpc();
|
||||||
|
|
||||||
|
if ((packet.getAction().equals(WrapperPlayClientInteractEntity.InteractAction.INTERACT)
|
||||||
|
|| packet.getAction().equals(WrapperPlayClientInteractEntity.InteractAction.INTERACT_AT))
|
||||||
|
&& npc.getType().equals(typeRegistry.getByName("allay"))) {
|
||||||
|
PacketEvents.getAPI().getPlayerManager().sendPacket(player,
|
||||||
|
new WrapperPlayServerEntityEquipment(packet.getEntityId(), Collections.singletonList(
|
||||||
|
new Equipment(EquipmentSlot.MAIN_HAND, ItemStack.EMPTY))));
|
||||||
|
player.updateInventory();
|
||||||
|
}
|
||||||
|
|
||||||
InteractionType type = wrapClickType(packet.getAction());
|
InteractionType type = wrapClickType(packet.getAction());
|
||||||
|
|
||||||
|
User user = userManager.get(player);
|
||||||
|
if (!user.canInteract()) return;
|
||||||
|
|
||||||
NpcInteractEvent interactEvent = new NpcInteractEvent(player, entry, type);
|
NpcInteractEvent interactEvent = new NpcInteractEvent(player, entry, type);
|
||||||
Bukkit.getPluginManager().callEvent(interactEvent);
|
Bukkit.getPluginManager().callEvent(interactEvent);
|
||||||
if (interactEvent.isCancelled()) return;
|
if (interactEvent.isCancelled()) return;
|
||||||
|
|
Loading…
Reference in a new issue