ArrayList<Material> cannot be passed

Discussion in 'Plugin Development' started by sickray34s, Jan 16, 2014.

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

    sickray34s

    Hello guys i'm having a slight prob with this line of code i have been stuck on it for two days and so far i got to this:
    Code:java
    1. /*code by sickray34s (A.K.A) Kevin Connelly
    2. * 1.7.4 version
    3. * beta stage
    4. */
    5. package com.sickray34s;
    6.  
    7. import java.io.File;
    8. import java.util.ArrayList;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.Location;
    12. import org.bukkit.Material;
    13. import org.bukkit.Sound;
    14. import org.bukkit.World;
    15. import org.bukkit.configuration.file.FileConfiguration;
    16. import org.bukkit.entity.Item;
    17. import org.bukkit.event.EventHandler;
    18. import org.bukkit.event.Listener;
    19. import org.bukkit.event.block.Action;
    20. import org.bukkit.event.player.PlayerInteractEvent;
    21. import org.bukkit.inventory.ItemStack;
    22. import org.bukkit.plugin.java.JavaPlugin;
    23.  
    24.  
    25.  
    26.  
    27. public class DropPartyLogic extends JavaPlugin implements Listener {
    28. FileConfiguration config;
    29.  
    30.  
    31.  
    32.  
    33. public void onEnable(){
    34. getLogger().info("onEnable has been invoked!");
    35.  
    36.  
    37. try{
    38.  
    39.  
    40.  
    41. config = getConfig();
    42. File ItemsConfig = new File(getDataFolder() + "ItemsConfig.yml");
    43. if(!ItemsConfig.exists()){
    44. getDataFolder().mkdir();
    45. if(!config.contains("Items.list")){
    46. config.set("Item.list", "DIAMOND,GOLD_INGOT");
    47.  
    48. config.options().copyDefaults(true);
    49. saveConfig();
    50. }
    51.  
    52.  
    53. }
    54. }catch(Exception e1){
    55. e1.printStackTrace();
    56. }
    57.  
    58.  
    59.  
    60.  
    61. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    62. }
    63. public void onDisable(){
    64. getLogger().info("onDisable has been invoked!");
    65.  
    66.  
    67. }
    68.  
    69.  
    70. @EventHandler
    71. public void onPlayerUse(PlayerInteractEvent event){
    72. ArrayList<Material> items = new ArrayList<Material>();
    73. for(String s : config.getString("Items.list").split(",")){
    74.  
    75. Material m = Material.getMaterial(s.trim().replace(' ' , '_').toUpperCase());
    76. if(m != null) items.add(m);
    77.  
    78.  
    79.  
    80.  
    81.  
    82. }
    83.  
    84.  
    85.  
    86.  
    87. if(event.getAction().equals(Action.LEFT_CLICK_AIR)){
    88. if(event.getPlayer().getItemInHand().getType().equals(Material.BLAZE_ROD) && event.getPlayer().hasPermission("dps.wand")){
    89. Location loc = event.getPlayer().getLocation();
    90. World world = event.getPlayer().getWorld();
    91. ItemStack item = new ItemStack(items.get((int) Math.random() * items.size()), 1);
    92. Item postitem = world.dropItem(loc, item);
    93. event.getPlayer().getWorld().playSound(loc,Sound.NOTE_SNARE_DRUM,1, 0);
    94. postitem.setVelocity(loc.getDirection().multiply(1.7));
    95.  
    96. }
    97. }
    98. }
    99. }
    100.  

    What i want to do is get a list of Materials from a config.yml and randomly drop a item from that list. if anyone can help please reply.
     
  2. Offline

    Necrodoom

    moved to correct section.
     
  3. Offline

    1Rogue Retired Staff

    What line has the actual error?
     
  4. Offline

    DevRosemberg

    Um, he is doing .mkdir() to the datafolder by checking if the ItemsConfig excists.
     
  5. Offline

    sickray34s

    it says
    Code:
    [10:28:38 ERROR]: Could not pass event PlayerInteractEvent to DropPartyStick v5.
    0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:481) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:466) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:191) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7
    .2-R0.2-b2974jnks]
            at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerInte
    ractEvent(CraftEventFactory.java:161) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7
    .2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :978) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.a(SourceFile:43
    ) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInArmAnimation.handle(SourceFi
    le:9) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.NullPointerException
            at com.sickray34s.DropPartyLogic.onPlayerUse(DropPartyLogic.java:74) ~[?
    :?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _11]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _11]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_11]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_11]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
            ... 15 more
     
  6. Offline

    LucasEmanuel

    It seems you have removed a lot of code in your paste, including what could be causing the issue. I don't see any line in there that can explain the error you stated in the heading for this thread.
     
  7. Offline

    1Rogue Retired Staff

    That and line 74 is blank, can you get an updated error?
     
  8. Offline

    sickray34s

    all i get is a PlayerInteractEventv error
    Code:
    [10:28:38 ERROR]: Could not pass event PlayerInteractEvent to DropPartyStick v5.
    0
    it could as well be line 91
    Code:
     ItemStack item = new ItemStack(materials.get((int) Math.random() * materials.size()), 1);
    Can anyone help?

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

    sickray34s

  10. Offline

    L33m4n123



    then put your stuff into a try-catch block and print the stacktrace then
     
  11. Offline

    sickray34s

    were would i put that try-catch?

    Bump

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

    Sagacious_Zed Bukkit Docs

    Try blocks should surround code which throws checked exceptions if you intend to deal with the exception. In contrast to letting the exception return up the call stack.
     
  13. Offline

    sickray34s

    i used a try catch but it did not help much, Bump.
     
Thread Status:
Not open for further replies.

Share This Page