Added RankUpdate command.

Fixed Lobby joinable issue with server monitor.
Changed server monitor to be fully dynamic for us.
This commit is contained in:
Jonathan Williams 2014-07-01 10:23:22 -07:00
parent 8e8e66f8c1
commit 9fd3f14248
14 changed files with 196 additions and 131 deletions

View File

@ -1,16 +0,0 @@
package mineplex.core;
import org.bukkit.Server;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public interface INautilusPlugin
{
JavaPlugin GetPlugin();
String GetWebServerAddress();
Server GetRealServer();
PluginManager GetPluginManager();
}

View File

@ -5,6 +5,8 @@ import java.util.Iterator;
import java.util.Map.Entry;
import java.util.UUID;
import mineplex.core.MiniPlugin;
import mineplex.core.account.command.UpdateRank;
import mineplex.core.account.event.AsyncClientLoadEvent;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.ClientWebResponseEvent;
@ -24,7 +26,6 @@ import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
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.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result;
import org.bukkit.event.player.PlayerKickEvent;
@ -32,10 +33,8 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class CoreClientManager implements Listener
public class CoreClientManager extends MiniPlugin
{
private static CoreClientManager _instance;
private JavaPlugin _plugin;
private AccountRepository _repository;
private NautHashMap<String, CoreClient> _clientList;
@ -43,26 +42,25 @@ public class CoreClientManager implements Listener
private Object _clientLock = new Object();
protected CoreClientManager(JavaPlugin plugin, String webServer)
public CoreClientManager(JavaPlugin plugin, String webServer)
{
_instance = this;
super("Client Manager", plugin);
_plugin = plugin;
_repository = new AccountRepository(webServer);
_clientList = new NautHashMap<String, CoreClient>();
_duplicateLoginGlitchPreventionList = new HashSet<String>();
_plugin.getServer().getPluginManager().registerEvents(this, _plugin);
}
public static CoreClientManager Initialize(JavaPlugin plugin, String webServer)
public AccountRepository getRepository()
{
if (_instance == null)
{
_instance = new CoreClientManager(plugin, webServer);
}
return _instance;
return _repository;
}
@Override
public void AddCommands()
{
AddCommand(new UpdateRank(this));
}
public CoreClient Add(String name)

View File

@ -0,0 +1,104 @@
package mineplex.core.account.command;
import java.util.Iterator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
public class UpdateRank extends CommandBase<CoreClientManager>
{
public UpdateRank(CoreClientManager plugin)
{
super(plugin, Rank.ADMIN, "updateRank");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args == null)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), "/" + AliasUsed + " joeschmo MODERATOR"));
}
else
{
if (args.length == 0)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), "Player argument missing."));
return;
}
final String playerName = args[0];
Rank tempRank = null;
try
{
tempRank = Rank.valueOf(args[1]);
}
catch (Exception ex)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), ChatColor.RED + "" + ChatColor.BOLD + "Invalid rank!"));
return;
}
final Rank rank = tempRank;
if (rank == Rank.MODERATOR || rank == Rank.HELPER || rank == Rank.ALL || rank == Rank.MAPDEV)
{
Plugin.getRepository().MatchPlayerName(new Callback<List<String>>()
{
public void run(List<String> matches)
{
boolean matchedExact = false;
for (String match : matches)
{
if (match.equalsIgnoreCase(playerName))
{
matchedExact = true;
}
}
if (matchedExact)
{
for (Iterator<String> matchIterator = matches.iterator(); matchIterator.hasNext();)
{
if (!matchIterator.next().equalsIgnoreCase(playerName))
{
matchIterator.remove();
}
}
}
UtilPlayer.searchOffline(matches, new Callback<String>()
{
public void run(final String target)
{
if (target == null)
{
return;
}
Plugin.getRepository().SaveRank(new Callback<Rank>()
{
public void run(Rank rank)
{
caller.sendMessage(F.main(Plugin.GetName(), target + "'s rank has been updated to " + rank.Name + "!"));
}
}, target, rank, true);
}
}, caller, playerName, true);
}
}, playerName);
}
}
}
}

