9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2026-01-06 15:51:50 +00:00

Fixed duplicate entity ids causing visual issues

This commit is contained in:
LoJoSho
2022-08-18 17:35:18 -05:00
parent e95b30131c
commit 8f012f6c97
5 changed files with 13 additions and 3 deletions

View File

@@ -20,7 +20,9 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
@@ -234,6 +236,7 @@ public class Database {
}
public static int getNextEntityId() {
return new AtomicInteger().incrementAndGet();
Random random = new Random();
return random.nextInt(999999);
}
}

View File

@@ -58,6 +58,7 @@ public class HookManager {
this.registerHook(citizensHook.getClass());
this.listeners.add(citizensHook);
this.citizensHook = citizensHook;
this.plugin.getLogger().info("Successfully Hooked into Citizens!");
} else {
this.citizensHook = null;
}

View File

@@ -5,6 +5,7 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.*;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.database.Database;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerNamedEntitySpawn;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerPlayerInfo;
import io.github.fisher2911.hmccosmetics.packet.wrappers.WrapperPlayServerRelEntityMove;
@@ -385,7 +386,7 @@ public class PacketManager {
packet.getIntegers().write(0, mountId);
packet.getIntegerArrays().write(0, new int[]{passengerId});
for (final Player p : sendTo) {
p.sendMessage("MountID: " + mountId + " Passenger ID: " + new int[]{passengerId} + " / Raw Passenger: " + passengerId);
//p.sendMessage("MountID: " + mountId + " / Raw Passenger: " + passengerId + " | Next Entity: " + Database.getNextEntityId());
sendPacketAsync(p, packet);
}
}

View File

@@ -2,6 +2,7 @@ package io.github.fisher2911.hmccosmetics.user;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.database.Database;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
import org.bukkit.Bukkit;
@@ -46,7 +47,7 @@ public class Backpack {
if (currentSize == particleCount) return;
if (currentSize < particleCount) {
for (int i = currentSize; i < particleCount; i++) {
this.particleIDS.add(new AtomicInteger().incrementAndGet());
this.particleIDS.add(Database.getNextEntityId());
}
return;
}
@@ -57,6 +58,7 @@ public class Backpack {
PacketManager.sendEntitySpawnPacket(location, this.armorStandID, EntityType.ARMOR_STAND, other);
PacketManager.sendArmorStandMetaContainer(this.armorStandID, other);
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
plugin.getLogger().info("Sent spawnForOther. Mount: " + owner.getEntityId() + " | Armorstand: " + this.armorStandID);
//PacketManager.sendRidingPacket(owner.getEntityId(), new int[]{this.armorStandID}, other);
}
@@ -117,6 +119,7 @@ public class Backpack {
PacketManager.sendLookPacket(this.armorStandID, location, other);
if (!isSelf || !firstPersonMode || this.particleIDS.size() == 0) {
PacketManager.sendRidingPacket(owner.getEntityId(), this.armorStandID, other);
plugin.getLogger().info("Sent updateBackpack. Mount: " + owner.getEntityId() + " | Armorstand: " + this.armorStandID);
//PacketManager.sendRidingPacket(owner.getEntityId(), new int[]{this.armorStandID}, other);
return;
}
@@ -130,5 +133,6 @@ public class Backpack {
}
}
PacketManager.sendRidingPacket(particleIDS.get(particleIDS.size() - 1), this.armorStandID, other);
//plugin.getLogger().info("Sent updateBackpack Other. Mount: " + owner.getEntityId() + " | Armorstand: " + this.armorStandID);
}
}

View File

@@ -5,6 +5,7 @@ import io.github.fisher2911.hmccosmetics.config.CosmeticSettings;
import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.gui.BalloonItem;
import io.github.fisher2911.hmccosmetics.hook.CitizensHook;
import io.github.fisher2911.hmccosmetics.hook.HookManager;
import io.github.fisher2911.hmccosmetics.hook.ModelEngineHook;
import io.github.fisher2911.hmccosmetics.hook.entity.BalloonEntity;