Originally Posted by
Swiffy
post the class and ill give u a fix
Code:
package server.model.minigames;
import server.event.Event;
import server.event.EventContainer;
import server.event.EventManager;
import server.model.players.Player;
import server.model.players.PlayerHandler;
import server.util.Misc;
import server.model.players.Client;
public class TriviaBot {
public static void startup() {
EventManager.getSingleton().addEvent(new Event() {
@Override
public void execute(EventContainer e) {
if (getPlayerCount() > 0) {
askQuestion();
}
}
}, 900000);
}
public static void attemptAnswer(Player p, String attempt) {
if (!currentQuestion.equals("") && attempt.replaceAll("_", " ").equalsIgnoreCase(currentAnswer)) {
currentQuestion = "";
c.getItems().addItem(995, 125000);
sendServerMessage("<shad=255>Well done! "+p.playerName + " has quessed the question correctly and earned Coins!");
}
}
public static boolean acceptingQuestion() {
return !currentQuestion.equals("");
}
public static void askQuestion() {
final int random = Misc.random(TRIVIA_DATA.length - 1);
currentQuestion = TRIVIA_DATA[random][0];
currentAnswer = TRIVIA_DATA[random][1];
sendServerMessage(currentQuestion);
}
private static int getPlayerCount() {
int players = 0;
for (Player p : PlayerHandler.players) {
if (p != null)
players++;
}
return players;
}
private static void sendServerMessage(String message) {
for (Player p : PlayerHandler.players) {
if (p != null) {
((Client)p).sendMessage(message);
}
}
}
private static final String[][] TRIVIA_DATA = {
{"<shad=255>[Trivia] What year was Server first opened?", "2016"},
{"<shad=255>[Trivia] What is the highest leveled NPC in the game?", "Corporal Beast"},
{"<shad=255>[Trivia] Who created the server originally?", "Owner"},
{"<shad=255>[Trivia] Which NPC sells magic gear?", "Zaff"},
{"<shad=255>[Trivia] What is the highest rank in the game?", "Owner"},
};
private static String currentQuestion;
private static String currentAnswer;
}