Bonjour, bonsoir, j'aurai ici un problème de plugin, en effet, le projet est de faire une boss bar qui s'actualise a chaque fois qu'une commande est éxécutée, or, quand j'éxécute la commande, rien ne se passe. Voici le fichier main :
Voici le fichier de la commande :
package fr.zpazod.speedrunpluginre;
import java.io.File;
import java.io.IOException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Bukkit;
public final class main extends JavaPlugin {
private File pointsFile;
private FileConfiguration pointsConfig;
public PointsBossBar pointsBossBar;
@Override
public void onEnable() {
// Plugin startup logic
getLogger().info("SpeedrunPlugin has been enabled.");
PointsTab pointsTab = new PointsTab(this);
getServer().getPluginManager().registerEvents(pointsTab, this);
pointsBossBar = new PointsBossBar(this);
getServer().getPluginManager().registerEvents(pointsBossBar, this);
PointsCommand pointsCommand = new PointsCommand(this);
getCommand("points").setExecutor(pointsCommand);
VanishCommand vanishCommand = new VanishCommand();
getCommand("vanish").setExecutor(new VanishCommand());
if (!Bukkit.getServer().getPluginManager().getPlugin("SpeedrunPluginRe").getDataFolder().exists()) {
Bukkit.getServer().getPluginManager().getPlugin("SpeedrunPluginRe").getDataFolder().mkdir();
}
pointsFile = new File(Bukkit.getServer().getPluginManager().getPlugin("SpeedrunPluginRe").getDataFolder(), "points.yml");
if (!pointsFile.exists()) {
try {
pointsFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
pointsConfig = YamlConfiguration.loadConfiguration(pointsFile);
}
@Override
public void onDisable() {
// Plugin shutdown logic
getLogger().info("SpeedrunPlugin has been disabled.");
}
}
Voici le fichier de la commande :
Et voici le fichier gérant la boss bar :package fr.zpazod.speedrunpluginre;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
public class PointsCommand implements CommandExecutor {
private main plugin;
private File pointsFile;
private FileConfiguration pointsConfig;
public PointsCommand(main plugin) {
this.plugin = plugin;
pointsFile = new File(Bukkit.getServer().getPluginManager().getPlugin("SpeedrunPluginRe").getDataFolder(), "points.yml");
pointsConfig = YamlConfiguration.loadConfiguration(pointsFile);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
Player player = (Player) sender;
if (!player.hasPermission("points.give")) {
player.sendMessage("You do not have permission to use this command.");
return true;
}
if (args.length != 3) {
player.sendMessage("Usage: /points give <player> <points>");
return true;
}
Player targetPlayer = Bukkit.getPlayer(args[1]);
if (targetPlayer == null) {
player.sendMessage("Player not found.");
return true;
}
int points;
try {
points = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
player.sendMessage("Invalid number of points.");
return true;
}
if (points < 0) {
player.sendMessage("Points must be a positive number.");
return true;
}
int newPoints = pointsConfig.getInt(targetPlayer.getName()) + points;
pointsConfig.set(targetPlayer.getName(), newPoints);
try {
pointsConfig.save(pointsFile);
} catch (IOException e) {
e.printStackTrace();
}
plugin.pointsBossBar.updateBossBar();
targetPlayer.setPlayerListName(targetPlayer.getName() + " - " + newPoints + " points");
player.sendMessage("You have given " + targetPlayer.getName() + " " + points + " points.");
return true;
}
}
En éspérant trouver de l'aidepackage fr.zpazod.speedrunpluginre;
import org.bukkit.Bukkit;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import java.io.File;
public class PointsBossBar implements Listener {
private File pointsFile;
private FileConfiguration pointsConfig;
private BossBar bossBar;
public PointsBossBar(Plugin plugin) {
pointsFile = new File(plugin.getDataFolder(), "points.yml");
pointsConfig = YamlConfiguration.loadConfiguration(pointsFile);
bossBar = Bukkit.createBossBar("", BarColor.GREEN, BarStyle.SEGMENTED_10);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
updateBossBar();
bossBar.addPlayer(player);
}
public void updateBossBar() {
String topPlayerName = "";
int topPlayerPoints = 0;
for (String playerName : pointsConfig.getKeys(false)) {
int playerPoints = pointsConfig.getInt(playerName);
if (playerPoints > topPlayerPoints) {
topPlayerName = playerName;
topPlayerPoints = playerPoints;
}
}
bossBar.setTitle(topPlayerName + " - " + topPlayerPoints + " points");
double progress = topPlayerPoints / 100.0;
bossBar.setProgress(progress);
}
}