mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-22 16:39:21 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33437cd387 | ||
|
|
9f4e4616d4 | ||
|
|
01c62bc94e | ||
|
|
3be4bdeb6f | ||
|
|
145aec9b7f | ||
|
|
4a2266bbfa | ||
|
|
7fa3cd6cb7 | ||
|
|
9c5fe9c426 | ||
|
|
0a9d750d3e | ||
|
|
da996fb146 |
@@ -8,7 +8,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.hibiscusmc"
|
||||
version = "2.6.1"
|
||||
version = "2.6.2"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "java")
|
||||
@@ -63,6 +63,9 @@ allprojects {
|
||||
|
||||
// md-5 Repo
|
||||
maven("https://repo.md-5.net/content/groups/public/")
|
||||
|
||||
// MMOItems
|
||||
maven("https://nexus.phoenixdevt.fr/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -175,7 +178,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.
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public class Settings {
|
||||
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_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments";
|
||||
private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments";
|
||||
@@ -107,6 +108,8 @@ public class Settings {
|
||||
@Getter
|
||||
private static int tickPeriod;
|
||||
@Getter
|
||||
private static int packetEntityTeleportCooldown;
|
||||
@Getter
|
||||
private static double emoteDistance;
|
||||
@Getter
|
||||
private static Vector balloonOffset;
|
||||
@@ -173,6 +176,7 @@ 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);
|
||||
|
||||
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;
|
||||
@Getter
|
||||
private final String id;
|
||||
@Getter @Setter
|
||||
private int distance = WardrobeSettings.getDisplayRadius();
|
||||
@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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,16 +31,12 @@ 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());
|
||||
}
|
||||
|
||||
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,7 +53,7 @@ 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.sendArmorstandMetadata(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ public class PlayerGameListener implements Listener {
|
||||
public PlayerGameListener() {
|
||||
registerInventoryClickListener();
|
||||
registerMenuChangeListener();
|
||||
registerEntityStatusListener();
|
||||
registerPlayerEquipmentListener();
|
||||
registerPlayerArmListener();
|
||||
registerEntityUseListener();
|
||||
@@ -483,6 +484,22 @@ public class PlayerGameListener implements Listener {
|
||||
List<com.comphenix.protocol.wrappers.Pair<EnumWrappers.ItemSlot, ItemStack>> armor = event.getPacket().getSlotStackPairLists().read(0);
|
||||
|
||||
for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) {
|
||||
if (equipmentSlot.equals(EquipmentSlot.HAND)) {
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(EnumWrappers.ItemSlot.MAINHAND, user.getPlayer().getInventory().getItemInMainHand());
|
||||
armor.add(pair);
|
||||
continue;
|
||||
}
|
||||
if (equipmentSlot.equals(EquipmentSlot.OFF_HAND)) {
|
||||
ItemStack item = null;
|
||||
if (user.getPlayer().getInventory().getItemInOffHand().getType().isAir()) {
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) item = user.getUserCosmeticItem(CosmeticSlot.OFFHAND);
|
||||
} else {
|
||||
item = user.getPlayer().getInventory().getItemInOffHand();
|
||||
}
|
||||
Pair<EnumWrappers.ItemSlot, ItemStack> pair = new Pair<>(EnumWrappers.ItemSlot.OFFHAND, item);
|
||||
armor.add(pair);
|
||||
continue;
|
||||
}
|
||||
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());
|
||||
@@ -495,6 +512,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 +576,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 +593,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,8 +18,6 @@ public interface NMSHandler {
|
||||
|
||||
Entity getEntity(int entityId);
|
||||
|
||||
Entity getHMCArmorStand(Location loc);
|
||||
|
||||
ArmorStand getMEGEntity(Location loc);
|
||||
|
||||
Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType);
|
||||
@@ -29,14 +26,6 @@ public interface NMSHandler {
|
||||
|
||||
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,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() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserBalloonPufferfish extends UserEntity {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -18,8 +18,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;
|
||||
@@ -138,7 +136,7 @@ public class PacketManager extends BasePacket {
|
||||
} else {
|
||||
final List<WrappedDataValue> wrappedDataValueList = Lists.newArrayList();
|
||||
wrappedDataValueList.add(new WrappedDataValue(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x20));
|
||||
wrapper.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) 0x10);
|
||||
wrappedDataValueList.add(new WrappedDataValue(15, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0x10));
|
||||
packet.getDataValueCollectionModifier().write(0, wrappedDataValueList);
|
||||
}
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
|
||||
@@ -35,6 +35,9 @@ 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
|
||||
|
||||
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.
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
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;
|
||||
@@ -55,18 +50,12 @@ 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();
|
||||
@@ -105,54 +94,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,14 +1,9 @@
|
||||
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;
|
||||
@@ -55,18 +50,12 @@ 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();
|
||||
@@ -107,54 +96,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,14 +1,9 @@
|
||||
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;
|
||||
@@ -55,18 +50,12 @@ 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();
|
||||
@@ -106,55 +95,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,14 +1,9 @@
|
||||
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,18 +53,12 @@ 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();
|
||||
@@ -115,54 +104,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,14 +1,9 @@
|
||||
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,18 +52,12 @@ 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();
|
||||
@@ -116,54 +105,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(
|
||||
|
||||
Reference in New Issue
Block a user