Skip to content

Commit

Permalink
Announce joins and quits in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
BomBardyGamer committed Dec 23, 2023
1 parent 7a6b980 commit 0ce3d02
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import dev.emortal.velocity.adapter.resourcepack.ResourcePackProvider;
import dev.emortal.velocity.adapter.scheduler.EmortalScheduler;
import dev.emortal.velocity.adapter.server.ServerProvider;
import net.kyori.adventure.audience.Audience;
import org.jetbrains.annotations.NotNull;

public record AdapterContext(@NotNull EmortalCommandManager commandManager, @NotNull EmortalEventManager eventManager,
@NotNull PlayerProvider playerProvider, @NotNull EmortalScheduler scheduler, @NotNull ServerProvider serverProvider,
@NotNull ResourcePackProvider resourcePackProvider) {
@NotNull PlayerProvider playerProvider, @NotNull EmortalScheduler scheduler,
@NotNull ServerProvider serverProvider, @NotNull ResourcePackProvider resourcePackProvider,
@NotNull Audience audience) {
}
11 changes: 11 additions & 0 deletions src/main/java/dev/emortal/velocity/lang/ChatMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,17 @@ public interface ChatMessages {

Args0 DISCORD_COMMAND = () -> MiniMessage.miniMessage().deserialize("<click:open_url:'https://discord.com/invite/TZyuMSha96'><gradient:#7289da:#51629c:#51629c>Click to join our</gradient> <#7289da><bold>Discord</bold><#51629c>!</click>");

Args1<String> JOIN = username -> Component.text()
.append(Component.text("JOIN", NamedTextColor.GREEN, TextDecoration.BOLD))
.append(Component.text(" | ", NamedTextColor.DARK_GRAY))
.append(Component.text(username, NamedTextColor.WHITE))
.build();
Args1<String> QUIT = username -> Component.text()
.append(Component.text("QUIT", NamedTextColor.RED, TextDecoration.BOLD))
.append(Component.text(" | ", NamedTextColor.DARK_GRAY))
.append(Component.text(username, NamedTextColor.WHITE))
.build();

@FunctionalInterface
interface Args0 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public VelocityModuleEnvironmentProvider(@NotNull ProxyServer proxy, @NotNull Co
new VelocityPlayerProvider(proxy),
new VelocityEmortalScheduler(proxy.getScheduler(), plugin),
new VelocityServerProvider(proxy),
new VelocityResourcePackProvider(proxy)
new VelocityResourcePackProvider(proxy),
proxy
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/emortal/velocity/player/PlayerModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.emortal.velocity.module.VelocityModuleEnvironment;
import dev.emortal.velocity.player.commands.PlaytimeCommand;
import dev.emortal.velocity.player.listener.McPlayerListener;
import dev.emortal.velocity.player.listener.PlayerJoinQuitListener;
import org.jetbrains.annotations.NotNull;

@ModuleData(name = "player")
Expand All @@ -25,6 +26,7 @@ public boolean onLoad() {

if (service != null) {
super.registerCommand(new PlaytimeCommand(service, sessionCache, super.adapters().commandManager().usernameSuggesters()));
super.registerEventListener(new PlayerJoinQuitListener(super.adapters().audience()));
super.registerEventListener(new McPlayerListener(service, sessionCache));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.emortal.velocity.player.listener;

import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.LoginEvent;
import dev.emortal.velocity.lang.ChatMessages;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import org.jetbrains.annotations.NotNull;

public final class PlayerJoinQuitListener {
private static final Key JOIN_QUIT_SOUND = Key.key(Key.MINECRAFT_NAMESPACE, "entity.item.pickup");

private final Audience audience;

public PlayerJoinQuitListener(@NotNull Audience audience) {
this.audience = audience;
}

@Subscribe
public void onJoin(@NotNull LoginEvent event) {
ChatMessages.JOIN.send(this.audience, event.getPlayer().getUsername());
this.audience.playSound(Sound.sound(JOIN_QUIT_SOUND, Sound.Source.MASTER, 1F, 1.2F));
}

@Subscribe
public void onQuit(@NotNull DisconnectEvent event) {
ChatMessages.QUIT.send(this.audience, event.getPlayer().getUsername());
this.audience.playSound(Sound.sound(JOIN_QUIT_SOUND, Sound.Source.MASTER, 1F, 0.5F));
}
}
2 changes: 1 addition & 1 deletion src/test/java/dev/emortal/testing/DummyPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public GameProfile getGameProfile() {
}

@Override
public void clearHeaderAndFooter() {
public void clearPlayerListHeaderAndFooter() {
}

@Override
Expand Down

0 comments on commit 0ce3d02

Please sign in to comment.