net.minecraft.network.play.client.CPacketChatMessage Java Examples

The following examples show how to use net.minecraft.network.play.client.CPacketChatMessage. 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: InstantMessage.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onPacketIn(PacketEvent.Incoming.Pre event) {
  if (event.getPacket() instanceof SPacketLoginSuccess) {
    
    if (MC.currentScreen instanceof GuiConnecting) {
      
      ServerData serverData = MC.getCurrentServerData();
      String serverName = serverData != null ? serverData.serverName : "Unknown";
      String serverIP = serverData != null ? serverData.serverIP : "";
      
      GuiConnecting_networkManager.get(MC.currentScreen)
          .sendPacket(
              new CPacketChatMessage(
                  message
                      .get()
                      .replace("{SRVNAME}", serverName)
                      .replace("{IP}", serverIP)
                      .replace("{NAME}", MC.getSession().getUsername())));
    } else {
      getLog().warn("Did not send message as current screen is not GuiConnecting");
    }
  }
}
 
Example #2
Source File: ChatSuffixModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onSendChatMessage(EventSendChatMessage event) {
    final CommandsModule cmds = (CommandsModule) Seppuku.INSTANCE.getModuleManager().find(CommandsModule.class);
    if (cmds == null)
        return;

    if (event.getMessage().startsWith("/") || event.getMessage().startsWith(cmds.prefix.getValue()))
        return;

    event.setCanceled(true);
    Minecraft.getMinecraft().getConnection().sendPacket(new CPacketChatMessage(event.getMessage() + " " + prefix));
}
 
Example #3
Source File: ChatMutatorModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void sendPacket(EventSendPacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof CPacketChatMessage) {
            final CPacketChatMessage packet = (CPacketChatMessage) event.getPacket();

            final CommandsModule cmds = (CommandsModule) Seppuku.INSTANCE.getModuleManager().find(CommandsModule.class);

            if (cmds != null) {
                if (packet.getMessage().startsWith("/") || packet.getMessage().startsWith(cmds.prefix.getValue())) {
                    return;
                }

                switch (this.mode.getValue()) {
                    case LEET:
                        packet.message = leetSpeak(packet.message);
                        break;
                    case FANCY:
                        packet.message = fancy(packet.message);
                        break;
                    case RETARD:
                        packet.message = retard(packet.message);
                        break;
                    case CONSOLE:
                        packet.message = console(packet.message);
                        break;
                }
            }
        }
    }
}
 
