Java Code Examples for us.myles.ViaVersion.api.data.UserConnection#get()
The following examples show how to use
us.myles.ViaVersion.api.data.UserConnection#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkullHandler.java From ViaVersion with MIT License | 6 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an head update packet, but there is no head! O_o " + tag); return -1; } int id = storage.get(position).getOriginal(); if (id >= SKULL_WALL_START && id <= SKULL_END) { Tag skullType = tag.get("SkullType"); if (skullType != null) { id += ((Number) tag.get("SkullType").getValue()).intValue() * 20; } if (tag.contains("Rot")) { id += ((Number) tag.get("Rot").getValue()).intValue(); } } else { Via.getPlatform().getLogger().warning("Why does this block have the skull block entity? " + tag); return -1; } return id; }
Example 2
Source File: BedHandler.java From ViaVersion with MIT License | 6 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an bed color update packet, but there is no bed! O_o " + tag); return -1; } // RED_BED + FIRST_BED int blockId = storage.get(position).getOriginal() - 972 + 748; Tag color = tag.get("color"); if (color != null) { blockId += (((Number) color.getValue()).intValue() * 16); } return blockId; }
Example 3
Source File: WorldPackets.java From ViaVersion with MIT License | 6 votes |
private static int checkStorage(UserConnection user, Position position, int newId) { BlockStorage storage = user.get(BlockStorage.class); if (storage.contains(position)) { BlockStorage.ReplacementData data = storage.get(position); if (data.getOriginal() == newId) { if (data.getReplacement() != -1) { return data.getReplacement(); } } else { storage.remove(position); // Check if the new id has to be stored if (storage.isWelcome(newId)) storage.store(position, newId); } } else if (storage.isWelcome(newId)) storage.store(position, newId); return newId; }
Example 4
Source File: BackwardsBlockEntityProvider.java From ViaBackwards with MIT License | 6 votes |
/** * Transform blocks to block entities! * * @param user The user * @param position The position of the block entity * @param tag The block entity tag */ public CompoundTag transform(UserConnection user, Position position, CompoundTag tag) throws Exception { String id = (String) tag.get("id").getValue(); BackwardsBlockEntityHandler handler = handlers.get(id); if (handler == null) { if (Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("Unhandled BlockEntity " + id + " full tag: " + tag); } return tag; } BackwardsBlockStorage storage = user.get(BackwardsBlockStorage.class); Integer blockId = storage.get(position); if (blockId == null) { if (Via.getManager().isDebug()) { ViaBackwards.getPlatform().getLogger().warning("Handled BlockEntity does not have a stored block :( " + id + " full tag: " + tag); } return tag; } return handler.transform(user, blockId, tag); }
Example 5
Source File: BungeeEntityIdProvider.java From ViaVersion with MIT License | 5 votes |
@Override public int getEntityId(UserConnection user) throws Exception { BungeeStorage storage = user.get(BungeeStorage.class); ProxiedPlayer player = storage.getPlayer(); return (int) getClientEntityId.invoke(player); }
Example 6
Source File: BungeeBossBarProvider.java From ViaVersion with MIT License | 5 votes |
@Override public void handleAdd(UserConnection user, UUID barUUID) { if (user.has(BungeeStorage.class)) { BungeeStorage storage = user.get(BungeeStorage.class); // Check if bossbars are supported by bungee, static maybe if (storage.getBossbar() != null) { storage.getBossbar().add(barUUID); } } }
Example 7
Source File: BungeeBossBarProvider.java From ViaVersion with MIT License | 5 votes |
@Override public void handleRemove(UserConnection user, UUID barUUID) { if (user.has(BungeeStorage.class)) { BungeeStorage storage = user.get(BungeeStorage.class); if (storage.getBossbar() != null) { storage.getBossbar().remove(barUUID); } } }
Example 8
Source File: VelocityBossBarProvider.java From ViaVersion with MIT License | 5 votes |
@Override public void handleAdd(UserConnection user, UUID barUUID) { if (user.has(VelocityStorage.class)) { VelocityStorage storage = user.get(VelocityStorage.class); // Check if bossbars are supported by bungee, static maybe if (storage.getBossbar() != null) { storage.getBossbar().add(barUUID); } } }
Example 9
Source File: VelocityBossBarProvider.java From ViaVersion with MIT License | 5 votes |
@Override public void handleRemove(UserConnection user, UUID barUUID) { if (user.has(VelocityStorage.class)) { VelocityStorage storage = user.get(VelocityStorage.class); if (storage.getBossbar() != null) { storage.getBossbar().remove(barUUID); } } }
Example 10
Source File: BlockItemPackets1_11.java From ViaBackwards with MIT License | 5 votes |
private boolean isLlama(UserConnection user) { WindowTracker tracker = user.get(WindowTracker.class); if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) { EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol()); EntityTracker.StoredEntity storedEntity = entTracker.getEntity(tracker.getEntityId()); return storedEntity != null && storedEntity.getType().is(Entity1_11Types.EntityType.LIAMA); } return false; }
Example 11
Source File: BlockItemPackets1_11.java From ViaBackwards with MIT License | 5 votes |
private Optional<ChestedHorseStorage> getChestedHorse(UserConnection user) { WindowTracker tracker = user.get(WindowTracker.class); if (tracker.getInventory() != null && tracker.getInventory().equals("EntityHorse")) { EntityTracker.ProtocolEntityTracker entTracker = user.get(EntityTracker.class).get(getProtocol()); EntityTracker.StoredEntity storedEntity = entTracker.getEntity(tracker.getEntityId()); if (storedEntity != null) return Optional.of(storedEntity.get(ChestedHorseStorage.class)); } return Optional.empty(); }
Example 12
Source File: RelativeMoveUtil.java From ViaRewind with MIT License | 4 votes |
public static Vector[] calculateRelativeMoves(UserConnection user, int entityId, int relX, int relY, int relZ) { EntityTracker tracker = user.get(EntityTracker.class); Vector offset = tracker.getEntityOffset(entityId); relX += offset.getBlockX(); relY += offset.getBlockY(); relZ += offset.getBlockZ(); if (relX > Short.MAX_VALUE) { offset.setBlockX(relX - Short.MAX_VALUE); relX = Short.MAX_VALUE; } else if (relX < Short.MIN_VALUE) { offset.setBlockX(relX - Short.MIN_VALUE); relX = Short.MIN_VALUE; } else { offset.setBlockX(0); } if (relY > Short.MAX_VALUE) { offset.setBlockY(relY - Short.MAX_VALUE); relY = Short.MAX_VALUE; } else if (relY < Short.MIN_VALUE) { offset.setBlockY(relY - Short.MIN_VALUE); relY = Short.MIN_VALUE; } else { offset.setBlockY(0); } if (relZ > Short.MAX_VALUE) { offset.setBlockZ(relZ - Short.MAX_VALUE); relZ = Short.MAX_VALUE; } else if (relZ < Short.MIN_VALUE) { offset.setBlockZ(relZ - Short.MIN_VALUE); relZ = Short.MIN_VALUE; } else { offset.setBlockZ(0); } int sentRelX, sentRelY, sentRelZ; Vector[] moves; if (relX > Byte.MAX_VALUE * 128 || relX < Byte.MIN_VALUE * 128 || relY > Byte.MAX_VALUE * 128 || relY < Byte.MIN_VALUE * 128 || relZ > Byte.MAX_VALUE * 128 || relZ < Byte.MIN_VALUE * 128) { byte relX1 = (byte) (relX / 256); byte relX2 = (byte) (Math.round((relX - relX1 * 128) / 128f)); byte relY1 = (byte) (relY / 256); byte relY2 = (byte) (Math.round((relY - relY1 * 128) / 128f)); byte relZ1 = (byte) (relZ / 256); byte relZ2 = (byte) (Math.round((relZ - relZ1 * 128) / 128f)); sentRelX = relX1 + relX2; sentRelY = relY1 + relY2; sentRelZ = relZ1 + relZ2; moves = new Vector[] {new Vector(relX1, relY1, relZ1), new Vector(relX2, relY2, relZ2)}; } else { sentRelX = Math.round(relX / 128f); sentRelY = Math.round(relY / 128f); sentRelZ = Math.round(relZ / 128f); moves = new Vector[] {new Vector(sentRelX, sentRelY, sentRelZ)}; } offset.setBlockX(offset.getBlockX() + relX - sentRelX * 128); offset.setBlockY(offset.getBlockY() + relY - sentRelY * 128); offset.setBlockZ(offset.getBlockZ() + relZ - sentRelZ * 128); tracker.setEntityOffset(entityId, offset); return moves; }
Example 13
Source File: CommandBlockProvider.java From ViaVersion with MIT License | 4 votes |
private CommandBlockStorage getStorage(UserConnection connection) { return connection.get(CommandBlockStorage.class); }
Example 14
Source File: BannerHandler.java From ViaVersion with MIT License | 4 votes |
@Override public int transform(UserConnection user, CompoundTag tag) { BlockStorage storage = user.get(BlockStorage.class); Position position = new Position((int) getLong(tag.get("x")), (short) getLong(tag.get("y")), (int) getLong(tag.get("z"))); if (!storage.contains(position)) { Via.getPlatform().getLogger().warning("Received an banner color update packet, but there is no banner! O_o " + tag); return -1; } int blockId = storage.get(position).getOriginal(); Tag base = tag.get("Base"); int color = 0; if (base != null) { color = ((Number) tag.get("Base").getValue()).intValue(); } // Standing banner if (blockId >= BANNER_START && blockId <= BANNER_STOP) { blockId += ((15 - color) * 16); // Wall banner } else if (blockId >= WALL_BANNER_START && blockId <= WALL_BANNER_STOP) { blockId += ((15 - color) * 4); } else { Via.getPlatform().getLogger().warning("Why does this block have the banner block entity? :(" + tag); } if (tag.get("Patterns") instanceof ListTag) { for (Tag pattern : (ListTag) tag.get("Patterns")) { if (pattern instanceof CompoundTag) { Tag c = ((CompoundTag) pattern).get("Color"); if (c instanceof IntTag) { ((IntTag)c).setValue(15 - (int) c.getValue()); // Invert color id } } } } Tag name = tag.get("CustomName"); if (name instanceof StringTag) { ((StringTag) name).setValue(ChatRewriter.legacyTextToJson(((StringTag) name).getValue()).toString()); } return blockId; }