NewsManager : Reduced dynamic string generation every time news changes

This commit is contained in:
Jonathan Williams 2015-03-25 15:04:00 -07:00
parent 589d4b1aae
commit 09fe3ad6a8

View File

@ -76,8 +76,19 @@ public class NewsManager extends MiniPlugin
String[] newsStrings = new String[maxPosition];
for (Iterator<String> iterator = newsEntries.keySet().iterator(); iterator.hasNext();)
{
String newsPosition = iterator.next();
newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition);
int newsPos = Integer.parseInt(iterator.next());
ChatColor col = ChatColor.RED;
if (newsPos == 1) col = ChatColor.GOLD;
else if (newsPos == 2) col = ChatColor.YELLOW;
else if (newsPos == 3) col = ChatColor.GREEN;
else if (newsPos == 4) col = ChatColor.AQUA;
else if (newsPos == 5) col = ChatColor.LIGHT_PURPLE;
newsStrings[newsPos - 1] = col + C.Bold + "MINEPLEX" + ChatColor.RESET + " - " + newsEntries.get(newsPos + "");
if (newsStrings[newsPos - 1].length() > 64)
newsStrings[newsPos - 1] = newsStrings[newsPos - 1].substring(0, 64);
}
_news = newsStrings;
@ -230,13 +241,6 @@ public class NewsManager extends MiniPlugin
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
@ -250,16 +254,11 @@ public class NewsManager extends MiniPlugin
// Resets newsIndex if outside of bounds of news array after RefreshNews but before UtilTime.elapsed above
_newsIndex = 0;
}
//Text
String text = col + C.Bold + "MINEPLEX" + ChatColor.RESET + " - " + _news[_newsIndex];
if (text.length() > 64)
text = text.substring(0, 64);
double healthPercent = (double)_newsIndex/(double)(_news.length-1);
String text = _news[_newsIndex];
UtilTextTop.display(text, UtilServer.getPlayers());
UtilTextTop.display(text, true, UtilServer.getPlayers());
for (Creature pet : Manager.getPetManager().getPets())
{
if (pet instanceof Wither)
@ -275,7 +274,7 @@ public class NewsManager extends MiniPlugin
((MountDragon)mount).SetName(text);
//((MountDragon)mount).setHealthPercent(healthPercent);
}
}
}
for (Gadget gadget : Manager.GetGadget().getGadgets(GadgetType.Morph))
{