Code:
private static final void addFloorItemsTask() {
CoresManager.slowExecutor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
for(int floorItemKey = 1 ; floorItemKey < Settings.MAX_FLOORITEMS + 1; floorItemKey++){ //load the a RespawnableFloorItem data, using the flooritemKey indexer. These are the keys / first number in the notepad
//Regular flooritems
WorldTile spawnTile = new WorldTile(FloorItemsLoader.get_FloorItem_X(floorItemKey) ,FloorItemsLoader.get_FloorItem_Y(floorItemKey) ,FloorItemsLoader.get_FloorItem_Z(floorItemKey)); //The tile for the Respawnable item.
Region region = getRegion(spawnTile.getRegionId());//The region of the tile
FloorItem floorItem = new FloorItem( new Item(FloorItemsLoader.get_FloorItem_ItemID(floorItemKey) , FloorItemsLoader.get_FloorItem_Amount(floorItemKey) ) , spawnTile ,null,false,false); // The floor item, belonging to NULL.
//Randomized floorItems
FloorItem floorItemRandom = new FloorItem( FloorItemsLoader.create_RandomItem(), spawnTile ,null,false,false); // The floor item, belonging to NULL.
FloorItem retrievedFloorItem;// used for Random items.
if(FloorItemsLoader.get_FloorItem_ItemID(floorItemKey) == 0){//Loading a random item.
if(FloorItemsLoader.tileDoesContainRandomItem( floorItemKey,region, spawnTile ) ){ //the passed tile, does contain a flooritem that has an item that is within the randomitems Array
retrievedFloorItem = FloorItemsLoader.getRandomFlooritemOnTile( floorItemKey,region,spawnTile); //now that we know the tile does contain a random item, we need to get that flooritem on the tile
if(retrievedFloorItem != null) { removeGroundItem(region,spawnTile,retrievedFloorItem); }
addGroundItem( spawnTile,floorItemRandom); //spawn new floor items
}else{//The tile did not contain a random item, so add one.
addGroundItem( spawnTile,floorItemRandom);
}
}else{
if(FloorItemsLoader.doesContainExactly(floorItemKey , region, spawnTile, floorItem) ) { // This is going to pass the above data, to be tested against flooritems that exist or don't.
//The amounts were found in the amount requested , do nothing. :)
}else{
//The amount of flooritems was not equal to the desired. This could mean, none was found, or some amount was found. This only looks for null ownership items, not player owned.
//Because of this, we will remove them and then add them back. Other wise, it will just stay 0 or the other amount for forever until reset or someone picks the single item.
//Let's remove the items, if they exist, then add them.
removeGroundItem(region,spawnTile,floorItem); //remove any found floor items
addGroundItem( spawnTile,floorItem); //spawn new floor items
}
}
}
} catch (Throwable e) {
//Logger.handle(e);
}
}
//}, 0,30, TimeUnit.MINUTES);
}, 0,5, TimeUnit.SECONDS);
}
public static final void addGroundItem(WorldTile tile,FloorItem item) {
try{
if( item.getDefinitions().isStackable() ){ //just add 1 stackable item
addGroundItem(item, tile);
}else{//add mutli items
for(int spawned_Amount = 0; spawned_Amount != item.getAmount() ; spawned_Amount++ ){
addGroundItem(new Item(item.getId() , 1 ), tile); //add 1 on the tile
}
}
}catch(Exception e){
//Logger.handle(e);
}
}
public static final void removeGroundItem(Region region,WorldTile floorItemTile,FloorItem item) {
try{
region.forceGetFloorItems();
FloorItem flooritem = region.getGroundItem(item.getId(), floorItemTile , null);
if(flooritem==null){return;}
if( flooritem.getDefinitions().isStackable() ){
removeGroundItem(flooritem);
}else{
for(int spawned_Amount = 0; spawned_Amount < item.getAmount() ; spawned_Amount++ ){
region.forceGetFloorItems();
flooritem = region.getGroundItem( item.getId(), floorItemTile , null ); //new floor item
if(flooritem!=null){ removeGroundItem(flooritem); } //let's not remove what doesn't exist.
}
}
}catch(Exception e){
Logger.handle(e);
}
}