9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-21 07:59:19 +00:00

Compare commits

..

6 Commits

37 changed files with 501 additions and 536 deletions

View File

@@ -2,13 +2,13 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
plugins { plugins {
id("java") id("java")
id("com.gradleup.shadow") version "8.3.2" id("com.github.johnrengelman.shadow") version "8.1.1"
id("xyz.jpenilla.run-paper") version "2.3.1" id("xyz.jpenilla.run-paper") version "2.0.0"
id("net.minecrell.plugin-yml.bukkit") version "0.6.0" id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
} }
group = "com.hibiscusmc" group = "com.hibiscusmc"
version = "2.7.4${getGitCommitHash()}" version = "2.7.3-DEV"
allprojects { allprojects {
apply(plugin = "java") apply(plugin = "java")
@@ -49,6 +49,9 @@ allprojects {
} }
} }
// UpdateChecker
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
// ParticleHelper // ParticleHelper
maven("https://repo.bytecode.space/repository/maven-public/") maven("https://repo.bytecode.space/repository/maven-public/")
@@ -66,21 +69,22 @@ allprojects {
// Hibiscus Commons // Hibiscus Commons
maven("https://repo.hibiscusmc.com/releases") maven("https://repo.hibiscusmc.com/releases")
mavenLocal()
} }
dependencies { dependencies {
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") }) compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
compileOnly("com.mojang:authlib:1.5.25") compileOnly("com.mojang:authlib:1.5.25")
//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.1-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.19.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("com.comphenix.protocol:ProtocolLib:5.1.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.2")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
//compileOnly("it.unimi.dsi:fastutil:8.5.14") compileOnly("it.unimi.dsi:fastutil:8.5.13")
compileOnly("org.projectlombok:lombok:1.18.34") compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("me.lojosho:HibiscusCommons:0.5.1") compileOnly("me.lojosho:HibiscusCommons:0.4.7")
// Handled by Spigot Library Loader // Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.17.0") compileOnly("net.kyori:adventure-api:4.17.0")
@@ -120,21 +124,15 @@ tasks {
} }
runServer { runServer {
minecraftVersion("1.21.1") minecraftVersion("1.20.6")
downloadPlugins {
hangar("PlaceholderAPI", "2.11.6")
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")
}
} }
shadowJar { shadowJar {
mergeServiceFiles() mergeServiceFiles()
relocate("dev.triumphteam.gui", "com.hibiscusmc.hmccosmetics.shaded.gui") relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
relocate("com.owen1212055.particlehelper", "com.hibiscusmc.hmccosmetics.shaded.particlehelper") relocate("com.owen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
relocate("com.ticxo.playeranimator", "com.hibiscusmc.hmccosmetics.shaded.playeranimator") relocate("com.ticxo.playeranimator", "com.hisbiscusmc.hmccosmetics.playeranimator")
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar") archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
dependencies { dependencies {
@@ -142,7 +140,7 @@ tasks {
} }
doLast { doLast {
archiveFile.get().asFile.copyTo(layout.projectDirectory.file("run/plugins/HMCCosmeticsRemapped.jar").asFile, true) archiveFile.get().asFile.copyTo(File("D:\\Server\\Paper1_21\\plugins\\${project.name}-${project.version}.jar"), true)
println("If you use the plugin, consider buying it for: ") println("If you use the plugin, consider buying it for: ")
println("The custom resource pack, Oraxen + ItemAdder configurations, and Discord support!") println("The custom resource pack, Oraxen + ItemAdder configurations, and Discord support!")
println("Polymart: https://polymart.org/resource/1879") println("Polymart: https://polymart.org/resource/1879")
@@ -159,7 +157,7 @@ tasks {
bukkit { bukkit {
load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD load = BukkitPluginDescription.PluginLoadOrder.POSTWORLD
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin" main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
apiVersion = "1.20" apiVersion = "1.19"
authors = listOf("LoJoSho") authors = listOf("LoJoSho")
depend = listOf("HibiscusCommons", "ProtocolLib") depend = listOf("HibiscusCommons", "ProtocolLib")
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco") softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
@@ -263,23 +261,3 @@ java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21 toolchain.languageVersion.set(JavaLanguageVersion.of(21
)) ))
} }
fun getGitCommitHash(): String {
var includeHash = true
val includeHashVariable = System.getenv("HMCC_INCLUDE_HASH")
if (!includeHashVariable.isNullOrEmpty()) includeHash = includeHashVariable.toBoolean()
if (includeHash) {
return try {
val process = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
.redirectErrorStream(true)
.start()
process.inputStream.bufferedReader().use { "-" + it.readLine().trim() }
} catch (e: Exception) {
"-unknown" // Fallback if Git is not available or an error occurs
}
}
return ""
}

View File

@@ -4,7 +4,7 @@ plugins {
} }
java { java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21 toolchain.languageVersion.set(JavaLanguageVersion.of(17
)) ))
} }

View File

@@ -20,7 +20,6 @@ import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener; import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener;
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener; import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener; import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
import com.hibiscusmc.hmccosmetics.listener.ServerListener;
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.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
@@ -95,7 +94,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
// Listener // Listener
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this); getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this); getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
getServer().getPluginManager().registerEvents(new ServerListener(), this);
// Taken from PaperLib // Taken from PaperLib
if (HibiscusCommonsPlugin.isOnPaper()) { if (HibiscusCommonsPlugin.isOnPaper()) {
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this); getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);

View File

@@ -43,14 +43,10 @@ public class CosmeticCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String @NotNull [] args) {
boolean silent = false; boolean silent = false;
boolean console = false;
if (!(sender instanceof Player)) {
console = true;
}
if (args.length == 0) { if (args.length == 0) {
if (console) { if (!(sender instanceof Player)) {
// Console
return true; return true;
} }
if (!sender.hasPermission("hmccosmetics.cmd.default")) { if (!sender.hasPermission("hmccosmetics.cmd.default")) {
@@ -144,7 +140,7 @@ public class CosmeticCommand implements CommandExecutor {
CosmeticUser user = CosmeticUsers.getUser(player); CosmeticUser user = CosmeticUsers.getUser(player);
if (!user.canEquipCosmetic(cosmetic) && !console) { if (!user.canEquipCosmetic(cosmetic)) {
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission"); if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
return true; return true;
} }
@@ -251,16 +247,12 @@ public class CosmeticCommand implements CommandExecutor {
} }
// cosmetic menu exampleMenu playerName // cosmetic menu exampleMenu playerName
case ("menu") -> { case ("menu") -> {
if (args.length == 1) return true;
if (!sender.hasPermission("hmccosmetics.cmd.menu")) { if (!sender.hasPermission("hmccosmetics.cmd.menu")) {
if (!silent) MessagesUtil.sendMessage(sender, "no-permission"); if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
return true; return true;
} }
Menu menu; Menu menu = Menus.getMenu(args[1]);
if (args.length == 1) {
menu = Menus.getDefaultMenu();
} else {
menu = Menus.getMenu(args[1]);
}
if (sender instanceof Player) player = ((Player) sender).getPlayer(); if (sender instanceof Player) player = ((Player) sender).getPlayer();
if (sender.hasPermission("hmccosmetics.cmd.menu.other")) { if (sender.hasPermission("hmccosmetics.cmd.menu.other")) {
@@ -342,7 +334,7 @@ public class CosmeticCommand implements CommandExecutor {
} }
Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]); Wardrobe wardrobe = WardrobeSettings.getWardrobe(args[1]);
if (wardrobe == null) { if (wardrobe == null) {
wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1, null); wardrobe = new Wardrobe(args[1], new WardrobeLocation(null, null, null), null, -1);
WardrobeSettings.addWardrobe(wardrobe); WardrobeSettings.addWardrobe(wardrobe);
//MessagesUtil.sendMessage(player, "no-wardrobes"); //MessagesUtil.sendMessage(player, "no-wardrobes");
//return true; //return true;

View File

@@ -30,15 +30,11 @@ public class Settings {
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death"; private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join"; private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join";
private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join"; private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join";
private static final String ITEM_PROCESSING_PATH = "item-processing";
private static final String ITEM_PROCESS_DISPLAY_NAME_PATH = "display-name";
private static final String ITEM_PROCESS_LORE_PATH = "lore";
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode"; private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes"; private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
private static final String EMOTE_DISTANCE_PATH = "emote-distance"; private static final String EMOTE_DISTANCE_PATH = "emote-distance";
private static final String HOOK_SETTING_PATH = "hook-settings"; private static final String HOOK_SETTING_PATH = "hook-settings";
private static final String HOOK_ITEMADDER_PATH = "itemsadder"; private static final String HOOK_ITEMADDER_PATH = "itemsadder";
private static final String HOOK_NEXO_PATH = "nexo";
private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change"; private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change";
private static final String HOOK_WORLDGUARD_PATH = "worldguard"; private static final String HOOK_WORLDGUARD_PATH = "worldguard";
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check"; private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
@@ -53,6 +49,8 @@ public class Settings {
private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds"; private static final String COSMETIC_DISABLED_WORLDS_PATH = "disabled-worlds";
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet"; private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet"; private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
private static final String COSMETIC_BACKPACK_LIGHT_EMINATION_PATH = "backpack-light-emination";
private static final String COSMETIC_BACKPACK_LIGHT_BLOCK_DETECTION = "backpack-block-detection";
private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics"; private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics";
private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward"; private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward";
private static final String MENU_SETTINGS_PATH = "menu-settings"; private static final String MENU_SETTINGS_PATH = "menu-settings";
@@ -92,14 +90,8 @@ public class Settings {
@Getter @Getter
private static boolean forceShowOnJoin; private static boolean forceShowOnJoin;
@Getter @Getter
private static boolean itemProcessingDisplayName;
@Getter
private static boolean itemProcessingLore;
@Getter
private static boolean itemsAdderChangeReload; private static boolean itemsAdderChangeReload;
@Getter @Getter
private static boolean nexoChangeReload;
@Getter
private static boolean worldGuardMoveCheck; private static boolean worldGuardMoveCheck;
@Getter @Getter
private static boolean cosmeticEmoteBlockCheck; private static boolean cosmeticEmoteBlockCheck;
@@ -115,6 +107,10 @@ public class Settings {
@Getter @Getter
private static boolean backpackForceRidingEnabled; private static boolean backpackForceRidingEnabled;
@Getter @Getter
private static boolean backpackLightEmination;
@Getter
private static boolean backpackBlockDetection;
@Getter
private static boolean emotesEnabled; private static boolean emotesEnabled;
@Getter @Getter
private static boolean disabledGamemodesEnabled; private static boolean disabledGamemodesEnabled;
@@ -195,10 +191,6 @@ public class Settings {
disabledWorlds = new ArrayList<>(); disabledWorlds = new ArrayList<>();
} }
ConfigurationNode itemProcessingSettings = cosmeticSettings.node(ITEM_PROCESSING_PATH);
itemProcessingDisplayName = itemProcessingSettings.node(ITEM_PROCESS_DISPLAY_NAME_PATH).getBoolean(true);
itemProcessingLore = itemProcessingSettings.node(ITEM_PROCESS_LORE_PATH).getBoolean(true);
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false); unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false); forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false); forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
@@ -210,6 +202,8 @@ public class Settings {
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false); emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false); destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false); backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
backpackLightEmination = cosmeticSettings.node(COSMETIC_BACKPACK_LIGHT_EMINATION_PATH).getBoolean(true);
backpackBlockDetection = cosmeticSettings.node(COSMETIC_BACKPACK_LIGHT_BLOCK_DETECTION).getBoolean(true);
cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> { cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase()); EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase());
@@ -260,13 +254,9 @@ public class Settings {
dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25); dyeMenuOutputSlot = dyeMenuSettings.node(DYE_MENU_OUTPUT_SLOT).getInt(25);
ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH); ConfigurationNode hookSettings = source.node(HOOK_SETTING_PATH);
ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH); ConfigurationNode itemsAdderSettings = hookSettings.node(HOOK_ITEMADDER_PATH);
itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false); itemsAdderChangeReload = itemsAdderSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(false);
ConfigurationNode nexoSettings = hookSettings.node(HOOK_NEXO_PATH);
nexoChangeReload = nexoSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(true);
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH); ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true); worldGuardMoveCheck = worldGuardSettings.node(HOOK_WG_MOVE_CHECK_PATH).getBoolean(true);
// I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check. // I messed up in release 2.2.6 and forgot to change player_move_check to player-move-check.

