Solved Using commands from console on events

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Jul 21, 2014.

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

    Fhbgsdhkfbl

    Hey bukkit forums, I am coding something with signs,
    and when they right click the sign, it will run a command from console,
    I'm not exactly sure how to do that,

    Bukkit.dispatchCommand is for players, and that doesn't work cause they don't have the permission node for the command
     
  2. Offline

    michaelkrauty

    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "command here");
     
    Fhbgsdhkfbl and Saladoc like this.
  3. Offline

    Saladoc

    False. It's for CommandSenders.

    Try
    Code:java
    1. Bukkit.dispatchCommand( Bukkit.getConsoleSender() , yourCommandString);
    and you should be fine.

    edit: Now I got ninja'd :D
     
    Fhbgsdhkfbl likes this.
  4. Offline

    Fhbgsdhkfbl

    Saladoc michaelkrauty
    Thanks guys I appreciate it :D

    Code:java
    1. @EventHandler
    2. public void kitSigns(SignChangeEvent e) {
    3. if (e.getLine(0).equalsIgnoreCase("stupefy")) {
    4. e.setLine(0, ChatColor.GOLD + "[DPHogwarts]");
    5. e.setLine(1, ChatColor.GRAY + "Stupefy");
    6. e.setLine(2, ChatColor.GRAY + "100 Galleons");
    7. e.setLine(3, ChatColor.DARK_AQUA + "==============");
    8. }
    9. }
    10. @EventHandler
    11. public void onSignClick(PlayerInteractEvent e) {
    12. Player p = e.getPlayer();
    13. if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
    14. if ((e.getClickedBlock().getState() instanceof Sign)) {
    15. Sign s = (Sign)e.getClickedBlock().getState();
    16. if (s.getLine(1).equalsIgnoreCase(ChatColor.GRAY + "Stupefy")) {
    17. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "teach Stupefy" + p.getName());
    18. }
    19. }
    20. }


    Would this work?
     
  5. Offline

    michaelkrauty

    it should, but I assume you'll need to add a space to
    Code:
    "teach Stupefy" + p.getName()
     
  6. Offline

    Fhbgsdhkfbl

    michaelkrauty
    Probably, thanks :p
    now, how would I check if they don't have enough money before it withdraws?

    Code:java
    1. @EventHandler
    2. public void onSignClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
    5. if ((e.getClickedBlock().getState() instanceof Sign)) {
    6. Sign s = (Sign)e.getClickedBlock().getState();
    7. if (s.getLine(1).equalsIgnoreCase(ChatColor.GRAY + "Stupefy")) {
    8. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "teach Stupefy " + p.getName());
    9. econ.withdrawPlayer(p.getName(), 100);
    10. p.sendMessage(ChatColor.GOLD + "[DPHogwarts] §eYou have bought §9Stupefy§e.");
    11. }
    12. }
    13. }
     
  7. Offline

    fireblast709

    Fhbgsdhkfbl get the balance, check if balance > 100
     
  8. Offline

    Fhbgsdhkfbl

  9. Offline

    fireblast709

  10. Offline

    Fhbgsdhkfbl

    fireblast709
    Which string would I check to see the balance is lower than 100?
     
  11. Offline

    fireblast709

  12. Offline

    Fhbgsdhkfbl

    fireblast709
    I read through it, but I can't find which one XD
     
  13. Offline

    fireblast709

  14. Offline

    Fhbgsdhkfbl

    fireblast709
    Oh okay xDDD Sorry about that, Im off tonight :p
    I don't understand how to use that string and check if it's below 100 :/
     
  15. Offline

    fireblast709

  16. Offline

    Fhbgsdhkfbl

    fireblast709
    I can't figure it out, thanks for the help though!
     
Thread Status:
Not open for further replies.

Share This Page