WorldEdit API - Setting Selection

Discussion in 'Spigot Plugin Development' started by Invaerne, Jan 13, 2019.

Thread Status:
Not open for further replies.
  1. Hi all,

    Is there anyway to set WorldEdit primary and secondary selection by using the WorldEdit API?

    All help will be greatly appreciated.

    - Inv

    Code (Text):
      public void onSelection(PlayerInteractEvent event)
            if (event.getAction() == Action.LEFT_CLICK_BLOCK) {

            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {

  2. This can help you
  3. Code (Java):
    import com.sk89q.worldedit.bukkit.*;
    import com.sk89q.worldedit.bukkit.selections.*;

    WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    Selection selection = worldEditPlugin.getSelection(player);

    if (selection != null) {
        World world = selection.getWorld();
        Location min = selection.getMinimumPoint();
        Location max = selection.getMaximumPoint();
        // Do something with min/max
    } else {
        // No selection available
    This class is for get a player's selection
  4. The OP was talking about setting the selection not getting it.

    One could create a new CuboidSelection and then set it with WorldEditPlugin#setSelection.
    • Informative Informative x 2
    • Agree Agree x 1
  5. The problem with CuboidSelection that I am having is that it requries to set both positions, so each PlayerInteractEvent will override both values - and I want to set each invidually (right click, left click).
  6. I'm not sure how that's a problem. Store one (or both) in a variable and only make a new CuboidSelection when both are set (or in whichever other condition you like).
    • Informative Informative x 1
  7. You are right! Thank you sir!
Thread Status:
Not open for further replies.

Share This Page