mirror of
https://github.com/essentials/Essentials.git
synced 2025-07-31 20:00:47 +02:00
Make chat handling more thread safe (and also faster)
This commit is contained in:
@@ -77,11 +77,17 @@ public class Settings implements ISettings
|
|||||||
{
|
{
|
||||||
return config.getInt("sethome-multiple." + set, config.getInt("sethome-multiple.default", 3));
|
return config.getInt("sethome-multiple." + set, config.getInt("sethome-multiple.default", 3));
|
||||||
}
|
}
|
||||||
|
private int chatRadius = 0;
|
||||||
|
|
||||||
|
private int _getChatRadius()
|
||||||
|
{
|
||||||
|
return config.getInt("chat.radius", config.getInt("chat-radius", 0));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getChatRadius()
|
public int getChatRadius()
|
||||||
{
|
{
|
||||||
return config.getInt("chat.radius", config.getInt("chat-radius", 0));
|
return chatRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,19 +119,29 @@ public class Settings implements ISettings
|
|||||||
{
|
{
|
||||||
return isCommandDisabled(cmd.getName());
|
return isCommandDisabled(cmd.getName());
|
||||||
}
|
}
|
||||||
|
private Set<String> disabledCommands = new HashSet<String>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCommandDisabled(String label)
|
public boolean isCommandDisabled(String label)
|
||||||
{
|
{
|
||||||
|
return disabledCommands.contains(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> getDisabledCommands()
|
||||||
|
{
|
||||||
|
Set<String> disCommands = new HashSet<String>();
|
||||||
for (String c : config.getStringList("disabled-commands"))
|
for (String c : config.getStringList("disabled-commands"))
|
||||||
{
|
{
|
||||||
if (!c.equalsIgnoreCase(label))
|
disCommands.add(c.toLowerCase(Locale.ENGLISH));
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return config.getBoolean("disable-" + label.toLowerCase(Locale.ENGLISH), false);
|
for (String c : config.getKeys(false))
|
||||||
|
{
|
||||||
|
if (c.startsWith("disable-"))
|
||||||
|
{
|
||||||
|
disCommands.add(c.substring(8).toLowerCase(Locale.ENGLISH));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return disCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,11 +208,17 @@ public class Settings implements ISettings
|
|||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
private String nicknamePrefix = "~";
|
||||||
|
|
||||||
|
private String _getNicknamePrefix()
|
||||||
|
{
|
||||||
|
return config.getString("nickname-prefix", "~");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNicknamePrefix()
|
public String getNicknamePrefix()
|
||||||
{
|
{
|
||||||
return config.getString("nickname-prefix", "~");
|
return nicknamePrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -250,9 +272,15 @@ public class Settings implements ISettings
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
private ChatColor operatorColor = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatColor getOperatorColor() throws Exception
|
public ChatColor getOperatorColor()
|
||||||
|
{
|
||||||
|
return operatorColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChatColor _getOperatorColor()
|
||||||
{
|
{
|
||||||
String colorName = config.getString("ops-name-color", null);
|
String colorName = config.getString("ops-name-color", null);
|
||||||
|
|
||||||
@@ -262,7 +290,7 @@ public class Settings implements ISettings
|
|||||||
}
|
}
|
||||||
if ("none".equalsIgnoreCase(colorName) || colorName.isEmpty())
|
if ("none".equalsIgnoreCase(colorName) || colorName.isEmpty())
|
||||||
{
|
{
|
||||||
throw new Exception();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -317,7 +345,7 @@ public class Settings implements ISettings
|
|||||||
{
|
{
|
||||||
return config.getString("backup.command", null);
|
return config.getString("backup.command", null);
|
||||||
}
|
}
|
||||||
private Map<String, MessageFormat> chatFormats = new HashMap<String, MessageFormat>();
|
private Map<String, MessageFormat> chatFormats = Collections.synchronizedMap(new HashMap<String, MessageFormat>());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MessageFormat getChatFormat(String group)
|
public MessageFormat getChatFormat(String group)
|
||||||
@@ -392,6 +420,17 @@ public class Settings implements ISettings
|
|||||||
signUsePerSecond = _getSignUsePerSecond();
|
signUsePerSecond = _getSignUsePerSecond();
|
||||||
kits = _getKits();
|
kits = _getKits();
|
||||||
chatFormats.clear();
|
chatFormats.clear();
|
||||||
|
changeDisplayName = _changeDisplayName();
|
||||||
|
disabledCommands = getDisabledCommands();
|
||||||
|
nicknamePrefix = _getNicknamePrefix();
|
||||||
|
operatorColor = _getOperatorColor();
|
||||||
|
changePlayerListName = _changePlayerListName();
|
||||||
|
configDebug = _isDebug();
|
||||||
|
prefixsuffixconfigured = _isPrefixSuffixConfigured();
|
||||||
|
addprefixsuffix = _addPrefixSuffix();
|
||||||
|
disablePrefix = _disablePrefix();
|
||||||
|
disableSuffix = _disableSuffix();
|
||||||
|
chatRadius = _getChatRadius();
|
||||||
}
|
}
|
||||||
private List<Integer> itemSpawnBl = new ArrayList<Integer>();
|
private List<Integer> itemSpawnBl = new ArrayList<Integer>();
|
||||||
|
|
||||||
@@ -479,11 +518,17 @@ public class Settings implements ISettings
|
|||||||
return config.getBoolean("protect.disable.warn-on-build-disallow", false);
|
return config.getBoolean("protect.disable.warn-on-build-disallow", false);
|
||||||
}
|
}
|
||||||
private boolean debug = false;
|
private boolean debug = false;
|
||||||
|
private boolean configDebug = false;
|
||||||
|
|
||||||
|
private boolean _isDebug()
|
||||||
|
{
|
||||||
|
return config.getBoolean("debug", false);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDebug()
|
public boolean isDebug()
|
||||||
{
|
{
|
||||||
return debug || config.getBoolean("debug", false);
|
return debug || configDebug;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -610,43 +655,79 @@ public class Settings implements ISettings
|
|||||||
{
|
{
|
||||||
return config.getBoolean("remove-god-on-disconnect", false);
|
return config.getBoolean("remove-god-on-disconnect", false);
|
||||||
}
|
}
|
||||||
|
private boolean changeDisplayName = true;
|
||||||
|
|
||||||
@Override
|
private boolean _changeDisplayName()
|
||||||
public boolean changeDisplayName()
|
|
||||||
{
|
{
|
||||||
return config.getBoolean("change-displayname", true);
|
return config.getBoolean("change-displayname", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean changePlayerListName()
|
public boolean changeDisplayName()
|
||||||
|
{
|
||||||
|
return changeDisplayName;
|
||||||
|
}
|
||||||
|
private boolean changePlayerListName = false;
|
||||||
|
|
||||||
|
private boolean _changePlayerListName()
|
||||||
{
|
{
|
||||||
return config.getBoolean("change-playerlist", false);
|
return config.getBoolean("change-playerlist", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean changePlayerListName()
|
||||||
|
{
|
||||||
|
return changePlayerListName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean useBukkitPermissions()
|
public boolean useBukkitPermissions()
|
||||||
{
|
{
|
||||||
return config.getBoolean("use-bukkit-permissions", false);
|
return config.getBoolean("use-bukkit-permissions", false);
|
||||||
}
|
}
|
||||||
|
private boolean prefixsuffixconfigured = false;
|
||||||
|
private boolean addprefixsuffix = false;
|
||||||
|
|
||||||
|
private boolean _addPrefixSuffix()
|
||||||
|
{
|
||||||
|
return config.getBoolean("add-prefix-suffix", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean _isPrefixSuffixConfigured()
|
||||||
|
{
|
||||||
|
return config.hasProperty("add-prefix-suffix");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addPrefixSuffix()
|
public boolean addPrefixSuffix()
|
||||||
{
|
{
|
||||||
return config.getBoolean("add-prefix-suffix", ess.getServer().getPluginManager().isPluginEnabled("EssentialsChat"));
|
return prefixsuffixconfigured ? addprefixsuffix : ess.getServer().getPluginManager().isPluginEnabled("EssentialsChat");
|
||||||
}
|
}
|
||||||
|
private boolean disablePrefix = false;
|
||||||
|
|
||||||
@Override
|
private boolean _disablePrefix()
|
||||||
public boolean disablePrefix()
|
|
||||||
{
|
{
|
||||||
return config.getBoolean("disablePrefix", false);
|
return config.getBoolean("disablePrefix", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean disableSuffix()
|
public boolean disablePrefix()
|
||||||
|
{
|
||||||
|
return disablePrefix;
|
||||||
|
}
|
||||||
|
private boolean disableSuffix = false;
|
||||||
|
|
||||||
|
private boolean _disableSuffix()
|
||||||
{
|
{
|
||||||
return config.getBoolean("disableSuffix", false);
|
return config.getBoolean("disableSuffix", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean disableSuffix()
|
||||||
|
{
|
||||||
|
return disableSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getAutoAfk()
|
public long getAutoAfk()
|
||||||
{
|
{
|
||||||
@@ -713,7 +794,7 @@ public class Settings implements ISettings
|
|||||||
{
|
{
|
||||||
return config.getBoolean("world-teleport-permissions", false);
|
return config.getBoolean("world-teleport-permissions", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isWorldHomePermissions()
|
public boolean isWorldHomePermissions()
|
||||||
{
|
{
|
||||||
@@ -800,38 +881,35 @@ public class Settings implements ISettings
|
|||||||
{
|
{
|
||||||
return (config.getLong("teleport-invulnerability", 0) > 0);
|
return (config.getLong("teleport-invulnerability", 0) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTeleportInvulnerability()
|
public boolean isTeleportInvulnerability()
|
||||||
{
|
{
|
||||||
return teleportInvulnerability;
|
return teleportInvulnerability;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long loginAttackDelay;
|
private long loginAttackDelay;
|
||||||
|
|
||||||
private long _getLoginAttackDelay()
|
private long _getLoginAttackDelay()
|
||||||
{
|
{
|
||||||
return config.getLong("login-attack-delay", 0) * 1000;
|
return config.getLong("login-attack-delay", 0) * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLoginAttackDelay()
|
public long getLoginAttackDelay()
|
||||||
{
|
{
|
||||||
return loginAttackDelay;
|
return loginAttackDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int signUsePerSecond;
|
private int signUsePerSecond;
|
||||||
|
|
||||||
private int _getSignUsePerSecond()
|
private int _getSignUsePerSecond()
|
||||||
{
|
{
|
||||||
final int perSec = config.getInt("sign-use-per-second", 4);
|
final int perSec = config.getInt("sign-use-per-second", 4);
|
||||||
return perSec > 0 ? perSec : 1;
|
return perSec > 0 ? perSec : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSignUsePerSecond()
|
public int getSignUsePerSecond()
|
||||||
{
|
{
|
||||||
return signUsePerSecond;
|
return signUsePerSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@ import java.util.Calendar;
|
|||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -284,10 +285,10 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final String opPrefix = ess.getSettings().getOperatorColor().toString();
|
final ChatColor opPrefix = ess.getSettings().getOperatorColor();
|
||||||
if (opPrefix.length() > 0)
|
if (opPrefix != null && opPrefix.toString().length() > 0)
|
||||||
{
|
{
|
||||||
prefix.insert(0, opPrefix);
|
prefix.insert(0, opPrefix.toString());
|
||||||
suffix = "§f";
|
suffix = "§f";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,7 +326,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
{
|
{
|
||||||
output = Util.lastCode(strPrefix) + nickname.substring(0, 14);
|
output = Util.lastCode(strPrefix) + nickname.substring(0, 14);
|
||||||
}
|
}
|
||||||
if (output.charAt(output.length() - 1) == '§') {
|
if (output.charAt(output.length() - 1) == '§')
|
||||||
|
{
|
||||||
output = output.substring(0, output.length() - 1);
|
output = output.substring(0, output.length() - 1);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
@@ -639,7 +641,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
{
|
{
|
||||||
return vanished;
|
return vanished;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVanished(final boolean set)
|
public void setVanished(final boolean set)
|
||||||
{
|
{
|
||||||
vanished = set;
|
vanished = set;
|
||||||
@@ -671,21 +673,23 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
|||||||
final boolean set = !vanished;
|
final boolean set = !vanished;
|
||||||
this.setVanished(set);
|
this.setVanished(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkSignThrottle() {
|
public boolean checkSignThrottle()
|
||||||
if (isSignThrottled()) {
|
{
|
||||||
|
if (isSignThrottled())
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
updateThrottle();
|
updateThrottle();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSignThrottled()
|
public boolean isSignThrottled()
|
||||||
{
|
{
|
||||||
final long minTime = lastThrottledAction + (1000 / ess.getSettings().getSignUsePerSecond());
|
final long minTime = lastThrottledAction + (1000 / ess.getSettings().getSignUsePerSecond());
|
||||||
return (System.currentTimeMillis() < minTime);
|
return (System.currentTimeMillis() < minTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateThrottle()
|
public void updateThrottle()
|
||||||
{
|
{
|
||||||
lastThrottledAction = System.currentTimeMillis();;
|
lastThrottledAction = System.currentTimeMillis();;
|
||||||
|
@@ -440,14 +440,14 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||||||
|
|
||||||
public List<String> getIgnoredPlayers()
|
public List<String> getIgnoredPlayers()
|
||||||
{
|
{
|
||||||
return config.getStringList("ignore");
|
return Collections.synchronizedList(config.getStringList("ignore"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIgnoredPlayers(List<String> players)
|
public void setIgnoredPlayers(List<String> players)
|
||||||
{
|
{
|
||||||
if (players == null || players.isEmpty())
|
if (players == null || players.isEmpty())
|
||||||
{
|
{
|
||||||
ignoredPlayers = new ArrayList<String>();
|
ignoredPlayers = Collections.synchronizedList(new ArrayList<String>());
|
||||||
config.removeProperty("ignore");
|
config.removeProperty("ignore");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -466,7 +466,7 @@ public abstract class UserData extends PlayerExtension implements IConf
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isIgnoredPlayer(user);
|
return isIgnoredPlayer(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isIgnoredPlayer(IUser user)
|
public boolean isIgnoredPlayer(IUser user)
|
||||||
|
@@ -3,6 +3,7 @@ package com.earth2me.essentials.chat;
|
|||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@@ -40,9 +41,13 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
|
|||||||
event.setMessage(Util.formatMessage(user, "essentials.chat", event.getMessage()));
|
event.setMessage(Util.formatMessage(user, "essentials.chat", event.getMessage()));
|
||||||
String group = user.getGroup();
|
String group = user.getGroup();
|
||||||
String world = user.getWorld().getName();
|
String world = user.getWorld().getName();
|
||||||
event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[]
|
MessageFormat format = ess.getSettings().getChatFormat(group);
|
||||||
{
|
synchronized (format)
|
||||||
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
|
{
|
||||||
}));
|
event.setFormat(format.format(new Object[]
|
||||||
|
{
|
||||||
|
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user