Skip to content

Commit

Permalink
Code: Update Code Behaviour (#11)
Browse files Browse the repository at this point in the history
Update the behaviour to avoid initializing two times the code from
AywenCraftPlugin.java and MOTDChanger.java
  • Loading branch information
ri1ongithub authored Jul 4, 2024
2 parents 3d49636 + 3dbb00a commit 89eb897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
10 changes: 1 addition & 9 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ public final class AywenCraftPlugin extends JavaPlugin {
public void onEnable() {
Bukkit.getServer().getLogger().info("Hello le monde, ici le plugin AywenCraft !");

// Initialiser et démarrer le MOTDChanger
motdChanger = new MOTDChanger();
motdChanger.onEnable();
motdChanger.startMOTDChanger(this);

// Enregistrer la commande /version
this.getCommand("version").setExecutor(new VersionCommand(this));
}

@Override
public void onDisable() {
// Arrêter proprement le MOTDChanger
if (motdChanger != null) {
motdChanger.onDisable();
}

// Plugin shutdown logic
}
}
27 changes: 8 additions & 19 deletions src/main/java/fr/communaywen/core/utils/MOTDChanger.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
package fr.communaywen.core.utils;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class MOTDChanger extends JavaPlugin {
public class MOTDChanger {

private final List<String> motdList = Arrays.asList(
"Premier MOTD",
"Second MOTD",
"Troisième MOTD",
"Quatrième MOTD",
"Cinquième MOTD"
"Bienvenue sur notre serveur !",
"Profitez de votre séjour !",
"Découvrez de nouvelles aventures !",
"Participez à nos événements spéciaux !",
"Amusez-vous bien sur notre serveur !"
);

@Override
public void onEnable() {
startMOTDChanger();
}

private void startMOTDChanger() {
public void startMOTDChanger(JavaPlugin plugin) {
AtomicInteger index = new AtomicInteger(0);

new BukkitRunnable() {
Expand All @@ -32,10 +25,6 @@ public void run() {
String nextMOTD = motdList.get(index.getAndIncrement() % motdList.size());
Bukkit.getServer().setMotd(nextMOTD);
}
}.runTaskTimer(this, 0L, 12000L); // 12000 ticks = 10 minutes
}

@Override
public void onDisable() {
}.runTaskTimer(plugin, 0L, 12000L); // 12000 ticks = 10 minutes
}
}

0 comments on commit 89eb897

Please sign in to comment.