Null Pointer Exception

Discussion in 'Plugin Development' started by prinzpommes, Jul 21, 2013.

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

    prinzpommes

    Hi there! :D

    I wrote a small Plugin, mostly for personal use. It features several Recipes and a Method to display a private Message to a Player joining instead of "user" joined the game.

    The Problem now is that i get a Null Pointer Exception whenever i join my test Server...


    Error:
    Show Spoiler
    [SEVERE] Could not pass event PlayerJoinEvent to Recipes v1.6.2_V0.8_03_BETA
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:363)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:479)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:464)
    at net.minecraft.server.management.ServerConfigurationManager.func_72377_c(ServerConfigurationManager.java:321)
    at net.minecraft.server.management.ServerConfigurationManager.func_72355_a(ServerConfigurationManager.java:182)
    at net.minecraft.network.NetLoginHandler.completeConnection(NetLoginHandler.java:214)
    at cpw.mods.fml.common.network.FMLNetworkHandler.handleClientConnection(FMLNetworkHandler.java:171)
    at cpw.mods.fml.common.network.FMLNetworkHandler.onConnectionReceivedFromClient(FMLNetworkHandler.java:124)
    at net.minecraft.network.NetLoginHandler.func_72529_d(NetLoginHandler.java:190)
    at net.minecraft.network.NetLoginHandler.func_72532_c(NetLoginHandler.java:80)
    at net.minecraft.server.ServerListenThread.func_71766_a(ServerListenThread.java:57)
    at net.minecraft.server.dedicated.DedicatedServerListenThread.func_71747_b(DedicatedServerListenThread.java:33)
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:877)
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:318)
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:746)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:630)
    at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
    Caused by: java.lang.NullPointerException
    at com.github.prinzpommes.MOTD.message(MOTD.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:361)
    ... 17 more


    The Lines the Error is refering to are the following:

    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import com.github.prinzpommes.Recipe;
    9. import org.bukkit.event.EventHandler;
    10.  
    11.  
    12.  
    13. public class MOTD implements Listener {
    14.  
    15.  
    16.  
    17. private static String PrivateJoinMessage;
    18.  
    19.  
    20. public MOTD(Recipe plugin) {
    21. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    22. }
    23.  
    24.  
    25. @EventHandler
    26.  
    27. public void message(PlayerJoinEvent event) {
    28.  
    29.  
    30. Recipe.getCFGL();
    31. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    32. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    33. ChatColor.GRAY + "Online ("
    34. + Bukkit.getServer().getOnlinePlayers().length
    35. + "/" + Bukkit.getMaxPlayers() + "): "
    36. + listPlayers());
    37.  
    38.  
    39. }
    40.  
    41.  
    42.  
    43. public static String listPlayers() {
    44.  
    45.  
    46. Player ar[] = Bukkit.getOnlinePlayers();
    47. String liste = "";
    48. for (Player p : Bukkit.getOnlinePlayers()) {
    49.  
    50.  
    51. if (p.equals(ar[Bukkit.getOnlinePlayers().length - 1])) {
    52.  
    53.  
    54. liste += p.getDisplayName();
    55. } else {
    56.  
    57.  
    58. liste += p.getDisplayName() + ", ";
    59. }
    60. }
    61.  
    62.  
    63. return liste;
    64. }
    65.  
    66.  
    67. }
    68.  
    69.  



    Anyone got a fix for that?

    Thanks in advance!
    pp
     
  2. Offline

    tills13

    Make sure that it's retrieving the PrivateJoinMessage. Try printing out the result of this line: PrivateJoinMessage = Configloader.getPrivatJoinMessage();
     
  3. Offline

    xTrollxDudex

    prinzpommes
    Where did you get the plugin variable from?
     
  4. Offline

    prinzpommes

    Last edited by a moderator: Jun 3, 2016
    ysl3000 likes this.
  5. Offline

    xTrollxDudex

    prinzpommes
    You cant really directly get a variable from another class.
    I know you are a noob at java but seriously learn some basic java and understand it, it will make your life a lot easier, no joke.
     
  6. Offline

    prinzpommes

    xTrollxDudex well thanks :) do you have any quick fix though?

    pp
     
  7. Offline

    xTrollxDudex

    prinzpommes
    Its not quick, but put this in the LISTENER
    PHP:
    Main plugin;
    public 
    MOTD(Main plugin){
    this.plugin plugin;
    }
    replace all occurrences of "Main" with the actual main class name.

    Put this in the MAIN class(the one that extends JavaPlugin)
    PHP:
    getServer().getPluginManager().registerEvents(new MOTD(this), this);
    Get rid of your old registry line and replace it with this one.

    Now you can use "plugin" in MOTD.
     
    prinzpommes likes this.
  8. Offline

    1Rogue Retired Staff

    You are registering events for your listener class, within your listener class, and then not keeping the plugin variable. Also by java standards, you should keep the beginning letter of variables lowercase. As a last thing to note, you should make sure that the amount of players isn't 0, or getting the online players will most likely return null.

    Code:java
    1.  
    2. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    3. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    4. ChatColor.GRAY + "Online ("
    5. + Bukkit.getServer().getOnlinePlayers().length
    6. + "/" + Bukkit.getMaxPlayers() + "): "
    7. + listPlayers());
    8.  
    9. --------------------
    10.  
    11. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    12. int online = 0;
    13. if (Bukkit.getServer().getOnlinePlayers().length != null) {
    14. int online = Bukkit.getServer().getOnlinePlayers().length;
    15. }
    16. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    17. ChatColor.GRAY + "Online ("
    18. + online
    19. + "/" + Bukkit.getMaxPlayers() + "): "
    20. + listPlayers());



    My only other thought is that maybe the string you are getting from the config isn't actually returning a proper value, so try catching that as well.

    Code:java
    1.  
    2. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    3. if (PrivateJoinMessage == null) {
    4. PrivateJoinMessage = "online%";
    5. }
    6. int online = 0;
    7. if (Bukkit.getServer().getOnlinePlayers().length != null) {
    8. int online = Bukkit.getServer().getOnlinePlayers().length;
    9. }
    10. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    11. ChatColor.GRAY + "Online ("
    12. + online
    13. + "/" + Bukkit.getMaxPlayers() + "): "
    14. + listPlayers());
    15.  



    (I may be using the wrong check to see if the string value returned from Configloader.getPrivatJoinMessage() is null, but it's the concept that is important).

    And as xTrollxDudex stated, you should invest the time into learning the concepts behind java as well, it will help you with debugging your own code.
    \

    From what I saw within the MOTD class, "plugin" wasn't a variable used outside of the constructor. Though it would definitely make things simpler down the line to keep instances of the external classes in the main class, rather than static classes or the reverse (classes having instances of the main).
     
    xTrollxDudex likes this.
  9. Offline

    prinzpommes


    Thanks for the quick answer... doesnt seems to actually fix the problem. Same error as before.


    The Operator != is undefined for the argument type int,null...
    and:
    online is duplicated..
     
  10. Offline

    1Rogue Retired Staff


    Java standards

    remove the online variable/idea, it was an unnecessary catch of an error I considered possible.

    Code:java
    1.  
    2. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    3. if (PrivateJoinMessage == null) {
    4. PrivateJoinMessage = "online%";
    5. }
    6. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    7. ChatColor.GRAY + "Online ("
    8. + Bukkit.getServer().getOnlinePlayers().length
    9. + "/" + Bukkit.getMaxPlayers() + "): "
    10. + listPlayers());
     
  11. Offline

    xTrollxDudex

    You would never get a null "Online players " because prinzpommes was listeneing for PlayerJoinEvent, therefore, even if there was 0 online players, the player that just joined would make it 1.
     
    1Rogue likes this.
  12. Offline

    prinzpommes


    That solves the Error, but now i got the same Error as before this post. The Message is not displaying.

    pp
     
  13. Offline

    1Rogue Retired Staff


    Well that would be because you don't send it anywhere, haha.

    event.getPlayer().sendMessage(PrivateJoinMessage);
     
  14. Offline

    xTrollxDudex

  15. Offline

    prinzpommes


    Upps :D
    well i working half the way it should now :D the online%is now dosplayed properly, but the actuall message is missing now.

    pp

    btw: 1Rogue was right :) i needed to add the:

    Code:java
    1. if (PrivateJoinMessage == null) {
    2. PrivateJoinMessage = "online%";
    3. }

    to prevent an error.
     
    ysl3000 likes this.
  16. Offline

    1Rogue Retired Staff

    Keep in mind, that is just a catch for an error, so you still have an issue somewhere else (like, the config probably isn't returning the value that it should). You should focus on fixing those bugs as well.
     
  17. Offline

    xTrollxDudex

  18. Offline

    prinzpommes

    Here it is:
    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import com.github.prinzpommes.Recipe;
    9. import org.bukkit.event.EventHandler;
    10.  
    11.  
    12.  
    13. public class MOTD implements Listener {
    14.  
    15.  
    16.  
    17. private static String PrivateJoinMessage;
    18.  
    19. public MOTD(Recipe plugin) {
    20. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    21. }
    22.  
    23.  
    24. @EventHandler
    25.  
    26. public void message(PlayerJoinEvent event) {
    27.  
    28. Recipe.getCFGL();
    29. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    30. if (PrivateJoinMessage == null) {
    31. PrivateJoinMessage = "online%";
    32. }
    33. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    34. ChatColor.GRAY + "Online ("
    35. + Bukkit.getServer().getOnlinePlayers().length
    36. + "/" + Bukkit.getMaxPlayers() + "): "
    37. + listPlayers());
    38.  
    39.  
    40. event.getPlayer().sendMessage(PrivateJoinMessage);
    41. }
    42.  
    43.  
    44.  
    45. public static String listPlayers() {
    46.  
    47.  
    48. Player ar[] = Bukkit.getOnlinePlayers();
    49. String liste = "";
    50. for (Player p : Bukkit.getOnlinePlayers()) {
    51.  
    52.  
    53. if (p.equals(ar[Bukkit.getOnlinePlayers().length - 1])) {
    54.  
    55.  
    56. liste += p.getDisplayName();
    57. } else {
    58.  
    59.  
    60. liste += p.getDisplayName() + ", ";
    61. }
    62. }
    63.  
    64.  
    65. return liste;
    66. }
    67.  
    68.  
    69. }
    70.  
    71.  


    Also: the config is ignored now. i tried removing online% from the config but it didnt work.

    pp
     
    ysl3000 likes this.
  19. Offline

    1Rogue Retired Staff

    Mind posting your Configloader class?
     
  20. Offline

    prinzpommes

    nno problem :)

    Configloader.class
    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import com.github.prinzpommes.Recipe;
    4.  
    5. public class Configloader {
    6.  
    7. private Recipe plugin;
    8.  
    9. private static String PrivateJoinMessage;
    10. private static boolean netherrack;
    11. private static boolean netherbrick;
    12. private static boolean glowstone;
    13. private static boolean soulsand;
    14. private static boolean blazerod;
    15. private static boolean netherstar;
    16. private static boolean netherwartseed;
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23. public Configloader(Recipe Recipe)
    24.  
    25. {
    26. this.plugin = Recipe;
    27.  
    28. PrivateJoinMessage = this.plugin.getConfig().getString("message.privatejoinmessage");
    29.  
    30.  
    31. netherrack = this.plugin.getConfig().getBoolean("netherrack");
    32. netherbrick = this.plugin.getConfig().getBoolean("netherbrick");
    33. glowstone = this.plugin.getConfig ().getBoolean("glowstone");
    34. soulsand = this.plugin.getConfig ().getBoolean("soulsand");
    35. blazerod = this.plugin.getConfig ().getBoolean("blazerod");
    36. netherstar = this.plugin.getConfig().getBoolean("netherstar");
    37. netherwartseed = this.plugin.getConfig().getBoolean("netherwartseed");
    38. }
    39.  
    40.  
    41.  
    42. public static boolean getnetherrack(){
    43. return netherrack;
    44. }
    45. public static boolean getnetherbrick(){
    46. return netherbrick;
    47. }
    48. public static boolean getglowstone(){
    49. return glowstone;
    50. }
    51. public static boolean getsoulsand(){
    52. return soulsand;
    53. }
    54. public static boolean getblazerod(){
    55. return blazerod;
    56. }
    57. public static boolean getnetherstar(){
    58. return netherstar;
    59. }
    60. public static boolean getnetherwartseed(){
    61. return netherwartseed;
    62. }
    63.  
    64.  
    65. public static String getPrivatJoinMessage(){
    66. return PrivateJoinMessage;
    67. }
    68.  
    69.  
    70. }
    71.  


    just in case ;)

    Recipe.class

    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import java.io.File;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.inventory.FurnaceRecipe;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.inventory.ShapedRecipe;
    11. import org.bukkit.inventory.ShapelessRecipe;
    12. import org.bukkit.material.SpawnEgg;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import com.github.prinzpommes.Configloader;
    15. import com.github.prinzpommes.MOTD;
    16.  
    17.  
    18.  
    19. public class Recipe extends JavaPlugin {
    20.  
    21. public static Recipe plugin;
    22. public final static Logger logger = Logger.getLogger("Minecraft");
    23. private static String mainDirectory = "plugins/Recipes/";
    24. private static Configloader CFGL;
    25.  
    26. Logger log;
    27.  
    28. protected FileConfiguration config = null;
    29.  
    30. public void onEnable() {
    31. log = Logger.getLogger("Minecraft");
    32. new File(mainDirectory).mkdir();
    33. log.info("Welcome to the Future of Crafting! Recipes has been enabled successfully.");
    34.  
    35. new MOTD (this);
    36. CFGL = new Configloader(this);
    37.  
    38. new Configloader(this);
    39.  
    40. config = this.getConfig();
    41.  
    42. this.getConfig().options().copyDefaults(true);
    43. this.saveConfig();
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54.  
    55.  
    56.  
    57.  
    58. ShapedRecipe sr = new ShapedRecipe(new ItemStack(
    59. Material.ENCHANTMENT_TABLE, 1));
    60. sr.shape(new String[] { " ", " b ", "www" })
    61. .setIngredient('b', Material.BOOKSHELF)
    62. .setIngredient('w', Material.WOOD);
    63.  
    64. ShapedRecipe glows1 = new ShapedRecipe(
    65. new ItemStack(Material.GLOWSTONE));
    66. glows1.shape(new String[] { "rr ", "rr ", " " }).setIngredient('r',
    67. Material.REDSTONE_TORCH_ON);
    68. ShapedRecipe glows2 = new ShapedRecipe(
    69. new ItemStack(Material.GLOWSTONE));
    70. glows2.shape(new String[] { " rr", " rr", " " }).setIngredient('r',
    71. Material.REDSTONE_TORCH_ON);
    72. ShapedRecipe glows3 = new ShapedRecipe(
    73. new ItemStack(Material.GLOWSTONE));
    74. glows3.shape(new String[] { " ", "rr ", "rr " }).setIngredient('r',
    75. Material.REDSTONE_TORCH_ON);
    76. ShapedRecipe glows4 = new ShapedRecipe(
    77. new ItemStack(Material.GLOWSTONE));
    78. glows4.shape(new String[] { " ", " rr", " rr" }).setIngredient('r',
    79. Material.REDSTONE_TORCH_ON);
    80.  
    81. ShapelessRecipe wheat = new ShapelessRecipe(new ItemStack(
    82. Material.SEEDS, 3));
    83. wheat.addIngredient(Material.WHEAT);
    84.  
    85. ShapedRecipe grass1 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    86. grass1.shape(new String[] { "ee ", "ee ", " " }).setIngredient('e',
    87. Material.DIRT);
    88. ShapedRecipe grass2 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    89. grass2.shape(new String[] { " ee", " ee", " " }).setIngredient('e',
    90. Material.DIRT);
    91. ShapedRecipe grass3 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    92. grass3.shape(new String[] { " ", " ee", " ee" }).setIngredient('e',
    93. Material.DIRT);
    94. ShapedRecipe grass4 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    95. grass4.shape(new String[] { " ", "ee ", "ee " }).setIngredient('e',
    96. Material.DIRT);
    97.  
    98. ShapedRecipe oldcobble1 = new ShapedRecipe(new ItemStack(
    99. Material.MOSSY_COBBLESTONE, 1));
    100. oldcobble1.shape(new String[] { "g ", "c ", " " })
    101. .setIngredient('g', Material.GRASS)
    102. .setIngredient('c', Material.COBBLESTONE);
    103. ShapedRecipe oldcobble2 = new ShapedRecipe(new ItemStack(
    104. Material.MOSSY_COBBLESTONE, 1));
    105. oldcobble2.shape(new String[] { " g ", " c ", " " })
    106. .setIngredient('g', Material.GRASS)
    107. .setIngredient('c', Material.COBBLESTONE);
    108. ShapedRecipe oldcobble3 = new ShapedRecipe(new ItemStack(
    109. Material.MOSSY_COBBLESTONE, 1));
    110. oldcobble3.shape(new String[] { " g", " c", " " })
    111. .setIngredient('g', Material.GRASS)
    112. .setIngredient('c', Material.COBBLESTONE);
    113. ShapedRecipe oldcobble4 = new ShapedRecipe(new ItemStack(
    114. Material.MOSSY_COBBLESTONE, 1));
    115. oldcobble4.shape(new String[] { " ", "g ", "c " })
    116. .setIngredient('g', Material.GRASS)
    117. .setIngredient('c', Material.COBBLESTONE);
    118. ShapedRecipe oldcobble5 = new ShapedRecipe(new ItemStack(
    119. Material.MOSSY_COBBLESTONE, 1));
    120. oldcobble5.shape(new String[] { " ", " g ", " c " })
    121. .setIngredient('g', Material.GRASS)
    122. .setIngredient('c', Material.COBBLESTONE);
    123. ShapedRecipe oldcobble6 = new ShapedRecipe(new ItemStack(
    124. Material.MOSSY_COBBLESTONE, 1));
    125. oldcobble6.shape(new String[] { " ", " g", " c" })
    126. .setIngredient('g', Material.GRASS)
    127. .setIngredient('c', Material.COBBLESTONE);
    128.  
    129. ShapedRecipe villager = new ShapedRecipe(
    130. new SpawnEgg((byte) 120).toItemStack(1));
    131. villager.shape(new String[] { "rcr", "rer", "rlr" })
    132. .setIngredient('r', Material.EMERALD)
    133. .setIngredient('c', Material.WORKBENCH)
    134. .setIngredient('l', Material.LEATHER)
    135. .setIngredient('e', Material.EGG);
    136.  
    137. ShapedRecipe wolf = new ShapedRecipe(
    138. new SpawnEgg((byte) 95).toItemStack(1));
    139. wolf.shape(new String[] { "rbr", "rer", "rcr" })
    140. .setIngredient('r', Material.EMERALD)
    141. .setIngredient('b', Material.BONE)
    142. .setIngredient('c', Material.ROTTEN_FLESH)
    143. .setIngredient('e', Material.EGG);
    144.  
    145. ShapedRecipe schwein = new ShapedRecipe(
    146. new SpawnEgg((byte) 90).toItemStack(1));
    147. schwein.shape(new String[] { "rbr", "rer", "rcr" })
    148. .setIngredient('r', Material.EMERALD)
    149. .setIngredient('b', Material.BONE)
    150. .setIngredient('c', Material.PORK)
    151. .setIngredient('e', Material.EGG);
    152.  
    153. ShapedRecipe schaf = new ShapedRecipe(
    154. new SpawnEgg((byte) 91).toItemStack(1));
    155. schaf.shape(new String[] { "rbr", "rer", "rcr" })
    156. .setIngredient('r', Material.EMERALD)
    157. .setIngredient('b', Material.BONE)
    158. .setIngredient('c', Material.WOOL)
    159. .setIngredient('e', Material.EGG);
    160.  
    161. ShapedRecipe kuh = new ShapedRecipe(
    162. new SpawnEgg((byte) 92).toItemStack(1));
    163. kuh.shape(new String[] { "rbr", "rer", "rcr" })
    164. .setIngredient('r', Material.EMERALD)
    165. .setIngredient('b', Material.BONE)
    166. .setIngredient('c', Material.RAW_BEEF)
    167. .setIngredient('e', Material.EGG);
    168.  
    169. ShapedRecipe huhn = new ShapedRecipe(
    170. new SpawnEgg((byte) 93).toItemStack(1));
    171. huhn.shape(new String[] { "rbr", "rer", "rcr" })
    172. .setIngredient('r', Material.EMERALD)
    173. .setIngredient('b', Material.BONE)
    174. .setIngredient('c', Material.RAW_CHICKEN)
    175. .setIngredient('e', Material.EGG);
    176.  
    177. ShapelessRecipe netz1 = new ShapelessRecipe(new ItemStack(
    178. Material.STRING, 3));
    179. netz1.addIngredient(Material.WEB);
    180.  
    181. ShapedRecipe netz2 = new ShapedRecipe(new ItemStack(Material.WEB, 1));
    182. netz2.shape(new String[] { "s s", " s ", "s s" }).setIngredient('s',
    183. Material.STRING);
    184.  
    185. ShapelessRecipe sattel1 = new ShapelessRecipe(new ItemStack(
    186. Material.LEATHER, 3));
    187. sattel1.addIngredient(Material.SADDLE);
    188.  
    189. ShapedRecipe sattel2 = new ShapedRecipe(new ItemStack(Material.SADDLE,
    190. 1));
    191. sattel2.shape(new String[] { "l l", "lll", " " }).setIngredient('l',
    192. Material.LEATHER);
    193.  
    194. ShapedRecipe sattel3 = new ShapedRecipe(new ItemStack(Material.SADDLE,
    195. 1));
    196. sattel3.shape(new String[] { " ", "l l", "lll" }).setIngredient('l',
    197. Material.LEATHER);
    198.  
    199. ShapelessRecipe grassbueschel = new ShapelessRecipe(new ItemStack(
    200. Material.LONG_GRASS, 3, (byte) 1));
    201. grassbueschel.addIngredient(Material.GRASS);
    202.  
    203. ShapedRecipe chain_helm1 = new ShapedRecipe(new ItemStack(
    204. Material.CHAINMAIL_HELMET, 1));
    205. chain_helm1.shape(new String[] { "gdg", "g g", " " })
    206. .setIngredient('g', Material.GLASS)
    207. .setIngredient('d', Material.DIAMOND);
    208.  
    209. ShapedRecipe chain_helm2 = new ShapedRecipe(new ItemStack(
    210. Material.CHAINMAIL_HELMET, 1));
    211. chain_helm2.shape(new String[] { " ", "gdg", "g g" })
    212. .setIngredient('g', Material.GLASS)
    213. .setIngredient('d', Material.DIAMOND);
    214.  
    215. ShapedRecipe chain_brust = new ShapedRecipe(new ItemStack(
    216. Material.CHAINMAIL_CHESTPLATE, 1));
    217. chain_brust.shape(new String[] { "g g", "gdg", "ggg" })
    218. .setIngredient('g', Material.GLASS)
    219. .setIngredient('d', Material.DIAMOND);
    220.  
    221. ShapedRecipe chain_bein = new ShapedRecipe(new ItemStack(
    222. Material.CHAINMAIL_LEGGINGS, 1));
    223. chain_bein.shape(new String[] { "gdg", "g g", "g g" })
    224. .setIngredient('g', Material.GLASS)
    225. .setIngredient('d', Material.DIAMOND);
    226.  
    227. ShapedRecipe chain_fuss1 = new ShapedRecipe(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
    228. chain_fuss1.shape(new String[] { "g g", "g g", " " })
    229. .setIngredient('g', Material.GLASS);
    230.  
    231. ShapedRecipe chain_fuss2 = new ShapedRecipe(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
    232. chain_fuss2.shape(new String[] { " ", "g g", "g g" })
    233. .setIngredient('g', Material.GLASS);
    234.  
    235. ShapedRecipe soul1 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    236. soul1.shape(new String[] { "gg ", "gg ", " " })
    237. .setIngredient('g',Material.GRAVEL);
    238. ShapedRecipe soul2 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    239. soul2.shape(new String[] { " gg", " gg", " " })
    240. .setIngredient('g',Material.GRAVEL);
    241. ShapedRecipe soul3 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    242. soul3.shape(new String[] { " ", "gg ", "gg " })
    243. .setIngredient('g',Material.GRAVEL);
    244. ShapedRecipe soul4 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    245. soul4.shape(new String[] { " ", " gg", " gg" })
    246. .setIngredient('g',Material.GRAVEL);
    247.  
    248. ShapedRecipe blazerod = new ShapedRecipe(new ItemStack(Material.BLAZE_ROD, 1));
    249. blazerod.shape(new String[] { "ggg", "gbg", "ggg" })
    250. .setIngredient('g', Material.GOLD_BLOCK)
    251. .setIngredient('b',Material.STICK);
    252.  
    253. ShapedRecipe netherstar = new ShapedRecipe(new ItemStack(Material.NETHER_STAR, 1));
    254. netherstar.shape(new String[] { " d ", "dbd", " d " })
    255. .setIngredient('d', Material.DIAMOND)
    256. .setIngredient('b',Material.BLAZE_POWDER);
    257.  
    258. ShapedRecipe netherwartseed1 = new ShapedRecipe(new ItemStack(Material.NETHER_STALK, 6));
    259. netherwartseed1.shape(new String[] { "nnn", "nrn", "nnn" })
    260. .setIngredient('n', Material.NETHERRACK)
    261. .setIngredient('r',Material.RED_MUSHROOM);
    262.  
    263. ShapedRecipe netherwartseed2 = new ShapedRecipe(new ItemStack(Material.NETHER_STALK, 3));
    264. netherwartseed2.shape(new String[] { "nnn", "nrn", "nnn" })
    265. .setIngredient('n', Material.NETHERRACK)
    266. .setIngredient('r',Material.BROWN_MUSHROOM);
    267.  
    268. ShapedRecipe feder1 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    269. feder1.shape(new String[] { "p ", "s ", " " })
    270. .setIngredient('p', Material.PAPER)
    271. .setIngredient('s',Material.STRING);
    272. ShapedRecipe feder2 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    273. feder2.shape(new String[] { " p ", " s ", " " })
    274. .setIngredient('p', Material.PAPER)
    275. .setIngredient('s',Material.STRING);
    276. ShapedRecipe feder3 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    277. feder3.shape(new String[] { " p", " s", " " })
    278. .setIngredient('p', Material.PAPER)
    279. .setIngredient('s',Material.STRING);
    280. ShapedRecipe feder4 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    281. feder4.shape(new String[] { " ", "p ", "s " })
    282. .setIngredient('p', Material.PAPER)
    283. .setIngredient('s',Material.STRING);
    284. ShapedRecipe feder5 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    285. feder5.shape(new String[] { " ", " p ", " s " })
    286. .setIngredient('p', Material.PAPER)
    287. .setIngredient('s',Material.STRING);
    288. ShapedRecipe feder6 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    289. feder6.shape(new String[] { " ", " p", " s" })
    290. .setIngredient('p', Material.PAPER)
    291. .setIngredient('s',Material.STRING);
    292.  
    293.  
    294. FurnaceRecipe sponge = new FurnaceRecipe(new ItemStack(Material.SPONGE,
    295. 1), Material.SANDSTONE);
    296. FurnaceRecipe ironingot1 = new FurnaceRecipe(new ItemStack(
    297. Material.IRON_INGOT, 1), Material.IRON_PICKAXE);
    298. FurnaceRecipe ironingot2 = new FurnaceRecipe(new ItemStack(
    299. Material.IRON_INGOT, 1), Material.IRON_AXE);
    300. FurnaceRecipe ironingot3 = new FurnaceRecipe(new ItemStack(
    301. Material.IRON_INGOT, 1), Material.IRON_HOE);
    302. FurnaceRecipe ironingot4 = new FurnaceRecipe(new ItemStack(
    303. Material.IRON_INGOT, 1), Material.IRON_SWORD);
    304. FurnaceRecipe goldingot1 = new FurnaceRecipe(new ItemStack(
    305. Material.GOLD_INGOT, 1), Material.GOLD_PICKAXE);
    306. FurnaceRecipe goldingot2 = new FurnaceRecipe(new ItemStack(
    307. Material.GOLD_INGOT, 1), Material.GOLD_AXE);
    308. FurnaceRecipe goldingot3 = new FurnaceRecipe(new ItemStack(
    309. Material.GOLD_INGOT, 1), Material.GOLD_HOE);
    310. FurnaceRecipe goldingot4 = new FurnaceRecipe(new ItemStack(
    311. Material.GOLD_INGOT, 1), Material.GOLD_SWORD);
    312. FurnaceRecipe diamond1 = new FurnaceRecipe(new ItemStack(
    313. Material.DIAMOND, 1), Material.DIAMOND_PICKAXE);
    314. FurnaceRecipe diamond2 = new FurnaceRecipe(new ItemStack(
    315. Material.DIAMOND, 1), Material.DIAMOND_AXE);
    316. FurnaceRecipe diamond3 = new FurnaceRecipe(new ItemStack(
    317. Material.DIAMOND, 1), Material.DIAMOND_HOE);
    318. FurnaceRecipe diamond4 = new FurnaceRecipe(new ItemStack(
    319. Material.DIAMOND, 1), Material.DIAMOND_SWORD);
    320. FurnaceRecipe nbrick = new FurnaceRecipe(new ItemStack(
    321. Material.NETHER_BRICK, 1), Material.NETHERRACK);
    322. FurnaceRecipe nrack = new FurnaceRecipe(new ItemStack(
    323. Material.NETHERRACK, 1), Material.GRAVEL);
    324. FurnaceRecipe rottenflesh = new FurnaceRecipe(new ItemStack(
    325. Material.RAW_BEEF, 1), Material.ROTTEN_FLESH);
    326. FurnaceRecipe gravel = new FurnaceRecipe(new ItemStack(
    327. Material.GRAVEL, 1), Material.DIRT);
    328.  
    329.  
    330. getServer().addRecipe(sponge);
    331.  
    332. getServer().addRecipe(gravel);
    333.  
    334. getServer().addRecipe(sr);
    335.  
    336. getServer().addRecipe(ironingot1);
    337. getServer().addRecipe(ironingot2);
    338. getServer().addRecipe(ironingot3);
    339. getServer().addRecipe(ironingot4);
    340.  
    341. getServer().addRecipe(goldingot1);
    342. getServer().addRecipe(goldingot2);
    343. getServer().addRecipe(goldingot3);
    344. getServer().addRecipe(goldingot4);
    345.  
    346. getServer().addRecipe(diamond1);
    347. getServer().addRecipe(diamond2);
    348. getServer().addRecipe(diamond3);
    349. getServer().addRecipe(diamond4);
    350.  
    351. getServer().addRecipe(wheat);
    352.  
    353. getServer().addRecipe(grass1);
    354. getServer().addRecipe(grass2);
    355. getServer().addRecipe(grass3);
    356. getServer().addRecipe(grass4);
    357.  
    358. getServer().addRecipe(oldcobble1);
    359. getServer().addRecipe(oldcobble2);
    360. getServer().addRecipe(oldcobble3);
    361. getServer().addRecipe(oldcobble4);
    362. getServer().addRecipe(oldcobble5);
    363. getServer().addRecipe(oldcobble6);
    364.  
    365. getServer().addRecipe(villager);
    366.  
    367. getServer().addRecipe(wolf);
    368.  
    369. getServer().addRecipe(huhn);
    370.  
    371. getServer().addRecipe(kuh);
    372.  
    373. getServer().addRecipe(schaf);
    374.  
    375. getServer().addRecipe(schwein);
    376.  
    377. getServer().addRecipe(netz1);
    378. getServer().addRecipe(netz2);
    379.  
    380. getServer().addRecipe(sattel1);
    381. getServer().addRecipe(sattel2);
    382. getServer().addRecipe(sattel3);
    383.  
    384. getServer().addRecipe(grassbueschel);
    385.  
    386. getServer().addRecipe(chain_helm1);
    387. getServer().addRecipe(chain_helm2);
    388. getServer().addRecipe(chain_brust);
    389. getServer().addRecipe(chain_bein);
    390. getServer().addRecipe(chain_fuss1);
    391. getServer().addRecipe(chain_fuss2);
    392.  
    393. getServer().addRecipe(rottenflesh);
    394.  
    395. getServer().addRecipe(feder1);
    396. getServer().addRecipe(feder2);
    397. getServer().addRecipe(feder3);
    398. getServer().addRecipe(feder4);
    399. getServer().addRecipe(feder5);
    400. getServer().addRecipe(feder6);
    401.  
    402.  
    403.  
    404. if(Configloader.getnetherrack()){
    405.  
    406. getServer().addRecipe(nrack);
    407. }
    408.  
    409. if(Configloader.getnetherwartseed()){
    410.  
    411. getServer().addRecipe(netherwartseed1);
    412. getServer().addRecipe(netherwartseed2);
    413. }
    414.  
    415. if(Configloader.getblazerod()){
    416.  
    417. getServer().addRecipe(blazerod);
    418. }
    419.  
    420. if(Configloader.getnetherbrick()){
    421.  
    422. getServer().addRecipe(nbrick);
    423. }
    424. if(Configloader.getglowstone()){
    425.  
    426. getServer().addRecipe(glows1);
    427. getServer().addRecipe(glows2);
    428. getServer().addRecipe(glows3);
    429. getServer().addRecipe(glows4);
    430. }
    431. if(Configloader.getsoulsand()){
    432.  
    433. getServer().addRecipe(soul1);
    434. getServer().addRecipe(soul2);
    435. getServer().addRecipe(soul3);
    436. getServer().addRecipe(soul4);
    437. }
    438. if(Configloader.getnetherstar()){
    439.  
    440. getServer().addRecipe(netherstar);
    441. }
    442.  
    443.  
    444. }
    445.  
    446.  
    447. public void onDisable() {
    448. log = Logger.getLogger("Minecraft");
    449. log.info("Returning back to now...");
    450. }
    451. public static Configloader getCFGL() {
    452. return CFGL;
    453. }
    454.  
    455.  
    456.  
    457. }
    458.  


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

    1Rogue Retired Staff

    Try adding a catch on your constructor, if the value returned is null.

    For an example on a couple...

    Code:java
    1.  
    2. private static String PrivateJoinMessage = "online%";
    3. private static boolean netherrack = false;
    4. private static boolean netherbrick = false;
    5. private static boolean glowstone = false;
    6. ....etc...
    7.  
    8.  
    9.  
    10.  
    11.  
    12.  
    13. public Configloader(Recipe Recipe)
    14.  
    15. {
    16. this.plugin = Recipe;
    17.  
    18. if (this.plugin.getConfig().getString("message.privatejoinmessage") != null) {
    19. PrivateJoinMessage = this.plugin.getConfig().getString("message.privatejoinmessage");
    20. }
    21. if (this.plugin.getConfig().getBoolean("netherrack") != null) {
    22. netherrack = this.plugin.getConfig().getBoolean("netherrack");
    23. }
    24. ......etc.....
    25. }
     
  22. Offline

    prinzpommes


    Doesnt solve the Problem. The Config set still isnt displayed. This includes the "Welcome Sentence" and the removal of online%

    pp
     
    ysl3000 likes this.
  23. Offline

    1Rogue Retired Staff

    How are you calling the Configloader in your main class?
     
  24. Offline

    prinzpommes


    do you mean this?
    1. new Configloader(this);
    2. config = this.getConfig();
    3. this.getConfig().options().copyDefaults(true);
    4. this.saveConfig();
     
    ysl3000 likes this.
  25. Offline

    1Rogue Retired Staff

    Where are you setting Configloader equal to something? Can you post the whole main class?
     
  26. Offline

    prinzpommes


    main(Recipe):

    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import java.io.File;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Material;
    7. import org.bukkit.configuration.file.FileConfiguration;
    8. import org.bukkit.inventory.FurnaceRecipe;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.inventory.ShapedRecipe;
    11. import org.bukkit.inventory.ShapelessRecipe;
    12. import org.bukkit.material.SpawnEgg;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import com.github.prinzpommes.Configloader;
    15. import com.github.prinzpommes.MOTD;
    16.  
    17.  
    18.  
    19. public class Recipe extends JavaPlugin {
    20.  
    21. public static Recipe plugin;
    22. public final static Logger logger = Logger.getLogger("Minecraft");
    23. private static String mainDirectory = "plugins/Recipes/";
    24. private static Configloader CFGL;
    25.  
    26. Logger log;
    27.  
    28. protected FileConfiguration config = null;
    29.  
    30. public void onEnable() {
    31. log = Logger.getLogger("Minecraft");
    32. new File(mainDirectory).mkdir();
    33. log.info("Welcome to the Future of Crafting! Recipes has been enabled successfully.");
    34.  
    35. new MOTD (this);
    36. CFGL = new Configloader(this);
    37.  
    38. new Configloader(this);
    39.  
    40. config = this.getConfig();
    41.  
    42. this.getConfig().options().copyDefaults(true);
    43. this.saveConfig();
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51.  
    52.  
    53.  
    54.  
    55.  
    56.  
    57.  
    58. ShapedRecipe sr = new ShapedRecipe(new ItemStack(
    59. Material.ENCHANTMENT_TABLE, 1));
    60. sr.shape(new String[] { " ", " b ", "www" })
    61. .setIngredient('b', Material.BOOKSHELF)
    62. .setIngredient('w', Material.WOOD);
    63.  
    64. ShapedRecipe glows1 = new ShapedRecipe(
    65. new ItemStack(Material.GLOWSTONE));
    66. glows1.shape(new String[] { "rr ", "rr ", " " }).setIngredient('r',
    67. Material.REDSTONE_TORCH_ON);
    68. ShapedRecipe glows2 = new ShapedRecipe(
    69. new ItemStack(Material.GLOWSTONE));
    70. glows2.shape(new String[] { " rr", " rr", " " }).setIngredient('r',
    71. Material.REDSTONE_TORCH_ON);
    72. ShapedRecipe glows3 = new ShapedRecipe(
    73. new ItemStack(Material.GLOWSTONE));
    74. glows3.shape(new String[] { " ", "rr ", "rr " }).setIngredient('r',
    75. Material.REDSTONE_TORCH_ON);
    76. ShapedRecipe glows4 = new ShapedRecipe(
    77. new ItemStack(Material.GLOWSTONE));
    78. glows4.shape(new String[] { " ", " rr", " rr" }).setIngredient('r',
    79. Material.REDSTONE_TORCH_ON);
    80.  
    81. ShapelessRecipe wheat = new ShapelessRecipe(new ItemStack(
    82. Material.SEEDS, 3));
    83. wheat.addIngredient(Material.WHEAT);
    84.  
    85. ShapedRecipe grass1 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    86. grass1.shape(new String[] { "ee ", "ee ", " " }).setIngredient('e',
    87. Material.DIRT);
    88. ShapedRecipe grass2 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    89. grass2.shape(new String[] { " ee", " ee", " " }).setIngredient('e',
    90. Material.DIRT);
    91. ShapedRecipe grass3 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    92. grass3.shape(new String[] { " ", " ee", " ee" }).setIngredient('e',
    93. Material.DIRT);
    94. ShapedRecipe grass4 = new ShapedRecipe(new ItemStack(Material.GRASS, 2));
    95. grass4.shape(new String[] { " ", "ee ", "ee " }).setIngredient('e',
    96. Material.DIRT);
    97.  
    98. ShapedRecipe oldcobble1 = new ShapedRecipe(new ItemStack(
    99. Material.MOSSY_COBBLESTONE, 1));
    100. oldcobble1.shape(new String[] { "g ", "c ", " " })
    101. .setIngredient('g', Material.GRASS)
    102. .setIngredient('c', Material.COBBLESTONE);
    103. ShapedRecipe oldcobble2 = new ShapedRecipe(new ItemStack(
    104. Material.MOSSY_COBBLESTONE, 1));
    105. oldcobble2.shape(new String[] { " g ", " c ", " " })
    106. .setIngredient('g', Material.GRASS)
    107. .setIngredient('c', Material.COBBLESTONE);
    108. ShapedRecipe oldcobble3 = new ShapedRecipe(new ItemStack(
    109. Material.MOSSY_COBBLESTONE, 1));
    110. oldcobble3.shape(new String[] { " g", " c", " " })
    111. .setIngredient('g', Material.GRASS)
    112. .setIngredient('c', Material.COBBLESTONE);
    113. ShapedRecipe oldcobble4 = new ShapedRecipe(new ItemStack(
    114. Material.MOSSY_COBBLESTONE, 1));
    115. oldcobble4.shape(new String[] { " ", "g ", "c " })
    116. .setIngredient('g', Material.GRASS)
    117. .setIngredient('c', Material.COBBLESTONE);
    118. ShapedRecipe oldcobble5 = new ShapedRecipe(new ItemStack(
    119. Material.MOSSY_COBBLESTONE, 1));
    120. oldcobble5.shape(new String[] { " ", " g ", " c " })
    121. .setIngredient('g', Material.GRASS)
    122. .setIngredient('c', Material.COBBLESTONE);
    123. ShapedRecipe oldcobble6 = new ShapedRecipe(new ItemStack(
    124. Material.MOSSY_COBBLESTONE, 1));
    125. oldcobble6.shape(new String[] { " ", " g", " c" })
    126. .setIngredient('g', Material.GRASS)
    127. .setIngredient('c', Material.COBBLESTONE);
    128.  
    129. ShapedRecipe villager = new ShapedRecipe(
    130. new SpawnEgg((byte) 120).toItemStack(1));
    131. villager.shape(new String[] { "rcr", "rer", "rlr" })
    132. .setIngredient('r', Material.EMERALD)
    133. .setIngredient('c', Material.WORKBENCH)
    134. .setIngredient('l', Material.LEATHER)
    135. .setIngredient('e', Material.EGG);
    136.  
    137. ShapedRecipe wolf = new ShapedRecipe(
    138. new SpawnEgg((byte) 95).toItemStack(1));
    139. wolf.shape(new String[] { "rbr", "rer", "rcr" })
    140. .setIngredient('r', Material.EMERALD)
    141. .setIngredient('b', Material.BONE)
    142. .setIngredient('c', Material.ROTTEN_FLESH)
    143. .setIngredient('e', Material.EGG);
    144.  
    145. ShapedRecipe schwein = new ShapedRecipe(
    146. new SpawnEgg((byte) 90).toItemStack(1));
    147. schwein.shape(new String[] { "rbr", "rer", "rcr" })
    148. .setIngredient('r', Material.EMERALD)
    149. .setIngredient('b', Material.BONE)
    150. .setIngredient('c', Material.PORK)
    151. .setIngredient('e', Material.EGG);
    152.  
    153. ShapedRecipe schaf = new ShapedRecipe(
    154. new SpawnEgg((byte) 91).toItemStack(1));
    155. schaf.shape(new String[] { "rbr", "rer", "rcr" })
    156. .setIngredient('r', Material.EMERALD)
    157. .setIngredient('b', Material.BONE)
    158. .setIngredient('c', Material.WOOL)
    159. .setIngredient('e', Material.EGG);
    160.  
    161. ShapedRecipe kuh = new ShapedRecipe(
    162. new SpawnEgg((byte) 92).toItemStack(1));
    163. kuh.shape(new String[] { "rbr", "rer", "rcr" })
    164. .setIngredient('r', Material.EMERALD)
    165. .setIngredient('b', Material.BONE)
    166. .setIngredient('c', Material.RAW_BEEF)
    167. .setIngredient('e', Material.EGG);
    168.  
    169. ShapedRecipe huhn = new ShapedRecipe(
    170. new SpawnEgg((byte) 93).toItemStack(1));
    171. huhn.shape(new String[] { "rbr", "rer", "rcr" })
    172. .setIngredient('r', Material.EMERALD)
    173. .setIngredient('b', Material.BONE)
    174. .setIngredient('c', Material.RAW_CHICKEN)
    175. .setIngredient('e', Material.EGG);
    176.  
    177. ShapelessRecipe netz1 = new ShapelessRecipe(new ItemStack(
    178. Material.STRING, 3));
    179. netz1.addIngredient(Material.WEB);
    180.  
    181. ShapedRecipe netz2 = new ShapedRecipe(new ItemStack(Material.WEB, 1));
    182. netz2.shape(new String[] { "s s", " s ", "s s" }).setIngredient('s',
    183. Material.STRING);
    184.  
    185. ShapelessRecipe sattel1 = new ShapelessRecipe(new ItemStack(
    186. Material.LEATHER, 3));
    187. sattel1.addIngredient(Material.SADDLE);
    188.  
    189. ShapedRecipe sattel2 = new ShapedRecipe(new ItemStack(Material.SADDLE,
    190. 1));
    191. sattel2.shape(new String[] { "l l", "lll", " " }).setIngredient('l',
    192. Material.LEATHER);
    193.  
    194. ShapedRecipe sattel3 = new ShapedRecipe(new ItemStack(Material.SADDLE,
    195. 1));
    196. sattel3.shape(new String[] { " ", "l l", "lll" }).setIngredient('l',
    197. Material.LEATHER);
    198.  
    199. ShapelessRecipe grassbueschel = new ShapelessRecipe(new ItemStack(
    200. Material.LONG_GRASS, 3, (byte) 1));
    201. grassbueschel.addIngredient(Material.GRASS);
    202.  
    203. ShapedRecipe chain_helm1 = new ShapedRecipe(new ItemStack(
    204. Material.CHAINMAIL_HELMET, 1));
    205. chain_helm1.shape(new String[] { "gdg", "g g", " " })
    206. .setIngredient('g', Material.GLASS)
    207. .setIngredient('d', Material.DIAMOND);
    208.  
    209. ShapedRecipe chain_helm2 = new ShapedRecipe(new ItemStack(
    210. Material.CHAINMAIL_HELMET, 1));
    211. chain_helm2.shape(new String[] { " ", "gdg", "g g" })
    212. .setIngredient('g', Material.GLASS)
    213. .setIngredient('d', Material.DIAMOND);
    214.  
    215. ShapedRecipe chain_brust = new ShapedRecipe(new ItemStack(
    216. Material.CHAINMAIL_CHESTPLATE, 1));
    217. chain_brust.shape(new String[] { "g g", "gdg", "ggg" })
    218. .setIngredient('g', Material.GLASS)
    219. .setIngredient('d', Material.DIAMOND);
    220.  
    221. ShapedRecipe chain_bein = new ShapedRecipe(new ItemStack(
    222. Material.CHAINMAIL_LEGGINGS, 1));
    223. chain_bein.shape(new String[] { "gdg", "g g", "g g" })
    224. .setIngredient('g', Material.GLASS)
    225. .setIngredient('d', Material.DIAMOND);
    226.  
    227. ShapedRecipe chain_fuss1 = new ShapedRecipe(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
    228. chain_fuss1.shape(new String[] { "g g", "g g", " " })
    229. .setIngredient('g', Material.GLASS);
    230.  
    231. ShapedRecipe chain_fuss2 = new ShapedRecipe(new ItemStack(Material.CHAINMAIL_BOOTS, 1));
    232. chain_fuss2.shape(new String[] { " ", "g g", "g g" })
    233. .setIngredient('g', Material.GLASS);
    234.  
    235. ShapedRecipe soul1 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    236. soul1.shape(new String[] { "gg ", "gg ", " " })
    237. .setIngredient('g',Material.GRAVEL);
    238. ShapedRecipe soul2 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    239. soul2.shape(new String[] { " gg", " gg", " " })
    240. .setIngredient('g',Material.GRAVEL);
    241. ShapedRecipe soul3 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    242. soul3.shape(new String[] { " ", "gg ", "gg " })
    243. .setIngredient('g',Material.GRAVEL);
    244. ShapedRecipe soul4 = new ShapedRecipe(new ItemStack(Material.SOUL_SAND, 1));
    245. soul4.shape(new String[] { " ", " gg", " gg" })
    246. .setIngredient('g',Material.GRAVEL);
    247.  
    248. ShapedRecipe blazerod = new ShapedRecipe(new ItemStack(Material.BLAZE_ROD, 1));
    249. blazerod.shape(new String[] { "ggg", "gbg", "ggg" })
    250. .setIngredient('g', Material.GOLD_BLOCK)
    251. .setIngredient('b',Material.STICK);
    252.  
    253. ShapedRecipe netherstar = new ShapedRecipe(new ItemStack(Material.NETHER_STAR, 1));
    254. netherstar.shape(new String[] { " d ", "dbd", " d " })
    255. .setIngredient('d', Material.DIAMOND)
    256. .setIngredient('b',Material.BLAZE_POWDER);
    257.  
    258. ShapedRecipe netherwartseed1 = new ShapedRecipe(new ItemStack(Material.NETHER_STALK, 6));
    259. netherwartseed1.shape(new String[] { "nnn", "nrn", "nnn" })
    260. .setIngredient('n', Material.NETHERRACK)
    261. .setIngredient('r',Material.RED_MUSHROOM);
    262.  
    263. ShapedRecipe netherwartseed2 = new ShapedRecipe(new ItemStack(Material.NETHER_STALK, 3));
    264. netherwartseed2.shape(new String[] { "nnn", "nrn", "nnn" })
    265. .setIngredient('n', Material.NETHERRACK)
    266. .setIngredient('r',Material.BROWN_MUSHROOM);
    267.  
    268. ShapedRecipe feder1 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    269. feder1.shape(new String[] { "p ", "s ", " " })
    270. .setIngredient('p', Material.PAPER)
    271. .setIngredient('s',Material.STRING);
    272. ShapedRecipe feder2 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    273. feder2.shape(new String[] { " p ", " s ", " " })
    274. .setIngredient('p', Material.PAPER)
    275. .setIngredient('s',Material.STRING);
    276. ShapedRecipe feder3 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    277. feder3.shape(new String[] { " p", " s", " " })
    278. .setIngredient('p', Material.PAPER)
    279. .setIngredient('s',Material.STRING);
    280. ShapedRecipe feder4 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    281. feder4.shape(new String[] { " ", "p ", "s " })
    282. .setIngredient('p', Material.PAPER)
    283. .setIngredient('s',Material.STRING);
    284. ShapedRecipe feder5 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    285. feder5.shape(new String[] { " ", " p ", " s " })
    286. .setIngredient('p', Material.PAPER)
    287. .setIngredient('s',Material.STRING);
    288. ShapedRecipe feder6 = new ShapedRecipe(new ItemStack(Material.FEATHER, 1));
    289. feder6.shape(new String[] { " ", " p", " s" })
    290. .setIngredient('p', Material.PAPER)
    291. .setIngredient('s',Material.STRING);
    292.  
    293.  
    294. FurnaceRecipe sponge = new FurnaceRecipe(new ItemStack(Material.SPONGE,
    295. 1), Material.SANDSTONE);
    296. FurnaceRecipe ironingot1 = new FurnaceRecipe(new ItemStack(
    297. Material.IRON_INGOT, 1), Material.IRON_PICKAXE);
    298. FurnaceRecipe ironingot2 = new FurnaceRecipe(new ItemStack(
    299. Material.IRON_INGOT, 1), Material.IRON_AXE);
    300. FurnaceRecipe ironingot3 = new FurnaceRecipe(new ItemStack(
    301. Material.IRON_INGOT, 1), Material.IRON_HOE);
    302. FurnaceRecipe ironingot4 = new FurnaceRecipe(new ItemStack(
    303. Material.IRON_INGOT, 1), Material.IRON_SWORD);
    304. FurnaceRecipe goldingot1 = new FurnaceRecipe(new ItemStack(
    305. Material.GOLD_INGOT, 1), Material.GOLD_PICKAXE);
    306. FurnaceRecipe goldingot2 = new FurnaceRecipe(new ItemStack(
    307. Material.GOLD_INGOT, 1), Material.GOLD_AXE);
    308. FurnaceRecipe goldingot3 = new FurnaceRecipe(new ItemStack(
    309. Material.GOLD_INGOT, 1), Material.GOLD_HOE);
    310. FurnaceRecipe goldingot4 = new FurnaceRecipe(new ItemStack(
    311. Material.GOLD_INGOT, 1), Material.GOLD_SWORD);
    312. FurnaceRecipe diamond1 = new FurnaceRecipe(new ItemStack(
    313. Material.DIAMOND, 1), Material.DIAMOND_PICKAXE);
    314. FurnaceRecipe diamond2 = new FurnaceRecipe(new ItemStack(
    315. Material.DIAMOND, 1), Material.DIAMOND_AXE);
    316. FurnaceRecipe diamond3 = new FurnaceRecipe(new ItemStack(
    317. Material.DIAMOND, 1), Material.DIAMOND_HOE);
    318. FurnaceRecipe diamond4 = new FurnaceRecipe(new ItemStack(
    319. Material.DIAMOND, 1), Material.DIAMOND_SWORD);
    320. FurnaceRecipe nbrick = new FurnaceRecipe(new ItemStack(
    321. Material.NETHER_BRICK, 1), Material.NETHERRACK);
    322. FurnaceRecipe nrack = new FurnaceRecipe(new ItemStack(
    323. Material.NETHERRACK, 1), Material.GRAVEL);
    324. FurnaceRecipe rottenflesh = new FurnaceRecipe(new ItemStack(
    325. Material.RAW_BEEF, 1), Material.ROTTEN_FLESH);
    326. FurnaceRecipe gravel = new FurnaceRecipe(new ItemStack(
    327. Material.GRAVEL, 1), Material.DIRT);
    328.  
    329.  
    330. getServer().addRecipe(sponge);
    331.  
    332. getServer().addRecipe(gravel);
    333.  
    334. getServer().addRecipe(sr);
    335.  
    336. getServer().addRecipe(ironingot1);
    337. getServer().addRecipe(ironingot2);
    338. getServer().addRecipe(ironingot3);
    339. getServer().addRecipe(ironingot4);
    340.  
    341. getServer().addRecipe(goldingot1);
    342. getServer().addRecipe(goldingot2);
    343. getServer().addRecipe(goldingot3);
    344. getServer().addRecipe(goldingot4);
    345.  
    346. getServer().addRecipe(diamond1);
    347. getServer().addRecipe(diamond2);
    348. getServer().addRecipe(diamond3);
    349. getServer().addRecipe(diamond4);
    350.  
    351. getServer().addRecipe(wheat);
    352.  
    353. getServer().addRecipe(grass1);
    354. getServer().addRecipe(grass2);
    355. getServer().addRecipe(grass3);
    356. getServer().addRecipe(grass4);
    357.  
    358. getServer().addRecipe(oldcobble1);
    359. getServer().addRecipe(oldcobble2);
    360. getServer().addRecipe(oldcobble3);
    361. getServer().addRecipe(oldcobble4);
    362. getServer().addRecipe(oldcobble5);
    363. getServer().addRecipe(oldcobble6);
    364.  
    365. getServer().addRecipe(villager);
    366.  
    367. getServer().addRecipe(wolf);
    368.  
    369. getServer().addRecipe(huhn);
    370.  
    371. getServer().addRecipe(kuh);
    372.  
    373. getServer().addRecipe(schaf);
    374.  
    375. getServer().addRecipe(schwein);
    376.  
    377. getServer().addRecipe(netz1);
    378. getServer().addRecipe(netz2);
    379.  
    380. getServer().addRecipe(sattel1);
    381. getServer().addRecipe(sattel2);
    382. getServer().addRecipe(sattel3);
    383.  
    384. getServer().addRecipe(grassbueschel);
    385.  
    386. getServer().addRecipe(chain_helm1);
    387. getServer().addRecipe(chain_helm2);
    388. getServer().addRecipe(chain_brust);
    389. getServer().addRecipe(chain_bein);
    390. getServer().addRecipe(chain_fuss1);
    391. getServer().addRecipe(chain_fuss2);
    392.  
    393. getServer().addRecipe(rottenflesh);
    394.  
    395. getServer().addRecipe(feder1);
    396. getServer().addRecipe(feder2);
    397. getServer().addRecipe(feder3);
    398. getServer().addRecipe(feder4);
    399. getServer().addRecipe(feder5);
    400. getServer().addRecipe(feder6);
    401.  
    402.  
    403.  
    404. if(Configloader.getnetherrack()){
    405.  
    406. getServer().addRecipe(nrack);
    407. }
    408.  
    409. if(Configloader.getnetherwartseed()){
    410.  
    411. getServer().addRecipe(netherwartseed1);
    412. getServer().addRecipe(netherwartseed2);
    413. }
    414.  
    415. if(Configloader.getblazerod()){
    416.  
    417. getServer().addRecipe(blazerod);
    418. }
    419.  
    420. if(Configloader.getnetherbrick()){
    421.  
    422. getServer().addRecipe(nbrick);
    423. }
    424. if(Configloader.getglowstone()){
    425.  
    426. getServer().addRecipe(glows1);
    427. getServer().addRecipe(glows2);
    428. getServer().addRecipe(glows3);
    429. getServer().addRecipe(glows4);
    430. }
    431. if(Configloader.getsoulsand()){
    432.  
    433. getServer().addRecipe(soul1);
    434. getServer().addRecipe(soul2);
    435. getServer().addRecipe(soul3);
    436. getServer().addRecipe(soul4);
    437. }
    438. if(Configloader.getnetherstar()){
    439.  
    440. getServer().addRecipe(netherstar);
    441. }
    442.  
    443.  
    444. }
    445.  
    446.  
    447. public void onDisable() {
    448. log = Logger.getLogger("Minecraft");
    449. log.info("Returning back to now...");
    450. }
    451. public static Configloader getCFGL() {
    452. return CFGL;
    453. }
    454.  
    455.  
    456.  
    457. }
    458.  



    Configloader:

    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import com.github.prinzpommes.Recipe;
    4.  
    5. public class Configloader {
    6.  
    7. private Recipe plugin;
    8.  
    9. private static String PrivateJoinMessage;
    10. private static boolean netherrack;
    11. private static boolean netherbrick;
    12. private static boolean glowstone;
    13. private static boolean soulsand;
    14. private static boolean blazerod;
    15. private static boolean netherstar;
    16. private static boolean netherwartseed;
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23. public Configloader(Recipe Recipe)
    24.  
    25. {
    26. this.plugin = Recipe;
    27.  
    28. PrivateJoinMessage = this.plugin.getConfig().getString("message.privatejoinmessage");
    29.  
    30.  
    31. netherrack = this.plugin.getConfig().getBoolean("netherrack");
    32. netherbrick = this.plugin.getConfig().getBoolean("netherbrick");
    33. glowstone = this.plugin.getConfig ().getBoolean("glowstone");
    34. soulsand = this.plugin.getConfig ().getBoolean("soulsand");
    35. blazerod = this.plugin.getConfig ().getBoolean("blazerod");
    36. netherstar = this.plugin.getConfig().getBoolean("netherstar");
    37. netherwartseed = this.plugin.getConfig().getBoolean("netherwartseed");
    38. }
    39.  
    40.  
    41.  
    42. public static boolean getnetherrack(){
    43. return netherrack;
    44. }
    45. public static boolean getnetherbrick(){
    46. return netherbrick;
    47. }
    48. public static boolean getglowstone(){
    49. return glowstone;
    50. }
    51. public static boolean getsoulsand(){
    52. return soulsand;
    53. }
    54. public static boolean getblazerod(){
    55. return blazerod;
    56. }
    57. public static boolean getnetherstar(){
    58. return netherstar;
    59. }
    60. public static boolean getnetherwartseed(){
    61. return netherwartseed;
    62. }
    63.  
    64.  
    65. public static String getPrivatJoinMessage(){
    66. return PrivateJoinMessage;
    67. }
    68.  
    69.  
    70. }
    71.  


    MOTD:

    Code:java
    1. package com.github.prinzpommes;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8. import com.github.prinzpommes.Recipe;
    9. import org.bukkit.event.EventHandler;
    10.  
    11.  
    12.  
    13. public class MOTD implements Listener {
    14.  
    15.  
    16.  
    17. private static String PrivateJoinMessage;
    18.  
    19. public MOTD(Recipe plugin) {
    20. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    21. }
    22.  
    23.  
    24. @EventHandler
    25.  
    26. public void message(PlayerJoinEvent event) {
    27.  
    28. Recipe.getCFGL();
    29. PrivateJoinMessage = Configloader.getPrivatJoinMessage();
    30. if (PrivateJoinMessage == null) {
    31. PrivateJoinMessage = "online%";
    32. }
    33. PrivateJoinMessage = PrivateJoinMessage.replace("online%",
    34. ChatColor.GRAY + "Online ("
    35. + Bukkit.getServer().getOnlinePlayers().length
    36. + "/" + Bukkit.getMaxPlayers() + "): "
    37. + listPlayers());
    38.  
    39.  
    40. event.getPlayer().sendMessage(PrivateJoinMessage);
    41. }
    42.  
    43.  
    44.  
    45. public static String listPlayers() {
    46.  
    47.  
    48. Player ar[] = Bukkit.getOnlinePlayers();
    49. String liste = "";
    50. for (Player p : Bukkit.getOnlinePlayers()) {
    51.  
    52.  
    53. if (p.equals(ar[Bukkit.getOnlinePlayers().length - 1])) {
    54.  
    55.  
    56. liste += p.getDisplayName();
    57. } else {
    58.  
    59.  
    60. liste += p.getDisplayName() + ", ";
    61. }
    62. }
    63.  
    64.  
    65. return liste;
    66. }
    67.  
    68.  
    69. }
    70.  
     
    ysl3000 likes this.
  27. Offline

    1Rogue Retired Staff

    In your onEnable, try this:

    Show Spoiler

    Currently:
    Code:java
    1.  
    2. log = Logger.getLogger("Minecraft");
    3. new File(mainDirectory).mkdir();
    4. log.info("Welcome to the Future of Crafting! Recipes has been enabled successfully.");
    5.  
    6. new MOTD (this);
    7. CFGL = new Configloader(this);
    8.  
    9. new Configloader(this);
    10.  
    11. config = this.getConfig();
    12.  
    13. this.getConfig().options().copyDefaults(true);
    14. this.saveConfig();


    Updated:
    Code:java
    1.  
    2. log = Logger.getLogger("Minecraft");
    3. File pldir = new File(mainDirectory);
    4. if (!pldir.exists()) {
    5. pldir.mkdir();
    6. }
    7. log.info("Welcome to the Future of Crafting! Recipes has been enabled successfully.");
    8. CFGL = new Configloader(this);
    9. config = this.getConfig();
    10.  
    11. new MOTD (this);


    Also you should set "new MOTD(this)" to a MOTD variable.
     
  28. Offline

    CubieX

    Your config file would be helpful. Perharps the path to the key you try to get from config is not right.
     
  29. Offline

    1Rogue Retired Staff

    They were also trying to call from the config before it was loaded into the plugin.
     
  30. Offline

    prinzpommes

    Code:
    #################################################################
    #via this config you can enable "nether"-Features. This is for  #
    #people who like to disable the nether!                        #
    #################################################################
    PrivateJoinMessage: Hi there! Have a nice stay! online%
    ###
    netherrack: true
    netherbrick: true
    glowstone: true
    soulsand: true
    blazerod: true
    netherstar: true
    netherwartseed: true
    The Config-File

    btw 1Rogue:

    this.getConfig().options().copyDefaults(true);
    this.saveConfig();

    that was missing right? the config wasnt even copied ;)

    + Still isnt working, neither does he display the message correctly, nor i am able to change anything.
     
    ysl3000 likes this.
Thread Status:
Not open for further replies.

Share This Page