View File

@ -1,7 +1,10 @@
package mineplex.core.account.repository;
import java.util.List;
import java.util.UUID;
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
import mineplex.core.account.repository.token.LoginToken;
import mineplex.core.account.repository.token.RankUpdateToken;
import mineplex.core.common.Rank;
@ -37,4 +40,18 @@ public class AccountRepository
new AsyncJsonWebCall(_webAddress + "PlayerAccount/RankUpdate").Execute(Rank.class, callback, token);
}
public void MatchPlayerName(final Callback<List<String>> callback, final String userName)
{
Thread asyncThread = new Thread(new Runnable()
{
public void run()
{
List<String> tokenList = new JsonWebCall(_webAddress + "PlayerAccount/GetMatches").Execute(new TypeToken<List<String>>(){}.getType(), userName);
callback.run(tokenList);
}
});
asyncThread.start();
}
}

View File

@ -18,10 +18,10 @@ public class CommandCenter implements Listener
protected CoreClientManager ClientManager;
protected NautHashMap<String, ICommand> Commands;
public static void Initialize(JavaPlugin plugin, CoreClientManager clientManager)
public static void Initialize(JavaPlugin plugin)
{
if (Instance == null)
Instance = new CommandCenter(plugin, clientManager);
Instance = new CommandCenter(plugin);
}
public CoreClientManager GetClientManager()
@ -29,14 +29,18 @@ public class CommandCenter implements Listener
return ClientManager;
}
private CommandCenter(JavaPlugin instance, CoreClientManager manager)
private CommandCenter(JavaPlugin instance)
{
Plugin = instance;
ClientManager = manager;
Commands = new NautHashMap<String, ICommand>();
Plugin.getServer().getPluginManager().registerEvents(this, Plugin);
}
public void setClientManager(CoreClientManager clientManager)
{
ClientManager = clientManager;
}
@EventHandler
public void OnPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
{

View File

@ -39,7 +39,7 @@ public class Portal extends MiniPlugin implements PluginMessageListener
private CoreClientManager _clientier;
private String serverName = "";
public Portal(JavaPlugin plugin)
public Portal(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Portal", plugin);
@ -47,7 +47,7 @@ public class Portal extends MiniPlugin implements PluginMessageListener
Bukkit.getMessenger().registerIncomingPluginChannel(GetPlugin(), "BungeeCord", this);
_repository.initialize(plugin.getConfig().getBoolean("serverstatus.us"));
_clientier = CoreClientManager.Initialize(plugin, plugin.getConfig().getString("webServer"));
_clientier = clientManager;
}
public void SendAllPlayers(String serverName)
@ -196,6 +196,7 @@ public class Portal extends MiniPlugin implements PluginMessageListener
@EventHandler
public void onPreCommand(PlayerCommandPreprocessEvent e)
{
/*
String[] baseArgs = e.getMessage().split(" ");
String command = baseArgs[0];
String[] args = new String[baseArgs.length - 1];
@ -289,6 +290,7 @@ public class Portal extends MiniPlugin implements PluginMessageListener
return;
}
}
*/
}
@Override

View File

@ -19,11 +19,13 @@ public class EnjinTranslator extends JavaPlugin
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
saveConfig();
//Core Modules
CoreClientManager clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
//Static Modules
CommandCenter.Initialize(this, clientManager);
CommandCenter.Initialize(this);
//Core Modules
CoreClientManager clientManager = new CoreClientManager(this, GetWebServerAddress());
CommandCenter.Instance.setClientManager(clientManager);
DonationManager donationManager = new DonationManager(this, GetWebServerAddress());
//Other Modules
Punish punish = new Punish(this, GetWebServerAddress(), clientManager);

View File

@ -11,6 +11,7 @@
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${BUILD_FILES}\common.xml"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,clean"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>

View File

@ -1,6 +1,5 @@
package mineplex.hub;
import mineplex.core.INautilusPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
@ -48,12 +47,10 @@ import mineplex.minecraft.game.core.condition.ConditionManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
public class Hub extends JavaPlugin implements IRelation
{
private String WEB_CONFIG = "webServer";
@ -61,24 +58,25 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
public void onEnable()
{
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
saveConfig();
String webServerAddress = getConfig().getString(WEB_CONFIG);
Logger.initialize(this);
//Core Modules
CoreClientManager clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
//Static Modules
CommandCenter.Initialize(this, clientManager);
CommandCenter.Initialize(this);
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(clientManager);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
Punish punish = new Punish(this, GetWebServerAddress(), clientManager);
Portal portal = new Portal(this);
Punish punish = new Punish(this, webServerAddress, clientManager);
Portal portal = new Portal(this, clientManager);
AntiHack.Initialize(this, punish, portal);
DonationManager donationManager = new DonationManager(this, GetWebServerAddress());
DonationManager donationManager = new DonationManager(this, webServerAddress);
//Other Modules
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
@ -86,13 +84,13 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
new MessageManager(this, clientManager, preferenceManager);
Creature creature = new Creature(this);
NpcManager npcManager = new NpcManager(this, creature);
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, GetWebServerAddress());
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress);
new AntiStack(this);
//Main Modules
PacketHandler packetHandler = new PacketHandler(this);
PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager);
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), new DisguiseManager(this, packetHandler), new TaskManager(this, GetWebServerAddress()), portal, partyManager, preferenceManager, petManager);
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), new DisguiseManager(this, packetHandler), new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
@ -112,9 +110,9 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
Teleport teleport = new Teleport(this, clientManager, new Spawn(this));
Energy energy = new Energy(this);
ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager, GetWebServerAddress());
SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, blockRestore, fire, new Movement(this), teleport, energy, GetWebServerAddress());
ClassManager classManager = new ClassManager(this, clientManager, donationManager, skillManager, itemFactory, GetWebServerAddress());
ItemFactory itemFactory = new ItemFactory(this, blockRestore, conditionManager, damage, energy, fire, throwManager, webServerAddress);
SkillFactory skillManager = new SkillFactory(this, damage, this, combatManager, conditionManager, throwManager, blockRestore, fire, new Movement(this), teleport, energy, webServerAddress);
ClassManager classManager = new ClassManager(this, clientManager, donationManager, skillManager, itemFactory, webServerAddress);
ClassShopManager shopManager = new ClassShopManager(this, classManager, skillManager, itemFactory);
@ -133,32 +131,6 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
{
}
@Override
public JavaPlugin GetPlugin()
{
return this;
}
@Override
public String GetWebServerAddress()
{
String webServerAddress = getConfig().getString(WEB_CONFIG);
return webServerAddress;
}
@Override
public Server GetRealServer()
{
return getServer();
}
@Override
public PluginManager GetPluginManager()
{
return GetRealServer().getPluginManager();
}
@Override
public boolean CanHurt(Player a, Player b)

