mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Compare commits
256 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e2b2edadd | ||
|
|
7e384fcd79 | ||
|
|
e88b84610e | ||
|
|
223ffa46eb | ||
|
|
f408108682 | ||
|
|
b9f9448367 | ||
|
|
c40aca9946 | ||
|
|
98d2692def | ||
|
|
ebbc80c465 | ||
|
|
775699d9ca | ||
|
|
b0ba5fc011 | ||
|
|
af01ff600b | ||
|
|
2e4619da02 | ||
|
|
b4bd08c249 | ||
|
|
19981b33d3 | ||
|
|
c7c4c0e583 | ||
|
|
935c157421 | ||
|
|
20a3a508c2 | ||
|
|
92b75c43ab | ||
|
|
a6ad2c19aa | ||
|
|
fe8b4c97ff | ||
|
|
8c119c78db | ||
|
|
ce33a72fc2 | ||
|
|
2a8f30636d | ||
|
|
4103c2c232 | ||
|
|
fb5c9d205c | ||
|
|
126d576303 | ||
|
|
c74b76837b | ||
|
|
d2c37f8273 | ||
|
|
dbadbda82f | ||
|
|
d66aa3b79c | ||
|
|
1c5cd7b467 | ||
|
|
10f8dda150 | ||
|
|
e76aa0783e | ||
|
|
0676125f07 | ||
|
|
7aef681149 | ||
|
|
d5ac55f266 | ||
|
|
c2b787c97c | ||
|
|
732c3de0d8 | ||
|
|
3843a28804 | ||
|
|
a63494ba9f | ||
|
|
c7e6a77eb8 | ||
|
|
075d2b3182 | ||
|
|
515de7d2c8 | ||
|
|
429287c9f3 | ||
|
|
fed13b8ee6 | ||
|
|
8011dda200 | ||
|
|
7abfb0edf1 | ||
|
|
1f8c772712 | ||
|
|
7d727bb68f | ||
|
|
007f27f109 | ||
|
|
e0e0d0c997 | ||
|
|
75a1458ae1 | ||
|
|
548b15d99d | ||
|
|
50f04373b7 | ||
|
|
27a6c1bd54 | ||
|
|
bb08fb108c | ||
|
|
3907bc5839 | ||
|
|
1ef7f4759f | ||
|
|
937f66e8c5 | ||
|
|
158f3afdec | ||
|
|
38bdc01e9f | ||
|
|
797992362a | ||
|
|
9716a079be | ||
|
|
dfe51ba5b8 | ||
|
|
f5e81446a6 | ||
|
|
c99a57a6bf | ||
|
|
79630263f2 | ||
|
|
478c4280c1 | ||
|
|
4fd439acc4 | ||
|
|
58c955a00f | ||
|
|
2f9325b2fb | ||
|
|
823270648b | ||
|
|
d5e988261b | ||
|
|
13303096ec | ||
|
|
3ee79e8443 | ||
|
|
7785556967 | ||
|
|
1296ca6e92 | ||
|
|
f56d5c9093 | ||
|
|
bae04fba3f | ||
|
|
cbe5404399 | ||
|
|
dc4098782a | ||
|
|
2eb0b26fb3 | ||
|
|
22159fa9f4 | ||
|
|
539c09801c | ||
|
|
bed5cd7bbb | ||
|
|
4a1a631557 | ||
|
|
ad282a9efe | ||
|
|
86ef4d0efa | ||
|
|
da09a542f1 | ||
|
|
62f32cc03d | ||
|
|
ff1addfd65 | ||
|
|
73f013bf1f | ||
|
|
204fee4456 | ||
|
|
e7ea62a4d2 | ||
|
|
42802e41b4 | ||
|
|
7e7d81d0f8 | ||
|
|
b07c3c9878 | ||
|
|
a19d564460 | ||
|
|
b3408143f0 | ||
|
|
3c1539285d | ||
|
|
a642d88af2 | ||
|
|
36d4009f5e | ||
|
|
bebee807bc | ||
|
|
26c579b69f | ||
|
|
ef665e7e83 | ||
|
|
7a6475c467 | ||
|
|
63963cccc3 | ||
|
|
7cf6a3c75c | ||
|
|
22a5bb4cf1 | ||
|
|
148d163d9c | ||
|
|
ef36e66c51 | ||
|
|
e5fda588c3 | ||
|
|
3baf2694be | ||
|
|
a1dafdee5b | ||
|
|
e3a42d8b4a | ||
|
|
b366f5930b | ||
|
|
45eb1fa668 | ||
|
|
c466405a81 | ||
|
|
172ffc0333 | ||
|
|
41ac857a11 | ||
|
|
737d63642c | ||
|
|
7b9b7678a3 | ||
|
|
fe88d0c608 | ||
|
|
e14935af7b | ||
|
|
3e83d370f8 | ||
|
|
874a7f5624 | ||
|
|
3af992a291 | ||
|
|
9ef7791998 | ||
|
|
1cbe17ddd4 | ||
|
|
2841742af9 | ||
|
|
6e2f333404 | ||
|
|
af8949b713 | ||
|
|
d6f7d0fcb3 | ||
|
|
a8f035bbe2 | ||
|
|
301fd6a349 | ||
|
|
90b71e7dc9 | ||
|
|
e6827cdf72 | ||
|
|
1212ab2025 | ||
|
|
e31f000de6 | ||
|
|
70028598d5 | ||
|
|
07b772d228 | ||
|
|
065e48c125 | ||
|
|
49eb1d61ef | ||
|
|
9e1a30025f | ||
|
|
76429ed041 | ||
|
|
f5a01c0104 | ||
|
|
545f258f90 | ||
|
|
720437212b | ||
|
|
d932732d9b | ||
|
|
1118be1153 | ||
|
|
1dc549d645 | ||
|
|
4136d19396 | ||
|
|
52de7425e4 | ||
|
|
f470e55142 | ||
|
|
470de3b749 | ||
|
|
ea72499826 | ||
|
|
6b19bf442a | ||
|
|
436de38102 | ||
|
|
4bb00071d4 | ||
|
|
650cf75168 | ||
|
|
0d07e8a267 | ||
|
|
b7ec587d7d | ||
|
|
e807c7e2f7 | ||
|
|
15e1f0aaa9 | ||
|
|
f1e975f940 | ||
|
|
89fba800a4 | ||
|
|
863275a2ce | ||
|
|
b516cfced4 | ||
|
|
28034318ac | ||
|
|
c2e4764ace | ||
|
|
948bfb17f5 | ||
|
|
6c98b7696a | ||
|
|
2c4638fa47 | ||
|
|
ced2fe7b03 | ||
|
|
3a56f074fa | ||
|
|
dca5abe4ec | ||
|
|
1dd54ea1cb | ||
|
|
b81af97573 | ||
|
|
74d64b16d2 | ||
|
|
2174ec6124 | ||
|
|
1de84bce6f | ||
|
|
3aa5939225 | ||
|
|
44650250c5 | ||
|
|
49fff9b650 | ||
|
|
190f66a990 | ||
|
|
8a34f100d3 | ||
|
|
79687a22fc | ||
|
|
f5fac4e048 | ||
|
|
eac0812dbb | ||
|
|
93f5bfbb2a | ||
|
|
94cba225a6 | ||
|
|
ab614d8b07 | ||
|
|
e7fd39a077 | ||
|
|
530cdb282b | ||
|
|
97534f6916 | ||
|
|
22fb52acc6 | ||
|
|
cf0da580e0 | ||
|
|
64a590b581 | ||
|
|
afb3218bc1 | ||
|
|
170911a6a1 | ||
|
|
ea5b878f74 | ||
|
|
88af1cd68e | ||
|
|
34237e0a45 | ||
|
|
a037487497 | ||
|
|
e7b1fda73e | ||
|
|
c591641754 | ||
|
|
2a0aa1593a | ||
|
|
330723a45c | ||
|
|
f6a1438299 | ||
|
|
1f0f8e5f70 | ||
|
|
216c05ed9b | ||
|
|
89fbacafac | ||
|
|
8c45bfc76b | ||
|
|
4ad3c02d88 | ||
|
|
477729242b | ||
|
|
e96d06892a | ||
|
|
5b1b91f119 | ||
|
|
446e629474 | ||
|
|
57c2cd0719 | ||
|
|
8f2a01b348 | ||
|
|
6fe5817fd7 | ||
|
|
663b3d1647 | ||
|
|
bf0a372edd | ||
|
|
5d0237e28c | ||
|
|
349311cb58 | ||
|
|
a1098641b5 | ||
|
|
8c0ca5083d | ||
|
|
c42ecadd90 | ||
|
|
735386718e | ||
|
|
95459cc2d2 | ||
|
|
fe52edd833 | ||
|
|
d659128ae4 | ||
|
|
397eebf38f | ||
|
|
e18690496f | ||
|
|
c522581d46 | ||
|
|
c31d2e1aee | ||
|
|
9879c82d40 | ||
|
|
1873f5b9b5 | ||
|
|
68d94be743 | ||
|
|
14e38e7974 | ||
|
|
5cc19ab2db | ||
|
|
93b1c20c40 | ||
|
|
49435436cb | ||
|
|
0477e801a6 | ||
|
|
5779d278a9 | ||
|
|
0a8821d3e8 | ||
|
|
e96e9e00bb | ||
|
|
217fb5d332 | ||
|
|
6636cc9548 | ||
|
|
c3fcf760d7 | ||
|
|
7116767e22 | ||
|
|
0877165f9f | ||
|
|
b43466a793 | ||
|
|
401e6170e6 | ||
|
|
782eb4c464 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -115,3 +115,4 @@ run/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
/qodana.yaml
|
||||
|
||||
@@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.hibiscusmc"
|
||||
version = "2.7.4${getGitCommitHash()}"
|
||||
version = "2.8.3${getGitCommitHash()}"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
@@ -16,16 +16,16 @@ allprojects {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
|
||||
// Paper Repo
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
|
||||
// Jitpack
|
||||
maven("https://jitpack.io")
|
||||
|
||||
// ProtocolLib repo
|
||||
maven("https://repo.dmulloy2.net/repository/public/") //ProtocolLib Repo, constantly down
|
||||
// Geary
|
||||
maven("https://repo.mineinabyss.com/releases/")
|
||||
maven("https://repo.mineinabyss.com/snapshots/")
|
||||
|
||||
@@ -64,6 +64,9 @@ allprojects {
|
||||
// Eco-Suite/Auxilor Repo
|
||||
maven("https://repo.auxilor.io/repository/maven-public/")
|
||||
|
||||
// Triumph GUI
|
||||
maven("https://repo.triumphteam.dev/snapshots")
|
||||
|
||||
// Hibiscus Commons
|
||||
maven("https://repo.hibiscusmc.com/releases")
|
||||
}
|
||||
@@ -72,30 +75,48 @@ allprojects {
|
||||
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
//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.21.4-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:24.1.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0")
|
||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12")
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.12") {
|
||||
exclude(group = "org.bukkit")
|
||||
exclude(group = "com.google.guava")
|
||||
exclude(group = "com.google.code.gson")
|
||||
exclude(group = "it.unimi.dsi")
|
||||
exclude(group = "com.sk89q.jnbt")
|
||||
exclude(group = "org.enginehub.lin-bus.format")
|
||||
}
|
||||
compileOnly("io.github.toxicity188:BetterHud-standard-api:1.12") //Standard api
|
||||
compileOnly("io.github.toxicity188:BetterHud-bukkit-api:1.12") //Platform api
|
||||
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
|
||||
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
|
||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||
compileOnly("me.lojosho:HibiscusCommons:0.5.1")
|
||||
compileOnly("me.lojosho:HibiscusCommons:0.8.1-d9fbae1d")
|
||||
|
||||
// Handled by Spigot Library Loader
|
||||
compileOnly("net.kyori:adventure-api:4.17.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.17.0")
|
||||
compileOnly("net.kyori:adventure-platform-bukkit:4.3.3")
|
||||
// Handled by Spigot Library Loader ~ Deprecated as of Dec 16, 2025
|
||||
/*
|
||||
compileOnly("net.kyori:adventure-api:4.24.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.24.0")
|
||||
compileOnly("net.kyori:adventure-platform-bukkit:4.4.1")
|
||||
*/
|
||||
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.34")
|
||||
testCompileOnly("org.projectlombok:lombok:1.18.34")
|
||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.34")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.36")
|
||||
testCompileOnly("org.projectlombok:lombok:1.18.36")
|
||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.36")
|
||||
|
||||
implementation("dev.triumphteam:triumph-gui:3.1.10") {
|
||||
implementation("dev.triumphteam:triumph-gui:3.2.0-SNAPSHOT") {
|
||||
exclude("net.kyori") // Already have adventure API
|
||||
}
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
|
||||
}
|
||||
|
||||
tasks {
|
||||
javadoc {
|
||||
// javadoc spec has these added.
|
||||
(options as StandardJavadocDocletOptions)
|
||||
.tags("apiNote:a:API:", "implSpec:a:Implementation Requirements", "implNote:a:Implementation Note:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,12 +141,14 @@ tasks {
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("1.21.1")
|
||||
minecraftVersion("1.21.8")
|
||||
|
||||
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")
|
||||
hangar("Multiverse-Core", "5.3.4")
|
||||
url("https://download.luckperms.net/1604/bukkit/loader/LuckPerms-Bukkit-5.5.15.jar")
|
||||
github("Test-Account666", "PlugManX", "2.4.1", "PlugManX-2.4.1.jar")
|
||||
//github("gecolay", "GSit", "2.4.3", "GSit-2.4.3.jar")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +184,8 @@ bukkit {
|
||||
main = "com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin"
|
||||
apiVersion = "1.20"
|
||||
authors = listOf("LoJoSho")
|
||||
depend = listOf("HibiscusCommons", "ProtocolLib")
|
||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
|
||||
depend = listOf("HibiscusCommons")
|
||||
softDepend = listOf("Nexo", "BetterHud", "ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems", "Eco")
|
||||
version = "${project.version}"
|
||||
loadBefore = listOf(
|
||||
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
||||
@@ -260,8 +283,10 @@ bukkit {
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21
|
||||
))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
fun getGitCommitHash(): String {
|
||||
@@ -282,4 +307,4 @@ fun getGitCommitHash(): String {
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ plugins {
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21
|
||||
))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.HMCCosmeticSetupEvent;
|
||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommand;
|
||||
import com.hibiscusmc.hmccosmetics.command.CosmeticCommandTabComplete;
|
||||
@@ -10,26 +9,28 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.impl.HMCColorDyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.items.HookHMCCosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.misc.HookBetterHud;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.placeholders.HMCPlaceholderExpansion;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PaperPlayerGameListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.ServerListener;
|
||||
import com.hibiscusmc.hmccosmetics.listener.*;
|
||||
import com.hibiscusmc.hmccosmetics.packets.CosmeticPacketInterface;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerSearchManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
||||
import com.ticxo.playeranimator.PlayerAnimatorImpl;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import me.lojosho.hibiscuscommons.HibiscusPlugin;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.shaded.configupdater.common.config.CommentedConfiguration;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
import me.lojosho.shaded.configurate.ConfigurationOptions;
|
||||
@@ -49,9 +50,13 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
private static HMCCosmeticsPlugin instance;
|
||||
private static YamlConfigurationLoader configLoader;
|
||||
|
||||
@Getter
|
||||
private PlayerSearchManager playerSearchManager;
|
||||
|
||||
public HMCCosmeticsPlugin() {
|
||||
super(13873, 1879);
|
||||
new HookHMCCosmetics();
|
||||
new HookBetterHud();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,15 +64,20 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
// Search Service
|
||||
this.playerSearchManager = new PlayerSearchManager(this);
|
||||
|
||||
// File setup
|
||||
saveDefaultConfig();
|
||||
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
|
||||
if (!Path.of(getDataFolder().getPath(), "translations.yml").toFile().exists()) saveResource("translations.yml", false);
|
||||
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
|
||||
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
|
||||
|
||||
// Player Animator
|
||||
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet
|
||||
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) {
|
||||
saveResource("menus/defaultmenu_hats.yml", false);
|
||||
saveResource("menus/defaultmenu_balloons.yml", false);
|
||||
saveResource("menus/defaultmenu_hands.yml", false);
|
||||
saveResource("menus/defaultmenu_backpacks.yml", false);
|
||||
}
|
||||
|
||||
// Configuration Sync
|
||||
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
||||
@@ -87,6 +97,7 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
|
||||
// Setup
|
||||
setup();
|
||||
setPacketInterface(new CosmeticPacketInterface());
|
||||
|
||||
// Commands
|
||||
getServer().getPluginCommand("cosmetic").setExecutor(new CosmeticCommand());
|
||||
@@ -96,7 +107,9 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
getServer().getPluginManager().registerEvents(new PlayerConnectionListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerGameListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new ServerListener(), this);
|
||||
// Taken from PaperLib
|
||||
getServer().getPluginManager().registerEvents(new PlayerMovementListener(), this);
|
||||
getServer().getPluginManager().registerEvents(playerSearchManager, this);
|
||||
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||
getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
|
||||
}
|
||||
@@ -107,6 +120,15 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null && Settings.isWorldGuardMoveCheck()) {
|
||||
getServer().getPluginManager().registerEvents(new WGListener(), this);
|
||||
}
|
||||
|
||||
// HMCColor
|
||||
if (Hooks.isActiveHook("HMCColor")) {
|
||||
try {
|
||||
DyeMenuProvider.setDyeMenuProvider(new HMCColorDyeMenu());
|
||||
} catch (IllegalStateException e) {
|
||||
getLogger().warning("Unable to set HMCColor as the dye menu. There is likely another plugin registering another dye menu.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,9 +145,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) continue;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
player.setInvisible(false);
|
||||
}
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe(true);
|
||||
}
|
||||
@@ -227,8 +246,6 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.isEmotesEnabled() && (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1"))) EmoteManager.loadEmotes(); // PlayerAnimator does not support 1.20.2 yet
|
||||
|
||||
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
|
||||
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
|
||||
getInstance().getLogger().info(Menus.getMenuNames().size() + " Menus Successfully Setup");
|
||||
|
||||
@@ -2,116 +2,214 @@ package com.hibiscusmc.hmccosmetics.api;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticProvider;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HMCCosmeticsAPI {
|
||||
|
||||
/**
|
||||
* Attempts to get a cosmetic from HMCCosmetics
|
||||
*
|
||||
* @param cosmetic Cosmetic Id
|
||||
* @return A {@link Cosmetic} if exists or null if it does not
|
||||
*/
|
||||
@Nullable
|
||||
public static Cosmetic getCosmetic(@NotNull String cosmetic) {
|
||||
return Cosmetics.getCosmetic(cosmetic);
|
||||
/**
|
||||
* The main API class for HMCCosmetics. This class provides methods to interact with the plugin.
|
||||
*/
|
||||
public final class HMCCosmeticsAPI {
|
||||
private HMCCosmeticsAPI() {
|
||||
throw new UnsupportedOperationException("This class cannot be instantiated.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get the CosmeticUser from an online user. If a player is offline it will return null.
|
||||
* A player maybe online but not have a CosmeticUser attached to them, either from delay specified in the config
|
||||
* or from a /reload. Always check if it's null!
|
||||
*
|
||||
* @param uuid Player Unique ID
|
||||
* @return A {@link CosmeticUser} if exists or null if it does not
|
||||
* Retrieves a {@link Cosmetic} associated with the specified id.
|
||||
* <p>
|
||||
* This method attempts to fetch a {@link Cosmetic} using the given id. If no {@link Cosmetic} exists
|
||||
* with the specified id, it will return {@code null}.
|
||||
* </p>
|
||||
* @param id the id of the {@link Cosmetic} to retrieve
|
||||
* @return the {@link Cosmetic} if it exists, or {@code null} if no cosmetic is associated with the given id
|
||||
*/
|
||||
@Nullable
|
||||
public static CosmeticUser getUser(@NotNull UUID uuid) {
|
||||
public static @Nullable Cosmetic getCosmetic(@NotNull String id) {
|
||||
return Cosmetics.getCosmetic(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the {@link CosmeticUser} associated with the specified player's {@link UUID}.
|
||||
* <p>
|
||||
* This method attempts to fetch a {@link CosmeticUser} for an online player. If the player is offline,
|
||||
* or if no {@link CosmeticUser} is currently associated with them, it will return {@code null}.
|
||||
* </p>
|
||||
* Note that a player may be online but not have a {@link CosmeticUser} attached due to:
|
||||
* <ul>
|
||||
* <li>A delay specified in the configuration</li>
|
||||
* <li>A recent server reload (e.g., via the {@code /reload} command)</li>
|
||||
* </ul>
|
||||
* Always perform a {@code null} check before using the returned object to ensure safe operation.
|
||||
*
|
||||
* @param uuid the {@link UUID} of the player whose {@link CosmeticUser} is being retrieved
|
||||
* @return the {@link CosmeticUser} if it exists, or {@code null} if the player is offline or unassociated
|
||||
*/
|
||||
public static @Nullable CosmeticUser getUser(@NotNull UUID uuid) {
|
||||
return CosmeticUsers.getUser(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get a HMCCosmetics Menu. Returns null if no menu exists under that id.
|
||||
* Retrieves a {@link Menu} associated with the specified id, or {@code null} if no menu exists with the given id.
|
||||
*
|
||||
* @param id Menu ID
|
||||
* @return A {@link Menu} if exists or null if it does not
|
||||
* @param id the id of the menu to retrieve
|
||||
* @return the {@link Menu} if it exists, or {@code null} if no menu is associated with the given id
|
||||
*/
|
||||
@Nullable
|
||||
public static Menu getMenu(@NotNull String id) {
|
||||
public static @Nullable Menu getMenu(@NotNull String id) {
|
||||
return Menus.getMenu(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equips a cosmetic to a player. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip.
|
||||
* @param user CosmeticUser to equip cosmetic to
|
||||
* @param cosmetic Cosmetic to equip
|
||||
* Equips a {@link Cosmetic} to a player. To retrieve the necessary {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser}
|
||||
* and {@link #getCosmetic} methods respectively.
|
||||
*
|
||||
* @param user the {@link CosmeticUser} to equip the cosmetic to
|
||||
* @param cosmetic the {@link Cosmetic} to equip
|
||||
*/
|
||||
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic) {
|
||||
equipCosmetic(user, cosmetic, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Equips a cosmetic to a player with a color. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip.
|
||||
* @param user CosmeticUser to equip cosmetic to
|
||||
* @param cosmetic Cosmetic to equip
|
||||
* @param color Color to apply to cosmetic
|
||||
* Equips a {@link Cosmetic} to a player with an optional color customization. To retrieve the necessary
|
||||
* {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser} and {@link #getCosmetic} methods
|
||||
* respectively.
|
||||
*
|
||||
* @param user the {@link CosmeticUser} to equip the cosmetic to
|
||||
* @param cosmetic the {@link Cosmetic} to equip
|
||||
* @param color the color to apply to the cosmetic, or {@code null} if the cosmetic does not support color
|
||||
* customization
|
||||
*/
|
||||
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
user.addCosmetic(cosmetic, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a cosmetic in cosmeticslot.
|
||||
* @param user The user to remove the cosmetic from
|
||||
* @param slot The slot to remove the cosmetic from
|
||||
* Removes a cosmetic from a specified slot for the given user.
|
||||
*
|
||||
* @param user the {@link CosmeticUser} from whom the cosmetic will be removed
|
||||
* @param slot the {@link CosmeticSlot} from which the cosmetic will be removed
|
||||
*/
|
||||
public static void unequipCosmetic(@NotNull CosmeticUser user, @NotNull CosmeticSlot slot) {
|
||||
user.removeCosmeticSlot(slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all Cosmetics that are currently registered with HMCC. This list is immutable!
|
||||
* @return A list of all registered cosmetics
|
||||
* Retrieves a list of all cosmetics currently registered with HMCC.
|
||||
*
|
||||
* @return an {@code immutable} list containing all registered {@link Cosmetic} object
|
||||
*/
|
||||
public static List<Cosmetic> getAllCosmetics() {
|
||||
public static @NotNull List<Cosmetic> getAllCosmetics() {
|
||||
return List.copyOf(Cosmetics.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all CosmeticUsers that are currently registered with HMCC. This list is immutable!
|
||||
* @return A list of all registered CosmeticUsers
|
||||
* Retrieves a list of all cosmetic users currently registered with HMCC.
|
||||
*
|
||||
* @return an immutable list containing all registered {@link CosmeticUser} objects
|
||||
*/
|
||||
public static List<CosmeticUser> getAllCosmeticUsers() {
|
||||
public static @NotNull List<CosmeticUser> getAllCosmeticUsers() {
|
||||
return List.copyOf(CosmeticUsers.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the NMS version of the server as recognized by HMCCosmetics. This will be null until HMCC setup has been completed.
|
||||
* @return The NMS version of the server in String format
|
||||
* Retrieves a map of all cosmetic slots currently registered with HMCC.
|
||||
*
|
||||
* @return an immutable {@link Map} containing all registered cosmetic slots
|
||||
*/
|
||||
@Nullable
|
||||
public static String getNMSVersion() {
|
||||
return NMSHandlers.getVersion();
|
||||
public static @NotNull Map<String, CosmeticSlot> getAllCosmeticSlots() {
|
||||
return Map.copyOf(CosmeticSlot.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the HMCCosmetics version.
|
||||
* @return The HMCCosmetics version in String format
|
||||
* Registers a new cosmetic slot with the specified id. If a slot with the same id already exists,
|
||||
* the existing slot will be returned.
|
||||
*
|
||||
* <p>
|
||||
* The provided id will automatically be converted to uppercase when registering the slot.
|
||||
* </p>
|
||||
*
|
||||
* @param id the id for the cosmetic slot
|
||||
* @return the {@link CosmeticSlot} associated with the given id
|
||||
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
|
||||
*/
|
||||
@NotNull
|
||||
public static String getHMCCVersion() {
|
||||
public static @NotNull CosmeticSlot registerCosmeticSlot(@NotNull String id) {
|
||||
return CosmeticSlot.register(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new cosmetic user provider to use for constructing {@link CosmeticUser} instances.
|
||||
*
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if another plugin has already registered a provider
|
||||
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
|
||||
*/
|
||||
public static void registerCosmeticUserProvider(@NotNull CosmeticUserProvider provider) {
|
||||
CosmeticUsers.registerProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current {@link CosmeticUserProvider} that is in use.
|
||||
*
|
||||
* @return the current {@link CosmeticUserProvider}
|
||||
*/
|
||||
public static @NotNull CosmeticUserProvider getCosmeticUserProvider() {
|
||||
return CosmeticUsers.getProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new cosmetic user provider to use for constructing {@link Cosmetic} instances.
|
||||
*
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if another plugin has already registered a provider
|
||||
* @apiNote this should be done in your {@link JavaPlugin#onLoad()} or it may error.
|
||||
*/
|
||||
public static void registerCosmeticProvider(@NotNull CosmeticProvider provider) {
|
||||
Cosmetics.registerProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current {@link CosmeticProvider} that is in use.
|
||||
*
|
||||
* @return the current {@link CosmeticProvider}
|
||||
*/
|
||||
public static @NotNull CosmeticProvider getCosmeticProvider() {
|
||||
return Cosmetics.getProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the NMS version of the server as recognized by HMCCosmetics.
|
||||
*
|
||||
* <p>This value will be {@code null} until the HMCC setup has been completed. Ensure setup is finished
|
||||
* before attempting to access this version.</p>
|
||||
*
|
||||
* @return the NMS version of the server in string format, or {@code null} if setup is not complete.
|
||||
*/
|
||||
public static @Nullable String getNMSVersion() {
|
||||
MinecraftVersion version = NMSHandlers.getVersion();
|
||||
if (version == null) return null;
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the version of HMCCosmetics currently in use.
|
||||
*
|
||||
* @return the HMCCosmetics version in string format
|
||||
*/
|
||||
public static @NotNull String getHMCCVersion() {
|
||||
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,42 +6,50 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a cosmetic type not registered with HMCC default cosmetics is attempted to be registered. So if someone puts "test" in the config slot, and it's not a default cosmetic, this event will be called.
|
||||
* Called when an attempt is made to register a cosmetic type that is not part of the default HMCC cosmetics.
|
||||
* <p>
|
||||
* For example, if a user specifies "test" in the config slot, and it is not a default cosmetic, this event will be
|
||||
* triggered.
|
||||
* </p>
|
||||
*/
|
||||
public class CosmeticTypeRegisterEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final String id;
|
||||
private final ConfigurationNode config;
|
||||
|
||||
public CosmeticTypeRegisterEvent(String id, ConfigurationNode config) {
|
||||
public CosmeticTypeRegisterEvent(@NotNull String id, @NotNull ConfigurationNode config) {
|
||||
this.id = id;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the cosmetic trying to be registered. For example, "beanie" or "test"
|
||||
* @return The id. This is the key in the cosmetic config
|
||||
* Returns the id of the cosmetic attempting to be registered.
|
||||
*
|
||||
* @return the id of the cosmetic. This is the key in the cosmetic configuration.
|
||||
*/
|
||||
public String getId() {
|
||||
public @NotNull String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This will already be in the nested node below the id in the config.
|
||||
* @return The cosmetic config node in the cosmetic config that was attempted to get registered
|
||||
* Retrieves the {@link ConfigurationNode} for the cosmetic that was attempted to be registered.
|
||||
* <p>
|
||||
* This node is nested below the id in the configuration.
|
||||
* </p>
|
||||
*
|
||||
* @return the configuration node for the cosmetic in the cosmetic configuration
|
||||
*/
|
||||
public ConfigurationNode getConfig() {
|
||||
public @NotNull ConfigurationNode getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,17 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when the plugin is set up and/or reloaded
|
||||
* Called when the plugin is set up and/or reloaded.
|
||||
*/
|
||||
public class HMCCosmeticSetupEvent extends Event {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player equips a cosmetic
|
||||
* Called when a player equips a {@link Cosmetic}.
|
||||
*/
|
||||
public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private Cosmetic cosmetic;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||
super(who);
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Cosmetic} being equipped in this event
|
||||
* Gets the {@link Cosmetic} being equipped in this event.
|
||||
*
|
||||
* @return The {@link Cosmetic} which is being equipped in this event
|
||||
* @return the cosmetic which is being equipped in this event
|
||||
*/
|
||||
@NotNull
|
||||
public Cosmetic getCosmetic() {
|
||||
@@ -30,9 +32,9 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Cosmetic} that the player will equip
|
||||
* Sets the {@link Cosmetic} that the player will equip.
|
||||
*
|
||||
* @param cosmetic The {@link Cosmetic} that the player will equip
|
||||
* @param cosmetic the cosmetic that the player will equip
|
||||
*/
|
||||
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
this.cosmetic = cosmetic;
|
||||
@@ -43,28 +45,17 @@ public class PlayerCosmeticEquipEvent extends PlayerCosmeticEvent implements Can
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from equipping the cosmetic
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a cosmetic user related event
|
||||
* Represents an event related to a {@link CosmeticUser}.
|
||||
*/
|
||||
public abstract class PlayerCosmeticEvent extends Event {
|
||||
protected CosmeticUser user;
|
||||
public abstract class PlayerCosmeticEvent extends PlayerEvent {
|
||||
protected final CosmeticUser user;
|
||||
|
||||
public PlayerCosmeticEvent(@NotNull final CosmeticUser who) {
|
||||
public PlayerCosmeticEvent(@NotNull CosmeticUser who) {
|
||||
super(who.getUniqueId());
|
||||
user = who;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user involved in this event
|
||||
* Returns the {@link CosmeticUser} involved in this event.
|
||||
*
|
||||
* @return User who is involved in this event
|
||||
* @return the user who is involved in this event
|
||||
*/
|
||||
@NotNull
|
||||
public final CosmeticUser getUser() {
|
||||
public final @NotNull CosmeticUser getUser() {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,25 +6,26 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when cosmetics are hidden from a player
|
||||
* Called when cosmetics are hidden from a player.
|
||||
*/
|
||||
public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final CosmeticUser.HiddenReason reason;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticHideEvent(@NotNull CosmeticUser who, @NotNull CosmeticUser.HiddenReason reason) {
|
||||
super(who);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player
|
||||
* Gets the {@link CosmeticUser.HiddenReason} as to why cosmetics are being hidden for the player.
|
||||
*
|
||||
* @return The {@link CosmeticUser.HiddenReason} why cosmetics are being hidden for the player
|
||||
* @return the reason why cosmetics are being hidden for the player
|
||||
*/
|
||||
@NotNull
|
||||
public CosmeticUser.HiddenReason getReason() {
|
||||
public @NotNull CosmeticUser.HiddenReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@@ -33,28 +34,17 @@ public class PlayerCosmeticHideEvent extends PlayerCosmeticEvent implements Canc
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from hiding cosmetics
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player has equipped a {@link Cosmetic}.
|
||||
*/
|
||||
public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private Cosmetic cosmetic;
|
||||
|
||||
public PlayerCosmeticPostEquipEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||
@@ -15,32 +19,29 @@ public class PlayerCosmeticPostEquipEvent extends PlayerCosmeticEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Cosmetic} being equipped in this event
|
||||
* Gets the {@link Cosmetic} being equipped in this event.
|
||||
*
|
||||
* @return The {@link Cosmetic} which is being equipped in this event
|
||||
* @return the cosmetic which is being equipped in this event
|
||||
*/
|
||||
@NotNull
|
||||
public Cosmetic getCosmetic() {
|
||||
public @NotNull Cosmetic getCosmetic() {
|
||||
return cosmetic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Cosmetic} that the player will equip
|
||||
* Sets the {@link Cosmetic} that the player will equip.
|
||||
*
|
||||
* @param cosmetic The {@link Cosmetic} that the player will equip
|
||||
* @param cosmetic the cosmetic that the player will equip
|
||||
*/
|
||||
public void setCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,22 +7,24 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player removes a cosmetic
|
||||
* Called when a player removes a {@link Cosmetic}.
|
||||
*/
|
||||
public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final Cosmetic cosmetic;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticRemoveEvent(@NotNull CosmeticUser who, @NotNull Cosmetic cosmetic) {
|
||||
super(who);
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Cosmetic} being removed in this event
|
||||
* Gets the {@link Cosmetic} being removed in this event.
|
||||
*
|
||||
* @return The {@link Cosmetic} which is being removed in this event
|
||||
* @return the cosmetic which is being removed in this event
|
||||
*/
|
||||
public Cosmetic getCosmetic() {
|
||||
return cosmetic;
|
||||
@@ -33,27 +35,17 @@ public class PlayerCosmeticRemoveEvent extends PlayerCosmeticEvent implements Ca
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from removing the cosmetic
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when cosmetics are shown from a player
|
||||
* Called when cosmetics are shown from a player.
|
||||
*/
|
||||
public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerCosmeticShowEvent(@NotNull CosmeticUser who) {
|
||||
@@ -21,28 +22,17 @@ public class PlayerCosmeticShowEvent extends PlayerCosmeticEvent implements Canc
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from showing cosmetics
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player starts playing an emote
|
||||
*/
|
||||
public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final String animationId;
|
||||
|
||||
public PlayerEmoteStartEvent(@NotNull CosmeticUser who, @NotNull String animationId) {
|
||||
super(who);
|
||||
this.animationId = animationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the animation id of the emote the player started playing
|
||||
* @implNote The returned string of this method may be an invalid animation id. Make sure to validate it before use
|
||||
*
|
||||
* @return The animation id of the emote which the player started playing
|
||||
*/
|
||||
@NotNull
|
||||
public String getAnimationId() {
|
||||
return animationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from playing the emote
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player stops playing an emote
|
||||
*/
|
||||
public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
private final UserEmoteManager.StopEmoteReason reason;
|
||||
|
||||
public PlayerEmoteStopEvent(@NotNull CosmeticUser who, @NotNull UserEmoteManager.StopEmoteReason reason) {
|
||||
super(who);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||
*
|
||||
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||
* @deprecated As of release 2.2.5+, replaced by {@link #getReason()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||
*
|
||||
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||
* @since 2.2.5
|
||||
*/
|
||||
@NotNull
|
||||
public UserEmoteManager.StopEmoteReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from stopping the emote
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents an event related to a {@link org.bukkit.entity.Player}.
|
||||
*/
|
||||
public abstract class PlayerEvent extends Event {
|
||||
protected final UUID player;
|
||||
|
||||
public PlayerEvent(@NotNull UUID uuid) {
|
||||
this.player = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link UUID} of the player involved in this event.
|
||||
*
|
||||
* @return the UUID of the player who is involved in this event
|
||||
*/
|
||||
public final @NotNull UUID getUniqueId() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player's cosmetic data is loaded.
|
||||
*/
|
||||
public class PlayerLoadEvent extends PlayerCosmeticEvent {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
public PlayerLoadEvent(@NotNull CosmeticUser who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,35 @@ package com.hibiscusmc.hmccosmetics.api.events;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a menu is closed by a player
|
||||
* Called when a {@link Menu} is closed by a player.
|
||||
*/
|
||||
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final InventoryCloseEvent.Reason reason;
|
||||
|
||||
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu, @NotNull InventoryCloseEvent.Reason reason) {
|
||||
super(who, menu);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link InventoryCloseEvent.Reason} why the menu was closed.
|
||||
* @return The reason why the menu was closed.
|
||||
*/
|
||||
public InventoryCloseEvent.Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a menu related event
|
||||
* Represents an event related to a player's interaction with a {@link Menu}.
|
||||
*/
|
||||
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||
protected Menu menu;
|
||||
protected final Menu menu;
|
||||
|
||||
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
super(who);
|
||||
@@ -16,12 +16,11 @@ public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Menu} involved with this event
|
||||
* Gets the {@link Menu} involved with this event.
|
||||
*
|
||||
* @return The {@link Menu} which is involved with the event
|
||||
* @return the menu involved in this event
|
||||
*/
|
||||
@NotNull
|
||||
public final Menu getMenu() {
|
||||
public @NotNull final Menu getMenu() {
|
||||
return menu;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a menu is opened by a player
|
||||
* Called when a {@link Menu} is opened by a player.
|
||||
*/
|
||||
public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
@@ -22,28 +23,17 @@ public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from opening a {@link Menu}
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Called before a player's data is loaded into the plugin.
|
||||
*
|
||||
* <p>
|
||||
* If this event is cancelled, the player's data will not be loaded,
|
||||
* and the player will not be able to interact with the plugin.
|
||||
* </p>
|
||||
*/
|
||||
public class PlayerPreLoadEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerPreLoadEvent(@NotNull UUID id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called before a player's data is un-loaded from the plugin.
|
||||
*
|
||||
* <p>
|
||||
* If this event is cancelled, the player's data will not be un-loaded,
|
||||
* and will be kept in memory.
|
||||
* </p>
|
||||
*/
|
||||
public class PlayerPreUnloadEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlayerPreUnloadEvent(@NotNull CosmeticUser who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a players data is unloaded from the plugin. This is called when a player leaves the server.
|
||||
*/
|
||||
public class PlayerUnloadEvent extends PlayerCosmeticEvent {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
public PlayerUnloadEvent(@NotNull CosmeticUser who) {
|
||||
super(who);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,18 @@ package com.hibiscusmc.hmccosmetics.api.events;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player enters their wardrobe
|
||||
* Called when a player enters their {@link Wardrobe}.
|
||||
*/
|
||||
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
@Getter @Setter
|
||||
|
||||
private Wardrobe wardrobe;
|
||||
|
||||
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
|
||||
@@ -22,33 +21,38 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can
|
||||
this.wardrobe = wardrobe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Wardrobe} the player is entering.
|
||||
* @return The wardrobe being entered
|
||||
*/
|
||||
public Wardrobe getWardrobe() {
|
||||
return wardrobe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link Wardrobe} the player is entering.
|
||||
* @param wardrobe the wardrobe being entered
|
||||
*/
|
||||
public void setWardrobe(Wardrobe wardrobe) {
|
||||
this.wardrobe = wardrobe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from entering their wardrobe
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,11 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player leaves their wardrobe
|
||||
* Called when a player leaves their {@link com.hibiscusmc.hmccosmetics.config.Wardrobe}.
|
||||
*/
|
||||
public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerWardrobeLeaveEvent(@NotNull CosmeticUser who) {
|
||||
@@ -21,28 +22,17 @@ public class PlayerWardrobeLeaveEvent extends PlayerCosmeticEvent implements Can
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cancellation state of this event
|
||||
*
|
||||
* <p>
|
||||
* Canceling this event will prevent the player from leaving their wardrobe
|
||||
* </p>
|
||||
*
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,11 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
@@ -23,7 +22,6 @@ import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -144,6 +142,11 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
if (user == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic) && !console) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||
return true;
|
||||
@@ -152,11 +155,11 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
TagResolver placeholders =
|
||||
TagResolver.resolver(Placeholder.parsed("cosmetic", cosmetic.getId()),
|
||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmetic.getSlot().name())));
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmetic.getSlot().toString())));
|
||||
|
||||
if (!silent) MessagesUtil.sendMessage(player, "equip-cosmetic", placeholders);
|
||||
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
user.addCosmetic(cosmetic, color);
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
return true;
|
||||
}
|
||||
@@ -187,11 +190,12 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (args[1].equalsIgnoreCase("all")) {
|
||||
cosmeticSlots = user.getSlotsWithCosmetics();
|
||||
} else {
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1].toUpperCase())) {
|
||||
String rawSlot = args[1].toUpperCase();
|
||||
if (!CosmeticSlot.contains(rawSlot)) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-slot");
|
||||
return true;
|
||||
}
|
||||
cosmeticSlots = Set.of(CosmeticSlot.valueOf(args[1].toUpperCase()));
|
||||
cosmeticSlots = Set.of(CosmeticSlot.valueOf(rawSlot));
|
||||
}
|
||||
|
||||
for (CosmeticSlot cosmeticSlot : cosmeticSlots) {
|
||||
@@ -203,7 +207,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
TagResolver placeholders =
|
||||
TagResolver.resolver(Placeholder.parsed("cosmetic", user.getCosmetic(cosmeticSlot).getId()),
|
||||
TagResolver.resolver(Placeholder.parsed("player", player.getName())),
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.name())));
|
||||
TagResolver.resolver(Placeholder.parsed("cosmeticslot", cosmeticSlot.toString())));
|
||||
|
||||
if (!silent) MessagesUtil.sendMessage(player, "unequip-cosmetic", placeholders);
|
||||
|
||||
@@ -243,9 +247,9 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
} else {
|
||||
user.enterWardrobe(false, wardrobe);
|
||||
user.enterWardrobe(wardrobe, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -306,12 +310,17 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
|
||||
final String rawSlot = args[1];
|
||||
if (!CosmeticSlot.contains(rawSlot)) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||
return true;
|
||||
}
|
||||
final CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot); // This is checked above. While IDEs may say the slot might be null, it will not be.
|
||||
final Cosmetic cosmetic = user.getCosmetic(slot);
|
||||
if (cosmetic == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||
return true;
|
||||
}
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
|
||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||
|
||||
if (args.length >= 3) {
|
||||
if (args[2].isEmpty()) {
|
||||
@@ -323,9 +332,13 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||
return true;
|
||||
}
|
||||
user.addPlayerCosmetic(cosmetic, color); // #FFFFFF
|
||||
user.addCosmetic(cosmetic, color); // #FFFFFF
|
||||
} else {
|
||||
DyeMenu.openMenu(user, cosmetic);
|
||||
if (DyeMenuProvider.hasMenuProvider()) {
|
||||
DyeMenuProvider.openMenu(player, user, cosmetic);
|
||||
} else {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-color");
|
||||
}
|
||||
}
|
||||
}
|
||||
case ("setwardrobesetting") -> {
|
||||
@@ -377,6 +390,11 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
|
||||
return true;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("defaultmenu")) {
|
||||
WardrobeSettings.setWardrobeDefaultMenu(wardrobe, args[3]);
|
||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-menu");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
case ("dump") -> {
|
||||
@@ -391,6 +409,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
|
||||
}
|
||||
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
|
||||
player.sendMessage("Cosmetics -> " + user.getCosmetics());
|
||||
player.sendMessage("EntityId -> " + player.getEntityId());
|
||||
return true;
|
||||
@@ -452,59 +471,6 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "debug-enabled");
|
||||
}
|
||||
}
|
||||
case ("emote") -> {
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.emote")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
if (sender.hasPermission("hmccosmetics.cmd.emote.other")) {
|
||||
if (args.length >= 2) player = Bukkit.getPlayer(args[1]);
|
||||
}
|
||||
if (player == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.EMOTE)) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "emote-none");
|
||||
return true;
|
||||
}
|
||||
|
||||
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
|
||||
cosmeticEmoteType.run(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
case ("playemote") -> {
|
||||
// /cosmetic playEmote <emoteId> [playerName]
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.playemote")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "not-enough-args");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EmoteManager.has(args[1])) {
|
||||
MessagesUtil.sendDebugMessages("Did not contain " + args[1]);
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) {
|
||||
if (args.length >= 3) player = Bukkit.getPlayer(args[2]);
|
||||
}
|
||||
if (player == null) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "invalid-player");
|
||||
return true;
|
||||
}
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
user.getUserEmoteManager().playEmote(args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
case "disableall" -> {
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.disableall")) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
@@ -44,8 +43,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.hide")) completions.add("hide");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.disableall")) completions.add("disableall");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.hiddenreasons")) completions.add("hiddenreasons");
|
||||
if (hasPermission(sender, "hmccosmetics.cmd.clearhiddenreasons")) completions.add("clearhiddenreasons");
|
||||
@@ -74,7 +71,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
if (menu.canOpen(user.getPlayer())) completions.add(menu.getId());
|
||||
}
|
||||
}
|
||||
case "dataclear", "hide", "show", "emote", "hiddenreasons", "clearhiddenreasons" -> {
|
||||
case "dataclear", "hide", "show", "hiddenreasons", "clearhiddenreasons" -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(player.getName());
|
||||
}
|
||||
@@ -94,7 +91,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
}
|
||||
case "dye" -> {
|
||||
for (CosmeticSlot slot : user.getDyeableSlots()) {
|
||||
completions.add(slot.name());
|
||||
completions.add(slot.toString());
|
||||
}
|
||||
}
|
||||
case "setwardrobesetting" -> {
|
||||
@@ -102,7 +99,6 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
completions.add(wardrobe.getId());
|
||||
}
|
||||
}
|
||||
case "playemote" -> completions.addAll(EmoteManager.getAllNames());
|
||||
}
|
||||
StringUtil.copyPartialMatches(args[1], completions, finalCompletions);
|
||||
}
|
||||
@@ -112,7 +108,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
case "dye" -> {
|
||||
completions.add("#FFFFFF");
|
||||
}
|
||||
case "menu", "wardrobe", "apply", "unapply", "playemote" -> {
|
||||
case "menu", "wardrobe", "apply", "unapply" -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(player.getName());
|
||||
}
|
||||
@@ -123,6 +119,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
completions.add("leavelocation");
|
||||
completions.add("permission");
|
||||
completions.add("distance");
|
||||
completions.add("defaultmenu");
|
||||
}
|
||||
}
|
||||
StringUtil.copyPartialMatches(args[2], completions, finalCompletions);
|
||||
@@ -135,6 +132,11 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
if (Hooks.isActiveHook("HMCColor")) completions.addAll(HMCColorContextKt.getHmcColor().getConfig().getColors().keySet());
|
||||
completions.add("#FFFFFF");
|
||||
}
|
||||
case "setwardrobesetting" -> {
|
||||
if (args[2].equalsIgnoreCase("defaultmenu")) {
|
||||
completions.addAll(Menus.getMenuNames());
|
||||
}
|
||||
}
|
||||
}
|
||||
StringUtil.copyPartialMatches(args[3], completions, finalCompletions);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public class Settings {
|
||||
private static final String ITEM_PROCESS_LORE_PATH = "lore";
|
||||
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
|
||||
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
|
||||
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
|
||||
private static final String HOOK_SETTING_PATH = "hook-settings";
|
||||
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
|
||||
private static final String HOOK_NEXO_PATH = "nexo";
|
||||
@@ -43,24 +42,18 @@ public class Settings {
|
||||
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_LEGACY = "player_move_check";
|
||||
private static final String COSMETIC_EMOTE_ENABLE = "emote-enable";
|
||||
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
|
||||
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
|
||||
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
|
||||
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
|
||||
private static final String COSMETIC_EMOTE_CAMERA_PATH = "emote-camera";
|
||||
private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move";
|
||||
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_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
|
||||
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_OFFHAND_PREVENT_SWAPPING = "offhand-prevent-swapping";
|
||||
private static final String MENU_SETTINGS_PATH = "menu-settings";
|
||||
private static final String MENU_CLICK_COOLDOWN_PATH = "click-cooldown";
|
||||
private static final String MENU_CLICK_COOLDOWN_TIME_PATH = "time";
|
||||
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
|
||||
private static final String EQUIP_CLICK_TYPE = "equip-click";
|
||||
private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
|
||||
private static final String DYE_CLICK_TYPE = "dye-click";
|
||||
private static final String SHADING_PATH = "shading";
|
||||
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
|
||||
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
|
||||
@@ -72,6 +65,9 @@ public class Settings {
|
||||
private static final String LOCKED_COSMETIC_COLOR_PATH = "locked-cosmetic-color";
|
||||
private static final String ENABLED_PATH = "enabled";
|
||||
private static final String SLOT_OPTIONS_PATH = "slot-options";
|
||||
private static final String BACKPACK_PREVENT_DARKNESS_PATH = "backpack-prevent-darkness";
|
||||
private static final String BETTER_HUD_PATH = "betterhud";
|
||||
private static final String BETTER_HUD_HIDE_IN_WARDROBE_PATH = "wardrobe-hide";
|
||||
|
||||
@Getter
|
||||
private static String defaultMenu;
|
||||
@@ -101,26 +97,20 @@ public class Settings {
|
||||
private static boolean nexoChangeReload;
|
||||
@Getter
|
||||
private static boolean worldGuardMoveCheck;
|
||||
@Getter
|
||||
private static boolean cosmeticEmoteBlockCheck;
|
||||
private static final HashMap<EquipmentSlot, SlotOptionConfig> slotOptions = new HashMap<>();
|
||||
@Getter
|
||||
private static boolean emoteAirCheck;
|
||||
@Getter
|
||||
private static boolean emoteDamageLeave;
|
||||
@Getter
|
||||
private static boolean emoteInvincible;
|
||||
@Getter
|
||||
private static boolean destroyLooseCosmetics;
|
||||
@Getter
|
||||
private static boolean backpackForceRidingEnabled;
|
||||
private static boolean preventOffhandSwapping;
|
||||
@Getter
|
||||
private static boolean emotesEnabled;
|
||||
private static boolean backpackForceRidingEnabled;
|
||||
@Getter
|
||||
private static boolean disabledGamemodesEnabled;
|
||||
@Getter
|
||||
private static boolean balloonHeadForward;
|
||||
@Getter
|
||||
private static boolean backpackPreventDarkness;
|
||||
@Getter
|
||||
private static List<String> disabledGamemodes;
|
||||
@Getter
|
||||
private static List<String> disabledWorlds;
|
||||
@@ -129,20 +119,18 @@ public class Settings {
|
||||
@Getter
|
||||
private static int tickPeriod;
|
||||
@Getter
|
||||
private static int packetEntityTeleportCooldown;
|
||||
@Getter
|
||||
private static Long defaultMenuCooldown;
|
||||
@Getter
|
||||
private static boolean menuClickCooldown;
|
||||
@Getter
|
||||
private static double emoteDistance;
|
||||
@Getter
|
||||
private static Vector balloonOffset;
|
||||
@Getter
|
||||
private static String cosmeticEquipClickType;
|
||||
@Getter
|
||||
private static String cosmeticUnEquipClickType;
|
||||
@Getter
|
||||
private static String cosmeticDyeClickType;
|
||||
@Getter
|
||||
private static boolean defaultShading;
|
||||
@Getter
|
||||
private static String firstRowShift;
|
||||
@@ -160,12 +148,10 @@ public class Settings {
|
||||
private static String equipableCosmeticColor;
|
||||
@Getter
|
||||
private static String lockedCosmeticColor;
|
||||
@Getter
|
||||
private static boolean emoteCameraEnabled;
|
||||
@Getter
|
||||
private static boolean emoteMoveCheck;
|
||||
@Getter @Setter
|
||||
private static boolean allPlayersHidden;
|
||||
@Getter
|
||||
private static boolean wardrobeHideHud;
|
||||
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
@@ -202,14 +188,9 @@ public class Settings {
|
||||
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
|
||||
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
||||
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
|
||||
emotesEnabled = cosmeticSettings.node(COSMETIC_EMOTE_ENABLE).getBoolean(true);
|
||||
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
|
||||
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
|
||||
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
|
||||
emoteDamageLeave = cosmeticSettings.node(COSMETIC_EMOTE_DAMAGE_PATH).getBoolean(false);
|
||||
emoteInvincible = cosmeticSettings.node(COSMETIC_EMOTE_INVINCIBLE_PATH).getBoolean(false);
|
||||
destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false);
|
||||
backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false);
|
||||
preventOffhandSwapping = cosmeticSettings.node(COSMETIC_OFFHAND_PREVENT_SWAPPING).getBoolean(false);
|
||||
|
||||
cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> {
|
||||
EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase());
|
||||
@@ -224,10 +205,8 @@ public class Settings {
|
||||
|
||||
tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1);
|
||||
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
|
||||
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
|
||||
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
|
||||
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
|
||||
balloonHeadForward = cosmeticSettings.node(COSMETIC_BALLOON_HEAD_FORWARD_PATH).getBoolean(false);
|
||||
backpackPreventDarkness = cosmeticSettings.node(BACKPACK_PREVENT_DARKNESS_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH);
|
||||
|
||||
@@ -247,8 +226,9 @@ public class Settings {
|
||||
lockedCosmeticColor = shadingSettings.node(LOCKED_COSMETIC_COLOR_PATH).getString();
|
||||
|
||||
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
|
||||
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
|
||||
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
|
||||
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ANY");
|
||||
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ANY");
|
||||
cosmeticDyeClickType = cosmeticTypeSettings.node(DYE_CLICK_TYPE).getString("ANY");
|
||||
|
||||
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
|
||||
balloonOffset = loadVector(balloonSection);
|
||||
@@ -267,6 +247,9 @@ public class Settings {
|
||||
ConfigurationNode nexoSettings = hookSettings.node(HOOK_NEXO_PATH);
|
||||
nexoChangeReload = nexoSettings.node(HOOK_RELOAD_CHANGE_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode betterHudSettings = hookSettings.node(BETTER_HUD_PATH);
|
||||
wardrobeHideHud = betterHudSettings.node(BETTER_HUD_HIDE_IN_WARDROBE_PATH).getBoolean(true);
|
||||
|
||||
ConfigurationNode worldGuardSettings = hookSettings.node(HOOK_WORLDGUARD_PATH);
|
||||
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.
|
||||
|
||||
@@ -54,7 +54,7 @@ public class Wardrobe {
|
||||
Location wardrobeLocation = location.getNpcLocation();
|
||||
Location location = user.getEntity().getLocation();
|
||||
if (wardrobeLocation == null) return false;
|
||||
if (distance == -1) return true;
|
||||
if (distance <= 0) return true;
|
||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||
return wardrobeLocation.distanceSquared(location) <= distance * distance;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.LocationSerializer;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
@@ -170,7 +169,8 @@ public class WardrobeSettings {
|
||||
MessagesUtil.sendDebugMessages("Wardrobe Location: " + npcLocation);
|
||||
Location viewerLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(VIEWER_LOCATION_PATH));
|
||||
MessagesUtil.sendDebugMessages("Viewer Location: " + viewerLocation);
|
||||
Location leaveLocation = Utils.replaceIfNull(LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH)), viewerLocation);
|
||||
Location leaveLocation = LocationSerializer.INSTANCE.deserialize(Location.class, wardrobesNode.node(LEAVE_LOCATION_PATH));
|
||||
if (leaveLocation == null) leaveLocation = viewerLocation;
|
||||
MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation);
|
||||
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
|
||||
|
||||
@@ -282,4 +282,14 @@ public class WardrobeSettings {
|
||||
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
public static void setWardrobeDefaultMenu(Wardrobe wardrobe, String defaultMenu) {
|
||||
wardrobe.setDefaultMenu(defaultMenu);
|
||||
|
||||
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||
|
||||
plugin.getConfig().set("wardrobe.wardrobes." + wardrobe.getId() + ".default-menu", defaultMenu);
|
||||
|
||||
plugin.saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,69 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class Cosmetic {
|
||||
protected static ItemStack UNDEFINED_DISPLAY_ITEM_STACK;
|
||||
|
||||
@Getter @Setter
|
||||
static {
|
||||
UNDEFINED_DISPLAY_ITEM_STACK = new ItemStack(Material.BARRIER);
|
||||
|
||||
ItemMeta meta = UNDEFINED_DISPLAY_ITEM_STACK.getItemMeta();
|
||||
if (meta != null) {
|
||||
// Legacy methods for Spigot >:(
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&cUndefined Item Display"));
|
||||
meta.setLore(List.of(
|
||||
ChatColor.translateAlternateColorCodes('&', "&cPlease check your configurations & console to"),
|
||||
ChatColor.translateAlternateColorCodes('&', "&censure there are no errors.")));
|
||||
}
|
||||
UNDEFINED_DISPLAY_ITEM_STACK.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/** Identifier of the cosmetic. */
|
||||
private String id;
|
||||
@Getter @Setter
|
||||
private String permission;
|
||||
private ItemStack item;
|
||||
@Getter @Setter
|
||||
private String material;
|
||||
@Getter @Setter
|
||||
private CosmeticSlot slot;
|
||||
@Getter @Setter
|
||||
private boolean dyable;
|
||||
|
||||
protected Cosmetic(String id, @NotNull ConfigurationNode config) {
|
||||
/** Permission to use the cosmetic. */
|
||||
private String permission;
|
||||
|
||||
/** The display {@link ItemStack} of the cosmetic. */
|
||||
@Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
|
||||
private ItemStack item;
|
||||
|
||||
/** The material string of the cosmetic. */
|
||||
private String material;
|
||||
|
||||
/** The {@link CosmeticSlot} this cosmetic occupies. */
|
||||
private CosmeticSlot slot;
|
||||
|
||||
/** Whether the cosmetic is dyeable or not. */
|
||||
private boolean dyeable;
|
||||
|
||||
/** The config for the cosmetic */
|
||||
private ConfigurationNode config;
|
||||
|
||||
protected Cosmetic(@NotNull String id, @NotNull ConfigurationNode config) {
|
||||
this.id = id;
|
||||
this.config = config;
|
||||
|
||||
if (!config.node("permission").virtual()) {
|
||||
this.permission = config.node("permission").getString();
|
||||
@@ -39,23 +73,54 @@ public abstract class Cosmetic {
|
||||
|
||||
if (!config.node("item").virtual()) {
|
||||
this.material = config.node("item", "material").getString();
|
||||
this.item = generateItemStack(config.node("item"));
|
||||
try {
|
||||
this.item = generateItemStack(config.node("item"));
|
||||
} catch(Exception ex) {
|
||||
MessagesUtil.sendDebugMessages("Forcing %s to use undefined display".formatted(getId()));
|
||||
this.item = UNDEFINED_DISPLAY_ITEM_STACK;
|
||||
}
|
||||
}
|
||||
|
||||
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
|
||||
this.slot = CosmeticSlot.valueOf(config.node("slot").getString());
|
||||
|
||||
setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
|
||||
setDyable(config.node("dyeable").getBoolean(false));
|
||||
this.dyeable = config.node("dyeable").getBoolean(false);
|
||||
MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
|
||||
}
|
||||
|
||||
MessagesUtil.sendDebugMessages("Dyeable " + dyable);
|
||||
Cosmetics.addCosmetic(this);
|
||||
protected Cosmetic(String id, String permission, ItemStack item, String material, CosmeticSlot slot, boolean dyeable) {
|
||||
this.id = id;
|
||||
this.permission = permission;
|
||||
this.item = item;
|
||||
this.material = material;
|
||||
this.slot = slot;
|
||||
this.dyeable = dyeable;
|
||||
}
|
||||
|
||||
public boolean requiresPermission() {
|
||||
return permission != null;
|
||||
}
|
||||
|
||||
public abstract void update(CosmeticUser user);
|
||||
/**
|
||||
* Dispatched when an update is requested upon the cosmetic. Instead, you should use {@link CosmeticUser#updateCosmetic(CosmeticSlot)})}
|
||||
* @param user the user to preform the update against
|
||||
*/
|
||||
@Deprecated(since = "2.8.2")
|
||||
public void update(CosmeticUser user) {
|
||||
if(this instanceof CosmeticUpdateBehavior behavior) {
|
||||
behavior.dispatchUpdate(user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action preformed on the update. Instead, you should use {@link CosmeticUser#updateCosmetic(CosmeticSlot)})}
|
||||
* @param user the user to preform the update against
|
||||
*/
|
||||
@Deprecated(since = "2.8.2")
|
||||
protected void doUpdate(final CosmeticUser user) {
|
||||
// #update should be the preferred way of interacting with this api now.
|
||||
this.update(user);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItem() {
|
||||
@@ -63,6 +128,11 @@ public abstract class Cosmetic {
|
||||
return item.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an {@link ItemStack} from a {@link ConfigurationNode}.
|
||||
* @param config the configuration node
|
||||
* @return the {@link ItemStack}
|
||||
*/
|
||||
protected ItemStack generateItemStack(ConfigurationNode config) {
|
||||
try {
|
||||
ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config);
|
||||
@@ -76,4 +146,14 @@ public abstract class Cosmetic {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* While cosmetics registered in HMCC are made through a configuration, cosmetics registered from other plugins
|
||||
* may not and instead opt for {@link Cosmetic#Cosmetic(String, String, ItemStack, String, CosmeticSlot, boolean)}, which doesn't use a config.
|
||||
* This should be used only for reference.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public @Nullable ConfigurationNode getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents any object that can wear/hold cosmetics,
|
||||
* users, for example.
|
||||
*/
|
||||
public interface CosmeticHolder {
|
||||
@Nullable Cosmetic getCosmetic(@NotNull CosmeticSlot slot);
|
||||
|
||||
@NotNull ImmutableCollection<Cosmetic> getCosmetics();
|
||||
|
||||
void addCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color);
|
||||
|
||||
default void addCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
addCosmetic(cosmetic, null);
|
||||
}
|
||||
|
||||
default void removeCosmetics() {
|
||||
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
|
||||
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
|
||||
removeCosmeticSlot(slot);
|
||||
}
|
||||
}
|
||||
|
||||
void removeCosmeticSlot(@NotNull CosmeticSlot slot);
|
||||
|
||||
default void removeCosmeticSlot(@NotNull Cosmetic cosmetic) {
|
||||
removeCosmeticSlot(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
default boolean hasCosmeticInSlot(@NotNull CosmeticSlot slot) {
|
||||
return getCosmetic(slot) != null;
|
||||
}
|
||||
|
||||
default boolean hasCosmeticInSlot(@NotNull Cosmetic cosmetic) {
|
||||
final var existingCosmetic = getCosmetic(cosmetic.getSlot());
|
||||
if (existingCosmetic == null) return false;
|
||||
return Objects.equals(cosmetic.getId(), existingCosmetic.getId());
|
||||
}
|
||||
|
||||
default boolean canEquipCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
return canEquipCosmetic(cosmetic, false);
|
||||
}
|
||||
|
||||
boolean canEquipCosmetic(@NotNull Cosmetic cosmetic, boolean ignoreWardrobe);
|
||||
|
||||
boolean updateCosmetic(@NotNull CosmeticSlot slot);
|
||||
|
||||
boolean updateMovementCosmetic(@NotNull CosmeticSlot slot, final Location from, final Location to);
|
||||
|
||||
/**
|
||||
* Just for backwards compatibility, ensures that the given viewer and the given cosmetic holder
|
||||
* represent the same user.
|
||||
*
|
||||
* @param viewer the viewer
|
||||
* @param cosmeticHolder the cosmetic holder
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
static @NotNull CosmeticUser ensureSingleCosmeticUser(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user) || !user.getUniqueId().equals(viewer.getUniqueId())) {
|
||||
throw new IllegalStateException("This method does not support having a different viewer than" +
|
||||
" the same cosmetic holder. Needs to be updated to support the overload that takes a viewer and" +
|
||||
" a cosmetic holder instead of a single CosmeticUser.");
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* Allow custom implementations of a {@link Cosmetic}.
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class CosmeticProvider {
|
||||
protected static final Map<CosmeticSlot, BiFunction<String, ConfigurationNode, Cosmetic>> MAPPINGS = Map.ofEntries(
|
||||
Map.entry(CosmeticSlot.HELMET, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.CHESTPLATE, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.LEGGINGS, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.BOOTS, CosmeticArmorType::new),
|
||||
Map.entry(CosmeticSlot.OFFHAND, CosmeticArmorType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.BACKPACK, CosmeticBackpackType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new)
|
||||
);
|
||||
|
||||
private static final String EXCEPTION_MESSAGE = "Unknown slot %s provided for mapping, if you registered your own CosmeticSlot please ensure that you've also registered a custom CosmeticProvider! Or if you have already registered a custom CosmeticProvider ensure it is registered in your plugins `onLoad` method instead of `onEnable`!";
|
||||
|
||||
/**
|
||||
* Construct the {@link Cosmetic}.
|
||||
* @param id the cosmetic id
|
||||
* @param config the configuration node of the cosmetic
|
||||
* @param slot the occupying slot of the cosmetic
|
||||
* @return the {@link Cosmetic}
|
||||
* @throws IllegalArgumentException if the provided cosmetic could not be mapped
|
||||
*/
|
||||
public @NotNull Cosmetic createCosmetic(String id, ConfigurationNode config, CosmeticSlot slot) throws IllegalArgumentException {
|
||||
final var mapper = MAPPINGS.get(slot);
|
||||
if(mapper == null) {
|
||||
throw new IllegalArgumentException(
|
||||
EXCEPTION_MESSAGE.formatted(slot)
|
||||
);
|
||||
}
|
||||
|
||||
return mapper.apply(id, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the plugin that is providing this {@link CosmeticProvider}
|
||||
* @return the plugin
|
||||
*/
|
||||
public abstract Plugin getProviderPlugin();
|
||||
|
||||
/**
|
||||
* Default Implementation.
|
||||
*/
|
||||
static class Default extends CosmeticProvider {
|
||||
public static final CosmeticProvider INSTANCE = new Default();
|
||||
|
||||
@Override
|
||||
public Plugin getProviderPlugin() {
|
||||
return HMCCosmeticsPlugin.getInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,81 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
public enum CosmeticSlot {
|
||||
HELMET,
|
||||
CHESTPLATE,
|
||||
LEGGINGS,
|
||||
BOOTS,
|
||||
MAINHAND,
|
||||
OFFHAND,
|
||||
BACKPACK,
|
||||
BALLOON,
|
||||
EMOTE,
|
||||
CUSTOM
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Getter
|
||||
public class CosmeticSlot {
|
||||
private static final ConcurrentHashMap<String, CosmeticSlot> REGISTRY = new ConcurrentHashMap<>();
|
||||
|
||||
public static final CosmeticSlot HELMET = register("HELMET");
|
||||
public static final CosmeticSlot CHESTPLATE = register("CHESTPLATE");
|
||||
public static final CosmeticSlot LEGGINGS = register("LEGGINGS");
|
||||
public static final CosmeticSlot BOOTS = register("BOOTS");
|
||||
public static final CosmeticSlot MAINHAND = register("MAINHAND");
|
||||
public static final CosmeticSlot OFFHAND = register("OFFHAND");
|
||||
public static final CosmeticSlot BACKPACK = register("BACKPACK");
|
||||
public static final CosmeticSlot BALLOON = register("BALLOON");
|
||||
|
||||
private final String name;
|
||||
|
||||
private CosmeticSlot(@NotNull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new slot with the given name. If a slot with the given name already exists, it will be returned.
|
||||
* @param name The name of the slot (This will automatically be converted into all UPPERCASE)
|
||||
* @return The slot that was registered or already exists.
|
||||
* @throws IllegalArgumentException if a cosmetic slot by that name has already been registered
|
||||
*/
|
||||
@NotNull
|
||||
public static CosmeticSlot register(@NotNull String name) {
|
||||
final String upperName = name.toUpperCase();
|
||||
if(REGISTRY.containsKey(upperName)) {
|
||||
throw new IllegalArgumentException("A cosmetic slot with name '" + name + "' is already registered.");
|
||||
}
|
||||
|
||||
final CosmeticSlot slot = new CosmeticSlot(upperName);
|
||||
REGISTRY.put(upperName, slot);
|
||||
return slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An unmodifiable map of all the slots that have been registered.
|
||||
*/
|
||||
@NotNull
|
||||
public static Map<String, CosmeticSlot> values() {
|
||||
return Collections.unmodifiableMap(REGISTRY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the slot with the given name.
|
||||
* @param name The name of the slot to get. This is automatically converted to all UPPERCASE.
|
||||
* @return The slot with the given name, or null if it does not exist.
|
||||
*/
|
||||
@Nullable
|
||||
public static CosmeticSlot valueOf(@NotNull String name) {
|
||||
final String upperName = name.toUpperCase();
|
||||
return REGISTRY.get(upperName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the registry contains a slot with the given name.
|
||||
* @param name The name of the slot to check for. This is automatically converted to all UPPERCASE.
|
||||
* @return True if the slot exists, false otherwise.
|
||||
*/
|
||||
public static boolean contains(@NotNull String name) {
|
||||
final String upperName = name.toUpperCase();
|
||||
return REGISTRY.containsKey(upperName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,12 @@ package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.CosmeticTypeRegisterEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -22,10 +19,12 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
public class Cosmetics {
|
||||
|
||||
private static final HashBiMap<String, Cosmetic> COSMETICS = HashBiMap.create();
|
||||
|
||||
private static CosmeticProvider PROVIDER = CosmeticProvider.Default.INSTANCE;
|
||||
|
||||
public static void addCosmetic(Cosmetic cosmetic) {
|
||||
COSMETICS.put(cosmetic.getId(), cosmetic);
|
||||
}
|
||||
@@ -35,7 +34,7 @@ public class Cosmetics {
|
||||
}
|
||||
|
||||
public static void removeCosmetic(Cosmetic cosmetic) {
|
||||
COSMETICS.remove(cosmetic);
|
||||
COSMETICS.remove(cosmetic.getId());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -92,30 +91,51 @@ public class Cosmetics {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom {@link CosmeticProvider} to provide your own user implementation to
|
||||
* be used and queried.
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if the provider is already registered by another plugin
|
||||
*/
|
||||
public static void registerProvider(final CosmeticProvider provider) {
|
||||
if(PROVIDER != CosmeticProvider.Default.INSTANCE) {
|
||||
throw new IllegalArgumentException("CosmeticProvider already registered by %s, this conflicts with %s attempting to register their own.".formatted(
|
||||
PROVIDER.getProviderPlugin().getName(),
|
||||
provider.getProviderPlugin().getName()
|
||||
));
|
||||
}
|
||||
|
||||
PROVIDER = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current {@link CosmeticProvider} being used.
|
||||
* @return the current {@link CosmeticProvider} being used
|
||||
*/
|
||||
public static CosmeticProvider getProvider() {
|
||||
return PROVIDER;
|
||||
}
|
||||
|
||||
private static void setupCosmetics(@NotNull CommentedConfigurationNode config) {
|
||||
for (ConfigurationNode cosmeticConfig : config.childrenMap().values()) {
|
||||
String id = cosmeticConfig.key().toString();
|
||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
||||
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
||||
if (slotNode.virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
String slot = slotNode.getString("");
|
||||
CosmeticSlot cosmeticSlot = CosmeticSlot.valueOf(slot);
|
||||
if (cosmeticSlot == null) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String id = cosmeticConfig.key().toString();
|
||||
MessagesUtil.sendDebugMessages("Attempting to add " + id);
|
||||
ConfigurationNode slotNode = cosmeticConfig.node("slot");
|
||||
if (slotNode.virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because there is no slot defined!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, slotNode.getString())) {
|
||||
MessagesUtil.sendDebugMessages("Unable to create " + id + " because " + slotNode.getString() + " is not a valid slot!", Level.WARNING);
|
||||
continue;
|
||||
}
|
||||
switch (CosmeticSlot.valueOf(slotNode.getString())) {
|
||||
case BALLOON -> new CosmeticBalloonType(id, cosmeticConfig);
|
||||
case BACKPACK -> new CosmeticBackpackType(id, cosmeticConfig);
|
||||
case MAINHAND -> new CosmeticMainhandType(id, cosmeticConfig);
|
||||
case EMOTE -> new CosmeticEmoteType(id, cosmeticConfig);
|
||||
case HELMET, CHESTPLATE, LEGGINGS, BOOTS, OFFHAND -> new CosmeticArmorType(id, cosmeticConfig);
|
||||
default -> new CosmeticTypeRegisterEvent(id, cosmeticConfig).callEvent();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (Settings.isDebugMode()) e.printStackTrace();
|
||||
addCosmetic(PROVIDER.createCosmetic(id, cosmeticConfig, cosmeticSlot));
|
||||
} catch(Exception ex) {
|
||||
log.error("Unable to construct cosmetic for {}, skipping processing it.", id, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Updates cosmetics whenever a player moves.
|
||||
*/
|
||||
public interface CosmeticMovementBehavior {
|
||||
void dispatchMove(
|
||||
@NotNull final CosmeticUser user,
|
||||
@NotNull final Location from,
|
||||
@NotNull final Location to
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.behavior;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Generic updates that happen every tick or when manually requested to be dispatched.
|
||||
*/
|
||||
public interface CosmeticUpdateBehavior {
|
||||
void dispatchUpdate(
|
||||
@NotNull final CosmeticUser user
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
@@ -15,8 +16,7 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CosmeticArmorType extends Cosmetic {
|
||||
|
||||
public class CosmeticArmorType extends Cosmetic implements CosmeticUpdateBehavior {
|
||||
private final EquipmentSlot equipSlot;
|
||||
|
||||
public CosmeticArmorType(String id, ConfigurationNode config) {
|
||||
@@ -31,8 +31,8 @@ public class CosmeticArmorType extends Cosmetic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) return;
|
||||
public void dispatchUpdate(@NotNull CosmeticUser user) {
|
||||
if (user.isInWardrobe()) return;
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
if (entity == null) return;
|
||||
if (Settings.getSlotOption(equipSlot).isRequireEmpty() && entity instanceof HumanEntity humanEntity) {
|
||||
@@ -48,9 +48,11 @@ public class CosmeticArmorType extends Cosmetic {
|
||||
}
|
||||
|
||||
public ItemStack getItem(@NotNull CosmeticUser user, ItemStack cosmeticItem) {
|
||||
if (!(user.getEntity() instanceof HumanEntity humanEntity)) return null;
|
||||
Player player = user.getPlayer();
|
||||
if (player == null) return null;
|
||||
|
||||
if (Settings.getSlotOption(equipSlot).isAddEnchantments()) {
|
||||
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
|
||||
ItemStack equippedItem = player.getInventory().getItem(equipSlot);
|
||||
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
||||
}
|
||||
// Basically, if force offhand is off AND there is no item in an offhand slot, then the equipment packet to add the cosmetic
|
||||
|
||||
@@ -2,16 +2,19 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -20,21 +23,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
@Getter
|
||||
private final String modelName;
|
||||
@Getter
|
||||
@Getter
|
||||
public class CosmeticBackpackType extends Cosmetic implements CosmeticUpdateBehavior, CosmeticMovementBehavior {
|
||||
private int height = -1;
|
||||
private ItemStack firstPersonBackpack;
|
||||
|
||||
public CosmeticBackpackType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
modelName = config.node("model").getString();
|
||||
|
||||
if (!config.node("firstperson-item").virtual()) {
|
||||
this.firstPersonBackpack = generateItemStack(config.node("firstperson-item"));
|
||||
this.height = config.node("height").getInt(5);
|
||||
@@ -42,34 +39,48 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
if (entity == null) return;
|
||||
|
||||
Location loc = entity.getLocation().clone().add(0, 2, 0);
|
||||
|
||||
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
||||
if (user.isHidden()) {
|
||||
// Sometimes the backpack is not despawned when the player is hidden (weird ass logic happening somewhere)
|
||||
user.despawnBackpack();
|
||||
public void dispatchUpdate(@NotNull CosmeticUser user) {
|
||||
Entity entity = user.getEntity();
|
||||
if(entity == null) {
|
||||
return;
|
||||
}
|
||||
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
|
||||
|
||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
Location entityLocation = entity.getLocation();
|
||||
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||
|
||||
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||
if(backpackManager == null) return;
|
||||
|
||||
UserEntity entityManager = backpackManager.getEntityManager();
|
||||
if(entityManager == null) return;
|
||||
|
||||
entityManager.teleport(loc);
|
||||
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
|
||||
int firstArmorStandId = backpackManager.getFirstArmorStandId();
|
||||
|
||||
List<Player> newViewers = entityManager.refreshViewers(loc);
|
||||
|
||||
if(!newViewers.isEmpty()) {
|
||||
HMCCPacketManager.spawnInvisibleArmorstand(firstArmorStandId, entityLocation, UUID.randomUUID(), newViewers);
|
||||
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), newViewers);
|
||||
|
||||
if (user.getPlayer() != null) {
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(user.getUserBackpackManager().getFirstArmorStandId(), scaleAttribute.getValue(), newViewers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||
HMCCPacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, 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 (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
|
||||
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, entityManager.getViewers());
|
||||
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, newViewers);
|
||||
|
||||
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
|
||||
if (isFirstPersonCompadible() && !user.isInWardrobe() && user.getPlayer() != null) {
|
||||
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++) {
|
||||
if (i == 0) {
|
||||
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), particleCloud.get(i), owner);
|
||||
@@ -77,23 +88,38 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
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), firstArmorStandId, owner);
|
||||
if (!user.isHidden()) {
|
||||
//if (loc.getPitch() < -70) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, new ItemStack(Material.AIR), owner);
|
||||
//else NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, firstPersonBackpack, owner);
|
||||
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
||||
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, firstPersonBackpack), owner);
|
||||
}
|
||||
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
||||
}
|
||||
|
||||
user.getUserBackpackManager().showBackpack();
|
||||
backpackManager.showBackpack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchMove(@NotNull CosmeticUser user, @NotNull Location from, @NotNull Location to) {
|
||||
@SuppressWarnings("DuplicatedCode") // thanks.
|
||||
Entity entity = user.getEntity();
|
||||
if(entity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location entityLocation = entity.getLocation();
|
||||
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||
|
||||
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||
if(backpackManager == null) return;
|
||||
|
||||
UserEntity entityManager = backpackManager.getEntityManager();
|
||||
if(entityManager == null) return;
|
||||
|
||||
entityManager.teleport(loc);
|
||||
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
}
|
||||
|
||||
public boolean isFirstPersonCompadible() {
|
||||
return firstPersonBackpack != null;
|
||||
}
|
||||
|
||||
public ItemStack getFirstPersonBackpack() {
|
||||
return firstPersonBackpack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
@@ -17,12 +20,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CosmeticBalloonType extends Cosmetic {
|
||||
public class CosmeticBalloonType extends Cosmetic implements CosmeticUpdateBehavior, CosmeticMovementBehavior {
|
||||
|
||||
@Getter
|
||||
private final String modelName;
|
||||
@Getter
|
||||
private List<String> dyableParts;
|
||||
private List<String> dyeableParts;
|
||||
@Getter
|
||||
private final boolean showLead;
|
||||
@Getter
|
||||
@@ -41,8 +44,8 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
balloonOffset = Settings.loadVector(balloonOffsetNode);
|
||||
|
||||
try {
|
||||
if (!config.node("dyable-parts").virtual()) {
|
||||
dyableParts = config.node("dyable-parts").getList(String.class);
|
||||
if (!config.node("dyeable-parts").virtual()) {
|
||||
dyeableParts = config.node("dyeable-parts").getList(String.class);
|
||||
}
|
||||
} catch (SerializationException e) {
|
||||
// Seriously?
|
||||
@@ -53,7 +56,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
public void dispatchUpdate(@NotNull CosmeticUser user) {
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||
|
||||
@@ -65,6 +68,29 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
return;
|
||||
}
|
||||
|
||||
Location newLocation = entity.getLocation();
|
||||
newLocation = newLocation.clone().add(getBalloonOffset());
|
||||
if (Settings.isBalloonHeadForward()) newLocation.setPitch(0);
|
||||
|
||||
if (!user.isHidden() && showLead) {
|
||||
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
|
||||
if (sendTo.isEmpty()) return;
|
||||
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchMove(@NotNull CosmeticUser user, @NotNull Location from, @NotNull Location to) {
|
||||
Entity entity = Bukkit.getEntity(user.getUniqueId());
|
||||
UserBalloonManager userBalloonManager = user.getBalloonManager();
|
||||
|
||||
if (entity == null || userBalloonManager == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
|
||||
if (!userBalloonManager.getModelEntity().isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location newLocation = entity.getLocation();
|
||||
Location currentLocation = user.getBalloonManager().getLocation();
|
||||
newLocation = newLocation.clone().add(getBalloonOffset());
|
||||
@@ -79,26 +105,22 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
}
|
||||
|
||||
Vector velocity = newLocation.toVector().subtract(currentLocation.toVector());
|
||||
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||
userBalloonManager.setLocation(newLocation);
|
||||
userBalloonManager.setVelocity(velocity.multiply(1.1));
|
||||
|
||||
MessagesUtil.sendDebugMessages("Balloon Cosmetic Update for " + user.getEntity().getName());
|
||||
MessagesUtil.sendDebugMessages("Ballon previous location is " + currentLocation);
|
||||
MessagesUtil.sendDebugMessages("Balloon location set to " + newLocation);
|
||||
MessagesUtil.sendDebugMessages("Balloon velocity set to " + velocity);
|
||||
|
||||
HMCCPacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer);
|
||||
HMCCPacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer);
|
||||
if (user.isHidden()) {
|
||||
userBalloonManager.getPufferfish().hidePufferfish();
|
||||
return;
|
||||
}
|
||||
if (!user.isHidden() && showLead) {
|
||||
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
|
||||
if (sendTo.isEmpty()) return;
|
||||
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDyablePart(String name) {
|
||||
public boolean isDyeablePart(String name) {
|
||||
// If player does not define parts, dye whole model
|
||||
if (dyableParts == null) return true;
|
||||
if (dyableParts.isEmpty()) return true;
|
||||
return dyableParts.contains(name);
|
||||
if (dyeableParts == null) return true;
|
||||
if (dyeableParts.isEmpty()) return true;
|
||||
return dyeableParts.contains(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CosmeticEmoteType extends Cosmetic {
|
||||
|
||||
private final String animationId;
|
||||
private final String text;
|
||||
|
||||
public CosmeticEmoteType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
|
||||
animationId = config.node("animation").getString();
|
||||
text = config.node("text").getString();
|
||||
MessagesUtil.sendDebugMessages("CosmeticEmoteType Animation id " + animationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(CosmeticUser user) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
public void run(@NotNull CosmeticUser user) {
|
||||
user.getUserEmoteManager().playEmote(this);
|
||||
}
|
||||
|
||||
public String getAnimationId() {
|
||||
return animationId;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CosmeticMainhandType extends Cosmetic {
|
||||
|
||||
public CosmeticMainhandType(String id, ConfigurationNode config) {
|
||||
super(id, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
Player player = user.getPlayer();
|
||||
|
||||
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPlayerUtils.getNearbyPlayers(player));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.database.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
@@ -9,7 +8,6 @@ import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -87,7 +85,7 @@ public abstract class Data {
|
||||
|
||||
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
|
||||
switch (reason) {
|
||||
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED -> {
|
||||
case EMOTE, NONE, GAMEMODE, WORLD, DISABLED, POTION -> {
|
||||
return false;
|
||||
}
|
||||
default -> {
|
||||
|
||||
@@ -38,12 +38,14 @@ public class MySQLData extends SQLData {
|
||||
HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance();
|
||||
try {
|
||||
openConnection();
|
||||
if (connection == null) throw new NullPointerException("Connection is null");
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
if (connection == null) throw new IllegalStateException("Connection is null");
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
"(UUID varchar(36) PRIMARY KEY, " +
|
||||
"COSMETICS MEDIUMTEXT " +
|
||||
");").execute();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
");")) {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
} catch (SQLException | IllegalStateException e) {
|
||||
plugin.getLogger().severe("");
|
||||
plugin.getLogger().severe("");
|
||||
plugin.getLogger().severe("MySQL DATABASE CAN NOT BE REACHED.");
|
||||
@@ -60,32 +62,20 @@ public class MySQLData extends SQLData {
|
||||
@Override
|
||||
public void clear(UUID uniqueId) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
PreparedStatement preparedSt = null;
|
||||
try {
|
||||
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
||||
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
|
||||
preparedSt.setString(1, uniqueId.toString());
|
||||
preparedSt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (preparedSt != null) preparedSt.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openConnection() throws SQLException {
|
||||
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
// ...
|
||||
// });
|
||||
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
||||
|
||||
// Connection isn't null AND Connection isn't closed :: return
|
||||
try {
|
||||
if (isConnectionOpen()) {
|
||||
return;
|
||||
} else if (connection != null) close(); // Close connection if still active
|
||||
if (isConnectionOpen()) return;
|
||||
if (connection != null) close(); // Close connection if still active
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace(); // If isConnectionOpen() throws error
|
||||
}
|
||||
@@ -94,17 +84,15 @@ public class MySQLData extends SQLData {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, setupProperties());
|
||||
} catch (SQLException e) {
|
||||
} catch (SQLException | ClassNotFoundException e) {
|
||||
System.out.println(e.getMessage());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
try {
|
||||
if (connection == null) throw new NullPointerException("Connection is null");
|
||||
if (connection == null) throw new IllegalStateException("Connection is null");
|
||||
connection.close();
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
@@ -115,13 +103,12 @@ public class MySQLData extends SQLData {
|
||||
@NotNull
|
||||
private Properties setupProperties() {
|
||||
Properties props = new Properties();
|
||||
props.put("user", user);
|
||||
props.put("password", password);
|
||||
props.put("autoReconnect", "true");
|
||||
props.setProperty("user", user);
|
||||
props.setProperty("password", password);
|
||||
return props;
|
||||
}
|
||||
|
||||
private boolean isConnectionOpen() throws RuntimeException {
|
||||
private boolean isConnectionOpen() {
|
||||
try {
|
||||
return connection != null && !connection.isClosed();
|
||||
} catch (SQLException e) {
|
||||
@@ -143,12 +130,12 @@ public class MySQLData extends SQLData {
|
||||
}
|
||||
|
||||
try {
|
||||
if (connection == null) throw new NullPointerException("Connection is null");
|
||||
if (connection == null) throw new IllegalStateException("Connection is null");
|
||||
ps = connection.prepareStatement(query);
|
||||
} catch (SQLException | NullPointerException e) {
|
||||
} catch (SQLException | IllegalStateException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return ps;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@@ -23,22 +22,17 @@ public abstract class SQLData extends Data {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
UserData data = new UserData(uniqueId);
|
||||
|
||||
PreparedStatement preparedStatement = null;
|
||||
try {
|
||||
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
|
||||
try (PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;")){
|
||||
preparedStatement.setString(1, uniqueId.toString());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
if (rs.next()) {
|
||||
String rawData = rs.getString("COSMETICS");
|
||||
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
|
||||
data.setCosmetics(cosmetics);
|
||||
try (ResultSet rs = preparedStatement.executeQuery()) {
|
||||
if (rs.next()) {
|
||||
String rawData = rs.getString("COSMETICS");
|
||||
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
|
||||
data.setCosmetics(cosmetics);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (preparedStatement != null) preparedStatement.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
return data;
|
||||
});
|
||||
@@ -48,18 +42,12 @@ public abstract class SQLData extends Data {
|
||||
@SuppressWarnings("resource")
|
||||
public void save(CosmeticUser user) {
|
||||
Runnable run = () -> {
|
||||
PreparedStatement preparedSt = null;
|
||||
try {
|
||||
preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
|
||||
try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
|
||||
preparedSt.setString(1, user.getUniqueId().toString());
|
||||
preparedSt.setString(2, serializeData(user));
|
||||
preparedSt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (preparedSt != null) preparedSt.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
};
|
||||
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {
|
||||
|
||||
@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
|
||||
|
||||
openConnection();
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
|
||||
"(UUID varchar(36) PRIMARY KEY, " +
|
||||
"COSMETICS MEDIUMTEXT " +
|
||||
");").execute();
|
||||
");")) {
|
||||
preparedStatement.execute();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -48,27 +50,16 @@ public class SQLiteData extends SQLData {
|
||||
@SuppressWarnings("resource")
|
||||
public void clear(UUID uniqueId) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
PreparedStatement preparedSt = null;
|
||||
try {
|
||||
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
|
||||
try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
|
||||
preparedSt.setString(1, uniqueId.toString());
|
||||
preparedSt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (preparedSt != null) preparedSt.close();
|
||||
} catch (SQLException e) {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openConnection() throws SQLException {
|
||||
// Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
// ...
|
||||
// });
|
||||
// connection = DriverManager.getConnection("jdbc:mysql://" + DatabaseSettings.getHost() + ":" + DatabaseSettings.getPort() + "/" + DatabaseSettings.getDatabase(), setupProperties());
|
||||
|
||||
if (connection != null && !connection.isClosed()) return;
|
||||
|
||||
// Close Connection if still active
|
||||
@@ -88,9 +79,12 @@ public class SQLiteData extends SQLData {
|
||||
@Override
|
||||
public PreparedStatement preparedStatement(String query) {
|
||||
PreparedStatement ps = null;
|
||||
if (!isConnectionOpen()) MessagesUtil.sendDebugMessages("Connection is not open");
|
||||
|
||||
try {
|
||||
if (!isConnectionOpen()) {
|
||||
MessagesUtil.sendDebugMessages("Connection is not open");
|
||||
openConnection();
|
||||
}
|
||||
ps = connection.prepareStatement(query);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.emotes;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.ticxo.playeranimator.api.PlayerAnimator;
|
||||
import com.ticxo.playeranimator.api.animation.pack.AnimationPack;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Manages Emotes
|
||||
*/
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
public class EmoteManager {
|
||||
private static final @NotNull Map<String, String> emotes = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Loads all BlockBench animations from the emotes folder and puts it into the animation manager registry and local registry
|
||||
*/
|
||||
public static void loadEmotes() {
|
||||
// Clear the PlayerAnimator and local registries
|
||||
PlayerAnimator.api.getAnimationManager().clearRegistry();
|
||||
emotes.clear();
|
||||
|
||||
// Get the emote directory and check if it exists
|
||||
File emoteDir = new File(HMCCosmeticsPlugin.getInstance().getDataFolder().getPath() + "/emotes/");
|
||||
if (!emoteDir.exists()) return;
|
||||
|
||||
// Get all the files inside the directory and check if it isn't 0
|
||||
File[] emoteFiles = emoteDir.listFiles();
|
||||
if (emoteFiles == null || emoteFiles.length == 0) return;
|
||||
|
||||
// Remove any files that don't have the file extension ".bbmodel" and check if there are still resulting files
|
||||
emoteFiles = Arrays.stream(emoteFiles).filter(file -> file.getPath().endsWith(".bbmodel")).distinct().toArray(File[]::new);
|
||||
if (emoteFiles.length == 0) return;
|
||||
|
||||
// Loop through all files, importing all block bench animations into the registry
|
||||
for (File animationFile : emoteFiles) {
|
||||
String animationKey = FilenameUtils.removeExtension(animationFile.getName());
|
||||
PlayerAnimator.api.getAnimationManager().importAnimations(animationKey, animationFile);
|
||||
}
|
||||
|
||||
// Loops through all the entries in the registries and unpacks any animation packs to ensure if there were multiple animations
|
||||
// inside a singular file, that they are added to the local registry individually for tab completion
|
||||
for (Map.Entry<String, AnimationPack> packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) {
|
||||
packEntry.getValue().getAnimations().keySet().forEach(animationName -> {
|
||||
// API key is the format "animationKey.animationFileName.animationName"
|
||||
String apiKey = packEntry.getKey().replace(":", ".") + "." + animationName;
|
||||
emotes.put(animationName, apiKey);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if there is an animation with the specified name
|
||||
* @param animationName Name whose presence is to be tested
|
||||
* @return True if this registry contains a mapping for the specified name
|
||||
*/
|
||||
public static boolean has(@NotNull String animationName) {
|
||||
return emotes.containsKey(animationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code API key} to which the specified name is mapped, or {@code null} if this map contains no mapping for the name.
|
||||
* @param animationName Name whose {@code API key} is to be fetched
|
||||
* @return The {@code API key} of the specified name or {@code null} if there was no animation name found
|
||||
*/
|
||||
public static @Nullable String get(@NotNull String animationName) {
|
||||
return emotes.get(animationName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a set of all the laoded animation names
|
||||
* @return A set of all loaded animation names
|
||||
*/
|
||||
public static @NotNull Set<String> getAllNames() {
|
||||
return emotes.keySet();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Types;
|
||||
@@ -11,13 +13,13 @@ import com.hibiscusmc.hmccosmetics.gui.type.types.TypeCosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import dev.triumphteam.gui.builder.item.ItemBuilder;
|
||||
import dev.triumphteam.gui.components.GuiType;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.config.serializer.ItemSerializer;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.util.AdventureUtils;
|
||||
import me.lojosho.hibiscuscommons.util.StringUtils;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -52,7 +54,7 @@ public class Menu {
|
||||
private final boolean shading;
|
||||
|
||||
public Menu(String id, @NotNull ConfigurationNode config) {
|
||||
this.id = id;
|
||||
this.id = config.node("id").getString(id);
|
||||
this.config = config;
|
||||
|
||||
title = config.node("title").getString("chest");
|
||||
@@ -104,8 +106,7 @@ public class Menu {
|
||||
|
||||
int priority = config.node("priority").getInt(1);
|
||||
|
||||
Type type = null;
|
||||
|
||||
Type type = Types.getDefaultType();
|
||||
if (!config.node("type").virtual()) {
|
||||
String typeId = config.node("type").getString("");
|
||||
if (Types.isType(typeId)) type = Types.getType(typeId);
|
||||
@@ -119,7 +120,7 @@ public class Menu {
|
||||
menuItems.sort(priorityCompare);
|
||||
items.put(slot, menuItems);
|
||||
} else {
|
||||
items.put(slot, new ArrayList<>(Arrays.asList(menuItem)));
|
||||
items.put(slot, new ArrayList<>(List.of(menuItem)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,16 +133,25 @@ public class Menu {
|
||||
public void openMenu(@NotNull CosmeticUser user, boolean ignorePermission) {
|
||||
Player player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
openMenu(player, user, ignorePermission);
|
||||
}
|
||||
|
||||
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder) {
|
||||
openMenu(viewer, cosmeticHolder, false);
|
||||
}
|
||||
|
||||
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, boolean ignorePermission) {
|
||||
if (!ignorePermission && !permissionNode.isEmpty()) {
|
||||
if (!player.hasPermission(permissionNode) && !player.isOp()) {
|
||||
MessagesUtil.sendMessage(player, "no-permission");
|
||||
if (!viewer.hasPermission(permissionNode) && !viewer.isOp()) {
|
||||
MessagesUtil.sendMessage(viewer, "no-permission");
|
||||
return;
|
||||
}
|
||||
}
|
||||
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
|
||||
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, this.title));
|
||||
Gui gui = Gui.gui()
|
||||
.title(component)
|
||||
.rows(this.rows)
|
||||
.type(GuiType.CHEST)
|
||||
.inventory((title, owner, type) -> Bukkit.createInventory(owner, rows * 9, title))
|
||||
.create();
|
||||
|
||||
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
@@ -153,7 +163,7 @@ public class Menu {
|
||||
Bukkit.getScheduler().cancelTask(taskid.get());
|
||||
}
|
||||
|
||||
updateMenu(user, gui);
|
||||
updateMenu(viewer, cosmeticHolder, gui);
|
||||
};
|
||||
|
||||
if (refreshRate != -1) {
|
||||
@@ -164,22 +174,36 @@ public class Menu {
|
||||
});
|
||||
|
||||
gui.setCloseGuiAction(event -> {
|
||||
if (cosmeticHolder instanceof CosmeticUser user) {
|
||||
PlayerMenuCloseEvent closeEvent = new PlayerMenuCloseEvent(user, this, event.getReason());
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(closeEvent));
|
||||
}
|
||||
|
||||
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
|
||||
});
|
||||
|
||||
// API
|
||||
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(event));
|
||||
if (event.isCancelled()) return;
|
||||
// Internal
|
||||
Runnable openGuiTask = () -> {
|
||||
gui.open(viewer);
|
||||
updateMenu(viewer, cosmeticHolder, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
|
||||
};
|
||||
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
gui.open(player);
|
||||
updateMenu(user, gui); // fixes shading? I know I do this twice but it's easier than writing a whole new class to deal with this shit
|
||||
});
|
||||
// API
|
||||
if (cosmeticHolder instanceof CosmeticUser user) {
|
||||
PlayerMenuOpenEvent event = new PlayerMenuOpenEvent(user, this);
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
openGuiTask.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
// Internal
|
||||
else {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), openGuiTask);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMenu(CosmeticUser user, Gui gui) {
|
||||
private void updateMenu(Player viewer, CosmeticHolder cosmeticHolder, Gui gui) {
|
||||
StringBuilder title = new StringBuilder(this.title);
|
||||
|
||||
int row = 0;
|
||||
@@ -203,15 +227,15 @@ public class Menu {
|
||||
// Handles the items
|
||||
List<MenuItem> menuItems = items.get(i);
|
||||
MenuItem item = menuItems.get(0);
|
||||
updateItem(user, gui, i);
|
||||
updateItem(viewer, cosmeticHolder, gui, i);
|
||||
|
||||
if (item.type() instanceof TypeCosmetic) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(item.itemConfig().node("cosmetic").getString(""));
|
||||
if (cosmetic == null) continue;
|
||||
if (user.hasCosmeticInSlot(cosmetic)) {
|
||||
if (cosmeticHolder.hasCosmeticInSlot(cosmetic)) {
|
||||
title.append(Settings.getEquippedCosmeticColor());
|
||||
} else {
|
||||
if (user.canEquipCosmetic(cosmetic, true)) {
|
||||
if (cosmeticHolder.canEquipCosmetic(cosmetic, true)) {
|
||||
title.append(Settings.getEquipableCosmeticColor());
|
||||
} else {
|
||||
title.append(Settings.getLockedCosmeticColor());
|
||||
@@ -227,42 +251,42 @@ public class Menu {
|
||||
}
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("Updated menu with title " + title);
|
||||
gui.updateTitle(StringUtils.parseStringToString(Hooks.processPlaceholders(user.getPlayer(), title.toString())));
|
||||
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, title.toString())));
|
||||
} else {
|
||||
for (int i = 0; i < gui.getInventory().getSize(); i++) {
|
||||
if (items.containsKey(i)) {
|
||||
updateItem(user, gui, i);
|
||||
updateItem(viewer, cosmeticHolder, gui, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateItem(CosmeticUser user, Gui gui, int slot) {
|
||||
private void updateItem(Player viewer, CosmeticHolder cosmeticHolder, Gui gui, int slot) {
|
||||
if (!items.containsKey(slot)) return;
|
||||
List<MenuItem> menuItems = items.get(slot);
|
||||
if (menuItems.isEmpty()) return;
|
||||
|
||||
for (MenuItem item : menuItems) {
|
||||
Type type = item.type();
|
||||
ItemStack modifiedItem = getMenuItem(user, type, item.itemConfig(), item.item().clone(), slot);
|
||||
ItemStack modifiedItem = getMenuItem(viewer, cosmeticHolder, type, item.itemConfig(), item.item().clone(), slot);
|
||||
if (modifiedItem.getType().isAir()) continue;
|
||||
GuiItem guiItem = ItemBuilder.from(modifiedItem).asGuiItem();
|
||||
guiItem.setAction(event -> {
|
||||
UUID uuid = user.getUniqueId();
|
||||
UUID uuid = viewer.getUniqueId();
|
||||
if (Settings.isMenuClickCooldown()) {
|
||||
Long userCooldown = Menus.getCooldown(uuid);
|
||||
if (userCooldown != 0 && (System.currentTimeMillis() - Menus.getCooldown(uuid) <= getCooldown())) {
|
||||
MessagesUtil.sendDebugMessages("Cooldown for " + user.getUniqueId() + " System time: " + System.currentTimeMillis() + " Cooldown: " + Menus.getCooldown(user.getUniqueId()) + " Difference: " + (System.currentTimeMillis() - Menus.getCooldown(user.getUniqueId())));
|
||||
MessagesUtil.sendMessage(user.getPlayer(), "on-click-cooldown");
|
||||
MessagesUtil.sendDebugMessages("Cooldown for " + viewer.getUniqueId() + " System time: " + System.currentTimeMillis() + " Cooldown: " + Menus.getCooldown(viewer.getUniqueId()) + " Difference: " + (System.currentTimeMillis() - Menus.getCooldown(viewer.getUniqueId())));
|
||||
MessagesUtil.sendMessage(viewer, "on-click-cooldown");
|
||||
return;
|
||||
} else {
|
||||
Menus.addCooldown(user.getUniqueId(), System.currentTimeMillis());
|
||||
Menus.addCooldown(uuid, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
MessagesUtil.sendDebugMessages("Updated Menu Item in slot number " + slot);
|
||||
final ClickType clickType = event.getClick();
|
||||
if (type != null) type.run(user, item.itemConfig(), clickType);
|
||||
updateMenu(user, gui);
|
||||
if (type != null) type.run(viewer, cosmeticHolder, item.itemConfig(), clickType);
|
||||
updateMenu(viewer, cosmeticHolder, gui);
|
||||
});
|
||||
|
||||
MessagesUtil.sendDebugMessages("Set an item in slot " + slot + " in the menu of " + getId());
|
||||
@@ -297,11 +321,11 @@ public class Menu {
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Contract("_, _, _, _, _ -> param2")
|
||||
@Contract("_, _, _, _, _, _ -> param4")
|
||||
@NotNull
|
||||
private ItemStack getMenuItem(CosmeticUser user, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
private ItemStack getMenuItem(Player viewer, CosmeticHolder cosmeticHolder, Type type, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
if (!itemStack.hasItemMeta()) return itemStack;
|
||||
return type.setItem(user, config, itemStack, slot);
|
||||
return type.setItem(viewer, cosmeticHolder, config, itemStack, slot);
|
||||
}
|
||||
|
||||
public boolean canOpen(Player player) {
|
||||
|
||||
@@ -3,9 +3,10 @@ package com.hibiscusmc.hmccosmetics.gui;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record MenuItem(List<Integer> slots, ItemStack item, Type type, int priority, ConfigurationNode itemConfig) {
|
||||
public record MenuItem(@NotNull List<Integer> slots, @NotNull ItemStack item, Type type, int priority, ConfigurationNode itemConfig) {
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
@@ -22,10 +23,11 @@ public class Menus {
|
||||
private static final HashMap<String, Menu> MENUS = new HashMap<>();
|
||||
private static final HashMap<UUID, Long> COOLDOWNS = new HashMap<>();
|
||||
|
||||
public static void addMenu(Menu menu) {
|
||||
public static void addMenu(@NotNull Menu menu) {
|
||||
MENUS.put(menu.getId().toUpperCase(), menu);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Menu getMenu(@NotNull String id) {
|
||||
return MENUS.get(id.toUpperCase());
|
||||
}
|
||||
@@ -40,11 +42,18 @@ public class Menus {
|
||||
return MENUS.containsKey(id.toUpperCase());
|
||||
}
|
||||
|
||||
public static boolean hasMenu(Menu menu) {
|
||||
public static boolean hasMenu(@NotNull Menu menu) {
|
||||
return MENUS.containsValue(menu);
|
||||
}
|
||||
|
||||
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
|
||||
public static boolean hasDefaultMenu() {
|
||||
return MENUS.containsKey(Settings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Menu getDefaultMenu() {
|
||||
return Menus.getMenu(Settings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getMenuNames() {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Action {
|
||||
@@ -16,5 +18,13 @@ public abstract class Action {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
run(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #run(Player, CosmeticHolder, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void run(CosmeticUser user, String raw);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.actions.*;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Actions {
|
||||
@@ -28,7 +31,6 @@ public class Actions {
|
||||
private static final ActionCosmeticHide ACTION_HIDE = new ActionCosmeticHide();
|
||||
private static final ActionCosmeticToggle ACTION_TOGGLE = new ActionCosmeticToggle();
|
||||
|
||||
|
||||
public static Action getAction(@NotNull String id) {
|
||||
return actions.get(id.toUpperCase());
|
||||
}
|
||||
@@ -41,16 +43,20 @@ public class Actions {
|
||||
actions.put(action.getId().toUpperCase(), action);
|
||||
}
|
||||
|
||||
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
|
||||
public static void runActions(Player viewer, CosmeticHolder cosmeticHolder, @NotNull List<String> raw) {
|
||||
for (String a : raw) {
|
||||
String id = StringUtils.substringBetween(a, "[", "]").toUpperCase();
|
||||
String id = StringUtils.substringBetween(a, "[", "]");
|
||||
String message = StringUtils.substringAfter(a, "] ");
|
||||
MessagesUtil.sendDebugMessages("ID is " + id + " // Raw Data is " + message);
|
||||
if (isAction(id)) {
|
||||
getAction(id).run(user, message);
|
||||
if (id != null && isAction(id.toUpperCase())) {
|
||||
getAction(id).run(viewer, cosmeticHolder, message);
|
||||
} else {
|
||||
MessagesUtil.sendDebugMessages("Possible ids: " + actions.keySet());
|
||||
MessagesUtil.sendDebugMessages("Invalid Action ID (" + id + ") used in menus (Full raw: '" + a + "'). Make sure all actions are properly typed out. Here are all possible actions: " + actions.keySet(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void runActions(CosmeticUser user, @NotNull List<String> raw) {
|
||||
runActions(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCloseMenu extends Action {
|
||||
@@ -10,8 +12,13 @@ public class ActionCloseMenu extends Action {
|
||||
super("close");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
viewer.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
user.getPlayer().closeInventory();
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionConsoleCommand extends Action {
|
||||
@@ -13,8 +15,15 @@ public class ActionConsoleCommand extends Action {
|
||||
super("console-command");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
// todo: some of these generalizations may require more specific implementations, for example,
|
||||
// todo: what if we wanted to execute console commands only for the cosmetic holder?
|
||||
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(viewer, raw));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
HMCCosmeticsPlugin.getInstance().getServer().dispatchCommand(Bukkit.getConsoleSender(), Hooks.processPlaceholders(user.getPlayer(), raw));
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCosmeticHide extends Action {
|
||||
@@ -11,8 +13,14 @@ public class ActionCosmeticHide extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||
if (user.isHidden()) return;
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCosmeticShow extends Action {
|
||||
@@ -11,11 +13,17 @@ public class ActionCosmeticShow extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||
if (!user.isHidden()) return;
|
||||
|
||||
// Do not hide if it's already off for WG
|
||||
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionCosmeticToggle extends Action {
|
||||
@@ -11,7 +13,8 @@ public class ActionCosmeticToggle extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!(cosmeticHolder instanceof CosmeticUser user)) return;
|
||||
if (user.isHidden()) {
|
||||
if (!user.isHidden(CosmeticUser.HiddenReason.ACTION) && !user.isHidden(CosmeticUser.HiddenReason.COMMAND)) return;
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
@@ -20,4 +23,9 @@ public class ActionCosmeticToggle extends Action {
|
||||
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ActionEquip extends Action {
|
||||
|
||||
@@ -12,10 +14,15 @@ public class ActionEquip extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(raw);
|
||||
if (cosmetic == null) return;
|
||||
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
cosmeticHolder.addCosmetic(cosmetic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@@ -15,7 +17,7 @@ public class ActionMenu extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
boolean ignorePermission = false;
|
||||
|
||||
raw = raw.replaceAll(" ", ""); // Removes all spaces
|
||||
@@ -32,6 +34,11 @@ public class ActionMenu extends Action {
|
||||
|
||||
Menu menu = Menus.getMenu(raw);
|
||||
MessagesUtil.sendDebugMessages(raw + " | " + ignorePermission);
|
||||
menu.openMenu(user, ignorePermission);
|
||||
menu.openMenu(viewer, cosmeticHolder, ignorePermission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionMessage extends Action {
|
||||
@@ -11,8 +13,13 @@ public class ActionMessage extends Action {
|
||||
super("message");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
MessagesUtil.sendMessageNoKey(viewer, raw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
MessagesUtil.sendMessageNoKey(user.getPlayer(), raw);
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
@@ -24,7 +25,7 @@ public class ActionParticle extends Action {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void run(CosmeticUser user, @NotNull String raw) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
String[] rawString = raw.split(" ");
|
||||
ParticleType<?, ?> particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
|
||||
if (particleType == null) {
|
||||
@@ -43,9 +44,14 @@ public class ActionParticle extends Action {
|
||||
}
|
||||
|
||||
particle = HMCCServerUtils.addParticleValues(particle, rawString);
|
||||
Location location = user.getPlayer().getLocation();
|
||||
Location location = viewer.getLocation();
|
||||
for (Player player : HMCCPacketManager.getViewers(location)) {
|
||||
particle.compile().send(player, location);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, @NotNull String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ActionPlayerCommand extends Action {
|
||||
@@ -12,8 +14,14 @@ public class ActionPlayerCommand extends Action {
|
||||
super("player-command");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
// todo: what if we wanted the cosmetic holder to execute the command instead
|
||||
viewer.performCommand(MessagesUtil.processStringNoKeyString(viewer, Hooks.processPlaceholders(viewer, raw)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), Hooks.processPlaceholders(user.getPlayer(), raw)));
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
@@ -16,8 +17,7 @@ public class ActionSound extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
||||
Player player = user.getPlayer();
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
String[] processedString = raw.split(" ");
|
||||
|
||||
String soundName = processedString[0];
|
||||
@@ -31,6 +31,11 @@ public class ActionSound extends Action {
|
||||
|
||||
MessagesUtil.sendDebugMessages("Attempting to play " + soundName, Level.INFO);
|
||||
|
||||
player.playSound(player.getLocation(), soundName, volume, pitch);
|
||||
viewer.playSound(viewer.getLocation(), soundName, volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, @NotNull String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ActionUnequip extends Action {
|
||||
|
||||
@@ -12,10 +13,15 @@ public class ActionUnequip extends Action {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, String raw) {
|
||||
if (!CosmeticSlot.contains(raw)) return;
|
||||
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
||||
user.removeCosmeticSlot(slot);
|
||||
cosmeticHolder.removeCosmeticSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
run(user.getPlayer(), user, raw);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,20 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.special;
|
||||
|
||||
import com.hibiscusmc.hmccolor.HMCColorApi;
|
||||
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
|
||||
import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.util.ColorBuilder;
|
||||
import me.lojosho.hibiscuscommons.util.StringUtils;
|
||||
import org.bukkit.*;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
public interface DyeMenu {
|
||||
|
||||
public class DyeMenu {
|
||||
/**
|
||||
* Overrideable method that is called when a player wishing to dye a menu.
|
||||
* After the method is called, the menu plugin itself is supposed to handle everything else, including adding the cosmetic to the CosmeticHolder
|
||||
*
|
||||
* @param viewer The player that is viewing the menu
|
||||
* @param cosmeticHolder The CosmeticHolder that is being dyed (Can be different from the viewer)
|
||||
* @param cosmetic (The cosmetic that is wished to be dyed)
|
||||
*/
|
||||
void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic);
|
||||
|
||||
public static void openMenu(@NotNull CosmeticUser user, Cosmetic cosmetic) {
|
||||
Player player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
if (!Hooks.isActiveHook("HMCColor")) {
|
||||
addCosmetic(user, cosmetic, null);
|
||||
return;
|
||||
}
|
||||
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
||||
if (originalItem == null || !cosmetic.isDyable()) return;
|
||||
|
||||
Gui gui = HMCColorApi.createColorMenu(player);
|
||||
gui.updateTitle(Hooks.processPlaceholders(player, StringUtils.parseStringToString(Settings.getDyeMenuName())));
|
||||
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
|
||||
gui.setDefaultTopClickAction(event -> {
|
||||
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
|
||||
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
|
||||
if (item == null) return;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return;
|
||||
|
||||
Color color = null;
|
||||
if (meta instanceof LeatherArmorMeta leatherMeta) {
|
||||
color = leatherMeta.getColor();
|
||||
} else if (meta instanceof PotionMeta potionMeta) {
|
||||
color = potionMeta.getColor();
|
||||
} else if (meta instanceof MapMeta mapMeta) {
|
||||
color = mapMeta.getColor();
|
||||
} else if (meta instanceof FireworkEffectMeta fireworkEffectMeta) {
|
||||
FireworkEffect effect = fireworkEffectMeta.getEffect();
|
||||
if (effect != null) {
|
||||
color = effect.getColors().stream().findFirst().isPresent() ? effect.getColors().stream().findFirst().get() : null;
|
||||
}
|
||||
}
|
||||
if (color == null) return;
|
||||
|
||||
addCosmetic(user, cosmetic, color);
|
||||
event.setCancelled(true);
|
||||
} else event.setCancelled(true);
|
||||
});
|
||||
|
||||
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
|
||||
gui.setCloseGuiAction(event -> {});
|
||||
gui.open(player);
|
||||
}
|
||||
|
||||
private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
|
||||
Player player = user.getPlayer();
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
player.closeInventory();
|
||||
user.updateCosmetic(cosmetic.getSlot());
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.special;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DyeMenuProvider {
|
||||
|
||||
private static DyeMenu instance = null;
|
||||
|
||||
/**
|
||||
* Sets the provider of the DyeMenu. Check {@link DyeMenuProvider#hasMenuProvider()} before attempting to set this,
|
||||
* it is locked once a dye menu has been set!
|
||||
* @param dyeMenu The dye menu implementation that wishes to be the provider.
|
||||
* @throws IllegalStateException IllegalStateException will be thrown if a dye menu provider already is set by another plugin.
|
||||
*/
|
||||
public static void setDyeMenuProvider(@NotNull DyeMenu dyeMenu) throws IllegalStateException {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("DyeMenu Implementation has already been set by another plugin.");
|
||||
}
|
||||
instance = dyeMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when wishing to dye a cosmetic to hand it off to the dye menu implementation
|
||||
* @param viewer The viewer of the menu
|
||||
* @param cosmeticHolder The cosmetic holder that the player viewer wishing to modify (could be themselves or another CosmeticHolder)
|
||||
* @param cosmetic The cosmetic the user wishes to dye
|
||||
* @throws IllegalStateException IllegalStateException will be thrown if the dye menu instance is null (Check {@link DyeMenuProvider#hasMenuProvider()} before calling)
|
||||
*/
|
||||
public static void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic) throws IllegalStateException {
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException("Unable to open a dye menu without instance of it.");
|
||||
}
|
||||
instance.openMenu(viewer, cosmeticHolder, cosmetic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does HMCC have a dye menu provider already set?
|
||||
* @return True if it is already set and locked; false if none have been set.
|
||||
*/
|
||||
public static boolean hasMenuProvider() {
|
||||
return instance != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.special.impl;
|
||||
|
||||
import com.hibiscusmc.hmccolor.HMCColorApi;
|
||||
import com.hibiscusmc.hmccolor.shaded.gui.guis.Gui;
|
||||
import com.hibiscusmc.hmccolor.shaded.gui.guis.GuiItem;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.AdventureUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class HMCColorDyeMenu implements DyeMenu {
|
||||
|
||||
@Override
|
||||
public void openMenu(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic) {
|
||||
ItemStack originalItem = cosmetic.getItem();
|
||||
if (originalItem == null || !cosmetic.isDyeable()) return;
|
||||
|
||||
Gui gui = HMCColorApi.createColorMenu(viewer);
|
||||
gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, Settings.getDyeMenuName())));
|
||||
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
|
||||
gui.setDefaultTopClickAction(event -> {
|
||||
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
|
||||
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
|
||||
if (item == null) return;
|
||||
|
||||
Color color = NMSHandlers.getHandler().getUtilHandler().getColor(item);
|
||||
if (color == null) return;
|
||||
|
||||
addCosmetic(viewer, cosmeticHolder, cosmetic, color);
|
||||
event.setCancelled(true);
|
||||
} else event.setCancelled(true);
|
||||
});
|
||||
|
||||
gui.setPlayerInventoryAction(event -> event.setCancelled(true));
|
||||
gui.setCloseGuiAction(event -> {});
|
||||
gui.open(viewer);
|
||||
}
|
||||
|
||||
private void addCosmetic(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
cosmeticHolder.addCosmetic(cosmetic, color);
|
||||
viewer.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
viewer.closeInventory();
|
||||
cosmeticHolder.updateCosmetic(cosmetic.getSlot());
|
||||
}, 2);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,23 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.type;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Type {
|
||||
|
||||
@@ -18,11 +32,87 @@ public abstract class Type {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||
run(user, config, null);
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config) {
|
||||
run(viewer, cosmeticHolder, config, null);
|
||||
}
|
||||
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ClickType clickType) {
|
||||
run(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), config, clickType);
|
||||
}
|
||||
|
||||
public void run(CosmeticUser user, ConfigurationNode config) {
|
||||
final var player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
run(player, user, config, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #run(Player, CosmeticHolder, ConfigurationNode, ClickType)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract void run(CosmeticUser user, ConfigurationNode config, ClickType clickType);
|
||||
|
||||
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
return setItem(CosmeticHolder.ensureSingleCosmeticUser(viewer, cosmeticHolder), config, itemStack, slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Override {@link #setItem(Player, CosmeticHolder, ConfigurationNode, ItemStack, int)} instead.
|
||||
*/
|
||||
public abstract ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot);
|
||||
|
||||
@Contract("_, _ -> param2")
|
||||
@NotNull
|
||||
@SuppressWarnings("Duplicates")
|
||||
protected ItemMeta processItemMeta(Player viewer, @NotNull ItemMeta itemMeta) {
|
||||
// New implementation - Paper and forks
|
||||
// I know this is a kinda batshit way to do it (with serializing and deserializing MiniMessage)
|
||||
// But currently I can't think of another good way of doing it without a big refactor. I'll come back to this
|
||||
// At a later date.
|
||||
if (HibiscusCommonsPlugin.isOnPaper()) {
|
||||
List<Component> processedLore = new ArrayList<>();
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
String displayName = MiniMessage.miniMessage().serialize(itemMeta.displayName());
|
||||
displayName = Hooks.processPlaceholders(viewer, displayName);
|
||||
itemMeta.displayName(MiniMessage.miniMessage().deserialize(displayName).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (Component loreLine : itemMeta.lore()) {
|
||||
String loreStringLine = MiniMessage.miniMessage().serialize(loreLine);
|
||||
loreStringLine = Hooks.processPlaceholders(viewer, loreStringLine);
|
||||
processedLore.add(MiniMessage.miniMessage().deserialize(loreStringLine).decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
|
||||
itemMeta.lore(processedLore);
|
||||
} else {
|
||||
// Legacy implementation - Spigot
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
itemMeta.setDisplayName(Hooks.processPlaceholders(viewer, itemMeta.getDisplayName()));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
processedLore.add(Hooks.processPlaceholders(viewer, loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(viewer, skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
itemMeta.setLore(processedLore);
|
||||
}
|
||||
|
||||
return itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,43 @@ public class Types {
|
||||
|
||||
private static final HashMap<String, Type> types = new HashMap<>();
|
||||
|
||||
private static TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||
private static TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
||||
private static final TypeCosmetic TYPE_COSMETIC = new TypeCosmetic();
|
||||
private static final TypeEmpty TYPE_EMPTY = new TypeEmpty();
|
||||
|
||||
/**
|
||||
* Get's a Menu Item type. Add custom menu item types with {@link #addType(Type)}
|
||||
* @param id A non-case sensitive ID
|
||||
* @return The type of Menu Item
|
||||
*/
|
||||
public static Type getType(@NotNull String id) {
|
||||
return types.get(id.toUpperCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a type is valid. Add custom menu item types with {@link #addType(Type)}
|
||||
* @param id A non-case sensitive ID
|
||||
* @return True if exists, False if not.
|
||||
*/
|
||||
public static boolean isType(@NotNull String id) {
|
||||
return types.containsKey(id.toUpperCase());
|
||||
}
|
||||
|
||||
public static void addType(Type type) {
|
||||
types.put(type.getId().toUpperCase(), type);
|
||||
/**
|
||||
* Adds a Menu Item Type to the types HashMap for reference. Menu Types will automatically be added using this method.
|
||||
* @param type A non-null {@link Type} that'll be added. ID should be unique; can't be duplicated
|
||||
*/
|
||||
public static boolean addType(@NotNull Type type) {
|
||||
String id = type.getId().toUpperCase();
|
||||
if (types.containsKey(id)) return false;
|
||||
types.put(id, type);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default menu item; {@link TypeEmpty}
|
||||
* @return The empty menu type.
|
||||
*/
|
||||
public static TypeEmpty getDefaultType() {
|
||||
return TYPE_EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.special.DyeMenuProvider;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
@@ -19,9 +21,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -38,7 +37,7 @@ public class TypeCosmetic extends Type {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, ClickType clickType) {
|
||||
MessagesUtil.sendDebugMessages("Running Cosmetic Click Type");
|
||||
if (config.node("cosmetic").virtual()) {
|
||||
MessagesUtil.sendDebugMessages("Cosmetic Config Field Virtual");
|
||||
@@ -46,32 +45,33 @@ public class TypeCosmetic extends Type {
|
||||
}
|
||||
String cosmeticName = config.node("cosmetic").getString();
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(cosmeticName);
|
||||
Player player = user.getPlayer();
|
||||
if (cosmetic == null) {
|
||||
MessagesUtil.sendDebugMessages("No Cosmetic Found");
|
||||
MessagesUtil.sendMessage(player, "invalid-cosmetic");
|
||||
MessagesUtil.sendMessage(viewer, "invalid-cosmetic");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic)) {
|
||||
if (!cosmeticHolder.canEquipCosmetic(cosmetic)) {
|
||||
MessagesUtil.sendDebugMessages("No Cosmetic Permission");
|
||||
MessagesUtil.sendMessage(player, "no-cosmetic-permission");
|
||||
MessagesUtil.sendMessage(viewer, "no-cosmetic-permission");
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isUnEquippingCosmetic = false;
|
||||
if (user.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
|
||||
if (cosmeticHolder.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
|
||||
|
||||
String dyeClick = Settings.getCosmeticDyeClickType();
|
||||
String requiredClick;
|
||||
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
|
||||
else requiredClick = Settings.getCosmeticEquipClickType();
|
||||
|
||||
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
|
||||
MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
|
||||
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) {
|
||||
MessagesUtil.sendMessage(user.getPlayer(), "invalid-click-type");
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean isRequiredClick = requiredClick.equalsIgnoreCase("ANY") || requiredClick.equalsIgnoreCase(clickType.name());
|
||||
final boolean isDyeClick = dyeClick.equalsIgnoreCase("ANY") || dyeClick.equalsIgnoreCase(clickType.name());
|
||||
|
||||
if (!isRequiredClick) isUnEquippingCosmetic = false;
|
||||
|
||||
List<String> actionStrings = new ArrayList<>();
|
||||
ConfigurationNode actionConfig = config.node("actions");
|
||||
@@ -99,25 +99,27 @@ public class TypeCosmetic extends Type {
|
||||
if (isUnEquippingCosmetic) {
|
||||
if (!actionConfig.node("on-unequip").virtual()) actionStrings.addAll(actionConfig.node("on-unequip").getList(String.class));
|
||||
MessagesUtil.sendDebugMessages("on-unequip");
|
||||
user.removeCosmeticSlot(cosmetic);
|
||||
cosmeticHolder.removeCosmeticSlot(cosmetic);
|
||||
} else {
|
||||
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
|
||||
MessagesUtil.sendDebugMessages("on-equip");
|
||||
MessagesUtil.sendDebugMessages("Preparing for on-equip with the following checks:");
|
||||
MessagesUtil.sendDebugMessages("CosmeticDyeable? " + cosmetic.isDyeable() + " / isDyeClick? " + isDyeClick + " / isHMCColorActive? " + Hooks.isActiveHook("HMCColor"));
|
||||
// TODO: Redo this
|
||||
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) {
|
||||
DyeMenu.openMenu(user, cosmetic);
|
||||
} else {
|
||||
user.addPlayerCosmetic(cosmetic);
|
||||
if (cosmetic.isDyeable() && isDyeClick && DyeMenuProvider.hasMenuProvider()) {
|
||||
DyeMenuProvider.openMenu(viewer, cosmeticHolder, cosmetic);
|
||||
} else if (isRequiredClick) {
|
||||
cosmeticHolder.addCosmetic(cosmetic);
|
||||
}
|
||||
}
|
||||
|
||||
Actions.runActions(user, actionStrings);
|
||||
Actions.runActions(viewer, cosmeticHolder, actionStrings);
|
||||
|
||||
} catch (SerializationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// Fixes issue with offhand cosmetics not appearing. Yes, I know this is dumb
|
||||
Runnable run = () -> user.updateCosmetic(cosmetic.getSlot());
|
||||
Runnable run = () -> cosmeticHolder.updateCosmetic(cosmetic.getSlot());
|
||||
if (cosmetic instanceof CosmeticArmorType) {
|
||||
if (((CosmeticArmorType) cosmetic).getEquipSlot().equals(EquipmentSlot.OFF_HAND)) {
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 1);
|
||||
@@ -128,8 +130,18 @@ public class TypeCosmetic extends Type {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(@NotNull CosmeticUser user, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
run(user.getPlayer(), user, config, clickType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
return setItem(user.getPlayer(), user, config, itemStack, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack setItem(@NotNull Player viewer, @NotNull CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
|
||||
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta?");
|
||||
|
||||
if (config.node("cosmetic").virtual()) {
|
||||
@@ -141,9 +153,9 @@ public class TypeCosmetic extends Type {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (user.hasCosmeticInSlot(cosmetic) && (!config.node("equipped-item").virtual() || !config.node("locked-equipped-item").virtual())) {
|
||||
if (cosmeticHolder.hasCosmeticInSlot(cosmetic) && (!config.node("equipped-item").virtual() || !config.node("locked-equipped-item").virtual())) {
|
||||
MessagesUtil.sendDebugMessages("GUI Equipped Item");
|
||||
ConfigurationNode equippedItem = config.node(user.canEquipCosmetic(cosmetic, true) && !config.node("equipped-item").virtual() ? "equipped-item" : "locked-equipped-item");
|
||||
ConfigurationNode equippedItem = config.node(cosmeticHolder.canEquipCosmetic(cosmetic, true) && !config.node("equipped-item").virtual() ? "equipped-item" : "locked-equipped-item");
|
||||
try {
|
||||
if (equippedItem.node("material").virtual()) equippedItem.node("material").set(config.node("item", "material").getString());
|
||||
} catch (SerializationException e) {
|
||||
@@ -154,12 +166,12 @@ public class TypeCosmetic extends Type {
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
|
||||
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in equipped item?");
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (!user.canEquipCosmetic(cosmetic, true) && !config.node("locked-item").virtual()) {
|
||||
if (!cosmeticHolder.canEquipCosmetic(cosmetic, true) && !config.node("locked-item").virtual()) {
|
||||
MessagesUtil.sendDebugMessages("GUI Locked Item");
|
||||
ConfigurationNode lockedItem = config.node("locked-item");
|
||||
try {
|
||||
@@ -172,35 +184,10 @@ public class TypeCosmetic extends Type {
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processLoreLines(user, itemStack.getItemMeta()));
|
||||
if (itemStack.hasItemMeta()) itemStack.setItemMeta(processItemMeta(viewer, itemStack.getItemMeta()));
|
||||
else MessagesUtil.sendDebugMessages("ItemStack has no ItemMeta in locked item?");
|
||||
return itemStack;
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Contract("_, _ -> param2")
|
||||
@NotNull
|
||||
@SuppressWarnings("Duplicates")
|
||||
private ItemMeta processLoreLines(CosmeticUser user, @NotNull ItemMeta itemMeta) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
itemMeta.setLore(processedLore);
|
||||
return itemMeta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.type.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Actions;
|
||||
import com.hibiscusmc.hmccosmetics.gui.type.Type;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.serialize.SerializationException;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -23,9 +23,10 @@ public class TypeEmpty extends Type {
|
||||
// This is an empty type, meaning, when a menu item has a type of "empty" it will run the code in the method run.
|
||||
}
|
||||
|
||||
// This is the code that's run when the item is clicked.
|
||||
// This is the code that's run when the item is clicked. The item is clicked by the "viewer" player in a menu for the
|
||||
// given "cosmeticHolder". They're the same player by default, but it's not guaranteed.
|
||||
@Override
|
||||
public void run(CosmeticUser user, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
public void run(Player viewer, CosmeticHolder cosmeticHolder, @NotNull ConfigurationNode config, ClickType clickType) {
|
||||
List<String> actionStrings = new ArrayList<>(); // List where we keep the actions the server will execute.
|
||||
ConfigurationNode actionConfig = config.node("actions"); // Configuration node that actions are under.
|
||||
|
||||
@@ -52,36 +53,32 @@ public class TypeEmpty extends Type {
|
||||
}
|
||||
|
||||
// We run the actions once we got the raw strings from the config.
|
||||
Actions.runActions(user, actionStrings);
|
||||
Actions.runActions(viewer, cosmeticHolder, actionStrings);
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// backward-compatibility method, will not be required in the future
|
||||
@Override
|
||||
public void run(CosmeticUser user, ConfigurationNode config, ClickType clickType) {
|
||||
final var player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
run(player, user, config, clickType);
|
||||
}
|
||||
|
||||
// backward-compatibility method, will not be required in the future
|
||||
@Override
|
||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, ItemStack itemStack, int slot) {
|
||||
return setItem(user.getPlayer(), user, config, itemStack, slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public ItemStack setItem(CosmeticUser user, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
List<String> processedLore = new ArrayList<>();
|
||||
public ItemStack setItem(Player viewer, CosmeticHolder cosmeticHolder, ConfigurationNode config, @NotNull ItemStack itemStack, int slot) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if (itemMeta.hasDisplayName()) {
|
||||
itemMeta.setDisplayName(Hooks.processPlaceholders(user.getPlayer(), itemMeta.getDisplayName()));
|
||||
}
|
||||
|
||||
if (itemMeta.hasLore()) {
|
||||
for (String loreLine : itemMeta.getLore()) {
|
||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner() && skullMeta.getOwner() != null) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
|
||||
itemMeta.setLore(processedLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
itemStack.setItemMeta(processItemMeta(viewer, itemMeta));
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class HookHMCCosmetics extends Hook {
|
||||
public HookHMCCosmetics() {
|
||||
super("HMCCosmetics", HookFlag.ITEM_SUPPORT);
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,5 +25,4 @@ public class HookHMCCosmetics extends Hook {
|
||||
if (cosmetic == null) return null;
|
||||
return cosmetic.getItem();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.misc;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerWardrobeEnterEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerWardrobeLeaveEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import kr.toxicity.hud.api.BetterHud;
|
||||
import kr.toxicity.hud.api.player.HudPlayer;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class HookBetterHud extends Hook {
|
||||
|
||||
public HookBetterHud() {
|
||||
super("BetterHUD");
|
||||
setActive(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerEnterWardrobe(@NotNull PlayerWardrobeEnterEvent event) {
|
||||
if (!Settings.isWardrobeHideHud()) return;
|
||||
UUID uuid = event.getUniqueId();
|
||||
HudPlayer hudPlayer = BetterHud.getInstance().getPlayerManager().getHudPlayer(uuid);
|
||||
if (hudPlayer == null) return;
|
||||
hudPlayer.setHudEnabled(false);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlayerLeaveWardrobe(@NotNull PlayerWardrobeLeaveEvent event) {
|
||||
if (!Settings.isWardrobeHideHud()) return;
|
||||
UUID uuid = event.getUniqueId();
|
||||
HudPlayer hudPlayer = BetterHud.getInstance().getPlayerManager().getHudPlayer(uuid);
|
||||
if (hudPlayer == null) return;
|
||||
hudPlayer.setHudEnabled(true);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.TranslationUtil;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -74,29 +73,20 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
|
||||
if (slot == null) return null;
|
||||
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
|
||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||
if (cosmetic == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
|
||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||
|
||||
String output;
|
||||
switch (placeholderArgs.get(2).toLowerCase()) {
|
||||
case "material" -> {
|
||||
output = getMaterialName(user.getCosmetic(slot));
|
||||
}
|
||||
case "custommodeldata" -> {
|
||||
output = getModelData(user.getCosmetic(slot));
|
||||
}
|
||||
case "name" -> {
|
||||
output = getItemName(user.getCosmetic(slot));
|
||||
}
|
||||
case "lore" -> {
|
||||
output = getItemLore(user.getCosmetic(slot));
|
||||
}
|
||||
case "permission" -> {
|
||||
output = user.getCosmetic(slot).getPermission();
|
||||
}
|
||||
default -> {
|
||||
output = user.getCosmetic(slot).getId();
|
||||
}
|
||||
case "material" -> output = getMaterialName(cosmetic);
|
||||
case "custommodeldata" -> output = getModelData(cosmetic);
|
||||
case "itemmodel" -> output = getItemModel(cosmetic);
|
||||
case "itemname" -> output = getItemName(cosmetic);
|
||||
case "name" -> output = getDisplayName(cosmetic);
|
||||
case "lore" -> output = getItemLore(cosmetic);
|
||||
case "permission" -> output = user.getCosmetic(slot).getPermission();
|
||||
default -> output = user.getCosmetic(slot).getId();
|
||||
}
|
||||
if (output == null) output = "none";
|
||||
return TranslationUtil.getTranslation("current-cosmetic", output);
|
||||
@@ -122,7 +112,8 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
String args1 = placeholderArgs.get(1);
|
||||
|
||||
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
|
||||
String rawSlot = args1.toUpperCase();
|
||||
if (CosmeticSlot.contains(rawSlot)) {
|
||||
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null));
|
||||
}
|
||||
|
||||
@@ -150,7 +141,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
String args1 = placeholderArgs.get(1).toUpperCase(); // changes offhand to OFFHAND
|
||||
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args1)) return null;
|
||||
if (!CosmeticSlot.contains(args1)) return null;
|
||||
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(args1);
|
||||
int amount = 0;
|
||||
@@ -217,13 +208,55 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
return String.valueOf(itemMeta.getCustomModelData());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the cosmetic items item model
|
||||
* @param cosmetic The cosmetic to get its item model
|
||||
* @return The cosmetic items item model
|
||||
*/
|
||||
@Nullable
|
||||
public String getItemModel(@NotNull Cosmetic cosmetic) {
|
||||
try {
|
||||
ItemStack item = cosmetic.getItem();
|
||||
if (item == null) return null;
|
||||
if (!item.hasItemMeta()) return null;
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta == null && itemMeta.hasItemModel() ) return null;
|
||||
return itemMeta.getItemModel().asString();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the cosmetic items item name
|
||||
* @param cosmetic The cosmetic to get its items item name
|
||||
* @return The cosmetic items item name
|
||||
*/
|
||||
@Nullable
|
||||
public String getItemName(@NotNull Cosmetic cosmetic) {
|
||||
try {
|
||||
ItemStack item = cosmetic.getItem();
|
||||
if (item == null) return null;
|
||||
if (!item.hasItemMeta()) return null;
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta == null || !itemMeta.hasItemName()) return null;
|
||||
return itemMeta.getDisplayName();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cosmetic items display name
|
||||
* @param cosmetic The cosmetic to get its items display name
|
||||
* @return The cosmetic items display name
|
||||
*/
|
||||
@Nullable
|
||||
public String getItemName(@NotNull Cosmetic cosmetic) {
|
||||
public String getDisplayName(@NotNull Cosmetic cosmetic) {
|
||||
ItemStack item = cosmetic.getItem();
|
||||
if (item == null) return null;
|
||||
if (!item.hasItemMeta()) return null;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.worldguard;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
@@ -8,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
@@ -20,33 +20,44 @@ import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Contains {@link com.sk89q.worldguard.WorldGuard WorldGuard} related event listeners
|
||||
*/
|
||||
public class WGListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(@NotNull PlayerMoveEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
Player player = event.getPlayer();
|
||||
Location from = event.getFrom();
|
||||
Location to = event.getTo();
|
||||
if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
Location location = event.getPlayer().getLocation();
|
||||
Location location = player.getLocation();
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
if (user.isHidden()) {
|
||||
if (set.getRegions().isEmpty()) {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
}
|
||||
if (user.isHidden() && set.getRegions().isEmpty()) {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
}
|
||||
|
||||
Set<String> wardrobeNames = WardrobeSettings.getWardrobeNames();
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||
if (protectedRegion.getFlags().get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||
Map<Flag<?>, Object> flags = protectedRegion.getFlags();
|
||||
if (flags.containsKey(WGHook.getCosmeticEnableFlag())) {
|
||||
if (flags.get(WGHook.getCosmeticEnableFlag()).toString().equalsIgnoreCase("ALLOW")) {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
} else {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLDGUARD);
|
||||
}
|
||||
}
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
||||
user.enterWardrobe(true, wardrobe);
|
||||
if (flags.containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
String wardrobeName = flags.getOrDefault(WGHook.getCosmeticWardrobeFlag(), "").toString();
|
||||
if (wardrobeName.isEmpty() || !wardrobeNames.contains(wardrobeName)) return;
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(wardrobeName);
|
||||
if (wardrobe == null) return;
|
||||
user.enterWardrobe(wardrobe, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,24 +85,7 @@ public class WGListener implements Listener {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticWardrobeFlag())) {
|
||||
if (!WardrobeSettings.getWardrobeNames().contains(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString())) return;
|
||||
Wardrobe wardrobe = WardrobeSettings.getWardrobe(protectedRegion.getFlags().get(WGHook.getCosmeticWardrobeFlag()).toString());
|
||||
user.enterWardrobe(true, wardrobe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerEmote(PlayerEmoteStartEvent event) {
|
||||
Player player = event.getUser().getPlayer();
|
||||
if (player == null) return;
|
||||
Location location = player.getLocation();
|
||||
ApplicableRegionSet set = getRegions(location);
|
||||
for (ProtectedRegion protectedRegion : set.getRegions()) {
|
||||
if (protectedRegion.getFlags().containsKey(WGHook.getEmotesEnableFlag())) {
|
||||
if (protectedRegion.getFlags().get(WGHook.getEmotesEnableFlag()).toString().equalsIgnoreCase("DENY")) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
user.enterWardrobe(wardrobe, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,12 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PaperPlayerGameListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerArmorEquip(PlayerArmorChangeEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
@@ -18,7 +19,7 @@ public class PaperPlayerGameListener implements Listener {
|
||||
user.updateCosmetic(slotTypeToCosmeticType(event.getSlotType()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerRespawn(PlayerPostRespawnEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerLoadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreLoadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreUnloadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerUnloadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -21,64 +23,89 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerConnectionListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
|
||||
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
|
||||
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
|
||||
MessagesUtil.sendMessageNoKey(
|
||||
event.getPlayer(),
|
||||
"<br>" +
|
||||
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
|
||||
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
|
||||
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
|
||||
"<br>"
|
||||
);
|
||||
}
|
||||
|
||||
// This literally makes me want to end it all but I can't do that so I'll just cry instead
|
||||
Runnable run = () -> {
|
||||
if (!event.getPlayer().isOnline()) return; // If a player is no longer online, don't run this.
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
Database.get(uuid).thenAccept(data -> {
|
||||
if (data == null) return;
|
||||
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.
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (cosmeticUser.getPlayer() == null) return;
|
||||
cosmeticUser.updateCosmetic();
|
||||
}, 4);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (DatabaseSettings.isEnabledDelay()) {
|
||||
MessagesUtil.sendDebugMessages("Delay Enabled with " + DatabaseSettings.getDelayLength() + " ticks");
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, DatabaseSettings.getDelayLength());
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
HMCCosmeticsPlugin.getInstance(),
|
||||
() -> this.loadUserData(event.getPlayer()),
|
||||
DatabaseSettings.getDelayLength()
|
||||
);
|
||||
} else {
|
||||
run.run();
|
||||
this.loadUserData(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadUserData(final Player player) {
|
||||
if(!player.isOnline()) return;
|
||||
final UUID playerId = player.getUniqueId();
|
||||
|
||||
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(playerId);
|
||||
Bukkit.getPluginManager().callEvent(preLoadEvent);
|
||||
if (preLoadEvent.isCancelled()) return;
|
||||
|
||||
Database.get(playerId).thenAccept(userData -> {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
|
||||
.createCosmeticUser(playerId)
|
||||
.initialize(userData);
|
||||
cosmeticUser.startTicking();
|
||||
|
||||
CosmeticUsers.addUser(cosmeticUser);
|
||||
MessagesUtil.sendDebugMessages("Run User Join for " + playerId);
|
||||
|
||||
PlayerLoadEvent playerLoadEvent = new PlayerLoadEvent(cosmeticUser);
|
||||
Bukkit.getPluginManager().callEvent(playerLoadEvent);
|
||||
|
||||
// And finally, launch an update for the cosmetics they have.
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (cosmeticUser.getPlayer() == null) return;
|
||||
cosmeticUser.updateCosmetic();
|
||||
}, 4);
|
||||
});
|
||||
}).exceptionally(ex -> {
|
||||
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + playerId + ". Exception: " + ex.getMessage());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return; // Player never initialized, don't do anything
|
||||
|
||||
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(user);
|
||||
Bukkit.getPluginManager().callEvent(preUnloadEvent);
|
||||
if (preUnloadEvent.isCancelled()) return;
|
||||
|
||||
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
|
||||
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe(true);
|
||||
user.getPlayer().setInvisible(false);
|
||||
}
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
|
||||
event.getPlayer().setInvisible(false);
|
||||
|
||||
final Player player = user.getPlayer();
|
||||
if(player != null) player.setInvisible(false);
|
||||
}
|
||||
Menus.removeCooldown(event.getPlayer().getUniqueId()); // Removes any menu cooldowns a player might have
|
||||
Database.save(user);
|
||||
user.destroy();
|
||||
CosmeticUsers.removeUser(user.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void notifyAdminUpdate(final PlayerJoinEvent event) {
|
||||
if (event.getPlayer().isOp() || event.getPlayer().hasPermission("hmccosmetics.notifyupdate")) {
|
||||
if (!HMCCosmeticsPlugin.getInstance().getLatestVersion().equalsIgnoreCase(HMCCosmeticsPlugin.getInstance().getDescription().getVersion()) && HMCCosmeticsPlugin.getInstance().getLatestVersion().isEmpty())
|
||||
MessagesUtil.sendMessageNoKey(
|
||||
event.getPlayer(),
|
||||
"<br>" +
|
||||
"<GRAY>There is a new version of <light_purple><Bold>HMCCosmetics<reset><gray> available!<br>" +
|
||||
"<GRAY>Current version: <red>" + HMCCosmeticsPlugin.getInstance().getDescription().getVersion() + " <GRAY>| Latest version: <light_purple>" + HMCCosmeticsPlugin.getInstance().getLatestVersion() + "<br>" +
|
||||
"<GRAY>Download it on <gold><click:OPEN_URL:'https://www.spigotmc.org/resources/100107/'>Spigot<reset> <gray>or <gold><click:OPEN_URL:'https://polymart.org/resource/1879'>Polymart<reset><gray>!" +
|
||||
"<br>"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,19 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerCosmeticPostEquipEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
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.HookNexo;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -54,28 +36,10 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spigotmc.event.entity.EntityDismountEvent;
|
||||
import org.spigotmc.event.entity.EntityMountEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerGameListener implements Listener {
|
||||
|
||||
public PlayerGameListener() {
|
||||
registerInventoryClickListener();
|
||||
registerMenuChangeListener();
|
||||
registerEntityStatusListener();
|
||||
registerPlayerEquipmentListener();
|
||||
registerPlayerArmListener();
|
||||
registerEntityUseListener();
|
||||
registerSlotChangeListener();
|
||||
registerPassengerSetListener();
|
||||
|
||||
//registerLookMovement();
|
||||
//registerMoveListener();
|
||||
//registerTeleportMovement();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerClick(@NotNull InventoryClickEvent event) {
|
||||
// || !event.getClickedInventory().getType().equals(InventoryType.PLAYER)
|
||||
@@ -108,14 +72,10 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
|
||||
if (user == null) return;
|
||||
if (event.isSneaking()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.SNEAK);
|
||||
}
|
||||
|
||||
if (!event.isSneaking()) return;
|
||||
if (!user.isInWardrobe()) return;
|
||||
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@@ -129,29 +89,24 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (user.getEntity() == null || user.isInWardrobe()) return; // fixes disconnecting when in wardrobe (the entity stuff)
|
||||
|
||||
if (Settings.getDisabledWorlds().contains(user.getEntity().getLocation().getWorld().getName())) {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
} else {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
}
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
||||
user.respawnBackpack();
|
||||
}
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
user.respawnBalloon();
|
||||
}
|
||||
|
||||
user.respawnBackpack();
|
||||
user.respawnBalloon();
|
||||
user.updateCosmetic();
|
||||
}, 2);
|
||||
}, 4);
|
||||
|
||||
if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@@ -183,8 +138,7 @@ public class PlayerGameListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerHit(EntityDamageByEntityEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (!entity.getPersistentDataContainer().has(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT))
|
||||
return;
|
||||
if (!entity.getPersistentDataContainer().has(HMCCServerUtils.getCosmemeticMobKey(), PersistentDataType.BOOLEAN)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@@ -193,36 +147,15 @@ public class PlayerGameListener implements Listener {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
if (Settings.isEmoteInvincible()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (Settings.isEmoteDamageLeave()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.DAMAGE);
|
||||
}
|
||||
}
|
||||
if (user.isInWardrobe()) {
|
||||
if (WardrobeSettings.isPreventDamage()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe();
|
||||
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (!Settings.isEmoteMoveCheck() && user.getUserEmoteManager().isPlayingEmote()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
user.updateCosmetic(CosmeticSlot.BACKPACK);
|
||||
user.updateCosmetic(CosmeticSlot.BALLOON);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerPoseChange(EntityPoseChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) return;
|
||||
@@ -282,12 +215,6 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
if (user == null) return;
|
||||
// Really need to look into optimization of this
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking() && event.getPlayer().hasPermission("hmccosmetics.emote.shiftrun")) {
|
||||
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
|
||||
cosmeticEmoteType.run(user);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
if (user.getEntity() == null) return; // Player has likely logged off
|
||||
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
||||
@@ -349,7 +276,7 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getEntity());
|
||||
if (user == null) return;
|
||||
|
||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||
if (user.isInWardrobe()) user.leaveWardrobe(false);
|
||||
|
||||
if (Settings.isUnapplyOnDeath() && !event.getEntity().hasPermission("hmccosmetics.unapplydeath.bypass")) {
|
||||
user.removeCosmetics();
|
||||
@@ -418,6 +345,15 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEntityEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final Entity entity = event.getRightClicked();
|
||||
// Balloons are technically actual entities, so we need to cancel any interactions with them
|
||||
if (!entity.getPersistentDataContainer().has(HMCCServerUtils.getCosmemeticMobKey(), PersistentDataType.BOOLEAN)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerVanish(HibiscusPlayerVanishEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
@@ -464,308 +400,11 @@ public class PlayerGameListener implements Listener {
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.PLUGIN);
|
||||
}
|
||||
|
||||
private void registerInventoryClickListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
int invTypeClicked = event.getPacket().getIntegers().read(0);
|
||||
int slotClicked = event.getPacket().getIntegers().read(2);
|
||||
|
||||
// Must be a player inventory.
|
||||
if (invTypeClicked != 0) return;
|
||||
// -999 is when a player clicks outside their inventory. https://wiki.vg/Inventory#Player_Inventory
|
||||
if (slotClicked == -999) return;
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slotClicked);
|
||||
if (cosmeticSlot == null) return;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
|
||||
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerMenuChangeListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.WINDOW_ITEMS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
MessagesUtil.sendDebugMessages("Menu Initial ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
int windowID = event.getPacket().getIntegers().read(0);
|
||||
List<ItemStack> slotData = event.getPacket().getItemListModifier().read(0);
|
||||
if (windowID != 0) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
|
||||
HashMap<Integer, ItemStack> items = new HashMap<>();
|
||||
|
||||
if (!user.isInWardrobe()) {
|
||||
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||
if ((cosmetic instanceof CosmeticArmorType cosmeticArmorType)) {
|
||||
boolean requireEmpty = Settings.getSlotOption(cosmeticArmorType.getEquipSlot()).isRequireEmpty();
|
||||
boolean isAir = user.getPlayer().getInventory().getItem(cosmeticArmorType.getEquipSlot()).getType().isAir();
|
||||
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + cosmeticArmorType.getId() + " - " + requireEmpty + " - " + isAir);
|
||||
if (requireEmpty && !isAir) continue;
|
||||
items.put(HMCCInventoryUtils.getPacketArmorSlot(cosmeticArmorType.getEquipSlot()), user.getUserCosmeticItem(cosmeticArmorType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
packet.getIntegers().write(0, 0);
|
||||
for (int slot = 0; slot < 46; slot++) {
|
||||
if ((slot >= 5 && slot <= 8) || slot == 45) {
|
||||
if (!items.containsKey(slot)) continue;
|
||||
slotData.set(slot, items.get(slot));
|
||||
MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
|
||||
}
|
||||
}
|
||||
packet.getItemListModifier().write(0, slotData);
|
||||
packet.getItemModifier().write(0, event.getPacket().getItemModifier().read(0));
|
||||
event.setPacket(packet);
|
||||
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowID + " with " + slotData.size());
|
||||
/*
|
||||
for (Cosmetic cosmetic : user.getCosmetic()) {
|
||||
if ((cosmetic instanceof CosmeticArmorType) || (cosmetic instanceof CosmeticMainhandType)) {
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(cosmetic);
|
||||
}, 1);
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerSlotChangeListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.SET_SLOT) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
MessagesUtil.sendDebugMessages("SetSlot Initial ");
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
|
||||
int windowID = event.getPacket().getIntegers().read(0);
|
||||
if (windowID != 0) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
|
||||
int slot = event.getPacket().getIntegers().read(2);
|
||||
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
|
||||
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
|
||||
if (cosmeticSlot == null || equipmentSlot == null) return;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return;
|
||||
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
|
||||
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return;
|
||||
}
|
||||
event.getPacket().getItemModifier().write(0, user.getUserCosmeticItem(cosmeticSlot));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerPlayerEquipmentListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
Player player = event.getPlayer(); // Player that's sent
|
||||
int entityID = event.getPacket().getIntegers().read(0);
|
||||
// User
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityID);
|
||||
if (user == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
|
||||
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
|
||||
|
||||
for (int i = 0; i < armor.size(); i++) {
|
||||
com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack> pair = armor.get(i);
|
||||
switch (pair.getFirst()) {
|
||||
case MAINHAND -> {
|
||||
if (user.getPlayer() == event.getPlayer()) continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
|
||||
if (user.getPlayer() != null && user.getPlayer().isInvisible()) continue; // Fixes integration with GSit still showing mainhand even when hidden
|
||||
armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
|
||||
}
|
||||
default -> {
|
||||
EquipmentSlot slot = HMCCInventoryUtils.getEquipmentSlot(pair.getFirst());
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.getItemSlotToCosmeticSlot(pair.getFirst());
|
||||
if (slot == null || cosmeticSlot == null) continue;
|
||||
if (Settings.getSlotOption(slot).isRequireEmpty()
|
||||
&& !user.getPlayer().getInventory().getItem(slot).getType().isAir()) continue;
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
if (cosmeticArmor == null) continue;
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticArmor);
|
||||
if (item == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> armorPair = new Pair<>(HMCCInventoryUtils.itemBukkitSlot(slot), item);
|
||||
armor.set(i, armorPair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.getPacket().getSlotStackPairLists().write(0, armor);
|
||||
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerEntityStatusListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_STATUS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
int entityid = event.getPacket().getIntegers().read(0);
|
||||
byte status = event.getPacket().getBytes().read(0);
|
||||
|
||||
MessagesUtil.sendDebugMessages("EntityStatus Initial " + entityid + " - " + status);
|
||||
if (status != 55) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityid);
|
||||
if (user == null) {
|
||||
MessagesUtil.sendDebugMessages("EntityStatus User is null");
|
||||
return;
|
||||
}
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerPassengerSetListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.MOUNT) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
CosmeticUser viewerUser = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
if (viewerUser == null) return;
|
||||
if (viewerUser.isInWardrobe()) return;
|
||||
|
||||
int ownerId = event.getPacket().getIntegers().read(0);
|
||||
MessagesUtil.sendDebugMessages("Mount Packet Sent - Read - EntityID: " + ownerId);
|
||||
Entity entity = HMCCServerUtils.getEntity(ownerId);
|
||||
if (entity == null) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(entity.getUniqueId());
|
||||
if (user == null) return;
|
||||
MessagesUtil.sendDebugMessages("Mount Packet Sent - " + user.getUniqueId());
|
||||
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) return;
|
||||
if (user.getUserBackpackManager() == null) return;
|
||||
|
||||
// Basically, take the original passengers and "bump" them to the end of the list
|
||||
int[] originalPassengers = event.getPacket().getIntegerArrays().read(0);
|
||||
List<Integer> passengers = new ArrayList<>(user.getUserBackpackManager().getEntityManager().getIds());
|
||||
|
||||
passengers.addAll(Arrays.stream(originalPassengers).boxed().toList());
|
||||
|
||||
event.getPacket().getIntegerArrays().write(0, passengers.stream().mapToInt(Integer::intValue).toArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerPlayerArmListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
Player player = event.getPlayer();
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!user.isInWardrobe()) return;
|
||||
if (!user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return;
|
||||
|
||||
Menu menu = user.getWardrobeManager().getLastOpenMenu();
|
||||
if (menu == null) return;
|
||||
menu.openMenu(user);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerEntityUseListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.USE_ENTITY) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
if (user.getUserEmoteManager().isPlayingEmote() || user.isInWardrobe()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerLookMovement() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.LOOK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// TODO: Finish
|
||||
MessagesUtil.sendDebugMessages("Look Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
user.getUserBackpackManager().getEntityManager().setRotation(Math.round(event.getPacket().getFloat().read(0)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerMoveListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.POSITION) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// TODO: Finish
|
||||
MessagesUtil.sendDebugMessages("Position Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
// The yaw follows the head, which makes it look weird and do weird things when moving around
|
||||
user.getUserBackpackManager().getEntityManager().teleport(new Location(player.getWorld(), event.getPacket().getDoubles().read(0), event.getPacket().getDoubles().read(1), event.getPacket().getDoubles().read(2), event.getPacket().getFloat().read(0), event.getPacket().getFloat().read(1)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerTeleportMovement() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.POSITION_LOOK) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// TODO: Finish
|
||||
MessagesUtil.sendDebugMessages("Teleport Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(CosmeticSlot.BACKPACK));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private EquipmentSlot getArmorSlot(final Material material) {
|
||||
for (final EquipmentSlot slot : EquipmentSlot.values()) {
|
||||
final Set<Material> armorItems = ARMOR_ITEMS.get(slot);
|
||||
if (armorItems == null) continue;
|
||||
if (material == null) continue;
|
||||
if (armorItems.contains(material)) return slot;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class PlayerMovementListener implements Listener {
|
||||
private static final List<CosmeticSlot> MOVEMENT_COSMETICS = List.of(
|
||||
CosmeticSlot.BACKPACK,
|
||||
CosmeticSlot.BALLOON
|
||||
);
|
||||
|
||||
// Player Id -> Small Location
|
||||
private final Map<UUID, SmallLocation> locations = new HashMap<>();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent ev) {
|
||||
final Player player = ev.getPlayer();
|
||||
|
||||
final CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if(user == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!updateDirtyLocation(ev.getPlayer(), ev.getTo())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(final CosmeticSlot slot : MOVEMENT_COSMETICS) {
|
||||
user.updateMovementCosmetic(slot, ev.getFrom(), ev.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateDirtyLocation(final Player player, final Location nextLoc) {
|
||||
final SmallLocation previous = locations.computeIfAbsent(
|
||||
player.getUniqueId(),
|
||||
$ -> SmallLocation.fromLocation(nextLoc)
|
||||
);
|
||||
final SmallLocation next = SmallLocation.fromLocation(nextLoc);
|
||||
|
||||
if(next.distanceTo(previous) > 0.25) {
|
||||
this.locations.put(player.getUniqueId(), next);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(next.yawDistanceTo(previous) > 5) {
|
||||
this.locations.put(player.getUniqueId(), next);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onWorldChange(final PlayerChangedWorldEvent ev) {
|
||||
this.locations.remove(ev.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(final PlayerQuitEvent ev) {
|
||||
locations.remove(ev.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
record SmallLocation(
|
||||
double x,
|
||||
double y,
|
||||
double z,
|
||||
float yaw
|
||||
) {
|
||||
public double distanceTo(SmallLocation other) {
|
||||
double dx = this.x - other.x;
|
||||
double dy = this.y - other.y;
|
||||
double dz = this.z - other.z;
|
||||
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
}
|
||||
|
||||
public float yawDistanceTo(SmallLocation other) {
|
||||
float diff = Math.abs(this.yaw - other.yaw) % 360;
|
||||
return diff > 180 ? 360 - diff : diff;
|
||||
}
|
||||
|
||||
public static SmallLocation fromLocation(final Location location) {
|
||||
return new SmallLocation(location.getX(), location.getY(), location.getZ(), location.getYaw());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,39 +3,38 @@ 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.api.events.HibiscusHooksAllActiveEvent;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ServerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onHookReload(HibiscusHookReload event) {
|
||||
Hook hook = event.getHook();
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onHookReload(@NotNull HibiscusHookReload event) {
|
||||
final Hook hook = event.getHook();
|
||||
final HibiscusHookReload.ReloadType reloadType = event.getReloadType();
|
||||
|
||||
if (hook instanceof HookItemAdder) {
|
||||
switch (event.getReloadType()) {
|
||||
case INITIAL -> {
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
case RELOAD -> {
|
||||
if (!Settings.isItemsAdderChangeReload()) return;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
if (reloadType == HibiscusHookReload.ReloadType.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();
|
||||
}
|
||||
if (reloadType == HibiscusHookReload.ReloadType.RELOAD) {
|
||||
if (!Settings.isNexoChangeReload()) return;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onAllHooksReady(@NotNull HibiscusHooksAllActiveEvent event) {
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
package com.hibiscusmc.hmccosmetics.packets;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import me.lojosho.hibiscuscommons.packets.PacketAction;
|
||||
import me.lojosho.hibiscuscommons.packets.PacketInterface;
|
||||
import me.lojosho.hibiscuscommons.packets.wrapper.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CosmeticPacketInterface implements PacketInterface {
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction writeContainerContent(@NotNull Player player, @NotNull ContainerContentWrapper wrapper) {
|
||||
int windowId = wrapper.getWindowId();
|
||||
MessagesUtil.sendDebugMessages("writeContainerContent (windowid: " + windowId + " )");
|
||||
if (windowId != 0) return PacketAction.NOTHING;
|
||||
List<ItemStack> slotData = wrapper.getSlotData();
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return PacketAction.NOTHING;
|
||||
|
||||
HashMap<Integer, ItemStack> cosmeticItems = new HashMap<>();
|
||||
|
||||
if (!user.isInWardrobe()) {
|
||||
for (Cosmetic cosmetic : user.getCosmetics()) {
|
||||
if (cosmetic instanceof CosmeticArmorType armorType) {
|
||||
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
|
||||
boolean isAir = user.getPlayer().getInventory().getItem(armorType.getEquipSlot()).getType().isAir();
|
||||
MessagesUtil.sendDebugMessages("Menu Fired (Checks) - " + armorType.getId() + " - " + requireEmpty + " - " + isAir);
|
||||
if (requireEmpty && !isAir) continue;
|
||||
cosmeticItems.put(HMCCInventoryUtils.getPacketArmorSlot(armorType.getEquipSlot()), user.getUserCosmeticItem(armorType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int slot = 0; slot < 46; slot++) {
|
||||
if ((slot >= 5 && slot <= 8) || slot == 45) {
|
||||
if (!cosmeticItems.containsKey(slot)) continue;
|
||||
slotData.set(slot, cosmeticItems.get(slot));
|
||||
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + cosmeticItems.get(slot));
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.setSlotData(slotData);
|
||||
MessagesUtil.sendDebugMessages("Menu Fired, updated cosmetics " + " on slotdata " + windowId + " with " + slotData.size());
|
||||
return PacketAction.CHANGED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction writeSlotContent(@NotNull Player player, @NotNull SlotContentWrapper wrapper) {
|
||||
int windowId = wrapper.getWindowId();
|
||||
int slot = wrapper.getSlot();
|
||||
ItemStack itemStack = wrapper.getItemStack();
|
||||
|
||||
MessagesUtil.sendDebugMessages("SetSlot Initial ");
|
||||
if (windowId != 0) return PacketAction.NOTHING;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null || user.isInWardrobe()) return PacketAction.NOTHING;
|
||||
|
||||
MessagesUtil.sendDebugMessages("SetSlot Slot " + slot);
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slot);
|
||||
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getPacketArmorSlot(slot);
|
||||
if (cosmeticSlot == null || equipmentSlot == null) return PacketAction.NOTHING;
|
||||
if (!user.hasCosmeticInSlot(cosmeticSlot)) return PacketAction.NOTHING;
|
||||
if (Settings.getSlotOption(equipmentSlot).isRequireEmpty()) {
|
||||
if (!player.getInventory().getItem(equipmentSlot).getType().isAir()) return PacketAction.NOTHING;
|
||||
}
|
||||
wrapper.setItemStack(user.getUserCosmeticItem(cosmeticSlot));
|
||||
return PacketAction.CHANGED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction writeEquipmentContent(@NotNull Player player, @NotNull EntityEquipmentWrapper wrapper) {
|
||||
if (player.getEntityId() != wrapper.getEntityId()) return PacketAction.NOTHING;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null || user.isInWardrobe()) return PacketAction.NOTHING;
|
||||
Map<EquipmentSlot, ItemStack> armor = wrapper.getArmor();
|
||||
|
||||
for (Map.Entry<EquipmentSlot, ItemStack> armorSlot : armor.entrySet()) {
|
||||
EquipmentSlot slot = armorSlot.getKey();
|
||||
|
||||
if (slot == EquipmentSlot.HAND) {
|
||||
if (user.getPlayer().getUniqueId() == player.getUniqueId())
|
||||
continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
|
||||
if (user.getPlayer() != null && user.getPlayer().isInvisible())
|
||||
continue; // Fixes integration with GSit still showing mainhand even when hidden
|
||||
armor.put(slot, player.getInventory().getItemInMainHand());
|
||||
} else {
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.BukkitCosmeticSlot(slot);
|
||||
if (cosmeticSlot == null) continue;
|
||||
if (Settings.getSlotOption(slot).isRequireEmpty() && player.getInventory().getItem(slot).getType().isAir())
|
||||
continue;
|
||||
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
if (cosmeticArmor == null) continue;
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticSlot);
|
||||
if (item == null) continue;
|
||||
armor.put(slot, item);
|
||||
}
|
||||
}
|
||||
|
||||
wrapper.setArmor(armor);
|
||||
MessagesUtil.sendDebugMessages("Equipment for " + user.getPlayer().getName() + " has been updated for " + player.getName());
|
||||
return PacketAction.CHANGED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction writePassengerContent(@NotNull Player player, @NotNull PassengerWrapper wrapper) {
|
||||
// TODO: Figure out what to do with this, because with it in, it ruins backpacks (they keep getting thrown to random locations).
|
||||
return PacketAction.NOTHING;
|
||||
/*
|
||||
CosmeticUser viewerUser = CosmeticUsers.getUser(player);
|
||||
if (viewerUser == null || viewerUser.isInWardrobe()) return PacketAction.NOTHING;
|
||||
|
||||
int ownerId = wrapper.getOwner();
|
||||
|
||||
Optional<CosmeticUser> optionalCosmeticUser = CosmeticUsers.values().stream().filter(user -> user.getPlayer() != null).filter(user -> ownerId == user.getPlayer().getEntityId()).findFirst();
|
||||
if (optionalCosmeticUser.isEmpty()) return PacketAction.NOTHING;
|
||||
CosmeticUser user = optionalCosmeticUser.get();
|
||||
|
||||
Cosmetic backpackCosmetic = user.getCosmetic(CosmeticSlot.BACKPACK);
|
||||
if (backpackCosmetic == null) return PacketAction.NOTHING;
|
||||
if (!(backpackCosmetic instanceof CosmeticBackpackType cosmeticBackpackType)) return PacketAction.NOTHING;
|
||||
if (user.getUniqueId().equals(viewerUser.getUniqueId())) {
|
||||
if (cosmeticBackpackType.isFirstPersonCompadible()) return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
if (user.getUserBackpackManager() == null) return PacketAction.NOTHING;
|
||||
|
||||
List<Integer> originalPassengers = wrapper.getPassengers();
|
||||
List<Integer> passengers = new ArrayList<>(user.getUserBackpackManager().getEntityManager().getIds());
|
||||
passengers.addAll(originalPassengers);
|
||||
wrapper.setPassengers(passengers);
|
||||
return PacketAction.CHANGED;
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketAction readPlayerScale(@NotNull Player player, @NotNull PlayerScaleWrapper wrapper) {
|
||||
int entityId = wrapper.getEntityId();
|
||||
Player changedPlayer = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(onlinePlayer -> onlinePlayer.getEntityId() == entityId)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (changedPlayer == null) return PacketAction.NOTHING;
|
||||
|
||||
CosmeticUser cosmeticUser = CosmeticUsers.getUser(changedPlayer.getUniqueId());
|
||||
if (cosmeticUser == null || cosmeticUser.isInWardrobe()) return PacketAction.NOTHING;
|
||||
|
||||
UserBackpackManager backpack = cosmeticUser.getUserBackpackManager();
|
||||
if (backpack != null) {
|
||||
for (int cosmeticId : backpack.getEntityManager().getIds()) {
|
||||
HMCCPacketManager.sendEntityScalePacket(cosmeticId, wrapper.getScale(), Collections.singletonList(player));
|
||||
}
|
||||
}
|
||||
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction readInventoryClick(@NotNull Player player, @NotNull InventoryClickWrapper wrapper) {
|
||||
int clickType = wrapper.getClickType();
|
||||
int slotNumber = wrapper.getSlotNumber();
|
||||
if (clickType != 0 || slotNumber == -999) return PacketAction.NOTHING;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null || user.isInWardrobe()) return PacketAction.NOTHING;
|
||||
CosmeticSlot cosmeticSlot = HMCCInventoryUtils.NMSCosmeticSlot(slotNumber);
|
||||
if (cosmeticSlot == null || !user.hasCosmeticInSlot(cosmeticSlot)) return PacketAction.NOTHING;
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(cosmeticSlot), 1);
|
||||
MessagesUtil.sendDebugMessages("Packet fired, updated cosmetic " + cosmeticSlot);
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction readPlayerAction(@NotNull Player player, @NotNull PlayerActionWrapper wrapper) {
|
||||
if (!Settings.isPreventOffhandSwapping()) return PacketAction.NOTHING;
|
||||
String actionType = wrapper.getActionType();
|
||||
MessagesUtil.sendDebugMessages("EntityStatus Initial " + player.getEntityId() + " - " + actionType);
|
||||
// If it's not SWAP_ITEM_WITH_OFFHAND, ignore
|
||||
if (!actionType.equalsIgnoreCase("SWAP_ITEM_WITH_OFFHAND")) return PacketAction.NOTHING;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) {
|
||||
MessagesUtil.sendDebugMessages("EntityStatus User is null");
|
||||
return PacketAction.NOTHING;
|
||||
}
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return PacketAction.NOTHING;
|
||||
return PacketAction.CANCELLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction readPlayerArm(@NotNull Player player, @NotNull PlayerSwingWrapper wrapper) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null || !user.isInWardrobe() || !user.getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return PacketAction.NOTHING;
|
||||
|
||||
Menu menu = user.getWardrobeManager().getLastOpenMenu();
|
||||
if (menu == null) return PacketAction.NOTHING;
|
||||
menu.openMenu(user);
|
||||
return PacketAction.CANCELLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull PacketAction readEntityHandle(@NotNull Player player, @NotNull PlayerInteractWrapper wrapper) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null || !user.isInWardrobe()) return PacketAction.NOTHING;
|
||||
else return PacketAction.CANCELLED;
|
||||
}
|
||||
}
|
||||
@@ -8,28 +8,29 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.Wardrobe;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticMovementBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.InventoryUtils;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@@ -38,6 +39,7 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -45,120 +47,183 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CosmeticUser {
|
||||
|
||||
public class CosmeticUser implements CosmeticHolder {
|
||||
@Getter
|
||||
private final UUID uniqueId;
|
||||
private int taskId;
|
||||
private int taskId = -1;
|
||||
private final HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
||||
private UserWardrobeManager userWardrobeManager;
|
||||
private UserBalloonManager userBalloonManager;
|
||||
@Getter
|
||||
@Getter @Nullable
|
||||
private UserBackpackManager userBackpackManager;
|
||||
@Getter
|
||||
private final UserEmoteManager userEmoteManager;
|
||||
|
||||
// Cosmetic Settings/Toggles
|
||||
private final ArrayList<HiddenReason> hiddenReason = new ArrayList<>();
|
||||
private final HashMap<CosmeticSlot, Color> colors = new HashMap<>();
|
||||
// Cosmetic caches
|
||||
private final HashMap<String, ItemStack> cosmeticItems = new HashMap<>();
|
||||
|
||||
public CosmeticUser(UUID uuid) {
|
||||
this.uniqueId = uuid;
|
||||
userEmoteManager = new UserEmoteManager(this);
|
||||
tick();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #CosmeticUser(UUID)} instead and use {@link #initialize(UserData)} to populate the user with data.
|
||||
* @param uuid
|
||||
* @param data
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "2.7.5")
|
||||
public CosmeticUser(UUID uuid, UserData data) {
|
||||
this.uniqueId = uuid;
|
||||
userEmoteManager = new UserEmoteManager(this);
|
||||
loadData(data);
|
||||
tick();
|
||||
this(uuid);
|
||||
initialize(data);
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
// Occasionally updates the entity cosmetics
|
||||
Runnable run = () -> {
|
||||
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
|
||||
updateCosmetic();
|
||||
if (isHidden() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().isEmpty()) MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
|
||||
};
|
||||
public CosmeticUser(@NotNull UUID uuid) {
|
||||
this.uniqueId = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the {@link CosmeticUser}.
|
||||
* @param userData the associated {@link UserData}
|
||||
* @return the {@link CosmeticUser}
|
||||
* @apiNote Initialize is called after {@link CosmeticUserProvider#createCosmeticUser(UUID)} so it is possible to
|
||||
* populate an extending version of {@link CosmeticUser} with data then override this method to apply your
|
||||
* own state.
|
||||
*/
|
||||
public CosmeticUser initialize(final @Nullable UserData userData) {
|
||||
if(userData != null) {
|
||||
// CosmeticSlot -> Entry<Cosmetic, Integer>
|
||||
for(final Map.Entry<CosmeticSlot, Map.Entry<Cosmetic, Integer>> entry : userData.getCosmetics().entrySet()) {
|
||||
final Cosmetic cosmetic = entry.getValue().getKey();
|
||||
final Integer colorRGBInt = entry.getValue().getValue();
|
||||
|
||||
if (!this.canApplyCosmetic(cosmetic)) {
|
||||
MessagesUtil.sendDebugMessages("Cannot apply cosmetic[id=" + cosmetic.getId() + "]");
|
||||
continue;
|
||||
}
|
||||
|
||||
Color color = null;
|
||||
if (colorRGBInt != -1) color = Color.fromRGB(colorRGBInt); // -1 is defined as no color; anything else is a color
|
||||
|
||||
this.addCosmetic(cosmetic, color);
|
||||
}
|
||||
this.applyHiddenState(userData.getHiddenReasons());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only called from {@link #initialize(UserData)} and can't be called directly.
|
||||
* This is used to help hooking plugins apply custom logic to the user.
|
||||
*/
|
||||
protected boolean applyCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
this.addCosmetic(cosmetic, color);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only called from {@link #initialize(UserData)} and can't be called directly.
|
||||
* This is used to help hooking plugins apply custom logic to the user.
|
||||
*/
|
||||
protected boolean canApplyCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
return canEquipCosmetic(cosmetic, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is only called from {@link #initialize(UserData)} and can't be called directly.
|
||||
* This is used to help hooking plugins apply custom logic to the user.
|
||||
*/
|
||||
protected void applyHiddenState(@NotNull List<HiddenReason> hiddenReasons) {
|
||||
if(!hiddenReason.isEmpty()) {
|
||||
for(final HiddenReason reason : this.hiddenReason) {
|
||||
this.silentlyAddHideFlag(reason);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Player bukkitPlayer = getPlayer();
|
||||
if (bukkitPlayer != null && Settings.isDisabledGamemodesEnabled() && Settings.getDisabledGamemodes().contains(bukkitPlayer.getGameMode().toString())) {
|
||||
MessagesUtil.sendDebugMessages("Hiding cosmetics due to gamemode");
|
||||
hideCosmetics(HiddenReason.GAMEMODE);
|
||||
} else if (this.isHidden(HiddenReason.GAMEMODE)) {
|
||||
MessagesUtil.sendDebugMessages("Showing cosmetics for gamemode");
|
||||
showCosmetics(HiddenReason.GAMEMODE);
|
||||
}
|
||||
|
||||
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(bukkitPlayer.getLocation().getWorld().getName())) {
|
||||
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
|
||||
hideCosmetics(CosmeticUser.HiddenReason.WORLD);
|
||||
} else if (this.isHidden(HiddenReason.WORLD)) {
|
||||
MessagesUtil.sendDebugMessages("Showing Cosmetics due to world");
|
||||
showCosmetics(HiddenReason.WORLD);
|
||||
}
|
||||
|
||||
if (bukkitPlayer != null && bukkitPlayer.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
|
||||
hideCosmetics(HiddenReason.POTION);
|
||||
}
|
||||
|
||||
if (Settings.isAllPlayersHidden()) {
|
||||
hideCosmetics(HiddenReason.DISABLED);
|
||||
}
|
||||
|
||||
for (final HiddenReason reason : hiddenReasons) {
|
||||
this.silentlyAddHideFlag(reason);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start ticking against the {@link CosmeticUser}.
|
||||
* @implNote The tick-rate is determined by the tick period specified in the configuration, if it is less-than or equal to 0
|
||||
* there will be no {@link BukkitTask} created, and the {@link CosmeticUser#taskId} will be -1
|
||||
*/
|
||||
public final void startTicking() {
|
||||
int tickPeriod = Settings.getTickPeriod();
|
||||
if (tickPeriod > 0) {
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), run, 0, tickPeriod);
|
||||
taskId = task.getTaskId();
|
||||
if(tickPeriod <= 0) {
|
||||
MessagesUtil.sendDebugMessages("CosmeticUser tick is disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
final BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), this::tick, 0, tickPeriod);
|
||||
this.taskId = task.getTaskId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch an operation to happen against this {@link CosmeticUser}
|
||||
* at a pre-determined tick-rate.
|
||||
* The tick-rate is determined by the tick period specified in the configuration.
|
||||
*/
|
||||
protected void tick() {
|
||||
MessagesUtil.sendDebugMessages("Tick[uuid=" + uniqueId + "]", Level.INFO);
|
||||
|
||||
if (Hooks.isInvisible(uniqueId)) {
|
||||
this.hideCosmetics(HiddenReason.VANISH);
|
||||
} else {
|
||||
this.showCosmetics(HiddenReason.VANISH);
|
||||
}
|
||||
|
||||
this.updateCosmetic();
|
||||
|
||||
if(isHidden() && !playerCosmetics.isEmpty()) {
|
||||
MessagesUtil.sendActionBar(getPlayer(), "hidden-cosmetics");
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
Bukkit.getScheduler().cancelTask(taskId);
|
||||
if(this.taskId != -1) { // ensure we're actually ticking this user.
|
||||
Bukkit.getScheduler().cancelTask(taskId);
|
||||
}
|
||||
|
||||
despawnBackpack();
|
||||
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) {
|
||||
@Override
|
||||
public Cosmetic getCosmetic(@NotNull CosmeticSlot slot) {
|
||||
return playerCosmetics.get(slot);
|
||||
}
|
||||
|
||||
public ImmutableCollection<Cosmetic> getCosmetics() {
|
||||
@Override
|
||||
public @NotNull ImmutableCollection<Cosmetic> getCosmetics() {
|
||||
return ImmutableList.copyOf(playerCosmetics.values());
|
||||
}
|
||||
|
||||
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
addPlayerCosmetic(cosmetic, null);
|
||||
}
|
||||
|
||||
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
@Override
|
||||
public void addCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
// API
|
||||
PlayerCosmeticEquipEvent event = new PlayerCosmeticEquipEvent(this, cosmetic);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
@@ -190,15 +255,24 @@ public class CosmeticUser {
|
||||
Bukkit.getPluginManager().callEvent(postEquipEvent);
|
||||
}
|
||||
|
||||
public void removeCosmetics() {
|
||||
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
|
||||
for (CosmeticSlot slot : CosmeticSlot.values()) {
|
||||
removeCosmeticSlot(slot);
|
||||
}
|
||||
/**
|
||||
* @deprecated Use {@link #addCosmetic(Cosmetic)} instead
|
||||
*/
|
||||
@Deprecated(since = "2.7.7", forRemoval = true)
|
||||
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic) {
|
||||
addCosmetic(cosmetic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #addCosmetic(Cosmetic, Color)} instead
|
||||
*/
|
||||
@Deprecated(since = "2.7.7", forRemoval = true)
|
||||
public void addPlayerCosmetic(@NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
addCosmetic(cosmetic, color);
|
||||
}
|
||||
|
||||
public void removeCosmeticSlot(CosmeticSlot slot) {
|
||||
@Override
|
||||
public void removeCosmeticSlot(@NotNull CosmeticSlot slot) {
|
||||
// API
|
||||
PlayerCosmeticRemoveEvent event = new PlayerCosmeticRemoveEvent(this, getCosmetic(slot));
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
@@ -212,51 +286,68 @@ public class CosmeticUser {
|
||||
if (slot == CosmeticSlot.BALLOON) {
|
||||
despawnBalloon();
|
||||
}
|
||||
if (slot == CosmeticSlot.EMOTE) {
|
||||
if (getUserEmoteManager().isPlayingEmote()) getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.UNEQUIP);
|
||||
}
|
||||
colors.remove(slot);
|
||||
playerCosmetics.remove(slot);
|
||||
removeArmor(slot);
|
||||
}
|
||||
|
||||
|
||||
public void removeCosmeticSlot(Cosmetic cosmetic) {
|
||||
removeCosmeticSlot(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
public boolean hasCosmeticInSlot(CosmeticSlot slot) {
|
||||
@Override
|
||||
public boolean hasCosmeticInSlot(@NotNull CosmeticSlot slot) {
|
||||
return playerCosmetics.containsKey(slot);
|
||||
}
|
||||
|
||||
public boolean hasCosmeticInSlot(Cosmetic cosmetic) {
|
||||
if (getCosmetic(cosmetic.getSlot()) == null) return false;
|
||||
return Objects.equals(cosmetic.getId(), getCosmetic(cosmetic.getSlot()).getId());
|
||||
}
|
||||
|
||||
public Set<CosmeticSlot> getSlotsWithCosmetics() {
|
||||
return Set.copyOf(playerCosmetics.keySet());
|
||||
}
|
||||
|
||||
public void updateCosmetic(CosmeticSlot slot) {
|
||||
if (getCosmetic(slot) == null) {
|
||||
return;
|
||||
@Override
|
||||
public boolean updateCosmetic(@NotNull CosmeticSlot slot) {
|
||||
final Cosmetic cosmetic = playerCosmetics.get(slot);
|
||||
if(cosmetic == null) {
|
||||
return false;
|
||||
}
|
||||
getCosmetic(slot).update(this);
|
||||
return;
|
||||
|
||||
if(!(cosmetic instanceof CosmeticUpdateBehavior behavior)) {
|
||||
MessagesUtil.sendDebugMessages("Attempted to update cosmetic that does not implement CosmeticUpdateBehavior");
|
||||
return false;
|
||||
}
|
||||
|
||||
behavior.dispatchUpdate(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateCosmetic(Cosmetic cosmetic) {
|
||||
updateCosmetic(cosmetic.getSlot());
|
||||
@Override
|
||||
public boolean updateMovementCosmetic(@NotNull CosmeticSlot slot, @NotNull final Location from, @NotNull final Location to) {
|
||||
final Cosmetic cosmetic = playerCosmetics.get(slot);
|
||||
if(cosmetic == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(cosmetic instanceof CosmeticMovementBehavior behavior)) {
|
||||
MessagesUtil.sendDebugMessages("Attempted to update cosmetic that does not implement CosmeticMovementBehavior");
|
||||
return false;
|
||||
}
|
||||
|
||||
behavior.dispatchMove(this, from, to);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean updateCosmetic(@NotNull final Cosmetic cosmetic) {
|
||||
return updateCosmetic(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
public void updateCosmetic() {
|
||||
MessagesUtil.sendDebugMessages("updateCosmetic (All) - start");
|
||||
HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
|
||||
final HashMap<EquipmentSlot, ItemStack> items = new HashMap<>();
|
||||
|
||||
for (Cosmetic cosmetic : getCosmetics()) {
|
||||
if (cosmetic instanceof CosmeticArmorType armorType) {
|
||||
if (getUserEmoteManager().isPlayingEmote() || isInWardrobe()) return;
|
||||
for(final Cosmetic cosmetic : playerCosmetics.values()) {
|
||||
if(!(cosmetic instanceof CosmeticUpdateBehavior behavior)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// defers item updates to end of operation
|
||||
if(cosmetic instanceof CosmeticArmorType armorType) {
|
||||
if (isInWardrobe()) return;
|
||||
if (!(getEntity() instanceof HumanEntity humanEntity)) return;
|
||||
|
||||
boolean requireEmpty = Settings.getSlotOption(armorType.getEquipSlot()).isRequireEmpty();
|
||||
@@ -266,15 +357,22 @@ public class CosmeticUser {
|
||||
|
||||
items.put(HMCCInventoryUtils.getEquipmentSlot(armorType.getSlot()), armorType.getItem(this));
|
||||
} else {
|
||||
updateCosmetic(cosmetic.getSlot());
|
||||
behavior.dispatchUpdate(this);
|
||||
}
|
||||
}
|
||||
if (items.isEmpty() || getEntity() == null) return;
|
||||
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), items, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
|
||||
MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size());
|
||||
|
||||
final Entity entity = this.getEntity();
|
||||
if(!items.isEmpty() && entity != null) {
|
||||
PacketManager.equipmentSlotUpdate(
|
||||
entity.getEntityId(),
|
||||
items,
|
||||
HMCCPacketManager.getViewers(entity.getLocation())
|
||||
);
|
||||
MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size());
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getUserCosmeticItem(CosmeticSlot slot) {
|
||||
public ItemStack getUserCosmeticItem(@NotNull CosmeticSlot slot) {
|
||||
Cosmetic cosmetic = getCosmetic(slot);
|
||||
if (cosmetic == null) return new ItemStack(Material.AIR);
|
||||
return getUserCosmeticItem(cosmetic);
|
||||
@@ -289,7 +387,7 @@ public class CosmeticUser {
|
||||
if (cosmetic instanceof CosmeticArmorType armorType) {
|
||||
item = armorType.getItem(this, cosmetic.getItem());
|
||||
}
|
||||
if (cosmetic instanceof CosmeticBackpackType || cosmetic instanceof CosmeticMainhandType) {
|
||||
if (cosmetic instanceof CosmeticBackpackType) {
|
||||
item = cosmetic.getItem();
|
||||
}
|
||||
if (cosmetic instanceof CosmeticBalloonType) {
|
||||
@@ -351,29 +449,15 @@ public class CosmeticUser {
|
||||
}
|
||||
|
||||
|
||||
if (colors.containsKey(cosmetic.getSlot())) {
|
||||
Color color = colors.get(cosmetic.getSlot());
|
||||
if (itemMeta instanceof LeatherArmorMeta leatherMeta) {
|
||||
leatherMeta.setColor(color);
|
||||
} else if (itemMeta instanceof PotionMeta potionMeta) {
|
||||
potionMeta.setColor(color);
|
||||
} else if (itemMeta instanceof MapMeta mapMeta) {
|
||||
mapMeta.setColor(color);
|
||||
} else if (itemMeta instanceof FireworkEffectMeta fireworkMeta) {
|
||||
fireworkMeta.setEffect(
|
||||
FireworkEffect.builder()
|
||||
.with(FireworkEffect.Type.BALL)
|
||||
.withColor(color)
|
||||
.trail(false)
|
||||
.flicker(false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
itemMeta.getPersistentDataContainer().set(HMCCInventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
|
||||
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString());
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
|
||||
if (colors.containsKey(cosmetic.getSlot())) {
|
||||
Color color = colors.get(cosmetic.getSlot());
|
||||
item = NMSHandlers.getHandler().getUtilHandler().setColor(item, color);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@@ -386,7 +470,22 @@ public class CosmeticUser {
|
||||
return userWardrobeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #enterWardrobe(Wardrobe, boolean)} instead.
|
||||
* @param ignoreDistance
|
||||
* @param wardrobe
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "2.7.5")
|
||||
public void enterWardrobe(boolean ignoreDistance, @NotNull Wardrobe wardrobe) {
|
||||
enterWardrobe(wardrobe, ignoreDistance);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to enter a wardrobe. You can listen to the {@link PlayerWardrobeEnterEvent} to cancel the event or modify any data.
|
||||
* @param wardrobe The wardrobe to enter. Use {@link WardrobeSettings#getWardrobe(String)} to get pre-existing wardrobe or use your own by {@link Wardrobe}.
|
||||
* @param ignoreDistance If true, the player can enter the wardrobe from any distance. If false, the player must be within the distance set in the wardrobe (If wardrobe has a distance of 0 or lower, the player can enter from any distance).
|
||||
*/
|
||||
public void enterWardrobe(@NotNull Wardrobe wardrobe, boolean ignoreDistance) {
|
||||
if (wardrobe.hasPermission() && !getPlayer().hasPermission(wardrobe.getPermission())) {
|
||||
MessagesUtil.sendMessage(getPlayer(), "no-permission");
|
||||
return;
|
||||
@@ -412,10 +511,18 @@ public class CosmeticUser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #leaveWardrobe(boolean)} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "2.7.5")
|
||||
public void leaveWardrobe() {
|
||||
leaveWardrobe(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the player to leave the wardrobe. If a player is not in the wardrobe, this will do nothing, use (@{@link #isInWardrobe()} to check if they are).
|
||||
* @param ejected If true, the player was ejected from the wardrobe (Skips transition). If false, the player left the wardrobe normally.
|
||||
*/
|
||||
public void leaveWardrobe(boolean ejected) {
|
||||
PlayerWardrobeLeaveEvent event = new PlayerWardrobeLeaveEvent(this);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
@@ -446,6 +553,10 @@ public class CosmeticUser {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks if the player is in a wardrobe. If they are, it will return true, else false. See {@link #getWardrobeManager()} to get the wardrobe manager.
|
||||
* @return If the player is in a wardrobe.
|
||||
*/
|
||||
public boolean isInWardrobe() {
|
||||
return userWardrobeManager != null;
|
||||
}
|
||||
@@ -513,9 +624,9 @@ public class CosmeticUser {
|
||||
EquipmentSlot equipmentSlot = HMCCInventoryUtils.getEquipmentSlot(slot);
|
||||
if (equipmentSlot == null) return;
|
||||
if (getPlayer() != null) {
|
||||
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
|
||||
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), HMCCPacketManager.getViewers(getEntity().getLocation()));
|
||||
} else {
|
||||
HMCCPacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
|
||||
HMCCPacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, HMCCPacketManager.getViewers(getEntity().getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +645,7 @@ public class CosmeticUser {
|
||||
* @return Entity
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return Bukkit.getEntity(uniqueId);
|
||||
return getPlayer();
|
||||
}
|
||||
|
||||
public Color getCosmeticColor(CosmeticSlot slot) {
|
||||
@@ -542,25 +653,27 @@ public class CosmeticUser {
|
||||
}
|
||||
|
||||
public List<CosmeticSlot> getDyeableSlots() {
|
||||
ArrayList<CosmeticSlot> dyableSlots = new ArrayList<>();
|
||||
ArrayList<CosmeticSlot> dyeableSlots = new ArrayList<>();
|
||||
|
||||
for (Cosmetic cosmetic : getCosmetics()) {
|
||||
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot());
|
||||
for (Cosmetic cosmetic : playerCosmetics.values()) {
|
||||
if (cosmetic.isDyeable()) dyeableSlots.add(cosmetic.getSlot());
|
||||
}
|
||||
|
||||
return dyableSlots;
|
||||
return dyeableSlots;
|
||||
}
|
||||
|
||||
public boolean canEquipCosmetic(Cosmetic cosmetic) {
|
||||
return canEquipCosmetic(cosmetic, false);
|
||||
}
|
||||
|
||||
public boolean canEquipCosmetic(Cosmetic cosmetic, boolean ignoreWardrobe) {
|
||||
@Override
|
||||
public boolean canEquipCosmetic(@NotNull Cosmetic cosmetic, boolean ignoreWardrobe) {
|
||||
if (!cosmetic.requiresPermission()) return true;
|
||||
if (isInWardrobe() && !ignoreWardrobe) {
|
||||
if (WardrobeSettings.isTryCosmeticsInWardrobe() && userWardrobeManager.getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return true;
|
||||
}
|
||||
return getPlayer().hasPermission(cosmetic.getPermission());
|
||||
final Player player = getPlayer();
|
||||
if (player != null) return player.hasPermission(cosmetic.getPermission());
|
||||
// This sucks, but basically if we can find a player, use that. If not, try to find the entity. If it can't find the entity, just return false.
|
||||
final Entity entity = getEntity();
|
||||
if (entity != null) return entity.hasPermission(cosmetic.getPermission());
|
||||
return false;
|
||||
}
|
||||
|
||||
public void hidePlayer() {
|
||||
@@ -624,7 +737,7 @@ public class CosmeticUser {
|
||||
if (!isBalloonSpawned()) respawnBalloon();
|
||||
CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON);
|
||||
getBalloonManager().addPlayerToModel(this, balloonType);
|
||||
List<Player> viewer = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation());
|
||||
List<Player> viewer = HMCCPacketManager.getViewers(getEntity().getLocation());
|
||||
HMCCPacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
|
||||
}
|
||||
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
|
||||
@@ -667,6 +780,7 @@ public class CosmeticUser {
|
||||
NONE,
|
||||
WORLDGUARD,
|
||||
PLUGIN,
|
||||
VANISH,
|
||||
POTION,
|
||||
ACTION,
|
||||
COMMAND,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Allow custom implementations of a {@link CosmeticUser}.
|
||||
*/
|
||||
public abstract class CosmeticUserProvider {
|
||||
/**
|
||||
* Construct the custom {@link CosmeticUser}.
|
||||
* @param playerId the player uuid
|
||||
* @return the {@link CosmeticUser}
|
||||
* @apiNote This method is called during the {@link PlayerJoinEvent}.
|
||||
*/
|
||||
public abstract @NotNull CosmeticUser createCosmeticUser(@NotNull UUID playerId);
|
||||
|
||||
/**
|
||||
* Represents the plugin that is providing this {@link CosmeticUserProvider}
|
||||
* @return the plugin
|
||||
*/
|
||||
public abstract Plugin getProviderPlugin();
|
||||
|
||||
/**
|
||||
* Default implementation.
|
||||
*/
|
||||
static class Default extends CosmeticUserProvider {
|
||||
public static CosmeticUserProvider INSTANCE = new Default();
|
||||
|
||||
@Override
|
||||
public @NotNull CosmeticUser createCosmeticUser(@NotNull UUID playerId) {
|
||||
return new CosmeticUser(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin getProviderPlugin() {
|
||||
return HMCCosmeticsPlugin.getInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -9,10 +8,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class CosmeticUsers {
|
||||
|
||||
private static final HashBiMap<UUID, CosmeticUser> COSMETIC_USERS = HashBiMap.create();
|
||||
private static final ConcurrentHashMap<UUID, CosmeticUser> COSMETIC_USERS = new ConcurrentHashMap<>();
|
||||
|
||||
private static CosmeticUserProvider PROVIDER = CosmeticUserProvider.Default.INSTANCE;
|
||||
|
||||
/**
|
||||
* Adds a user to the Hashmap of stored CosmeticUsers. This will not override an entry if it already exists. If you need to override, delete then add.
|
||||
@@ -52,7 +54,7 @@ public class CosmeticUsers {
|
||||
/**
|
||||
* This method allows you to get a CosmeticUser from just using the player class. This just allows you to have a bit less boilerplate.
|
||||
* @param player The player to lookup (will take their UUID from the class)
|
||||
* @return Returns the user if there is a vlaid user, returns null if not.
|
||||
* @return Returns the user if there is a valid user, returns null if not.
|
||||
*/
|
||||
@Nullable
|
||||
public static CosmeticUser getUser(@NotNull Player player) {
|
||||
@@ -72,12 +74,38 @@ public class CosmeticUsers {
|
||||
return COSMETIC_USERS.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a custom {@link CosmeticUserProvider} to provide your own user implementation to
|
||||
* be used and queried.
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if the provider is already registered by another plugin
|
||||
*/
|
||||
public static void registerProvider(final CosmeticUserProvider provider) {
|
||||
if(PROVIDER != CosmeticUserProvider.Default.INSTANCE) {
|
||||
throw new IllegalArgumentException("CosmeticUserProvider already registered by %s, this conflicts with %s attempting to register their own.".formatted(
|
||||
PROVIDER.getProviderPlugin().getName(),
|
||||
provider.getProviderPlugin().getName()
|
||||
));
|
||||
}
|
||||
|
||||
PROVIDER = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current {@link CosmeticUserProvider} being used.
|
||||
* @return the current {@link CosmeticUserProvider} being used
|
||||
*/
|
||||
public static CosmeticUserProvider getProvider() {
|
||||
return PROVIDER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the values for CosmeticUsers to allow you to iterate over everyone.
|
||||
* @return CosmeticUsers in a set. This will never be null, but might be empty.
|
||||
*/
|
||||
@NotNull
|
||||
public static Set<CosmeticUser> values() {
|
||||
return COSMETIC_USERS.values();
|
||||
// fix this later; this is a temporary fix. It was originally a set, now it's a collection
|
||||
return Set.copyOf(COSMETIC_USERS.values());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,33 +5,32 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.util.ServerUtils;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class UserBackpackManager {
|
||||
|
||||
@Getter
|
||||
private boolean backpackHidden;
|
||||
@Getter
|
||||
private int invisibleArmorStand;
|
||||
private final int invisibleArmorStand;
|
||||
private ArrayList<Integer> particleCloud = new ArrayList<>();
|
||||
@Getter
|
||||
private final CosmeticUser user;
|
||||
@Getter
|
||||
@Getter @Nullable
|
||||
private UserEntity entityManager;
|
||||
|
||||
public UserBackpackManager(CosmeticUser user) {
|
||||
@@ -56,8 +55,15 @@ public class UserBackpackManager {
|
||||
getEntityManager().setIds(List.of(invisibleArmorStand));
|
||||
getEntityManager().teleport(user.getEntity().getLocation());
|
||||
List<Player> outsideViewers = getEntityManager().getViewers();
|
||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
|
||||
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
|
||||
|
||||
HMCCPacketManager.spawnInvisibleArmorstand(getFirstArmorStandId(), user.getEntity().getLocation(), UUID.randomUUID(), outsideViewers);
|
||||
|
||||
if (user.getPlayer() != null) {
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(getFirstArmorStandId(), scaleAttribute.getValue(), outsideViewers);
|
||||
}
|
||||
}
|
||||
|
||||
Entity entity = user.getEntity();
|
||||
|
||||
@@ -75,8 +81,7 @@ public class UserBackpackManager {
|
||||
if (cosmeticBackpackType.isFirstPersonCompadible()) {
|
||||
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
|
||||
int entityId = ServerUtils.getNextEntityId();
|
||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.AREA_EFFECT_CLOUD, UUID.randomUUID());
|
||||
HMCCPacketManager.sendCloudEffect(entityId, HMCCPacketManager.getViewers(user.getEntity().getLocation()));
|
||||
HMCCPacketManager.spawnCloudAndHandleEffect(entityId, user.getEntity().getLocation(), UUID.randomUUID(), HMCCPacketManager.getViewers(user.getEntity().getLocation()));
|
||||
this.particleCloud.add(entityId);
|
||||
}
|
||||
// Copied code from updating the backpack
|
||||
@@ -84,26 +89,12 @@ public class UserBackpackManager {
|
||||
if (i == 0) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), 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.getLast(), user.getUserBackpackManager().getFirstArmorStandId(), owner);
|
||||
if (!user.isHidden()) PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner);
|
||||
}
|
||||
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), 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
|
||||
if (cosmeticBackpackType.getModelName() != null && Hooks.isActiveHook("ModelEngine")) {
|
||||
if (ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||
return;
|
||||
}
|
||||
/* TODO: Readd ModelEngine support
|
||||
ModeledEntity modeledEntity = ModelEngineAPI.createModeledEntity(new PacketBaseEntity(getFirstArmorStandId(), UUID.randomUUID(), entity.getLocation()));
|
||||
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()));
|
||||
model.setCanHurt(false);
|
||||
modeledEntity.addModel(model, false);
|
||||
*/
|
||||
}
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.entity.data.BukkitEntityData;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import com.ticxo.modelengine.api.nms.RenderParsers;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
@@ -50,7 +50,8 @@ public class UserBalloonManager {
|
||||
e.setSmall(true);
|
||||
e.setMarker(true);
|
||||
e.setPersistent(false);
|
||||
e.getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
|
||||
e.setAI(false);
|
||||
e.getPersistentDataContainer().set(HMCCServerUtils.getCosmemeticMobKey(), PersistentDataType.BOOLEAN, true);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ public class UserBalloonManager {
|
||||
|
||||
if (color != null) {
|
||||
modeledEntity.getModels().forEach((d, singleModel) -> {
|
||||
if (cosmeticBalloonType.isDyablePart(d)) {
|
||||
if (cosmeticBalloonType.isDyeablePart(d)) {
|
||||
singleModel.setDefaultTint(color);
|
||||
singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers());
|
||||
}
|
||||
@@ -100,7 +101,12 @@ public class UserBalloonManager {
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
pufferfish.destroyPufferfish();
|
||||
// This code is like a brick road, always bumpy.
|
||||
// Basically, the balloon viewers ignore people in wardrobe, which well, if your the user in the wardrobe, ain't including you.
|
||||
// This manually passes in the viewers for it to destroy, which includes the person in the wardrobe
|
||||
if (user.getPlayer() != null && user.isInWardrobe()) pufferfish.destroyPufferfish(List.of(user.getPlayer()));
|
||||
else pufferfish.destroyPufferfish();
|
||||
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(modelEntity);
|
||||
if (entity == null) {
|
||||
@@ -180,6 +186,10 @@ public class UserBalloonManager {
|
||||
this.getModelEntity().teleport(location);
|
||||
}
|
||||
|
||||
public Vector getVelocity() {
|
||||
return getModelEntity().getVelocity();
|
||||
}
|
||||
|
||||
public void setVelocity(Vector vector) {
|
||||
this.getModelEntity().setVelocity(vector);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -26,6 +21,7 @@ public class UserBalloonPufferfish extends UserEntity {
|
||||
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
|
||||
super(owner);
|
||||
this.pufferFishEntityId = pufferFishEntityId;
|
||||
setIds(List.of(pufferFishEntityId));
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@@ -35,8 +31,11 @@ public class UserBalloonPufferfish extends UserEntity {
|
||||
}
|
||||
|
||||
public void spawnPufferfish(Location location, List<Player> sendTo) {
|
||||
NMSHandlers.getHandler().getPacketHandler().sendInvisibleEntity(pufferFishEntityId, EntityType.PUFFERFISH, location, uuid, sendTo);
|
||||
/*
|
||||
HMCCPacketManager.sendEntitySpawnPacket(location, pufferFishEntityId, EntityType.PUFFERFISH, uuid, sendTo);
|
||||
HMCCPacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo);
|
||||
*/
|
||||
}
|
||||
|
||||
public void destroyPufferfish() {
|
||||
@@ -45,6 +44,12 @@ public class UserBalloonPufferfish extends UserEntity {
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
public void destroyPufferfish(List<Player> viewers) {
|
||||
HMCCPacketManager.sendEntityDestroyPacket(pufferFishEntityId, viewers);
|
||||
//getViewers().clear();
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> refreshViewers(Location location) {
|
||||
if (destroyed) return List.of(); //Prevents refreshing a destroyed entity
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStartEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerEmoteStopEvent;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
|
||||
import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UserEmoteManager {
|
||||
|
||||
private CosmeticUser user;
|
||||
private UserEmoteModel model;
|
||||
private Entity textEntity;
|
||||
|
||||
public UserEmoteManager(CosmeticUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void playEmote(String animationId) {
|
||||
MessagesUtil.sendDebugMessages("playEmote " + animationId);
|
||||
playEmote(EmoteManager.get(animationId), null);
|
||||
}
|
||||
|
||||
public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) {
|
||||
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
|
||||
playEmote(EmoteManager.get(cosmeticEmoteType.getAnimationId()), cosmeticEmoteType.getText());
|
||||
}
|
||||
|
||||
public void playEmote(String emoteAnimation, String text) {
|
||||
if (isPlayingEmote()) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
// API
|
||||
PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, emoteAnimation);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
// Internal
|
||||
try {
|
||||
model = new UserEmoteModel(user);
|
||||
// Play animation id
|
||||
if (emoteAnimation != null) {
|
||||
model.playAnimation(emoteAnimation);
|
||||
}
|
||||
// Show the text
|
||||
if (text != null && textEntity == null) {
|
||||
// removed in 2.7.0
|
||||
//textEntity = HMCCNMSHandlers.getHandler().spawnDisplayEntity(user.getPlayer().getLocation().add(0, 3, 0), text);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlayingEmote() {
|
||||
if (model == null) return false;
|
||||
return model.isPlayingAnimation();
|
||||
}
|
||||
|
||||
public void stopEmote(StopEmoteReason emoteReason) {
|
||||
if (!isPlayingEmote()) return;
|
||||
// API
|
||||
PlayerEmoteStopEvent event = new PlayerEmoteStopEvent(user, emoteReason);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
// Internal
|
||||
model.stopAnimation();
|
||||
if (textEntity != null) {
|
||||
textEntity.remove();
|
||||
textEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void despawnTextEntity() {
|
||||
if (textEntity != null) {
|
||||
textEntity.remove();
|
||||
textEntity = null;
|
||||
}
|
||||
}
|
||||
|
||||
public enum StopEmoteReason {
|
||||
SNEAK,
|
||||
DAMAGE,
|
||||
CONNECTION,
|
||||
TELEPORT,
|
||||
UNEQUIP
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import com.ticxo.playeranimator.api.model.player.PlayerModel;
|
||||
import me.lojosho.hibiscuscommons.util.ServerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserEmoteModel extends PlayerModel {
|
||||
|
||||
private final CosmeticUser user;
|
||||
private String emotePlaying;
|
||||
private final int armorStandId;
|
||||
private GameMode originalGamemode;
|
||||
|
||||
public UserEmoteModel(@NotNull CosmeticUser user) {
|
||||
super(user.getPlayer());
|
||||
this.user = user;
|
||||
armorStandId = ServerUtils.getNextEntityId();
|
||||
getRangeManager().setRenderDistance(Settings.getViewDistance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playAnimation(@NotNull String id) {
|
||||
super.playAnimation(id);
|
||||
|
||||
emotePlaying = id;
|
||||
|
||||
// Add config option that either allows player to move or forces them into a spot.
|
||||
Player player = user.getPlayer();
|
||||
List<Player> viewer = Collections.singletonList(user.getPlayer());
|
||||
List<Player> outsideViewers = HMCCPacketManager.getViewers(player.getLocation());
|
||||
// Send equipment packet to the player as well (Fixes Optifine still rendering armor when emoting)
|
||||
HMCCPacketManager.equipmentSlotUpdate(player, true, outsideViewers);
|
||||
outsideViewers.remove(player);
|
||||
|
||||
user.getPlayer().setInvisible(true);
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
||||
|
||||
originalGamemode = player.getGameMode();
|
||||
|
||||
if (Settings.isEmoteCameraEnabled()) {
|
||||
Location newLocation = player.getLocation().clone();
|
||||
newLocation.setPitch(0);
|
||||
|
||||
double DISTANCE = Settings.getEmoteDistance();
|
||||
|
||||
Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE));
|
||||
if (DISTANCE > 0) {
|
||||
MessagesUtil.sendDebugMessages("Yaw " + (int) thirdPersonLocation.getYaw());
|
||||
MessagesUtil.sendDebugMessages("New Yaw " + ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
|
||||
thirdPersonLocation.setYaw(ServerUtils.getNextYaw((int) thirdPersonLocation.getYaw(), 180));
|
||||
}
|
||||
if (Settings.isCosmeticEmoteBlockCheck() && thirdPersonLocation.getBlock().getType().isOccluding()) {
|
||||
stopAnimation();
|
||||
MessagesUtil.sendMessage(player, "emote-blocked");
|
||||
return;
|
||||
}
|
||||
// Check if block below player is an air block
|
||||
if (Settings.isEmoteAirCheck() && newLocation.clone().subtract(0, 1, 0).getBlock().getType().isAir()) {
|
||||
stopAnimation();
|
||||
MessagesUtil.sendMessage(player, "emote-blocked");
|
||||
}
|
||||
|
||||
HMCCPacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||
HMCCPacketManager.sendInvisibilityPacket(armorStandId, viewer);
|
||||
HMCCPacketManager.sendLookPacket(armorStandId, thirdPersonLocation, viewer);
|
||||
|
||||
HMCCPacketManager.gamemodeChangePacket(player, 3);
|
||||
HMCCPacketManager.sendCameraPacket(armorStandId, viewer);
|
||||
}
|
||||
|
||||
|
||||
MessagesUtil.sendDebugMessages("playAnimation run");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
if (super.getAnimationProperty() == null) {
|
||||
stopAnimation();
|
||||
return false;
|
||||
}
|
||||
boolean update = (super.update() && isPlayingAnimation());
|
||||
if (!update) {
|
||||
stopAnimation();
|
||||
}
|
||||
return update;
|
||||
}
|
||||
|
||||
public void stopAnimation() {
|
||||
emotePlaying = null;
|
||||
despawn();
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
Player player = user.getPlayer();
|
||||
if (player == null) return;
|
||||
|
||||
List<Player> viewer = Collections.singletonList(player);
|
||||
List<Player> outsideViewers = HMCCPacketManager.getViewers(player.getLocation());
|
||||
// Send Equipment packet to all (Fixes Optifine Issue)
|
||||
HMCCPacketManager.equipmentSlotUpdate(player, false, outsideViewers);
|
||||
outsideViewers.remove(player);
|
||||
|
||||
int entityId = player.getEntityId();
|
||||
HMCCPacketManager.sendCameraPacket(entityId, viewer);
|
||||
HMCCPacketManager.sendEntityDestroyPacket(armorStandId, viewer);
|
||||
if (this.originalGamemode != null) {
|
||||
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode));
|
||||
player.setGameMode(this.originalGamemode);
|
||||
}
|
||||
|
||||
if (user.getPlayer() != null) player.setInvisible(false);
|
||||
user.getUserEmoteManager().despawnTextEntity();
|
||||
user.showPlayer();
|
||||
user.showCosmetics(CosmeticUser.HiddenReason.EMOTE);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isPlayingAnimation() {
|
||||
return emotePlaying != null;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class UserEntity {
|
||||
|
||||
@@ -40,46 +39,73 @@ public class UserEntity {
|
||||
}
|
||||
|
||||
public List<Player> refreshViewers(Location location) {
|
||||
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
|
||||
ArrayList<Player> newPlayers = new ArrayList<>();
|
||||
ArrayList<Player> removePlayers = new ArrayList<>();
|
||||
List<Player> players = HMCCPlayerUtils.getNearbyPlayers(location);
|
||||
Player ownerPlayer = Bukkit.getPlayer(owner);
|
||||
//Prevents mass refreshes
|
||||
//if(System.currentTimeMillis() - viewerLastUpdate <= 3000) {
|
||||
// return List.of();
|
||||
//}
|
||||
|
||||
Entity ownerPlayer = Bukkit.getEntity(owner);
|
||||
if (ownerPlayer == null) {
|
||||
MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list");
|
||||
return List.of();
|
||||
}
|
||||
|
||||
final List<Player> players = HMCCosmeticsPlugin.getInstance()
|
||||
.getPlayerSearchManager()
|
||||
.getPlayersInRange(location, Settings.getViewDistance());
|
||||
|
||||
final ArrayList<UUID> newPlayerIds = new ArrayList<>();
|
||||
final ArrayList<UUID> removePlayerIds = new ArrayList<>();
|
||||
|
||||
// Go through all nearby players, check if they are new to the viewers list.
|
||||
for (Player player : players) {
|
||||
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
|
||||
removePlayers.add(player);
|
||||
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(player));
|
||||
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
|
||||
&& !player.canSee(ownerPlayer)
|
||||
) {
|
||||
removePlayerIds.add(player.getUniqueId());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!viewers.contains(player)) {
|
||||
viewers.add(player);
|
||||
newPlayers.add(player);
|
||||
continue;
|
||||
}
|
||||
// bad loopdy loops
|
||||
for (Player viewerPlayer : viewers) {
|
||||
if (!players.contains(viewerPlayer)) {
|
||||
removePlayers.add(viewerPlayer);
|
||||
HMCCPacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer));
|
||||
}
|
||||
newPlayerIds.add(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
viewers.removeAll(removePlayers);
|
||||
setViewerLastUpdate(System.currentTimeMillis());
|
||||
return newPlayers;
|
||||
// Basically, if they are not nearby, they are still in the viewers and we need to kick em to the curb
|
||||
for (Player viewerPlayer : viewers) {
|
||||
if (!players.contains(viewerPlayer)) {
|
||||
removePlayerIds.add(viewerPlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
// If there are players for removal, send the packets to them
|
||||
if (!removePlayerIds.isEmpty()) {
|
||||
final List<Player> removePlayers = removePlayerIds.stream()
|
||||
.map(Bukkit::getPlayer)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
HMCCPacketManager.sendEntityDestroyPacket(ids, removePlayers);
|
||||
viewers.removeAll(removePlayers);
|
||||
}
|
||||
|
||||
this.setViewerLastUpdate(System.currentTimeMillis());
|
||||
return newPlayerIds.stream()
|
||||
.map(Bukkit::getPlayer)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
|
||||
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
|
||||
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
|
||||
if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||
//if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||
}
|
||||
this.location = location;
|
||||
for (Integer entity : ids) {
|
||||
@@ -98,7 +124,7 @@ public class UserEntity {
|
||||
// First person backpacks need both packets to rotate properly, otherwise they look off
|
||||
// Regular backpacks just need the look packet
|
||||
if (additonalPacket) HMCCPacketManager.sendRotationPacket(entity, yaw, false, getViewers());
|
||||
HMCCPacketManager.sendLookPacket(entity, location, getViewers());
|
||||
HMCCPacketManager.sendRotateHeadPacket(entity, location, getViewers());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
@@ -64,6 +65,7 @@ public class UserWardrobeManager {
|
||||
private BossBar bossBar;
|
||||
@Getter
|
||||
private boolean active;
|
||||
@Setter
|
||||
@Getter
|
||||
private WardrobeStatus wardrobeStatus;
|
||||
@Getter
|
||||
@@ -108,15 +110,22 @@ public class UserWardrobeManager {
|
||||
MessagesUtil.sendMessage(player, "opened-wardrobe");
|
||||
|
||||
Runnable run = () -> {
|
||||
if (!player.isOnline()) {
|
||||
end();
|
||||
return;
|
||||
}
|
||||
|
||||
// Armorstand
|
||||
HMCCPacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||
HMCCPacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
|
||||
HMCCPacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendTeleportPacket(ARMORSTAND_ID, viewingLocation.getX(), viewingLocation.getY(), viewingLocation.getZ(), viewingLocation.getYaw(), viewingLocation.getPitch(), false, viewer);
|
||||
//NMSHandlers.getHandler().getPacketHandler().sendLookAtPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
||||
HMCCPacketManager.sendRotateHeadPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
||||
|
||||
// Player
|
||||
user.getPlayer().teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
user.getPlayer().setInvisible(true);
|
||||
HMCCPacketManager.gamemodeChangePacket(player, 3);
|
||||
player.teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
player.setInvisible(true);
|
||||
HMCCPacketManager.gamemodeChangePacket(player, GameMode.SPECTATOR);
|
||||
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
||||
|
||||
// NPC
|
||||
@@ -133,10 +142,14 @@ public class UserWardrobeManager {
|
||||
HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
|
||||
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName);
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(NPC_ID, scaleAttribute.getValue(), viewer);
|
||||
}
|
||||
}, 4);
|
||||
|
||||
// Location
|
||||
HMCCPacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
|
||||
HMCCPacketManager.sendRotateHeadPacket(NPC_ID, npcLocation, viewer);
|
||||
HMCCPacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
|
||||
|
||||
// Misc
|
||||
@@ -170,9 +183,9 @@ public class UserWardrobeManager {
|
||||
Component message = MessagesUtil.processStringNoKey(player, WardrobeSettings.getBossbarMessage());
|
||||
|
||||
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
//Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.showBossBar(bossBar);
|
||||
player.showBossBar(bossBar);
|
||||
}
|
||||
|
||||
if (WardrobeSettings.isEnterOpenMenu()) {
|
||||
@@ -241,11 +254,11 @@ public class UserWardrobeManager {
|
||||
if (WardrobeSettings.isForceExitGamemode()) {
|
||||
MessagesUtil.sendDebugMessages("Force Exit Gamemode " + WardrobeSettings.getExitGamemode());
|
||||
player.setGameMode(WardrobeSettings.getExitGamemode());
|
||||
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(WardrobeSettings.getExitGamemode())); // Success
|
||||
HMCCPacketManager.gamemodeChangePacket(player, WardrobeSettings.getExitGamemode()); // Success
|
||||
} else {
|
||||
MessagesUtil.sendDebugMessages("Original Gamemode " + this.originalGamemode);
|
||||
player.setGameMode(this.originalGamemode);
|
||||
HMCCPacketManager.gamemodeChangePacket(player, HMCCServerUtils.convertGamemode(this.originalGamemode)); // Success
|
||||
HMCCPacketManager.gamemodeChangePacket(player, this.originalGamemode); // Success
|
||||
}
|
||||
user.showPlayer();
|
||||
|
||||
@@ -274,9 +287,8 @@ public class UserWardrobeManager {
|
||||
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), items, viewer);
|
||||
|
||||
if (WardrobeSettings.isEnabledBossbar()) {
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.hideBossBar(bossBar);
|
||||
//Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
player.hideBossBar(bossBar);
|
||||
}
|
||||
|
||||
user.updateCosmetic();
|
||||
@@ -284,7 +296,7 @@ public class UserWardrobeManager {
|
||||
run.run();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
private void update() {
|
||||
final AtomicInteger data = new AtomicInteger();
|
||||
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@@ -305,15 +317,17 @@ public class UserWardrobeManager {
|
||||
int yaw = data.get();
|
||||
location.setYaw(yaw);
|
||||
|
||||
HMCCPacketManager.sendLookPacket(NPC_ID, location, viewer);
|
||||
HMCCPacketManager.sendRotateHeadPacket(NPC_ID, location, viewer);
|
||||
user.hidePlayer();
|
||||
int rotationSpeed = WardrobeSettings.getRotationSpeed();
|
||||
location.setYaw(HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed));
|
||||
HMCCPacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
|
||||
int newYaw = HMCCServerUtils.getNextYaw(yaw - 30, rotationSpeed);
|
||||
location.setYaw(newYaw);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(NPC_ID, newYaw, 0, false, viewer);
|
||||
HMCCPacketManager.sendRotationPacket(NPC_ID, newYaw, true, viewer);
|
||||
int nextyaw = HMCCServerUtils.getNextYaw(yaw, rotationSpeed);
|
||||
data.set(nextyaw);
|
||||
|
||||
for (CosmeticSlot slot : CosmeticSlot.values()) {
|
||||
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
|
||||
HMCCPacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
|
||||
}
|
||||
|
||||
@@ -346,10 +360,6 @@ public class UserWardrobeManager {
|
||||
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
|
||||
}
|
||||
|
||||
public void setWardrobeStatus(WardrobeStatus status) {
|
||||
this.wardrobeStatus = status;
|
||||
}
|
||||
|
||||
public enum WardrobeStatus {
|
||||
SETUP,
|
||||
STARTING,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -12,24 +11,20 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class HMCCInventoryUtils {
|
||||
|
||||
/**
|
||||
* Converts from the Bukkit item slots to ProtocolLib item slots. Will produce a null if an improper bukkit item slot is sent through
|
||||
* @param slot The BUKKIT item slot to convert.
|
||||
* @return The ProtocolLib item slot that is returned
|
||||
*/
|
||||
public static EnumWrappers.ItemSlot itemBukkitSlot(final EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HEAD -> EnumWrappers.ItemSlot.HEAD;
|
||||
case CHEST -> EnumWrappers.ItemSlot.CHEST;
|
||||
case LEGS -> EnumWrappers.ItemSlot.LEGS;
|
||||
case FEET -> EnumWrappers.ItemSlot.FEET;
|
||||
case HAND -> EnumWrappers.ItemSlot.MAINHAND;
|
||||
case OFF_HAND -> EnumWrappers.ItemSlot.OFFHAND;
|
||||
};
|
||||
private static final Map<CosmeticSlot, EquipmentSlot> SLOT_MAP = new HashMap<>();
|
||||
static {
|
||||
SLOT_MAP.put(CosmeticSlot.HELMET, EquipmentSlot.HEAD);
|
||||
SLOT_MAP.put(CosmeticSlot.CHESTPLATE, EquipmentSlot.CHEST);
|
||||
SLOT_MAP.put(CosmeticSlot.LEGGINGS, EquipmentSlot.LEGS);
|
||||
SLOT_MAP.put(CosmeticSlot.BOOTS, EquipmentSlot.FEET);
|
||||
SLOT_MAP.put(CosmeticSlot.OFFHAND, EquipmentSlot.OFF_HAND);
|
||||
SLOT_MAP.put(CosmeticSlot.MAINHAND, EquipmentSlot.HAND);
|
||||
}
|
||||
|
||||
public static int getPacketArmorSlot(final EquipmentSlot slot) {
|
||||
@@ -55,18 +50,6 @@ public class HMCCInventoryUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static CosmeticSlot getItemSlotToCosmeticSlot(final EnumWrappers.ItemSlot slot) {
|
||||
return switch (slot) {
|
||||
case HEAD -> CosmeticSlot.HELMET;
|
||||
case CHEST -> CosmeticSlot.CHESTPLATE;
|
||||
case LEGS -> CosmeticSlot.LEGGINGS;
|
||||
case FEET -> CosmeticSlot.BOOTS;
|
||||
case OFFHAND -> CosmeticSlot.OFFHAND;
|
||||
case MAINHAND -> CosmeticSlot.MAINHAND;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HAND -> CosmeticSlot.MAINHAND;
|
||||
@@ -132,55 +115,7 @@ public class HMCCInventoryUtils {
|
||||
@Contract(pure = true)
|
||||
@Nullable
|
||||
public static EquipmentSlot getEquipmentSlot(@NotNull CosmeticSlot slot) {
|
||||
switch (slot) {
|
||||
case HELMET -> {
|
||||
return EquipmentSlot.HEAD;
|
||||
}
|
||||
case CHESTPLATE -> {
|
||||
return EquipmentSlot.CHEST;
|
||||
}
|
||||
case LEGGINGS -> {
|
||||
return EquipmentSlot.LEGS;
|
||||
}
|
||||
case BOOTS -> {
|
||||
return EquipmentSlot.FEET;
|
||||
}
|
||||
case OFFHAND -> {
|
||||
return EquipmentSlot.OFF_HAND;
|
||||
}
|
||||
case MAINHAND -> {
|
||||
return EquipmentSlot.HAND;
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EquipmentSlot getEquipmentSlot(@NotNull EnumWrappers.ItemSlot slot) {
|
||||
switch (slot) {
|
||||
case HEAD -> {
|
||||
return EquipmentSlot.HEAD;
|
||||
}
|
||||
case CHEST -> {
|
||||
return EquipmentSlot.CHEST;
|
||||
}
|
||||
case LEGS -> {
|
||||
return EquipmentSlot.LEGS;
|
||||
}
|
||||
case FEET -> {
|
||||
return EquipmentSlot.FEET;
|
||||
}
|
||||
case OFFHAND -> {
|
||||
return EquipmentSlot.OFF_HAND;
|
||||
}
|
||||
case MAINHAND -> {
|
||||
return EquipmentSlot.HAND;
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return SLOT_MAP.get(slot);
|
||||
}
|
||||
|
||||
public static boolean isCosmeticItem(ItemStack itemStack) {
|
||||
|
||||
@@ -1,35 +1,33 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HMCCPlayerUtils {
|
||||
|
||||
@Nullable
|
||||
public static WrappedSignedProperty getSkin(Player player) {
|
||||
WrappedSignedProperty skinData = WrappedGameProfile.fromPlayer(player).getProperties()
|
||||
.get("textures").stream().findAny().orElse(null);
|
||||
|
||||
if (skinData == null) {
|
||||
return null;
|
||||
}
|
||||
return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)}
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated(since = "2.7.5", forRemoval = true)
|
||||
public static List<Player> getNearbyPlayers(@NotNull Player player) {
|
||||
return getNearbyPlayers(player.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)}
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated(since = "2.7.5", forRemoval = true)
|
||||
public static List<Player> getNearbyPlayers(@NotNull Location location) {
|
||||
return PacketManager.getViewers(location, Settings.getViewDistance());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.owen1212055.particlehelper.api.particle.MultiParticle;
|
||||
import com.owen1212055.particlehelper.api.particle.Particle;
|
||||
import com.owen1212055.particlehelper.api.particle.types.*;
|
||||
@@ -9,6 +10,8 @@ import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.math.BigInteger;
|
||||
@@ -158,12 +161,7 @@ public class HMCCServerUtils {
|
||||
return nextYaw;
|
||||
}
|
||||
|
||||
public static boolean hasClass(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
public static NamespacedKey getCosmemeticMobKey() {
|
||||
return new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticmob");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.util.AdventureUtils;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.title.Title;
|
||||
@@ -43,41 +42,35 @@ public class MessagesUtil {
|
||||
public static void sendMessage(Player player, String key) {
|
||||
Component finalMessage = processString(player, key);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
player.sendMessage(finalMessage);
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String key) {
|
||||
Component finalMessage = processString(null, key);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
sender.sendMessage(finalMessage);
|
||||
}
|
||||
|
||||
public static void sendMessage(Player player, String key, TagResolver placeholder) {
|
||||
Component finalMessage = processString(player, key, placeholder);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
player.sendMessage(finalMessage);
|
||||
}
|
||||
|
||||
public static void sendMessageNoKey(Player player, String message) {
|
||||
Component finalMessage = processStringNoKey(player, message);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
player.sendMessage(finalMessage);
|
||||
}
|
||||
|
||||
public static void sendActionBar(Player player, String key) {
|
||||
Component finalMessage = processString(player, key);
|
||||
if (finalMessage == null) return;
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendActionBar(finalMessage);
|
||||
player.sendActionBar(finalMessage);
|
||||
}
|
||||
|
||||
public static void sendTitle(Player player, String message) {
|
||||
@@ -85,12 +78,10 @@ public class MessagesUtil {
|
||||
}
|
||||
|
||||
public static void sendTitle(Player player, String message, int fadein, int stay, int fadeout) {
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
Title.Times times = Title.Times.times(Duration.ofMillis(fadein), Duration.ofMillis(stay), Duration.ofMillis(fadeout));
|
||||
Title title = Title.title(processStringNoKey(player, message), Component.empty(), times);
|
||||
|
||||
target.showTitle(title);
|
||||
player.showTitle(title);
|
||||
}
|
||||
|
||||
public static Component processString(Player player, String key) {
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Octree<T> {
|
||||
|
||||
private static final int MAX_CAPACITY = 8;
|
||||
private BoundingBox boundary;
|
||||
private List<Entry> points;
|
||||
private Octree<T>[] children;
|
||||
private boolean isDivided;
|
||||
|
||||
public Octree(BoundingBox boundary) {
|
||||
this.boundary = boundary;
|
||||
this.points = new ArrayList<>();
|
||||
this.isDivided = false;
|
||||
}
|
||||
|
||||
public boolean insert(Point3D position, T data) {
|
||||
if (!boundary.contains(position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (points.size() < MAX_CAPACITY && !isDivided) {
|
||||
points.add(new Entry(position, data));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isDivided) {
|
||||
subdivide();
|
||||
}
|
||||
|
||||
for (Octree<T> child : children) {
|
||||
if (child.insert(position, data)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean remove(Point3D point, T player) {
|
||||
if (!boundary.contains(point)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (points.size() < MAX_CAPACITY && !isDivided) {
|
||||
points.removeIf(entry -> entry.position.equals(point) && entry.data.equals(player));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isDivided) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Octree<T> child : children) {
|
||||
if (child.remove(point, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<T> queryRange(BoundingBox range) {
|
||||
List<T> found = new ArrayList<>();
|
||||
|
||||
if (!boundary.intersects(range)) {
|
||||
return found;
|
||||
}
|
||||
|
||||
for (Entry entry : points) {
|
||||
if (range.contains(entry.position)) {
|
||||
found.add(entry.data);
|
||||
}
|
||||
}
|
||||
|
||||
if (isDivided) {
|
||||
for (Octree<T> child : children) {
|
||||
found.addAll(child.queryRange(range));
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private void subdivide() {
|
||||
double x = boundary.center.x;
|
||||
double y = boundary.center.y;
|
||||
double z = boundary.center.z;
|
||||
double newHalfSize = boundary.halfSize / 2.0;
|
||||
|
||||
children = new Octree[8];
|
||||
children[0] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y - newHalfSize, z - newHalfSize), newHalfSize));
|
||||
children[1] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y - newHalfSize, z - newHalfSize), newHalfSize));
|
||||
children[2] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y + newHalfSize, z - newHalfSize), newHalfSize));
|
||||
children[3] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y + newHalfSize, z - newHalfSize), newHalfSize));
|
||||
children[4] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y - newHalfSize, z + newHalfSize), newHalfSize));
|
||||
children[5] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y - newHalfSize, z + newHalfSize), newHalfSize));
|
||||
children[6] = new Octree<>(new BoundingBox(new Point3D(x - newHalfSize, y + newHalfSize, z + newHalfSize), newHalfSize));
|
||||
children[7] = new Octree<>(new BoundingBox(new Point3D(x + newHalfSize, y + newHalfSize, z + newHalfSize), newHalfSize));
|
||||
|
||||
isDivided = true;
|
||||
}
|
||||
|
||||
public static class Point3D {
|
||||
double x, y, z;
|
||||
|
||||
public Point3D(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BoundingBox {
|
||||
Point3D center;
|
||||
double halfSize;
|
||||
|
||||
public BoundingBox(Point3D center, double halfSize) {
|
||||
this.center = center;
|
||||
this.halfSize = halfSize;
|
||||
}
|
||||
|
||||
public boolean contains(Point3D point) {
|
||||
return Math.abs(point.x - center.x) <= halfSize &&
|
||||
Math.abs(point.y - center.y) <= halfSize &&
|
||||
Math.abs(point.z - center.z) <= halfSize;
|
||||
}
|
||||
|
||||
public boolean intersects(BoundingBox other) {
|
||||
return Math.abs(center.x - other.center.x) <= halfSize + other.halfSize &&
|
||||
Math.abs(center.y - other.center.y) <= halfSize + other.halfSize &&
|
||||
Math.abs(center.z - other.center.z) <= halfSize + other.halfSize;
|
||||
}
|
||||
}
|
||||
|
||||
private class Entry {
|
||||
Point3D position;
|
||||
T data;
|
||||
|
||||
Entry(Point3D position, T data) {
|
||||
this.position = position;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerSearchManager implements Listener {
|
||||
private final Map<UUID, Octree<Player>> worldOctrees = new HashMap<>();
|
||||
private final Map<UUID, Octree.Point3D> playerPositions = new HashMap<>();
|
||||
|
||||
//private static final double WORLD_HALF_SIZE = 30_000_000; // Previous built in value
|
||||
private final double WORLD_HALF_SIZE;
|
||||
|
||||
public PlayerSearchManager(@NotNull HMCCosmeticsPlugin plugin) {
|
||||
WORLD_HALF_SIZE = (double) plugin.getServer().getMaxWorldSize() / 2;
|
||||
}
|
||||
|
||||
private Octree<Player> getOrCreateOctree(World world) {
|
||||
return worldOctrees.computeIfAbsent(world.getUID(), $ -> {
|
||||
Octree.BoundingBox worldBoundary = new Octree.BoundingBox(
|
||||
new Octree.Point3D(0, 160, 0), WORLD_HALF_SIZE
|
||||
);
|
||||
return new Octree<>(worldBoundary);
|
||||
});
|
||||
}
|
||||
|
||||
private Octree.Point3D toPoint3D(Location location) {
|
||||
return new Octree.Point3D(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public boolean addPlayer(Player player) {
|
||||
Octree<Player> octree = getOrCreateOctree(player.getWorld());
|
||||
Octree.Point3D point = toPoint3D(player.getLocation());
|
||||
|
||||
if(octree.insert(point, player)) {
|
||||
playerPositions.put(player.getUniqueId(), point);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removePlayer(Player player) {
|
||||
Octree<Player> octree = worldOctrees.get(player.getWorld().getUID());
|
||||
if (octree == null) return false;
|
||||
|
||||
Octree.Point3D point = playerPositions.remove(player.getUniqueId());
|
||||
if (point != null) return octree.remove(point, player);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updatePlayerPosition(Player player) {
|
||||
removePlayer(player);
|
||||
addPlayer(player);
|
||||
}
|
||||
|
||||
public List<Player> getPlayersInRange(Location location, double range) {
|
||||
Octree<Player> octree = worldOctrees.get(location.getWorld().getUID());
|
||||
if (octree == null) return Collections.emptyList();
|
||||
|
||||
Octree.Point3D point = toPoint3D(location);
|
||||
Octree.BoundingBox searchArea = new Octree.BoundingBox(point, range);
|
||||
|
||||
return octree.queryRange(searchArea)
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
worldOctrees.clear();
|
||||
playerPositions.clear();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (event.hasChangedBlock()) updatePlayerPosition(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
updatePlayerPosition(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
removePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
addPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import me.lojosho.hibiscuscommons.util.StringUtils;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -32,7 +31,7 @@ public class TranslationUtil {
|
||||
public static String getTranslation(String key, String message) {
|
||||
List<TranslationPair> pairs = keys.get(key);
|
||||
for (TranslationPair pair : pairs) {
|
||||
if (pair.key().equals(message)) return StringUtils.parseStringToString(pair.value());
|
||||
if (pair.key().equals(message)) return pair.value();
|
||||
}
|
||||
|
||||
return message;
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.misc;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
* @return original if not null, otherwise replacement
|
||||
*/
|
||||
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final @NotNull T replacement) {
|
||||
return replaceIfNull(original, replacement, t -> {
|
||||
});
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> T replaceIf(final @Nullable T original, final T replacement, final @Nullable T... checks) {
|
||||
for (final T check : checks) {
|
||||
if (original == check) return replacement;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
public static <T> T replaceIf(final @Nullable T original, final T replacement, final @NotNull Predicate<T> predicate) {
|
||||
if (predicate.test(original)) return replacement;
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
* @param consumer accepts the original object, can be used for logging
|
||||
* @return original if not null, otherwise replacement
|
||||
*/
|
||||
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final T replacement,
|
||||
final @NotNull Consumer<T> consumer) {
|
||||
if (original == null) {
|
||||
consumer.accept(replacement);
|
||||
return replacement;
|
||||
}
|
||||
consumer.accept(original);
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t object being checked
|
||||
* @param consumer accepted if t is not null
|
||||
* @param <T> type
|
||||
*/
|
||||
|
||||
public static <T> void doIfNotNull(final @Nullable T t, final @NotNull Consumer<T> consumer) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
consumer.accept(t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t object being checked
|
||||
* @param function applied if t is not null
|
||||
* @param <T> type
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static <T> Optional<T> returnIfNotNull(final @Nullable T t,
|
||||
final @NotNull Function<T, T> function) {
|
||||
if (t == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(function.apply(t));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enumAsString Enum value as a string to be parsed
|
||||
* @param enumClass enum type enumAsString is to be converted to
|
||||
* @param defaultEnum default value to be returned
|
||||
* @return enumAsString as an enum, or default enum if it could not be parsed
|
||||
*/
|
||||
|
||||
public static <E extends Enum<E>> E stringToEnum(final @NotNull String enumAsString,
|
||||
final @NotNull Class<E> enumClass,
|
||||
E defaultEnum) {
|
||||
return stringToEnum(enumAsString, enumClass, defaultEnum, e -> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enumAsString Enum value as a string to be parsed
|
||||
* @param enumClass enum type enumAsString is to be converted to
|
||||
* @param defaultEnum default value to be returned
|
||||
* @param consumer accepts the returned enum, can be used for logging
|
||||
* @return enumAsString as an enum, or default enum if it could not be parsed
|
||||
*/
|
||||
|
||||
public static <E extends Enum<E>> E stringToEnum(final @NotNull String enumAsString,
|
||||
@NotNull final Class<E> enumClass,
|
||||
final E defaultEnum,
|
||||
final @NotNull Consumer<E> consumer) {
|
||||
try {
|
||||
final E value = Enum.valueOf(enumClass, enumAsString);
|
||||
consumer.accept(value);
|
||||
return value;
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
consumer.accept(defaultEnum);
|
||||
return defaultEnum;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +1,35 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove;
|
||||
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Display;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HMCCPacketManager extends PacketManager {
|
||||
|
||||
// The cloud effect map, in case it gets lost: Map<Integer, Number> dataValues = Map.of(0, (byte) 0x20, 8, 0f);
|
||||
private static final List<CosmeticSlot> EQUIPMENT_SLOTS = List.of(CosmeticSlot.HELMET, CosmeticSlot.CHESTPLATE, CosmeticSlot.LEGGINGS, CosmeticSlot.BOOTS, CosmeticSlot.MAINHAND, CosmeticSlot.OFFHAND);
|
||||
|
||||
public static void sendEntitySpawnPacket(
|
||||
final @NotNull Location location,
|
||||
final int entityId,
|
||||
@@ -44,16 +46,7 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final UUID uuid,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getUUIDs().write(0, uuid);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getEntityTypeModifier().write(0, entityType);
|
||||
packet.getDoubles().
|
||||
write(0, location.getX()).
|
||||
write(1, location.getY()).
|
||||
write(2, location.getZ());
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendSpawnEntityPacket(entityId, uuid, entityType, location, sendTo);
|
||||
}
|
||||
|
||||
public static void equipmentSlotUpdate(
|
||||
@@ -91,56 +84,59 @@ public class HMCCPacketManager extends PacketManager {
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
if (cosmeticSlot == CosmeticSlot.BACKPACK || cosmeticSlot == CosmeticSlot.CUSTOM || cosmeticSlot == CosmeticSlot.BALLOON || cosmeticSlot == CosmeticSlot.EMOTE) return;
|
||||
|
||||
if (!EQUIPMENT_SLOTS.contains(cosmeticSlot)) return;
|
||||
equipmentSlotUpdate(entityId, HMCCInventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
|
||||
}
|
||||
|
||||
public static void sendArmorstandMetadata(
|
||||
int entityId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entityId);
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
|
||||
// 0x21 = Invisible + Fire (Aka, burns to make it not take the light of the block its in, avoiding turning it black)
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x21));
|
||||
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
public static void sendInvisibilityPacket(
|
||||
int entityId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entityId);
|
||||
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, Map.of(0, (byte) 0x20), sendTo);
|
||||
}
|
||||
|
||||
public static void sendCloudEffect(
|
||||
public static void spawnCloudAndHandleEffect(
|
||||
int entityId,
|
||||
Location location,
|
||||
UUID uuid,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
NMSHandlers.getHandler().getPacketHandler().sendInvisibleParticleCloud(entityId, location, uuid, sendTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* This handles both spawn + metadata in a bundle packet
|
||||
* @param entityId
|
||||
* @param location
|
||||
* @param uuid
|
||||
* @param sendTo
|
||||
*/
|
||||
public static void spawnInvisibleArmorstand(
|
||||
int entityId,
|
||||
Location location,
|
||||
UUID uuid,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
byte mask = getMask();
|
||||
NMSHandlers.getHandler().getPacketHandler().sendInvisibleArmorstand(entityId, location, uuid, mask, sendTo);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just a normal meta data packet (non-bundled)
|
||||
* @param entityId
|
||||
* @param sendTo
|
||||
*/
|
||||
public static void sendArmorstandMetadata(
|
||||
int entityId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entityId);
|
||||
byte mask = getMask();
|
||||
Map<Integer, Number> dataValues = Map.of(0, mask, 15, (byte) 0x10);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(entityId, dataValues, sendTo);
|
||||
}
|
||||
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||
wrappedDataValueList.add(new WrappedDataValue(8, WrappedDataWatcher.Registry.get(Float.class), 0f));
|
||||
//wrappedDataValueList.add(new WrappedDataValue(11, WrappedDataWatcher.Registry.get(Integer.class), 21));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
private static byte getMask() {
|
||||
return (byte) (Settings.isBackpackPreventDarkness() ? 0x21 : 0x20);
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
@@ -157,17 +153,7 @@ public class HMCCPacketManager extends PacketManager {
|
||||
boolean onGround,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
float yaw = location.getYaw() * ROTATION_FACTOR;
|
||||
float pitch = location.getPitch() * ROTATION_FACTOR;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) yaw);
|
||||
packet.getBytes().write(1, (byte) pitch);
|
||||
|
||||
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||
packet.getBooleans().write(0, onGround);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, location.getYaw(), location.getPitch(), onGround, sendTo);
|
||||
}
|
||||
|
||||
public static void sendRotationPacket(
|
||||
@@ -176,19 +162,9 @@ public class HMCCPacketManager extends PacketManager {
|
||||
boolean onGround,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
float ROTATION_FACTOR = 256.0F / 360.0F;
|
||||
float yaw2 = yaw * ROTATION_FACTOR;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getBytes().write(0, (byte) yaw2);
|
||||
packet.getBytes().write(1, (byte) 0);
|
||||
|
||||
//Bukkit.getLogger().info("DEBUG: Yaw: " + (location.getYaw() * ROTATION_FACTOR) + " | Original Yaw: " + location.getYaw());
|
||||
packet.getBooleans().write(0, onGround);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendRotationPacket(entityId, yaw, 0, onGround, sendTo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mostly to deal with backpacks, this deals with entities riding other entities.
|
||||
* @param mountId The entity that is the "mount", ex. a player
|
||||
@@ -213,12 +189,7 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final int[] passengerIds,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
packet.getIntegers().write(0, mountId);
|
||||
packet.getIntegerArrays().write(0, passengerIds);
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, packet);
|
||||
}
|
||||
NMSHandlers.getHandler().getPacketHandler().sendMountPacket(mountId, passengerIds, sendTo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,32 +206,6 @@ public class HMCCPacketManager extends PacketManager {
|
||||
sendRidingPacket(mountId, new int[] {passengerId}, sendTo);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param location Location of the fake player.
|
||||
* @param uuid UUID of the fake player. Should be random.
|
||||
* @param entityId The entityID that the entity will take on.
|
||||
* @param sendTo Who should it send the packet to?
|
||||
*/
|
||||
public static void sendFakePlayerSpawnPacket(
|
||||
final @NotNull Location location,
|
||||
final UUID uuid,
|
||||
final int entityId,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
if (HMCCosmeticsAPI.getNMSVersion().contains("v1_19_R3") || HMCCosmeticsAPI.getNMSVersion().contains("v1_20_R1")) {
|
||||
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setPlayerUUID(uuid);
|
||||
wrapper.setPosition(location.toVector());
|
||||
wrapper.setPitch(location.getPitch());
|
||||
wrapper.setYaw(location.getYaw());
|
||||
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
|
||||
return;
|
||||
}
|
||||
sendEntitySpawnPacket(location, entityId, EntityType.PLAYER, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fake player entity.
|
||||
* @param skinnedPlayer The original player it bases itself off of.
|
||||
@@ -271,28 +216,10 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final Player skinnedPlayer,
|
||||
final int entityId,
|
||||
final UUID uuid,
|
||||
final String NPCName,
|
||||
final String npcName,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();
|
||||
info.setAction(EnumWrappers.PlayerInfoAction.ADD_PLAYER);
|
||||
|
||||
String name = NPCName;
|
||||
while (name.length() > 16) {
|
||||
name = name.substring(16);
|
||||
}
|
||||
|
||||
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
||||
WrappedSignedProperty skinData = HMCCPlayerUtils.getSkin(skinnedPlayer);
|
||||
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
||||
|
||||
info.getHandle().getPlayerInfoDataLists().write(1, Collections.singletonList(new PlayerInfoData(
|
||||
wrappedGameProfile,
|
||||
0,
|
||||
EnumWrappers.NativeGameMode.CREATIVE,
|
||||
WrappedChatComponent.fromText(name)
|
||||
)));
|
||||
for (final Player p : sendTo) sendPacket(p, info.getHandle());
|
||||
NMSHandlers.getHandler().getPacketHandler().sendFakePlayerInfoPacket(skinnedPlayer, entityId, uuid, npcName, sendTo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,27 +231,10 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final int playerId,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
/*
|
||||
0x01 = Is on fire
|
||||
0x02 = Is courching
|
||||
0x04 = Unusued
|
||||
0x08 = Sprinting
|
||||
0x10 = Is swimming
|
||||
0x20 = Invisibile
|
||||
0x40 = Is Glowing
|
||||
0x80 = Is flying with an elytra
|
||||
https://wiki.vg/Entity_metadata#Entity
|
||||
*/
|
||||
// https://minecraft.wiki/w/Java_Edition_protocol/Entity_metadata#Avatar
|
||||
final byte mask = 0x01 | 0x02 | 0x04 | 0x08 | 0x010 | 0x020 | 0x40;
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, playerId);
|
||||
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataValueList.add(new WrappedDataValue(17, WrappedDataWatcher.Registry.get(Byte.class), mask));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
if (NMSHandlers.getVersion().isLowerOrEqual(MinecraftVersion.v1_21_8)) NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(playerId, Map.of(17, mask), sendTo);
|
||||
else NMSHandlers.getHandler().getPacketHandler().sendSharedEntityData(playerId, Map.of(16, mask), sendTo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,9 +249,7 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final UUID uuid,
|
||||
final List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
|
||||
packet.getUUIDLists().write(0, List.of(uuid));
|
||||
for (final Player p : sendTo) sendPacket(p, packet);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendPlayerInfoRemovePacket(uuid, sendTo);
|
||||
}
|
||||
|
||||
public static void sendLeashPacket(
|
||||
@@ -367,31 +275,60 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final boolean onGround,
|
||||
@NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE);
|
||||
WrapperPlayServerRelEntityMove wrapper = new WrapperPlayServerRelEntityMove(packet);
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setDx(to.getX() - from.getX());
|
||||
wrapper.setDy(to.getY() - from.getY());
|
||||
wrapper.setDz(to.getZ() - from.getZ());
|
||||
wrapper.setOnGround(onGround);
|
||||
for (final Player p : sendTo) {
|
||||
sendPacket(p, wrapper.getHandle());
|
||||
}
|
||||
NMSHandlers.getHandler().getPacketHandler().sendMovePacket(entityId, from, to, onGround, sendTo);
|
||||
}
|
||||
|
||||
public static void sendEntityScalePacket(
|
||||
int entityId,
|
||||
double scale,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
NMSHandlers.getHandler().getPacketHandler().sendEntityScalePacket(entityId, scale, sendTo);
|
||||
}
|
||||
|
||||
// For future transition to display entities
|
||||
public static void sendDisplayEntityMetadataPacket(
|
||||
int entityid,
|
||||
ItemStack backpackItem,
|
||||
List<Player> sendTo) {
|
||||
// TODO: Make the default values adjustable
|
||||
Vector3f translation = new Vector3f(0, 3, 0);
|
||||
Vector3f scale = new Vector3f(1, 1, 1);
|
||||
Quaternionf rotationLeft = new Quaternionf();
|
||||
Quaternionf rotationRight = new Quaternionf();
|
||||
Display.Billboard billboard = Display.Billboard.FIXED;
|
||||
int blockLight = 15;
|
||||
int skylight = 15;
|
||||
int viewRange = Settings.getViewDistance();
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
ItemDisplay.ItemDisplayTransform transform = ItemDisplay.ItemDisplayTransform.HEAD;
|
||||
|
||||
NMSHandlers.getHandler().getPacketHandler().sendItemDisplayMetadata(
|
||||
entityid,
|
||||
translation,
|
||||
scale,
|
||||
rotationLeft,
|
||||
rotationRight,
|
||||
billboard,
|
||||
blockLight,
|
||||
skylight,
|
||||
viewRange,
|
||||
width,
|
||||
height,
|
||||
transform,
|
||||
backpackItem,
|
||||
sendTo
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nearby players (or viewers) of a location through the view distance set in the config. If the view distance is 0, it will return all players in the world.
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
public static List<Player> getViewers(Location location) {
|
||||
ArrayList<Player> viewers = new ArrayList<>();
|
||||
if (Settings.getViewDistance() <= 0) {
|
||||
viewers.addAll(location.getWorld().getPlayers());
|
||||
} else {
|
||||
viewers.addAll(HMCCPlayerUtils.getNearbyPlayers(location));
|
||||
}
|
||||
return viewers;
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
if (player == null) return;
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
|
||||
public static List<Player> getViewers(@NotNull Location location) {
|
||||
return PacketManager.getViewers(location, Settings.getViewDistance());
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user