Multi Sidebars
Providers
Now you know how to make a basic sidebar with a single provider, we also support multiple providers to enhance your plugin structure!
Let's say I want the sidebar to have different variants between 4 of the gamemodes, we can do that by creating multiple providers.
- SurvivalSidebarProvider.java
- CreativeSidebarProvider.java
- AdventureSidebarProvider.java
- SpectatorSidebarProvider.java
@InjectableComponent
public class SurvivalSidebarProvider implements SidebarProvider {
@Override
public @Nullable Component getTitle(@NotNull MCPlayer mcPlayer) {
return Component.text("You are playing in Survival mode!", NamedTextColor.GREEN);
}
@Override
public @Nullable List<SidebarLine> getLines(@NotNull MCPlayer mcPlayer) {
return Arrays.asList(
SidebarLine.of(Component.text("SURVIVAL", NamedTextColor.RED))
);
}
@Override
public boolean shouldDisplay(@NotNull MCPlayer mcPlayer) {
return mcPlayer.getGameMode() == GameMode.SURVIVAL;
}
}
@InjectableComponent
public class CreativeSidebarProvider implements SidebarProvider {
@Override
public @Nullable Component getTitle(@NotNull MCPlayer mcPlayer) {
return Component.text("You are playing in Creative mode!", NamedTextColor.AQUA);
}
@Override
public @Nullable List<SidebarLine> getLines(@NotNull MCPlayer mcPlayer) {
return Arrays.asList(
SidebarLine.of(Component.text("CREATIVE", NamedTextColor.RED))
);
}
@Override
public boolean shouldDisplay(@NotNull MCPlayer mcPlayer) {
return mcPlayer.getGameMode() == GameMode.CREATIVE;
}
}
@InjectableComponent
public class AdventureSidebarProvider implements SidebarProvider {
@Override
public @Nullable Component getTitle(@NotNull MCPlayer mcPlayer) {
return Component.text("You are playing in Adventure mode!", NamedTextColor.GOLD);
}
@Override
public @Nullable List<SidebarLine> getLines(@NotNull MCPlayer mcPlayer) {
return Arrays.asList(
SidebarLine.of(Component.text("ADVENTURE", NamedTextColor.RED))
);
}
@Override
public boolean shouldDisplay(@NotNull MCPlayer mcPlayer) {
return mcPlayer.getGameMode() == GameMode.ADVENTURE;
}
}
@InjectableComponent
public class SpectatorSidebarProvider implements SidebarProvider {
@Override
public @Nullable Component getTitle(@NotNull MCPlayer mcPlayer) {
return Component.text("You are playing in Spectator mode!", NamedTextColor.GRAY);
}
@Override
public @Nullable List<SidebarLine> getLines(@NotNull MCPlayer mcPlayer) {
return Arrays.asList(
SidebarLine.of(Component.text("SPECTATOR", NamedTextColor.RED))
);
}
@Override
public boolean shouldDisplay(@NotNull MCPlayer mcPlayer) {
return mcPlayer.getGameMode() == GameMode.SPECTATOR;
}
}
Priority
Every sidebar provider contains a method to set the priority of the sidebar, the higher the priority, the higher the sidebar will be displayed. If one of the sidebar has been displayed, the sidebar with lower priority will be hidden.
@Override
public int getPriority() {
return 0;
}