/** replaces selected text, or inserts text at the position on the cursor */ public void writeText(String par1Str) { String var2 = ""; String var3 = ChatAllowedCharacters.filerAllowedCharacters(par1Str); int var4 = this.cursorPosition < this.selectionEnd ? this.cursorPosition : this.selectionEnd; int var5 = this.cursorPosition < this.selectionEnd ? this.selectionEnd : this.cursorPosition; int var6 = this.maxStringLength - this.text.length() - (var4 - this.selectionEnd); boolean var7 = false; if (this.text.length() > 0) { var2 = var2 + this.text.substring(0, var4); } int var8; if (var6 < var3.length()) { var2 = var2 + var3.substring(0, var6); var8 = var6; } else { var2 = var2 + var3; var8 = var3.length(); } if (this.text.length() > 0 && var5 < this.text.length()) { var2 = var2 + this.text.substring(var5); } this.text = var2; this.moveCursorBy(var4 - this.selectionEnd + var8); }
public void handleChat(Packet3Chat par1Packet3Chat) { ModLoader.serverChat(this, par1Packet3Chat.message); if (playerEntity.getChatVisibility() == 2) { sendPacketToPlayer(new Packet3Chat("Cannot send chat message.")); return; } String s = par1Packet3Chat.message; if (s.length() > 100) { kickPlayerFromServer("Chat message too long"); return; } s = s.trim(); for (int i = 0; i < s.length(); i++) { if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i))) { kickPlayerFromServer("Illegal characters in chat"); return; } } if (s.startsWith("/")) { func_72566_d(s); } else { if (playerEntity.getChatVisibility() == 1) { sendPacketToPlayer(new Packet3Chat("Cannot send chat message.")); return; } s = (new StringBuilder()) .append("<") .append(playerEntity.username) .append("> ") .append(s) .toString(); logger.info(s); mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat(s, false)); } chatSpamThresholdCount += 20; if (chatSpamThresholdCount > 200 && !mcServer.getConfigurationManager().areCommandsAllowed(playerEntity.username)) { kickPlayerFromServer("disconnect.spam"); } }
public void handleChat(Packet3Chat par1Packet3Chat) { if (this.playerEntity.func_71126_v() == 2) { this.sendPacket(new Packet3Chat("Cannot send chat message.")); } else { String var2 = par1Packet3Chat.message; if (var2.length() > 100) { this.kickPlayer("Chat message too long"); } else { var2 = var2.trim(); for (int var3 = 0; var3 < var2.length(); ++var3) { if (!ChatAllowedCharacters.isAllowedCharacter(var2.charAt(var3))) { this.kickPlayer("Illegal characters in chat"); return; } } if (var2.startsWith("/")) { this.handleSlashCommand(var2); } else { if (this.playerEntity.func_71126_v() == 1) { this.sendPacket(new Packet3Chat("Cannot send chat message.")); return; } var2 = "<" + this.playerEntity.username + "> " + var2; logger.info(var2); this.mcServer .getConfigurationManager() .sendPacketToAllPlayers(new Packet3Chat(var2, false)); } this.field_72581_m += 20; if (this.field_72581_m > 200 && !this.mcServer.getConfigurationManager().isOp(this.playerEntity.username)) { this.kickPlayer("disconnect.spam"); } } } }
/** Call this method from you GuiScreen to process the keys into textbox. */ public boolean textboxKeyTyped(char par1, int par2) { if (this.isEnabled && this.isFocused) { switch (par1) { case 1: this.setCursorPositionEnd(); this.setSelectionPos(0); return true; case 3: GuiScreen.setClipboardString(this.getSelectedtext()); return true; case 22: this.writeText(GuiScreen.getClipboardString()); return true; case 24: GuiScreen.setClipboardString(this.getSelectedtext()); this.writeText(""); return true; default: switch (par2) { case 14: if (GuiScreen.isCtrlKeyDown()) { this.deleteWords(-1); } else { this.deleteFromCursor(-1); } return true; case 199: if (GuiScreen.isShiftKeyDown()) { this.setSelectionPos(0); } else { this.setCursorPositionZero(); } return true; case 203: if (GuiScreen.isShiftKeyDown()) { if (GuiScreen.isCtrlKeyDown()) { this.setSelectionPos(this.getNthWordFromPos(-1, this.getSelectionEnd())); } else { this.setSelectionPos(this.getSelectionEnd() - 1); } } else if (GuiScreen.isCtrlKeyDown()) { this.setCursorPosition(this.getNthWordFromCursor(-1)); } else { this.moveCursorBy(-1); } return true; case 205: if (GuiScreen.isShiftKeyDown()) { if (GuiScreen.isCtrlKeyDown()) { this.setSelectionPos(this.getNthWordFromPos(1, this.getSelectionEnd())); } else { this.setSelectionPos(this.getSelectionEnd() + 1); } } else if (GuiScreen.isCtrlKeyDown()) { this.setCursorPosition(this.getNthWordFromCursor(1)); } else { this.moveCursorBy(1); } return true; case 207: if (GuiScreen.isShiftKeyDown()) { this.setSelectionPos(this.text.length()); } else { this.setCursorPositionEnd(); } return true; case 211: if (GuiScreen.isCtrlKeyDown()) { this.deleteWords(1); } else { this.deleteFromCursor(1); } return true; default: if (ChatAllowedCharacters.isAllowedCharacter(par1)) { this.writeText(Character.toString(par1)); return true; } else { return false; } } } } else { return false; } }
/** Process the contents of this packet */ public void handle(NetHandlerPlayServer handler) { PacketThreadUtil.processPacket(this, handler, handler.playerEntity.getWorldForPlayer()); PacketBuffer var2; ItemStack var3; ItemStack var4; if ("MC|BEdit".equals(this.channel)) { var2 = new PacketBuffer(Unpooled.wrappedBuffer(this.data)); try { var3 = var2.readItemStackFromBuffer(); if (var3 == null) return; if (!ItemWritableBook.validBookPageTagContents(var3.getTagCompound())) { throw new IOException("Invalid book tag!"); } var4 = handler.playerEntity.inventory.getCurrentItem(); if (var4 != null) { if (var3.getItem() == Items.writable_book && var3.getItem() == var4.getItem()) { var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages", 8)); } } } catch (Exception ignored) { } finally { var2.release(); } } else if ("MC|BSign".equals(this.channel)) { var2 = new PacketBuffer(Unpooled.wrappedBuffer(this.data)); try { var3 = var2.readItemStackFromBuffer(); if (var3 == null) { return; } if (!ItemEditableBook.validBookTagContents(var3.getTagCompound())) { throw new IOException("Invalid book tag!"); } var4 = handler.playerEntity.inventory.getCurrentItem(); if (var4 != null) { if (var3.getItem() == Items.written_book && var4.getItem() == Items.writable_book) { var4.setTagInfo("author", new NBTTagString(handler.playerEntity.getName())); var4.setTagInfo("title", new NBTTagString(var3.getTagCompound().getString("title"))); var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages", 8)); var4.setItem(Items.written_book); } } } catch (Exception ignored) { } finally { var2.release(); } } else if ("MC|TrSel".equals(this.channel)) { try { int var40 = this.data.readInt(); Container container = handler.playerEntity.openContainer; if (container instanceof ContainerMerchant) { ((ContainerMerchant) container).setCurrentRecipeIndex(var40); } } catch (Exception ignored) { } } else if ("MC|AdvCdm".equals(this.channel)) { if (!handler.serverController.isCommandBlockEnabled()) { handler.playerEntity.addChatMessage(new FormattedTextTranslation("advMode.notEnabled")); } else if (handler.playerEntity.canCommandSenderUseCommand(2, "") && handler.playerEntity.capabilities.isCreativeMode) { var2 = this.data; try { byte var43 = var2.readByte(); CommandBlockLogic var46 = null; if (var43 == 0) { var46 = $.bind( handler.playerEntity.world.getTileEntity( new BlockPos(var2.readInt(), var2.readInt(), var2.readInt()), TileEntityCommandBlock.class), TileEntityCommandBlock::getCommandBlockLogic); } else if (var43 == 1) { var46 = $.bind( handler.playerEntity.world.getEntityByID( var2.readInt(), EntityMinecartCommandBlock.class), EntityMinecartCommandBlock::getCommandBlockLogic); } String var49 = var2.readString(var2.readableBytes()); boolean var6 = var2.readBoolean(); if (var46 != null) { var46.setCommand(var49); var46.setCommandFeedback(var6); if (!var6) { var46.func_145750_b(null); } var46.markForUpdate(); handler.playerEntity.addChatMessage( new FormattedTextTranslation("advMode.setCommand.success", var49)); } } catch (Exception ignored) { } finally { var2.release(); } } else { handler.playerEntity.addChatMessage(new FormattedTextTranslation("advMode.notAllowed")); } } else if ("MC|Beacon".equals(this.channel)) { if (handler.playerEntity.openContainer instanceof ContainerBeacon) { try { var2 = this.data; int var44 = var2.readInt(); int var47 = var2.readInt(); ContainerBeacon var50 = (ContainerBeacon) handler.playerEntity.openContainer; Slot var51 = var50.getSlot(0); if (var51.hasStack()) { var51.decreaseStackSize(1); IInventory var7 = var50.getTileEntity(); var7.setField(1, var44); var7.setField(2, var47); var7.markDirty(); } } catch (Exception ignored) { } } } else if ("MC|ItemName".equals(this.channel) && handler.playerEntity.openContainer instanceof ContainerAnvil) { ContainerAnvil container = (ContainerAnvil) handler.playerEntity.openContainer; if (this.data != null && this.data.readableBytes() >= 1) { String data = ChatAllowedCharacters.filterAllowedCharacters(this.data.readString(32767)); if (data.length() <= 30) { container.updateItemName(data); } } else { container.updateItemName(""); } } }