Solved ClassCastEx - List of Locations

Discussion in 'Plugin Development' started by Europia79, May 11, 2014.

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

    Europia79

    Code:
    java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bukkit.Location
    I'm getting a ClassCastException on line 4 below

    Code:java
    1. public void setBases(String arena) {
    2. ArrayList<Location> locs = plugin.getBases(getMatch().getArena().getName());
    3. for (int i = 0; i < locs.size(); i++) {
    4. World w = locs.get(i).getWorld();
    5. Block block = w.getBlockAt(locs.get(i));
    6. block.setType(plugin.getBaseBlock());
    7. }
    8. }


    Code:java
    1. public ArrayList<Location> getBases(String a) {
    2. // bases.yml
    3. // PATH = "{arenaName}.{index}"
    4. String path = a;
    5. if (basesYml.getConfigurationSection(path) != null
    6. && basesYml.getConfigurationSection(path).getKeys(false) != null
    7. && basesYml.getConfigurationSection(path).getKeys(false).size() >= 2) {
    8. ConfigurationSection cs = basesYml.getConfigurationSection(path);
    9. Map<Integer, Location> locs = SerializerUtil.parseLocations(cs);
    10. if (locs != null) {
    11. ArrayList<Location> temp = new ArrayList<Location>();
    12. for (Integer i : locs.keySet()) {
    13. temp.add(locs.get(i));
    14. }
    15. return temp;
    16. }
    17. }
    18. getLogger().severe("BombPlugin:getBases(String ArenaName) has failed to return a List of Locations.");
    19. return null;
    20. }


    When I added debugging messages to setBases(), the size of the ArrayList is 2 (as expected). And the for-loop goes thru only on i=0.

    I tried with the enhanced-for-loop and got the error at the for-statement.
     
  2. Offline

    thecrystalflame

    try using iteration or a for each loop.

    Code:java
    1.  
    2. for (Location current : locs) {
    3. Block block = current.getBlock();
    4. block.setType(plugin.getBaseBlock());
    5. }
    6.  
     
  3. Offline

    Europia79

    thecrystalflame

    yeah, the first thing I tried was the for-each loop (aka enhanced-for-loop).

    Just tried the iterator() and got the same error.

    This is really wierd: I have a container that is a List of Locations... And it's giving me a ClassCastException for trying to get what i've stored in the container ? Bizarre.

    I've tried doing it as List, ArrayList, and even Map. And now looping with an iterator().

    If anyone thinks it'll be faster/easier to help on Skype or Teamviewer, just lemme know. After we figure this out, we can post the solution.

    I'm Nicodemis79 on Skype.
     
  4. Offline

    Rocoty

    Can you post the error? Also have you tried completely recompiling the code and see if the error points to another line?
     
  5. Offline

    Europia79

    Rocoty

    recompiling the code is a good idea. I was doing it in Netbeans 7.3 IDE. I switch to the command line and did
    Code:
    mvn clean package
    I mean. I was always doing clean+build in the IDE. But it was worth a shot at the the command line (eventho it didn't work).

    This is the error:
    server.log (open)

    Code:
    2014-05-12 08:44:04 [Server thread][INFO] Starting minecraft server version 1.7.2
    2014-05-12 08:44:04 [Server thread][INFO] Loading properties
    2014-05-12 08:44:04 [Server thread][INFO] Default game type: SURVIVAL
    2014-05-12 08:44:04 [Server thread][INFO] Generating keypair
    2014-05-12 08:44:04 [Server thread][INFO] Starting Minecraft server on *:25599
    2014-05-12 08:44:04 [Server thread][INFO] This server is running CraftBukkit version git-Bukkit-1.7.2-R0.3-b3020jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.3)
    2014-05-12 08:44:05 [Server thread][INFO] [PermissionsEx] sql backend registered!
    2014-05-12 08:44:05 [Server thread][INFO] [PermissionsEx] file backend registered!
    2014-05-12 08:44:05 [Server thread][INFO] [CrackShot] Loading CrackShot v0.97.6
    2014-05-12 08:44:05 [Server thread][INFO] [VirtualPlayers] Loading VirtualPlayers v1.5.3
    2014-05-12 08:44:05 [Server thread][INFO] [Vault] Loading Vault v1.2.27-b349
    2014-05-12 08:44:05 [Server thread][INFO] [WorldEdit] Loading WorldEdit v5.5.8
    2014-05-12 08:44:05 [Server thread][INFO] [PermissionsEx] Loading PermissionsEx v1.20.4
    2014-05-12 08:44:05 [Server thread][INFO] [PermissionsEx] Initializing file backend
    2014-05-12 08:44:05 [Server thread][INFO] Permissions file successfully reloaded
    2014-05-12 08:44:05 [Server thread][INFO] [WorldGuard] Loading WorldGuard v5.8
    2014-05-12 08:44:05 [Server thread][INFO] [Essentials] Loading Essentials v2.12.2
    2014-05-12 08:44:05 [Server thread][INFO] [EssentialsChat] Loading EssentialsChat v2.12.2
    2014-05-12 08:44:05 [Server thread][INFO] [BattleTracker] Loading BattleTracker v2.5.8.8
    2014-05-12 08:44:05 [Server thread][INFO] [BattleArena] Loading BattleArena v3.9.7.5.5
    2014-05-12 08:44:05 [Server thread][INFO] [BombArena] Loading BombArena v172140512-0843
    2014-05-12 08:44:05 [Server thread][INFO] [Vault] Enabling Vault v1.2.27-b349
    2014-05-12 08:44:05 [Server thread][INFO] [Vault][Economy] Essentials Economy found: Waiting
    2014-05-12 08:44:05 [Server thread][INFO] [Vault][Permission] PermissionsEx found: Waiting
    2014-05-12 08:44:05 [Server thread][INFO] [Vault][Permission] SuperPermissions loaded as backup permission system.
    2014-05-12 08:44:05 [Server thread][INFO] [Vault][Chat] PermissionsEx found: Waiting
    2014-05-12 08:44:05 [Server thread][INFO] [Vault] Enabled Version 1.2.27-b349
    2014-05-12 08:44:05 [Server thread][INFO] Preparing level "world"
    2014-05-12 08:44:05 [Server thread][INFO] Preparing start region for level 0 (Seed: 3084267604052651227)
    2014-05-12 08:44:05 [Thread-7][INFO] ----- Bukkit Auto Updater -----
    2014-05-12 08:44:05 [Thread-7][INFO] It appears that you're running a Beta Build, when you've specified in bukkit.yml that you prefer to run Recommended Builds.
    2014-05-12 08:44:05 [Thread-7][INFO] If you would like to be kept informed about new Beta Build releases, it is recommended that you change 'preferred-channel' in your bukkit.yml to 'beta'.
    2014-05-12 08:44:05 [Thread-7][INFO] With that set, you will be told whenever a new version is available for download, so that you can always keep up to date and secure with the latest fixes.
    2014-05-12 08:44:05 [Thread-7][INFO] If you would like to disable this warning, simply set 'suggest-channels' to false in bukkit.yml.
    2014-05-12 08:44:05 [Thread-7][INFO] ----- ------------------- -----
    2014-05-12 08:44:05 [Server thread][INFO] Preparing start region for level 1 (Seed: 3084267604052651227)
    2014-05-12 08:44:05 [Server thread][INFO] [CrackShot] Enabling CrackShot v0.97.6
    2014-05-12 08:44:06 [Server thread][INFO] [CrackShot] Gun-mode activated. Boop!
    2014-05-12 08:44:06 [Server thread][INFO] [VirtualPlayers] Enabling VirtualPlayers v1.5.3
    2014-05-12 08:44:06 [Server thread][INFO] [WorldEdit] Enabling WorldEdit v5.5.8
    2014-05-12 08:44:06 [Server thread][INFO] WEPIF: Using the Bukkit Permissions API.
    2014-05-12 08:44:06 [Server thread][INFO] [PermissionsEx] Enabling PermissionsEx v1.20.4
    2014-05-12 08:44:06 [Server thread][INFO] WEPIF: PermissionsEx detected! Using PermissionsEx for permissions.
    2014-05-12 08:44:06 [Server thread][INFO] [Vault][Permission] PermissionsEx hooked.
    2014-05-12 08:44:06 [Server thread][INFO] [Vault][Chat] PermissionsEx_Chat hooked.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] Enabling WorldGuard v5.8
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world) TNT ignition is PERMITTED.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world) Lighters are PERMITTED.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world) Lava fire is blocked.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world) Fire spread is UNRESTRICTED.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] Loaded configuration for world 'world'
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world_the_end) TNT ignition is PERMITTED.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world_the_end) Lighters are PERMITTED.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world_the_end) Lava fire is blocked.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] (world_the_end) Fire spread is UNRESTRICTED.
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] Loaded configuration for world 'world_the_end'
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] 0 regions loaded for 'world'
    2014-05-12 08:44:06 [Server thread][INFO] [WorldGuard] 0 regions loaded for 'world_the_end'
    2014-05-12 08:44:06 [Server thread][INFO] [Essentials] Enabling Essentials v2.12.2
    2014-05-12 08:44:06 [Server thread][INFO] [Vault][Economy] Essentials Economy hooked.
    2014-05-12 08:44:06 [Server thread][INFO] Essentials: Using PermissionsEx based permissions.
    2014-05-12 08:44:06 [Server thread][INFO] [EssentialsChat] Enabling EssentialsChat v2.12.2
    2014-05-12 08:44:06 [Server thread][INFO] [BattleTracker] Enabling BattleTracker v2.5.8.8
    2014-05-12 08:44:06 [Server thread][INFO] [BattleTracker v2.5.8.8] enabled!
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] Enabling BattleArena v3.9.7.5.5
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] v3.9.7.5.5 enabling!
    2014-05-12 08:44:07 [Thread-10][INFO] [BattleTracker_v2.5.8.8] can't find a version for the plugin result was DISABLED
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] Essentials detected. God mode handling activated
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] WorldEdit detected.
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] WorldGuard detected. WorldGuard regions can now be used
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] Warning currency was empty, using name from config.yml
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] found economy plugin Vault. [Default]
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] no additional Arena modules
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] registering classes: gladiator, archer, monk, assault, support, recon, engineer, Vector, Dragonuv, Barrett, Fal, 552, AKS-75X, UMP-45X, FAMAS-X, stg77, P90X
    2014-05-12 08:44:07 [Server thread][INFO] [BattleArena] v3.9.7.5.5 enabled!
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] Enabling BombArena v172140512-0843
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] Loading config.yml
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] PlantTime = 8 seconds
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] DetonationTime = 35 seconds
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] DefuseTime = 8 times
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] Tolerance = 500 milliseconds
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] BombBlock = TNT
    2014-05-12 08:44:07 [Thread-11][INFO] [BattleArena_v3.9.7.5.5] can't find a version for the plugin result was DISABLED releaseType: null
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] BaseBlock = BREWING_STAND
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] Baseinv = BREWING
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] BattleArena version = 3.9.7.5.5
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] BattleArena version = 397550
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] Loaded BombArena arenas: b1
    2014-05-12 08:44:07 [Server thread][INFO] Number of Bombs Planted
    2014-05-12 08:44:07 [Server thread][INFO] -----------------------
    2014-05-12 08:44:07 [Server thread][INFO] 1 Europia79 9 out of 10 (90%)
    2014-05-12 08:44:07 [Server thread][INFO] 2 DerpImaBlock 4 out of 4 (100%)
    2014-05-12 08:44:07 [Server thread][INFO] Number of Bombs Defused
    2014-05-12 08:44:07 [Server thread][INFO] -----------------------
    2014-05-12 08:44:07 [Server thread][INFO] 1 DerpImaBlock 1
    2014-05-12 08:44:07 [Server thread][INFO] 2 Europia79 0
    2014-05-12 08:44:07 [Server thread][INFO] [BombArena] updating arenas.yml with TNT
    2014-05-12 08:44:07 [Server thread][INFO] BombArena Saving arenas b1 to C:\Users\Nikolai\Desktop\503\plugins\BombArena\arenas.yml configSection=.
    2014-05-12 08:44:07 [Server thread][INFO] Server permissions file permissions.yml is empty, ignoring it
    2014-05-12 08:44:07 [Server thread][INFO] Done (2.101s)! For help, type "help" or "?"
    2014-05-12 08:44:07 [Server thread][INFO] Starting GS4 status listener
    2014-05-12 08:44:07 [Query Listener #1][INFO] Query running on 0.0.0.0:25566
    2014-05-12 08:44:27 [User Authenticator #1][INFO] UUID of player Europia79 is 232b72237fe74eb192cec2a8ffe213f2
    2014-05-12 08:44:27 [Server thread][INFO] Europia79[/192.168.1.1:53483] logged in with entity id 30 at ([world] -399.8741149902344, 4.125, -1220.029296875)
    2014-05-12 08:44:37 [Server thread][INFO] Plugins (11): CrackShot, VirtualPlayers, Vault, WorldEdit, PermissionsEx, WorldGuard, Essentials, EssentialsChat, BattleTracker, BattleArena, BombArena
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester is connecting'
    2014-05-12 08:44:43 [Server thread][INFO] tester connecting.  Details:tester h=20.0 o=true d=false loc=world,0.0,0.0,0.0 gm=SURVIVAL
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester gettingMessage= Welcome, tester!'
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester gettingMessage= Type /help for a list of commands.'
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester gettingMessage= Type /list to see who else is online.'
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester gettingMessage= Players online: 1 - World time: 7:42 AM'
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester gettingMessage= You have no new mail.'
    2014-05-12 08:44:43 [Server thread][INFO] [tester] 'tester gettingMessage= Set fly mode enabled for tester.'
    2014-05-12 08:44:58 [Server thread][INFO] Europia79 issued server command: /bomb join
    2014-05-12 08:45:02 [Server thread][INFO] Executing 'bomb join' for player 'tester'
    2014-05-12 08:45:02 [Server thread][INFO] [BattleArena] Couldnt teleport player=tester loc=Location{world=CraftWorld{name=world},x=-429.4908447265625,y=4.0,z=-1206.81494140625,pitch=6.299859,yaw=0.1504296}
    2014-05-12 08:45:02 [Server thread][INFO] [BA Warning] couldn't teleport tester srcLoc=[LocationType loc=world,0.0,0.0,0.0,0.0,0.0 type=HOME] destLoc=[LocationType loc=world,-429.4908447265625,4.0,-1206.81494140625,0.1504296,6.299859 type=WAITROOM]
    2014-05-12 08:45:02 [Server thread][INFO] [tester] 'tester gettingMessage= You joined the BombArena queue.Position: 2/32'
    2014-05-12 08:45:02 [Server thread][INFO] [tester] 'tester setting scoreboard waiting'
    2014-05-12 08:45:05 [Server thread][INFO] [tester] 'tester gettingMessage= Your BombArena match against Red starts in 6 seconds.'
    2014-05-12 08:45:05 [Server thread][INFO] [tester] 'tester gettingMessage= [BOMB] Red[1250] vs Blue[1250]!'
    2014-05-12 08:45:05 [Server thread][INFO] [BOMB] Red[1250] vs Blue[1250]!
    2014-05-12 08:45:05 [Server thread][INFO] [tester] 'tester setting scoreboard default'
    2014-05-12 08:45:11 [Server thread][INFO] [BattleArena] Couldnt teleport player=tester loc=Location{world=CraftWorld{name=world},x=-462.2050476074219,y=4.125,z=-1221.1220703125,pitch=1.499865,yaw=-91.04959}
    2014-05-12 08:45:11 [Server thread][INFO] [BA Warning] couldn't teleport tester srcLoc=[LocationType loc=world,0.0,0.0,0.0,0.0,0.0 type=WAITROOM] destLoc=[LocationType loc=world,-462.2050476074219,4.125,-1221.1220703125,-91.04959,1.499865 type=ARENA]
    2014-05-12 08:45:11 [Server thread][INFO] [tester] 'tester gettingMessage= onStart matchID = 0'
    2014-05-12 08:45:11 [Server thread][INFO] [BombArena] BombArena.java:assignBases()
    2014-05-12 08:45:11 [Server thread][INFO] [BombArena] arena name = b1
    2014-05-12 08:45:11 [Server thread][WARN] java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bukkit.Location
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.euro.demolition.BombArena.assignBases(BombArena.java:594)
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.euro.demolition.BombArena.onStart(BombArena.java:490)
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.alk.arena.objects.arenas.Arena.privateOnStart(Arena.java:115)
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.alk.arena.objects.arenas.ArenaControllerInterface.onStart(ArenaControllerInterface.java:23)
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.alk.arena.competition.match.Match.startMatch(Match.java:452)
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.alk.arena.competition.match.Match.access$200(Match.java:104)
    2014-05-12 08:45:11 [Server thread][WARN]    at mc.alk.arena.competition.match.Match$3.run(Match.java:402)
    2014-05-12 08:45:11 [Server thread][WARN]    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftTask.run(CraftTask.java:53)
    2014-05-12 08:45:11 [Server thread][WARN]    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    2014-05-12 08:45:11 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:587)
    2014-05-12 08:45:11 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250)
    2014-05-12 08:45:11 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545)
    2014-05-12 08:45:11 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457)
    2014-05-12 08:45:11 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
    2014-05-12 08:45:11 [Server thread][INFO] [tester] 'tester gettingMessage=  O---[{==========> Fight <==========}]---O'
    2014-05-12 08:45:11 [Server thread][INFO] [tester] 'tester setting scoreboard default'
    2014-05-12 08:45:31 [Server thread][INFO] [tester] 'tester gettingMessage= m[BOMB] Game ends in 8 minutes.'
    2014-05-12 08:46:01 [Server thread][INFO] [tester] 'tester gettingMessage= m[BOMB] Game ends in 7 minutes 30 seconds.'
    2014-05-12 08:46:12 [Server thread][INFO] [tester] 'tester gettingMessage= [CONSOLE: Stopping the server..]'
    2014-05-12 08:46:12 [Server thread][INFO] CONSOLE: Stopping the server..
    2014-05-12 08:46:12 [Server thread][INFO] Stopping server
    2014-05-12 08:46:12 [Server thread][INFO] [BombArena] Disabling BombArena v172140512-0843
    2014-05-12 08:46:12 [Server thread][INFO] [BattleArena] Disabling BattleArena v3.9.7.5.5


    What I did: I was like "ya know what, I don't really NEED the setBases() method right now... So lemme comment it out for now and come back to it..." ...Well, as you can see, the assignBases() method uses the getBases(String arenaName) method too.

    It errors when I try to retrieve the contents of the List:

    Code:java
    1. // ArrayList<Location> locations = plugin.getBases(getMatch().getArena().getName());
    2. List<Location> locations = plugin.getBases(getMatch().getArena().getName());
    3. ...
    4. Location ONE = locations.get(0); // line 594
    5. Location TWO = locations.get(1); // line 595


    Pardon the code: I know it looks really weird, but there can only ever be 2 teams and 2 bases in this arena type. The rules of the game become nonsensical when there's more than 2 teams.

    i'm starting to think there's something wrong with the getBases() method... I'm adding debugging lines right now.

    Code:
    2014-05-12 09:17:05 [Server thread][WARN] java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bukkit.Location
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.euro.demolition.BombPlugin.getBases(BombPlugin.java:189)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.euro.demolition.BombArena.setBases(BombArena.java:496)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.euro.demolition.BombArena.onStart(BombArena.java:483)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.alk.arena.objects.arenas.Arena.privateOnStart(Arena.java:115)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.alk.arena.objects.arenas.ArenaControllerInterface.onStart(ArenaControllerInterface.java:23)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.alk.arena.competition.match.Match.startMatch(Match.java:452)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.alk.arena.competition.match.Match.access$200(Match.java:104)
    2014-05-12 09:17:05 [Server thread][WARN]    at mc.alk.arena.competition.match.Match$3.run(Match.java:402)
    2014-05-12 09:17:05 [Server thread][WARN]    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftTask.run(CraftTask.java:53)
    2014-05-12 09:17:05 [Server thread][WARN]    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    2014-05-12 09:17:05 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:587)
    2014-05-12 09:17:05 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250)
    2014-05-12 09:17:05 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545)
    2014-05-12 09:17:05 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457)
    2014-05-12 09:17:05 [Server thread][WARN]    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
    Here's the code with debugging lines: line 189 in the log corresponds to line 13 below:
    Code:java
    1. public ArrayList<Location> getBases(String a) {
    2. // bases.yml
    3. // PATH = "{arenaName}.{index}"
    4. String path = a;
    5. if (basesYml.getConfigurationSection(path) != null
    6. && basesYml.getConfigurationSection(path).getKeys(false) != null
    7. && basesYml.getConfigurationSection(path).getKeys(false).size() >= 2) {
    8. ConfigurationSection cs = basesYml.getConfigurationSection(path);
    9. Map<Integer, Location> locs = SerializerUtil.parseLocations(cs);
    10. if (locs != null) {
    11. ArrayList<Location> temp = new ArrayList<Location>();
    12. for (Integer i : locs.keySet()) {
    13. debug.log("getBases(String arenaName) " + i + ": " + locs.get(i).toString()); // line 189
    14. temp.add(locs.get(i));
    15. }
    16. debug.log("getBases(String arenaName) size of returning List = " + temp.size());
    17. return temp;
    18. }
    19. }
    20. getLogger().severe("BombPlugin:getBases(String ArenaName) has failed to return a List of Locations.");
    21. return null;
    22. }


    temp.add(locs.get(i)); never caused an error, but locs.get(i).toString() does ?

    Ya know what: I bet I'm using SerializerUtil.parseLocations(cs) incorrectly.

    It probably doesn't like the ConfigurationSection that I'm giving it.

    Here are the toString() contents of both those things: the cs and the return value of SerializerUtil.parseLocations(cs) - which is a map:
    Code:
    2014-05-12 09:36:21 [Server thread][INFO] [BombArena] getBases() cs = MemorySection[path='b1', root='YamlConfiguration']
    2014-05-12 09:36:21 [Server thread][INFO] [BombArena] getBases() map = {1=[Location{world=CraftWorld{name=world},x=-401.0,y=4.0,z=-1221.0,pitch=0.0,yaw=0.0}], 2=[Location{world=CraftWorld{name=world},x=-462.0,y=4.0,z=-1221.0,pitch=0.0,yaw=0.0}]}
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  6. Offline

    Rocoty

    Europia79 That is actually pretty interesting and really strange. There is no explicit casting going on in your code as far as I can tell. And the first element in the stacktrace IS that line. I'll see what I can do for research on this.

    Europia79 It might be that somehow, for some reason the elements in the List are not Locations, but rather ArrayList<Location>. Which would seem strange, because your ArrayList is declared to hold only Locations. Can you show me the way you are adding the elements to the list?

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

    Shevchik

    Your map is actually <Integer, ArrayList<Location>>, not <Integer, Location>.
     
    Europia79 likes this.
  8. Offline

    Europia79

    Shevchik Rocoty

    I was actually thinking the same thing while I was at work today... Then right now, I'm loading up different versions of BattleArena (it's the one that has SerializerUtil.parseLocations)... And I was like, "ya know what, I know I had this working... why load up different version when I can just see if alkarin changed it ?"

    https://github.com/alkarinv/BattleA...va/mc/alk/arena/util/SerializerUtil.java#L116

    Apparently, I was compiling against 1 version of BattleArena, then running it with a completely different version! (a newer one). lol

    yep, just tested with an old version... it works. Now I just gotta update my code and add backwards compatibility.

    Which will probably be a pain since we're talking about 2 different YAML formats: one that pulls a list of locations, and one that pulls just one location per node.

    Code:
    OLD_FORMAT:
      '1': world,-401.0,4.0,-1221.0,0.0,0.0
      '2': world,-462.0,4.0,-1221.0,0.0,0.0
    NEW_FORMAT:
      '1':
      - world,-401.0,4.0,-1221.0,0.0,0.0
      '2':
      - world,-462.0,4.0,-1221.0,0.0,0.0
    Hmm... every time I add a location to bases.yml, should I duplicate it ? And add it twice: Once in the old format, and once in the new format ? I mean, I would like to make my plugin user-friendly... Where admins can choose which version of BattleArena that they wanna use... And my plugin will simply 'work' and they don't have to worry about it.

    Or should I implement backwards compatibility another way ?

    Anyways, thanks for helping Rocoty and Shevchik! I'm so glad we finally got this solved.
     
    Rocoty likes this.
Thread Status:
Not open for further replies.

Share This Page