Skip to content

Commit

Permalink
Version 0.2.0: allow control of report logging. Command syntax changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
totemo committed Dec 4, 2015
1 parent 4dcee42 commit 3880eba
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Tools for detecting various kinds of lag.

Commands
--------
Note that, unless otherwise noted, plugin settings do not persist across restarts. The plugin defaults to a safe, passive state.


```/nerdlag event watch (<plugin> | all) [<thresh_nanos>]```
* Start watching the duration of event handlers for the specified plugin, or all plugins.
Expand All @@ -14,13 +16,12 @@ Commands
```/nerdlag event unwatch (<plugin> | all)</li>```
* Stop watching the duration of event handlers for the specified plugin, or all plugins.

```/nerdlag event notify (on|off)```
* Control whether the player receives in-game notifications of reports of events that exceed their duration threshold.

```/nerdlag event subscribe```
* Subscribe to in-game notifications of reports of events that exceed their duration threshold.
* Reports will always be written to the server log, regardless of whether you subscribe to in-game notifications.

```/nerdlag event unsubscribe```
* Unsubscribe from in-game notifications of reports of events that exceed their duration threshold.
```/nerdlag event log (on|off)```
* Control whether reports of events that exceed their duration threshold will be written to the server log.
* By default, reports are not logged.


Permissions
Expand Down
6 changes: 3 additions & 3 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: NerdLag
version: 0.1.0
version: 0.2.0
author: totemo
description: Tools for detecting various kinds of lag.
website: http://github.com/totemo/NerdLag
Expand All @@ -15,6 +15,6 @@ commands:
usage: |
/<command> event watch <plugin> [<thresh_nanos>]: Start watching event durations for <plugin> (can be "all"), with optional instantaneous reporting above a threshold.
/<command> event unwatch <plugin>: Stop watching event durations for <plugin> (can be "all").
/<command> event subscribe: Start receiving in-game reports of events taking longer than the threshold.
/<command> event unsubscribe: Stop receiving in-game reports of events taking longer than the threshold.
/<command> event notify (on|off): Control in-game notifications of reports of events taking longer than the threshold.
/<command> event log (on|off): Control logging of reports of events taking longer than the threshold.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>io.totemo</groupId>
<artifactId>NerdLag</artifactId>
<name>NerdLag</name>
<version>0.1.0</version>
<version>0.2.0</version>
<packaging>jar</packaging>
<description>Better organisation for your Bukkit help system.</description>
<url>https://github.com/totemo/NerdLag</url>
Expand Down
42 changes: 27 additions & 15 deletions src/io/totemo/nerdlag/NerdLag.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class NerdLag extends JavaPlugin implements MaxTimedRegisteredListener.Ev
* <ul>
* <li>/nerdlag event watch (<plugin> | all) [<thresh_nanos>]</li>
* <li>/nerdlag event unwatch (<plugin> | all)</li>
* <li>/nerdlag event subscribe</li>
* <li>/nerdlag event unsubscribe</li>
* <li>/nerdlag event notify (on|off)</li>
* <li>/nerdlag event log (on|off)</li>
* </ul>
*/
@Override
Expand Down Expand Up @@ -78,26 +78,31 @@ public boolean onCommand(CommandSender sender, Command command, String name, Str
sender.sendMessage(success.toString());
return true;

} else if (args.length == 2 && args[1].equals("subscribe")) {
} else if (args.length == 3 && args[1].equals("notify")) {
if (sender instanceof Player) {
Player player = (Player) sender;
_eventSubscribers.add(player.getUniqueId());
sender.sendMessage(ChatColor.GOLD + "You will receive event duration notifications.");
boolean notify = args[2].equalsIgnoreCase("on") ||
args[2].equalsIgnoreCase("yes") ||
args[2].equalsIgnoreCase("true");
if (notify) {
_eventSubscribers.add(player.getUniqueId());
} else {
_eventSubscribers.remove(player.getUniqueId());
}
sender.sendMessage(ChatColor.GOLD + "In-game event duration notifications " + (notify ? "enabled." : "disabled."));
} else {
sender.sendMessage(ChatColor.RED + "You have to be in-game to receive event duration notifications.");
sender.sendMessage(ChatColor.RED + "You have to be in-game to manage event duration notifications.");
}
return true;

} else if (args.length == 2 && args[1].equals("unsubscribe")) {
if (sender instanceof Player) {
Player player = (Player) sender;
_eventSubscribers.remove(player.getUniqueId());
sender.sendMessage(ChatColor.GOLD + "You will no longer receive event duration notifications.");
} else {
sender.sendMessage(ChatColor.RED + "You have to be in-game to unsubscribe from duration notifications.");
}
} else if (args.length == 3 && args[1].equals("log")) {
_logReports = args[2].equalsIgnoreCase("on") ||
args[2].equalsIgnoreCase("yes") ||
args[2].equalsIgnoreCase("true");
sender.sendMessage(ChatColor.GOLD + "Logging of reported events to server log " + (_logReports ? "enabled." : "disabled."));
return true;
}

} // /nerdlag event subcommands
}
return false;
Expand All @@ -118,7 +123,9 @@ public void reportDuration(MaxTimedRegisteredListener reg, long durationNanos) {
builder.append(nanosToMicros(durationNanos)).append(" \u00b5s (max ");
builder.append(nanosToMicros(reg.getMaxDurationNanos())).append(" \u00b5s)");
String message = builder.toString();
getLogger().info(message);
if (_logReports) {
getLogger().info(message);
}

for (UUID uuid : _eventSubscribers) {
Player player = Bukkit.getPlayer(uuid);
Expand Down Expand Up @@ -228,4 +235,9 @@ protected void unwatchPlugins(Set<Plugin> plugins) {
* logouts or player deaths invalidating the Player instance.
*/
protected HashSet<UUID> _eventSubscribers = new HashSet<UUID>();

/**
* Whether reports will be written to the server log.
*/
protected boolean _logReports;
} // class NerdLag

0 comments on commit 3880eba

Please sign in to comment.