-
Notifications
You must be signed in to change notification settings - Fork 41
First Minigame
So, let's create our first minigame with this API then.
First off, setup a new project in eclipse as seen here.
The basic start now is as follows. This uses the default arena and the default command set. The "my_minigame" parameter is the name of our minigame.
public class Main extends JavaPlugin {
MinigamesAPI api = null;
public void onEnable() {
api = MinigamesAPI.getAPI().setupAPI(this, "my_minigame");
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return api.getCommandHandler().handleArgs(this, "minigamesexample", "/" + cmd.getName(), sender, args);
}
}
The next step would be allowing to overwrite arena functions for our needs, so let's add custom arena loading and a custom IArena class. (this example is taken from the MGAPI-Test plugin)
public class Main extends JavaPlugin {
MinigamesAPI api = null;
public void onEnable() {
api = MinigamesAPI.getAPI().setupAPI(this, "example", IArena.class);
PluginInstance pinstance = MinigamesAPI.getAPI().pinstances.get(this);
pinstance.addLoadedArenas(loadArenas(this, pinstance.getArenasConfig()));
}
public static ArrayList<Arena> loadArenas(JavaPlugin plugin, ArenasConfig cf) {
ArrayList<Arena> ret = new ArrayList<Arena>();
FileConfiguration config = cf.getConfig();
if (!config.isSet("arenas")) {
return ret;
}
for (String arena : config.getConfigurationSection("arenas.").getKeys(false)) {
if (Validator.isArenaValid(plugin, arena, cf.getConfig())) {
ret.add(initArena(plugin, arena));
}
}
return ret;
}
public static IArena initArena(JavaPlugin m, String arena) {
IArena a = new IArena(m, arena);
ArenaSetup s = MinigamesAPI.getAPI().pinstances.get(m).arenaSetup;
a.init(Util.getSignLocationFromArena(m, arena), Util.getAllSpawns(m, arena), Util.getMainLobby(m), Util.getComponentForArena(m, arena, "lobby"), s.getPlayerCount(m, arena, true), s.getPlayerCount(m, arena, false), s.getArenaVIP(m, arena));
return a;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return api.getCommandHandler().handleArgs(this, "minigamesexample", "/" + cmd.getName(), sender, args);
}
}
That's the Main class I normally start with. The following code is my new IArena class which extends the default Arena. You can now start overwriting the given Arena functions and add your own stuff. I normally use the Main class above as Listener too and add custom stuff like the flying cars of the first example on the main wiki page.
public class IArena extends Arena {
public IArena(JavaPlugin plugin, String name) {
super(plugin, name);
}
@Override
public void joinPlayerLobby(String playername){
Bukkit.getLogger().info("Test joinPlayerLobby()");
return;
}
@Override
public void start(boolean tp){
Bukkit.getLogger().info("Test start()");
return;
}
}
lol