Solved Server crash on raytrace: getOrCreateChunk()

Discussion in 'Spigot Plugin Development' started by WAS, Apr 19, 2017.

  1. WAS

    WAS

    I'm trying to get a location in a range. But I'm having some issues. In certain circumstances the function will just kill the server. The range is not set more than 10 at any time (while view distance is max, and max view rendered). The issue seems to be the ray trace being finite when it's bound to 10 (it's hard coded).

    Update. Figured it out, I believe. This:

    Code (Java):
      public Location getTargetBlock(Location location, int range) {
         BlockIterator iter = new BlockIterator(location, range);
         Block lastBlock = iter.next();
         while (iter.hasNext()) { // Chunk: get or create chunk error here
           if (lastBlock.getType() != Material.AIR) {
             break;
           }
         }
         return lastBlock.getLocation();
      }
    should I guess be (from looking at another example)

    Code (Java):
      public Location getTargetBlock(Location location, int range) {
         BlockIterator iter = new BlockIterator(location, range);
         Block lastBlock = iter.next();
         while (iter.hasNext()) { // Chunk: get or create chunk error here
           if (lastBlock.getType() != Material.AIR) {
             continue;
           }
           break;
         }
         return lastBlock.getLocation();
      }
     
    #1 WAS, Apr 19, 2017
    Last edited: Apr 19, 2017