use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class PlayerData method quitMinigame.
public void quitMinigame(MinigamePlayer player, boolean forced) {
Minigame minigame = player.getMinigame();
boolean isWinner = false;
if (GameOverModule.getMinigameModule(minigame).getWinners().contains(player))
isWinner = true;
QuitMinigameEvent event = new QuitMinigameEvent(player, minigame, forced, isWinner);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (!minigame.isSpectator(player)) {
if (player.getEndTime() == 0)
player.setEndTime(System.currentTimeMillis());
if (isWinner)
GameOverModule.getMinigameModule(minigame).getWinners().remove(player);
else
GameOverModule.getMinigameModule(minigame).getLosers().remove(player);
if (!isWinner) {
if (!minigame.canSaveCheckpoint() && minigame.isEnabled()) {
StoredGameStats saveData = new StoredGameStats(minigame, player);
saveData.addStat(MinigameStats.Attempts, 1);
for (DynamicMinigameStat stat : MinigameStats.getDynamicStats()) {
if (stat.doesApply(minigame, player, false)) {
saveData.addStat(stat, stat.getValue(minigame, player, false));
}
}
saveData.applySettings(minigame.getStatSettings(saveData));
plugin.queueStatSave(saveData, false);
}
}
//Call Types quit.
mdata.minigameType(minigame.getType()).quitMinigame(player, minigame, forced);
//Call Mechanic quit.
minigame.getMechanic().quitMinigame(minigame, player, forced);
//Prepare player for quit
if (player.getPlayer().getVehicle() != null) {
Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
vehicle.eject();
}
player.getPlayer().closeInventory();
if (player.getLoadout() != null) {
player.getLoadout().removeLoadout(player);
}
player.removeMinigame();
minigame.removePlayer(player);
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
player.getPlayer().setFallDistance(0);
player.getPlayer().setNoDamageTicks(60);
final MinigamePlayer fplayer = player;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
fplayer.getPlayer().setFireTicks(0);
}
});
player.resetAllStats();
if (!player.isDead()) {
player.restorePlayerData();
if (!isWinner)
player.teleport(minigame.getQuitPosition());
else
player.teleport(minigame.getEndPosition());
} else {
if (!isWinner)
player.setQuitPos(minigame.getQuitPosition());
else
player.setQuitPos(minigame.getEndPosition());
player.setRequiredQuit(true);
}
//Reward Player
if (isWinner) {
player.claimTempRewardItems();
}
player.claimRewards();
//Reset Minigame
if (minigame.getPlayers().size() == 0) {
if (minigame.getMinigameTimer() != null) {
minigame.getMinigameTimer().stopTimer();
minigame.setMinigameTimer(null);
}
if (minigame.getFloorDegenerator() != null) {
minigame.getFloorDegenerator().stopDegenerator();
}
minigame.setState(MinigameState.IDLE);
if (minigame.getBlockRecorder().hasData()) {
minigame.getBlockRecorder().restoreBlocks();
minigame.getBlockRecorder().restoreEntities();
minigame.getBlockRecorder().setCreatedRegenBlocks(false);
}
if (minigame.getMpTimer() != null) {
minigame.getMpTimer().pauseTimer();
minigame.getMpTimer().removeTimer();
minigame.setMpTimer(null);
}
if (minigame.getMpBets() != null) {
minigame.setMpBets(null);
}
mdata.clearClaimedScore(minigame);
WeatherTimeModule.getMinigameModule(minigame).stopTimeLoop();
GameOverModule.getMinigameModule(minigame).stopEndGameTimer();
for (Team team : TeamsModule.getMinigameModule(minigame).getTeams()) {
team.setScore(0);
}
}
minigame.getScoreboardManager().resetScores(player.getName());
for (MinigamePlayer pl : minigame.getSpectators()) {
player.getPlayer().showPlayer(pl.getPlayer());
}
if (minigame.getPlayers().size() == 0 && !minigame.isRegenerating()) {
HandlerList.unregisterAll(minigame.getBlockRecorder());
}
//Send out messages
if (!forced) {
mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.quit.plyMsg", player.getName(), minigame.getName(true)), "error", player);
}
plugin.getLogger().info(player.getName() + " quit " + minigame);
player.updateInventory();
} else {
if (player.getPlayer().getVehicle() != null) {
Vehicle vehicle = (Vehicle) player.getPlayer().getVehicle();
vehicle.eject();
}
player.getPlayer().setFallDistance(0);
player.getPlayer().setNoDamageTicks(60);
final Player fplayer = player.getPlayer();
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
fplayer.setFireTicks(0);
}
});
player.getPlayer().closeInventory();
if (!player.isDead()) {
player.restorePlayerData();
}
player.teleport(minigame.getQuitPosition());
player.removeMinigame();
minigame.removeSpectator(player);
for (MinigamePlayer pl : minigame.getPlayers()) {
pl.getPlayer().showPlayer(player.getPlayer());
}
player.sendMessage(MinigameUtils.formStr("player.spectate.quit.plyMsg", minigame.getName(true)), "error");
mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.quit.minigameMsg", player.getName(), minigame.getName(true)), "error", player);
}
if (player.getPlayer().getGameMode() != GameMode.CREATIVE)
player.setCanFly(false);
if (!forced) {
minigame.getScoreboardData().reload();
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class MultiplayerType method joinMinigame.
@Override
public boolean joinMinigame(MinigamePlayer player, Minigame mgm) {
if (!LobbySettingsModule.getMinigameModule(mgm).canInteractPlayerWait())
player.setCanInteract(false);
if (!LobbySettingsModule.getMinigameModule(mgm).canMovePlayerWait())
player.setFrozen(true);
if (!mgm.isWaitingForPlayers() && !mgm.hasStarted()) {
if (mgm.getMpTimer() == null && mgm.getPlayers().size() == mgm.getMinPlayers()) {
mgm.setMpTimer(new MultiplayerTimer(mgm));
mgm.getMpTimer().startTimer();
if (mgm.getPlayers().size() == mgm.getMaxPlayers()) {
mgm.getMpTimer().setPlayerWaitTime(0);
mdata.sendMinigameMessage(mgm, MinigameUtils.getLang("minigame.skipWaitTime"), "info", null);
}
} else if (mgm.getMpTimer() != null && mgm.getPlayers().size() == mgm.getMaxPlayers()) {
mgm.getMpTimer().setPlayerWaitTime(0);
mdata.sendMinigameMessage(mgm, MinigameUtils.getLang("minigame.skipWaitTime"), "info", null);
} else if (mgm.getMpTimer() == null) {
int neededPlayers = mgm.getMinPlayers() - mgm.getPlayers().size();
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("minigame.waitingForPlayers", neededPlayers), null, null);
}
} else if (mgm.hasStarted()) {
player.setLatejoining(true);
//TODO: Late join delay variable
player.sendMessage(MinigameUtils.formStr("minigame.lateJoin", 5));
final MinigamePlayer fply = player;
final Minigame fmgm = mgm;
if (mgm.isTeamGame()) {
Team smTeam = null;
for (Team team : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (smTeam == null || team.getPlayers().size() < smTeam.getPlayers().size()) {
smTeam = team;
}
}
smTeam.addPlayer(player);
player.sendMessage(String.format(smTeam.getAssignMessage(), smTeam.getChatColor() + smTeam.getDisplayName()), null);
final Team fteam = smTeam;
player.setLateJoinTimer(Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (fply.isInMinigame()) {
List<Location> locs = new ArrayList<Location>();
if (TeamsModule.getMinigameModule(fmgm).hasTeamStartLocations()) {
locs.addAll(fteam.getStartLocations());
} else {
locs.addAll(fmgm.getStartLocations());
}
Collections.shuffle(locs);
fply.teleport(locs.get(0));
fply.getLoadout().equiptLoadout(fply);
fply.setLatejoining(false);
fply.setFrozen(false);
fply.setCanInteract(true);
fply.setLateJoinTimer(-1);
}
}
}, //TODO: Latejoin variable
5 * 20));
} else {
player.setLateJoinTimer(Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (fply.isInMinigame()) {
List<Location> locs = new ArrayList<Location>(fmgm.getStartLocations());
Collections.shuffle(locs);
fply.teleport(locs.get(0));
fply.getLoadout().equiptLoadout(fply);
fply.setLatejoining(false);
fply.setFrozen(false);
fply.setCanInteract(true);
fply.setLateJoinTimer(-1);
}
}
}, //TODO: Latejoin variable
5 * 20));
}
player.getPlayer().setScoreboard(mgm.getScoreboardManager());
mgm.setScore(player, 1);
mgm.setScore(player, 0);
}
return true;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Minigames method hookPlaceHolderApi.
private void hookPlaceHolderApi() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
hasPAPI = true;
log.info("--------------------");
log.info("Hooking PlaceHolder API");
placeHolderManager = new PlaceHolderManager(this);
placeHolderManager.register();
log.info("Adding Placeholders for " + getMinigameManager().getAllMinigames().size() + " games");
for (Map.Entry<String, Minigame> game : getMinigameManager().getAllMinigames().entrySet()) {
log.fine("Adding Placeholders for " + game.getKey());
placeHolderManager.addGameIdentifiers(game.getValue());
}
log.info("PlaceHolders: " + placeHolderManager.getRegisteredPlaceHolders().toString());
log.info("--------------------");
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Minigames method onDisable.
public void onDisable() {
if (getPlugin() == null) {
log().info("Minigames is disabled");
return;
}
final PluginDescriptionFile desc = this.getDescription();
for (final Player p : this.getServer().getOnlinePlayers()) {
if (this.playerManager.getMinigamePlayer(p).isInMinigame()) {
this.playerManager.quitMinigame(this.playerManager.getMinigamePlayer(p), true);
}
}
for (final Minigame minigame : this.minigameManager.getAllMinigames().values()) {
if (minigame.getType() == MinigameType.GLOBAL && "treasure_hunt".equals(minigame.getMechanicName()) && minigame.isEnabled()) {
if (minigame.getMinigameTimer() != null) {
minigame.getMinigameTimer().stopTimer();
}
TreasureHuntMechanic.removeTreasure(minigame);
}
}
for (final Minigame mg : this.minigameManager.getAllMinigames().values()) {
mg.saveMinigame();
}
this.backend.shutdown();
this.playerManager.saveDeniedCommands();
final MinigameSave globalLoadouts = new MinigameSave("globalLoadouts");
if (this.minigameManager.hasLoadouts()) {
for (final String loadout : this.minigameManager.getLoadouts()) {
for (final Integer slot : this.minigameManager.getLoadout(loadout).getItems()) {
globalLoadouts.getConfig().set(loadout + '.' + slot, this.minigameManager.getLoadout(loadout).getItem(slot));
}
if (!this.minigameManager.getLoadout(loadout).getAllPotionEffects().isEmpty()) {
for (final PotionEffect eff : this.minigameManager.getLoadout(loadout).getAllPotionEffects()) {
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".amp", eff.getAmplifier());
globalLoadouts.getConfig().set(loadout + ".potions." + eff.getType().getName() + ".dur", eff.getDuration());
}
} else {
globalLoadouts.getConfig().set(loadout + ".potions", null);
}
if (this.minigameManager.getLoadout(loadout).getUsePermissions()) {
globalLoadouts.getConfig().set(loadout + ".usepermissions", true);
} else {
globalLoadouts.getConfig().set(loadout + ".usepermissions", null);
}
}
} else {
globalLoadouts.getConfig().set("globalloadouts", null);
}
globalLoadouts.saveConfig();
this.minigameManager.saveRewardSigns();
resourceManager.saveResources();
log().info(desc.getName() + " successfully disabled.");
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class Events method itemPickup.
@EventHandler(ignoreCancelled = true)
public void itemPickup(EntityPickupItemEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
MinigamePlayer ply = pdata.getMinigamePlayer(player);
if (ply.isInMinigame()) {
Minigame mgm = ply.getMinigame();
if (!mgm.hasItemPickup() || mgm.isSpectator(ply)) {
event.setCancelled(true);
}
}
}
}
Aggregations