WorldEdit Selection Problem?

Discussion in 'Plugin Development' started by PolarCraft, Nov 30, 2013.

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

    PolarCraft

    Okay so I have been trying to do a selection with worldedit and i did this.

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. if(cmd.getName().equalsIgnoreCase("rset")){
    4. if(sender.hasPermission("rb.set")){
    5. if (sender instanceof Player) {
    6. WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    7. Selection selection = WorldEditPlugin.getSelection(Player);
    8. if (selection != null) {
    9. World world = selection.getWorld();
    10. Location min = selection.getMinimumPoint();
    11. Location max = selection.getMaximumPoint();
    12.  
    13. // Do something with min/max
    14. } else {
    15. // No selection available
    16. }
    17. }
    18. }
    19. }
    20. }
    21. }


    But player is not a variable. What would i do for the variable?
    Also how could I do a randomization of the blocks after the you enter the command?
     
  2. Offline

    Rprrr

    PolarCraft
    You're using 'Player'. Of course it's not a variable, because you didn't determine it. And because you're spelling it as a class name ("Player"), it even handles it as the Bukkit "Player" class. You would have to retrieve your own player variable after checking if the player is a sender (you're already doing that, so that is fine), like so:

    Code:
    Player player = (Player) sender;
    This, by the way, is some réally basic Java, so I'd advise you getting to know the basics better first.
     
  3. Offline

    PolarCraft

    Rprrr ... Already tried that should of said that. Error when doing that.
    "Cannot make a static reference to the non-static method getSelection(Player) from the type WorldEditPlugin"
     
  4. Offline

    sgavster

    PolarCraft Don't use Player in the
    Code:
     Selection selection = WorldEditPlugin.getSelection(Player);
    use (Player) sender
     
  5. Offline

    PolarCraft

  6. Offline

    sgavster

    PolarCraft
     
  7. Offline

    Rprrr

    PolarCraft
    You did not read my post (properly) and you do not understand the basics of Java... What I said, does work, you're simply doing it wrong.
     
  8. Offline

    AoH_Ruthless

    PolarCraft
    Set a variable for Player:

    Code:
    if(sender instanceof Player) {
        Player player = (Player)sender;
        //code
    }
    then get the Selection with the variable:

    Code:java
    1. Selection sel = WorldEditPlugin.getSelection(player);
     
  9. Offline

    Rprrr

  10. Offline

    PolarCraft

    Rprrr sgavster AoH_Ruthless Already did that. Hints this.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. if(cmd.getName().equalsIgnoreCase("rset")){
    4. if(sender.hasPermission("rb.set")){
    5. if (sender instanceof Player) {
    6. Player player = (Player) sender;
    7. WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    8. Selection selection = WorldEditPlugin.getSelection(player);
    9. if (selection != null) {
    10. World world = selection.getWorld();
    11. Location min = selection.getMinimumPoint();
    12. Location max = selection.getMaximumPoint();
     
  11. Offline

    Rprrr

    PolarCraft
    Now you're using the 'WorldEditPlugin' class and not the variable of that class (worldEdit). That's probably the mistake (I cannot be entirely sure about this being the issue, because I've never worked with the WorldEdit API, but that would make sense to me).
     
  12. Offline

    PolarCraft

    Rprrr Nor have I worked with the api of worldedit. Just looked at there wiki and they said to do this.
     
  13. Offline

    AoH_Ruthless

    Rprrr
    I know you said that and I know that's what you meant, but even so I found it slightly unclear so I reiterated it in a different manner.

    PolarCraft
    Call line 7 in your onEnable();
    then in line 8 use worldEdit instead of WorldEditPlugin. Also, just use your common sense. Why would you initialize a variable but never use it?

    PS: You might want to add checks in your onEnable() to see if WorldEdit is on the server, and if not, disable the plugin.
     
  14. Offline

    PolarCraft

    AoH_Ruthless worldEdit cannot be resolved
    Also I did this for the check.
    Code:java
    1. WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    2. if (worldEdit == null) {
    3. Bukkit.getLogger().log(Level.SEVERE, "WorldEdit not found!");
    4. return;
    5. }
     
  15. Offline

    AoH_Ruthless

    PolarCraft
    Wait, my mistake, set it in both the onCommand and onEnable.
     
  16. Offline

    PolarCraft

    AoH_Ruthless How could i make a timer that is incorporated into changing blocks within the amount set in the config.yml?
     
  17. Offline

    AoH_Ruthless

    PolarCraft
    Can you give me an example of what you want? I don't really understand what you are asking.
     
  18. Offline

    PolarCraft

    Like when you type /rset it enables a timer which changes the selected blocks to different blocks set in the config.yml.
     
  19. Offline

    xTrollxDudex

    PolarCraft
    You need to bring the worldEdit variable into scope, move it outside of the onEnable.
     
  20. Offline

    PolarCraft

    xTrollxDudex Already did that. But can you help me with the question at hand?
     
  21. Offline

    xTrollxDudex

    PolarCraft
    Loop through the blocks in the selection and get Material.matchMaterial(...) the string from the config
     
  22. Offline

    PolarCraft

    xTrollxDudex Now since the worldedit takes min, max how would i set it so it takes both of those?
     
Thread Status:
Not open for further replies.

Share This Page