Skip to content
Snippets Groups Projects
Commit 1a1bf044 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Refacto et classe périodique ajoutée.

parent dc1e1c93
No related branches found
No related tags found
1 merge request!6Donner le joueur habitué aux joueurs.
Pipeline #44 failed
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>com.slprojects</groupId> <groupId>com.slprojects</groupId>
<artifactId>SLCraftPlugin</artifactId> <artifactId>SLCraftPlugin</artifactId>
<version>1.6.0</version> <version>1.6.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SLCraftPlugin</name> <name>SLCraftPlugin</name>
......
...@@ -3,8 +3,9 @@ package com.slprojects.slcraftplugin; ...@@ -3,8 +3,9 @@ package com.slprojects.slcraftplugin;
import com.slprojects.slcraftplugin.commands.admins.WildReset; import com.slprojects.slcraftplugin.commands.admins.WildReset;
import com.slprojects.slcraftplugin.commands.publics.LinkCode; import com.slprojects.slcraftplugin.commands.publics.LinkCode;
import com.slprojects.slcraftplugin.commands.publics.Wild; import com.slprojects.slcraftplugin.commands.publics.Wild;
import com.slprojects.slcraftplugin.parallelTasks.PlayerDataHandler;
import com.slprojects.slcraftplugin.parallelTasks.InternalWebServer; import com.slprojects.slcraftplugin.parallelTasks.InternalWebServer;
import com.slprojects.slcraftplugin.parallelTasks.PeriodicEvent;
import com.slprojects.slcraftplugin.parallelTasks.PlayerDataHandler;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
import net.luckperms.api.cacheddata.CachedMetaData; import net.luckperms.api.cacheddata.CachedMetaData;
...@@ -38,19 +39,20 @@ import java.sql.SQLException; ...@@ -38,19 +39,20 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public final class Main extends JavaPlugin implements Listener { public final class Main extends JavaPlugin implements Listener {
// Variables // Variables
private List<UUID> wildCommandActiveUsers;
private static FileConfiguration config; private static FileConfiguration config;
private static LuckPerms luckPermsApi; private static LuckPerms luckPermsApi;
// Publiques car on les appelle ailleurs
public PlayerDataHandler playerDataHandler; public PlayerDataHandler playerDataHandler;
public Wild wildCommand; public Wild wildCommand;
public PeriodicEvent periodicEvent;
public final static int ticksPerSeconds = 20;
// Fonctions appelées à des évènements clés
@Override @Override
public void onEnable() { public void onEnable() {
// On s'assure qu'on a placeholder api // On s'assure qu'on a placeholder api
...@@ -84,11 +86,14 @@ public final class Main extends JavaPlugin implements Listener { ...@@ -84,11 +86,14 @@ public final class Main extends JavaPlugin implements Listener {
reloadConfig(); reloadConfig();
config = getConfig(); config = getConfig();
updateConfig(); updateConfig();
playerDataHandler = new PlayerDataHandler(this);
// On initialise la base de donnée
initDatabase(); initDatabase();
playerDataHandler = new PlayerDataHandler(this);
InternalWebServer.startServer(this);
periodicEvent = new PeriodicEvent(this);
// On initialise les commandes
wildCommand = new Wild(this); wildCommand = new Wild(this);
getCommand("wild").setExecutor(wildCommand); getCommand("wild").setExecutor(wildCommand);
...@@ -98,8 +103,6 @@ public final class Main extends JavaPlugin implements Listener { ...@@ -98,8 +103,6 @@ public final class Main extends JavaPlugin implements Listener {
LinkCode linkCodeCommand = new LinkCode(this); LinkCode linkCodeCommand = new LinkCode(this);
getCommand("getLinkCode").setExecutor(linkCodeCommand); getCommand("getLinkCode").setExecutor(linkCodeCommand);
InternalWebServer.startServer(this);
getServer().getConsoleSender().sendMessage(ChatColor.GREEN+"SL-Craft | Plugin démarré"); getServer().getConsoleSender().sendMessage(ChatColor.GREEN+"SL-Craft | Plugin démarré");
} }
...@@ -142,7 +145,7 @@ public final class Main extends JavaPlugin implements Listener { ...@@ -142,7 +145,7 @@ public final class Main extends JavaPlugin implements Listener {
} }
// On renvoie chaque message des joueurs sur le canal de chat du serveur discord // On renvoie chaque message des joueurs sur le canal de chat du serveur discord
@SuppressWarnings({"unchecked", "deprecation"}) @SuppressWarnings({"deprecation"})
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
void AsyncChatEvent(AsyncPlayerChatEvent e) { void AsyncChatEvent(AsyncPlayerChatEvent e) {
String playerFormattedMessage = e.getMessage(); String playerFormattedMessage = e.getMessage();
...@@ -316,6 +319,8 @@ public final class Main extends JavaPlugin implements Listener { ...@@ -316,6 +319,8 @@ public final class Main extends JavaPlugin implements Listener {
saveConfig(); saveConfig();
reloadConfig(); reloadConfig();
} }
// 1.6.1
} }
private void initDatabase(){ private void initDatabase(){
......
...@@ -76,7 +76,7 @@ public class Wild implements CommandExecutor { ...@@ -76,7 +76,7 @@ public class Wild implements CommandExecutor {
int playerIndex = wildUsersIndexes.indexOf(player.getUniqueId()); int playerIndex = wildUsersIndexes.indexOf(player.getUniqueId());
plugin.getServer().getConsoleSender().sendMessage("["+ plugin.getName() +"] Le joueur "+ChatColor.GOLD+player.getName()+ChatColor.RESET+" a exécuté la commande "+ChatColor.GOLD+"/wild"+ChatColor.RESET+" : "+ChatColor.GREEN+"accepté"); plugin.getServer().getConsoleSender().sendMessage("["+ plugin.getName() +"] Le joueur "+ChatColor.GOLD+player.getName()+ChatColor.RESET+" a exécuté la commande "+ChatColor.GOLD+"/wild"+ChatColor.RESET+" : "+ChatColor.GREEN+"accepté");
player.sendMessage("Vous allez être téléporté dans §c" + plugin.getConfig().getInt("wild.move-cooldown") + "s§r, ne bougez pas."); player.sendMessage("Vous allez être téléporté dans §c" + plugin.getConfig().getInt("wild.move-cooldown") + "s§r, ne bougez pas.");
int delayInTicks = plugin.getConfig().getInt("wild.move-cooldown") * 20; int delayInTicks = plugin.getConfig().getInt("wild.move-cooldown") * plugin.ticksPerSeconds;
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
......
package com.slprojects.slcraftplugin.parallelTasks;
import com.slprojects.slcraftplugin.Main;
import org.bukkit.scheduler.BukkitRunnable;
public class PeriodicEvent {
private final Main plugin;
private boolean doesTheEventHasBeenCalled = false;
private final int periodicEventCallTime;
public PeriodicEvent(Main plugin){
this.plugin = plugin;
startPeriodicEvent();
periodicEventCallTime = plugin.getConfig().getInt("periodicEventCallTime");
}
public void startPeriodicEvent(){
if(doesTheEventHasBeenCalled) throw new RuntimeException("L'exécution de l'évènement périodique est déjà enclanchée.");
doesTheEventHasBeenCalled = true;
new BukkitRunnable(){
@Override
public void run(){
periodicEvent();
}
}.runTaskLater(plugin, (long) periodicEventCallTime * Main.ticksPerSeconds);
}
private void periodicEvent(){
// S'exécute à la fin
startPeriodicEvent();
}
}
package com.slprojects.slcraftplugin.parallelTasks;
public class PeriodicPlayerEvent {
}
...@@ -24,3 +24,6 @@ commands: ...@@ -24,3 +24,6 @@ commands:
aliases: [ getlinkcode ] aliases: [ getlinkcode ]
usage: /getlinkcode usage: /getlinkcode
permission: slcraft.getlinkcode permission: slcraft.getlinkcode
periodicEventCallTime: 60 # En sencondes
ticks-per-seconds: 20
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment