Checking a player in cuboid area.

Discussion in 'Plugin Development' started by PlayFriik, Dec 28, 2014.

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

    PlayFriik

    I was thinking, how I would check when player is in certain cuboid area and I found this:
    http://bukkit.org/threads/testing-for-a-player-in-a-certain-area.303849/
    I just renamed minX, maxX, minY etc > X1, X2, Y1 etc.

    But the problem is that I can't figure out how I would check for the world?

    My code at the moment:
    Code:
                            // Getting game world name for config.
                            plugin.gameName1.addAll(plugin.mapsSection);
                            String gameName2 = plugin.gameName1.get(1);
                            // Getting the game world name for checking later.
                            World w1 = Bukkit.getWorld(gameName2);
                            // X1, X2 etc in config.
                            double X1 = plugin.getConfig().getDouble("Maps." + gameName2 + ".GreenTeam.base.X1");
                            double X2 = plugin.getConfig().getDouble("Maps." + gameName2 + ".GreenTeam.base.X2");
                            double Y1 = plugin.getConfig().getDouble("Maps." + gameName2 + ".GreenTeam.base.Y1");
                            double Y2 = plugin.getConfig().getDouble("Maps." + gameName2 + ".GreenTeam.base.Y2");
                            double Z1 = plugin.getConfig().getDouble("Maps." + gameName2 + ".GreenTeam.base.Z1");
                            double Z2 = plugin.getConfig().getDouble("Maps." + gameName2 + ".GreenTeam.base.Z2");
                            // Getting player's world name and cords.
                            World w = player.getWorld();
                            double x = player.getLocation().getX();
                            double y = player.getLocation().getY();
                            double z = player.getLocation().getZ();
                            // Checking....
                            if(x >= X1 && x <= X2 && y >= Y1 && y <= Y2 && z >= Z1 && z <= Z2 && w == w1) {
                                // Removing 1 score from green team.
                                plugin.greenTeamScore--;
                            }
     
  2. Offline

    nuclearmissile

    if(player.getWorld().equals(w1));

    Does that work? If not I might need more details.
     
  3. Offline

    PlayFriik

  4. Offline

    nuclearmissile

    Ok then, I'll need more detail if that didn't work. Post a stack trace if it's throwing an exception.
     
  5. Offline

    PlayFriik

    @nuclearmissile
    Sorry, but I can't understand that last sentence.. (I feel really stupid right now)

    // FIXED!
     
    Last edited: Dec 28, 2014
  6. Offline

    567legodude

    For this, I use the Cuboid API that someone made. (I believe it was KingFarris or something).
    You create a cuboid with two locations as the corners, and then you can do
    cuboid#contains(player.getLocation());
    It will return true if the player is inside the region.
     
  7. Offline

    MordorKing78

    @nuclearmissile if w1 is a string it should be if(p.getWorld.getName().equals(string here));
     
  8. Offline

    drpk

Thread Status:
Not open for further replies.

Share This Page