2014-09-22 09:46:36 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
2014-10-03 03:17:36 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-07-09 04:47:40 +02:00
|
|
|
import mineplex.core.common.Rank;
|
2014-09-22 09:46:36 +02:00
|
|
|
import mineplex.core.common.util.C;
|
2015-07-09 04:47:40 +02:00
|
|
|
import mineplex.core.common.util.UtilMath;
|
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
2015-02-20 00:53:46 +01:00
|
|
|
import mineplex.core.leaderboard.LeaderboardManager;
|
2014-09-22 09:46:36 +02:00
|
|
|
import nautilus.game.arcade.ArcadeManager;
|
2015-07-09 04:47:40 +02:00
|
|
|
import nautilus.game.arcade.GameType;
|
2014-09-22 09:46:36 +02:00
|
|
|
import nautilus.game.arcade.events.GameStateChangeEvent;
|
|
|
|
import nautilus.game.arcade.game.Game.GameState;
|
|
|
|
import nautilus.game.arcade.stats.StatTracker;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
2014-10-03 03:17:36 +02:00
|
|
|
import org.bukkit.event.EventPriority;
|
2014-09-22 09:46:36 +02:00
|
|
|
import org.bukkit.event.HandlerList;
|
|
|
|
import org.bukkit.event.Listener;
|
2015-07-09 04:47:40 +02:00
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
2014-10-03 03:17:36 +02:00
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
2014-09-22 09:46:36 +02:00
|
|
|
|
|
|
|
public class GameStatManager implements Listener
|
|
|
|
{
|
|
|
|
ArcadeManager Manager;
|
2014-10-03 03:17:36 +02:00
|
|
|
|
|
|
|
private final HashMap<UUID, Long> _joinTimes = new HashMap<>();
|
2014-09-22 09:46:36 +02:00
|
|
|
|
|
|
|
public GameStatManager(ArcadeManager manager)
|
|
|
|
{
|
|
|
|
Manager = manager;
|
|
|
|
|
2015-02-26 06:07:07 +01:00
|
|
|
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
|
2014-09-22 09:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void StatEnableDisable(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
if (!Manager.IsRewardStats())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetState() != GameState.Live)
|
|
|
|
return;
|
|
|
|
|
2015-06-26 01:03:25 +02:00
|
|
|
//int requirement = (int)((double)event.GetGame().Manager.GetPlayerFull() * 0.75d);
|
|
|
|
int requirement = 2;
|
2014-09-22 09:46:36 +02:00
|
|
|
|
|
|
|
event.GetGame().CanAddStats = (double)event.GetGame().GetPlayers(true).size() >= requirement;
|
|
|
|
|
|
|
|
if (!event.GetGame().CanAddStats)
|
2015-03-17 11:52:58 +01:00
|
|
|
event.GetGame().Announce(C.Bold + "Stats/Achievements Disabled. Requires " + requirement + " Players.", event.GetGame().PlaySoundGameStart);
|
2014-09-22 09:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void StatRegister(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
if (!Manager.IsRewardStats())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.GetState() != GameState.Dead)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Player player : event.GetGame().GetStats().keySet())
|
|
|
|
{
|
|
|
|
for (String stat : event.GetGame().GetStats().get(player).keySet())
|
|
|
|
{
|
2015-02-20 00:53:46 +01:00
|
|
|
int value = event.GetGame().GetStats().get(player).get(stat);
|
2015-08-05 08:56:52 +02:00
|
|
|
|
|
|
|
if (value <= 0)
|
|
|
|
continue;
|
|
|
|
|
2015-02-20 00:53:46 +01:00
|
|
|
Manager.GetStatsManager().incrementStat(player, stat, value);
|
|
|
|
|
|
|
|
// Leaderboard hook for logging appropriate stat events
|
|
|
|
// Note: Rejects stat events that are not of the appropriate types.
|
|
|
|
int gameId = event.GetGame().GetType().getGameId();
|
|
|
|
LeaderboardManager.getInstance().attemptStatEvent(player, stat.split("\\.")[1], gameId, value);
|
2014-09-22 09:46:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void StatGameRecord(GameStateChangeEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetState() == GameState.End)
|
|
|
|
{
|
|
|
|
for (StatTracker tracker : event.GetGame().getStatTrackers())
|
|
|
|
HandlerList.unregisterAll(tracker);
|
|
|
|
|
|
|
|
if (event.GetGame().CanAddStats)
|
|
|
|
{
|
2015-02-19 00:51:36 +01:00
|
|
|
//Manager.saveBasicStats(event.GetGame());
|
2014-09-22 09:46:36 +02:00
|
|
|
|
2015-02-19 00:51:36 +01:00
|
|
|
//if (Manager.IsTournamentServer())
|
|
|
|
// Manager.saveLeaderboardStats(event.GetGame());
|
2014-09-22 09:46:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-03 03:17:36 +02:00
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
|
|
|
public void playTimeStatJoin(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
_joinTimes.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void playTimeStatQuit(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
Long joinTime = _joinTimes.remove(event.getPlayer().getUniqueId());
|
|
|
|
|
|
|
|
if (joinTime != null)
|
|
|
|
{
|
|
|
|
int timeInGame = (int) ((System.currentTimeMillis() - joinTime) / 1000);
|
|
|
|
|
|
|
|
Manager.GetStatsManager().incrementStat(event.getPlayer(), "Global.TimeInGame", timeInGame);
|
|
|
|
}
|
|
|
|
}
|
2015-07-09 04:47:40 +02:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void statBoostCommand(PlayerCommandPreprocessEvent event)
|
|
|
|
{
|
2015-08-28 22:22:04 +02:00
|
|
|
if (event.getMessage().startsWith("/statboost ") && Manager.GetClients().Get(event.getPlayer()).GetRank().has(Rank.OWNER))
|
2015-07-09 04:47:40 +02:00
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
|
|
|
|
String[] tokens = event.getMessage().split(" ");
|
|
|
|
|
|
|
|
if (tokens.length < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player player = UtilPlayer.searchOnline(event.getPlayer(), tokens[1], true);
|
|
|
|
if (player == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (GameType type : GameType.values())
|
|
|
|
{
|
|
|
|
int wins = UtilMath.r(50);
|
|
|
|
int loss = UtilMath.r(50);
|
|
|
|
int play = wins+loss;
|
|
|
|
|
|
|
|
Manager.GetStatsManager().incrementStat(player, type.GetName() + ".Wins", wins);
|
|
|
|
Manager.GetStatsManager().incrementStat(player, type.GetName() + ".Losses", loss);
|
|
|
|
Manager.GetStatsManager().incrementStat(player, type.GetName() + ".GamesPlayed", play);
|
|
|
|
}
|
|
|
|
|
|
|
|
event.getPlayer().sendMessage("Gave Stats: " + player.getName());
|
|
|
|
}
|
|
|
|
}
|
2014-09-22 09:46:36 +02:00
|
|
|
}
|