Claiming chunks and enter messages?

Discussion in 'Plugin Development' started by valon750, May 27, 2013.

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

    valon750

    Greetings Bukkit community!

    I was hoping you lot may be able to help with a little project of mine. I'm looking to set up my server so players can claim chunks (originally bigger regions but I don't know how to do that), so that the chunk is locked to them, or others that the owner can specify.

    I'm aware of how I would go about checking the chunk the player is currently in, and I have a SLIGHT idea of how to link it to a player, however there's probably a cleaner method.

    On top of this, how would I go about letting users set a greeting message? I know HOW to essentially, by letting the user set it via a command and have it save to a config, but I can't use a PlayerMoveEvent because surely it'd send the message EVERY time the player moves in the region

    Any advice, much appreciated!
     
  2. Offline

    Pew446

    I always find the best way to learn is to look at other people's code and find out how they did it. Here is Towny's source code, which I'm sure you know Towny is capable of all the things you asked. I would try to find specifically where these pieces of code are, but I need to go, so good luck! :)
     
  3. Offline

    valon750

    Pew446

    Had a look, it's all very confusing to me. Obviously for them it's been coded how they need it, so everything fits in nicely, but dissecting code to grab the bits I need is a whole other ordeal

    Alright everyone, this just dawned on me, how do I go about adding it to the config or whatnot when there's more than one region the player owns? There'd have to be some sort of list, but I've never attempted to use lists in a file, so amaze me!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  4. Offline

    Junrall

  5. Offline

    valon750

    Junrall

    huh, now isn't that something...

    Now I now that says if the player is inside the region, but I don't think it mentions anything about then they enter or leave the region.
     
  6. Offline

    Junrall

    valon750

    Nope... you'll have to use the API to check if a player is or isn't in a region, then send them a message. I'm not sure what would be the most efficient way to constantly check every player, but I'm sure there is someone here on the forums who has that knowledge. :)
     
  7. Offline

    boolean

    valon750 - Just use the selection api to check if they are in a new region using a onPlayerMove

    Of course, it's more efficient if you only check onPlayerMove to players that have run a command to "Enable" it and then stop running it when they disable it.
     
  8. Offline

    Junrall

    Perhaps running a scheduled task that will check all online players who are in motion. Again, not a strong area for me. :p
     
  9. Offline

    valon750

    Junrall boolean

    Ah well, I'll figure something out eventually!

    Now, an issue that is yet to be solved, I THINK I can understand what needs to be done to save a chunk for the player when they claim it, however I don't know how to set it up so the player can claim multiple chunks, I've never tried lists before in a file so it's beyond me.

    Edit:

    An example being...

    Code:
    Player:
        Valon750:
            Claimed: (number claimed)
            - chunk
            - chunk
            - chunk
     
  10. Offline

    blablubbabc

    You have to somehow store the locations of the chunks owned by a player. Onplayermove you can check if the players chunk has changed and if the new Chunk is owned by someone else print the join / leave messages.

    Hint: to get the coordinates of a chunk you can use x << 4 and y << 4

    For a concrete example you could maybe look into factions source as this is exactly how they are doing this.
     
  11. Offline

    valon750

    blablubbabc

    I was thinking I can do player.getLocation().getChunk().getZ(); and player.getLocation().getChunk().getX(); then save those in a file.. maybe like...

    Code:
    Player:
        Valon750:
            Claimed:
                Chunk 1:
                X = 0.000
                Z = 0.000
                Chunk 2:
                
    the main issue is how I'd actually go about doing that :( I'll have a go at looking through factions' work, but I'm terrible when it comes to dissecting plugins.
     
  12. Offline

    blablubbabc

    You could also store the chunk information as a string list, each string representing one chunk. Example:

    <worldname>; <chunkx>;<chunky>

    And then parse this information.
     
  13. Offline

    valon750

    blablubbabc A string list? I think I must of done something with that before... I just can't remember where...
     
  14. Offline

    blablubbabc

    Write a method that converts the chunk information to a string and a method that reads the chunkinformation from such a string. The config has methods for storing and reading lists of strings so for each player that owns chunks you store a stringlist.
     
  15. Offline

    valon750

    blablubbabc

    Huh, I really need to get someone working on these plugins with me
     
Thread Status:
Not open for further replies.

Share This Page