Solved java.lang.IllegalAccessError ??? How do I fix?

Discussion in 'Plugin Development' started by wreed12345, Jul 23, 2013.

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

    wreed12345

    Did some research and none of it made sense for my plugin and this errror, I hope someone with experience in this field can possibly help me out I have never seen this error before...

    Code:
    22:58:52 [SEVERE] Could not pass event BlockPlaceEvent to RCChestLimit v0.0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callBlockPlace
    Event(CraftEventFactory.java:114)
            at net.minecraft.server.v1_6_R2.ItemBlock.processBlockPlace(ItemBlock.ja
    va:89)
            at net.minecraft.server.v1_6_R2.ItemBlock.interactWith(ItemBlock.java:73
    )
            at net.minecraft.server.v1_6_R2.ItemStack.placeItem(ItemStack.java:79)
            at net.minecraft.server.v1_6_R2.PlayerInteractManager.interact(PlayerInt
    eractManager.java:389)
            at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java
    :630)
            at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java
    :118)
            at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:5
    90)
            at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:4
    86)
            at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java
    :419)
            at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:5
    82)
    Caused by: java.lang.IllegalAccessError: tried to access field io.github.wreed12
    345.TempPlayers.players from class io.github.wreed12345.RCChestLimit
            at io.github.wreed12345.RCChestLimit.placeBlock(RCChestLimit.java:95)
            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.ja
    va:425)
            ... 19 more
    >
    If you need to see any of the classes let me know.

    I know this error comes up when trying to access fields you can not access, but everything in the class is public so I don't see why its not working :(

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

    SnipsRevival

    Can we see some code please?
     
  3. Offline

    wreed12345

    My main class for the plugin:
    Code:java
    1. package io.github.wreed12345;
    2.  
    3. import java.io.File;
    4. import java.util.ArrayList;
    5. import java.util.List;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.Material;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.configuration.file.YamlConfiguration;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.BlockPlaceEvent;
    15. import org.bukkit.plugin.Plugin;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    19. import com.sk89q.worldguard.protection.managers.RegionManager;
    20.  
    21.  
    22. public class RCChestLimit extends JavaPlugin implements Listener {
    23.  
    24. public WorldGuardPlugin getWorldGuard() {
    25. Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
    26.  
    27. // WorldGuard may not be loaded
    28. if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
    29. return null; // Maybe you want throw an exception instead
    30. }
    31.  
    32. return (WorldGuardPlugin) plugin;
    33. }
    34.  
    35. /** @author William Reed */
    36.  
    37. final String VERSION = "0.0.1 Beta";
    38. public WorldGuardPlugin wg;
    39. public RegionManager rm;
    40.  
    41. @Override
    42. public void onEnable() {
    43. getServer().getPluginManager().registerEvents(this, this);
    44.  
    45. wg = getWorldGuard();
    46. //change this name
    47.  
    48.  
    49. loadYAML();
    50.  
    51. getLogger().info("RCChestLimit " + VERSION + " has been enabled!");
    52. }
    53.  
    54. @Override
    55. public void onDisable() {
    56. saveYAML();
    57.  
    58. getLogger().info("RCChestLimit " + VERSION + " has been disabled");
    59. }
    60.  
    61. public List<TempPlayers> players = new ArrayList<TempPlayers>();
    62.  
    63. @EventHandler
    64. public void placeBlock(BlockPlaceEvent event) {
    65. rm = wg.getRegionManager(Bukkit.getServer().getWorld("world"));
    66. //first check if a chest was placed
    67. if (event.getBlock().getType().equals(Material.CHEST)) {
    68. System.out.println("chest placed");
    69. if (
    70. rm.getRegion("wreed58")
    71. .contains(
    72. event.getBlock().getLocation().getBlockX(),
    73. event.getBlock().getLocation().getBlockY(),
    74. event.getBlock().getLocation().getBlockZ())) {
    75. System.out.println("chest in protected area");
    76.  
    77. //check if player has placed chest there before
    78. if(chestData.getConfigurationSection("name").contains(event.getPlayer().getName())){
    79. //check players count of chests. if > 2 cancel event.
    80. if(chestData.getInt("name." + event.getPlayer().getName() + ".chests") > 2){
    81. event.setCancelled(true);
    82. event.getPlayer().sendMessage(ChatColor.RED + "You can not place more than two chests here");
    83. }else{
    84. chestData.set("name." + event.getPlayer().getName() + ".chests", 2);
    85. //exit since they can clearly place another chest.
    86. return;
    87. }
    88. }else { //name doesnt exist in data, so create it
    89.  
    90. for (String s : chestData.getConfigurationSection("name").getKeys(false)) {
    91. players.add(new TempPlayers(s, chestData.getInt("name." + s + ".chests")));
    92. }
    93. players.add(new TempPlayers(event.getPlayer().getName(), 1));
    94.  
    95. chestData.set("name", TempPlayers.players);
    96.  
    97. for(int i = 0; i < TempPlayers.players.size(); i++){
    98. String player;
    99. player = TempPlayers.players.get(i);
    100. chestData.set("name." + player + ".chests", players.get(i).chest);
    101. }
    102. saveYAML();
    103.  
    104. //conserve ram
    105. players.clear();
    106. TempPlayers.players.clear();
    107. TempPlayers.chests.clear();
    108. }
    109. }
    110. }
    111. }
    112.  
    113. //LOWER COUNT IF THEY BREAK A CHEST
    114. public File file;
    115. public FileConfiguration chestData;
    116.  
    117. void loadYAML() {
    118. file = new File(this.getDataFolder(), "chests.yml");
    119. if (!file.exists()) {
    120. try {
    121. file.getParentFile().mkdir();
    122. file.createNewFile();
    123. chestData = YamlConfiguration.loadConfiguration(file);
    124. chestData.set("name", "will");
    125. chestData.set("name.will.chests", 1);
    126. saveYAML();
    127. return;
    128. } catch (Exception e) {
    129. System.out.println("cant create chests.yml");
    130. }
    131. }
    132. chestData = YamlConfiguration.loadConfiguration(file);
    133. }
    134.  
    135. void saveYAML() {
    136. try {
    137. chestData.save(file);
    138. } catch (Exception e) {
    139. System.out.println("OMGOMGOMG cant save chests.yml");
    140. }
    141. }
    142. }
    143.  

    Code for the class where the error comes up
    Code:java
    1. package io.github.wreed12345;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. public class TempPlayers {
    7.  
    8. public static List<String> players = new ArrayList<String>();
    9. public static List<Integer> chests = new ArrayList<Integer>();
    10.  
    11. public String player;
    12. public int chest;
    13.  
    14. public TempPlayers(String player, int chest) {
    15. players.add(player);
    16. chests.add(chest);
    17.  
    18. this.player = player;
    19. this.chest = chest;
    20. }
    21. }
    22.  

    SnipsRevival
     
  4. Offline

    collielimabean

    wreed12345
    You are performing something called direct variable access. Although you have declared your variables to be public, which means that anyone can see your variable. However, using <ClassName>.<variable> is an attempt to get the value directly, which Java forbids. To correct, you must create an accessor method:

    Code:java
    1. public List<Integer> getChests()
    2. {
    3. return chests;
    4. }


    And in your code, you must use the method instead of the direct access.

    [On a side note, <ClassName>.<Variable> only works if the variable is declared static, which means the variable is initialized once (class variable).]


    Helpful link:
    http://stackoverflow.com/questions/11498287/accessor-methods-in-java
     
  5. Offline

    wreed12345

    both of those variables are declared as static? Both lists in that class are static ... collielimabean
     
  6. Offline

    collielimabean

    Dang - didn't catch that. Sorry about that.

    I'm not sure then - could be that you are trying to store something illegally through the configuration? I'm not familiar with the FileConfiguration API.
     
  7. Offline

    wreed12345

    It sounds unlikely because i used this method almost exactly the same through another plugin I made collielimabean

    Just confirmed that it has nothing to do with the FileConfiguration API. I created a new List<String> called names and performed this:
    Code:java
    1. names = TempPlayers.players;

    And that is where the error comes up. This seems extremely odd

    Well this is extremely weird but I created a new class called TemporaryPlayers and copied everything there from the TempPlayers class and it all works fine...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
Thread Status:
Not open for further replies.

Share This Page