Making multiple kits within the same plugin?

Discussion in 'Plugin Development' started by TCO_007, Jan 29, 2014.

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

    TCO_007

    Hi guys. Sorry i post so much haha. I just really want to learn and be confident with coding so I like to ask a lot of questions. Anyways, I have made 2 kits so far, pvp (which is just the normal) and trampler (basically stomper, just renamed). I want to be able to make it so its one kit per life but first I believe I have to combine both of those kits into the same plugin. Right now they are seperate plugins just names PvPKit and TramplerKit. Do you guys know how I can combine them and keep adding more kits into the same plugin in the future? Thanks!
    Code for PvPKit:
    Code:
    package me.TCOB055.PvPKit;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class PvPKit extends JavaPlugin{
     
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if (commandLabel.equalsIgnoreCase("pvp")){
            //this is the permission    V
            if (player.hasPermission("Kit.PVP")){
            player.sendMessage(ChatColor.AQUA + "You have received the kit...." + ChatColor.GOLD + "PVP");
            player.getInventory().clear();
            player.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
            player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
            //Leather tut V
            ItemStack chestplateBlack = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
            LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateBlack.getItemMeta();
            chestplatemeta.setColor(Color.BLACK);
            chestplateBlack.setItemMeta(chestplatemeta);
            //Leather tut ^
            player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
            player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
            for (int i = 0; i < 32; i++) {
                player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                }
            player.getInventory().setChestplate(chestplateBlack);
            //adding leather ^
            ItemStack bootsBlack = new ItemStack(Material.LEATHER_BOOTS, 1);
            LeatherArmorMeta bootsmeta = (LeatherArmorMeta) bootsBlack.getItemMeta();
            bootsmeta.setColor(Color.BLACK);
            bootsBlack.setItemMeta(bootsmeta);
            player.getInventory().setBoots(bootsBlack);
       
       
       
       
            } else {
                player.sendMessage(ChatColor.RED + "You cannot use this kit!");
            }
            return false;
        }
            return false;
    }
     
    }
    Code for Trampler:
    Code:
    package me.TCOB055.Trampler;
     
    import java.util.ArrayList;
    import java.util.List;
     
     
     
     
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Trampler extends JavaPlugin implements Listener {
     
            List<String> stomper = new ArrayList<String>();
     
            @Override
            public void onEnable() {
                    this.getServer().getPluginManager().registerEvents(this, this);
                    this.getLogger().info("Trampler has been enabled!");
            }
     
            @EventHandler
            public void onPlayerDamage(EntityDamageEvent e) {
                    if (e.getEntity() instanceof Player) {
                            Player p = (Player) e.getEntity();
                            if (stomper.contains(p.getName())) {
                                    e.setDamage((double) p.getFallDistance() / 8);
                                    if (p.getFallDistance() > 3) {
                                            List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
                                            for (Entity tmp : nearby)
                                                    if (tmp instanceof Player) {
                                                            ((Player) tmp).damage((double) p.getFallDistance() / 2);
                                                    }
                                    }
                            }
                    }
            }
     
            @Override
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                Player player = (Player) sender;
                    if (label.equalsIgnoreCase("Trampler") && args.length == 0) {
                        if (player.hasPermission("kit.Trampler")){
                            stomper.add(sender.getName());
                            sender.sendMessage(ChatColor.AQUA + "You have chosen the kit...." + ChatColor.GOLD + " Trampler!" + ChatColor.GREEN + " Jump on to someone from a high place to take the fall damage you would have received and give it to them!");
                            player.getInventory().clear();
                            ItemStack StoneSword1 = new ItemStack(Material.STONE_SWORD, 1);
                            StoneSword1.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                            player.getInventory().addItem(StoneSword1);
                            player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                                //Leather tut V
                            ItemStack chestplateAqua = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
                            LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateAqua.getItemMeta();
                            chestplatemeta.setColor(Color.AQUA);
                            chestplateAqua.setItemMeta(chestplatemeta);
                                //Leather tut ^
                            player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                         
                                for (int i = 0; i < 32; i++) {
                                    player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                                    }
                            player.getInventory().setChestplate(chestplateAqua);
                                //adding leather ^
                            ItemStack chainProt1 = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
                            chainProt1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                            player.getInventory().setBoots(chainProt1);
                     
                    } else {
                        player.sendMessage(ChatColor.RED + "You can't use this kit!");
                    }
                 
                 
                    return false;
     
            }
                    return false;
    }}
    Feel free to give some suggestions on how I can make them better too :D
     
  2. Offline

    The_Doctor_123

    Have them in the same class?
     
  3. Offline

    Blingdaddy1

    Just make a new command...

    add another if (cmd.getName().equalsIgnoreCase("cmd")) {
    to
    Code:java
    1. return false;
    2.  
    3. } //here so
    4. if (cmd.getName().equalsIgnoreCase("cmd")) {
    5. //do stuff
    6. return false;
     
  4. Offline

    TCO_007

    Well, it could be if it needs to be. The most organized way is what I would like it to be but Im used to dirty so that works too lol
    The_Doctor_123

    I dont know what you mean Blingdaddy1
    Sorry, im new to coding. I know what an if statement is but I have no idea where i would put it if you understand what I am saying. Like would I have it all in the same class?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  5. Offline

    Blingdaddy1

    Ok so
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. Player player = (Player) sender;
    4. if (label.equalsIgnoreCase("Trampler") && args.length == 0) {
    5. if (player.hasPermission("kit.Trampler")){
    6. stomper.add(sender.getName());
    7. sender.sendMessage(ChatColor.AQUA + "You have chosen the kit...." + ChatColor.GOLD + " Trampler!" + ChatColor.GREEN + " Jump on to someone from a high place to take the fall damage you would have received and give it to them!");
    8. player.getInventory().clear();
    9. ItemStack StoneSword1 = new ItemStack(Material.STONE_SWORD, 1);
    10. StoneSword1.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    11. player.getInventory().addItem(StoneSword1);
    12. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    13. //Leather tut V
    14. ItemStack chestplateAqua = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    15. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateAqua.getItemMeta();
    16. chestplatemeta.setColor(Color.AQUA);
    17. chestplateAqua.setItemMeta(chestplatemeta);
    18. //Leather tut ^
    19. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    20.  
    21. for (int i = 0; i < 32; i++) {
    22. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    23. }
    24. player.getInventory().setChestplate(chestplateAqua);
    25. //adding leather ^
    26. ItemStack chainProt1 = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
    27. chainProt1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    28. player.getInventory().setBoots(chainProt1);
    29.  
    30. } else {
    31. // end of old command //
    32. }
    33. player.sendMessage(ChatColor.RED + "You can't use this kit!");
    34. }
    35. // new command //
    36. if (cmd.getName().equalsIgnoreCase("NEWCOMMAND")) {
    37. //do stuff
    38. }
    39.  
    40.  
    41. return false;
    42.  
    43. }
    44. return false;
    45. return false;
    46. }
     
  6. Offline

    TCO_007

    So like this Blingdaddy1?
    Code:
    package me.TCOB055.main;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class main extends JavaPlugin implements Listener{
          public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                Player player = (Player) sender;
                if (commandLabel.equalsIgnoreCase("pvp")){
                //this is the permission    V
                if (player.hasPermission("Kit.PVP")){
                player.sendMessage(ChatColor.AQUA + "You have received the kit...." + ChatColor.GOLD + "PVP");
                player.getInventory().clear();
                player.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
                player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                //Leather tut V
                ItemStack chestplateBlack = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
                LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateBlack.getItemMeta();
                chestplatemeta.setColor(Color.BLACK);
                chestplateBlack.setItemMeta(chestplatemeta);
                //Leather tut ^
                player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
                for (int i = 0; i < 32; i++) {
                    player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                    }
                player.getInventory().setChestplate(chestplateBlack);
                //adding leather ^
                ItemStack bootsBlack = new ItemStack(Material.LEATHER_BOOTS, 1);
                LeatherArmorMeta bootsmeta = (LeatherArmorMeta) bootsBlack.getItemMeta();
                bootsmeta.setColor(Color.BLACK);
                bootsBlack.setItemMeta(bootsmeta);
                player.getInventory().setBoots(bootsBlack);
             
             
             
             
                } else {
                    player.sendMessage(ChatColor.RED + "You cannot use this kit!");
                }
                return false;
            }
                return false;
        }
         
          List<String> stomper = new ArrayList<String>();
         
          @Override
          public void onEnable() {
                  this.getServer().getPluginManager().registerEvents(this, this);
                  this.getLogger().info("Trampler has been enabled!");
          }
     
          @EventHandler
          public void onPlayerDamage(EntityDamageEvent e) {
                  if (e.getEntity() instanceof Player) {
                          Player p = (Player) e.getEntity();
                          if (stomper.contains(p.getName())) {
                                  e.setDamage((double) p.getFallDistance() / 8);
                                  if (p.getFallDistance() > 3) {
                                          List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
                                          for (Entity tmp : nearby)
                                                  if (tmp instanceof Player) {
                                                          ((Player) tmp).damage((double) p.getFallDistance() / 2);
                                                  }
                                  }
                          }
                  }
          }
     
          public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
              Player player = (Player) sender;
                  if (label.equalsIgnoreCase("Trampler") && args.length == 0) {
                      if (player.hasPermission("kit.Trampler")){
                          stomper.add(sender.getName());
                          sender.sendMessage(ChatColor.AQUA + "You have chosen the kit...." + ChatColor.GOLD + " Trampler!" + ChatColor.GREEN + " Jump on to someone from a high place to take the fall damage you would have received and give it to them!");
                          player.getInventory().clear();
                          ItemStack StoneSword1 = new ItemStack(Material.STONE_SWORD, 1);
                          StoneSword1.addEnchantment(Enchantment.DAMAGE_ALL, 1);
                          player.getInventory().addItem(StoneSword1);
                          player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                              //Leather tut V
                          ItemStack chestplateAqua = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
                          LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateAqua.getItemMeta();
                          chestplatemeta.setColor(Color.AQUA);
                          chestplateAqua.setItemMeta(chestplatemeta);
                              //Leather tut ^
                          player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                         
                              for (int i = 0; i < 32; i++) {
                                  player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
                                  }
                          player.getInventory().setChestplate(chestplateAqua);
                              //adding leather ^
                          ItemStack chainProt1 = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
                          chainProt1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
                          player.getInventory().setBoots(chainProt1);
                     
                  } else {
                      player.sendMessage(ChatColor.RED + "You can't use this kit!");
                  }
                 
                 
                  return false;
     
          }
                    return false;
    }
          }
    I entered in this code (combined Trampler and pvp) and it didnt work. Nothing happened for PvPKit and it said Trampler was an unknown command. Do you see what I did wrong?
    Code:java
    1. package me.TCOB055.main;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Color;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.enchantments.Enchantment;
    12. import org.bukkit.entity.Entity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.EntityDamageEvent;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.inventory.meta.LeatherArmorMeta;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21. public class main extends JavaPlugin implements Listener{
    22. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    23. Player player = (Player) sender;
    24. if (commandLabel.equalsIgnoreCase("pvp")){
    25. //this is the permission V
    26. if (player.hasPermission("Kit.PVP")){
    27. player.sendMessage(ChatColor.AQUA + "You have received the kit...." + ChatColor.GOLD + "PVP");
    28. player.getInventory().clear();
    29. player.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    30. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    31. //Leather tut V
    32. ItemStack chestplateBlack = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    33. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateBlack.getItemMeta();
    34. chestplatemeta.setColor(Color.BLACK);
    35. chestplateBlack.setItemMeta(chestplatemeta);
    36. //Leather tut ^
    37. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    38. player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    39. for (int i = 0; i < 32; i++) {
    40. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    41. }
    42. player.getInventory().setChestplate(chestplateBlack);
    43. //adding leather ^
    44. ItemStack bootsBlack = new ItemStack(Material.LEATHER_BOOTS, 1);
    45. LeatherArmorMeta bootsmeta = (LeatherArmorMeta) bootsBlack.getItemMeta();
    46. bootsmeta.setColor(Color.BLACK);
    47. bootsBlack.setItemMeta(bootsmeta);
    48. player.getInventory().setBoots(bootsBlack);
    49.  
    50.  
    51.  
    52.  
    53. } else {
    54. player.sendMessage(ChatColor.RED + "You cannot use this kit!");
    55. }
    56. return false;
    57. }
    58. return false;
    59. }
    60.  
    61. List<String> stomper = new ArrayList<String>();
    62.  
    63. @Override
    64. public void onEnable() {
    65. this.getServer().getPluginManager().registerEvents(this, this);
    66. this.getLogger().info("Trampler has been enabled!");
    67. }
    68.  
    69. @EventHandler
    70. public void onPlayerDamage(EntityDamageEvent e) {
    71. if (e.getEntity() instanceof Player) {
    72. Player p = (Player) e.getEntity();
    73. if (stomper.contains(p.getName())) {
    74. e.setDamage((double) p.getFallDistance() / 8);
    75. if (p.getFallDistance() > 3) {
    76. List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
    77. for (Entity tmp : nearby)
    78. if (tmp instanceof Player) {
    79. ((Player) tmp).damage((double) p.getFallDistance() / 2);
    80. }
    81. }
    82. }
    83. }
    84. }
    85.  
    86. public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {
    87. Player player = (Player) sender;
    88. if (label.equalsIgnoreCase("Trampler") && args.length == 0) {
    89. if (player.hasPermission("kit.Trampler")){
    90. stomper.add(sender.getName());
    91. sender.sendMessage(ChatColor.AQUA + "You have chosen the kit...." + ChatColor.GOLD + " Trampler!" + ChatColor.GREEN + " Jump on to someone from a high place to take the fall damage you would have received and give it to them!");
    92. player.getInventory().clear();
    93. ItemStack StoneSword1 = new ItemStack(Material.STONE_SWORD, 1);
    94. StoneSword1.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    95. player.getInventory().addItem(StoneSword1);
    96. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    97. //Leather tut V
    98. ItemStack chestplateAqua = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    99. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateAqua.getItemMeta();
    100. chestplatemeta.setColor(Color.AQUA);
    101. chestplateAqua.setItemMeta(chestplatemeta);
    102. //Leather tut ^
    103. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    104.  
    105. for (int i = 0; i < 32; i++) {
    106. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    107. }
    108. player.getInventory().setChestplate(chestplateAqua);
    109. //adding leather ^
    110. ItemStack chainProt1 = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
    111. chainProt1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    112. player.getInventory().setBoots(chainProt1);
    113.  
    114. } else {
    115. player.sendMessage(ChatColor.RED + "You can't use this kit!");
    116. }
    117.  
    118.  
    119. return false;
    120.  
    121. }
    122. return false;
    123. }
    124. }
    125.  
    126.  
    127.  
    128.  


    Sorry If any of that code was absolutely horribe Blingdaddy1 XD
    Like i said, im new to coding XD

    Blingdaddy1 but where would I put the @EventHandler for the Trampler kit now?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    jimuskin

    TCO_007 Use only one onCommand. If you want another command, add an else if statement at the "}" where the commandname is checked.
     
  8. Offline

    TCO_007

    I typed this into the code and Trampler works now. I just have a problem getting the PvPKit to work though. It just keeps saying unknown command and I cant figure out why? Any help?
    Code:java
    1. package me.TCOB055.main;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Color;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.enchantments.Enchantment;
    12. import org.bukkit.entity.Entity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.EntityDamageEvent;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.inventory.meta.LeatherArmorMeta;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21. public class main extends JavaPlugin implements Listener{
    22.  
    23. List<String> stomper = new ArrayList<String>();
    24. @Override
    25. public void onEnable() {
    26. this.getServer().getPluginManager().registerEvents(this, this);
    27. this.getLogger().info("Trampler has been enabled!");
    28. }
    29.  
    30. @EventHandler
    31. public void onPlayerDamage(EntityDamageEvent e) {
    32. if (e.getEntity() instanceof Player) {
    33. Player p = (Player) e.getEntity();
    34. if (stomper.contains(p.getName())) {
    35. e.setDamage((double) p.getFallDistance() / 8);
    36. if (p.getFallDistance() > 3) {
    37. List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
    38. for (Entity tmp : nearby)
    39. if (tmp instanceof Player) {
    40. ((Player) tmp).damage((double) p.getFallDistance() / 2);
    41. }
    42. }
    43. }
    44. }
    45. }
    46.  
    47.  
    48. @Override
    49. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    50. Player player = (Player) sender;
    51. if (label.equalsIgnoreCase("Trampler") && args.length == 0) {
    52. if (player.hasPermission("kit.Trampler")){
    53. stomper.add(sender.getName());
    54. sender.sendMessage(ChatColor.AQUA + "You have chosen the kit...." + ChatColor.GOLD + " Trampler!" + ChatColor.GREEN + " Jump on to someone from a high place to take the fall damage you would have received and give it to them!");
    55. player.getInventory().clear();
    56. ItemStack StoneSword1 = new ItemStack(Material.STONE_SWORD, 1);
    57. StoneSword1.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    58. player.getInventory().addItem(StoneSword1);
    59. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    60. //Leather tut V
    61. ItemStack chestplateAqua = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    62. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateAqua.getItemMeta();
    63. chestplatemeta.setColor(Color.AQUA);
    64. chestplateAqua.setItemMeta(chestplatemeta);
    65. //Leather tut ^
    66. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    67.  
    68. for (int i = 0; i < 32; i++) {
    69. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    70. }
    71. player.getInventory().setChestplate(chestplateAqua);
    72. //adding leather ^
    73. ItemStack chainProt1 = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
    74. chainProt1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    75. player.getInventory().setBoots(chainProt1);
    76.  
    77. } else {
    78. player.sendMessage(ChatColor.RED + "You can't use this kit!");
    79. }
    80. //pvp kit starts here
    81. if (cmd.getName().equalsIgnoreCase("pvp")) {
    82. //this is the permission V
    83. if (player.hasPermission("Kit.PVP")){
    84. player.sendMessage(ChatColor.AQUA + "You have received the kit...." + ChatColor.GOLD + " PVP");
    85. player.getInventory().clear();
    86. player.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    87. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    88. //Leather tut V
    89. ItemStack chestplateBlack = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    90. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateBlack.getItemMeta();
    91. chestplatemeta.setColor(Color.BLACK);
    92. chestplateBlack.setItemMeta(chestplatemeta);
    93. //Leather tut ^
    94. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    95. player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    96. for (int i = 0; i < 32; i++) {
    97. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    98. }
    99. player.getInventory().setChestplate(chestplateBlack);
    100. //adding leather ^
    101. ItemStack bootsBlack = new ItemStack(Material.LEATHER_BOOTS, 1);
    102. LeatherArmorMeta bootsmeta = (LeatherArmorMeta) bootsBlack.getItemMeta();
    103. bootsmeta.setColor(Color.BLACK);
    104. bootsBlack.setItemMeta(bootsmeta);
    105. player.getInventory().setBoots(bootsBlack);
    106.  
    107.  
    108.  
    109.  
    110. } else {
    111. player.sendMessage(ChatColor.RED + "You cannot use this kit!");
    112. }
    113. }
    114. return false;
    115. }
    116. return false;
    117.  
    118. }
    119. }


    Im terribly confused now jimuskin
    I have no idea where that stuff is. I suck at coding lol

    I think i know what you mean but what would i do with all the other code?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    jimuskin

    TCO_007 Copy/paste it into your "else if" statement. Check out several tutorials on commands if you don't understand it :D
     
  10. Offline

    TCO_007

    Should I have different classes and packages? If so, how do i do that lol. Im really new to coding and I get stuck really easy.
     
  11. Offline

    xTigerRebornx

    TCO_007 I would recommend that you have separate classes for your commands, separate packages is really only needed for organization (in your case). There are plenty of tutorials on having separate classes for your commands on here.
     
  12. Offline

    TCO_007

    I thought this code shoulve worked though. Why doesnt it?
    Code:java
    1. package me.TCOB055.main;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Color;
    8. import org.bukkit.Material;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.enchantments.Enchantment;
    12. import org.bukkit.entity.Entity;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.entity.EntityDamageEvent;
    17. import org.bukkit.inventory.ItemStack;
    18. import org.bukkit.inventory.meta.LeatherArmorMeta;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21. public class main extends JavaPlugin implements Listener{
    22.  
    23. List<String> stomper = new ArrayList<String>();
    24. @Override
    25. public void onEnable() {
    26. this.getServer().getPluginManager().registerEvents(this, this);
    27. this.getLogger().info("Trampler has been enabled!");
    28. }
    29.  
    30. @EventHandler
    31. public void onPlayerDamage(EntityDamageEvent e) {
    32. if (e.getEntity() instanceof Player) {
    33. Player p = (Player) e.getEntity();
    34. if (stomper.contains(p.getName())) {
    35. e.setDamage((double) p.getFallDistance() / 8);
    36. if (p.getFallDistance() > 3) {
    37. List<Entity> nearby = p.getNearbyEntities(5, 5, 5);
    38. for (Entity tmp : nearby)
    39. if (tmp instanceof Player) {
    40. ((Player) tmp).damage((double) p.getFallDistance() / 2);
    41. }
    42. }
    43. }
    44. }
    45. }
    46.  
    47.  
    48. @Override
    49. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    50. Player player = (Player) sender;
    51. if (label.equalsIgnoreCase("Trampler") && args.length == 0) {
    52. if (player.hasPermission("kit.Trampler")){
    53. stomper.add(sender.getName());
    54. sender.sendMessage(ChatColor.AQUA + "You have chosen the kit...." + ChatColor.GOLD + " Trampler!" + ChatColor.GREEN + " Jump on to someone from a high place to take the fall damage you would have received and give it to them!");
    55. player.getInventory().clear();
    56. ItemStack StoneSword1 = new ItemStack(Material.STONE_SWORD, 1);
    57. StoneSword1.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    58. player.getInventory().addItem(StoneSword1);
    59. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    60. //Leather tut V
    61. ItemStack chestplateAqua = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    62. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateAqua.getItemMeta();
    63. chestplatemeta.setColor(Color.AQUA);
    64. chestplateAqua.setItemMeta(chestplatemeta);
    65. //Leather tut ^
    66. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    67.  
    68. for (int i = 0; i < 32; i++) {
    69. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    70. }
    71. player.getInventory().setChestplate(chestplateAqua);
    72. //adding leather ^
    73. ItemStack chainProt1 = new ItemStack(Material.CHAINMAIL_BOOTS, 1);
    74. chainProt1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);
    75. player.getInventory().setBoots(chainProt1);
    76.  
    77. } else {
    78. player.sendMessage(ChatColor.RED + "You can't use this kit!");
    79. }
    80. //pvp kit starts here
    81. if (cmd.getName().equalsIgnoreCase("pvp")) {
    82. //this is the permission V
    83. if (player.hasPermission("Kit.PVP")){
    84. player.sendMessage(ChatColor.AQUA + "You have received the kit...." + ChatColor.GOLD + " PVP");
    85. player.getInventory().clear();
    86. player.getInventory().addItem(new ItemStack(Material.IRON_SWORD));
    87. player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
    88. //Leather tut V
    89. ItemStack chestplateBlack = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
    90. LeatherArmorMeta chestplatemeta = (LeatherArmorMeta) chestplateBlack.getItemMeta();
    91. chestplatemeta.setColor(Color.BLACK);
    92. chestplateBlack.setItemMeta(chestplatemeta);
    93. //Leather tut ^
    94. player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
    95. player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
    96. for (int i = 0; i < 32; i++) {
    97. player.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP));
    98. }
    99. player.getInventory().setChestplate(chestplateBlack);
    100. //adding leather ^
    101. ItemStack bootsBlack = new ItemStack(Material.LEATHER_BOOTS, 1);
    102. LeatherArmorMeta bootsmeta = (LeatherArmorMeta) bootsBlack.getItemMeta();
    103. bootsmeta.setColor(Color.BLACK);
    104. bootsBlack.setItemMeta(bootsmeta);
    105. player.getInventory().setBoots(bootsBlack);
    106.  
    107.  
    108.  
    109.  
    110. } else {
    111. player.sendMessage(ChatColor.RED + "You cannot use this kit!");
    112. }
    113. }
    114. return false;
    115. }
    116. return false;
    117.  
    118. }
    119. }
    jimuskin

    xTigerRebornx Thanks Tiger haha
    Im gonna need a lot of tutorials probably lol

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  13. Offline

    xTigerRebornx

    TCO_007 Everyone starts somewhere :p
     
  14. Offline

    TCO_007

  15. Offline

    xTigerRebornx

  16. Offline

    jimuskin

    TCO_007 Just look them up on google etc. Look up something like "How to make a bukkit plugin". As for your code, did you compile and run it? Are there any errors?
     
  17. Offline

    TCO_007

    Alright! Thanks so much for your help xTigerRebornx and jimuskin!

    jimuskin It didnt say it had any errors in the log.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  18. Offline

    jimuskin

    TCO_007 Well then, what part doesn't work?
     
  19. Offline

    TCO_007

    Alright! Cool! Thanks KraZ__

    Where would I put the @EventHandler though for my kits like Stomper (renamed Trampler) or something?

    @KraZ__ I put in the code from above with Inventory i; in it and it says that...
    the blank final field i may not have been initialized. Should that happen?
    I have 2 classes so far...
    main:
    Code:java
    1. package me.TCOB055.Kits;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.plugin.Plugin;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class Main extends JavaPlugin {
    9. private static Plugin plugin;
    10.  
    11. public void onEnable() {
    12. plugin = this;
    13. //This is where we register our events/commands
    14. //registerEvents(this, new Trampler());
    15. //getCommand("trampler").setExecutor(new Trampler());
    16.  
    17. // getCommand("your_command_in_lower_case").setExecutor(new commandClass());
    18. }
    19.  
    20. public void onDisable() {
    21. plugin = null;//To stop memory leeks
    22.  
    23. }
    24.  
    25.  
    26. //Much eaisier then registering events in 10 diffirent methods
    27. public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
    28. for (Listener listener : listeners) {
    29. Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
    30. }
    31. }
    32.  
    33. //To access the plugin variable from other classes
    34. public static Plugin getPlugin() {
    35. return plugin;
    36. }
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43. }


    KitsInterface:
    Code:java
    1. package me.TCOB055.Kits;
    2.  
    3. import org.bukkit.inventory.Inventory;
    4. import org.bukkit.inventory.ItemStack;
    5.  
    6. public interface KitsInterface {
    7.  
    8. Inventory i;
    9.  
    10. public ItemStack[] getArmourContents();
    11.  
    12. public void setArmourHelmet(ItemStack helmet);
    13.  
    14. public void setArmourChestplate(ItemStack chestplate);
    15.  
    16. public void setArmourLeggins(ItemStack leggings);
    17.  
    18. public void setArmourBoots(ItemStack boots);
    19.  
    20. public ItemStack getArmourHelmet();
    21.  
    22. public ItemStack getArmourChestplate();
    23.  
    24. public ItemStack getArmourLeggins();
    25.  
    26. public ItemStack getArmourBoots();
    27.  
    28. public void setInventory(Inventory i);
    29.  
    30. public Inventory getInventory();
    31.  
    32. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page