-
Notifications
You must be signed in to change notification settings - Fork 69
Developers
####Example providing a custom tabList
You can set a complete custom tabList for a player using BungeeTabListPlus.
For this you need a class which implements ITabListProvider.
TabListManager.setCustomTabList(ProxiedPlayer player, ITabListProvider tablist)
sets a tablist to a player
TabListManager.removeCustomTabList(ProxiedPlayer player)
removes the custom tablist
you can use one ITabListProvider object for multiple players - however you should not cache Objects of the type TabList
or Slot
since the plugin may alter them while updating the tabList for one client.
the getTabList() method of ITabListProvieder is called every time the tablist is resend to the client. BungeeTabListPlus uses a single thread to update tablists to all players this means that in getTabList() you should not do blocking I/O or sleep.
To manually update the tabList to a player do BungeeTabListPlus.getInstance().sendImmediate(ProxiedPlayer player)
.
import codecrafter47.bungeetablistplus.api.ITabListProvider;
import codecrafter47.bungeetablistplus.api.Slot;
import codecrafter47.bungeetablistplus.api.TabList;
import codecrafter47.bungeetablistplus.managers.TabListManager;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
/**
*
* @author florian
*/
public class Example extends Plugin implements Listener {
@Override
public void onEnable() {
getProxy().getPluginManager().registerListener(this, this);
}
@EventHandler
public void onChat(ChatEvent event){
if(!(event.getSender() instanceof ProxiedPlayer))return;
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
// add a tabList to a player
TabListManager.setCustomTabList(player, new ITabListProvider() {
@Override
public TabList getTabList(ProxiedPlayer player) {
TabList tabList = new TabList();
tabList.setFooter("footer text");
tabList.setHeader("header text");
// row and column start with index 0
tabList.setSlot(1/* row */, 1/* column */, new Slot("Hi"));
Slot slot2 = new Slot(player.getName());
slot2.setSkin(player.getName());
tabList.setSlot(1, 2, slot2);
return tabList;
}
});
}
}