Minigame Area Selecting And Saving.

Discussion in 'Plugin Development' started by HouseMD, Oct 4, 2012.

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

    HouseMD

    I'm trying to figure out the best methods of first creating a "arena" that is an area that can be saved and loaded on restarts, and then later checked for if players are in areas and such.

    Any snippet examples are welcome here :)
     
  2. try hooking into worldedit to select the points of the area to select the area and save to an schematic/restore
     
  3. Offline

    Lolmewn

    You could also see how ChessCraft (or whatever it was called) does it. Something with Chess anyway. Chessboard perhaps.
     
  4. Offline

    maxp0wer789

    If you watch your arena from top-down it's a rectangle.
    To programmatically describe a rectangle you best save the coordinates of it's top-left corner and it's width and height.
    You can ignore the y-Axis completely if your arena should be sky-to-bedrock, if the height of your arena IS important however, you can add it to the collision calculation.

    Also your Arena class can implement the Serializable interface to be saved and loadded binary as an object.

    An Arena class would look like this:

    Code:
    public class Arena implements Serializable {
       
        private int posX;
        private int posZ;
       
        private int width;
        private int depth;
     
        public Arena() { /*constructor stuff*/}
       
        public boolean isPlayerInArena(Location _playerPos) {
            return        _playerPos.getX() > posX
                    &&    _playerPos.getX() < posX + width
                    &&    _playerPos.getZ() > posZ
                    &&    _playerPos.getZ() < posZ + depth;
        }   
    }
    greetings maxp0wer
     
  5. Offline

    Zidkon

    I will give you a new challenge, what if there is more than 1 arena? :p is there any way to make the check without a list?
     
  6. Offline

    maxp0wer789

    Nope of course you'll need a list to store your arenas in, so you can save/load all your arenas and check whether you are in one.
    I would write a manager class looking something like this:

    Code:
    public class ArenaHandler implements Serializable {
     
        private ArrayList<Arena> arenas = new ArrayList<Arena>();
       
        public void addArena(Arena _arena) {
            arenas.add(_arena);
        }
        public void removeArena(Arena _arena) {
            arenas.remove(_arena);
        }
        public boolean isPlayerInArena(Location _playerPos) {
            for(int i = 0; i < arenas.size(); i++) {
                if(arenas.get(i).isPlayerInArena(_playerPos)
                    return true;
            }
            return false;
        }
    }
    You can now load/save the whole class on startup/shutdown.

    I can't think of a way right now, to do it completely without a list (and why should i want to?).

    hope i could answer your question at least a little

    greetings maxp0wer
     
  7. Offline

    HouseMD

    i currently have a very bad system for saving, loading areas where they are all stored into one arraylist :L
    if anyone had a barebones example of a way for saying and reloading areas efficiently, please give me a bump in the right direction :L
     
Thread Status:
Not open for further replies.

Share This Page