mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 03:49:19 +00:00
Fixed backpack being removed and not respawned on teleport
This commit is contained in:
@@ -4,6 +4,7 @@ import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import com.sun.tools.jconsole.JConsoleContext;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.concurrent.Threads;
|
||||
import io.github.fisher2911.hmccosmetics.database.dao.ArmorItemDAO;
|
||||
@@ -18,6 +19,7 @@ import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class Database {
|
||||
|
||||
@@ -71,7 +73,7 @@ public class Database {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadUser(final UUID uuid) {
|
||||
public void loadUser(final UUID uuid, final Consumer<User> onComplete) {
|
||||
final int armorStandId = ARMOR_STAND_ID.getAndDecrement();
|
||||
Threads.getInstance().execute(
|
||||
() -> {
|
||||
@@ -84,11 +86,14 @@ public class Database {
|
||||
|
||||
final List<ArmorItemDAO> armorItems = this.armorItemDao.queryForEq("uuid", uuid.toString());
|
||||
|
||||
final UserDAO finalUser = user;
|
||||
final User actualUser = user.toUser(this.plugin.getCosmeticManager(), armorItems, armorStandId);
|
||||
Bukkit.getScheduler().runTask(this.plugin,
|
||||
() -> this.plugin.getUserManager().add(
|
||||
finalUser.toUser(this.plugin.getCosmeticManager(), armorItems, armorStandId)
|
||||
)
|
||||
() -> {
|
||||
this.plugin.getUserManager().add(
|
||||
actualUser
|
||||
);
|
||||
onComplete.accept(actualUser);
|
||||
}
|
||||
);
|
||||
|
||||
} catch (final SQLException exception) {
|
||||
@@ -96,7 +101,9 @@ public class Database {
|
||||
}
|
||||
});
|
||||
|
||||
this.plugin.getUserManager().add(new User(uuid, PlayerArmor.empty(), armorStandId));
|
||||
final User user = new User(uuid, PlayerArmor.empty(), armorStandId);
|
||||
this.plugin.getUserManager().add(user);
|
||||
onComplete.accept(user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,9 @@ public class JoinListener implements Listener {
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
this.database.loadUser(player.getUniqueId());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin,
|
||||
() -> this.userManager.resendCosmetics(player));
|
||||
this.database.loadUser(player.getUniqueId(),
|
||||
user -> Bukkit.getScheduler().runTaskAsynchronously(this.plugin,
|
||||
() -> this.userManager.resendCosmetics(player)));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -20,15 +20,7 @@ import java.util.UUID;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
private static final ProtocolManager protocolManager;
|
||||
|
||||
static {
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
}
|
||||
|
||||
public static PacketContainer getEntitySpawnPacket(final Location location, final int entityId, final EntityType entityType) {
|
||||
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
final PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
|
||||
// Entity ID
|
||||
@@ -89,6 +81,7 @@ public class PacketManager {
|
||||
}
|
||||
|
||||
public static void sendPacket(final Player to, final PacketContainer... packets) {
|
||||
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
try {
|
||||
for (final PacketContainer packet : packets) {
|
||||
protocolManager.sendServerPacket(to, packet);
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
||||
@@ -82,7 +83,7 @@ public class User {
|
||||
|
||||
final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, this.armorStandId, EntityType.ARMOR_STAND);
|
||||
|
||||
PacketManager.sendPacket(player, packet);
|
||||
PacketManager.sendPacket(other, packet);
|
||||
}
|
||||
|
||||
public void spawnArmorStand() {
|
||||
@@ -101,7 +102,7 @@ public class User {
|
||||
public void updateArmorStand() {
|
||||
if (!this.hasArmorStand) {
|
||||
this.spawnArmorStand();
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
@@ -136,6 +137,7 @@ public class User {
|
||||
|
||||
public void despawnAttached() {
|
||||
PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.armorStandId));
|
||||
this.hasArmorStand = false;
|
||||
}
|
||||
|
||||
public boolean hasArmorStand() {
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class UserManager {
|
||||
|
||||
@@ -39,7 +38,7 @@ public class UserManager {
|
||||
private final Settings settings;
|
||||
private final MessageHandler messageHandler;
|
||||
|
||||
private final Map<UUID, User> userMap = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, User> userMap = new HashMap<>();
|
||||
private final Map<Integer, User> armorStandIdMap = new HashMap<>();
|
||||
|
||||
private BukkitTask teleportTask;
|
||||
@@ -129,6 +128,7 @@ public class UserManager {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final PlayerArmor playerArmor = user.getPlayerArmor();
|
||||
|
||||
final List<Pair<EnumWrappers.ItemSlot, ItemStack>> equipmentList = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user