Solved Setting noDamage zones

Discussion in 'Plugin Development' started by SmRndmGy, Jun 15, 2019.

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

    SmRndmGy

    So i've been working on a kitPVP plugin lately. The first thing i wanted to to is setting an area at the spawn where the players can't damage each other by cancelling the EntityDamageEvent. My proble is that i don't seem to be able to figure out how to define zones.

    This is what i've done:

    I have made a config file where i could put the coordinates of the corners of said zone. I was able to read the config and get the values into integers. Now i tried to get the players position and cancel the event if he is between those coordinates and that's where i got stuck. I tried doing this:
    Code:
        @EventHandler
        public void onDamage(EntityDamageEvent e) {
            if(e.getEntity() instanceof Player) {
                Player p = (Player) e.getEntity();
                if(p.getLocation().getBlockX() < protectX2 && p.getLocation().getBlockX() > protectX) {
                    if(p.getLocation().getBlockZ() < protectZ2 && p.getLocation().getBlockZ() > protectZ) {
                        e.setCancelled(true);
                    }
                }
            }
        }
    Note: protectX and protectZ are the coords of one corner and protectX2 and protectZ2 the coords of the other one. i also tried swapping the values of protectX and protectX2 and the same for Z.
     
  2. Offline

    Minesuchtiiii

    Iterate over the X, Y & Z values at the same time and check if the player is inside that box. If yes cancel the event
     
  3. Offline

    SmRndmGy

    I'm sorry if this seems stupid but i don't know how to do so...
     
  4. Offline

    Minesuchtiiii

    Code:
    for(int x ...) {
    
    for(int y ...) {
    
    for(int z ...) {
    
    
    
    //your code
    
    
    }
    }
    
    
    }
     
Thread Status:
Not open for further replies.

Share This Page