Object instances within Bukkit

Discussion in 'Plugin Development' started by Shuzz, Apr 1, 2011.

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

    Shuzz

    Hey guys,

    I just started working on a simple compass tracker plugin in order to get going with Bukkit.
    Idea is to enable players to let their compass point at the location of another player, therefore being able to find each other. Also planned are things like invisible mode and so on...
    (btw, I like the overall layout of the API, it seems simple and straightforward enough...)

    However, there's something I was wondering about:
    I can make my compass point to another player by getting that player's location via getLocation() and then using that location with my own player entities' setCompassTarget(Location) method.
    e.g.
    Code:
    me.setCompassTarget(trackingTarget.getLocation());
    Now I'm wondering what will happen if that player moves?
    Will the player's Location object simply be updated with the new coordinates, therefore not requiring the plugin to do any more work or will I have to make my plugin respond to PlayerMoveEvents in order to keep updating the compass target location?

    Is there a general rule of thumb concerning re-using object instances within Bukkit?
    I.e. can I rely on getting the same instance of objects from method calls usually or are the objects cloned, recreated under certain condition, whatever?

    Thanks in advance, keep up the good work! :)

    Regards,

    Shuzz
     
  2. Offline

    Edward Hand

    I'm pretty sure you'll have to keep updating it.
    Try it and see!
     
  3. Offline

    Shuzz

    Seriously, I hope you're wrong (but I fear you might not be... ;) )

    If that is truly the case, I would have to register for PlayerMoveEvents. And I suppose that those would fire quite often, especially on bigger servers.
    Anyway, I'll try it out.
    I push comes to shove, I'll try to write some kind of delegate wrapper around a Player object...
     
  4. Offline

    willurd

    Edward Hand is right. I'm currently writing a plugin that has this behavior and that's how it works. I have a player listener that listens for player move AND teleport events and sets the location accordingly. On the plus side, I've never found it to fire more than 4 or 5 times a second when a player is running, and that's on the high end. I've never tested if a player is falling, but I can't imagine it'd be much more. That's really not that much IMO.

    And yes, as Edward Hand said, the best thing you can do to learn the system (I'm currently doing it too!) is to take your hypotheses and test them yourself. You'll internalize it much more. It's really easy to write a listener in Bukkit and have it log to the console when an event happens. This'll help you figure out if something is feasible.
     
Thread Status:
Not open for further replies.

Share This Page