Search in sources :

Example 1 with MiniGolfBallMoveEvent

use of gg.projecteden.nexus.features.minigolf.models.events.MiniGolfBallMoveEvent in project Nexus by ProjectEdenGG.

the class MiniGolf method miniGolfTask.

private void miniGolfTask() {
    Tasks.repeat(0, TickTime.TICK, () -> {
        if (golfBalls.isEmpty())
            return;
        for (GolfBall golfBall : new ArrayList<>(golfBalls)) {
            Snowball ball = golfBall.getSnowball();
            if (ball == null)
                continue;
            if (!ball.isValid()) {
                golfBall.remove();
                continue;
            }
            // Location location = ball.getLocation();
            // if (golfBall.getLastLocation().equals(location))
            // continue;
            MiniGolfBallMoveEvent ballMoveEvent = new MiniGolfBallMoveEvent(golfBall, golfBall.getLastLocation(), ball.getLocation());
            if (!ballMoveEvent.callEvent()) {
                ball.teleportAsync(golfBall.getLastLocation());
                ball.setVelocity(ball.getVelocity());
            }
            Block below = golfBall.getBlockBelow();
            Material belowType = below.getType();
            for (ModifierBlockType modifierBlockType : ModifierBlockType.values()) {
                ModifierBlock modifierBlock = modifierBlockType.getModifierBlock();
                if (modifierBlockType.equals(ModifierBlockType.DEFAULT) || modifierBlock.getMaterials().contains(belowType)) {
                    MiniGolfBallModifierBlockEvent modifierBlockEvent = new MiniGolfBallModifierBlockEvent(golfBall, modifierBlockType);
                    if (modifierBlockEvent.callEvent()) {
                        modifierBlock.handleRoll(golfBall);
                        break;
                    }
                }
            }
        }
    });
}
Also used : Snowball(org.bukkit.entity.Snowball) ModifierBlock(gg.projecteden.nexus.features.minigolf.models.blocks.ModifierBlock) MiniGolfBallModifierBlockEvent(gg.projecteden.nexus.features.minigolf.models.events.MiniGolfBallModifierBlockEvent) ModifierBlockType(gg.projecteden.nexus.features.minigolf.models.blocks.ModifierBlockType) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) ModifierBlock(gg.projecteden.nexus.features.minigolf.models.blocks.ModifierBlock) Material(org.bukkit.Material) MiniGolfBallMoveEvent(gg.projecteden.nexus.features.minigolf.models.events.MiniGolfBallMoveEvent) GolfBall(gg.projecteden.nexus.features.minigolf.models.GolfBall)

Aggregations

GolfBall (gg.projecteden.nexus.features.minigolf.models.GolfBall)1 ModifierBlock (gg.projecteden.nexus.features.minigolf.models.blocks.ModifierBlock)1 ModifierBlockType (gg.projecteden.nexus.features.minigolf.models.blocks.ModifierBlockType)1 MiniGolfBallModifierBlockEvent (gg.projecteden.nexus.features.minigolf.models.events.MiniGolfBallModifierBlockEvent)1 MiniGolfBallMoveEvent (gg.projecteden.nexus.features.minigolf.models.events.MiniGolfBallMoveEvent)1 ArrayList (java.util.ArrayList)1 Material (org.bukkit.Material)1 Block (org.bukkit.block.Block)1 Snowball (org.bukkit.entity.Snowball)1