mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-30 04:19:28 +00:00
Added "ticking" to users to hopefully fix issues with cosmetics sometimes not showing
This commit is contained in:
@@ -23,7 +23,7 @@ public class CosmeticArmorType extends Cosmetic {
|
||||
@Override
|
||||
public void update(CosmeticUser user) {
|
||||
Player player = Bukkit.getPlayer(user.getUniqueId());
|
||||
PacketManager.equipmentSlotUpdate(player, getSlot(), PlayerUtils.getNearbyPlayers(player));
|
||||
PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation()));
|
||||
}
|
||||
|
||||
public EquipmentSlot getEquipSlot() {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CosmeticBalloonType extends Cosmetic {
|
||||
if (player == null) return;
|
||||
if (user.isInWardrobe()) return;
|
||||
|
||||
List<Player> viewer = PlayerUtils.getNearbyPlayers(player);
|
||||
List<Player> viewer = PacketManager.getViewers(player.getLocation());
|
||||
viewer.add(player);
|
||||
|
||||
BalloonEntity balloonEntity = user.getBalloonEntity();
|
||||
|
||||
@@ -49,6 +49,7 @@ public class PlayerConnectionListener implements Listener {
|
||||
Database.save(user);
|
||||
user.despawnBackpack();
|
||||
user.despawnBalloon();
|
||||
user.destroy();
|
||||
CosmeticUsers.removeUser(user.getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,9 @@ public class PlayerGameListener implements Listener {
|
||||
registerPlayerEquipmentListener();
|
||||
registerPlayerArmListener();
|
||||
|
||||
registerLookMovement();
|
||||
registerMoveListener();
|
||||
registerTeleportMovement();
|
||||
//registerLookMovement();
|
||||
//registerMoveListener();
|
||||
//registerTeleportMovement();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -98,7 +98,7 @@ public class PlayerGameListener implements Listener {
|
||||
user.getBackpackEntity().teleport(event.getTo());
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.showBackpack();
|
||||
user.updateCosmetic();
|
||||
}, 2);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ public class PlayerGameListener implements Listener {
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
user.addPlayerCosmetic(cosmetic, color);
|
||||
user.updateCosmetic();
|
||||
}, 4);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.*;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.config.WardrobeSettings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
@@ -24,12 +25,17 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CosmeticUser {
|
||||
|
||||
private UUID uniqueId;
|
||||
private int taskId;
|
||||
private HashMap<CosmeticSlot, Cosmetic> playerCosmetics = new HashMap<>();
|
||||
private Wardrobe wardrobe;
|
||||
private ArmorStand invisibleArmorstand;
|
||||
@@ -41,13 +47,30 @@ public class CosmeticUser {
|
||||
private HashMap<CosmeticSlot, Color> colors = new HashMap<>();
|
||||
|
||||
public CosmeticUser() {
|
||||
hideBackpack = false;
|
||||
hideCosmetics = false;
|
||||
// Empty
|
||||
}
|
||||
|
||||
|
||||
public CosmeticUser(UUID uuid) {
|
||||
this.uniqueId = uuid;
|
||||
tick();
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
// Occasionally updates the entity cosmetics
|
||||
Runnable run = () -> {
|
||||
MessagesUtil.sendDebugMessages("tick " + uniqueId, Level.INFO);
|
||||
updateCosmetic();
|
||||
};
|
||||
|
||||
int tickPeriod = Settings.getTickPeriod();
|
||||
if (tickPeriod > 0) {
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(HMCCosmeticsPlugin.getInstance(), run, 0, tickPeriod);
|
||||
taskId = task.getTaskId();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
Bukkit.getScheduler().cancelTask(taskId);
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
|
||||
@@ -431,7 +431,7 @@ public class PacketManager extends BasePacket {
|
||||
sendMovePacket(entityId, from, to, onGround, getViewers(to));
|
||||
}
|
||||
|
||||
private static List<Player> getViewers(Location location) {
|
||||
public static List<Player> getViewers(Location location) {
|
||||
ArrayList<Player> viewers = new ArrayList();
|
||||
if (Settings.getViewDistance() <= 0) {
|
||||
viewers.addAll(location.getWorld().getPlayers());
|
||||
|
||||
Reference in New Issue
Block a user