View File

@@ -14,12 +14,10 @@ public class Wardrobe {
private final String id; private final String id;
@Getter @Setter @Getter @Setter
private int distance; private int distance;
@Getter @Setter @Nullable @Getter @Setter
private String permission; private String permission;
@Getter @Setter @Getter @Setter
private WardrobeLocation location; private WardrobeLocation location;
@Getter @Setter @Nullable
private String defaultMenu;
/** /**
* This creates a Wardrobe object with all the information that a user will need when entering. * This creates a Wardrobe object with all the information that a user will need when entering.
@@ -27,14 +25,12 @@ public class Wardrobe {
* @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work * @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work
* @param permission The permission required to enter the wardrobe, if null, no permission is required * @param permission The permission required to enter the wardrobe, if null, no permission is required
* @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance * @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance
* @param defaultMenu The default menu that the player will open when entering the wardrobe.
*/ */
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance, @Nullable String defaultMenu) { public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance) {
this.id = id; this.id = id;
this.location = location; this.location = location;
this.distance = distance; this.distance = distance;
if (permission != null) this.permission = permission; if (permission != null) this.permission = permission;
if (defaultMenu != null) this.defaultMenu = defaultMenu;
} }
/** /**

View File

@@ -45,7 +45,6 @@ public class WardrobeSettings {
private static final String WARDROBES_PATH = "wardrobes"; private static final String WARDROBES_PATH = "wardrobes";
private static final String PERMISSION_PATH = "permission"; private static final String PERMISSION_PATH = "permission";
private static final String DISTANCE_PATH = "distance"; private static final String DISTANCE_PATH = "distance";
private static final String WARDROBE_DEFAULT_MENU = "default-menu";
private static final String BOSSBAR_PATH = "bossbar"; private static final String BOSSBAR_PATH = "bossbar";
private static final String BOSSBAR_ENABLE_PATH = "enabled"; private static final String BOSSBAR_ENABLE_PATH = "enabled";
private static final String BOSSBAR_TEXT_PATH = "text"; private static final String BOSSBAR_TEXT_PATH = "text";
@@ -175,10 +174,9 @@ public class WardrobeSettings {
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation); WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
String permission = wardrobesNode.node(PERMISSION_PATH).getString(); String permission = wardrobesNode.node(PERMISSION_PATH).getString();
String defaultMenu = wardrobesNode.node(WARDROBE_DEFAULT_MENU).getString();
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1); int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance, defaultMenu); Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance);
addWardrobe(wardrobe); addWardrobe(wardrobe);
} catch (Exception e) { } catch (Exception e) {
MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE); MessagesUtil.sendDebugMessages("Unable to create wardrobe " + id, Level.SEVERE);

View File

@@ -2,16 +2,23 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer; import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
import me.lojosho.shaded.configurate.ConfigurationNode; import me.lojosho.shaded.configurate.ConfigurationNode;
import me.lojosho.shaded.configurate.serialize.SerializationException; import me.lojosho.shaded.configurate.serialize.SerializationException;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Display;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
public abstract class Cosmetic { public abstract class Cosmetic {
@@ -76,4 +83,52 @@ public abstract class Cosmetic {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
protected ItemDisplayMetadata generateItemDisplayMetadata(ConfigurationNode config) {
ItemDisplayMetadata metadata = new ItemDisplayMetadata();
if (!config.virtual()) {
ConfigurationNode translationNode = config.node("translation");
ConfigurationNode scaleNode = config.node("scale");
ConfigurationNode rotationLeftNode = config.node("rotation-left");
ConfigurationNode rotationRightNode = config.node("rotation-right");
ConfigurationNode skyLightNode = config.node("sky-light");
ConfigurationNode viewRangeNode = config.node("viewrange");
ConfigurationNode widthNode = config.node("width");
ConfigurationNode heightNode = config.node("height");
ConfigurationNode displayTransformNode = config.node("display-transform");
ConfigurationNode itemstackNode = config.node("item");
if (!translationNode.virtual()) metadata.translation = stringToVector(translationNode.getString("0,0,0"));
if (!scaleNode.virtual()) metadata.scale = stringToVector(scaleNode.getString("1,1,1"));
if (!rotationLeftNode.virtual()) metadata.rotationLeft = stringToQuaternion(rotationLeftNode.getString("0,0,0,1"));
if (!rotationRightNode.virtual()) metadata.rotationRight = stringToQuaternion(rotationRightNode.getString("0,0,0,1"));
if (!skyLightNode.virtual()) metadata.skyLight = skyLightNode.getInt(15);
if (!viewRangeNode.virtual()) metadata.viewRange = viewRangeNode.getFloat(1);
if (!widthNode.virtual()) metadata.width = widthNode.getFloat(0);
if (!heightNode.virtual()) metadata.height = heightNode.getFloat(0);
if (!displayTransformNode.virtual()) try {
metadata.displayTransform = ItemDisplay.ItemDisplayTransform.valueOf(displayTransformNode.getString());
} catch (Exception ignored) {}
if (!itemstackNode.virtual()) try {
metadata.itemStack = ItemSerializer.INSTANCE.deserialize(ItemStack.class, itemstackNode);
} catch (Exception ignored) {}
}
return metadata;
}
protected Vector3f stringToVector(String string) {
List<String> vector = Arrays.stream(string.replace(" ", "").split(",", 3)).toList();
while (vector.size() < 3) vector.add("0");
float x = Float.parseFloat(vector.get(0)), y = Float.parseFloat(vector.get(1)), z = Float.parseFloat(vector.get(2));
return new Vector3f(x, y, z);
}
protected Quaternionf stringToQuaternion(String string) {
List<String> vector = Arrays.stream(string.replace(" ", "").split(",", 4)).toList();
while (vector.size() < 3) vector.add("0");
if (vector.size() < 4) vector.add("1");
float x = Float.parseFloat(vector.get(0)), y = Float.parseFloat(vector.get(1)), z = Float.parseFloat(vector.get(2)), w = Float.parseFloat(vector.get(3));
return new Quaternionf(x, y, z, w);
}
} }

View File

@@ -22,12 +22,7 @@ public class CosmeticArmorType extends Cosmetic {
public CosmeticArmorType(String id, ConfigurationNode config) { public CosmeticArmorType(String id, ConfigurationNode config) {
super(id, config); super(id, config);
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(getSlot()); this.equipSlot = HMCCInventoryUtils.getEquipmentSlot(getSlot());
if (slot == null) {
// Hypothetically it shouldn't be null, but it was happening on some random servers? Adding this just in case
throw new IllegalArgumentException("Invalid slot for cosmetic armor type: " + getSlot() + " in " + id + " cosmetic config.");
}
this.equipSlot = slot;
} }
@Override @Override
@@ -57,7 +52,6 @@ public class CosmeticArmorType extends Cosmetic {
return cosmeticItem; return cosmeticItem;
} }
@NotNull
public EquipmentSlot getEquipSlot() { public EquipmentSlot getEquipSlot() {
return this.equipSlot; return this.equipSlot;
} }

View File

@@ -3,17 +3,18 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter; import lombok.Getter;
import me.lojosho.hibiscuscommons.util.packets.PacketManager; import lombok.Setter;
import me.lojosho.shaded.configurate.ConfigurationNode; import me.lojosho.shaded.configurate.ConfigurationNode;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
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;
@@ -29,16 +30,24 @@ public class CosmeticBackpackType extends Cosmetic {
@Getter @Getter
private int height = -1; private int height = -1;
private ItemStack firstPersonBackpack; private ItemStack firstPersonBackpack;
@Getter @Setter
private ItemDisplayMetadata metadata;
@Getter @Setter
private ItemDisplayMetadata firstPersonMetadata;
public CosmeticBackpackType(String id, ConfigurationNode config) { public CosmeticBackpackType(String id, ConfigurationNode config) {
super(id, config); super(id, config);
modelName = config.node("model").getString(); modelName = config.node("model").getString();
if (!config.node("firstperson-item").virtual()) { ConfigurationNode firstPersonNode = config.node("firstperson-item");
this.firstPersonBackpack = generateItemStack(config.node("firstperson-item")); if (!firstPersonNode.virtual()) {
this.firstPersonBackpack = generateItemStack(firstPersonNode);
this.height = config.node("height").getInt(5); this.height = config.node("height").getInt(5);
} }
this.firstPersonMetadata = generateItemDisplayMetadata(config.node("firstperson-metadata")).setVertical();
this.metadata = generateItemDisplayMetadata(config.node("metadata")).setFixed();
} }
@Override @Override
@@ -46,7 +55,7 @@ public class CosmeticBackpackType extends Cosmetic {
Entity entity = Bukkit.getEntity(user.getUniqueId()); Entity entity = Bukkit.getEntity(user.getUniqueId());
if (entity == null) return; if (entity == null) return;
Location loc = entity.getLocation().clone().add(0, 2, 0); Location loc = entity.getLocation();
if (user.isInWardrobe() || !user.isBackpackSpawned()) return; if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
if (user.isHidden()) { if (user.isHidden()) {
@@ -56,20 +65,20 @@ public class CosmeticBackpackType extends Cosmetic {
} }
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc); List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
user.getUserBackpackManager().getEntityManager().teleport(loc); UserBackpackManager backpackManager = user.getUserBackpackManager();
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible()); //backpackManager.getEntityManager().setRotation((int) loc.getYaw(), false);
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers); HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), backpackManager.getFirstItemDisplayId(), EntityType.ITEM_DISPLAY, UUID.randomUUID(), outsideViewers);
HMCCPacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); //metadata.rotationLeft.rotateY((float) Math.toRadians(loc.getYaw()));
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers); HMCCPacketManager.sendItemDisplayMetadata(backpackManager.getFirstItemDisplayId(), metadata, user.getUserCosmeticItem(this, getItem()), outsideViewers);
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players // If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers()); if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), backpackManager.getFirstItemDisplayId(), backpackManager.getEntityManager().getViewers());
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstItemDisplayId(), outsideViewers);
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) { if (!user.isInWardrobe() && isFirstPersonCompatible() && user.getPlayer() != null) {
List<Player> owner = List.of(user.getPlayer()); List<Player> owner = List.of(user.getPlayer());
ArrayList<Integer> particleCloud = user.getUserBackpackManager().getAreaEffectEntityId(); ArrayList<Integer> particleCloud = backpackManager.getAreaEffectEntityId();
for (int i = 0; i < particleCloud.size(); i++) { for (int i = 0; i < particleCloud.size(); i++) {
if (i == 0) { if (i == 0) {
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner); HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
@@ -77,19 +86,18 @@ public class CosmeticBackpackType extends Cosmetic {
HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner); HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
} }
} }
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner); HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), backpackManager.getFirstItemDisplayId(), owner);
if (!user.isHidden()) { if (!user.isHidden()) {
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner); HMCCPacketManager.sendItemDisplayMetadata(backpackManager.getFirstItemDisplayId(), firstPersonMetadata, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
} }
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO); MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
} }
user.getUserBackpackManager().showBackpack(); //MessagesUtil.sendDebugMessages("TTTTTTT " + backpackManager.refreshBlock(backpackManager.getEntityManager().getViewers()));
backpackManager.showBackpack();
} }
public boolean isFirstPersonCompadible() { public boolean isFirstPersonCompatible() {
return firstPersonBackpack != null; return firstPersonBackpack != null;
} }

View File

@@ -12,7 +12,6 @@ import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level; import java.util.logging.Level;
public class Database { public class Database {
@@ -57,7 +56,7 @@ public class Database {
data.save(CosmeticUsers.getUser(player)); data.save(CosmeticUsers.getUser(player));
} }
public static CompletableFuture<UserData> get(UUID uniqueId) { public static CosmeticUser get(UUID uniqueId) {
return data.get(uniqueId); return data.get(uniqueId);
} }

View File

@@ -1,37 +0,0 @@
package com.hibiscusmc.hmccosmetics.database;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class UserData {
@Getter
private UUID owner;
@Setter
@Getter
private HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics;
@Getter
private ArrayList<CosmeticUser.HiddenReason> hiddenReasons;
public UserData(UUID owner) {
this.owner = owner;
this.cosmetics = new HashMap<>();
this.hiddenReasons = new ArrayList<>();
}
public void addCosmetic(CosmeticSlot slot, Cosmetic cosmetic, Integer color) {
cosmetics.put(slot, Map.entry(cosmetic, color));
}
public void addHiddenReason(CosmeticUser.HiddenReason reason) {
hiddenReasons.add(reason);
}
}

View File

@@ -5,7 +5,6 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.EnumUtils;
@@ -15,7 +14,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
public abstract class Data { public abstract class Data {
@@ -24,7 +22,7 @@ public abstract class Data {
public abstract void save(CosmeticUser user); public abstract void save(CosmeticUser user);
@Nullable @Nullable
public abstract CompletableFuture<UserData> get(UUID uniqueId); public abstract CosmeticUser get(UUID uniqueId);
public abstract void clear(UUID uniqueId); public abstract void clear(UUID uniqueId);
@@ -50,9 +48,13 @@ public abstract class Data {
return data.toString(); return data.toString();
} }
public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw) {
return deserializeData(user, raw, Settings.isForcePermissionJoin());
}
@NotNull @NotNull
public final HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> deserializeData(@NotNull String raw) { public final Map<CosmeticSlot, Map<Cosmetic, Color>> deserializeData(CosmeticUser user, @NotNull String raw, boolean permissionCheck) {
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = new HashMap<>(); Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = new HashMap<>();
String[] rawData = raw.split(","); String[] rawData = raw.split(",");
ArrayList<CosmeticUser.HiddenReason> hiddenReason = new ArrayList<>(); ArrayList<CosmeticUser.HiddenReason> hiddenReason = new ArrayList<>();
@@ -74,14 +76,59 @@ public abstract class Data {
String[] colorSplitData = splitData[1].split("&"); String[] colorSplitData = splitData[1].split("&");
if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]); if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]);
if (slot == null || cosmetic == null) continue; if (slot == null || cosmetic == null) continue;
cosmetics.put(slot, Map.entry(cosmetic, Integer.parseInt(colorSplitData[1]))); if (permissionCheck && cosmetic.requiresPermission()) {
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
continue;
}
}
cosmetics.put(slot, Map.of(cosmetic, Color.fromRGB(Integer.parseInt(colorSplitData[1]))));
} else { } else {
if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]); if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]);
if (slot == null || cosmetic == null) continue; if (slot == null || cosmetic == null) continue;
cosmetics.put(slot, Map.entry(cosmetic, -1)); if (permissionCheck && cosmetic.requiresPermission()) {
if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) {
continue;
}
}
HashMap<Cosmetic, Color> cosmeticColorHashMap = new HashMap<>();
cosmeticColorHashMap.put(cosmetic, null);
cosmetics.put(slot, cosmeticColorHashMap);
} }
} }
MessagesUtil.sendDebugMessages("Hidden Reason: " + hiddenReason);
// if else this, if else that, if else I got to deal with this anymore i'll lose my mind
if (!hiddenReason.isEmpty()) {
for (CosmeticUser.HiddenReason reason : hiddenReason) user.silentlyAddHideFlag(reason);
} else {
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// Handle gamemode check
if (user.getPlayer() != null && Settings.isDisabledGamemodesEnabled() && Settings.getDisabledGamemodes().contains(user.getPlayer().getGameMode().toString())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to gamemode");
user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
return;
} else {
if (user.isHidden(CosmeticUser.HiddenReason.GAMEMODE)) {
MessagesUtil.sendDebugMessages("Join Gamemode Check: Showing Cosmetics");
user.showCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
return;
}
}
// Handle world check
if (user.getPlayer() != null && Settings.getDisabledWorlds().contains(user.getPlayer().getWorld().getName())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
if (user.isHidden(CosmeticUser.HiddenReason.WORLD)) {
MessagesUtil.sendDebugMessages("Join World Check: Showing Cosmetics");
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
}
if (Settings.isAllPlayersHidden()) {
user.hideCosmetics(CosmeticUser.HiddenReason.DISABLED);
}
});
}
return cosmetics; return cosmetics;
} }

View File

@@ -1,11 +1,9 @@
package com.hibiscusmc.hmccosmetics.database.types; package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public class NoneData extends Data { public class NoneData extends Data {
@Override @Override
@@ -19,8 +17,8 @@ public class NoneData extends Data {
} }
@Override @Override
public @Nullable CompletableFuture<UserData> get(UUID uniqueId) { public @Nullable CosmeticUser get(UUID uniqueId) {
return CompletableFuture.completedFuture(new UserData(uniqueId)); return new CosmeticUser(uniqueId);
} }
@Override @Override

View File

@@ -3,7 +3,6 @@ package com.hibiscusmc.hmccosmetics.database.types;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Color; import org.bukkit.Color;
@@ -14,15 +13,14 @@ import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public abstract class SQLData extends Data { public abstract class SQLData extends Data {
@Override @Override
@SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData @SuppressWarnings({"resource"}) // Duplicate is from deprecated InternalData
public CompletableFuture<UserData> get(UUID uniqueId) { public CosmeticUser get(UUID uniqueId) {
return CompletableFuture.supplyAsync(() -> { CosmeticUser user = new CosmeticUser(uniqueId);
UserData data = new UserData(uniqueId);
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
try { try {
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;"); preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
@@ -30,8 +28,21 @@ public abstract class SQLData extends Data {
ResultSet rs = preparedStatement.executeQuery(); 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); Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
data.setCosmetics(cosmetics); // Load cosmetics, put them into the addedCosmetic hashmap
HashMap<Cosmetic, Color> addedCosmetics = new HashMap<>();
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
addedCosmetics.put(cosmetic, cosmeticColors.get(cosmetic));
}
}
// Run a task on the main thread, adding the cosmetics to the player
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
// This can not be async.
for (Cosmetic cosmetic : addedCosmetics.keySet()) {
user.addPlayerCosmetic(cosmetic, addedCosmetics.get(cosmetic));
}
});
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@@ -40,8 +51,9 @@ public abstract class SQLData extends Data {
if (preparedStatement != null) preparedStatement.close(); if (preparedStatement != null) preparedStatement.close();
} catch (SQLException e) {} } catch (SQLException e) {}
} }
return data;
}); });
return user;
} }
@Override @Override

View File

@@ -128,9 +128,8 @@ public class TypeCosmetic extends Type {
} }
@Override @Override
public ItemStack setItem(@NotNull CosmeticUser user, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) { public ItemStack setItem(CosmeticUser user, @NotNull ConfigurationNode config, ItemStack itemStack, int slot) {
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta())); itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta?");
if (config.node("cosmetic").virtual()) { if (config.node("cosmetic").virtual()) {
return itemStack; return itemStack;
@@ -154,8 +153,7 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) { } catch (SerializationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta())); itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in equipped item?");
return itemStack; return itemStack;
} }
@@ -172,8 +170,7 @@ public class TypeCosmetic extends Type {
} catch (SerializationException e) { } catch (SerializationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta())); itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in locked item?");
return itemStack; return itemStack;
} }
return itemStack; return itemStack;
@@ -196,7 +193,7 @@ public class TypeCosmetic extends Type {
} }
if (itemMeta instanceof SkullMeta skullMeta) { if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) { if (skullMeta.hasOwner()) {
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner())); skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
} }
} }

View File

@@ -75,7 +75,7 @@ public class TypeEmpty extends Type {
} }
if (itemMeta instanceof SkullMeta skullMeta) { if (itemMeta instanceof SkullMeta skullMeta) {
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) { if (skullMeta.hasOwner()) {
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner())); skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
} }
} }

View File

@@ -39,9 +39,10 @@ public class WGListener implements Listener {
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) { if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) { if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD); user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
} else { return;
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
} }
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
return;
} }
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) { if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return; if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;

View File

@@ -4,7 +4,6 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings; import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.database.Database; import com.hibiscusmc.hmccosmetics.database.Database;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.gui.Menus; import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
@@ -18,8 +17,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class PlayerConnectionListener implements Listener { public class PlayerConnectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@@ -36,24 +33,17 @@ public class PlayerConnectionListener implements Listener {
); );
} }
// This literally makes me want to end it all but I can't do that so I'll just cry instead
Runnable run = () -> { Runnable run = () -> {
if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this. if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this.
UUID uuid = event.getPlayer().getUniqueId(); CosmeticUser user = Database.get(event.getPlayer().getUniqueId());
Database.get(uuid).thenAccept(data -> { CosmeticUsers.addUser(user);
if (data == null) return; MessagesUtil.sendDebugMessages("Run User Join");
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
CosmeticUser cosmeticUser = new CosmeticUser(uuid, data);
CosmeticUsers.addUser(cosmeticUser);
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
// And finally, launch an update for the cosmetics they have. // And finally, launch an update for the cosmetics they have.
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
if (cosmeticUser.getPlayer() == null) return; if (user.getPlayer() == null) return;
cosmeticUser.updateCosmetic(); user.updateCosmetic();
}, 4); }, 4);
});
});
}; };
if (DatabaseSettings.isEnabledDelay()) { if (DatabaseSettings.isEnabledDelay()) {

View File

@@ -25,13 +25,10 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager; import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager; import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils; import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import me.lojosho.hibiscuscommons.api.events.*; import me.lojosho.hibiscuscommons.api.events.*;
import me.lojosho.hibiscuscommons.hooks.Hook;
import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder; import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder;
import me.lojosho.hibiscuscommons.hooks.items.HookNexo;
import me.lojosho.hibiscuscommons.util.packets.PacketManager; import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@@ -69,7 +66,6 @@ public class PlayerGameListener implements Listener {
registerPlayerArmListener(); registerPlayerArmListener();
registerEntityUseListener(); registerEntityUseListener();
registerSlotChangeListener(); registerSlotChangeListener();
registerPassengerSetListener();
//registerLookMovement(); //registerLookMovement();
//registerMoveListener(); //registerMoveListener();
@@ -383,10 +379,6 @@ public class PlayerGameListener implements Listener {
public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) { public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) {
CosmeticUser user = event.getUser(); CosmeticUser user = event.getUser();
if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) { if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) {
if (user.getBalloonManager() == null) {
MessagesUtil.sendDebugMessages("Balloon Manager is null? " + user.getEntity().getName());
return;
}
CosmeticBalloonType cosmetic = (CosmeticBalloonType) event.getCosmetic(); CosmeticBalloonType cosmetic = (CosmeticBalloonType) event.getCosmetic();
Location npclocation = user.getWardrobeManager().getNpcLocation().clone().add(cosmetic.getBalloonOffset()); Location npclocation = user.getWardrobeManager().getNpcLocation().clone().add(cosmetic.getBalloonOffset());
// We know that no other entity besides a regular player will be in the wardrobe // We know that no other entity besides a regular player will be in the wardrobe
@@ -433,6 +425,21 @@ public class PlayerGameListener implements Listener {
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN); user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHookReload(HibiscusHookReload event) {
if (event.getHook() instanceof HookItemAdder hook) {
switch (event.getReloadType()) {
case INITIAL -> {
HMCCosmeticsPlugin.setup();
}
case RELOAD -> {
if (!Settings.isItemsAdderChangeReload()) return;
HMCCosmeticsPlugin.setup();
}
}
}
}
// These emote mostly handles emotes from other plugins, such as ItemsAdder // These emote mostly handles emotes from other plugins, such as ItemsAdder
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerPlayEmote(HibiscusPlayerEmotePlayEvent event) { public void onPlayerPlayEmote(HibiscusPlayerEmotePlayEvent event) {
@@ -448,22 +455,6 @@ public class PlayerGameListener implements Listener {
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE); user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
} }
@EventHandler(priority = EventPriority.LOW)
public void onPlayerHibiscusPose(HibiscusPlayerPoseEvent event) {
if (event.isGettingUp()) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.hideCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerHibiscusGetUpPose(HibiscusPlayerPoseEvent event) {
if (!event.isGettingUp()) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return;
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
}
private void registerInventoryClickListener() { private void registerInventoryClickListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
@Override @Override
@@ -594,7 +585,6 @@ public class PlayerGameListener implements Listener {
switch (pair.getFirst()) { switch (pair.getFirst()) {
case MAINHAND -> { 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() == 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())); armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
} }
default -> { default -> {
@@ -640,37 +630,6 @@ public class PlayerGameListener implements Listener {
}); });
} }
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() { private void registerPlayerArmListener() {
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
@Override @Override
@@ -760,6 +719,10 @@ public class PlayerGameListener implements Listener {
}); });
} }
@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()) {

View File

@@ -1,41 +0,0 @@
package com.hibiscusmc.hmccosmetics.listener;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload;
import me.lojosho.hibiscuscommons.hooks.Hook;
import me.lojosho.hibiscuscommons.hooks.items.HookItemAdder;
import me.lojosho.hibiscuscommons.hooks.items.HookNexo;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
public class ServerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHookReload(HibiscusHookReload event) {
Hook hook = event.getHook();
if (hook instanceof HookItemAdder) {
switch (event.getReloadType()) {
case INITIAL -> {
HMCCosmeticsPlugin.setup();
}
case RELOAD -> {
if (!Settings.isItemsAdderChangeReload()) return;
HMCCosmeticsPlugin.setup();
}
}
}
if (hook instanceof HookNexo) {
switch (event.getReloadType()) {
case INITIAL -> {
HMCCosmeticsPlugin.setup();
}
case RELOAD -> {
if (!Settings.isNexoChangeReload()) return;
HMCCosmeticsPlugin.setup();
}
}
}
}
}

View File

@@ -13,7 +13,6 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
import com.hibiscusmc.hmccosmetics.database.UserData;
import com.hibiscusmc.hmccosmetics.gui.Menus; import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager; import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
@@ -39,7 +38,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*; import org.bukkit.inventory.meta.*;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
@@ -60,9 +58,8 @@ public class CosmeticUser {
// Cosmetic Settings/Toggles // Cosmetic Settings/Toggles
private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>(); private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>();
private final HashMap<CosmeticSlot, ItemStack> cachedCosmeticItems = new HashMap<>();
private final HashMap<CosmeticSlot, Color> colors = new HashMap<>(); private final HashMap<CosmeticSlot, Color> colors = new HashMap<>();
// Cosmetic caches
private final HashMap<String, ItemStack> cosmeticItems = new HashMap<>();
public CosmeticUser(UUID uuid) { public CosmeticUser(UUID uuid) {
this.uniqueId = uuid; this.uniqueId = uuid;
@@ -70,13 +67,6 @@ public class CosmeticUser {
tick(); tick();
} }
public CosmeticUser(UUID uuid, UserData data) {
this.uniqueId = uuid;
userEmoteManager = new UserEmoteManager(this);
loadData(data);
tick();
}
private void tick() { private void tick() {
// Occasionally updates the entity cosmetics // Occasionally updates the entity cosmetics
Runnable run = () -> { Runnable run = () -> {
@@ -98,54 +88,6 @@ public class CosmeticUser {
despawnBalloon(); despawnBalloon();
} }
public void loadData(@NotNull UserData data) {
boolean permissionCheck = Settings.isForcePermissionJoin();
for (Map.Entry<CosmeticSlot, Map.Entry<Cosmetic, Integer>> entry : data.getCosmetics().entrySet()) {
Cosmetic cosmetic = entry.getValue().getKey();
Color color = entry.getValue().getValue() == -1 ? null : Color.fromRGB(entry.getValue().getValue());
if (permissionCheck && cosmetic.requiresPermission()) {
if (getPlayer() != null && !getPlayer().hasPermission(cosmetic.getPermission())) {
continue;
}
}
addPlayerCosmetic(cosmetic, color);
}
if (!hiddenReason.isEmpty()) {
for (CosmeticUser.HiddenReason reason : hiddenReason) silentlyAddHideFlag(reason);
} else {
for (HiddenReason reason : data.getHiddenReasons()) {
if (getPlayer() != null && Settings.isDisabledGamemodesEnabled() && Settings.getDisabledGamemodes().contains(getPlayer().getGameMode().toString())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to gamemode");
hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
return;
} else {
if (isHidden(CosmeticUser.HiddenReason.GAMEMODE)) {
MessagesUtil.sendDebugMessages("Join Gamemode Check: Showing Cosmetics");
showCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
return;
}
}
// Handle world check
if (getPlayer() != null && Settings.getDisabledWorlds().contains(getPlayer().getWorld().getName())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else {
if (isHidden(CosmeticUser.HiddenReason.WORLD)) {
MessagesUtil.sendDebugMessages("Join World Check: Showing Cosmetics");
showCosmetics(CosmeticUser.HiddenReason.WORLD);
}
}
if (Settings.isAllPlayersHidden()) {
hideCosmetics(CosmeticUser.HiddenReason.DISABLED);
}
silentlyAddHideFlag(reason);
}
}
}
public Cosmetic getCosmetic(CosmeticSlot slot) { public Cosmetic getCosmetic(CosmeticSlot slot) {
return playerCosmetics.get(slot); return playerCosmetics.get(slot);
} }
@@ -154,11 +96,11 @@ public class CosmeticUser {
return ImmutableList.copyOf(playerCosmetics.values()); return ImmutableList.copyOf(playerCosmetics.values());
} }
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic) { public void addPlayerCosmetic(Cosmetic cosmetic) {
addPlayerCosmetic(cosmetic, null); addPlayerCosmetic(cosmetic, null);
} }
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) { public void addPlayerCosmetic(Cosmetic cosmetic, Color color) {
// API // API
PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, cosmetic); PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, cosmetic);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
@@ -215,6 +157,7 @@ public class CosmeticUser {
if (slot == CosmeticSlot.EMOTE) { if (slot == CosmeticSlot.EMOTE) {
if (getUserEmoteManager().isPlayingEmote()) getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.UNEQUIP); if (getUserEmoteManager().isPlayingEmote()) getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.UNEQUIP);
} }
cachedCosmeticItems.remove(slot);
colors.remove(slot); colors.remove(slot);
playerCosmetics.remove(slot); playerCosmetics.remove(slot);
removeArmor(slot); removeArmor(slot);
@@ -280,12 +223,16 @@ public class CosmeticUser {
return getUserCosmeticItem(cosmetic); return getUserCosmeticItem(cosmetic);
} }
public ItemStack getUserCosmeticItem(@NotNull Cosmetic cosmetic) { public ItemStack getUserCosmeticItem(Cosmetic cosmetic) {
ItemStack item = null; ItemStack item = null;
if (!hiddenReason.isEmpty()) { if (!hiddenReason.isEmpty()) {
if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticBalloonType) return new ItemStack(Material.AIR); if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticBalloonType) return new ItemStack(Material.AIR);
return getPlayer().getInventory().getItem(HMCCInventoryUtils.getEquipmentSlot(cosmetic.getSlot())); return getPlayer().getInventory().getItem(HMCCInventoryUtils.getEquipmentSlot(cosmetic.getSlot()));
} }
// Check if the item is cached. This helps with performance as we don't need to keep recreating the item
if (cachedCosmeticItems.containsKey(cosmetic.getSlot())) {
return cachedCosmeticItems.get(cosmetic.getSlot());
}
if (cosmetic instanceof CosmeticArmorType armorType) { if (cosmetic instanceof CosmeticArmorType armorType) {
item = armorType.getItem(this, cosmetic.getItem()); item = armorType.getItem(this, cosmetic.getItem());
} }
@@ -303,11 +250,15 @@ public class CosmeticUser {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public ItemStack getUserCosmeticItem(@NotNull Cosmetic cosmetic, @Nullable ItemStack item) { public ItemStack getUserCosmeticItem(Cosmetic cosmetic, ItemStack item) {
if (item == null) { if (item == null) {
//MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null"); //MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);
} }
// Check if the item is cached. This helps with performance as we don't need to keep recreating the item
if (cachedCosmeticItems.containsKey(cosmetic.getSlot())) {
return cachedCosmeticItems.get(cosmetic.getSlot());
}
if (item.hasItemMeta()) { if (item.hasItemMeta()) {
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
@@ -334,22 +285,18 @@ public class CosmeticUser {
itemMeta = skullMeta; itemMeta = skullMeta;
} }
if (Settings.isItemProcessingDisplayName()) { List<String> processedLore = new ArrayList<>();
if (itemMeta.hasDisplayName()) {
String displayName = itemMeta.getDisplayName();
itemMeta.setDisplayName(Hooks.processPlaceholders(getPlayer(), displayName));
}
}
if (Settings.isItemProcessingLore()) {
List<String> processedLore = new ArrayList<>();
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(getPlayer(), loreLine));
}
}
itemMeta.setLore(processedLore);
}
if (itemMeta.hasLore()) {
for (String loreLine : itemMeta.getLore()) {
processedLore.add(Hooks.processPlaceholders(getPlayer(), loreLine));
}
}
if (itemMeta.hasDisplayName()) {
String displayName = itemMeta.getDisplayName();
itemMeta.setDisplayName(Hooks.processPlaceholders(getPlayer(), displayName));
}
itemMeta.setLore(processedLore);
if (colors.containsKey(cosmetic.getSlot())) { if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot()); Color color = colors.get(cosmetic.getSlot());
@@ -375,6 +322,7 @@ public class CosmeticUser {
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
} }
cachedCosmeticItems.put(cosmetic.getSlot(), item);
return item; return item;
} }
@@ -386,7 +334,7 @@ public class CosmeticUser {
return userWardrobeManager; return userWardrobeManager;
} }
public void enterWardrobe(boolean ignoreDistance, @NotNull Wardrobe wardrobe) { public void enterWardrobe(boolean ignoreDistance, Wardrobe wardrobe) {
if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) { if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) {
MessagesUtil.sendMessage(getPlayer(), "no-permission"); MessagesUtil.sendMessage(getPlayer(), "no-permission");
return; return;
@@ -487,6 +435,10 @@ public class CosmeticUser {
public void despawnBalloon() { public void despawnBalloon() {
if (this.userBalloonManager == null) return; if (this.userBalloonManager == null) return;
List<Player> sentTo = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation());
HMCCPacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo);
this.userBalloonManager.remove(); this.userBalloonManager.remove();
this.userBalloonManager = null; this.userBalloonManager = null;
} }

View File

@@ -1,24 +1,28 @@
package com.hibiscusmc.hmccosmetics.user.manager; package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.ModelEngineAPI; import com.ticxo.modelengine.api.ModelEngineAPI;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter; import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks; import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.util.ServerUtils; import me.lojosho.hibiscuscommons.util.ServerUtils;
import me.lojosho.hibiscuscommons.util.packets.PacketManager; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
@@ -27,23 +31,26 @@ public class UserBackpackManager {
@Getter @Getter
private boolean backpackHidden; private boolean backpackHidden;
@Getter @Getter
private int invisibleArmorStand; private int itemDisplayId;
private ArrayList<Integer> particleCloud = new ArrayList<>(); private ArrayList<Integer> particleCloud = new ArrayList<>();
@Getter @Getter
private final CosmeticUser user; private final CosmeticUser user;
@Getter @Getter
private UserEntity entityManager; private UserEntity entityManager;
//@Getter @Setter
//private boolean inBlock;
public UserBackpackManager(CosmeticUser user) { public UserBackpackManager(CosmeticUser user) {
this.user = user; this.user = user;
this.backpackHidden = false; this.backpackHidden = false;
this.invisibleArmorStand = ServerUtils.getNextEntityId(); //this.inBlock = false;
this.itemDisplayId = ServerUtils.getNextEntityId();
this.entityManager = new UserEntity(user.getUniqueId()); this.entityManager = new UserEntity(user.getUniqueId());
if (user.getEntity() != null) this.entityManager.refreshViewers(user.getEntity().getLocation()); // Fixes an issue where a player, who somehow removes their potions, but doesn't have an entity produces an NPE (it's dumb) if (user.getEntity() != null) this.entityManager.refreshViewers(user.getEntity().getLocation()); // Fixes an issue where a player, who somehow removes their potions, but doesn't have an entity produces an NPE (it's dumb)
} }
public int getFirstArmorStandId() { public int getFirstItemDisplayId() {
return invisibleArmorStand; return itemDisplayId;
} }
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
@@ -53,11 +60,12 @@ public class UserBackpackManager {
} }
private void spawn(CosmeticBackpackType cosmeticBackpackType) { private void spawn(CosmeticBackpackType cosmeticBackpackType) {
getEntityManager().setIds(List.of(invisibleArmorStand)); Location entityLoc = user.getEntity().getLocation();
getEntityManager().teleport(user.getEntity().getLocation()); entityLoc.setPitch(0f);
getEntityManager().setIds(List.of(itemDisplayId));
getEntityManager().teleport(entityLoc);
List<Player> outsideViewers = getEntityManager().getViewers(); List<Player> outsideViewers = getEntityManager().getViewers();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers()); HMCCPacketManager.sendEntitySpawnPacket(entityLoc, getFirstItemDisplayId(), EntityType.ITEM_DISPLAY, UUID.randomUUID(), getEntityManager().getViewers());
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
Entity entity = user.getEntity(); Entity entity = user.getEntity();
@@ -67,12 +75,12 @@ public class UserBackpackManager {
passengerIDs[i] = entity.getPassengers().get(i).getEntityId(); passengerIDs[i] = entity.getPassengers().get(i).getEntityId();
} }
passengerIDs[passengerIDs.length - 1] = this.getFirstArmorStandId(); passengerIDs[passengerIDs.length - 1] = this.getFirstItemDisplayId();
ArrayList<Player> owner = new ArrayList<>(); ArrayList<Player> owner = new ArrayList<>();
if (user.getPlayer() != null) owner.add(user.getPlayer()); if (user.getPlayer() != null) owner.add(user.getPlayer());
if (cosmeticBackpackType.isFirstPersonCompadible()) { if (cosmeticBackpackType.isFirstPersonCompatible()) {
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) { for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
int entityId = ServerUtils.getNextEntityId(); int entityId = ServerUtils.getNextEntityId();
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID()); HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
@@ -84,10 +92,11 @@ public class UserBackpackManager {
if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner); if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
else HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner); else HMCCPacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner);
} }
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner); HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1),getFirstItemDisplayId(), owner);
if (!user.isHidden()) PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner); if (!user.isHidden()) HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), cosmeticBackpackType.getFirstPersonMetadata(), user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), outsideViewers);
} }
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), cosmeticBackpackType.getMetadata(), user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), passengerIDs, outsideViewers); HMCCPacketManager.sendRidingPacket(entity.getEntityId(), passengerIDs, outsideViewers);
// No one should be using ME because it barely works but some still use it, so it's here // No one should be using ME because it barely works but some still use it, so it's here
@@ -108,13 +117,13 @@ public class UserBackpackManager {
} }
public void despawnBackpack() { public void despawnBackpack() {
HMCCPacketManager.sendEntityDestroyPacket(invisibleArmorStand, getEntityManager().getViewers()); IntList entityIds = IntArrayList.of(itemDisplayId);
if (particleCloud != null) { if (particleCloud != null) {
for (Integer entityId : particleCloud) { entityIds.addAll(particleCloud);
HMCCPacketManager.sendEntityDestroyPacket(entityId, getEntityManager().getViewers());
}
this.particleCloud = null; this.particleCloud = null;
} }
HMCCPacketManager.sendEntityDestroyPacket(entityIds, getEntityManager().getViewers());
} }
public void hideBackpack() { public void hideBackpack() {
@@ -140,11 +149,42 @@ public class UserBackpackManager {
} }
public void setItem(ItemStack item) { public void setItem(ItemStack item) {
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers()); ItemDisplayMetadata metadata = Optional.ofNullable((CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK)).map(CosmeticBackpackType::getMetadata).orElse(new ItemDisplayMetadata());
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), metadata, item, getEntityManager().getViewers());
} }
public void clearItems() { public void clearItems() {
ItemStack item = new ItemStack(Material.AIR); ItemStack item = new ItemStack(Material.AIR);
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers()); //PacketManager.equipmentSlotUpdate(getFirstItemDisplayId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers());
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), item, getEntityManager().getViewers());
} }
/**
* Refreshes the block detection for the backpack
* @param outsideViewers
* @return true if the entity was updated, false if not
*//*
public boolean refreshBlock(List<Player> outsideViewers) {
if (Settings.isBackpackBlockDetection()) {
if (isInBlock() && checkBlock()) {
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), false, outsideViewers);
setInBlock(false);
return true;
}
if (!isInBlock() && !checkBlock()) {
HMCCPacketManager.sendItemDisplayMetadata(getFirstItemDisplayId(), true, outsideViewers);
setInBlock(true);
return true;
}
}
return false;
}
public boolean checkBlock() {
if (Settings.isBackpackBlockDetection()) {
Block block = getEntityManager().getLocation().clone().add(0, 1.5, 0).getBlock();
return block.getType().isAir();
}
return false;
}*/
} }

