Skip to content

Commit 8279814

Browse files
committed
Add PlayerCodeOfConductSendEvent
Enables customizing the code of conduct per send
1 parent e7445e1 commit 8279814

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package io.papermc.paper.event.player;
2+
3+
import com.google.common.base.Preconditions;
4+
import io.papermc.paper.connection.PlayerCommonConnection;
5+
import io.papermc.paper.connection.PlayerConfigurationConnection;
6+
import org.bukkit.event.Event;
7+
import org.bukkit.event.HandlerList;
8+
import org.jetbrains.annotations.ApiStatus;
9+
import org.jspecify.annotations.NullMarked;
10+
11+
/**
12+
* This event is called when the code of conduct is sent to the player.
13+
*/
14+
@ApiStatus.Experimental
15+
@NullMarked
16+
public class PlayerCodeOfConductSendEvent extends Event {
17+
18+
private static final HandlerList HANDLER_LIST = new HandlerList();
19+
20+
private String codeOfConduct;
21+
private final PlayerCommonConnection connection;
22+
23+
@ApiStatus.Internal
24+
public PlayerCodeOfConductSendEvent( final PlayerConfigurationConnection connection, final String codeOfConduct) {
25+
this.connection = connection;
26+
this.codeOfConduct = codeOfConduct;
27+
}
28+
29+
/**
30+
* Gets the connection that will receive the code of conduct.
31+
*
32+
* @return connection
33+
*/
34+
public PlayerCommonConnection getConnection() {
35+
return connection;
36+
}
37+
38+
/**
39+
* Gets the code of conduct to be sent.
40+
*
41+
* @return the code of conduct
42+
*/
43+
public String getCodeOfConduct() {
44+
return this.codeOfConduct;
45+
}
46+
47+
/**
48+
* Sets the code of conduct to be sent.
49+
*
50+
* @param codeOfConduct the code of conduct
51+
*/
52+
public void setCodeOfConduct(final String codeOfConduct) {
53+
Preconditions.checkArgument(codeOfConduct != null, "Code of Conduct cannot be null");
54+
this.codeOfConduct = codeOfConduct;
55+
}
56+
57+
@Override
58+
public HandlerList getHandlers() {
59+
return HANDLER_LIST;
60+
}
61+
62+
public static HandlerList getHandlerList() {
63+
return HANDLER_LIST;
64+
}
65+
}

paper-server/patches/sources/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@
7171
this.configurationTasks.add(this.prepareSpawnTask);
7272
this.configurationTasks.add(new JoinWorldTask());
7373
this.startNextTask();
74+
@@ -120,6 +_,12 @@
75+
string = codeOfConducts.values().iterator().next();
76+
}
77+
78+
+ // Paper start - Code of Conduct event
79+
+ io.papermc.paper.event.player.PlayerCodeOfConductSendEvent event = new io.papermc.paper.event.player.PlayerCodeOfConductSendEvent(this.paperConnection, string);
80+
+ event.callEvent();
81+
+ string = event.getCodeOfConduct();
82+
+ // Paper end - Code of Conduct event
83+
+
84+
return string;
85+
}));
86+
}
7487
@@ -132,12 +_,14 @@
7588
@Override
7689
public void handleClientInformation(ServerboundClientInformationPacket packet) {

0 commit comments

Comments
 (0)