forked from sorceress/EasyAuth
Fixes #42
This commit is contained in:
parent
9e01af9e9f
commit
dc9b151b64
|
@ -3,11 +3,11 @@ org.gradle.jvmargs=-Xmx1G
|
|||
|
||||
# Fabric properties
|
||||
minecraft_version=1.16.4
|
||||
yarn_mappings=1.16.4+build.1
|
||||
loader_version=0.10.6+build.214
|
||||
yarn_mappings=1.16.4+build.7
|
||||
loader_version=0.10.8
|
||||
|
||||
#Fabric api
|
||||
fabric_version=0.25.1+build.416-1.16
|
||||
fabric_version=0.28.0+1.16
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.7.3
|
||||
|
|
|
@ -117,7 +117,7 @@ public class AuthEventHandler {
|
|||
|
||||
// Setting the session expire time
|
||||
if(config.main.sessionTimeoutTime != -1)
|
||||
playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000;
|
||||
playerCache.validUntil = System.currentTimeMillis() + config.main.sessionTimeoutTime * 1000L;
|
||||
}
|
||||
else if(config.main.spawnOnJoin) {
|
||||
((PlayerAuth) player).hidePosition(false);
|
||||
|
@ -128,14 +128,13 @@ public class AuthEventHandler {
|
|||
}
|
||||
|
||||
// Player chatting
|
||||
public static ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket) {
|
||||
public static ActionResult onPlayerChat(PlayerEntity player, String message) {
|
||||
// Getting the message to then be able to check it
|
||||
String msg = chatMessageC2SPacket.getChatMessage();
|
||||
if(
|
||||
!((PlayerAuth) player).isAuthenticated() &&
|
||||
!msg.startsWith("/login") &&
|
||||
!msg.startsWith("/register") &&
|
||||
(!config.experimental.allowChat || msg.startsWith("/"))
|
||||
!message.startsWith("/login") &&
|
||||
!message.startsWith("/register") &&
|
||||
(!config.experimental.allowChat || message.startsWith("/"))
|
||||
) {
|
||||
player.sendMessage(((PlayerAuth) player).getAuthMessage(), false);
|
||||
return ActionResult.FAIL;
|
||||
|
|
|
@ -7,9 +7,9 @@ import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
|
|||
import net.minecraft.util.ActionResult;
|
||||
|
||||
public interface ChatCallback {
|
||||
Event<ChatCallback> EVENT = EventFactory.createArrayBacked(ChatCallback.class, listeners -> (player, chatMessageC2SPacket) -> {
|
||||
Event<ChatCallback> EVENT = EventFactory.createArrayBacked(ChatCallback.class, listeners -> (player, message) -> {
|
||||
for (ChatCallback event : listeners) {
|
||||
ActionResult result = event.onPlayerChat(player, chatMessageC2SPacket);
|
||||
ActionResult result = event.onPlayerChat(player, message);
|
||||
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
|
@ -18,5 +18,5 @@ public interface ChatCallback {
|
|||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult onPlayerChat(PlayerEntity player, ChatMessageC2SPacket chatMessageC2SPacket);
|
||||
ActionResult onPlayerChat(PlayerEntity player, String message);
|
||||
}
|
|
@ -24,17 +24,16 @@ public abstract class MixinServerPlayNetworkHandler {
|
|||
public ServerPlayerEntity player;
|
||||
|
||||
@Inject(
|
||||
method = "onGameMessage(Lnet/minecraft/network/packet/c2s/play/ChatMessageC2SPacket;)V",
|
||||
method = "method_31286(Ljava/lang/String;)V",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
// Thanks to Liach for helping me out!
|
||||
target = "net/minecraft/network/NetworkThreadUtils.forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/server/world/ServerWorld;)V",
|
||||
target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V",
|
||||
shift = At.Shift.AFTER
|
||||
),
|
||||
cancellable = true
|
||||
)
|
||||
private void onChatMessage(ChatMessageC2SPacket chatMessageC2SPacket, CallbackInfo ci) {
|
||||
ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, chatMessageC2SPacket);
|
||||
private void onPlayerChat(String message, CallbackInfo ci) {
|
||||
ActionResult result = ChatCallback.EVENT.invoker().onPlayerChat(this.player, message);
|
||||
if (result == ActionResult.FAIL) {
|
||||
ci.cancel();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue