Preventing signs with blocked IP addresses.

This commit is contained in:
ryanhamshire 2015-03-18 15:49:07 -07:00
parent 4662f7a3f3
commit 68da411528
3 changed files with 38 additions and 18 deletions

View File

@ -121,6 +121,13 @@ public class BlockEventHandler implements Listener
String signMessage = lines.toString(); String signMessage = lines.toString();
//prevent signs with blocked IP addresses
if(!player.hasPermission("griefprevention.spam") && GriefPrevention.instance.containsBlockedIP(signMessage))
{
event.setCancelled(true);
return;
}
//if not empty and wasn't the same as the last sign, log it and remember it for later //if not empty and wasn't the same as the last sign, log it and remember it for later
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
if(notEmpty && playerData.lastMessage != null && !playerData.lastMessage.equals(signMessage)) if(notEmpty && playerData.lastMessage != null && !playerData.lastMessage.equals(signMessage))

View File

@ -28,6 +28,8 @@ import java.util.UUID;
import java.util.Vector; import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
@ -2698,4 +2700,23 @@ public class GriefPrevention extends JavaPlugin
return result; return result;
} }
public boolean containsBlockedIP(String message)
{
message = message.replace("\r\n", "");
Pattern ipAddressPattern = Pattern.compile("([0-9]{1,3}\\.){3}[0-9]{1,3}");
Matcher matcher = ipAddressPattern.matcher(message);
//if it looks like an IP address
if(matcher.find())
{
//and it's not in the list of allowed IP addresses
if(!GriefPrevention.instance.config_spam_allowedIpAddresses.contains(matcher.group()))
{
return true;
}
}
return false;
}
} }

View File

@ -246,25 +246,17 @@ class PlayerEventHandler implements Listener
//filter IP addresses //filter IP addresses
if(!muted) if(!muted)
{ {
Pattern ipAddressPattern = Pattern.compile("([0-9]{1,3}\\.){3}[0-9]{1,3}"); if(GriefPrevention.instance.containsBlockedIP(message))
Matcher matcher = ipAddressPattern.matcher(message);
//if it looks like an IP address
if(matcher.find())
{ {
//and it's not in the list of allowed IP addresses //log entry
if(!GriefPrevention.instance.config_spam_allowedIpAddresses.contains(matcher.group())) GriefPrevention.AddLogEntry("Muted IP address from " + player.getName() + ": " + message);
{
//log entry //spam notation
GriefPrevention.AddLogEntry("Muted IP address from " + player.getName() + ": " + message); playerData.spamCount+=5;
spam = true;
//spam notation
playerData.spamCount+=5; //block message
spam = true; muted = true;
//block message
muted = true;
}
} }
} }