Work with API

Work with API

In beginning, you need to register plugin. How you can do this:

MinigamesPluginController api = ((MinigamesAPI) Bukkit.getPluginManager().getPlugin("MinigamesAPI")).registerMinigame(this, getConfig());

MinigamesPluginController class includes manager for to work with parts of the game.

ArenaManager This class includes method to work with arenas.

SignManager This class allows you to control game signs and set click handlers.

SessionManager This class allows you to control the game sessions and create new sessions.

Detailed descriptions of all functions is JavaDocs.

Event: Plugin causes the next events: GamePlayerHitEvent, GamePlayerKillEvent, GameSessionStartEvent, GameSessionStopEvent, GameSignDestroyEvent, PlayerJoinGameSessionEvent, PlayerLeaveGameSessionEvent и GameSessionTickEvent (called once per second during game). Their meaning is clear from their names.

Code example:

api.getArenaManager().createArena("testarena", firstCorner, secondCorner, new Location[]{spawn1, spawn2});

- Creates a new arena with name testarena and with given angles and spawns.

api.getSessionManager().createSession(api.getArenaManager().getArena("testarena")).joinPlayer(api.getAPI().getGamePlayer("serega6531"));

- Starts a new game on the arena "testarena" and adds player serega6531.

if(api.getSessionManager().getPlayerSession("serega6531") != null) api.getAPI().getPlayerSession("serega6531").joinPlayer(api.getAPI().getGamePlayer("testplayer"))

- If player with name serega6531 in game, then aading in this game player with name testplayer

    private void loadSigns(){
        if(!getConfig().contains("signs")) return;
        ConfigurationSection sign;
        String data;
        String spl[];
        Location loc;
        ConfigurationSection signs = getConfig().getConfigurationSection("signs");
        for(String signname : signs.getValues(false).keySet()){
            sign = signs.getConfigurationSection(signname);
            loc = deserializeLocation(sign.getConfigurationSection("location"));
            data = sign.getString("data");
            spl = data.split(";;");
            api.getSignManager().registerSign(new GameSign(sh, spl[0], spl[1], spl[2], loc, this));
        }
    }
    private void saveSigns(){
        GameSign[] signs = api.getSignManager().getSignsToSave(this);
        ConfigurationSection sec, ssec;
        if(!getConfig().contains("signs")) sec = getConfig().createSection("signs");
        else sec = getConfig().getConfigurationSection("signs");
        int id = 0;
        for(GameSign sign : signs){
            ssec = sec.createSection("sign" + id);
            ssec.createSection("location", serializeLocation(sign.getLocation()));
            ssec.set("data", sign.getCommand() + ";;" + sign.getArgument() + ";;" + sign.getText());
            id++;
        }
    }

- Saves and loads signs from config. (that should make minigame itself)

    @EventHandler
    public void onSignChange(SignChangeEvent e){
        if(!e.getLine(0).equalsIgnoreCase("[GameSign]")) return;
        api.getSignManager().registerSign(new GameSign(new SignHandler(){
 
            @Override
            public void onClick(Player player, String command,
                    String argument) {
                player.sendMessage("Clicked! " + command + " - " + argument);
            }
       
        }, e.getLine(1), e.getLine(2), e.getLine(3), e.getBlock().getLocation(), Test.pl));
    }

- Registers a new signs during their cration.

JavaDocs


Comments

Posts Quoted:
Reply
Clear All Quotes