9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

Carved Pumpkin Config Option now works

This commit is contained in:
LoJoSho
2022-12-28 14:51:40 -06:00
parent 69ed099c9a
commit c3ccd6b9a4
3 changed files with 49 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.List; import java.util.List;
@@ -37,6 +38,13 @@ public interface NMSHandler {
int slot int slot
); );
void equipmentSlotUpdate(
int entityId,
org.bukkit.inventory.EquipmentSlot slot,
ItemStack item,
List<Player> sendTo
);
default boolean getSupported () { default boolean getSupported () {
return false; return false;
} }

View File

@@ -11,8 +11,11 @@ import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.List; import java.util.List;
@@ -137,7 +140,13 @@ public class Wardrobe {
player.teleport(exitLocation); player.teleport(exitLocation);
} }
if (!player.isOnline()) return; if (!player.isOnline()) return;
if (WardrobeSettings.isEquipPumpkin()) {
NMSHandlers.getHandler().equipmentSlotUpdate(VIEWER.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
}
VIEWER.updateCosmetic(); VIEWER.updateCosmetic();
MessagesUtil.sendMessage(player, "closed-wardrobe"); MessagesUtil.sendMessage(player, "closed-wardrobe");
} }
@@ -160,7 +169,7 @@ public class Wardrobe {
location.setYaw(yaw); location.setYaw(yaw);
PacketManager.sendLookPacket(NPC_ID, location, viewer); PacketManager.sendLookPacket(NPC_ID, location, viewer);
VIEWER.updateCosmetic(); //VIEWER.updateCosmetic();
int rotationSpeed = WardrobeSettings.getRotationSpeed(); int rotationSpeed = WardrobeSettings.getRotationSpeed();
location.setYaw(getNextYaw(yaw - 30, rotationSpeed)); location.setYaw(getNextYaw(yaw - 30, rotationSpeed));
PacketManager.sendRotationPacket(NPC_ID, location, true, viewer); PacketManager.sendRotationPacket(NPC_ID, location, true, viewer);
@@ -182,6 +191,10 @@ public class Wardrobe {
VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset())); VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()));
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); // Pufferfish goes away for some reason? //PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); // Pufferfish goes away for some reason?
} }
if (WardrobeSettings.isEquipPumpkin()) {
NMSHandlers.getHandler().equipmentSlotUpdate(VIEWER.getPlayer().getEntityId(), EquipmentSlot.HEAD, new ItemStack(Material.CARVED_PUMPKIN), viewer);
}
} }
}; };

View File

@@ -156,6 +156,33 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
for (Player p : sendTo) sendPacket(p, packet); for (Player p : sendTo) sendPacket(p, packet);
} }
@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 @Override
public void slotUpdate( public void slotUpdate(
Player player, Player player,