[TUTORIAL|MEDIUM] Arenas and Managers

Discussion in 'Resources' started by Ultimate_n00b, Sep 25, 2013.

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


    There's a lot of demand for arena plugins out there. And the ones released, have a lot of downloads. People try to make these, and then quite when they can't figure out how to do it. Weeelll, here goes! I'm going to make a few classes based off my new Minecraft Brawl plugin, and put them here.
    Alright, start reading!

    So first things first, you need an arena object to start off with. So things we'll need:
    • Name: We have to be able to tell arenas apart
    • (for most arenas) Two points defining the boundaries: This is to check if a player leaves, and do stuff like not allowing breaking in the arena.
    • A spot to go to when it starts
    • A spot to go to when it finishes
    To see what our arena object looks like, check out thisgist.

    So you have a basic arena object that holds a few variables. But we'll need to add/remove players. I'm going to add a new class called PlayerManager, and each arena has their own PlayerManager. What is everything a player manager would need?
    • Add/Remove Players
    • Separate Inventories
    • Teleporting
    I'll add a subclass to the PlayerManager to hold the player's inventory and such things.

    Here is our now arena class, with the PlayerManager.
    And here is our new PlayerManager.

    So now we can add & remove players, restore inventory, and teleport them to where they need to go (without taking fall damage!). Pretty simple right?

    Now we want an easy way to keep track of arenas. We'll create a Arena Manager class, to add, remove, and check if the said arena exists. We will also have the arena add itself when it's defined.

    Here is the ArenaManager.
    Here is the new Arena.

    Alright so we'll want to be able to save these arenas to file, then load them again. There's a few difficult things, such as saving locations. I typed up a modified version of my LocationUtils class from MCBrawl. All it does, is convert Locations to and from a single string (taking use of Java's .split() method).

    You can find the util LocationUtils here.

    So now I'll need a way to take use of this. I am going to make a method inside of the arena object for this called save. So while we have a way to save it, we need to load it. If you haven't made a main class yet, I suggest you make one now. So we'll want to load all the arenas from inside the config when the plugin starts. Let's loop through a Arenas section will which exist in the config once we save our arenas. You can find an example class here. You're done! If you want to save an arena, here's a example:
    1. arena.save(getConfig(), "Arenas");

    While the config can be anything, make sure to make it Arenas. Either that, or change what section we loop through in the onEnable.

    You can find the new LocationUtils here.
    You can find the new ArenaTutorial (Main Class) here.
    You can find the modified Arena here.

    So we can save/load arenas from the config. What next? As per-request, I decided to all rollbacking. Here goes!

    We're going to be using a runnable for this. To make this easier and for the sake of the tutorial, I modified the ArenaTutorial (main plugin class) to have a public static instance of itself. Alright, on to the real stuff. So first thing that we need to do, is get the minimum and maximum points of the arena. I'm going to check in the Arena constructor which point is which, and then set them again. After that, we'll need a list of blocks in the arena. Because we have these two points, we can loop through them easily. We can loop through them all (3 for loops) and add each state to a list.

    Why would we add the state to the list? The BlockState of a block contains all the information about it. It contains direction, skull type, chest items, etc. With this, we can reset all the data later. So now that we have our original blocks, we're going to add a rollback method. This will create a new instance of a new class called RollbackRunnable which will roll back our blocks. If you want to see how that works, you can check out the code. It's pretty well commented.

    Modified ArenaTutorial class here.
    Modified Arena class here.
    New RollbackRunnable class here.

    Next tutorials:
    • Starting/Stopping the arena (including rollback!)
    • Adding teams & Multiple Spawns

    NOTE!: If you want to see my status on Minecraft Brawl / how I made a more advanced arena (like restoring things like gamemode on join/leave, lives, IconMenu for classes, removing a life when they leave they arena, etc) you can find it all on github here.

    Thanks for reading!
    Later on I'll update this with some more advanced stuff. I just wanted to show you guys the basics of arena making.
    Jakpok and MrSparkzz like this.
  2. Offline


    Although I can appreciate a good tutorial, I was a tad disappointed you didn't talk about saving/loading arena data to file, creating an interface to create/modify arenas in game, etc. As I think those are the most difficult aspects of a good arena plugin.
  3. Offline


    Thanks for the feedback, I'll make sure to add something for this. Do you think I should add commands for it?

    Oh, and here is how I do it in my Minecraft Brawl plugin.

    1. http://forums.bukkit.org/threads/tutorial-make-a-minigame-plugin.168164/page-3#post-1868730
    2. Mine actually goes into more detail, it's just that I put all the code into gists.
    3. His is for Minigames, mine is for arenas in general

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


    Ultimate_n00b Your "PlayerData" class misses something, because you just clear the normal inventory with "p.getInventory().clear()" and not the armor! You need to add "p.getInventory().setArmorContents(new ItemStack[] { new ItemStack(0), new ItemStack(0), new ItemStack(0), new ItemStack(0) });" in order to clear the whole inventory ;)
  5. Offline


    DarkBladee12, or p.getInventory().setArmorContents(null);
  6. Offline


    In my Minecraft Brawl plugin, just .clear() on the player's inventory does clear the armor.
  7. Offline


  8. Offline


    You could be right actually, because I override the armor, which would make it look like it was removed.

    Thanks for letting me know, I'll get that changed.
  9. Offline


  10. Offline


    As am I, and ArenaAPI is almost finished.

    Updated with the new ArenaManager class.
    Next update will have lobbies.

    Huh? The two locations define the boundary of the arena, which I will use later to check for certain stuff.

    Why would they extend the class? Couldn't they just modify it?

    This isn't an API?

    :confused: it says tutorial in the title

    But.. this thread isn't for that? This thread is a tutorial.

    And where you took a snippet of my text:
    "almost finished" doesn't mean "imma post a thread in resources on something that people can't use!".

    This thread has nothing to do with an API, it has to do with showing people how to make Arenas without one. Now, is this conversation over?

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


    As per-request, working on loading/saving from a config. I'll post it within the next few hours.

    Alright, added. I think I know what I am adding next to the tutorial, but does anyone else have suggestions?

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


    Suggestion: Voting if you have multiple arenas and arena resetting when game ends! :)
  13. Offline


    Resetting as in what? Like, reset of blocks? If so, I am currently trying to make this tutorial open. I will get into specific ideas in the future though, just not now.
  14. Offline


    I meant, after a game ends, blocks would restore to their original value so the original map would go back.
  15. Offline


    I'll think about it.
  16. Offline


    Alright, thanks. :)
  17. Offline


    It wouldn't be too hard to do (I've messed with rollback a lot recently) but I'm not quite sure the best way to roll it back. Normally there are a lot of checks that need to happen to roll it backs. Simple things such as some blocks need to be placed first and such. It also doesn't help that one of the methods is deprecated.
  18. Offline


    Hmm okay, that's true. Another method could be to access a compressed world folder on a server and overwrite it with the changed one? Just another thought, but yeah, make sure you find out the best method I guess. :)
  19. Offline


    Wtf. When you call the Arena constructor you automatically put the arena in the ArenaManger, making ArenaManager.addArena(new Arena()) completely redundant
  20. Offline


    Hm? I use that method in the Arena constructor to add it.
  21. Offline


    When you add the arena you call the constructor which automatically puts it into the list for you. But then you readded it to the list after calling the constructor.
  22. Offline


    Ah, I see what you mean. That's fixed now.

    Alright, figured out the fastest/easiest way to time splice rolling back blocks.

    Example code found here, tutorial will be here soon.

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


    Added a quick tutorial on rollback of blocks!
    Coming up:

    • Teams & Multiple Spawns
    • Starting/Stopping + Rollback on finish!
  24. Offline


    I really like where this is going. I see great potential in the near future.
  25. Offline


    Dang, I haven't updated this in a while. I'll add an update tomorrow.
  26. Offline


    The gist is gone :(
  27. Offline


    Yeah, sadly. I removed the code from that project, as I deemed it not needing it. The code is still in the first post though.
  28. Offline


    Ok lol. Just though I'd tell you.
  29. Offline


    Y u no add teams?
  30. Offline


    I'll add teams later - haven't updated this in a while.
Thread Status:
Not open for further replies.

Share This Page