public CachedPlayer(Player player) { super(player); this.uuid = UUID.fromString(player.getUniqueId().toString()); this.name = player.getName(); this.isOnline = true; this.location = new CachedLocation(player.getLocation()); this.rotation = player.getRotation().clone(); this.velocity = player.getVelocity().clone(); this.scale = player.getScale().clone(); this.address = player.getConnection().getAddress().toString(); this.latency = player.getConnection().getLatency(); // Collect unlocked advancements for (AdvancementTree tree : player.getUnlockedAdvancementTrees()) { addUnlockedAdvancements(player, tree.getRootAdvancement()); } // This will be moved to the other constructor once Sponge implements the offline inventory API this.helmet = player.getHelmet().map(ItemStack::copy).orElse(null); this.chestplate = player.getChestplate().map(ItemStack::copy).orElse(null); this.leggings = player.getLeggings().map(ItemStack::copy).orElse(null); this.boots = player.getBoots().map(ItemStack::copy).orElse(null); this.inventory = new CachedInventory(player.getInventory()); }
public void sendArmorUpdate(Player player) { // Ensure that the player is on our pipe if (!isOnPipe(player.getUniqueId())) return; int armor = 0; armor += calculate(player.getHelmet()); armor += calculate(player.getChestplate()); armor += calculate(player.getLeggings()); armor += calculate(player.getBoots()); PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player.getUniqueId())); try { wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID wrapper.write(Type.INT, 1); // only 1 property wrapper.write(Type.STRING, "generic.armor"); wrapper.write(Type.DOUBLE, 0D); //default 0 armor wrapper.write(Type.VAR_INT, 1); // 1 modifier wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid wrapper.write(Type.DOUBLE, (double) armor); // the modifier value wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number wrapper.send(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } }
public void sendArmorUpdate(Player player) { // Ensure that the player is on our pipe if (!isOnPipe(player.getUniqueId())) return; int armor = 0; armor += calculate(player.getHelmet()); armor += calculate(player.getChestplate()); armor += calculate(player.getLeggings()); armor += calculate(player.getBoots()); PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player.getUniqueId())); try { wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID wrapper.write(Type.INT, 1); // only 1 property wrapper.write(Type.STRING, "generic.armor"); wrapper.write(Type.DOUBLE, 0D); //default 0 armor wrapper.write(Type.VAR_INT, 1); // 1 modifier wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid wrapper.write(Type.DOUBLE, (double) armor); // the modifier value wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number wrapper.send(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } }