Search in sources :

Example 1 with MinigamerDeathEvent

use of gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent in project Nexus by ProjectEdenGG.

the class SabotageMatchData method endMeeting.

public void endMeeting() {
    if (votingScreen instanceof ResultsScreen)
        return;
    AbstractVoteScreen oldScreen = votingScreen;
    votingScreen = new ResultsScreen();
    meetingEnded = LocalDateTime.now();
    match.getTasks().cancel(meetingTaskID);
    match.getTasks().cancel(endMeetingTask);
    meetingTaskID = -1;
    endMeetingTask = -1;
    match.getMinigamers().forEach(minigamer -> {
        oldScreen.close(minigamer);
        votingScreen.open(minigamer);
        minigamer.getPlayer().getInventory().remove(Sabotage.VOTING_ITEM.get());
    });
    match.getTasks().wait(TimeUtils.TickTime.SECOND.x(Sabotage.POST_MEETING_DELAY), () -> {
        match.getMinigamers().forEach(minigamer -> votingScreen.close(minigamer));
        Minigamer ejected = null;
        int votes = getVotesFor(null).size();
        boolean tie = false;
        for (Minigamer minigamer : match.getAliveMinigamers()) {
            int mVotes = getVotesFor(minigamer).size();
            if (mVotes > votes) {
                ejected = minigamer;
                votes = mVotes;
                tie = false;
            } else if (mVotes == votes) {
                ejected = null;
                tie = true;
            }
        }
        String ejectedName;
        if (ejected != null) {
            ejectedName = ejected.getNickname();
        } else
            ejectedName = "Nobody";
        String display = ejectedName + " was ejected.";
        if (ejected == null)
            display += " (" + (tie ? "Tied" : "Skipped") + ")";
        // TODO: true animation
        match.showTitle(Title.title(Component.empty(), new JsonBuilder(display).build(), Title.Times.of(fade, Duration.ofSeconds(7), fade)));
        match.playSound(Sound.sound(org.bukkit.Sound.ENTITY_PLAYER_SPLASH_HIGH_SPEED, Sound.Source.PLAYER, 1.0F, 1.0F));
        clearVotes();
        votingScreen = null;
        roundStarted = LocalDateTime.now();
        match.getMinigamers().forEach(Minigamer::respawn);
        SabotageTeam team = SabotageTeam.of(ejected);
        if (team == SabotageTeam.JESTER) {
            ejected.scored();
            match.end();
        } else if (ejected != null)
            match.getMechanic().onDeath(new MinigamerDeathEvent(ejected));
    });
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) AbstractVoteScreen(gg.projecteden.nexus.features.menus.sabotage.AbstractVoteScreen) ResultsScreen(gg.projecteden.nexus.features.menus.sabotage.ResultsScreen) SabotageTeam(gg.projecteden.nexus.features.minigames.models.mechanics.custom.sabotage.SabotageTeam) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent)

Example 2 with MinigamerDeathEvent

use of gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent in project Nexus by ProjectEdenGG.

the class AntiCampingTask method teleport.

