Rewrite leaderboard backend (again)

This commit is contained in:
AlexTheCoder 2017-05-11 14:48:35 -04:00
parent b4c27307ba
commit 5d1199634d
9 changed files with 209 additions and 129 deletions

View File

@ -4,6 +4,17 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.packethandler.IPacketHandler;
@ -14,24 +25,13 @@ import mineplex.core.updater.event.UpdateEvent;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity;
import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class HologramManager implements Listener, IPacketHandler
public class HologramManager extends MiniPlugin implements IPacketHandler
{
private ArrayList<Hologram> _activeHolograms = new ArrayList<Hologram>();
public HologramManager(JavaPlugin arcadeManager, PacketHandler packetHandler)
public HologramManager(JavaPlugin plugin, PacketHandler packetHandler)
{
Bukkit.getPluginManager().registerEvents(this, arcadeManager);
super("Hologram Manager", plugin);
packetHandler.addPacketHandler(this, true, PacketPlayInUseEntity.class);
}

View File

@ -12,13 +12,11 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.hologram.HologramManager;
import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType;
import mineplex.core.stats.StatsManager;
public class LeaderboardManager extends MiniPlugin
@ -26,15 +24,13 @@ public class LeaderboardManager extends MiniPlugin
private final Map<String, Leaderboard> _leaderboards = new HashMap<>();
private final long REFRESH_RATE;
private final LeaderboardRepository _repo;
private final HologramManager _holo;
private final Map<Leaderboard, Runnable> _loading = new HashMap<>();
public LeaderboardManager(JavaPlugin plugin, HologramManager hologram)
public LeaderboardManager(JavaPlugin plugin)
{
super("Leaderboard Manager", plugin);
_repo = new LeaderboardRepository(plugin);
_holo = hologram;
addCommand(new CommandBase<LeaderboardManager>(this, Rank.DEVELOPER, "cycleleaderboard")
{
@ -88,7 +84,7 @@ public class LeaderboardManager extends MiniPlugin
public HologramManager getHologramManager()
{
return _holo;
return Managers.get(HologramManager.class);
}
public Leaderboard getLeaderboard(String identifier)
@ -96,16 +92,14 @@ public class LeaderboardManager extends MiniPlugin
return _leaderboards.get(identifier);
}
public void handleStatIncrease(Player player, String stat, int value)
public void handleStatIncrease(Map<Integer, Map<Integer, Long>> stats)
{
final int accountId = Managers.get(CoreClientManager.class).getAccountId(player);
Managers.get(StatsManager.class).loadStatId(stat, id ->
{
if (accountId != -1)
{
_repo.insertStat(accountId, id, value);
_repo.insertStats(stats);
}
});
public void handleStatIncrease(int accountId, Map<Integer, Long> stats)
{
_repo.insertStats(accountId, stats);
}
public void registerLeaderboard(String identifier, Leaderboard board)
@ -118,10 +112,6 @@ public class LeaderboardManager extends MiniPlugin
final Runnable postLoad = () ->
{
_leaderboards.put(identifier, board);
if (board.getType() == LeaderboardSQLType.MONTHLY_SEASON || board.getType() == LeaderboardSQLType.YEARLY_SEASON)
{
log("Warning! You have selected a LeaderboardSQLType identified to be potentially expensive and intensive on Leaderboard ID: " + identifier);
}
_repo.loadLeaderboard(board, board::update);
};
_loading.put(board, postLoad);

View File

@ -1,6 +1,7 @@
package mineplex.core.leaderboard;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@ -14,46 +15,142 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilServer;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
public class LeaderboardRepository extends RepositoryBase
{
private static final int SEASON = 1;
private static final String CREATE_ALL_TIME = "CREATE TABLE accountStatsAllTime (accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex(value), FOREIGN KEY (accountId) REFERENCES Account.accounts(id), FOREIGN KEY (statId) REFERENCES Account.stats(id));";
private static final String CREATE_SEASONAL = "CREATE TABLE accountStatsSeasonal (accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, date DATE NOT NULL, season INT NOT NULL, PRIMARY KEY (accountId, statId, date, season), INDEX valueIndex(value), FOREIGN KEY (accountId) REFERENCES Account.accounts(id), FOREIGN KEY (statId) REFERENCES Account.stats(id));";
private static final String CREATE_TOTAL = "CREATE TABLE accountSeasonStatsTotal (accountId INT NOT NULL, statId INT NOT NULL, season SMALLINT NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId, season), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_YEARLY = "CREATE TABLE accountSeasonStatsYearly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_MONTHLY = "CREATE TABLE accountSeasonStatsMonthly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_WEEKLY = "CREATE TABLE accountSeasonStatsWeekly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_DAILY = "CREATE TABLE accountSeasonStatsDaily (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String INSERT_STAT = "INSERT INTO accountStatsSeasonal (accountId, statId, value, date, season) VALUES (?, (SELECT id FROM stats WHERE name=?), ?, CURDATE(), " + SEASON + ");";
private static final String UPDATE_STAT = "UPDATE accountStatsSeasonal SET value=value + ? WHERE accountId=? AND statId=? AND date=CURDATE() AND season=" + SEASON + ";";
private static final String INSERT_STAT = "INSERT INTO accountSeasonStatsTotal (accountId, statId, season, value) VALUES (?, ?, " + SEASON + ", ?);";
private static final String INSERT_STAT_ALL = "INSERT INTO accountSeasonStatsTotal (accountId, statId, season, value) VALUES (?, ?, 0, ?);";
private static final String UPDATE_STAT = "UPDATE accountSeasonStatsTotal SET value=value + ? WHERE accountId=? AND statId=? AND season=" + SEASON + ";";
private static final String UPDATE_STAT_ALL = "UPDATE accountSeasonStatsTotal SET value=value + ? WHERE accountId=? AND statId=? AND season=0;";
private static final String FETCH_STAT_ALL = "SELECT a.name, sl.value FROM accountStatsAllTime AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_ALL = "SELECT a.name, sl.value FROM accountSeasonStatsTotal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% AND season=0 ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_YEARLY = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_MONTHLY = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE MONTH(sl.date) = MONTH(CURDATE()) AND YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_WEEKLY = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEARWEEK(sl.date, 1) = YEARWEEK(CURDATE(), 1) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_DAILY = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.date = CURDATE() AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_ALL_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_YEARLY_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_MONTHLY_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE MONTH(sl.date) = MONTH(CURDATE()) AND YEAR(`date`) = YEAR(CURDATE()) AND sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_WEEKLY_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEARWEEK(sl.date, 1) = YEARWEEK(CURDATE(), 1) AND sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_DAILY_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.date = CURDATE() AND sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
public LeaderboardRepository(JavaPlugin plugin)
{
super(DBPool.getAccount());
}
public void insertStat(int accountId, int statId, int value)
public void insertStats(Map<Integer, Map<Integer, Long>> stats)
{
UtilServer.runAsync(() ->
{
int rowsAffected = executeUpdate(UPDATE_STAT, (Runnable)null, new ColumnInt("value", value), new ColumnInt("accountId", accountId), new ColumnInt("statId", statId));
if (rowsAffected == 0)
try (Connection c = getConnection())
{
executeInsert(INSERT_STAT, null, new ColumnInt("accountId", accountId), new ColumnInt("statId", statId), new ColumnInt("value", value));
final boolean auto = c.getAutoCommit();
c.setAutoCommit(true);
PreparedStatement s = c.prepareStatement(UPDATE_STAT);
PreparedStatement u = c.prepareStatement(UPDATE_STAT_ALL);
for (Integer accountId : stats.keySet())
{
for (Integer statId : stats.get(accountId).keySet())
{
s.setLong(1, stats.get(accountId).get(statId));
s.setInt(2, accountId);
s.setInt(3, statId);
s.addBatch();
u.setLong(1, stats.get(accountId).get(statId));
u.setInt(2, accountId);
u.setInt(3, statId);
u.addBatch();
}
}
int[] rowsAffected1 = s.executeBatch();
int[] rowsAffected2 = u.executeBatch();
c.setAutoCommit(false);
s = c.prepareStatement(INSERT_STAT);
u = c.prepareStatement(INSERT_STAT_ALL);
int i = 0;
for (Integer accountId : stats.keySet())
{
for (Integer statId : stats.get(accountId).keySet())
{
if (rowsAffected1[i] < 1)
{
s.setInt(1, accountId);
s.setInt(2, statId);
s.setLong(3, stats.get(accountId).get(statId));
s.addBatch();
}
if (rowsAffected2[i] < 1)
{
u.setInt(1, accountId);
u.setInt(2, statId);
u.setLong(3, stats.get(accountId).get(statId));
u.addBatch();
}
i++;
}
}
s.executeBatch();
u.executeBatch();
c.setAutoCommit(auto);
}
catch (SQLException e)
{
e.printStackTrace();
}
});
}
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Integer>> leaderboard)
public void insertStats(int accountId, Map<Integer, Long> stats)
{
UtilServer.runAsync(() ->
try (Connection c = getConnection())
{
final boolean auto = c.getAutoCommit();
c.setAutoCommit(true);
PreparedStatement s = c.prepareStatement(UPDATE_STAT);
for (Integer statId : stats.keySet())
{
s.setLong(1, stats.get(statId));
s.setInt(2, accountId);
s.setInt(3, statId);
s.addBatch();
}
int[] rowsAffected = s.executeBatch();
c.setAutoCommit(false);
s = c.prepareStatement(INSERT_STAT);
int i = 0;
for (Integer statId : stats.keySet())
{
if (rowsAffected[i] < 1)
{
s.setInt(1, accountId);
s.setInt(2, statId);
s.setLong(3, stats.get(statId));
s.addBatch();
}
i++;
}
s.executeBatch();
c.setAutoCommit(auto);
}
catch (SQLException e)
{
e.printStackTrace();
}
}
public void loadLeaderboard(Leaderboard board, Consumer<Map<String, Integer>> leaderboard)
{
Map<String, Integer> names = new LinkedHashMap<>();
try (Connection c = getConnection())
@ -82,7 +179,6 @@ public class LeaderboardRepository extends RepositoryBase
{
UtilServer.runSync(() -> leaderboard.accept(names));
}
});
}
@SuppressWarnings("unchecked")
@ -145,10 +241,10 @@ public class LeaderboardRepository extends RepositoryBase
public static enum LeaderboardSQLType
{
DAILY_SEASON(FETCH_STAT_DAILY_SEASON),
WEEKLY_SEASON(FETCH_STAT_WEEKLY_SEASON),
MONTHLY_SEASON(FETCH_STAT_MONTHLY_SEASON),
YEARLY_SEASON(FETCH_STAT_YEARLY_SEASON),
DAILY(FETCH_STAT_DAILY),
WEEKLY(FETCH_STAT_WEEKLY),
MONTHLY(FETCH_STAT_MONTHLY),
YEARLY(FETCH_STAT_YEARLY),
ALL(FETCH_STAT_ALL),
ALL_SEASON(FETCH_STAT_ALL_SEASON)
;

View File

@ -21,6 +21,7 @@ import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTasks;
import mineplex.core.leaderboard.LeaderboardManager;
import mineplex.core.stats.command.GiveStatCommand;
import mineplex.core.stats.command.MasterBuilderUnban;
import mineplex.core.stats.command.SetLevelCommand;
@ -39,6 +40,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
private final CoreClientManager _coreClientManager;
private final StatsRepository _repository;
private final LeaderboardManager _leaderboard;
private final Map<String, Integer> _stats = new HashMap<>();
private final Map<CoreClient, Map<String, Long>> _statUploadQueue = new HashMap<>();
@ -51,10 +53,20 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
_repository = new StatsRepository();
_coreClientManager = clientManager;
_leaderboard = new LeaderboardManager(plugin);
UtilScheduler.runAsyncEvery(UpdateType.SEC, () ->
{
save(_statUploadQueue, _repository::saveStats, "increment");
save(_statUploadQueueOverRidable, map -> _repository.saveStats(map, true), "override");
save(_statUploadQueue, map ->
{
_repository.saveStats(map);
_leaderboard.handleStatIncrease(map);
}, "increment");
save(_statUploadQueueOverRidable, map ->
{
_repository.saveStats(map, true);
_leaderboard.handleStatIncrease(map);
}, "override");
});
for (Stat stat : _repository.retrieveStats())
@ -125,6 +137,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
*
* @param value The value, must be greater or equal to zero
*/
@Deprecated
public void setStat(Player player, String statName, long value)
{
if (value < 0)
@ -158,6 +171,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
*
* @param value The value, must be greater or equal to zero
*/
@Deprecated
public void setStat(final int accountId, final String statName, final long value)
{
if (value < 0)
@ -172,6 +186,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
});
}
@Deprecated
private void addToOverRidableQueue(String statName, CoreClient client, long value)
{
if (client.getAccountId() == -1)

View File

@ -52,7 +52,6 @@ import mineplex.core.ignore.IgnoreManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.leaderboard.LeaderboardManager;
import mineplex.core.memory.MemoryFix;
import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
@ -196,8 +195,6 @@ public class Arcade extends JavaPlugin
ProjectileManager projectileManager = new ProjectileManager(this);
HologramManager hologramManager = new HologramManager(this, packetHandler);
new LeaderboardManager(this, hologramManager);
//Inventory
InventoryManager inventoryManager = new InventoryManager(this, _clientManager);
CastleManager castleManager = new CastleManager(this, _clientManager, hologramManager, false);

View File

@ -347,8 +347,6 @@ public abstract class Game extends ListenerComponent implements Lifetimed
public boolean EloRanking = false;
public int EloStart = 1000;
public boolean Leaderboards = false;
public boolean CanAddStats = true;
public boolean CanGiveLoot = true;

View File

@ -184,7 +184,6 @@ public class CastleAssault extends TeamGame
this.AllowFlintAndSteel = true;
this.BlockPlaceAllow.add(Material.FIRE.getId());
this.CrownsEnabled = true;
this.Leaderboards = true;
this.FirstKillReward = 20;
this.GemKillDeathRespawn = 1;
@ -206,12 +205,12 @@ public class CastleAssault extends TeamGame
if (lobbyCustomLocs.containsKey("TOP_DAILY_WINS"))
{
Location loc = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0);
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_WINS", new Leaderboard("Top Daily Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault.Wins"}, LeaderboardSQLType.DAILY_SEASON, loc, 10));
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_WINS", new Leaderboard("Top Daily Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault.Wins"}, LeaderboardSQLType.DAILY, loc, 10));
}
if (lobbyCustomLocs.containsKey("TOP_DAILY_KILLS"))
{
Location loc = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0);
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault.Kills"}, LeaderboardSQLType.DAILY_SEASON, loc, 10));
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault.Kills"}, LeaderboardSQLType.DAILY, loc, 10));
}
if (lobbyCustomLocs.containsKey("TOP_WINS"))
{

View File

@ -47,7 +47,6 @@ import org.bukkit.material.MaterialData;
import org.bukkit.metadata.MetadataValue;
import mineplex.core.Managers;
import mineplex.core.common.Pair;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
@ -60,9 +59,7 @@ import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.leaderboard.Leaderboard;
import mineplex.core.leaderboard.LeaderboardManager;
import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType;
import mineplex.core.loot.ChestLoot;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
@ -85,7 +82,6 @@ import nautilus.game.arcade.game.games.castleassault.kits.KitPlayer;
import nautilus.game.arcade.game.games.castleassault.kits.KitTank;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.lobby.current.NewGameLobbyManager;
public class CastleAssaultTDM extends TeamGame
{
@ -144,7 +140,6 @@ public class CastleAssaultTDM extends TeamGame
this.AllowFlintAndSteel = true;
this.BlockPlaceAllow.add(Material.FIRE.getId());
this.CrownsEnabled = true;
this.Leaderboards = true;
this.FirstKillReward = 20;
this.GemKillDeathRespawn = 1;
@ -157,33 +152,33 @@ public class CastleAssaultTDM extends TeamGame
_flintAndSteel = new ItemBuilder(Material.FLINT_AND_STEEL).setData((short) (Material.FLINT_AND_STEEL.getMaxDurability() - MAX_FLINT_AND_STEEL_USES));
generateLoot();
if (manager.IsRewardStats())
{
if (manager.GetLobby() instanceof NewGameLobbyManager)
{
Map<String, List<Location>> lobbyCustomLocs = ((NewGameLobbyManager)manager.GetLobby()).getCustomLocs();
if (lobbyCustomLocs.containsKey("TOP_DAILY_WINS"))
{
Location loc = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0);
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_WINS", new Leaderboard("Top Daily Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault TDM.Wins"}, LeaderboardSQLType.DAILY_SEASON, loc, 10));
}
if (lobbyCustomLocs.containsKey("TOP_DAILY_KILLS"))
{
Location loc = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0);
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault TDM.Kills"}, LeaderboardSQLType.DAILY_SEASON, loc, 10));
}
if (lobbyCustomLocs.containsKey("TOP_WINS"))
{
Location loc = lobbyCustomLocs.get("TOP_WINS").get(0);
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_WINS", new Leaderboard("Top Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault TDM.Wins"}, LeaderboardSQLType.ALL_SEASON, loc, 10));
}
if (lobbyCustomLocs.containsKey("TOP_KILLS"))
{
Location loc = lobbyCustomLocs.get("TOP_KILLS").get(0);
Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_KILLS", new Leaderboard("Top Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault TDM.Kills"}, LeaderboardSQLType.ALL_SEASON, loc, 10));
}
}
}
// if (manager.IsRewardStats())
// {
// if (manager.GetLobby() instanceof NewGameLobbyManager)
// {
// Map<String, List<Location>> lobbyCustomLocs = ((NewGameLobbyManager)manager.GetLobby()).getCustomLocs();
// if (lobbyCustomLocs.containsKey("TOP_DAILY_WINS"))
// {
// Location loc = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0);
// Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_WINS", new Leaderboard("Top Daily Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault TDM.Wins"}, LeaderboardSQLType.DAILY_SEASON, loc, 10));
// }
// if (lobbyCustomLocs.containsKey("TOP_DAILY_KILLS"))
// {
// Location loc = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0);
// Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault TDM.Kills"}, LeaderboardSQLType.DAILY_SEASON, loc, 10));
// }
// if (lobbyCustomLocs.containsKey("TOP_WINS"))
// {
// Location loc = lobbyCustomLocs.get("TOP_WINS").get(0);
// Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_WINS", new Leaderboard("Top Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault TDM.Wins"}, LeaderboardSQLType.ALL_SEASON, loc, 10));
// }
// if (lobbyCustomLocs.containsKey("TOP_KILLS"))
// {
// Location loc = lobbyCustomLocs.get("TOP_KILLS").get(0);
// Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULT_KILLS", new Leaderboard("Top Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault TDM.Kills"}, LeaderboardSQLType.ALL_SEASON, loc, 10));
// }
// }
// }
}
private void generateLoot()

View File

@ -12,12 +12,10 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.Managers;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.leaderboard.LeaderboardManager;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
@ -74,14 +72,6 @@ public class GameStatManager implements Listener
continue;
Manager.GetStatsManager().incrementStat(player, stat, value);
if (!event.GetGame().Leaderboards)
continue;
if (stat.startsWith("Global."))
continue;
Manager.runSyncLater(() -> Managers.get(LeaderboardManager.class).handleStatIncrease(player, stat, value), 40L);
}
}
}