(Moved) Respawning a Chest + Its Inventory, IllegalPluginAccessException

Discussion in 'Plugin Development' started by Gabum, Jan 6, 2014.

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

    Gabum

    Hello Minecraft Dudes/Mates/Dudettes/Matesses!
    I'm trying to create a plugin for loot chests, that gives the player a random item from a chest when he right-clicks it, and then disappears for a time.

    But I'm getting problems right now. I have this code:
    Code:java
    1. public void RespawnChest(final Chest chest, final Location loc){
    2.  
    3. final Inventory inv = chest.getBlockInventory();
    4. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("DungeonsAndEnderdragons"), new Runnable(){
    5.  
    6. int time = 100;
    7. Location l = loc;
    8.  
    9. public void run(){
    10.  
    11. if (loc.getBlock().getType() != Material.AIR){
    12. loc.getBlock().setType(Material.AIR);
    13. }
    14.  
    15. if (time >= 0){
    16. loc.getBlock().setType(Material.CHEST);
    17. Chest c = (Chest) loc.getBlock().getState();
    18. for (ItemStack i : inv.getContents()){
    19. c.getInventory().addItem(i);
    20. }
    21. return;
    22. }
    23.  
    24. time--;
    25.  
    26. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("DungeonsAndEnderdragons"), this, 20L);
    27.  
    28. }
    29.  
    30. });
    31.  
    32. }


    But I'm getting a IllegalPluginAccessException at this line (first time it comes):
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("DungeonsAndEnderdragons"), this, 20L);


    The Name of the Plugin is DungeonsAndEnderdragons, I controlled it several times. I already changed
    Code:java
    1. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getServer().getPluginManager().getPlugin("DungeonsAndEnderdragons")


    to "this", but the error keeps there. The name of the Plugin must be right. I'm pretty sure about that.

    So, do you have an idea why it throws the exception?

    Gabum
     
  2. Offline

    bigteddy98

    This is the format it should be, yours isn't in this format:
    Code:java
    1. scheduleSyncDelayedTask(Plugin plugin, Runnable task, long delay)
     
  3. Offline

    Gabum

    Thx for the fast answer, but I fixed the bug already.
    It seems like it had something to do with that the class the method was in also extended JavaPlugin. I moved the method into the main class, and call it from there. Now it works.
     
Thread Status:
Not open for further replies.

Share This Page