1.12.2 How to make a plugin that counts walkes rounds

Discussion in 'Spigot Plugin Development' started by Nebelmonster, May 14, 2022.

  1. So I have been on a server where you could run around the spawn in a circle and it counted how many times you ran around the spawn.
    The plugin counted up once I ran a whole circle.

    Now I want to make a similar plugin. But how so I track if a person ran a circle?
     
  2. Are you sure the example you showed us isn't just counting the blocks travelled in general. If that's not the case I can think of many reasons on how to track blocks of a player running around a circle.

    The first idea that comes to my mind is making hidden waypoints and then calculating the blocks travelled from the last waypoint.
     
  3. No the example is not counting the blocks travelled. I just already ran 46 labs
     
  4. Here is how I would perhaps do it:

    For simplicity imagine your spawn being at (0,0). You will have a north-south and east-west axis. The signs of the coordinates in each quadrant are:
    north-east: (+,-)
    south-east: (+,+)
    south-west: (-,+)
    north-west: (-,-)

    Create an enum for each side: NORTH, EAST, SOUTH, WEST.

    Define the radius of your spawn which is the minimum distance that a player has to be away from the center for a lap to count. Also define its square:
    Code (Text):
    int radius = 10;
    int radiusSquared = radius * radius;
    Listen to PlayerMoveEvent and compare the signs for x and z of .from() and .to(). For example if the signs changed from (+,-) to (+,+) you know that the player just crossed the east-west axis on the east side.
    If the crossing happend while
    Code (Text):
    player.getLocation().distanceSquared(spawn) > radiusSquared
    was true, map the enum corresponding to the crossing to the player:
    Code (Text):
    Map<Player, Side> latestSideCrossed = new HashMap<>();
    latestSideCrossed.put(player, Side.EAST);
    Now start two quadrant counters (clockwise and anti-clockwise). If the next crossing happens on the south/north side increase the corresponding counter by 1 and reset the other one. Also update the enum value in the HashMap. Once a counter hits 4 a lap just happened.
     
    #4 Timmetatsch, May 14, 2022
    Last edited: May 15, 2022