use of gg.projecteden.nexus.features.minigames.models.events.matches.MatchStartEvent in project Nexus by ProjectEdenGG.
the class Mechanic method onStart.
public void onStart(@NotNull MatchStartEvent event) {
Match match = event.getMatch();
match.broadcast("Starting match");
match.broadcastNoPrefix("");
int lives = match.getArena().getLives();
if (lives > 0)
match.getMinigamers().forEach(minigamer -> minigamer.setLives(lives));
else
match.getMinigamers().forEach(minigamer -> {
if (minigamer.getTeam().getLives() > 0)
minigamer.setLives(minigamer.getTeam().getLives());
});
int beginDelay = match.getArena().getBeginDelay();
if (beginDelay > 0) {
int taskId = match.getTasks().countdown(Countdown.builder().duration(TickTime.SECOND.x(beginDelay)).onSecond(i -> {
if (Arrays.asList(60, 30, 15, 5, 4, 3, 2, 1).contains(i))
match.broadcast("&7Starting in &e" + plural(i + " second", i) + "...");
}).onComplete(() -> {
MatchBeginEvent beginEvent = new MatchBeginEvent(match);
if (beginEvent.callEvent())
onBegin(beginEvent);
}));
match.getTasks().register(MatchTaskType.BEGIN_DELAY, taskId);
} else {
MatchBeginEvent beginEvent = new MatchBeginEvent(match);
if (beginEvent.callEvent())
onBegin(beginEvent);
}
int taskId = match.getTasks().repeat(0, 1, () -> match.getMinigamers().forEach(Minigamer::tick));
match.getTasks().register(MatchTaskType.TICK, taskId);
}
use of gg.projecteden.nexus.features.minigames.models.events.matches.MatchStartEvent in project Nexus by ProjectEdenGG.
the class HideAndSeek method onStart.
@Override
public void onStart(@NotNull MatchStartEvent event) {
super.onStart(event);
Match match = event.getMatch();
HideAndSeekMatchData matchData = match.getMatchData();
if (matchData.getMapMaterials().size() == 0) {
error("Arena has no blocks whitelisted!", match);
return;
}
for (Minigamer minigamer : match.getMinigamers()) {
if (isZombie(minigamer)) {
continue;
}
MiscDisguise disguise = new MiscDisguise(DisguiseType.FALLING_BLOCK, matchData.getBlockChoice(minigamer));
disguise.setEntity(minigamer.getPlayer());
disguise.startDisguise();
matchData.getDisguises().put(minigamer.getPlayer().getUniqueId(), disguise);
DisguiseAPI.setActionBarShown(minigamer.getPlayer(), false);
}
int taskId = match.getTasks().repeat(0, 1, () -> {
for (Minigamer minigamer : getHumans(match)) {
Player player = minigamer.getPlayer();
UUID userId = player.getUniqueId();
Map<Minigamer, Location> solidPlayers = matchData.getSolidPlayers();
int immobileTicks = minigamer.getImmobileTicks();
Material blockChoice = matchData.getBlockChoice(userId);
Component blockName = Component.translatable(blockChoice.getTranslationKey());
// if player just moved, break their disguise
if (immobileTicks < SOLIDIFY_PLAYER_AT && solidPlayers.containsKey(minigamer)) {
blockChange(minigamer, solidPlayers.remove(minigamer), Material.AIR);
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
player.removePotionEffect(PotionEffectType.INVISIBILITY);
FallingBlock fallingBlock = matchData.getSolidBlocks().remove(minigamer.getPlayer().getUniqueId());
if (fallingBlock != null)
fallingBlock.remove();
matchData.getDisguises().get(minigamer.getPlayer().getUniqueId()).startDisguise();
}
// check how long they've been still
if (immobileTicks < TickTime.SECOND.x(2)) {
sendBarWithTimer(minigamer, new JsonBuilder("&bYou are currently partially disguised as a ").next(blockName));
} else if (immobileTicks < SOLIDIFY_PLAYER_AT) {
// countdown until solidification
int seconds = (int) Math.ceil((SOLIDIFY_PLAYER_AT - immobileTicks) / 20d);
String display = String.format(plural("&dFully disguising in %d second", seconds) + "...", seconds);
sendBarWithTimer(minigamer, display);
} else {
if (!solidPlayers.containsKey(minigamer)) {
Location location = minigamer.getPlayer().getLocation();
if (immobileTicks == SOLIDIFY_PLAYER_AT && MaterialTag.ALL_AIR.isTagged(location.getBlock().getType())) {
// save fake block location
solidPlayers.put(minigamer, location);
// create a falling block to render on the hider's client
if (blockChoice.isSolid() && blockChoice.isOccluding()) {
FallingBlock fallingBlock = minigamer.getPlayer().getWorld().spawnFallingBlock(getCenteredLocation(location), blockChoice.createBlockData());
fallingBlock.setGravity(false);
fallingBlock.setHurtEntities(false);
fallingBlock.setDropItem(false);
fallingBlock.setVelocity(new Vector());
matchData.getSolidBlocks().put(minigamer.getPlayer().getUniqueId(), fallingBlock);
// stop their disguise (as otherwise the hider sees 2 of their block)
matchData.getDisguises().get(minigamer.getPlayer().getUniqueId()).stopDisguise();
}
// add invisibility to hide them/their falling block disguise
player.addPotionEffect(new PotionEffectBuilder(PotionEffectType.INVISIBILITY).maxDuration().ambient(true).build());
// run usual ticking
disguisedBlockTick(minigamer);
} else
sendBarWithTimer(minigamer, "&cYou cannot fully disguise inside non-air blocks!");
} else {
disguisedBlockTick(minigamer);
}
}
}
});
match.getTasks().register(taskId);
// separate task so this doesn't run as often
int hunterTaskId = match.getTasks().repeat(0, 5, () -> getZombies(match).forEach(minigamer -> {
Block block = minigamer.getPlayer().getTargetBlock(4, TargetBlockInfo.FluidMode.NEVER);
if (block == null)
return;
Material type = block.getType();
if (MaterialTag.ALL_AIR.isTagged(type))
return;
Component name = Component.translatable(type.getTranslationKey());
// this will create some grammatically weird messages ("Oak Planks is a possible hider")
// idk what to do about that though
JsonBuilder message = new JsonBuilder();
if (matchData.getMapMaterials().contains(type))
message.color(NamedTextColor.GREEN).next(name).next(" is a possible hider");
else
message.color(NamedTextColor.RED).next(name).next(" is not a possible hider");
sendBarWithTimer(minigamer, message);
}));
match.getTasks().register(hunterTaskId);
}
use of gg.projecteden.nexus.features.minigames.models.events.matches.MatchStartEvent in project Nexus by ProjectEdenGG.
the class HoleInTheWall method onStart.
@Override
public void onStart(@NotNull MatchStartEvent event) {
super.onStart(event);
Match match = event.getMatch();
HoleInTheWallArena arena = event.getMatch().getArena();
HoleInTheWallMatchData matchData = event.getMatch().getMatchData();
matchData.getTracks().forEach(track -> {
Optional<Minigamer> minigamer = arena.worldguard().getPlayersInRegion(track.getRegion()).stream().map(PlayerManager::get).filter(_minigamer -> _minigamer.isPlaying(match)).findFirst();
minigamer.ifPresent(track::setMinigamer);
});
match.getTasks().countdown(Countdown.builder().duration(TickTime.SECOND.x(5)).onSecond(i -> match.broadcast("&7Starting in &e" + i + "...")).onComplete(() -> {
match.broadcast("Go!");
matchData.getTracks().stream().filter(track -> track.getMinigamer() != null).forEach(Track::start);
}));
}
use of gg.projecteden.nexus.features.minigames.models.events.matches.MatchStartEvent in project Nexus by ProjectEdenGG.
the class MonsterMaze method onStart.
@Override
public void onStart(@NotNull MatchStartEvent event) {
super.onStart(event);
Match match = event.getMatch();
MonsterMazeMatchData matchData = match.getMatchData();
ProtectedRegion floor = match.getArena().getProtectedRegion("floor");
List<Location> goals = new ArrayList<>();
for (BlockVector3 vector : match.getArena().getRegion("floor")) {
Location location = match.worldguard().toLocation(vector);
if (location.getBlock().getType() == goalMaterial)
goals.add(location.add(0, 1, 0));
}
List<Block> spawnpoints = match.worldguard().getRandomBlocks(floor, floorMaterial, MONSTERS);
spawnpoints.stream().map(block -> block.getLocation().add(.5, 1, .5)).forEach(spawnpoint -> {
Mob monster = match.spawn(spawnpoint, Zombie.class);
monster.setAI(false);
monster.setSilent(true);
monster.setCollidable(false);
monster.setInvulnerable(true);
matchData.getMonsters().add(monster);
});
match.getMinigamers().forEach(this::preventJump);
match.getTasks().wait(TickTime.SECOND.x(5), () -> {
for (Mob monster : matchData.getMonsters()) {
monster.setAI(true);
updatePath(monster, goals);
}
match.getTasks().repeat(TickTime.SECOND.x(7), 30, () -> {
for (Mob monster : matchData.getMonsters()) if (!monster.getPathfinder().hasPath())
updatePath(monster, goals);
});
match.getTasks().repeat(0, 2, () -> {
for (Minigamer minigamer : match.getMinigamers()) for (Mob monster : matchData.getMonsters()) {
double distance = monster.getLocation().distance(minigamer.getPlayer().getLocation());
if (distance < .7) {
minigamer.getPlayer().damage(4);
launch(minigamer, monster);
}
}
});
List<Block> powerupLocations = match.worldguard().getRandomBlocks(floor, floorMaterial, POWERUPS);
match.broadcast("Power ups have spawned!");
for (Block block : powerupLocations) new PowerUpUtils(match, Arrays.asList(JUMPS)).spawn(block.getLocation().add(0, 1, 0), true);
});
}
Aggregations