diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index 707d0f8c3..c756bea2f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -1377,97 +1377,97 @@ public enum Achievement AchievementCategory.MOBA), CAKE_WARS_WIN("Cake Dinners", 15000, - new String[]{"Cake Wars Rumble.Wins", "Cake Wars Duos.Wins"}, + new String[]{"Cake Wars 4v4v4v4.Wins", "Cake Wars Duos.Wins"}, new String[]{"Win 100 games of Cake Wars"}, new int[]{100}, AchievementCategory.CAKE_WARS), CAKE_WARS_KILLS("Cake Slayer", 15000, - new String[]{"Cake Wars Rumble.Kills", "Cake Wars Duos.Kills"}, + new String[]{"Cake Wars 4v4v4v4.Kills", "Cake Wars Duos.Kills"}, new String[]{"Kill 1000 players in Cake Wars"}, new int[]{1000}, AchievementCategory.CAKE_WARS), CAKE_WARS_BITES("Big Appetite", 15000, - new String[]{"Cake Wars Rumble.Bites", "Cake Wars Duos.Bites"}, + new String[]{"Cake Wars 4v4v4v4.Bites", "Cake Wars Duos.Bites"}, new String[]{"Take 500 bites of cake in Cake Wars"}, new int[]{500}, AchievementCategory.CAKE_WARS), CAKE_WARS_EAT_WHOLE_CAKE("Greedy", 2000, - new String[]{"Cake Wars Rumble.EatWholeCake", "Cake Wars Duos.EatWholeCake"}, + new String[]{"Cake Wars 4v4v4v4.EatWholeCake", "Cake Wars Duos.EatWholeCake"}, new String[]{"Eat a whole cake"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_SURVIVE_10("This game has cakes?", 4000, - new String[]{"Cake Wars Rumble.Survive10", "Cake Wars Duos.Survive10"}, + new String[]{"Cake Wars 4v4v4v4.Survive10", "Cake Wars Duos.Survive10"}, new String[]{"Survive 10 minutes without", "a cake"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_FIRST_BLOOD("Cold Baked Killer", 2000, - new String[]{"Cake Wars Rumble.FirstBlood", "Cake Wars Duos.FirstBlood"}, + new String[]{"Cake Wars 4v4v4v4.FirstBlood", "Cake Wars Duos.FirstBlood"}, new String[]{"Get 10 First Bloods"}, new int[]{10}, AchievementCategory.CAKE_WARS), CAKE_WARS_EAT_1("Starving", 2000, - new String[]{"Cake Wars Rumble.Eat1", "Cake Wars Duos.Eat1"}, + new String[]{"Cake Wars 4v4v4v4.Eat1", "Cake Wars Duos.Eat1"}, new String[]{"Eat a cake within the first", "minute of the game"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_NO_DEATHS("You call that a challenge", 4000, - new String[]{"Cake Wars Rumble.NoDeaths", "Cake Wars Duos.NoDeaths"}, + new String[]{"Cake Wars 4v4v4v4.NoDeaths", "Cake Wars Duos.NoDeaths"}, new String[]{"Win a game without dying"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_BUY_ALL("Team Player", 2000, - new String[]{"Cake Wars Rumble.BuyAll", "Cake Wars Duos.BuyAll"}, + new String[]{"Cake Wars 4v4v4v4.BuyAll", "Cake Wars Duos.BuyAll"}, new String[]{"Purchase all Team Upgrades", "within one game"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_WIN_WITHOUT_KILL("Love not War", 4000, - new String[]{"Cake Wars Rumble.NoKills", "Cake Wars Duos.NoKills"}, + new String[]{"Cake Wars 4v4v4v4.NoKills", "Cake Wars Duos.NoKills"}, new String[]{"Win a game without killing", "a player"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_WIN_WITH_1("Last Crumb", 2000, - new String[]{"Cake Wars Rumble.WinWithOneBite", "Cake Wars Duos.WinWithOneBite"}, + new String[]{"Cake Wars 4v4v4v4.WinWithOneBite", "Cake Wars Duos.WinWithOneBite"}, new String[]{"Win a game with only one", "bite of your cake left"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_WIN_IN_10("Gotta go fast", 2000, - new String[]{"Cake Wars Rumble.WinIn10", "Cake Wars Duos.WinIn10"}, + new String[]{"Cake Wars 4v4v4v4.WinIn10", "Cake Wars Duos.WinIn10"}, new String[]{"Win a game within 10", "minutes"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_FINAL_BITE("Last Laugh", 2000, - new String[]{"Cake Wars Rumble.FinalBite", "Cake Wars Duos.FinalBite"}, + new String[]{"Cake Wars 4v4v4v4.FinalBite", "Cake Wars Duos.FinalBite"}, new String[]{"Get the final bite on every", "cake within a game"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_OWN_ALL_BEACONS("I <3 Capture Points", 4000, - new String[]{"Cake Wars Rumble.OwnAllBeacons", "Cake Wars Duos.OwnAllBeacons"}, + new String[]{"Cake Wars 4v4v4v4.OwnAllBeacons", "Cake Wars Duos.OwnAllBeacons"}, new String[]{"Own all beacons for your team", "in one game"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_GET_GOOD("Get Good", 15000, - new String[]{"Cake Wars Rumble.GetGood", "Cake Wars Duos.GetGood"}, + new String[]{"Cake Wars 4v4v4v4.GetGood", "Cake Wars Duos.GetGood"}, new String[]{"Kill a player while falling", "from a great height.", "Then save yourself from dying"}, new int[]{1}, AchievementCategory.CAKE_WARS), CAKE_WARS_FLOOR_IS_LAVA("The Floor Is Lava", 15000, - new String[]{"Cake Wars Rumble.FloorIsLava", "Cake Wars Duos.FloorIsLava"}, + new String[]{"Cake Wars 4v4v4v4.FloorIsLava", "Cake Wars Duos.FloorIsLava"}, new String[]{"Win a game of Cake Wars while", "after the first 30 seconds of the game,", "only stand on player placed blocks", "", "Includes Deploy Platforms and", "near Shops"}, new int[]{1}, AchievementCategory.CAKE_WARS), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java index e12f59fc1..65b811160 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java @@ -247,7 +247,7 @@ public enum AchievementCategory CAKE_WARS("Cake Wars", null, new StatDisplay[] { - new StatDisplay(C.Bold + "Rumble", true), + new StatDisplay(C.Bold + "4v4v4v4", true), StatDisplay.fromGame("Wins", GameDisplay.CakeWars4, "Wins"), StatDisplay.fromGame("Games Play", GameDisplay.CakeWars4, "Wins", "Losses"), StatDisplay.fromGame("Best Win Streak", GameDisplay.CakeWars4, "BestWinStreak"), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index 09273a8d0..64a870971 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -109,7 +109,7 @@ public enum GameDisplay BattleRoyale("Battle Royale", Material.DIAMOND_SWORD, (byte)0, GameCategory.EVENT, 72, false), - CakeWars4("Cake Wars Rumble", Material.CAKE, (byte)0, GameCategory.CLASSICS, 73, true), + CakeWars4("Cake Wars 4v4v4v4", Material.CAKE, (byte)0, GameCategory.CLASSICS, 73, true), CakeWarsDuos("Cake Wars Duos", Material.CAKE, (byte)0, GameCategory.CLASSICS, 74, false), GemHunters("Gem Hunters", Material.EMERALD, (byte) 0, GameCategory.SURVIVAL, 71, false), diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index f74785ccc..f05187192 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -656,7 +656,7 @@ public class Hologram { newText[i] = newLines[newText.length - (i + 1)]; } - if (newText.equals(_hologramText)) + if (Arrays.equals(newText, _hologramText)) { return this; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramInteraction.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramInteraction.java index b6bc659e3..cafec6c5f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramInteraction.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramInteraction.java @@ -3,7 +3,8 @@ package mineplex.core.hologram; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +@FunctionalInterface public interface HologramInteraction { - public void onClick(Player player, ClickType clickType); + void onClick(Player player, ClickType clickType); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java index 88f6547cd..af6b9624a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/HologramManager.java @@ -15,6 +15,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import mineplex.core.MiniPlugin; +import mineplex.core.ReflectivelyCreateMiniPlugin; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTime; import mineplex.core.packethandler.IPacketHandler; @@ -25,14 +26,17 @@ import mineplex.core.updater.event.UpdateEvent; import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity; import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity.EnumEntityUseAction; +@ReflectivelyCreateMiniPlugin public class HologramManager extends MiniPlugin implements IPacketHandler { - private ArrayList _activeHolograms = new ArrayList(); - public HologramManager(JavaPlugin plugin, PacketHandler packetHandler) + private final List _activeHolograms = new ArrayList<>(); + + private HologramManager() { - super("Hologram Manager", plugin); - packetHandler.addPacketHandler(this, true, PacketPlayInUseEntity.class); + super("Hologram Manager"); + + require(PacketHandler.class).addPacketHandler(this, true, PacketPlayInUseEntity.class); } void addHologram(Hologram hologram) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/DynamicLeaderboard.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/DynamicLeaderboard.java new file mode 100644 index 000000000..f119b32f0 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/DynamicLeaderboard.java @@ -0,0 +1,149 @@ +package mineplex.core.leaderboard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.hologram.Hologram.HologramTarget; +import mineplex.core.recharge.Recharge; + +public class DynamicLeaderboard extends LeaderboardDisplay implements PlayerActionHook +{ + + private final List _leaderboards; + private final Map _viewingTime; + + public DynamicLeaderboard(LeaderboardManager manager, List leaderboards) + { + super(manager); + + _leaderboards = leaderboards; + _viewingTime = new HashMap<>(); + + _leaderboards.forEach(leaderboard -> + { + leaderboard.getHologram().setHologramTarget(HologramTarget.WHITELIST); + leaderboard.getHologram().setInteraction((player, clickType) -> rotateTime(player)); + }); + } + + private void rotateTime(Player player) + { + if (_leaderboards.size() == 1 || !Recharge.Instance.use(player, "Leaderboard Interact", 500, false, false)) + { + return; + } + + int newIndex = _viewingTime.get(player) + 1; + + if (newIndex == _leaderboards.size()) + { + newIndex = 0; + } + + setViewingTime(player, newIndex, true); + } + + @Override + public void onPlayerJoin(Player player) + { + setViewingTime(player, 0); + } + + @Override + public void onPlayerQuit(Player player) + { + _viewingTime.remove(player); + } + + public void setViewingTime(Player player) + { + setViewingTime(player, 0); + } + + public void setViewingTime(Player player, int newIndex) + { + setViewingTime(player, newIndex, false); + } + + public void setViewingTime(Player player, int newIndex, boolean inform) + { + Integer oldIndex = _viewingTime.get(player); + + if (oldIndex != null) + { + _leaderboards.get(oldIndex).getHologram().removePlayer(player); + } + + if (newIndex == -1) + { + return; + } + + StaticLeaderboard newLeaderboard = _leaderboards.get(newIndex); + + if (inform) + { + player.playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1); + player.sendMessage(F.main(_manager.getName(), "You are now viewing " + F.name(newLeaderboard.getName()) + ".")); + } + + newLeaderboard.getHologram().addPlayer(player); + _viewingTime.put(player, newIndex); + } + + @Override + public void register() + { + } + + @Override + public void unregister() + { + _leaderboards.forEach(LeaderboardDisplay::unregister); + _viewingTime.clear(); + } + + @Override + public void update() + { + _leaderboards.forEach(leaderboard -> + { + leaderboard.update(); + + if (_leaderboards.size() > 1) + { + String[] text = leaderboard.getHologram().getText(); + String[] newText = new String[text.length + 3]; + + System.arraycopy(text, 0, newText, 0, text.length); + newText[text.length] = C.blankLine; + newText[text.length + 1] = C.cYellowB + "Click to view the"; + newText[text.length + 2] = C.cYellowB + "next category"; + + leaderboard.getHologram().setText(newText); + } + }); + } + + @Override + public List getDisplayedLeaderboards() + { + List leaderboards = new ArrayList<>(); + + _leaderboards.forEach(display -> leaderboards.addAll(display.getDisplayedLeaderboards())); + + return leaderboards; + } + + public List getLeaderboards() + { + return _leaderboards; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/Leaderboard.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/Leaderboard.java index 201d8790b..b15209fcb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/Leaderboard.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/Leaderboard.java @@ -1,112 +1,102 @@ package mineplex.core.leaderboard; -import java.util.Collections; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import org.bukkit.Location; - -import mineplex.core.Managers; -import mineplex.core.common.Pair; import mineplex.core.common.util.C; -import mineplex.core.hologram.Hologram; -import mineplex.core.hologram.HologramManager; import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType; public class Leaderboard { - private static final HologramManager HOLOGRAM_MANAGER = Managers.get(HologramManager.class); + private static final String NULL_ENTRY = C.cGray + " - "; - private final String _display; - private final Pair _statDisplay; - private final String[] _statNames; - private final int[] _statIds; - private final int _size, _start; private final LeaderboardSQLType _type; - private final Location _loc; - private Hologram _holo; - - public Leaderboard(String display, Pair statDisplayNames, String[] statNames, LeaderboardSQLType type, Location displayLoc, int size) + private final int _start, _size; + private final int[] _statIds; + private final String[] _statNames; + private final Map _entries; + private final List _formattedEntries; + + public Leaderboard(LeaderboardSQLType type, String... statNames) { - this(display, statDisplayNames, statNames, type, displayLoc, size, 0); + this(type, 10, statNames); } - @SuppressWarnings("unchecked") - public Leaderboard(String display, Pair statDisplayNames, String[] statNames, LeaderboardSQLType type, Location displayLoc, int size, int start) + public Leaderboard(LeaderboardSQLType type, int size, String... statNames) + { + this(type, 0, size, statNames); + } + + public Leaderboard(LeaderboardSQLType type, int start, int size, String... statNames) { - _display = display; - _statDisplay = statDisplayNames; - _statNames = statNames; - _statIds = new int[_statNames.length]; _type = type; - _size = size; _start = start; - _loc = displayLoc; + _size = size; + _statIds = new int[statNames.length]; + _statNames = statNames; + _entries = new HashMap<>(size); + _formattedEntries = new ArrayList<>(size); + } - update(Collections.EMPTY_MAP); - } - - public int getSize() + public void update(Map entries) { - return _size; + _entries.clear(); + _entries.putAll(entries); + _formattedEntries.clear(); + + AtomicInteger place = new AtomicInteger(_start); + + entries.forEach((name, value) -> _formattedEntries.add(C.cAqua + "#" + place.incrementAndGet() + C.cGray + " - " + C.cYellow + name + C.cGray + " - " + C.cYellow + value)); + + while (place.getAndIncrement() < _size) + { + _formattedEntries.add(NULL_ENTRY); + } } - - public int getStart() - { - return _start; - } - - /** - * The returned array is not safe for mutation - */ - public String[] getStatNames() - { - return _statNames; - } - - public synchronized int[] getStatIds() - { - return _statIds; - } - + public LeaderboardSQLType getType() { return _type; } - - public void update(Map names) + + public int getStart() { - deconstruct(); - LinkedList display = new LinkedList<>(); - display.add(C.cAqua + _display); - display.add(C.blankLine); - AtomicInteger place = new AtomicInteger(_start + 1); - - names.forEach((name, value) -> - { - display.add(C.cGreen + "#" + place + " " + name + C.cRed + " " + value + " " + (value == 1 ? _statDisplay.getLeft() : _statDisplay.getRight())); - place.getAndIncrement(); - }); - - _holo = new Hologram(HOLOGRAM_MANAGER, _loc, display.toArray(new String[0])) - .start(); + return _start; } - - public synchronized void setStatId(int index, int id) + + public int getSize() + { + return _size; + } + + synchronized void setStatId(int index, int id) { if (_statIds.length > index && index >= 0) { _statIds[index] = id; } } - - public void deconstruct() + + synchronized int[] getStatIds() { - if (_holo != null) - { - _holo.stop(); - _holo = null; - } + return _statIds; + } + + String[] getStatNames() + { + return _statNames; + } + + public Map getEntries() + { + return _entries; + } + + public List getFormattedEntries() + { + return _formattedEntries; } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardDisplay.java new file mode 100644 index 000000000..ab3f31b77 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardDisplay.java @@ -0,0 +1,22 @@ +package mineplex.core.leaderboard; + +import java.util.List; + +public abstract class LeaderboardDisplay +{ + + protected final LeaderboardManager _manager; + + LeaderboardDisplay(LeaderboardManager manager) + { + _manager = manager; + } + + public abstract void register(); + + public abstract void unregister(); + + public abstract void update(); + + public abstract List getDisplayedLeaderboards(); +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardManager.java index e7d274a1b..631947f0d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardManager.java @@ -8,35 +8,46 @@ import java.util.Map; import java.util.Map.Entry; import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; -import mineplex.core.Managers; import mineplex.core.MiniPlugin; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.command.CommandBase; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; import mineplex.core.hologram.HologramManager; import mineplex.core.stats.StatsManager; public class LeaderboardManager extends MiniPlugin { + public enum Perm implements Permission { CYCLE_LEADERBOARD_COMMAND, } - private final Map _leaderboards = new HashMap<>(); + private final StatsManager _statsManager; + private final HologramManager _hologramManager; private final LeaderboardRepository _repo; - private final Map _loading = new HashMap<>(); - - public LeaderboardManager(JavaPlugin plugin) + + private final Map _leaderboards; + private final Map _loading; + + public LeaderboardManager(StatsManager statsManager) { - super("Leaderboard Manager", plugin); - - _repo = new LeaderboardRepository(plugin); - + super("Leaderboard"); + + _statsManager = statsManager; + _hologramManager = require(HologramManager.class); + + _repo = new LeaderboardRepository(); + _leaderboards = new HashMap<>(); + _loading = new HashMap<>(); + addCommand(new CommandBase(this, Perm.CYCLE_LEADERBOARD_COMMAND, "cycleleaderboard") { @Override @@ -47,10 +58,12 @@ public class LeaderboardManager extends MiniPlugin } }); - long refreshRate = 5 * 60 * 20 + ((UtilMath.r(5) + 1) * 60 * 20); - - runSyncTimer(this::refreshBoards, 0, refreshRate); - + int oneMinute = 60 * 20; + int refreshRate = oneMinute * 10; + int initialDelay = UtilMath.r(oneMinute); + + runSyncTimer(this::refreshBoards, initialDelay, refreshRate); + runSyncTimer(() -> { Iterator> iterator = _loading.entrySet().iterator(); @@ -72,77 +85,112 @@ public class LeaderboardManager extends MiniPlugin } } }, 0, 20 * 2); - + generatePermissions(); } - + private void generatePermissions() { PermissionGroup.DEV.setPermission(Perm.CYCLE_LEADERBOARD_COMMAND, true, true); } - + private void refreshBoards() { List leaderboards = new ArrayList<>(); - leaderboards.addAll(_leaderboards.values()); - _repo.loadLeaderboards(_leaderboards.values(), boards -> + _leaderboards.values().forEach(display -> leaderboards.addAll(display.getDisplayedLeaderboards())); + + _repo.loadLeaderboards(leaderboards, boards -> { for (int i = 0; i < boards.length && i < leaderboards.size(); i++) { leaderboards.get(i).update(boards[i]); + _leaderboards.values().forEach(LeaderboardDisplay::update); } }); } - - public HologramManager getHologramManager() - { - return Managers.get(HologramManager.class); - } - - public Leaderboard getLeaderboard(String identifier) - { - return _leaderboards.get(identifier); - } - + public void handleStatIncrease(Map> stats) { _repo.insertStats(stats); } - - public void handleStatIncrease(int accountId, Map stats) + + public void registerLeaderboard(String identifier, LeaderboardDisplay display) { - _repo.insertStats(accountId, stats); - } - - public void registerLeaderboard(String identifier, Leaderboard board) - { - if (_leaderboards.containsKey(identifier)) + LeaderboardDisplay oldDisplay = _leaderboards.remove(identifier); + + if (oldDisplay != null) { - board.deconstruct(); - return; + oldDisplay.unregister(); } + + List boards = display.getDisplayedLeaderboards(); + final Runnable postLoad = () -> { - _leaderboards.put(identifier, board); - _repo.loadLeaderboard(board, board::update); - }; - _loading.put(board, postLoad); - for (int i = 0; i < board.getStatNames().length; i++) - { - final int index = i; - Managers.get(StatsManager.class).loadStatId(board.getStatNames()[index], id -> + _leaderboards.put(identifier, display); + + for (Leaderboard board : boards) { - board.setStatId(index, id); - }); + _repo.loadLeaderboard(board, board::update); + } + + if (display instanceof PlayerActionHook) + { + PlayerActionHook actionHook = (PlayerActionHook) display; + UtilServer.getPlayersCollection().forEach(actionHook::onPlayerJoin); + } + + display.update(); + }; + + for (Leaderboard board : boards) + { + _loading.put(board, postLoad); + + for (int i = 0; i < board.getStatNames().length; i++) + { + final int index = i; + _statsManager.loadStatId(board.getStatNames()[index], id -> board.setStatId(index, id)); + } } } - + public void unregisterLeaderboard(String boardIdentifier) { - if (!_leaderboards.containsKey(boardIdentifier)) + LeaderboardDisplay display = _leaderboards.remove(boardIdentifier); + + if (display != null) { - return; + display.unregister(); } - _leaderboards.remove(boardIdentifier).deconstruct(); + } + + @EventHandler + public void playerJoin(PlayerJoinEvent event) + { + _leaderboards.values().forEach(display -> + { + if (display instanceof PlayerActionHook) + { + ((PlayerActionHook) display).onPlayerJoin(event.getPlayer()); + } + }); + } + + @EventHandler + public void playerQuit(PlayerQuitEvent event) + { + _leaderboards.values().forEach(display -> + { + if (display instanceof PlayerActionHook) + { + ((PlayerActionHook) display).onPlayerQuit(event.getPlayer()); + } + }); + } + + public HologramManager getHologramManager() + { + return _hologramManager; } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java index d16d3e3e6..6ba12fbfb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/LeaderboardRepository.java @@ -38,7 +38,7 @@ public class LeaderboardRepository extends RepositoryBase 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 seasonId=(SELECT id FROM statSeasons WHERE now() BETWEEN startDate AND endDate LIMIT 1) ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; - public LeaderboardRepository(JavaPlugin plugin) + public LeaderboardRepository() { super(DBPool.getAccount()); } @@ -227,7 +227,7 @@ public class LeaderboardRepository extends RepositoryBase }); } - public static enum LeaderboardSQLType + public enum LeaderboardSQLType { DAILY(FETCH_STAT_DAILY), WEEKLY(FETCH_STAT_WEEKLY), @@ -239,7 +239,7 @@ public class LeaderboardRepository extends RepositoryBase private String _sql; - private LeaderboardSQLType(String sql) + LeaderboardSQLType(String sql) { _sql = sql; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/PlayerActionHook.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/PlayerActionHook.java new file mode 100644 index 000000000..b2d6b972c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/PlayerActionHook.java @@ -0,0 +1,12 @@ +package mineplex.core.leaderboard; + +import org.bukkit.entity.Player; + +interface PlayerActionHook +{ + + void onPlayerJoin(Player player); + + void onPlayerQuit(Player player); + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/RotatingLeaderboard.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/RotatingLeaderboard.java new file mode 100644 index 000000000..0039e320b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/RotatingLeaderboard.java @@ -0,0 +1,127 @@ +package mineplex.core.leaderboard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.common.Pair; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.hologram.Hologram; +import mineplex.core.recharge.Recharge; + +public class RotatingLeaderboard extends LeaderboardDisplay implements PlayerActionHook +{ + + private final Map _viewingGroup; + private final List>> _leaderboards; + private final Hologram _rotator; + + public RotatingLeaderboard(LeaderboardManager manager, Location rotatorLocation) + { + super(manager); + + _viewingGroup = new HashMap<>(); + _leaderboards = new ArrayList<>(3); + _rotator = new Hologram(manager.getHologramManager(), rotatorLocation, C.cGreenB + "Click to view the", C.cGreenB + "next mode!") + .setInteraction((player, clickType) -> rotateGroup(player)); + } + + public RotatingLeaderboard addMode(String modeName, List leaderboards) + { + _leaderboards.add(Pair.create(modeName, leaderboards)); + return this; + } + + public void rotateGroup(Player player) + { + if (!Recharge.Instance.use(player, "Leaderboard Interact", 500, false, false)) + { + return; + } + + int newIndex = _viewingGroup.get(player) + 1; + + if (newIndex == _leaderboards.size()) + { + newIndex = 0; + } + + setViewingGroup(player, newIndex); + } + + @Override + public void onPlayerJoin(Player player) + { + _viewingGroup.put(player, 0); + _leaderboards.get(0).getRight().forEach(leaderboard -> leaderboard.onPlayerJoin(player)); + } + + @Override + public void onPlayerQuit(Player player) + { + _viewingGroup.remove(player); + _leaderboards.forEach(pair -> pair.getRight().forEach(leaderboard -> leaderboard.onPlayerQuit(player))); + } + + private void setViewingGroup(Player player, int newIndex) + { + Integer oldIndex = _viewingGroup.put(player, newIndex); + Pair> newPair = _leaderboards.get(newIndex); + List newLeaderboards = newPair.getRight(); + + if (oldIndex != null) + { + _leaderboards.get(oldIndex).getRight().forEach(leaderboard -> leaderboard.setViewingTime(player, -1)); + player.playSound(player.getLocation(), Sound.CLICK, 1, 1); + player.sendMessage(F.main(_manager.getName(), "You are now viewing " + F.name(newPair.getLeft()) + ".")); + } + + newLeaderboards.forEach(leaderboard -> leaderboard.setViewingTime(player)); + } + + @Override + public void register() + { + _rotator.start(); + } + + @Override + public void unregister() + { + _rotator.stop(); + _leaderboards.forEach(pair -> pair.getRight().forEach(LeaderboardDisplay::unregister)); + _leaderboards.clear(); + _viewingGroup.clear(); + } + + @Override + public void update() + { + _leaderboards.forEach(pair -> pair.getRight().forEach(leaderboard -> + { + leaderboard.update(); + leaderboard.getLeaderboards().forEach(staticLeaderboard -> + { + String[] newText = staticLeaderboard.getHologram().getText(); + newText[0] += " " + pair.getLeft(); + staticLeaderboard.getHologram().setText(newText); + }); + })); + } + + @Override + public List getDisplayedLeaderboards() + { + List leaderboards = new ArrayList<>(); + + _leaderboards.forEach(pair -> pair.getRight().forEach(leaderboard -> leaderboards.addAll(leaderboard.getDisplayedLeaderboards()))); + + return leaderboards; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StaticLeaderboard.java b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StaticLeaderboard.java new file mode 100644 index 000000000..26ee47cdb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/leaderboard/StaticLeaderboard.java @@ -0,0 +1,71 @@ +package mineplex.core.leaderboard; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.bukkit.Location; + +import mineplex.core.common.util.C; +import mineplex.core.hologram.Hologram; + +public class StaticLeaderboard extends LeaderboardDisplay +{ + + private final String _name; + private final Leaderboard _leaderboard; + private final Hologram _hologram; + + public StaticLeaderboard(LeaderboardManager manager, String name, Leaderboard leaderboard, Location location) + { + super(manager); + + _name = name; + _leaderboard = leaderboard; + _hologram = new Hologram(manager.getHologramManager(), location); + } + + @Override + public void register() + { + } + + @Override + public void unregister() + { + _hologram.stop(); + } + + @Override + public void update() + { + List text = new ArrayList<>(); + + text.add(C.cAquaB + _name); + text.add(C.blankLine); + text.addAll(_leaderboard.getFormattedEntries()); + + _hologram.setText(text.toArray(new String[0])); + + if (!_hologram.isInUse()) + { + _hologram.start(); + } + } + + @Override + public List getDisplayedLeaderboards() + { + return Collections.singletonList(_leaderboard); + } + + public String getName() + { + return _name; + } + + public Hologram getHologram() + { + return _hologram; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java index 174cb6a7a..8b3eaebdd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java @@ -62,7 +62,7 @@ public class StatsManager extends MiniDbClientPlugin _repository = new StatsRepository(); _coreClientManager = clientManager; - _leaderboard = new LeaderboardManager(plugin); + _leaderboard = new LeaderboardManager(this); clientManager.addStoredProcedureLoginProcessor(new ILoginProcessor() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 0ff1e5698..506a65b41 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -183,7 +183,7 @@ public class Clans extends JavaPlugin new CustomTagFix(this, packetHandler); GearManager customGear = new GearManager(this, packetHandler, _clientManager, _donationManager); - HologramManager hologram = new HologramManager(this, packetHandler); + HologramManager hologram = require(HologramManager.class); _clansManager = new ClansManager(this, serverStatusManager.getCurrentServerName(), incognito, packetHandler, punish, _clientManager, _donationManager, preferenceManager, blockRestore, statsManager, teleport, chat, customGear, hologram, inventory); new Recipes(this); new Farming(this); diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java index 4e600a733..f1ecb3602 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/ClansHub.java @@ -121,7 +121,7 @@ public class ClansHub extends JavaPlugin Creature creature = new Creature(this); NpcManager npcManager = new NpcManager(this, creature); InventoryManager inventoryManager = new InventoryManager(this, clientManager); - HologramManager hologramManager = new HologramManager(this, packetHandler); + HologramManager hologramManager = require(HologramManager.class); CastleManager castleManager = new CastleManager(this, clientManager, hologramManager, false); PetManager petManager = new PetManager(this, clientManager, donationManager, inventoryManager, disguiseManager, creature, blockRestore); PollManager pollManager = new PollManager(this, clientManager, donationManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 9ce3ea39d..0932eb9d0 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -119,7 +119,7 @@ public class Hub extends JavaPlugin implements IRelation incognito.setPreferencesManager(preferenceManager); - HologramManager hologramManager = new HologramManager(this, packetHandler); + HologramManager hologramManager = require(HologramManager.class); preferenceManager.GiveItem = true; Creature creature = new Creature(this); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 295e89cac..95268f24d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -190,7 +190,7 @@ public class Arcade extends JavaPlugin BlockRestore blockRestore = require(BlockRestore.class); ProjectileManager projectileManager = new ProjectileManager(this); - HologramManager hologramManager = new HologramManager(this, packetHandler); + HologramManager hologramManager = require(HologramManager.class); //Inventory InventoryManager inventoryManager = new InventoryManager(this, _clientManager); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java index e7104e1fa..ba3368ed6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/CakeWars.java @@ -1,7 +1,10 @@ package nautilus.game.arcade.game.games.cakewars; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -13,10 +16,17 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.inventory.ItemStack; +import mineplex.core.Managers; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.leaderboard.DynamicLeaderboard; +import mineplex.core.leaderboard.Leaderboard; +import mineplex.core.leaderboard.LeaderboardManager; +import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType; +import mineplex.core.leaderboard.RotatingLeaderboard; +import mineplex.core.leaderboard.StaticLeaderboard; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -25,14 +35,14 @@ import nautilus.game.arcade.GameType; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; import nautilus.game.arcade.game.games.AbsorptionFix; +import nautilus.game.arcade.game.games.cakewars.capturepoint.CakePointModule; +import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule; +import nautilus.game.arcade.game.games.cakewars.general.CakeSpawnerModule; +import nautilus.game.arcade.game.games.cakewars.island.CakeIslandModule; import nautilus.game.arcade.game.games.cakewars.kits.KitCakeArcher; import nautilus.game.arcade.game.games.cakewars.kits.KitCakeBuilder; import nautilus.game.arcade.game.games.cakewars.kits.KitCakeWarrior; -import nautilus.game.arcade.game.games.cakewars.island.CakeIslandModule; -import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule; -import nautilus.game.arcade.game.games.cakewars.capturepoint.CakePointModule; import nautilus.game.arcade.game.games.cakewars.shop.CakeShopModule; -import nautilus.game.arcade.game.games.cakewars.general.CakeSpawnerModule; import nautilus.game.arcade.game.games.cakewars.team.CakeTeam; import nautilus.game.arcade.game.games.cakewars.team.CakeTeamModule; import nautilus.game.arcade.game.games.cakewars.trackers.EatAllCakesTracker; @@ -81,6 +91,7 @@ public class CakeWars extends TeamGame "All players standing on the Resource Generator get the items generated." }; private static final int RESPAWN_TIME = 6; + private static final LeaderboardManager LEADERBOARD_MANAGER = Managers.get(LeaderboardManager.class); private final Map _averages; @@ -363,6 +374,116 @@ public class CakeWars extends TeamGame { WorldData.GetAllCustomLocs().computeIfAbsent("POINT Center GOLD", k -> new ArrayList<>()).add(location); } + + if (Manager.IsRewardStats() && Manager.GetLobby() instanceof NewGameLobbyManager) + { + Map> locations = ((NewGameLobbyManager) Manager.GetLobby()).getCustomLocs(); + + if (!locations.containsKey("LEADERBOARDS")) + { + return; + } + + Location rotator = locations.get("ROTATOR").get(0); + Location topStreak = locations.get("TOP_STREAK").get(0); + Location topWins = locations.get("TOP_WINS").get(0); + Location topKills = locations.get("TOP_KILLS").get(0); + + String two = "Cake Wars Duos."; + String four = "Cake Wars 4v4v4v4."; + String bestStreakDuos = two + WinStreakModule.BEST_STREAK_STAT; + String killsDuos = two + "Kills"; + String winsDuos = two + "Wins"; + String bestStreak4 = four + WinStreakModule.BEST_STREAK_STAT; + String kills4 = four + "Kills"; + String wins4 = four + "Wins"; + + LEADERBOARD_MANAGER.registerLeaderboard(GetName(), + new RotatingLeaderboard(LEADERBOARD_MANAGER, rotator) + + .addMode("Duos", Arrays.asList( + + new DynamicLeaderboard(LEADERBOARD_MANAGER, Collections.singletonList( + new StaticLeaderboard(LEADERBOARD_MANAGER, "Best Win Streak", new Leaderboard( + LeaderboardSQLType.ALL, + bestStreakDuos + ), topStreak) + )), + + new DynamicLeaderboard(LEADERBOARD_MANAGER, Arrays.asList( + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Wins", new Leaderboard( + LeaderboardSQLType.ALL, + winsDuos + ), topWins), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Weekly Wins", new Leaderboard( + LeaderboardSQLType.WEEKLY, + winsDuos + ), topWins), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Daily Wins", new Leaderboard( + LeaderboardSQLType.DAILY, + winsDuos + ), topWins) + )), + + new DynamicLeaderboard(LEADERBOARD_MANAGER, Arrays.asList( + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Kills", new Leaderboard( + LeaderboardSQLType.ALL, + killsDuos + ), topKills), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Weekly Kills", new Leaderboard( + LeaderboardSQLType.WEEKLY, + killsDuos + ), topKills), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Daily Kills", new Leaderboard( + LeaderboardSQLType.DAILY, + killsDuos + ), topKills) + )) + + )) + + .addMode("4v4v4v4", Arrays.asList( + + new DynamicLeaderboard(LEADERBOARD_MANAGER, Collections.singletonList( + new StaticLeaderboard(LEADERBOARD_MANAGER, "Best Win Streak", new Leaderboard( + LeaderboardSQLType.ALL, + bestStreak4 + ), topStreak) + )), + + new DynamicLeaderboard(LEADERBOARD_MANAGER, Arrays.asList( + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Wins", new Leaderboard( + LeaderboardSQLType.ALL, + wins4 + ), topWins), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Weekly Wins", new Leaderboard( + LeaderboardSQLType.WEEKLY, + wins4 + ), topWins), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Daily Wins", new Leaderboard( + LeaderboardSQLType.DAILY, + wins4 + ), topWins) + )), + + new DynamicLeaderboard(LEADERBOARD_MANAGER, Arrays.asList( + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Kills", new Leaderboard( + LeaderboardSQLType.ALL, + kills4 + ), topKills), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Weekly Kills", new Leaderboard( + LeaderboardSQLType.WEEKLY, + kills4 + ), topKills), + new StaticLeaderboard(LEADERBOARD_MANAGER, "Top Daily Kills", new Leaderboard( + LeaderboardSQLType.DAILY, + kills4 + ), topKills) + )) + + )) + ); + } } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java index 7e25e504c..43eb10a34 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/cakewars/team/CakeTeamModule.java @@ -49,6 +49,7 @@ import nautilus.game.arcade.game.games.cakewars.event.CakeWarsEatCakeEvent; import nautilus.game.arcade.game.games.cakewars.shop.CakeItem; import nautilus.game.arcade.game.games.cakewars.shop.CakeShopModule; import nautilus.game.arcade.game.games.cakewars.shop.trap.CakeTrapItem; +import nautilus.game.arcade.game.modules.compass.CompassModule; import nautilus.game.arcade.world.WorldData; public class CakeTeamModule extends CakeModule @@ -448,6 +449,9 @@ public class CakeTeamModule extends CakeModule MapUtil.QuickChangeBlockAt(cakeTeam.getCake(), Material.AIR); } }); + + _game.getModule(CompassModule.class) + .setGiveCompassToAlive(true); } return null; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssault.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssault.java index e3d6b403e..709a3f383 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssault.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssault.java @@ -60,7 +60,6 @@ import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; 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; @@ -79,6 +78,7 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.leaderboard.Leaderboard; import mineplex.core.leaderboard.LeaderboardManager; import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType; +import mineplex.core.leaderboard.StaticLeaderboard; import mineplex.core.loot.ChestLoot; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; @@ -115,32 +115,32 @@ public class CastleAssault extends TeamGame private static final int MAX_FLINT_AND_STEEL_USES = 4; private static final int ITEMS_PER_CHEST = 5; private static final long TIME_TILL_REFILL = 2 * 60 * 1000; - + private long _lastRefill; - + private ItemBuilder _flintAndSteel; private ItemBuilder _wearableTnt; - + private Map _streakData = new WeakHashMap<>(); private Map> _crystals = new HashMap<>(); private Map _kings = new HashMap<>(); private List _tntCarry = new ArrayList<>(); - + private List _chests = new ArrayList<>(); - + private ChestLoot _rangedGear = new ChestLoot(true); private ChestLoot _rodsAndGaps = new ChestLoot(true); private ChestLoot _potionGearCommon = new ChestLoot(true); private ChestLoot _potionGearRare = new ChestLoot(true); private ChestLoot _miscGear = new ChestLoot(); - + private ObjectiveTNTSpawner _tntSpawner; private Map _teamKills = new HashMap<>(); - + private boolean _writeScoreboard = true; - + private boolean _killsAreObjective = false; - + @SuppressWarnings("deprecation") public CastleAssault(ArcadeManager manager) { @@ -165,7 +165,7 @@ public class CastleAssault extends TeamGame "TNT Respawns every 1 minute" } ); - + _help = new String[] { "Use the TNT spawning platforms to run TNT to the enemy crystals to destroy them!", @@ -173,7 +173,7 @@ public class CastleAssault extends TeamGame "Go on Kill Streaks to earn Kill Streak Rewards to obtain better armor & weapons!", "Chests refill every 2 minutes with potions, golden applegates, fishing rods, and other useful PvP items!" }; - + this.HungerSet = 20; this.DeathOut = false; this.DeathSpectateSecs = 5; @@ -205,40 +205,67 @@ public class CastleAssault extends TeamGame getModule(GameSummaryModule.class) .replaceComponent(GameSummaryComponentType.GEMS, new GemSummaryComponent(this::GetGems, C.cGold, "Crowns")); - + _flintAndSteel = new ItemBuilder(Material.FLINT_AND_STEEL).setData((short) (Material.FLINT_AND_STEEL.getMaxDurability() - MAX_FLINT_AND_STEEL_USES)); _wearableTnt = new ItemBuilder(Material.TNT).setTitle(C.cRed + "TNT").addLore(C.cRedB + "Right Click with Weapon to " + F.name("Detonate")); generateLoot(); - - if (manager.IsRewardStats()) + + if (manager.IsRewardStats() && manager.GetLobby() instanceof NewGameLobbyManager) { - if (manager.GetLobby() instanceof NewGameLobbyManager) + LeaderboardManager leaderboardManager = Managers.get(LeaderboardManager.class); + Map> lobbyCustomLocs = ((NewGameLobbyManager)manager.GetLobby()).getCustomLocs(); + + if (lobbyCustomLocs.containsKey("TOP_DAILY_WINS")) { - Map> 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.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, 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.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.Kills"}, LeaderboardSQLType.ALL_SEASON, loc, 10)); - } + Location loc = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_DAILY_WINS", new StaticLeaderboard( + leaderboardManager, + "Top Daily Wins", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".Wins" + ), + loc)); + } + if (lobbyCustomLocs.containsKey("TOP_DAILY_KILLS")) + { + Location loc = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_DAILY_KILLS", new StaticLeaderboard( + leaderboardManager, + "Top Daily Kills", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".Kills" + ), + loc)); + } + if (lobbyCustomLocs.containsKey("TOP_WINS")) + { + Location loc = lobbyCustomLocs.get("TOP_WINS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_WINS", new StaticLeaderboard( + leaderboardManager, + "Top Wins", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".Wins" + ), + loc)); + } + if (lobbyCustomLocs.containsKey("TOP_KILLS")) + { + Location loc = lobbyCustomLocs.get("TOP_KILLS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_KILLS", new StaticLeaderboard( + leaderboardManager, + "Top Kills", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".Kills" + ), + loc)); } } } - + private void generateLoot() { { @@ -263,7 +290,7 @@ public class CastleAssault extends TeamGame _miscGear.addLoot(new ItemStack(Material.SNOW_BALL, 16), 3); } } - + private void fillChest(Block block) { if (block.getType() != Material.CHEST && block.getType() != Material.TRAPPED_CHEST) @@ -271,15 +298,15 @@ public class CastleAssault extends TeamGame return; } Chest chest = (Chest) block.getState(); - + chest.getBlockInventory().clear(); int[] slots = UtilMath.random.ints(ITEMS_PER_CHEST, 0, chest.getBlockInventory().getSize()).toArray(); - + for (int slot : slots) { double chance = UtilMath.random.nextDouble(); double subChance = UtilMath.random.nextDouble(); - + ChestLoot loot = _miscGear; if (chance <= 0.6) { @@ -300,7 +327,7 @@ public class CastleAssault extends TeamGame chest.getBlockInventory().setItem(slot, loot.getLoot()); } } - + public ItemStack getNewFlintAndSteel(boolean kitItem) { if (kitItem) @@ -309,7 +336,7 @@ public class CastleAssault extends TeamGame } return _flintAndSteel.build(); } - + public void writeScoreboard() { if (!_writeScoreboard) @@ -369,7 +396,7 @@ public class CastleAssault extends TeamGame } Scoreboard.draw(); } - + public void writeFinalScoreboard(String deadKing, String winKing, String warrior) { _writeScoreboard = false; @@ -379,10 +406,10 @@ public class CastleAssault extends TeamGame Scoreboard.write(C.cWhite + "by " + winKing + "'s " + C.cWhite + "army with the help of"); Scoreboard.write(warrior + C.cWhite + "!"); Scoreboard.writeNewLine(); - + Scoreboard.draw(); } - + @Override public void ParseData() { @@ -420,7 +447,7 @@ public class CastleAssault extends TeamGame this.CreatureAllowOverride = false; _tntSpawner = new ObjectiveTNTSpawner(WorldData.GetDataLocs("BLACK")); } - + @Override public void EndCheck() { @@ -465,7 +492,7 @@ public class CastleAssault extends TeamGame { AddGems(player, 10, "Participation", false, false); } - + int crowns = 0; for (Entry data : GetGems(player).entrySet()) { @@ -474,7 +501,7 @@ public class CastleAssault extends TeamGame crowns += data.getValue().Gems; } } - + { int streak = _streakData.getOrDefault(player, new KillStreakData()).getBestStreak(); if (streak >= 2 && streak < 4) @@ -483,7 +510,7 @@ public class CastleAssault extends TeamGame } else if (streak >= 4 && streak < 6) { - AddGems(player, 1 * crowns, streak + " Player Kill Streak", false, false); + AddGems(player, 1 * crowns, streak + " Player Kill Streak", false, false); } else if (streak >= 6 && streak < 8) { @@ -501,11 +528,11 @@ public class CastleAssault extends TeamGame } } } - + @Override @EventHandler public void ScoreboardUpdate(UpdateEvent event) {}; - + @EventHandler public void onUpdate(UpdateEvent event) { @@ -521,7 +548,7 @@ public class CastleAssault extends TeamGame _chests.forEach(this::fillChest); Bukkit.broadcastMessage(C.cGreenB + "Chests have refilled!"); } - + GameTeam red = GetTeam(ChatColor.RED); GameTeam blue = GetTeam(ChatColor.AQUA); TeamKing redKing = _kings.get(red); @@ -551,7 +578,7 @@ public class CastleAssault extends TeamGame { AddGems(player, 10, "Participation", false, false); } - + int crowns = 0; for (Entry data : GetGems(player).entrySet()) { @@ -560,7 +587,7 @@ public class CastleAssault extends TeamGame crowns += data.getValue().Gems; } } - + { int streak = _streakData.getOrDefault(player, new KillStreakData()).getBestStreak(); if (streak >= 2 && streak < 4) @@ -569,7 +596,7 @@ public class CastleAssault extends TeamGame } else if (streak >= 4 && streak < 6) { - AddGems(player, 1 * crowns, streak + " Player Kill Streak", false, false); + AddGems(player, 1 * crowns, streak + " Player Kill Streak", false, false); } else if (streak >= 6 && streak < 8) { @@ -610,7 +637,7 @@ public class CastleAssault extends TeamGame { AddGems(player, 10, "Participation", false, false); } - + int crowns = 0; for (Entry data : GetGems(player).entrySet()) { @@ -619,7 +646,7 @@ public class CastleAssault extends TeamGame crowns += data.getValue().Gems; } } - + { int streak = _streakData.getOrDefault(player, new KillStreakData()).getBestStreak(); if (streak >= 2 && streak < 4) @@ -628,7 +655,7 @@ public class CastleAssault extends TeamGame } else if (streak >= 4 && streak < 6) { - AddGems(player, 1 * crowns, streak + " Player Kill Streak", false, false); + AddGems(player, 1 * crowns, streak + " Player Kill Streak", false, false); } else if (streak >= 6 && streak < 8) { @@ -644,7 +671,7 @@ public class CastleAssault extends TeamGame SetState(GameState.End); return; } - + _tntSpawner.update(); if (!_killsAreObjective) { @@ -659,7 +686,7 @@ public class CastleAssault extends TeamGame writeScoreboard(); } } - + @EventHandler public void onEditSettings(GameStateChangeEvent event) { @@ -667,7 +694,7 @@ public class CastleAssault extends TeamGame { return; } - + if (event.GetState() == GameState.Live) { _lastRefill = System.currentTimeMillis(); @@ -676,14 +703,14 @@ public class CastleAssault extends TeamGame Manager.GetExplosion().setEnabled(false); Manager.GetCreature().SetDisableCustomDrops(true); } - + if (event.GetState() == GameState.End) { Manager.GetDamage().SetEnabled(true); Manager.GetExplosion().setEnabled(true); Manager.GetCreature().SetDisableCustomDrops(false); } - + if (event.GetState() == GameState.Dead) { Managers.get(LeaderboardManager.class).unregisterLeaderboard("TOP_CASTLEASSAULT_DAILY_WINS"); @@ -692,7 +719,7 @@ public class CastleAssault extends TeamGame Managers.get(LeaderboardManager.class).unregisterLeaderboard("TOP_CASTLEASSAULT_KILLS"); } } - + @EventHandler(priority = EventPriority.HIGHEST) public void handleDeath(CombatDeathEvent event) { @@ -700,22 +727,22 @@ public class CastleAssault extends TeamGame { return; } - + event.SetBroadcastType(DeathMessageType.Detailed); } - + @EventHandler public void disableDamageLevel(CustomDamageEvent event) { event.SetDamageToLevel(false); } - + @EventHandler public void BlockFade(BlockFadeEvent event) { event.setCancelled(true); } - + @EventHandler public void BlockBurn(BlockBurnEvent event) { @@ -727,7 +754,7 @@ public class CastleAssault extends TeamGame { event.setCancelled(true); } - + @EventHandler public void hangingBreak(HangingBreakEvent event) { @@ -736,7 +763,7 @@ public class CastleAssault extends TeamGame event.setCancelled(true); } } - + @EventHandler public void noFlow(BlockFromToEvent event) { @@ -768,7 +795,7 @@ public class CastleAssault extends TeamGame e.setCancelled(true); } } - + @SuppressWarnings("deprecation") @EventHandler(ignoreCancelled=true) public void onPlayerEmptyBucket(PlayerBucketEmptyEvent event) @@ -777,7 +804,7 @@ public class CastleAssault extends TeamGame { return; } - + Player player = event.getPlayer(); if (player.getItemInHand().getType() == Material.WATER_BUCKET) { @@ -806,7 +833,7 @@ public class CastleAssault extends TeamGame player.sendBlockChange(block.getLocation(), block.getType(), block.getData()); } } - + @SuppressWarnings("deprecation") @EventHandler(ignoreCancelled=true) public void onPlayerFillBucket(PlayerBucketFillEvent event) @@ -815,7 +842,7 @@ public class CastleAssault extends TeamGame { return; } - + Player player = event.getPlayer(); Block block = event.getBlockClicked().getRelative(event.getBlockFace()); if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) @@ -855,7 +882,7 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onCombatDeath(CombatDeathEvent event) { @@ -879,7 +906,7 @@ public class CastleAssault extends TeamGame { return; } - + AddStat(player, GetKit(player).GetName() + "KitKills", 1, false, false); if (_killsAreObjective) { @@ -933,12 +960,12 @@ public class CastleAssault extends TeamGame } } } - + if (UtilPlayer.isSpectator(player)) { return; } - + player.setLevel(player.getLevel() + 1); player.getInventory().addItem(new ItemBuilder(Material.GOLDEN_APPLE).setTitle(C.cPurple + "Golden Applegate").build()); KillStreakData data = _streakData.computeIfAbsent(player, (key) -> new KillStreakData()); @@ -953,7 +980,7 @@ public class CastleAssault extends TeamGame Bukkit.broadcastMessage(F.main("Game", C.cGreen + C.Bold + player.getName() + ChatColor.RESET + " is on a " + F.elem(C.cDPurple + data.getKills() + " player Kill Streak") + "!")); } } - + @EventHandler public void TNTExplosion(ExplosionPrimeEvent event) { @@ -963,7 +990,7 @@ public class CastleAssault extends TeamGame } float radius = event.getRadius(); event.setRadius(0f); - + String thrower = UtilEnt.GetMetadata(event.getEntity(), "THROWER"); Player player = UtilPlayer.searchExact(thrower); if (player == null) @@ -978,7 +1005,7 @@ public class CastleAssault extends TeamGame { radius += 3; } - + Map nearby = UtilPlayer.getInRadius(event.getEntity().getLocation(), radius); for (Player near : nearby.keySet()) { @@ -994,9 +1021,9 @@ public class CastleAssault extends TeamGame { continue; } - + double mult = nearby.get(near); - + int highestBlastProt = 0; int blastProtEPF = 0; for (ItemStack item : near.getInventory().getArmorContents()) @@ -1011,20 +1038,20 @@ public class CastleAssault extends TeamGame } } blastProtEPF = Math.min(blastProtEPF, 20); - + double damage = 10 * mult; damage = damage * (1 - (blastProtEPF / 25)); - + double knockbackReduction = 1 - (highestBlastProt * 0.15); - + near.damage(damage, event.getEntity()); UtilAction.velocity(near, UtilAlg.getTrajectory(event.getEntity().getLocation(), near.getLocation()), 1 * mult * knockbackReduction, false, 0, mult * knockbackReduction, 10, true); } - + if (event.getEntity().hasMetadata("OBJECTIVE_TNT")) { List crystals = new ArrayList<>(); - + for (List c : _crystals.values()) { crystals.addAll(c); @@ -1096,19 +1123,19 @@ public class CastleAssault extends TeamGame TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), TNTPrimed.class); tnt.setFuseTicks(60); - + double throwMult = 1; - + if (GetKit(player).GetName().equals("Demolitionist")) { throwMult = ((KitDemolitionist)GetKit(player)).getThrowMultiplier(player); } - + UtilAction.velocity(tnt, player.getLocation().getDirection(), 0.5 * throwMult, false, 0, 0.1, 10, false); - + UtilEnt.SetMetadata(tnt, "THROWER", player.getName()); } - + @EventHandler public void onLaunch(ProjectileHitEvent event) { @@ -1116,7 +1143,7 @@ public class CastleAssault extends TeamGame { return; } - + if (event.getEntity() instanceof EnderPearl && event.getEntity().getShooter() != null && event.getEntity().getShooter() instanceof Entity) { Entity shooter = (Entity) event.getEntity().getShooter(); @@ -1134,7 +1161,7 @@ public class CastleAssault extends TeamGame Manager.runSyncLater(event.getEntity()::remove, 1L); } } - + @EventHandler public void onOpenChest(PlayerInteractEvent event) { @@ -1142,7 +1169,7 @@ public class CastleAssault extends TeamGame { return; } - + if (event.getClickedBlock() != null && event.getClickedBlock().getType() == Material.CHEST) { if (UtilPlayer.isSpectator(event.getPlayer())) @@ -1151,7 +1178,7 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler(ignoreCancelled = true) public void onDamage(EntityDamageEvent event) { @@ -1212,7 +1239,7 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler public void onDrop(PlayerDropItemEvent event) { @@ -1220,17 +1247,17 @@ public class CastleAssault extends TeamGame { return; } - + ItemStack drop = event.getItemDrop().getItemStack(); if (drop.hasItemMeta() && drop.getItemMeta().hasLore() && drop.getItemMeta().getLore().stream().map(ChatColor::stripColor).anyMatch(lore -> lore.equals("Kit Item"))) { event.setCancelled(true); return; } - + event.getItemDrop().remove(); } - + @EventHandler public void craftItem(PrepareItemCraftEvent event) { @@ -1238,13 +1265,13 @@ public class CastleAssault extends TeamGame { return; } - + if (event.getInventory().getResult().getType() == Material.FLINT_AND_STEEL) { event.getInventory().setResult(_flintAndSteel.build()); } } - + @EventHandler public void onInvClick(InventoryClickEvent event) { @@ -1282,7 +1309,7 @@ public class CastleAssault extends TeamGame } } - + @EventHandler public void onPearl(PlayerInteractEvent event) { @@ -1290,12 +1317,12 @@ public class CastleAssault extends TeamGame { return; } - + if (!UtilEvent.isAction(event, ActionType.R)) { return; } - + if (event.getItem() != null && event.getItem().getType() == Material.ENDER_PEARL) { Player player = (Player) event.getPlayer(); @@ -1306,7 +1333,7 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler public void onItemDespawn(ItemDespawnEvent event) { @@ -1314,7 +1341,7 @@ public class CastleAssault extends TeamGame { return; } - + if (_tntSpawner.isSpawned()) { if (_tntSpawner.getItem().getEntityId() == event.getEntity().getEntityId()) @@ -1323,7 +1350,7 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPickup(PlayerPickupItemEvent event) { @@ -1335,7 +1362,7 @@ public class CastleAssault extends TeamGame { return; } - + if (_tntSpawner.isSpawned() && event.getItem().getEntityId() == _tntSpawner.getItem().getEntityId()) { event.setCancelled(true); @@ -1352,24 +1379,24 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler(ignoreCancelled = true) public void TNTUse(PlayerInteractEvent event) { Player player = event.getPlayer(); - + if (!_tntCarry.contains(player)) { return; } - + if (!UtilEvent.isAction(event, ActionType.R)) { return; } - + event.setCancelled(true); - + player.getInventory().setHelmet((ItemStack) player.getMetadata("OLD_HELM").get(0).value()); player.removeMetadata("OLD_HELM", UtilServer.getPlugin()); player.removeMetadata("TNT_START", UtilServer.getPlugin()); @@ -1381,7 +1408,7 @@ public class CastleAssault extends TeamGame tnt.setFuseTicks(0); UtilPlayer.message(player, F.main("Game", "You used " + F.skill("Detonate") + ".")); } - + @EventHandler public void TNTExpire(UpdateEvent event) { @@ -1389,12 +1416,12 @@ public class CastleAssault extends TeamGame { return; } - + if (event.getType() != UpdateType.FASTER) { return; } - + Bukkit.getOnlinePlayers().forEach(player -> { player.getInventory().remove(_wearableTnt.build()); @@ -1405,27 +1432,27 @@ public class CastleAssault extends TeamGame while (tntIterator.hasNext()) { Player player = tntIterator.next(); - + if (player.isDead() || UtilTime.elapsed(player.getMetadata("TNT_START").get(0).asLong(), 60000)) { TNTPrimed tnt = player.getWorld().spawn(player.getEyeLocation(), TNTPrimed.class); UtilEnt.SetMetadata(tnt, "THROWER", player.getName()); UtilEnt.SetMetadata(tnt, "OBJECTIVE_TNT", true); tnt.setFuseTicks(0); - + if (!player.isDead()) { player.getInventory().setHelmet((ItemStack) player.getMetadata("OLD_HELM").get(0).value()); } player.removeMetadata("OLD_HELM", UtilServer.getPlugin()); player.removeMetadata("TNT_START", UtilServer.getPlugin()); - + tntIterator.remove(); continue; } - + List crystals = new ArrayList<>(); - + for (List c : _crystals.values()) { crystals.addAll(c); @@ -1438,18 +1465,18 @@ public class CastleAssault extends TeamGame UtilEnt.SetMetadata(tnt, "THROWER", player.getName()); UtilEnt.SetMetadata(tnt, "OBJECTIVE_TNT", true); tnt.setFuseTicks(0); - + if (!player.isDead()) { player.getInventory().setHelmet((ItemStack) player.getMetadata("OLD_HELM").get(0).value()); } player.removeMetadata("OLD_HELM", UtilServer.getPlugin()); player.removeMetadata("TNT_START", UtilServer.getPlugin()); - + tntIterator.remove(); } } - + UtilTextBottom.display(GetTeam(player).GetColor() + player.getName() + " has the TNT!", UtilServer.getPlayers()); UtilFirework.playFirework(player.getEyeLocation(), Type.BURST, GetTeam(player).GetColorBase(), false, false); if (player.getInventory().getHelmet() == null || player.getInventory().getHelmet().getType() == Material.AIR) @@ -1458,19 +1485,19 @@ public class CastleAssault extends TeamGame } } } - + @EventHandler public void onDeath(PlayerDeathEvent event) { Player player = event.getEntity(); - + _streakData.getOrDefault(player, new KillStreakData()).reset(); - + if (!_tntCarry.contains(player)) { return; } - + player.removeMetadata("OLD_HELM", UtilServer.getPlugin()); player.removeMetadata("TNT_START", UtilServer.getPlugin()); _tntCarry.remove(player); @@ -1480,7 +1507,7 @@ public class CastleAssault extends TeamGame tnt.setFuseTicks(0); UtilPlayer.message(player, F.main("Game", "You used " + F.skill("Detonate") + ".")); } - + @EventHandler public void onBlockPlace(BlockPlaceEvent event) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssaultTDM.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssaultTDM.java index 31baf5b37..26da93b18 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssaultTDM.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/castleassault/CastleAssaultTDM.java @@ -48,7 +48,6 @@ import org.bukkit.material.Dispenser; import org.bukkit.material.MaterialData; 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; @@ -64,6 +63,7 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.leaderboard.Leaderboard; import mineplex.core.leaderboard.LeaderboardManager; import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType; +import mineplex.core.leaderboard.StaticLeaderboard; import mineplex.core.loot.ChestLoot; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; @@ -178,32 +178,59 @@ 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.IsRewardStats() && manager.GetLobby() instanceof NewGameLobbyManager) { - if (manager.GetLobby() instanceof NewGameLobbyManager) + LeaderboardManager leaderboardManager = Managers.get(LeaderboardManager.class); + Map> lobbyCustomLocs = ((NewGameLobbyManager)manager.GetLobby()).getCustomLocs(); + + if (lobbyCustomLocs.containsKey("TOP_DAILY_WINS")) { - Map> 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_CASTLEASSAULTTDM_DAILY_WINS", new Leaderboard("Top Daily Wins", Pair.create("Win", "Wins"), new String[] {"Castle Assault TDM.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_CASTLEASSAULTTDM_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault TDM.Kills"}, LeaderboardSQLType.DAILY, loc, 10)); - } - if (lobbyCustomLocs.containsKey("TOP_WINS")) - { - Location loc = lobbyCustomLocs.get("TOP_WINS").get(0); - Managers.get(LeaderboardManager.class).registerLeaderboard("TOP_CASTLEASSAULTTDM_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_CASTLEASSAULTTDM_KILLS", new Leaderboard("Top Kills", Pair.create("Kill", "Kills"), new String[] {"Castle Assault TDM.Kills"}, LeaderboardSQLType.ALL_SEASON, loc, 10)); - } + Location loc = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_DAILY_WINS", new StaticLeaderboard( + leaderboardManager, + "Top Daily Wins", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".Wins" + ), + loc)); + } + if (lobbyCustomLocs.containsKey("TOP_DAILY_KILLS")) + { + Location loc = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_DAILY_KILLS", new StaticLeaderboard( + leaderboardManager, + "Top Daily Kills", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".Kills" + ), + loc)); + } + if (lobbyCustomLocs.containsKey("TOP_WINS")) + { + Location loc = lobbyCustomLocs.get("TOP_WINS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_WINS", new StaticLeaderboard( + leaderboardManager, + "Top Wins", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".Wins" + ), + loc)); + } + if (lobbyCustomLocs.containsKey("TOP_KILLS")) + { + Location loc = lobbyCustomLocs.get("TOP_KILLS").get(0); + leaderboardManager.registerLeaderboard("TOP_CA_KILLS", new StaticLeaderboard( + leaderboardManager, + "Top Kills", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".Kills" + ), + loc)); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java index 8fca147d0..da1aceadd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java @@ -29,7 +29,6 @@ import mineplex.core.Managers; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; import mineplex.core.antihack.AntiHack; -import mineplex.core.common.Pair; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilServer; @@ -41,6 +40,7 @@ import mineplex.core.imagemap.objects.PlayerMapBoard; import mineplex.core.leaderboard.Leaderboard; import mineplex.core.leaderboard.LeaderboardManager; import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType; +import mineplex.core.leaderboard.StaticLeaderboard; import mineplex.minecraft.game.core.combat.DeathMessageType; import nautilus.game.arcade.ArcadeManager; @@ -252,35 +252,75 @@ public class Moba extends TeamGame if (Manager.IsRewardStats() && Manager.GetLobby() instanceof NewGameLobbyManager) { + LeaderboardManager leaderboardManager = Managers.get(LeaderboardManager.class); Map> lobbyCustomLocs = ((NewGameLobbyManager) Manager.GetLobby()).getCustomLocs(); LeaderboardManager leaderboard = Managers.get(LeaderboardManager.class); - Pair winPair = Pair.create("Win", "Wins"); - Pair killPair = Pair.create("Kill", "Kills"); - Pair goldPair = Pair.create("Gold", "Gold"); { Location location = lobbyCustomLocs.get("TOP_DAILY_WINS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_DAILY_WINS", new Leaderboard("Top Daily Wins", winPair, new String[]{GetName() + ".Wins"}, LeaderboardSQLType.DAILY, location, 10)); + leaderboard.registerLeaderboard("TOP_HOG_DAILY_WINS", new StaticLeaderboard( + leaderboardManager, + "Top Daily Wins", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".Wins" + ), + location)); } { Location location = lobbyCustomLocs.get("TOP_DAILY_KILLS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_DAILY_KILLS", new Leaderboard("Top Daily Kills", killPair, new String[]{GetName() + ".Kills"}, LeaderboardSQLType.DAILY, location, 10)); + leaderboard.registerLeaderboard("TOP_HOG_DAILY_KILLS", new StaticLeaderboard( + leaderboardManager, + "Top Daily Kills", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".Kills" + ), + location)); } { Location location = lobbyCustomLocs.get("TOP_DAILY_GOLD").get(0); - leaderboard.registerLeaderboard("TOP_HOG_DAILY_GOLD", new Leaderboard("Top Daily Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.DAILY, location, 10)); + leaderboard.registerLeaderboard("TOP_HOG_DAILY_GOLD", new StaticLeaderboard( + leaderboardManager, + "Top Daily Gold Earned", + new Leaderboard( + LeaderboardSQLType.DAILY, + GetName() + ".GoldEarned" + ), + location)); } { Location location = lobbyCustomLocs.get("TOP_WINS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_WINS", new Leaderboard("Top Wins", winPair, new String[]{GetName() + ".Wins"}, LeaderboardSQLType.ALL, location, 10)); + leaderboard.registerLeaderboard("TOP_HOG_WINS", new StaticLeaderboard( + leaderboardManager, + "Top Wins", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".Wins" + ), + location)); } { Location location = lobbyCustomLocs.get("TOP_KILLS").get(0); - leaderboard.registerLeaderboard("TOP_HOG_KILLS", new Leaderboard("Top Kills", killPair, new String[]{GetName() + ".Kills"}, LeaderboardSQLType.ALL, location, 10)); + leaderboard.registerLeaderboard("TOP_HOG_KILLS", new StaticLeaderboard( + leaderboardManager, + "Top Kills", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".Kills" + ), + location)); } { Location location = lobbyCustomLocs.get("TOP_GOLD").get(0); - leaderboard.registerLeaderboard("TOP_HOG_GOLD", new Leaderboard("Top Gold Earned", goldPair, new String[]{GetName() + ".GoldEarned"}, LeaderboardSQLType.ALL, location, 10)); + leaderboard.registerLeaderboard("TOP_HOG_GOLD", new StaticLeaderboard( + leaderboardManager, + "Top Gold", + new Leaderboard( + LeaderboardSQLType.ALL, + GetName() + ".GoldEarned" + ), + location)); } _progression.spawnRoleViewers(lobbyCustomLocs); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/winstreak/WinStreakModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/winstreak/WinStreakModule.java index 7e64dfc1d..c6f656e03 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/winstreak/WinStreakModule.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/winstreak/WinStreakModule.java @@ -18,8 +18,8 @@ import nautilus.game.arcade.game.modules.gamesummary.GameSummaryModule; public class WinStreakModule extends Module { - static final String STREAK_STAT = "WinStreak"; - static final String BEST_STREAK_STAT = "BestWinStreak"; + public static final String STREAK_STAT = "WinStreak"; + public static final String BEST_STREAK_STAT = "BestWinStreak"; private static final String SCRAMBLE_TEXT = C.cGold + C.Scramble + "!"; static final String BEST_STREAK_TEXT = SCRAMBLE_TEXT + C.cGreenB + " NEW BEST STREAK " + SCRAMBLE_TEXT; diff --git a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java index 2588beddb..b2f8a7a1c 100644 --- a/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java +++ b/Plugins/mavericks-review-hub/src/mineplex/mavericks/review/Hub.java @@ -120,7 +120,7 @@ public class Hub extends JavaPlugin BlockRestore blockRestore = require(BlockRestore.class); ProjectileManager projectileManager = new ProjectileManager(this); - HologramManager hologramManager = new HologramManager(this, packetHandler); + HologramManager hologramManager = require(HologramManager.class); ServerConfiguration serverConfiguration = new ServerConfiguration(this, _clientManager); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java index b644aa575..4a75d23b4 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/GemHunters.java @@ -241,7 +241,7 @@ public class GemHunters extends JavaPlugin new CustomTagFix(this, packetHandler); // Holograms - HologramManager hologramManager = new HologramManager(this, packetHandler); + HologramManager hologramManager = require(HologramManager.class); // Menus new MenuManager(this); diff --git a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/Leaderboards.java b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/Leaderboards.java index 2c6edf938..a97b9bef7 100644 --- a/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/Leaderboards.java +++ b/Plugins/mineplex-game-gemhunters/src/mineplex/gemhunters/world/Leaderboards.java @@ -1,14 +1,17 @@ package mineplex.gemhunters.world; import mineplex.core.Managers; -import mineplex.core.common.Pair; import mineplex.core.common.util.UtilServer; import mineplex.core.leaderboard.Leaderboard; import mineplex.core.leaderboard.LeaderboardManager; import mineplex.core.leaderboard.LeaderboardRepository.LeaderboardSQLType; +import mineplex.core.leaderboard.StaticLeaderboard; public class Leaderboards { + + private static final String STAT_BASE = "Gem Hunters"; + private final LeaderboardManager _manager; private final WorldDataModule _worldData; @@ -23,9 +26,37 @@ public class Leaderboards private void createLeaderboards() { - _manager.registerLeaderboard("TOP_GEM_HUNTERS_KILLS", new Leaderboard("Top Kills", Pair.create("Kill", "Kills"), new String[] {"Gem Hunters.Kills"}, LeaderboardSQLType.ALL, _worldData.getCustomLocation("TOP_KILLS").get(0), 10)); - _manager.registerLeaderboard("TOP_GEM_HUNTERS_DAILY_KILLS", new Leaderboard("Top Daily Kills", Pair.create("Kill", "Kills"), new String[] {"Gem Hunters.Kills"}, LeaderboardSQLType.DAILY, _worldData.getCustomLocation("TOP_DAILY_KILLS").get(0), 10)); - _manager.registerLeaderboard("TOP_GEM_HUNTERS_GEMS", new Leaderboard("Top Gems Cashed Out", Pair.create("Gem", "Gems"), new String[] {"Gem Hunters.GemsEarned"}, LeaderboardSQLType.ALL, _worldData.getCustomLocation("TOP_GEMS").get(0), 10)); - _manager.registerLeaderboard("TOP_GEM_HUNTERS_DAILY_GEMS", new Leaderboard("Top Daily Gems Cashed Out", Pair.create("Gem", "Gems"), new String[] {"Gem Hunters.GemsEarned"}, LeaderboardSQLType.DAILY, _worldData.getCustomLocation("TOP_DAILY_GEMS").get(0), 10)); + _manager.registerLeaderboard("TOP_GEM_HUNTERS_KILLS", new StaticLeaderboard( + _manager, + "Top Kills", + new Leaderboard( + LeaderboardSQLType.ALL, + STAT_BASE + ".Kills" + ), + _worldData.getCustomLocation("TOP_KILLS").get(0))); + _manager.registerLeaderboard("TOP_GEM_HUNTERS_DAILY_KILLS", new StaticLeaderboard( + _manager, + "Top Daily Kills", + new Leaderboard( + LeaderboardSQLType.DAILY, + STAT_BASE + ".Kills" + ), + _worldData.getCustomLocation("TOP_DAILY_KILLS").get(0))); + _manager.registerLeaderboard("TOP_GEM_HUNTERS_GEMS", new StaticLeaderboard( + _manager, + "Top Gems Cashed Out", + new Leaderboard( + LeaderboardSQLType.ALL, + STAT_BASE + ".GemsEarned" + ), + _worldData.getCustomLocation("TOP_GEMS").get(0))); + _manager.registerLeaderboard("TOP_GEM_HUNTERS_DAILY_GEMS", new StaticLeaderboard( + _manager, + "Top Daily Gems Cashed Out", + new Leaderboard( + LeaderboardSQLType.DAILY, + STAT_BASE + ".GemsEarned" + ), + _worldData.getCustomLocation("TOP_DAILY_GEMS").get(0))); } } \ No newline at end of file