use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class MultiplayerType method timerExpire.
@EventHandler
public void timerExpire(TimerExpireEvent event) {
if (event.getMinigame().getType() == MinigameType.MULTIPLAYER && event.getMinigameState() == MinigameState.STARTED) {
if (event.getMinigame().isTeamGame()) {
Minigame mgm = event.getMinigame();
if (TeamsModule.getMinigameModule(mgm).getDefaultWinner() != null) {
TeamsModule tm = TeamsModule.getMinigameModule(mgm);
List<MinigamePlayer> w;
List<MinigamePlayer> l;
if (TeamsModule.getMinigameModule(mgm).hasTeam(TeamsModule.getMinigameModule(mgm).getDefaultWinner())) {
w = new ArrayList<MinigamePlayer>(tm.getTeam(tm.getDefaultWinner()).getPlayers().size());
l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - tm.getTeam(tm.getDefaultWinner()).getPlayers().size());
w.addAll(tm.getTeam(tm.getDefaultWinner()).getPlayers());
} else {
w = new ArrayList<MinigamePlayer>();
l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size());
}
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (t.getColor() != TeamsModule.getMinigameModule(mgm).getDefaultWinner())
l.addAll(t.getPlayers());
}
plugin.pdata.endMinigame(mgm, w, l);
} else {
List<Team> drawTeams = new ArrayList<Team>();
Team winner = null;
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (winner == null || (t.getScore() > winner.getScore() && (drawTeams.isEmpty() || t.getScore() > drawTeams.get(0).getScore()))) {
winner = t;
} else if (winner != null && t.getScore() == winner.getScore()) {
if (!drawTeams.isEmpty()) {
drawTeams.clear();
}
drawTeams.add(winner);
drawTeams.add(t);
winner = null;
} else if (!drawTeams.isEmpty() && drawTeams.get(0).getScore() == t.getScore()) {
drawTeams.add(t);
}
}
if (winner != null) {
List<MinigamePlayer> w = new ArrayList<MinigamePlayer>(winner.getPlayers());
List<MinigamePlayer> l = new ArrayList<MinigamePlayer>(mgm.getPlayers().size() - winner.getPlayers().size());
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (t != winner)
l.addAll(t.getPlayers());
}
pdata.endMinigame(mgm, w, l);
} else {
List<MinigamePlayer> players = new ArrayList<MinigamePlayer>(mgm.getPlayers());
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
t.resetScore();
}
if (mgm.getMinigameTimer() != null) {
mgm.getMinigameTimer().stopTimer();
mgm.setMinigameTimer(null);
}
if (mgm.getMpTimer() != null) {
mgm.getMpTimer().setStartWaitTime(0);
mgm.getMpTimer().pauseTimer();
mgm.getMpTimer().removeTimer();
mgm.setMpTimer(null);
}
if (mgm.getFloorDegenerator() != null && mgm.getPlayers().size() == 0) {
mgm.getFloorDegenerator().stopDegenerator();
}
if (mgm.getMpBets() != null && mgm.getPlayers().size() == 0) {
mgm.setMpBets(null);
}
for (MinigamePlayer ply : players) {
pdata.quitMinigame(ply, true);
if (!plugin.getConfig().getBoolean("multiplayer.broadcastwin")) {
if (drawTeams.size() == 2) {
ply.sendMessage(MinigameUtils.formStr("player.end.team.tie", drawTeams.get(0).getChatColor() + drawTeams.get(0).getDisplayName() + ChatColor.WHITE, drawTeams.get(1).getChatColor() + drawTeams.get(1).getDisplayName() + ChatColor.WHITE, event.getMinigame().getName(true)), "error");
} else {
ply.sendMessage(MinigameUtils.formStr("player.end.team.tieCount", drawTeams.size(), event.getMinigame().getName(true)), "error");
}
String scores = "";
int c = 1;
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
scores += t.getChatColor().toString() + t.getScore();
if (c != TeamsModule.getMinigameModule(mgm).getTeams().size())
scores += ChatColor.WHITE + " : ";
c++;
}
ply.sendMessage(MinigameUtils.getLang("minigame.info.score") + " " + scores);
}
}
if (plugin.getConfig().getBoolean("multiplayer.broadcastwin")) {
if (drawTeams.size() == 2) {
plugin.getServer().broadcastMessage(ChatColor.RED + "[Minigames] " + MinigameUtils.formStr("player.end.team.tie", drawTeams.get(0).getChatColor() + drawTeams.get(0).getDisplayName() + ChatColor.WHITE, drawTeams.get(1).getChatColor() + drawTeams.get(1).getDisplayName() + ChatColor.WHITE, event.getMinigame().getName(true)));
} else {
plugin.getServer().broadcastMessage(ChatColor.RED + "[Minigames] " + MinigameUtils.formStr("player.end.team.tieCount", drawTeams.size(), event.getMinigame().getName(true)));
}
String scores = "";
int c = 1;
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
scores += t.getChatColor().toString() + t.getScore();
if (c != TeamsModule.getMinigameModule(mgm).getTeams().size())
scores += ChatColor.WHITE + " : ";
c++;
}
plugin.getServer().broadcastMessage(MinigameUtils.getLang("minigame.info.score") + " " + scores);
}
}
}
} else {
MinigamePlayer player = null;
int score = 0;
for (MinigamePlayer ply : event.getMinigame().getPlayers()) {
if (ply.getScore() > 0) {
if (ply.getScore() > score) {
player = ply;
score = ply.getScore();
} else if (ply.getScore() == score) {
if (player != null && ply.getDeaths() < player.getDeaths()) {
player = ply;
} else if (player == null) {
player = ply;
}
}
}
}
List<MinigamePlayer> losers = new ArrayList<MinigamePlayer>();
losers.addAll(event.getMinigame().getPlayers());
List<MinigamePlayer> winners = new ArrayList<MinigamePlayer>();
if (player != null) {
losers.remove(player);
winners.add(player);
}
pdata.endMinigame(event.getMinigame(), winners, losers);
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class CTFMechanic method dropFlag.
@EventHandler
private void dropFlag(PlayerDeathEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getEntity());
if (ply == null)
return;
if (ply.isInMinigame()) {
Minigame mgm = ply.getMinigame();
if (mgm.isFlagCarrier(ply)) {
CTFFlag flag = mgm.getFlagCarrier(ply);
Location loc = flag.spawnFlag(ply.getPlayer().getLocation());
if (loc != null) {
DropFlagEvent ev = new DropFlagEvent(mgm, flag, ply);
Bukkit.getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
String id = MinigameUtils.createLocationID(loc);
Team team = mgm.getFlagCarrier(ply).getTeam();
mgm.addDroppedFlag(id, flag);
mgm.removeFlagCarrier(ply);
if (team != null)
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.dropped", ply.getName(), team.getChatColor() + team.getDisplayName() + ChatColor.WHITE), null, null);
else
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.droppedNeutral", ply.getName()), null, null);
flag.stopCarrierParticleEffect();
flag.startReturnTimer();
}
} else {
flag.respawnFlag();
mgm.removeFlagCarrier(ply);
flag.stopCarrierParticleEffect();
}
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class InfectionMechanic method playerDeath.
@EventHandler(ignoreCancelled = true)
private void playerDeath(PlayerDeathEvent event) {
MinigamePlayer player = pdata.getMinigamePlayer(event.getEntity());
if (player == null)
return;
if (player.isInMinigame()) {
Minigame mgm = player.getMinigame();
if (mgm.isTeamGame() && mgm.getMechanicName().equals("infection")) {
Team blue = TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.BLUE);
Team red = TeamsModule.getMinigameModule(mgm).getTeam(TeamColor.RED);
if (blue.getPlayers().contains(player)) {
if (!red.isFull()) {
MultiplayerType.switchTeam(mgm, player, red);
InfectionModule.getMinigameModule(mgm).addInfectedPlayer(player);
if (event.getEntity().getKiller() != null) {
MinigamePlayer killer = pdata.getMinigamePlayer(event.getEntity().getKiller());
killer.addScore();
mgm.setScore(killer, killer.getScore());
}
player.resetScore();
mgm.setScore(player, player.getScore());
if (mgm.getLives() != player.getDeaths()) {
mdata.sendMinigameMessage(mgm, String.format(red.getGameAssignMessage(), player.getName(), red.getChatColor() + red.getDisplayName()), "error", null);
}
if (blue.getPlayers().isEmpty()) {
List<MinigamePlayer> w;
List<MinigamePlayer> l;
w = new ArrayList<MinigamePlayer>(red.getPlayers());
l = new ArrayList<MinigamePlayer>();
pdata.endMinigame(mgm, w, l);
}
} else {
pdata.quitMinigame(player, false);
}
} else {
if (event.getEntity().getKiller() != null) {
MinigamePlayer killer = pdata.getMinigamePlayer(event.getEntity().getKiller());
killer.addScore();
mgm.setScore(killer, killer.getScore());
}
}
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class JoinSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
if (player.isInMinigame()) {
return false;
}
boolean invOk = true;
boolean fullInv;
if (plugin.getConfig().getBoolean("requireEmptyInventory")) {
fullInv = true;
for (ItemStack item : player.getPlayer().getInventory().getContents()) {
if (item != null) {
System.out.println("Found: " + item);
invOk = false;
break;
}
}
for (ItemStack item : player.getPlayer().getInventory().getArmorContents()) {
if (item != null && item.getType() != Material.AIR) {
System.out.println("Found armor: " + item);
invOk = false;
break;
}
}
} else {
fullInv = false;
invOk = player.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR;
}
if (invOk) {
Minigame mgm = plugin.mdata.getMinigame(sign.getLine(2));
if (mgm != null && (!mgm.getUsePermissions() || player.getPlayer().hasPermission("minigame.join." + mgm.getName(false).toLowerCase()))) {
if (mgm.isEnabled()) {
if (!sign.getLine(3).isEmpty() && Minigames.plugin.hasEconomy()) {
double amount = Double.parseDouble(sign.getLine(3).replace("$", ""));
if (Minigames.plugin.getEconomy().getBalance(player.getPlayer().getPlayer()) >= amount) {
Minigames.plugin.getEconomy().withdrawPlayer(player.getPlayer().getPlayer(), amount);
} else {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.join.notEnoughMoney"));
return false;
}
}
plugin.pdata.joinMinigame(player, mgm, false, 0.0);
return true;
} else if (!mgm.isEnabled()) {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.notEnabled"));
}
} else if (mgm == null) {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noMinigame"));
} else if (mgm.getUsePermissions()) {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.formStr("minigame.error.noPermission", "minigame.join." + mgm.getName(false).toLowerCase()));
}
} else if (!MinigameUtils.isMinigameTool(player.getPlayer().getInventory().getItemInMainHand())) {
if (fullInv) {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyInv"));
} else {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyHand"));
}
}
return false;
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class BetSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
Minigame mgm = plugin.mdata.getMinigame(sign.getLine(2));
if (mgm != null) {
boolean invOk = true;
boolean fullInv;
boolean moneyBet = sign.getLine(3).startsWith("$");
if (plugin.getConfig().getBoolean("requireEmptyInventory")) {
fullInv = true;
ItemStack[] contents = player.getPlayer().getInventory().getContents();
for (int i = 0; i < contents.length; ++i) {
// Non money bets can hold an item
if (!moneyBet && i == player.getPlayer().getInventory().getHeldItemSlot()) {
continue;
}
if (contents[i] != null) {
invOk = false;
break;
}
}
for (ItemStack item : player.getPlayer().getInventory().getArmorContents()) {
if (item != null && item.getType() != Material.AIR) {
invOk = false;
break;
}
}
} else {
fullInv = false;
invOk = (moneyBet ? player.getPlayer().getInventory().getItemInMainHand().getType() == Material.AIR : player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR);
}
if (invOk) {
if (mgm.isEnabled() && (!mgm.getUsePermissions() || player.getPlayer().hasPermission("minigame.join." + mgm.getName(false).toLowerCase()))) {
if (mgm.isSpectator(player)) {
return false;
}
if (!sign.getLine(3).startsWith("$")) {
plugin.pdata.joinMinigame(player, plugin.mdata.getMinigame(sign.getLine(2)), true, 0.0);
} else {
if (plugin.hasEconomy()) {
Double bet = Double.parseDouble(sign.getLine(3).replace("$", ""));
plugin.pdata.joinMinigame(player, plugin.mdata.getMinigame(sign.getLine(2)), true, bet);
return true;
} else {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noVault"));
}
}
} else if (!mgm.isEnabled()) {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.notEnabled"));
} else if (mgm.getUsePermissions()) {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.formStr("minigame.error.noPermission", "minigame.join." + mgm.getName(false).toLowerCase()));
}
} else if (!moneyBet) {
if (fullInv && player.getPlayer().getInventory().getItemInMainHand().getType() != Material.AIR) {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyInv"));
} else {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.bet.noBet"));
}
} else {
if (fullInv) {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyInv"));
} else {
player.sendMessage(ChatColor.AQUA + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("sign.emptyHand"));
}
}
} else {
player.sendMessage(ChatColor.RED + "[Minigames] " + ChatColor.WHITE + MinigameUtils.getLang("minigame.error.noMinigame"));
}
return false;
}
Aggregations