Repository navigation
Getting Started
The API is published on JitPack. It only needs the Spigot API, and it compiles for Java 8, so it fits any plugin from 1.8.8 to 26.x.
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.nsider4</groupId>
<artifactId>ChatGames-API</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>Gradle (Kotlin DSL)
repositories {
maven("https://jitpack.io")
}
dependencies {
compileOnly("com.github.nsider4:ChatGames-API:2.0.0")
}Never shade the API into your jar. ChatGames is already on the server and provides these classes. Use
provided(Maven) orcompileOnly(Gradle). A shaded copy gives you a second, emptyGameTyperegistry and confusing errors.
name: MyPlugin
main: com.example.myplugin.MyPlugin
version: 1.0.0
api-version: '1.13'
depend: [ChatGames-Premium] # or softdepend, see below
folia-supported: true # only if the rest of your plugin supports Foliadepend makes Bukkit enable ChatGames before your plugin, so the API is ready in your onEnable.
public final class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
ChatGamesAPI api = ChatGamesAPI.get();
api.registerGame(this, /* a ChatGame */);
api.registerRace(this, /* a RaceGame */);
api.registerRewardAction(this, "mycoins", (player, amount) -> { /* ... */ });
api.registerChallengeType(this, "boss_kills");
}
}ChatGamesAPI.get() throws IllegalStateException if ChatGames isn't enabled. You don't need to keep
the instance; calling get() again is cheap.
If your plugin should also run without ChatGames, use softdepend: [ChatGames-Premium] and keep every
reference to the API in a separate class, so the classes are only loaded when ChatGames is there:
// MyPlugin.java
@Override
public void onEnable() {
if (getServer().getPluginManager().isPluginEnabled("ChatGames-Premium")) {
ChatGamesHook.register(this); // the only class that imports org.nsider.chatgames.api
}
}Everything you register belongs to your plugin. When your plugin disables (server stop, /reload,
a plugin manager), ChatGames removes your games, races, reward actions and challenge types, and stops
your game if it is running. You don't need an onDisable for it.
The server owner's config sections for your games are kept, and so are players' stats, so everything is still there when your plugin comes back.
Games and races get an id: 2 to 32 lower-case letters, digits or _, starting with a letter,
e.g. capitals, boss_hunt, quiz2. The id is used in:
- the config files (
games.yml/races.yml/messages.yml/rewards.ymlsections); - the command
/chatgames <id>and the permissionchatgames.start.<id>; - placeholders like
%chatgames_wins_<id>%.
Pick ids that won't clash with other plugins, and never change them later: a new id is a new game,
with new config sections and empty stats. An id that is already a game (built-in or another
plugin's) or a /chatgames sub-command (top, stop, menu...) is refused with an
IllegalArgumentException.
- Make a chat game or a race.
- Read Threads and Folia before calling the API from async code.
Basics
Adding content
Reacting and reading
Reference