Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CaptureTimer {
- private int captureTime;
- private final int startCaptureTime;
- private List<Player> invader;
- private final List<Location<World>> locations;
- public CaptureTimer(int captureTime, List<Player> invader, Location<World> warbase) {
- this.captureTime = captureTime * 60;
- this.startCaptureTime = captureTime * 60;
- this.invader = invader;
- this.locations = getWarBaseLcations(warbase);
- }
- public void setInvader(List<Player> invader) {
- this.invader = invader;
- }
- public void update() {
- System.out.println(invader.toString());
- if (isCapturing(invader, locations)) {
- System.out.println(1);
- countDown();
- } else {
- System.out.println(2);
- countUp();
- }
- }
- private List<Location<World>> getWarBaseLcations(Location<World> warBase) {
- List<Location<World>> locations = new ArrayList<>();
- int x1 = warBase.getBlockX() + 7;
- for (int x0 = warBase.getBlockX() - 7; x0 <= x1; x0++) {
- int y1 = warBase.getBlockY() + 7;
- for (int y0 = warBase.getBlockY() - 7; y0 <= y1; y0++) {
- int z1 = warBase.getBlockZ() + 7;
- for (int z0 = warBase.getBlockZ() - 7; z0 <= z1; z0++) {
- locations.add(new Location<>(warBase.getExtent(), x0, y0, z0));
- }
- }
- }
- return locations;
- }
- private boolean deepEquals(Location<World> location, Location<World> equals) {
- if (location.getBlockX() != equals.getBlockX()) return false;
- if (location.getBlockY() != equals.getBlockY()) return false;
- if (location.getBlockZ() != equals.getBlockZ()) return false;
- return true;
- }
- private boolean isCapturing(List<Player> invader, List<Location<World>> locations) {
- for (Player player : invader) {
- Location<World> playerLoc = new Location<>(
- player.getWorld(),
- player.getLocation().getBlockX(),
- player.getLocation().getBlockY(),
- player.getLocation().getBlockZ());
- System.out.println(player.getName() + " : " + playerLoc.toString());
- for (Location<World> location : locations) {
- if (deepEquals(location, playerLoc)) {
- System.out.println(player + " : " + playerLoc);
- return true;
- }
- }
- }
- return false;
- }
- private void countDown() {
- if (captureTime > 0) {
- captureTime--;
- }
- }
- private void countUp() {
- if (captureTime < startCaptureTime)
- captureTime++;
- }
- public int getCaptureTime() {
- return captureTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement