use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class PlayingState method begin.
@Override
@SuppressWarnings("null")
public void begin() {
this.game.setAcceptsSpectators(true);
this.game.setAcceptsPlayers(false);
this.resetTimer();
RemoveEntities.doRemove(this.game);
for (Option option : game.getOptions()) {
option.start(game);
}
this.game.forEachOfflinePlayer((player, team) -> {
if (team != null) {
PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
Warlords.addPlayer(new WarlordsPlayer(player, this, team, playerSettings));
}
});
this.game.forEachOfflineWarlordsPlayer(wp -> {
CustomScoreboard customScoreboard = Warlords.playerScoreboards.get(wp.getUuid());
updateBasedOnGameState(customScoreboard, wp);
if (wp.getEntity() instanceof Player) {
wp.applySkillBoost((Player) wp.getEntity());
}
});
if (DatabaseManager.playerService != null) {
Warlords.newChain().async(() -> game.forEachOfflinePlayer((player, team) -> {
DatabasePlayer databasePlayer = DatabaseManager.playerService.findByUUID(player.getUniqueId());
DatabaseManager.updatePlayerAsync(databasePlayer);
DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.SEASON_5, () -> {
});
DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.WEEKLY, () -> {
});
DatabaseManager.loadPlayer(player.getUniqueId(), PlayersCollections.DAILY, () -> {
});
})).execute();
} else {
System.out.println("ATTENTION - playerService is null");
}
game.registerEvents(new Listener() {
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onWin(WarlordsGameTriggerWinEvent event) {
game.setNextState(new EndState(game, event));
winEvent = event;
}
});
GameRunnable.create(game, this::updateScoreboard).runTaskTimer(0, 10);
new GameRunnable(game) {
@Override
public void run() {
counter++;
timer += GameRunnable.SECOND;
if (counter >= 60) {
counter -= 60;
PlayerFilter.playingGame(game).forEach(wp -> wp.getMinuteStats().advanceMinute());
}
PlayerFilter.playingGame(game).forEach(wp -> wp.getSecondStats().advanceSecond());
}
}.runTaskTimer(0, GameRunnable.SECOND);
game.registerGameMarker(TimerSkipAbleMarker.class, (delay) -> {
counter += delay / GameRunnable.SECOND;
timer += delay;
});
Warlords.getInstance().hideAndUnhidePeople();
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class SoothingPuddle method onActivate.
@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
wp.subtractEnergy(energyCost);
Location location = player.getLocation();
Vector speed = player.getLocation().getDirection().multiply(SPEED);
ArmorStand stand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
stand.setHelmet(new ItemStack(Material.STAINED_GLASS, 1, (short) 6));
stand.setGravity(false);
stand.setVisible(false);
new GameRunnable(wp.getGame()) {
int timer = 0;
@Override
public void run() {
quarterStep(false);
quarterStep(false);
quarterStep(false);
quarterStep(false);
quarterStep(false);
quarterStep(false);
quarterStep(true);
}
private void quarterStep(boolean last) {
if (!stand.isValid()) {
this.cancel();
return;
}
speed.add(new Vector(0, GRAVITY * SPEED, 0));
Location newLoc = stand.getLocation();
newLoc.add(speed);
stand.teleport(newLoc);
newLoc.add(0, 1.75, 0);
stand.setHeadPose(new EulerAngle(-speed.getY() * 3, 0, 0));
boolean shouldExplode;
timer++;
if (last) {
Matrix4d center = new Matrix4d(newLoc);
for (float i = 0; i < 6; i++) {
double angle = Math.toRadians(i * 90) + timer * 0.3;
double width = 0.4D;
ParticleEffect.VILLAGER_HAPPY.display(0, 0, 0, 0, 2, center.translateVector(newLoc.getWorld(), 0, Math.sin(angle) * width, Math.cos(angle) * width), 500);
}
}
WarlordsPlayer directHit;
if (!newLoc.getBlock().isEmpty() && newLoc.getBlock().getType() != Material.GRASS && newLoc.getBlock().getType() != Material.BARRIER && newLoc.getBlock().getType() != Material.VINE) {
// Explode based on collision
shouldExplode = true;
} else {
directHit = PlayerFilter.entitiesAroundRectangle(newLoc, 1, 2, 1).aliveTeammatesOfExcludingSelf(wp).findFirstOrNull();
shouldExplode = directHit != null;
newLoc.add(0, -1, 0);
}
newLoc.add(0, 1, 0);
if (shouldExplode) {
stand.remove();
Utils.playGlobalSound(newLoc, "rogue.healingremedy.impact", 1.5f, 0.2f);
Utils.playGlobalSound(newLoc, Sound.GLASS, 1.5f, 0.7f);
Utils.playGlobalSound(newLoc, "mage.waterbolt.impact", 1.5f, 0.3f);
FireWorkEffectPlayer.playFirework(newLoc, FireworkEffect.builder().withColor(Color.WHITE).with(FireworkEffect.Type.BURST).build());
for (WarlordsPlayer nearEntity : PlayerFilter.entitiesAround(newLoc, HITBOX, HITBOX, HITBOX).aliveTeammatesOf(wp)) {
nearEntity.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
}
CircleEffect circleEffect = new CircleEffect(wp.getGame(), wp.getTeam(), newLoc, HITBOX, new CircumferenceEffect(ParticleEffect.VILLAGER_HAPPY, ParticleEffect.REDSTONE), new AreaEffect(1, ParticleEffect.DRIP_WATER).particlesPerSurface(0.025));
BukkitTask task = Bukkit.getScheduler().runTaskTimer(Warlords.getInstance(), circleEffect::playEffects, 0, 1);
wp.getGame().registerGameTask(task);
new GameRunnable(wp.getGame()) {
int timeLeft = 4;
@Override
public void run() {
PlayerFilter.entitiesAround(newLoc, HITBOX, HITBOX, HITBOX).aliveTeammatesOf(wp).forEach((ally) -> ally.addHealingInstance(wp, name, puddleMinHealing, puddleMaxHealing, critChance, critMultiplier, false, false));
timeLeft--;
if (timeLeft < 0) {
this.cancel();
task.cancel();
}
}
}.runTaskTimer(20, 20);
this.cancel();
}
}
}.runTaskTimer(0, 1);
Utils.playGlobalSound(player.getLocation(), "mage.frostbolt.activation", 2, 0.7f);
return true;
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class UndyingArmy method onActivate.
@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
wp.subtractEnergy(energyCost);
UndyingArmy tempUndyingArmy = new UndyingArmy();
int numberOfPlayersWithArmy = 0;
for (WarlordsPlayer teammate : PlayerFilter.entitiesAround(wp, radius, radius, radius).aliveTeammatesOf(wp).closestFirst(wp)) {
tempUndyingArmy.getPlayersPopped().put(teammate, false);
if (teammate != wp) {
wp.sendMessage(WarlordsPlayer.RECEIVE_ARROW + ChatColor.GRAY + " Your " + ChatColor.YELLOW + "Undying Army" + ChatColor.GRAY + " is now protecting " + teammate.getName() + ChatColor.GRAY + ".");
teammate.sendMessage(WarlordsPlayer.RECEIVE_ARROW + ChatColor.GRAY + " " + ChatColor.GRAY + wp.getName() + "'s " + ChatColor.YELLOW + "Undying Army" + ChatColor.GRAY + " is now protecting you for " + ChatColor.GOLD + duration + ChatColor.GRAY + " seconds.");
}
teammate.getCooldownManager().addRegularCooldown(name, "ARMY", UndyingArmy.class, tempUndyingArmy, wp, CooldownTypes.ABILITY, cooldownManager -> {
}, duration * 20);
new GameRunnable(wp.getGame()) {
@Override
public void run() {
Optional<UndyingArmy> optionalUndyingArmy = new CooldownFilter<>(teammate, RegularCooldown.class).findFirstObject(tempUndyingArmy, UndyingArmy.class);
if (optionalUndyingArmy.isPresent()) {
if (!(optionalUndyingArmy.get()).isArmyDead(teammate)) {
float healAmount = 100 + (teammate.getMaxHealth() - teammate.getHealth()) * 0.035f;
teammate.addHealingInstance(wp, name, healAmount, healAmount, -1, 100, false, false);
teammate.playSound(teammate.getLocation(), "paladin.holyradiance.activation", 0.1f, 0.7f);
// particles
Location playerLoc = teammate.getLocation();
playerLoc.add(0, 2.1, 0);
Location particleLoc = playerLoc.clone();
for (int i = 0; i < 1; i++) {
for (int j = 0; j < 10; j++) {
double angle = j / 10D * Math.PI * 2;
double width = 0.5;
particleLoc.setX(playerLoc.getX() + Math.sin(angle) * width);
particleLoc.setY(playerLoc.getY() + i / 5D);
particleLoc.setZ(playerLoc.getZ() + Math.cos(angle) * width);
ParticleEffect.REDSTONE.display(new ParticleEffect.OrdinaryColor(255, 255, 255), particleLoc, 500);
}
}
} else {
this.cancel();
}
} else {
this.cancel();
}
}
}.runTaskTimer(0, 20);
numberOfPlayersWithArmy++;
if (numberOfPlayersWithArmy >= maxArmyAllies) {
break;
}
}
Utils.playGlobalSound(player.getLocation(), Sound.ZOMBIE_IDLE, 2, 0.3f);
Utils.playGlobalSound(player.getLocation(), Sound.AMBIENCE_THUNDER, 2, 0.9f);
// particles
Location loc = player.getEyeLocation();
loc.setPitch(0);
loc.setYaw(0);
Matrix4d matrix = new Matrix4d();
for (int i = 0; i < 9; i++) {
loc.setYaw(loc.getYaw() + 360F / 9F);
matrix.updateFromLocation(loc);
for (int c = 0; c < 30; c++) {
double angle = c / 30D * Math.PI * 2;
double width = 1.5;
ParticleEffect.ENCHANTMENT_TABLE.display(0, 0.1f, 0, 0, 1, matrix.translateVector(player.getWorld(), radius, Math.sin(angle) * width, Math.cos(angle) * width), 500);
}
for (int c = 0; c < 15; c++) {
double angle = c / 15D * Math.PI * 2;
double width = 0.6;
ParticleEffect.SPELL.display(0, 0, 0, 0, 1, matrix.translateVector(player.getWorld(), radius, Math.sin(angle) * width, Math.cos(angle) * width), 500);
}
}
CircleEffect circle = new CircleEffect(wp.getGame(), wp.getTeam(), player.getLocation(), radius);
circle.addEffect(new CircumferenceEffect(ParticleEffect.VILLAGER_HAPPY, ParticleEffect.REDSTONE).particlesPerCircumference(2));
circle.playEffects();
return true;
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class WaterBreath method onActivate.
@Override
public boolean onActivate(@Nonnull WarlordsPlayer wp, @Nonnull Player player) {
wp.subtractEnergy(energyCost);
wp.getCooldownManager().removeDebuffCooldowns();
wp.getSpeed().removeSlownessModifiers();
wp.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
Location playerLoc = player.getLocation();
playerLoc.setPitch(0);
playerLoc.add(0, 1.7, 0);
Vector viewDirection = playerLoc.getDirection();
Location hitbox = player.getLocation();
hitbox.setPitch(0);
hitbox.add(hitbox.getDirection().multiply(-1));
PlayerFilter.entitiesAroundRectangle(playerLoc, 7.5, 10, 7.5).excluding(wp).forEach(target -> {
Vector direction = target.getLocation().subtract(hitbox).toVector().normalize();
if (viewDirection.dot(direction) > .68) {
if (wp.isTeammateAlive(target)) {
target.getCooldownManager().removeDebuffCooldowns();
target.getSpeed().removeSlownessModifiers();
target.addHealingInstance(wp, name, minDamageHeal, maxDamageHeal, critChance, critMultiplier, false, false);
target.getCooldownManager().removeCooldown(Overheal.OVERHEAL_MARKER);
target.getCooldownManager().addRegularCooldown("Overheal", "OVERHEAL", Overheal.class, Overheal.OVERHEAL_MARKER, wp, CooldownTypes.BUFF, cooldownManager -> {
}, Overheal.OVERHEAL_DURATION * 20);
} else {
final Location loc = target.getLocation();
final Vector v = player.getLocation().toVector().subtract(loc.toVector()).normalize().multiply(-1.1).setY(0.2);
target.setVelocity(v);
}
}
});
Utils.playGlobalSound(player.getLocation(), "mage.waterbreath.activation", 2, 1);
ParticleEffect.HEART.display(0.6f, 0.6f, 0.6f, 1, 2, player.getLocation().add(0, 0.7, 0), 500);
new GameRunnable(wp.getGame()) {
@Override
public void run() {
this.playEffect();
this.playEffect();
}
int animationTimer = 0;
final Matrix4d center = new Matrix4d(playerLoc);
public void playEffect() {
if (animationTimer > 12) {
this.cancel();
}
for (int i = 0; i < 4; i++) {
double angle = Math.toRadians(i * 90) + animationTimer * 0.15;
double width = animationTimer * 0.3;
ParticleEffect.DRIP_WATER.display(0, 0, 0, 0, 1, center.translateVector(wp.getWorld(), animationTimer / 2D, Math.sin(angle) * width, Math.cos(angle) * width), 500);
ParticleEffect.ENCHANTMENT_TABLE.display(0, 0, 0, 0, 1, center.translateVector(wp.getWorld(), animationTimer / 2D, Math.sin(angle) * width, Math.cos(angle) * width), 500);
ParticleEffect.VILLAGER_HAPPY.display(0, 0, 0, 0, 1, center.translateVector(wp.getWorld(), animationTimer / 2D, Math.sin(angle) * width, Math.cos(angle) * width), 500);
}
animationTimer++;
}
}.runTaskTimer(0, 1);
return true;
}
use of com.ebicep.warlords.util.warlords.GameRunnable in project Warlords by ebicep.
the class Windfury method onActivate.
@Override
public boolean onActivate(WarlordsPlayer wp, Player player) {
wp.subtractEnergy(energyCost);
Windfury tempWindfury = new Windfury();
final boolean[] firstProc = { true };
wp.getCooldownManager().addCooldown(new RegularCooldown<Windfury>(name, "FURY", Windfury.class, tempWindfury, wp, CooldownTypes.ABILITY, cooldownManager -> {
}, duration * 20) {
@Override
public void onEndFromAttacker(WarlordsDamageHealingEvent event, float currentDamageValue, boolean isCrit) {
if (event.getAbility().isEmpty()) {
WarlordsPlayer victim = event.getPlayer();
WarlordsPlayer attacker = event.getAttacker();
float min = event.getMin();
float max = event.getMax();
int windfuryActivate = (int) (Math.random() * 100);
if (firstProc[0]) {
firstProc[0] = false;
windfuryActivate = 0;
}
if (windfuryActivate < procChance) {
new BukkitRunnable() {
int counter = 0;
@Override
public void run() {
victim.getGameState().getGame().forEachOnlinePlayerWithoutSpectators((player1, t) -> {
player1.playSound(victim.getLocation(), "shaman.windfuryweapon.impact", 2, 1);
});
if (Warlords.getPlayerSettings(attacker.getUuid()).getSkillBoostForClass() == ClassesSkillBoosts.WINDFURY_WEAPON) {
victim.addDamageInstance(attacker, "Windfury Weapon", min * 1.35f * 1.2f, max * 1.35f * 1.2f, 25, 200, false);
} else {
victim.addDamageInstance(attacker, "Windfury Weapon", min * 1.35f, max * 1.35f, 25, 200, false);
}
counter++;
if (counter == 2) {
this.cancel();
}
}
}.runTaskTimer(Warlords.getInstance(), 3, 3);
}
}
}
});
Utils.playGlobalSound(player.getLocation(), "shaman.windfuryweapon.activation", 2, 1);
new GameRunnable(wp.getGame()) {
@Override
public void run() {
if (wp.getCooldownManager().hasCooldown(tempWindfury)) {
Location location = wp.getLocation();
location.add(0, 1.2, 0);
ParticleEffect.CRIT.display(0.2F, 0F, 0.2F, 0.1F, 3, location, 500);
} else {
this.cancel();
}
}
}.runTaskTimer(0, 4);
return true;
}
Aggregations