From 0a994a78e9c60f7982683e1118cd112b881b6811 Mon Sep 17 00:00:00 2001 From: BuildTools <18whitechristop@gmail.com> Date: Fri, 16 Jun 2017 20:35:49 -0700 Subject: [PATCH] add coinflip command, add mvp to config, prevent maps with too few player slots from being polled --- .../commons/bukkit/commands/MiscCommands.java | 17 +++ .../i18n/templates/pgm/PGMMessages.properties | 1 + PGM/src/main/java/tc/oc/pgm/Config.java | 6 + .../java/tc/oc/pgm/commands/PollCommands.java | 4 + .../oc/pgm/highlights/HighlightListener.java | 118 +++++++++--------- .../java/tc/oc/pgm/tokens/TokenListener.java | 50 ++++---- PGM/src/main/resources/config.yml | 3 + 7 files changed, 117 insertions(+), 82 deletions(-) diff --git a/Commons/bukkit/src/main/java/tc/oc/commons/bukkit/commands/MiscCommands.java b/Commons/bukkit/src/main/java/tc/oc/commons/bukkit/commands/MiscCommands.java index 2b1bf9e..45f8e2f 100644 --- a/Commons/bukkit/src/main/java/tc/oc/commons/bukkit/commands/MiscCommands.java +++ b/Commons/bukkit/src/main/java/tc/oc/commons/bukkit/commands/MiscCommands.java @@ -6,6 +6,7 @@ import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissionsException; import net.md_5.bungee.api.ChatColor; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -37,6 +38,22 @@ public class MiscCommands implements Commands { this.identityProvider = identityProvider; } + @Command( + aliases = { "coinflip" }, + desc = "Flip a Coin", + flags = "b", + min = 0, + max = 0 + ) + @CommandPermissions("coinflip") + public void coinFlip(final CommandContext args, final CommandSender sender) throws CommandException { + if (args.hasFlag('b')) { + Bukkit.broadcastMessage(ChatColor.AQUA + (Math.random() < 0.5 ? "Heads" : "Tails")); + } else { + sender.sendMessage(ChatColor.AQUA + (Math.random() < 0.5 ? "Heads" : "Tails")); + } + } + @Command( aliases = { "sudo" }, usage = " [command... (rand|mode|near|color|*)=value]", diff --git a/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties b/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties index 972c3a7..9d95b81 100644 --- a/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties +++ b/Commons/core/src/main/i18n/templates/pgm/PGMMessages.properties @@ -263,6 +263,7 @@ poll.disabled = Polls are disabled on this server! poll.map.alreadyset = A map has already been set! poll.map.restarting = You cannot set a map because a restart is queued! poll.map.notallowed = You are not allowed to set that map! +poll.map.toomanyplayers = There are too many players online to set that map! poll.tutorialmessage = Use {0}/vote [yes|no] {1}to vote announce.online = Announced server as online diff --git a/PGM/src/main/java/tc/oc/pgm/Config.java b/PGM/src/main/java/tc/oc/pgm/Config.java index 4085588..98bf46e 100644 --- a/PGM/src/main/java/tc/oc/pgm/Config.java +++ b/PGM/src/main/java/tc/oc/pgm/Config.java @@ -30,6 +30,12 @@ public class Config { return getConfiguration().getInt("minimum-players", 1); } + public static class MVP { + public static boolean enabled() { + return getConfiguration().getBoolean("mvp.enabled", true); + } + } + public static class Token { public static boolean enabled() { return getConfiguration().getBoolean("tokens.enabled", true); diff --git a/PGM/src/main/java/tc/oc/pgm/commands/PollCommands.java b/PGM/src/main/java/tc/oc/pgm/commands/PollCommands.java index cd3a9ce..b1c17b1 100644 --- a/PGM/src/main/java/tc/oc/pgm/commands/PollCommands.java +++ b/PGM/src/main/java/tc/oc/pgm/commands/PollCommands.java @@ -160,6 +160,10 @@ public class PollCommands implements Commands { throw newCommandException(sender, new TranslatableComponent("poll.map.notallowed")); } + if (PGM.get().getServer().getOnlinePlayers().size() * 4 / 5 > nextMap.getDocument().max_players()) { + throw newCommandException(sender, new TranslatableComponent("poll.map.toomanyplayers")); + } + startPoll(new PollNextMap(PGM.getPollManager(), Bukkit.getServer(), sender, initiator.getName(), PGM.getMatchManager(), nextMap)); return null; } diff --git a/PGM/src/main/java/tc/oc/pgm/highlights/HighlightListener.java b/PGM/src/main/java/tc/oc/pgm/highlights/HighlightListener.java index 3f1c669..26ce0e6 100644 --- a/PGM/src/main/java/tc/oc/pgm/highlights/HighlightListener.java +++ b/PGM/src/main/java/tc/oc/pgm/highlights/HighlightListener.java @@ -27,76 +27,78 @@ public class HighlightListener implements Listener { @EventHandler public void matchEnd(MatchEndEvent event) { - StatsUserFacet bestPlayerStats = null; - MatchPlayer bestPlayer = null; - double bestPlayerPoints = 0; + if (Config.MVP.enabled()) { + StatsUserFacet bestPlayerStats = null; + MatchPlayer bestPlayer = null; + double bestPlayerPoints = 0; - if (event.getMatch().getParticipatingPlayers().size() < 10) { - return; - } - - for (MatchPlayer player : event.getMatch().getParticipatingPlayers()) { - StatsUserFacet facet = player.getUserContext().facet(StatsUserFacet.class); - - double points = 0; - points += facet.matchKills(); - points -= facet.deaths(); - points -= facet.teammatesKilled(); - for (long wool : facet.getWoolCaptureTimes()) { - int woolPoints = (int)((wool * 2.25) - 2); - points += Math.min(Math.max(woolPoints, 0), 120); + if (event.getMatch().getParticipatingPlayers().size() < 10) { + return; } - for (long core : facet.getCoreLeakTimes()) { - int corePoints = (int)((core * 2.25) - 2); - points += Math.min(Math.max(corePoints, 0), 120); + for (MatchPlayer player : event.getMatch().getParticipatingPlayers()) { + StatsUserFacet facet = player.getUserContext().facet(StatsUserFacet.class); + + double points = 0; + points += facet.matchKills(); + points -= facet.deaths(); + points -= facet.teammatesKilled(); + for (long wool : facet.getWoolCaptureTimes()) { + int woolPoints = (int) ((wool * 2.25) - 2); + points += Math.min(Math.max(woolPoints, 0), 120); + } + + for (long core : facet.getCoreLeakTimes()) { + int corePoints = (int) ((core * 2.25) - 2); + points += Math.min(Math.max(corePoints, 0), 120); + } + + for (DestroyableContribution destroyable : facet.getDestroyableDestroyTimes().keySet()) { + int destroyablePoints = (int) ((facet.getDestroyableDestroyTimes().get(destroyable) * 2.25 * destroyable.getPercentage()) - 2); + points += Math.min(Math.max(destroyablePoints, 0), 120); + } + + for (long flag : facet.getFlagCaptureTimes()) { + int flagPoints = (int) (flag / 1.75); + points += Math.min(Math.max(flagPoints, 0), 120); + } + + points += (facet.getBlocksBroken() / 30); + + if (bestPlayerStats == null || points > bestPlayerPoints) { + bestPlayerStats = facet; + bestPlayer = player; + bestPlayerPoints = points; + } } - for (DestroyableContribution destroyable : facet.getDestroyableDestroyTimes().keySet()) { - int destroyablePoints = (int)((facet.getDestroyableDestroyTimes().get(destroyable) * 2.25 * destroyable.getPercentage()) - 2); - points += Math.min(Math.max(destroyablePoints, 0), 120); - } + if (bestPlayer != null) { + final BaseComponent title = new Component(new TranslatableComponent("broadcast.gameOver.mvp"), ChatColor.AQUA, ChatColor.BOLD); + Component subtitle; - for (long flag : facet.getFlagCaptureTimes()) { - int flagPoints = (int)(flag / 1.75); - points += Math.min(Math.max(flagPoints, 0), 120); - } - - points += (facet.getBlocksBroken() / 30); - - if (bestPlayerStats == null || points > bestPlayerPoints) { - bestPlayerStats = facet; - bestPlayer = player; - bestPlayerPoints = points; - } - } - - if (bestPlayer != null) { - final BaseComponent title = new Component(new TranslatableComponent("broadcast.gameOver.mvp"), ChatColor.AQUA, ChatColor.BOLD); - Component subtitle; - - if (Config.Token.enabled()) { - if (Math.random() < Config.Token.mvpChance()) { - String appendMe; - if (Math.random() > 0.25) { - TokenUtil.giveMutationTokens(TokenUtil.getUser(bestPlayer.getBukkit()), 1); - appendMe = ChatColor.YELLOW + ": +1 Mutation Token!"; + if (Config.Token.enabled()) { + if (Math.random() < Config.Token.mvpChance()) { + String appendMe; + if (Math.random() > 0.25) { + TokenUtil.giveMutationTokens(TokenUtil.getUser(bestPlayer.getBukkit()), 1); + appendMe = ChatColor.YELLOW + ": +1 Mutation Token!"; + } else { + TokenUtil.giveMapTokens(TokenUtil.getUser(bestPlayer.getBukkit()), 1); + appendMe = ChatColor.YELLOW + ": +1 SetNext Token!"; + } + subtitle = new Component(bestPlayer.getDisplayName() + appendMe); } else { - TokenUtil.giveMapTokens(TokenUtil.getUser(bestPlayer.getBukkit()), 1); - appendMe = ChatColor.YELLOW + ": +1 SetNext Token!"; + subtitle = new Component(bestPlayer.getDisplayName()); } - subtitle = new Component(bestPlayer.getDisplayName() + appendMe); } else { subtitle = new Component(bestPlayer.getDisplayName()); } - } else { - subtitle = new Component(bestPlayer.getDisplayName()); - } - for(MatchPlayer viewer : event.getMatch().getPlayers()) { - scheduler.createDelayedTask(100L, () -> { - viewer.showTitle(title, subtitle, 0, 60, 60); - }); + for (MatchPlayer viewer : event.getMatch().getPlayers()) { + scheduler.createDelayedTask(100L, () -> { + viewer.showTitle(title, subtitle, 0, 60, 60); + }); + } } } } diff --git a/PGM/src/main/java/tc/oc/pgm/tokens/TokenListener.java b/PGM/src/main/java/tc/oc/pgm/tokens/TokenListener.java index 263f594..860ac54 100644 --- a/PGM/src/main/java/tc/oc/pgm/tokens/TokenListener.java +++ b/PGM/src/main/java/tc/oc/pgm/tokens/TokenListener.java @@ -42,33 +42,35 @@ public class TokenListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void handleMatchEndEvent(final MatchEndEvent event) { - Match match = event.getMatch(); - //use the same playtime rules as raindrops - boolean applyCutoff = Comparables.greaterThan(match.getLength(), RaindropConstants.TEAM_REWARD_CUTOFF); - final Set winners = event.getMatch().needMatchModule(VictoryMatchModule.class).winners(); - for(MatchPlayer player : match.getParticipatingPlayers()) { - if(player.getParty() instanceof Team) { - Team team = (Team) player.getParty(); - Duration teamTime = team.getCumulativeParticipation(player.getPlayerId()); - if(!(applyCutoff && Comparables.lessThan(teamTime, RaindropConstants.TEAM_REWARD_CUTOFF))) { - Competitor playerTeam = player.getCompetitor(); - assert playerTeam != null; - double chance; - if (winners.contains(playerTeam)) { - chance = Config.Token.winningChance(); - } else { - chance = Config.Token.losingChance(); - } - if (Math.random() < chance) { - if (Math.random() > Config.Token.setNextTokenChange()) { - Bukkit.broadcastMessage(player.getDisplayName() + ChatColor.AQUA + " has won a Mutation Token!"); - TokenUtil.giveMutationTokens(TokenUtil.getUser(player.getBukkit()), 1); + if (Config.Token.enabled()) { + Match match = event.getMatch(); + //use the same playtime rules as raindrops + boolean applyCutoff = Comparables.greaterThan(match.getLength(), RaindropConstants.TEAM_REWARD_CUTOFF); + final Set winners = event.getMatch().needMatchModule(VictoryMatchModule.class).winners(); + for (MatchPlayer player : match.getParticipatingPlayers()) { + if (player.getParty() instanceof Team) { + Team team = (Team) player.getParty(); + Duration teamTime = team.getCumulativeParticipation(player.getPlayerId()); + if (!(applyCutoff && Comparables.lessThan(teamTime, RaindropConstants.TEAM_REWARD_CUTOFF))) { + Competitor playerTeam = player.getCompetitor(); + assert playerTeam != null; + double chance; + if (winners.contains(playerTeam)) { + chance = Config.Token.winningChance(); } else { - Bukkit.broadcastMessage(player.getDisplayName() + ChatColor.AQUA + " has won a SetNext Token!"); - TokenUtil.giveMapTokens(TokenUtil.getUser(player.getBukkit()), 1); + chance = Config.Token.losingChance(); + } + if (Math.random() < chance) { + if (Math.random() > Config.Token.setNextTokenChange()) { + Bukkit.broadcastMessage(player.getDisplayName() + ChatColor.AQUA + " has won a Mutation Token!"); + TokenUtil.giveMutationTokens(TokenUtil.getUser(player.getBukkit()), 1); + } else { + Bukkit.broadcastMessage(player.getDisplayName() + ChatColor.AQUA + " has won a SetNext Token!"); + TokenUtil.giveMapTokens(TokenUtil.getUser(player.getBukkit()), 1); + } } - } + } } } } diff --git a/PGM/src/main/resources/config.yml b/PGM/src/main/resources/config.yml index dca3fed..423330f 100644 --- a/PGM/src/main/resources/config.yml +++ b/PGM/src/main/resources/config.yml @@ -91,6 +91,9 @@ tokens: losing-chance: 0.001 sn-chance: 0.25 +mvp: + enabled: true + poll: enabled: true maps: