use of au.com.mineauz.minigames.minigame.Minigame 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.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 RegionEvents method playerMove.
@EventHandler(ignoreCancelled = true)
private void playerMove(PlayerMoveEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply == null)
return;
if (ply.isInMinigame()) {
Minigame mg = ply.getMinigame();
executeRegionChanges(mg, ply);
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class RegionEvents method playerQuit.
@EventHandler(ignoreCancelled = true)
private void playerQuit(QuitMinigameEvent event) {
MinigamePlayer ply = event.getMinigamePlayer();
if (ply == null)
return;
Minigame mg = ply.getMinigame();
for (Region r : RegionModule.getMinigameModule(mg).getRegions()) {
if (r.hasPlayer(ply))
r.removePlayer(ply);
}
for (Node node : RegionModule.getMinigameModule(event.getMinigame()).getNodes()) {
node.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
if (event.getMinigame().getPlayers().size() > 1) {
for (NodeExecutor exec : node.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
} else {
for (NodeExecutor exec : node.getExecutors()) exec.clearTriggers();
node.setEnabled(true);
}
}
for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
if (region.playerInRegion(ply))
region.execute(Triggers.getTrigger("GAME_QUIT"), event.getMinigamePlayer());
if (event.getMinigame().getPlayers().size() > 1) {
for (RegionExecutor exec : region.getExecutors()) exec.removeTrigger(event.getMinigamePlayer());
} else {
for (RegionExecutor exec : region.getExecutors()) {
exec.clearTriggers();
}
region.removeTickTask();
region.setEnabled(true);
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class RegionEvents method playerJoin.
@EventHandler(ignoreCancelled = true)
private void playerJoin(JoinMinigameEvent event) {
final MinigamePlayer ply = event.getMinigamePlayer();
if (ply == null)
return;
final Minigame mg = event.getMinigame();
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
executeRegionChanges(mg, ply);
for (Node node : RegionModule.getMinigameModule(mg).getNodes()) {
node.execute(Triggers.getTrigger("GAME_JOIN"), ply);
}
for (Region region : RegionModule.getMinigameModule(mg).getRegions()) {
if (region.hasPlayer(ply))
region.execute(Triggers.getTrigger("GAME_JOIN"), ply);
}
}
});
if (event.getMinigame().getPlayers().size() == 0) {
for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
for (RegionExecutor ex : region.getExecutors()) {
if (ex.getTrigger().getName().equalsIgnoreCase("TICK")) {
region.startTickTask();
break;
}
}
}
}
}
Aggregations