This commit is contained in:
Trixkz 2021-11-24 14:09:19 -05:00
parent 8cb6f1d901
commit 980743ef62
4 changed files with 79 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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:

View File

@ -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<Block> getBlocks(Location center, int radius) {
return getBlocks(center, radius, radius);
}
public static List<Block> getBlocks(Location center, int radius, int yRadius) {
if (radius < 0) {
return new ArrayList<>();
}
int iterations = radius * 2 + 1;
List<Block> 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;
}
}