Revert "Unpushed work."

This reverts commit ddf90fe005.
This commit is contained in:
Jitse Boonstra
2018-12-14 14:44:37 +01:00
parent ddf90fe005
commit d741db78de
67 changed files with 105 additions and 1719 deletions
@@ -4,6 +4,8 @@
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;
@@ -37,6 +39,7 @@ 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) {
@@ -48,6 +51,17 @@ 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,6 +4,9 @@
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;
@@ -11,9 +14,6 @@ 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,75 +35,38 @@ public class PacketListener {
private final Set<UUID> delay = new HashSet<>();
public void start(JavaPlugin plugin) {
String versionName = plugin.getServer().getClass().getPackage().getName().split("\\.")[3];
if (versionName.equals("v1_7_R4")) {
new LegacyTinyProtocol(plugin) {
new TinyProtocol(plugin) {
@Override
public Object onPacketInAsync(Player player, net.minecraft.util.io.netty.channel.Channel channel, Object packet) {
@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 (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())) {
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));
if (delay.contains(player.getUniqueId())) {
return null;
}
return super.onPacketInAsync(player, channel, packet);
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;
}
};
} else {
new TinyProtocol(plugin) {
@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);
}
};
}
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;