Solved Signs running commands

Discussion in 'Plugin Development' started by Failplease, Jan 1, 2014.

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

    Failplease

    The following code does not output any stack traces, nor does it work. How would I get it make it so that if a player right clicks a sign it runs the command on the sign, and if a player walks on a block with a sign underneath it, the command is also run.
    Code:
    @EventHandler
        public void onClick(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if(p.hasPermission("signcommand.use")) {
                if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    Block b = e.getClickedBlock();
                    if(b.getType().equals(Material.SIGN)) {
                        Sign s = (Sign) b.getState();
                        if(s.getLine(0).equalsIgnoreCase("[SC]")) {
                            String string = s.getLine(1) + " " + s.getLine(2) + " " + s.getLine(3);
                            String cmd = string.replace("%p%", p.getName());
                            Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
                        }
                    }
                }
            }
        }
       
        @EventHandler
        public void onWalkOver(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if(p.hasPermission("signcommand.step")) {
                Location l = p.getLocation().subtract(0, 2, 0);
                Block b = l.getBlock();
                if(b.getType().equals(Material.SIGN)) {
                    Sign s = (Sign) b.getState();
                    if(s.getLine(0).equalsIgnoreCase("[SC]")) {
                        String string = s.getLine(1) + " " + s.getLine(2) + " " + s.getLine(3);
                        String cmd = string.replace("%p%", p.getName());
                        Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), cmd);
                    }
                }
            }
        }
    (I've already registered the event.)
     
  2. Offline

    XvBaseballkidvX

    Im pretty sure you need to use BlockState for a sign.
     
  3. Offline

    Dako

    Player player = event.getPlayer();
    player.executeCommand("command*"); *not sure if / is needed

    Example:

    player.executeCommand(sign.getLine[1]);
     
  4. Offline

    Failplease

    XvBaseballkidvX
    How would I do that?

    Dako
    I don't want to have the player use the command, because if I choose to do /warp, then they will have to wait 3 seconds to warp. They might also not have the permission. So I want the console to execute the command.
     
  5. Offline

    ASHninja1997

    Failplease
    To execute a command from the console use this code
    Code:java
    1. getSever().dispatchCommand(getServer().getConsoleSender, "your command");
     
  6. Offline

    XvBaseballkidvX

    Failplease This is how:
    Code:java
    1. @EventHandler
    2. public void onSignClick(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. Block block = event.getClickedBlock();
    5. if(block == null) return; //So it doesnt give you NPE Errors when you click the air
    6. BlockState state = block.getState();
    7. if(state instanceof Sign){
    8. Sign sign = (Sign) state;
    9. //Do the rest of your stuff :P
    10. }
    11. }
     
  7. Offline

    Failplease

Thread Status:
Not open for further replies.

Share This Page