Search in sources :

Example 46 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class BasicRecorder method takeItem.

@EventHandler(ignoreCancelled = true)
private void takeItem(PlayerInteractEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame() && event.getAction() == Action.RIGHT_CLICK_BLOCK && !ply.getMinigame().isSpectator(ply)) {
        Minigame mgm = ply.getMinigame();
        RecorderData d = mgm.getBlockRecorder();
        if (event.getClickedBlock().getState() instanceof InventoryHolder) {
            d.addBlock(event.getClickedBlock().getLocation().getBlock(), ply);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) InventoryHolder(org.bukkit.inventory.InventoryHolder) EventHandler(org.bukkit.event.EventHandler)

Example 47 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class BasicRecorder method bucketEmpty.

@EventHandler(ignoreCancelled = true)
private void bucketEmpty(PlayerBucketEmptyEvent event) {
    MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame()) {
        Minigame mgm = ply.getMinigame();
        RecorderData d = mgm.getBlockRecorder();
        if (((d.getWhitelistMode() && d.getWBBlocks().contains(event.getBlockClicked().getType())) || (!d.getWhitelistMode() && !d.getWBBlocks().contains(event.getBlockClicked().getType()))) && mgm.canBlockPlace()) {
            Location loc = new Location(event.getBlockClicked().getWorld(), event.getBlockFace().getModX() + event.getBlockClicked().getX(), event.getBlockFace().getModY() + event.getBlockClicked().getY(), event.getBlockFace().getModZ() + event.getBlockClicked().getZ());
            d.addBlock(loc.getBlock(), pdata.getMinigamePlayer(event.getPlayer()));
        } else {
            event.setCancelled(true);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 48 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class SingleplayerType method onPlayerRespawn.

/*----------------*/
/*-----EVENTS-----*/
/*----------------*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
    if (pdata.getMinigamePlayer(event.getPlayer()).isInMinigame()) {
        MinigamePlayer player = pdata.getMinigamePlayer(event.getPlayer());
        Minigame mgm = player.getMinigame();
        if (mgm.getType() == MinigameType.SINGLEPLAYER) {
            event.setRespawnLocation(player.getCheckpoint());
            player.sendMessage(MinigameUtils.getLang("player.checkpoint.deathRevert"), MinigameMessageType.ERROR);
            player.getLoadout().equiptLoadout(player);
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 49 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class MinigamePlayerManager method revertToCheckpoint.

public void revertToCheckpoint(MinigamePlayer player) {
    RevertCheckpointEvent event = new RevertCheckpointEvent(player);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        player.teleport(player.getCheckpoint());
        player.addRevert();
        player.sendInfoMessage(MinigameUtils.getLang("player.checkpoint.revert"));
        // Reset the player's health and extinguish flames when they revert
        Player p = player.getPlayer();
        if ((p != null) && (p.isOnline())) {
            p.setFireTicks(0);
            AttributeInstance maxHealth = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
            if (maxHealth != null) {
                p.setHealth(maxHealth.getValue());
            }
            p.setFoodLevel(20);
            p.setSaturation(20f);
            p.setRemainingAir(p.getMaximumAir());
        }
    }
}
Also used : Player(org.bukkit.entity.Player) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) AttributeInstance(org.bukkit.attribute.AttributeInstance)

Example 50 with MinigamePlayer

use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.

the class MinigamePlayerManager method endMinigame.

public void endMinigame(Minigame minigame, List<MinigamePlayer> winners, List<MinigamePlayer> losers) {
    // When the minigame ends, the flag for recognizing the start teleportation needs to be resetted
    minigame.setPlayersAtStart(false);
    EndMinigameEvent event = new EndMinigameEvent(winners, losers, minigame);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        winners = event.getWinners();
        losers = event.getLosers();
        // Call Mechanics End
        minigame.getMechanic().endMinigame(minigame, winners, losers);
        // Prepare split money
        double bets = 0;
        if (minigame.getMpBets() != null) {
            if (minigame.getMpBets().hasMoneyBets()) {
                List<MinigamePlayer> plys = new ArrayList<>(event.getWinners());
                if (!plys.isEmpty()) {
                    bets = minigame.getMpBets().claimMoneyBets() / (double) plys.size();
                    BigDecimal roundBets = new BigDecimal(bets);
                    roundBets = roundBets.setScale(2, BigDecimal.ROUND_HALF_UP);
                    bets = roundBets.doubleValue();
                }
                minigame.setMpBets(null);
            }
        }
        // Broadcast Message
        broadcastEndGame(winners, minigame);
        GameOverModule gom = GameOverModule.getMinigameModule(minigame);
        boolean usedTimer = false;
        gom.setWinners(winners);
        gom.setLosers(losers);
        if (gom.getTimer() > 0 && minigame.getType() == MinigameType.MULTIPLAYER) {
            gom.startEndGameTimer();
            usedTimer = true;
        }
        for (MinigamePlayer player : losers) {
            player.setEndTime(System.currentTimeMillis());
            if (!usedTimer)
                quitMinigame(player, true);
            PlayMGSound.playSound(player, MGSounds.getSound("lose"));
        }
        for (MinigamePlayer player : winners) {
            player.setEndTime(System.currentTimeMillis());
            StoredGameStats saveData = new StoredGameStats(minigame, player);
            saveData.addStat(MinigameStats.Attempts, 1);
            saveData.addStat(MinigameStats.Wins, 1);
            saveData.addStat(MinigameStats.Kills, player.getKills());
            saveData.addStat(MinigameStats.Deaths, player.getDeaths());
            saveData.addStat(MinigameStats.Score, player.getScore());
            saveData.addStat(MinigameStats.Reverts, player.getReverts());
            saveData.addStat(MinigameStats.CompletionTime, player.getEndTime() - player.getStartTime() + player.getStoredTime());
            if (minigame.getShowCompletionTime()) {
                player.sendInfoMessage("Completion time: " + (double) (winners.get(0).getEndTime() - winners.get(0).getStartTime() + winners.get(0).getStoredTime()) / 1000 + " seconds");
            }
            for (DynamicMinigameStat stat : MinigameStats.getDynamicStats()) {
                if (stat.doesApply(minigame, player, true)) {
                    saveData.addStat(stat, stat.getValue(minigame, player, true));
                }
            }
            saveData.applySettings(minigame.getStatSettings(saveData));
            if (!usedTimer)
                quitMinigame(player, true);
            // Group money bets
            if (bets != 0) {
                plugin.getEconomy().depositPlayer(player.getPlayer().getPlayer(), bets);
                player.sendInfoMessage(MinigameUtils.formStr("player.bet.winMoney", Minigames.getPlugin().getEconomy().format(bets)));
            }
            // Record player completion and give rewards
            if (minigame.isEnabled()) {
                plugin.queueStatSave(saveData, true);
            } else {
                MinigameUtils.debugMessage("Skipping SQL data save for " + saveData + "; minigame is disabled");
            }
            // Item Bets (for non groups)
            if (minigame.getMpBets() != null) {
                if (minigame.getMpBets().hasBets()) {
                    if (!player.isInMinigame())
                        player.getPlayer().getInventory().addItem(minigame.getMpBets().claimBets());
                    else {
                        for (ItemStack i : minigame.getMpBets().claimBets()) {
                            player.addTempRewardItem(i);
                        }
                    }
                    minigame.setMpBets(null);
                }
            }
            PlayMGSound.playSound(player, MGSounds.getSound("win"));
        }
        if (!usedTimer) {
            gom.clearLosers();
            gom.clearWinners();
        }
        mgManager.clearClaimedScore(minigame);
        // Call Types End.
        mgManager.minigameType(minigame.getType()).endMinigame(winners, losers, minigame);
        minigame.getScoreboardData().reload();
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) StoredGameStats(au.com.mineauz.minigames.stats.StoredGameStats) DynamicMinigameStat(au.com.mineauz.minigames.stats.DynamicMinigameStat) ItemStack(org.bukkit.inventory.ItemStack) BigDecimal(java.math.BigDecimal)

Aggregations

MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)134 EventHandler (org.bukkit.event.EventHandler)46 Minigame (au.com.mineauz.minigames.minigame.Minigame)40 ArrayList (java.util.ArrayList)25 Team (au.com.mineauz.minigames.minigame.Team)24 OfflineMinigamePlayer (au.com.mineauz.minigames.objects.OfflineMinigamePlayer)15 Player (org.bukkit.entity.Player)15 Location (org.bukkit.Location)11 ItemStack (org.bukkit.inventory.ItemStack)8 MinigameTool (au.com.mineauz.minigames.tool.MinigameTool)7 Menu (au.com.mineauz.minigames.menu.Menu)5 TeamColor (au.com.mineauz.minigames.minigame.TeamColor)5 List (java.util.List)5 PotionEffect (org.bukkit.potion.PotionEffect)5 ResourcePack (au.com.mineauz.minigames.objects.ResourcePack)4 Material (org.bukkit.Material)4 Sign (org.bukkit.block.Sign)4 MenuItemCustom (au.com.mineauz.minigames.menu.MenuItemCustom)3 MenuItem (au.com.mineauz.minigames.menu.MenuItem)2 MenuItemBoolean (au.com.mineauz.minigames.menu.MenuItemBoolean)2