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<>(tm.getTeam(tm.getDefaultWinner()).getPlayers().size());
l = new ArrayList<>(mgm.getPlayers().size() - tm.getTeam(tm.getDefaultWinner()).getPlayers().size());
w.addAll(tm.getTeam(tm.getDefaultWinner()).getPlayers());
} else {
w = new ArrayList<>();
l = new ArrayList<>(mgm.getPlayers().size());
}
for (Team t : TeamsModule.getMinigameModule(mgm).getTeams()) {
if (t.getColor() != TeamsModule.getMinigameModule(mgm).getDefaultWinner())
l.addAll(t.getPlayers());
}
plugin.getPlayerManager().endMinigame(mgm, w, l);
} else {
List<Team> drawTeams = new ArrayList<>();
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<>(winner.getPlayers());
List<MinigamePlayer> l = new ArrayList<>(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<>(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)), MinigameMessageType.ERROR);
} else {
ply.sendMessage(MinigameUtils.formStr("player.end.team.tieCount", drawTeams.size(), event.getMinigame().getName(true)), MinigameMessageType.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.sendInfoMessage(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<>(event.getMinigame().getPlayers());
List<MinigamePlayer> winners = new ArrayList<>();
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 PlaceHolderManager method onPlaceholderRequest.
@Override
public String onPlaceholderRequest(Player player, String identifier) {
if (player == null) {
return "";
}
if (!identifiers.containsKey(identifier)) {
return null;
}
Set<String> games = plugin.getMinigameManager().getAllMinigames().keySet();
if (identifier.contains("_")) {
String[] parts = identifier.split("_");
String gameName = parts[0];
if (games.contains(gameName)) {
Minigame minigame = plugin.getMinigameManager().getMinigame(gameName);
try {
switch(parts[1]) {
case "enabled":
return Boolean.toString(minigame.isEnabled());
case "maxPlayers":
return Integer.toString(minigame.getMaxPlayers());
case "currentPlayers":
return Integer.toString(minigame.getPlayers().size());
case "type":
return minigame.getType().getName();
case "mechanic":
return minigame.getMechanicName();
case "state":
return minigame.getState().name();
case "objective":
return minigame.getObjective();
case "gameType":
return minigame.getGametypeName();
case "timeLeft":
return Integer.toString(minigame.getMinigameTimer().getTimeLeft());
case "name":
return minigame.getName(true);
default:
for (ModulePlaceHolderProvider provider : providers) {
if (provider.hasPlaceHolder(parts[1])) {
return provider.onPlaceHolderRequest(player, gameName, parts[1]);
}
}
return null;
}
} catch (Exception e) {
plugin.getLogger().warning("Error processing PAPI:" + identifier);
plugin.getLogger().warning(e.getMessage());
if (plugin.isDebugging()) {
e.printStackTrace();
}
return null;
}
} else {
// this means the first part is not a gameName ?? what else could it be
return null;
}
} else {
switch(identifier) {
case "gameCount":
return Integer.toString(plugin.getMinigameManager().getAllMinigames().size());
case "enabledGameCount":
return Long.toString(plugin.getMinigameManager().getAllMinigames().values().stream().filter(Minigame::isEnabled).count());
case "totalPlaying":
return Long.toString(plugin.getPlayerManager().getAllMinigamePlayers().stream().filter(MinigamePlayer::isInMinigame).count());
default:
return null;
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class BasicRecorder method vehicleDestroy.
@EventHandler(ignoreCancelled = true)
private void vehicleDestroy(VehicleDestroyEvent event) {
if (event.getAttacker() != null) {
if (event.getAttacker() instanceof Player) {
Player ply = (Player) event.getAttacker();
Minigame mg = pdata.getMinigamePlayer(ply).getMinigame();
if (pdata.getMinigamePlayer(ply).isInMinigame()) {
if (!mg.getBlockRecorder().hasEntity(event.getVehicle())) {
mg.getBlockRecorder().addEntity(event.getVehicle(), pdata.getMinigamePlayer(ply), false);
}
}
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class BasicRecorder method blockBreak.
@EventHandler(priority = EventPriority.HIGH)
private void blockBreak(BlockBreakEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply == null)
return;
if (ply.isInMinigame()) {
if (!ply.getMinigame().hasStarted() || ply.isLatejoining()) {
event.setCancelled(true);
return;
}
Minigame mgm = ply.getMinigame();
RecorderData d = mgm.getBlockRecorder();
if (((d.getWhitelistMode() && d.getWBBlocks().contains(event.getBlock().getType())) || (!d.getWhitelistMode() && !d.getWBBlocks().contains(event.getBlock().getType()))) && mgm.canBlockBreak()) {
if (event.getBlock().getState() instanceof Sign) {
Sign sign = (Sign) event.getBlock().getState();
if (sign.getLine(0).equalsIgnoreCase(ChatColor.DARK_BLUE + "[Minigame]")) {
event.setCancelled(true);
} else {
d.addBlock(event.getBlock(), ply);
if (!mgm.canBlocksdrop()) {
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
}
} else {
Location above = event.getBlock().getLocation().clone();
above.setY(above.getY() + 1);
d.addBlock(event.getBlock(), ply);
if (!mgm.canBlocksdrop()) {
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
}
} else {
event.setCancelled(true);
}
}
}
use of au.com.mineauz.minigames.minigame.Minigame in project Minigames by AddstarMC.
the class BasicRecorder method igniteblock.
@EventHandler(ignoreCancelled = true)
public void igniteblock(BlockIgniteEvent event) {
MinigamePlayer ply = null;
if (event.getPlayer() != null)
ply = pdata.getMinigamePlayer(event.getPlayer());
if (ply == null)
return;
if (ply.isInMinigame() && (event.getCause() == IgniteCause.FIREBALL || event.getCause() == IgniteCause.FLINT_AND_STEEL)) {
Minigame mgm = ply.getMinigame();
RecorderData d = mgm.getBlockRecorder();
if (((d.getWhitelistMode() && d.getWBBlocks().contains(Material.FIRE)) || (!d.getWhitelistMode() && !d.getWBBlocks().contains(Material.FIRE))) && mgm.canBlockPlace()) {
d.addBlock(event.getBlock(), pdata.getMinigamePlayer(event.getPlayer()));
} else {
event.setCancelled(true);
}
}
}
Aggregations