mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-21 16:09:27 +00:00
Compare commits
4 Commits
nms_packet
...
v2.7.8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bebee807bc | ||
|
|
26c579b69f | ||
|
|
ef665e7e83 | ||
|
|
7a6475c467 |
@@ -69,7 +69,6 @@ allprojects {
|
|||||||
|
|
||||||
// Hibiscus Commons
|
// Hibiscus Commons
|
||||||
maven("https://repo.hibiscusmc.com/releases")
|
maven("https://repo.hibiscusmc.com/releases")
|
||||||
mavenLocal()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -78,21 +77,16 @@ allprojects {
|
|||||||
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
|
||||||
compileOnly("org.jetbrains:annotations:24.1.0")
|
compileOnly("org.jetbrains:annotations:24.1.0")
|
||||||
|
compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0")
|
||||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
|
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
|
||||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") {
|
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12")
|
||||||
exclude(group = "org.bukkit")
|
|
||||||
exclude(group = "com.google.guava")
|
|
||||||
exclude(group = "com.google.code.gson")
|
|
||||||
exclude(group = "it.unimi.dsi")
|
|
||||||
exclude(group = "com.sk89q.jnbt")
|
|
||||||
}
|
|
||||||
compileOnly("io.github.toxicity188:BetterHud-standard-api:1.12") //Standard api
|
compileOnly("io.github.toxicity188:BetterHud-standard-api:1.12") //Standard api
|
||||||
compileOnly("io.github.toxicity188:BetterHud-bukkit-api:1.12") //Platform api
|
compileOnly("io.github.toxicity188:BetterHud-bukkit-api:1.12") //Platform api
|
||||||
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
|
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
|
||||||
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
|
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
|
||||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||||
compileOnly("me.lojosho:HibiscusCommons:0.6.3-32402bd")
|
compileOnly("me.lojosho:HibiscusCommons:0.6.3-0f0baaf4")
|
||||||
|
|
||||||
// Handled by Spigot Library Loader
|
// Handled by Spigot Library Loader
|
||||||
compileOnly("net.kyori:adventure-api:4.19.0")
|
compileOnly("net.kyori:adventure-api:4.19.0")
|
||||||
@@ -145,7 +139,7 @@ tasks {
|
|||||||
downloadPlugins {
|
downloadPlugins {
|
||||||
hangar("PlaceholderAPI", "2.11.6")
|
hangar("PlaceholderAPI", "2.11.6")
|
||||||
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
||||||
url("https://download.luckperms.net/1567/bukkit/loader/LuckPerms-Bukkit-5.4.150.jar")
|
url("https://download.luckperms.net/1582/bukkit/loader/LuckPerms-Bukkit-5.4.165.jar")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,8 +175,8 @@ bukkit {
|
|||||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||||
apiVersion = "1.20"
|
apiVersion = "1.20"
|
||||||
authors = listOf("LoJoSho")
|
authors = listOf("LoJoSho")
|
||||||
depend = listOf("HibiscusCommons")
|
depend = listOf("HibiscusCommons", "ProtocolLib")
|
||||||
softDepend = listOf("BetterHud", "ModelEngine", "Nexo", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
|
softDepend = listOf("BetterHud", "ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
|
||||||
version = "${project.version}"
|
version = "${project.version}"
|
||||||
loadBefore = listOf(
|
loadBefore = listOf(
|
||||||
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.17"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ public class CosmeticCommand implements CommandExecutor {
|
|||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||||
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
|
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
|
||||||
}
|
}
|
||||||
|
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
|
||||||
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
||||||
player.sendMessage("EntityId -> " + player.getEntityId());
|
player.sendMessage("EntityId -> " + player.getEntityId());
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ public class MySQLData extends SQLData {
|
|||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
if (connection == null) throw new NullPointerException("Connection is null");
|
if (connection == null) throw new NullPointerException("Connection is null");
|
||||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||||
"(UUID varchar(36) PRIMARY KEY, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");")) {
|
||||||
|
preparedStatement.execute();
|
||||||
|
}
|
||||||
} catch (SQLException | NullPointerException e) {
|
} catch (SQLException | NullPointerException e) {
|
||||||
plugin.getLogger().severe("");
|
plugin.getLogger().severe("");
|
||||||
plugin.getLogger().severe("");
|
plugin.getLogger().severe("");
|
||||||
@@ -60,17 +62,11 @@ public class MySQLData extends SQLData {
|
|||||||
@Override
|
@Override
|
||||||
public void clear(UUID uniqueId) {
|
public void clear(UUID uniqueId) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
PreparedStatement preparedSt = null;
|
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
|
||||||
try {
|
|
||||||
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
|
||||||
preparedSt.setString(1, uniqueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (preparedSt != null) preparedSt.close();
|
|
||||||
} catch (SQLException e) {}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,22 +23,17 @@ public abstract class SQLData extends Data {
|
|||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
UserData data = new UserData(uniqueId);
|
UserData data = new UserData(uniqueId);
|
||||||
|
|
||||||
PreparedStatement preparedStatement = null;
|
try (PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;")){
|
||||||
try {
|
|
||||||
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
|
|
||||||
preparedStatement.setString(1, uniqueId.toString());
|
preparedStatement.setString(1, uniqueId.toString());
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
try (ResultSet rs = preparedStatement.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
String rawData = rs.getString("COSMETICS");
|
String rawData = rs.getString("COSMETICS");
|
||||||
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
|
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
|
||||||
data.setCosmetics(cosmetics);
|
data.setCosmetics(cosmetics);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (preparedStatement != null) preparedStatement.close();
|
|
||||||
} catch (SQLException e) {}
|
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
@@ -48,18 +43,12 @@ public abstract class SQLData extends Data {
|
|||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public void save(CosmeticUser user) {
|
public void save(CosmeticUser user) {
|
||||||
Runnable run = () -> {
|
Runnable run = () -> {
|
||||||
PreparedStatement preparedSt = null;
|
try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
|
||||||
try {
|
|
||||||
preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
|
||||||
preparedSt.setString(1, user.getUniqueId().toString());
|
preparedSt.setString(1, user.getUniqueId().toString());
|
||||||
preparedSt.setString(2, serializeData(user));
|
preparedSt.setString(2, serializeData(user));
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (preparedSt != null) preparedSt.close();
|
|
||||||
} catch (SQLException e) {}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {
|
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {
|
||||||
|
|||||||
@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
|
|||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||||
|
|
||||||
openConnection();
|
openConnection();
|
||||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||||
"(UUID varchar(36) PRIMARY KEY, " +
|
"(UUID varchar(36) PRIMARY KEY, " +
|
||||||
"COSMETICS MEDIUMTEXT " +
|
"COSMETICS MEDIUMTEXT " +
|
||||||
");").execute();
|
");")) {
|
||||||
|
preparedStatement.execute();
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -48,17 +50,11 @@ public class SQLiteData extends SQLData {
|
|||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public void clear(UUID uniqueId) {
|
public void clear(UUID uniqueId) {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
PreparedStatement preparedSt = null;
|
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
|
||||||
try {
|
|
||||||
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
|
||||||
preparedSt.setString(1, uniqueId.toString());
|
preparedSt.setString(1, uniqueId.toString());
|
||||||
preparedSt.executeUpdate();
|
preparedSt.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (preparedSt != null) preparedSt.close();
|
|
||||||
} catch (SQLException e) {}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.listener;
|
package com.hibiscusmc.hmccosmetics.listener;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.events.*;
|
||||||
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
|
import com.comphenix.protocol.wrappers.Pair;
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerCosmeticPostEquipEvent;
|
import com.hibiscusmc.hmccosmetics.api.events.PlayerCosmeticPostEquipEvent;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
@@ -47,6 +52,17 @@ import java.util.*;
|
|||||||
|
|
||||||
public class PlayerGameListener implements Listener {
|
public class PlayerGameListener implements Listener {
|
||||||
|
|
||||||
|
public PlayerGameListener() {
|
||||||
|
registerInventoryClickListener();
|
||||||
|
registerMenuChangeListener();
|
||||||
|
registerEntityStatusListener();
|
||||||
|
registerPlayerEquipmentListener();
|
||||||
|
registerPlayerArmListener();
|
||||||
|
registerEntityUseListener();
|
||||||
|
registerSlotChangeListener();
|
||||||
|
registerPassengerSetListener();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
||||||
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
|
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
|
||||||
@@ -410,6 +426,251 @@ public class PlayerGameListener implements Listener {
|
|||||||
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerInventoryClickListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, List.of(PacketType.Play.Client.WINDOW_CLICK), ListenerOptions.ASYNC) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
int invTypeClicked = event.getPacket().getIntegers().read(0);
|
||||||
|
int slotClicked = -999;
|
||||||
|
if (NMSHandlers.getVersion().isHigherOrEqual(MinecraftVersion.v1_21_5)) {
|
||||||
|
slotClicked = event.getPacket().getShorts().read(0);
|
||||||
|
} else {
|
||||||
|
slotClicked = event.getPacket().getIntegers().read(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must be a player inventory.
|
||||||
|
if (invTypeClicked != 0) return;
|
||||||
|
// -999 is when a player clicks outside their inventory. https://wiki.vg/Inventory#Player_Inventory
|
||||||
|
if (slotClicked == -999) return;
|
||||||
|
if (event.getPlayer() == null) return;
|
||||||
|
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.isInWardrobe()) return;
|
||||||
|
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slotClicked);
|
||||||
|
if (cosmeticSlot == null) return;
|
||||||
|
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||||
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
|
||||||
|
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerMenuChangeListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, List.of(PacketType.Play.Server.WINDOW_ITEMS), ListenerOptions.ASYNC) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
MessagesUtil.sendDebugMessages("Menu Initial ");
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (event.getPlayer() == null) return;
|
||||||
|
|
||||||
|
int windowID = event.getPacket().getIntegers().read(0);
|
||||||
|
List<ItemStack> slotData = event.getPacket().getItemListModifier().read(0);
|
||||||
|
if (windowID != 0) return;
|
||||||
|
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
|
||||||
|
HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||||
|
|
||||||
|
if (!user.isInWardrobe()) {
|
||||||
|
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||||
|
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
||||||
|
boolean requireEmpty = Settings.getSlotOption(cosmeticArmorType.getEquipSlot()).isRequireEmpty();
|
||||||
|
boolean isAir = user.getPlayer().getInventory().getItem(cosmeticArmorType.getEquipSlot()).getType().isAir();
|
||||||
|
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + cosmeticArmorType.getId() + " - " + requireEmpty + " - " + isAir);
|
||||||
|
if (requireEmpty && !isAir) continue;
|
||||||
|
items.put(HMCCInventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||||
|
packet.getIntegers().write(0, 0);
|
||||||
|
for (int slot = 0; slot < 46; slot++) {
|
||||||
|
if ((slot >= 5 && slot <= 8) || slot == 45) {
|
||||||
|
if (!items.containsKey(slot)) continue;
|
||||||
|
slotData.set(slot, items.get(slot));
|
||||||
|
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packet.getItemListModifier().write(0, slotData);
|
||||||
|
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
|
||||||
|
event.setPacket(packet);
|
||||||
|
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
|
||||||
|
/*
|
||||||
|
for (Cosmetic cosmetic : user.getCosmetic()) {
|
||||||
|
if ((cosmetic instanceof CosmeticArmorType) || (cosmetic instanceof CosmeticMainhandType)) {
|
||||||
|
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||||
|
user.updateCosmetic(cosmetic);
|
||||||
|
}, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerSlotChangeListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SET_SLOT) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
MessagesUtil.sendDebugMessages("SetSlot Initial ");
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (event.getPlayer() == null) return;
|
||||||
|
|
||||||
|
int windowID = event.getPacket().getIntegers().read(0);
|
||||||
|
if (windowID != 0) return;
|
||||||
|
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.isInWardrobe()) return;
|
||||||
|
|
||||||
|
int slot = event.getPacket().getIntegers().read(2);
|
||||||
|
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
|
||||||
|
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
|
||||||
|
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
|
||||||
|
if (cosmeticSlot == null || equipmentSlot == null) return;
|
||||||
|
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||||
|
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
|
||||||
|
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return;
|
||||||
|
}
|
||||||
|
event.getPacket().getItemModifier().write(0, user.getUserCosmeticItem(cosmeticSlot));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerPlayerEquipmentListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
Player player = event.getPlayer(); // Player that's sent
|
||||||
|
int entityID = event.getPacket().getIntegers().read(0);
|
||||||
|
// User
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.isInWardrobe()) return;
|
||||||
|
|
||||||
|
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
|
||||||
|
|
||||||
|
for (int i = 0; i < armor.size(); i++) {
|
||||||
|
com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack> pair = armor.get(i);
|
||||||
|
switch (pair.getFirst()) {
|
||||||
|
case MAINHAND -> {
|
||||||
|
if (user.getPlayer() == event.getPlayer()) continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
|
||||||
|
if (user.getPlayer() != null && user.getPlayer().isInvisible()) continue; // Fixes integration with GSit still showing mainhand even when hidden
|
||||||
|
armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(pair.getFirst());
|
||||||
|
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.getItemSlotToCosmeticSlot(pair.getFirst());
|
||||||
|
if (slot == null || cosmeticSlot == null) continue;
|
||||||
|
if (Settings.getSlotOption(slot).isRequireEmpty()
|
||||||
|
&& !user.getPlayer().getInventory().getItem(slot).getType().isAir()) continue;
|
||||||
|
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||||
|
if (cosmeticArmor == null) continue;
|
||||||
|
ItemStack item = user.getUserCosmeticItem(cosmeticArmor);
|
||||||
|
if (item == null) continue;
|
||||||
|
Pair<EnumWrappers.ItemSlot, ItemStack> armorPair = new Pair<>(HMCCInventoryUtils.itemBukkitSlot(slot), item);
|
||||||
|
armor.set(i, armorPair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.getPacket().getSlotStackPairLists().write(0, armor);
|
||||||
|
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEntityStatusListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_STATUS) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
int entityid = event.getPacket().getIntegers().read(0);
|
||||||
|
byte status = event.getPacket().getBytes().read(0);
|
||||||
|
|
||||||
|
MessagesUtil.sendDebugMessages("EntityStatus Initial " + entityid + " - " + status);
|
||||||
|
if (status != 55) return;
|
||||||
|
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(entityid);
|
||||||
|
if (user == null) {
|
||||||
|
MessagesUtil.sendDebugMessages("EntityStatus User is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerPassengerSetListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.MOUNT) {
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
CosmeticUser viewerUser = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||||
|
if (viewerUser == null) return;
|
||||||
|
if (viewerUser.isInWardrobe()) return;
|
||||||
|
|
||||||
|
int ownerId = event.getPacket().getIntegers().read(0);
|
||||||
|
MessagesUtil.sendDebugMessages("Mount Packet Sent - Read - EntityID: " + ownerId);
|
||||||
|
Entity entity = HMCCServerUtils.getEntity(ownerId);
|
||||||
|
if (entity == null) return;
|
||||||
|
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(entity.getUniqueId());
|
||||||
|
if (user == null) return;
|
||||||
|
MessagesUtil.sendDebugMessages("Mount Packet Sent - " + user.getUniqueId());
|
||||||
|
|
||||||
|
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
||||||
|
if (user.getUserBackpackManager() == null) return;
|
||||||
|
|
||||||
|
// Basically, take the original passengers and "bump" them to the end of the list
|
||||||
|
int[] originalPassengers = event.getPacket().getIntegerArrays().read(0);
|
||||||
|
List<Integer> passengers = new ArrayList<>(user.getUserBackpackManager().getEntityManager().getIds());
|
||||||
|
|
||||||
|
passengers.addAll(Arrays.stream(originalPassengers).boxed().toList());
|
||||||
|
|
||||||
|
event.getPacket().getIntegerArrays().write(0, passengers.stream().mapToInt(Integer::intValue).toArray());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerPlayerArmListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
if (event.getPlayer() == null) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||||
|
if (user == null) return;
|
||||||
|
if (!user.isInWardrobe()) return;
|
||||||
|
if (!user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
|
||||||
|
|
||||||
|
Menu menu = user.getWardrobeManager().getLastOpenMenu();
|
||||||
|
if (menu == null) return;
|
||||||
|
menu.openMenu(user);
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEntityUseListener() {
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
if (event.getPlayer() == null) return;
|
||||||
|
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||||
|
if (user == null) return;
|
||||||
|
if (user.isInWardrobe()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private EquipmentSlot getArmorSlot(final Material material) {
|
private EquipmentSlot getArmorSlot(final Material material) {
|
||||||
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.listener;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.nms.CosmeticChannelHandler;
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import net.minecraft.network.Connection;
|
|
||||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
public class PlayerPacketListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
Channel channel = ((CraftPlayer) event.getPlayer()).getHandle().connection.connection.channel;
|
|
||||||
ChannelPipeline pipeline = channel.pipeline();
|
|
||||||
|
|
||||||
CosmeticChannelHandler channelHandler = new CosmeticChannelHandler(player);
|
|
||||||
for (String key : pipeline.toMap().keySet()) {
|
|
||||||
if (!(pipeline.get(key) instanceof Connection)) continue;
|
|
||||||
pipeline.addBefore(key, "hmccosmetics_channel_handler", channelHandler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.nms;
|
|
||||||
|
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
|
||||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
|
||||||
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
|
||||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.ChannelDuplexHandler;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import io.netty.channel.ChannelPromise;
|
|
||||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
|
||||||
import net.minecraft.core.NonNullList;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
|
||||||
import net.minecraft.network.protocol.game.*;
|
|
||||||
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
|
||||||
import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
|
||||||
import net.minecraft.world.inventory.ClickType;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class CosmeticChannelHandler extends ChannelDuplexHandler {
|
|
||||||
private final Player player;
|
|
||||||
|
|
||||||
public CosmeticChannelHandler(Player player) {
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
|
||||||
if (!(msg instanceof Packet packet)) {
|
|
||||||
super.write(ctx, msg, promise);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (packet) {
|
|
||||||
case ClientboundContainerSetContentPacket setContentPacket -> msg = handleMenuChange(setContentPacket);
|
|
||||||
case ClientboundContainerSetSlotPacket setSlotPacket -> msg = handleSlotChange(setSlotPacket);
|
|
||||||
case ClientboundSetEquipmentPacket equipmentPacket -> msg = handlePlayerEquipment(equipmentPacket);
|
|
||||||
case ClientboundSetPassengersPacket passengerPacket -> msg = handlePassengerSet(passengerPacket);
|
|
||||||
default -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg == null) return;
|
|
||||||
else super.write(ctx, msg, promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handleMenuChange(ClientboundContainerSetContentPacket packet) {
|
|
||||||
MessagesUtil.sendDebugMessages("Menu Initial ");
|
|
||||||
int windowId = packet.getContainerId();
|
|
||||||
NonNullList<ItemStack> slotData = NonNullList.create();
|
|
||||||
slotData.addAll(packet.getItems());
|
|
||||||
if (windowId != 0) return packet;
|
|
||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
|
||||||
if (user == null) return packet;
|
|
||||||
|
|
||||||
HashMap<Integer, ItemStack> items = new HashMap<>();
|
|
||||||
|
|
||||||
if (!user.isInWardrobe()) for (Cosmetic cosmetic : user.getCosmetics()) if (cosmetic instanceof CosmeticArmorType armorType) {
|
|
||||||
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
|
|
||||||
boolean isAir = user.getPlayer().getInventory().getItem(armorType.getEquipSlot()).getType().isAir();
|
|
||||||
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + armorType.getId() + " - " + requireEmpty + " - " + isAir);
|
|
||||||
if (requireEmpty && !isAir) continue;
|
|
||||||
items.put(HMCCInventoryUtils.getPacketArmorSlot(armorType.getEquipSlot()), CraftItemStack.asNMSCopy(user.getUserCosmeticItem(armorType)));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int slot = 0; slot < 46; slot++) {
|
|
||||||
if ((slot >= 5 && slot <= 8) || slot == 45) {
|
|
||||||
if (!items.containsKey(slot)) continue;
|
|
||||||
slotData.set(slot, items.get(slot));
|
|
||||||
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowId + " with " + slotData.size());
|
|
||||||
return new ClientboundContainerSetContentPacket(0, packet.getStateId(), slotData, packet.getCarriedItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handleSlotChange(ClientboundContainerSetSlotPacket packet) {
|
|
||||||
MessagesUtil.sendDebugMessages("SetSlot Initial ");
|
|
||||||
|
|
||||||
int windowId = packet.getContainerId();
|
|
||||||
if (windowId != 0) return packet;
|
|
||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
|
||||||
if (user == null || user.isInWardrobe()) return packet;
|
|
||||||
|
|
||||||
int slot = packet.getSlot();
|
|
||||||
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
|
|
||||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
|
|
||||||
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
|
|
||||||
if (cosmeticSlot == null || equipmentSlot == null) return packet;
|
|
||||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return packet;
|
|
||||||
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
|
|
||||||
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack item = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticSlot));
|
|
||||||
return new ClientboundContainerSetSlotPacket(0, packet.getStateId(), slot, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handlePlayerEquipment(ClientboundSetEquipmentPacket packet) {
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(packet.getEntity());
|
|
||||||
if (user == null || user.isInWardrobe()) return packet;
|
|
||||||
|
|
||||||
List<Pair<net.minecraft.world.entity.EquipmentSlot, ItemStack>> armor = packet.getSlots();
|
|
||||||
|
|
||||||
for (int i = 0; i < armor.size(); i++) {
|
|
||||||
Pair<net.minecraft.world.entity.EquipmentSlot, ItemStack> pair = armor.get(i);
|
|
||||||
if (pair.getFirst() == net.minecraft.world.entity.EquipmentSlot.MAINHAND) {
|
|
||||||
if (user.getPlayer().getUniqueId() == player.getUniqueId())
|
|
||||||
continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
|
|
||||||
if (user.getPlayer() != null && user.getPlayer().isInvisible())
|
|
||||||
continue; // Fixes integration with GSit still showing mainhand even when hidden
|
|
||||||
armor.set(i, new Pair<>(pair.getFirst(), CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand())));
|
|
||||||
} else {
|
|
||||||
EquipmentSlot slot = CraftEquipmentSlot.getSlot(pair.getFirst());
|
|
||||||
if (slot == null) continue;
|
|
||||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
|
|
||||||
if (cosmeticSlot == null) continue;
|
|
||||||
if (Settings.getSlotOption(slot).isRequireEmpty() && player.getInventory().getItem(slot).getType().isAir())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
|
||||||
if (cosmeticArmor == null) continue;
|
|
||||||
ItemStack item = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticSlot));
|
|
||||||
if (item == null) continue;
|
|
||||||
armor.set(i, new Pair<>(pair.getFirst(), item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
|
|
||||||
return new ClientboundSetEquipmentPacket(packet.getEntity(), armor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handlePassengerSet(ClientboundSetPassengersPacket packet) {
|
|
||||||
CosmeticUser viewerUser = CosmeticUsers.getUser(player);
|
|
||||||
if (viewerUser == null || viewerUser.isInWardrobe()) return packet;
|
|
||||||
|
|
||||||
int ownerId = packet.getVehicle();
|
|
||||||
MessagesUtil.sendDebugMessages("Mount Packet Sent - Read - EntityID: " + ownerId);
|
|
||||||
Entity entity = HMCCServerUtils.getEntity(ownerId);
|
|
||||||
if (entity == null) return packet;
|
|
||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(entity.getUniqueId());
|
|
||||||
if (user == null) return packet;
|
|
||||||
MessagesUtil.sendDebugMessages("Mount Packet Sent - " + user.getUniqueId());
|
|
||||||
|
|
||||||
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return packet;
|
|
||||||
if (user.getUserBackpackManager() == null) return packet;
|
|
||||||
|
|
||||||
List<Integer> passengers = new ArrayList<>(user.getUserBackpackManager().getEntityManager().getIds());
|
|
||||||
for (int passenger : packet.getPassengers()) passengers.add(passenger);
|
|
||||||
|
|
||||||
int[] passengerIds = passengers.stream().mapToInt(Integer::intValue).toArray();
|
|
||||||
return (Packet<?>) NMSHandlers.getHandler().getPacketHandler().createMountPacket(ownerId, passengerIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
|
||||||
if (!(msg instanceof Packet packet)) {
|
|
||||||
super.channelRead(ctx, msg);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (packet) {
|
|
||||||
case ServerboundContainerClickPacket clickPacket -> handleInventoryClick(clickPacket);
|
|
||||||
case ServerboundPlayerActionPacket playerActionPacket -> msg = handlePlayerAction(playerActionPacket);
|
|
||||||
case ServerboundSwingPacket swingPacket -> msg = handlePlayerArm(swingPacket);
|
|
||||||
case ServerboundUseItemOnPacket useItemOnPacket -> msg = handleEntityUse(useItemOnPacket);
|
|
||||||
default -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg == null) return;
|
|
||||||
else super.channelRead(ctx, msg);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleInventoryClick(ServerboundContainerClickPacket packet) {
|
|
||||||
ClickType clickType = packet.getClickType();
|
|
||||||
int slotClicked = packet.getSlotNum();
|
|
||||||
|
|
||||||
if (clickType != ClickType.PICKUP || slotClicked == -999) return;
|
|
||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
|
||||||
if (user == null || user.isInWardrobe()) return;
|
|
||||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slotClicked);
|
|
||||||
if (cosmeticSlot == null || !user.hasCosmeticInSlot(cosmeticSlot)) return;
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
|
|
||||||
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handlePlayerAction(ServerboundPlayerActionPacket packet) {
|
|
||||||
ServerboundPlayerActionPacket.Action action = packet.getAction();
|
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages("EntityStatus Initial " + player.getEntityId() + " - " + action);
|
|
||||||
if (action != ServerboundPlayerActionPacket.Action.SWAP_ITEM_WITH_OFFHAND) return packet;
|
|
||||||
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
|
||||||
if (user == null) {
|
|
||||||
MessagesUtil.sendDebugMessages("EntityStatus User is null");
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return packet;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handlePlayerArm(ServerboundSwingPacket packet) {
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
|
||||||
if (user == null || !user.isInWardrobe() || !user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return packet;
|
|
||||||
|
|
||||||
Menu menu = user.getWardrobeManager().getLastOpenMenu();
|
|
||||||
if (menu == null) return packet;
|
|
||||||
menu.openMenu(user);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Packet<?> handleEntityUse(ServerboundUseItemOnPacket packet) {
|
|
||||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
|
||||||
if (user == null || !user.isInWardrobe()) return packet;
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -144,7 +144,7 @@ public class CosmeticUser implements CosmeticHolder {
|
|||||||
showCosmetics(HiddenReason.GAMEMODE);
|
showCosmetics(HiddenReason.GAMEMODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(getEntity().getLocation().getWorld().getName())) {
|
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(bukkitPlayer.getLocation().getWorld().getName())) {
|
||||||
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
|
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
|
||||||
hideCosmetics(CosmeticUser.HiddenReason.WORLD);
|
hideCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||||
} else if (this.isHidden(HiddenReason.WORLD)) {
|
} else if (this.isHidden(HiddenReason.WORLD)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||||
|
|
||||||
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||||
@@ -79,7 +80,7 @@ public class UserEntity {
|
|||||||
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
|
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
|
||||||
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
|
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
|
||||||
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
|
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
|
||||||
//if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||||
}
|
}
|
||||||
this.location = location;
|
this.location = location;
|
||||||
for (Integer entity : ids) {
|
for (Integer entity : ids) {
|
||||||
@@ -98,7 +99,7 @@ public class UserEntity {
|
|||||||
// First person backpacks need both packets to rotate properly, otherwise they look off
|
// First person backpacks need both packets to rotate properly, otherwise they look off
|
||||||
// Regular backpacks just need the look packet
|
// Regular backpacks just need the look packet
|
||||||
if (additonalPacket) HMCCPacketManager.sendRotationPacket(entity, yaw, false, getViewers());
|
if (additonalPacket) HMCCPacketManager.sendRotationPacket(entity, yaw, false, getViewers());
|
||||||
HMCCPacketManager.sendRotateHeadPacket(entity, location, getViewers());
|
HMCCPacketManager.sendLookPacket(entity, location, getViewers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,12 +117,12 @@ public class UserWardrobeManager {
|
|||||||
// Armorstand
|
// Armorstand
|
||||||
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||||
HMCCPacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
|
HMCCPacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
|
||||||
HMCCPacketManager.sendRotateHeadPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
HMCCPacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
player.teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
player.teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||||
player.setInvisible(true);
|
player.setInvisible(true);
|
||||||
HMCCPacketManager.gamemodeChangePacket(player, GameMode.SPECTATOR);
|
HMCCPacketManager.gamemodeChangePacket(player, 3);
|
||||||
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
||||||
|
|
||||||
// NPC
|
// NPC
|
||||||
@@ -142,7 +142,7 @@ public class UserWardrobeManager {
|
|||||||
}, 4);
|
}, 4);
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
HMCCPacketManager.sendRotateHeadPacket(NPC_ID, npcLocation, viewer);
|
HMCCPacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
|
||||||
HMCCPacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
|
HMCCPacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
@@ -234,7 +234,7 @@ public class UserWardrobeManager {
|
|||||||
// NPC
|
// NPC
|
||||||
if (user.isBalloonSpawned()) user.getBalloonManager().sendRemoveLeashPacket();
|
if (user.isBalloonSpawned()) user.getBalloonManager().sendRemoveLeashPacket();
|
||||||
HMCCPacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
|
HMCCPacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success
|
||||||
HMCCPacketManager.sendRemovePlayerPacket(WARDROBE_UUID, viewer); // Success
|
HMCCPacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
HMCCPacketManager.sendCameraPacket(player.getEntityId(), viewer);
|
HMCCPacketManager.sendCameraPacket(player.getEntityId(), viewer);
|
||||||
@@ -247,11 +247,11 @@ public class UserWardrobeManager {
|
|||||||
if (WardrobeSettings.isForceExitGamemode()) {
|
if (WardrobeSettings.isForceExitGamemode()) {
|
||||||
MessagesUtil.sendDebugMessages("Force Exit Gamemode " + WardrobeSettings.getExitGamemode());
|
MessagesUtil.sendDebugMessages("Force Exit Gamemode " + WardrobeSettings.getExitGamemode());
|
||||||
player.setGameMode(WardrobeSettings.getExitGamemode());
|
player.setGameMode(WardrobeSettings.getExitGamemode());
|
||||||
HMCCPacketManager.gamemodeChangePacket(player, WardrobeSettings.getExitGamemode()); // Success
|
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(WardrobeSettings.getExitGamemode())); // Success
|
||||||
} else {
|
} else {
|
||||||
MessagesUtil.sendDebugMessages("Original Gamemode " + this.originalGamemode);
|
MessagesUtil.sendDebugMessages("Original Gamemode " + this.originalGamemode);
|
||||||
player.setGameMode(this.originalGamemode);
|
player.setGameMode(this.originalGamemode);
|
||||||
HMCCPacketManager.gamemodeChangePacket(player, this.originalGamemode); // Success
|
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode)); // Success
|
||||||
}
|
}
|
||||||
user.showPlayer();
|
user.showPlayer();
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ public class UserWardrobeManager {
|
|||||||
int yaw = data.get();
|
int yaw = data.get();
|
||||||
location.setYaw(yaw);
|
location.setYaw(yaw);
|
||||||
|
|
||||||
HMCCPacketManager.sendRotateHeadPacket(NPC_ID, location, viewer);
|
HMCCPacketManager.sendLookPacket(NPC_ID, location, viewer);
|
||||||
user.hidePlayer();
|
user.hidePlayer();
|
||||||
int rotationSpeed = WardrobeSettings.getRotationSpeed();
|
int rotationSpeed = WardrobeSettings.getRotationSpeed();
|
||||||
location.setYaw(HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed));
|
location.setYaw(HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed));
|
||||||
@@ -323,11 +323,10 @@ public class UserWardrobeManager {
|
|||||||
HMCCPacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
|
HMCCPacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle backpacks
|
|
||||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
||||||
HMCCPacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
|
HMCCPacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
|
||||||
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||||
//user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
|
user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
|
||||||
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,4 +358,5 @@ public class UserWardrobeManager {
|
|||||||
RUNNING,
|
RUNNING,
|
||||||
STOPPING,
|
STOPPING,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.util;
|
package com.hibiscusmc.hmccosmetics.util;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@@ -27,6 +28,22 @@ public class HMCCInventoryUtils {
|
|||||||
SLOT_MAP.put(CosmeticSlot.MAINHAND, EquipmentSlot.HAND);
|
SLOT_MAP.put(CosmeticSlot.MAINHAND, EquipmentSlot.HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from the Bukkit item slots to ProtocolLib item slots. Will produce a null if an improper bukkit item slot is sent through
|
||||||
|
* @param slot The BUKKIT item slot to convert.
|
||||||
|
* @return The ProtocolLib item slot that is returned
|
||||||
|
*/
|
||||||
|
public static EnumWrappers.ItemSlot itemBukkitSlot(final EquipmentSlot slot) {
|
||||||
|
return switch (slot) {
|
||||||
|
case HEAD -> EnumWrappers.ItemSlot.HEAD;
|
||||||
|
case CHEST -> EnumWrappers.ItemSlot.CHEST;
|
||||||
|
case LEGS -> EnumWrappers.ItemSlot.LEGS;
|
||||||
|
case FEET -> EnumWrappers.ItemSlot.FEET;
|
||||||
|
case HAND -> EnumWrappers.ItemSlot.MAINHAND;
|
||||||
|
case OFF_HAND -> EnumWrappers.ItemSlot.OFFHAND;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static int getPacketArmorSlot(final EquipmentSlot slot) {
|
public static int getPacketArmorSlot(final EquipmentSlot slot) {
|
||||||
return switch (slot) {
|
return switch (slot) {
|
||||||
case HEAD -> 5;
|
case HEAD -> 5;
|
||||||
@@ -50,17 +67,17 @@ public class HMCCInventoryUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static CosmeticSlot getItemSlotToCosmeticSlot(final EnumWrappers.ItemSlot slot) {
|
public static CosmeticSlot getItemSlotToCosmeticSlot(final EnumWrappers.ItemSlot slot) {
|
||||||
// return switch (slot) {
|
return switch (slot) {
|
||||||
// case HEAD -> CosmeticSlot.HELMET;
|
case HEAD -> CosmeticSlot.HELMET;
|
||||||
// case CHEST -> CosmeticSlot.CHESTPLATE;
|
case CHEST -> CosmeticSlot.CHESTPLATE;
|
||||||
// case LEGS -> CosmeticSlot.LEGGINGS;
|
case LEGS -> CosmeticSlot.LEGGINGS;
|
||||||
// case FEET -> CosmeticSlot.BOOTS;
|
case FEET -> CosmeticSlot.BOOTS;
|
||||||
// case OFFHAND -> CosmeticSlot.OFFHAND;
|
case OFFHAND -> CosmeticSlot.OFFHAND;
|
||||||
// case MAINHAND -> CosmeticSlot.MAINHAND;
|
case MAINHAND -> CosmeticSlot.MAINHAND;
|
||||||
// default -> null;
|
default -> null;
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
|
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
|
||||||
return switch (slot) {
|
return switch (slot) {
|
||||||
@@ -130,31 +147,31 @@ public class HMCCInventoryUtils {
|
|||||||
return SLOT_MAP.get(slot);
|
return SLOT_MAP.get(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static EquipmentSlot getEquipmentSlot(@NotNull EnumWrappers.ItemSlot slot) {
|
public static EquipmentSlot getEquipmentSlot(@NotNull EnumWrappers.ItemSlot slot) {
|
||||||
// switch (slot) {
|
switch (slot) {
|
||||||
// case HEAD -> {
|
case HEAD -> {
|
||||||
// return EquipmentSlot.HEAD;
|
return EquipmentSlot.HEAD;
|
||||||
// }
|
}
|
||||||
// case CHEST -> {
|
case CHEST -> {
|
||||||
// return EquipmentSlot.CHEST;
|
return EquipmentSlot.CHEST;
|
||||||
// }
|
}
|
||||||
// case LEGS -> {
|
case LEGS -> {
|
||||||
// return EquipmentSlot.LEGS;
|
return EquipmentSlot.LEGS;
|
||||||
// }
|
}
|
||||||
// case FEET -> {
|
case FEET -> {
|
||||||
// return EquipmentSlot.FEET;
|
return EquipmentSlot.FEET;
|
||||||
// }
|
}
|
||||||
// case OFFHAND -> {
|
case OFFHAND -> {
|
||||||
// return EquipmentSlot.OFF_HAND;
|
return EquipmentSlot.OFF_HAND;
|
||||||
// }
|
}
|
||||||
// case MAINHAND -> {
|
case MAINHAND -> {
|
||||||
// return EquipmentSlot.HAND;
|
return EquipmentSlot.HAND;
|
||||||
// }
|
}
|
||||||
// default -> {
|
default -> {
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
public static boolean isCosmeticItem(ItemStack itemStack) {
|
public static boolean isCosmeticItem(ItemStack itemStack) {
|
||||||
if (itemStack == null) return false;
|
if (itemStack == null) return false;
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.util;
|
package com.hibiscusmc.hmccosmetics.util;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HMCCPlayerUtils {
|
public class HMCCPlayerUtils {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static WrappedSignedProperty getSkin(Player player) {
|
||||||
|
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
||||||
|
.get("textures").stream().findAny().orElse(null);
|
||||||
|
|
||||||
|
if (skinData == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)}
|
* Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)}
|
||||||
* @param player
|
* @param player
|
||||||
|
|||||||
@@ -18,6 +18,20 @@ public class HMCCServerUtils {
|
|||||||
|
|
||||||
private static String COLOR_CHAR = "&";
|
private static String COLOR_CHAR = "&";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a bukkit gamemode into an integer for use in packets
|
||||||
|
* @param gamemode Bukkit gamemode to convert.
|
||||||
|
* @return int of the gamemode
|
||||||
|
*/
|
||||||
|
public static int convertGamemode(final GameMode gamemode) {
|
||||||
|
return switch (gamemode) {
|
||||||
|
case SURVIVAL -> 0;
|
||||||
|
case CREATIVE -> 1;
|
||||||
|
case ADVENTURE -> 2;
|
||||||
|
case SPECTATOR -> 3;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static org.bukkit.entity.Entity getEntity(int entityId) {
|
public static org.bukkit.entity.Entity getEntity(int entityId) {
|
||||||
return NMSHandlers.getHandler().getUtilHandler().getEntity(entityId);
|
return NMSHandlers.getHandler().getUtilHandler().getEntity(entityId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,30 @@
|
|||||||
package com.hibiscusmc.hmccosmetics.util.packets;
|
package com.hibiscusmc.hmccosmetics.util.packets;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.wrappers.*;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
|
||||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||||
|
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove;
|
||||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.joml.Quaternionf;
|
|
||||||
import org.joml.Vector3f;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class HMCCPacketManager extends PacketManager {
|
public class HMCCPacketManager extends PacketManager {
|
||||||
|
|
||||||
@@ -43,7 +46,16 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final @NotNull List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendSpawnEntityPacket(entityId, uuid, entityType, location, sendTo);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||||
|
packet.getModifier().writeDefaults();
|
||||||
|
packet.getUUIDs().write(0, uuid);
|
||||||
|
packet.getIntegers().write(0, entityId);
|
||||||
|
packet.getEntityTypeModifier().write(0, entityType);
|
||||||
|
packet.getDoubles().
|
||||||
|
write(0, location.getX()).
|
||||||
|
write(1, location.getY()).
|
||||||
|
write(2, location.getZ());
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void equipmentSlotUpdate(
|
public static void equipmentSlotUpdate(
|
||||||
@@ -85,20 +97,53 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
|
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendArmorstandMetadata(int entityId, List<Player> sendTo) {
|
public static void sendArmorstandMetadata(
|
||||||
|
int entityId,
|
||||||
|
List<Player> sendTo
|
||||||
|
) {
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
|
packet.getModifier().writeDefaults();
|
||||||
|
packet.getIntegers().write(0, entityId);
|
||||||
|
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||||
|
|
||||||
// 0x21 = Invisible + Fire (Aka, burns to make it not take the light of the block its in, avoiding turning it black)
|
// 0x21 = Invisible + Fire (Aka, burns to make it not take the light of the block its in, avoiding turning it black)
|
||||||
byte mask = (byte) (Settings.isBackpackPreventDarkness() ? 0x21 : 0x20);
|
byte mask = 0x20;
|
||||||
Map<Integer, Number> dataValues = Map.of(0, mask, 15, (byte) 0x10);
|
if (Settings.isBackpackPreventDarkness()) mask = 0x21;
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
|
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), mask));
|
||||||
|
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
|
||||||
|
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendInvisibilityPacket(int entityId, List<Player> sendTo) {
|
public static void sendInvisibilityPacket(
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, Map.of(0, (byte) 0x20), sendTo);
|
int entityId,
|
||||||
|
List<Player> sendTo
|
||||||
|
) {
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
|
packet.getModifier().writeDefaults();
|
||||||
|
packet.getIntegers().write(0, entityId);
|
||||||
|
|
||||||
|
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||||
|
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||||
|
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendCloudEffect(int entityId, List<Player> sendTo) {
|
public static void sendCloudEffect(
|
||||||
Map<Integer, Number> dataValues = Map.of(0, (byte) 0x20, 8, 0f);
|
int entityId,
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
|
List<Player> sendTo
|
||||||
|
) {
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
|
packet.getModifier().writeDefaults();
|
||||||
|
packet.getIntegers().write(0, entityId);
|
||||||
|
|
||||||
|
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||||
|
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||||
|
wrappedDataValueList.add(new WrappedDataValue(8, WrappedDataWatcher.Registry.get(Float.class), 0f));
|
||||||
|
//wrappedDataValueList.add(new WrappedDataValue(11, WrappedDataWatcher.Registry.get(Integer.class), 21));
|
||||||
|
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||||
|
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendRotationPacket(
|
public static void sendRotationPacket(
|
||||||
@@ -116,10 +161,16 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
@NotNull List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
byte yaw = (byte) (location.getYaw() * ROTATION_FACTOR);
|
float yaw = location.getYaw() * ROTATION_FACTOR;
|
||||||
byte pitch = (byte) (location.getPitch() * ROTATION_FACTOR);
|
float pitch = location.getPitch() * ROTATION_FACTOR;
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||||
|
packet.getIntegers().write(0, entityId);
|
||||||
|
packet.getBytes().write(0, (byte) yaw);
|
||||||
|
packet.getBytes().write(1, (byte) pitch);
|
||||||
|
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, yaw, pitch, onGround, sendTo);
|
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||||
|
packet.getBooleans().write(0, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendRotationPacket(
|
public static void sendRotationPacket(
|
||||||
@@ -129,7 +180,15 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
@NotNull List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, yaw * ROTATION_FACTOR, 0, onGround, sendTo);
|
float yaw2 = yaw * ROTATION_FACTOR;
|
||||||
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||||
|
packet.getIntegers().write(0, entityId);
|
||||||
|
packet.getBytes().write(0, (byte) yaw2);
|
||||||
|
packet.getBytes().write(1, (byte) 0);
|
||||||
|
|
||||||
|
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||||
|
packet.getBooleans().write(0, onGround);
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -157,7 +216,12 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
final int[] passengerIds,
|
final int[] passengerIds,
|
||||||
final @NotNull List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendMountPacket(mountId, passengerIds, sendTo);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||||
|
packet.getIntegers().write(0, mountId);
|
||||||
|
packet.getIntegerArrays().write(0, passengerIds);
|
||||||
|
for (final Player p : sendTo) {
|
||||||
|
sendPacket(p, packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,7 +251,17 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
final int entityId,
|
final int entityId,
|
||||||
final @NotNull List<Player> sendTo
|
final @NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
sendEntitySpawnPacket(location, entityId, EntityType.PLAYER, uuid, sendTo);
|
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) {
|
||||||
|
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
||||||
|
wrapper.setEntityID(entityId);
|
||||||
|
wrapper.setPlayerUUID(uuid);
|
||||||
|
wrapper.setPosition(location.toVector());
|
||||||
|
wrapper.setPitch(location.getPitch());
|
||||||
|
wrapper.setYaw(location.getYaw());
|
||||||
|
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendEntitySpawnPacket(location, entityId, EntityType.PLAYER, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -200,10 +274,28 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
final Player skinnedPlayer,
|
final Player skinnedPlayer,
|
||||||
final int entityId,
|
final int entityId,
|
||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final String npcName,
|
final String NPCName,
|
||||||
final List<Player> sendTo
|
final List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendFakePlayerInfoPacket(skinnedPlayer, entityId, uuid, npcName, sendTo);
|
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
|
||||||
|
info.setAction(EnumWrappers.PlayerInfoAction.ADD_PLAYER);
|
||||||
|
|
||||||
|
String name = NPCName;
|
||||||
|
while (name.length() > 16) {
|
||||||
|
name = name.substring(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
||||||
|
WrappedSignedProperty skinData = HMCCPlayerUtils.getSkin(skinnedPlayer);
|
||||||
|
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
||||||
|
|
||||||
|
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
|
||||||
|
wrappedGameProfile,
|
||||||
|
0,
|
||||||
|
EnumWrappers.NativeGameMode.CREATIVE,
|
||||||
|
WrappedChatComponent.fromText(name)
|
||||||
|
)));
|
||||||
|
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,20 +319,32 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
https://wiki.vg/Entity_metadata#Entity
|
https://wiki.vg/Entity_metadata#Entity
|
||||||
*/
|
*/
|
||||||
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
|
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(playerId, Map.of(17, mask), sendTo);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||||
|
packet.getModifier().writeDefaults();
|
||||||
|
packet.getIntegers().write(0, playerId);
|
||||||
|
|
||||||
|
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||||
|
wrappedDataValueList.add(new WrappedDataValue(17, WrappedDataWatcher.Registry.get(Byte.class), mask));
|
||||||
|
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||||
|
|
||||||
|
for (final Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a fake player from being seen by players.
|
* Removes a fake player from being seen by players.
|
||||||
|
* @param player Which gameprofile to wrap for removing the player.
|
||||||
* @param uuid What is the fake player UUID
|
* @param uuid What is the fake player UUID
|
||||||
* @param sendTo Whom to send the packet to
|
* @param sendTo Whom to send the packet to
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static void sendRemovePlayerPacket(
|
public static void sendRemovePlayerPacket(
|
||||||
|
final Player player,
|
||||||
final UUID uuid,
|
final UUID uuid,
|
||||||
final List<Player> sendTo
|
final List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendPlayerInfoRemovePacket(uuid, sendTo);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
|
||||||
|
packet.getUUIDLists().write(0, List.of(uuid));
|
||||||
|
for (final Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendLeashPacket(
|
public static void sendLeashPacket(
|
||||||
@@ -266,39 +370,16 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
final boolean onGround,
|
final boolean onGround,
|
||||||
@NotNull List<Player> sendTo
|
@NotNull List<Player> sendTo
|
||||||
) {
|
) {
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendMovePacket(entityId, from, to, onGround, sendTo);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||||
|
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
|
||||||
|
wrapper.setEntityID(entityId);
|
||||||
|
wrapper.setDx(to.getX() - from.getX());
|
||||||
|
wrapper.setDy(to.getY() - from.getY());
|
||||||
|
wrapper.setDz(to.getZ() - from.getZ());
|
||||||
|
wrapper.setOnGround(onGround);
|
||||||
|
for (final Player p : sendTo) {
|
||||||
|
sendPacket(p, wrapper.getHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendDisplayEntityMetadataPacket(int entityid, ItemStack backpackItem, List<Player> sendTo) {
|
|
||||||
// TODO: Make the default values adjustable
|
|
||||||
Vector3f translation = new Vector3f(0, 3, 0);
|
|
||||||
Vector3f scale = new Vector3f(1, 1, 1);
|
|
||||||
Quaternionf rotationLeft = new Quaternionf();
|
|
||||||
Quaternionf rotationRight = new Quaternionf();
|
|
||||||
Display.Billboard billboard = Display.Billboard.FIXED;
|
|
||||||
int blockLight = 15;
|
|
||||||
int skylight = 15;
|
|
||||||
int viewRange = Settings.getViewDistance();
|
|
||||||
int width = 0;
|
|
||||||
int height = 0;
|
|
||||||
ItemDisplay.ItemDisplayTransform transform = ItemDisplay.ItemDisplayTransform.HEAD;
|
|
||||||
|
|
||||||
NMSHandlers.getHandler().getPacketHandler().sendItemDisplayMetadata(
|
|
||||||
entityid,
|
|
||||||
translation,
|
|
||||||
scale,
|
|
||||||
rotationLeft,
|
|
||||||
rotationRight,
|
|
||||||
billboard,
|
|
||||||
blockLight,
|
|
||||||
skylight,
|
|
||||||
viewRange,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
transform,
|
|
||||||
backpackItem,
|
|
||||||
sendTo
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,4 +391,9 @@ public class HMCCPacketManager extends PacketManager {
|
|||||||
public static List<Player> getViewers(@NotNull Location location) {
|
public static List<Player> getViewers(@NotNull Location location) {
|
||||||
return PacketManager.getViewers(location, Settings.getViewDistance());
|
return PacketManager.getViewers(location, Settings.getViewDistance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sendPacket(Player player, PacketContainer packet) {
|
||||||
|
if (player == null) return;
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
// Courtesy of Packet Wrapper
|
||||||
|
public class AbstractPacket {
|
||||||
|
|
||||||
|
// The packet we will be modifying
|
||||||
|
protected PacketContainer handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new strongly typed wrapper for the given packet.
|
||||||
|
*
|
||||||
|
* @param handle - handle to the raw packet data.
|
||||||
|
* @param type - the packet type.
|
||||||
|
*/
|
||||||
|
protected AbstractPacket(PacketContainer handle, PacketType type) {
|
||||||
|
// Make sure we're given a valid packet
|
||||||
|
if (handle == null)
|
||||||
|
throw new IllegalArgumentException("Packet handle cannot be NULL.");
|
||||||
|
if (!Objects.equal(handle.getType(), type))
|
||||||
|
throw new IllegalArgumentException(handle.getHandle()
|
||||||
|
+ " is not a packet of type " + type);
|
||||||
|
|
||||||
|
this.handle = handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a handle to the raw packet data.
|
||||||
|
*
|
||||||
|
* @return Raw packet data.
|
||||||
|
*/
|
||||||
|
public PacketContainer getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the current packet to the given receiver.
|
||||||
|
*
|
||||||
|
* @param receiver - the receiver.
|
||||||
|
* @throws RuntimeException If the packet cannot be sent.
|
||||||
|
*/
|
||||||
|
public void sendPacket(Player receiver) {
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver,
|
||||||
|
getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the current packet to all online players.
|
||||||
|
*/
|
||||||
|
public void broadcastPacket() {
|
||||||
|
ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulate receiving the current packet from the given sender.
|
||||||
|
*
|
||||||
|
* @param sender - the sender.
|
||||||
|
* @throws RuntimeException If the packet cannot be received.
|
||||||
|
* @deprecated Misspelled. recieve to receive
|
||||||
|
* @see #receivePacket(Player)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public void recievePacket(Player sender) {
|
||||||
|
try {
|
||||||
|
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
|
||||||
|
getHandle());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Cannot recieve packet.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulate receiving the current packet from the given sender.
|
||||||
|
*
|
||||||
|
* @param sender - the sender.
|
||||||
|
* @throws RuntimeException if the packet cannot be received.
|
||||||
|
*/
|
||||||
|
public void receivePacket(Player sender) {
|
||||||
|
try {
|
||||||
|
ProtocolLibrary.getProtocolManager().receiveClientPacket(sender,
|
||||||
|
getHandle());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Cannot receive packet.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
|
||||||
|
public static final PacketType TYPE =
|
||||||
|
PacketType.Play.Server.NAMED_ENTITY_SPAWN;
|
||||||
|
|
||||||
|
public WrapperPlayServerNamedEntitySpawn() {
|
||||||
|
super(new PacketContainer(TYPE), TYPE);
|
||||||
|
handle.getModifier().writeDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) {
|
||||||
|
super(packet, TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Entity ID.
|
||||||
|
* <p>
|
||||||
|
* Notes: entity's ID
|
||||||
|
*
|
||||||
|
* @return The current Entity ID
|
||||||
|
*/
|
||||||
|
public int getEntityID() {
|
||||||
|
return handle.getIntegers().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Entity ID.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setEntityID(int value) {
|
||||||
|
handle.getIntegers().write(0, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the entity of the painting that will be spawned.
|
||||||
|
*
|
||||||
|
* @param world - the current world of the entity.
|
||||||
|
* @return The spawned entity.
|
||||||
|
*/
|
||||||
|
public Entity getEntity(World world) {
|
||||||
|
return handle.getEntityModifier(world).read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the entity of the painting that will be spawned.
|
||||||
|
*
|
||||||
|
* @param event - the packet event.
|
||||||
|
* @return The spawned entity.
|
||||||
|
*/
|
||||||
|
public Entity getEntity(@NotNull PacketEvent event) {
|
||||||
|
return getEntity(event.getPlayer().getWorld());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Player UUID.
|
||||||
|
* <p>
|
||||||
|
* Notes: player's UUID
|
||||||
|
*
|
||||||
|
* @return The current Player UUID
|
||||||
|
*/
|
||||||
|
public UUID getPlayerUUID() {
|
||||||
|
return handle.getUUIDs().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Player UUID.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setPlayerUUID(UUID value) {
|
||||||
|
handle.getUUIDs().write(0, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the position of the spawned entity as a vector.
|
||||||
|
*
|
||||||
|
* @return The position as a vector.
|
||||||
|
*/
|
||||||
|
public Vector getPosition() {
|
||||||
|
return new Vector(getX(), getY(), getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the position of the spawned entity using a vector.
|
||||||
|
*
|
||||||
|
* @param position - the new position.
|
||||||
|
*/
|
||||||
|
public void setPosition(@NotNull Vector position) {
|
||||||
|
setX(position.getX());
|
||||||
|
setY(position.getY());
|
||||||
|
setZ(position.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getX() {
|
||||||
|
return handle.getDoubles().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(double value) {
|
||||||
|
handle.getDoubles().write(0, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getY() {
|
||||||
|
return handle.getDoubles().read(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(double value) {
|
||||||
|
handle.getDoubles().write(1, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getZ() {
|
||||||
|
return handle.getDoubles().read(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZ(double value) {
|
||||||
|
handle.getDoubles().write(2, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the yaw of the spawned entity.
|
||||||
|
*
|
||||||
|
* @return The current Yaw
|
||||||
|
*/
|
||||||
|
public float getYaw() {
|
||||||
|
return (handle.getBytes().read(0) * 360.F) / 256.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the yaw of the spawned entity.
|
||||||
|
*
|
||||||
|
* @param value - new yaw.
|
||||||
|
*/
|
||||||
|
public void setYaw(float value) {
|
||||||
|
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the pitch of the spawned entity.
|
||||||
|
*
|
||||||
|
* @return The current pitch
|
||||||
|
*/
|
||||||
|
public float getPitch() {
|
||||||
|
return (handle.getBytes().read(1) * 360.F) / 256.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pitch of the spawned entity.
|
||||||
|
*
|
||||||
|
* @param value - new pitch.
|
||||||
|
*/
|
||||||
|
public void setPitch(float value) {
|
||||||
|
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||||
|
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||||
|
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
|
||||||
|
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
|
||||||
|
|
||||||
|
public WrapperPlayServerPlayerInfo() {
|
||||||
|
super(new PacketContainer(TYPE), TYPE);
|
||||||
|
handle.getModifier().writeDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
|
||||||
|
super(packet, TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerInfoAction getAction() {
|
||||||
|
return handle.getPlayerInfoAction().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAction(PlayerInfoAction value) {
|
||||||
|
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_17_R1") || HMCCosmeticsAPI.getNMSVersion().contains("v1_18_R2") || HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R1")) {
|
||||||
|
handle.getPlayerInfoAction().write(0, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// New way of handling it 1.19.3+
|
||||||
|
handle.getPlayerInfoActions().write(0, Set.of(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PlayerInfoData> getData() {
|
||||||
|
return handle.getPlayerInfoDataLists().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(List<PlayerInfoData> value) {
|
||||||
|
handle.getPlayerInfoDataLists().write(0, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.util.packets.wrappers;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
|
||||||
|
public static final PacketType TYPE =
|
||||||
|
PacketType.Play.Server.REL_ENTITY_MOVE;
|
||||||
|
|
||||||
|
public WrapperPlayServerRelEntityMove() {
|
||||||
|
super(new PacketContainer(TYPE), TYPE);
|
||||||
|
handle.getModifier().writeDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WrapperPlayServerRelEntityMove(PacketContainer packet) {
|
||||||
|
super(packet, TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Entity ID.
|
||||||
|
* <p>
|
||||||
|
* Notes: entity's ID
|
||||||
|
*
|
||||||
|
* @return The current Entity ID
|
||||||
|
*/
|
||||||
|
public int getEntityID() {
|
||||||
|
return handle.getIntegers().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Entity ID.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setEntityID(int value) {
|
||||||
|
handle.getIntegers().write(0, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the entity of the painting that will be spawned.
|
||||||
|
*
|
||||||
|
* @param world - the current world of the entity.
|
||||||
|
* @return The spawned entity.
|
||||||
|
*/
|
||||||
|
public Entity getEntity(World world) {
|
||||||
|
return handle.getEntityModifier(world).read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the entity of the painting that will be spawned.
|
||||||
|
*
|
||||||
|
* @param event - the packet event.
|
||||||
|
* @return The spawned entity.
|
||||||
|
*/
|
||||||
|
public Entity getEntity(@NotNull PacketEvent event) {
|
||||||
|
return getEntity(event.getPlayer().getWorld());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve DX.
|
||||||
|
*
|
||||||
|
* @return The current DX
|
||||||
|
*/
|
||||||
|
public double getDx() {
|
||||||
|
return handle.getShorts().read(0) / 4096D;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DX.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setDx(double value) {
|
||||||
|
handle.getShorts().write(0, (short) (value * 4096));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve DY.
|
||||||
|
*
|
||||||
|
* @return The current DY
|
||||||
|
*/
|
||||||
|
public double getDy() {
|
||||||
|
return handle.getShorts().read(1) / 4096D;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DY.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setDy(double value) {
|
||||||
|
handle.getShorts().write(1, (short) (value * 4096));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve DZ.
|
||||||
|
*
|
||||||
|
* @return The current DZ
|
||||||
|
*/
|
||||||
|
public double getDz() {
|
||||||
|
return handle.getShorts().read(2) / 4096D;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DZ.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setDz(double value) {
|
||||||
|
handle.getShorts().write(2, (short) (value * 4096));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the yaw of the current entity.
|
||||||
|
*
|
||||||
|
* @return The current Yaw
|
||||||
|
*/
|
||||||
|
public float getYaw() {
|
||||||
|
return (handle.getBytes().read(0) * 360.F) / 256.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the yaw of the current entity.
|
||||||
|
*
|
||||||
|
* @param value - new yaw.
|
||||||
|
*/
|
||||||
|
public void setYaw(float value) {
|
||||||
|
handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the pitch of the current entity.
|
||||||
|
*
|
||||||
|
* @return The current pitch
|
||||||
|
*/
|
||||||
|
public float getPitch() {
|
||||||
|
return (handle.getBytes().read(1) * 360.F) / 256.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pitch of the current entity.
|
||||||
|
*
|
||||||
|
* @param value - new pitch.
|
||||||
|
*/
|
||||||
|
public void setPitch(float value) {
|
||||||
|
handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve On Ground.
|
||||||
|
*
|
||||||
|
* @return The current On Ground
|
||||||
|
*/
|
||||||
|
public boolean getOnGround() {
|
||||||
|
return handle.getBooleans().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set On Ground.
|
||||||
|
*
|
||||||
|
* @param value - new value.
|
||||||
|
*/
|
||||||
|
public void setOnGround(boolean value) {
|
||||||
|
handle.getBooleans().write(0, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
Reference in New Issue
Block a user