From 89825659a6f3fff7b8d338c934147f1f16a95ed5 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Tue, 7 Feb 2023 15:04:17 -0600 Subject: [PATCH] more refactoring --- .../cosmetic/types/CosmeticBalloonType.java | 4 +- .../hmccosmetics/user/CosmeticUser.java | 37 ++++++++++--------- .../user/manager/UserWardrobeManager.java | 20 +++++----- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java index ddf26058..82c4e026 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java @@ -48,11 +48,11 @@ public class CosmeticBalloonType extends Cosmetic { @Override public void update(CosmeticUser user) { Player player = Bukkit.getPlayer(user.getUniqueId()); - UserBalloonManager userBalloonManager = user.getBalloonEntity(); + UserBalloonManager userBalloonManager = user.getBalloonManager(); Location newLocation = player.getLocation(); if (player == null || userBalloonManager == null || newLocation == null) return; if (user.isInWardrobe()) return; - Location currentLocation = user.getBalloonEntity().getLocation(); + Location currentLocation = user.getBalloonManager().getLocation(); newLocation = newLocation.clone().add(Settings.getBalloonOffset()); List viewer = PacketManager.getViewers(player.getLocation()); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index 3f74287a..e509f7f8 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -80,9 +80,6 @@ public class CosmeticUser { public Collection getCosmetic() { return playerCosmetics.values(); } - public UserBalloonManager getBalloonEntity() { - return this.userBalloonManager; - } public void addPlayerCosmetic(Cosmetic cosmetic) { addPlayerCosmetic(cosmetic, null); @@ -206,6 +203,18 @@ public class CosmeticUser { return item; } + public UserBackpackManager getUserBackpackManager() { + return userBackpackManager; + } + + public UserBalloonManager getBalloonManager() { + return this.userBalloonManager; + } + + public UserWardrobeManager getWardrobeManager() { + return userWardrobeManager; + } + public void enterWardrobe() { enterWardrobe(false); } @@ -231,19 +240,15 @@ public class CosmeticUser { } } - public UserWardrobeManager getWardrobe() { - return userWardrobeManager; - } - public void leaveWardrobe() { PlayerWardrobeLeaveEvent event = new PlayerWardrobeLeaveEvent(this); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; } - if (!getWardrobe().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return; + if (!getWardrobeManager().getWardrobeStatus().equals(UserWardrobeManager.WardrobeStatus.RUNNING)) return; - getWardrobe().setWardrobeStatus(UserWardrobeManager.WardrobeStatus.STOPPING); + getWardrobeManager().setWardrobeStatus(UserWardrobeManager.WardrobeStatus.STOPPING); if (WardrobeSettings.isEnabledTransition()) { MessagesUtil.sendTitle( @@ -284,9 +289,7 @@ public class CosmeticUser { userBackpackManager = null; } - public UserBackpackManager getUserBackpackManager() { - return userBackpackManager; - } + public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { Player player = Bukkit.getPlayer(getUniqueId()); @@ -298,7 +301,7 @@ public class CosmeticUser { List viewer = PlayerUtils.getNearbyPlayers(player); viewer.add(player); - PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer); + PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), player.getEntityId(), viewer); } public void despawnBalloon() { @@ -382,9 +385,9 @@ public class CosmeticUser { hideCosmetics = true; hiddenReason = reason; if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - getBalloonEntity().removePlayerFromModel(getPlayer()); + getBalloonManager().removePlayerFromModel(getPlayer()); List viewer = PlayerUtils.getNearbyPlayers(getPlayer()); - PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), -1, viewer); + PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer); } if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { userBackpackManager.getArmorstand().getEquipment().clear(); @@ -406,9 +409,9 @@ public class CosmeticUser { hiddenReason = HiddenReason.NONE; if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON); - getBalloonEntity().addPlayerToModel(this, balloonType); + getBalloonManager().addPlayerToModel(this, balloonType); List viewer = PlayerUtils.getNearbyPlayers(getPlayer()); - PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer); + PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer); } if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK); 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 8f5c23fb..d78653c7 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 @@ -118,12 +118,12 @@ public class UserWardrobeManager { } 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.getBalloonManager().getPufferfishBalloonId(), -1, viewer); + PacketManager.sendLeashPacket(VIEWER.getBalloonManager().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); - VIEWER.getBalloonEntity().getModelEntity().teleport(npcLocation.clone().add(Settings.getBalloonOffset())); + PacketManager.sendTeleportPacket(VIEWER.getBalloonManager().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer); + VIEWER.getBalloonManager().getModelEntity().teleport(npcLocation.clone().add(Settings.getBalloonOffset())); } if (WardrobeSettings.getEnabledBossbar()) { @@ -171,7 +171,7 @@ public class UserWardrobeManager { this.active = false; // NPC - if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), -1, viewer); + if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) PacketManager.sendLeashPacket(VIEWER.getBalloonManager().getModelId(), -1, viewer); PacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success @@ -257,11 +257,11 @@ public class UserWardrobeManager { } if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - PacketManager.sendTeleportPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer); - VIEWER.getBalloonEntity().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset())); - PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), -1, outsideViewers); - PacketManager.sendEntityDestroyPacket(VIEWER.getBalloonEntity().getModelId(), outsideViewers); - PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getPufferfishBalloonId(), NPC_ID, viewer); // Pufferfish goes away for some reason? + PacketManager.sendTeleportPacket(VIEWER.getBalloonManager().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer); + VIEWER.getBalloonManager().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset())); + PacketManager.sendLeashPacket(VIEWER.getBalloonManager().getPufferfishBalloonId(), -1, outsideViewers); + PacketManager.sendEntityDestroyPacket(VIEWER.getBalloonManager().getModelId(), outsideViewers); + PacketManager.sendLeashPacket(VIEWER.getBalloonManager().getPufferfishBalloonId(), NPC_ID, viewer); // Pufferfish goes away for some reason? } if (WardrobeSettings.isEquipPumpkin()) {