Commands with CommandBlocks

Discussion in 'Plugin Development' started by PhilDEV_Acc, Dec 13, 2019.

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


    How can I code a Plugin Command that can be run by a Command Block?

    Thanks for helping.
    My code is:

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.block.CommandBlock;
    import org.bukkit.command.BlockCommandSender;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.*;

    public class TorPluginMain extends JavaPlugin {

    public void onEnable() {
    public void onDisable() {

    public boolean onCommand(CommandSender sender, Command befehl, String befehlsname, String[] args) {

    Location position = .getLocation();
    World welt = .getWorld();

    position.setY(position.getY() + 2);

    position.setZ(position.getZ() + 1);
    return true;

    Last edited: Dec 13, 2019
  2. Offline

    timtower Moderator Moderator

  3. Offline


    I want that with a Command, blocks are placed at a specific Position like a gate.
    How can I code this?

  4. Offline

    timtower Moderator Moderator

    @PhilDEV_Acc Cast to the BlockCommandSender after checking if the sender is one, then get the block, then you can work based on that position.
  5. Offline


    I'm sorry if I'm annoying but I don't quite understand what you mean can you send an example code?
    I am so thankful you help me I'm at the beginning of Plugins coding.
  6. Offline

    timtower Moderator Moderator

    I won't spoonfeed.
  7. Offline


    I think you understood wrong I asked for the Constalcion, not the whole code. I'm sorry.
  8. Offline

    timtower Moderator Moderator

    And I already said how you should do it.
  9. Offline


    I coded a new onCommand method but by block.getLocation is a error:

    "The Method getLocation() ist undefined for the type BlockCommandSender.

    Maybe you can help me.
    if (sender instanceof BlockCommandSender) {

    BlockCommandSender block = (BlockCommandSender) sender;

    Location position = block.getLocation();
    World welt = block.getWorld();

    double yStart = position.getY();
    double zStart = position.getZ();
  10. Offline

    timtower Moderator Moderator

  11. Offline


    Use block.getBlock().getLocation() instead of block.getLocation() (similarly for welt)
    Is your dev environment good? Normally, the code completion suggestions should reveal such things quickly.
  12. Offline


    Thank you
    @knokko I use Eclipse IDE. Do you sugest a better environment?
    Eclipse is working perfectly fine.
  13. Offline

    timtower Moderator Moderator

    @PhilDEV_Acc Eclipse is fine for development.
    Other IDE's are persobal prederence.
Thread Status:
Not open for further replies.

Share This Page