Returning true to a command block?

Discussion in 'Plugin Development' started by Datdenkikniet, Nov 8, 2013.

Thread Status:
Not open for further replies.
  1. If I have a code, which checks if a commandBlock executes a command, how would I be able to let that command block output some redstone?
     
  2. Offline

    The_Doctor_123

    Are you listening for an event or on the onCommand method?
     
  3. Offline

    The_Doctor_123

    Datdenkikniet
    Hmm.. I think you could cast the CommandSender to a CommandBlock and then power that block(however you do that..).
     
  4. The_Doctor_123 its weird, because when I put my command in the command block, for some reason it stays powered...... Even if it returns false.....
     
  5. Offline

    The_Doctor_123

  6. The_Doctor_123 could you tell me how to do that?
    if you need my code, here it is:
    Show Spoiler

    Code:java
    1. if (label.equalsIgnoreCase("testforblock")){
    2. if (sender.hasPermission("1.7.2cmds.testforblock")){
    3. if (sender instanceof Player){
    4. try{
    5. if (args.length == 3){
    6. Double x = Double.parseDouble(args[0]);
    7. Double y = Double.parseDouble(args[1]);
    8. Double z = Double.parseDouble(args[2]);
    9. Location loc = new Location(((Player) sender).getWorld(), x, y, z);
    10. if (Bukkit.getWorld(((Player)sender).getWorld().getName()).getBlockAt(loc).getType() != Material.AIR){
    11. String s = Bukkit.getWorld(((Player)sender).getWorld().getName()).getBlockAt(loc).getType().name();
    12. sender.sendMessage("There is some " + s + " at the chosen location!");
    13. return true;
    14. } else {
    15. sender.sendMessage("The block at your location is air!");
    16. return true;
    17. }
    18. } else
    19. {
    20. sender.sendMessage("Wrong usage! Usage: /testforblock world x y z (for command blocks/console commands) or /testforblock x y z (for players)");
    21. return true;
    22. }
    23. } catch (NumberFormatException e){
    24. sender.sendMessage("Your arguments are not numbers!");
    25. return true;
    26. }
    27. } else if (sender instanceof ConsoleCommandSender || sender instanceof BlockCommandSender){
    28. try{
    29. if (args.length == 4){
    30. World world = Bukkit.getWorld(args[0]);
    31. Double x = Double.parseDouble(args[1]);
    32. Double y = Double.parseDouble(args[2]);
    33. Double z = Double.parseDouble(args[3]);
    34. Location loc = new Location(world, x, y, z);
    35. if (world.getBlockAt(loc).getType() != Material.AIR){
    36. String s = world.getBlockAt(loc).getType().name();
    37. if (sender instanceof BlockCommandSender){
    38. // here something should happen with the block
    39. }
    40. return true;
    41. } else {
    42. return false;
    43. }
    44. } else
    45. {
    46. return false;
    47. }
    48. } catch (NumberFormatException e){
    49. //sender.sendMessage("Your arguments are not numbers!");
    50. return false;
    51. }
    52. }
    53. }
    54. return true;
    55. }
    56. return false;
    57. }

     
  7. Offline

    evilmidget38

    There's API support for this being worked on. Something should hopefully show up after the 1.7 update.
     
    bennie3211 and (deleted member) like this.
  8. If it does no output at all when you type the command in the command block then type /gamerule commandBlockOutput on
     
  9. Offline

    JacKlink01


    Any news on possible API support for this?
    Thanks.
     
  10. Offline

    newboyhun

Thread Status:
Not open for further replies.

Share This Page