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

Correction d'un bug relatif au calcul des ticks et avancement sur la classe Periodic Event.

parent 55c3959c
No related branches found
No related tags found
1 merge request!6Donner le joueur habitué aux joueurs.
Pipeline #48 passed
...@@ -51,7 +51,6 @@ public final class Main extends JavaPlugin implements Listener { ...@@ -51,7 +51,6 @@ public final class Main extends JavaPlugin implements Listener {
public PlayerDataHandler playerDataHandler; public PlayerDataHandler playerDataHandler;
public Wild wildCommand; public Wild wildCommand;
public PeriodicEvent periodicEvent; public PeriodicEvent periodicEvent;
public final static int ticksPerSeconds = 20;
@Override @Override
public void onEnable() { public void onEnable() {
...@@ -321,6 +320,9 @@ public final class Main extends JavaPlugin implements Listener { ...@@ -321,6 +320,9 @@ public final class Main extends JavaPlugin implements Listener {
} }
// 1.6.1 // 1.6.1
config.options().copyDefaults(true);
saveConfig();
reloadConfig();
} }
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") * plugin.ticksPerSeconds; int delayInTicks = plugin.getConfig().getInt("wild.move-cooldown") * plugin.getConfig().getInt("ticks-per-seconds");
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
......
package com.slprojects.slcraftplugin.parallelTasks; package com.slprojects.slcraftplugin.parallelTasks;
import com.slprojects.slcraftplugin.Main; import com.slprojects.slcraftplugin.Main;
import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class PeriodicEvent { public class PeriodicEvent {
private final Main plugin; private final Main plugin;
private boolean doesTheEventHasBeenCalled = false; private boolean doesTheEventIsCurrentlyRunning = false;
private final int periodicEventCallTime; private final int periodicEventCallTime;
public PeriodicEvent(Main plugin){ public PeriodicEvent(Main plugin){
this.plugin = plugin; this.plugin = plugin;
startPeriodicEvent(); startPeriodicEvent();
periodicEventCallTime = plugin.getConfig().getInt("periodicEventCallTime"); periodicEventCallTime = plugin.getConfig().getInt("periodic-event-call-time") * plugin.getConfig().getInt("ticks-per-seconds");
} }
public void startPeriodicEvent(){ public void startPeriodicEvent(){
if(doesTheEventHasBeenCalled) throw new RuntimeException("L'exécution de l'évènement périodique est déjà enclanchée."); if(doesTheEventIsCurrentlyRunning) throw new RuntimeException("L'exécution de l'évènement périodique est déjà enclanchée.");
doesTheEventIsCurrentlyRunning = true;
doesTheEventHasBeenCalled = true;
new BukkitRunnable(){ new BukkitRunnable(){
@Override @Override
public void run(){ public void run(){
periodicEvent(); periodicEvent();
} }
}.runTaskLater(plugin, (long) periodicEventCallTime * Main.ticksPerSeconds); }.runTaskLater(plugin, (periodicEventCallTime));
} }
private void periodicEvent(){ private void periodicEvent(){
plugin.getServer().getConsoleSender().sendMessage(ChatColor.GOLD+"[SL-Craft] Évènement périodique éxecuté.");
// S'exécute à la fin // S'exécute à la fin
doesTheEventIsCurrentlyRunning = false;
startPeriodicEvent(); startPeriodicEvent();
} }
} }
...@@ -39,3 +39,7 @@ discordBot-api-url: "http://node.sl-projects.com:27001/" ...@@ -39,3 +39,7 @@ discordBot-api-url: "http://node.sl-projects.com:27001/"
# Config générale # Config générale
server-type: prod # prod/dev server-type: prod # prod/dev
# Periodic events
periodic-event-call-time: 60 # En sencondes
ticks-per-seconds: 20
\ No newline at end of file
...@@ -24,6 +24,3 @@ commands: ...@@ -24,6 +24,3 @@ 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