Example #4
Source File: DiscordBypassModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void sendPacket(EventSendPacket event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        if (event.getPacket() instanceof CPacketChatMessage) {
            final CPacketChatMessage packet = (CPacketChatMessage) event.getPacket();
            final CommandsModule commands = (CommandsModule) Seppuku.INSTANCE.getModuleManager().find(CommandsModule.class);
            if (commands != null) {
                if (packet.getMessage().startsWith(commands.prefix.getValue()) || packet.getMessage().startsWith("/"))
                    return;
                //Technically the "spawn area" is usually around 23x23 chunks, but jj might've changed it... or perhaps he might not be using the spawn chunks at all.
                //Just in case he's going to the "anarchy definition" of spawn, I set it to 1k. Better safe than sorry, nobody except jj will notice the extra #.
                if (Minecraft.getMinecraft().player.posX <= 1000 || Minecraft.getMinecraft().player.posZ <= 1000) {
                    //This might seem like a stupid way to do it, but it's the best one I know to get this done without making the whole message lowercase.
                    //If you want the straightforward method, you can use the part that is commented out down here.
                    /*
                    if (packet.message.toLowerCase().contains("discord"))
                        packet.message = packet.message.toLowerCase().replace("discord", "disc#ord");
                     */
                    if (packet.message.toLowerCase().contains("discord")) {
                        for (int i = 0; i < packet.message.length(); i++) {
                            if (packet.message.toLowerCase().charAt(i) == 'd') {
                                if (packet.message.toLowerCase().toLowerCase().charAt(i + 1) == 'i' &&
                                        packet.message.toLowerCase().toLowerCase().charAt(i + 2) == 's' &&
                                        packet.message.toLowerCase().toLowerCase().charAt(i + 3) == 'c' &&
                                        packet.message.toLowerCase().toLowerCase().charAt(i + 4) == 'o' &&
                                        packet.message.toLowerCase().toLowerCase().charAt(i + 5) == 'r' &&
                                        packet.message.toLowerCase().toLowerCase().charAt(i + 6) == 'd')
                                    packet.message = new StringBuilder(packet.message).insert(i + 3, "#").toString();
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example #5
Source File: SayCommand.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void exec(String input) {
    if (!this.clamp(input, 2)) {
        this.printUsage();
        return;
    }

    final String[] split = input.split(" ");

    Minecraft.getMinecraft().player.connection.sendPacket(new CPacketChatMessage(input.substring(split[0].length() + 1)));
}
 
Example #6
Source File: SayCmd.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void call(String[] args) throws CmdException
{
	if(args.length < 1)
		throw new CmdSyntaxError();
	
	String message = String.join(" ", args);
	CPacketChatMessage packet = new CPacketChatMessage(message);
	mc.getConnection().sendPacket(packet);
}
 
Example #7
Source File: SayCommand.java    From ForgeHax with MIT License 5 votes vote down vote up
@RegisterCommand
public Command say(CommandBuilders builders) {
  return builders
    .newCommandBuilder()
    .name("say")
    .description("Send chat message")
    .options(
      parser -> {
        parser.acceptsAll(Arrays.asList("fake", "f"),
          "Send a fake message that won't be treated as command");
        parser.acceptsAll(Arrays.asList("local", "l"), "Send message from local chat");
      }
    )
    .processor(
      data -> {
        boolean fake = data.hasOption("fake");
        // any emoji will work until 1.13
        final int fakePrefix = 0x1F921;
        String msg = data.getArgumentCount() > 0 ? data.getArgumentAsString(0) : "";
        
        if (getLocalPlayer() != null) {
          if (fake) {
            msg = new StringBuilder().appendCodePoint(fakePrefix).append(msg).toString();
          }
          if (data.hasOption("local")) {
            getLocalPlayer().sendChatMessage(msg);
          } else {
            PacketHelper.ignoreAndSend(new CPacketChatMessage(msg));
          }
        }
      }
    )
    .build();
}
 
Example #8
Source File: ChatCommandService.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onSendPacket(PacketEvent.Outgoing.Pre event) {
  if (event.getPacket() instanceof CPacketChatMessage) {
    String message = ((CPacketChatMessage) event.getPacket()).getMessage();
    if (!PacketHelper.isIgnored(event.getPacket())
        && message.startsWith(activationCharacter.getAsString()) && message.length() > 1) {
      // cut out the . from the message
      String line = message.substring(1);
      handleCommand(line);
      event.setCanceled(true);
    }
  }
}
 
Example #9
Source File: FancyChat.java    From ForgeHax with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPacketSent(PacketEvent.Outgoing.Pre event) {
  if (event.getPacket() instanceof CPacketChatMessage
      && !PacketHelper.isIgnored(event.getPacket())) {
    
    boolean is0Arg = false;
    boolean is1Arg = false;
    boolean isIgnore = false;
    
    String prefix = "";
    String command = "";
    String message;
    String arg1 = "";
    
    String inputMessage = ((CPacketChatMessage) event.getPacket()).getMessage();
    
    Matcher prefixMatcher = prefixPattern.matcher(inputMessage);
    if (prefixMatcher.find()) {
      prefix = prefixMatcher.group(1);
      command = prefixMatcher.group(2);
      
      Matcher cmd0ArgMatcher = command0ArgPattern.matcher(command);
      Matcher cmd1ArgMatcher = command1ArgPattern.matcher(command);
      
      // if command is found, make sure the match is not just a substring
      if (cmd0ArgMatcher.find() && command.length() == cmd0ArgMatcher.group().length()) {
        is0Arg = true;
        message = inputMessage.substring(prefixMatcher.end());
        
      } else if (cmd1ArgMatcher.find() && command.length() == cmd1ArgMatcher.group().length()) {
        is1Arg = true;
        Matcher arg1Matcher = Pattern.compile(" .+? ").matcher(inputMessage);
        
        if (arg1Matcher.find()) {
          arg1 = inputMessage.substring(arg1Matcher.start(), arg1Matcher.end()).trim();
          message = inputMessage.substring(arg1Matcher.end());
        } else {
          isIgnore = true;
          message = inputMessage;
        }
        
      } else {
        message = inputMessage;
        // Completely ignore all unknown commands
        isIgnore = true;
      }
    } else {
      message = inputMessage;
    }
    
    if (!isIgnore) {
      String messageOut = prettify(message);
      
      if (is0Arg) {
        messageOut = prefix + command + " " + messageOut;
      } else if (is1Arg) {
        messageOut = prefix + command + " " + arg1 + " " + messageOut;
      }
      
      if (getNetworkManager() != null) {
        CPacketChatMessage packet = new CPacketChatMessage(messageOut);
        PacketHelper.ignore(packet);
        getNetworkManager().sendPacket(packet);
        event.setCanceled(true);
      }
    }
  }
}