mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 03:49:19 +00:00
Forgot to commit UserManager class in the previous commit
This commit is contained in:
@@ -1,31 +1,25 @@
|
||||
package io.github.fisher2911.hmccosmetics.user;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
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.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.util.Keys;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
|
||||
import net.minecraft.world.entity.EnumItemSlot;
|
||||
import net.minecraft.world.level.levelgen.HeightMap;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -34,8 +28,6 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -43,9 +35,11 @@ import java.util.UUID;
|
||||
|
||||
public class UserManager {
|
||||
|
||||
private int currentArmorStandId = Integer.MAX_VALUE;
|
||||
private final HMCCosmetics plugin;
|
||||
|
||||
private final Map<UUID, User> userMap = new HashMap<>();
|
||||
private final Map<Integer, User> armorStandIdMap = new HashMap<>();
|
||||
|
||||
private BukkitTask teleportTask;
|
||||
|
||||
@@ -56,7 +50,8 @@ public class UserManager {
|
||||
|
||||
public void add(final Player player) {
|
||||
final UUID uuid = player.getUniqueId();
|
||||
this.userMap.put(uuid, new User(uuid, new PlayerArmor(
|
||||
final int armorStandId = this.currentArmorStandId;
|
||||
final User user = new User(uuid, new PlayerArmor(
|
||||
new ArmorItem(
|
||||
new ItemStack(Material.AIR),
|
||||
"",
|
||||
@@ -71,7 +66,11 @@ public class UserManager {
|
||||
"",
|
||||
ArmorItem.Type.BACKPACK
|
||||
)
|
||||
)));
|
||||
),
|
||||
armorStandId);
|
||||
this.userMap.put(uuid, user);
|
||||
this.armorStandIdMap.put(armorStandId, user);
|
||||
this.currentArmorStandId--;
|
||||
}
|
||||
|
||||
public Optional<User> get(final UUID uuid) {
|
||||
@@ -83,8 +82,13 @@ public class UserManager {
|
||||
}
|
||||
|
||||
public void remove(final UUID uuid) {
|
||||
this.get(uuid).ifPresent(User::detach);
|
||||
this.userMap.remove(uuid);
|
||||
final User user = this.userMap.remove(uuid);
|
||||
|
||||
if (user == null) return;
|
||||
|
||||
user.despawnAttached();
|
||||
|
||||
this.armorStandIdMap.remove(user.getArmorStandId());
|
||||
}
|
||||
|
||||
public void startTeleportTask() {
|
||||
@@ -98,7 +102,8 @@ public class UserManager {
|
||||
|
||||
private void registerPacketListener() {
|
||||
final ProtocolManager protocolManager = this.plugin.getProtocolManager();
|
||||
protocolManager.addPacketListener(new PacketAdapter(this.plugin,
|
||||
protocolManager.addPacketListener(new PacketAdapter(
|
||||
this.plugin,
|
||||
ListenerPriority.NORMAL,
|
||||
PacketType.Play.Server.ENTITY_EQUIPMENT) {
|
||||
@Override
|
||||
@@ -141,6 +146,66 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
protocolManager.addPacketListener(new PacketAdapter(
|
||||
this.plugin,
|
||||
ListenerPriority.NORMAL,
|
||||
PacketType.Play.Server.SPAWN_ENTITY_LIVING
|
||||
) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() != PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().sendMessage("What the heck * 2");
|
||||
|
||||
Bukkit.broadcast(Component.text("Received spawn"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
if (event.getPacketType() != PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPlayer().sendMessage("What the heck");
|
||||
|
||||
PacketContainer packet = event.getPacket();
|
||||
|
||||
Entity entity = packet.getEntityModifier(event).read(0);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (entity == null) {
|
||||
Bukkit.broadcast(Component.text("Entity null" + packet));
|
||||
} else {
|
||||
Bukkit.broadcast(Component.text("Not null: " + entity.getEntityId()));
|
||||
}
|
||||
}
|
||||
|
||||
final int id = entity.getEntityId();
|
||||
|
||||
final User user = armorStandIdMap.get(id);
|
||||
|
||||
if (user == null) return;
|
||||
|
||||
user.addArmorStandPassenger(entity);
|
||||
|
||||
// user.
|
||||
//
|
||||
// WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity);
|
||||
//
|
||||
//
|
||||
// WrappedDataWatcher.Serializer chatSerializer = WrappedDataWatcher.Registry.getChatComponentSerializer(true);
|
||||
//
|
||||
// dataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, chatSerializer),
|
||||
// Optional.of(WrappedChatComponent.fromChatMessage(leveledMob.getTag() /* or name, or what you need here */)[0].getHandle()));
|
||||
//
|
||||
// packet.getWatchableCollectionModifier().write(0, dataWatcher.getWatchableObjects());
|
||||
//
|
||||
event.setPacket(packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setFakeHelmet(final User user) {
|
||||
|
||||
Reference in New Issue
Block a user