diff --git a/src/main/java/rip/tilly/bedwars/game/Game.java b/src/main/java/rip/tilly/bedwars/game/Game.java index 2426911..c70d80f 100644 --- a/src/main/java/rip/tilly/bedwars/game/Game.java +++ b/src/main/java/rip/tilly/bedwars/game/Game.java @@ -18,6 +18,7 @@ import rip.tilly.bedwars.game.arena.CopiedArena; import rip.tilly.bedwars.generators.Generator; import rip.tilly.bedwars.generators.GeneratorTier; import rip.tilly.bedwars.generators.GeneratorType; +import rip.tilly.bedwars.playerdata.PlayerData; import rip.tilly.bedwars.utils.CC; import rip.tilly.bedwars.utils.CustomLocation; import rip.tilly.bedwars.utils.TimeUtils; @@ -85,6 +86,12 @@ public class Game { this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.sendTitle(title))); } + public void broadcastTitleToOneTeam(String message, String subMessage, GameTeam gameTeam) { + Title title = new Title(CC.translate(message), CC.translate(subMessage), 5, 20, 5); + + this.teams.stream().filter(team -> team == gameTeam).forEach(team -> team.playingPlayers().forEach(player -> player.sendTitle(title))); + } + public void broadcast(String message) { this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.sendMessage(CC.translate(message)))); } @@ -306,4 +313,16 @@ public class Game { this.addEntityToRemove(teamAUpgradesVillager); this.addEntityToRemove(teamBUpgradesVillager); } + + public boolean checkTrapStatus(Player player) { + PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + GameTeam gameTeam = this.getTeams().get(playerData.getTeamId()); + + if (player.getLocation().distance((gameTeam.getId() == 0 ? this.copiedArena.getA().toBukkitLocation() : this.copiedArena.getB().toBukkitLocation())) < 15) { + return true; + } + + return false; + } } diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/MovementListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/MovementListener.java index cc12e4f..216b3bc 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/MovementListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/MovementListener.java @@ -12,6 +12,9 @@ import rip.tilly.bedwars.game.GameState; import rip.tilly.bedwars.events.PlayerKillEvent; import rip.tilly.bedwars.playerdata.PlayerData; import rip.tilly.bedwars.playerdata.PlayerState; +import rip.tilly.bedwars.playerdata.currentgame.PlayerCurrentGameData; +import rip.tilly.bedwars.upgrades.Upgrade; +import rip.tilly.bedwars.utils.CC; public class MovementListener implements Listener { @@ -24,11 +27,13 @@ public class MovementListener implements Listener { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); + if (player.getGameMode() == GameMode.CREATIVE && player.isOp()) { return; } PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()); + if (playerData == null) { this.plugin.getLogger().warning(player.getName() + "'s player data is null"); return; @@ -56,6 +61,26 @@ public class MovementListener implements Listener { } } + if (game.getGameState() == GameState.FIGHTING) { + game.getTeams().forEach(gameTeam -> { + gameTeam.playingPlayers().forEach(teamPlayer -> { + PlayerData teamPlayerData = this.plugin.getPlayerDataManager().getPlayerData(teamPlayer.getUniqueId()); + + PlayerCurrentGameData teamPlayerCurrentGameData = teamPlayerData.getCurrentGameData(); + + if (teamPlayerCurrentGameData.getLevelForUpgrade(Upgrade.TRAP) != 0) { + if (game.checkTrapStatus(player)) { + teamPlayerCurrentGameData.getUpgrades().remove(Upgrade.TRAP); + + teamPlayer.sendMessage(CC.translate("&cYour trap has been activated")); + + game.broadcastTitleToOneTeam("&cTRAP ACTIVATED", "&eYour trap has been activated", gameTeam); + } + } + }); + }); + } + if (game.getGameState() != GameState.ENDING) { if (player.getLocation().getY() <= game.getArena().getDeadZone()) { Player killer = playerData.getLastDamager(); diff --git a/src/main/java/rip/tilly/bedwars/runnables/GameRunnable.java b/src/main/java/rip/tilly/bedwars/runnables/GameRunnable.java index 417fc41..e14dca5 100644 --- a/src/main/java/rip/tilly/bedwars/runnables/GameRunnable.java +++ b/src/main/java/rip/tilly/bedwars/runnables/GameRunnable.java @@ -13,8 +13,6 @@ public class GameRunnable extends BukkitRunnable { private Game game; - private int amount; - public GameRunnable(Game game) { this.game = game; } @@ -33,9 +31,8 @@ public class GameRunnable extends BukkitRunnable { break; case FIGHTING: - this.amount++; this.game.incrementDuration(); - this.game.tick(this.amount, this.game); + this.game.tick(this.game.getDurationTimer(), this.game); break; case ENDING: diff --git a/src/main/java/rip/tilly/bedwars/utils/LocationUtils.java b/src/main/java/rip/tilly/bedwars/utils/LocationUtils.java new file mode 100644 index 0000000..c11bfd7 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/LocationUtils.java @@ -0,0 +1,34 @@ +package rip.tilly.bedwars.utils; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import java.util.ArrayList; +import java.util.List; + +public class LocationUtils { + + public static List getBlocks(Location center, int radius) { + return getBlocks(center, radius, radius); + } + + public static List getBlocks(Location center, int radius, int yRadius) { + if (radius < 0) { + return new ArrayList<>(); + } + + int iterations = radius * 2 + 1; + + List blocks = new ArrayList<>(iterations * iterations * iterations); + + for (int x = -radius; x <= radius; x++) { + for (int y = -yRadius; y <= yRadius; y++) { + for (int z = -radius; z <= radius; z++) { + blocks.add(center.getBlock().getRelative(x, y, z)); + } + } + } + + return blocks; + } +}