Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlayerJoinEvent and broadcast join messages #46

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/org/sculk/event/player/PlayerJoinEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.sculk.event.player;


import lombok.NonNull;
import org.sculk.player.Player;

/*
* ____ _ _
* / ___| ___ _ _| | | __
* \___ \ / __| | | | | |/ /
* ___) | (__| |_| | | <
* |____/ \___|\__,_|_|_|\_\
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author: SculkTeams
* @link: http://www.sculkmp.org/
*/
public class PlayerJoinEvent extends PlayerEvent {

@NonNull
protected String joinMessage;

public PlayerJoinEvent(Player player, @NonNull String joinMessage) {
super(player);
this.joinMessage = joinMessage;
}

public @NonNull String getJoinMessage() {
return joinMessage;
}

public void setJoinMessage(@NonNull String joinMessage) {
this.joinMessage = joinMessage;
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/sculk/lang/LanguageKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public enum LanguageKeys {
SCULK_PLUGINS_DISABLED("sculk.plugins.disabled"),
SCULK_NETWORK_INTERFACES_STOPPING("sculk.network.interfaces.stopping"),
SCULK_CONSOLE_CLOSING("sculk.console.closing"),
SCULK_THREADS_STOPPING("sculk.threads.stopping");
SCULK_THREADS_STOPPING("sculk.threads.stopping"),

MINECRAFT_PLAYER_JOIN("multiplayer.player.joined");

private final String key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;
import org.cloudburstmc.protocol.bedrock.packet.TextPacket;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.sculk.Server;
import org.sculk.network.session.SculkServerSession;
import org.sculk.utils.TextFormat;

import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import lombok.Getter;
import lombok.Setter;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.protocol.bedrock.BedrockPeer;
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.packet.*;
import org.sculk.Server;
import org.sculk.lang.Translatable;
import org.sculk.network.BedrockInterface;
import org.sculk.network.broadcaster.EntityEventBroadcaster;
import org.sculk.network.broadcaster.PacketBroadcaster;
import org.sculk.player.Player;
import org.sculk.Server;
import org.sculk.network.BedrockInterface;
import org.sculk.network.handler.*;
import org.sculk.player.Player;
import org.sculk.player.client.ClientChainData;
import org.sculk.player.text.RawTextBuilder;
import org.sculk.utils.SkinUtils;
Expand Down Expand Up @@ -134,6 +133,8 @@ private void notifyTerrainReady(Object e) {

private void onClientSpawnResponse(Object e) {
this.setPacketHandler(new InGamePacketHandler(this.getPlayer(),this));
assert this.player != null;
this.player.doFirstSpawn();
}


Expand Down
25 changes: 19 additions & 6 deletions src/main/java/org/sculk/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import lombok.Setter;
import org.cloudburstmc.protocol.bedrock.data.AttributeData;
import org.cloudburstmc.protocol.bedrock.data.DisconnectFailReason;
import org.cloudburstmc.protocol.bedrock.data.command.*;
import org.cloudburstmc.protocol.bedrock.data.command.CommandData;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataMap;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.data.skin.SerializedSkin;
import org.cloudburstmc.protocol.bedrock.packet.*;
import org.cloudburstmc.protocol.common.PacketSignal;
import org.sculk.Server;
import org.sculk.command.Command;
import org.sculk.command.CommandSender;
Expand All @@ -23,20 +22,23 @@
import org.sculk.entity.data.SyncedEntityData;
import org.sculk.event.player.PlayerChangeSkinEvent;
import org.sculk.event.player.PlayerChatEvent;
import org.sculk.event.player.PlayerJoinEvent;
import org.sculk.form.Form;
import org.sculk.lang.Language;
import org.sculk.lang.LanguageKeys;
import org.sculk.lang.Translatable;
import org.sculk.network.handler.PlayerSkinHandler;
import org.sculk.network.session.SculkServerSession;
import org.sculk.player.chat.StandardChatFormatter;
import org.sculk.player.client.ClientChainData;
import org.sculk.player.client.LoginChainData;
import org.sculk.player.skin.Skin;
import org.sculk.player.text.RawTextBuilder;
import org.sculk.utils.SkinUtils;
import org.sculk.utils.TextFormat;

import java.lang.ref.WeakReference;
import java.util.*;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -102,6 +104,17 @@ public void initEntity() {
super.initEntity();
}

public void doFirstSpawn() {
PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(this, this.getLanguage().translate(LanguageKeys.MINECRAFT_PLAYER_JOIN, List.of(this.getName())));
playerJoinEvent.call();
String joinMessage = playerJoinEvent.getJoinMessage();
if (!joinMessage.isEmpty()) {
String defaultJoinMessage = this.getLanguage().translate(LanguageKeys.MINECRAFT_PLAYER_JOIN, List.of(this.getName()));
System.out.println(defaultJoinMessage);
Server.getInstance().broadcastMessage(TextFormat.YELLOW + defaultJoinMessage + TextFormat.RESET);
}
}

/**
* Called when a player changes their skin.
* Plugin developers should not use this, use setSkin() and sendSkin() instead.
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/language/en_GB.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ sculk.console.closing=Closing console
sculk.threads.stopping=Stopping other threads

sculk.command.list=Lists connected players

multiplayer.player.joined={%0} has joined the game
2 changes: 1 addition & 1 deletion src/main/resources/language/fr_FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6061,7 +6061,7 @@ multiplayer.packErrors=Au moins un de vos packs de ressources ou de comportement
multiplayer.packErrors.realms=Au moins un de vos packs de ressources ou de comportement n'a pas pu être chargé. Essayez de télécharger ce monde depuis vos paramètres Realm pour plus d'informations sur l'erreur.
multiplayer.player.inventory.recovered=L'inventaire a été récupéré et placé dans des coffres à proximité.
multiplayer.player.inventory.failed=L'inventaire a été récupéré. Trouvez un lieu sûr et nous placerons un coffre à proximité la prochaine fois que vous rejoindrez ce monde.
multiplayer.player.joined=%s a rejoint la partie
multiplayer.player.joined={%0} a rejoint la partie
multiplayer.player.joined.renamed=%s (anciennement %s) a rejoint la partie
multiplayer.player.joined.realms=%s a rejoint le Realm
multiplayer.player.joined.realms.renamed=%s (anciennement %s) a rejoint le Realm
Expand Down
Loading