Implement SkillPoints in my own plugin.
Shilodabing opened this issue · 2 comments
Hello nathan,
So.. Im trying to do a system of grading. With a command , I can grade a book of a player and let to the author of the book win x skillpoints. The problem is , All works BUT the skillspoints are given to the player executing the command to grade the book, not to the author. Here the code of my plugin. Can you help me with this?
public boolean onCommand(CommandSender sender, Command cmd, final String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
world = p.getWorld();
if(cmd.getName().equalsIgnoreCase("calificar") && p.hasPermission("calificacion.calificar")) {
Mage m = main.api.getMage(p);
ItemStack is = p.getInventory().getItemInHand();
ItemStack mano = p.getInventory().getItemInMainHand();
if(args.length == 1){
if(args[0].length() == 1) {
if(mano != null && mano.getType() != Material.AIR){
if(mano.getType() == Material.WRITTEN_BOOK) {
String calificar = args[0];
switch(calificar) {
case "A":
ItemMeta catlm2 = is.getItemMeta();
catlm2.setLore(Arrays.asList(ChatColor.GREEN + "test"));
is.setItemMeta(catlm2);
m.addSkillPoints(15);
break;
case "B":
ItemMeta catlm3 = is.getItemMeta();
catlm3.setLore(Arrays.asList(ChatColor.PURPLE + "test"));
is.setItemMeta(catlm3);
m.addSkillPoints(10);
break;
case "C":
ItemMeta catlm4 = is.getItemMeta();
catlm4.setLore(Arrays.asList(ChatColor.YELLOW + "test"));
is.setItemMeta(catlm4);
m.addSkillPoints(5);
break;
case "D":
ItemMeta catlm5 = is.getItemMeta();
catlm5.setLore(Arrays.asList(ChatColor.RED + "test"));
is.setItemMeta(catlm5);
m.addSkillPoints(0);
break;
default:
p.sendMessage(ChatColor.RED + "Calificación Incorrecta!");
return true;
}
BookMeta bm = (BookMeta) is.getItemMeta();
String name = bm.getAuthor();
Player autor = Bukkit.getPlayer(name );
autor.getInventory().addItem(mano);
p.getInventory().remove(mano);
return true;
}
}
}
}
}
regards nathan.
Amakna
If I'm reading this correctly, I think you want to grab the author name first, get the Player for that, get the Mage for that player- and then give the skill points to that player.
Right now it's getting the Mage from the CommandSender, which will always be the player executing the command.
I think that should do it- if not, let me know!