Solved Team only allowed to build in their own base ?

Discussion in 'Plugin Development' started by Hugo_Meteo, Aug 24, 2016.

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

    Hugo_Meteo

    Hey,
    I'm making a plugin and I'm stuck on something I've never touched before: Allow a specific team to build in a specific region.

    I've tried lots of things about cuboid etc, none worked (no errors btw).

    Any help about making this ? :) (3 teams)

    thanks !
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Hugo_Meteo First try to get the min and max of the x,y,z.
    Then check if the block is within the min and max. If so: allow (if the correct team) else: cancel.
     
  3. Offline

    Hugo_Meteo

    @timtower thanks for answer.

    Any hint about how to check min & max about x y z?
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    Hugo_Meteo

    @timtower well, I did what you said, but I can't put the "check" in a "if"
    I'm sure that it's something stupid but ^^

    Here is my code
    Code:
    if(Team.isInTeamR(p)){
                if(e.getBlock().getType() == Material.TORCH || e.getBlock().getType() == Material.WATER_BUCKET || e.getBlock().getType() == Material.LAVA_BUCKET){
                    e.setCancelled(false);
                }
                if(!(e.getBlock().getType() == Material.TORCH || e.getBlock().getType() == Material.WATER_BUCKET || e.getBlock().getType() == Material.LAVA_BUCKET)){
                   
                    double minX = getConfig().getDouble("base.rouge.inf.x");
                    double minY = getConfig().getDouble("base.rouge.inf.y");
                    double minZ = getConfig().getDouble("base.rouge.inf.z");
                    String monde = getConfig().getString("loc.monde.monde");
                    World world = Bukkit.getWorld(monde);
                    double maxX = getConfig().getDouble("base.rouge.sup.x");
                    double maxY = getConfig().getDouble("base.rouge.sup.y");
                    double maxZ = getConfig().getDouble("base.rouge.sup.z");
                   
                    double x = e.getBlock().getX();
                    double y = e.getBlock().getY();
                    double z = e.getBlock().getZ();
                   
                    if((minX < x < maxX) && (minY < y < maxY) && (minZ < z < maxZ)){
                   
                        e.setCancelled(false);
                    }
                   
                }
               
                e.setCancelled(true);
            }
    
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Hugo_Meteo You can only use 1 compare thing at the time, so you need to do minX<x && x<maxX
     
  7. Offline

    Hugo_Meteo

    @timtower

    Well, I did everthing, it wasn't working.
    So I tried with debugging, and everything seems to be fine, but can't still place block in "allowed" area.

    Code:
    if(Team.isInTeamR(p)){
                Bukkit.broadcastMessage("team red");
                if(!(e.getBlock().getType() == Material.TORCH || e.getBlock().getType() == Material.WATER_BUCKET || e.getBlock().getType() == Material.LAVA_BUCKET)){
                    Bukkit.broadcastMessage("check pos");
                    double minX = getConfig().getDouble("base.rouge.inf.x");
                    double minY = getConfig().getDouble("base.rouge.inf.y");
                    double minZ = getConfig().getDouble("base.rouge.inf.z");
                    double maxX = getConfig().getDouble("base.rouge.sup.x");
                    double maxY = getConfig().getDouble("base.rouge.sup.y");
                    double maxZ = getConfig().getDouble("base.rouge.sup.z");
                  
                    double x = e.getBlock().getX();
                    double y = e.getBlock().getY();
                    double z = e.getBlock().getZ();
                    Bukkit.broadcastMessage(ChatColor.RED+""+minX+"," + x +","+ maxX+"," + minY+"," + y +","+ maxY+"," + minZ +","+ z+"," + maxZ);
                    Bukkit.broadcastMessage("check end");
                    if(minX < x && x < maxX && minY < y && y < maxY && minZ < z && z < maxZ){
                        p.sendMessage("Allowed");
                        e.setCancelled(false);
                    }
                    Bukkit.broadcastMessage("check failed");
                  
                }
              
                e.setCancelled(true);
                p.sendMessage("Forbidden");
            }else{
                p.sendMessage("No team");
            }
    
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Hugo_Meteo You cancel it again after you allow it.
     
  9. Offline

    Hugo_Meteo

    timtower likes this.
Thread Status:
Not open for further replies.

Share This Page