Add debug output to keyword replacer

This commit is contained in:
KHobbits 2013-08-30 01:36:35 +01:00
parent 52e9cc6ba1
commit 2973b1335c
1 changed files with 46 additions and 23 deletions

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.textreader;
import com.earth2me.essentials.ExecuteTimer;
import net.ess3.api.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DateUtil;
@ -20,6 +21,7 @@ import org.bukkit.plugin.Plugin;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.PlayerList;
import static com.earth2me.essentials.PlayerList.getMergedList;
import java.util.logging.Level;
public class KeywordReplacer implements IText
@ -28,6 +30,7 @@ public class KeywordReplacer implements IText
private final transient List<String> replaced;
private final transient IEssentials ess;
private final transient boolean extended;
private transient ExecuteTimer execTimer;
public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess)
{
@ -50,18 +53,22 @@ public class KeywordReplacer implements IText
private void replaceKeywords(final CommandSender sender)
{
String displayName, ipAddress, balance, mails, world;
String worlds, online, unique, playerlist, date, time;
String worlds, online, unique, onlineList, date, time;
String worldTime12, worldTime24, worldDate, plugins;
String userName, version, address, tps, uptime;
String coords;
execTimer = new ExecuteTimer();
execTimer.start();
if (sender instanceof Player)
{
final User user = ess.getUser(sender);
user.setDisplayNick();
displayName = user.getDisplayName();
displayName = user.getDisplayName();
ipAddress = user.getAddress() == null || user.getAddress().getAddress() == null ? "" : user.getAddress().getAddress().toString();
address = user.getAddress() == null ? "" : user.getAddress().toString();
execTimer.mark("User Grab");
balance = NumberUtil.displayCurrency(user.getMoney(), ess);
execTimer.mark("Economy");
mails = Integer.toString(user.getMails().size());
final Location location = user.getLocation();
world = location == null || location.getWorld() == null ? "" : location.getWorld().getName();
@ -74,6 +81,7 @@ public class KeywordReplacer implements IText
{
displayName = address = ipAddress = balance = mails = world = worldTime12 = worldTime24 = worldDate = coords = "";
}
execTimer.mark("Player variables");
Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, extended);
userName = sender.getName();
@ -87,6 +95,7 @@ public class KeywordReplacer implements IText
}
online = Integer.toString(ess.getServer().getOnlinePlayers().length - playerHidden);
unique = Integer.toString(ess.getUserMap().getUniqueUsers());
execTimer.mark("Player list");
final StringBuilder worldsBuilder = new StringBuilder();
for (World w : ess.getServer().getWorlds())
@ -112,7 +121,7 @@ public class KeywordReplacer implements IText
}
playerlistBuilder.append(p.getDisplayName());
}
playerlist = playerlistBuilder.toString();
onlineList = playerlistBuilder.toString();
final StringBuilder pluginlistBuilder = new StringBuilder();
for (Plugin p : ess.getServer().getPluginManager().getPlugins())
@ -124,29 +133,33 @@ public class KeywordReplacer implements IText
pluginlistBuilder.append(p.getDescription().getName());
}
plugins = pluginlistBuilder.toString();
execTimer.mark("List builders");
date = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
time = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
version = ess.getServer().getVersion();
tps = Double.toString(ess.getTimer().getAverageTPS());
uptime = DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime());
execTimer.mark("Server Dates");
for (int i = 0; i < input.getLines().size(); i++)
{
String line = input.getLines().get(i);
line = line.replace("{PLAYER}", displayName);
line = line.replace("{DISPLAYNAME}", displayName);
line = line.replace("{USERNAME}", userName);
line = line.replace("{USERNAME}", userName);
line = line.replace("{BALANCE}", balance);
line = line.replace("{MAILS}", mails);
line = line.replace("{WORLD}", world);
line = line.replace("{ONLINE}", online);
line = line.replace("{UNIQUE}", unique);
line = line.replace("{WORLDS}", worlds);
line = line.replace("{PLAYERLIST}", playerlist);
line = line.replace("{PLAYERLIST}", onlineList);
line = line.replace("{TIME}", time);
line = line.replace("{DATE}", date);
line = line.replace("{WORLDTIME12}", worldTime12);
@ -155,35 +168,45 @@ public class KeywordReplacer implements IText
line = line.replace("{COORDS}", coords);
line = line.replace("{TPS}", tps);
line = line.replace("{UPTIME}", uptime);
if (extended)
{
line = line.replace("{IP}", ipAddress);
line = line.replace("{ADDRESS}", address);
line = line.replace("{PLUGINS}", plugins);
line = line.replace("{VERSION}", version);
}
for (String groupName : playerList.keySet()) {
final List<User> groupUsers = playerList.get(groupName);
if (groupUsers != null && !groupUsers.isEmpty())
for (String groupName : playerList.keySet())
{
line = line.replaceAll("\\{PLAYERLIST\\:" + groupName.toUpperCase() + "(?:\\:([^\\{\\}]*))?\\}",
PlayerList.listUsers(ess, groupUsers, " "));
}
}
boolean doReplace = true;
while (doReplace) {
final String newLine = line.replaceAll("\\{PLAYERLIST\\:\\w*(?:\\:([^\\{\\}]*))?\\}", "$1");
if (newLine.equals(line)) {
doReplace = false;
final List<User> groupUsers = playerList.get(groupName);
if (groupUsers != null && !groupUsers.isEmpty())
{
line = line.replaceAll("\\{PLAYERLIST\\:" + groupName.toUpperCase() + "(?:\\:([^\\{\\}]*))?\\}",
PlayerList.listUsers(ess, groupUsers, " "));
}
}
boolean doReplace = true;
while (doReplace)
{
final String newLine = line.replaceAll("\\{PLAYERLIST\\:\\w*(?:\\:([^\\{\\}]*))?\\}", "$1");
if (newLine.equals(line))
{
doReplace = false;
}
line = newLine;
}
line = newLine;
}
replaced.add(line);
}
execTimer.mark("String replace");
final String timeroutput = execTimer.end();
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "Keyword Replacer " + timeroutput);
}
}
@Override