View File

@@ -11,7 +11,6 @@ import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.entity.data.BukkitEntityData; import com.ticxo.modelengine.api.entity.data.BukkitEntityData;
import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity; import com.ticxo.modelengine.api.model.ModeledEntity;
import com.ticxo.modelengine.api.nms.RenderParsers;
import lombok.Getter; import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks; import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers; import me.lojosho.hibiscuscommons.nms.NMSHandlers;
@@ -31,17 +30,16 @@ import java.util.logging.Level;
public class UserBalloonManager { public class UserBalloonManager {
private final CosmeticUser user; private CosmeticUser user;
@Getter @Getter
private BalloonType balloonType; private BalloonType balloonType;
private CosmeticBalloonType cosmeticBalloonType; private CosmeticBalloonType cosmeticBalloonType;
@Getter @Getter
private UserBalloonPufferfish pufferfish; private UserBalloonPufferfish pufferfish;
private final ArmorStand modelEntity; private final ArmorStand modelEntity;
public UserBalloonManager(CosmeticUser user, @NotNull Location location) { public UserBalloonManager(CosmeticUser user, @NotNull Location location) {
this.user = user; this.user = user;
this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getUtilHandler().getNextEntityId(), UUID.randomUUID()); this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID());
this.modelEntity = location.getWorld().spawn(location, ArmorStand.class, (e) -> { this.modelEntity = location.getWorld().spawn(location, ArmorStand.class, (e) -> {
e.setInvisible(true); e.setInvisible(true);
e.setGravity(false); e.setGravity(false);
@@ -84,7 +82,7 @@ public class UserBalloonManager {
modeledEntity.getModels().forEach((d, singleModel) -> { modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) { if (cosmeticBalloonType.isDyablePart(d)) {
singleModel.setDefaultTint(color); singleModel.setDefaultTint(color);
singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers()); singleModel.getModelRenderer().sendToClient();
} }
}); });
} }
@@ -100,7 +98,6 @@ public class UserBalloonManager {
} }
public void remove() { public void remove() {
pufferfish.destroyPufferfish();
if (balloonType == BalloonType.MODELENGINE) { if (balloonType == BalloonType.MODELENGINE) {
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(modelEntity); final ModeledEntity entity = ModelEngineAPI.getModeledEntity(modelEntity);
if (entity == null) { if (entity == null) {
@@ -159,7 +156,6 @@ public class UserBalloonManager {
public int getPufferfishBalloonId() { public int getPufferfishBalloonId() {
return pufferfish.getPufferFishEntityId(); return pufferfish.getPufferFishEntityId();
} }
public UUID getPufferfishBalloonUniqueId() { public UUID getPufferfishBalloonUniqueId() {
return pufferfish.getUuid(); return pufferfish.getUuid();
} }

View File

@@ -3,10 +3,7 @@ package com.hibiscusmc.hmccosmetics.user.manager;
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;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -17,11 +14,8 @@ import java.util.UUID;
public class UserBalloonPufferfish extends UserEntity { public class UserBalloonPufferfish extends UserEntity {
@Getter private int pufferFishEntityId;
private final int pufferFishEntityId; private UUID uuid;
@Getter
private final UUID uuid;
private boolean destroyed = false;
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) { public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
super(owner); super(owner);
@@ -29,6 +23,14 @@ public class UserBalloonPufferfish extends UserEntity {
this.uuid = uuid; this.uuid = uuid;
} }
public int getPufferFishEntityId() {
return pufferFishEntityId;
}
public UUID getUuid() {
return uuid;
}
public void hidePufferfish() { public void hidePufferfish() {
HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers()); HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers());
getViewers().clear(); getViewers().clear();
@@ -39,15 +41,35 @@ public class UserBalloonPufferfish extends UserEntity {
HMCCPacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo); HMCCPacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo);
} }
public void destroyPufferfish() {
HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers());
getViewers().clear();
destroyed = true;
}
@Override @Override
public List<Player> refreshViewers(Location location) { public List<Player> refreshViewers(Location location) {
if (destroyed) return List.of(); //Prevents refreshing a destroyed entity if (System.currentTimeMillis() - getViewerLastUpdate() <= 1000) return List.of(); //Prevents mass refreshes
return super.refreshViewers(location); ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = HMCCPlayerUtils.getNearbyPlayers(location);
for (Player player : players) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user != null && getOwner() != user.getUniqueId() && user.isInWardrobe()) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
removePlayers.add(player);
HMCCPacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(player));
continue;
}
if (!getViewers().contains(player)) {
getViewers().add(player);
newPlayers.add(player);
continue;
}
// bad loopdy loops
for (Player viewerPlayer : getViewers()) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
HMCCPacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(viewerPlayer));
}
}
}
getViewers().removeAll(removePlayers);
setViewerLastUpdate(System.currentTimeMillis());
return newPlayers;
} }
} }

