public void addPortedClient(UserConnection info) { portedPlayers.put(info.get(ProtocolInfo.class).getUuid(), info); }
public static UUID getUUID(UserConnection user) { return user.get(ProtocolInfo.class).getUuid(); } }
@Override public Set<UUID> getPlayers() { return Collections.singleton(connection.get(ProtocolInfo.class).getUuid()); }
@Override public Item getHandItem(final UserConnection info) { if (HandItemCache.CACHE) { return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); } else { return super.getHandItem(info); // TODO: On API Docs write about this } } });
/** * Disconnect a connection * * @param reason The reason to use, not used if player is not active. */ public void disconnect(final String reason) { if (!getChannel().isOpen()) return; if (pendingDisconnect) return; pendingDisconnect = true; if (get(ProtocolInfo.class).getUuid() != null) { final UUID uuid = get(ProtocolInfo.class).getUuid(); Via.getPlatform().runSync(new Runnable() { @Override public void run() { if (!Via.getPlatform().kickPlayer(uuid, ChatColor.translateAlternateColorCodes('&', reason))) { getChannel().close(); // =) } } }); } }
@Override public int getWorldBlockData(UserConnection user, Position position) { if (blockStateIds != null) { UUID uuid = user.get(ProtocolInfo.class).getUuid(); Optional<Player> player = Sponge.getServer().getPlayer(uuid); if (player.isPresent()) { World world = player.get().getWorld(); Optional<Chunk> chunk = world.getChunkAtBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); if (chunk.isPresent()) { BlockState b = chunk.get().getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); Integer id = blockStateIds.get(b); if (id == null) { System.out.println("id not found"); } else { return id; } } } } return 0; } }
@Override public void sendPlayer(UserConnection info) { if (USE_NMS) { Player player = Bukkit.getPlayer(info.get(ProtocolInfo.class).getUuid()); if (player != null) { try { // Tick player Object entityPlayer = getHandle.invoke(player); Object pc = connection.get(entityPlayer); if (pc != null) { handleFlying.invoke(pc, (info.get(MovementTracker.class).isGround() ? idlePacket2 : idlePacket)); // Tick world info.get(MovementTracker.class).incrementIdlePacket(); } } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } } } else { super.sendPlayer(info); } } }
@Override public Item getHandItem(final UserConnection info) { if (HandItemCache.CACHE) { return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid()); } else { try { return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Item>() { @Override public Item call() throws Exception { UUID playerUUID = info.get(ProtocolInfo.class).getUuid(); if (Bukkit.getPlayer(playerUUID) != null) { return HandItemCache.convert(Bukkit.getPlayer(playerUUID).getItemInHand()); } return null; } }).get(10, TimeUnit.SECONDS); } catch (Exception e) { Via.getPlatform().getLogger().severe("Error fetching hand item: " + e.getClass().getName()); if (Via.getManager().isDebug()) e.printStackTrace(); return null; } } } });
UUID uuid = info.getUuid(); BukkitInventoryUpdateTask updateTask = updateTasks.get(uuid); final boolean registered = updateTask != null;
@Override public int getWorldBlockData(UserConnection user, Position position) { UUID uuid = user.get(ProtocolInfo.class).getUuid(); Player player = Bukkit.getPlayer(uuid); if (player != null) { World world = player.getWorld(); int x = (int) (position.getX() >> 4); int z = (int) (position.getZ() >> 4); if (world.isChunkLoaded(x, z)) { Chunk c = getChunk(world, x, z); Block b = c.getBlock(position.getX().intValue(), position.getY().intValue(), position.getZ().intValue()); return b.getTypeId() << 4 | b.getData(); } } return 0; }
UUID uuid = getUser().get(ProtocolInfo.class).getUuid();