mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
feat: add 1.21.4 support
This commit is contained in:
@@ -6,12 +6,12 @@ plugins {
|
|||||||
id("com.gradleup.shadow") version "8.3.4"
|
id("com.gradleup.shadow") version "8.3.4"
|
||||||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
||||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4" apply false
|
id("io.papermc.paperweight.userdev") apply false
|
||||||
//id("io.papermc.hangar-publish-plugin") version "0.1.1"
|
//id("io.papermc.hangar-publish-plugin") version "0.1.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "me.lojosho"
|
group = "me.lojosho"
|
||||||
version = "0.5.2${getGitCommitHash()}"
|
version = "0.5.3${getGitCommitHash()}"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
@@ -23,6 +23,9 @@ allprojects {
|
|||||||
maven("https://oss.sonatype.org/content/groups/public/")
|
maven("https://oss.sonatype.org/content/groups/public/")
|
||||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||||
|
|
||||||
|
// Paper Repo
|
||||||
|
maven("https://papermc.io/repo/repository/maven-public/")
|
||||||
|
|
||||||
// UpdateChecker
|
// UpdateChecker
|
||||||
maven("https://repo.jeff-media.com/public")
|
maven("https://repo.jeff-media.com/public")
|
||||||
|
|
||||||
@@ -74,7 +77,8 @@ 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("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.1.0-dev.0")
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public class NMSHandlers {
|
|||||||
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");
|
||||||
|
put("1.21.4", "v1_21_R3");
|
||||||
}};
|
}};
|
||||||
|
|
||||||
private static NMSHandler handler;
|
private static NMSHandler handler;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
userdevVersion=2.0.0-beta.8
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
|
val userdevVersion: String by settings
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
maven("https://repo.papermc.io/repository/maven-public/")
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
}
|
}
|
||||||
|
plugins {
|
||||||
|
id("io.papermc.paperweight.userdev") version userdevVersion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = "HibiscusCommons"
|
rootProject.name = "HibiscusCommons"
|
||||||
@@ -14,4 +18,5 @@ include(
|
|||||||
"v1_20_R4",
|
"v1_20_R4",
|
||||||
"v1_21_R1",
|
"v1_21_R1",
|
||||||
"v1_21_R2",
|
"v1_21_R2",
|
||||||
|
"v1_21_R3",
|
||||||
)
|
)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4"
|
id("io.papermc.paperweight.userdev")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4"
|
id("io.papermc.paperweight.userdev")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4"
|
id("io.papermc.paperweight.userdev")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4"
|
id("io.papermc.paperweight.userdev")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4"
|
id("io.papermc.paperweight.userdev")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.papermc.paperweight.userdev") version "1.7.4"
|
id("io.papermc.paperweight.userdev")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
30
v1_21_R3/build.gradle.kts
Normal file
30
v1_21_R3/build.gradle.kts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
plugins {
|
||||||
|
id("java")
|
||||||
|
id("io.papermc.paperweight.userdev")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT")
|
||||||
|
implementation(project(":common"))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
|
||||||
|
build {
|
||||||
|
dependsOn(reobfJar)
|
||||||
|
}
|
||||||
|
|
||||||
|
compileJava {
|
||||||
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(21));
|
||||||
|
}
|
||||||
|
|
||||||
|
javadoc {
|
||||||
|
options.encoding = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
processResources {
|
||||||
|
filteringCharset = Charsets.UTF_8.name()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package me.lojosho.hibiscuscommons.nms.v1_21_R3;
|
||||||
|
|
||||||
|
import net.minecraft.network.protocol.Packet;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerConnection;
|
||||||
|
import org.bukkit.craftbukkit.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
package me.lojosho.hibiscuscommons.nms.v1_21_R3;
|
||||||
|
|
||||||
|
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.PositionMoveRotation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.level.portal.TeleportTransition;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
|
import net.minecraft.world.scores.Team;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
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<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 {
|
||||||
|
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
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
ClientboundTeleportEntityPacket packet = ClientboundTeleportEntityPacket.teleport(entityId, new PositionMoveRotation(new Vec3(x, y, z), Vec3.ZERO, yaw, pitch), java.util.Set.of(), onGround);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package me.lojosho.hibiscuscommons.nms.v1_21_R3;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.craftbukkit.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