public void sendMetadataBuffer(int entityID) { List<Metadata> metadataList = metadataBuffer.get(entityID); if (metadataList != null) { PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser()); wrapper.write(Type.VAR_INT, entityID); wrapper.write(Types1_9.METADATA_LIST, metadataList); MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataList); handleMetadata(entityID, metadataList); if (metadataList.size() > 0) { try { wrapper.send(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } } metadataBuffer.remove(entityID); } }
public int getEntityId(UserConnection user) throws Exception { return user.get(EntityTracker.class).getEntityID(); } }
/** * Rewrite chat being sent to the client so that gamemode issues don't occur. * * @param obj The json object being sent by the server * @param user The player involved. (Required for Gamemode info) */ public static void toClient(JsonObject obj, UserConnection user) { //Check gamemode change if (obj.get("translate") != null && obj.get("translate").getAsString().equals("gameMode.changed")) { String gameMode = user.get(EntityTracker.class).getGameMode().getText(); JsonObject gameModeObject = new JsonObject(); gameModeObject.addProperty("text", gameMode); gameModeObject.addProperty("color", "gray"); gameModeObject.addProperty("italic", true); JsonArray array = new JsonArray(); array.add(gameModeObject); obj.add("with", array); } } }
if ((getMetaByIndex(metadataList, 12)) == null) { metadataList.add(new Metadata(12, MetaType1_9.Boolean, true)); if (entityID != getProvidedEntityId() && Via.getConfig().isShieldBlocking()) { if ((data & 0x10) == 0x10) { if (validBlocking.contains(entityID)) { Item shield = new Item((short) 442, (byte) 1, (short) 0, null); setSecondHand(entityID, shield); } else { setSecondHand(entityID, null); setSecondHand(entityID, null); if (metadata.getId() == 0 && getMetaByIndex(metadataList, 10) != null) { Metadata meta = getMetaByIndex(metadataList, 10); //Only happens if the armorstand is small byte data = (byte) metadata.getValue(); && ((String) getMetaByIndex(metadataList, 2).getValue()).length() != 0 && (boolean) getMetaByIndex(metadataList, 3).getValue()) { if (!knownHolograms.contains(entityID)) { knownHolograms.add(entityID); try { PacketWrapper wrapper = new PacketWrapper(0x25, null, getUser()); wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.SHORT, (short) 0); UUID uuid = getUser().get(ProtocolInfo.class).getUuid(); Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId());
public void sendPermission(UserConnection user) throws Exception { if (!isEnabled()) return; PacketWrapper wrapper = new PacketWrapper(0x1B, null, user); // Entity status wrapper.write(Type.INT, user.get(EntityTracker.class).getProvidedEntityId()); // Entity ID wrapper.write(Type.BYTE, (byte) 26); // Hardcoded op permission level wrapper.send(Protocol1_9TO1_8.class); user.get(CommandBlockStorage.class).setPermissions(true); }
@Listener public void placeBlock(ChangeBlockEvent.Place e, @Root Player player) { if (isOnPipe(player.getUniqueId())) { Location loc = e.getTransactions().get(0).getFinal().getLocation().get(); getUserConnection(player.getUniqueId()) .get(EntityTracker.class) .addBlockInteraction(new Position((long) loc.getX(), (long) loc.getY(), (long) loc.getZ())); } } }
@EventHandler public void onServerConnect(ServerConnectEvent event) { // Ignore if it doesn't exist (Like BungeeCord 1.8) if (setMainHand == null || getSettings == null) return; UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { Object settings = getSettings.invoke(event.getPlayer()); if (settings != null) { if (user.has(EntityTracker.class)) { setMainHand.invoke(settings, user.get(EntityTracker.class).getMainHand()); } } } } catch (Exception e) { e.printStackTrace(); } } }
public void removeEntity(Integer entityID) { clientEntityTypes.remove(entityID); vehicleMap.remove(entityID); uuidMap.remove(entityID); validBlocking.remove(entityID); knownHolograms.remove(entityID); metadataBuffer.remove(entityID); BossBar bar = bossBarMap.remove(entityID); if (bar != null) { bar.hide(); // Send to provider Via.getManager().getProviders().get(BossBarProvider.class).handleRemove(getUser(), bar.getId()); } }
@Override public void init(UserConnection userConnection) { // Entity tracker userConnection.put(new EntityTracker(userConnection)); // Chunk tracker userConnection.put(new ClientChunks(userConnection)); // Movement tracker userConnection.put(new MovementTracker(userConnection)); // Inventory tracker userConnection.put(new InventoryTracker(userConnection)); // Place block tracker userConnection.put(new PlaceBlockTracker(userConnection)); // CommandBlock storage userConnection.put(new CommandBlockStorage(userConnection)); } }
@EventHandler(priority = EventPriority.HIGH) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { int entityId = user.get(EntityTracker.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9TO1_8.class); } } catch (Exception e) { e.printStackTrace(); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void placeBlock(BlockPlaceEvent e) { if (isOnPipe(e.getPlayer())) { Block b = e.getBlockPlaced(); getUserConnection(e.getPlayer()) .get(EntityTracker.class) .addBlockInteraction(new Position((long) b.getX(), (long) b.getY(), (long) b.getZ())); } } }
@Subscribe public void onServerConnect(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null || setSettings == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { PlayerSettings settings = event.getPlayer().getPlayerSettings(); if (user.has(EntityTracker.class)) { Object clientSettings = ReflectionUtil.get(settings, "settings", Object.class); ReflectionUtil.set(clientSettings, "mainHand", user.get(EntityTracker.class).getMainHand()); setSettings.invoke(event.getPlayer(), clientSettings); } } } catch (Exception e) { e.printStackTrace(); } } }
public void setSecondHand(int entityID, Item item) { PacketWrapper wrapper = new PacketWrapper(0x3C, null, getUser()); wrapper.write(Type.VAR_INT, entityID); wrapper.write(Type.VAR_INT, 1); // slot wrapper.write(Type.ITEM, item); try { wrapper.send(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } }
@Subscribe(order = PostOrder.LAST) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { int entityId = user.get(EntityTracker.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9TO1_8.class); } } catch (Exception e) { e.printStackTrace(); } } }
public int getProvidedEntityId() { try { return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(getUser()); } catch (Exception e) { return entityID; } } }
public void sendTeamPacket(boolean add, boolean now) { PacketWrapper wrapper = new PacketWrapper(0x41, null, getUser()); wrapper.write(Type.STRING, "viaversion"); // Use viaversion as name if (add) { // add if (!teamExists) { wrapper.write(Type.BYTE, (byte) 0); // make team wrapper.write(Type.STRING, "viaversion"); wrapper.write(Type.STRING, ""); // prefix wrapper.write(Type.STRING, ""); // suffix wrapper.write(Type.BYTE, (byte) 0); // friendly fire wrapper.write(Type.STRING, ""); // nametags wrapper.write(Type.STRING, "never"); // collision rule :) wrapper.write(Type.BYTE, (byte) 0); // color } else { wrapper.write(Type.BYTE, (byte) 3); } wrapper.write(Type.STRING_ARRAY, new String[]{getUser().get(ProtocolInfo.class).getUsername()}); } else { wrapper.write(Type.BYTE, (byte) 1); // remove team } teamExists = add; try { wrapper.send(Protocol1_9TO1_8.class, true, now); } catch (Exception e) { e.printStackTrace(); } }