-
Notifications
You must be signed in to change notification settings - Fork 0
Game Setup
To make plugin a game engine, the main class has to extend the GameEngine
. It declares two abstract getters for two key objects for the game logic - GameManager
and GameType
object. Creating the plugin based on GameEngine class doesn't differ much from extending the well known JavaPlugin
class provided by Spigot API, except for two additional getters. Those will be used to obtain GameManager and GameType at any time.
Custom game engine plugin class declaration:
package me.kavu.test.mygameplugin;
import dev.kavu.gameapi.GameEngine;
import dev.kavu.gameapi.GameType;
import dev.kavu.gameapi.GameManager;
public final class MyGameEngine extends GameEngine {
private final GameType myGame = new GameType("MyGame", "mygame", "mg", 4, 16);
private final GameManager gameManager = new GameManager(this);
@Override
public GameType getGameType() {
return myGame;
}
@Override
public GameManager getGameManager() {
return gameManager;
}
}
GameManager
class collects almost all necessary tools for the full game management. It is fine to store GameManager object in a variable as shown below, although, it is more recomended to store it in a final field instead. This is because of the concept of GameManager as a one and permament tool for controlling the whole game. Best practice is to declare it in main plugin class (extending GameEngine
) and return by GameEngnie.getGameManager()
function.
Game manager mainly stores other, more percise and cathegorized tools. It is created to accumulate them in one class and also predefine some if not specified in the constructor. Thus, it will be the source for other important game logic parts, as for ex.: GameStateTimer
or MapManager
.
Along side the game manager, game engine stores the GameType
object. This class defines the basic properties of the game, such as name, minimum and maximum amount of players. It should be stored in GameEngine class. It functions as a set of constant and dynamic data that is meaningful for the game logic.
GameType
object is created using its constructor where the basic data is passed in arguments.
GameType myGame = new GameType("MyGame", "mygame", "mg", 4, 16);
Game type contains a set of properties that can be accessed using getProperties()
method. Properties
object is serializable thus its values can be stored ex. in a file or in database.
Rules are properties that game considers as instructions to how to act in certain situations. Rule
objects are generics of enum types, which forces assigned values to be constant. This API provides BoolState
enum representing the boolean value.
Rule<BoolState> myRule = new Rule<>("my_rule", BoolState.TRUE);
To store rules there is a RuleSet
class. Its object can be stored in game manager. Moreover, it implements the Set
interface so can be iterated though using foreach loop.
RuleSet ruleSet = gameManager.getRuleSet();
ruleSet.add(myRule);
for(Rule<?> rule : ruleSet) {
System.out.println(rule.getName() + ": " + rule.getState());
}
Adding rules to the rule set is nearly the same as adding objects to the set. Although, there cannot be rules with same name in the set. This will throw an exception. Rule
object can be also obtained from rule set by its name using getRule()
method.
© 2023 Kamil Więczaszek under Apache 2.0
- Java version: 8
- Build: Maven
- Minecraft version: 1.8.8+
- License: Apache 2.0