summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-07-15 20:35:09 +0200
committersnowleo <schneeleo@gmail.com>2011-07-15 20:35:09 +0200
commitd2db6348d92752ee6a07a875ccd63ee779b32361 (patch)
treeb9e7fec0ceb18e4bc53e12c151fff771ad7f4a6e
parentae7275c7ad4de45c2cf2b0903f1a27724d0f2c25 (diff)
downloadEssentials-d2db6348d92752ee6a07a875ccd63ee779b32361.tar
Essentials-d2db6348d92752ee6a07a875ccd63ee779b32361.tar.gz
Essentials-d2db6348d92752ee6a07a875ccd63ee779b32361.tar.lz
Essentials-d2db6348d92752ee6a07a875ccd63ee779b32361.tar.xz
Essentials-d2db6348d92752ee6a07a875ccd63ee779b32361.zip
Moved user.setDisplayName() from EssentialsChat to Essentials
Added new config: change-displayname (default to true) It allows users to disable the setDisplayName, if they have other plugins that modify the display name Updated user.getNick() to use StringBuilder
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java25
-rw-r--r--Essentials/src/com/earth2me/essentials/Settings.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java25
-rw-r--r--Essentials/src/config.yml3
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java10
5 files changed, 49 insertions, 19 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 64ff9ae7b..a975b7c44 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -60,6 +60,10 @@ public class EssentialsPlayerListener extends PlayerListener
{
}
}
+ if (ess.getSettings().changeDisplayName())
+ {
+ user.setDisplayName(user.getNick());
+ }
}
@Override
@@ -85,6 +89,10 @@ public class EssentialsPlayerListener extends PlayerListener
user.setAfk(false);
ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
}
+ if (ess.getSettings().changeDisplayName())
+ {
+ user.setDisplayName(user.getNick());
+ }
}
@Override
@@ -266,9 +274,13 @@ public class EssentialsPlayerListener extends PlayerListener
return;
}
- user.setDisplayName(user.getNick());
+ if (ess.getSettings().changeDisplayName())
+ {
+ user.setDisplayName(user.getNick());
+ }
user.setAfk(false);
- if (user.isAuthorized("essentials.sleepingignored")) {
+ if (user.isAuthorized("essentials.sleepingignored"))
+ {
user.setSleepingIgnored(true);
}
@@ -344,6 +356,10 @@ public class EssentialsPlayerListener extends PlayerListener
return;
}
User user = ess.getUser(event.getPlayer());
+ if (ess.getSettings().changeDisplayName())
+ {
+ user.setDisplayName(user.getNick());
+ }
if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
{
return;
@@ -637,7 +653,10 @@ public class EssentialsPlayerListener extends PlayerListener
@Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{
- if (event.isCancelled()) return;
+ if (event.isCancelled())
+ {
+ return;
+ }
User user = ess.getUser(event.getPlayer());
String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase();
if (("msg".equals(cmd) || "r".equals(cmd) || "mail".equals(cmd)))
diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java
index 443878815..25222deb1 100644
--- a/Essentials/src/com/earth2me/essentials/Settings.java
+++ b/Essentials/src/com/earth2me/essentials/Settings.java
@@ -395,5 +395,10 @@ public class Settings implements IConf
{
return config.getBoolean("remove-god-on-disconnect", false);
}
+
+ boolean changeDisplayName()
+ {
+ return config.getBoolean("change-displayname", true);
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 4de4d2f7f..65cbef512 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -223,26 +223,39 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
public String getNick()
{
- String nickname = getNickname();
- if (ess.getSettings().isCommandDisabled("nick") || nickname == null || nickname.isEmpty() || nickname.equals(getName()))
+ final StringBuilder nickname = new StringBuilder();
+ final String nick = getNickname();
+ if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName()))
{
- nickname = getName();
+ nickname.append(getName());
}
else
{
- nickname = ess.getSettings().getNicknamePrefix() + nickname;
+ nickname.append(ess.getSettings().getNicknamePrefix()).append(nick);
}
if (isOp())
{
try
{
- nickname = ess.getSettings().getOperatorColor().toString() + nickname + "§f";
+ nickname.insert(0, ess.getSettings().getOperatorColor().toString());
+ nickname.append("§f");
}
catch (Exception e)
{
}
}
- return nickname;
+
+ final String prefix = ess.getPermissionsHandler().getPrefix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
+ final String suffix = ess.getPermissionsHandler().getSuffix(this).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName());
+
+ nickname.insert(0, prefix);
+ nickname.append(suffix);
+ if (suffix.length() > 1 && suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§"))
+ {
+ nickname.append("§f");
+ }
+
+ return nickname.toString();
}
public Teleport getTeleport()
diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml
index c56f4a39c..50c71aa65 100644
--- a/Essentials/src/config.yml
+++ b/Essentials/src/config.yml
@@ -34,6 +34,9 @@ ops-name-color: 'c'
# The character(s) to prefix all nicknames, so that you know they are not true usernames.
nickname-prefix: '~'
+# Disable this if you have any other plugin, that modifies the displayname of a user.
+change-displayname: true
+
# The delay, in seconds, required between /home, /tp, etc.
teleport-cooldown: 0
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
index 57c41de72..466641e32 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
@@ -35,15 +35,6 @@ public class EssentialsChatPlayerListener extends PlayerListener
public void onPlayerJoin(final PlayerJoinEvent event)
{
final User user = ess.getUser(event.getPlayer());
- updateDisplayName(user);
- }
-
- private void updateDisplayName(final User user)
- {
- final String prefix = ess.getPermissionsHandler().getPrefix(user).replace('&', '§').replace("{WORLDNAME}", user.getWorld().getName());
- final String suffix = ess.getPermissionsHandler().getSuffix(user).replace('&', '§').replace("{WORLDNAME}", user.getWorld().getName());
-
- user.setDisplayName(prefix + user.getNick() + suffix + (suffix.length() > 1 && suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§") ? "" : "§f"));
}
@Override
@@ -58,7 +49,6 @@ public class EssentialsChatPlayerListener extends PlayerListener
return;
final User user = ess.getUser(event.getPlayer());
- updateDisplayName(user);
if (user.isAuthorized("essentials.chat.color"))
{