Unpushed work.
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
|
||||
package net.jitse.npclib.api;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.events.NPCDestroyEvent;
|
||||
import net.jitse.npclib.events.NPCSpawnEvent;
|
||||
@@ -39,7 +37,6 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||
protected final List<String> lines;
|
||||
|
||||
protected JavaPlugin plugin;
|
||||
protected GameProfile gameProfile;
|
||||
protected Location location;
|
||||
|
||||
public NPC(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
|
||||
@@ -51,17 +48,6 @@ public abstract class NPC implements PacketHandler, ActionHandler {
|
||||
NPCManager.add(this);
|
||||
}
|
||||
|
||||
protected GameProfile generateGameProfile(UUID uuid, String name) {
|
||||
GameProfile gameProfile = new GameProfile(uuid, name);
|
||||
|
||||
if (skin != null) {
|
||||
gameProfile.getProperties().put("textures", new Property("textures", skin.getValue(), skin.getSignature()));
|
||||
}
|
||||
|
||||
return gameProfile;
|
||||
}
|
||||
|
||||
|
||||
public void destroy() {
|
||||
destroy(true);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
package net.jitse.npclib.listeners;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import io.netty.channel.Channel;
|
||||
import net.jitse.npclib.NPCManager;
|
||||
import net.jitse.npclib.api.NPC;
|
||||
import net.jitse.npclib.events.NPCInteractEvent;
|
||||
@@ -14,6 +11,9 @@ import net.jitse.npclib.events.click.ClickType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import tinyprotocol.LegacyTinyProtocol;
|
||||
import tinyprotocol.Reflection;
|
||||
import tinyprotocol.TinyProtocol;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -35,38 +35,75 @@ public class PacketListener {
|
||||
private final Set<UUID> delay = new HashSet<>();
|
||||
|
||||
public void start(JavaPlugin plugin) {
|
||||
new TinyProtocol(plugin) {
|
||||
String versionName = plugin.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
if (versionName.equals("v1_7_R4")) {
|
||||
new LegacyTinyProtocol(plugin) {
|
||||
|
||||
@Override
|
||||
public Object onPacketInAsync(Player player, Channel channel, Object packet) {
|
||||
@Override
|
||||
public Object onPacketInAsync(Player player, net.minecraft.util.io.netty.channel.Channel channel, Object packet) {
|
||||
|
||||
if (packetPlayInUseEntityClazz.isInstance(packet)) {
|
||||
NPC npc = NPCManager.getAllNPCs().stream().filter(
|
||||
check -> check.isActuallyShown(player) && check.getEntityId() == (int) entityIdField.get(packet))
|
||||
.findFirst().orElse(null);
|
||||
if (packetPlayInUseEntityClazz.isInstance(packet)) {
|
||||
NPC npc = NPCManager.getAllNPCs().stream().filter(
|
||||
check -> check.isActuallyShown(player) && check.getEntityId() == (int) entityIdField.get(packet))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if (npc == null) {
|
||||
// Default player, not doing magic with the packet.
|
||||
return super.onPacketInAsync(player, channel, packet);
|
||||
}
|
||||
if (npc == null) {
|
||||
// Default player, not doing magic with the packet.
|
||||
return super.onPacketInAsync(player, channel, packet);
|
||||
}
|
||||
|
||||
if (delay.contains(player.getUniqueId())) {
|
||||
if (delay.contains(player.getUniqueId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClickType clickType = actionField.get(packet).toString()
|
||||
.equals("ATTACK") ? ClickType.LEFT_CLICK : ClickType.RIGHT_CLICK;
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new NPCInteractEvent(player, clickType, npc));
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
delay.add(uuid);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> delay.remove(uuid));
|
||||
return null;
|
||||
}
|
||||
|
||||
ClickType clickType = actionField.get(packet).toString()
|
||||
.equals("ATTACK") ? ClickType.LEFT_CLICK : ClickType.RIGHT_CLICK;
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new NPCInteractEvent(player, clickType, npc));
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
delay.add(uuid);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> delay.remove(uuid));
|
||||
return null;
|
||||
return super.onPacketInAsync(player, channel, packet);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
new TinyProtocol(plugin) {
|
||||
|
||||
return super.onPacketInAsync(player, channel, packet);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public Object onPacketInAsync(Player player, io.netty.channel.Channel channel, Object packet) {
|
||||
|
||||
if (packetPlayInUseEntityClazz.isInstance(packet)) {
|
||||
NPC npc = NPCManager.getAllNPCs().stream().filter(
|
||||
check -> check.isActuallyShown(player) && check.getEntityId() == (int) entityIdField.get(packet))
|
||||
.findFirst().orElse(null);
|
||||
|
||||
if (npc == null) {
|
||||
// Default player, not doing magic with the packet.
|
||||
return super.onPacketInAsync(player, channel, packet);
|
||||
}
|
||||
|
||||
if (delay.contains(player.getUniqueId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClickType clickType = actionField.get(packet).toString()
|
||||
.equals("ATTACK") ? ClickType.LEFT_CLICK : ClickType.RIGHT_CLICK;
|
||||
|
||||
Bukkit.getPluginManager().callEvent(new NPCInteractEvent(player, clickType, npc));
|
||||
|
||||
UUID uuid = player.getUniqueId();
|
||||
delay.add(uuid);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> delay.remove(uuid));
|
||||
return null;
|
||||
}
|
||||
|
||||
return super.onPacketInAsync(player, channel, packet);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
package net.jitse.npclib.nms.holograms;
|
||||
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import tinyprotocol.Reflection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
Reference in New Issue
Block a user