Commands with CommandBlocks

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

Thread Status:
Not open for further replies.
  1. Hello,
    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.plugin.java.JavaPlugin;
    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);
    welt.getBlockAt(position).setType(Material.AIR);

    position.setZ(position.getZ() + 1);
    welt.getBlockAt(position).setType(Material.AIR);
    }
    return true;
    }

    }
     
    Last edited: Dec 13, 2019
  2. Online

    timtower Administrator Administrator Moderator

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

    @timtower
     
  4. Online

    timtower Administrator Administrator 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. 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. Online

    timtower Administrator Administrator Moderator

    I won't spoonfeed.
     
  7. I think you understood wrong I asked for the Constalcion, not the whole code. I'm sorry.
     
  8. Online

    timtower Administrator Administrator Moderator

    And I already said how you should do it.
     
  9. 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.
    Code:
    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. Online

    timtower Administrator Administrator Moderator

  11. 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. Thank you
    @knokko I use Eclipse IDE. Do you sugest a better environment?
    Eclipse is working perfectly fine.
     
  13. Online

    timtower Administrator Administrator Moderator

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

Share This Page