Guest User

CaptureTimer

a guest
Apr 1st, 2021
11
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class CaptureTimer {
  2.     private int captureTime;
  3.     private final int startCaptureTime;
  4.     private List<Player> invader;
  5.     private final List<Location<World>> locations;
  6.  
  7.     public CaptureTimer(int captureTime, List<Player> invader, Location<World> warbase) {
  8.         this.captureTime = captureTime * 60;
  9.         this.startCaptureTime = captureTime * 60;
  10.         this.invader = invader;
  11.         this.locations = getWarBaseLcations(warbase);
  12.     }
  13.  
  14.     public void setInvader(List<Player> invader) {
  15.         this.invader = invader;
  16.     }
  17.  
  18.     public void update() {
  19.         System.out.println(invader.toString());
  20.         if (isCapturing(invader, locations)) {
  21.             System.out.println(1);
  22.             countDown();
  23.         } else {
  24.             System.out.println(2);
  25.             countUp();
  26.         }
  27.     }
  28.  
  29.  
  30.     private List<Location<World>> getWarBaseLcations(Location<World> warBase) {
  31.  
  32.         List<Location<World>> locations = new ArrayList<>();
  33.  
  34.         int x1 = warBase.getBlockX() + 7;
  35.         for (int x0 = warBase.getBlockX() - 7; x0 <= x1; x0++) {
  36.             int y1 = warBase.getBlockY() + 7;
  37.             for (int y0 = warBase.getBlockY() - 7; y0 <= y1; y0++) {
  38.                 int z1 = warBase.getBlockZ() + 7;
  39.                 for (int z0 = warBase.getBlockZ() - 7; z0 <= z1; z0++) {
  40.                     locations.add(new Location<>(warBase.getExtent(), x0, y0, z0));
  41.                 }
  42.             }
  43.         }
  44.         return locations;
  45.     }
  46.  
  47.     private boolean deepEquals(Location<World> location, Location<World> equals) {
  48.         if (location.getBlockX() != equals.getBlockX()) return false;
  49.         if (location.getBlockY() != equals.getBlockY()) return false;
  50.         if (location.getBlockZ() != equals.getBlockZ()) return false;
  51.         return true;
  52.     }
  53.  
  54.     private boolean isCapturing(List<Player> invader, List<Location<World>> locations) {
  55.         for (Player player : invader) {
  56.             Location<World> playerLoc = new Location<>(
  57.                     player.getWorld(),
  58.                     player.getLocation().getBlockX(),
  59.                     player.getLocation().getBlockY(),
  60.                     player.getLocation().getBlockZ());
  61.             System.out.println(player.getName() + " : " + playerLoc.toString());
  62.             for (Location<World> location : locations) {
  63.                 if (deepEquals(location, playerLoc)) {
  64.                     System.out.println(player + " : " + playerLoc);
  65.                     return true;
  66.                 }
  67.             }
  68.         }
  69.         return false;
  70.     }
  71.  
  72.  
  73.     private void countDown() {
  74.         if (captureTime > 0) {
  75.             captureTime--;
  76.         }
  77.     }
  78.  
  79.     private void countUp() {
  80.         if (captureTime < startCaptureTime)
  81.             captureTime++;
  82.     }
  83.  
  84.     public int getCaptureTime() {
  85.         return captureTime;
  86.     }
  87.  
  88.  
  89. }
  90.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×