WorldEdit API: Get brush and mask materials

Discussion in 'Plugin Development' started by Robnoo, Dec 12, 2018.

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

    Robnoo

    Hi all,

    Is it possible to get the material of the brush and the mask of an item a player is currently holding?
    I already looked up for other threads, but without success.

    This is my class:
    WorldEditManager Class (open)

    Code:java
    1.  
    2. package me.robnoo02.brushinfo;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7.  
    8. import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    9. import com.sk89q.worldedit.command.tool.BrushTool;
    10. import com.sk89q.worldedit.command.tool.InvalidToolBindException;
    11. import com.sk89q.worldedit.session.SessionManager;
    12. import com.sk89q.worldedit.world.item.ItemType;
    13.  
    14. public class WorldEditManager {
    15.  
    16. WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    17.  
    18. @SuppressWarnings("deprecation")
    19. public BrushTool getBrushTool(Player p) {
    20. try {
    21. // I thought this gave me the brushtool so I could use a getter, but that doesn't work.
    22. BrushTool tool = worldEdit.getSession(p).getBrushTool(ItemType.REGISTRY.get(matToString(p.getItemInHand().getType())));
    23. // I can't get further than this at the moment. I have no idea if this has something to do with brush or not.
    24. SessionManager session = new SessionManager(worldEdit.getWorldEdit());
    25. return tool;
    26. } catch (InvalidToolBindException e) {
    27. e.printStackTrace();
    28. return null;
    29. }
    30. }
    31.  
    32. // This method converts a material to a string-formatted key for a HashMap<String, ItemType>.
    33. public String matToString(Material mat) {
    34. String output = String.valueOf(mat);
    35. output = output.replaceAll("_", "");
    36. return output;
    37. }
    38. }
    39.  


    Am I looking in the right direction?
    Does anyone know a good way to get the item and it's data?
    I've never used the WorldEdit API like that before.
    I tried to read the code on GitHub, but I do not understand all aspects of Java yet. (Experience + Dutch <> English)
    I mainly used this page.

    Thank you in advance,
    Robnoo
     
    Last edited: Dec 12, 2018
Thread Status:
Not open for further replies.

Share This Page