public void setSecondHand(Item item) { setSecondHand(entityID, item); }
@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)); } }
public int getEntityId(UserConnection user) throws Exception { return user.get(EntityTracker.class).getEntityID(); } }
public void sendPlayer(UserConnection userConnection) { // Old method using packets. ChannelHandlerContext context = PipelineUtil.getContextBefore("decoder", userConnection.getChannel().pipeline()); if (context != null) { if (userConnection.get(MovementTracker.class).isGround()) { context.fireChannelRead(getGroundPacket()); } else { context.fireChannelRead(getFlyingPacket()); } userConnection.get(MovementTracker.class).incrementIdlePacket(); } } }
public void sendPlayer(UserConnection userConnection) { if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } } }
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); }
@Override public void handle(PacketWrapper wrapper) throws Exception { MovementTracker tracker = wrapper.user().get(MovementTracker.class); tracker.incrementIdlePacket(); // If packet has the ground data if (wrapper.is(Type.BOOLEAN, 0)) { tracker.setGround(wrapper.get(Type.BOOLEAN, 0)); } } }
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); } }
@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())); } } }
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(); } }
public void addOrUpdateBlock(Position position, CompoundTag tag) { Pair<Integer, Integer> chunkPos = getChunkCoords(position); if (!storedCommandBlocks.containsKey(chunkPos)) storedCommandBlocks.put(chunkPos, new ConcurrentHashMap<Position, CompoundTag>()); Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkPos); if (blocks.containsKey(position)) if (blocks.get(position).equals(tag)) return; blocks.put(position, tag); }
@Override protected void filterPacket(UserConnection info, Object packet, List output) throws Exception { output.addAll(info.get(ClientChunks.class).transformMapChunkBulk(packet)); }
public void unloadChunks(UserConnection userConnection) { if (isEnabled()) getStorage(userConnection).unloadChunks(); } }
public Optional<CompoundTag> get(UserConnection user, Position position) throws Exception { checkPermission(user); if (isEnabled()) return getStorage(user).getCommandBlock(position); return Optional.absent(); }
private void checkPermission(UserConnection user) throws Exception { if (!isEnabled()) return; CommandBlockStorage storage = getStorage(user); if (!storage.isPermissions()) { sendPermission(user); } }
public void addOrUpdateBlock(UserConnection user, Position position, CompoundTag tag) throws Exception { checkPermission(user); if (isEnabled()) getStorage(user).addOrUpdateBlock(position, tag); }
public void unloadChunk(UserConnection user, int x, int z) throws Exception { checkPermission(user); if (isEnabled()) getStorage(user).unloadChunk(x, z); }
public void sendPlayer(UserConnection userConnection) { if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } } }
public int getProvidedEntityId() { try { return Via.getManager().getProviders().get(EntityIdProvider.class).getEntityId(getUser()); } catch (Exception e) { return entityID; } } }
public Optional<CompoundTag> getCommandBlock(Position position) { Pair<Integer, Integer> chunkCoords = getChunkCoords(position); Map<Position, CompoundTag> blocks = storedCommandBlocks.get(chunkCoords); if (blocks == null) return Optional.absent(); CompoundTag tag = blocks.get(position); if (tag == null) return Optional.absent(); tag = tag.clone(); tag.put(new ByteTag("powered", (byte) 0)); tag.put(new ByteTag("auto", (byte) 0)); tag.put(new ByteTag("conditionMet", (byte) 0)); return Optional.of(tag); }