mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Synchronize calls in AsyncPlayerChatEvent listener. Resolves #524
This commit is contained in:
parent
4fce1109a1
commit
8fc25111e2
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Sun Apr 26 22:23:22 CEST 2015
|
||||
build.number=990
|
||||
#Mon Apr 27 00:31:14 CEST 2015
|
||||
build.number=991
|
||||
|
@ -27,7 +27,8 @@ public class Command_uuid extends TFM_Command
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("purge".equals(args[0])) {
|
||||
if ("purge".equals(args[0]))
|
||||
{
|
||||
playerMsg("Purged " + TFM_UuidManager.purge() + " cached UUIDs.");
|
||||
return true;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_RollbackManager.RollbackEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Sync;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidManager;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
@ -558,7 +559,7 @@ public class TFM_PlayerListener implements Listener
|
||||
final Player player = event.getPlayer();
|
||||
String message = event.getMessage().trim();
|
||||
|
||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
|
||||
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerDataSync(player);
|
||||
|
||||
// Check for spam
|
||||
final Long lastRan = TFM_Heartbeat.getLastRan();
|
||||
@ -570,8 +571,8 @@ public class TFM_PlayerListener implements Listener
|
||||
{
|
||||
if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT)
|
||||
{
|
||||
TFM_Util.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
|
||||
TFM_Util.autoEject(player, "Kicked for spamming chat.");
|
||||
TFM_Sync.bcastMsg(player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
|
||||
TFM_Sync.autoEject(player, "Kicked for spamming chat.");
|
||||
|
||||
playerdata.resetMsgCount();
|
||||
|
||||
@ -583,7 +584,7 @@ public class TFM_PlayerListener implements Listener
|
||||
// Check for message repeat
|
||||
if (playerdata.getLastMessage().equalsIgnoreCase(message))
|
||||
{
|
||||
TFM_Util.playerMsg(player, "Please do not repeat messages.");
|
||||
TFM_Sync.playerMsg(player, "Please do not repeat messages.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -593,9 +594,9 @@ public class TFM_PlayerListener implements Listener
|
||||
// Check for muted
|
||||
if (playerdata.isMuted())
|
||||
{
|
||||
if (!TFM_AdminList.isSuperAdmin(player))
|
||||
if (!TFM_AdminList.isSuperAdminSync(player))
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
|
||||
TFM_Sync.playerMsg(player, ChatColor.RED + "You are muted, STFU! - You will be unmuted in 5 minutes.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -610,7 +611,7 @@ public class TFM_PlayerListener implements Listener
|
||||
if (message.length() > 100)
|
||||
{
|
||||
message = message.substring(0, 100);
|
||||
TFM_Util.playerMsg(player, "Message was shortened because it was too long to send.");
|
||||
TFM_Sync.playerMsg(player, "Message was shortened because it was too long to send.");
|
||||
}
|
||||
|
||||
// Check for caps
|
||||
@ -633,7 +634,7 @@ public class TFM_PlayerListener implements Listener
|
||||
// Check for adminchat
|
||||
if (playerdata.inAdminChat())
|
||||
{
|
||||
TFM_Util.adminChatMessage(player, message, false);
|
||||
TFM_Sync.adminChatMessage(player, message, false);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ public class TFM_AdminList
|
||||
seniorConsoleNames = new HashSet<String>();
|
||||
superIps = new HashSet<String>();
|
||||
|
||||
SUPERADMIN_SERVICE = new Function<Player, Boolean>() {
|
||||
SUPERADMIN_SERVICE = new Function<Player, Boolean>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public Boolean apply(Player f)
|
||||
@ -414,6 +415,10 @@ public class TFM_AdminList
|
||||
return admin != null && admin.isActivated();
|
||||
}
|
||||
|
||||
public static synchronized boolean isSuperAdminSync(CommandSender sender) {
|
||||
return isSuperAdmin(sender);
|
||||
}
|
||||
|
||||
public static boolean isSuperAdmin(CommandSender sender)
|
||||
{
|
||||
if (!(sender instanceof Player))
|
||||
|
@ -29,6 +29,14 @@ public class TFM_PlayerData
|
||||
return PLAYER_DATA.containsKey(TFM_Util.getIp(player));
|
||||
}
|
||||
|
||||
public static TFM_PlayerData getPlayerDataSync(Player player)
|
||||
{
|
||||
synchronized (PLAYER_DATA)
|
||||
{
|
||||
return getPlayerData(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static TFM_PlayerData getPlayerData(Player player)
|
||||
{
|
||||
final String ip = TFM_Util.getIp(player);
|
||||
|
@ -30,7 +30,8 @@ public class TFM_ServerInterface
|
||||
{
|
||||
String[] whitelisted = MinecraftServer.getServer().getPlayerList().getWhitelisted();
|
||||
int size = whitelisted.length;
|
||||
for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players) {
|
||||
for (EntityPlayer player : MinecraftServer.getServer().getPlayerList().players)
|
||||
{
|
||||
MinecraftServer.getServer().getPlayerList().getWhitelist().remove(player.getProfile());
|
||||
}
|
||||
|
||||
|
80
src/me/StevenLawson/TotalFreedomMod/TFM_Sync.java
Normal file
80
src/me/StevenLawson/TotalFreedomMod/TFM_Sync.java
Normal file
@ -0,0 +1,80 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TFM_Sync
|
||||
{
|
||||
|
||||
public static void playerMsg(final Player player, final String message)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
TFM_Util.playerMsg(player, message);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
|
||||
public static void playerKick(final Player player, final String reason)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.kickPlayer(reason);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
|
||||
public static void adminChatMessage(final CommandSender sender, final String message, final boolean isRed)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
TFM_Util.adminChatMessage(sender, message, isRed);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
|
||||
public static void autoEject(final Player player, final String kickMessage)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
TFM_Util.autoEject(player, kickMessage);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
|
||||
public static void bcastMsg(final String message, final ChatColor color)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
TFM_Util.bcastMsg(message, color);
|
||||
}
|
||||
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
}
|
@ -122,8 +122,10 @@ public class TFM_UuidManager
|
||||
return generateSpoofUuid(username);
|
||||
}
|
||||
|
||||
public static void rawSetUUID(String name, UUID uuid) {
|
||||
if (name == null || uuid == null || name.isEmpty()) {
|
||||
public static void rawSetUUID(String name, UUID uuid)
|
||||
{
|
||||
if (name == null || uuid == null || name.isEmpty())
|
||||
{
|
||||
TFM_Log.warning("Not setting raw UUID: name and uuid may not be null!");
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user