mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-23 08:59:18 +00:00
feat: remove 1.20.1 and 1.20.2 support; bump api
This commit is contained in:
@@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "me.lojosho"
|
group = "me.lojosho"
|
||||||
version = "0.5.4${getGitCommitHash()}"
|
version = "0.5.5${getGitCommitHash()}"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
@@ -78,10 +78,10 @@ allprojects {
|
|||||||
// Included externally
|
// Included externally
|
||||||
compileOnly("com.mojang:authlib:1.5.25")
|
compileOnly("com.mojang:authlib:1.5.25")
|
||||||
//compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT")
|
//compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT")
|
||||||
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||||
compileOnly("org.jetbrains:annotations:26.0.1")
|
compileOnly("org.jetbrains:annotations:26.0.1")
|
||||||
compileOnly("io.th0rgal:oraxen:1.182.0")
|
compileOnly("io.th0rgal:oraxen:1.182.0")
|
||||||
compileOnly("com.nexomc:nexo:0.1.0-dev.0")
|
compileOnly("com.nexomc:nexo:0.8.0-dev.8")
|
||||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14")
|
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14")
|
||||||
compileOnly("com.mineinabyss:geary-papermc:0.31.0-dev.4")
|
compileOnly("com.mineinabyss:geary-papermc:0.31.0-dev.4")
|
||||||
compileOnly("it.unimi.dsi:fastutil:8.5.13")
|
compileOnly("it.unimi.dsi:fastutil:8.5.13")
|
||||||
@@ -120,8 +120,6 @@ allprojects {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(path = ":common"))
|
implementation(project(path = ":common"))
|
||||||
implementation(project(path = ":v1_20_R1", configuration = "reobf"))
|
|
||||||
implementation(project(path = ":v1_20_R2", configuration = "reobf"))
|
|
||||||
implementation(project(path = ":v1_20_R3", configuration = "reobf"))
|
implementation(project(path = ":v1_20_R3", configuration = "reobf"))
|
||||||
implementation(project(path = ":v1_20_R4", configuration = "reobf"))
|
implementation(project(path = ":v1_20_R4", configuration = "reobf"))
|
||||||
implementation(project(path = ":v1_21_R1", configuration = "reobf"))
|
implementation(project(path = ":v1_21_R1", configuration = "reobf"))
|
||||||
@@ -157,8 +155,6 @@ tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
dependsOn(":v1_20_R1:reobfJar")
|
|
||||||
dependsOn(":v1_20_R2:reobfJar")
|
|
||||||
dependsOn(":v1_20_R3:reobfJar")
|
dependsOn(":v1_20_R3:reobfJar")
|
||||||
dependsOn(":v1_20_R4:reobfJar")
|
dependsOn(":v1_20_R4:reobfJar")
|
||||||
dependsOn(":v1_21_R1:reobfJar")
|
dependsOn(":v1_21_R1:reobfJar")
|
||||||
|
|||||||
@@ -10,12 +10,10 @@ import java.util.LinkedHashMap;
|
|||||||
public class NMSHandlers {
|
public class NMSHandlers {
|
||||||
|
|
||||||
private static final LinkedHashMap<String, String> VERSION_MAP = new LinkedHashMap <>() {{
|
private static final LinkedHashMap<String, String> VERSION_MAP = new LinkedHashMap <>() {{
|
||||||
put("1.20.1", "v1_20_R1");
|
|
||||||
put("1.20.2", "v1_20_R2");
|
|
||||||
put("1.20.4", "v1_20_R3");
|
put("1.20.4", "v1_20_R3");
|
||||||
// 1.20.5 is not supported; was imminently bumped to 1.20.6
|
// 1.20.5 is not supported; was imminently bumped to 1.20.6
|
||||||
put("1.20.6", "v1_20_R4");
|
put("1.20.6", "v1_20_R4");
|
||||||
put("1.21", "v1_21_R1");
|
// 1.20 is not supported; was imminently bumped to 1.21.1
|
||||||
put("1.21.1", "v1_21_R1");
|
put("1.21.1", "v1_21_R1");
|
||||||
// 1.20.2 is not supported; was imminently bumped to 1.21.3
|
// 1.20.2 is not supported; was imminently bumped to 1.21.3
|
||||||
put("1.21.3", "v1_21_R2");
|
put("1.21.3", "v1_21_R2");
|
||||||
|
|||||||
@@ -12,8 +12,6 @@ pluginManagement {
|
|||||||
rootProject.name = "HibiscusCommons"
|
rootProject.name = "HibiscusCommons"
|
||||||
include(
|
include(
|
||||||
"common",
|
"common",
|
||||||
"v1_20_R1",
|
|
||||||
"v1_20_R2",
|
|
||||||
"v1_20_R3",
|
"v1_20_R3",
|
||||||
"v1_20_R4",
|
"v1_20_R4",
|
||||||
"v1_21_R1",
|
"v1_21_R1",
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("java")
|
|
||||||
id("io.papermc.paperweight.userdev")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT")
|
|
||||||
pluginRemapper("net.fabricmc:tiny-remapper:0.10.4:fat")
|
|
||||||
implementation(project(":common"))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
|
|
||||||
build {
|
|
||||||
dependsOn(reobfJar)
|
|
||||||
}
|
|
||||||
|
|
||||||
compileJava {
|
|
||||||
options.encoding = Charsets.UTF_8.name()
|
|
||||||
options.release.set(21)
|
|
||||||
}
|
|
||||||
javadoc {
|
|
||||||
options.encoding = Charsets.UTF_8.name()
|
|
||||||
}
|
|
||||||
processResources {
|
|
||||||
filteringCharset = Charsets.UTF_8.name()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R1;
|
|
||||||
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerConnection;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class NMSCommon {
|
|
||||||
|
|
||||||
public void sendPacket(Player player, Packet packet) {
|
|
||||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
ServerPlayerConnection connection = serverPlayer.connection;
|
|
||||||
connection.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R1;
|
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.network.protocol.game.*;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
|
||||||
import net.minecraft.world.scores.PlayerTeam;
|
|
||||||
import net.minecraft.world.scores.Team;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftEquipmentSlot;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.scoreboard.CraftScoreboard;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
|
||||||
|
|
||||||
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
|
||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
|
||||||
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
passengerConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
linkConstructor = ClientboundSetEntityLinkPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
linkConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
teleportConstructor = ClientboundTeleportEntityPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
teleportConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
cameraConstructor = ClientboundSetCameraPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
cameraConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
lookAtConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendEquipmentSlotUpdate(
|
|
||||||
int entityId,
|
|
||||||
org.bukkit.inventory.EquipmentSlot slot,
|
|
||||||
ItemStack item,
|
|
||||||
List<Player> sendTo
|
|
||||||
) {
|
|
||||||
|
|
||||||
EquipmentSlot nmsSlot = null;
|
|
||||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
|
||||||
|
|
||||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
|
||||||
nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
|
||||||
nmsItem = CraftItemStack.asNMSCopy(item);
|
|
||||||
|
|
||||||
if (nmsSlot == null) return;
|
|
||||||
|
|
||||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
|
||||||
|
|
||||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
|
||||||
|
|
||||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendEquipmentSlotUpdate(
|
|
||||||
int entityId,
|
|
||||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
|
||||||
List<Player> sendTo
|
|
||||||
) {
|
|
||||||
|
|
||||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = new ArrayList<>();
|
|
||||||
|
|
||||||
for (org.bukkit.inventory.EquipmentSlot slot : equipment.keySet()) {
|
|
||||||
EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
|
||||||
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(equipment.get(slot));
|
|
||||||
|
|
||||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
|
||||||
pairs.add(pair);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendSlotUpdate(
|
|
||||||
Player player,
|
|
||||||
int slot
|
|
||||||
) {
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
ServerPlayer player1 = ((CraftPlayer) player).getHandle();
|
|
||||||
|
|
||||||
if (index < Inventory.getSelectionSize()) {
|
|
||||||
index += 36;
|
|
||||||
} else if (index > 39) {
|
|
||||||
index += 5; // Off hand
|
|
||||||
} else if (index > 35) {
|
|
||||||
index = 8 - (index - 36);
|
|
||||||
}
|
|
||||||
ItemStack item = player.getInventory().getItem(slot);
|
|
||||||
|
|
||||||
Packet packet = new ClientboundContainerSetSlotPacket(player1.inventoryMenu.containerId, player1.inventoryMenu.incrementStateId(), index, CraftItemStack.asNMSCopy(item));
|
|
||||||
sendPacket(player, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
|
||||||
//Creating the team
|
|
||||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
|
||||||
|
|
||||||
//Setting name visibility
|
|
||||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
|
||||||
|
|
||||||
//Remove the Team (i assume so if it exists)
|
|
||||||
ClientboundSetPlayerTeamPacket removeTeamPacket = ClientboundSetPlayerTeamPacket.createRemovePacket(team);
|
|
||||||
sendPacket(player, removeTeamPacket);
|
|
||||||
//Creating the Team
|
|
||||||
ClientboundSetPlayerTeamPacket createTeamPacket = ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true);
|
|
||||||
sendPacket(player, createTeamPacket);
|
|
||||||
//Adding players to the team (You have to use the NPC's name, and add it to a list)
|
|
||||||
ClientboundSetPlayerTeamPacket createPlayerTeamPacket = ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(team, new ArrayList<String>() {{
|
|
||||||
add(name);
|
|
||||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
|
||||||
sendPacket(player, createPlayerTeamPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMountPacket(int mountId, int[] passengerIds, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(mountId);
|
|
||||||
byteBuf.writeVarIntArray(passengerIds);
|
|
||||||
try {
|
|
||||||
ClientboundSetPassengersPacket packet = passengerConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendLeashPacket(int leashEntity, int entityId, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeInt(leashEntity);
|
|
||||||
byteBuf.writeInt(entityId);
|
|
||||||
try {
|
|
||||||
ClientboundSetEntityLinkPacket packet = linkConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTeleportPacket(
|
|
||||||
int entityId,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
double z,
|
|
||||||
float yaw,
|
|
||||||
float pitch,
|
|
||||||
boolean onGround,
|
|
||||||
List<Player> sendTo
|
|
||||||
) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeDouble(x);
|
|
||||||
byteBuf.writeDouble(y);
|
|
||||||
byteBuf.writeDouble(z);
|
|
||||||
byteBuf.writeByte((byte) (yaw * 256.0F / 360.0F));
|
|
||||||
byteBuf.writeByte((byte) (pitch * 256.0F / 360.0F));
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ClientboundTeleportEntityPacket packet = teleportConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
try {
|
|
||||||
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R1;
|
|
||||||
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.world.scores.PlayerTeam;
|
|
||||||
import net.minecraft.world.scores.Team;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.scoreboard.CraftScoreboard;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class NMSUtils extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSUtils {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextEntityId() {
|
|
||||||
return net.minecraft.world.entity.Entity.nextEntityId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public org.bukkit.entity.Entity getEntity(int entityId) {
|
|
||||||
net.minecraft.world.entity.Entity entity = getNMSEntity(entityId);
|
|
||||||
if (entity == null) return null;
|
|
||||||
return entity.getBukkitEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
|
||||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
|
||||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
|
||||||
if (entity == null) continue;
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id("java")
|
|
||||||
id("io.papermc.paperweight.userdev")
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
|
|
||||||
implementation(project(":common"))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
|
|
||||||
build {
|
|
||||||
dependsOn(reobfJar)
|
|
||||||
}
|
|
||||||
|
|
||||||
compileJava {
|
|
||||||
options.encoding = Charsets.UTF_8.name()
|
|
||||||
options.release.set(21)
|
|
||||||
}
|
|
||||||
javadoc {
|
|
||||||
options.encoding = Charsets.UTF_8.name()
|
|
||||||
}
|
|
||||||
processResources {
|
|
||||||
filteringCharset = Charsets.UTF_8.name()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R2;
|
|
||||||
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.server.network.ServerPlayerConnection;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class NMSCommon {
|
|
||||||
|
|
||||||
public void sendPacket(Player player, Packet packet) {
|
|
||||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
|
||||||
ServerPlayerConnection connection = serverPlayer.connection;
|
|
||||||
connection.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R2;
|
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.network.protocol.game.*;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
|
||||||
import net.minecraft.world.scores.PlayerTeam;
|
|
||||||
import net.minecraft.world.scores.Team;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftEquipmentSlot;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.scoreboard.CraftScoreboard;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
|
||||||
|
|
||||||
static Constructor<ClientboundSetPassengersPacket> passengerConstructor;
|
|
||||||
static Constructor<ClientboundSetEntityLinkPacket> linkConstructor;
|
|
||||||
static Constructor<ClientboundTeleportEntityPacket> teleportConstructor;
|
|
||||||
static Constructor<ClientboundSetCameraPacket> cameraConstructor;
|
|
||||||
static Constructor<ClientboundPlayerLookAtPacket> lookAtConstructor;
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
passengerConstructor = ClientboundSetPassengersPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
passengerConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
linkConstructor = ClientboundSetEntityLinkPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
linkConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
teleportConstructor = ClientboundTeleportEntityPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
teleportConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
cameraConstructor = ClientboundSetCameraPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
cameraConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
lookAtConstructor = ClientboundPlayerLookAtPacket.class.getDeclaredConstructor(FriendlyByteBuf.class);
|
|
||||||
lookAtConstructor.setAccessible(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendEquipmentSlotUpdate(
|
|
||||||
int entityId,
|
|
||||||
org.bukkit.inventory.EquipmentSlot slot,
|
|
||||||
ItemStack item,
|
|
||||||
List<Player> sendTo
|
|
||||||
) {
|
|
||||||
|
|
||||||
EquipmentSlot nmsSlot = null;
|
|
||||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
|
||||||
|
|
||||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
|
||||||
nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
|
||||||
nmsItem = CraftItemStack.asNMSCopy(item);
|
|
||||||
|
|
||||||
if (nmsSlot == null) return;
|
|
||||||
|
|
||||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
|
||||||
|
|
||||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
|
||||||
|
|
||||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendEquipmentSlotUpdate(
|
|
||||||
int entityId,
|
|
||||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
|
||||||
List<Player> sendTo
|
|
||||||
) {
|
|
||||||
|
|
||||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = new ArrayList<>();
|
|
||||||
|
|
||||||
for (org.bukkit.inventory.EquipmentSlot slot : equipment.keySet()) {
|
|
||||||
EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
|
||||||
net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.asNMSCopy(equipment.get(slot));
|
|
||||||
|
|
||||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
|
||||||
pairs.add(pair);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendSlotUpdate(
|
|
||||||
Player player,
|
|
||||||
int slot
|
|
||||||
) {
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
ServerPlayer player1 = ((CraftPlayer) player).getHandle();
|
|
||||||
|
|
||||||
if (index < Inventory.getSelectionSize()) {
|
|
||||||
index += 36;
|
|
||||||
} else if (index > 39) {
|
|
||||||
index += 5; // Off hand
|
|
||||||
} else if (index > 35) {
|
|
||||||
index = 8 - (index - 36);
|
|
||||||
}
|
|
||||||
ItemStack item = player.getInventory().getItem(slot);
|
|
||||||
|
|
||||||
Packet packet = new ClientboundContainerSetSlotPacket(player1.inventoryMenu.containerId, player1.inventoryMenu.incrementStateId(), index, CraftItemStack.asNMSCopy(item));
|
|
||||||
sendPacket(player, packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
|
||||||
//Creating the team
|
|
||||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
|
||||||
|
|
||||||
//Setting name visibility
|
|
||||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
|
||||||
|
|
||||||
//Remove the Team (i assume so if it exists)
|
|
||||||
ClientboundSetPlayerTeamPacket removeTeamPacket = ClientboundSetPlayerTeamPacket.createRemovePacket(team);
|
|
||||||
sendPacket(player, removeTeamPacket);
|
|
||||||
//Creating the Team
|
|
||||||
ClientboundSetPlayerTeamPacket createTeamPacket = ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true);
|
|
||||||
sendPacket(player, createTeamPacket);
|
|
||||||
//Adding players to the team (You have to use the NPC's name, and add it to a list)
|
|
||||||
ClientboundSetPlayerTeamPacket createPlayerTeamPacket = ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(team, new ArrayList<String>() {{
|
|
||||||
add(name);
|
|
||||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
|
||||||
sendPacket(player, createPlayerTeamPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMountPacket(int mountId, int[] passengerIds, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(mountId);
|
|
||||||
byteBuf.writeVarIntArray(passengerIds);
|
|
||||||
try {
|
|
||||||
ClientboundSetPassengersPacket packet = passengerConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendLeashPacket(int leashEntity, int entityId, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeInt(leashEntity);
|
|
||||||
byteBuf.writeInt(entityId);
|
|
||||||
try {
|
|
||||||
ClientboundSetEntityLinkPacket packet = linkConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendTeleportPacket(
|
|
||||||
int entityId,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
double z,
|
|
||||||
float yaw,
|
|
||||||
float pitch,
|
|
||||||
boolean onGround,
|
|
||||||
List<Player> sendTo
|
|
||||||
) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeDouble(x);
|
|
||||||
byteBuf.writeDouble(y);
|
|
||||||
byteBuf.writeDouble(z);
|
|
||||||
byteBuf.writeByte((byte) (yaw * 256.0F / 360.0F));
|
|
||||||
byteBuf.writeByte((byte) (pitch * 256.0F / 360.0F));
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
|
|
||||||
try {
|
|
||||||
ClientboundTeleportEntityPacket packet = teleportConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendRotationPacket(int entityId, float yaw, boolean onGround, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
byteBuf.writeFloat(yaw);
|
|
||||||
byteBuf.writeBoolean(onGround);
|
|
||||||
try {
|
|
||||||
ClientboundPlayerLookAtPacket packet = lookAtConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendCameraPacket(int entityId, List<Player> sendTo) {
|
|
||||||
FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.buffer());
|
|
||||||
byteBuf.writeVarInt(entityId);
|
|
||||||
try {
|
|
||||||
ClientboundSetCameraPacket packet = cameraConstructor.newInstance(byteBuf);
|
|
||||||
for (Player p : sendTo) sendPacket(p, packet);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package me.lojosho.hibiscuscommons.nms.v1_20_R2;
|
|
||||||
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
|
||||||
|
|
||||||
public class NMSUtils extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSUtils {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNextEntityId() {
|
|
||||||
return net.minecraft.world.entity.Entity.nextEntityId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public org.bukkit.entity.Entity getEntity(int entityId) {
|
|
||||||
net.minecraft.world.entity.Entity entity = getNMSEntity(entityId);
|
|
||||||
if (entity == null) return null;
|
|
||||||
return entity.getBukkitEntity();
|
|
||||||
}
|
|
||||||
|
|
||||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
|
||||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
|
||||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
|
||||||
if (entity == null) continue;
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user