Solved Trying to select Area with WorldEdit API?

Discussion in 'Plugin Development' started by The_Nesko, Apr 6, 2016.

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

    The_Nesko

    Hello i have been struggling with this problem for a while so what i'm trying to do is get area selected with wand form world edit plugin, i get selection and store the min and max cords in the config and get them somewhere else but i't doesn't work.

    Here is the code where i'm storing the selection.
    Code:
    else if (args[0].equalsIgnoreCase("AddFallZone")) {
                  
                        if (length == 2) {
                            String parkourName = settings.getData().getString("ParkourNameTemp.Maker " + player.getName());
                      
                            if (parkourName == null) {
                                player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + " You are not i process of making a parkour map!");
                                player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + " First stand on the start block of parkour map and type in next:");
                                player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + " /PM CreateParkour <ParkourName>");
                                return true;
                            }
                      
                            String connectedCheckpoint = settings.getData().getString("ParkourMaker." + parkourName + ".Checkpoints." + args[1] + ".Name");
                      
                            if (connectedCheckpoint == null) {
                                player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + "Argument Error!");
                                player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + "That Checkpoint does not exist!");
                               return true;
                            }
                      
                            int amountOfFallzones = settings.getData().getInt("ParkourMaker." + parkourName + ".Fallzones.AmountOfFallzones");
                            amountOfFallzones = amountOfFallzones + 1;
                      
                            Selection selection = getWorldEdit().getSelection(player);
                      
                            if (selection == null) {
                               sender.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + " You didn't select two corners with your world edit wand"
                                      + " please do that and try again!");
                               return true;
                            }
                      
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".FirstCorner.X", (int) selection.getMinimumPoint().getX());
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".FirstCorner.Y", (int) selection.getMinimumPoint().getY());
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".FirstCorner.Z", (int) selection.getMinimumPoint().getZ());
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".FirstCorner.World", selection.getMinimumPoint().getWorld().getName());              
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".SecoundCorner.X", (int) selection.getMaximumPoint().getX());
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".SecoundCorner.Y", (int) selection.getMaximumPoint().getY());
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".SecoundCorner.Z", (int) selection.getMaximumPoint().getZ());
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".SecoundCorner.World", selection.getMaximumPoint().getWorld().getName());              
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".Area.World", selection.getWorld().getName());              
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones." + amountOfFallzones + ".ConnectedCheckpoint", args[1]);              
                            settings.getData().set("ParkourMaker." + parkourName + ".Fallzones.AmountOfFallzones", amountOfFallzones);
                            settings.saveData();
                      
                            return true;
                        }
                        else {
                            player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + "Argument Error!");
                            player.sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + "Usage: /PM AddFallZone <ConectedCheckpoint>");
                           return true;
                        }
                    }
    

    And this is where i'm trying to get the cords and make a CuboidSelection.
    Code:
    @EventHandler
        public void onStepInFallZone(PlayerMoveEvent e) {
            String parkourPlayerIsIn = CreatingParkour.playerInWitchParkour.get(e.getPlayer().getName());
            if (parkourPlayerIsIn == null) return;
      
            int amountOfFallzones = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones.AmountOfFallzones");
      
            for (int i = 1; i < amountOfFallzones; i++) {
               int FZMinX = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".FirstCorner.X");
               int FZMinY = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".FirstCorner.Y");
               int FZMinZ = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".FirstCorner.Z");
               World FZMinWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".FirstCorner.World"));
          
               int FZMaxX = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".SecoundCorner.X");
               int FZMaxY = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".SecoundCorner.Y");
               int FZMaxZ = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".SecoundCorner.Z");
               World FZMaxWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".SecoundCorner.World"));
          
               Location FZFirstCorner = new Location(FZMinWorld, FZMinX, FZMinY, FZMinZ);
               Location FZSecoundCorner = new Location(FZMaxWorld, FZMaxX, FZMaxY, FZMaxZ);
               World FZWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".Area.World"));
               CuboidSelection fallZone = new CuboidSelection(FZWorld, FZFirstCorner, FZSecoundCorner);
          
               if(fallZone.contains(e.getTo())) {
                  String FZconnectedCheckpoint = settings.getData().getString("ParkourMaker." + parkourPlayerIsIn + ".Fallzones." + i + ".ConnectedCheckpoint");   
                
                   int CheckpointX = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Checkpoints." + FZconnectedCheckpoint + ".X");
                   int CheckpointY = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Checkpoints." + FZconnectedCheckpoint + ".Y");
                   int CheckpointZ = settings.getData().getInt("ParkourMaker." + parkourPlayerIsIn + ".Checkpoints." + FZconnectedCheckpoint + ".Z");
                   World CheckpointWorld = Bukkit.getServer().getWorld(settings.getData().getString("ParkourMaker." + parkourPlayerIsIn + ".Checkpoints." + FZconnectedCheckpoint + ".World"));      
                  Location checkpointLoc = new Location(CheckpointWorld, CheckpointX, CheckpointY, CheckpointZ);
            
                   e.getPlayer().teleport(checkpointLoc);
                   e.getPlayer().sendMessage(ChatColor.GRAY + "[PM]" + ChatColor.RED + " You have been teleported to your last checkpoint!");
                     break;
               }
            }
        }
    
    Any ideas on how to solve this?
    And yes i did register listeners.

    EDIT:
    I found the problem looks like the code is good but for some reason when i make a selection that has 6 block or less in it it acts like it's not selected or only one half is selected or like the coordinates are inverted, but when i make a bigger selection then it works as it is supposed to.
     
    Last edited: Apr 7, 2016
Thread Status:
Not open for further replies.

Share This Page