View File

@ -44,7 +44,7 @@ public class GroupStatusData
// Lobby joinable checking
if (existingServer.Motd.isEmpty() || existingServer.Motd.equals(""))
{
if (existingServer.Players / existingServer.MaxPlayers < 10)
if (serverStatusData.MaxPlayers - serverStatusData.Players > 15)
_joinableCount--;
}
else
@ -66,8 +66,10 @@ public class GroupStatusData
// Lobby joinable checking
if (serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals(""))
{
if (serverStatusData.Players / serverStatusData.MaxPlayers < 10)
if (serverStatusData.MaxPlayers - serverStatusData.Players > 15)
{
_joinableCount++;
}
}
else
{

View File

@ -15,6 +15,7 @@ import java.util.Map.Entry;
public class ServerMonitor
{
private static boolean _us = true;
private static Repository _repository = new Repository();
private static int _count = 0;
private static HashSet<ProcessRunner> _processes = new HashSet<ProcessRunner>();
@ -22,9 +23,9 @@ public class ServerMonitor
public static void main (String args[])
{
boolean us = !new File("eu.dat").exists();
_us = !new File("eu.dat").exists();
_repository.initialize(us);
_repository.initialize(_us);
HashMap<String, Entry<String, Long>> serverTracker = new HashMap<String, Entry<String, Long>>();
while (true)
@ -34,6 +35,7 @@ public class ServerMonitor
for (ServerStatusData statusData : _repository.retrieveOldServerStatuses())
{
/*
if (us)
{
if (!serverTracker.containsKey(statusData.Name))
@ -48,9 +50,12 @@ public class ServerMonitor
}
}
else
killServer(statusData);
*/
killServer(statusData);
}
/*
if (us)
{
// Remove successfully restarted US servers
@ -65,6 +70,7 @@ public class ServerMonitor
}
else
{
*/
List<DynamicServerData> dynamicServers = new ArrayList<DynamicServerData>(_repository.retrieveDynamicServers());
if (_count % 15 == 0)
@ -165,7 +171,7 @@ public class ServerMonitor
serversToKill--;
}
}
}
//}
int processWaits = 0;

