mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-03-02 11:11:58 +01:00
Add debug output to keyword replacer
This commit is contained in:
parent
52e9cc6ba1
commit
2973b1335c
@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials.textreader;
|
package com.earth2me.essentials.textreader;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.ExecuteTimer;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
@ -20,6 +21,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.PlayerList;
|
import com.earth2me.essentials.PlayerList;
|
||||||
import static com.earth2me.essentials.PlayerList.getMergedList;
|
import static com.earth2me.essentials.PlayerList.getMergedList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
public class KeywordReplacer implements IText
|
public class KeywordReplacer implements IText
|
||||||
@ -28,6 +30,7 @@ public class KeywordReplacer implements IText
|
|||||||
private final transient List<String> replaced;
|
private final transient List<String> replaced;
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
private final transient boolean extended;
|
private final transient boolean extended;
|
||||||
|
private transient ExecuteTimer execTimer;
|
||||||
|
|
||||||
public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess)
|
public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess)
|
||||||
{
|
{
|
||||||
@ -50,10 +53,12 @@ public class KeywordReplacer implements IText
|
|||||||
private void replaceKeywords(final CommandSender sender)
|
private void replaceKeywords(final CommandSender sender)
|
||||||
{
|
{
|
||||||
String displayName, ipAddress, balance, mails, world;
|
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 worldTime12, worldTime24, worldDate, plugins;
|
||||||
String userName, version, address, tps, uptime;
|
String userName, version, address, tps, uptime;
|
||||||
String coords;
|
String coords;
|
||||||
|
execTimer = new ExecuteTimer();
|
||||||
|
execTimer.start();
|
||||||
if (sender instanceof Player)
|
if (sender instanceof Player)
|
||||||
{
|
{
|
||||||
final User user = ess.getUser(sender);
|
final User user = ess.getUser(sender);
|
||||||
@ -61,7 +66,9 @@ public class KeywordReplacer implements IText
|
|||||||
displayName = user.getDisplayName();
|
displayName = user.getDisplayName();
|
||||||
ipAddress = user.getAddress() == null || user.getAddress().getAddress() == null ? "" : user.getAddress().getAddress().toString();
|
ipAddress = user.getAddress() == null || user.getAddress().getAddress() == null ? "" : user.getAddress().getAddress().toString();
|
||||||
address = user.getAddress() == null ? "" : user.getAddress().toString();
|
address = user.getAddress() == null ? "" : user.getAddress().toString();
|
||||||
|
execTimer.mark("User Grab");
|
||||||
balance = NumberUtil.displayCurrency(user.getMoney(), ess);
|
balance = NumberUtil.displayCurrency(user.getMoney(), ess);
|
||||||
|
execTimer.mark("Economy");
|
||||||
mails = Integer.toString(user.getMails().size());
|
mails = Integer.toString(user.getMails().size());
|
||||||
final Location location = user.getLocation();
|
final Location location = user.getLocation();
|
||||||
world = location == null || location.getWorld() == null ? "" : location.getWorld().getName();
|
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 = "";
|
displayName = address = ipAddress = balance = mails = world = worldTime12 = worldTime24 = worldDate = coords = "";
|
||||||
}
|
}
|
||||||
|
execTimer.mark("Player variables");
|
||||||
Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, extended);
|
Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, extended);
|
||||||
|
|
||||||
userName = sender.getName();
|
userName = sender.getName();
|
||||||
@ -87,6 +95,7 @@ public class KeywordReplacer implements IText
|
|||||||
}
|
}
|
||||||
online = Integer.toString(ess.getServer().getOnlinePlayers().length - playerHidden);
|
online = Integer.toString(ess.getServer().getOnlinePlayers().length - playerHidden);
|
||||||
unique = Integer.toString(ess.getUserMap().getUniqueUsers());
|
unique = Integer.toString(ess.getUserMap().getUniqueUsers());
|
||||||
|
execTimer.mark("Player list");
|
||||||
|
|
||||||
final StringBuilder worldsBuilder = new StringBuilder();
|
final StringBuilder worldsBuilder = new StringBuilder();
|
||||||
for (World w : ess.getServer().getWorlds())
|
for (World w : ess.getServer().getWorlds())
|
||||||
@ -112,7 +121,7 @@ public class KeywordReplacer implements IText
|
|||||||
}
|
}
|
||||||
playerlistBuilder.append(p.getDisplayName());
|
playerlistBuilder.append(p.getDisplayName());
|
||||||
}
|
}
|
||||||
playerlist = playerlistBuilder.toString();
|
onlineList = playerlistBuilder.toString();
|
||||||
|
|
||||||
final StringBuilder pluginlistBuilder = new StringBuilder();
|
final StringBuilder pluginlistBuilder = new StringBuilder();
|
||||||
for (Plugin p : ess.getServer().getPluginManager().getPlugins())
|
for (Plugin p : ess.getServer().getPluginManager().getPlugins())
|
||||||
@ -125,6 +134,8 @@ public class KeywordReplacer implements IText
|
|||||||
}
|
}
|
||||||
plugins = pluginlistBuilder.toString();
|
plugins = pluginlistBuilder.toString();
|
||||||
|
|
||||||
|
execTimer.mark("List builders");
|
||||||
|
|
||||||
date = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
|
date = DateFormat.getDateInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
|
||||||
time = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
|
time = DateFormat.getTimeInstance(DateFormat.MEDIUM, ess.getI18n().getCurrentLocale()).format(new Date());
|
||||||
|
|
||||||
@ -133,6 +144,8 @@ public class KeywordReplacer implements IText
|
|||||||
tps = Double.toString(ess.getTimer().getAverageTPS());
|
tps = Double.toString(ess.getTimer().getAverageTPS());
|
||||||
uptime = DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime());
|
uptime = DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime());
|
||||||
|
|
||||||
|
execTimer.mark("Server Dates");
|
||||||
|
|
||||||
for (int i = 0; i < input.getLines().size(); i++)
|
for (int i = 0; i < input.getLines().size(); i++)
|
||||||
{
|
{
|
||||||
String line = input.getLines().get(i);
|
String line = input.getLines().get(i);
|
||||||
@ -146,7 +159,7 @@ public class KeywordReplacer implements IText
|
|||||||
line = line.replace("{ONLINE}", online);
|
line = line.replace("{ONLINE}", online);
|
||||||
line = line.replace("{UNIQUE}", unique);
|
line = line.replace("{UNIQUE}", unique);
|
||||||
line = line.replace("{WORLDS}", worlds);
|
line = line.replace("{WORLDS}", worlds);
|
||||||
line = line.replace("{PLAYERLIST}", playerlist);
|
line = line.replace("{PLAYERLIST}", onlineList);
|
||||||
line = line.replace("{TIME}", time);
|
line = line.replace("{TIME}", time);
|
||||||
line = line.replace("{DATE}", date);
|
line = line.replace("{DATE}", date);
|
||||||
line = line.replace("{WORLDTIME12}", worldTime12);
|
line = line.replace("{WORLDTIME12}", worldTime12);
|
||||||
@ -162,9 +175,9 @@ public class KeywordReplacer implements IText
|
|||||||
line = line.replace("{ADDRESS}", address);
|
line = line.replace("{ADDRESS}", address);
|
||||||
line = line.replace("{PLUGINS}", plugins);
|
line = line.replace("{PLUGINS}", plugins);
|
||||||
line = line.replace("{VERSION}", version);
|
line = line.replace("{VERSION}", version);
|
||||||
}
|
|
||||||
|
|
||||||
for (String groupName : playerList.keySet()) {
|
for (String groupName : playerList.keySet())
|
||||||
|
{
|
||||||
final List<User> groupUsers = playerList.get(groupName);
|
final List<User> groupUsers = playerList.get(groupName);
|
||||||
if (groupUsers != null && !groupUsers.isEmpty())
|
if (groupUsers != null && !groupUsers.isEmpty())
|
||||||
{
|
{
|
||||||
@ -174,16 +187,26 @@ public class KeywordReplacer implements IText
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean doReplace = true;
|
boolean doReplace = true;
|
||||||
while (doReplace) {
|
while (doReplace)
|
||||||
|
{
|
||||||
final String newLine = line.replaceAll("\\{PLAYERLIST\\:\\w*(?:\\:([^\\{\\}]*))?\\}", "$1");
|
final String newLine = line.replaceAll("\\{PLAYERLIST\\:\\w*(?:\\:([^\\{\\}]*))?\\}", "$1");
|
||||||
if (newLine.equals(line)) {
|
if (newLine.equals(line))
|
||||||
|
{
|
||||||
doReplace = false;
|
doReplace = false;
|
||||||
}
|
}
|
||||||
line = newLine;
|
line = newLine;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
replaced.add(line);
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user