From 8421aad59c4bf31f46b0dc70b69f4796b9d86563 Mon Sep 17 00:00:00 2001 From: samczsun Date: Thu, 15 Dec 2016 20:15:03 -0500 Subject: [PATCH] Multiversion support (but not used) --- .../src/mineplex/core/titles/Titles.java | 252 ++++++++++++++---- 1 file changed, 201 insertions(+), 51 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java b/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java index 469710976..fffc4398a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/titles/Titles.java @@ -2,8 +2,8 @@ package mineplex.core.titles; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,6 +21,8 @@ import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.EntitySlime; import net.minecraft.server.v1_8_R3.Items; import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.Packet; +import net.minecraft.server.v1_8_R3.PacketPlayOutAttachEntity; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityMetadata; import net.minecraft.server.v1_8_R3.PacketPlayOutHeldItemSlot; @@ -50,7 +52,6 @@ import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.book.BookBuilder; import mineplex.core.common.DummyEntity; -import mineplex.core.common.MinecraftVersion; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.LineFormat; @@ -570,13 +571,13 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand TrackTier nextTier = track.getRequirements().getNextTier(player); trackHover - .append("Progress: ") - .color(ChatColor.YELLOW) - .append(String.valueOf(nextTier.get(player)), ComponentBuilder.FormatRetention.NONE) - .color(ChatColor.WHITE) - .append("/") - .append(String.valueOf(nextTier.getGoal())) - .append("\n\n"); + .append("Progress: ") + .color(ChatColor.YELLOW) + .append(String.valueOf(nextTier.get(player)), ComponentBuilder.FormatRetention.NONE) + .color(ChatColor.WHITE) + .append("/") + .append(String.valueOf(nextTier.getGoal())) + .append("\n\n"); } trackHover .append("Click to view this track", ComponentBuilder.FormatRetention.NONE) @@ -613,29 +614,17 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand if (_disabled) return; - _armorStandIds.getOrDefault(player.getEntityId(), Collections.emptyMap()).forEach((uuid, entityId) -> + Map map = _armorStandIds.get(player.getEntityId()); + + if (map == null) return; + + map.forEach((uuid, entityId) -> { - DataWatcher armorStandWatcher = new DataWatcher(new DummyEntity(((CraftWorld) player.getWorld()).getHandle())); - armorStandWatcher.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); - armorStandWatcher.a(1, (short) 300, net.minecraft.server.v1_8_R3.Entity.META_AIR, 0); - if (track != null && track.getRequirements().getTier(player) != null) - { - TrackTier currentTier = track.getRequirements().getTier(player); - armorStandWatcher.a(2, currentTier.getDisplayName(), net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME, currentTier.getDisplayName()); - armorStandWatcher.a(3, (byte) 1, net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME_VISIBLE, true); - } - else - { - armorStandWatcher.a(2, "", net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME, ""); - armorStandWatcher.a(3, (byte) 0, net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME_VISIBLE, false); - } - armorStandWatcher.a(10, (byte) 0x10, EntityArmorStand.META_ARMOR_OPTION, (byte) 0x10); // Small + Player other = Bukkit.getPlayer(uuid); + if (other == null) + return; - PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(); - entityMetadata.a = entityId; - entityMetadata.b = armorStandWatcher.c(); - - ((CraftPlayer) Bukkit.getPlayer(uuid)).getHandle().playerConnection.networkManager.handle(entityMetadata); + updateArmorStand(other, track, entityId); }); } @@ -651,9 +640,7 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand if (packetInfo.getPacket() instanceof PacketPlayOutNamedEntitySpawn) { PacketPlayOutNamedEntitySpawn packet = (PacketPlayOutNamedEntitySpawn) packetInfo.getPacket(); - - Player player = (Player) UtilEnt.getEntityById(packet.a); - summonForEntity(packetInfo.getPlayer(), player); + summonForEntity(packetInfo.getPlayer(), (Player) UtilEnt.getEntityById(packet.a)); } else if (packetInfo.getPacket() instanceof PacketPlayOutEntityDestroy) { @@ -667,14 +654,26 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand private void summonForEntity(Player receiver, Player player) { - if (UtilPlayer.getVersion(receiver) == MinecraftVersion.Version1_8) + switch (UtilPlayer.getVersion(receiver)) { - // don't display to 1.8 players. - return; + case Version1_9: + summonForEntity19(receiver, player); + break; + case Version1_8: + // do nothing + break; + case ALL: + // do nothing + break; } + } + private void summonForEntity19(Player receiver, Player player) + { World world = ((CraftWorld) receiver.getWorld()).getHandle(); - Track existingTitle = getActiveTrack(player); + + DataWatcher armorStandWatcher = getArmorStandWatcher(player, getActiveTrack(player)); + armorStandWatcher.a(10, (byte) 0x10, EntityArmorStand.META_ARMOR_OPTION, (byte) 0x10); // Small DataWatcher squidWatcher = new DataWatcher(new DummyEntity(world)); squidWatcher.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); @@ -683,20 +682,6 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand slimeWatcher.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); slimeWatcher.a(16, -1, EntitySlime.META_SIZE, -1); - DataWatcher armorStandWatcher = new DataWatcher(new DummyEntity(world)); - armorStandWatcher.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); - armorStandWatcher.a(1, (short) 300, net.minecraft.server.v1_8_R3.Entity.META_AIR, 0); - if (existingTitle != null) - { - TrackTier currentTier = existingTitle.getRequirements().getTier(player); - if (currentTier != null) - { - armorStandWatcher.a(2, currentTier.getDisplayName(), net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME, currentTier.getDisplayName()); - armorStandWatcher.a(3, (byte) 1, net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME_VISIBLE, true); - } - } - armorStandWatcher.a(10, (byte) 0x10, EntityArmorStand.META_ARMOR_OPTION, (byte) 0x10); // Small - PacketPlayOutSpawnEntityLiving spawnSlime = new PacketPlayOutSpawnEntityLiving(); spawnSlime.a = UtilEnt.getNewEntityId(); spawnSlime.b = EntityType.SLIME.getTypeId(); @@ -760,6 +745,148 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand }); } + // Unused, but I've put my heart and soul into it and so it's staying here + private void summonForEntity18(Player receiver, Player player) + { + World world = ((CraftWorld) receiver.getWorld()).getHandle(); + + DataWatcher armorStandWatcher = getArmorStandWatcher(player, getActiveTrack(player)); + + List entityIds = new ArrayList<>(); + + entityIds.add(player.getEntityId()); + + List packets = new ArrayList<>(); + + for (int i = 0; i < 11; i++) + { + DataWatcher slimeWatcher0 = new DataWatcher(new DummyEntity(world)); + slimeWatcher0.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); + slimeWatcher0.a(16, (byte) -1, EntitySlime.META_SIZE, -1); + + DataWatcher silverfishWatcher0 = new DataWatcher(new DummyEntity(world)); + silverfishWatcher0.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); + + PacketPlayOutSpawnEntityLiving spawnSlime = new PacketPlayOutSpawnEntityLiving(); + spawnSlime.a = UtilEnt.getNewEntityId(); + spawnSlime.b = EntityType.SLIME.getTypeId(); + spawnSlime.c = MathHelper.floor(player.getLocation().getX() * 32.0D); + spawnSlime.d = -150; + spawnSlime.e = MathHelper.floor(player.getLocation().getZ() * 32.0D); + spawnSlime.i = 0; + spawnSlime.j = 0; + spawnSlime.k = 0; + spawnSlime.f = 0; + spawnSlime.g = 0; + spawnSlime.h = 0; + spawnSlime.uuid = UUID.randomUUID(); + spawnSlime.l = slimeWatcher0; + + PacketPlayOutSpawnEntityLiving spawnSilverfish = new PacketPlayOutSpawnEntityLiving(); + spawnSilverfish.a = UtilEnt.getNewEntityId(); + spawnSilverfish.b = EntityType.SILVERFISH.getTypeId(); + spawnSilverfish.c = MathHelper.floor(player.getLocation().getX() * 32.0D); + spawnSilverfish.d = -150; + spawnSilverfish.e = MathHelper.floor(player.getLocation().getZ() * 32.0D); + spawnSilverfish.i = 0; + spawnSilverfish.j = 0; + spawnSilverfish.k = 0; + spawnSilverfish.f = 0; + spawnSilverfish.g = 0; + spawnSilverfish.h = 0; + spawnSilverfish.uuid = UUID.randomUUID(); + spawnSilverfish.l = silverfishWatcher0; + + entityIds.add(spawnSlime.a); + entityIds.add(spawnSilverfish.a); + + packets.add(spawnSlime); + packets.add(spawnSilverfish); + } + + PacketPlayOutSpawnEntityLiving spawnArmorStand = new PacketPlayOutSpawnEntityLiving(); + spawnArmorStand.a = UtilEnt.getNewEntityId(); + spawnArmorStand.b = EntityType.ARMOR_STAND.getTypeId(); + spawnArmorStand.c = MathHelper.floor(player.getLocation().getX() * 32.0D); + spawnArmorStand.d = -150; + spawnArmorStand.e = MathHelper.floor(player.getLocation().getZ() * 32.0D); + spawnArmorStand.i = 0; + spawnArmorStand.j = 0; + spawnArmorStand.k = 0; + spawnArmorStand.f = 0; + spawnArmorStand.g = 0; + spawnArmorStand.h = 0; + spawnArmorStand.uuid = UUID.randomUUID(); + spawnArmorStand.l = armorStandWatcher; + packets.add(spawnArmorStand); + entityIds.add(spawnArmorStand.a); + + for (int i = 0; i < entityIds.size() - 1; i++) + { + int a = entityIds.get(i); + int b = entityIds.get(i + 1); + + PacketPlayOutAttachEntity attachSlimeToPlayer = new PacketPlayOutAttachEntity(); + attachSlimeToPlayer.a = 0; + attachSlimeToPlayer.b = b; + attachSlimeToPlayer.c = a; + + packets.add(attachSlimeToPlayer); + } + + entityIds.remove(player.getEntityId()); + + _armorStandIds.computeIfAbsent(player.getEntityId(), key -> new HashMap<>()).put(receiver.getUniqueId(), spawnArmorStand.a); + _allIds.computeIfAbsent(player.getEntityId(), key -> new HashMap<>()).put(receiver.getUniqueId(), entityIds); + + runSync(() -> + { + for (Packet p : packets) + { + ((CraftPlayer) receiver).getHandle().playerConnection.networkManager.handle(p); + } + }); + } + + private void updateArmorStand(Player receiver, Track currentTrack, int entityId) + { + switch (UtilPlayer.getVersion(receiver)) + { + case Version1_9: + updateArmorStand19(receiver, currentTrack, entityId); + break; + case Version1_8: + // do nothing + break; + case ALL: + // do nothing + break; + } + } + + private void updateArmorStand19(Player player, Track track, int entityId) + { + DataWatcher armorStandWatcher = getArmorStandWatcher(player, track); + armorStandWatcher.a(10, (byte) 0x10, EntityArmorStand.META_ARMOR_OPTION, (byte) 0x10); // Small + + PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(); + entityMetadata.a = entityId; + entityMetadata.b = armorStandWatcher.c(); + + ((CraftPlayer) player).getHandle().playerConnection.networkManager.handle(entityMetadata); + } + + private void updateArmorStand18(Player player, Track track, int entityId) + { + DataWatcher armorStandWatcher = getArmorStandWatcher(player, track); + + PacketPlayOutEntityMetadata entityMetadata = new PacketPlayOutEntityMetadata(); + entityMetadata.a = entityId; + entityMetadata.b = armorStandWatcher.c(); + + ((CraftPlayer) player).getHandle().playerConnection.networkManager.handle(entityMetadata); + } + private void destroyForEntity(Player receiver, int id) { Map innerMap = _armorStandIds.get(id); @@ -793,6 +920,29 @@ public class Titles extends MiniDbClientPlugin implements IPacketHand } } + private DataWatcher getArmorStandWatcher(Player player, Track existingTitle) + { + World world = ((CraftWorld) player.getWorld()).getHandle(); + + DataWatcher armorStandWatcher = new DataWatcher(new DummyEntity(world)); + armorStandWatcher.a(0, (byte) 0x20, net.minecraft.server.v1_8_R3.Entity.META_ENTITYDATA, (byte) 0x20); + armorStandWatcher.a(1, (short) 300, net.minecraft.server.v1_8_R3.Entity.META_AIR, 0); + + if (existingTitle != null && existingTitle.getRequirements().getTier(player) != null) + { + TrackTier currentTier = existingTitle.getRequirements().getTier(player); + armorStandWatcher.a(2, currentTier.getDisplayName(), net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME, currentTier.getDisplayName()); + armorStandWatcher.a(3, (byte) 1, net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME_VISIBLE, true); + } + else + { + armorStandWatcher.a(2, "", net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME, ""); + armorStandWatcher.a(3, (byte) 0, net.minecraft.server.v1_8_R3.Entity.META_CUSTOMNAME_VISIBLE, false); + } + + return armorStandWatcher; + } + public void forceEnable() { if (_disabled)