-
Notifications
You must be signed in to change notification settings - Fork 529
/
ArmorStandUtils.java
73 lines (65 loc) · 2.82 KB
/
ArmorStandUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package io.github.thebusybiscuit.slimefun4.utils;
import javax.annotation.Nonnull;
import io.papermc.lib.PaperLib;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import io.github.thebusybiscuit.slimefun4.core.services.holograms.HologramsService;
import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.HologramProjector;
/**
* This class holds utilities for {@link ArmorStand}, useful for classes
* dealing with {@link ArmorStand}s that are not from {@link HologramsService}
*
* @see HologramProjector
* @see AncientPedestal
*
* @author JustAHuman
*/
public class ArmorStandUtils {
/**
* Spawns an {@link ArmorStand} at the given {@link Location} with the given custom name
* <br>
* Set Properties: Invisible, Silent, Marker, No-Gravity, No Base Plate, Don't Remove When Far Away
*
* @param location The {@link Location} to spawn the {@link ArmorStand}
* @param customName The {@link String} custom name the {@link ArmorStand} should display
*
* @return The spawned {@link ArmorStand}
*/
public static @Nonnull ArmorStand spawnArmorStand(@Nonnull Location location, @Nonnull String customName) {
ArmorStand armorStand = spawnArmorStand(location);
armorStand.setCustomName(customName);
armorStand.setCustomNameVisible(true);
return armorStand;
}
/**
* Spawns an {@link ArmorStand} at the given {@link Location}
* <br>
* Set Properties: Invisible, Silent, Marker, No-Gravity, No Base Plate, Don't Remove When Far Away
*
* @param location The {@link Location} to spawn the {@link ArmorStand}
*
* @return The spawned {@link ArmorStand}
*/
public static @Nonnull ArmorStand spawnArmorStand(@Nonnull Location location) {
// The consumer method was moved from World to RegionAccessor in 1.20.2
// Due to this, we need to use a rubbish workaround to support 1.20.1 and below
// This causes flicker on these versions which sucks but not sure a better way around this right now.
if (PaperLib.getMinecraftVersion() <= 20
&& PaperLib.getMinecraftPatchVersion() < 2
) {
ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class);
setupArmorStand(armorStand);
return armorStand;
}
return location.getWorld().spawn(location, ArmorStand.class, armorStand -> setupArmorStand(armorStand));
}
private static void setupArmorStand(ArmorStand armorStand) {
armorStand.setVisible(false);
armorStand.setSilent(true);
armorStand.setMarker(true);
armorStand.setGravity(false);
armorStand.setBasePlate(false);
armorStand.setRemoveWhenFarAway(false);
}
}