commands dont work.

Discussion in 'Plugin Development' started by JJScoder, Jun 7, 2018.

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

    JJScoder

    Plugin,yml (open)

    1. name: antrixBuild
    2. version: 1.0
    3. main: gosintary.build.antrixmc.main

    4. commands:
    5. wall:
    6. description: Hello!
    7. window:
    8. description: Hello!
    9. door:
    10. description: Hello!
    11. stair:
    12. description: Hello!
    13. floor:
    14. description: Hello!
    15. roof:
    16. description: Hello!

    Console Log (open)
    07.06 19:54:58 [Server] INFO Gosintary issued server command: /wall

    Code (open)

    Code:
    package gosintary.build.antrixmc;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    public class main extends JavaPlugin{
      
        //
        // rpGetPlayerDirection - Convert Player's Yaw into a human readable direction out of 16 possible.
        //
        public String rpGetPlayerDirection(Player playerSelf){
             String dir = "";
             float y = playerSelf.getLocation().getYaw();
             if( y < 0 ){y += 360;}
             y %= 360;
             int i = (int)((y+8) / 22.5);
             if(i == 0){dir = "west";}
             else if(i == 1){dir = "west northwest";}
             else if(i == 2){dir = "northwest";}
             else if(i == 3){dir = "north northwest";}
             else if(i == 4){dir = "north";}
             else if(i == 5){dir = "north northeast";}
             else if(i == 6){dir = "northeast";}
             else if(i == 7){dir = "east northeast";}
             else if(i == 8){dir = "east";}
             else if(i == 9){dir = "east southeast";}
             else if(i == 10){dir = "southeast";}
             else if(i == 11){dir = "south southeast";}
             else if(i == 12){dir = "south";}
             else if(i == 13){dir = "south southwest";}
             else if(i == 14){dir = "southwest";}
             else if(i == 15){dir = "west southwest";}
             else {dir = "west";}
             return dir;
        }
      
        public boolean onCommand(String l, Command cmd, CommandSender s, String[] args) {
            Player p = (Player) s;
    //--------------------------------------------------------------------------------------------------\\
            if(l.equalsIgnoreCase("wall")) {
                if(rpGetPlayerDirection(p).equals("north")){
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("east")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("south")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("west")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load wallw");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }
            }
    //--------------------------------------------------------------------------------------------------\\
            if(l.equalsIgnoreCase("door")) {
                if(rpGetPlayerDirection(p).equals("north")){
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("east")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("south")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("west")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load doorw");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }
            }
            //--------------------------------------------------------------------------------------------------\\
            if(l.equalsIgnoreCase("window")) {
                if(rpGetPlayerDirection(p).equals("north")){
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("east")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("south")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("west")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load windoww");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }
            }
    //--------------------------------------------------------------------------------------------------\\
            if(l.equalsIgnoreCase("stair")) {
                if(rpGetPlayerDirection(p).equals("north")){
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("east")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/rotate 90");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("south")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/rotate 180");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }else if(rpGetPlayerDirection(p).equals("west")) {
                    if(p.isOp()) {
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                    }else if(!(p.isOp())) {
                        p.setOp(true);
                        Bukkit.dispatchCommand(p, "schem load stairw");
                        Bukkit.dispatchCommand(p, "/rotate 270");
                        Bukkit.dispatchCommand(p, "/paste");
                        p.setOp(false);
                    }
                }
            }
    //--------------------------------------------------------------------------------------------------\\
            if(l.equalsIgnoreCase("floor")) {
                if(p.isOp()) {
                    Bukkit.dispatchCommand(p, "schem load floorw");
                    Bukkit.dispatchCommand(p, "/paste");
                }else if(!(p.isOp())) {
                    p.setOp(true);
                    Bukkit.dispatchCommand(p, "schem load floorw");
                    Bukkit.dispatchCommand(p, "/paste");
                    p.setOp(false);
                }
            }
    //--------------------------------------------------------------------------------------------------\\
            if(l.equalsIgnoreCase("roof")) {
                if(p.isOp()) {
                    Bukkit.dispatchCommand(p, "schem load roofw");
                    Bukkit.dispatchCommand(p, "/paste");
                }else if(!(p.isOp())) {
                    p.setOp(true);
                    Bukkit.dispatchCommand(p, "schem load roofw");
                    Bukkit.dispatchCommand(p, "/paste");
                    p.setOp(false);
                }
            }
          
            return false;
        }
      
    }


    When I run the command nothing happens. Can you help me figure out why?
     
  2. Offline

    !PoKu

    1.The method onCommand, its arguments are not
    Code:
    (String l, Command cmd, CommandSender s, String[] args)
    its arguments are
    Code:
    (CommandSender sender, Command cmd, String label, String[] args)
    2.You need to register the commnds and set with your CommandExecutor
     
  3. Online

    timtower Ninja on the waves Moderator

    @!PoKu 2 is only the case when the executor isn't the main class.
     
    !PoKu likes this.
  4. Offline

    ThePandaPlayer

    I have managed to create plugins in one class. The abstract class JavaPlugin has its own CommandExecutor methods. You just need to @Override it.

    Exactly. My first plugin release just had all of the command code stuffed into one giant class. (Not a good idea as adding just one faulty command can cause the plugin to not load at all)
     
Thread Status:
Not open for further replies.

Share This Page