diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java index 8709390c..60a54443 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -29,6 +29,7 @@ public class Settings { private static final String TICK_PERIOD_PATH = "tick-period"; private static final String UNAPPLY_DEATH_PATH = "unapply-on-death"; private static final String FORCE_PERMISSION_JOIN_PATH = "force-permission-join"; + private static final String EMOTE_DISTANCE_PATH = "emote-distance"; private static String defaultMenu; private static String dyeMenuName; @@ -44,6 +45,7 @@ public class Settings { private static int lookDownPitch; private static int viewDistance; private static int tickPeriod; + private static double emoteDistance; private static Vector balloonOffset; public static void load(ConfigurationNode source) { @@ -70,6 +72,7 @@ public class Settings { requireEmptyBoots = cosmeticSettings.node(REQUIRE_EMPTY_BOOTS_PATH).getBoolean(); unapplyOnDeath = cosmeticSettings.node(UNAPPLY_DEATH_PATH).getBoolean(false); forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false); + emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3); tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1); lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt(); @@ -193,6 +196,10 @@ public class Settings { public static boolean getDebugMode() { return debugMode; } + + public static double getEmoteDistance() { + return emoteDistance; + } public static void setDebugMode(boolean newSetting) { debugMode = newSetting; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java index 0c70421e..9dbe42b6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java @@ -15,8 +15,8 @@ public class UserEmoteManager { public void playEmote(CosmeticEmoteType cosmeticEmoteType) { MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId()); - model = new UserEmoteModel(user); try { + model = new UserEmoteModel(user); model.playAnimation(cosmeticEmoteType.getAnimationId()); } catch (Exception e) { e.printStackTrace(); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java index d2398246..9e232e5e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java @@ -11,6 +11,7 @@ import com.ticxo.playeranimator.api.model.player.PlayerModel; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -36,19 +37,25 @@ public class UserEmoteModel extends PlayerModel { id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits. super.playAnimation(id); emotePlaying = id; - user.getPlayer().setInvisible(true); - user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE); - // Add config option that either allows player to move or forces them into a spot. Player player = user.getPlayer(); List viewer = List.of(user.getPlayer()); Location newLocation = player.getLocation().clone(); newLocation.setPitch(0); - Location behindPlayerLoc = player.getLocation().add(newLocation.getDirection().normalize().multiply(-3)); + double DISTANCE = Settings.getEmoteDistance(); + Location thirdPersonLocation = newLocation.add(newLocation.getDirection().normalize().multiply(DISTANCE)); + if (thirdPersonLocation.getBlock().getType() != Material.AIR) { + stopAnimation(); + MessagesUtil.sendMessage(player, "emote-blocked"); + return; + } + user.getPlayer().setInvisible(true); + user.hideCosmetics(CosmeticUser.HiddenReason.EMOTE); + originalGamemode = player.getGameMode(); - PacketManager.sendEntitySpawnPacket(behindPlayerLoc, armorstandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer); + PacketManager.sendEntitySpawnPacket(thirdPersonLocation, armorstandId, EntityType.ARMOR_STAND, UUID.randomUUID(), viewer); PacketManager.sendInvisibilityPacket(armorstandId, viewer); PacketManager.sendLookPacket(armorstandId, player.getLocation(), viewer); @@ -78,8 +85,10 @@ public class UserEmoteModel extends PlayerModel { Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> { PacketManager.sendCameraPacket(user.getPlayer().getEntityId(), viewer); PacketManager.sendEntityDestroyPacket(armorstandId, viewer); - PacketManager.gamemodeChangePacket(user.getPlayer(), ServerUtils.convertGamemode(this.originalGamemode)); - user.getPlayer().setGameMode(this.originalGamemode); + if (this.originalGamemode != null) { + PacketManager.gamemodeChangePacket(user.getPlayer(), ServerUtils.convertGamemode(this.originalGamemode)); + user.getPlayer().setGameMode(this.originalGamemode); + } if (user.getPlayer() != null) user.getPlayer().setInvisible(false); user.showPlayer(); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java index d78653c7..2b7a9328 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java @@ -240,9 +240,9 @@ public class UserWardrobeManager { PacketManager.sendLookPacket(NPC_ID, location, viewer); VIEWER.hidePlayer(); int rotationSpeed = WardrobeSettings.getRotationSpeed(); - location.setYaw(getNextYaw(yaw - 30, rotationSpeed)); + location.setYaw(ServerUtils.getNextYaw(yaw - 30, rotationSpeed)); PacketManager.sendRotationPacket(NPC_ID, location, true, viewer); - int nextyaw = getNextYaw(yaw, rotationSpeed); + int nextyaw = ServerUtils.getNextYaw(yaw, rotationSpeed); data.set(nextyaw); for (CosmeticSlot slot : CosmeticSlot.values()) { @@ -273,15 +273,6 @@ public class UserWardrobeManager { runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2); } - private static int getNextYaw(final int current, final int rotationSpeed) { - int nextYaw = current + rotationSpeed; - if (nextYaw > 179) { - nextYaw = (current + rotationSpeed) - 358; - return nextYaw; - } - return nextYaw; - } - public int getArmorstandId() { return ARMORSTAND_ID; } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/ServerUtils.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/ServerUtils.java index f756bb69..a7896503 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/ServerUtils.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/ServerUtils.java @@ -137,4 +137,13 @@ public class ServerUtils { } } } + + public static int getNextYaw(final int current, final int rotationSpeed) { + int nextYaw = current + rotationSpeed; + if (nextYaw > 179) { + nextYaw = (current + rotationSpeed) - 358; + return nextYaw; + } + return nextYaw; + } } diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 18644b68..95f31134 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -23,6 +23,8 @@ cosmetic-settings: unapply-on-death: false # If when a player dies, their cosmetics should be unapplied. If this is true, use hmccosmetics.unapplydeath.bypass to bypass force-permission-join: true # Checks a player permission if they can have a cosmetic when they join the server. + emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player. + # view distance in blocks that other players will see the backpack cosmetic # setting this to lower than the server player view distance should fix the # bug where players see random backpacks. Put -1 to ignore and send packets to everyone. diff --git a/common/src/main/resources/messages.yml b/common/src/main/resources/messages.yml index 3623f814..d1377471 100644 --- a/common/src/main/resources/messages.yml +++ b/common/src/main/resources/messages.yml @@ -17,6 +17,8 @@ unequip-cosmetic: "%prefix% You have unequipped Hidden cosmetics" show-cosmetic: "%prefix% Revealed cosmetics!" +emote-blocked: "%prefix% You can not use your emote here!" + invalid-slot: "%prefix% Invalid cosmetic slot!" invalid-player: "%prefix% Invalid Player!" invalid-menu: "%prefix% Invalid Menu!"