Rework tags (now they won't duplicate when Essentials changes display name).

This commit is contained in:
StevenLawson 2014-08-12 18:25:57 -04:00
parent 891d8d178f
commit 1a50c16d9a
3 changed files with 79 additions and 59 deletions

View File

@ -18,20 +18,30 @@ public class Command_tag extends TFM_Command
{
public static final List<String> FORBIDDEN_WORDS = Arrays.asList(new String[]
{
"admin", "owner", "moderator", "developer", "&k"
"admin", "owner", "moderator", "developer"
});
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
if (args.length == 1)
{
if ("clearall".equals(args[0]))
if ("list".equalsIgnoreCase(args[0]))
{
playerMsg("Tags for all online players:");
for (final Player player : server.getOnlinePlayers())
{
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
if (playerdata.getTag() != null)
{
playerMsg(player.getName() + ": " + playerdata.getTag());
}
}
return true;
}
else if ("clearall".equalsIgnoreCase(args[0]))
{
if (!TFM_AdminList.isSuperAdmin(sender))
{
@ -40,47 +50,44 @@ public class Command_tag extends TFM_Command
}
TFM_Util.adminAction(sender.getName(), "Removing all tags", false);
int count = 0;
for (Player player : server.getOnlinePlayers())
{
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
int count = 0;
for (final Player player : server.getOnlinePlayers())
{
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
if (playerdata.getTag() != null)
{
count++;
TFM_PlayerData.getPlayerData(player).setTag(null);
playerdata.setTag(null);
}
}
playerMsg(count + " tag(s) removed.");
return true;
}
else if ("off".equalsIgnoreCase(args[0]))
{
if (senderIsConsole)
{
playerMsg("Only in-game players can set tags. Use \"/tag clearall\" to reset all tags.");
return true;
playerMsg("\"/tag off\" can't be used from the console. Use \"/tag clear <player>\" or \"/tag clearall\" instead.");
}
if ("off".equals(args[0]))
else
{
TFM_PlayerData.getPlayerData(sender_p).setTag(null);
playerMsg("Your tag has been removed.");
return true;
}
if (ChatColor.stripColor(TFM_Util.colorize(args[0])).length() > 20)
return true;
}
else
{
playerMsg("That tag is too long [Max = 20 characters, not including color codes].");
return true;
}
return false;
}
if (args.length == 2)
}
else if (args.length >= 2)
{
if ("clear".equals(args[0]))
if ("clear".equalsIgnoreCase(args[0]))
{
if (!TFM_AdminList.isSuperAdmin(sender))
{
@ -98,42 +105,56 @@ public class Command_tag extends TFM_Command
TFM_PlayerData.getPlayerData(player).setTag(null);
playerMsg("Removed " + player.getName() + "'s tag.");
return true;
}
}
if ("set".equals(args[0]))
else if ("set".equalsIgnoreCase(args[0]))
{
final String tag = StringUtils.join(args, " ", 1, args.length);
final String inputTag = StringUtils.join(args, " ", 1, args.length);
final String outputTag = TFM_Util.colorize(StringUtils.replaceEachRepeatedly(StringUtils.strip(inputTag),
new String[]
{
"" + ChatColor.COLOR_CHAR, "&k"
},
new String[]
{
"", ""
}
)) + ChatColor.RESET;
if (!TFM_AdminList.isSuperAdmin(sender))
{
for (String word : FORBIDDEN_WORDS)
final String rawTag = ChatColor.stripColor(outputTag).toLowerCase();
if (rawTag.length() > 20)
{
if (!tag.toLowerCase().contains(word))
{
continue;
playerMsg("That tag is too long (Max is 20 characters).");
return true;
}
if (word.contains(String.valueOf(ChatColor.COLOR_CHAR)))
for (String word : FORBIDDEN_WORDS)
{
playerMsg("That tag contains a forbidden color-code.");
if (rawTag.contains(word))
{
playerMsg("That tag contains a forbidden word.");
return true;
}
}
}
TFM_PlayerData.getPlayerData(sender_p).setTag(outputTag);
playerMsg("Tag set to '" + outputTag + "'.");
return true;
}
else
{
playerMsg("That tag contains a forbidden word.");
}
return true;
}
}
TFM_PlayerData.getPlayerData(sender_p).setTag(TFM_Util.colorize(tag));
playerMsg("Tag set to " + TFM_Util.colorize(tag));
return true;
}
return false;
}
}
else
{
return false;
}
}
}

View File

@ -630,9 +630,8 @@ public class TFM_PlayerListener implements Listener
// Set the tag
if (playerdata.getTag() != null)
{
player.setDisplayName((playerdata.getTag() + " " + player.getDisplayName().replaceAll(" ", "")));
event.setFormat("<" + playerdata.getTag().replaceAll("%", "%%") + " %1$s> %2$s");
}
}
catch (Exception ex)
{

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.Bridge.TFM_EssentialsBridge;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -72,7 +73,6 @@ public class TFM_PlayerData
return playerdata;
}
Iterator<Entry<Player, TFM_PlayerData>> it = userinfo.entrySet().iterator();
while (it.hasNext())
{
@ -391,7 +391,7 @@ public class TFM_PlayerData
player.setOp(false);
player.setGameMode(GameMode.SURVIVAL);
player.setFlying(false);
player.setDisplayName(player.getName());
TFM_EssentialsBridge.setNickname(player.getName(), player.getName());
player.closeInventory();
player.setTotalExperience(0);