DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
DreamArmorStand.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamArmorStand;
25
26import com.dreamfirestudios.dreamcore.DreamChat.DreamMessageFormatter;
27import com.dreamfirestudios.dreamcore.DreamChat.DreamMessageSettings;
28import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
29import org.bukkit.Location;
30import org.bukkit.entity.ArmorStand;
31import org.bukkit.inventory.ItemStack;
32
33import java.util.Objects;
34
40public class DreamArmorStand {
41
51 public static void equipArmorStand(ArmorStand armorStand, ItemStack item, ArmorStandSlot slot) {
52 if (armorStand == null || item == null) throw new IllegalArgumentException("ArmorStand or Item cannot be null");
53
54 switch (slot) {
55 case HEAD -> armorStand.getEquipment().setHelmet(item);
56 case CHEST -> armorStand.getEquipment().setChestplate(item);
57 case LEGS -> armorStand.getEquipment().setLeggings(item);
58 case FEET -> armorStand.getEquipment().setBoots(item);
59 case HAND -> armorStand.getEquipment().setItemInMainHand(item);
60 case OFFHAND -> armorStand.getEquipment().setItemInOffHand(item);
61 default -> throw new IllegalArgumentException("Unknown ArmorStand slot: " + slot);
62 }
63
64 new ArmorStandEqippedEvent(armorStand, item, slot);
65 }
66
78 public static void setPose(ArmorStand armorStand, ArmorStandPose pose, float angleX, float angleY, float angleZ) {
79 if (armorStand == null || pose == null) throw new IllegalArgumentException("ArmorStand or Pose cannot be null");
80
81 var rotation = new org.bukkit.util.EulerAngle(Math.toRadians(angleX), Math.toRadians(angleY), Math.toRadians(angleZ));
82
83 switch (pose) {
84 case HEAD -> armorStand.setHeadPose(rotation);
85 case BODY -> armorStand.setBodyPose(rotation);
86 case LEFT_ARM -> armorStand.setLeftArmPose(rotation);
87 case RIGHT_ARM -> armorStand.setRightArmPose(rotation);
88 case LEFT_LEG -> armorStand.setLeftLegPose(rotation);
89 case RIGHT_LEG -> armorStand.setRightLegPose(rotation);
90 }
91
92 new ArmorStandPosedEvent(armorStand, pose, angleX, angleY, angleZ);
93 }
94
102 public static void toggleVisibility(ArmorStand armorStand) {
103 if (armorStand == null) throw new IllegalArgumentException("ArmorStand cannot be null");
104 armorStand.setVisible(!armorStand.isVisible());
105 }
106
114 public static void disableGravity(ArmorStand armorStand) {
115 if (armorStand == null) throw new IllegalArgumentException("ArmorStand cannot be null");
116 armorStand.setGravity(false);
117 }
118
126 public static void enableGravity(ArmorStand armorStand) {
127 if (armorStand == null) throw new IllegalArgumentException("ArmorStand cannot be null");
128 armorStand.setGravity(true);
129 }
130
139 public static void setGlowing(ArmorStand armorStand, boolean glowing) {
140 if (armorStand == null) throw new IllegalArgumentException("ArmorStand cannot be null");
141 armorStand.setGlowing(glowing);
142 new ArmorStandGlowEvent(armorStand, glowing);
143 }
144
153 public static void teleportArmorStand(ArmorStand armorStand, Location newLocation) {
154 if (armorStand == null || newLocation == null) throw new IllegalArgumentException("ArmorStand or Location cannot be null");
155 armorStand.teleport(newLocation);
156 }
157
166 public static void setCustomName(ArmorStand armorStand, String customName) {
167 if (armorStand == null || customName == null) throw new IllegalArgumentException("ArmorStand or CustomName cannot be null");
168 armorStand.customName(DreamMessageFormatter.format(customName, DreamMessageSettings.all()));
169 }
170
179 public static ArmorStand cloneArmorStand(ArmorStand original) {
180 if (original == null) throw new IllegalArgumentException("Original ArmorStand cannot be null");
181 Location loc = original.getLocation();
182 return new DreamfireArmorStandBuilder(loc)
183 .visible(original.isVisible())
184 .customNameVisible(original.isCustomNameVisible())
185 .customName(PlainTextComponentSerializer.plainText().serialize(Objects.requireNonNull(original.customName())))
186 .canPickupItems(original.getCanPickupItems())
187 .gravity(original.hasGravity())
188 .arms(original.hasArms())
189 .basePlate(original.hasBasePlate())
190 .small(original.isSmall())
191 .marker(original.isMarker())
192 .glowing(original.isGlowing())
193 .build();
194 }
195}
Event fired when an ArmorStand is equipped with an item in a specific slot.
Event fired when an ArmorStand has its glowing state changed.
Event fired when an ArmorStand has one of its poses changed.
Utility class for performing operations on ArmorStand entities, such as equipping items,...
static void toggleVisibility(ArmorStand armorStand)
Toggles the visibility of the armor stand.
static void disableGravity(ArmorStand armorStand)
Disables gravity for the armor stand.
static void setGlowing(ArmorStand armorStand, boolean glowing)
Sets the glowing effect for the armor stand.
static void setPose(ArmorStand armorStand, ArmorStandPose pose, float angleX, float angleY, float angleZ)
Sets the pose of the armor stand.
static void equipArmorStand(ArmorStand armorStand, ItemStack item, ArmorStandSlot slot)
Equips an armor stand with an item in a specific slot.
static void setCustomName(ArmorStand armorStand, String customName)
Sets a custom name for the armor stand.
static void teleportArmorStand(ArmorStand armorStand, Location newLocation)
Teleports the armor stand to a new location.
static ArmorStand cloneArmorStand(ArmorStand original)
Clones an armor stand by creating a new instance with the same properties.
static void enableGravity(ArmorStand armorStand)
Enables gravity for the armor stand.
A builder class for creating and configuring ArmorStand instances.
DreamfireArmorStandBuilder visible(boolean isVisible)
Sets the visibility of the armor stand.
Represents the different body parts of an org.bukkit.entity.ArmorStand that can be posed or animated.
Represents the equipment slots of an org.bukkit.entity.ArmorStand.