Bonjour je suis en train de créer un plugin avec des royaumes mais il y a une erreur pour un menu et apparemment, cela vient du code du la commande.
Voici le code:
Classe principale (Main):
package fr.stylebleu.terraiaplug;
import org.bukkit.plugin.java.JavaPlugin;
import fr.stylebleu.terraiaplug.commands.CommandKingdom;
import fr.stylebleu.terraiaplug.commands.CommandSpawn;
import fr.stylebleu.terraiaplug.commands.CommandTest;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
System.out.println("The plugin TerraiaPlug is now ENABLED!");
getCommand("test").setExecutor(new CommandTest());
getCommand("bc").setExecutor(new CommandTest());
getCommand("spawn").setExecutor(new CommandSpawn());
getCommand("kingdom").setExecutor(new CommandKingdom());
getServer().getPluginManager().registerEvents(new TerraiaPlugListeners(), this);
}
@Override
public void onDisable() {
System.out.println("The plugin TerraiaPlug is now DISABLED!");
}
}
Classe de la commande (CommandKingdom):
package fr.stylebleu.terraiaplug.commands;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class CommandKingdom implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args ) {
if(sender instanceof Player){
Player player = (Player)sender;
if(cmd.getName().equalsIgnoreCase("kingdom")){
KingdomData kingdom1 = new KingdomData("A");
Inventory menukingdom = Bukkit.createInventory(null, 54, "§6[§eMenu Royaume§6]" + kingdom1.getnameKingdom());
ItemStack ndroy = new ItemStack(Material.OAK_SIGN, 1);
ItemMeta ndroyM = ndroy.getItemMeta();
ndroyM.setDisplayName("§6Nom du Royaume :§e§l" + kingdom1.getnameKingdom());
ndroy.setItemMeta(ndroyM);
menukingdom.setItem(5, ndroy);
player.openInventory(menukingdom);
}
}
return false;
}
}
Données des royaumes (DataKingdom):
package fr.stylebleu.terraiaplug.commands;
import org.bukkit.entity.Player;
public class KingdomData {
private String nameKingdom;
KingdomData kingdom1 = new KingdomData(nameKingdom);
public KingdomData(String nameKingdom) {
this.nameKingdom = nameKingdom;
}
public String getnameKingdom() {
return nameKingdom;
}
public void setnameKingdom(String name) {
this.nameKingdom = name;
}
}
Voici le code:
Classe principale (Main):
package fr.stylebleu.terraiaplug;
import org.bukkit.plugin.java.JavaPlugin;
import fr.stylebleu.terraiaplug.commands.CommandKingdom;
import fr.stylebleu.terraiaplug.commands.CommandSpawn;
import fr.stylebleu.terraiaplug.commands.CommandTest;
public class Main extends JavaPlugin {
@Override
public void onEnable() {
System.out.println("The plugin TerraiaPlug is now ENABLED!");
getCommand("test").setExecutor(new CommandTest());
getCommand("bc").setExecutor(new CommandTest());
getCommand("spawn").setExecutor(new CommandSpawn());
getCommand("kingdom").setExecutor(new CommandKingdom());
getServer().getPluginManager().registerEvents(new TerraiaPlugListeners(), this);
}
@Override
public void onDisable() {
System.out.println("The plugin TerraiaPlug is now DISABLED!");
}
}
Classe de la commande (CommandKingdom):
package fr.stylebleu.terraiaplug.commands;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class CommandKingdom implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args ) {
if(sender instanceof Player){
Player player = (Player)sender;
if(cmd.getName().equalsIgnoreCase("kingdom")){
KingdomData kingdom1 = new KingdomData("A");
Inventory menukingdom = Bukkit.createInventory(null, 54, "§6[§eMenu Royaume§6]" + kingdom1.getnameKingdom());
ItemStack ndroy = new ItemStack(Material.OAK_SIGN, 1);
ItemMeta ndroyM = ndroy.getItemMeta();
ndroyM.setDisplayName("§6Nom du Royaume :§e§l" + kingdom1.getnameKingdom());
ndroy.setItemMeta(ndroyM);
menukingdom.setItem(5, ndroy);
player.openInventory(menukingdom);
}
}
return false;
}
}
Données des royaumes (DataKingdom):
package fr.stylebleu.terraiaplug.commands;
import org.bukkit.entity.Player;
public class KingdomData {
private String nameKingdom;
KingdomData kingdom1 = new KingdomData(nameKingdom);
public KingdomData(String nameKingdom) {
this.nameKingdom = nameKingdom;
}
public String getnameKingdom() {
return nameKingdom;
}
public void setnameKingdom(String name) {
this.nameKingdom = name;
}
}