View File

@@ -23,13 +23,13 @@ public class UserEmoteModel extends PlayerModel {
private final CosmeticUser user; private final CosmeticUser user;
private String emotePlaying; private String emotePlaying;
private final int armorStandId; private final int itemDisplayId;
private GameMode originalGamemode; private GameMode originalGamemode;
public UserEmoteModel(@NotNull CosmeticUser user) { public UserEmoteModel(@NotNull CosmeticUser user) {
super(user.getPlayer()); super(user.getPlayer());
this.user = user; this.user = user;
armorStandId = ServerUtils.getNextEntityId(); itemDisplayId = ServerUtils.getNextEntityId();
getRangeManager().setRenderDistance(Settings.getViewDistance()); getRangeManager().setRenderDistance(Settings.getViewDistance());
} }
@@ -75,12 +75,12 @@ public class UserEmoteModel extends PlayerModel {
MessagesUtil.sendMessage(player, "emote-blocked"); MessagesUtil.sendMessage(player, "emote-blocked");
} }
HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer); HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, itemDisplayId, EntityType.ITEM_DISPLAY, UUID.randomUUID(), viewer);
HMCCPacketManager.sendInvisibilityPacket(armorStandId, viewer); //HMCCPacketManager.sendInvisibilityPacket(itemDisplayId, viewer);
HMCCPacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer); HMCCPacketManager.sendLookPacket(itemDisplayId, thirdPersonLocation, viewer);
HMCCPacketManager.gamemodeChangePacket(player, 3); HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(armorStandId, viewer); HMCCPacketManager.sendCameraPacket(itemDisplayId, viewer);
} }
@@ -115,7 +115,7 @@ public class UserEmoteModel extends PlayerModel {
int entityId = player.getEntityId(); int entityId = player.getEntityId();
HMCCPacketManager.sendCameraPacket(entityId, viewer); HMCCPacketManager.sendCameraPacket(entityId, viewer);
HMCCPacketManager.sendEntityDestroyPacket(armorStandId, viewer); HMCCPacketManager.sendEntityDestroyPacket(itemDisplayId, viewer);
if (this.originalGamemode != null) { if (this.originalGamemode != null) {
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode)); HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode));
player.setGameMode(this.originalGamemode); player.setGameMode(this.originalGamemode);

