Skip to content

Instantly share code, notes, and snippets.

@daltonks
Created October 24, 2011 21:00
Show Gist options
  • Save daltonks/1310281 to your computer and use it in GitHub Desktop.
Save daltonks/1310281 to your computer and use it in GitHub Desktop.
package me.dalton.mineconquer;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class CaptureHandler {
static List<CaptureSpot> captureSpots = new ArrayList<CaptureSpot>();
public static void newCapturer(Player playa){
Location location = playa.getLocation();
int px = location.getBlockX();
int pz = location.getBlockZ();
String name = playa.getName();
ChunkData playerChunk = new ChunkData(playa.getLocation().getBlock().getChunk());
//get adjacent chunks and find the closest
double distance = 9001;
ChunkData closestChunk = null;
for(ChunkData enemyChunk : Util.getEnemyChunks(name))
if(enemyChunk.isAdjacentTo(playerChunk)){
double tempDistance = Util.getDistance(enemyChunk.X * 16 + 8, enemyChunk.Z * 16 + 8, px, pz);
if(tempDistance < distance){
distance = tempDistance;
closestChunk = enemyChunk;
}
}
if(closestChunk == null)
return;
for(CaptureSpot spot : captureSpots){
if(spot.chunk.equals(closestChunk)){
spot.addAttacker(name);
return;
}
}
captureSpots.add(new CaptureSpot(name, closestChunk));
//TODO broadcasting that their chunk is being taken over
}
public static void iterateSpots(){
for(CaptureSpot cSection : captureSpots){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment