public static ITextComponent translate(ICommandSender sender, ITextComponent component) { if (component instanceof TextComponentTranslation && sender instanceof EntityPlayer) { TextComponentTranslation translation = (TextComponentTranslation) component; if (!TerrariumHandshakeTracker.isFriendly((EntityPlayer) sender)) { String key = translation.getKey(); return new TextComponentString(String.format(LANGUAGE_MAP.getOrDefault(key, key), translation.getFormatArgs())); } } return component; }
@Override public synchronized void onReceivePacket(PacketEvent event) { Packet p = event.getPacket(); if (event.getState() == EventState.PRE) { if (p instanceof SPacketOpenWindow) { SPacketOpenWindow packet = event.cast(); // Remove any entries that were created over a second ago, this should make up for INSANE latency futureInventories.removeIf(i -> System.nanoTime() / 1000000L - i.time > 1000); System.out.println("Received packet " + packet.getGuiId() + " " + packet.getEntityId() + " " + packet.getSlotCount() + " " + packet.getWindowId()); System.out.println(packet.getWindowTitle()); if (packet.getWindowTitle() instanceof TextComponentTranslation && ((TextComponentTranslation) packet.getWindowTitle()).getKey().equals("container.enderchest")) { // title is not customized (i.e. this isn't just a renamed shulker) enderChestWindowId = packet.getWindowId(); return; } futureInventories.stream() .filter(i -> i.type.equals(packet.getGuiId()) && i.slots == packet.getSlotCount()) .findFirst().ifPresent(matched -> { // Remove the future inventory futureInventories.remove(matched); // Setup the remembered inventory getCurrentContainer().setup(matched.pos, packet.getWindowId(), packet.getSlotCount()); }); } if (p instanceof SPacketCloseWindow) { getCurrent().save(); } } }