9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-26 18:39:07 +00:00

Begun working on transitions

This commit is contained in:
LoJoSho
2023-01-07 12:08:59 -06:00
parent c0bca7b3e6
commit 1b802861e3
5 changed files with 106 additions and 52 deletions

View File

@@ -35,6 +35,10 @@ public class WardrobeSettings {
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 final String TRANSITION_PATH = "transition";
private static final String TRANSITION_ENABLE_PATH = "enabled";
private static final String TRANSITION_DELAY_PATH = "delay";
private static final String TRANSITION_TEXT_PATH = "text";
private static ConfigurationNode configRoot;
private static boolean disableOnDamage;
@@ -56,6 +60,9 @@ public class WardrobeSettings {
private static String bossbarMessage;
private static BossBar.Overlay bossbarOverlay;
private static BossBar.Color bossbarColor;
private static boolean enabledTransition;
private static String transitionText;
private static int transitionDelay;
public static void load(ConfigurationNode source) {
configRoot = source;
@@ -88,6 +95,10 @@ public class WardrobeSettings {
bossbarColor = BossBar.Color.YELLOW;
}
ConfigurationNode transitionNode = source.node(TRANSITION_PATH);
enabledTransition = transitionNode.node(TRANSITION_ENABLE_PATH).getBoolean(false);
transitionText = transitionNode.node(TRANSITION_TEXT_PATH).getString("");
transitionDelay = transitionNode.node(TRANSITION_DELAY_PATH).getInt(1);
try {
wardrobeLocation = LocationSerializer.INSTANCE.deserialize(Location.class, source.node(STATIC_LOCATION_PATH));
@@ -186,6 +197,17 @@ public class WardrobeSettings {
public static BossBar.Color getBossbarColor() {
return bossbarColor;
}
public static boolean isEnabledTransition() {
return enabledTransition;
}
public static String getTransitionText() {
return transitionText;
}
public static int getTransitionDelay() {
return transitionDelay;
}
public static void setWardrobeLocation(Location newLocation) {
wardrobeLocation = newLocation;

View File

@@ -199,8 +199,10 @@ public class CosmeticUser {
return;
}
wardrobe = new Wardrobe(this);
wardrobe.start();
if (wardrobe == null) {
wardrobe = new Wardrobe(this);
wardrobe.start();
}
}
public Wardrobe getWardrobe() {

View File

@@ -22,6 +22,8 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@@ -49,9 +51,6 @@ public class Wardrobe {
public void start() {
Player player = VIEWER.getPlayer();
MessagesUtil.sendDebugMessages("start");
MessagesUtil.sendDebugMessages("NPC ID " + NPC_ID);
MessagesUtil.sendDebugMessages("armorstand id " + ARMORSTAND_ID);
this.originalGamemode = player.getGameMode();
if (WardrobeSettings.isReturnLastLocation()) {
@@ -60,62 +59,77 @@ public class Wardrobe {
this.exitLocation = WardrobeSettings.getLeaveLocation();
}
viewingLocation = WardrobeSettings.getViewerLocation();
npcLocation = WardrobeSettings.getWardrobeLocation();
VIEWER.hidePlayer();
List<Player> viewer = List.of(player);
// Armorstand
PacketManager.sendEntitySpawnPacket(WardrobeSettings.getViewerLocation(), ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
PacketManager.sendLookPacket(ARMORSTAND_ID, WardrobeSettings.getViewerLocation(), viewer);
// Player
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
Runnable run = () -> {
// Armorstand
PacketManager.sendEntitySpawnPacket(viewingLocation, ARMORSTAND_ID, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer);
PacketManager.sendInvisibilityPacket(ARMORSTAND_ID, viewer);
PacketManager.sendLookPacket(ARMORSTAND_ID, viewingLocation, viewer);
// NPC
npcName = "WardrobeNPC-" + NPC_ID;
while (npcName.length() > 16) {
npcName = npcName.substring(16);
}
PacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, npcName, viewer);
// Player
PacketManager.gamemodeChangePacket(player, 3);
PacketManager.sendCameraPacket(ARMORSTAND_ID, viewer);
// NPC 2
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
PacketManager.sendFakePlayerSpawnPacket(WardrobeSettings.getWardrobeLocation(), WARDROBE_UUID, NPC_ID, viewer);
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + WardrobeSettings.getWardrobeLocation());
NMSHandlers.getHandler().hideNPCName(player, npcName);
}, 4);
// NPC
npcName = "WardrobeNPC-" + NPC_ID;
while (npcName.length() > 16) {
npcName = npcName.substring(16);
}
PacketManager.sendFakePlayerInfoPacket(player, NPC_ID, WARDROBE_UUID, npcName, viewer);
// Location
PacketManager.sendLookPacket(NPC_ID, WardrobeSettings.getWardrobeLocation(), viewer);
PacketManager.sendRotationPacket(NPC_ID, WardrobeSettings.getWardrobeLocation(), true, viewer);
// NPC 2
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
PacketManager.sendFakePlayerSpawnPacket(npcLocation, WARDROBE_UUID, NPC_ID, viewer);
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
NMSHandlers.getHandler().hideNPCName(player, npcName);
}, 4);
// Misc
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
// Location
PacketManager.sendLookPacket(NPC_ID, npcLocation, viewer);
PacketManager.sendRotationPacket(NPC_ID, npcLocation, true, viewer);
// Misc
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer);
}
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), -1, viewer);
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), NPC_ID, viewer); // This needs a possible fix
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer);
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getModelId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer);
}
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();
};
if (WardrobeSettings.isEnabledTransition()) {
MessagesUtil.sendTitle(VIEWER.getPlayer(), WardrobeSettings.getTransitionText());
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), run, 40);
} else {
run.run();
}
if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), -1, viewer);
PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), NPC_ID, viewer); // This needs a possible fix
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getModelId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
}
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();
}
public void end() {

View File

@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
import com.hibiscusmc.hmccosmetics.hooks.PAPIHook;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.misc.Adventure;
@@ -10,10 +11,12 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.title.Title;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.spongepowered.configurate.ConfigurationNode;
import java.time.Duration;
import java.util.HashMap;
import java.util.logging.Level;
@@ -63,6 +66,15 @@ public class MessagesUtil {
target.sendActionBar(finalMessage);
}
public static void sendTitle(Player player, String message) {
Audience target = BukkitAudiences.create(HMCCosmeticsPlugin.getInstance()).player(player);
Title.Times times = Title.Times.times(Duration.ofMillis(3000), Duration.ofMillis(3000), Duration.ofMillis(1000));
Title title = Title.title(processStringNoKey(player, message), Component.empty(), times);
target.showTitle(title);
}
public static Component processString(Player player, String key) {
return processString(player, key, null);
}

View File

@@ -51,6 +51,10 @@ wardrobe:
text: "Left-Click to open the menu!"
progress: 100
overlay: PROGRESS
transition:
enabled: true
text: "<black>"
delay: 40
wardrobe-location:
world: "World"
x: 0