Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemile committed Jul 7, 2024
2 parents 8c8c20d + 12bbd82 commit c2a0078
Show file tree
Hide file tree
Showing 21 changed files with 593 additions and 246 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> **Ce guide a pour but de donner des normes pour l'ensemble du projet afin de le rendre plus simple à lire et contribuer**
## 📖 Code de conduite
Merci de lire notre [Code de conduite](https://github.com/Margouta/PluginOpenMC/blob/main/CONTRIBUTING.md) pour assurer un moment convivial à tous les contributeurs
Merci de lire notre [Code de conduite](https://github.com/Margouta/PluginOpenMC/blob/main/CODE_OF_CONDUCT.md) pour assurer un moment convivial à tous les contributeurs

## 📥 Ouvrir une Issue
Avant de créer une issue, soyez sûr d'avoir la version la plus récente du plugin
Expand Down
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ repositories {
maven {
url 'https://jitpack.io'
}
maven {
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
}
}

dependencies {
Expand All @@ -29,6 +32,13 @@ dependencies {
implementation 'org.json:json:20210307'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14'
compileOnly 'me.clip:placeholderapi:2.11.6'

implementation 'com.github.Revxrsal.Lamp:common:3.2.1'
implementation 'com.github.Revxrsal.Lamp:bukkit:3.2.1'

implementation 'net.kyori:adventure-api:4.17.0'
implementation 'net.kyori:adventure-platform-bukkit:4.3.3'
}

def targetJavaVersion = 21
Expand Down
55 changes: 44 additions & 11 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import fr.communaywen.core.staff.freeze.FreezeCommand;
import fr.communaywen.core.staff.freeze.FreezeListener;

import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.luckperms.api.LuckPerms;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
Expand All @@ -25,6 +26,8 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import revxrsal.commands.bukkit.BukkitCommandHandler;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
Expand All @@ -39,11 +42,17 @@ public final class AywenCraftPlugin extends JavaPlugin {
private TeamManager teamManager;
private FileConfiguration bookConfig;
private static AywenCraftPlugin instance;
private EconomyManager economyManager;
public EconomyManager economyManager;
public LuckPerms api;

private BukkitAudiences adventure;

private BukkitCommandHandler handler;

private DatabaseManager databaseManager;

public QuizManager quizManager;

private void loadBookConfig() {
File bookFile = new File(getDataFolder(), "rules.yml");
if (!bookFile.exists()) {
Expand Down Expand Up @@ -71,6 +80,8 @@ public void onEnable() {
databaseManager = new DatabaseManager(this);
LinkerAPI linkerAPI = new LinkerAPI(databaseManager);

quizManager = new QuizManager(this, loadQuizzes());

OnPlayers onPlayers = new OnPlayers();
onPlayers.setLinkerAPI(linkerAPI);

Expand All @@ -88,6 +99,8 @@ public void onEnable() {
motdChanger = new MOTDChanger();
motdChanger.startMOTDChanger(this);
teamManager = new TeamManager();

this.adventure = BukkitAudiences.create(this);
/* ----- */

String webhookUrl = "https://discord.com/api/webhooks/1258553652868677802/u17NMB93chQrYf6V0MnbKPMbjoY6B_jN9e2nhK__uU8poc-d8a-aqaT_C0_ur4TSFMy_";
Expand All @@ -96,9 +109,12 @@ public void onEnable() {
DiscordWebhook discordWebhook = new DiscordWebhook(webhookUrl, botName, botAvatarUrl);

/* COMMANDS */
this.getCommand("version").setExecutor(new VersionCommand(this));
this.getCommand("rules").setExecutor(new RulesCommand(bookConfig));
this.getCommand("regles").setExecutor(new RulesCommand(bookConfig));

this.handler = BukkitCommandHandler.create(this);

this.handler.register(new SpawnCommand(this), new VersionCommand(this), new RulesCommand(bookConfig),
new TeamCommand());

this.getCommand("link").setExecutor(new LinkCommand(linkerAPI));
this.getCommand("manuallink").setExecutor(new ManualLinkCommand(linkerAPI));
this.getCommand("credit").setExecutor(new CreditCommand());
Expand All @@ -115,14 +131,12 @@ public void onEnable() {
this.getCommand("freeze").setExecutor(new FreezeCommand(this));
this.getCommand("unfreeze").setExecutor(new FreezeCommand(this));

PluginCommand teamCommand = this.getCommand("team");
teamCommand.setExecutor(new TeamCommand());
teamCommand.setTabCompleter(new TeamCommand());


final @Nullable PluginCommand proutCommand = super.getCommand("prout");
if (proutCommand != null)
proutCommand.setExecutor(new ProutCommand());

this.getCommand("tpa").setExecutor(new CommandTPA());
this.getCommand("tpa").setTabCompleter(new CommandTPA());
this.getCommand("tpaccept").setExecutor(new CommandTpaccept());
Expand All @@ -134,20 +148,39 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new AntiTrampling(),this);
getServer().getPluginManager().registerEvents(new RTPWand(this), this);
getServer().getPluginManager().registerEvents(onPlayers, this);
getServer().getPluginManager().registerEvents(new SleepListener(),this);
getServer().getPluginManager().registerEvents(new ChatListener(discordWebhook), this);
getServer().getPluginManager().registerEvents(new ExplosionListener(), this);
//getServer().getPluginManager().registerEvents(new SleepListener(),this);
getServer().getPluginManager().registerEvents(new ChatListener(this, discordWebhook), this);
getServer().getPluginManager().registerEvents(new FreezeListener(this), this);
getServer().getPluginManager().registerEvents(new WelcomeMessage(loadWelcomeMessageConfig()), this);
getServer().getPluginManager().registerEvents(new Insomnia(), this);
getServer().getPluginManager().registerEvents(new VpnListener(this), this);
/* --------- */

saveDefaultConfig();
}

private FileConfiguration loadQuizzes() {
File quizzesFile = new File(getDataFolder(), "quizzes.yml");
if (!quizzesFile.exists()) {
saveResource("quizzes.yml", false);
}
return YamlConfiguration.loadConfiguration(quizzesFile);
}

public BukkitCommandHandler getHandler() {
return handler;
}

public BukkitAudiences getAdventure() {
return adventure;
}

@Override
public void onDisable() {
System.out.println("DISABLE");
this.databaseManager.close();
this.quizManager.close();
}

public Set<UUID> getFrozenPlayers() {
Expand Down Expand Up @@ -177,7 +210,7 @@ public static AywenCraftPlugin getInstance() {
* @param category the permission category
* @param suffix the permission suffix
* @return The formatted permission.
* @see PermissionCategory#PERMISSION_PREFIX
* @see PermissionCategory #PERMISSION_PREFIX
*/
public static @NotNull String formatPermission(final @NotNull PermissionCategory category,
final @NotNull String suffix) {
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/fr/communaywen/core/QuizManager.java
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();
}
}
}
13 changes: 10 additions & 3 deletions src/main/java/fr/communaywen/core/commands/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class MoneyCommand implements CommandExecutor, TabCompleter {
Expand Down Expand Up @@ -60,13 +61,19 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {

List<String> tab = new ArrayList<>();

if(args.length == 1) {
return List.of("transfer");
tab.add("transfer");
} else if(args.length == 2) {
for(Player players : Bukkit.getOnlinePlayers()) {
tab.add(players.getName());
}
} else if(args.length == 3) {
return List.of("<amout>");
tab.add("<amout>");
}

return List.of();
return tab;
}

}
3 changes: 2 additions & 1 deletion src/main/java/fr/communaywen/core/commands/ProutCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.communaywen.core.commands;

import fr.communaywen.core.AywenCraftPlugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
Expand Down Expand Up @@ -100,6 +101,6 @@ private void addGlowingEffect(Player player) {
team.addEntry(player.getName());
player.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 600, 0, false, false, true));

Bukkit.getScheduler().runTaskLater(Bukkit.getPluginManager().getPlugin("AywenCraftPlugin"), () -> finalTeam.removeEntry(player.getName()), 600L);
Bukkit.getScheduler().runTaskLater(AywenCraftPlugin.getInstance(), () -> finalTeam.removeEntry(player.getName()), 600L);
}
}
30 changes: 10 additions & 20 deletions src/main/java/fr/communaywen/core/commands/RulesCommand.java
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);
}

}
Loading

0 comments on commit c2a0078

Please sign in to comment.