Removed 1.8 R1 support (and updated version id to v2.3.1)

Drastic improvement in library size.
This commit is contained in:
Jitse Boonstra 2019-11-04 10:13:14 +01:00
parent faf4603d80
commit 82ee9522a3
21 changed files with 14 additions and 382 deletions

View File

@ -8,7 +8,7 @@
<parent>
<artifactId>npclib</artifactId>
<groupId>net.jitse</groupId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-api</artifactId>

View File

@ -8,13 +8,12 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms</artifactId>
<modules>
<module>v1_8_R1</module>
<module>v1_8_R2</module>
<module>v1_8_R3</module>
<module>v1_9_R1</module>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_10_R1</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_11_R1</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_12_R1</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_13_R1</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_13_R2</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_14_R1</artifactId>

View File

@ -1,48 +0,0 @@
<?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>
<packaging>jar</packaging>
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</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>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,138 +0,0 @@
/*
* Copyright (c) 2018 Jitse Boonstra
*/
package net.jitse.npclib.nms.v1_8_R1;
import net.jitse.npclib.NPCLib;
import net.jitse.npclib.api.state.NPCSlot;
import net.jitse.npclib.hologram.Hologram;
import net.jitse.npclib.internal.MinecraftVersion;
import net.jitse.npclib.internal.NPCBase;
import net.jitse.npclib.nms.v1_8_R1.packets.*;
import net.minecraft.server.v1_8_R1.*;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
/**
* @author Jitse Boonstra
*/
public class NPC_v1_8_R1 extends NPCBase {
private PacketPlayOutNamedEntitySpawn packetPlayOutNamedEntitySpawn;
private PacketPlayOutScoreboardTeam packetPlayOutScoreboardTeamRegister;
private PacketPlayOutPlayerInfo packetPlayOutPlayerInfoAdd, packetPlayOutPlayerInfoRemove;
private PacketPlayOutEntityHeadRotation packetPlayOutEntityHeadRotation;
private PacketPlayOutEntityDestroy packetPlayOutEntityDestroy;
private Set<UUID> hasTeamRegistered = new HashSet<>();
public NPC_v1_8_R1(NPCLib instance, List<String> lines) {
super(instance, lines);
}
@Override
public void createPackets() {
this.hologram = new Hologram(MinecraftVersion.V1_8_R1, location.clone().add(0, 0.5, 0), text);
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.
}
@Override
public void onLogout(Player player) {
super.onLogout(player);
hasTeamRegistered.remove(player.getUniqueId());
}
@Override
public void sendShowPackets(Player player) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
if (hasTeamRegistered.add(player.getUniqueId()))
playerConnection.sendPacket(packetPlayOutScoreboardTeamRegister);
playerConnection.sendPacket(packetPlayOutPlayerInfoAdd);
playerConnection.sendPacket(packetPlayOutNamedEntitySpawn);
playerConnection.sendPacket(packetPlayOutEntityHeadRotation);
hologram.show(player);
Bukkit.getScheduler().runTaskLater(instance.getPlugin(), () ->
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove), 50);
}
@Override
public void sendHidePackets(Player player) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
playerConnection.sendPacket(packetPlayOutEntityDestroy);
playerConnection.sendPacket(packetPlayOutPlayerInfoRemove);
hologram.hide(player);
}
@Override
public void sendMetadataPacket(Player player) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadataWrapper().create(activeStates, entityId);
playerConnection.sendPacket(packet);
}
@Override
public void sendEquipmentPacket(Player player, NPCSlot slot, boolean auto) {
PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection;
ItemStack item;
switch (slot) {
case HELMET:
item = helmet;
break;
case CHESTPLATE:
item = chestplate;
break;
case LEGGINGS:
item = leggings;
break;
case BOOTS:
item = boots;
break;
case MAINHAND:
item = inHand;
break;
default:
if (!auto) {
throw new IllegalArgumentException(slot.toString() + " is not a supported slot for the version of your server");
}
return;
}
PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, slot.getSlot(), CraftItemStack.asNMSCopy(item));
playerConnection.sendPacket(packet);
}
}

View File

@ -1,26 +0,0 @@
/*
* 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;
}
}

View File

@ -1,16 +0,0 @@
package net.jitse.npclib.nms.v1_8_R1.packets;
import net.jitse.npclib.api.state.NPCState;
import net.minecraft.server.v1_8_R1.DataWatcher;
import net.minecraft.server.v1_8_R1.PacketPlayOutEntityMetadata;
public class PacketPlayOutEntityMetadataWrapper {
public PacketPlayOutEntityMetadata create(NPCState[] activateStates, int entityId) {
DataWatcher dataWatcher = new DataWatcher(null);
byte masked = NPCState.getMasked(activateStates);
dataWatcher.a(0, masked);
return new PacketPlayOutEntityMetadata(entityId, dataWatcher, true);
}
}

View File

@ -1,45 +0,0 @@
/*
* 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;
}
}

View File

@ -1,35 +0,0 @@
/*
* 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;
}
}

View File

@ -1,53 +0,0 @@
/*
* 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;
}
}

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_8_R2</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_8_R3</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_9_R1</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-nms-v1_9_R2</artifactId>

View File

@ -8,7 +8,7 @@
<parent>
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<artifactId>npclib-plugin</artifactId>
@ -26,12 +26,6 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms-v1_8_R1</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.jitse</groupId>
<artifactId>npclib-nms-v1_8_R2</artifactId>

View File

@ -7,7 +7,7 @@
<groupId>net.jitse</groupId>
<artifactId>npclib</artifactId>
<version>2.3-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>