This code is for Hyperion. However, you can use this for educational purpose to make it work for any server.
Purpose: To add a server-sided filterable send message system. When enabled by the player, any message deemed allowed to be filtered will not be sent to the player.
This merely cancels the message being sent to the player, therefor when the filter to turned off, the player will still not be able to view messages filtered. Filter cautiously.
Any messages you would like to allow to be filtered(not shown if enabled by the player) will look like the first as opposed to the original code under it:
Code:
player.getActionSender().sendMessage("You swing your pick at the rock...", true);
player.getActionSender().sendMessage("You swing your pick at the rock...");
You do NOT have to change any of the existing sendMessages to say false, not have to use the second argument to say false- only true.
In ActionSender.java:
Code:
private boolean chatFilter;
public void setChatFilter(boolean a) {
chatFilter = a;
}
/**
* Send a message unless player's chat filter is enabled and message is filterable.
* @param message The message to send.
* @param filterable If the message is allowed to be filtered.
* @return The action sender instance, for chaining.
*/
public ActionSender sendMessage(String message, boolean filterable) {
if ((filterable) && (chatFilter)) {
return this;
} else {
player.write(new PacketBuilder(253, Type.VARIABLE).putRS2String(message).toPacket());
return this;
}
}
In CommandPacketHandler.java:
Code:
else if(command.equals("chatfilter")) {
if(args.length == 2) {
int filter = Integer.parseInt(args[1]);
if (filter == 1) {
player.getActionSender().setChatFilter(true);
} else {
player.getActionSender().setChatFilter(false);
}
} else {
player.getActionSender().sendMessage("Syntax is ::chatfilter [0/1].");
}
}