mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-24 17:39:18 +00:00
Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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.7.6${getGitCommitHash()}"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
@@ -18,7 +18,7 @@ allprojects {
|
||||
mavenCentral()
|
||||
|
||||
// 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
|
||||
@@ -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,31 +75,42 @@ 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.20.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("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.6.0-85d65299")
|
||||
|
||||
// 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")
|
||||
compileOnly("net.kyori:adventure-api:4.19.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.19.0")
|
||||
compileOnly("net.kyori:adventure-platform-bukkit:4.3.4")
|
||||
|
||||
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.1.12-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:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -120,7 +134,7 @@ tasks {
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("1.21.1")
|
||||
minecraftVersion("1.21.4")
|
||||
|
||||
downloadPlugins {
|
||||
hangar("PlaceholderAPI", "2.11.6")
|
||||
@@ -162,7 +176,7 @@ bukkit {
|
||||
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")
|
||||
softDepend = listOf("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 +274,10 @@ bukkit {
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21
|
||||
))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
fun getGitCommitHash(): String {
|
||||
|
||||
@@ -4,8 +4,10 @@ plugins {
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21
|
||||
))
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.hibiscusmc.hmccosmetics.emotes.EmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
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;
|
||||
@@ -52,6 +53,7 @@ public final class HMCCosmeticsPlugin extends HibiscusPlugin {
|
||||
public HMCCosmeticsPlugin() {
|
||||
super(13873, 1879);
|
||||
new HookHMCCosmetics();
|
||||
new HookBetterHud();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,116 +2,213 @@ 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.NMSHandlers;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
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;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
public static @NotNull Map<String, CosmeticSlot> getAllCosmeticSlots() {
|
||||
return Map.copyOf(CosmeticSlot.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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() {
|
||||
return NMSHandlers.getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the HMCCosmetics version.
|
||||
* @return The HMCCosmetics version in String format
|
||||
* Retrieves the version of HMCCosmetics currently in use.
|
||||
*
|
||||
* @return the HMCCosmetics version in string format
|
||||
*/
|
||||
@NotNull
|
||||
public static String getHMCCVersion() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,22 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -6,23 +6,27 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player starts playing an emote
|
||||
* 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 static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final String animationId;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
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
|
||||
* Gets the animation id of the emote the player started playing.
|
||||
*
|
||||
* @return The animation id of the emote which the player started playing
|
||||
* @implNote The returned string of this method may be an invalid animation id.
|
||||
* Make sure to validate it before use by calling {@link com.hibiscusmc.hmccosmetics.emotes.EmoteManager#get(String)}.
|
||||
*
|
||||
* @return the animation id of the emote which the player started playing
|
||||
*/
|
||||
@NotNull
|
||||
public String getAnimationId() {
|
||||
@@ -34,28 +38,17 @@ public class PlayerEmoteStartEvent extends PlayerCosmeticEvent implements Cancel
|
||||
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;
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,15 @@ import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Called when a player stops playing an emote
|
||||
* 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 static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final UserEmoteManager.StopEmoteReason reason;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
public PlayerEmoteStopEvent(@NotNull CosmeticUser who, @NotNull UserEmoteManager.StopEmoteReason reason) {
|
||||
super(who);
|
||||
this.reason = reason;
|
||||
@@ -25,20 +27,19 @@ public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancell
|
||||
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||
* @deprecated As of release 2.2.5+, replaced by {@link #getReason()}
|
||||
*/
|
||||
@Deprecated
|
||||
@Deprecated(forRemoval = true)
|
||||
@NotNull
|
||||
public UserEmoteManager.StopEmoteReason getStopEmoteReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing
|
||||
* Gets the {@link UserEmoteManager.StopEmoteReason} as to why the emote has stopped playing.
|
||||
*
|
||||
* @return The {@link UserEmoteManager.StopEmoteReason} why the emote has stopped playing
|
||||
* @return the reason why the emote has stopped playing
|
||||
* @since 2.2.5
|
||||
*/
|
||||
@NotNull
|
||||
public UserEmoteManager.StopEmoteReason getReason() {
|
||||
public @NotNull UserEmoteManager.StopEmoteReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@@ -47,28 +48,17 @@ public class PlayerEmoteStopEvent extends PlayerCosmeticEvent implements Cancell
|
||||
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;
|
||||
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,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,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ 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);
|
||||
|
||||
@@ -187,11 +187,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 +204,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 +244,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,11 +307,12 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, args[1])) {
|
||||
String rawSlot = args[1];
|
||||
if (!CosmeticSlot.contains(rawSlot)) {
|
||||
if (!silent) MessagesUtil.sendMessage(player, "invalid-slot");
|
||||
return true;
|
||||
}
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(args[1]);
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(rawSlot);
|
||||
Cosmetic cosmetic = user.getCosmetic(slot);
|
||||
|
||||
if (args.length >= 3) {
|
||||
@@ -377,6 +379,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") -> {
|
||||
|
||||
@@ -94,7 +94,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
|
||||
}
|
||||
case "dye" -> {
|
||||
for (CosmeticSlot slot : user.getDyeableSlots()) {
|
||||
completions.add(slot.name());
|
||||
completions.add(slot.toString());
|
||||
}
|
||||
}
|
||||
case "setwardrobesetting" -> {
|
||||
@@ -123,6 +123,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 +136,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);
|
||||
}
|
||||
|
||||
@@ -72,6 +72,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;
|
||||
@@ -121,6 +124,8 @@ public class Settings {
|
||||
@Getter
|
||||
private static boolean balloonHeadForward;
|
||||
@Getter
|
||||
private static boolean backpackPreventDarkness;
|
||||
@Getter
|
||||
private static List<String> disabledGamemodes;
|
||||
@Getter
|
||||
private static List<String> disabledWorlds;
|
||||
@@ -166,6 +171,8 @@ public class Settings {
|
||||
private static boolean emoteMoveCheck;
|
||||
@Getter @Setter
|
||||
private static boolean allPlayersHidden;
|
||||
@Getter
|
||||
private static boolean wardrobeHideHud;
|
||||
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
@@ -228,6 +235,7 @@ public class Settings {
|
||||
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);
|
||||
|
||||
@@ -267,6 +275,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.hibiscusmc.hmccosmetics.cosmetic;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.*;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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.MAINHAND, CosmeticMainhandType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.BACKPACK, CosmeticBackpackType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.BALLOON, CosmeticBalloonType::new),
|
||||
|
||||
Map.entry(CosmeticSlot.EMOTE, CosmeticEmoteType::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,82 @@
|
||||
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");
|
||||
public static final CosmeticSlot EMOTE = register("EMOTE");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ import java.util.logging.Level;
|
||||
|
||||
public class CosmeticBackpackType extends Cosmetic {
|
||||
|
||||
@Getter
|
||||
private final String modelName;
|
||||
@Getter
|
||||
private int height = -1;
|
||||
private ItemStack firstPersonBackpack;
|
||||
@@ -33,8 +31,6 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
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);
|
||||
|
||||
@@ -18,6 +18,6 @@ public class CosmeticMainhandType extends Cosmetic {
|
||||
public void update(@NotNull CosmeticUser user) {
|
||||
Player player = user.getPlayer();
|
||||
|
||||
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPlayerUtils.getNearbyPlayers(player));
|
||||
HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -11,6 +12,8 @@ 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.components.InventoryProvider;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import lombok.Getter;
|
||||
@@ -24,6 +27,7 @@ import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -141,7 +145,9 @@ public class Menu {
|
||||
final Component component = AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title));
|
||||
Gui gui = Gui.gui()
|
||||
.title(component)
|
||||
.type(GuiType.CHEST)
|
||||
.rows(this.rows)
|
||||
.inventory((title, owner, rows) -> Bukkit.createInventory(owner, rows, title))
|
||||
.create();
|
||||
|
||||
gui.setDefaultClickAction(event -> event.setCancelled(true));
|
||||
@@ -164,6 +170,9 @@ public class Menu {
|
||||
});
|
||||
|
||||
gui.setCloseGuiAction(event -> {
|
||||
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());
|
||||
});
|
||||
|
||||
|
||||
@@ -3,12 +3,15 @@ package com.hibiscusmc.hmccosmetics.gui;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
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 +25,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 +44,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() {
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ActionUnequip extends Action {
|
||||
|
||||
@Override
|
||||
public void run(CosmeticUser user, String raw) {
|
||||
if (!EnumUtils.isValidEnum(CosmeticSlot.class, raw)) return;
|
||||
if (!CosmeticSlot.contains(raw)) return;
|
||||
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(raw);
|
||||
user.removeCosmeticSlot(slot);
|
||||
|
||||
@@ -15,8 +15,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DyeMenu {
|
||||
|
||||
@@ -27,7 +26,7 @@ public class DyeMenu {
|
||||
addCosmetic(user, cosmetic, null);
|
||||
return;
|
||||
}
|
||||
ItemStack originalItem = user.getUserCosmeticItem(cosmetic);
|
||||
ItemStack originalItem = cosmetic.getItem();
|
||||
if (originalItem == null || !cosmetic.isDyable()) return;
|
||||
|
||||
Gui gui = HMCColorApi.createColorMenu(player);
|
||||
@@ -65,7 +64,7 @@ public class DyeMenu {
|
||||
gui.open(player);
|
||||
}
|
||||
|
||||
private static void addCosmetic(@NotNull CosmeticUser user, Cosmetic cosmetic, Color color) {
|
||||
private static void addCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) {
|
||||
Player player = user.getPlayer();
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
player.setItemOnCursor(new ItemStack(Material.AIR));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,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 +151,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;
|
||||
|
||||
@@ -46,7 +46,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);
|
||||
user.enterWardrobe(wardrobe, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,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);
|
||||
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,10 +1,11 @@
|
||||
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.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;
|
||||
@@ -40,19 +41,37 @@ public class PlayerConnectionListener implements Listener {
|
||||
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;
|
||||
|
||||
PlayerPreLoadEvent preLoadEvent = new PlayerPreLoadEvent(uuid);
|
||||
Bukkit.getPluginManager().callEvent(preLoadEvent);
|
||||
if (preLoadEvent.isCancelled()) return;
|
||||
|
||||
Database.get(uuid).thenAccept(userData -> {
|
||||
if (userData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
CosmeticUser cosmeticUser = new CosmeticUser(uuid, data);
|
||||
CosmeticUser cosmeticUser = CosmeticUsers.getProvider()
|
||||
.createCosmeticUser(uuid)
|
||||
.initialize(userData);
|
||||
cosmeticUser.startTicking();
|
||||
|
||||
CosmeticUsers.addUser(cosmeticUser);
|
||||
MessagesUtil.sendDebugMessages("Run User Join for " + uuid);
|
||||
|
||||
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 " + uuid + ". Exception: " + ex.getMessage());
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -68,6 +87,10 @@ public class PlayerConnectionListener implements Listener {
|
||||
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return; // Player never initialized, don't do anything
|
||||
|
||||
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
|
||||
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe(true);
|
||||
user.getPlayer().setInvisible(false);
|
||||
|
||||
@@ -2,10 +2,7 @@ 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.events.*;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
@@ -19,7 +16,6 @@ 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;
|
||||
@@ -29,9 +25,6 @@ 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,8 +47,6 @@ 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.*;
|
||||
|
||||
@@ -70,10 +61,6 @@ public class PlayerGameListener implements Listener {
|
||||
registerEntityUseListener();
|
||||
registerSlotChangeListener();
|
||||
registerPassengerSetListener();
|
||||
|
||||
//registerLookMovement();
|
||||
//registerMoveListener();
|
||||
//registerTeleportMovement();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
@@ -115,7 +102,7 @@ public class PlayerGameListener implements Listener {
|
||||
if (!event.isSneaking()) return;
|
||||
if (!user.isInWardrobe()) return;
|
||||
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
@@ -129,7 +116,7 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
|
||||
if (user.isInWardrobe()) {
|
||||
user.leaveWardrobe();
|
||||
user.leaveWardrobe(false);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
@@ -206,7 +193,7 @@ public class PlayerGameListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe();
|
||||
if (WardrobeSettings.isDamagedKicked()) user.leaveWardrobe(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +336,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();
|
||||
@@ -465,7 +452,7 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
|
||||
private void registerInventoryClickListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, List.of(PacketType.Play.Client.WINDOW_CLICK), ListenerOptions.ASYNC) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@@ -491,7 +478,7 @@ public class PlayerGameListener implements Listener {
|
||||
}
|
||||
|
||||
private void registerMenuChangeListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.WINDOW_ITEMS) {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, List.of(PacketType.Play.Server.WINDOW_ITEMS), ListenerOptions.ASYNC) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
MessagesUtil.sendDebugMessages("Menu Initial ");
|
||||
@@ -525,7 +512,7 @@ public class PlayerGameListener implements Listener {
|
||||
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));
|
||||
if (Settings.isDebugMode()) MessagesUtil.sendDebugMessages("Set " + slot + " as " + items.get(slot));
|
||||
}
|
||||
}
|
||||
packet.getItemListModifier().write(0, slotData);
|
||||
@@ -708,58 +695,6 @@ public class PlayerGameListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
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()) {
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -15,27 +16,23 @@ public class ServerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onHookReload(HibiscusHookReload event) {
|
||||
Hook hook = event.getHook();
|
||||
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.MONITOR, ignoreCancelled = true)
|
||||
public void onAllHooksReady(HibiscusHooksAllActiveEvent event) {
|
||||
HMCCosmeticsPlugin.setup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ 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;
|
||||
@@ -46,10 +45,9 @@ import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CosmeticUser {
|
||||
|
||||
@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;
|
||||
@@ -61,91 +59,154 @@ public class CosmeticUser {
|
||||
// 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;
|
||||
this.userEmoteManager = new UserEmoteManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.addPlayerCosmetic(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.addPlayerCosmetic(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(getEntity().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 (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() && !getUserEmoteManager().isPlayingEmote() && !getCosmetics().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) {
|
||||
return playerCosmetics.get(slot);
|
||||
}
|
||||
@@ -192,12 +253,11 @@ public class CosmeticUser {
|
||||
|
||||
public void removeCosmetics() {
|
||||
// Small optimization could be made, but Concurrent modification prevents us from both getting and removing
|
||||
for (CosmeticSlot slot : CosmeticSlot.values()) {
|
||||
for (CosmeticSlot slot : CosmeticSlot.values().values()) {
|
||||
removeCosmeticSlot(slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeCosmeticSlot(CosmeticSlot slot) {
|
||||
// API
|
||||
PlayerCosmeticRemoveEvent event = new PlayerCosmeticRemoveEvent(this, getCosmetic(slot));
|
||||
@@ -220,7 +280,6 @@ public class CosmeticUser {
|
||||
removeArmor(slot);
|
||||
}
|
||||
|
||||
|
||||
public void removeCosmeticSlot(Cosmetic cosmetic) {
|
||||
removeCosmeticSlot(cosmetic.getSlot());
|
||||
}
|
||||
@@ -270,7 +329,7 @@ public class CosmeticUser {
|
||||
}
|
||||
}
|
||||
if (items.isEmpty() || getEntity() == null) return;
|
||||
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), items, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()));
|
||||
PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), items, HMCCPacketManager.getViewers(getEntity().getLocation()));
|
||||
MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size());
|
||||
}
|
||||
|
||||
@@ -386,7 +445,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 +486,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 +528,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 +599,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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +710,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 +753,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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,20 +90,6 @@ public class UserBackpackManager {
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class UserEntity {
|
||||
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);
|
||||
List<Player> players = HMCCPacketManager.getViewers(location);
|
||||
Player ownerPlayer = Bukkit.getPlayer(owner);
|
||||
if (ownerPlayer == null) {
|
||||
MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list");
|
||||
|
||||
@@ -64,6 +64,7 @@ public class UserWardrobeManager {
|
||||
private BossBar bossBar;
|
||||
@Getter
|
||||
private boolean active;
|
||||
@Setter
|
||||
@Getter
|
||||
private WardrobeStatus wardrobeStatus;
|
||||
@Getter
|
||||
@@ -108,14 +109,19 @@ 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);
|
||||
|
||||
// Player
|
||||
user.getPlayer().teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
user.getPlayer().setInvisible(true);
|
||||
player.teleport(viewingLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
player.setInvisible(true);
|
||||
HMCCPacketManager.gamemodeChangePacket(player, 3);
|
||||
HMCCPacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
|
||||
|
||||
@@ -284,7 +290,7 @@ public class UserWardrobeManager {
|
||||
run.run();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
private void update() {
|
||||
final AtomicInteger data = new AtomicInteger();
|
||||
|
||||
BukkitRunnable runnable = new BukkitRunnable() {
|
||||
@@ -313,7 +319,7 @@ public class UserWardrobeManager {
|
||||
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 +352,6 @@ public class UserWardrobeManager {
|
||||
runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2);
|
||||
}
|
||||
|
||||
public void setWardrobeStatus(WardrobeStatus status) {
|
||||
this.wardrobeStatus = status;
|
||||
}
|
||||
|
||||
public enum WardrobeStatus {
|
||||
SETUP,
|
||||
STARTING,
|
||||
|
||||
@@ -12,10 +12,22 @@ 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 {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -132,29 +144,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;
|
||||
}
|
||||
}
|
||||
return SLOT_MAP.get(slot);
|
||||
}
|
||||
|
||||
public static EquipmentSlot getEquipmentSlot(@NotNull EnumWrappers.ItemSlot slot) {
|
||||
|
||||
@@ -24,12 +24,24 @@ public class HMCCPlayerUtils {
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -157,13 +157,4 @@ public class HMCCServerUtils {
|
||||
}
|
||||
return nextYaw;
|
||||
}
|
||||
|
||||
public static boolean hasClass(String className) {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch (ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import java.util.*;
|
||||
|
||||
public class HMCCPacketManager extends PacketManager {
|
||||
|
||||
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,
|
||||
@@ -91,8 +93,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -106,7 +107,9 @@ public class HMCCPacketManager extends PacketManager {
|
||||
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));
|
||||
byte mask = 0x20;
|
||||
if (Settings.isBackpackPreventDarkness()) mask = 0x21;
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), mask));
|
||||
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
@@ -379,13 +382,18 @@ public class HMCCPacketManager extends PacketManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
public static List<Player> getViewers(@NotNull Location location) {
|
||||
ArrayList<Player> viewers = new ArrayList<>();
|
||||
if (Settings.getViewDistance() <= 0) {
|
||||
viewers.addAll(location.getWorld().getPlayers());
|
||||
} else {
|
||||
viewers.addAll(HMCCPlayerUtils.getNearbyPlayers(location));
|
||||
viewers.addAll(PacketManager.getViewers(location, Settings.getViewDistance()));
|
||||
}
|
||||
return viewers;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ cosmetic-settings:
|
||||
emote-move: false
|
||||
# This make it so it always sends the riding packets for the backpack. This sends more packets but is more reliable for servers which modify player passengers.
|
||||
backpack-force-riding-packet: false
|
||||
# This prevents the backpack from being dark when the player is below a block at the expense of making the backpack bright
|
||||
backpack-prevent-darkness: true
|
||||
# This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable.
|
||||
# This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located.
|
||||
entity-cooldown-teleport-packet: 500
|
||||
@@ -103,13 +105,13 @@ menu-settings:
|
||||
shading:
|
||||
# Below is the shading mechanism behind cosmetic items. This is a bit complicated, but it allows for a lot of customization.
|
||||
# The shading is done through the title and by shifting textures around. This is done by offsets.
|
||||
# Only Oraxen is support by default. Vanilla can't properly handle it without a lot of unicodes and ItemsAdder adds weird offsets and decolors it. (This is why it is disabled by default)
|
||||
# Only Nexo is support by default. Vanilla can't properly handle it without a lot of unicodes and ItemsAdder adds weird offsets and decolors it. (This is why it is disabled by default)
|
||||
enabled: false # Default of menus having shading. This can be toggled individually in menus with "shading: true/false"
|
||||
first-row-shift: "<s:-169>" # Oraxen: "<s:-169>"
|
||||
sequent-row-shift: " <s:-169>" # Oraxen: " <s:-169>" (Space is important here!)
|
||||
individual-column-shift: "<s:-3>" # Oraxen: "<s:-3>"
|
||||
background: "<g:shade_row_<row>:colorable> " # Oraxen: "<g:shade_row_<row>:colorable>
|
||||
clear-background: "<g:clear_row_<row>:colorable> " # Oraxen: "<g:clear_row_<row>:colorable> "
|
||||
first-row-shift: "<shift:-169>" # Nexo: "<shift:-169>"
|
||||
sequent-row-shift: " <shift:-169>" # Nexo: " <shift:-169>" (Space is important here!)
|
||||
individual-column-shift: "<shift:-3>" # Nexo: "<shift:-3>"
|
||||
background: "<glyph:shade_row_<row>:colorable> " # Nexo: "<glyph:shade_row_<row>:colorable>
|
||||
clear-background: "<glyph:clear_row_<row>:colorable> " # Nexo: "<glyph:clear_row_<row>:colorable> "
|
||||
#These use MiniMessage for color! https://docs.advntr.dev/minimessage/format.html#color
|
||||
equipped-cosmetic-color: "<yellow>"
|
||||
equipable-cosmetic-color: "<green>"
|
||||
@@ -121,6 +123,7 @@ menu-settings:
|
||||
dye-menu:
|
||||
# If you use ItemsAdder, set this to "<white>:img_offset_-8::img_dye_menu:"
|
||||
# If you use Oraxen, set this to "<white><s:-8><g:dye_menu>"
|
||||
# If you use Nexo, set this to "<white><shift:-8><glyph:dye_menu>"
|
||||
title: "<white>"
|
||||
input-slot: 10
|
||||
output-slot: 16
|
||||
@@ -136,6 +139,8 @@ hook-settings:
|
||||
# Checks worldguard regions for HMCC flags. If set to false, flags will not work properly.
|
||||
# Requires restart to apply changes.
|
||||
player-move-check: true
|
||||
betterhud:
|
||||
wardrobe-hide: true
|
||||
wardrobe:
|
||||
# how much yaw should change per tick, set to 0 for none
|
||||
rotation-speed: 3
|
||||
@@ -168,6 +173,7 @@ wardrobe:
|
||||
enabled: true
|
||||
# If you use ItemsAdder, set this to "<black>%img_title%
|
||||
# If you use Oraxen, set this to "<black><glyph:title>"
|
||||
# If you use Nexo, set this to "<black>%nexo_title%" and use PlaceholderAPI
|
||||
text: "<black>"
|
||||
delay: 40
|
||||
title-fade-in: 1000 # milliseconds
|
||||
|
||||
@@ -19,6 +19,7 @@ set-wardrobe-viewing: "%prefix% <gradient:#6D9DC5:#45CDE9>Set new wardrobe viewi
|
||||
set-wardrobe-leaving: "%prefix% <gradient:#6D9DC5:#45CDE9>Set new wardrobe leaving location!"
|
||||
set-wardrobe-permission: "%prefix% <gradient:#6D9DC5:#45CDE9>Set new wardrobe permission!"
|
||||
set-wardrobe-distance: "%prefix% <gradient:#6D9DC5:#45CDE9>Set new wardrobe distance!"
|
||||
set-wardrobe-menu: "%prefix% <gradient:#6D9DC5:#45CDE9>Set new wardrobe menu!"
|
||||
no-wardrobes: "%prefix% <red>There are no wardrobes with that name!"
|
||||
wardrobe-not-setup: "%prefix% <red>This wardrobe does not have all required locations set!"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user