use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigamePlayerManager method teleportToStart.
public void teleportToStart(Minigame minigame) {
List<MinigamePlayer> findStart = new ArrayList<>();
for (MinigamePlayer ply : minigame.getPlayers()) {
if (ply.getStartPos() == null) {
findStart.add(ply);
}
}
if (findStart.size() != 0) {
getStartLocations(findStart, minigame);
}
for (MinigamePlayer ply : minigame.getPlayers()) {
ply.teleport(ply.getStartPos());
}
minigame.setPlayersAtStart(true);
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigamePlayerManager method partyMode.
public void partyMode(MinigamePlayer player, int amount, long delay) {
if (!onPartyMode())
return;
final int fcount = amount;
final MinigamePlayer fplayer = player;
final long fdelay = delay;
partyMode(fplayer);
if (amount == 1)
return;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
if (fplayer != null) {
partyMode(fplayer, fcount - 1, fdelay);
}
}, delay);
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigamePlayerManager method spectateMinigame.
public void spectateMinigame(MinigamePlayer player, Minigame minigame) {
SpectateMinigameEvent event = new SpectateMinigameEvent(player, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
boolean tpd;
if (minigame.getSpectatorLocation() != null)
tpd = player.teleport(minigame.getSpectatorLocation());
else {
player.sendMessage(MinigameUtils.getLang("minigame.error.noSpectatePos"), MinigameMessageType.ERROR);
return;
}
if (!tpd) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), MinigameMessageType.ERROR);
return;
}
player.storePlayerData();
player.setMinigame(minigame);
player.setGamemode(GameMode.ADVENTURE);
minigame.addSpectator(player);
if (minigame.canSpectateFly()) {
player.getPlayer().setAllowFlight(true);
}
for (MinigamePlayer pl : minigame.getPlayers()) {
pl.getPlayer().hidePlayer(plugin, player.getPlayer());
}
player.getPlayer().setScoreboard(minigame.getScoreboardManager());
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
player.sendInfoMessage(MinigameUtils.formStr("player.spectate.join.plyMsg", minigame.getName(true)) + "\n" + MinigameUtils.formStr("player.spectate.join.plyHelp", "\"/minigame quit\""));
mgManager.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.join.minigameMsg", player.getName(), minigame.getName(true)), null, player);
}
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigamePlayerManager method getStartLocations.
public void getStartLocations(List<MinigamePlayer> players, Minigame game) {
mgManager.sendMinigameMessage(game, MinigameUtils.getLang("minigame.startRandomized"), MinigameMessageType.INFO, (List<MinigamePlayer>) null);
Collections.shuffle(players);
int pos = 0;
Map<Team, Integer> tpos = new HashMap<>();
for (Team t : TeamsModule.getMinigameModule(game).getTeams()) {
tpos.put(t, 0);
}
if (game.isRandomizeStart()) {
if (game.isTeamGame()) {
MinigameUtils.debugMessage("Setting Starts for Team game");
TeamsModule mod = TeamsModule.getMinigameModule(game);
if (mod.hasTeamStartLocations()) {
for (Team team : mod.getTeams()) {
MinigameUtils.debugMessage("Team" + team.getDisplayName() + " is randomized");
Collections.shuffle(team.getStartLocations());
}
} else {
MinigameUtils.debugMessage("Team game using global starts randomized");
Collections.shuffle(game.getStartLocations());
}
} else {
MinigameUtils.debugMessage("Setting Starts for MP game randomized");
Collections.shuffle(game.getStartLocations());
}
} else {
if (game.isTeamGame()) {
MinigameUtils.debugMessage("Setting Starts for Team game");
} else {
MinigameUtils.debugMessage("MP game using global starts");
}
}
for (MinigamePlayer player : players) {
Location result = null;
if (!game.isTeamGame()) {
if (pos < game.getStartLocations().size()) {
player.setStartTime(Calendar.getInstance().getTimeInMillis());
result = game.getStartLocations().get(pos);
} else {
MinigameUtils.debugMessage("StartLocations filled - recycling from start");
if (!game.getStartLocations().isEmpty()) {
pos = 0;
result = game.getStartLocations().get(pos);
}
}
} else {
Team team = player.getTeam();
if (team != null) {
if (TeamsModule.getMinigameModule(game).hasTeamStartLocations()) {
if (tpos.get(team) >= team.getStartLocations().size()) {
MinigameUtils.debugMessage("Team Starts for " + team.getDisplayName() + " filled - recylcing from start");
tpos.put(team, 0);
}
result = team.getStartLocations().get(tpos.get(team));
tpos.put(team, tpos.get(team) + 1);
} else {
if (pos < game.getStartLocations().size()) {
result = game.getStartLocations().get(pos);
} else {
MinigameUtils.debugMessage("StartLocations filled - recycling from start");
pos = 0;
if (!game.getStartLocations().isEmpty()) {
result = game.getStartLocations().get(pos);
}
}
}
} else {
player.sendMessage(MinigameUtils.getLang("minigame.error.noTeam"), MinigameMessageType.ERROR);
}
}
if (result == null) {
player.sendMessage(MinigameUtils.getLang("minigame.error.incorrectStart"), MinigameMessageType.ERROR);
quitMinigame(player, false);
} else {
player.setStartPos(result);
player.setCheckpoint(result);
pos++;
}
}
}
use of au.com.mineauz.minigames.objects.MinigamePlayer in project Minigames by AddstarMC.
the class MinigamePlayerManager method joinMinigame.
public void joinMinigame(MinigamePlayer player, Minigame minigame, boolean isBetting, Double betAmount) {
MinigameType type = minigame.getType();
JoinMinigameEvent event = new JoinMinigameEvent(player, minigame);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
Minigames.log.info("Start Event was cancelled..: " + event.toString());
return;
}
if (!mgManager.minigameStartStateCheck(minigame, player))
return;
// Do betting stuff
if (isBetting)
handleBets(minigame, player, betAmount);
// Try teleport the player to their designated area.
ResourcePack pack = getResourcePack(minigame);
if (pack != null && pack.isValid()) {
if (player.applyResourcePack(pack))
player.sendInfoMessage(MinigameUtils.getLang("minigame.resourcepack.apply"));
}
// Check if Minigame is full
if (minigame.isGameFull()) {
player.sendMessage(MinigameUtils.getLang("minigame.full"), MinigameMessageType.ERROR);
return;
}
if (!mgManager.teleportPlayerOnJoin(minigame, player)) {
player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), MinigameMessageType.ERROR);
return;
}
// Give them the game type name
if (minigame.getGametypeName() == null)
player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getType().getName()), MinigameMessageType.WIN);
else
player.sendMessage(MinigameUtils.formStr("player.join.plyInfo", minigame.getGametypeName()), MinigameMessageType.WIN);
// Give them the objective
if (minigame.getObjective() != null) {
player.sendUnprefixedMessage(ChatColor.GREEN + "----------------------------------------------------");
player.sendInfoMessage(ChatColor.AQUA.toString() + ChatColor.BOLD + MinigameUtils.formStr("player.join.objective", ChatColor.RESET.toString() + ChatColor.WHITE + minigame.getObjective()));
player.sendUnprefixedMessage(ChatColor.GREEN + "----------------------------------------------------");
}
// Prepare regeneration region for rollback.
mgManager.addBlockRecorderData(minigame);
// Standardize player
player.storePlayerData();
player.setMinigame(minigame);
minigame.addPlayer(player);
WeatherTimeModule mod = WeatherTimeModule.getMinigameModule(minigame);
if (mod != null) {
mod.applyCustomTime(player);
mod.applyCustomWeather(player);
}
player.setCheckpoint(player.getPlayer().getLocation());
player.getPlayer().setFallDistance(0);
player.getPlayer().setWalkSpeed(0.2f);
player.setStartTime(Calendar.getInstance().getTimeInMillis());
player.setGamemode(minigame.getDefaultGamemode());
player.getPlayer().setAllowFlight(false);
for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
player.getPlayer().removePotionEffect(potion.getType());
}
// Hide Spectators
for (MinigamePlayer pl : minigame.getSpectators()) {
player.getPlayer().hidePlayer(plugin, pl.getPlayer());
}
if (minigame.getPlayers().size() == 1) {
// Register regen recorder events
if (minigame.getBlockRecorder().hasRegenArea())
Bukkit.getServer().getPluginManager().registerEvents(minigame.getBlockRecorder(), plugin);
if (mod != null)
mod.startTimeLoop();
}
// Call Type specific join
mgManager.minigameType(type).joinMinigame(player, minigame);
// Call Mechanic specific join
minigame.getMechanic().onJoinMinigame(minigame, player);
// Send other players the join message.
mgManager.sendMinigameMessage(minigame, MinigameUtils.formStr("player.join.plyMsg", player.getName(), minigame.getName(true)), null, player);
player.updateInventory();
if (minigame.canDisplayScoreboard()) {
player.getPlayer().setScoreboard(minigame.getScoreboardManager());
minigame.setScore(player, 1);
minigame.setScore(player, 0);
}
if (minigame.getState() == MinigameState.STARTING && minigame.canLateJoin()) {
player.sendInfoMessage(MinigameUtils.formStr("minigame.lateJoinWait", minigame.getMpTimer().getStartWaitTimeLeft()));
}
}
Aggregations