Solved Powering button with command

Discussion in 'Spigot Plugin Development' started by Boobah, Feb 13, 2020.

  1. I've made a plugin in Spigot 1.8 that lets you remotely trigger a button with /fire. The plugin works and powers redstone around it, but doesn't power the block it's attached to. How do I fix this?

    When I press the button with hand:
    [​IMG]

    When I trigger the button with /fire:
    [​IMG]


    I power the button with:
    Code (Java):
    Block b = Main.buttons.get(player); // gets button location from hashmap
    b.setData((byte) (b.getData() | 0x8));
    then after 1 second the button is reset.
     
  2. You should be using API methods when possible.

    Try something like:

    Code (Java):
    Button button = (Button) block.getState().getData();
    button.setPowered(true);
     
    • Like Like x 1
  3. I've tried this before and nothing happens when I type the command.

    Code (Text):
    Block b = Main.buttons.get(player);
    Button button = (Button) b.getState().getData();
    button.setPowered(true);
     
  4. You probably need to update the state after changing it
     
    • Agree Agree x 2
  5. This should work. Plottwist. 1.13+ code. :D

    Code (Text):

    Block b = Main.buttons.get(player);
    BlockState state = b.getState();
    Powerable button = (Powerable) state.getBlockData();
    button.setPowered(true);
    state.setBlockData(button);
    state.update();
     
     
  6. I'm using spigot 1.8.