Re-added auto de-caps

This commit is contained in:
Jerome van der Sar 2012-09-16 14:45:05 +02:00
parent 8e0b7d94a8
commit 14cfea879d
2 changed files with 28 additions and 12 deletions

View File

@ -35,7 +35,7 @@ public class Command_qop extends TFM_Command
if (!matched_player) if (!matched_player)
{ {
sender.sendMessage("No targets matched."); TFM_Util.playerMsg(sender, "No targets matched.");
} }
return true; return true;

View File

@ -301,11 +301,13 @@ public class TFM_PlayerListener implements Listener
{ {
try try
{ {
String m = event.getMessage();
Player p = event.getPlayer(); Player p = event.getPlayer();
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p); TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
playerdata.incrementMsgCount(); playerdata.incrementMsgCount();
// check for spam
if (playerdata.getMsgCount() > 10) if (playerdata.getMsgCount() > 10)
{ {
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED); TFM_Util.bcastMsg(p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
@ -335,14 +337,28 @@ public class TFM_PlayerListener implements Listener
} }
} }
// Truncate messages that are too long. // truncate messages that are too long
String message = event.getMessage(); if (m.length() > 95)
if (message.length() > 85)
{ {
event.setMessage(message.substring(0, 85)); event.setMessage(m.substring(0, 95));
TFM_Util.playerMsg(p, "Message was shortened, because it was too long to send.");
} }
// check for caps
int caps = 0;
for (int i=0; i<m.length(); i++)
{
if (Character.isUpperCase(m.charAt(i)))
caps++;
}
if(caps > 6)
{
event.setMessage(m.toLowerCase());
}
// strip color from messages
event.setMessage(ChatColor.stripColor(event.getMessage())); event.setMessage(ChatColor.stripColor(event.getMessage()));
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -411,7 +427,7 @@ public class TFM_PlayerListener implements Listener
} }
else else
{ {
//Commands that will not auto-kick the user, but still deny: // commands that will not auto-kick the user, but still deny:
if (Pattern.compile("^/time").matcher(command).find()) if (Pattern.compile("^/time").matcher(command).find())
{ {
p.sendMessage(ChatColor.GRAY + "Server-side time changing is disabled. Please use /ptime to set your own personal time."); p.sendMessage(ChatColor.GRAY + "Server-side time changing is disabled. Please use /ptime to set your own personal time.");
@ -529,8 +545,8 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) public void onPlayerLogin(PlayerLoginEvent event)
{ {
//This should supersede all other onPlayerLogin authentication on the TFM server. // this should supersede all other onPlayerLogin authentication on the TFM server.
//When using the TFM CraftBukkit, CraftBukkit itself should not do any of its own authentication. // when using the TFM CraftBukkit, CraftBukkit itself should not do any of its own authentication.
final Server server = TotalFreedomMod.plugin.getServer(); final Server server = TotalFreedomMod.plugin.getServer();
@ -554,7 +570,7 @@ public class TFM_PlayerListener implements Listener
return; return;
} }
//Not safe to use TFM_Util.isUserSuperadmin for player logging in because p.getAddress() will return a null until after player login. // not safe to use TFM_Util.isUserSuperadmin for player logging in because p.getAddress() will return a null until after player login.
boolean is_superadmin; boolean is_superadmin;
if (server.getOnlineMode()) if (server.getOnlineMode())
{ {
@ -689,7 +705,7 @@ public class TFM_PlayerListener implements Listener
} }
} }
boolean can_kick = true; //If the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop. boolean can_kick = true; // if the server is full of superadmins, however unlikely that might be, this will prevent an infinite loop.
while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick) while (server.getOnlinePlayers().length >= server.getMaxPlayers() && can_kick)
{ {
can_kick = false; can_kick = false;