Made NPCs spawn for 1.7.10 (1.7 R4) (#10).
Disabled TinyProtocol to work on some other things first.
This commit is contained in:
@@ -25,11 +25,11 @@ import java.util.*;
|
||||
public abstract class NPC implements PacketHandler, ActionHandler {
|
||||
|
||||
protected final UUID uuid = UUID.randomUUID();
|
||||
protected final String name = uuid.toString().replace("-", "").substring(0, 10);
|
||||
// Below was previously = (int) Math.ceil(Math.random() * 100000) + 100000 (new is experimental).
|
||||
protected final int entityId = Integer.MAX_VALUE - NPCManager.getAllNPCs().size();
|
||||
|
||||
protected double cosFOV = Math.cos(Math.toRadians(60));
|
||||
protected String name = uuid.toString().replace("-", "").substring(0, 10);
|
||||
|
||||
private final Set<UUID> shown = new HashSet<>();
|
||||
private final Set<UUID> autoHidden = new HashSet<>();
|
||||
|
||||
@@ -5,14 +5,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;
|
||||
import net.jitse.npclib.events.click.ClickType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -35,38 +27,38 @@ public class PacketListener {
|
||||
private final Set<UUID> delay = new HashSet<>();
|
||||
|
||||
public void start(JavaPlugin plugin) {
|
||||
new TinyProtocol(plugin) {
|
||||
|
||||
@Override
|
||||
public Object onPacketInAsync(Player player, 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);
|
||||
}
|
||||
};
|
||||
// new TinyProtocol(plugin) {
|
||||
//
|
||||
// @Override
|
||||
// public Object onPacketInAsync(Player player, 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);
|
||||
// }
|
||||
// };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user