Solved Keeping each player in his own region

Discussion in 'Plugin Development' started by robertlit, Jul 24, 2019.

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

    robertlit

    I am making a skyblock plugin for my own use (doesn't have to configurable). I have already coded the island generator (actual block placing) and the location generator for the island. (All islands will be in a separate world called "islands")
    Any ideas on how I can give each player an area, based on their island location, that they cannot leave or build out of??

    Thanks in advance!
     
    Last edited: Jul 25, 2019
  2. Offline

    CraftCreeper6

    @robertlit
    Location#distance (location2)
    or Location#distanceSquared(location2)

    could do the trick. Check if the return value of either of those functions is greater than the maximum distance they are allowed in PlayerMoveEvent, then, send them back to either the border, or to their islands home.
     
  3. Offline

    robertlit

    @CraftCreeper6 Thanks, I think I understand. However, can you explain what does the distance method return.. Does it retrun the distance in the X dimension? the Z dimension?the Y dimension? or all of them?
    And if in all of them I want the players to be able to move between void and build limit so that might be a problem..
     
  4. Offline

    CraftCreeper6

    @robertlit
    All of them.

    I suppose you could make your own function for this.

    Using Pythagoras you can get a pretty accurate representation of the distance the player is from an origin point.

    Assuming you know Pythagoras, a^2 = b^2 + c^2 where b and c are delta X and delta Z (change in X and change in Z)

    So it comes out something like this:

    Distance = sqrt([X1-X2]^2 + [Z1-Z2]^2)

    Though because you're using Minecraft Locations, it's likely your X and Z will be doubles, so you'll have to use Math.Pow(value, power) to raise it to the power.
     
  5. Offline

    robertlit

    @CraftCreeper6
    Alright thanks!! That is (hopefully) exactly what i was looking for!

    (And btw I do know the Pythagoras theorem)

    EDIT: Wouldn't it be easier to check if the X of a player is larger than (islandhome#getX() + alloweddistance) or the Z of a player is larger than (islandhome#getZ() + alloweddistance), if yes teleport back???
     
    Last edited: Jul 25, 2019
  6. Offline

    CraftCreeper6

    @robertlit
    That does not allow for negative distances, you'd have to assign both the positive and negative versions of each axis, which is 4 assignments. But yes it would work.
     
  7. Offline

    robertlit

    @CraftCreeper6 You're right! The method with the Pythagoras theorem is much better!
    Thank you again for giving me this idea!
     
    CraftCreeper6 likes this.
Thread Status:
Not open for further replies.

Share This Page