Block commands / Allowing a serten command(s)

Discussion in 'Spigot Plugin Development' started by DjPluton, May 6, 2015.

  1. Hi, I need some help with blocking commands for players, if some one have code example that would help me that would be great :D.
  2. So you mean permissions?
  3. You mean block commands of other plugins?
  4. I want to block commands from other plugins and att the same time allow commands from my plugin :)
    #4 DjPluton, May 6, 2015
    Last edited: May 6, 2015
  5. Anyone there xD ?
  6. Bump every 24 hours.

    Code (Text):
    @SPGEARClub He he he, you've been ninja'd
  7. It's only been 15 minutes, calm down.

    What you're looking for is a permissions plugin, which does exactly what you want - controlling what players can do (primarily commands). To set it all up:
    1.) Get a permissions plugin. I'd recommend PermissionsEX
    2.) For all of your existing plugins, find the permission nodes (those look like "plugin.command.something"). They're usually found on the page you download the plugin, but some bigger plugins you may have to Google around for. E.g: Essentials, located here.
    3.) As for programming, you can do a basic:
    Code (Text):
    if (p.hasPermission("yourpermission.node.goeshere") {
       //Player is allowed (AKA has permissions), continue...
    Else {
      p.sendMessage("You don't have permission!")
  8. konsolas


    Take a look at ServerCommandEvent. It allows you to process commands executed anywhere from any plugin.
    • Like Like x 1
  9. gigosaurus


    It sounds like you want to use PlayerCommandPreprocessEvent
    Taken from the description:

    Some examples of valid uses for this event are:
    • Conditionally blocking commands belonging to other plugins. For example, blocking the use of the /home command in a combat arena.
    • Agree Agree x 1
  10. konsolas


    Same difference. However, servercommandevent can block commands executed server side.
    • Like Like x 1
  11. gigosaurus


    This event is called when a command is run from the server console.

    So not what the OP wants.
  12. I am using that right now, but I dont know how to get the commandline i need to allow /login and /createAccount but block everything else.

    Thats not what im after :p
    #12 DjPluton, May 7, 2015
    Last edited by a moderator: May 7, 2015
  13. if event.getCommand (or whatever) does not equal /login or /createAccount
    cancel the event

    Now translate that to java

  14. String command = e.getMessage();
    String co = command.replaceAll(" ", "/");
    String[] cmd = co.split("/");

    if(cmd[1].equals("login") || cmd[1].equals("createlogin")){

    p.sendMessage(ChatColor.GOLD+"["+ChatColor.AQUA+"VerySure"+ChatColor.GOLD+"] "+ChatColor.RED+"YOU HAVE TO LOGIN ! ");
  15. Couple things,

    Remove the string co= ...
    Change the cmd thing to
    String[] cmd = command.split(" ").toLowercase();

    then when checking do cmd[0].equals("/whatever")

    I do 0 instead of 1 because Java starts counting from 0
    • Agree Agree x 1