Migrated /list-, AdminChat- and Login message-colors to TFM_PlayerRank

Reverted colors due to popular request
This commit is contained in:
unknown 2013-12-03 14:05:06 +01:00
parent d4c3a4ad45
commit 27a04635a2
6 changed files with 162 additions and 139 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun Dec 01 19:01:54 CET 2013
build.number=658
#Tue Dec 03 14:03:33 CET 2013
build.number=663

View File

@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerRank;
import me.StevenLawson.TotalFreedomMod.TFM_Superadmin;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
@ -60,64 +61,8 @@ public class Command_list extends TFM_Command
{
continue;
}
final StringBuilder prefix = new StringBuilder();
if (TFM_Util.DEVELOPERS.contains(player.getName()))
{
prefix.append(ChatColor.DARK_PURPLE).append("[Dev]");
names.add(prefix.append(player.getName()).toString());
continue;
}
if (userSuperadmin)
{
TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(player.getName());
if (player.getName().equals("markbyron"))
{
prefix.append(ChatColor.DARK_RED).append("[Owner]");
names.add(prefix.append(player.getName()).toString());
continue;
}
if (entry == null)
{
entry = TFM_SuperadminList.getAdminEntryByIP(player.getAddress().getAddress().getHostAddress().trim());
if (entry == null)
{
prefix.append(ChatColor.AQUA).append("[SA]");
names.add(prefix.append(player.getName()).toString());
continue;
}
}
if (entry.isSeniorAdmin())
{
prefix.append(ChatColor.GOLD).append("[SrA]");
}
else if (entry.isTelnetAdmin())
{
prefix.append(ChatColor.DARK_GREEN).append("[STA]");
}
else
{
prefix.append(ChatColor.AQUA).append("[SA]");
}
}
else
{
if (player.isOp())
{
prefix.append(ChatColor.BLUE).append("[OP]");
}
else
{
prefix.append(ChatColor.GREEN);
}
}
names.add(prefix.append(player.getName()).toString());
names.add(TFM_PlayerRank.fromSender(sender).getPrefix() + player.getName());
}
onlineUsers.append("Connected ");

View File

@ -687,7 +687,7 @@ public class TFM_PlayerListener implements Listener
TFM_UserList.getInstance(TotalFreedomMod.plugin).addUser(player);
boolean impostor = TFM_SuperadminList.isSuperadminImpostor(player);
final boolean impostor = TFM_SuperadminList.isSuperadminImpostor(player);
if (impostor || TFM_SuperadminList.isUserSuperadmin(player))
{
@ -717,6 +717,8 @@ public class TFM_PlayerListener implements Listener
player.setOp(true);
}
} else if (TFM_Util.DEVELOPERS.contains(player.getName())) {
TFM_Util.bcastMsg(ChatColor.AQUA + player.getName() + " is " + TFM_Util.getRank(player));
}
if (TFM_ConfigEntry.ADMIN_ONLY_MODE.getBoolean())

View File

