public AutoAccept() { super("Auto Accept", 0xB3FFAC, ModuleCategory.MISCELLANEOUS); listeners.add(new Listener<ReceivePacket>() { @Override public void call(ReceivePacket event) { if (event.getPacket() instanceof S02PacketChat) { S02PacketChat packet = (S02PacketChat) event.getPacket(); Serenity.getInstance().getFriendManager().getFriends().keySet().stream() .filter(friend -> StringUtils.stripControlCodes(packet.getChatComponent().getUnformattedText()).contains(friend + " has requested to teleport to you.") || StringUtils.stripControlCodes(packet.getChatComponent().getUnformattedText()).equalsIgnoreCase(friend + " has requested that you teleport to them.")) .filter(friend -> isValidTeleportMessage(StringUtils.stripControlCodes(packet.getChatComponent().getFormattedText()), false)) .forEach(friend -> { if (!EventManager.post(new TeleportAcceptEvent(friend).isCancelled())) mc.thePlayer.sendChatMessage(command.getValue().replace("$name", friend)); }); } } }); }
@Override public void onPacketReceive(EventPacketReceive event){ if(event.getPacket() instanceof S02PacketChat){ S02PacketChat p = (S02PacketChat) event.getPacket(); try{ String line = p.func_148915_c().getUnformattedText(); String[] spaceArray = line.split(" "); for(Friend friend : Friend.friendList){ if(spaceArray[0].toLowerCase().contains(friend.getName().toLowerCase())){ String lineAfterSpace = line.replace(spaceArray[0], ""); if(lineAfterSpace.trim().equals("has requested to teleport to you.")){ invoker.sendChatMessage("/tpaccept"); } } } if(FriendManager.isFriend(spaceArray[0])){ } }catch(Exception e){ e.printStackTrace(); } } }
/** * Opens a mod added container. * * @param player The player to open the container for * @param inventory The tile entity providing the inventory */ public static void openContainer(EntityPlayerMP player, IModInventory inventory) { if (player.openContainer != player.inventoryContainer) player.closeScreen(); if (inventory instanceof IModLockableInventory) { IModLockableInventory lockable = (IModLockableInventory)inventory; if (lockable.isLocked() && !player.canOpen(lockable.getLockCode()) && !player.isSpectator()) { player.playerNetServerHandler.sendPacket(new S02PacketChat(new ChatComponentTranslation(lockable.getLockMessageString(), inventory.getDisplayName()), (byte) 2)); player.playerNetServerHandler.sendPacket(new S29PacketSoundEffect(lockable.getLockSoundString(), player.posX, player.posY, player.posZ, 1.0F, 1.0F)); return; } } player.getNextWindowId(); Container container = inventory.createContainer(player.inventory, player); player.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(player.currentWindowId, inventory.getGuiID(), inventory.getDisplayName(), inventory.getSizeInventory())); player.openContainer = container; player.openContainer.windowId = player.currentWindowId; player.openContainer.onCraftGuiOpened(player); }
/** * Displays the GUI for interacting with a chest inventory. Args: chestInventory */ public void displayGUIChest(IInventory chestInventory) { if (this.openContainer != this.inventoryContainer) { this.closeScreen(); } if (chestInventory instanceof ILockableContainer) { ILockableContainer ilockablecontainer = (ILockableContainer)chestInventory; if (ilockablecontainer.isLocked() && !this.canOpen(ilockablecontainer.getLockCode()) && !this.isSpectator()) { this.playerNetServerHandler.sendPacket(new S02PacketChat(new ChatComponentTranslation("container.isLocked", new Object[] {chestInventory.getDisplayName()}), (byte)2)); this.playerNetServerHandler.sendPacket(new S29PacketSoundEffect("random.door_close", this.posX, this.posY, this.posZ, 1.0F, 1.0F)); return; } } this.getNextWindowId(); if (chestInventory instanceof IInteractionObject) { this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getDisplayName(), chestInventory.getSizeInventory())); this.openContainer = ((IInteractionObject)chestInventory).createContainer(this.inventory, this); } else { this.playerNetServerHandler.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "minecraft:container", chestInventory.getDisplayName(), chestInventory.getSizeInventory())); this.openContainer = new ContainerChest(this.inventory, chestInventory, this); } this.openContainer.windowId = this.currentWindowId; this.openContainer.onCraftGuiOpened(this); }
public void sendPacket(final Packet packetIn) { if (packetIn instanceof S02PacketChat) { S02PacketChat s02packetchat = (S02PacketChat)packetIn; EntityPlayer.EnumChatVisibility entityplayer$enumchatvisibility = this.playerEntity.getChatVisibility(); if (entityplayer$enumchatvisibility == EntityPlayer.EnumChatVisibility.HIDDEN) { return; } if (entityplayer$enumchatvisibility == EntityPlayer.EnumChatVisibility.SYSTEM && !s02packetchat.isChat()) { return; } } try { this.netManager.sendPacket(packetIn); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Sending packet"); CrashReportCategory crashreportcategory = crashreport.makeCategory("Packet being sent"); crashreportcategory.addCrashSectionCallable("Packet class", new Callable<String>() { public String call() throws Exception { return packetIn.getClass().getCanonicalName(); } }); throw new ReportedException(crashreport); } }
/** * Prints a chatmessage in the chat GUI */ public void handleChat(S02PacketChat packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController); if (packetIn.getType() == 2) { this.gameController.ingameGUI.setRecordPlaying(packetIn.getChatComponent(), false); } else { this.gameController.ingameGUI.getChatGUI().printChatMessage(packetIn.getChatComponent()); } }
@Override public void sendRawMessage(String message) { if (getHandle().playerNetServerHandler == null) return; for (net.minecraft.util.IChatComponent component : CraftChatMessage.fromString(message)) { getHandle().playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S02PacketChat(component)); } }
@Override public /* varargs */ void sendMessage(BaseComponent ... components) { if (CraftPlayer.this.getHandle().playerNetServerHandler == null) { return; } S02PacketChat packet = new S02PacketChat(); packet.components = components; CraftPlayer.this.getHandle().playerNetServerHandler.sendPacket(packet); }
@Override public void handleChat(Packet chatPacket) { if (!(((NeptunePacket) chatPacket).getHandle() instanceof S02PacketChat)) { return; } sendPacket(chatPacket); }
@Override public void onPacketReceive(EventPacketReceive event){ if(event.getPacket() instanceof S02PacketChat){ S02PacketChat p = (S02PacketChat) event.getPacket(); String line = p.func_148915_c().getUnformattedText(); if(line.toLowerCase().contains(".help") || line.toLowerCase().contains(".legit") && !line.contains(invoker.getSessionUsername())){ Resilience.getInstance().getLogger().infoChat("\247f[\247bTIP\247f] \247c"+"Did someone just tell you to type \".help\"? Don't worry! You can type \".say .help\" and it will say it in the chat!"); } } }
public void sendPacket(final Packet p_147359_1_) { if (p_147359_1_ instanceof S02PacketChat) { S02PacketChat var2 = (S02PacketChat)p_147359_1_; EntityPlayer.EnumChatVisibility var3 = this.playerEntity.func_147096_v(); if (var3 == EntityPlayer.EnumChatVisibility.HIDDEN) { return; } if (var3 == EntityPlayer.EnumChatVisibility.SYSTEM && !var2.func_148916_d()) { return; } } try { this.netManager.scheduleOutboundPacket(p_147359_1_, new GenericFutureListener[0]); } catch (Throwable var5) { CrashReport var6 = CrashReport.makeCrashReport(var5, "Sending packet"); CrashReportCategory var4 = var6.makeCategory("Packet being sent"); var4.addCrashSectionCallable("Packet class", new Callable() { private static final String __OBFID = "CL_00001454"; public String call() { return p_147359_1_.getClass().getCanonicalName(); } }); throw new ReportedException(var6); } }
/** * Prints a chatmessage in the chat GUI */ public void handleChat(S02PacketChat p_147251_1_) { final EventPacketReceive eventPacket = new EventPacketReceive(p_147251_1_); eventPacket.onEvent(); if(eventPacket.isCancelled()){ eventPacket.setCancelled(false); return; } this.gameController.ingameGUI.getChatGUI().func_146227_a(p_147251_1_.func_148915_c()); }
/** * @author jamierocks - 1st September 2016 * @reason Overwrite to pass chat to Canary. */ @Overwrite public void processChatMessage(C01PacketChatMessage packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, (NetHandlerPlayServer) (Object) this, this.playerEntity.getServerForPlayer()); if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN) { ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend"); chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); this.sendPacket(new S02PacketChat(chatcomponenttranslation)); return; } this.chatSpamThresholdCount += 20; final boolean op = Canary.ops().isOpped((PlayerReference) this.playerEntity); final boolean ignore = ((Player) this.playerEntity).canIgnoreRestrictions(); final String spamProtectionLevel = Configuration.getServerConfig().getSpamProtectionLevel(); if (spamProtectionLevel.equalsIgnoreCase("all") || (spamProtectionLevel.equalsIgnoreCase("default") && !(op || ignore))) { if (this.chatSpamThresholdCount > 200) { this.kickPlayerFromServer("disconnect.spam"); return; } } this.playerEntity.markPlayerActive(); ((Player) this.playerEntity).chat(packetIn.getMessage()); }
@Override public void handleChat(Packet chatPacket) { if (!(chatPacket instanceof S02PacketChat)) { return; } this.sendPacket(chatPacket); }
public void handleChat(S02PacketChat p_147251_1_) { ClientChatReceivedEvent event = new ClientChatReceivedEvent(p_147251_1_.func_148915_c()); if (!MinecraftForge.EVENT_BUS.post(event) && event.message != null) { this.gameController.ingameGUI.getChatGUI().printChatMessage(event.message); } }
public void sendPacket(final Packet p_147359_1_) { if (p_147359_1_ instanceof S02PacketChat) { S02PacketChat s02packetchat = (S02PacketChat)p_147359_1_; EntityPlayer.EnumChatVisibility enumchatvisibility = this.playerEntity.func_147096_v(); if (enumchatvisibility == EntityPlayer.EnumChatVisibility.HIDDEN) { return; } if (enumchatvisibility == EntityPlayer.EnumChatVisibility.SYSTEM && !s02packetchat.func_148916_d()) { return; } } try { this.netManager.scheduleOutboundPacket(p_147359_1_, new GenericFutureListener[0]); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Sending packet"); CrashReportCategory crashreportcategory = crashreport.makeCategory("Packet being sent"); crashreportcategory.addCrashSectionCallable("Packet class", new Callable() { private static final String __OBFID = "CL_00001454"; public String call() { return p_147359_1_.getClass().getCanonicalName(); } }); throw new ReportedException(crashreport); } }
@Override public boolean onChat(S02PacketChat chatPacket, IChatComponent chat, String message) { /* This is here to block repeating messages */ if (prevMessage.equals(message)) { return false; } /* This is here to block users on the blocklist */ String preUsername = new String(); String[] words = message.split(" "); preUsername = words[0]; String username = new String(); for(int i = 0; i < preUsername.length(); i++) { if(!(preUsername.charAt(i) == '�' || ((i > 0) && preUsername.charAt(i-1) == '�')) && !((preUsername.charAt(i) == '<') || preUsername.charAt(i) == '>')&& !((preUsername.charAt(i) == '[') || preUsername.charAt(i) == ']')) { username += preUsername.charAt(i); } } username = username.toLowerCase(); if(namesArray != null) { for(int i = 0; i < namesArray.length; i++) { if(namesArray[i] != null && username.equals(namesArray[i].toLowerCase())) { return false; } } } else { return true; } prevMessage = message; return true; }
public void addChatComponentMessage(IChatComponent chatComponent) { this.playerNetServerHandler.sendPacket(new S02PacketChat(chatComponent)); }
/** * Send a chat message to the CommandSender */ public void addChatMessage(IChatComponent component) { this.playerNetServerHandler.sendPacket(new S02PacketChat(component)); }
/** * Processes block placement and block activation (anvil, furnace, etc.) */ public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer()); WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension); ItemStack itemstack = this.playerEntity.inventory.getCurrentItem(); boolean flag = false; BlockPos blockpos = packetIn.getPosition(); EnumFacing enumfacing = EnumFacing.getFront(packetIn.getPlacedBlockDirection()); this.playerEntity.markPlayerActive(); if (packetIn.getPlacedBlockDirection() == 255) { if (itemstack == null) { return; } this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack); } else if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit()) { if (this.hasMoved && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos)) { this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, blockpos, enumfacing, packetIn.getPlacedBlockOffsetX(), packetIn.getPlacedBlockOffsetY(), packetIn.getPlacedBlockOffsetZ()); } flag = true; } else { ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())}); chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation)); flag = true; } if (flag) { this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos)); this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos.offset(enumfacing))); } itemstack = this.playerEntity.inventory.getCurrentItem(); if (itemstack != null && itemstack.stackSize == 0) { this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null; itemstack = null; } if (itemstack == null || itemstack.getMaxItemUseDuration() == 0) { this.playerEntity.isChangingQuantityOnly = true; this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]); Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem); this.playerEntity.openContainer.detectAndSendChanges(); this.playerEntity.isChangingQuantityOnly = false; if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), packetIn.getStack())) { this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem())); } } }
/** * Process chat messages (broadcast back to clients) and commands (executes) */ public void processChatMessage(C01PacketChatMessage packetIn) { PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer()); if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN) { ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]); chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED); this.sendPacket(new S02PacketChat(chatcomponenttranslation)); } 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 { IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s}); this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false); } this.chatSpamThresholdCount += 20; if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile())) { this.kickPlayerFromServer("disconnect.spam"); } } }
public void sendChatMsgImpl(IChatComponent component, boolean isChat) { this.mcServer.addChatMessage(component); byte b0 = (byte)(isChat ? 1 : 0); this.sendPacketToAllPlayers(new S02PacketChat(component, b0)); }