mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-23 17:09:24 +00:00
Compare commits
75 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f98614c4ee | ||
|
|
d28bb23f8c | ||
|
|
502cb533f8 | ||
|
|
b7fdc2087a | ||
|
|
10a42a3c96 | ||
|
|
51fc52e24b | ||
|
|
be632d8e8c | ||
|
|
a732a2b0a0 | ||
|
|
b14a0b5d16 | ||
|
|
50393c62b0 | ||
|
|
dbc4a07895 | ||
|
|
ab329e4fbf | ||
|
|
90ad700d0a | ||
|
|
56529d6111 | ||
|
|
b6a06007e8 | ||
|
|
edccc9ce4e | ||
|
|
e0b2f0f6b1 | ||
|
|
57f4d3703c | ||
|
|
8ef6692198 | ||
|
|
c48830f3ac | ||
|
|
734c04c1f4 | ||
|
|
b08b4019a9 | ||
|
|
cfb7876b6e | ||
|
|
6047d0e3c3 | ||
|
|
880c333df9 | ||
|
|
c4d7b657dd | ||
|
|
5be3ce8d21 | ||
|
|
33bba631fc | ||
|
|
775b9c299d | ||
|
|
6e02331c13 | ||
|
|
b7457cec9c | ||
|
|
e7288a1910 | ||
|
|
26b90bd8bb | ||
|
|
24a10b6838 | ||
|
|
af7bc0dc3f | ||
|
|
162d4a6ed6 | ||
|
|
41140f60c5 | ||
|
|
a6145a607c | ||
|
|
89c6951a93 | ||
|
|
28c466e342 | ||
|
|
90caa23cd7 | ||
|
|
910f223151 | ||
|
|
ac1b50a957 | ||
|
|
9cb9bad3c8 | ||
|
|
f68e2633a2 | ||
|
|
c8ad5c0881 | ||
|
|
c93a718799 | ||
|
|
b5f781e00f | ||
|
|
f6cd73f436 | ||
|
|
8b0fcc5da9 | ||
|
|
b5787f22bf | ||
|
|
c1c431d914 | ||
|
|
b41dc66508 | ||
|
|
cfbf74257b | ||
|
|
9b2083b90a | ||
|
|
33437cd387 | ||
|
|
9f4e4616d4 | ||
|
|
01c62bc94e | ||
|
|
3be4bdeb6f | ||
|
|
145aec9b7f | ||
|
|
4a2266bbfa | ||
|
|
7fa3cd6cb7 | ||
|
|
9c5fe9c426 | ||
|
|
0a9d750d3e | ||
|
|
da996fb146 | ||
|
|
c051b267cf | ||
|
|
d1fc84b5bc | ||
|
|
b47b9d8235 | ||
|
|
edccc844c9 | ||
|
|
5788b2cce0 | ||
|
|
006319a757 | ||
|
|
a8ff8e6a7a | ||
|
|
8b20207442 | ||
|
|
8bbe12ed84 | ||
|
|
d23f3e19d2 |
@@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.hibiscusmc"
|
||||
version = "2.6.0"
|
||||
version = "2.6.5"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
@@ -32,9 +32,6 @@ allprojects {
|
||||
// PlaceholderAPI
|
||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||
|
||||
//Hikari
|
||||
maven("https://mvnrepository.com/artifact/com.zaxxer/HikariCP")
|
||||
|
||||
// Citizens & Denizen
|
||||
maven("https://maven.citizensnpcs.co/repo")
|
||||
|
||||
@@ -63,6 +60,9 @@ allprojects {
|
||||
|
||||
// md-5 Repo
|
||||
maven("https://repo.md-5.net/content/groups/public/")
|
||||
|
||||
// MMOItems
|
||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -70,12 +70,12 @@ allprojects {
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
|
||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
||||
compileOnly("com.ticxo:modelengine:R3.0.1")
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
|
||||
compileOnly("com.github.oraxen:oraxen:1.160.0")
|
||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
||||
compileOnly("com.mineinabyss:geary-papermc:0.24.1")
|
||||
compileOnly("com.mineinabyss:geary-papermc:0.27.0")
|
||||
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
|
||||
compileOnly("it.unimi.dsi:fastutil:8.5.11")
|
||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
|
||||
@@ -94,18 +94,19 @@ dependencies {
|
||||
implementation(project(path = ":v1_19_R2", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_19_R3", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_20_R1", configuration = "reobf"))
|
||||
implementation(project(path = ":v1_20_R2", configuration = "reobf"))
|
||||
|
||||
//compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT")
|
||||
implementation("net.kyori:adventure-api:4.11.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.1.2")
|
||||
implementation("dev.triumphteam:triumph-gui:3.1.3")
|
||||
implementation("org.spongepowered:configurate-yaml:4.1.2")
|
||||
implementation("org.spongepowered:configurate-yaml:4.2.0-SNAPSHOT")
|
||||
implementation("org.bstats:bstats-bukkit:3.0.0")
|
||||
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
|
||||
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
|
||||
implementation("com.github.BG-Software-LLC:CommentedConfiguration:bed3c46369")
|
||||
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ tasks {
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("1.20.1")
|
||||
minecraftVersion("1.20.2")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
@@ -135,6 +136,7 @@ tasks {
|
||||
dependsOn(":v1_19_R2:reobfJar")
|
||||
dependsOn(":v1_19_R3:reobfJar")
|
||||
dependsOn(":v1_20_R1:reobfJar")
|
||||
dependsOn(":v1_20_R2:reobfJar")
|
||||
mergeServiceFiles()
|
||||
|
||||
relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui")
|
||||
@@ -175,7 +177,7 @@ bukkit {
|
||||
apiVersion = "1.18"
|
||||
authors = listOf("LoJoSho")
|
||||
depend = listOf("ProtocolLib")
|
||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen")
|
||||
softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "Geary", "HMCColor", "WorldGuard", "MythicMobs", "PlaceholderAPI", "SuperVanish", "PremiumVanish", "LibsDisguises", "Denizen", "MMOItems")
|
||||
version = "${project.version}"
|
||||
loadBefore = listOf(
|
||||
"Cosmin" // Fixes an issue with Cosmin loading before and taking /cosmetic, when messing with what we do.
|
||||
@@ -184,6 +186,7 @@ bukkit {
|
||||
commands {
|
||||
register("cosmetic") {
|
||||
description = "Base Cosmetic Command"
|
||||
aliases = listOf("hmccosmetics", "cosmetics")
|
||||
}
|
||||
}
|
||||
permissions {
|
||||
|
||||
@@ -7,9 +7,9 @@ dependencies {
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
compileOnly("org.jetbrains:annotations:23.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
|
||||
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
|
||||
compileOnly("me.clip:placeholderapi:2.11.3")
|
||||
compileOnly("com.ticxo:modelengine:R3.0.1")
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.2")
|
||||
compileOnly("com.github.oraxen:oraxen:1.160.0")
|
||||
compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5")
|
||||
compileOnly("com.mineinabyss:geary-papermc:0.24-SNAPSHOT")
|
||||
@@ -19,6 +19,7 @@ dependencies {
|
||||
compileOnly("io.lumine:Mythic-Dist:5.2.1")
|
||||
compileOnly("com.denizenscript:denizen:1.2.7-SNAPSHOT")
|
||||
compileOnly("com.github.LeonMangler:SuperVanish:6.2.17")
|
||||
compileOnly("net.Indyuce:MMOItems-API:6.9.4-SNAPSHOT")
|
||||
compileOnlyApi("LibsDisguises:LibsDisguises:10.0.21") {
|
||||
exclude("org.spigotmc", "spigot")
|
||||
}
|
||||
@@ -33,7 +34,7 @@ dependencies {
|
||||
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
|
||||
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
|
||||
implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.7")
|
||||
implementation("com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT")
|
||||
implementation("com.github.BG-Software-LLC:CommentedConfiguration:bed3c46369")
|
||||
//implementation("com.ticxo.playeranimator:PlayerAnimator:R1.2.5")
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
Metrics metrics = new Metrics(this, pluginId);
|
||||
|
||||
// NMS version check
|
||||
if (!NMSHandlers.getHandler().getSupported()) {
|
||||
if (!NMSHandlers.isVersionSupported()) {
|
||||
getLogger().severe("This version is not supported! Consider switching versions?");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
@@ -98,7 +98,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
if (!emoteFile.exists()) emoteFile.mkdir();
|
||||
|
||||
// Player Animator
|
||||
PlayerAnimatorImpl.initialize(this);
|
||||
if (!NMSHandlers.getVersion().contains("v1_20_R2")) PlayerAnimatorImpl.initialize(this); // PlayerAnimator does not support 1.20.2 yet
|
||||
|
||||
// Configuration Sync
|
||||
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
||||
@@ -106,7 +106,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
final File translationFile = Path.of(getInstance().getDataFolder().getPath(), "translations.yml").toFile();
|
||||
try {
|
||||
CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"),
|
||||
"database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
|
||||
"database-settings", "wardrobe.wardrobes", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
|
||||
CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml"));
|
||||
CommentedConfiguration.loadConfiguration(translationFile).syncWithConfig(translationFile, getInstance().getResource("translations.yml"));
|
||||
} catch (Exception e) {
|
||||
@@ -252,7 +252,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
EmoteManager.loadEmotes();
|
||||
if (Settings.isEmotesEnabled() && !NMSHandlers.getVersion().contains("v1_20_R2")) EmoteManager.loadEmotes(); // PlayerAnimator does not support 1.20.2 yet
|
||||
|
||||
getInstance().getLogger().info("Successfully Enabled HMCCosmetics");
|
||||
getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup");
|
||||
|
||||
@@ -2,6 +2,8 @@ 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;
|
||||
@@ -12,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancel = false;
|
||||
@Getter @Setter
|
||||
private Wardrobe wardrobe;
|
||||
|
||||
public PlayerWardrobeEnterEvent(@NotNull CosmeticUser who, @NotNull Wardrobe wardrobe) {
|
||||
@@ -48,12 +51,4 @@ public class PlayerWardrobeEnterEvent extends PlayerCosmeticEvent implements Can
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public void setWardrobe(Wardrobe wardrobe) {
|
||||
this.wardrobe = wardrobe;
|
||||
}
|
||||
|
||||
public Wardrobe getWardrobe() {
|
||||
return wardrobe;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,6 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
case ("dataclear") -> {
|
||||
if (args.length == 1) return true;
|
||||
OfflinePlayer selectedPlayer = Bukkit.getOfflinePlayer(args[1]);
|
||||
if (selectedPlayer == null) return true;
|
||||
if (!sender.hasPermission("hmccosmetics.cmd.dataclear") && !sender.isOp()) {
|
||||
if (!silent) MessagesUtil.sendMessage(sender, "no-permission");
|
||||
return true;
|
||||
@@ -334,7 +333,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
if (args[2].equalsIgnoreCase("viewerlocation")) {
|
||||
WardrobeSettings.setViewerLocation(wardrobe, player.getLocation());
|
||||
WardrobeSettings.setViewerLocation(wardrobe, player.getEyeLocation());
|
||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-viewing");
|
||||
return true;
|
||||
}
|
||||
@@ -352,7 +351,7 @@ public class CosmeticCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
if (args[2].equalsIgnoreCase("distance")) {
|
||||
WardrobeSettings.setWardrobeDistance(wardrobe, Integer.valueOf(args[3]));
|
||||
WardrobeSettings.setWardrobeDistance(wardrobe, Integer.parseInt(args[3]));
|
||||
if (!silent) MessagesUtil.sendMessage(player, "set-wardrobe-distance");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ package com.hibiscusmc.hmccosmetics.config;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Settings {
|
||||
@@ -26,6 +29,8 @@ public class Settings {
|
||||
private static final String UNAPPLY_DEATH_PATH = "unapply-on-death";
|
||||
private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join";
|
||||
private static final String FORCE_SHOW_COSMETICS_PATH = "force-show-join";
|
||||
private static final String DISABLED_GAMEMODE_PATH = "disabled-gamemode";
|
||||
private static final String DISABLED_GAMEMODE_GAMEMODES_PATH = "gamemodes";
|
||||
private static final String EMOTE_DISTANCE_PATH = "emote-distance";
|
||||
private static final String HOOK_SETTING_PATH = "hook-settings";
|
||||
private static final String HOOK_ITEMADDER_PATH = "itemsadder";
|
||||
@@ -33,13 +38,16 @@ public class Settings {
|
||||
private static final String HOOK_WORLDGUARD_PATH = "worldguard";
|
||||
private static final String HOOK_WG_MOVE_CHECK_PATH = "player-move-check";
|
||||
private static final String HOOK_WG_MOVE_CHECK_PATH_LEGACY = "player_move_check";
|
||||
private static final String COSMETIC_EMOTE_ENABLE = "emote-enable";
|
||||
private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check";
|
||||
private static final String COSMETIC_EMOTE_AIR_CHECK_PATH = "emote-air-check";
|
||||
private static final String COSMETIC_EMOTE_DAMAGE_PATH = "emote-damage-leave";
|
||||
private static final String COSMETIC_EMOTE_INVINCIBLE_PATH = "emote-invincible";
|
||||
private static final String COSMETIC_EMOTE_CAMERA_PATH = "emote-camera";
|
||||
private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move";
|
||||
private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet";
|
||||
private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet";
|
||||
private static final String COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH = "offhand-always-show";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH = "leggings-add-enchantments";
|
||||
@@ -103,10 +111,20 @@ public class Settings {
|
||||
@Getter
|
||||
private static boolean backpackForceRidingEnabled;
|
||||
@Getter
|
||||
private static boolean cosmeticForceOffhandCosmeticShow;
|
||||
@Getter
|
||||
private static boolean emotesEnabled;
|
||||
@Getter
|
||||
private static boolean disabledGamemodesEnabled;
|
||||
@Getter
|
||||
private static List<String> disabledGamemodes;
|
||||
@Getter
|
||||
private static int viewDistance;
|
||||
@Getter
|
||||
private static int tickPeriod;
|
||||
@Getter
|
||||
private static int packetEntityTeleportCooldown;
|
||||
@Getter
|
||||
private static double emoteDistance;
|
||||
@Getter
|
||||
private static Vector balloonOffset;
|
||||
@@ -155,9 +173,18 @@ public class Settings {
|
||||
|
||||
ConfigurationNode cosmeticSettings = source.node(COSMETIC_SETTINGS_PATH);
|
||||
|
||||
ConfigurationNode disabledGamemodeSettings = cosmeticSettings.node(DISABLED_GAMEMODE_PATH);
|
||||
disabledGamemodesEnabled = disabledGamemodeSettings.node(ENABLED_PATH).getBoolean(true);
|
||||
try {
|
||||
disabledGamemodes = disabledGamemodeSettings.node(DISABLED_GAMEMODE_GAMEMODES_PATH).getList(String.class);
|
||||
} catch (Exception e) {
|
||||
disabledGamemodes = new ArrayList<>();
|
||||
}
|
||||
|
||||
unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false);
|
||||
forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false);
|
||||
forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false);
|
||||
emotesEnabled = cosmeticSettings.node(COSMETIC_EMOTE_ENABLE).getBoolean(true);
|
||||
emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3);
|
||||
cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true);
|
||||
emoteAirCheck = cosmeticSettings.node(COSMETIC_EMOTE_AIR_CHECK_PATH).getBoolean(true);
|
||||
@@ -173,6 +200,8 @@ public class Settings {
|
||||
viewDistance = cosmeticSettings.node(VIEW_DISTANCE_PATH).getInt(-3);
|
||||
emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true);
|
||||
emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false);
|
||||
packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1);
|
||||
cosmeticForceOffhandCosmeticShow = cosmeticSettings.node(COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH).getBoolean(false);
|
||||
|
||||
ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH);
|
||||
|
||||
|
||||
@@ -1,56 +1,52 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Wardrobe {
|
||||
|
||||
private String id;
|
||||
private int distance = WardrobeSettings.getDisplayRadius();
|
||||
@Getter
|
||||
private final String id;
|
||||
@Getter @Setter
|
||||
private int distance;
|
||||
@Getter @Setter
|
||||
private String permission;
|
||||
@Getter @Setter
|
||||
private WardrobeLocation location;
|
||||
|
||||
public Wardrobe(String id, WardrobeLocation location, @Nullable String permission, int distance) {
|
||||
/**
|
||||
* This creates a Wardrobe object with all the information that a user will need when entering.
|
||||
* @param id The id of the wardrobe
|
||||
* @param location The 3 locations of the Wardrobe, if any of these 3 locations are null, the wardrobe will not work
|
||||
* @param permission The permission required to enter the wardrobe, if null, no permission is required
|
||||
* @param distance The distance from the wardrobe that the player can be to enter, if -1, the player can enter from any distance
|
||||
*/
|
||||
public Wardrobe(@NotNull String id, @NotNull WardrobeLocation location, @Nullable String permission, int distance) {
|
||||
this.id = id;
|
||||
this.location = location;
|
||||
if (permission != null) this.permission = permission;
|
||||
if (distance != -1) this.distance = distance;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public WardrobeLocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setDistance(int distance) {
|
||||
this.distance = distance;
|
||||
if (permission != null) this.permission = permission;
|
||||
}
|
||||
|
||||
public void setPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* This checks if the wardrobe has a permission. If it's null, no permission is required and will return false. If it's not null, it will return true.
|
||||
* @return if the wardrobe has a permission
|
||||
*/
|
||||
public boolean hasPermission() {
|
||||
return permission != null;
|
||||
}
|
||||
public int getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public void setLocation(WardrobeLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public boolean canEnter(CosmeticUser user) {
|
||||
/**
|
||||
* Calculates if a player can enter a wardrobe. Will return true if the player can enter, else false.
|
||||
* @param user The user that is trying to enter the wardrobe
|
||||
* @return if the player can enter the wardrobe
|
||||
*/
|
||||
public boolean canEnter(@NotNull CosmeticUser user) {
|
||||
Location wardrobeLocation = location.getNpcLocation();
|
||||
Location location = user.getEntity().getLocation();
|
||||
if (wardrobeLocation == null) return false;
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
package com.hibiscusmc.hmccosmetics.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class WardrobeLocation {
|
||||
|
||||
@Setter
|
||||
@Getter @Setter
|
||||
private Location npcLocation;
|
||||
@Setter
|
||||
@Getter @Setter
|
||||
private Location viewerLocation;
|
||||
@Setter
|
||||
@Getter @Setter
|
||||
private Location leaveLocation;
|
||||
|
||||
public WardrobeLocation(Location npcLocation, Location viewerLocation, Location leaveLocation) {
|
||||
/**
|
||||
* This creates a WardrobeLocation object with the 3 locations that are required for a wardrobe to work
|
||||
* @param npcLocation The location of the NPC
|
||||
* @param viewerLocation The location of the viewer
|
||||
* @param leaveLocation The location that the player will be teleported to when they leave the wardrobe if return-last-location in the config is false
|
||||
*/
|
||||
public WardrobeLocation(@Nullable Location npcLocation, @Nullable Location viewerLocation, @Nullable Location leaveLocation) {
|
||||
this.npcLocation = npcLocation;
|
||||
this.viewerLocation = viewerLocation;
|
||||
this.leaveLocation = leaveLocation;
|
||||
}
|
||||
|
||||
public Location getNpcLocation() {
|
||||
return npcLocation.clone();
|
||||
}
|
||||
|
||||
public Location getViewerLocation() {
|
||||
return viewerLocation.clone();
|
||||
}
|
||||
|
||||
public Location getLeaveLocation() {
|
||||
return leaveLocation.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any of the locations are null
|
||||
* @return true if all locations are not null, else false
|
||||
*/
|
||||
public boolean hasAllLocations() {
|
||||
if (npcLocation == null || viewerLocation == null || leaveLocation == null) return false;
|
||||
return true;
|
||||
return npcLocation != null && viewerLocation != null && leaveLocation != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ import java.util.logging.Level;
|
||||
public class WardrobeSettings {
|
||||
|
||||
private static final String DISABLE_ON_DAMAGE_PATH = "disable-on-damage";
|
||||
private static final String DISPLAY_RADIUS_PATH = "display-radius";
|
||||
private static final String PORTABLE_PATH = "portable";
|
||||
private static final String ALWAYS_DISPLAY_PATH = "always-display";
|
||||
private static final String STATIC_RADIUS_PATH = "static-radius";
|
||||
private static final String ROTATION_SPEED_PATH = "rotation-speed";
|
||||
private static final String SPAWN_DELAY_PATH = "spawn-delay";
|
||||
private static final String DESPAWN_DELAY_PATH = "despawn-delay";
|
||||
@@ -63,14 +61,10 @@ public class WardrobeSettings {
|
||||
@Getter
|
||||
private static boolean disableOnDamage;
|
||||
@Getter
|
||||
private static int displayRadius;
|
||||
@Getter
|
||||
private static boolean portable;
|
||||
@Getter
|
||||
private static boolean alwaysDisplay;
|
||||
@Getter
|
||||
private static int staticRadius;
|
||||
@Getter
|
||||
private static int rotationSpeed;
|
||||
@Getter
|
||||
private static int spawnDelay;
|
||||
@@ -118,9 +112,7 @@ public class WardrobeSettings {
|
||||
configRoot = source;
|
||||
|
||||
disableOnDamage = source.node(DISABLE_ON_DAMAGE_PATH).getBoolean();
|
||||
displayRadius = source.node(DISPLAY_RADIUS_PATH).getInt();
|
||||
portable = source.node(PORTABLE_PATH).getBoolean();
|
||||
staticRadius = source.node(STATIC_RADIUS_PATH).getInt();
|
||||
alwaysDisplay = source.node(ALWAYS_DISPLAY_PATH).getBoolean();
|
||||
rotationSpeed = source.node(ROTATION_SPEED_PATH).getInt();
|
||||
spawnDelay = source.node(SPAWN_DELAY_PATH).getInt();
|
||||
@@ -173,10 +165,8 @@ public class WardrobeSettings {
|
||||
MessagesUtil.sendDebugMessages("Leave Location: " + leaveLocation);
|
||||
WardrobeLocation wardrobeLocation = new WardrobeLocation(npcLocation, viewerLocation, leaveLocation);
|
||||
|
||||
String permission = null;
|
||||
int distance = -1;
|
||||
if (!wardrobesNode.node(PERMISSION_PATH).virtual()) permission = wardrobesNode.node(PERMISSION_PATH).getString();
|
||||
if (!wardrobesNode.node(DISTANCE_PATH).virtual()) distance = wardrobesNode.node(DISTANCE_PATH).getInt();
|
||||
String permission = wardrobesNode.node(PERMISSION_PATH).getString();
|
||||
int distance = wardrobesNode.node(DISTANCE_PATH).getInt(-1);
|
||||
|
||||
Wardrobe wardrobe = new Wardrobe(id, wardrobeLocation, permission, distance);
|
||||
addWardrobe(wardrobe);
|
||||
@@ -206,22 +196,6 @@ public class WardrobeSettings {
|
||||
wardrobes.remove(id);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean inDistanceOfWardrobe(final Location wardrobeLocation, final Location playerLocation) {
|
||||
if (displayRadius == -1) return true;
|
||||
if (!wardrobeLocation.getWorld().equals(playerLocation.getWorld())) return false;
|
||||
return playerLocation.distanceSquared(wardrobeLocation) <= displayRadius * displayRadius;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean inDistanceOfStatic(Wardrobe wardrobe, final Location location) {
|
||||
Location wardrobeLocation = wardrobe.getLocation().getNpcLocation();
|
||||
if (wardrobeLocation == null) return false;
|
||||
if (staticRadius == -1) return true;
|
||||
if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false;
|
||||
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets where the NPC/Mannequin will spawn in the wardrobe
|
||||
* @param newLocation
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,16 +32,15 @@ public class CosmeticArmorType extends Cosmetic {
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this...
|
||||
ItemStack cosmeticItem = user.getUserCosmeticItem(this);
|
||||
if (!(entity instanceof HumanEntity humanEntity)) return;
|
||||
if (equipSlot.equals(EquipmentSlot.OFF_HAND)) {
|
||||
if (!humanEntity.getInventory().getItemInOffHand().getType().isAir()) return;
|
||||
}
|
||||
ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot);
|
||||
if (Settings.getShouldAddEnchants(equipSlot)) {
|
||||
cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments());
|
||||
}
|
||||
|
||||
// Basically, if force offhand is off AND there is no item in an offhand slot, then the equipment packet to add the cosmetic
|
||||
if (!Settings.isCosmeticForceOffhandCosmeticShow()
|
||||
&& equipSlot.equals(EquipmentSlot.OFF_HAND)
|
||||
&& ((entity instanceof Player) && !user.getPlayer().getInventory().getItemInOffHand().getType().isAir())) return;
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation()));
|
||||
//PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method
|
||||
}
|
||||
|
||||
public EquipmentSlot getEquipSlot() {
|
||||
|
||||
@@ -53,10 +53,10 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
List<Player> outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
|
||||
|
||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw());
|
||||
user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
|
||||
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||
PacketManager.sendInvisibilityPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
PacketManager.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
|
||||
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
|
||||
if (Settings.isBackpackForceRidingEnabled()) PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), user.getUserBackpackManager().getEntityManager().getViewers());
|
||||
|
||||
@@ -91,8 +91,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
if (!user.getHidden() && showLead) {
|
||||
List<Player> sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation);
|
||||
if (sendTo.isEmpty()) return;
|
||||
PacketManager.sendEntitySpawnPacket(newLocation, userBalloonManager.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager.getPufferfishBalloonUniqueId(), sendTo);
|
||||
PacketManager.sendInvisibilityPacket(userBalloonManager.getPufferfishBalloonId(), sendTo);
|
||||
user.getBalloonManager().getPufferfish().spawnPufferfish(newLocation, sendTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui.action.actions;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.gui.action.Action;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -13,6 +14,6 @@ public class ActionPlayerCommand extends Action {
|
||||
|
||||
@Override
|
||||
public void run(@NotNull CosmeticUser user, String raw) {
|
||||
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), raw));
|
||||
user.getPlayer().performCommand(MessagesUtil.processStringNoKeyString(user.getPlayer(), Hooks.processPlaceholders(user.getPlayer(), raw)));
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
@@ -186,6 +187,12 @@ public class TypeCosmetic extends Type {
|
||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner()) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
itemMeta.setLore(processedLore);
|
||||
return itemMeta;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
@@ -72,6 +73,14 @@ public class TypeEmpty extends Type {
|
||||
processedLore.add(Hooks.processPlaceholders(user.getPlayer(), loreLine));
|
||||
}
|
||||
}
|
||||
|
||||
if (itemMeta instanceof SkullMeta skullMeta) {
|
||||
if (skullMeta.hasOwner()) {
|
||||
skullMeta.setOwner(Hooks.processPlaceholders(user.getPlayer(), skullMeta.getOwner()));
|
||||
}
|
||||
}
|
||||
|
||||
itemMeta.setLore(processedLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Hooks {
|
||||
private static final HookCMI CMI_HOOK = new HookCMI();
|
||||
private static final HookLibsDisguises LIBS_DISGUISES_HOOK = new HookLibsDisguises();
|
||||
private static final HookModelEngine MODEL_ENGINE_HOOK = new HookModelEngine();
|
||||
private static final HookMMOItems MMO_ITEMS_HOOK = new HookMMOItems();
|
||||
|
||||
public static Hook getHook(@NotNull String id) {
|
||||
return hooks.get(id.toLowerCase());
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import com.mineinabyss.geary.addons.GearyPhase;
|
||||
import com.mineinabyss.geary.modules.GearyModuleKt;
|
||||
import com.mineinabyss.geary.papermc.tracking.items.ItemTrackingKt;
|
||||
import com.mineinabyss.geary.prefabs.PrefabKey;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,31 +10,19 @@ import org.jetbrains.annotations.NotNull;
|
||||
* A hook that integrates the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary} to provide custom items
|
||||
*/
|
||||
public class HookGeary extends Hook {
|
||||
private boolean enabled = false;
|
||||
|
||||
public HookGeary() {
|
||||
super("geary");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (!enabled) GearyModuleKt.getGeary().getPipeline().intercept(GearyPhase.INIT_ENTITIES, () -> {
|
||||
enabled = true;
|
||||
HMCCosmeticsPlugin.setup();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.mineinabyss.geary.papermc.GearyPlugin Geary}
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
if (enabled) {
|
||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||
if (prefabKey == null) return null;
|
||||
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
|
||||
} else return new ItemStack(Material.AIR);
|
||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||
if (prefabKey == null) return null;
|
||||
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.hibiscusmc.hmccosmetics.hooks.items;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hook;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HookMMOItems extends Hook {
|
||||
public HookMMOItems() {
|
||||
super("MMOItems");
|
||||
setEnabledItemHook(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(@NotNull String itemId) {
|
||||
String[] split = itemId.split(":", 2);
|
||||
if (split.length == 2) {
|
||||
return MMOItems.plugin.getItem(split[0], split[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -54,18 +54,15 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public String onRequest(@NotNull OfflinePlayer player, @NotNull String params) {
|
||||
if (!player.isOnline()) return null;
|
||||
if (!player.isOnline()) return TranslationUtil.getTranslation("user-cosmetic", "offline");
|
||||
CosmeticUser user = CosmeticUsers.getUser(player.getPlayer());
|
||||
if (user == null) return null;
|
||||
if (user == null) return TranslationUtil.getTranslation("user-cosmetic", "invalid-user");
|
||||
|
||||
List<String> placeholderArgs = Arrays.asList(params.split("_", 3));
|
||||
|
||||
switch (placeholderArgs.get(0).toLowerCase()) {
|
||||
case "using":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||
if (cosmetic == null) return "INVALID_COSMETIC";
|
||||
Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot());
|
||||
@@ -74,13 +71,10 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false));
|
||||
}
|
||||
case "current":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
|
||||
if (slot == null) return null;
|
||||
if (user.getCosmetic(slot) == null) return null;
|
||||
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
|
||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||
|
||||
String output;
|
||||
@@ -104,13 +98,11 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
output = user.getCosmetic(slot).getId();
|
||||
}
|
||||
}
|
||||
return TranslationUtil.getTranslation("current-cosmetic", String.valueOf(output));
|
||||
if (output == null) output = "none";
|
||||
return TranslationUtil.getTranslation("current-cosmetic", output);
|
||||
}
|
||||
case "unlocked":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||
if (cosmetic == null) {
|
||||
if (placeholderArgs.size() >= 3) {
|
||||
@@ -127,10 +119,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic, true)));
|
||||
}
|
||||
case "equipped":
|
||||
if (placeholderArgs == null) {
|
||||
return null;
|
||||
}
|
||||
if (placeholderArgs.get(1) != null) {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
String args1 = placeholderArgs.get(1);
|
||||
|
||||
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
|
||||
@@ -216,6 +205,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (!item.hasItemMeta()) return null;
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
if (itemMeta == null) return null;
|
||||
if (!itemMeta.hasDisplayName()) return null;
|
||||
return itemMeta.getDisplayName();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -51,16 +49,7 @@ public class PlayerConnectionListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) { // Remove any passengers if a user failed to initialize. Bugs can cause this to happen
|
||||
if (!event.getPlayer().getPassengers().isEmpty()) {
|
||||
for (Entity entity : event.getPlayer().getPassengers()) {
|
||||
if (entity.getType() == EntityType.ARMOR_STAND) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (user == null) return; // Player never initialized, don't do anything
|
||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||
if (user.getUserEmoteManager().isPlayingEmote()) {
|
||||
user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.CONNECTION);
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
@@ -56,6 +57,7 @@ public class PlayerGameListener implements Listener {
|
||||
public PlayerGameListener() {
|
||||
registerInventoryClickListener();
|
||||
registerMenuChangeListener();
|
||||
registerEntityStatusListener();
|
||||
registerPlayerEquipmentListener();
|
||||
registerPlayerArmListener();
|
||||
registerEntityUseListener();
|
||||
@@ -161,7 +163,6 @@ public class PlayerGameListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerHit(EntityDamageByEntityEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (event.getEntity().getEntityId() == event.getDamager().getEntityId()) event.setCancelled(true);
|
||||
if (!entity.getPersistentDataContainer().has(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
@@ -263,7 +264,13 @@ public class PlayerGameListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(CosmeticSlot.OFFHAND), 2);
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.updateCosmetic(CosmeticSlot.OFFHAND);
|
||||
List<Player> viewers = PacketManager.getViewers(user.getEntity().getLocation());
|
||||
if (viewers.isEmpty()) return;
|
||||
viewers.remove(user.getPlayer());
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(user.getEntity().getEntityId(), EquipmentSlot.HAND, event.getPlayer().getInventory().getItemInMainHand(), viewers);
|
||||
}, 2);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
@@ -328,6 +335,16 @@ public class PlayerGameListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user == null) return;
|
||||
|
||||
if (Settings.isDisabledGamemodesEnabled()) {
|
||||
if (Settings.getDisabledGamemodes().contains(event.getNewGameMode().toString())) {
|
||||
user.hideCosmetics(CosmeticUser.HiddenReason.GAMEMODE);
|
||||
} else {
|
||||
if (user.getHiddenReason() != null && user.getHiddenReason().equals(CosmeticUser.HiddenReason.GAMEMODE)) {
|
||||
user.showCosmetics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.isDestroyLooseCosmetics()) {
|
||||
ItemStack[] equippedArmor = event.getPlayer().getInventory().getArmorContents();
|
||||
if (equippedArmor.length == 0) return;
|
||||
@@ -341,11 +358,14 @@ public class PlayerGameListener implements Listener {
|
||||
public void onPlayerCosmeticEquip(PlayerCosmeticPostEquipEvent event) {
|
||||
CosmeticUser user = event.getUser();
|
||||
if (user.isInWardrobe() && event.getCosmetic().getSlot().equals(CosmeticSlot.BALLOON)) {
|
||||
Location NPCLocation = user.getWardrobeManager().getNpcLocation();
|
||||
CosmeticBalloonType cosmetic = (CosmeticBalloonType) event.getCosmetic();
|
||||
Location npclocation = user.getWardrobeManager().getNpcLocation().clone().add(cosmetic.getBalloonOffset());
|
||||
// We know that no other entity besides a regular player will be in the wardrobe
|
||||
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), NPCLocation.add(cosmetic.getBalloonOffset()), false, List.of(user.getPlayer()));
|
||||
user.getBalloonManager().getModelEntity().teleport(NPCLocation.add(cosmetic.getBalloonOffset()));
|
||||
List<Player> viewer = List.of(user.getPlayer());
|
||||
user.getBalloonManager().getPufferfish().spawnPufferfish(npclocation.clone().add(cosmetic.getBalloonOffset()), viewer);
|
||||
PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), user.getWardrobeManager().getNPC_ID(), viewer);
|
||||
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npclocation, false, viewer);
|
||||
user.getBalloonManager().getModelEntity().teleport(npclocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -479,14 +499,32 @@ public class PlayerGameListener implements Listener {
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
|
||||
|
||||
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.BukkitCosmeticSlot(equipmentSlot));
|
||||
if (cosmeticArmor == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), cosmeticArmor.getItem());
|
||||
armor.add(pair);
|
||||
for (int i = 0; i < armor.size(); i++) {
|
||||
com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack> pair = armor.get(i);
|
||||
switch (pair.getFirst()) {
|
||||
case MAINHAND -> {
|
||||
if (user.getPlayer() == event.getPlayer()) continue; // When a player scrolls real fast, it messes up the mainhand. This fixes it
|
||||
armor.set(i, new Pair<>(pair.getFirst(), user.getPlayer().getInventory().getItemInMainHand()));
|
||||
}
|
||||
case OFFHAND -> {
|
||||
if (Settings.isCosmeticForceOffhandCosmeticShow() && user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) {
|
||||
ItemStack item = user.getUserCosmeticItem(CosmeticSlot.OFFHAND);
|
||||
if (item == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> offhandPair = new Pair<>(EnumWrappers.ItemSlot.OFFHAND, item);
|
||||
armor.set(i, offhandPair);
|
||||
}
|
||||
}
|
||||
default -> {
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.getItemSlotToCosmeticSlot(pair.getFirst()));
|
||||
if (cosmeticArmor == null) continue;
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticArmor);
|
||||
if (item == null) continue;
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> armorPair = new Pair<>(InventoryUtils.itemBukkitSlot(cosmeticArmor.getEquipSlot()), item);
|
||||
armor.set(i, armorPair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.getPacket().getSlotStackPairLists().write(0, armor);
|
||||
@@ -495,6 +533,27 @@ public class PlayerGameListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
private void registerEntityStatusListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_STATUS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
int entityid = event.getPacket().getIntegers().read(0);
|
||||
byte status = event.getPacket().getBytes().read(0);
|
||||
|
||||
MessagesUtil.sendDebugMessages("EntityStatus Initial " + entityid + " - " + status);
|
||||
if (status != 55) return;
|
||||
|
||||
CosmeticUser user = CosmeticUsers.getUser(entityid);
|
||||
if (user == null) {
|
||||
MessagesUtil.sendDebugMessages("EntityStatus User is null");
|
||||
return;
|
||||
}
|
||||
if (!user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registerPlayerArmListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.ARM_ANIMATION) {
|
||||
@Override
|
||||
@@ -538,7 +597,11 @@ public class PlayerGameListener implements Listener {
|
||||
MessagesUtil.sendDebugMessages("Look Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
user.getUserBackpackManager().getEntityManager().setRotation(Math.round(event.getPacket().getFloat().read(0)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -551,20 +614,29 @@ public class PlayerGameListener implements Listener {
|
||||
MessagesUtil.sendDebugMessages("Position Packet ");
|
||||
Player player = event.getPlayer();
|
||||
if (event.getPlayer() == null) return;
|
||||
if (!(event.getPlayer() instanceof Player)) 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.TELEPORT_ACCEPT) {
|
||||
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;
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user == null) return;
|
||||
if (user.isBackpackSpawned()) {
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> user.updateCosmetic(CosmeticSlot.BACKPACK));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
@@ -19,24 +18,12 @@ public interface NMSHandler {
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
Entity getHMCArmorStand(Location loc);
|
||||
|
||||
ArmorStand getMEGEntity(Location loc);
|
||||
|
||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||
|
||||
Entity spawnDisplayEntity(Location location, String text);
|
||||
|
||||
UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType);
|
||||
|
||||
@Deprecated(since = "2.6.0")
|
||||
void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
);
|
||||
|
||||
void slotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
|
||||
@@ -3,17 +3,19 @@ package com.hibiscusmc.hmccosmetics.nms;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class NMSHandlers {
|
||||
|
||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3", "v1_20_R1"};
|
||||
private static final String[] SUPPORTED_VERSION = new String[]{"v1_18_R2", "v1_19_R1", "v1_19_R2", "v1_19_R3", "v1_20_R1", "v1_20_R2"};
|
||||
private static NMSHandler handler;
|
||||
@Getter
|
||||
private static String version;
|
||||
|
||||
@Nullable
|
||||
public static NMSHandler getHandler() {
|
||||
if (handler != null) {
|
||||
return handler;
|
||||
@@ -23,6 +25,11 @@ public class NMSHandlers {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static boolean isVersionSupported() {
|
||||
if (getHandler() == null) return false;
|
||||
return getHandler().getSupported();
|
||||
}
|
||||
|
||||
public static void setup() {
|
||||
if (handler != null) return;
|
||||
final String packageName = HMCCosmeticsPlugin.getInstance().getServer().getClass().getPackage().getName();
|
||||
|
||||
@@ -218,15 +218,15 @@ public class CosmeticUser {
|
||||
item = cosmetic.getItem();
|
||||
}
|
||||
}
|
||||
if (item == null) {
|
||||
MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
|
||||
return null;
|
||||
}
|
||||
return getUserCosmeticItem(cosmetic, item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public ItemStack getUserCosmeticItem(Cosmetic cosmetic, ItemStack item) {
|
||||
if (item == null) {
|
||||
MessagesUtil.sendDebugMessages("GetUserCosemticUser Item is null");
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
@@ -527,6 +527,7 @@ public class CosmeticUser {
|
||||
POTION,
|
||||
ACTION,
|
||||
COMMAND,
|
||||
EMOTE
|
||||
EMOTE,
|
||||
GAMEMODE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.hibiscusmc.hmccosmetics.user;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -41,8 +40,8 @@ public class CosmeticUsers {
|
||||
public static CosmeticUser getUser(int entityId) {
|
||||
Entity entity = ServerUtils.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity.getType().equals(EntityType.PLAYER)) return null;
|
||||
return COSMETIC_USERS.get(entity.getUniqueId());
|
||||
if (!(entity instanceof Player player)) return null;
|
||||
return COSMETIC_USERS.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static Set<CosmeticUser> values() {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class UserBackpackManager {
|
||||
getEntityManager().teleport(user.getEntity().getLocation());
|
||||
List<Player> outsideViewers = getEntityManager().getViewers();
|
||||
PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
|
||||
PacketManager.sendInvisibilityPacket(getFirstArmorStandId(), outsideViewers);
|
||||
PacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
|
||||
|
||||
Entity entity = user.getEntity();
|
||||
|
||||
@@ -91,7 +91,7 @@ public class UserBackpackManager {
|
||||
|
||||
// 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.api.getModelRegistry().getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||
if (ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName()) == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import com.ticxo.modelengine.api.entity.BaseEntity;
|
||||
import com.ticxo.modelengine.api.entity.BukkitEntity;
|
||||
import com.ticxo.modelengine.api.entity.Dummy;
|
||||
import com.ticxo.modelengine.api.entity.EntityDataTracker;
|
||||
import com.ticxo.modelengine.api.entity.data.BukkitEntityData;
|
||||
import com.ticxo.modelengine.api.model.ActiveModel;
|
||||
import com.ticxo.modelengine.api.model.ModeledEntity;
|
||||
import lombok.Getter;
|
||||
@@ -20,19 +25,23 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class UserBalloonManager {
|
||||
|
||||
private CosmeticUser user;
|
||||
@Getter
|
||||
private BalloonType balloonType;
|
||||
private CosmeticBalloonType cosmeticBalloonType;
|
||||
@Getter
|
||||
private UserBalloonPufferfish pufferfish;
|
||||
private final ArmorStand modelEntity;
|
||||
|
||||
public UserBalloonManager(CosmeticUser user, @NotNull Location location) {
|
||||
this.user = user;
|
||||
this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID());
|
||||
this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset()));
|
||||
}
|
||||
@@ -54,7 +63,7 @@ public class UserBalloonManager {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
String id = cosmeticBalloonType.getModelName();
|
||||
MessagesUtil.sendDebugMessages("Attempting Spawning for " + id);
|
||||
if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) {
|
||||
if (ModelEngineAPI.getBlueprint(id) == null) {
|
||||
MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + id, Level.SEVERE);
|
||||
return;
|
||||
}
|
||||
@@ -62,14 +71,19 @@ public class UserBalloonManager {
|
||||
ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id));
|
||||
model.setCanHurt(false);
|
||||
modeledEntity.addModel(model, false);
|
||||
|
||||
if (color != null) {
|
||||
modeledEntity.getModels().forEach((d, singleModel) -> {
|
||||
if (cosmeticBalloonType.isDyablePart(d)) {
|
||||
singleModel.getRendererHandler().setColor(color);
|
||||
singleModel.getRendererHandler().update();
|
||||
singleModel.setDefaultTint(color);
|
||||
singleModel.getModelRenderer().sendToClient();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
BukkitEntityData data = (BukkitEntityData) modeledEntity.getBase().getData();
|
||||
data.setBlockedCullIgnoreRadius((double) Settings.getViewDistance());
|
||||
data.getTracked().setPlayerPredicate(this::playerCheck);
|
||||
return;
|
||||
}
|
||||
if (balloonType == BalloonType.ITEM) {
|
||||
@@ -79,18 +93,19 @@ public class UserBalloonManager {
|
||||
|
||||
public void remove() {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity entity = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
|
||||
if (entity == null) return;
|
||||
|
||||
for (final Player player : entity.getRangeManager().getPlayerInRange()) {
|
||||
entity.hideFromPlayer(player);
|
||||
final ModeledEntity entity = ModelEngineAPI.getModeledEntity(modelEntity);
|
||||
if (entity == null) {
|
||||
MessagesUtil.sendDebugMessages("Balloon Removal Failed - Model Entity is Null");
|
||||
return;
|
||||
}
|
||||
|
||||
entity.destroy();
|
||||
MessagesUtil.sendDebugMessages("Balloon Model Engine Removal");
|
||||
}
|
||||
|
||||
modelEntity.remove();
|
||||
cosmeticBalloonType = null;
|
||||
MessagesUtil.sendDebugMessages("Balloon Entity Removed");
|
||||
}
|
||||
|
||||
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) {
|
||||
@@ -99,14 +114,13 @@ public class UserBalloonManager {
|
||||
|
||||
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType, Color color) {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
final ModeledEntity model = ModelEngineAPI.getModeledEntity(modelEntity);
|
||||
if (model == null) {
|
||||
spawnModel(cosmeticBalloonType, color);
|
||||
MessagesUtil.sendDebugMessages("model is null");
|
||||
return;
|
||||
}
|
||||
//if (model.getRangeManager().getPlayerInRange().contains(player)) return;
|
||||
model.showToPlayer(user.getPlayer());
|
||||
|
||||
MessagesUtil.sendDebugMessages("Show to player");
|
||||
return;
|
||||
}
|
||||
@@ -114,13 +128,11 @@ public class UserBalloonManager {
|
||||
modelEntity.getEquipment().setHelmet(user.getUserCosmeticItem(cosmeticBalloonType));
|
||||
}
|
||||
}
|
||||
public void removePlayerFromModel(final Player player) {
|
||||
public void removePlayerFromModel(final Player viewer) {
|
||||
if (balloonType == BalloonType.MODELENGINE) {
|
||||
final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId());
|
||||
|
||||
final ModeledEntity model = ModelEngineAPI.getModeledEntity(modelEntity);
|
||||
if (model == null) return;
|
||||
|
||||
model.hideFromPlayer(player);
|
||||
MessagesUtil.sendDebugMessages("Hidden from player");
|
||||
return;
|
||||
}
|
||||
@@ -136,7 +148,7 @@ public class UserBalloonManager {
|
||||
|
||||
|
||||
public int getPufferfishBalloonId() {
|
||||
return pufferfish.getId();
|
||||
return pufferfish.getPufferFishEntityId();
|
||||
}
|
||||
public UUID getPufferfishBalloonUniqueId() {
|
||||
return pufferfish.getUuid();
|
||||
@@ -171,7 +183,6 @@ public class UserBalloonManager {
|
||||
}
|
||||
|
||||
public void sendLeashPacket(int entityId) {
|
||||
if (cosmeticBalloonType == null) return;
|
||||
if (cosmeticBalloonType.isShowLead()) {
|
||||
PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation());
|
||||
}
|
||||
@@ -182,4 +193,21 @@ public class UserBalloonManager {
|
||||
ITEM,
|
||||
NONE
|
||||
}
|
||||
|
||||
private boolean playerCheck(final Player player) {
|
||||
MessagesUtil.sendDebugMessages("playerCheck");
|
||||
CosmeticUser viewer = CosmeticUsers.getUser(player.getUniqueId());
|
||||
|
||||
if (user.getPlayer() == player) {
|
||||
return (!user.getHidden());
|
||||
} else {
|
||||
if (user.isInWardrobe()) return false;
|
||||
MessagesUtil.sendDebugMessages("playerCheck - Not Same Player");
|
||||
if (viewer != null && viewer.isInWardrobe()) {
|
||||
MessagesUtil.sendDebugMessages("playerCheck - Viewer in Wardrobe");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (!user.getHidden());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -11,17 +15,17 @@ import java.util.UUID;
|
||||
|
||||
public class UserBalloonPufferfish extends UserEntity {
|
||||
|
||||
private int id;
|
||||
private int pufferFishEntityId;
|
||||
private UUID uuid;
|
||||
|
||||
public UserBalloonPufferfish(UUID owner, int id, UUID uuid) {
|
||||
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
|
||||
super(owner);
|
||||
this.id = id;
|
||||
this.pufferFishEntityId = pufferFishEntityId;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
public int getPufferFishEntityId() {
|
||||
return pufferFishEntityId;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@@ -29,7 +33,44 @@ public class UserBalloonPufferfish extends UserEntity {
|
||||
}
|
||||
|
||||
public void hidePufferfish() {
|
||||
PacketManager.sendEntityDestroyPacket(id, getViewers());
|
||||
PacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers());
|
||||
getViewers().clear();
|
||||
}
|
||||
|
||||
public void spawnPufferfish(Location location, List<Player> sendTo) {
|
||||
PacketManager.sendEntitySpawnPacket(location, pufferFishEntityId, EntityType.PUFFERFISH, uuid, sendTo);
|
||||
PacketManager.sendInvisibilityPacket(pufferFishEntityId, sendTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Player> refreshViewers(Location location) {
|
||||
if (System.currentTimeMillis() - getViewerLastUpdate() <= 1000) return List.of(); //Prevents mass refreshes
|
||||
ArrayList<Player> newPlayers = new ArrayList<>();
|
||||
ArrayList<Player> removePlayers = new ArrayList<>();
|
||||
List<Player> players = PlayerUtils.getNearbyPlayers(location);
|
||||
|
||||
for (Player player : players) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(player);
|
||||
if (user != null && getOwner() != user.getUniqueId() && user.isInWardrobe()) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
|
||||
removePlayers.add(player);
|
||||
PacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(player));
|
||||
continue;
|
||||
}
|
||||
if (!getViewers().contains(player)) {
|
||||
getViewers().add(player);
|
||||
newPlayers.add(player);
|
||||
continue;
|
||||
}
|
||||
// bad loopdy loops
|
||||
for (Player viewerPlayer : getViewers()) {
|
||||
if (!players.contains(viewerPlayer)) {
|
||||
removePlayers.add(viewerPlayer);
|
||||
PacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(viewerPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
getViewers().removeAll(removePlayers);
|
||||
setViewerLastUpdate(System.currentTimeMillis());
|
||||
return newPlayers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
@@ -20,7 +21,9 @@ public class UserEntity {
|
||||
@Getter
|
||||
private List<Player> viewers = new ArrayList<>();
|
||||
@Getter @Setter
|
||||
private Long lastUpdate = 0L;
|
||||
private Long viewerLastUpdate = 0L;
|
||||
@Getter @Setter
|
||||
private Long lastPositionUpdate = 0L;
|
||||
@Getter @Setter
|
||||
private List<Integer> ids = new ArrayList<>();
|
||||
@Getter
|
||||
@@ -35,7 +38,7 @@ public class UserEntity {
|
||||
}
|
||||
|
||||
public List<Player> refreshViewers(Location location) {
|
||||
if (System.currentTimeMillis() - lastUpdate <= 1000) return List.of(); //Prevents mass refreshes
|
||||
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
|
||||
ArrayList<Player> newPlayers = new ArrayList<>();
|
||||
ArrayList<Player> removePlayers = new ArrayList<>();
|
||||
List<Player> players = PlayerUtils.getNearbyPlayers(location);
|
||||
@@ -61,20 +64,33 @@ public class UserEntity {
|
||||
}
|
||||
}
|
||||
viewers.removeAll(removePlayers);
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
setViewerLastUpdate(System.currentTimeMillis());
|
||||
return newPlayers;
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
|
||||
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
|
||||
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
|
||||
if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||
}
|
||||
this.location = location;
|
||||
for (Integer entity : ids) {
|
||||
PacketManager.sendTeleportPacket(entity, location, false, getViewers());
|
||||
}
|
||||
setLastPositionUpdate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void setRotation(int yaw) {
|
||||
setRotation(yaw, false);
|
||||
}
|
||||
|
||||
public void setRotation(int yaw, boolean additonalPacket) {
|
||||
location.setYaw(yaw);
|
||||
for (Integer entity : ids) {
|
||||
// First person backpacks need both packets to rotate properly, otherwise they look off
|
||||
// Regular backpacks just need the look packet
|
||||
if (additonalPacket) PacketManager.sendRotationPacket(entity, yaw, false, getViewers());
|
||||
PacketManager.sendLookPacket(entity, location, getViewers());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class UserWardrobeManager {
|
||||
Runnable run = () -> {
|
||||
// Armorstand
|
||||
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
|
||||
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
|
||||
PacketManager.sendArmorstandMetadata(ARMORSTAND_ID, viewer);
|
||||
PacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
|
||||
|
||||
// Player
|
||||
@@ -145,6 +145,7 @@ public class UserWardrobeManager {
|
||||
Location balloonLocation = npcLocation.clone().add(cosmetic.getBalloonOffset());
|
||||
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation , false, viewer);
|
||||
user.getBalloonManager().getModelEntity().teleport(balloonLocation);
|
||||
user.getBalloonManager().setLocation(balloonLocation);
|
||||
}
|
||||
|
||||
if (WardrobeSettings.isEnabledBossbar()) {
|
||||
@@ -234,7 +235,7 @@ public class UserWardrobeManager {
|
||||
}
|
||||
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
|
||||
user.respawnBalloon();
|
||||
//user.respawnBalloon();
|
||||
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer);
|
||||
}
|
||||
|
||||
@@ -300,7 +301,9 @@ public class UserWardrobeManager {
|
||||
//PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.add(Settings.getBalloonOffset()), false, viewer);
|
||||
//user.getBalloonManager().getModelEntity().teleport(npcLocation.add(Settings.getBalloonOffset()));
|
||||
user.getBalloonManager().sendRemoveLeashPacket(outsideViewers);
|
||||
PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
|
||||
if (user.getBalloonManager().getBalloonType() != UserBalloonManager.BalloonType.MODELENGINE) {
|
||||
PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers);
|
||||
}
|
||||
user.getBalloonManager().sendLeashPacket(NPC_ID);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,17 @@ public class InventoryUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static CosmeticSlot getItemSlotToCosmeticSlot(final EnumWrappers.ItemSlot slot) {
|
||||
return switch (slot) {
|
||||
case HEAD -> CosmeticSlot.HELMET;
|
||||
case CHEST -> CosmeticSlot.CHESTPLATE;
|
||||
case LEGS -> CosmeticSlot.LEGGINGS;
|
||||
case FEET -> CosmeticSlot.BOOTS;
|
||||
case OFFHAND -> CosmeticSlot.OFFHAND;
|
||||
case MAINHAND -> CosmeticSlot.MAINHAND;
|
||||
};
|
||||
}
|
||||
|
||||
public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) {
|
||||
return switch (slot) {
|
||||
case HAND -> CosmeticSlot.MAINHAND;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.hooks.Hooks;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BasePacket {
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
if (player == null) return;
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.util.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.*;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -18,8 +19,6 @@ import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEnt
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
@@ -31,7 +30,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketManager extends BasePacket {
|
||||
public class PacketManager {
|
||||
|
||||
public static void sendEntitySpawnPacket(
|
||||
final @NotNull Location location,
|
||||
@@ -122,19 +121,25 @@ public class PacketManager extends BasePacket {
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(entityId, InventoryUtils.getEquipmentSlot(cosmeticSlot), user.getUserCosmeticItem(cosmeticSlot), sendTo);
|
||||
}
|
||||
|
||||
public static void armorStandMetaPacket(
|
||||
@NotNull Entity entity,
|
||||
public static void sendArmorstandMetadata(
|
||||
int entityId,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entity.getEntityId());
|
||||
WrappedDataWatcher metadata = new WrappedDataWatcher();
|
||||
if (metadata == null) return;
|
||||
// 0x10 & 0x20
|
||||
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||
metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
|
||||
packet.getWatchableCollectionModifier().write(0, metadata.getWatchableObjects());
|
||||
packet.getIntegers().write(0, entityId);
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
|
||||
if (NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x20);
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
|
||||
packet.getWatchableCollectionModifier().write(0, wrapper.getWatchableObjects());
|
||||
} else {
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
}
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
@@ -332,13 +337,17 @@ public class PacketManager extends BasePacket {
|
||||
final int entityId,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setPlayerUUID(uuid);
|
||||
wrapper.setPosition(location.toVector());
|
||||
wrapper.setPitch(location.getPitch());
|
||||
wrapper.setYaw(location.getYaw());
|
||||
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
|
||||
if (NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1") || NMSHandlers.getVersion().contains("v1_19_R2") || NMSHandlers.getVersion().contains("v1_19_R3") || NMSHandlers.getVersion().contains("v1_20_R1")) {
|
||||
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
|
||||
wrapper.setEntityID(entityId);
|
||||
wrapper.setPlayerUUID(uuid);
|
||||
wrapper.setPosition(location.toVector());
|
||||
wrapper.setPitch(location.getPitch());
|
||||
wrapper.setYaw(location.getYaw());
|
||||
for (final Player p : sendTo) sendPacket(p, wrapper.getHandle());
|
||||
return;
|
||||
}
|
||||
sendEntitySpawnPacket(location, entityId, EntityType.PLAYER, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -546,4 +555,9 @@ public class PacketManager extends BasePacket {
|
||||
}
|
||||
return viewers;
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, PacketContainer packet) {
|
||||
if (player == null) return;
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, null,false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,14 @@ cosmetic-settings:
|
||||
force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server.
|
||||
force-show-join: false # If the plugin should force show a player's cosmetics when they join the server.
|
||||
|
||||
disabled-gamemode:
|
||||
enabled: true
|
||||
# Which gamemodes should cosmetics be disabled for. This is useful for servers that have a creative world. All options are here, https://hub.spigotmc.org/javadocs/spigot/org/bukkit/GameMode.html
|
||||
gamemodes:
|
||||
- "SPECTATOR"
|
||||
|
||||
# This disables the entire internal emote system within the plugin. This option requires a restart.
|
||||
emote-enable: true
|
||||
emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player.
|
||||
emote-block-check: true # If the server should check if the block is open where the camera is placed (prevents players viewing through blocks)
|
||||
emote-air-check: true # Check if there is air under a player, if there is, don't play emote
|
||||
@@ -35,6 +43,12 @@ 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 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
|
||||
# This forces the offhand to always show the cosmetic. False means it will only show when the slot is empty.
|
||||
# There is a small visual blip for a tick when you put a new item in the offhand slot, hence why its disabled by default.
|
||||
offhand-always-show: false
|
||||
|
||||
helmet-add-enchantments: false # If the plugin should keep enchants on helmets. This is useful as some enchantments are client side only.
|
||||
chest-add-enchantments: false # If the plugin should keep enchants on chestplate. This is useful as some enchantments are client side only.
|
||||
@@ -89,8 +103,6 @@ hook-settings:
|
||||
# Requires restart to apply changes.
|
||||
player-move-check: true
|
||||
wardrobe:
|
||||
# spawn static wardrobe if in this radius of wardrobe-location
|
||||
static-radius: 10
|
||||
# how much yaw should change per tick, set to 0 for none
|
||||
rotation-speed: 3
|
||||
# Applies a pumpkin for an overlay of the player while in the wardrobe.
|
||||
@@ -125,6 +137,8 @@ wardrobe:
|
||||
title-fade-out: 1000 # milliseconds
|
||||
wardrobes:
|
||||
default:
|
||||
distance: -1 # Distance in blocks that a player can interact with the wardrobe. -1 to ignore.
|
||||
permission: "hmccosmetics.wardrobe.default" # Permission required to use the wardrobe.
|
||||
npc-location:
|
||||
world: "world"
|
||||
x: 0
|
||||
|
||||
@@ -67,7 +67,7 @@ jetpack:
|
||||
amount: 1
|
||||
firstperson-item:
|
||||
material: PAPER
|
||||
model-data: 14
|
||||
model-data: 15
|
||||
name: "<white>Jetpack"
|
||||
amount: 1
|
||||
hammer:
|
||||
@@ -155,6 +155,6 @@ hibiscus_flower:
|
||||
permission: "hmccosmetics.hibiscus_flower"
|
||||
item:
|
||||
material: PAPER
|
||||
model-data: 15
|
||||
model-data: 16
|
||||
name: "<#d24c9f>Hibiscus Flower"
|
||||
amount: 1
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
user-cosmetic:
|
||||
offline: "Offline"
|
||||
invalid-user: "Invalid User"
|
||||
unlocked-cosmetic:
|
||||
true: "true"
|
||||
false: "false"
|
||||
@@ -11,5 +14,5 @@ using-cosmetic:
|
||||
true: "true"
|
||||
false: "false"
|
||||
current-cosmetic:
|
||||
true: "true"
|
||||
false: "false"
|
||||
no-cosmetic: "No Cosmetic"
|
||||
none: "none"
|
||||
|
||||
@@ -13,4 +13,5 @@ include(
|
||||
"v1_19_R2",
|
||||
"v1_19_R3",
|
||||
"v1_20_R1",
|
||||
"v1_20_R2"
|
||||
)
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_18_R2;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
|
||||
public class HMCArmorStand extends ArmorStand {
|
||||
|
||||
public HMCArmorStand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public HMCArmorStand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_18_R2;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
@@ -26,13 +19,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_18_R2.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -55,37 +46,17 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity == null) continue;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
|
||||
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
|
||||
return hmcArmorStand.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
|
||||
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
|
||||
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
|
||||
|
||||
return invisibleArmorstand.getBukkitLivingEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) {
|
||||
return null;
|
||||
@@ -105,54 +76,6 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
return userBalloonManager1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
|
||||
EquipmentSlot nmsSlot = null;
|
||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
|
||||
|
||||
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
|
||||
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
|
||||
}
|
||||
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
return;
|
||||
}
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_19_R1;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
|
||||
public class HMCArmorStand extends ArmorStand {
|
||||
|
||||
public HMCArmorStand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public HMCArmorStand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_19_R1;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
@@ -26,13 +19,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -55,45 +46,22 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity == null) continue;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
|
||||
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
|
||||
return hmcArmorStand.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
|
||||
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
|
||||
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
|
||||
|
||||
return invisibleArmorstand.getBukkitLivingEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
|
||||
org.bukkit.entity.Entity entity = user.getEntity();
|
||||
@@ -107,54 +75,6 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
return userBalloonManager1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
|
||||
EquipmentSlot nmsSlot = null;
|
||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
|
||||
|
||||
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
|
||||
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
|
||||
}
|
||||
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
return;
|
||||
}
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_19_R2;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
|
||||
public class HMCArmorStand extends ArmorStand {
|
||||
|
||||
public HMCArmorStand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public HMCArmorStand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_19_R2;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
@@ -26,13 +19,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -55,37 +46,17 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity == null) continue;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
|
||||
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
|
||||
return hmcArmorStand.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
|
||||
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
|
||||
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
|
||||
|
||||
return invisibleArmorstand.getBukkitLivingEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) {
|
||||
return null;
|
||||
@@ -106,55 +77,6 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
return userBalloonManager1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
|
||||
EquipmentSlot nmsSlot = null;
|
||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
|
||||
|
||||
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
|
||||
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
|
||||
}
|
||||
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
return;
|
||||
}
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_19_R3;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
|
||||
|
||||
public class HMCArmorStand extends ArmorStand {
|
||||
|
||||
public HMCArmorStand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public HMCArmorStand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_19_R3;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -58,37 +52,17 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity == null) continue;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
|
||||
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
|
||||
return hmcArmorStand.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
|
||||
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
|
||||
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
|
||||
|
||||
return invisibleArmorstand.getBukkitLivingEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) {
|
||||
Display.TextDisplay entity = new Display.TextDisplay(net.minecraft.world.entity.EntityType.TEXT_DISPLAY, ((CraftWorld) location.getWorld()).getHandle());
|
||||
@@ -115,54 +89,6 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
return userBalloonManager1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
|
||||
EquipmentSlot nmsSlot = null;
|
||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
|
||||
|
||||
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
|
||||
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
|
||||
}
|
||||
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
return;
|
||||
}
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_20_R1;
|
||||
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
|
||||
public class HMCArmorStand extends ArmorStand {
|
||||
|
||||
public HMCArmorStand(Level world, double x, double y, double z) {
|
||||
super(world, x, y, z);
|
||||
}
|
||||
|
||||
public HMCArmorStand(Location loc) {
|
||||
super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
setInvisible(true);
|
||||
setInvulnerable(true);
|
||||
setMarker(true);
|
||||
setSilent(true);
|
||||
getBukkitLivingEntity().setCollidable(false);
|
||||
persist = false;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_20_R1;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.InventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -57,39 +51,17 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
if (entity == null) continue;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getHMCArmorStand(Location loc) {
|
||||
HMCArmorStand hmcArmorStand = new HMCArmorStand(loc);
|
||||
return hmcArmorStand.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) {
|
||||
HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation());
|
||||
|
||||
ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType);
|
||||
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item));
|
||||
((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack NMS");
|
||||
|
||||
return invisibleArmorstand.getBukkitLivingEntity();
|
||||
//PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
|
||||
//PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) {
|
||||
Display.TextDisplay entity = new Display.TextDisplay(net.minecraft.world.entity.EntityType.TEXT_DISPLAY, ((CraftWorld) location.getWorld()).getHandle());
|
||||
@@ -116,54 +88,6 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
return userBalloonManager1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
CosmeticUser user,
|
||||
CosmeticSlot cosmeticSlot,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
|
||||
EquipmentSlot nmsSlot = null;
|
||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
||||
|
||||
if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) {
|
||||
|
||||
if (user.getCosmetic(cosmeticSlot) instanceof CosmeticMainhandType) {
|
||||
CosmeticMainhandType cosmeticMainhandType = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND);
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticMainhandType));
|
||||
} else {
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot)));
|
||||
}
|
||||
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
return;
|
||||
}
|
||||
CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(cosmeticSlot);
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(cosmeticArmor.getEquipSlot());
|
||||
nmsItem = CraftItemStack.asNMSCopy(user.getUserCosmeticItem(cosmeticArmor));
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
|
||||
27
v1_20_R2/build.gradle.kts
Normal file
27
v1_20_R2/build.gradle.kts
Normal file
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("io.papermc.paperweight.userdev") version "1.5.1"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.20.2-R0.1-SNAPSHOT")
|
||||
implementation(project(":common"))
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
options.release.set(17)
|
||||
}
|
||||
javadoc {
|
||||
options.encoding = Charsets.UTF_8.name()
|
||||
}
|
||||
processResources {
|
||||
filteringCharset = Charsets.UTF_8.name()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_20_R2;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class MEGEntity extends ArmorStand {
|
||||
public MEGEntity(Location loc) {
|
||||
super(EntityType.ARMOR_STAND, ((CraftWorld) loc.getWorld()).getHandle());
|
||||
this.setPos(loc.getX(), loc.getY(), loc.getZ());
|
||||
|
||||
MessagesUtil.sendDebugMessages("Spawned MEGEntity at " + loc);
|
||||
setInvisible(true);
|
||||
setNoGravity(true);
|
||||
setSilent(true);
|
||||
setInvulnerable(true);
|
||||
setSmall(true);
|
||||
setMarker(true);
|
||||
|
||||
persist = false;
|
||||
getBukkitEntity().getPersistentDataContainer().set(new NamespacedKey(HMCCosmeticsPlugin.getInstance(), "cosmeticMob"), PersistentDataType.SHORT, Short.valueOf("1"));
|
||||
|
||||
((CraftWorld) loc.getWorld()).getHandle().addFreshEntity(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package com.hibiscusmc.hmccosmetics.nms.v1_20_R2;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerPlayerConnection;
|
||||
import net.minecraft.world.entity.Display;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.scores.PlayerTeam;
|
||||
import net.minecraft.world.scores.Team;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.scoreboard.CraftScoreboard;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
|
||||
@Override
|
||||
public int getNextEntityId() {
|
||||
return net.minecraft.world.entity.Entity.nextEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity getEntity(int entityId) {
|
||||
net.minecraft.world.entity.Entity entity = getNMSEntity(entityId);
|
||||
if (entity == null) return null;
|
||||
return entity.getBukkitEntity();
|
||||
}
|
||||
|
||||
private net.minecraft.world.entity.Entity getNMSEntity(int entityId) {
|
||||
for (ServerLevel world : ((CraftServer) Bukkit.getServer()).getHandle().getServer().getAllLevels()) {
|
||||
net.minecraft.world.entity.Entity entity = world.getEntity(entityId);
|
||||
if (entity == null) continue;
|
||||
return entity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArmorStand getMEGEntity(Location loc) {
|
||||
return (ArmorStand) new MEGEntity(loc).getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) {
|
||||
Display.TextDisplay entity = new Display.TextDisplay(net.minecraft.world.entity.EntityType.TEXT_DISPLAY, ((CraftWorld) location.getWorld()).getHandle());
|
||||
entity.setPos(location.getX(), location.getY(), location.getZ());
|
||||
entity.persist = false;
|
||||
//entity.setText(net.minecraft.network.chat.Component.literal("TEST!"));
|
||||
entity.setCustomNameVisible(true);
|
||||
entity.setCustomName(Component.literal(text));
|
||||
MessagesUtil.sendDebugMessages("spawnDisplayEntity - " + entity);
|
||||
((CraftWorld) location.getWorld()).getHandle().addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
return entity.getBukkitEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {
|
||||
org.bukkit.entity.Entity entity = user.getEntity();
|
||||
|
||||
UserBalloonManager userBalloonManager1 = new UserBalloonManager(user, entity.getLocation());
|
||||
userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset()));
|
||||
|
||||
userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
|
||||
userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));
|
||||
|
||||
return userBalloonManager1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void equipmentSlotUpdate(
|
||||
int entityId,
|
||||
org.bukkit.inventory.EquipmentSlot slot,
|
||||
ItemStack item,
|
||||
List<Player> sendTo
|
||||
) {
|
||||
|
||||
EquipmentSlot nmsSlot = null;
|
||||
net.minecraft.world.item.ItemStack nmsItem = null;
|
||||
|
||||
// Converting EquipmentSlot and ItemStack to NMS ones.
|
||||
nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
||||
nmsItem = CraftItemStack.asNMSCopy(item);
|
||||
|
||||
if (nmsSlot == null) return;
|
||||
|
||||
Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> pair = new Pair<>(nmsSlot, nmsItem);
|
||||
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> pairs = Collections.singletonList(pair);
|
||||
|
||||
ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs);
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void slotUpdate(
|
||||
Player player,
|
||||
int slot
|
||||
) {
|
||||
int index = 0;
|
||||
|
||||
ServerPlayer player1 = ((CraftPlayer) player).getHandle();
|
||||
|
||||
if (index < Inventory.getSelectionSize()) {
|
||||
index += 36;
|
||||
} else if (index > 39) {
|
||||
index += 5; // Off hand
|
||||
} else if (index > 35) {
|
||||
index = 8 - (index - 36);
|
||||
}
|
||||
ItemStack item = player.getInventory().getItem(slot);
|
||||
|
||||
Packet packet = new ClientboundContainerSetSlotPacket(player1.inventoryMenu.containerId, player1.inventoryMenu.incrementStateId(), index, CraftItemStack.asNMSCopy(item));
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
|
||||
public void hideNPCName(Player player, String NPCName) {
|
||||
//Creating the team
|
||||
PlayerTeam team = new PlayerTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), NPCName);
|
||||
|
||||
//Setting name visibility
|
||||
team.setNameTagVisibility(Team.Visibility.NEVER);
|
||||
|
||||
//Remove the Team (i assume so if it exists)
|
||||
ClientboundSetPlayerTeamPacket removeTeamPacket = ClientboundSetPlayerTeamPacket.createRemovePacket(team);
|
||||
sendPacket(player, removeTeamPacket);
|
||||
//Creating the Team
|
||||
ClientboundSetPlayerTeamPacket createTeamPacket = ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, true);
|
||||
sendPacket(player, createTeamPacket);
|
||||
//Adding players to the team (You have to use the NPC's name, and add it to a list)
|
||||
ClientboundSetPlayerTeamPacket createPlayerTeamPacket = ClientboundSetPlayerTeamPacket.createMultiplePlayerPacket(team, new ArrayList<String>() {{
|
||||
add(NPCName);
|
||||
}}, ClientboundSetPlayerTeamPacket.Action.ADD);
|
||||
sendPacket(player, createPlayerTeamPacket);
|
||||
}
|
||||
|
||||
public void sendPacket(Player player, Packet packet) {
|
||||
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
||||
ServerPlayerConnection connection = serverPlayer.connection;
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user