use of com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler in project Warlords by ebicep.
the class BasicScoreboardOption method getDateScoreboard.
private static SimpleScoreboardHandler getDateScoreboard(Game game) {
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy - kk:mm");
format.setTimeZone(TimeZone.getTimeZone("EST"));
SimpleScoreboardHandler simpleScoreboardHandler = new SimpleScoreboardHandler(0, "date") {
@Nonnull
@Override
public List<String> computeLines(@Nullable WarlordsPlayer player) {
return Collections.singletonList(ChatColor.GRAY + format.format(new Date()));
}
};
new GameRunnable(game) {
@Override
public void run() {
simpleScoreboardHandler.markChanged();
}
}.runTaskTimer(GameRunnable.SECOND, GameRunnable.SECOND);
return simpleScoreboardHandler;
}
use of com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler in project Warlords by ebicep.
the class WinAfterTimeoutOption method register.
@Override
public void register(Game game) {
new TimerSkipAbleMarker() {
@Override
public int getDelay() {
return timeRemaining * 20;
}
@Override
public void skipTimer(int delay) {
timeRemaining -= delay / 20;
}
}.register(game);
game.registerGameMarker(ScoreboardHandler.class, scoreboard = new SimpleScoreboardHandler(SCOREBOARD_PRIORITY, "timeout") {
@Override
public List<String> computeLines(@Nullable WarlordsPlayer player) {
final EnumSet<Team> teams = TeamMarker.getTeams(game);
Team winner = null;
if (teams.size() > 1) {
List<PointPredicterMarker> predictionMarkers = game.getMarkers(PointPredicterMarker.class);
int scoreNeededToEndGame = game.getOptions().stream().filter(e -> e instanceof WinByPointsOption).mapToInt(e -> ((WinByPointsOption) e).getPointLimit()).sorted().findFirst().orElse(Integer.MAX_VALUE);
int highestScore = Integer.MIN_VALUE;
int highestWinInSeconds = Integer.MAX_VALUE;
for (Team team : teams) {
int points = game.getPoints(team);
int winInSeconds;
if (predictionMarkers.isEmpty()) {
winInSeconds = Integer.MAX_VALUE;
} else {
double pointsPerMinute = predictionMarkers.stream().mapToDouble(e -> e.predictPointsNextMinute(team)).sum();
int pointsRemaining = scoreNeededToEndGame - points;
int winInSecondsCalculated = pointsPerMinute <= 0 ? Integer.MAX_VALUE : (int) (pointsRemaining / pointsPerMinute * 60);
int pointsAfterTimeIsOver = (int) (points + timeRemaining * pointsPerMinute / 60);
if (winInSecondsCalculated >= 0 && winInSecondsCalculated < timeRemaining) {
// This teamis going to win before the timer is over
winInSeconds = winInSecondsCalculated;
points = scoreNeededToEndGame;
} else {
winInSeconds = timeRemaining;
points = pointsAfterTimeIsOver;
}
}
if (points > highestScore) {
highestScore = points;
highestWinInSeconds = winInSeconds;
winner = team;
} else if (points == highestScore) {
if (winInSeconds < highestWinInSeconds) {
highestWinInSeconds = winInSeconds;
winner = team;
} else if (winInSeconds == highestWinInSeconds) {
winner = null;
}
}
}
}
StringBuilder message = new StringBuilder(64);
if (winner != null) {
message.append(winner.coloredPrefix()).append(ChatColor.GOLD).append(" Wins in: ");
} else {
message.append(ChatColor.WHITE).append("Time Left: ");
}
message.append(ChatColor.GREEN);
Utils.formatTimeLeft(message, timeRemaining);
return Collections.singletonList(message.toString());
}
});
}
use of com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler in project Warlords by ebicep.
the class FlagSpawnPointOption method register.
@Override
public void register(Game game) {
this.game = game;
// We register a gamemarker to prevent any captures for our own team if we lost our flag
game.registerGameMarker(FlagCaptureInhibitMarker.class, pFlag -> {
return !(info.getFlag() instanceof SpawnFlagLocation) && info.getTeam() == pFlag.getPlayer().getTeam();
});
game.registerGameMarker(DebugLocationMarker.class, DebugLocationMarker.create(Material.BANNER, 0, this.getClass(), "Flag spawn: " + info.getTeam(), this.info.getSpawnLocation()));
game.registerGameMarker(DebugLocationMarker.class, DebugLocationMarker.create(Material.BANNER, 15, this.getClass(), "Flag: " + info.getTeam(), () -> info.getFlag().getLocation(), () -> info.getFlag().getDebugInformation()));
FlagHolder holder = FlagHolder.create(() -> info);
game.registerGameMarker(FlagHolder.class, holder);
if (this.registerCompassMarker) {
game.registerGameMarker(CompassTargetMarker.class, holder);
}
game.registerGameMarker(ScoreboardHandler.class, scoreboard = new SimpleScoreboardHandler(info.getTeam() == Team.RED ? 20 : 21, "flag") {
@Override
public List<String> computeLines(@Nullable WarlordsPlayer player) {
String flagName = info.getTeam().coloredPrefix();
FlagLocation flag = info.getFlag();
if (flag instanceof SpawnFlagLocation) {
return singletonList(flagName + " Flag: " + ChatColor.GREEN + "Safe");
} else if (flag instanceof PlayerFlagLocation) {
PlayerFlagLocation pFlag = (PlayerFlagLocation) flag;
String extra = pFlag.getPickUpTicks() == 0 ? "" : ChatColor.YELLOW + " +" + pFlag.getComputedHumanMultiplier() + "§e%";
return singletonList(flagName + " Flag: " + ChatColor.RED + "Stolen!" + extra);
} else if (flag instanceof GroundFlagLocation) {
GroundFlagLocation gFlag = (GroundFlagLocation) flag;
return singletonList(flagName + " Flag: " + ChatColor.YELLOW + "Dropped! " + ChatColor.GRAY + gFlag.getDespawnTimerSeconds());
} else {
return singletonList(flagName + " Flag: " + ChatColor.GRAY + "Respawning...");
}
}
});
game.registerEvents(new Listener() {
@EventHandler(priority = EventPriority.LOW)
public void onArmorStandBreak(EntityDamageByEntityEvent event) {
boolean isOurArmorStand = renderer.getRenderedArmorStands().contains(event.getEntity());
WarlordsPlayer wp = Warlords.getPlayer(event.getDamager());
if (wp != null && wp.getGame() == game && isOurArmorStand) {
onFlagInteract(wp);
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPotentialFlagInteract(PlayerInteractEntityEvent event) {
onPotentialFlagInteract((PlayerEvent) event);
}
@EventHandler(priority = EventPriority.LOW)
public void onPotentialFlagInteract(PlayerInteractEvent event) {
onPotentialFlagInteract((PlayerEvent) event);
}
private void onPotentialFlagInteract(PlayerEvent event) {
WarlordsPlayer wp = Warlords.getPlayer(event.getPlayer());
if (wp != null && wp.getGame() == game) {
Location playerLocation = wp.getEntity().getEyeLocation();
Vector direction = wp.getEntity().getLocation().getDirection().multiply(3);
Vec3D from = new Vec3D(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ());
Vec3D to = new Vec3D(playerLocation.getX() + direction.getX(), playerLocation.getY() + direction.getY(), playerLocation.getZ() + direction.getZ());
checkFlagInteract(playerLocation, wp, from, to, renderer);
}
}
private void checkFlagInteract(Location playerLocation, WarlordsPlayer wp, Vec3D from, Vec3D to, FlagRenderer render) {
Location entityLoc = new Location(playerLocation.getWorld(), 0, 0, 0);
for (Entity stand : render.getRenderedArmorStands()) {
stand.getLocation(entityLoc);
if (entityLoc.getWorld() == playerLocation.getWorld() && entityLoc.distanceSquared(playerLocation) < 5 * 5) {
AxisAlignedBB aabb = new AxisAlignedBB(entityLoc.getX() - 0.5, entityLoc.getY(), entityLoc.getZ() - 0.5, entityLoc.getX() + 0.5, entityLoc.getY() + 2, entityLoc.getZ() + 0.5);
MovingObjectPosition mop = aabb.a(from, to);
if (mop != null) {
onFlagInteract(wp);
break;
}
}
}
}
private void onFlagInteract(WarlordsPlayer wp) {
Team team = wp.getTeam();
if (wp.isDeath()) {
return;
}
if (renderer.getLastFlagState() != info.getFlag()) {
// Prevent the player from interacting when the render state is outdated
return;
}
wp.setFlagCooldown(2);
if (info.getFlag() instanceof GroundFlagLocation) {
GroundFlagLocation groundFlagLocation = (GroundFlagLocation) info.getFlag();
if (team == info.getTeam()) {
// Return flag
info.setFlag(new SpawnFlagLocation(info.getSpawnLocation(), wp));
} else {
// Steal flag
info.setFlag(new PlayerFlagLocation(wp, groundFlagLocation.getDamageTimer()));
if (wp.getEntity().getVehicle() != null) {
wp.getEntity().getVehicle().remove();
}
}
} else if (info.getFlag() instanceof SpawnFlagLocation) {
if (team == info.getTeam()) {
// Nothing
wp.sendMessage("§cYou can't steal your own team's flag!");
} else {
// Steal flag
info.setFlag(new PlayerFlagLocation(wp, 0));
wp.getCooldownManager().addCooldown(new RegularCooldown<FlagSpawnPointOption>("Flag Damage Resistance", "RES", FlagSpawnPointOption.class, null, wp, CooldownTypes.BUFF, cooldownManager -> {
}, 15 * 20) {
@Override
public float modifyDamageAfterInterveneFromSelf(WarlordsDamageHealingEvent event, float currentDamageValue) {
return currentDamageValue * .9f;
}
});
}
}
}
});
}
use of com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler in project Warlords by ebicep.
the class ImposterModeOption method register.
@Override
public void register(@Nonnull Game game) {
this.game = game;
for (Team team : TeamMarker.getTeams(game)) {
imposters.put(team, new ArrayList<>());
}
game.registerGameMarker(ScoreboardHandler.class, new SimpleScoreboardHandler(30, "imposter") {
@Override
public List<String> computeLines(@Nullable WarlordsPlayer warlordsPlayer) {
if (warlordsPlayer == null) {
return Collections.emptyList();
}
if (imposters.get(warlordsPlayer.getTeam()).isEmpty()) {
return Collections.emptyList();
}
if (imposters.entrySet().stream().anyMatch(teamListEntry -> teamListEntry.getValue().contains(warlordsPlayer))) {
return Collections.singletonList(ChatColor.WHITE + "Role: " + ChatColor.RED + "Imposter");
}
return Collections.singletonList(ChatColor.WHITE + "Role: " + ChatColor.GREEN + "Innocent");
}
});
}
use of com.ebicep.warlords.game.option.marker.scoreboard.SimpleScoreboardHandler in project Warlords by ebicep.
the class InterceptionPointOption method register.
@Override
public void register(Game game) {
this.game = game;
game.registerGameMarker(CompassTargetMarker.class, new CompassTargetMarker() {
@Override
public int getCompassTargetPriority(WarlordsPlayer player) {
return (int) player.getDeathLocation().distanceSquared(location) / -100;
}
@Override
public String getToolbarName(WarlordsPlayer player) {
StringBuilder status = new StringBuilder();
if (teamAttacking == null) {
status.append(ChatColor.GRAY);
} else {
status.append(teamAttacking.teamColor());
}
status.append(name);
status.append(" ");
if (teamInCircle == null) {
status.append(ChatColor.GRAY);
} else {
status.append(teamInCircle.teamColor());
}
status.append((int) Math.floor(captureProgress * 100)).append("%");
status.append(ChatColor.WHITE).append(" - ");
if (inConflict) {
status.append(ChatColor.GOLD).append("In conflict");
} else if (teamOwning != player.getTeam()) {
if (teamInCircle != player.getTeam()) {
status.append(ChatColor.RED).append("Not under your control!");
} else {
status.append(ChatColor.AQUA).append("Your team is capturing this");
}
} else {
if (teamInCircle != player.getTeam()) {
status.append(ChatColor.RED).append("Point is under attack!");
} else {
status.append(ChatColor.GREEN).append("Safe");
}
}
return status.toString();
}
@Override
public Location getLocation() {
return location;
}
});
game.registerGameMarker(DebugLocationMarker.class, DebugLocationMarker.create(Material.TORCH, 0, this.getClass(), "Capture point: " + name, () -> location, () -> Arrays.asList("inConflict: " + inConflict, "teamOwning: " + teamOwning, "teamAttacking: " + teamAttacking, "teamInCircle: " + teamInCircle, "minCaptureRadius: " + minCaptureRadius, "maxCaptureRadius: " + maxCaptureRadius, "radius: " + computeCurrentRadius())));
game.registerGameMarker(ScoreboardHandler.class, scoreboard = new SimpleScoreboardHandler(19, "interception") {
@Override
public List<String> computeLines(@Nullable WarlordsPlayer player) {
StringBuilder status = new StringBuilder();
if (teamAttacking == null) {
status.append(ChatColor.GRAY);
} else {
status.append(teamAttacking.teamColor());
}
status.append(name);
status.append(ChatColor.WHITE);
status.append(": ");
if (teamInCircle == null) {
status.append(ChatColor.GRAY);
} else {
status.append(teamInCircle.teamColor());
}
status.append((int) Math.floor(captureProgress * 100)).append("%");
return Collections.singletonList(status.toString());
}
});
}
Aggregations