Hey there! I am trying to code a plugin which protects blocks via the use of right-clicking a block with a stick. Now, that part works, but I also want to include a command called '/stopprotect', which basically stops the user from protecting blocks when they right click with a stick. I have tried to code this in but to no avail. Could someone please have a look over my code to see what's wrong? com.shlockocraft.bigbeno37.ShlockoCraftCore: ShlockoCraftCore.java:http://pastie.org/4305282 com.shlockocraft.bigbeno37.ShlockoCraftCore.Data: ShlockoCraftAPI.java:http://pastie.org/4305283ShlockoCraftVAR.java:http://pastie.org/4305284 com.shlockocraft.bigbeno37.ShlockoCraftCore.Listener: ShlockoCraftExecutor.java:http://pastie.org/4305285ShlockoCraftListener.java:http://pastie.org/4305286 com.shlockocraft.bigbeno37.ShlockoCraftCore.Protection: ShlockoCraftProtectExecutor.java:http://pastie.org/4305288ShlockoCraftProtectListener.java:http://pastie.org/4305289 Thanks! P.S. When replying, can you also tell me some tips and tricks when it comes to reducing the lag on a server (E.G. Don't let *put method here* run continuously).
One thing: Never, ever, cast the sender object to player if you don't know if it is a player. It could also be the console, leading to big errors. As for the protecting part, I think the idea is to have something toggleable. Basically, this: When player does command, for example /startprotect, the players name gets put in a HashSet<String>. Then, in your event listener, you check if the player performing the event is in the HashSet. If not, ignore. When the /stopprotect command is issued, check if the players name is in the list, and if so, remove it.
You should always check with something like this: PHP: if (sender instanceof Player){//TODO: Do whateverPlayer mp = (Player) sender; //This is safe now}else{sender.sendMesssage("This command can only be used from a player.");}
Okay, thanks for the info! Oh, another thing. Instead of using booleans as 'checkers', should I use HashSet's instead?