View File

@@ -4,11 +4,11 @@ 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;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -44,15 +44,11 @@ public class UserEntity {
ArrayList<Player> newPlayers = new ArrayList<>(); ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>(); ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = HMCCPlayerUtils.getNearbyPlayers(location); List<Player> players = HMCCPlayerUtils.getNearbyPlayers(location);
Player ownerPlayer = Bukkit.getPlayer(owner);
if (ownerPlayer == null) {
MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list");
return List.of();
}
for (Player player : players) { for (Player player : players) {
CosmeticUser user = CosmeticUsers.getUser(player); CosmeticUser user = CosmeticUsers.getUser(player);
if (user != null && owner != user.getUniqueId() && user.isInWardrobe() && !player.canSee(ownerPlayer)) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe IntList ids = new IntArrayList(this.ids);
if (user != null && owner != user.getUniqueId() && user.isInWardrobe()) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
removePlayers.add(player); removePlayers.add(player);
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(player)); HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(player));
continue; continue;

View File

@@ -6,6 +6,7 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeLocation;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.gui.Menu; import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus; import com.hibiscusmc.hmccosmetics.gui.Menus;
@@ -13,6 +14,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils; import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils; import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@@ -41,7 +43,7 @@ public class UserWardrobeManager {
@Getter @Getter
private final int NPC_ID; private final int NPC_ID;
@Getter @Getter
private final int ARMORSTAND_ID; private final int ITEM_DISPLAY_ID;
@Getter @Getter
private final UUID WARDROBE_UUID; private final UUID WARDROBE_UUID;
@Getter @Getter
@@ -72,7 +74,7 @@ public class UserWardrobeManager {
public UserWardrobeManager(CosmeticUser user, Wardrobe wardrobe) { public UserWardrobeManager(CosmeticUser user, Wardrobe wardrobe) {
NPC_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId(); NPC_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId();
ARMORSTAND_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId(); ITEM_DISPLAY_ID = me.lojosho.hibiscuscommons.util.ServerUtils.getNextEntityId();
WARDROBE_UUID = UUID.randomUUID(); WARDROBE_UUID = UUID.randomUUID();
this.user = user; this.user = user;
@@ -83,11 +85,8 @@ public class UserWardrobeManager {
this.viewingLocation = wardrobeLocation.getViewerLocation(); this.viewingLocation = wardrobeLocation.getViewerLocation();
this.npcLocation = wardrobeLocation.getNpcLocation(); this.npcLocation = wardrobeLocation.getNpcLocation();
String defaultMenu = wardrobe.getDefaultMenu();
if (defaultMenu != null && Menus.hasMenu(defaultMenu)) this.lastOpenMenu = Menus.getMenu(defaultMenu);
else this.lastOpenMenu = Menus.getDefaultMenu();
wardrobeStatus = WardrobeStatus.SETUP; wardrobeStatus = WardrobeStatus.SETUP;
this.lastOpenMenu = Menus.getDefaultMenu();
} }
public void start() { public void start() {
@@ -108,16 +107,16 @@ public class UserWardrobeManager {
MessagesUtil.sendMessage(player, "opened-wardrobe"); MessagesUtil.sendMessage(player, "opened-wardrobe");
Runnable run = () -> { Runnable run = () -> {
// Armorstand // ItemDisplay
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer); HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ITEM_DISPLAY_ID, EntityType.ITEM_DISPLAY, UUID.randomUUID(), viewer);
HMCCPacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer); HMCCPacketManager.sendItemDisplayMetadata(ITEM_DISPLAY_ID, new ItemStack(Material.AIR), viewer);
HMCCPacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer); HMCCPacketManager.sendLookPacket(ITEM_DISPLAY_ID, viewingLocation, viewer);
// Player // Player
user.getPlayer().teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN); user.getPlayer().teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
user.getPlayer().setInvisible(true); user.getPlayer().setInvisible(true);
HMCCPacketManager.gamemodeChangePacket(player, 3); HMCCPacketManager.gamemodeChangePacket(player, 3);
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer); HMCCPacketManager.sendCameraPacket(ITEM_DISPLAY_ID, viewer);
// NPC // NPC
npcName = "WardrobeNPC-" + NPC_ID; npcName = "WardrobeNPC-" + NPC_ID;
@@ -132,7 +131,7 @@ public class UserWardrobeManager {
HMCCPacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer); HMCCPacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer);
HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer); HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation); MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName); NMSHandlers.getHandler().hideNPCName(player, npcName);
}, 4); }, 4);
// Location // Location
@@ -142,11 +141,13 @@ public class UserWardrobeManager {
// Misc // Misc
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
// Maybe null as backpack maybe despawned before entering // Maybe null as backpack maybe despawned before entering
if (user.getUserBackpackManager() == null) user.respawnBackpack(); UserBackpackManager userBackpackManager = user.getUserBackpackManager();
if (userBackpackManager == null) user.respawnBackpack();
if (user.isBackpackSpawned()) { if (user.isBackpackSpawned()) {
user.getUserBackpackManager().getEntityManager().teleport(npcLocation.clone().add(0, 2, 0)); userBackpackManager.getEntityManager().teleport(npcLocation.clone());
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(user.getCosmetic(CosmeticSlot.BACKPACK)), viewer); CosmeticBackpackType backpackCosmetic = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK);
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer); HMCCPacketManager.sendItemDisplayMetadata(ITEM_DISPLAY_ID, backpackCosmetic.getMetadata(), user.getUserCosmeticItem(backpackCosmetic), viewer);
HMCCPacketManager.ridingMountPacket(NPC_ID, userBackpackManager.getFirstItemDisplayId(), viewer);
} }
} }
@@ -235,7 +236,7 @@ public class UserWardrobeManager {
user.getPlayer().setInvisible(false); user.getPlayer().setInvisible(false);
// Armorstand // Armorstand
HMCCPacketManager.sendEntityDestroyPacket(ARMORSTAND_ID, viewer); // Sucess HMCCPacketManager.sendEntityDestroyPacket(ITEM_DISPLAY_ID, viewer); // Sucess
//PacketManager.sendEntityDestroyPacket(player.getEntityId(), viewer); // Success //PacketManager.sendEntityDestroyPacket(player.getEntityId(), viewer); // Success
if (WardrobeSettings.isForceExitGamemode()) { if (WardrobeSettings.isForceExitGamemode()) {
@@ -318,10 +319,10 @@ public class UserWardrobeManager {
} }
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().getFirstItemDisplayId(), location, false, viewer);
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer); HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstItemDisplayId(), viewer);
user.getUserBackpackManager().getEntityManager().setRotation(nextyaw); user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstItemDisplayId(), outsideViewers);
} }
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON) && user.isBalloonSpawned()) { if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON) && user.isBalloonSpawned()) {

View File

@@ -63,7 +63,6 @@ public class HMCCInventoryUtils {
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;
}; };
} }

