2
2
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
3
3
* Copyright (C) 2012 Kristian S. Stangeland
4
4
*
5
- * This program is free software; you can redistribute it and/or modify it under the terms of the
6
- * GNU General Public License as published by the Free Software Foundation; either version 2 of
5
+ * This program is free software; you can redistribute it and/or modify it under the terms of the
6
+ * GNU General Public License as published by the Free Software Foundation; either version 2 of
7
7
* the License, or (at your option) any later version.
8
8
*
9
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
11
* See the GNU General Public License for more details.
12
12
*
13
- * You should have received a copy of the GNU General Public License along with this program;
14
- * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
13
+ * You should have received a copy of the GNU General Public License along with this program;
14
+ * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
15
15
* 02111-1307 USA
16
16
*/
17
17
33
33
34
34
/**
35
35
* Handles the "protocol" administration command.
36
- *
36
+ *
37
37
* @author Kristian
38
38
*/
39
39
class CommandProtocol extends CommandBase {
40
40
/**
41
41
* Name of this command.
42
42
*/
43
43
public static final String NAME = "protocol" ;
44
-
44
+
45
45
private Plugin plugin ;
46
46
private Updater updater ;
47
47
private ProtocolConfig config ;
@@ -52,18 +52,18 @@ public CommandProtocol(ErrorReporter reporter, Plugin plugin, Updater updater, P
52
52
this .updater = updater ;
53
53
this .config = config ;
54
54
}
55
-
55
+
56
56
@ Override
57
57
protected boolean handleCommand (CommandSender sender , String [] args ) {
58
58
String subCommand = args [0 ];
59
-
59
+
60
60
// Only return TRUE if we executed the correct command
61
61
if (subCommand .equalsIgnoreCase ("config" ) || subCommand .equalsIgnoreCase ("reload" ))
62
62
reloadConfiguration (sender );
63
63
else if (subCommand .equalsIgnoreCase ("check" ))
64
64
checkVersion (sender );
65
- else if (subCommand .equalsIgnoreCase ("update" ))
66
- updateVersion (sender );
65
+ // else if (subCommand.equalsIgnoreCase("update"))
66
+ // updateVersion(sender);
67
67
else if (subCommand .equalsIgnoreCase ("timings" ))
68
68
toggleTimings (sender , args );
69
69
else if (subCommand .equalsIgnoreCase ("listeners" ))
@@ -72,19 +72,19 @@ else if (subCommand.equalsIgnoreCase("listeners"))
72
72
return false ;
73
73
return true ;
74
74
}
75
-
75
+
76
76
public void checkVersion (final CommandSender sender ) {
77
77
performUpdate (sender , UpdateType .NO_DOWNLOAD );
78
78
}
79
-
79
+
80
80
public void updateVersion (final CommandSender sender ) {
81
81
performUpdate (sender , UpdateType .DEFAULT );
82
82
}
83
-
83
+
84
84
// Display every listener on the server
85
85
private void printListeners (final CommandSender sender , String [] args ) {
86
86
ProtocolManager manager = ProtocolLibrary .getProtocolManager ();
87
-
87
+
88
88
for (PacketListener listener : manager .getPacketListeners ()) {
89
89
sender .sendMessage (ChatColor .GOLD + "Packet listeners:" );
90
90
sender .sendMessage (ChatColor .GOLD + " " + listener );
@@ -95,35 +95,35 @@ private void printListeners(final CommandSender sender, String[] args) {
95
95
sender .sendMessage (ChatColor .GOLD + " " + listener );
96
96
}
97
97
}
98
-
98
+
99
99
private void performUpdate (final CommandSender sender , UpdateType type ) {
100
100
if (updater .isChecking ()) {
101
101
sender .sendMessage (ChatColor .RED + "Already checking for an update." );
102
102
return ;
103
103
}
104
-
104
+
105
105
// Perform on an async thread
106
106
Runnable notify = new Runnable () {
107
107
@ Override
108
108
public void run () {
109
109
sender .sendMessage (ChatColor .YELLOW + "[ProtocolLib] " + updater .getResult ());
110
-
110
+
111
111
updater .removeListener (this );
112
112
updateFinished ();
113
113
}
114
114
};
115
115
updater .start (type );
116
116
updater .addListener (notify );
117
117
}
118
-
118
+
119
119
private void toggleTimings (CommandSender sender , String [] args ) {
120
120
TimedListenerManager manager = TimedListenerManager .getInstance ();
121
121
boolean state = !manager .isTiming (); // toggle
122
-
122
+
123
123
// Parse the boolean parameter
124
124
if (args .length == 2 ) {
125
125
Boolean parsed = parseBoolean (toQueue (args , 2 ), "start" );
126
-
126
+
127
127
if (parsed != null ) {
128
128
state = parsed ;
129
129
} else {
@@ -134,7 +134,7 @@ private void toggleTimings(CommandSender sender, String[] args) {
134
134
sender .sendMessage (ChatColor .RED + "Too many parameters." );
135
135
return ;
136
136
}
137
-
137
+
138
138
// Now change the state
139
139
if (state ) {
140
140
if (manager .startTiming ())
@@ -150,21 +150,21 @@ private void toggleTimings(CommandSender sender, String[] args) {
150
150
}
151
151
}
152
152
}
153
-
153
+
154
154
private void saveTimings (TimedListenerManager manager ) {
155
155
try {
156
156
File destination = new File (plugin .getDataFolder (), "Timings - " + System .currentTimeMillis () + ".txt" );
157
157
TimingReportGenerator generator = new TimingReportGenerator ();
158
-
158
+
159
159
// Print to a text file
160
160
generator .saveTo (destination , manager );
161
161
manager .clear ();
162
-
162
+
163
163
} catch (IOException e ) {
164
164
reporter .reportMinimal (plugin , "saveTimings()" , e );
165
165
}
166
166
}
167
-
167
+
168
168
/**
169
169
* Prevent further automatic updates until the next delay.
170
170
*/
@@ -174,7 +174,7 @@ public void updateFinished() {
174
174
config .setAutoLastTime (currentTime );
175
175
config .saveAll ();
176
176
}
177
-
177
+
178
178
public void reloadConfiguration (CommandSender sender ) {
179
179
plugin .reloadConfig ();
180
180
sender .sendMessage (ChatColor .YELLOW + "Reloaded configuration!" );
0 commit comments