Give Player Random Item with is in Config

Discussion in 'Plugin Help/Development/Requests' started by AlexanderL123, Nov 27, 2014.

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

    AlexanderL123

    Hello, Guys, im new here and i want to create a Advent Plugin, now i have i big problem, when i start my plugin i get an Error, but i don't know what this error mean and how i fix it.

    Here is my Error:
    Code:
    [22:52:34 ERROR]: Could not load 'plugins\AdventPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Name cannot be null
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[spigot165
    7.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:336) ~[spigot16
    57.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:258) [spigot16
    57.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:369) [spigot1657.
    jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:864) [spigot1657.jar:g
    it-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.Bukkit.reload(Bukkit.java:301) [spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2
    e95]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot1657.jar:g
    it-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) [spigot1
    657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [s
    pigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [spigot1657.jar
    :git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot1657.ja
    r:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    Caused by: java.lang.IllegalArgumentException: Name cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot1657.jar:git-Spigot-1
    .7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.getWorld(CraftServer.java:1119) ~[spigot1657.j
    ar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.Bukkit.getWorld(Bukkit.java:271) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge
    0f2e95]
            at advent.Advent.<init>(Advent.java:32) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_60]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_60]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_60]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_60]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_60]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot1657.j
    ar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot165
    7.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            ... 14 more
    And here my Code:
    Code:java
    1. package advent;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Random;
    5.  
    6. import net.minecraft.server.v1_7_R4.Block;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.Location;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15. import org.bukkit.inventory.ItemStack;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class Advent extends JavaPlugin implements Listener{
    19.  
    20. public void onEnable() {
    21. loadConfig();
    22. getServer().getPluginManager().registerEvents(this, this);
    23. itemliste = new ArrayList<Integer>();
    24. }
    25.  
    26. String ConfigBlockid = "Config.Blockid";
    27. String ConfigWorld = "Config.World";
    28. String ConfigX = "Config.X";
    29. String ConfigY = "Config.Y";
    30. String ConfigZ = "Config.Z";
    31. String List = "Config.ItemList";
    32. Location loc = new Location(Bukkit.getWorld(getConfig().getString(ConfigWorld)),
    33. getConfig().getInt(ConfigX),
    34. getConfig().getInt(ConfigY),
    35. getConfig().getInt(ConfigZ));
    36.  
    37. ArrayList<Integer> itemliste = null;
    38.  
    39. public void onDisable() {
    40.  
    41. }
    42.  
    43. @EventHandler
    44. public void onClick(PlayerInteractEvent e){
    45. Player p = e.getPlayer();
    46. if(e.getClickedBlock()!=Block.getById(getConfig().getInt(ConfigBlockid)))return;
    47. if(e.getClickedBlock().getLocation()!=loc)return;
    48. Random random = new Random(itemliste.size());
    49. int zahl = random.nextInt();
    50. ItemStack item = new ItemStack(itemliste.get(zahl),1);
    51. p.getInventory().addItem(item);
    52. p.updateInventory();
    53. p.sendMessage("&aYou get a advent present!");
    54. p.sendMessage("&a1 " + item.getType().name());
    55. e.setCancelled(true);
    56. }
    57.  
    58. public void loadConfig(){
    59. getConfig().addDefault(ConfigBlockid, 52);
    60. getConfig().addDefault(ConfigWorld, "world");
    61. getConfig().addDefault(ConfigX, 0);
    62. getConfig().addDefault(ConfigY, 250);
    63. getConfig().addDefault(ConfigZ, 0);
    64. int[] listOfStrings = {264,263};
    65. getConfig().addDefault(List, listOfStrings);
    66. for(int i=0; i<getConfig().getList(List).size(); i++){
    67. itemliste.add((Integer) getConfig().getList(List).get(i));
    68. }
    69. FileConfiguration cfg = getConfig();
    70. cfg.options().copyDefaults(true);
    71. saveConfig();
    72. }
    73.  
    74. }
    75.  
     
  2. Offline

    timtower Administrator Moderator

    Moved to Bukkit alternatives.
    AlexanderL123 Please show your plugin.yml
     
  3. Offline

    AlexanderL123

    My plugin.yml looks normaly, there isn't any thing wrong, i will post it

    Code:
    name: AdventPlugin
    version: 1.0
    author: AlexanderL123
     
    main: advent.Advent
     
  4. Offline

    timtower Administrator Moderator

    AlexanderL123 Whoops, misread the log. Config is empty when you load the plugin, getConfig().getString(ConfigWorld), that returns null, worldname on Bukkit.getWorld can't be null
     
  5. Offline

    AlexanderL123

    Now im getting an error in line 66 where my for loop is, i think it is totaly wrong, so, how i can add from a Config File all IDs ?
     
  6. Offline

    timtower Administrator Moderator

  7. Offline

    AlexanderL123

    Now im getting a YAML Error on load and an Error on line 71

    Code:
    [23:16:08 ERROR]: Error occurred while enabling AdventPlugin v1.0 (Is it up to date?)
    org.yaml.snakeyaml.error.YAMLException: Arrays of primitives are not fully supported.
            at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:101) ~[
    spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:161)
    ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter
    .java:213) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.configuration.file.YamlRepresenter$RepresentConfigurationSection.representData
    (YamlRepresenter.java:23) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:95) ~[s
    pigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:161)
    ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter
    .java:213) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:95) ~[s
    pigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:65) ~[spigo
    t1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:271) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208
    -ge0f2e95]
            at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:262) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208
    -ge0f2e95]
            at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:234) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208
    -ge0f2e95]
            at org.yaml.snakeyaml.Yaml.dump(Yaml.java:209) ~[spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge
    0f2e95]
            at org.bukkit.configuration.file.YamlConfiguration.saveToString(YamlConfiguration.java:40) ~
    [spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguration.java:103) ~[spigot
    1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.plugin.java.JavaPlugin.saveConfig(JavaPlugin.java:225) ~[spigot1657.jar:git-Sp
    igot-1.7.9-R0.2-208-ge0f2e95]
            at advent.Advent.loadConfig(Advent.java:71) ~[?:?]
            at advent.Advent.onEnable(Advent.java:23) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[spigot1657.jar:git-Sp
    igot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [spigot16
    57.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [spigot1
    657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:476) [spigot1657.j
    ar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:394) [spigot165
    7.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:866) [spigot1657.jar:g
    it-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.Bukkit.reload(Bukkit.java:301) [spigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2
    e95]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [spigot1657.jar:g
    it-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) [spigot1
    657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [s
    pigot1657.jar:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [spigot1657.jar
    :git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot1657.ja
    r:git-Spigot-1.7.9-R0.2-208-ge0f2e95]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot1657.jar:
    git-Spigot-1.7.9-R0.2-208-ge0f2e95]
    Now, i have addet Debugs Messages but, only Debug1 and the Location will Printout, but not Debug2

    Code:java
    1. @EventHandler
    2. public void onClick(PlayerInteractEvent e){
    3. Player p = e.getPlayer();
    4. if(e.getClickedBlock().getType()!=Material.CHEST)return;
    5. System.out.println("Debug1");
    6. Location loc = new Location(Bukkit.getWorld(getConfig().getString(ConfigWorld)),
    7. getConfig().getInt(ConfigX),
    8. getConfig().getInt(ConfigY),
    9. getConfig().getInt(ConfigZ));
    10. System.out.println(loc);
    11. if(e.getClickedBlock().getLocation()!=loc)return;
    12. System.out.println("Debug2");
    13. Random random = new Random(getConfig().getIntegerList(List).size());
    14. int zahl = random.nextInt();
    15. ItemStack item = new ItemStack(getConfig().getIntegerList(List).get(zahl),1);
    16. System.out.println("Debug3");
    17. p.getInventory().addItem(item);
    18. System.out.println("Debug4");
    19. p.updateInventory();
    20. System.out.println("Debug5");
    21. p.sendMessage("&aYou get a advent present!");
    22. p.sendMessage("&a1 " + item.getType().name());
    23. System.out.println("Debug6");
    24. e.setCancelled(true);
    25. }


    EDIT by TImtower: merged double posts
     
Thread Status:
Not open for further replies.

Share This Page