Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameAchievementManager.java

114 lines
3.1 KiB
Java
Raw Normal View History

2014-08-09 04:16:37 +02:00
package nautilus.game.arcade.managers;
import java.util.HashMap;
import mineplex.core.achievement.Achievement;
import mineplex.core.achievement.AchievementLog;
import mineplex.core.achievement.AchivementData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class GameAchievementManager implements Listener
{
ArcadeManager Manager;
public GameAchievementManager(ArcadeManager manager)
{
Manager = manager;
Manager.GetPluginManager().registerEvents(this, Manager.GetPlugin());
}
//Ensure that past achievement progress is ignored
@EventHandler
public void clearAchievementLog(PlayerJoinEvent event)
{
Manager.GetAchievement().clearLog(event.getPlayer());
}
//@EventHandler(priority = EventPriority.MONITOR)
public void processAchievementLog(final GameStateChangeEvent event)
{
if (Manager.IsTournamentServer())
return;
if (event.GetState() != GameState.Dead)
return;
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(Manager.GetPlugin(), new Runnable()
{
public void run()
{
for (Player player : UtilServer.getPlayers())
{
displayAchievementLog(player, event.GetGame(), Manager.GetAchievement().getLog(player));
}
}
}, 120);
//Delay after Gems
}
public void displayAchievementLog(Player player, Game game, NautHashMap<Achievement, AchievementLog> log)
{
if (log == null)
return;
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1f);
UtilPlayer.message(player, "");
UtilPlayer.message(player, ArcadeFormat.Line);
UtilPlayer.message(player, "§f§lAchievement Progress");
int out = 0;
//Display
for (Achievement type : log.keySet())
{
UtilPlayer.message(player, "");
AchivementData data = Manager.GetAchievement().get(player, type);
if (log.get(type).LevelUp)
{
UtilPlayer.message(player, F.elem(type.getName() + " " + data.getLevel() + "/" + type.getMaxLevel()) +
" " + F.elem(C.cGreen + "+" + log.get(type).Amount) +
" " + F.elem(C.cAqua + "LEVELED UP!"));
}
else
{
UtilPlayer.message(player, F.elem(type.getName() + " " + data.getLevel() + "/" + type.getMaxLevel()) +
" " + F.elem(C.cGreen + "+" + log.get(type).Amount) +
" " + F.elem(ChatColor.YELLOW + "" + (data.getExpNextLevel() - data.getExpRemainder()) + " to Next Level"));
}
out++;
}
while (out < 5)
{
//UtilPlayer.message(player, "");
out++;
}
UtilPlayer.message(player, "");
UtilPlayer.message(player, ArcadeFormat.Line);
}
}