Refactor all the tab APIs

This commit is contained in:
md_5 2013-06-08 14:06:09 +10:00
parent 9b9addfccd
commit b4220e9229
11 changed files with 67 additions and 52 deletions

View File

@ -3,7 +3,7 @@ package net.md_5.bungee.api.config;
import java.net.InetSocketAddress;
import java.util.Map;
import lombok.Data;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.tab.TabListHandler;
/**
* Class representing the configuration of a server listener. Used for allowing

View File

@ -1,9 +1,9 @@
package net.md_5.bungee.api;
package net.md_5.bungee.api.tab;
/**
* Represents a custom tab list, which may have slots manipulated.
*/
public interface TabAPI
public interface TabAPI extends TabListHandler
{
/**

View File

@ -0,0 +1,40 @@
package net.md_5.bungee.api.tab;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.md_5.bungee.api.tab.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@NoArgsConstructor
public abstract class TabListAdapter implements TabListHandler
{
@Getter
private ProxiedPlayer player;
@Override
public void init(ProxiedPlayer player)
{
this.player = player;
}
@Override
public void onConnect()
{
}
@Override
public void onDisconnect()
{
}
@Override
public void onServerChange()
{
}
@Override
public void onPingChange(int ping)
{
}
}

View File

@ -1,29 +1,30 @@
package net.md_5.bungee.api;
package net.md_5.bungee.api.tab;
import lombok.Data;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@Data
public abstract class TabListHandler
public interface TabListHandler
{
private final ProxiedPlayer player;
/**
* Called so that this class may set member fields to keep track of its
* internal state. You should not do any packet sending or manipulation of
* the passed player, other than storing it.
*
* @param player the player to be associated with this list
*/
void init(ProxiedPlayer player);
/**
* Called when this player first connects to the proxy.
*/
public void onConnect()
{
}
void onConnect();
/**
* Called when a player first connects to the proxy.
*
* @param player the connecting player
*/
public void onServerChange()
{
}
void onServerChange();
/**
* Called when a players ping changes. The new ping will have not updated in
@ -32,18 +33,14 @@ public abstract class TabListHandler
* @param player the player who's ping changed
* @param ping the player's new ping.
*/
public void onPingChange(int ping)
{
}
void onPingChange(int ping);
/**
* Called when a player disconnects.
*
* @param player the disconnected player
*/
public void onDisconnect()
{
}
void onDisconnect();
/**
* Called when a list update packet is sent from server to client.
@ -54,5 +51,5 @@ public abstract class TabListHandler
* @param ping ping of the subject player
* @return whether to send the packet to the client
*/
public abstract boolean onListUpdate(String name, boolean online, int ping);
boolean onListUpdate(String name, boolean online, int ping);
}

View File

@ -41,7 +41,6 @@ import lombok.Synchronized;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.ReconnectHandler;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;

View File

@ -21,13 +21,13 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.config.TexturePackInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PermissionCheckEvent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.scoreboard.Scoreboard;
import net.md_5.bungee.api.tab.TabListHandler;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.HandlerBoss;

View File

@ -18,11 +18,11 @@ import lombok.RequiredArgsConstructor;
import net.md_5.bungee.Util;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.config.TexturePackInfo;
import net.md_5.bungee.api.tab.TabListHandler;
import net.md_5.bungee.tablist.Global;
import net.md_5.bungee.tablist.GlobalPing;
import net.md_5.bungee.tablist.ServerUnique;

View File

@ -1,15 +1,15 @@
package net.md_5.bungee.tablist;
import net.md_5.bungee.api.TabAPI;
import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.HashSet;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.tab.TabAPI;
import net.md_5.bungee.api.tab.TabListAdapter;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
public class Custom extends TabListHandler implements TabAPI
public class Custom extends TabListAdapter implements TabAPI
{
private static final int ROWS = 20;
@ -20,11 +20,6 @@ public class Custom extends TabListHandler implements TabAPI
private String[][] sent = new String[ ROWS ][ COLUMNS ];
private String[][] pending = new String[ ROWS ][ COLUMNS ];
public Custom(ProxiedPlayer player)
{
super( player );
}
@Override
public synchronized void setSlot(int row, int column, String text)
{

View File

@ -2,20 +2,15 @@ package net.md_5.bungee.tablist;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.tab.TabListAdapter;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
public class Global extends TabListHandler
public class Global extends TabListAdapter
{
private boolean sentPing;
public Global(ProxiedPlayer player)
{
super( player );
}
@Override
public void onConnect()
{

View File

@ -11,11 +11,6 @@ public class GlobalPing extends Global
/*========================================================================*/
private int lastPing;
public GlobalPing(ProxiedPlayer player)
{
super( player );
}
@Override
public void onPingChange(int ping)
{

View File

@ -2,20 +2,14 @@ package net.md_5.bungee.tablist;
import java.util.Collection;
import java.util.HashSet;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.tab.TabListAdapter;
import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
public class ServerUnique extends TabListHandler
public class ServerUnique extends TabListAdapter
{
private final Collection<String> usernames = new HashSet<>();
public ServerUnique(ProxiedPlayer player)
{
super( player );
}
@Override
public void onServerChange()
{