@ -0,0 +1,120 @@
package me.StevenLawson.TotalFreedomMod;
import static me.StevenLawson.TotalFreedomMod.TFM_Util.DEVELOPERS;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public enum TFM_PlayerRank
{
IMPOSTOR("an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "Impostor", ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + "[IMP]"),
NON_OP("a " + ChatColor.GREEN + "Non-OP", ChatColor.GREEN.toString()),
OP("an " + ChatColor.RED + "OP", ChatColor.RED + "[OP]"),
SUPER("a " + ChatColor.GOLD + "Super Admin", ChatColor.GOLD + "[SA]"),
TELNET("a " + ChatColor.DARK_GREEN + "Super Telnet Admin", ChatColor.DARK_GREEN + "[STA]"),
SENIOR("a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"),
OWNER("the " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]"),
CONSOLE("The " + ChatColor.DARK_PURPLE + "Console", ChatColor.DARK_PURPLE + "[Console]");
private String loginMessage;
private String prefix;
private TFM_PlayerRank(String loginMessage, String prefix)
{
this.loginMessage = loginMessage;
this.prefix = prefix;
}
public static TFM_PlayerRank fromSender(CommandSender sender)
{
if (!(sender instanceof Player)) {
return CONSOLE;
}
if (TFM_SuperadminList.isSuperadminImpostor(sender))
{
return IMPOSTOR;
}
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry((Player) sender);
final TFM_PlayerRank rank;
if (entry != null && entry.isActivated())
{
if (sender.getName().equals("markbyron"))
{
return OWNER;
}
if (entry.isSeniorAdmin())
{
rank = SENIOR;
}
else if (entry.isTelnetAdmin())
{
rank = TELNET;
}
else
{
rank = SUPER;
}
final String loginMessage = entry.getCustomLoginMessage();
if (loginMessage != null && !loginMessage.isEmpty())
{
rank.setLoginMessage(ChatColor.translateAlternateColorCodes('&', loginMessage));
}
else
{
if (DEVELOPERS.contains(sender.getName()))
{
rank.setPrefix(ChatColor.DARK_PURPLE + "[Dev]");
rank.setLoginMessage("a " + ChatColor.DARK_PURPLE + "Developer");
}
}
}
else
{
if (sender.isOp())
{
rank = OP;
}
else
{
rank = NON_OP;
}
if (DEVELOPERS.contains(sender.getName()))
{
rank.setPrefix(ChatColor.DARK_PURPLE + "[Dev]");
rank.setLoginMessage("a " + ChatColor.DARK_PURPLE + "Developer");
}
}
return rank;
}
public String getPrefix()
{
return prefix;
}
public void setPrefix(String prefix)
{
this.prefix = prefix;
}
public void setLoginMessage(String rank)
{
this.loginMessage = rank;
}
public String getLoginMessage()
{
return loginMessage;
}
}

View File

@ -160,6 +160,34 @@ public class TFM_SuperadminList
}
}
public static TFM_Superadmin getAdminEntry(Player player)
{
final String name = player.getName().toLowerCase();
if (Bukkit.getOnlineMode())
{
if (superadminList.containsKey(name))
{
return superadminList.get(name);
}
}
try
{
final String ip = player.getAddress().getAddress().getHostAddress().trim();
if (ip != null && !ip.isEmpty())
{
return getAdminEntryByIP(ip);
}
}
catch (Exception ex)
{
return null;
}
return null;
}
@Deprecated
public static TFM_Superadmin getAdminEntry(String name)
{
name = name.toLowerCase();
@ -174,11 +202,6 @@ public class TFM_SuperadminList
}
}
public static TFM_Superadmin getAdminEntry(Player player)
{
return getAdminEntry(player.getName().toLowerCase());
}
public static TFM_Superadmin getAdminEntryByIP(String ip)
{
return getAdminEntryByIP(ip, false);

View File

@ -298,6 +298,7 @@ public class TFM_Util
return TFM_Util.mobtypes.get(mobname);
}
@Deprecated
private static void copy(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
@ -414,47 +415,10 @@ public class TFM_Util
}
}
@Deprecated
public static String getRank(CommandSender sender)
{
if (TFM_SuperadminList.isSuperadminImpostor(sender))
{
return "an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "impostor" + ChatColor.RESET + ChatColor.AQUA + "!";
}
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName());
if (entry != null && entry.isActivated())
{
String loginMessage = entry.getCustomLoginMessage();
if (loginMessage != null)
{
if (!loginMessage.isEmpty())
{
return ChatColor.translateAlternateColorCodes('&', loginMessage);
}
}
if (entry.isSeniorAdmin())
{
return "a " + ChatColor.GOLD + "Senior Admin" + ChatColor.AQUA + ".";
}
else if (entry.isTelnetAdmin())
{
return "a " + ChatColor.DARK_GREEN + "Super Telnet Admin" + ChatColor.AQUA + ".";
}
else
{
return "a " + ChatColor.AQUA + "Super Admin" + ChatColor.AQUA + ".";
}
}
if (sender.isOp())
{
return "an " + ChatColor.BLUE + "OP" + ChatColor.AQUA + ".";
}
return "a " + ChatColor.GREEN + "non-OP" + ChatColor.AQUA + ".";
return TFM_PlayerRank.fromSender(sender).getLoginMessage();
}
public static Date parseDateOffset(String time)
@ -769,7 +733,7 @@ public class TFM_Util
public static void adminChatMessage(CommandSender sender, String message, boolean senderIsConsole)
{
String name = sender.getName() + " " + getPrefix(sender, senderIsConsole);
String name = sender.getName() + " " + getPrefix(sender, senderIsConsole) + ChatColor.WHITE;
TFM_Log.info("[ADMIN] " + name + ": " + message);
for (Player player : Bukkit.getOnlinePlayers())
@ -781,41 +745,10 @@ public class TFM_Util
}
}
@Deprecated
public static String getPrefix(CommandSender sender, boolean senderIsConsole)
{
String prefix;
if (senderIsConsole)
{
prefix = ChatColor.BLUE + "(Console)";
}
else
{
final TFM_Superadmin entry = TFM_SuperadminList.getAdminEntry(sender.getName());
if (entry == null)
{
return ChatColor.AQUA + "(SA)";
}
else if (entry.isSeniorAdmin())
{
prefix = ChatColor.GOLD + "(SrA)";
}
else if (entry.isTelnetAdmin())
{
prefix = ChatColor.DARK_GREEN + "(STA)";
}
else
{
prefix = ChatColor.AQUA + "(SA)";
}
if (DEVELOPERS.contains(sender.getName()))
{
prefix = ChatColor.DARK_PURPLE + "(Dev)";
}
}
return prefix + ChatColor.WHITE;
return TFM_PlayerRank.fromSender(sender).getPrefix();
}
//getField: Borrowed from WorldEdit