2014-08-09 04:16:37 +02:00
|
|
|
package nautilus.game.arcade.managers;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import mineplex.core.achievement.Achievement;
|
2014-08-24 23:08:19 +02:00
|
|
|
import mineplex.core.achievement.AchievementData;
|
2014-08-09 04:16:37 +02:00
|
|
|
import mineplex.core.achievement.AchievementLog;
|
|
|
|
import mineplex.core.common.util.C;
|
2014-08-23 07:04:43 +02:00
|
|
|
import mineplex.core.common.util.Callback;
|
2014-08-09 04:16:37 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2014-08-12 03:23:53 +02:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2014-08-09 04:16:37 +02:00
|
|
|
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, "");
|
|
|
|
|
2014-08-24 23:08:19 +02:00
|
|
|
AchievementData data = Manager.GetAchievement().get(player, type);
|
2014-08-09 04:16:37 +02:00
|
|
|
|
2014-08-12 03:23:53 +02:00
|
|
|
String nameLevel = F.elem(C.cGold + C.Bold + type.getName() + " " + ChatColor.RESET + C.cYellow + data.getLevel() + C.cGold + "/" + C.cYellow + type.getMaxLevel());
|
|
|
|
String progress = F.elem(C.cGreen + "+" + log.get(type).Amount);
|
|
|
|
|
2014-08-23 07:04:43 +02:00
|
|
|
//Completed Achievement
|
|
|
|
if (data.getLevel() == type.getMaxLevel())
|
|
|
|
{
|
|
|
|
//Finishing for the first time
|
|
|
|
if (!Manager.GetTaskManager().hasCompletedTask(player, type.getName()))
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, nameLevel + " " + progress +
|
|
|
|
" " + F.elem(C.cAqua + C.Bold + "COMPLETE!"));
|
|
|
|
|
|
|
|
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f);
|
|
|
|
|
|
|
|
//Set Completed
|
|
|
|
Manager.GetTaskManager().completedTask(player, type.getName());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, nameLevel + " " + progress +
|
|
|
|
" " + F.elem(C.cYellow + C.Bold + "Complete"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Multi-Level Achievements
|
|
|
|
else if (log.get(type).LevelUp)
|
2014-08-09 04:16:37 +02:00
|
|
|
{
|
2014-08-12 03:23:53 +02:00
|
|
|
UtilPlayer.message(player, nameLevel + " " + progress +
|
|
|
|
" " + F.elem(C.cAqua + C.Bold + "LEVEL UP!"));
|
|
|
|
|
|
|
|
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1f, 1f);
|
2014-08-09 04:16:37 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-12 03:23:53 +02:00
|
|
|
UtilPlayer.message(player, nameLevel + " " + progress +
|
2014-08-09 04:16:37 +02:00
|
|
|
" " + F.elem(ChatColor.YELLOW + "" + (data.getExpNextLevel() - data.getExpRemainder()) + " to Next Level"));
|
|
|
|
}
|
|
|
|
|
2014-08-12 03:23:53 +02:00
|
|
|
for (String desc : type.getDesc())
|
|
|
|
{
|
|
|
|
UtilPlayer.message(player, desc);
|
|
|
|
out++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-09 04:16:37 +02:00
|
|
|
out++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (out < 5)
|
|
|
|
{
|
|
|
|
//UtilPlayer.message(player, "");
|
|
|
|
out++;
|
|
|
|
}
|
|
|
|
|
|
|
|
UtilPlayer.message(player, "");
|
|
|
|
UtilPlayer.message(player, ArcadeFormat.Line);
|
|
|
|
}
|
|
|
|
}
|