mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
chore: backend rework of NMS support (split off from one file) - BREAKS COMPATIBILITY WITH OLDER VERSIONS
This commit is contained in:
@@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "me.lojosho"
|
||||
version = "0.4.10"
|
||||
version = "0.5.0"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
|
||||
@@ -20,8 +20,9 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
|
||||
public void onStart() {
|
||||
instance = this;
|
||||
|
||||
if (!NMSHandlers.isVersionSupported()) {
|
||||
getLogger().severe("This version is not supported! Consider switching versions?");
|
||||
try {
|
||||
NMSHandlers.setup();
|
||||
} catch (RuntimeException e) {
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,34 +51,38 @@ public abstract class HibiscusPlugin extends JavaPlugin {
|
||||
Metrics metrics = new Metrics(this, bstats);
|
||||
}
|
||||
if (resourceID > 0) {
|
||||
// Update Checker
|
||||
UpdateChecker checker = new UpdateChecker(this, UpdateCheckSource.POLYMART, String.valueOf(resourceID))
|
||||
.onSuccess((commandSenders, latestVersion) -> {
|
||||
this.latestVersion = (String) latestVersion;
|
||||
String pluginName = getDescription().getName();
|
||||
|
||||
if (!this.latestVersion.equalsIgnoreCase(getDescription().getVersion())) {
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
getLogger().info("There is a new update for " + pluginName + "!");
|
||||
getLogger().info("Please download it as soon as possible for possible fixes and new features.");
|
||||
getLogger().info("Current Version " + getDescription().getVersion() + " | Latest Version " + latestVersion);
|
||||
//getLogger().info("Spigot: https://www.spigotmc.org/resources/100107/");
|
||||
getLogger().info("Polymart: https://polymart.org/resource/" + resourceID);
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
} else {
|
||||
getLogger().info("You are running the latest version of " + pluginName + "!");
|
||||
}
|
||||
})
|
||||
.setNotifyRequesters(false)
|
||||
.setNotifyOpsOnJoin(false)
|
||||
.checkEveryXHours(24)
|
||||
.checkNow();
|
||||
onLatestVersion = checker.isUsingLatestVersion();
|
||||
setupResourceUpdateChecker(this, resourceID);
|
||||
}
|
||||
|
||||
onStart();
|
||||
}
|
||||
|
||||
private void setupResourceUpdateChecker(HibiscusPlugin plugin, int resourceID) {
|
||||
// Update Checker
|
||||
UpdateChecker checker = new UpdateChecker(plugin, UpdateCheckSource.POLYMART, String.valueOf(resourceID))
|
||||
.onSuccess((commandSenders, latestVersion) -> {
|
||||
this.latestVersion = (String) latestVersion;
|
||||
String pluginName = getDescription().getName();
|
||||
|
||||
if (!this.latestVersion.equalsIgnoreCase(getDescription().getVersion())) {
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
getLogger().info("There is a new update for " + pluginName + "!");
|
||||
getLogger().info("Please download it as soon as possible for possible fixes and new features.");
|
||||
getLogger().info("Current Version " + getDescription().getVersion() + " | Latest Version " + latestVersion);
|
||||
//getLogger().info("Spigot: https://www.spigotmc.org/resources/100107/");
|
||||
getLogger().info("Polymart: https://polymart.org/resource/" + resourceID);
|
||||
getLogger().info("+++++++++++++++++++++++++++++++++++");
|
||||
} else {
|
||||
getLogger().info("You are running the latest version of " + pluginName + "!");
|
||||
}
|
||||
})
|
||||
.setNotifyRequesters(false)
|
||||
.setNotifyOpsOnJoin(false)
|
||||
.checkEveryXHours(24)
|
||||
.checkNow();
|
||||
onLatestVersion = checker.isUsingLatestVersion();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void onDisable() {
|
||||
|
||||
@@ -1,44 +1,22 @@
|
||||
package me.lojosho.hibiscuscommons.nms;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
public class NMSHandler {
|
||||
|
||||
public interface NMSHandler {
|
||||
private static NMSHandler instance;
|
||||
@Getter
|
||||
private NMSUtils utilHandler;
|
||||
@Getter
|
||||
private NMSPackets packetHandler;
|
||||
|
||||
int getNextEntityId();
|
||||
public NMSHandler(NMSUtils utilHandler, NMSPackets packetHandler) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("NMSHandler is already initialized.");
|
||||
}
|
||||
this.utilHandler = utilHandler;
|
||||
this.packetHandler = packetHandler;
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
void slotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
);
|
||||
|
||||
void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
void hideNPCName(
|
||||
Player player,
|
||||
String NPCName
|
||||
);
|
||||
|
||||
default boolean getSupported () {
|
||||
return false;
|
||||
instance = this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package me.lojosho.hibiscuscommons.nms;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -21,26 +20,21 @@ public class NMSHandlers {
|
||||
// 1.20.2 is not supported; was imminently bumped to 1.21.3
|
||||
put("1.21.3", "v1_21_R2");
|
||||
}};
|
||||
|
||||
private static NMSHandler handler;
|
||||
@Getter
|
||||
private static String version;
|
||||
|
||||
@Nullable
|
||||
public static boolean isVersionSupported() {
|
||||
return getVersion() != null;
|
||||
}
|
||||
|
||||
public static NMSHandler getHandler() {
|
||||
if (handler != null) {
|
||||
return handler;
|
||||
} else {
|
||||
setup();
|
||||
}
|
||||
if (handler == null) setup();
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static boolean isVersionSupported() {
|
||||
if (getHandler() == null) return false;
|
||||
return getHandler().getSupported();
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
public static void setup() throws RuntimeException {
|
||||
if (handler != null) return;
|
||||
final String bukkitVersion = Bukkit.getServer().getBukkitVersion();
|
||||
String minecraftVersion = bukkitVersion.substring(0, bukkitVersion.indexOf('-'));
|
||||
@@ -59,8 +53,7 @@ public class NMSHandlers {
|
||||
}
|
||||
HibiscusCommonsPlugin.getInstance().getLogger().severe(" ");
|
||||
HibiscusCommonsPlugin.getInstance().getLogger().severe("Please report this issue to the developer.");
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(HibiscusCommonsPlugin.getInstance());
|
||||
return;
|
||||
throw new RuntimeException("Failed to detect the server version.");
|
||||
}
|
||||
|
||||
for (String selectedVersion : VERSION_MAP.values()) {
|
||||
@@ -70,7 +63,9 @@ public class NMSHandlers {
|
||||
//MessagesUtil.sendDebugMessages(packageVersion + " has been detected.", Level.INFO);
|
||||
version = packageVersion;
|
||||
try {
|
||||
handler = (NMSHandler) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion + ".NMSHandler").getConstructor().newInstance();
|
||||
NMSUtils utilHandler = (NMSUtils) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion + ".NMSUtils").getConstructor().newInstance();
|
||||
NMSPackets packetHandler = (NMSPackets) Class.forName("me.lojosho.hibiscuscommons.nms." + packageVersion + ".NMSPackets").getConstructor().newInstance();
|
||||
handler = new NMSHandler(utilHandler, packetHandler);
|
||||
return;
|
||||
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
|
||||
IllegalAccessException | NoSuchMethodException e) {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.lojosho.hibiscuscommons.nms;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public interface NMSPackets {
|
||||
|
||||
void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
);
|
||||
|
||||
void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
void sendScoreboardHideNamePacket(
|
||||
Player player,
|
||||
String name
|
||||
);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.lojosho.hibiscuscommons.nms;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface NMSUtils {
|
||||
|
||||
int getNextEntityId();
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.Arrays;
|
||||
public class ServerUtils {
|
||||
|
||||
public static int getNextEntityId() {
|
||||
return NMSHandlers.getHandler().getNextEntityId();
|
||||
return NMSHandlers.getHandler().getUtilHandler().getNextEntityId();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -223,7 +223,7 @@ public class PacketManager {
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
NMSHandlers.getHandler().slotUpdate(player, slot);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendSlotUpdate(player, slot);
|
||||
}
|
||||
|
||||
public static void equipmentSlotUpdate(
|
||||
@@ -232,7 +232,7 @@ public class PacketManager {
|
||||
ItemStack item,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(entityId, slot, item, sendTo);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendEquipmentSlotUpdate(entityId, slot, item, sendTo);
|
||||
}
|
||||
|
||||
public static void equipmentSlotUpdate(
|
||||
@@ -240,7 +240,7 @@ public class PacketManager {
|
||||
HashMap<EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(entityId, equipment, sendTo);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendEquipmentSlotUpdate(entityId, equipment, sendTo);
|
||||
}
|
||||
|
||||
private static List<Player> getNearbyPlayers(Location location, int distance) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
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.CraftServer;
|
||||
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;
|
||||
@@ -26,32 +23,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
@@ -76,7 +51,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
@@ -98,7 +73,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
public void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
@@ -120,9 +95,9 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
@@ -135,19 +110,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
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(NPCName);
|
||||
add(name);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
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.CraftServer;
|
||||
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;
|
||||
@@ -26,32 +23,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
@@ -76,7 +51,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
@@ -98,7 +73,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
public void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
@@ -120,9 +95,9 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
@@ -135,19 +110,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
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(NPCName);
|
||||
add(name);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_20_R3;
|
||||
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
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_R3.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.scoreboard.CraftScoreboard;
|
||||
@@ -26,32 +23,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
@@ -76,7 +51,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
@@ -98,7 +73,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
public void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
@@ -120,9 +95,9 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
@@ -135,19 +110,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
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(NPCName);
|
||||
add(name);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_20_R3;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_20_R4;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
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.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
|
||||
@@ -26,32 +23,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
@@ -76,7 +51,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
@@ -98,7 +73,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
public void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
@@ -120,9 +95,9 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
@@ -135,19 +110,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
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(NPCName);
|
||||
add(name);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_20_R4;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_21_R1;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
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.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
|
||||
@@ -26,32 +23,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
@@ -76,7 +51,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
@@ -98,7 +73,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
public void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
@@ -120,9 +95,9 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
@@ -135,19 +110,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
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(NPCName);
|
||||
add(name);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_21_R1;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_21_R2;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,16 +5,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
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.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
|
||||
@@ -26,32 +23,10 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.nms.NMSPackets {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
@@ -76,7 +51,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
public void sendEquipmentSlotUpdate(
|
||||
int entityId,
|
||||
HashMap<org.bukkit.inventory.EquipmentSlot, ItemStack> equipment,
|
||||
List<Player> sendTo
|
||||
@@ -98,7 +73,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
public void sendSlotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
@@ -120,9 +95,9 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
public void sendScoreboardHideNamePacket(Player player, String name) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), name);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
@@ -135,19 +110,7 @@ public class NMSHandler implements me.lojosho.hibiscuscommons.nms.NMSHandler {
|
||||
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(NPCName);
|
||||
add(name);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_21_R2;
|
||||
|
||||
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