View File

@@ -33,7 +33,7 @@ public class HMCCServerUtils {
} }
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().getEntity(entityId);
} }
/** /**

View File

@@ -0,0 +1,49 @@
package com.hibiscusmc.hmccosmetics.util.misc;
import org.bukkit.Material;
import org.bukkit.entity.Display;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.inventory.ItemStack;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import java.util.HashMap;
import java.util.Map;
public class ItemDisplayMetadata {
public Vector3f translation;
public Vector3f scale;
public Quaternionf rotationLeft;
public Quaternionf rotationRight;
public Display.Billboard billboard;
public int skyLight;
public float viewRange;
public float width;
public float height;
public ItemDisplay.ItemDisplayTransform displayTransform;
public ItemStack itemStack;
public ItemDisplayMetadata() {
this.translation = new Vector3f();
this.scale = new Vector3f(1.0f, 1.0f, 1.0f);
this.rotationLeft = new Quaternionf();
this.rotationRight = new Quaternionf();
this.skyLight = 15;
this.viewRange = 1.0f;
this.width = 0.0f;
this.height = 0.0f;
this.displayTransform = ItemDisplay.ItemDisplayTransform.NONE;
this.itemStack = new ItemStack(Material.AIR);
}
public ItemDisplayMetadata setFixed() {
this.billboard = Display.Billboard.FIXED;
return this;
}
public ItemDisplayMetadata setVertical() {
this.billboard = Display.Billboard.VERTICAL;
return this;
}
}

View File

@@ -12,17 +12,22 @@ 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 com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils; import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
import com.hibiscusmc.hmccosmetics.util.misc.ItemDisplayMetadata;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn; import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo; import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove; 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.Display;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player; 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.*; import java.util.*;
@@ -33,7 +38,7 @@ public class HMCCPacketManager extends PacketManager {
final int entityId, final int entityId,
final EntityType entityType, final EntityType entityType,
final UUID uuid final UUID uuid
) { ) {
sendEntitySpawnPacket(location, entityId, entityType, uuid, getViewers(location)); sendEntitySpawnPacket(location, entityId, entityType, uuid, getViewers(location));
} }
@@ -44,16 +49,7 @@ public class HMCCPacketManager extends PacketManager {
final UUID uuid, final UUID uuid,
final @NotNull List<Player> sendTo final @NotNull List<Player> sendTo
) { ) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY); PacketManager.sendEntitySpawnPacket(location, entityId, entityType, uuid, sendTo);
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(
@@ -96,20 +92,17 @@ 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( public static void sendItemDisplayMetadata(int entityId, ItemStack itemStack, List<Player> sendTo) {
int entityId, ItemDisplayMetadata metadata = new ItemDisplayMetadata();
List<Player> sendTo PacketManager.sendItemDisplayMetadataPacket(entityId, metadata.translation, metadata.scale, metadata.rotationLeft, metadata.rotationRight, metadata.billboard, 0, metadata.skyLight, metadata.viewRange, metadata.width, metadata.height, metadata.displayTransform, itemStack, 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) public static void sendItemDisplayMetadata(int entityId, ItemDisplayMetadata metadata, List<Player> sendTo) {
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x21)); PacketManager.sendItemDisplayMetadataPacket(entityId, metadata.translation, metadata.scale, metadata.rotationLeft, metadata.rotationRight, metadata.billboard, 0, metadata.skyLight, metadata.viewRange, metadata.width, metadata.height, metadata.displayTransform, metadata.itemStack, sendTo);
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 sendItemDisplayMetadata(int entityId, ItemDisplayMetadata metadata, ItemStack itemStack, List<Player> sendTo) {
PacketManager.sendItemDisplayMetadataPacket(entityId, metadata.translation, metadata.scale, metadata.rotationLeft, metadata.rotationRight, metadata.billboard, 0, metadata.skyLight, metadata.viewRange, metadata.width, metadata.height, metadata.displayTransform, itemStack, sendTo);
} }
public static void sendInvisibilityPacket( public static void sendInvisibilityPacket(

View File

@@ -24,12 +24,6 @@ cosmetic-settings:
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server. force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server.
force-show-join: false # If the plugin should force show a player's cosmetics when they join the server. force-show-join: false # If the plugin should force show a player's cosmetics when they join the server.
# This determines what to process what areas to process placeholders when displaying the item to the user.
# This can be heavy on servers with a lot of players, so if experiencing lag issues relating to setting display/lores of items, disable this.
item-processing:
display-name: true
lore: true
# This is a list of worlds that cosmetics are hidden in. When a player enters one of these worlds, their cosmetics will be hidden. # This is a list of worlds that cosmetics are hidden in. When a player enters one of these worlds, their cosmetics will be hidden.
disabled-worlds: disabled-worlds:
- "disabledworld" - "disabledworld"
@@ -51,8 +45,17 @@ cosmetic-settings:
emote-camera: true emote-camera: true
# If a player should be able to move in an emote. This option really only affects if "emote-camera" is false # If a player should be able to move in an emote. This option really only affects if "emote-camera" is false
emote-move: false emote-move: false
# This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers. # This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers.
backpack-force-riding-packet: false backpack-force-riding-packet: false
# This makes the plugin either (true) always have the backpack eminate light to avoid the black backpack bug or (false) turns it off.
backpack-light-emination: true
# This activates the block detection for the backpack. This allows backpacks to not appear completely black when in a block.
# Requires backpack-light-emination to be true.
backpack-block-detection: true
# This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable. # This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable.
# This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located. # This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located.
entity-cooldown-teleport-packet: 500 entity-cooldown-teleport-packet: 500
@@ -129,9 +132,6 @@ hook-settings:
# This causes the plugin to reload itself after any ItemsAdder change. This keeps the plugin fully up to date with IA, but # This causes the plugin to reload itself after any ItemsAdder change. This keeps the plugin fully up to date with IA, but
# could cause console spam as HMCCosmetics has to reload itself as well. # could cause console spam as HMCCosmetics has to reload itself as well.
reload-on-change: false reload-on-change: false
nexo:
# This causes the plugin to reload itself after any Nexo change. This keeps the plugin fully up to date with Nexo
reload-on-change: true
worldguard: worldguard:
# Checks worldguard regions for HMCC flags. If set to false, flags will not work properly. # Checks worldguard regions for HMCC flags. If set to false, flags will not work properly.
# Requires restart to apply changes. # Requires restart to apply changes.
@@ -177,7 +177,6 @@ wardrobe:
default: default:
distance: -1 # Distance in blocks that a player can interact with the wardrobe. -1 to ignore. distance: -1 # Distance in blocks that a player can interact with the wardrobe. -1 to ignore.
permission: "hmccosmetics.wardrobe.default" # Permission required to use the wardrobe. permission: "hmccosmetics.wardrobe.default" # Permission required to use the wardrobe.
default-menu: defaultmenu
npc-location: npc-location:
world: "world" world: "world"
x: 0 x: 0

Binary file not shown.

View File

@@ -1,7 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

51
gradlew vendored
View File

@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Copyright © 2015-2021 the original authors. # Copyright <EFBFBD> 2015-2021 the original authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script # Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features: # requires all of these POSIX shell features:
# * functions; # * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», # * expansions <EFBFBD>$var<EFBFBD>, <EFBFBD>${var}<EFBFBD>, <EFBFBD>${var:-default}<EFBFBD>, <EFBFBD>${var+SET}<EFBFBD>,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»; # <EFBFBD>${var#prefix}<EFBFBD>, <EFBFBD>${var%suffix}<EFBFBD>, and <EFBFBD>$( cmd )<EFBFBD>;
# * compound commands having a testable exit status, especially «case»; # * compound commands having a testable exit status, especially <EFBFBD>case<EFBFBD>;
# * various built-in commands including «command», «set», and «ulimit». # * various built-in commands including <EFBFBD>command<EFBFBD>, <EFBFBD>set<EFBFBD>, and <EFBFBD>ulimit<EFBFBD>.
# #
# Important for patching: # Important for patching:
# #
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,11 +80,13 @@ do
esac esac
done done
# This is normally unused APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -131,29 +133,22 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
if ! command -v java >/dev/null 2>&1 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@@ -198,15 +193,11 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# Collect all arguments for the java command: # * put everything else in single quotes, so that it's not re-expanded.
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
@@ -214,12 +205,6 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \ org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args. # Use "xargs" to parse quoted args.
# #
# With -n1 it outputs one arg per line, with the quotes and backslashes removed. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.

15
gradlew.bat vendored
View File

@@ -14,7 +14,7 @@
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@@ -25,8 +25,7 @@
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=. if "%DIRNAME%" == "" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@@ -41,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -76,15 +75,13 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd if "%ERRORLEVEL%"=="0" goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL% if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
if %EXIT_CODE% equ 0 set EXIT_CODE=1 exit /b 1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal