Minigame plugin-Kits

Discussion in 'Plugin Development' started by XFarwar, Aug 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    XFarwar

    Hi, I need help for my plugin. I've created this:
    Code:java
    1. package Kits;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandExecutor;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.inventory.PlayerInventory;
    11.  
    12. import Main.Main;
    13.  
    14. public class Kits implements CommandExecutor {
    15. Main plugin;
    16. public Kits (Main plugin){
    17. this.plugin = plugin;
    18. }
    19. @Override
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
    21. String[] args) {
    22. if(cmd.getName().equalsIgnoreCase("mkit")){
    23. Player p = (Player) sender;
    24. if(args.length == 0){
    25. p.sendMessage(ChatColor.GRAY + "Usa il comando " + ChatColor.GREEN + "/mkit <nomekit>");
    26. }else{
    27. if(args[0].equalsIgnoreCase("Soldato")){
    28. ItemStack dsword = (new ItemStack(Material.DIAMOND_SWORD));
    29. ItemStack ihelmet = (new ItemStack(Material.IRON_HELMET));
    30. ItemStack ichest = (new ItemStack(Material.IRON_CHESTPLATE));
    31. ItemStack ilegg = (new ItemStack(Material.IRON_LEGGINGS));
    32. ItemStack iboots = (new ItemStack(Material.IRON_BOOTS));
    33. PlayerInventory pi1 = p.getInventory();
    34. pi1.setHelmet(ihelmet);
    35. pi1.setChestplate(ichest);
    36. pi1.setLeggings(ilegg);
    37. pi1.setBoots(iboots);
    38. pi1.addItem(dsword);
    39. p.sendMessage(ChatColor.GRAY + "[" + ChatColor.AQUA + "Kits"
    40. + ChatColor.GRAY + "]" + ChatColor.WHITE + "Hai selezionato il kit Soldato!");
    41.  
    42. }if(args[0].equalsIgnoreCase("Arcere")){
    43. ItemStack wsword = (new ItemStack(Material.WOOD_SWORD));
    44. ItemStack ihelmet = (new ItemStack(Material.IRON_HELMET));
    45. ItemStack gchest = (new ItemStack(Material.GOLD_CHESTPLATE));
    46. ItemStack llegg = (new ItemStack(Material.LEATHER_LEGGINGS));
    47. ItemStack lboots = (new ItemStack(Material.LEATHER_BOOTS));
    48. PlayerInventory pi2 = p.getInventory();
    49. pi2.setHelmet(ihelmet);
    50. pi2.setChestplate(gchest);
    51. pi2.setLeggings(llegg);
    52. pi2.setBoots(lboots);
    53. pi2.addItem(wsword);
    54. pi2.addItem(new ItemStack(Material.BOW, 1));
    55. pi2.addItem(new ItemStack(Material.ARROW, 500));
    56. p.sendMessage(ChatColor.GRAY + "[" + ChatColor.AQUA + "Kits"
    57. + ChatColor.GRAY + "]" + ChatColor.WHITE + "Hai selezionato il kit Arciere!");
    58. }
    59. }
    60. }
    61. return false;
    62.  
    63. }
    64. }
    65.  


    But, I need help about clearing invetory and adding kit. If i take Soldato (warrior in english) Kit and I type /mkit Arciere (archer in english), I would that plugin DON'T give arciere kit if player has already the same Kit or other kits. (Sorry for my english D:)

    Any helps? I know that I can use HashMap, but I'm pretty whit Java Coding, and I'm studing it.
     
  2. Offline

    born2kill_

    Maybe have a HashMap store two values, the Player and a boolean to check if they have chose a kit or not.
    So create a new HashMap
    Code:
    ArrayList<Player,> kitList = new ArrayList<Player>();
    Then, when they choose a kit, make it check that if they are in the ArrayList
    Code:
    if(kitList.contains(player) {
    player.sendMessage("Sorry but you can't chose a kit!");
    return;
    }
    And then add an else statement, and if they aren't in the kitList let them chose a kit.

    If they chose a kit and they aren't in the ArrayList, make it add them to the arraylist, and then when they die or quit make it remove them from the ArrayList.
    Sorry if it was confusing, just pm me for help.
     
  3. Offline

    XFarwar

    I know that it's so simple, but, I really need a complete and simple, simple example about my code, if anyone would help my a will very glad :D
     
  4. Offline

    XFarwar

    up D:
     
  5. Offline

    LavaisWatery


    Just going to give you a tip since it seems you are new to programming in general. Since you're going to be making this for a server I would suggest using separate classes to organize your project. It not only saves time but it also saves space.
     
Thread Status:
Not open for further replies.

Share This Page