mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
Configurable bossbar in wardrobe
This commit is contained in:
@@ -4,6 +4,8 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.misc.Utils;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
@@ -27,6 +29,12 @@ public class WardrobeSettings {
|
||||
private static final String LEAVE_LOCATION_PATH = "leave-location";
|
||||
private static final String EQUIP_PUMPKIN_WARDROBE = "equip-pumpkin";
|
||||
private static final String RETURN_LAST_LOCATION = "return-last-location";
|
||||
private static final String BOSSBAR_PATH = "bossbar";
|
||||
private static final String BOSSBAR_ENABLE_PATH = "enabled";
|
||||
private static final String BOSSBAR_TEXT_PATH = "text";
|
||||
private static final String BOSSBAR_PROGRESS_PATH = "progress";
|
||||
private static final String BOSSBAR_OVERLAY_PATH = "overlay";
|
||||
private static final String BOSSBAR_COLOR_PATH = "color";
|
||||
|
||||
private static ConfigurationNode configRoot;
|
||||
private static boolean disableOnDamage;
|
||||
@@ -37,12 +45,17 @@ public class WardrobeSettings {
|
||||
private static int rotationSpeed;
|
||||
private static int spawnDelay;
|
||||
private static int despawnDelay;
|
||||
private static float bossbarProgress;
|
||||
private static boolean applyCosmeticsOnClose;
|
||||
private static boolean equipPumpkin;
|
||||
private static boolean returnLastLocation;
|
||||
private static boolean enabledBossbar;
|
||||
private static Location wardrobeLocation;
|
||||
private static Location viewerLocation;
|
||||
private static Location leaveLocation;
|
||||
private static String bossbarMessage;
|
||||
private static BossBar.Overlay bossbarOverlay;
|
||||
private static BossBar.Color bossbarColor;
|
||||
|
||||
public static void load(ConfigurationNode source) {
|
||||
configRoot = source;
|
||||
@@ -57,7 +70,25 @@ public class WardrobeSettings {
|
||||
despawnDelay = source.node(DESPAWN_DELAY_PATH).getInt();
|
||||
applyCosmeticsOnClose = source.node(APPLY_COSMETICS_ON_CLOSE).getBoolean();
|
||||
equipPumpkin = source.node(EQUIP_PUMPKIN_WARDROBE).getBoolean();
|
||||
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean();
|
||||
returnLastLocation = source.node(RETURN_LAST_LOCATION).getBoolean(false);
|
||||
|
||||
ConfigurationNode bossBarNode = source.node(BOSSBAR_PATH);
|
||||
enabledBossbar = bossBarNode.node(BOSSBAR_ENABLE_PATH).getBoolean(false);
|
||||
bossbarProgress = bossBarNode.node(BOSSBAR_PROGRESS_PATH).getFloat(1.0f);
|
||||
bossbarMessage = bossBarNode.node(BOSSBAR_TEXT_PATH).getString("");
|
||||
if (EnumUtils.isValidEnum(BossBar.Overlay.class, bossBarNode.node(BOSSBAR_OVERLAY_PATH).getString(""))) {
|
||||
bossbarOverlay = BossBar.Overlay.valueOf(bossBarNode.node(BOSSBAR_OVERLAY_PATH).getString(""));
|
||||
} else {
|
||||
bossbarOverlay = BossBar.Overlay.PROGRESS;
|
||||
}
|
||||
|
||||
if (EnumUtils.isValidEnum(BossBar.Color.class, bossBarNode.node(BOSSBAR_COLOR_PATH).getString())) {
|
||||
bossbarColor = BossBar.Color.valueOf(bossBarNode.node(BOSSBAR_COLOR_PATH).getString());
|
||||
} else {
|
||||
bossbarColor = BossBar.Color.YELLOW;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
wardrobeLocation = LocationSerializer.INSTANCE.deserialize(Location.class, source.node(STATIC_LOCATION_PATH));
|
||||
MessagesUtil.sendDebugMessages("Wardrobe Location: " + wardrobeLocation);
|
||||
@@ -136,6 +167,26 @@ public class WardrobeSettings {
|
||||
return wardrobeLocation.distanceSquared(location) <= staticRadius * staticRadius;
|
||||
}
|
||||
|
||||
public static boolean getEnabledBossbar() {
|
||||
return enabledBossbar;
|
||||
}
|
||||
|
||||
public static float getBossbarProgress() {
|
||||
return bossbarProgress;
|
||||
}
|
||||
|
||||
public static String getBossbarText() {
|
||||
return bossbarMessage;
|
||||
}
|
||||
|
||||
public static BossBar.Overlay getBossbarOverlay() {
|
||||
return bossbarOverlay;
|
||||
}
|
||||
|
||||
public static BossBar.Color getBossbarColor() {
|
||||
return bossbarColor;
|
||||
}
|
||||
|
||||
public static void setWardrobeLocation(Location newLocation) {
|
||||
wardrobeLocation = newLocation;
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@@ -33,6 +37,7 @@ public class Wardrobe {
|
||||
private Location viewingLocation;
|
||||
private Location npcLocation;
|
||||
private Location exitLocation;
|
||||
private BossBar bossBar;
|
||||
private boolean active;
|
||||
|
||||
public Wardrobe(CosmeticUser user) {
|
||||
@@ -102,6 +107,17 @@ public class Wardrobe {
|
||||
|
||||
}
|
||||
|
||||
if (WardrobeSettings.getEnabledBossbar()) {
|
||||
|
||||
float progress = WardrobeSettings.getBossbarProgress();
|
||||
Component message = MessagesUtil.processStringNoKey(WardrobeSettings.getBossbarText());
|
||||
|
||||
bossBar = BossBar.bossBar(message, progress, WardrobeSettings.getBossbarColor(), WardrobeSettings.getBossbarOverlay());
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.showBossBar(bossBar);
|
||||
}
|
||||
|
||||
MessagesUtil.sendMessage(player, "opened-wardrobe");
|
||||
this.active = true;
|
||||
update();
|
||||
@@ -151,6 +167,12 @@ public class Wardrobe {
|
||||
NMSHandlers.getHandler().equipmentSlotUpdate(VIEWER.getPlayer().getEntityId(), EquipmentSlot.HEAD, player.getInventory().getHelmet(), viewer);
|
||||
}
|
||||
|
||||
if (WardrobeSettings.getEnabledBossbar()) {
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.hideBossBar(bossBar);
|
||||
}
|
||||
|
||||
VIEWER.updateCosmetic();
|
||||
|
||||
MessagesUtil.sendMessage(player, "closed-wardrobe");
|
||||
|
||||
@@ -34,22 +34,14 @@ public class MessagesUtil {
|
||||
}
|
||||
|
||||
public static void sendMessage(Player player, String key) {
|
||||
if (!messages.containsKey(key)) return;
|
||||
if (messages.get(key) == null) return;
|
||||
String message = messages.get(key);
|
||||
message = message.replaceAll("%prefix%", prefix);
|
||||
Component finalMessage = Adventure.MINI_MESSAGE.deserialize(message);
|
||||
Component finalMessage = processString(key);
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String key) {
|
||||
if (!messages.containsKey(key)) return;
|
||||
if (messages.get(key) == null) return;
|
||||
String message = messages.get(key);
|
||||
message = message.replaceAll("%prefix%", prefix);
|
||||
Component finalMessage = Adventure.MINI_MESSAGE.deserialize(message);
|
||||
Component finalMessage = processString(key);
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).sender(sender);
|
||||
|
||||
target.sendMessage(finalMessage);
|
||||
@@ -67,16 +59,25 @@ public class MessagesUtil {
|
||||
}
|
||||
|
||||
public static void sendActionBar(Player player, String key) {
|
||||
if (!messages.containsKey(key)) return;
|
||||
if (messages.get(key) == null) return;
|
||||
String message = messages.get(key);
|
||||
message = message.replaceAll("%prefix%", prefix);
|
||||
Component finalMessage = Adventure.MINI_MESSAGE.deserialize(message);
|
||||
Component finalMessage = processString(key);
|
||||
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
|
||||
|
||||
target.sendActionBar(finalMessage);
|
||||
}
|
||||
|
||||
public static Component processString(String key) {
|
||||
if (!messages.containsKey(key)) return null;
|
||||
if (messages.get(key) == null) return null;
|
||||
String message = messages.get(key);
|
||||
message = message.replaceAll("%prefix%", prefix);
|
||||
return Adventure.MINI_MESSAGE.deserialize(message);
|
||||
}
|
||||
|
||||
public static Component processStringNoKey(String message) {
|
||||
message = message.replaceAll("%prefix%", prefix);
|
||||
return Adventure.MINI_MESSAGE.deserialize(message);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void sendDebugMessages(String message) {
|
||||
|
||||
Reference in New Issue
Block a user