API LobbyAPI - Efficiently manage multiple worlds!

Discussion in 'Resources' started by Zombie_Striker, Dec 27, 2015.

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

    Zombie_Striker

    LobbyAPI - Efficiently manage multiple worlds!

    Bukkit Dev Link: http://dev.bukkit.org/bukkit-plugins/lobbyapi/

    Description:
    A while ago I wanted to host my own Minigame server, where I could have different minigames in different worlds. I did not want to use Bungee due to having to manage multiple servers, and I could not find any plugins that managed to help me control multiple worlds, while still feeling user friendly. As such, that is why I created LobbyAPI.

    Features:
    LobbyAPI aims to allow plugin developers to control almost every aspect of each world, such as:
    • Ability to have a max player count per world
    • Whitelist worlds
    • Custom Spawn points per world
    • Per-world Inventories
    • Permanent Day/night and "No Rain" variables
    • Spawn Items (Items given when spawning in a world)
    • Death Worlds (Determine whether a player gets teleported to a specific world on respawn)
    LobbyAPI also comes with a user friendly menu to teleport to worlds, which allows all players to easily teleport to any world they please without any messy or complicated commands. All they would need to do is click the icon which would represent the world the want to go to. Plugin developers can also control:
    • Whether a player can see a world through the Menu
    • Whether a player can teleport to a world
    • Where the player will be teleported to
    • What the name of the world would be in the menu
    • What the description for that would would be for the menu
    • What material the icon would be (default is wool, but can be changed to any type of material)
    • What "number" is associated with that world (E.g. The item amount)
    • What slot the icon for the world will be in.
    • What happens when the player finally is teleported to that world.
    How to use LobbyAPI's Menu:
    To get access to the menu, all you have to type is "/lobby". From there, it should open up the menu for the player. When first installing the plugin, the menu will be empty. That's where this next section comes in.

    How to use Lobby API to create and customize worlds:
    If you're a Plugin Developer
    Through Plugins (open)

    To create the world
    CREATING THE WORLD (open)

    Okay, this is the recommended way to control worlds. Now, before we get started, you need to make sure your plugin registers your world AFTER LobbyAPI has been enabled. Do this by either making LobbyAPI a dependency, or do the lazy way by creating a DelayedTask.

    Okay, so lets register your world
    Code:
    public void onEnable(){
    world = getServer().getWorld("Your world");
    
    LobbyAPI.registerWorld(world, new Location(world, 0, 80, 0),
    "Inventory Save Location",  "Description",
    0 /*if wool, this would be the durability of the material*/,
      0 /*The slot the world will be in*/, GameMode.Survival);
    
    LobbyAPI.setWorldMaterial(world, Material.TYPE);
    
    }
    Let me break down what each thing does:
    • "world" is the world's instance that you are registering. Basically, this is the world you want the player to have the ability to teleport to.
    • "New Location" Refers to the spawning point that the player would spawn at.
    • "Inventory Save location" is the name you want to designate all inventories that are on that world. This really only comes in handy if you want worlds to share the same inventories. If you want to worlds to have the same inventories, you would put the same name for both of them (E.g. If you had "Word" for world 1, and "Word" for world2, both worlds would share the same inventories)
    • "Description" should be self explanatory. This is what would appear under the item.
    • The First 0 is the durability of the item. If it were wool or clay, this would control what color it would be. If you're picking another material besides wool or clay, then keep it 0.
    • The second 0 refers to the slot that the icon will be in. "0" is the first slot, "1" is the one after that, ect.
    • "Gamemode.SURVIVAL" refers to what gamemode the player would be set to when the go to that specific world.
    • [OPTIONAL] The next line with "Material.TYPE" refers to what you want material you want the icon to be (E.g., Stone, wood, even bread or cake can be inputted). The default is WOOL.
    That is all you need to add a world to the menu. Simple, right? (not referring to the wall of text that explains what everything means)

    IMPORTANT: If you want a world to have an inventory, you must register it. If you do not, every time a player goes to that world, their inventory will be deleted for that world. If you want to save the inventory for worlds, but do not want them to be seen, go down to "Hidden Worlds"



    To unregistered a World
    Unregister World (open)

    To unregister the world:
    Code:
     LobbyAPI.unregisterWorld(World worldToUnregister);


    To change material/color/description of a World
    Changing any part of a world (open)

    Code:
     LobbyAPI.getLobbyWorld(World instance).setMaterial/Color/Description();


    To hide a World from the menu
    Unregister World (open)

    In order for a world to access an inventory, it must be registered, but you may not want the world to be accessed through the menu. This is where hidden worlds comes in. If you want a world to have certain features (access to an inventory/ setting static weather or time/ max players), but no to be able to be seen through the menu, you can hide the world using this method.
    Code:
     LobbyAPI.hideWorld(World worldToHide, boolean ifIt'sHidded);

    To registered a BungeeCord Server
    Unregistered bungeecord servers (open)

    Registering a bungeecord server is the same as registering a world:
    Code:
     LobbyAPI.registerBungeeCordServer(String server,int Slot, int amount,int item duribility (color of glass, if the material is not glass, then set this to 0));



    To unregistered a BungeeCord Server
    Unregistered bungeecord servers (open)

    Code:
     LobbyAPI.unregisterBungeeCordServer(String server);


    To change material/color/description of BungeeCord Server
    Chaning any part of a bungee server (open)

    Code:
     LobbyAPI.getServer(String the server name).setMaterial/Color/Description();


    To add itemstacks when a player joins a world.
    LINKING DEATH WORLDS (open)

    This one is actually quite simple.
    Code:
     LobbyAPI.setWorldToTeleportToOnDeath(World you die in, world you repsawn in);
    See? All you have to do is put in the instance of the world you die in, and the instance of the world you respawn in. This can be put where you create the world

    To link "death worlds"
    LINKING DEATH WORLDS (open)

    This also shows use of the LobbyAPI.setName() method. This can be used for easier access to naming itemstacks.
    Code:
    
                 ItemStack[] items = { LobbyAPI.setName(
                     "Displayname", 0, Material.TYPE, /*LORE*/null) };
                      //OR, in other words
                 ItemStack[] items = { Itemstacks you want };
                 LobbyAPI.setWorldItems(world, items);
    
    The main idea behind this is you want to create an itemstack array, and then store that itemstack array with the world.
    #Note: If the player does not have the item, it will always make sure the player has that item in their inventory (useful for hubs, worlds that need the player to always have an item). If you want to give the player the item one time only, the you would use the method that will be provided after this. (Currently coding it if you see this message.)

    How to see when a player teleports to a world/ clicks the world in the menu.
    EVENTS (open)

    This one you have to use my custom Events for, specifically, PlayerSelectWorldEvent and PlayerChangeWorldEvent (not to be confused with PlayerChangesWorldEvent that comes with bukkit, you should be able to see a difference with the imports)

    To get when a player selects a world:
    Code:
    @EventHandler
    public void onClick(PlayerSelectWorldEvent event){
    
    //To cancel the player from teleporting
    event.setCanceled(true);
    //To get the player who clicked:
    event.getPlayer();
    //To get where the player will spawn
    event.getDestination();
    //To set where the player will get teleported to
    event.setDestination(location);
    
    }
    
    To get when a player changes world:
    Code:
    @EventHandler
    public void onChangeWorld(PlayerChangeWorldEvent event){
    
    //To get the player who clicked:
    event.getPlayer();
    
    }
    
    With this, you can do anything to the player once they spawn in that world.


    If you want to use commands:
    Through Commands (open)

    To register a world
    Registering Worlds (open)

    This one is actually quite simple.
    Code:
     /LobbyAPI addWorld (WorldName) (Slot) (X) (Y) (Z) (Color (1 through 15))
    Note: WorldName is CaSeSenSiTive, meaning you have to make sure the name is exactly the same.
    This is a one time registration. All you need is to use this command once and it should last throughout restarts/reloads.

    To un-register a world
    Un-registering Worlds (open)

    Again, quite simple.
    Code:
     /LobbyAPI removeWorld (WorldName) 


    To register a BungeeCord Server
    Registering Servers (open)

    The way you enable BungeeCord servers is almost the same as you would for any other world
    Code:
     /LobbyAPI addServer (ServerName) (Slot) (Color (1 through 15))
    Note: Sever Name is CaSeSenSiTive, meaning you have to make sure the name is exactly the same.
    This is a one time registration. All you need is to use this command once and it should last throughout restarts/reloads.

    To un-register a world
    Un-registering Servers (open)

    Code:
     /LobbyAPI removeServer (ServerName) 



    Do you need help, or have a suggestion?
    Either post in the comments below your problem or suggestion, or go to the Bukkit Dev page and create a ticket. (I will most likely get to you faster if you post here)
     
    Last edited: Jan 23, 2016
    ChipDev likes this.
  2. Offline

    BlueCraftMC

    Can you give a quick tutorial, on how to give a player items on world joins? Ive been trying to do it. But i cant do it/do snt work.
     
  3. Offline

    Zombie_Striker

    @BlueCraftMC
    Sure, I just added the code to the main post, but here is the code required.
    Code:
    
                 ItemStack[] items = { LobbyAPI.setName(
                     "Displayname", 0, Material.TYPE, /*LORE*/null) };
                      //OR, in other words
                 ItemStack[] items = { Itemstack };
                 LobbyAPI.setWorldItems(world, items);
    
     
  4. Offline

    BlueCraftMC

    Thx for that, but what i meant was, how to do it without this api, only using craftbukkit. But this api looks awesome, I'm gonna use it on my plugins!!
     
  5. Offline

    Zombie_Striker

    @BlueCraftMC
    • PlayerChangedWorldEvent
    • If (the event (dot) get the world player's going to equals the world you're testing for)
    • Loop through all the items you want to give the player.
    • Give the player those items.
     
    BlueCraftMC likes this.
  6. Offline

    BlueCraftMC

    Thx! And good job on the plugin.

    Could i use PlayerJoinEvent instead of PlayerChangeWorldEvent?

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

    mcdorli

    PlayerJoinEvent fires, when the player enters the server, the other one is when the player changes world

    Can't test it currently, does this support per world inventorys?

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

    Zombie_Striker

    @mcdorli
    Yes. That is one of the things I felt was lacking in other plugins that managed worlds.

    You can have per-world inventories by changing the "save name" (the key that LobbyAPI uses to save the inventory in the config). Currently, every time you create a new world with the command, the "save name" is automatically set to be the world name (as such, worlds cannot share inventories when saved using the commands. I am working on an update to change the save names). If you use a plugin to register the worlds, you can set the save name to be whatever you want (and as such, create worlds that share inventories)
     
  9. Offline

    WolfMage1

    PlauerSelectWorldEvent
    PlauerChangeWorldEvent

    Plauer? xD
     
  10. Offline

    Zombie_Striker

    WolfMage1 likes this.
  11. Offline

    87pen

    @Zombie_Striker My one and only Zombie_Striker plan on having world specific inventories?
     
  12. Offline

    Valkyriean

    Hey, I have a question. I was looking through your plugin features and I saw this one:
    • Allows players to teleport from Server to Server.
    However, when I installed the plugin and did /lobbyapi Bungee it just says "Bungee for LobbyAPI has been disabled!". No matter how many times i try, it keeps saying that, even after I restarted the server. I looked through the instructions you posted that pertains to connecting worlds together, but I didn't see anything about connecting servers together. So, how would I go about connecting several servers together?
     
  13. Offline

    Zombie_Striker

    @Valkyriean
    The feature was very buggy/did not work (as noted by another member who tested it), and since I do not have a bungee server, nor do I know much about how it works, I could not fix those problems. Because of that, the feature is currently disabled. Once I can set up a bungee server or have other people to test it out, then I will attempt to add bungee support.
     
  14. Offline

    Valkyriean

    Thanks for the quick response! I guess ill just look for an alternative for now, but in the future I will be looking forward to using this plugin if it ends up supporting bungee :D
     
  15. Offline

    Zombie_Striker

    @Valkyriean
    After looking at the old code, it turns the problems were fixed when I updated the world storage system. When the file (1.7.08) is approved, you can add servers to the menu. I updated the OP post to show the commands/methods needed to do so.
     
  16. Offline

    Zombie_Striker

Thread Status:
Not open for further replies.

Share This Page