This is a very basic api for adding chat games your players can interact with.
>2K DOWNLOADS <3
Features: It comes with 4 default question types that can be disabled through config. These are:
- Letters in the alphabet questions.
- Random letter sequences that need to be copied (Case sensitive)
- Simple math questions
- Scrambled text (defined in config) that needs to be decoded:
the answer being 'flint and steel' in this case
Note: This is not a stand alone plugin even though it comes with 4 default question types. The plugin itself only has support for basic rewards (e.g. money and commands).
Commands: /chatgames current - shows current question, answer and duration
/chatgames leaderboard - shows top 10 scores if available
/chatgames list - shows all loaded question generators
/chatgames reload - reloads the plugin
/chatgames reset [player] - resets all scores/the player's score
/chatgames skip - skips the current question
/chatgames toggle - Toggles whether or not you receive chat game announcements
/chatgames version - shows the plugin's version
Permissions: chatgames.admin - most /chatgames commands
chatgames.admin.reload - /chatgames reload
chatgames.admin.reset - /chatgames reset [player]
chatgames.leaderboard - /chatgames leaderboard
chatgames.blacklist - never get chat games
chatgames.whitelist - always get chat games
API:
Code (Java):
publicclass ExampleQuestion
extends ChatGameGenerator
{ // You need to extend ChatGameGenerator (the generator automatically registers itself, so only create one instance) privatestaticfinalString ALPHABET
="abcdefghijklmnopqrstuvwxyz"; // Required in later versions public ExampleQuestion
(Plugin plugin
){ super(plugin
); } // #getNewQuestion() is called every time this generator gets to ask a question @Override
public Question getNewQuestion
(){ // You return a new Question object containing the question and the answer a player has to type (and if that answer is case sensitive) // In this example you have to answer what character is at the given position in the alphabet int index
=newRandom().
nextInt(ALPHABET.
length()); returnnew Question
(){ @Override
publicString getAnswer
(){ returnCharacter.
toString(ALPHABET.
charAt(index
)); } @Override
publicboolean isCaseSensitive
(){ returnfalse; } @Override
publicString getQuestion
(){ String message
="what's the %index% letter in the alphabet"; return message.
replace("%index%",
(index
+1)+(index
<3?(index
==0?"st":(index
==1?"nd":"rd")):"th")); } @Override
publicString getMessage
(){ return"&7Answer &e%question% &7to get rewards!"; } }; } // A generator needs a #getIdentifier() method as of update 6.0 @Override
publicString getName
(){ return"Alphabet"; } }
Code (Java):
// Note that this event is asynchronous as of update 4.0 because it's called by an AsyncPlayerChatEvent listener @EventHandler
publicvoid onWin
(AsyncChatGameWinEvent event
){ Player winner
= event.
getPlayer(); winner.
getInventory().
addItem(new ItemStack
(Material.
DIAMOND)); event.
setWinMessage("&aCongratulations! You won a diamond"); }
Code (Text):
// The script has to return a JSON object with the required members
// Put this script in the ChatGames\scripts directory
function getQuestion() {
return {
answer: "true",
caseSensitive: false,
question: "this is a lie",
message: "&7Is '&e%question%&7' a paradox?"
};
}
getQuestion();