@SubscribeEvent public void onSendPacket(PacketEvent.Outgoing.Pre event) { if(event.getPacket() instanceof CPacketChatMessage) { String message = ((CPacketChatMessage) event.getPacket()).getMessage(); if(message.startsWith(activationCharacter.getAsString()) && message.length() > 1) { // cut out the . from the message String line = message.substring(1); ConsoleIO.start(); ConsoleIO.write(line, ConsoleIO.HEADING); ConsoleIO.incrementIndent(); try { String[] arguments = CommandHelper.translate(line); GLOBAL_COMMAND.run(arguments); } catch (Throwable t) { Helper.printMessage(t.getMessage()); } ConsoleIO.finished(); event.setCanceled(true); } } }
private void disconnectWithMode(int mode) { switch(mode) { case 0: WMinecraft.getWorld().sendQuittingDisconnectingPacket(); break; case 1: WConnection.sendPacket(new CPacketChatMessage("�")); break; case 2: WConnection.sendPacket( new CPacketPlayer.Position(3.1e7d, 100, 3.1e7d, false)); break; case 3: WPlayer.sendAttackPacket(WMinecraft.getPlayer()); break; default: break; } }
/** * Executes the given command on the server side. * * @param command * @param recieveResults * - whether the client should recieve the results of the command * (in the form of a chat message). May temporarily modify the * client's game settings. Relies on the game rule * sendCommandFeedback = true */ public static void executeCommand(String command, boolean recieveResults) { if (!command.startsWith("/")) command = "/" + command; Minecraft mc = Minecraft.getMinecraft(); boolean hidden = false; if (recieveResults && mc.gameSettings.chatVisibility == EnumChatVisibility.HIDDEN) { hidden = true; mc.gameSettings.chatVisibility = EnumChatVisibility.SYSTEM; mc.gameSettings.sendSettingsToServer(); } mc.getConnection().sendPacket(new CPacketChatMessage(command)); if (hidden) { mc.gameSettings.chatVisibility = EnumChatVisibility.HIDDEN; mc.gameSettings.sendSettingsToServer(); } }
@Override public void call(String[] args) throws CmdException { if(args.length > 0) { String message = args[0]; for(int i = 1; i < args.length; i++) message += " " + args[i]; WConnection.sendPacket(new CPacketChatMessage(message)); }else throw new CmdSyntaxError("Message required."); }
@Override public void onUpdate() { // check gamemode if(WMinecraft.getPlayer().capabilities.isCreativeMode) return; // check for other players if(mc.isSingleplayer() || WMinecraft.getConnection().getPlayerInfoMap().size() == 1) return; // check health if(WMinecraft.getPlayer().getHealth() > health.getValueF() * 2F) return; // leave server switch(mode.getSelected()) { case 0: WMinecraft.getWorld().sendQuittingDisconnectingPacket(); break; case 1: WConnection.sendPacket(new CPacketChatMessage("�")); break; case 2: WConnection.sendPacket( new CPacketPlayer.Position(3.1e7, 100, 3.1e7, false)); break; case 3: WPlayer.sendAttackPacket(WMinecraft.getPlayer()); break; } // disable setEnabled(false); }
@Override public void runCommand(String s, String[] args) { try { String s1 = s.substring(4); Wrapper.getPlayer().connection.sendPacket(new CPacketChatMessage(s1)); }catch(Exception ex) { ex.printStackTrace(); Wrapper.addChatMessage("Usage: " + getSyntax()); } }
@Override public void processChatMessage(CPacketChatMessage p_147354_1_) { PacketThreadUtil.checkThreadAndEnqueue(p_147354_1_, this, this.player.getServerWorld()); String message = p_147354_1_.getMessage(); ServerPlayerSettings settings = this.player.getCapability(PlayerSettings.SETTINGS_CAP_SERVER, null); Map<String, String> playerVars = settings == null ? new HashMap<String, String>() : settings.variables; boolean replaceIgnored; if (message.length() > 1 && message.charAt(0) == '%') { int end = message.indexOf('%', 1); String val = end > 0 ? playerVars.get(message.substring(1, end)) : null; replaceIgnored = val == null || !val.startsWith("/") || (message.length() - 1 != end && message.charAt(end + 1) != ' ') || !this.player.getServer().getCommandManager().getCommands().containsKey(val.substring(1)); } else replaceIgnored = !message.startsWith("/") || !this.player.getServer().getCommandManager().getCommands().containsKey(message.substring(1).split(" ")[0]); try { String world = this.player.getEntityWorld().getSaveHandler().getWorldDirectory().getName(), dim = this.player.getEntityWorld().provider.getDimensionType().getName(); if (MoreCommandsConfig.enableGlobalVars && MoreCommandsConfig.enablePlayerVars) message = Variables.replaceVars(message, replaceIgnored, playerVars, GlobalSettings.getInstance().variables.get(ImmutablePair.of(world, dim))); else if (MoreCommandsConfig.enablePlayerVars) message = Variables.replaceVars(message, replaceIgnored, playerVars); else if (MoreCommandsConfig.enableGlobalVars) message = Variables.replaceVars(message, replaceIgnored, GlobalSettings.getInstance().variables.get(ImmutablePair.of(world, dim))); } catch (Variables.VariablesCouldNotBeResolvedException vcnbre) { message = vcnbre.getNewString(); } super.processChatMessage(new CPacketChatMessage(message)); }
@SubscribeEvent public void onPacketSent(PacketEvent.Outgoing.Pre event) { if (event.getPacket() instanceof CPacketChatMessage && !PacketHelper.isIgnored(event.getPacket())) { inputMessage = ((CPacketChatMessage) event.getPacket()).getMessage(); for (int i = 0; i < MODE.length; i++) { if (font.get().toUpperCase().equals(MODE[i]) ) { fontMode = i; } } if (inputMessage.startsWith("/r ")) { message = inputMessage.substring(3); isWhisper = true; isPM = false; } else if (inputMessage.startsWith("/pm ")) { Pattern pattern = Pattern.compile("\\s\\w*\\s"); Matcher matcher = pattern.matcher(inputMessage); if (matcher.find()) { recipient = inputMessage.substring(matcher.start(), matcher.end()).trim(); } message = inputMessage.replace("/pm " + recipient + " ", ""); isPM = true; isWhisper = false; isIgnore = false; } else if (inputMessage.startsWith("/ignore")) { isIgnore = true; isWhisper = false; isPM = false; } else { message = inputMessage; isWhisper = false; isPM = false; isIgnore = false; } char out[] = message.toCharArray(); for (int i = 0; i < message.toCharArray().length; i++) { if(alphabet.indexOf(message.charAt(i)) != -1 && ((message.toCharArray()[i]) != (char)0x3E)) // indexOf returns -1 if character isnt found - check for meme arrow // if (FONT[fontMode].length < alphabet.indexOf(message.charAt(i))) out[i] = (char)(FONT[fontMode][(alphabet.indexOf(message.charAt(i)))]); else // use normal input character if font doesnt have it out[i] = message.toCharArray()[i]; } String messageOut = new String(out); if (isWhisper) messageOut = "/r " + messageOut; else if (isPM) messageOut = "/pm " + recipient + " " + messageOut; else if (isIgnore) messageOut = inputMessage; CPacketChatMessage packet = new CPacketChatMessage(messageOut); PacketHelper.ignore(packet); getNetworkManager().sendPacket(packet); event.setCanceled(true); } }
/** * Process chat messages (broadcast back to clients) and commands (executes) */ public void processChatMessage(CPacketChatMessage packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld()); if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN) { TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]); textcomponenttranslation.getStyle().setColor(TextFormatting.RED); this.sendPacket(new SPacketChat(textcomponenttranslation)); } else { this.playerEntity.markPlayerActive(); String s = packetIn.getMessage(); s = StringUtils.normalizeSpace(s); for (int i = 0; i < s.length(); ++i) { if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i))) { this.kickPlayerFromServer("Illegal characters in chat"); return; } } if (s.startsWith("/")) { this.handleSlashCommand(s); } else { ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s}); this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false); } this.chatSpamThresholdCount += 20; if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile())) { this.kickPlayerFromServer("disconnect.spam"); } } }
/** * Sends a chat message from the player. */ public void sendChatMessage(String message) { this.connection.sendPacket(new CPacketChatMessage(message)); }
public static void leaveServer() { Minecraft.getMinecraft().player.connection.sendPacket(new CPacketChatMessage("�")); }
/** * Process chat messages (broadcast back to clients) and commands (executes) */ public void processChatMessage(CPacketChatMessage packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld()); if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN) { TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("chat.cannotSend", new Object[0]); textcomponenttranslation.getStyle().setColor(TextFormatting.RED); this.sendPacket(new SPacketChat(textcomponenttranslation)); } else { this.playerEntity.markPlayerActive(); String s = packetIn.getMessage(); s = StringUtils.normalizeSpace(s); for (int i = 0; i < s.length(); ++i) { if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i))) { this.kickPlayerFromServer("Illegal characters in chat"); return; } } if (s.startsWith("/")) { this.handleSlashCommand(s); } else { ITextComponent itextcomponent = new TextComponentTranslation("chat.type.text", this.playerEntity.getDisplayName(), net.minecraftforge.common.ForgeHooks.newChatWithLinks(s)); itextcomponent = net.minecraftforge.common.ForgeHooks.onServerChatEvent(this, s, itextcomponent); if (itextcomponent == null) return; this.serverController.getPlayerList().sendChatMsgImpl(itextcomponent, false); } this.chatSpamThresholdCount += 20; if (this.chatSpamThresholdCount > 200 && !this.serverController.getPlayerList().canSendCommands(this.playerEntity.getGameProfile())) { this.kickPlayerFromServer("disconnect.spam"); } } }
@Override public void processChatMessage(CPacketChatMessage p_147354_1_) { }
@Override public void processChatMessage(@Nonnull CPacketChatMessage p_147354_1_) { }
@Override public void processChatMessage(CPacketChatMessage packetIn) { }
/** * Process chat messages (broadcast back to clients) and commands (executes) */ void processChatMessage(CPacketChatMessage packetIn);