Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.global
- import com.ngxdev.arkgroovy.ArkGroovy
- import com.ngxdev.arkgroovy.enviorment.Exports
- import com.ngxdev.arkgroovy.helper.Commands
- import com.ngxdev.arkgroovy.helper.Events
- import groovy.transform.Field
- import ninja.coelho.arkjs.extern.database.AsyncDatabase
- import ninja.coelho.arkjs.extern.database.DatabaseManager
- import ninja.coelho.arkjs.system.datautil.ModelDatautilSystem
- import org.apache.commons.lang3.mutable.MutableInt
- import org.apache.commons.lang3.text.WordUtils
- import org.apache.commons.lang3.tuple.Pair
- import org.bukkit.Bukkit
- import org.bukkit.Material
- import org.bukkit.OfflinePlayer
- import org.bukkit.entity.Player
- import org.bukkit.event.EventPriority
- import org.bukkit.event.inventory.InventoryCloseEvent
- import org.bukkit.event.player.AsyncPlayerChatEvent
- import org.bukkit.inventory.ItemStack
- import org.bukkit.scheduler.BukkitTask
- import scripts.global.utils.ItemUtils
- import scripts.shared.systems.MenuBuilder
- import scripts.shared.systems.MenuEvent
- import scripts.shared.utils.ArkJsUtils
- import java.time.LocalDate
- import java.time.temporal.WeekFields
- @Field AsyncDatabase database = null
- @Field ModelDatautilSystem databaseUtils = null
- Bukkit.getScheduler().runTaskAsynchronously(ArkGroovy.plugin, {
- while (ArkJsUtils.arkjs.getSystemContext() == null) {}
- DatabaseManager manager = ArkJsUtils.arkjs.getSystemContext().getDatabaseManager()
- this.database = manager.getDatabase(manager.infoService().byName("default")).async()
- this.databaseUtils = (ModelDatautilSystem) ArkJsUtils.arkjs.getSystemRepository().byName("datautil")
- this.database.execute("CREATE TABLE IF NOT EXISTS rt_triviasanswered (server_id INT NOT NULL, week INT NOT NULL, player_uuid_least BIGINT NOT NULL, player_uuid_most BIGINT NOT NULL, count INT NOT NULL, PRIMARY KEY(server_id, week, player_uuid_least, player_uuid_most))", null)
- })
- @Field private final Map<String, Object> config = [
- "Geography": [
- "What is the capital of the United States?": [
- "Washington D.C.",
- "Washington D.C",
- "Washington DC"
- ],
- "What is the capital of the United Kingdom?": [
- "London"
- ],
- "What is the capital of Russia?": [
- "Moscow"
- ],
- "What is Earth's largest continent?": [
- "Asia"
- ],
- "What river runs through Baghdad?": [
- "Tigris"
- ],
- "What country has the most natural lakes?": [
- "Canada"
- ],
- "What is the only sea without any coasts?": [
- "Sargasso"
- ],
- "What is the oldest city in the world?": [
- "Damascus"
- ],
- "What is the largest country in South America?": [
- "Brazil"
- ],
- "What is the tallest mountain in the world?": [
- "Everest"
- ],
- "What is the fastest flowing river in the world?": [
- "Amazon"
- ]
- ],
- "Science": [
- "What is the force that allows satellites to orbit the Earth?": [
- "Gravity"
- ],
- "What is the chemical composition of water?": [
- "H2O"
- ],
- "In what type of matter are atoms most tightly packed?": [
- "Solid"
- ],
- "What planet has the most moons?": [
- "Jupiter"
- ],
- "What hormone does the pancreas produce?": [
- "Insulin"
- ],
- "Mycology is the study of what?": [
- "Fungi"
- ],
- "How many miles of blood vessels are there in the human body?": [
- "100,000",
- "100000"
- ],
- "What is the smallest biological unit of a living organism?": [
- "Cells"
- ],
- "What is the only letter of the alphabet that doesn't appear on the Periodic Table?": [
- "J"
- ],
- "What is the largest cell in the human body?": [
- "Ovum"
- ],
- "Which planet has the tallest mountain?": [
- "Mars"
- ],
- "What is the standard unit of kinetic energy?": [
- "Joule"
- ]
- ],
- "Math": [
- "What does 3 + 3 equal to?": [
- "6"
- ],
- "What are the first 5 numbers of Pi?": [
- "3.1415",
- "3.1416" // 9 comes after 5 and some people round it
- ],
- "What is 9 + 10 equal to?": [
- "19"
- ],
- "What is 8 * 7 equal to?": [
- "56"
- ],
- "What is 10 * 0 equal to?": [
- "0"
- ],
- "What is 6 / 3 equal to?": [
- "2"
- ]
- ],
- "General Knowledge": [
- "Who is the current owner of GotPvP?": [
- "Serayne",
- "Chris"
- ],
- "Who is the current developer of GotPvP?": [
- "LST",
- "Shoot"
- ],
- "Who is the biggest E-Girl on GotPvP?": [
- "Grace"
- ],
- "Who is the weeb on GotPvP?": [
- "Stalin"
- ],
- "In total, how many gamemodes are on GotPvP?": [
- "6"
- ],
- "What is the color of the Moderator tag on GotPvP?": [
- "Blue"
- ],
- "Who is Serayne's Wife?": [
- "Koalas"
- ],
- "Who is IKoalas' Husband?": [
- "Chris",
- "Serayne"
- ],
- "How many letters are in the name GotPvP?": [
- "6"
- ],
- "Who is the current manager of GotPvP?": [
- "Jelly",
- "James"
- ]
- ]
- ]
- @Field private final List<Map.Entry<String, List<Map.Entry<String, List<String>>>>> questions = new ArrayList<>()
- for (Map.Entry<String, Object> entry : this.config.entrySet()) {
- this.questions.add(Pair.of(entry.getKey(), new ArrayList<>((entry.getValue() as Map<String, List<String>>).entrySet())))
- }
- @Field private final long questionDelay = 1200 * 30
- @Field private synchronized List<String> answers = new ArrayList<>()
- @Field private BukkitTask task = Bukkit.getScheduler().runTaskTimer(ArkGroovy.plugin, {
- startTrivia(this.answers)
- }, this.questionDelay, this.questionDelay)
- def unload() {
- this.task.cancel()
- }
- Commands.create().assertPermission("trivia.commands.starttrivia").handler { command ->
- startTrivia(this.answers)
- }.register("starttrivia")
- void startTrivia(List<String> answers) {
- answers.clear()
- Random random = new Random()
- Map.Entry<String, List<Map.Entry<String, List<String>>>> section = this.questions.get(random.nextInt(this.questions.size()))
- List<Map.Entry<String, List<String>>> questionsEntries = section.getValue()
- Map.Entry<String, List<String>> question = questionsEntries.get(random.nextInt(questionsEntries.size()))
- answers.addAll(question.getValue())
- Bukkit.broadcastMessage("\n§d§l" + section.getKey().toUpperCase() + " >> §fA new chat game has started!")
- Bukkit.broadcastMessage("§fQ: §e" + question.getKey() + "\n ")
- }
- Events.subscribe(AsyncPlayerChatEvent.class, EventPriority.LOWEST).handler { event ->
- if (this.answers.isEmpty()) {
- return
- }
- String message = event.getMessage().toLowerCase()
- boolean answered = false
- for (String answer : this.answers) {
- if (message.contains(answer.toLowerCase())) {
- answered = true
- break
- }
- }
- if (!answered) {
- return
- }
- event.setCancelled(true)
- this.answers.clear()
- Player player = event.getPlayer()
- UUID uuid = player.getUniqueId()
- Bukkit.broadcastMessage("\n§d§lTrivia >> §b" + player.getName() + " §fhas correctly answered the question!\n ")
- this.database.execute("INSERT INTO rt_triviasanswered (server_id, week, player_uuid_least, player_uuid_most, count) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE count = count + 1", { statement ->
- statement.setInt(1, this.databaseUtils.getDataId())
- statement.setInt(2, getCurrentWeek())
- statement.setLong(3, uuid.getLeastSignificantBits())
- statement.setLong(4, uuid.getMostSignificantBits())
- statement.setInt(5, 1)
- })
- }
- @Field private static final Map<ItemStack, int[]> MENU_DECORATIONS = [
- (ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 6, "§0", [])): [ 0, 2, 21, 23, 6, 8 ] as int[],
- (ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 2, "§0", [])): [ 18, 20, 3, 5, 24, 26 ] as int[],
- (ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 4, "§0", [])): [ 1, 9, 11, 19 ] as int[],
- (ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 7, "§0", [])): [ 4, 12, 14, 22 ] as int[],
- (ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 12, "§0", [])): [ 7, 15, 17, 25 ] as int[]
- ]
- @Field private static final MenuEvent MENU_EVENT = { p, t, s -> }
- Commands.create().assertPlayer().handler { command ->
- showTriviaTop(command.sender(), this.database, this.databaseUtils)
- }.register("trivia", "triviatop")
- Events.subscribe(InventoryCloseEvent.class).handler { event ->
- String name = event.getInventory().getName()
- if (name == "§bGlobal Trivia Top" || name == "§bWeekly Trivia Top" || name == "§b" + WordUtils.capitalizeFully(Exports.ptr("templeid").toString()) + " Trivia Top") {
- Bukkit.getScheduler().runTask(ArkGroovy.plugin, {
- showTriviaTop((Player) event.getPlayer(), this.database, this.databaseUtils)
- })
- }
- }
- private static void showTriviaTop(Player player, AsyncDatabase database, ModelDatautilSystem databaseUtils) {
- MenuBuilder builder = new MenuBuilder(27, "§bTrivia Top")
- for (Map.Entry<ItemStack, int[]> entry : MENU_DECORATIONS.entrySet()) {
- ItemStack item = entry.getKey()
- for (int slot : entry.getValue()) {
- builder.set(slot, item, MENU_EVENT)
- }
- }
- builder.set(10, ItemUtils.createItem(Material.WATCH, "§dGlobal Top", []), { p, t, s ->
- database.executeQuery("SELECT * FROM rt_triviasanswered", { statement -> }, { result ->
- Map<UUID, MutableInt> answered = new HashMap<>()
- while (result.next()) {
- UUID uuid = new UUID(result.getLong(4), result.getLong(3))
- answered.computeIfAbsent(uuid, { k -> new MutableInt(0) }).add(result.getInt(5))
- }
- List<Map.Entry<UUID, MutableInt>> answeredList = new ArrayList<>(answered.entrySet())
- answeredList.sort({ entry, entry1 -> return entry1.getValue().compareTo(entry.getValue())})
- MenuBuilder builder1 = new MenuBuilder(27, "§bGlobal Trivia Top")
- ItemStack whiteStainedPane = ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 0, "§0", [])
- for (int i = 0; i < 9; ++i) {
- builder1.set(i, whiteStainedPane, MENU_EVENT)
- }
- for (int i = 9; i < 18; ++i) {
- int index = i - 9
- if (index >= answeredList.size()) {
- break
- }
- Map.Entry<UUID, MutableInt> entry = answeredList.get(index)
- OfflinePlayer online = Bukkit.getPlayer(entry.getKey())
- if (online == null) {
- online = Bukkit.getOfflinePlayer(entry.getKey())
- }
- String name = online.getName()
- builder1.set(i, ItemUtils.createSkull(name, "§7" + (index + 1) + ". §a" + name, [ "", "§bCount§7: §d" + entry.getValue().intValue() ]), MENU_EVENT)
- }
- for (int i = 18; i < 27; ++i) {
- builder1.set(i, whiteStainedPane, MENU_EVENT)
- }
- Bukkit.getScheduler().runTask(ArkGroovy.plugin, {
- player.openInventory(builder1.get())
- })
- })
- })
- builder.set(13, ItemUtils.createItem(Material.COMPASS, "§dServer Top", []), { p, t, s ->
- database.executeQuery("SELECT * FROM rt_triviasanswered WHERE server_id = ?", { statement ->
- statement.setInt(1, databaseUtils.getDataId())
- }, { result ->
- Map<UUID, MutableInt> answered = new HashMap<>()
- while (result.next()) {
- UUID uuid = new UUID(result.getLong(4), result.getLong(3))
- answered.computeIfAbsent(uuid, { k -> new MutableInt(0) }).add(result.getInt(5))
- }
- List<Map.Entry<UUID, MutableInt>> answeredList = new ArrayList<>(answered.entrySet())
- answeredList.sort({ entry, entry1 -> return entry1.getValue().compareTo(entry.getValue())})
- MenuBuilder builder1 = new MenuBuilder(27, "§b" + WordUtils.capitalizeFully(Exports.ptr("templeid").toString()) + " Trivia Top")
- ItemStack whiteStainedPane = ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 0, "§0", [])
- for (int i = 0; i < 9; ++i) {
- builder1.set(i, whiteStainedPane, MENU_EVENT)
- }
- for (int i = 9; i < 18; ++i) {
- int index = i - 9
- if (index >= answeredList.size()) {
- break
- }
- Map.Entry<UUID, MutableInt> entry = answeredList.get(index)
- OfflinePlayer online = Bukkit.getPlayer(entry.getKey())
- if (online == null) {
- online = Bukkit.getOfflinePlayer(entry.getKey())
- }
- String name = online.getName()
- builder1.set(i, ItemUtils.createSkull(name, "§7" + (index + 1) + ". §a" + name, [ "", "§bCount§7: §d" + entry.getValue().intValue() ]), MENU_EVENT)
- }
- for (int i = 18; i < 27; ++i) {
- builder1.set(i, whiteStainedPane, MENU_EVENT)
- }
- Bukkit.getScheduler().runTask(ArkGroovy.plugin, {
- player.openInventory(builder1.get())
- })
- })
- })
- builder.set(16, ItemUtils.createItem(Material.BOOK, "§dWeekly Top", []), { p, t, s ->
- showWeeklyTop(database, player, getCurrentWeek())
- })
- player.openInventory(builder.get())
- }
- static void showWeeklyTop(AsyncDatabase database, Player player, int week) {
- database.executeQuery("SELECT * FROM rt_triviasanswered WHERE week = ?", { statement ->
- statement.setInt(1, week)
- }, { result ->
- Map<UUID, MutableInt> answered = new HashMap<>()
- while (result.next()) {
- UUID uuid = new UUID(result.getLong(4), result.getLong(3))
- answered.computeIfAbsent(uuid, { k -> new MutableInt(0) }).add(result.getInt(5))
- }
- List<Map.Entry<UUID, MutableInt>> answeredList = new ArrayList<>(answered.entrySet())
- answeredList.sort({ entry, entry1 -> return entry1.getValue().compareTo(entry.getValue())})
- MenuBuilder builder1 = new MenuBuilder(27, "§bWeekly Trivia Top")
- ItemStack whiteStainedPane = ItemUtils.createDamagedItem(Material.STAINED_GLASS_PANE, 0, "§0", [])
- for (int i = 0; i < 9; ++i) {
- builder1.set(i, whiteStainedPane, MENU_EVENT)
- }
- for (int i = 9; i < 18; ++i) {
- int index = i - 9
- if (index >= answeredList.size()) {
- break
- }
- Map.Entry<UUID, MutableInt> entry = answeredList.get(index)
- OfflinePlayer online = Bukkit.getPlayer(entry.getKey())
- if (online == null) {
- online = Bukkit.getOfflinePlayer(entry.getKey())
- }
- String name = online.getName()
- if (name == null) {
- continue
- }
- builder1.set(i, ItemUtils.createSkull(name, "§7" + (index + 1) + ". §a" + name, [ "", "§bCount§7: §d" + entry.getValue().intValue() ]), MENU_EVENT)
- }
- for (int i = 18; i < 27; ++i) {
- builder1.set(i, whiteStainedPane, MENU_EVENT)
- }
- Bukkit.getScheduler().runTask(ArkGroovy.plugin, {
- player.openInventory(builder1.get())
- })
- })
- }
- Commands.create().assertPermission("trivia.commands.currentweek").handler { command ->
- command.sender().sendMessage(getCurrentWeek().toString())
- }.register("currentweek")
- private static int getCurrentWeek() {
- LocalDate date = LocalDate.now()
- WeekFields weekFields = WeekFields.of(Locale.getDefault())
- return date.get(weekFields.weekOfWeekBasedYear())
- }
- Commands.create().assertPermission("trivia.command.clear").handler { command ->
- this.database.execute("DELETE FROM rt_triviasanswered", { statement -> })
- command.sender().sendMessage("§aCleared database!")
- }.register("cleartrivia")
- Commands.create().assertPlayer().assertPermission("trivia.command.previoustriviatop").handler { command ->
- showWeeklyTop(this.database, command.sender(), getCurrentWeek() - 1)
- }.register("previoustriviatop")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement