9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 12:29:16 +00:00

More checks and does not save invisibility from emote

This commit is contained in:
LoJoSho
2023-02-10 11:30:41 -06:00
parent 300e2cffba
commit db60046701
5 changed files with 37 additions and 6 deletions

View File

@@ -39,7 +39,9 @@ public class Data {
public String steralizeData(CosmeticUser user) {
String data = "";
if (user.getHidden()) {
data = "HIDDEN=" + user.getHiddenReason();
if (shouldHiddenSave(user.getHiddenReason())) {
data = "HIDDEN=" + user.getHiddenReason();
}
}
for (Cosmetic cosmetic : user.getCosmetic()) {
Color color = user.getCosmeticColor(cosmetic.getSlot());
@@ -99,4 +101,15 @@ public class Data {
}
return cosmetics;
}
private boolean shouldHiddenSave(CosmeticUser.HiddenReason reason) {
switch (reason) {
case EMOTE, NONE -> {
return false;
}
default -> {
return true;
}
}
}
}

View File

@@ -58,7 +58,10 @@ public class PlayerConnectionListener implements Listener {
}
}
if (user.isInWardrobe()) user.leaveWardrobe();
if (user.getUserEmoteManager().isPlayingEmote()) user.getUserEmoteManager().stopEmote();
if (user.getUserEmoteManager().isPlayingEmote()) {
user.getUserEmoteManager().stopEmote();
event.getPlayer().setInvisible(false);
}
Database.save(user);
user.destroy();
CosmeticUsers.removeUser(user.getUniqueId());

View File

@@ -14,6 +14,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.gui.Menus;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
@@ -80,8 +81,12 @@ public class PlayerGameListener implements Listener {
public void onPlayerShift(PlayerToggleSneakEvent event) {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (!event.isSneaking()) return;
if (user == null) return;
if (event.isSneaking()) {
user.getUserEmoteManager().stopEmote();
}
if (!event.isSneaking()) return;
if (!user.isInWardrobe()) return;
user.leaveWardrobe();
@@ -197,6 +202,10 @@ public class PlayerGameListener implements Listener {
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId());
if (user == null) return;
// Really need to look into optimization of this
if (user.hasCosmeticInSlot(CosmeticSlot.EMOTE) && event.getPlayer().isSneaking()) {
CosmeticEmoteType cosmeticEmoteType = (CosmeticEmoteType) user.getCosmetic(CosmeticSlot.EMOTE);
cosmeticEmoteType.run(user);
}
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
user.updateCosmetic(CosmeticSlot.OFFHAND);
}, 2);

View File

@@ -15,6 +15,8 @@ public class UserEmoteManager {
public void playEmote(CosmeticEmoteType cosmeticEmoteType) {
MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId());
if (isPlayingEmote()) return;
if (user.isInWardrobe()) return;
try {
model = new UserEmoteModel(user);
model.playAnimation(cosmeticEmoteType.getAnimationId());
@@ -25,10 +27,11 @@ public class UserEmoteManager {
public boolean isPlayingEmote() {
if (model == null) return false;
return true;
return model.isPlayingAnimation();
}
public void stopEmote() {
if (!isPlayingEmote()) return;
model.stopAnimation();
}
}

View File

@@ -81,9 +81,12 @@ public class UserEmoteModel extends PlayerModel {
public void stopAnimation() {
emotePlaying = null;
despawn();
List<Player> viewer = List.of(user.getPlayer());
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
PacketManager.sendCameraPacket(user.getPlayer().getEntityId(), viewer);
if (user.getPlayer() == null) return;
List<Player> viewer = List.of(user.getPlayer());
if (viewer == null) return;
int entityId = user.getPlayer().getEntityId();
PacketManager.sendCameraPacket(entityId, viewer);
PacketManager.sendEntityDestroyPacket(armorstandId, viewer);
if (this.originalGamemode != null) {
PacketManager.gamemodeChangePacket(user.getPlayer(), ServerUtils.convertGamemode(this.originalGamemode));