Search in sources :

Example 1 with MinigameException

use of gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException in project Nexus by ProjectEdenGG.

the class Mastermind method onInteract.

@EventHandler
public void onInteract(PlayerInteractEvent event) {
    Block block = event.getClickedBlock();
    if (EquipmentSlot.HAND != event.getHand() || block == null)
        return;
    Minigamer minigamer = PlayerManager.get(event.getPlayer());
    if (!minigamer.isPlaying(this))
        return;
    if (Action.LEFT_CLICK_BLOCK.equals(event.getAction())) {
        event.setCancelled(true);
        removeBlock(minigamer, block);
        return;
    }
    if (Action.RIGHT_CLICK_BLOCK.equals(event.getAction())) {
        Match match = minigamer.getMatch();
        MastermindMatchData matchData = match.getMatchData();
        if (isInRegion(match, block, "button")) {
            if (!MaterialTag.BUTTONS.isTagged(block.getType()))
                return;
            // TODO Cleanup
            try {
                matchData.guess(minigamer);
            } catch (MinigameException ex) {
                minigamer.tell("&cError: " + ex.getMessage());
            } catch (Exception ex) {
                minigamer.tell("&cUnknown error occurred");
                ex.printStackTrace();
            }
            return;
        }
        if (MaterialTag.SIGNS.isTagged(block.getType())) {
            int guess = matchData.getGuess(minigamer);
            if (isInRegion(match, block, "colorblind")) {
                if (guess != 1) {
                    minigamer.tell("You cannot change colorblind mode in the middle of the game");
                    return;
                }
                matchData.toggleColorblind(minigamer);
                matchData.giveLoadout(minigamer);
                matchData.createAnswer();
                match.getArena().regenerate();
                return;
            }
            if (isInRegion(match, block, "repeats_off")) {
                if (guess != 1) {
                    minigamer.tell("You cannot change the difficulty mode in the middle of the game");
                    return;
                }
                matchData.setRepeats(false);
                matchData.createAnswer();
                match.getArena().regenerate();
                minigamer.tell("Difficulty mode updated");
                return;
            }
            if (isInRegion(match, block, "repeats_on")) {
                if (guess != 1) {
                    minigamer.tell("You cannot change the difficulty mode in the middle of the game");
                    return;
                }
                matchData.setRepeats(true);
                matchData.createAnswer();
                match.getArena().regenerate();
                minigamer.tell("Difficulty mode updated");
                return;
            }
        }
        Block placed = event.getClickedBlock().getRelative(event.getBlockFace());
        if (!isNullOrAir(event.getItem()) && !canBuild(minigamer, placed))
            event.setCancelled(true);
    }
}
Also used : MinigameException(gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException) Block(org.bukkit.block.Block) IMastermindMatchData(gg.projecteden.nexus.features.minigames.models.matchdata.IMastermindMatchData) MastermindMatchData(gg.projecteden.nexus.features.minigames.models.matchdata.MastermindMatchData) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) MinigameException(gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException) Match(gg.projecteden.nexus.features.minigames.models.Match) EventHandler(org.bukkit.event.EventHandler)

Example 2 with MinigameException

use of gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException in project Nexus by ProjectEdenGG.

the class Multimind method onInteract.

