-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
21 changed files
with
593 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package fr.communaywen.core; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.event.player.AsyncPlayerChatEvent; | ||
import org.jetbrains.annotations.Debug; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.*; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class QuizManager { | ||
public Quiz currentQuiz; | ||
private ScheduledExecutorService timeoutExecutor; | ||
private ScheduledExecutorService executor; | ||
private List<Quiz> quizzes; | ||
public FileConfiguration config; | ||
private AywenCraftPlugin plugin; | ||
|
||
public QuizManager(AywenCraftPlugin plugin, FileConfiguration config) { | ||
this.plugin = plugin; | ||
this.config = config; | ||
this.quizzes = new ArrayList<>(); | ||
|
||
for (LinkedHashMap i : (List<LinkedHashMap>) config.getList("quizzes")) { | ||
this.quizzes.add( | ||
new Quiz((String) i.get("question"), (String) i.get("answer")) | ||
); | ||
}; | ||
|
||
Runnable runnable = () -> { | ||
if (Bukkit.getOnlinePlayers().size() < 1) return; | ||
|
||
this.timeoutExecutor = Executors.newScheduledThreadPool(1); | ||
|
||
int index = new Random().nextInt(this.quizzes.size()); | ||
|
||
currentQuiz = this.quizzes.get(index); | ||
Bukkit.broadcastMessage( | ||
"Nouvelle question : " + currentQuiz.question + "\n" + | ||
"Vous avez 30 seconds pour répondre" + "\n" + | ||
"Le premier a répondre gagne !" | ||
); | ||
|
||
Runnable tellAnswer = () -> { | ||
Bukkit.broadcastMessage("Personne n'as trouvée la réponse au quizz après 30 secondes"); | ||
Bukkit.broadcastMessage("La réponse était : " + currentQuiz.answer); | ||
currentQuiz = null; | ||
}; | ||
|
||
this.timeoutExecutor.schedule(tellAnswer, 30, TimeUnit.SECONDS); | ||
}; | ||
|
||
executor = Executors.newScheduledThreadPool(1); | ||
executor.scheduleAtFixedRate(runnable, 1, config.getInt("interval"), TimeUnit.MINUTES); | ||
} | ||
|
||
public void onPlayerChat(AsyncPlayerChatEvent event) { | ||
int money = new Random().nextInt(config.getInt("rewards.money.min"), config.getInt("rewards.money.max") - 1); | ||
|
||
if (currentQuiz == null) return; | ||
|
||
if (event.getMessage().toLowerCase().equals(currentQuiz.answer)) { | ||
String message = MessageFormat.format("{0} a trouvé la réponse en premier, il remporte {1} de monnaie", event.getPlayer().getDisplayName(), money); | ||
Bukkit.broadcastMessage(message); | ||
this.plugin.economyManager.addBalance(event.getPlayer(), money); | ||
currentQuiz = null; | ||
this.timeoutExecutor.shutdownNow(); | ||
this.timeoutExecutor = Executors.newScheduledThreadPool(1); | ||
} | ||
} | ||
|
||
public void close() { | ||
executor.shutdownNow(); | ||
} | ||
|
||
public class Quiz { | ||
public String question; | ||
public String answer; | ||
|
||
public Quiz(String question, String answer) { | ||
this.question = question; | ||
this.answer = answer.toLowerCase(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 10 additions & 20 deletions
30
src/main/java/fr/communaywen/core/commands/RulesCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,40 @@ | ||
package fr.communaywen.core.commands; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.BookMeta; | ||
import revxrsal.commands.annotation.Command; | ||
import revxrsal.commands.annotation.Description; | ||
import revxrsal.commands.bukkit.annotation.CommandPermission; | ||
|
||
import java.util.List; | ||
|
||
|
||
public class RulesCommand implements CommandExecutor { | ||
public class RulesCommand { | ||
|
||
private final FileConfiguration bookConfig; | ||
|
||
public RulesCommand(FileConfiguration bookConfig) { | ||
this.bookConfig = bookConfig; | ||
} | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (!(sender instanceof Player player)) { | ||
sender.sendMessage("Seul un joueur peut executer cette commande !"); | ||
return false; | ||
} | ||
|
||
@Command({"rules", "regles", "reglement"}) | ||
@Description("Affiche le règlement du serveur") | ||
@CommandPermission("ayw.command.rules") | ||
public void onCommand(Player player) { | ||
ItemStack book = new ItemStack(Material.WRITTEN_BOOK); | ||
BookMeta meta = (BookMeta) book.getItemMeta(); | ||
|
||
meta.setTitle(bookConfig.getString("title")); | ||
meta.setAuthor(bookConfig.getString("author")); | ||
|
||
List<String> pages = bookConfig.getStringList("pages"); | ||
|
||
for (int i = 0; i < pages.size(); i++) { | ||
pages.set(i, pages.get(i).replace("\\n", "\n")); | ||
} | ||
|
||
meta.setPages(pages); | ||
|
||
book.setItemMeta(meta); | ||
|
||
((Player) sender).openBook(book); | ||
|
||
return true; | ||
player.openBook(book); | ||
} | ||
|
||
} |
Oops, something went wrong.