Skip to content

Everything(temporary)

Oğuz Can Yılmazlar edited this page May 5, 2022 · 1 revision

Getting Started with BladeAPI

THIS WIKI IS IN AN EARLY STAGE, WILL BE REDONE EVENTUALLY

BladeAPI is a small system based minigame api, purpose built for creating minigames with flexibility and ease of use.

To get started, you'll need to integrate BladeAPI into your project using Maven or Gradle.

See the README to get Maven repository information to add it into your project.

Creating your first MiniGame

In order to create your first minigame you first need to create a class extending AbstractGame.

public class ExampleGame extends AbstractGame {
    public ExampleGame(String name, JavaPlugin plugin) {
        super(name, plugin);
    }
}

Adding phases to your MiniGame

To get your minigame running, you need to add phases to your minigame.

First we need to create a phase class extending AbstractPhase.

public class ExamplePhaseOne extends AbstractPhase {
    public ExamplePhaseOne(AbstractGame game) {
        super(game);
    }

    @Override
    public Duration duration() {
        return Duration.ofSeconds(10);
    }
}

The duration in our phase class determines our phase's duration(yeah i know, crazy right?). You can change the duration by returning a duration variable which can come in handy in the future.

private Duration duration = Duration.ofSeconds(10);

@Override
public Duration duration() {
    return duration;
}

The AbstractPhase class has onEnable, onDisable and onTick methods by default which you can override freely.

Adding a feature to your phase.

You can add the features implemented in the BladeAPI in the phase's constructor using addFeature method.

public ExamplePhaseOne(AbstractGame game) {
    super(game);
    addFeature(new NoHitFeature(this));
}

Creating your feature.

To create your own feature, you need to create a class extending the AbstractFeature class.

public class ExampleFeature extends AbstractFeature {
    public ExampleFeature(AbstractPhase abstractPhase) {
        super(abstractPhase);
    }
}

AbstractFeature class has onEnable, onDisable and onTick methods by default you can override them freely and AbstractFeature class implements Listener by default.

Starting your game

Finally! We can now instantiate our minigame.

To start our minigame we need to create it first.

ExampleGame exampleGame = new ExampleGame("example_game",/*plugin_instance*/);

Then we add our phases into our minigame.

exampleGame.addPhase(ExamplePhase.class);

Lastly, we enable our game.

exampleGame.enable(/*start_delay*/2,/*period*/1);

Notes

This part is temporary, will be removed when javadocs is present.

AbstractGame class:

  • You can add phases on the go inside of phases with the same (AbstractGame class) addPhase method.
  • addPhase method by default adds to the last, with addPhaseNext you can add a phase directly after the phase the game is in.
  • endPhase method ends the current phase.
  • setFrozen method, if true, prevents the current phase from ending. GameData class:
  • Holds winner, player, spectator list. AbstractPhase class:
  • timeLeft method returns the time left in duration.
  • getFeature method returns the feature in the phase(can return null, used for data between features)

Already implemented features

  • AutoRespawnOnDeathFeature: Respawns the player automatically.
  • MapFeature: Holds the spawnpoint locations(extremely early stage of feature).
  • NoBlockBreakFeature: Prevents block breaking.
  • NoBlockPlaceFeature: Prevents block placing.
  • NoHitFeature: Prevents player from getting damaged.
  • SpawnOnSpawnLocationFeature: Spawns the players on spawn location determined in MapFeature.
  • SpectatorOnDeathFeature: Makes the player spectator on death.
  • SpectatorOnJoinFeature: Makes the player spectator on join.
  • TeamFeature: Assigns players to the teams you specified with TeamFeatureSupplier.

Events

  • GameFinishEvent: Gets fired when the game is finished.
  • GameStartEvent: Gets fired when the game gets started.
  • GamePhaseChangeEvent: Gets fired when the phase changes.
  • PlayerJoinGameEvent: Gets fired when the player joins the minigame.
  • PlayerLeaveGameEvent: Gets fired when the player leaves the minigame.