private void teleport(@NotNull Minigamer minigamer, int floorId) {
    Arena arena = minigamer.getMatch().getArena();
    Mechanic mechanic = arena.getMechanic();
    ProtectedRegion floorAt;
    // Floor ID not provided, get it
    if (floorId == -1) {
        floorAt = getFloorAt(minigamer);
        if (floorAt == null)
            throw new InvalidInputException("Could not find floor for player " + minigamer.getNickname());
        floorId = Arena.getRegionNumber(floorAt);
    } else {
        // Floor ID provided (probably recursively trying to find next floor down)
        floorAt = arena.getProtectedRegion("floor_" + floorId);
    }
    if (floorId < 2) {
        MinigamerDeathEvent deathEvent = new MinigamerDeathEvent(minigamer);
        if (!deathEvent.callEvent())
            return;
        mechanic.onDeath(deathEvent);
    } else {
        Location location = minigamer.getPlayer().getLocation();
        location.setY(floorAt.getMinimumPoint().getY() - 1);
        Region floorTo = arena.getRegion("floor_" + --floorId);
        Location to = null;
        while (location.getY() >= floorTo.getMinimumPoint().getY()) {
            location.add(0, -1, 0);
            if (!location.getBlock().getType().isSolid())
                continue;
            to = location;
            break;
        }
        if (to != null) {
            teleport(minigamer, to);
            return;
        }
        // Set up correct origin and search radius for nearest block check
        int yDiff = floorTo.getMaximumPoint().getBlockY() - floorTo.getMinimumPoint().getBlockY();
        location.setY(floorTo.getMaximumPoint().getBlockY());
        if (yDiff > 0) {
            yDiff = (yDiff / 2) + 1;
            location.add(0, -yDiff, 0);
        }
        List<Block> blocks = BlockUtils.getBlocksInRadius(location.getBlock(), 4, yDiff, 4).stream().filter(block -> block.getType().isSolid()).sorted((block1, block2) -> {
            Double distance1 = block1.getLocation().distance(minigamer.getPlayer().getLocation());
            Double distance2 = block2.getLocation().distance(minigamer.getPlayer().getLocation());
            return distance1.compareTo(distance2);
        }).collect(Collectors.toList());
        // No blocks within required radius on below floor, try next one
        if (blocks.size() == 0) {
            teleport(minigamer, floorId);
            return;
        }
        teleport(minigamer, blocks.get(0).getLocation());
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) NonNull(lombok.NonNull) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Set(java.util.Set) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Match(gg.projecteden.nexus.features.minigames.models.Match) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) TickTime(gg.projecteden.utils.TimeUtils.TickTime) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Block(org.bukkit.block.Block) Builder(lombok.Builder) Location(org.bukkit.Location) Mechanic(gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic) Map(java.util.Map) AllArgsConstructor(lombok.AllArgsConstructor) NotNull(org.jetbrains.annotations.NotNull) Region(com.sk89q.worldedit.regions.Region) BlockUtils(gg.projecteden.nexus.utils.BlockUtils) LocationUtils(gg.projecteden.nexus.utils.LocationUtils) InvalidInputException(gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException) Mechanic(gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) Region(com.sk89q.worldedit.regions.Region) Block(org.bukkit.block.Block) Arena(gg.projecteden.nexus.features.minigames.models.Arena) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent) Location(org.bukkit.Location)

Example 3 with MinigamerDeathEvent

use of gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent in project Nexus by ProjectEdenGG.

the class Mechanic method kill.

public void kill(@NotNull Minigamer victim, @Nullable Minigamer attacker) {
    MinigamerDeathEvent event = new MinigamerDeathEvent(victim, attacker);
    if (!event.callEvent())
        return;
    onDeath(event);
}
Also used : MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent)

Aggregations

MinigamerDeathEvent (gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent)3 Minigamer (gg.projecteden.nexus.features.minigames.models.Minigamer)2 Region (com.sk89q.worldedit.regions.Region)1 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 AbstractVoteScreen (gg.projecteden.nexus.features.menus.sabotage.AbstractVoteScreen)1 ResultsScreen (gg.projecteden.nexus.features.menus.sabotage.ResultsScreen)1 Arena (gg.projecteden.nexus.features.minigames.models.Arena)1 Match (gg.projecteden.nexus.features.minigames.models.Match)1 Mechanic (gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic)1 SabotageTeam (gg.projecteden.nexus.features.minigames.models.mechanics.custom.sabotage.SabotageTeam)1 InvalidInputException (gg.projecteden.nexus.framework.exceptions.postconfigured.InvalidInputException)1 BlockUtils (gg.projecteden.nexus.utils.BlockUtils)1 JsonBuilder (gg.projecteden.nexus.utils.JsonBuilder)1 LocationUtils (gg.projecteden.nexus.utils.LocationUtils)1 TickTime (gg.projecteden.utils.TimeUtils.TickTime)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1