Configs

Discussion in 'Plugin Development' started by PotatoLol12321, Nov 6, 2014.

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

    PotatoLol12321

    Code:java
    1. package potato.kits;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class MenuInv extends JavaPlugin implements Listener {
    11.  
    12. private Menu menu;
    13.  
    14. public void onEnable() {
    15. menu = new Menu(this);
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. loadConfiguration();
    18. reloadConfig();
    19. }
    20.  
    21. public void loadConfiguration(){
    22. getConfig().options().copyDefaults(true);
    23. saveConfig();
    24. }
    25.  
    26. public void onDisable() {
    27. saveConfig();
    28. }
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLablel, String[] args) {
    31. if(commandLablel.equalsIgnoreCase("kit")) {
    32. Player player = (Player) sender;
    33. menu.show(player);
    34. }
    35. return false;
    36. }
    37. }



    Code:java
    1. package potato.kits;
    2.  
    3. import java.util.Arrays;
    4.  
    5.  
    6.  
    7. import java.util.List;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.DyeColor;
    12. import org.bukkit.GameMode;
    13. import org.bukkit.Location;
    14. import org.bukkit.Material;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.EventHandler;
    17. import org.bukkit.event.Listener;
    18. import org.bukkit.event.inventory.InventoryClickEvent;
    19. import org.bukkit.inventory.Inventory;
    20. import org.bukkit.inventory.ItemStack;
    21. import org.bukkit.inventory.meta.ItemMeta;
    22. import org.bukkit.material.Wool;
    23. import org.bukkit.plugin.Plugin;
    24. import org.bukkit.plugin.java.JavaPlugin;
    25.  
    26. @SuppressWarnings("unused")
    27. public class Menu extends JavaPlugin implements Listener {
    28.  
    29. private Inventory inv;
    30. private ItemStack a, b, c, d, e, f, g, h, i;
    31.  
    32. public Menu(Plugin p) {
    33.  
    34. inv = Bukkit.getServer().createInventory(null, 9, "§2§lKits");
    35. a = createItem(getConfig().getString("Slot1"));
    36. b = createItem1(getConfig().getString("Slot2"));
    37. c = createItem2(getConfig().getString("Slot3"));
    38. d = createItem3(getConfig().getString("Slot4"));
    39. e = createItem4(getConfig().getString("Slot5"));
    40. f = createItem5(getConfig().getString("Slot6"));
    41. g = createItem6(getConfig().getString("Slot7"));
    42. h = createItem7(getConfig().getString("Slot8"));
    43. i = createItem8(getConfig().getString("Slot9"));
    44.  
    45. inv.setItem(0, a);
    46. inv.setItem(1, b);
    47. inv.setItem(2, c);
    48. inv.setItem(3, d);
    49. inv.setItem(4, e);
    50. inv.setItem(5, f);
    51. inv.setItem(6, g);
    52. inv.setItem(7, h);
    53. inv.setItem(8, i);
    54.  
    55.  
    56. Bukkit.getServer().getPluginManager().registerEvents(this, p);
    57. }
    58.  
    59. @SuppressWarnings("deprecation")
    60. private ItemStack createItem(String name){
    61. ItemStack i = new ItemStack(Material.getMaterial(1));
    62. ItemMeta im= i.getItemMeta();
    63. im.setDisplayName(name);
    64. i.setItemMeta(im);
    65. return i;
    66. }
    67.  
    68. @SuppressWarnings("deprecation")
    69. private ItemStack createItem1(String name){
    70. ItemStack i = new ItemStack(Material.getMaterial(2) );
    71. ItemMeta im= i.getItemMeta();
    72. im.setDisplayName(name);
    73. i.setItemMeta(im);
    74. return i;
    75. }
    76.  
    77. private ItemStack createItem2(String name){
    78. @SuppressWarnings("deprecation")
    79. ItemStack i = new ItemStack(Material.getMaterial(3));
    80. ItemMeta im= i.getItemMeta();
    81. im.setDisplayName(name);
    82. i.setItemMeta(im);
    83. return i;
    84. }
    85.  
    86. @SuppressWarnings("deprecation")
    87. private ItemStack createItem3(String name){
    88. ItemStack i = new ItemStack(Material.getMaterial(4));
    89. ItemMeta im= i.getItemMeta();
    90. im.setDisplayName(name);
    91. i.setItemMeta(im);
    92. return i;
    93. }
    94.  
    95. @SuppressWarnings("deprecation")
    96. private ItemStack createItem4(String name){
    97. ItemStack i = new ItemStack(Material.getMaterial(5));
    98. ItemMeta im= i.getItemMeta();
    99. im.setDisplayName(name);
    100. i.setItemMeta(im);
    101. return i;
    102. }
    103.  
    104. private ItemStack createItem5(String name){
    105. @SuppressWarnings("deprecation")
    106. ItemStack i = new ItemStack(Material.getMaterial(6));
    107. ItemMeta im= i.getItemMeta();
    108. im.setDisplayName(name);
    109. i.setItemMeta(im);
    110. return i;
    111. }
    112.  
    113. @SuppressWarnings("deprecation")
    114. private ItemStack createItem6(String name){
    115. ItemStack i = new ItemStack(Material.getMaterial(7));
    116. ItemMeta im= i.getItemMeta();
    117. im.setDisplayName(name);
    118. i.setItemMeta(im);
    119. return i;
    120. }
    121.  
    122. @SuppressWarnings("deprecation")
    123. private ItemStack createItem7(String name){
    124. ItemStack i = new ItemStack(Material.getMaterial(8));
    125. ItemMeta im= i.getItemMeta();
    126. im.setDisplayName(name);
    127. i.setItemMeta(im);
    128. return i;
    129. }
    130.  
    131. @SuppressWarnings("deprecation")
    132. private ItemStack createItem8(String name){
    133. ItemStack i = new ItemStack(Material.getMaterial(9));
    134. ItemMeta im= i.getItemMeta();
    135. im.setDisplayName(name);
    136. i.setItemMeta(im);
    137. return i;
    138. }
    139.  
    140. public void show(Player p) {
    141. p.openInventory(inv);
    142. }
    143.  
    144. @EventHandler
    145. public void onInventoryClick(InventoryClickEvent e) {
    146. if (!e.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
    147. Player player = (Player) e.getWhoClicked();
    148. if (e.getCurrentItem().hasItemMeta()) {
    149. if (e.getCurrentItem().getItemMeta().getDisplayName().matches("§7Trainer")) {
    150. Bukkit.dispatchCommand(player, "kits Trainer");
    151. player.closeInventory();
    152. e.setCancelled(true);
    153. }
    154. if (e.getCurrentItem().getItemMeta().getDisplayName().matches("§7Pro Trainer")) {
    155. if(player.hasPermission("essentials.kits.ptrainer")){
    156. Bukkit.dispatchCommand(player, "kits PTrainer");
    157. player.closeInventory();
    158. e.setCancelled(true);
    159. } else {
    160. player.sendMessage("§cBeat all 8 gyms to get pro trainer");
    161. e.setCancelled(true);
    162. }
    163. }
    164. if (e.getCurrentItem().getItemMeta().getDisplayName().matches("§7Master Trainer")) {
    165. if(player.hasPermission("essentials.kits.mtrainer")) {
    166. Bukkit.dispatchCommand(player, "kits MTrainer");
    167. player.closeInventory();
    168. e.setCancelled(true);
    169. } else {
    170. player.sendMessage("§cBeat the elite 4 to get master trainer");
    171. e.setCancelled(true);
    172. }
    173. }
    174. if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§bVip")) {
    175. if (player.hasPermission("essentials.kits.vip")) {
    176. Bukkit.dispatchCommand(player, "kits Vip");
    177. player.closeInventory();
    178. e.setCancelled(true);
    179. } else {
    180. player.sendMessage("§cYou must be vip");
    181. e.setCancelled(true);
    182. }
    183. }
    184. if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("§3Vip+")) {
    185. if (player.hasPermission("essentials.kits.vip+")) {
    186. Bukkit.dispatchCommand(player, "kits Vip+");
    187. player.closeInventory();
    188. e.setCancelled(true);
    189. } else {
    190. player.sendMessage("§cYou must be vip+");
    191. e.setCancelled(true);
    192. }
    193. }
    194. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Elite")) {
    195. if (player.hasPermission("essentials.kits.elite")) {
    196. player.performCommand("kits elite");
    197. e.setCancelled(true);
    198. player.closeInventory();
    199. } else {
    200. player.sendMessage("§cYou must be elite");
    201. e.setCancelled(true);
    202. }
    203. }
    204. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Legend")) {
    205. if (player.hasPermission("essentials.kits.legend")) {
    206. Bukkit.dispatchCommand(player, "kits Legend");
    207. player.closeInventory();
    208. e.setCancelled(true);
    209. } else {
    210. player.sendMessage("§cYou must be atleast outlander");
    211. e.setCancelled(true);
    212. }
    213. }
    214. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Exit")) {
    215. player.closeInventory();
    216. e.setCancelled(true);
    217. }
    218. } else {
    219. e.setCancelled(true);
    220. }
    221. }
    222. }


    Its not loading the config.yml, any ideas what i'm doing wrong?
     
  2. Offline

    Skionz

    PotatoLol12321 Not ending your quotes. Aren't you getting like a ton of errors in your IDE?
     
  3. Offline

    Watto

  4. Offline

    PotatoLol12321

    Skionz I think the quotes are fine, i think i pasted wrong the first time. :/ (Re-pasted)
     
  5. Offline

    Skionz

  6. Offline

    PotatoLol12321

    Skionz Still not loading config. :/
     
  7. Offline

    Skionz

    PotatoLol12321 Did you remove the extension of JavaPlugin in your Menu class?
     
  8. Offline

    PotatoLol12321

    Skionz Still isn't loading the config on start, it shows up empty after i stop the server. :/

    Code:
    19:35:11 [SEVERE] Error occurred while enabling Kit v1 (Is it up to date?)
    java.lang.NullPointerException
            at potato.kits.Menu.<init>(Menu.java:37)
            at potato.kits.MenuInv.onEnable(MenuInv.java:15)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:457)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.jav
    a:284)
            at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.
    java:266)
            at net.minecraft.server.v1_6_R3.MinecraftServer.l(MinecraftServer.java:3
    15)
            at net.minecraft.server.v1_6_R3.MinecraftServer.f(MinecraftServer.java:2
    92)
            at net.minecraft.server.v1_6_R3.MinecraftServer.a(MinecraftServer.java:2
    52)
            at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.jav
    a:152)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :393)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  9. Offline

    Skionz

  10. Offline

    PotatoLol12321

    Skionz It points to line 37 "a = createItem(plugin.getConfig().getString("Slot1"));"

    Code:
    Slot1: '&1Test'
    Slot2: '&2Test'
    Slot3: '&3Test'
    Slot4: '&4Test'
    Slot5: '&5Test'
    Slot6: '&6Test'
    Slot7: '&7Test'
    Slot8: '&8Test'
    Slot9: '&9Test'
    Thats my config.yml right now. :/
     
  11. Offline

    Skionz

  12. Offline

    PotatoLol12321

    Skionz


    Code:
     @SuppressWarnings("null")
            public Menu(Plugin p) {
               
                    inv = Bukkit.getServer().createInventory(null, 9, "§2§lKits");
                    Plugin plugin = null;
                    a = createItem(plugin.getConfig().getString("Slot1"));
                    b = createItem1(plugin.getConfig().getString("Slot2"));
                    c = createItem2(plugin.getConfig().getString("Slot3"));
                    d = createItem3(plugin.getConfig().getString("Slot4"));
                    e = createItem4(plugin.getConfig().getString("Slot5"));
                    f = createItem5(plugin.getConfig().getString("Slot6"));
                    g = createItem6(plugin.getConfig().getString("Slot7"));
                    h = createItem7(plugin.getConfig().getString("Slot8"));
                    i = createItem8(plugin.getConfig().getString("Slot9"));
    I took of the java plugin extension I might of messed this part up.
     
  13. Offline

    Skionz

    PotatoLol12321 No wonder your getting a null pointer. plugin is null
    use p instead
     
  14. Offline

    PotatoLol12321

    Skionz what should i change that too? Its telling me to put null there. :/

    Skionz Thanks its working now! :D

    Skionz What do i do about this? :/

    Code:java
    1. @SuppressWarnings("deprecation")
    2. private ItemStack createItem(String name){
    3. Plugin plugin = p;
    4. ItemStack i = new ItemStack(Material.getMaterial(plugin.getConfig().getInt("Slot1.Item")));
    5. ItemMeta im= i.getItemMeta();
    6. im.setDisplayName(name);
    7. i.setItemMeta(im);
    8. return i;
    9. }


    Its giving me a red line on "Plugin plugin = p;" On the "p"

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

    Skionz

    PotatoLol12321 Read the error. It will tell you exactly what is wrong.
     
Thread Status:
Not open for further replies.

Share This Page