mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Initial Backpack testing
This commit is contained in:
@@ -33,7 +33,7 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
List<Player> sendTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
Location loc = player.getLocation();
|
||||
|
||||
PacketManager.armorStandMetaPacket((Entity) user.getBackpackEntity(), sendTo);
|
||||
PacketManager.armorStandMetaPacket(user.getBackpackEntity().getBukkitEntity(), sendTo);
|
||||
PacketManager.sendRotationPacket(user.getArmorstandId(), loc, false, sendTo);
|
||||
PacketManager.sendLookPacket(user.getArmorstandId(), loc, sendTo);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hibiscusmc.hmccosmetics.entities;
|
||||
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@@ -22,6 +22,7 @@ public class PlayerConnectionListener implements Listener {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
|
||||
if (user.isInWardrobe()) user.leaveWardrobe();
|
||||
Database.save(user);
|
||||
user.despawnBackpack();
|
||||
CosmeticUsers.removeUser(user.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -70,6 +71,13 @@ public class PlayerGameListener implements Listener {
|
||||
event.getPlayer().sendMessage("Left Wardrobe");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
|
||||
|
||||
user.updateCosmetic();
|
||||
}
|
||||
|
||||
private void registerInventoryClickListener() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) {
|
||||
@Override
|
||||
|
||||
@@ -7,8 +7,10 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.entities.InvisibleArmorstand;
|
||||
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -52,7 +54,7 @@ public class CosmeticUser {
|
||||
playerCosmetics.put(cosmetic.getSlot(), cosmetic);
|
||||
if (cosmetic.getSlot() == CosmeticSlot.BACKPACK) {
|
||||
CosmeticBackpackType backpackType = (CosmeticBackpackType) cosmetic;
|
||||
spawnBackpack();
|
||||
spawnBackpack(backpackType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,15 +123,16 @@ public class CosmeticUser {
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnBackpack() {
|
||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
Player player = Bukkit.getPlayer(getUniqueId());
|
||||
List<Player> sentTo = PlayerUtils.getNearbyPlayers(player.getLocation());
|
||||
|
||||
if (this.invisibleArmorstand != null) return;
|
||||
this.invisibleArmorstand = new InvisibleArmorstand(player.getLocation());
|
||||
invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(cosmeticBackpackType.getBackpackItem()));
|
||||
((CraftWorld) player.getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM);
|
||||
|
||||
PacketManager.armorStandMetaPacket((Entity) invisibleArmorstand, sentTo);
|
||||
PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo);
|
||||
PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo);
|
||||
|
||||
player.addPassenger(invisibleArmorstand.getBukkitEntity());
|
||||
|
||||
Reference in New Issue
Block a user