Add MVP module
This commit is contained in:
parent
dafc229d09
commit
c0202b4b2f
|
@ -157,6 +157,8 @@ broadcast.gameOver.gameOverText = Game over!
|
|||
broadcast.gameOver.teamWon = Your team won!
|
||||
broadcast.gameOver.teamLost = Your team lost
|
||||
|
||||
broadcast.gameOver.mvp = MVP
|
||||
|
||||
# {0} = singular / plural substitution
|
||||
broadcast.score.limitReached = Score limit of {0} reached
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import tc.oc.pgm.damage.DamageManifest;
|
|||
import tc.oc.pgm.destroyable.DestroyableManifest;
|
||||
import tc.oc.pgm.filters.FilterManifest;
|
||||
import tc.oc.pgm.flag.FlagManifest;
|
||||
import tc.oc.pgm.highlights.HighlightManifest;
|
||||
import tc.oc.pgm.itemkeep.ItemKeepManifest;
|
||||
import tc.oc.pgm.kits.KitManifest;
|
||||
import tc.oc.pgm.lane.LaneManifest;
|
||||
|
@ -68,5 +69,6 @@ public class PGMModulesManifest extends HybridManifest {
|
|||
install(new TokenManifest());
|
||||
install(new ObjectiveModeManifest());
|
||||
install(new BlitzManifest());
|
||||
install(new HighlightManifest());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,22 @@ import org.bukkit.event.HandlerList;
|
|||
|
||||
import tc.oc.pgm.match.Match;
|
||||
import tc.oc.pgm.match.Competitor;
|
||||
import tc.oc.pgm.match.MatchPlayer;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MatchScoreChangeEvent extends MatchEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Competitor competitor;
|
||||
private final Optional<MatchPlayer> player;
|
||||
private final double oldScore;
|
||||
private final double newScore;
|
||||
|
||||
public MatchScoreChangeEvent(Match match, Competitor competitor, double oldScore, double newScore) {
|
||||
public MatchScoreChangeEvent(Match match, Competitor competitor, Optional<MatchPlayer> player, double oldScore, double newScore) {
|
||||
super(match);
|
||||
this.competitor = competitor;
|
||||
this.player = player;
|
||||
this.oldScore = oldScore;
|
||||
this.newScore = newScore;
|
||||
}
|
||||
|
@ -23,6 +28,10 @@ public class MatchScoreChangeEvent extends MatchEvent {
|
|||
return this.competitor;
|
||||
}
|
||||
|
||||
public Optional<MatchPlayer> getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public double getOldScore() {
|
||||
return this.oldScore;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package tc.oc.pgm.highlights;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TranslatableComponent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import tc.oc.commons.core.chat.Component;
|
||||
import tc.oc.pgm.destroyable.DestroyableContribution;
|
||||
import tc.oc.pgm.events.MatchEndEvent;
|
||||
import tc.oc.pgm.match.MatchPlayer;
|
||||
import tc.oc.pgm.match.MatchScheduler;
|
||||
import tc.oc.pgm.playerstats.StatsUserFacet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class HighlightListener implements Listener {
|
||||
|
||||
private final MatchScheduler scheduler;
|
||||
|
||||
@Inject
|
||||
HighlightListener(MatchScheduler scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void matchEnd(MatchEndEvent event) {
|
||||
StatsUserFacet bestPlayerStats = null;
|
||||
MatchPlayer bestPlayer = null;
|
||||
int bestPlayerPoints = 0;
|
||||
|
||||
if (event.getMatch().getParticipatingPlayers().size() < 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (MatchPlayer player : event.getMatch().getParticipatingPlayers()) {
|
||||
StatsUserFacet facet = player.getUserContext().facet(StatsUserFacet.class);
|
||||
|
||||
int points = 0;
|
||||
points += facet.matchKills() * 2;
|
||||
points -= facet.deaths();
|
||||
for (long wool : facet.getWoolCaptureTimes()) {
|
||||
int woolPoints = (int)((wool * 2) - 2);
|
||||
points += Math.min(Math.max(woolPoints, 0), 120);
|
||||
}
|
||||
|
||||
for (long core : facet.getCoreLeakTimes()) {
|
||||
int corePoints = (int)((core * 2) - 2);
|
||||
points += Math.min(Math.max(corePoints, 0), 120);
|
||||
}
|
||||
|
||||
for (DestroyableContribution destroyable : facet.getDestroyableDestroyTimes().keySet()) {
|
||||
int destroyablePoints = (int)((facet.getDestroyableDestroyTimes().get(destroyable) * 2 * destroyable.getPercentage()) - 2);
|
||||
points += Math.min(Math.max(destroyablePoints, 0), 120);
|
||||
}
|
||||
|
||||
for (long flag : facet.getFlagCaptureTimes()) {
|
||||
int flagPoints = (int)(flag / 2);
|
||||
points += Math.min(Math.max(flagPoints, 0), 120);
|
||||
}
|
||||
|
||||
points += (facet.getBlocksBroken() / 20);
|
||||
|
||||
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 = new Component(bestPlayer.getDisplayName());
|
||||
|
||||
for(MatchPlayer viewer : event.getMatch().getPlayers()) {
|
||||
scheduler.createDelayedTask(100L, () -> {
|
||||
viewer.showTitle(title, subtitle, 0, 60, 60);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package tc.oc.pgm.highlights;
|
||||
|
||||
import tc.oc.commons.core.inject.HybridManifest;
|
||||
import tc.oc.pgm.map.inject.MapBinders;
|
||||
import tc.oc.pgm.match.MatchScope;
|
||||
import tc.oc.pgm.match.inject.MatchBinders;
|
||||
import tc.oc.pgm.match.inject.MatchScoped;
|
||||
|
||||
public class HighlightManifest extends HybridManifest implements MapBinders, MatchBinders {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(HighlightListener.class).in(MatchScoped.class);
|
||||
matchListener(HighlightListener.class, MatchScope.LOADED);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +1,50 @@
|
|||
package tc.oc.pgm.playerstats;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import tc.oc.commons.bukkit.event.targeted.TargetedEventHandler;
|
||||
import tc.oc.pgm.core.Core;
|
||||
import tc.oc.pgm.core.CoreBlockBreakEvent;
|
||||
import tc.oc.pgm.core.CoreLeakEvent;
|
||||
import tc.oc.pgm.destroyable.Destroyable;
|
||||
import tc.oc.pgm.destroyable.DestroyableContribution;
|
||||
import tc.oc.pgm.destroyable.DestroyableDestroyedEvent;
|
||||
import tc.oc.pgm.events.MatchPlayerDeathEvent;
|
||||
import tc.oc.pgm.events.MatchScoreChangeEvent;
|
||||
import tc.oc.pgm.events.PlayerPartyChangeEvent;
|
||||
import tc.oc.pgm.flag.event.FlagCaptureEvent;
|
||||
import tc.oc.pgm.match.MatchUserFacet;
|
||||
import tc.oc.pgm.match.ParticipantState;
|
||||
import tc.oc.pgm.match.inject.ForMatchUser;
|
||||
import tc.oc.pgm.spawns.events.ParticipantSpawnEvent;
|
||||
import tc.oc.pgm.wool.PlayerWoolPlaceEvent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
public class StatsUserFacet implements MatchUserFacet, Listener {
|
||||
|
||||
private final UUID player;
|
||||
private int lifeKills, teamKills, matchKills, deaths;
|
||||
private List<Long> woolCaptureTimes;
|
||||
private Map<Core, Long> coreTouchTimes;
|
||||
private List<Long> coreLeakTimes;
|
||||
private List<Long> flagCaptureTimes;
|
||||
private double pointsScored;
|
||||
private HashMap<DestroyableContribution, Long> destroyableDestroyTimes;
|
||||
private int blocksBroken;
|
||||
|
||||
@Inject public StatsUserFacet(@ForMatchUser UUID player) {
|
||||
this.player = player;
|
||||
woolCaptureTimes = new ArrayList<>();
|
||||
coreTouchTimes = new HashMap<>();
|
||||
coreLeakTimes = new ArrayList<>();
|
||||
flagCaptureTimes = new ArrayList<>();
|
||||
pointsScored = 0;
|
||||
destroyableDestroyTimes = new HashMap<>();
|
||||
blocksBroken = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,6 +75,32 @@ public class StatsUserFacet implements MatchUserFacet, Listener {
|
|||
return deaths;
|
||||
}
|
||||
|
||||
public List<Long> getWoolCaptureTimes() { return woolCaptureTimes; }
|
||||
|
||||
public Map<Core, Long> getCoreTouchTimes() {
|
||||
return coreTouchTimes;
|
||||
}
|
||||
|
||||
public List<Long> getCoreLeakTimes() {
|
||||
return coreLeakTimes;
|
||||
}
|
||||
|
||||
public List<Long> getFlagCaptureTimes() {
|
||||
return flagCaptureTimes;
|
||||
}
|
||||
|
||||
public double getPointsScored() {
|
||||
return pointsScored;
|
||||
}
|
||||
|
||||
public HashMap<DestroyableContribution, Long> getDestroyableDestroyTimes() {
|
||||
return destroyableDestroyTimes;
|
||||
}
|
||||
|
||||
public int getBlocksBroken() {
|
||||
return blocksBroken;
|
||||
}
|
||||
|
||||
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onKill(final MatchPlayerDeathEvent event) {
|
||||
ParticipantState killer = event.getKiller();
|
||||
|
@ -62,6 +113,61 @@ public class StatsUserFacet implements MatchUserFacet, Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onWoolPlace(final PlayerWoolPlaceEvent event) {
|
||||
if (event.getWool().isVisible() && event.getPlayer().getUniqueId().equals(player)) {
|
||||
woolCaptureTimes.add(event.getMatch().runningTime().toMinutes());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onFlagCapture(final FlagCaptureEvent event) {
|
||||
if (event.getGoal().isVisible() && event.getCarrier().getUniqueId().equals(player)) {
|
||||
flagCaptureTimes.add(event.getMatch().runningTime().toMinutes());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDestroyableDestroyed(final DestroyableDestroyedEvent event) {
|
||||
Destroyable destroyable = event.getDestroyable();
|
||||
|
||||
if (destroyable.isVisible()) {
|
||||
for (DestroyableContribution entry : event.getDestroyable().getContributions()) {
|
||||
if (entry.getPlayerState().getUniqueId().equals(player)) {
|
||||
destroyableDestroyTimes.put(entry, event.getMatch().runningTime().toMinutes());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCoreBlockBreak(final CoreBlockBreakEvent event) {
|
||||
if (event.getCore().isVisible() && event.getPlayer().getUniqueId().equals(player)) {
|
||||
coreTouchTimes.put(event.getCore(), event.getMatch().runningTime().toMinutes());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCoreLeak(final CoreLeakEvent event) {
|
||||
if (event.getCore().isVisible() && coreTouchTimes.containsKey(event.getCore())) {
|
||||
coreLeakTimes.add(coreTouchTimes.get(event.getCore()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onScoreEvent(final MatchScoreChangeEvent event) {
|
||||
if (event.getPlayer().isPresent() && event.getPlayer().get().getUniqueId().equals(player)) {
|
||||
pointsScored += event.getNewScore() - event.getOldScore();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onScoreEvent(final BlockBreakEvent event) {
|
||||
if (event.getPlayer().getUniqueId().equals(player)) {
|
||||
++blocksBroken;
|
||||
}
|
||||
}
|
||||
|
||||
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onSpawn(final ParticipantSpawnEvent event) {
|
||||
lifeKills = 0;
|
||||
|
@ -71,5 +177,12 @@ public class StatsUserFacet implements MatchUserFacet, Listener {
|
|||
public void onPartyChange(final PlayerPartyChangeEvent event) {
|
||||
lifeKills = 0;
|
||||
teamKills = 0;
|
||||
woolCaptureTimes.clear();
|
||||
coreTouchTimes.clear();
|
||||
coreLeakTimes.clear();
|
||||
flagCaptureTimes.clear();
|
||||
pointsScored = 0;
|
||||
destroyableDestroyTimes.clear();
|
||||
blocksBroken = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tc.oc.pgm.score;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -153,7 +154,7 @@ class ScoreBoxFactoryImpl extends FeatureDefinition.Impl implements ScoreBoxFact
|
|||
);
|
||||
}
|
||||
|
||||
smm.incrementScore(player.getCompetitor(), points);
|
||||
smm.incrementScore(player.getCompetitor(), points, Optional.of(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package tc.oc.pgm.score;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
@ -15,10 +16,7 @@ import tc.oc.commons.core.util.DefaultMapAdapter;
|
|||
import tc.oc.pgm.events.ListenerScope;
|
||||
import tc.oc.pgm.events.MatchPlayerDeathEvent;
|
||||
import tc.oc.pgm.events.MatchScoreChangeEvent;
|
||||
import tc.oc.pgm.match.Competitor;
|
||||
import tc.oc.pgm.match.Match;
|
||||
import tc.oc.pgm.match.MatchModule;
|
||||
import tc.oc.pgm.match.MatchScope;
|
||||
import tc.oc.pgm.match.*;
|
||||
import tc.oc.pgm.victory.VictoryMatchModule;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
@ -86,6 +84,10 @@ public class ScoreMatchModule extends MatchModule implements Listener {
|
|||
}
|
||||
|
||||
public void incrementScore(Competitor competitor, double amount) {
|
||||
this.incrementScore(competitor, amount, null);
|
||||
}
|
||||
|
||||
public void incrementScore(Competitor competitor, double amount, Optional<MatchPlayer> player) {
|
||||
double oldScore = this.scores.get(competitor);
|
||||
double newScore = oldScore + amount;
|
||||
|
||||
|
@ -93,7 +95,7 @@ public class ScoreMatchModule extends MatchModule implements Listener {
|
|||
newScore = this.config.scoreLimit.get();
|
||||
}
|
||||
|
||||
MatchScoreChangeEvent event = new MatchScoreChangeEvent(competitor.getMatch(), competitor, oldScore, newScore);
|
||||
MatchScoreChangeEvent event = new MatchScoreChangeEvent(competitor.getMatch(), competitor, player, oldScore, newScore);
|
||||
this.match.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
this.scores.put(competitor, event.getNewScore());
|
||||
|
|
Loading…
Reference in New Issue