3333import com .sk89q .worldguard .bukkit .WorldGuardPlugin ;
3434
3535public class GeneralCommands {
36-
37- @ Command (aliases = {"god" },
38- usage = "[player]" ,
39- desc = "Enable godmode on a player" ,
40- flags = "s" , min = 0 , max = 1 )
41- public static void god (CommandContext args , WorldGuardPlugin plugin ,
42- CommandSender sender ) throws CommandException {
36+
37+ @ Command (
38+ aliases = { "god" },
39+ usage = "[player]" ,
40+ desc = "Enable godmode on a player" ,
41+ flags = "s" ,
42+ min = 0 ,
43+ max = 1
44+ )
45+ public static void god (CommandContext args , WorldGuardPlugin plugin , CommandSender sender ) throws CommandException {
4346 ConfigurationManager config = plugin .getGlobalStateManager ();
44-
47+
4548 Iterable <Player > targets = null ;
4649 boolean included = false ;
47-
50+
4851 // Detect arguments based on the number of arguments provided
4952 if (args .argsLength () == 0 ) {
5053 targets = plugin .matchPlayers (plugin .checkPlayer (sender ));
51-
54+
5255 // Check permissions!
5356 plugin .checkPermission (sender , "worldguard.god" );
54- } else if (args .argsLength () == 1 ) {
57+ } else if (args .argsLength () == 1 ) {
5558 targets = plugin .matchPlayers (sender , args .getString (0 ));
56-
59+
5760 // Check permissions!
5861 plugin .checkPermission (sender , "worldguard.god.other" );
5962 }
6063
6164 for (Player player : targets ) {
6265 config .enableGodMode (player );
6366 player .setFireTicks (0 );
64-
67+
6568 // Tell the user
6669 if (player .equals (sender )) {
6770 player .sendMessage (ChatColor .YELLOW + "God mode enabled! Use /ungod to disable." );
68-
71+
6972 // Keep track of this
7073 included = true ;
7174 } else {
7275 player .sendMessage (ChatColor .YELLOW + "God enabled by "
7376 + plugin .toName (sender ) + "." );
74-
77+
7578 }
7679 }
77-
80+
7881 // The player didn't receive any items, then we need to send the
7982 // user a message so s/he know that something is indeed working
8083 if (!included && args .hasFlag ('s' )) {
8184 sender .sendMessage (ChatColor .YELLOW .toString () + "Players now have god mode." );
8285 }
8386 }
84-
85- @ Command (aliases = {"ungod" },
86- usage = "[player]" ,
87- desc = "Disable godmode on a player" ,
88- flags = "s" , min = 0 , max = 1 )
89- public static void ungod (CommandContext args , WorldGuardPlugin plugin ,
90- CommandSender sender ) throws CommandException {
87+
88+ @ Command (
89+ aliases = { "ungod" },
90+ usage = "[player]" ,
91+ desc = "Disable godmode on a player" ,
92+ flags = "s" ,
93+ min = 0 ,
94+ max = 1
95+ )
96+ public static void ungod (CommandContext args , WorldGuardPlugin plugin , CommandSender sender ) throws CommandException {
9197 ConfigurationManager config = plugin .getGlobalStateManager ();
92-
98+
9399 Iterable <Player > targets = null ;
94100 boolean included = false ;
95-
101+
96102 // Detect arguments based on the number of arguments provided
97103 if (args .argsLength () == 0 ) {
98104 targets = plugin .matchPlayers (plugin .checkPlayer (sender ));
99-
105+
100106 // Check permissions!
101107 plugin .checkPermission (sender , "worldguard.god" );
102- } else if (args .argsLength () == 1 ) {
108+ } else if (args .argsLength () == 1 ) {
103109 targets = plugin .matchPlayers (sender , args .getString (0 ));
104-
110+
105111 // Check permissions!
106112 plugin .checkPermission (sender , "worldguard.god.other" );
107113 }
108114
109115 for (Player player : targets ) {
110116 config .disableGodMode (player );
111-
117+
112118 // Tell the user
113119 if (player .equals (sender )) {
114120 player .sendMessage (ChatColor .YELLOW + "God mode disabled!" );
115-
121+
116122 // Keep track of this
117123 included = true ;
118124 } else {
119125 player .sendMessage (ChatColor .YELLOW + "God disabled by "
120126 + plugin .toName (sender ) + "." );
121-
127+
122128 }
123129 }
124-
130+
125131 // The player didn't receive any items, then we need to send the
126132 // user a message so s/he know that something is indeed working
127133 if (!included && args .hasFlag ('s' )) {
128134 sender .sendMessage (ChatColor .YELLOW .toString () + "Players no longer have god mode." );
129135 }
130136 }
131-
132- @ Command (aliases = {"heal" },
133- usage = "[player]" ,
134- desc = "Heal a player" ,
135- flags = "s" , min = 0 , max = 1 )
136- public static void heal (CommandContext args , WorldGuardPlugin plugin ,
137- CommandSender sender ) throws CommandException {
138-
137+
138+ @ Command (
139+ aliases = { "heal" },
140+ usage = "[player]" ,
141+ desc = "Heal a player" ,
142+ flags = "s" ,
143+ min = 0 ,
144+ max = 1
145+ )
146+ public static void heal (CommandContext args , WorldGuardPlugin plugin , CommandSender sender ) throws CommandException {
139147 Iterable <Player > targets = null ;
140148 boolean included = false ;
141-
149+
142150 // Detect arguments based on the number of arguments provided
143151 if (args .argsLength () == 0 ) {
144152 targets = plugin .matchPlayers (plugin .checkPlayer (sender ));
145-
153+
146154 // Check permissions!
147155 plugin .checkPermission (sender , "worldguard.heal" );
148- } else if (args .argsLength () == 1 ) {
156+ } else if (args .argsLength () == 1 ) {
149157 targets = plugin .matchPlayers (sender , args .getString (0 ));
150-
158+
151159 // Check permissions!
152160 plugin .checkPermission (sender , "worldguard.heal.other" );
153161 }
154162
155163 for (Player player : targets ) {
156164 player .setHealth (20 );
157-
165+
158166 // Tell the user
159167 if (player .equals (sender )) {
160168 player .sendMessage (ChatColor .YELLOW + "Healed!" );
161-
169+
162170 // Keep track of this
163171 included = true ;
164172 } else {
165173 player .sendMessage (ChatColor .YELLOW + "Healed by "
166174 + plugin .toName (sender ) + "." );
167-
175+
168176 }
169177 }
170-
178+
171179 // The player didn't receive any items, then we need to send the
172180 // user a message so s/he know that something is indeed working
173181 if (!included && args .hasFlag ('s' )) {
174182 sender .sendMessage (ChatColor .YELLOW .toString () + "Players healed." );
175183 }
176184 }
177-
178- @ Command (aliases = {"slay" },
179- usage = "[player]" ,
180- desc = "Slay a player" ,
181- flags = "s" , min = 0 , max = 1 )
182- public static void slay (CommandContext args , WorldGuardPlugin plugin ,
183- CommandSender sender ) throws CommandException {
184-
185+
186+ @ Command (
187+ aliases = { "slay" },
188+ usage = "[player]" ,
189+ desc = "Slay a player" ,
190+ flags = "s" ,
191+ min = 0 ,
192+ max = 1
193+ )
194+ public static void slay (CommandContext args , WorldGuardPlugin plugin , CommandSender sender ) throws CommandException {
195+
185196 Iterable <Player > targets = null ;
186197 boolean included = false ;
187-
198+
188199 // Detect arguments based on the number of arguments provided
189200 if (args .argsLength () == 0 ) {
190201 targets = plugin .matchPlayers (plugin .checkPlayer (sender ));
191-
202+
192203 // Check permissions!
193204 plugin .checkPermission (sender , "worldguard.slay" );
194- } else if (args .argsLength () == 1 ) {
205+ } else if (args .argsLength () == 1 ) {
195206 targets = plugin .matchPlayers (sender , args .getString (0 ));
196-
207+
197208 // Check permissions!
198209 plugin .checkPermission (sender , "worldguard.slay.other" );
199210 }
200211
201212 for (Player player : targets ) {
202213 player .setHealth (0 );
203-
214+
204215 // Tell the user
205216 if (player .equals (sender )) {
206217 player .sendMessage (ChatColor .YELLOW + "Slain!" );
207-
218+
208219 // Keep track of this
209220 included = true ;
210221 } else {
211222 player .sendMessage (ChatColor .YELLOW + "Slain by "
212223 + plugin .toName (sender ) + "." );
213-
224+
214225 }
215226 }
216-
227+
217228 // The player didn't receive any items, then we need to send the
218229 // user a message so s/he know that something is indeed working
219230 if (!included && args .hasFlag ('s' )) {
220231 sender .sendMessage (ChatColor .YELLOW .toString () + "Players slain." );
221232 }
222233 }
223-
224- @ Command (aliases = {"locate" },
225- usage = "[player]" ,
226- desc = "Locate a player" ,
227- flags = "" , min = 0 , max = 1 )
228- @ CommandPermissions ({"worldguard.locate" })
229- public static void locate (CommandContext args , WorldGuardPlugin plugin ,
230- CommandSender sender ) throws CommandException {
231-
234+
235+ @ Command (aliases = { "locate" },
236+ usage = "[player]" ,
237+ desc = "Locate a player" ,
238+ flags = "" ,
239+ min = 0 ,
240+ max = 1
241+ )
242+ @ CommandPermissions ({ "worldguard.locate" })
243+ public static void locate (CommandContext args , WorldGuardPlugin plugin , CommandSender sender ) throws CommandException {
232244 Player player = plugin .checkPlayer (sender );
233-
245+
234246 if (args .argsLength () == 0 ) {
235247 player .setCompassTarget (player .getWorld ().getSpawnLocation ());
236-
248+
237249 sender .sendMessage (ChatColor .YELLOW .toString () + "Compass reset to spawn." );
238250 } else {
239251 Player target = plugin .matchSinglePlayer (sender , args .getString (0 ));
240252 player .setCompassTarget (target .getLocation ());
241-
253+
242254 sender .sendMessage (ChatColor .YELLOW .toString () + "Compass repointed." );
243255 }
244256 }
245-
246- @ Command (aliases = {"stack" },
247- usage = "" ,
248- desc = "Stack items" ,
249- flags = "" , min = 0 , max = 0 )
250- @ CommandPermissions ({"worldguard.stack" })
251- public static void stack (CommandContext args , WorldGuardPlugin plugin ,
252- CommandSender sender ) throws CommandException {
253-
257+
258+ @ Command (
259+ aliases = { "stack" },
260+ usage = "" ,
261+ desc = "Stack items" ,
262+ flags = "" ,
263+ min = 0 ,
264+ max = 0
265+ )
266+ @ CommandPermissions ({ "worldguard.stack" })
267+ public static void stack (CommandContext args , WorldGuardPlugin plugin , CommandSender sender ) throws CommandException {
254268 Player player = plugin .checkPlayer (sender );
255269 boolean ignoreMax = plugin .hasPermission (player , "worldguard.stack.illegitimate" );
256-
270+
257271 ItemStack [] items = player .getInventory ().getContents ();
258272 int len = items .length ;
259273
260274 int affected = 0 ;
261-
275+
262276 for (int i = 0 ; i < len ; i ++) {
263277 ItemStack item = items [i ];
264278
265279 // Avoid infinite stacks and stacks with durability
266- if (item == null || item .getAmount () <= 0
267- || (!ignoreMax && item .getMaxStackSize () == 1 )) {
280+ if (
281+ item == null ||
282+ item .getAmount () <= 0 ||
283+ (!ignoreMax && item .getMaxStackSize () == 1 )
284+ ) {
268285 continue ;
269286 }
270287
@@ -278,22 +295,26 @@ public static void stack(CommandContext args, WorldGuardPlugin plugin,
278295 ItemStack item2 = items [j ];
279296
280297 // Avoid infinite stacks and stacks with durability
281- if (item2 == null || item2 .getAmount () <= 0
282- || (!ignoreMax && item .getMaxStackSize () == 1 )) {
298+ if (
299+ item2 == null ||
300+ item2 .getAmount () <= 0 ||
301+ (!ignoreMax && item .getMaxStackSize () == 1 )
302+ ) {
283303 continue ;
284304 }
285305
286306 // Same type?
287307 // Blocks store their color in the damage value
288- if (item2 .getTypeId () == item .getTypeId () &&
289- (!ItemType .usesDamageValue (item .getTypeId ())
290- || item .getDurability () == item2 .getDurability ())) {
308+ if (
309+ item2 .getTypeId () == item .getTypeId () &&
310+ item .getDurability () == item2 .getDurability ()
311+ ) {
291312 // This stack won't fit in the parent stack
292313 if (item2 .getAmount () > needed ) {
293314 item .setAmount (64 );
294315 item2 .setAmount (item2 .getAmount () - needed );
295316 break ;
296- // This stack will
317+ // This stack will
297318 } else {
298319 items [j ] = null ;
299320 item .setAmount (item .getAmount () + item2 .getAmount ());
0 commit comments