Skip to content
Nicholas edited this page May 25, 2017 · 6 revisions

Getting Started

(All code here should go in the onEnable() of your main plugin class)

Step 1: Setup & Configuration

Intro

In this tutorial, we'll be creating a simple spleef minigame.

Arena Object

Games require an arena to run in. Create one with Arena(String). It will also save a default version of the world for resetting to GameWorlds/

/*
Create an arena object. When created, it will load the world onto the server. If the world exists as a folder, it will be loaded from that; otherwise, a new world is generated. In order to increase the speed of this process, no terrain is generated.
*/
Arena arena = new Arena("Spleef");

Game Object

Game objects are the centerpart of your minigame.

/*
Arguments are (String name, Arena arena, Plugin registeringPlugin);
*/
Game spleef = new Game("Spleef", arena, this);

Configuring the Game

You can customize the Game in many ways, most of which involve disabling/enabling some included features. In this example, even though some of these are enabled by default, I'll be showing them anyway.

spleef.setPrefix("[Spleef]"); //Set the prefix for messages sent to players in the game.
GameSettings gSettings = spleef.getGameSettings(); //Set a variable for accessibility. 
gSettings.shouldUseTeams(false); //Since Spleef is a solo minigame, we're disabling automatic features related to teams.
gSettings.setMOTD(true); //This will override the server's MOTD, setting the game status (Ingame, Waiting) to be displayed in the server list.
gSettings.setMaximumPlayers(8);
gSettings.setMinimumPlayers(2);
gSettings.shouldSetPlayerListCount(true); //Set the maximum player count in the server list to the maximum allowed players.
gSettings.setAutomaticCountdown(true); //When minimum player requirements are filled, it will start counting down before starting the game.
gSettings.setCountdownTime(20); //Set the countdown time in seconds.
gSettings.setLobbyServer("hub"); //Set the BungeeCord hub server
gSettings.shouldLeavePlayerOnDisconnect(true); //Kick the player from the game when they disconnect from the server. If set to false, you can allow players to resume playing their game, but we don't need this feature here.

Arena Configuration

There are 45+ properties you can set for the arena. Think of these properties as WorldGuard region flags; in fact, they were introduced as a replacement to WorldGuard for minigames. You can disable or enable just about anything, with more properties being introduced in every update.

ArenaSettings aSettings = arena.getArenaSettings(); //Get a variable for convenience.
aSettings.setCanBuild(false);
aSettings.setCanDestroy(false); //While this is a Spleef minigame, we don't need players to be able to destroy blocks until the game starts. Properties can be changed at any time.
aSettings.setCanPvP(false);
aSettings.setAllowPlayerInvincibility(true);
aSettings.setAllowDurabilityChange(false);
aSettings.setAllowFoodLevelChange(false);
aSettings.setAllowMobSpawn(false);
aSettings.setAllowBlockDrop(false);
aSettings.setAllowItemDrop(false);
aSettings.setAllowInventoryChange(false);

//Game Locations
/*
You can add multiple spawn locations, used when the game starts. This is useful, since in most cases you don't want to spawn players inside the same location.
*/
spleef.addSpawn(mySpawn1);
spleef.addSpawn(mySpawn2); //etc...

arena.setLobbySpawn(myLobbySpawn); //Used before the game has started.
arena.setSpectatorSpawn(mySpecSpawn); //Used for spectators

Areas

Areas are a large and useful part of GameAPI. While initially they may seem miscellaneous, you will soon find how useful they are in minigames. Areas do nothing by themselves, but when used with events like PlayerEnterArea and PlayerLeaveArea, they become quite powerful. In this case, we'll be using it to define where the floor to our Spleef arena is. To create an Area, you just need a String ID and two locations.

Area spleefArea = new Area(corner1, corner2, "spleefArea");
spleef.registerArea(spleefArea); //Register the area to the spleef game.

As you can see, very simple. We won't be using it in this tutorial, but Areas act very much like WorldGuard regions in the way that they can have their own ArenaSettings.

GameStartEvent

Our game should now work as-is. You can join the server the plugin is loaded on, and you should automatically be teleported to the lobby location. If you get a second account and join (or set minimum players to 1), the countdown will start. However, even though the game will start and teleport you to a random spawn, nothing else will happen. This is what GameStartEvent is for.

GameStartEvent is where you give the player their default items; in this case, an enchanted diamond shovel. We'll also allow block breaking. Go ahead and create a class and call it GameStartListener.

public class GameStartListener implements Listener {

    @EventHandler
    public void onGameStart(GameStartEvent e){
        
    }

}

Before we do anything else, we should register the listener in the onEnable() method for your plugin:

Bukkit.getPluginManager().registerEvents(new GameStartListener(), this);

GameAPI uses GamePlayer instead of Bukkit's Player object for keeping track of players. This is to support offline player information, as well as provide a few helpful functions.

for(GamePlayer player : e.getGame().getPlayers()){

}

Clone this wiki locally