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 ScoreCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null && args.length >= 2) {
MinigamePlayer ply = null;
TeamColor color = TeamColor.matchColor(args[1]);
if (color == null) {
List<Player> plys = plugin.getServer().matchPlayer(args[1]);
if (!plys.isEmpty()) {
ply = plugin.pdata.getMinigamePlayer(plys.get(0));
} else {
sender.sendMessage(ChatColor.RED + "No player or team found by the name " + args[1]);
return true;
}
}
if (args[0].equalsIgnoreCase("get") && args.length >= 2) {
if (ply != null) {
if (ply.isInMinigame()) {
sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s Score: " + ChatColor.GREEN + ply.getScore());
} else {
sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
}
} else if (color != null) {
if (args.length >= 3) {
Minigame mg = null;
if (plugin.mdata.hasMinigame(args[2])) {
mg = plugin.mdata.getMinigame(args[2]);
} else {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]);
return true;
}
TeamsModule tmod = TeamsModule.getMinigameModule(mg);
if (mg.isTeamGame()) {
if (tmod.hasTeam(color)) {
Team t = tmod.getTeam(color);
sender.sendMessage(color.getColor() + t.getDisplayName() + ChatColor.GRAY + " score in " + mg.getName(false) + ": " + ChatColor.GREEN + t.getScore());
} else {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
}
} else {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!");
}
}
return true;
} else if (args[0].equalsIgnoreCase("set") && args.length >= 3) {
int score = 0;
if (args[2].matches("-?[0-9]+")) {
score = Integer.parseInt(args[2]);
} else {
sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number!");
return true;
}
if (ply != null) {
if (ply.isInMinigame()) {
ply.setScore(score);
ply.getMinigame().setScore(ply, ply.getScore());
sender.sendMessage(ChatColor.GRAY + ply.getName() + "'s score has been set to " + score);
if (ply.getMinigame().getMaxScore() != 0 && score >= ply.getMinigame().getMaxScorePerPlayer()) {
plugin.pdata.endMinigame(ply);
}
} else {
sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
}
} else if (color != null) {
if (args.length >= 4) {
Minigame mg = null;
if (plugin.mdata.hasMinigame(args[3])) {
mg = plugin.mdata.getMinigame(args[3]);
} else {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[2]);
return true;
}
TeamsModule tmod = TeamsModule.getMinigameModule(mg);
if (mg.isTeamGame() && mg.hasPlayers()) {
Team t = null;
if (tmod.hasTeam(color)) {
t = tmod.getTeam(color);
t.setScore(score);
sender.sendMessage(t.getChatColor() + t.getDisplayName() + ChatColor.GRAY + " score has been set to " + score);
} else {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
return true;
}
if (mg.getMaxScore() != 0 && score >= mg.getMaxScorePerPlayer()) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(t.getPlayers());
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mg.getPlayers().size() - t.getPlayers().size());
for (Team te : tmod.getTeams()) {
if (te != t) {
l.addAll(te.getPlayers());
}
}
plugin.pdata.endMinigame(mg, w, l);
}
} else if (!mg.hasPlayers()) {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!");
} else {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
}
} else {
sender.sendMessage(ChatColor.RED + "This command requires a Minigame name as the last argument!");
}
}
return true;
} else if (args[0].equalsIgnoreCase("add") && args.length >= 3) {
int score = 0;
if (args[2].matches("-?[0-9]+")) {
score = Integer.parseInt(args[2]);
} else {
score = 1;
}
if (ply != null) {
if (ply.isInMinigame()) {
ply.addScore(score);
ply.getMinigame().setScore(ply, ply.getScore());
sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + ply.getName() + "'s score, new score: " + ply.getScore());
if (ply.getMinigame().getMaxScore() != 0 && ply.getScore() >= ply.getMinigame().getMaxScorePerPlayer()) {
plugin.pdata.endMinigame(ply);
}
} else {
sender.sendMessage(ChatColor.RED + ply.getName() + " is not playing a Minigame!");
}
} else if (color != null) {
Minigame mg = null;
String mgName = null;
if (args.length == 4) {
mgName = args[3];
} else {
mgName = args[2];
}
if (plugin.mdata.hasMinigame(mgName)) {
mg = plugin.mdata.getMinigame(mgName);
} else {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + mgName);
return true;
}
TeamsModule tmod = TeamsModule.getMinigameModule(mg);
if (mg.isTeamGame() && mg.hasPlayers()) {
Team team = null;
if (tmod.hasTeam(color)) {
team = tmod.getTeam(color);
team.addScore(score);
sender.sendMessage(ChatColor.GRAY + "Added " + score + " to " + team.getChatColor() + team.getDisplayName() + ChatColor.GRAY + " score, new score: " + team.getScore());
} else {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " does not have a " + color.toString().toLowerCase() + " team.");
return true;
}
if (mg.getMaxScore() != 0 && team.getScore() >= mg.getMaxScorePerPlayer()) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(team.getPlayers());
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mg.getPlayers().size() - team.getPlayers().size());
for (Team te : tmod.getTeams()) {
if (te != team) {
l.addAll(te.getPlayers());
}
}
plugin.pdata.endMinigame(mg, w, l);
}
} else if (!mg.hasPlayers()) {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " has no players playing!");
} else {
sender.sendMessage(ChatColor.RED + mg.getName(false) + " is not a team Minigame!");
}
}
return true;
}
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class ScoreboardCommand method onCommand.
@Override
public boolean onCommand(final CommandSender sender, Minigame ignore, String label, String[] args) {
if (args == null || args.length < 3) {
return false;
}
// Decode arguments
final Minigame minigame = plugin.mdata.getMinigame(args[0]);
if (minigame == null) {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name " + args[0]);
return true;
}
final MinigameStat stat = MinigameStats.getStat(args[1]);
if (stat == null) {
sender.sendMessage(ChatColor.RED + "No statistic found by the name " + args[1]);
return true;
}
final StatSettings settings = minigame.getSettings(stat);
StatValueField field = null;
for (StatValueField f : settings.getFormat().getFields()) {
if (f.name().equalsIgnoreCase(args[2])) {
field = f;
break;
}
}
if (field == null) {
sender.sendMessage(ChatColor.RED + "No field found by the name " + args[2] + " for the statistic " + stat.getDisplayName());
return true;
}
// Prepare defaults for optionals
ScoreboardOrder order;
switch(field) {
case Last:
case Total:
case Max:
order = ScoreboardOrder.DESCENDING;
break;
case Min:
order = ScoreboardOrder.ASCENDING;
break;
default:
throw new AssertionError();
}
int start = 0;
int length = 8;
// Now the optionals
for (int i = 3; i < args.length - 1; i += 2) {
if (args[i].equalsIgnoreCase("-o")) {
// Order
if (args[i + 1].equalsIgnoreCase("asc") || args[i + 1].equalsIgnoreCase("ascending")) {
order = ScoreboardOrder.ASCENDING;
} else if (args[i + 1].equalsIgnoreCase("desc") || args[i + 1].equalsIgnoreCase("descending")) {
order = ScoreboardOrder.DESCENDING;
} else {
sender.sendMessage(ChatColor.RED + "Unknown order " + args[i + 1] + ". Expected asc, ascending, desc, or descending.");
return true;
}
} else if (args[i].equalsIgnoreCase("-l")) {
// Length
if (args[i + 1].matches("[1-9][0-9]*")) {
length = Integer.parseInt(args[i + 1]);
} else {
sender.sendMessage(ChatColor.RED + "Unknown length " + args[i + 1] + ". Expected positive non-zero number");
return true;
}
} else if (args[i].equalsIgnoreCase("-s")) {
// Start
if (args[i + 1].matches("[1-9][0-9]*")) {
start = Integer.parseInt(args[i + 1]) - 1;
} else {
sender.sendMessage(ChatColor.RED + "Unknown start " + args[i + 1] + ". Expected positive non-zero number");
return true;
}
} else {
sender.sendMessage(ChatColor.RED + "Unknown option " + args[i] + ". Expected -o, -l, or -s");
return true;
}
}
final ScoreboardOrder fOrder = order;
final StatValueField fField = field;
sender.sendMessage(ChatColor.GRAY + "Loading scoreboard...");
// Now load the values
ListenableFuture<List<StoredStat>> future = plugin.getBackend().loadStats(minigame, stat, field, order, start, length);
Futures.addCallback(future, new FutureCallback<List<StoredStat>>() {
@Override
public void onSuccess(List<StoredStat> result) {
sender.sendMessage(ChatColor.GREEN + minigame.getName(true) + " Scoreboard: " + settings.getDisplayName() + " - " + fField.getTitle() + " " + fOrder.toString().toLowerCase());
for (StoredStat playerStat : result) {
sender.sendMessage(ChatColor.AQUA + playerStat.getPlayerDisplayName() + ": " + ChatColor.WHITE + stat.displayValue(playerStat.getValue(), settings));
}
}
@Override
public void onFailure(Throwable t) {
sender.sendMessage(ChatColor.RED + "An internal error occured while loading the statistics");
t.printStackTrace();
}
});
return true;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class ScoreboardCommand method onTabComplete.
@Override
public List<String> onTabComplete(CommandSender sender, Minigame ignore, String alias, String[] args) {
if (args.length == 1) {
// Minigame
List<String> mgs = new ArrayList<String>(plugin.mdata.getAllMinigames().keySet());
return MinigameUtils.tabCompleteMatch(mgs, args[0]);
} else if (args.length == 2) {
// Stat
return MinigameUtils.tabCompleteMatch(Lists.newArrayList(MinigameStats.getAllStats().keySet()), args[1]);
} else if (args.length == 3) {
// Field
MinigameStat stat = MinigameStats.getStat(args[1]);
if (stat == null) {
return null;
}
final Minigame minigame = plugin.mdata.getMinigame(args[0]);
StatFormat format;
if (minigame == null) {
format = stat.getFormat();
} else {
StatSettings settings = minigame.getSettings(stat);
format = settings.getFormat();
}
String toMatch = args[2].toLowerCase();
List<String> matches = Lists.newArrayList();
for (StatValueField field : format.getFields()) {
if (field.name().toLowerCase().startsWith(toMatch)) {
matches.add(field.name());
}
}
return matches;
} else if (args.length > 3) {
if (args.length % 2 == 0) {
// Option
return MinigameUtils.tabCompleteMatch(Arrays.asList("-o", "-l", "-s"), args[args.length - 1]);
} else {
// Option Parameter
String previous = args[args.length - 2].toLowerCase();
String toMatch = args[args.length - 1].toLowerCase();
if (previous.equals("-o")) {
// Order
return MinigameUtils.tabCompleteMatch(Arrays.asList("asc", "ascending", "desc", "descending"), toMatch);
}
// The others cannot be tab completed
}
}
return null;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class SpectateCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Minigame minigame, String label, String[] args) {
if (args != null) {
if (plugin.mdata.hasMinigame(args[0])) {
MinigamePlayer ply = plugin.pdata.getMinigamePlayer((Player) sender);
Minigame mgm = plugin.mdata.getMinigame(args[0]);
plugin.pdata.spectateMinigame(ply, mgm);
} else {
sender.sendMessage(ChatColor.RED + "No Minigame found by the name: " + args[0]);
}
return true;
}
return false;
}
Aggregations