AlttdGriefPrevention/src/me/ryanhamshire/GriefPrevention/AutoExtendClaimTask.java
ryanhamshire 289b832b9a Ignored lots of compiler warnings.
Mostly these are deprecations from the Spigot team which I believe
shouldn't be deprecated.  For example, players refer to each other by
name, not UUID - so there will always be a need for player lookup by
name.  Also the block IDs are a well-documented standard that everyone
understands, even if they're not very human-friendly.  Plugins use those
IDs and data values to specify block types for example in config files.
As for the rest of the ignores, I either decided the warnings are just
noise based on the situation, or that I'm comfortable with the risks.
Possibly for the first time in 5 years of dev work on this plugin, I
just compiled without any warnings.  :)
2016-01-20 16:25:42 -08:00

97 lines
2.8 KiB
Java

package me.ryanhamshire.GriefPrevention;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.ChunkSnapshot;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
//automatically extends a claim downward based on block types detected
class AutoExtendClaimTask implements Runnable
{
private Claim claim;
private ArrayList<ChunkSnapshot> chunks;
private Environment worldType;
public AutoExtendClaimTask(Claim claim, ArrayList<ChunkSnapshot> chunks, Environment worldType)
{
this.claim = claim;
this.chunks = chunks;
this.worldType = worldType;
}
@Override
public void run()
{
int newY = this.getLowestBuiltY();
if(newY < this.claim.getLesserBoundaryCorner().getBlockY())
{
Bukkit.getScheduler().runTask(GriefPrevention.instance, new ExecuteExtendClaimTask(claim, newY));
}
}
@SuppressWarnings("deprecation")
private int getLowestBuiltY()
{
int y = this.claim.getLesserBoundaryCorner().getBlockY();
if(this.yTooSmall(y)) return y;
for(ChunkSnapshot chunk : this.chunks)
{
Biome biome = chunk.getBiome(0, 0);
ArrayList<Integer> playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome);
boolean ychanged = true;
while(!this.yTooSmall(y) && ychanged)
{
ychanged = false;
for(int x = 0; x < 16; x++)
{
for(int z = 0; z < 16; z++)
{
int blockType = chunk.getBlockTypeId(x, y, z);
while(!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
{
ychanged = true;
blockType = chunk.getBlockTypeId(x, --y, z);
}
if(this.yTooSmall(y)) return y;
}
}
}
if(this.yTooSmall(y)) return y;
}
return y;
}
private boolean yTooSmall(int y)
{
return y == 0 || y <= GriefPrevention.instance.config_claims_maxDepth;
}
//runs in the main execution thread, where it can safely change claims and save those changes
private class ExecuteExtendClaimTask implements Runnable
{
private Claim claim;
private int newY;
public ExecuteExtendClaimTask(Claim claim, int newY)
{
this.claim = claim;
this.newY = newY;
}
@Override
public void run()
{
GriefPrevention.instance.dataStore.extendClaim(claim, newY);
}
}
}