Solved Need help determining player distance from a stored block position (1.16.4)

Discussion in 'Plugin Development' started by clueinc, Dec 27, 2020.

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

    clueinc

    Hello all,

    I'm recently new to plugin development/servers so bare with me. I have plenty of programming experience in Python, MATLAB, and C++ so I'm not new to the concepts, and have used TensorFlow/Open-CV API's.

    I've read over the documentation and created some basic test pluggins over the course of the day. However, I still don't know what would be best--or how I would even--go about making the pluggin I have in mind.

    That being said, here it is:

    1. Create a 'wand' (optional) or manually specify block locations [easy enough]
    2. Get current location of player [.getLocation() should work from what I've read]
    3. Define a new event based on player.location and block.location [what I really don't know how to go about]
    4. When the event is triggered, get the location above the block [easy too]
    5. Add something about the block be it /summon, /setblock, [even easier]
    6. Remove that something when the player.location and block.location are no longer true [easy as long as I can do #3]

    Now, the main problem with this is that it needs to be a radius or cuboid, constantly getting player positions, and store the block.location(s) to be loaded next time.

    The main reason I'm worried is that it will lag out the server with it constantly issuing .getLocation() of the player. I don't know if this is even possible, or how to store the block positions (my assumption is likely a config.yml file or sql db).

    If any bukkit pro would like to weigh in, give some guidance, I would appreciate it. I need a general idea, or at least a path, then I can do the leg work!
     
  2. Offline

    Kars

    I don't understand. You want to get all the blocks in a circle or cuboid around the player?
     
  3. Offline

    CraftCreeper6

    @clueinc
    If you're worried about lag use a BukkitRunnable that repeats every x ticks (20 ticks in a second).

    To get distance in a radius you can use Location#distance(location2).

    So every x ticks, the BukkitRunnable will run, firing player#getLocation() and doing the distance calculation on the point stored in the config (which you should load into a variable if it's constant) for each player.

    I doubt it will lag much but there are some optimizations to be done here I'm sure.
     
  4. Offline

    clueinc

    Either or, more flexibility the better. I know I need to compare positions, so I was wondering if it would be better to have the plugin make the block location primary and player location secondary.

    Since @CraftCreeper6 notified me of a tick measuring plugin, my life is a lot easier. I tried looking into things like /schedule but no attempt was fruitful.

    Thank you! I had no idea that plugin even existed. That solves a lot of issues and worries. I'm guessing I just make my plugin dependent on that or list it in the requirements. Are there any good guides for this that you know of too?

    I only ask as google is saturated with many minecraft links/webpages that never answer the specific question I have.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 29, 2020
  5. Offline

    CraftCreeper6

    @clueinc
    BukkitRunnable is actually not a plugin, it's built into the Bukkit API.

    The doc is here.

    Most notably on that doc is runTaskTimer which will complete a given set of instructions after x ticks (delay) and repeat them every y ticks (period)

    Here's a good place to get started
     
Thread Status:
Not open for further replies.

Share This Page