Mineplex2018-withcommit/Plugins/Mineplex.Hub/src/mineplex/hub/modules/NewsManager.java

75 lines
2.3 KiB
Java
Raw Normal View History

package mineplex.hub.modules;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilDisplay;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.HubManager;
public class NewsManager extends MiniPlugin
{
public HubManager Manager;
private String[] _news;
private int _newsIndex = 0;
private long _newsTime = System.currentTimeMillis();
private int _mineplexIndex = 0;
public NewsManager(HubManager manager)
{
super("News Manager", manager.GetPlugin());
Manager = manager;
_news = new String[]
{
"New Game: " + C.cGold + C.Bold + "Halloween Horror" + ChatColor.RESET + "! Limited time!",
"New Super Smash Mobs Kit: " + C.cYellow + C.Bold + "Witch" + ChatColor.RESET + "!",
"New Halloween Hub Items! Limited time to unlock!",
"New Hub Mount: " + C.cYellow + C.Bold + "Horse of Horror" + ChatColor.RESET + "!",
"New Hub Gadget: " + C.cYellow + C.Bold + "Pumpkin Kings Head" + ChatColor.RESET + "!",
"New Hub Gadget: " + C.cYellow + C.Bold + "Bat Cannon" + ChatColor.RESET + "!",
};
}
@EventHandler
public void FlightUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
return;
//Mineplex Color
ChatColor col = ChatColor.RED;
if (_mineplexIndex == 1) col = ChatColor.GOLD;
else if (_mineplexIndex == 2) col = ChatColor.YELLOW;
else if (_mineplexIndex == 3) col = ChatColor.GREEN;
else if (_mineplexIndex == 4) col = ChatColor.AQUA;
else if (_mineplexIndex == 5) col = ChatColor.LIGHT_PURPLE;
_mineplexIndex = (_mineplexIndex + 1)%6;
//News Change
if (UtilTime.elapsed(_newsTime, 4500))
{
_newsIndex = (_newsIndex + 1)%_news.length;
_newsTime = System.currentTimeMillis();
}
//Text
String text = col + C.Bold + "MINEPLEX" + ChatColor.RESET + " - " + _news[_newsIndex];
if (text.length() > 64)
text = text.substring(0, 64);
for (Player player : UtilServer.getPlayers())
UtilDisplay.displayTextBar(Manager.GetPlugin(), player, (double)_newsIndex/(double)(_news.length-1), text);
}
}