@EventHandler
public void onInteract(PlayerInteractEvent event) {
    Block block = event.getClickedBlock();
    if (EquipmentSlot.HAND != event.getHand() || block == null)
        return;
    Minigamer minigamer = PlayerManager.get(event.getPlayer());
    if (!minigamer.isPlaying(this))
        return;
    if (Action.LEFT_CLICK_BLOCK.equals(event.getAction())) {
        event.setCancelled(true);
        removeBlock(minigamer, block);
        return;
    }
    if (Action.RIGHT_CLICK_BLOCK.equals(event.getAction())) {
        Match match = minigamer.getMatch();
        MultimindMatchData matchData = match.getMatchData();
        if (MaterialTag.BUTTONS.isTagged(block.getType())) {
            // TODO Cleanup
            try {
                matchData.guess(minigamer);
            } catch (MinigameException ex) {
                minigamer.tell("&cError: " + ex.getMessage());
            } catch (Exception ex) {
                minigamer.tell("&cUnknown error occurred");
                ex.printStackTrace();
            }
            return;
        }
        if (MaterialTag.SIGNS.isTagged(block.getType())) {
            int guess = matchData.getGuess(minigamer);
            Sign sign = (Sign) block.getState();
            String line1 = stripColor(sign.getLine(0));
            if (line1.equals("< Colorblind >")) {
                if (guess != 1) {
                    minigamer.tell("You cannot change colorblind mode in the middle of the game");
                    return;
                }
                matchData.toggleColorblind(minigamer);
                matchData.giveLoadout(minigamer);
                matchData.createAnswer();
                match.getArena().regenerate();
                return;
            }
            if (line1.equals("< Difficulty >")) {
                if (guess != 1) {
                    minigamer.tell("You cannot change the difficulty mode in the middle of the game");
                    return;
                }
                String line2 = stripColor(sign.getLine(1));
                if (line2.equals("Easy"))
                    matchData.setRepeats(false);
                else if (line2.equals("Hard"))
                    matchData.setRepeats(true);
                matchData.createAnswer();
                match.getArena().regenerate();
                minigamer.tell("Difficulty mode updated");
                return;
            }
        }
        Block placed = event.getClickedBlock().getRelative(event.getBlockFace());
        if (!isNullOrAir(event.getItem()) && !canBuild(minigamer, placed))
            event.setCancelled(true);
    }
}
Also used : MultimindMatchData(gg.projecteden.nexus.features.minigames.models.matchdata.MultimindMatchData) MinigameException(gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) MinigameException(gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException) Match(gg.projecteden.nexus.features.minigames.models.Match) EventHandler(org.bukkit.event.EventHandler)

Example 3 with MinigameException

use of gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException in project Nexus by ProjectEdenGG.

the class HoleInTheWall method onInitialize.

@Override
public void onInitialize(@NotNull MatchInitializeEvent event) {
    super.onInitialize(event);
    HoleInTheWallArena arena = event.getMatch().getArena();
    HoleInTheWallMatchData matchData = event.getMatch().getMatchData();
    for (Location location : arena.getDesignHangerLocation()) {
        Set<ProtectedRegion> trackRegions = arena.getRegionsLikeAt("track", location);
        if (trackRegions.size() != 1)
            throw new MinigameException("Was expecting 1 track region at " + getLocationString(location) + ", but found " + trackRegions.size());
        Track track = matchData.new Track(trackRegions.iterator().next(), location);
        track.reset();
        matchData.getTracks().add(track);
    }
}
Also used : ProtectedRegion(com.sk89q.worldguard.protection.regions.ProtectedRegion) MinigameException(gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException) HoleInTheWallArena(gg.projecteden.nexus.features.minigames.models.arenas.HoleInTheWallArena) HoleInTheWallMatchData(gg.projecteden.nexus.features.minigames.models.matchdata.HoleInTheWallMatchData) Track(gg.projecteden.nexus.features.minigames.models.matchdata.HoleInTheWallMatchData.Track) Location(org.bukkit.Location)

Aggregations

MinigameException (gg.projecteden.nexus.features.minigames.models.exceptions.MinigameException)3 Match (gg.projecteden.nexus.features.minigames.models.Match)2 Minigamer (gg.projecteden.nexus.features.minigames.models.Minigamer)2 Block (org.bukkit.block.Block)2 EventHandler (org.bukkit.event.EventHandler)2 ProtectedRegion (com.sk89q.worldguard.protection.regions.ProtectedRegion)1 HoleInTheWallArena (gg.projecteden.nexus.features.minigames.models.arenas.HoleInTheWallArena)1 HoleInTheWallMatchData (gg.projecteden.nexus.features.minigames.models.matchdata.HoleInTheWallMatchData)1 Track (gg.projecteden.nexus.features.minigames.models.matchdata.HoleInTheWallMatchData.Track)1 IMastermindMatchData (gg.projecteden.nexus.features.minigames.models.matchdata.IMastermindMatchData)1 MastermindMatchData (gg.projecteden.nexus.features.minigames.models.matchdata.MastermindMatchData)1 MultimindMatchData (gg.projecteden.nexus.features.minigames.models.matchdata.MultimindMatchData)1 Location (org.bukkit.Location)1 Sign (org.bukkit.block.Sign)1