use of au.com.mineauz.minigames.MultiplayerTimer in project Minigames by AddstarMC.
the class StartCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
Minigame mgm = plugin.mdata.getMinigame(args[0]);
if (mgm != null) {
if (!mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
MinigamePlayer caller = null;
if (sender instanceof Player)
caller = plugin.pdata.getMinigamePlayer((Player) sender);
plugin.mdata.startGlobalMinigame(mgm, caller);
} else if (mgm.getType() != MinigameType.GLOBAL && mgm.getType() != MinigameType.SINGLEPLAYER && mgm.hasPlayers()) {
if (mgm.getMpTimer() == null || mgm.getMpTimer().getPlayerWaitTimeLeft() != 0) {
if (mgm.getMpTimer() == null) {
mgm.setMpTimer(new MultiplayerTimer(mgm));
}
mgm.getMpTimer().setPlayerWaitTime(0);
mgm.getMpTimer().startTimer();
} else
sender.sendMessage(ChatColor.RED + mgm.getName(false) + " has already started.");
} else if (mgm.isEnabled() && mgm.getType() == MinigameType.GLOBAL) {
sender.sendMessage(ChatColor.RED + mgm.getName(false) + " is already running!");
}
} else {
sender.sendMessage(ChatColor.RED + "No Global or Multiplayer Minigame found by the name " + args[0]);
}
return true;
}
return false;
}
use of au.com.mineauz.minigames.MultiplayerTimer 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;
}
Aggregations