-
Notifications
You must be signed in to change notification settings - Fork 69
Developers
####Example providing a custom tabList
Some of the information is outdated. I will probably provide a better API soon.
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. It's also important that getTabList()
must not return null.
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;
}
});
}
}
You need one class for each variable. That class is required to implement either Variable
or PlayerVariable
or ServerVariable
depending on what you want. Once you have created the class you can register the variable by doing BungeeTabListPlus.getInstance().getVariablesManager().addVariable(String name, Variable variable);