Add Maven !

This commit is contained in:
MrMicky
2018-04-26 13:52:49 +02:00
parent f74d57962a
commit c9a58ccd48
72 changed files with 4557 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>1.0.4</version>
</parent>
<artifactId>npclib-nms-v1_8_R1</artifactId>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.nms.v1_8_R1;
import net.jitse.npclib.api.NPC;
import net.jitse.npclib.nms.holograms.Hologram;
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutEntityHeadRotationWrapper;
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutNamedEntitySpawnWrapper;
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutPlayerInfoWrapper;
import net.jitse.npclib.nms.v1_8_R1.packets.PacketPlayOutScoreboardTeamWrapper;
import net.jitse.npclib.skin.Skin;
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
/**
* @author Jitse Boonstra
*/
public class NPC_v1_8_R1 extends NPC {
private Hologram hologram;
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister, packetPlayOutScoreboardTeamUnregister;
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
public NPC_v1_8_R1(JavaPlugin plugin, Skin skin, double autoHideDistance, List<String> lines) {
super(plugin, skin, autoHideDistance, lines);
}
@Override
public void create(Location location) {
this.location = location;
this.hologram = new Hologram(location.clone().add(0, 0.5, 0), lines);
hologram.generatePackets(false);
this.gameProfile = generateGameProfile(uuid, name);
PacketPlayOutPlayerInfoWrapper packetPlayOutPlayerInfoWrapper = new PacketPlayOutPlayerInfoWrapper();
// Packets for spawning the NPC:
this.packetPlayOutScoreboardTeamRegister = new PacketPlayOutScoreboardTeamWrapper()
.createRegisterTeam(name); // First packet to send.
this.packetPlayOutPlayerInfoAdd = packetPlayOutPlayerInfoWrapper
.create(EnumPlayerInfoAction.ADD_PLAYER, gameProfile, name); // Second packet to send.
this.packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawnWrapper()
.create(uuid, location, entityId); // Third packet to send.
this.packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotationWrapper()
.create(location, entityId); // Fourth packet to send.
this.packetPlayOutPlayerInfoRemove = packetPlayOutPlayerInfoWrapper
.create(EnumPlayerInfoAction.REMOVE_PLAYER, gameProfile, name); // Fifth packet to send (delayed).
// Packet for destroying the NPC:
this.packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityId); // First packet to send.
// Second packet to send is "packetPlayOutPlayerInfoRemove".
this.packetPlayOutScoreboardTeamUnregister = new PacketPlayOutScoreboardTeamWrapper()
.createUnregisterTeam(name); // Third packet to send.
}
@Override
public void sendShowPackets(Player player) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutScoreboardTeamRegister);
playerConnection.sendPacket(packetPlayOutPlayerInfoAdd);
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
playerConnection.sendPacket(packetPlayOutEntityHeadRotation);
hologram.spawn(player);
Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 5);
}
@Override
public void sendHidePackets(Player player) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy);
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove);
hologram.destroy(player);
// Sending this a bit later so the player doesn't see the name (for that split second).
Bukkit.getScheduler().runTaskLater(plugin, () ->
playerConnection.sendPacket(packetPlayOutScoreboardTeamUnregister), 5);
}
}
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.nms.v1_8_R1.packets;
import com.comphenix.tinyprotocol.Reflection;
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityHeadRotation;
import org.bukkit.Location;
/**
* @author Jitse Boonstra
*/
public class PacketPlayOutEntityHeadRotationWrapper {
public PacketPlayOutEntityHeadRotation create(Location location, int entityId) {
PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation = new PacketPlayOutEntityHeadRotation();
Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "a", int.class).
set(packetPlayOutEntityHeadRotation, entityId);
Reflection.getField(packetPlayOutEntityHeadRotation.getClass(), "b", byte.class)
.set(packetPlayOutEntityHeadRotation, (byte) ((int) location.getYaw() * 256.0F / 360.0F));
return packetPlayOutEntityHeadRotation;
}
}
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.nms.v1_8_R1.packets;
import com.comphenix.tinyprotocol.Reflection;
import net.minecraft.server.v1_8_R1.DataWatcher;
import net.minecraft.server.v1_8_R1.PacketPlayOutNamedEntitySpawn;
import org.bukkit.Location;
import java.util.UUID;
/**
* @author Jitse Boonstra
*/
public class PacketPlayOutNamedEntitySpawnWrapper {
public PacketPlayOutNamedEntitySpawn create(UUID uuid, Location location, int entityId) {
PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn = new PacketPlayOutNamedEntitySpawn();
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "a", int.class)
.set(packetPlayOutNamedEntitySpawn, entityId);
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "b", UUID.class)
.set(packetPlayOutNamedEntitySpawn, uuid);
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "c", int.class)
.set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getX() * 32.0D));
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "d", int.class)
.set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getY() * 32.0D));
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "e", int.class)
.set(packetPlayOutNamedEntitySpawn, (int) Math.floor(location.getZ() * 32.0D));
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "f", byte.class)
.set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getYaw() * 256.0F / 360.0F)));
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "g", byte.class)
.set(packetPlayOutNamedEntitySpawn, (byte) ((int) (location.getPitch() * 256.0F / 360.0F)));
DataWatcher dataWatcher = new DataWatcher(null);
dataWatcher.a(10, (byte) 127);
Reflection.getField(packetPlayOutNamedEntitySpawn.getClass(), "i", DataWatcher.class)
.set(packetPlayOutNamedEntitySpawn, dataWatcher);
return packetPlayOutNamedEntitySpawn;
}
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.nms.v1_8_R1.packets;
import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.v1_8_R1.*;
import java.util.List;
/**
* @author Jitse Boonstra
*/
public class PacketPlayOutPlayerInfoWrapper {
public PacketPlayOutPlayerInfo create(EnumPlayerInfoAction action, GameProfile gameProfile, String name) {
PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = new PacketPlayOutPlayerInfo();
Reflection.getField(packetPlayOutPlayerInfo.getClass(), "a", EnumPlayerInfoAction.class)
.set(packetPlayOutPlayerInfo, action);
PlayerInfoData playerInfoData = new PlayerInfoData(packetPlayOutPlayerInfo, gameProfile,
1, EnumGamemode.NOT_SET, ChatSerializer.a(name));
Reflection.FieldAccessor<List> fieldAccessor = Reflection.getField(packetPlayOutPlayerInfo.getClass(),
"b", List.class);
List<PlayerInfoData> list = fieldAccessor.get(packetPlayOutPlayerInfo);
list.add(playerInfoData);
fieldAccessor.set(packetPlayOutPlayerInfo, list);
return packetPlayOutPlayerInfo;
}
}
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.nms.v1_8_R1.packets;
import com.comphenix.tinyprotocol.Reflection;
import net.minecraft.server.v1_8_R1.PacketPlayOutScoreboardTeam;
import org.bukkit.ChatColor;
import java.util.Collection;
/**
* @author Jitse Boonstra
*/
public class PacketPlayOutScoreboardTeamWrapper {
public PacketPlayOutScoreboardTeam createRegisterTeam(String name) {
PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam();
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "h", int.class)
.set(packetPlayOutScoreboardTeam, 0);
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "b", String.class)
.set(packetPlayOutScoreboardTeam, name);
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class)
.set(packetPlayOutScoreboardTeam, name);
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "e", String.class)
.set(packetPlayOutScoreboardTeam, "never");
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "i", int.class)
.set(packetPlayOutScoreboardTeam, 1);
// Could not get this working in the PacketPlayOutPlayerInfoWrapper class.
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "c", String.class)
.set(packetPlayOutScoreboardTeam, ChatColor.BLUE + "[NPC] ");
Reflection.FieldAccessor<Collection> collectionFieldAccessor = Reflection.getField(
packetPlayOutScoreboardTeam.getClass(), "g", Collection.class);
Collection collection = collectionFieldAccessor.get(packetPlayOutScoreboardTeam);
collection.add(name);
collectionFieldAccessor.set(packetPlayOutScoreboardTeam, collection);
return packetPlayOutScoreboardTeam;
}
public PacketPlayOutScoreboardTeam createUnregisterTeam(String name) {
PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeam = new PacketPlayOutScoreboardTeam();
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "h", int.class)
.set(packetPlayOutScoreboardTeam, 1);
Reflection.getField(packetPlayOutScoreboardTeam.getClass(), "a", String.class)
.set(packetPlayOutScoreboardTeam, name);
return packetPlayOutScoreboardTeam;
}
}