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);
}
}
}
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);
}
}
}
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);
}
}
}
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());
}
}
}
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();
}
}
Aggregations