View File

@ -8,7 +8,6 @@ import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import mineplex.core.INautilusPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
@ -39,12 +38,10 @@ import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import nautilus.game.arcade.game.GameServerConfig;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class Arcade extends JavaPlugin implements INautilusPlugin
public class Arcade extends JavaPlugin
{
private String WEB_CONFIG = "webServer";
@ -64,28 +61,31 @@ public class Arcade extends JavaPlugin implements INautilusPlugin
//Configs
getConfig().addDefault(WEB_CONFIG, "http://accounts.mineplex.com/");
getConfig().set(WEB_CONFIG, getConfig().getString(WEB_CONFIG));
saveConfig();
saveConfig();
String webServerAddress = getConfig().getString(WEB_CONFIG);
Logger.initialize(this);
_clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
CommandCenter.Initialize(this, _clientManager);
//Static Modules
CommandCenter.Initialize(this);
CoreClientManager clientManager = new CoreClientManager(this, webServerAddress);
CommandCenter.Instance.setClientManager(clientManager);
ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this);
_donationManager = new DonationManager(this, GetWebServerAddress());
_donationManager = new DonationManager(this, webServerAddress);
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
new MessageManager(this, _clientManager, preferenceManager);
AntiStack antistack = new AntiStack(this);
Portal portal = new Portal(this, clientManager);
Creature creature = new Creature(this);
Spawn spawn = new Spawn(this);
Teleport teleport = new Teleport(this, _clientManager, spawn);
new FileUpdater(this, new Portal(this));
new FileUpdater(this, portal);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, _clientManager));
PacketHandler packetHandler = new PacketHandler(this);
@ -93,12 +93,11 @@ public class Arcade extends JavaPlugin implements INautilusPlugin
_damageManager = new DamageManager(this, new CombatManager(this), new NpcManager(this, creature), disguiseManager);
Portal portal = new Portal(this);
Punish punish = new Punish(this, GetWebServerAddress(), _clientManager);
Punish punish = new Punish(this, webServerAddress, _clientManager);
AntiHack.Initialize(this, punish, portal);
//Arcade Manager
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, packetHandler, preferenceManager, GetWebServerAddress());
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, packetHandler, preferenceManager, webServerAddress);
new MemoryFix(this);
@ -250,30 +249,4 @@ public class Arcade extends JavaPlugin implements INautilusPlugin
System.out.println("Deleted Old Game: " + file.getName());
}
}
@Override
public JavaPlugin GetPlugin()
{
return this;
}
@Override
public String GetWebServerAddress()
{
String webServerAddress = getConfig().getString(WEB_CONFIG);
return webServerAddress;
}
@Override
public Server GetRealServer()
{
return getServer();
}
@Override
public PluginManager GetPluginManager()
{
return GetRealServer().getPluginManager();
}
}

View File

@ -511,7 +511,7 @@
repository.CommitChanges();
return rank.ToString();
return rank.Name;
}
}

Binary file not shown.