Fix Party server sending. Tweak playercount and GUI display

This commit is contained in:
TadahTech 2016-07-21 18:01:43 -05:00
parent 2b8930eee8
commit 5d0b5f80c0
6 changed files with 122 additions and 14 deletions

View File

@ -3,9 +3,11 @@ package mineplex.core.party;
import mineplex.core.common.Rank;
import mineplex.core.party.constants.PartyRemoveReason;
import mineplex.core.party.event.PartyMemberKickGUIEvent;
import mineplex.core.party.event.PartySendToServerEvent;
import mineplex.core.party.event.PartyTransferOwnerEvent;
import mineplex.core.party.ui.Menu;
import mineplex.core.portal.ServerTransferEvent;
import mineplex.serverdata.data.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -128,6 +130,7 @@ public class PartyEventListener implements Listener
return;
}
event.setParty(party);
event.setCancel(true);
if (!party.getOwner().equalsIgnoreCase(player.getName()))
@ -136,8 +139,21 @@ public class PartyEventListener implements Listener
return;
}
_plugin.getJoinManager().requestServerJoin(event.getServer(), party);
String server = event.getServer();
if(server.equalsIgnoreCase("Lobby"))
{
return;
}
_plugin.getJoinManager().requestServerJoin(event.getServer(), party);
}
@EventHandler
public void onSend(PartySendToServerEvent event)
{
Party party = event.getParty();
MinecraftServer server = event.getMinecraftServer();
_plugin.getRedisManager().sendPartyInfo(server.getName(), party);
}
@EventHandler

View File

@ -0,0 +1,44 @@
package mineplex.core.party.event;
import mineplex.core.party.Party;
import mineplex.serverdata.data.MinecraftServer;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
*
*/
public class PartySendToServerEvent extends Event
{
private static final HandlerList HANDLER_LIST = new HandlerList();
private final Party _party;
private final MinecraftServer _minecraftServer;
public PartySendToServerEvent(Party party, MinecraftServer minecraftServer)
{
_party = party;
_minecraftServer = minecraftServer;
}
public Party getParty()
{
return _party;
}
@Override
public HandlerList getHandlers()
{
return HANDLER_LIST;
}
public static HandlerList getHandlerList()
{
return HANDLER_LIST;
}
public MinecraftServer getMinecraftServer()
{
return _minecraftServer;
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core.portal;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
@ -8,6 +9,8 @@ import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTabTitle;
import mineplex.core.party.Party;
import mineplex.core.party.event.PartySendToServerEvent;
import mineplex.core.portal.Commands.SendCommand;
import mineplex.core.portal.Commands.ServerCommand;
import mineplex.serverdata.Region;
@ -29,6 +32,8 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
public class Portal extends MiniPlugin
{
@ -46,10 +51,10 @@ public class Portal extends MiniPlugin
public Portal(JavaPlugin plugin, CoreClientManager clientManager, String serverName)
{
super("Portal", plugin);
instance = this;
_clientManager = clientManager;
_region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
_serverName = serverName;
_repository = ServerManager.getServerRepository(_region);
@ -93,13 +98,20 @@ public class Portal extends MiniPlugin
final boolean override = serverName.equalsIgnoreCase("Lobby");
final Rank playerRank = _clientManager.Get(player).GetRank();
if(event.getParty() != null && override)
{
Party party = event.getParty();
sendParty(party);
return;
}
if (override)
{
sendPlayer(player, serverName);
return;
}
if(event.isCancel() && !event.isDraggedByParty())
if(event.isCancel())
{
return;
}
@ -121,6 +133,38 @@ public class Portal extends MiniPlugin
});
}
private void sendParty(Party party)
{
ServerRepository repository = ServerManager.getServerRepository(_region);
MinecraftServer best = null;
List<MinecraftServer> serverList = Lists.newArrayList(repository.getServersByGroup("Lobby"));
int lowest = Integer.MAX_VALUE;
for(MinecraftServer server : serverList)
{
int playercount = server.getPlayerCount();
if(playercount < 20)
{
continue;
}
if(playercount < lowest)
{
lowest = playercount;
if(best == null)
{
best = server;
}
}
}
if(best == null)
{
//Well, fuck.
best = serverList.get(new Random().nextInt(serverList.size()));
}
PartySendToServerEvent serverEvent = new PartySendToServerEvent(party, best);
getPluginManager().callEvent(serverEvent);
}
public static void transferPlayer(String playerName, String serverName)
{
ServerTransfer serverTransfer = new ServerTransfer(playerName, serverName);
@ -192,4 +236,6 @@ public class Portal extends MiniPlugin
UtilPlayer.message(player, F.main(getName(), "You have been sent from " + C.cGold + _serverName + C.cGray + " to " + C.cGold + serverName));
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core.portal;
import mineplex.core.party.Party;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -10,6 +11,7 @@ public class ServerTransferEvent extends Event
private static final HandlerList _handlers = new HandlerList();
private Player _player;
private String _server;
private Party _party;
private boolean _draggedByParty;
private boolean _cancel;
@ -59,4 +61,14 @@ public class ServerTransferEvent extends Event
{
_cancel = cancel;
}
public Party getParty()
{
return _party;
}
public void setParty(Party party)
{
_party = party;
}
}

View File

@ -12,9 +12,6 @@ import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.SnapshotPlugin;
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
import mineplex.core.command.CommandCenter;
import mineplex.core.common.MinecraftVersion;
import mineplex.core.common.Pair;
@ -39,8 +36,6 @@ import mineplex.core.portal.Portal;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.spawn.Spawn;

View File

@ -1,7 +1,6 @@
package mineplex.hub;
import mineplex.core.brawl.fountain.FountainManager;
import com.avaje.ebean.config.ServerConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -74,10 +73,6 @@ import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class Hub extends JavaPlugin implements IRelation
{
private String WEB_CONFIG = "webServer";