Skip to content

Commit

Permalink
Improved Paper and Velocity Bossbar handling
Browse files Browse the repository at this point in the history
- Improved velocity main command
- Added <servers> velocity placeholder, this will show the amount of servers in the network
- Updated to use the latest build of Paper 1.17.1
No permission messages now use native Components
  • Loading branch information
4drian3d committed Oct 6, 2021
1 parent 9ce93f3 commit 9cbeee7
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

public class PaperBossBar {
private Announcer plugin;
private float value;
public PaperBossBar(Announcer plugin){
this.plugin = plugin;
this.value = 1f;
}

private float value = 1f;
/**
* It will send a bossbar to the specified audience,
* with the specified characteristics showing an
Expand All @@ -32,21 +33,19 @@ public void sendBukkitBossBar (
final BossBar.Color color,
final BossBar.Overlay type) {

float finalTime = 0.1f/time;
final float finalTime = 0.1f/time;

BossBar bar = BossBar.bossBar(
content,
1,
color,
type);

value =1f;
audience.showBossBar(bar);
final float toReduce = finalTime;
new BukkitRunnable() {
@Override
public void run() {
value -= toReduce;
value -= finalTime;
if (value <= 0.02) {
audience.hideBossBar(bar);
cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.dreamerzero.titleannouncer.paper.commands.title.SelfTitleCommand;
import net.dreamerzero.titleannouncer.paper.commands.title.SendTitleCommand;
import net.dreamerzero.titleannouncer.paper.commands.title.WorldTitleCommand;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;

public class RegisterCommands {
private Announcer plugin;
Expand Down Expand Up @@ -65,11 +64,10 @@ private void initCommand(CommandFactory ...factories) {
PluginCommand command = this.plugin.getCommand(factory.getCommand());
command.setExecutor(factory.getExecutor());
// Waiting for https://github.com/PaperMC/Paper/pull/6676
command.setPermissionMessage(
LegacyComponentSerializer.legacySection().serialize(
new ConfigUtils().getPrefix().append(
command.permissionMessage(
new ConfigUtils().getPrefix().append(
new MiniMessageUtil().parse(
config.getString("messages.general.no-permission")))));
config.getString("messages.general.no-permission"))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ public void execute(Invocation invocation) {
String[] args = invocation.arguments();
ConfigUtils config = new ConfigUtils();
MiniMessageUtil mUtils = new MiniMessageUtil();
VelocityHelpMessages vMessages = new VelocityHelpMessages();

if (args.length == 0) {
source.sendMessage(mUtils.parse(
"<gradient:yellow:blue>TitleAnnouncer</gradient> <gray>by</gray> <gradient:green:yellow>4drian3d</gradient>"));
config.helpPrefix(source);
source.sendMessage(vMessages.titleHelpMessage);
source.sendMessage(vMessages.actionbarHelpMessage);
source.sendMessage(vMessages.bossbarHelpMessage);
source.sendMessage(vMessages.fullwikilink);
source.sendMessage(VelocityHelpMessages.titleHelpMessage);
source.sendMessage(VelocityHelpMessages.actionbarHelpMessage);
source.sendMessage(VelocityHelpMessages.bossbarHelpMessage);
source.sendMessage(VelocityHelpMessages.fullwikilink);
return;
}

Expand All @@ -44,29 +43,29 @@ public void execute(Invocation invocation) {
if(args.length == 2){
switch (args[1].toLowerCase()) {
case "title" -> {
source.sendMessage(vMessages.titleHelpMessage);
source.sendMessage(vMessages.titlewikilink);
source.sendMessage(VelocityHelpMessages.titleHelpMessage);
source.sendMessage(VelocityHelpMessages.titlewikilink);
}
case "actionbar" -> {
source.sendMessage(vMessages.actionbarHelpMessage);
source.sendMessage(vMessages.actionbarwikilink);
source.sendMessage(VelocityHelpMessages.actionbarHelpMessage);
source.sendMessage(VelocityHelpMessages.actionbarwikilink);
}
case "bossbar" -> {
source.sendMessage(vMessages.bossbarHelpMessage);
source.sendMessage(vMessages.bossbarwikilink);
source.sendMessage(VelocityHelpMessages.bossbarHelpMessage);
source.sendMessage(VelocityHelpMessages.bossbarwikilink);
}
default -> {
source.sendMessage(vMessages.titleHelpMessage);
source.sendMessage(vMessages.actionbarHelpMessage);
source.sendMessage(vMessages.bossbarHelpMessage);
source.sendMessage(vMessages.fullwikilink);
source.sendMessage(VelocityHelpMessages.titleHelpMessage);
source.sendMessage(VelocityHelpMessages.actionbarHelpMessage);
source.sendMessage(VelocityHelpMessages.bossbarHelpMessage);
source.sendMessage(VelocityHelpMessages.fullwikilink);
}
}
} else {
source.sendMessage(vMessages.titleHelpMessage);
source.sendMessage(vMessages.actionbarHelpMessage);
source.sendMessage(vMessages.bossbarHelpMessage);
source.sendMessage(vMessages.fullwikilink);
source.sendMessage(VelocityHelpMessages.titleHelpMessage);
source.sendMessage(VelocityHelpMessages.actionbarHelpMessage);
source.sendMessage(VelocityHelpMessages.bossbarHelpMessage);
source.sendMessage(VelocityHelpMessages.fullwikilink);
}
}
default -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ public VPlaceholders(ProxyServer proxy){
this.proxy = proxy;
}
public List<Template> replaceProxyPlaceholders(){
return List.of(Template.of("online", String.valueOf(proxy.getPlayerCount())));
return List.of(
Template.of("online", String.valueOf(proxy.getPlayerCount())),
Template.of("servers", String.valueOf(proxy.getAllServers().size())));
}

public List<Template> replaceProxyPlaceholders(Player player){
List<Template> templates = Arrays.asList(
Template.of("online", String.valueOf(proxy.getPlayerCount())),
Template.of("servers", String.valueOf(proxy.getAllServers().size())),
Template.of("name", player.getUsername()),
Template.of("ping", String.valueOf(player.getPing())),
Template.of("client", player.getClientBrand()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.concurrent.TimeUnit;

import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.scheduler.ScheduledTask;

import net.dreamerzero.titleannouncer.velocity.Announcer;
import net.kyori.adventure.audience.Audience;
Expand All @@ -12,47 +13,50 @@
public class VelocityBossbar {
private Announcer plugin;
private ProxyServer proxy;
private float value;
private ScheduledTask taskScheduled;

public VelocityBossbar(Announcer plugin, ProxyServer proxy){
this.plugin = plugin;
this.proxy = proxy;
this.value = 1f;
}

private float value = 1f;
public void sendVelocityBossbar(
final Audience audience,
final float time,
final Component content,
final BossBar.Color color,
final BossBar.Overlay type){

float finalTime = 0.1f/time;
final float finalTime = 0.1f/time;

BossBar bar = BossBar.bossBar(
content,
1,
color,
type);

value = 1f;

audience.showBossBar(bar);
final float toReduce = finalTime;

proxy.getScheduler()
taskScheduled = proxy.getScheduler()
.buildTask(plugin, () -> {
value -= toReduce;
value -= finalTime;
if (value <= 0.02) {
audience.hideBossBar(bar);
return;
cancelTask();
}
try {
bar.progress(value);
} catch (IllegalArgumentException e) {
return;
cancelTask();
}
})
.repeat(200L, TimeUnit.MILLISECONDS)
.schedule();
}

void cancelTask(){
taskScheduled.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import net.dreamerzero.titleannouncer.common.utils.MiniMessageUtil;

public class VelocityHelpMessages {
public final Component titleArguments = text("[Title]; [SubTitle]", AQUA);
public final Component actionbarArguments = text("[ActionBar]", AQUA);
public final Component bossbarArguments = text("[Time] [Color] [Style] [BossBar]", AQUA);
public final Component titleHelpMessage = text()
public static final Component titleArguments = text("[Title]; [SubTitle]", AQUA);
public static final Component actionbarArguments = text("[ActionBar]", AQUA);
public static final Component bossbarArguments = text("[Time] [Color] [Style] [BossBar]", AQUA);
public static final Component titleHelpMessage = text()
.append(text()
.append(text("Title", YELLOW))
)
Expand Down Expand Up @@ -59,7 +59,7 @@ public class VelocityHelpMessages {
)
.build();

public final Component actionbarHelpMessage = text()
public static final Component actionbarHelpMessage = text()
.color(YELLOW)
.append(text()
.append(text("ActionBar"))
Expand Down Expand Up @@ -106,7 +106,7 @@ public class VelocityHelpMessages {
)
.build();

public final Component bossbarHelpMessage = text()
public static final Component bossbarHelpMessage = text()
.color(YELLOW)
.append(text()
.append(text("BossBar"))
Expand Down Expand Up @@ -155,7 +155,7 @@ public class VelocityHelpMessages {
)
.build();

public final Component fullwikilink = text()
public static final Component fullwikilink = text()
.append(text()
.append(Component.text("Visit full guide on"))
.color(GOLD)
Expand All @@ -167,7 +167,7 @@ public class VelocityHelpMessages {
.hoverEvent(HoverEvent.showText(
new MiniMessageUtil().parse("<gradient:red:blue>Click Here</gradient>"))))
.build();
public final Component titlewikilink = text()
public static final Component titlewikilink = text()
.append(text()
.append(Component.text("Visit full guide on"))
.color(GOLD)
Expand All @@ -179,7 +179,7 @@ public class VelocityHelpMessages {
.hoverEvent(HoverEvent.showText(
new MiniMessageUtil().parse("<gradient:red:blue>Click Here</gradient>"))))
.build();
public final Component actionbarwikilink = text()
public static final Component actionbarwikilink = text()
.append(text()
.append(Component.text("Visit full guide on"))
.color(GOLD)
Expand All @@ -192,7 +192,7 @@ public class VelocityHelpMessages {
new MiniMessageUtil().parse("<gradient:red:blue>Click Here</gradient>"))))
.build();

public final Component bossbarwikilink = text()
public static final Component bossbarwikilink = text()
.append(text()
.append(Component.text("Visit full guide on"))
.color(GOLD)
Expand Down

0 comments on commit 9cbeee7

Please sign in to comment.