diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java index 2a2f1664..02c70ad4 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.java @@ -19,6 +19,8 @@ public class WardrobeSettings { private static final String ALWAYS_DISPLAY_PATH = WARDROBE_PATH + ".always-display"; private static final String STATIC_RADIUS_PATH = WARDROBE_PATH + ".static-radius"; private static final String ROTATION_SPEED_PATH = WARDROBE_PATH + ".rotation-speed"; + private static final String SPAWN_DELAY_PATH = WARDROBE_PATH + ".spawn-delay"; + private static final String DESPAWN_DELAY_PATH = WARDROBE_PATH + ".despawn-delay"; private static final String STATIC_LOCATION_PATH = WARDROBE_PATH + ".wardrobe-location"; private static final String VIEWER_LOCATION_PATH = WARDROBE_PATH + ".viewer-location"; private static final String WORLD_PATH = "world"; @@ -37,6 +39,8 @@ public class WardrobeSettings { private boolean alwaysDisplay; private int staticRadius; private int rotationSpeed; + private int spawnDelay; + private int despawnDelay; private Location wardrobeLocation; private Location viewerLocation; @@ -52,6 +56,8 @@ public class WardrobeSettings { this.staticRadius = config.getInt(STATIC_RADIUS_PATH); this.alwaysDisplay = config.getBoolean(ALWAYS_DISPLAY_PATH); this.rotationSpeed = config.getInt(ROTATION_SPEED_PATH); + this.spawnDelay = config.getInt(SPAWN_DELAY_PATH); + this.despawnDelay = config.getInt(DESPAWN_DELAY_PATH); final ConfigurationSection wardrobeLocationSection = config.getConfigurationSection(STATIC_LOCATION_PATH); if (wardrobeLocationSection == null) return; @@ -101,6 +107,14 @@ public class WardrobeSettings { return rotationSpeed; } + public int getSpawnDelay() { + return spawnDelay; + } + + public int getDespawnDelay() { + return despawnDelay; + } + public Location getWardrobeLocation() { return this.wardrobeLocation.clone(); } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java index 814f0065..9745eb9b 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java @@ -102,16 +102,22 @@ public class Wardrobe extends User { this.getUuid() ); - PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket); - this.spawnArmorStand(viewer, this.currentLocation, this.plugin.getSettings().getCosmeticSettings()); - this.updateArmorStand(viewer, plugin.getSettings(), this.currentLocation); - PacketManager.sendPacket( - viewer, - PacketManager.getLookPacket(this.getEntityId(), this.currentLocation), - PacketManager.getRotationPacket(this.getEntityId(), this.currentLocation), - PacketManager.getPlayerOverlayPacket(this.getEntityId()) + + Bukkit.getScheduler().runTaskLaterAsynchronously( + this.plugin, + () -> { + PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket); + this.spawnArmorStand(viewer, this.currentLocation, this.plugin.getSettings().getCosmeticSettings()); + this.updateArmorStand(viewer, plugin.getSettings(), this.currentLocation); + PacketManager.sendPacket( + viewer, + PacketManager.getLookPacket(this.getEntityId(), this.currentLocation), + PacketManager.getRotationPacket(this.getEntityId(), this.currentLocation), + PacketManager.getPlayerOverlayPacket(this.getEntityId()) + ); + }, + settings.getSpawnDelay() ); - viewer.sendMessage("Sent overlay"); this.spawned = true; this.startSpinTask(viewer); @@ -124,25 +130,31 @@ public class Wardrobe extends User { public void despawnFakePlayer(final Player viewer) { final WardrobeSettings settings = this.plugin.getSettings().getWardrobeSettings(); - PacketManager.sendPacket( - viewer, - PacketManager.getEntityDestroyPacket(this.getEntityId()) - // for spectator packets + Bukkit.getScheduler().runTaskLaterAsynchronously( + this.plugin, + () -> { + PacketManager.sendPacket( + viewer, + PacketManager.getEntityDestroyPacket(this.getEntityId()) + // for spectator packets // PacketManager.getEntityDestroyPacket(this.viewerId) - ); - this.showPlayer(this.plugin.getUserManager()); - this.despawnAttached(); - this.active = false; - this.spawned = false; - this.cameraLocked = false; - this.currentLocation = null; - this.getPlayerArmor().clear(); + ); + this.despawnAttached(); + this.showPlayer(this.plugin.getUserManager()); + this.active = false; + this.spawned = false; + this.cameraLocked = false; + this.currentLocation = null; + this.getPlayerArmor().clear(); - if (settings.isAlwaysDisplay()) { - this.currentLocation = settings.getWardrobeLocation(); - if (this.currentLocation == null) return; - this.spawnFakePlayer(viewer); - } + if (settings.isAlwaysDisplay()) { + this.currentLocation = settings.getWardrobeLocation(); + if (this.currentLocation == null) return; + this.spawnFakePlayer(viewer); + } + }, + settings.getDespawnDelay() + ); } private void startSpinTask(final Player player) { diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 8ddeebc9..b796fd5b 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -26,6 +26,10 @@ wardrobe: static-radius: 10 # how much yaw should change per tick, set to 0 for none rotation-speed: 3 + # how long in seconds until the wardrobe should be spawned + spawn-delay: 0 + # how long in seconds until the wardrobe should be despawned + despawn-delay: 0 # location of static wardrobe, remove for none wardrobe-location: world: "World"