Updated MotdManager to update both repositories.

This commit is contained in:
Jonathan Williams 2015-08-23 15:46:23 -07:00
parent 1e7f2f01a7
commit 34a5d9c722

View File

@ -1,5 +1,6 @@
package mineplex.bungee.motd;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -7,9 +8,13 @@ import java.util.Random;
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.BungeeServer;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ServerManager;
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
@ -20,7 +25,9 @@ public class MotdManager implements Listener, Runnable
private Plugin _plugin;
private DataRepository<GlobalMotd> _repository;
private DataRepository<GlobalMotd> _secondRepository;
private Region _region;
private Random _random = new Random();
private String _firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
private List<String> _motdLines;
@ -28,6 +35,7 @@ public class MotdManager implements Listener, Runnable
public MotdManager(Plugin plugin)
{
_plugin = plugin;
_region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 30L, TimeUnit.SECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
@ -38,12 +46,19 @@ public class MotdManager implements Listener, Runnable
if (new File("updateMOTD.dat").exists())
{
List<String> lines = new ArrayList<String>();
lines.add(" §f§l◄ §6§lNEW §f§l▬ §c§lSSM/SG/SW Teams§f§l ▬ §c§lMPS Update §f§l►");
//lines.add(" §d§lRank Sale §a§l40% Off");
//lines.add(" §f§l◄§c§lMAINTENANCE§f§l►");
if (_region == Region.US)
_secondRepository = new RedisDataRepository<GlobalMotd>(new ConnectionData("10.81.1.156", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionType.SLAVE, "ServerStatus"),
Region.ALL, GlobalMotd.class, "globalMotd");
else
_secondRepository = new RedisDataRepository<GlobalMotd>(new ConnectionData("10.33.53.16", 6379, ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionType.SLAVE, "ServerStatus"),
Region.ALL, GlobalMotd.class, "globalMotd");
updateMainMotd(" §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r", lines);
String motdLine = "§f§l◄ §a§lCarl the Creeper§f§l ►";
//String motdLine = " §f§l◄ §a§lCarl the Creeper§f§l ▬ §c§l75% OFF SALE§f§l ►";
//String motdLine = " §d§lRank Sale §a§l40% Off");
//String motdLine = " §f§l◄§c§lMAINTENANCE§f§l►");
updateMainMotd(" §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r", motdLine);
System.out.println("Updated Bungee MOTD");
}
}
@ -68,7 +83,7 @@ public class MotdManager implements Listener, Runnable
GlobalMotd motd = _repository.getElement("MainMotd");
if (motd != null)
{
{
_motdLines = motd.getMotd();
_firstLine = motd.getHeadline();
}
@ -78,9 +93,30 @@ public class MotdManager implements Listener, Runnable
* Update the main {@link GlobalMotd} determining the MOTD for Bungee instances.
* @param motdLines - the lines to update the MOTD to.
*/
public void updateMainMotd(String headline, List<String> motdLines)
public void updateMainMotd(String headline, String motdLine)
{
List<String> motdLines = new ArrayList<String>();
String colorStripped = ChatColor.stripColor(motdLine);
if (colorStripped.trim().length() > 45)
motdLine = motdLine.trim().substring(0, 45);
else
{
String trimmed = colorStripped.trim();
int count = trimmed.length();
int marker = 0;
while ((45 - count) / 2 * 1.55 > marker)
{
motdLine = " " + motdLine;
marker++;
}
}
motdLines.add(motdLine);
_repository.addElement(new GlobalMotd("MainMotd", headline, motdLines));
_secondRepository.addElement(new GlobalMotd("MainMotd", headline, motdLines));
}
public List<String> getMotdLines()