Boolean problem

Discussion in 'Plugin Development' started by bigbeno37, Jul 23, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    bigbeno37

    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:​

    com.shlockocraft.bigbeno37.ShlockoCraftCore.Data:
    ShlockoCraftAPI.java:​
    ShlockoCraftVAR.java:​

    com.shlockocraft.bigbeno37.ShlockoCraftCore.Listener:
    ShlockoCraftExecutor.java:​
    ShlockoCraftListener.java:​

    com.shlockocraft.bigbeno37.ShlockoCraftCore.Protection:
    ShlockoCraftProtectExecutor.java:​
    ShlockoCraftProtectListener.java:​

    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).
     
  2. Offline

    Lolmewn

    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.
     
  3. Offline

    lol768

    You should always check with something like this:
    PHP:
    if (sender instanceof Player)
    {
    //TODO: Do whatever
    Player mp = (Playersender//This is safe now
    }
    else
    {
    sender.sendMesssage("This command can only be used from a player.");
    }
     
  4. Offline

    bigbeno37

    Okay, thanks for the info! Oh, another thing. Instead of using booleans as 'checkers', should I use HashSet's instead?
     
Thread Status:
Not open for further replies.

Share This Page