generated from 4drian3d/VelocityPluginTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
185 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...rc/main/java/io/github/_4drian3d/signedvelocity/fabric/mixins/ChatCommandPacketMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github._4drian3d.signedvelocity.fabric.mixins; | ||
|
||
import io.github._4drian3d.signedvelocity.fabric.model.SignedChatCommandPacket; | ||
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(ServerboundChatCommandPacket.class) | ||
public class ChatCommandPacketMixin implements SignedChatCommandPacket { | ||
@Unique | ||
private boolean signedVelocity$handled = false; | ||
|
||
@Override | ||
public boolean signedVelocity$handled() { | ||
return this.signedVelocity$handled; | ||
} | ||
|
||
@Override | ||
public void signedVelocity$handled(boolean handled) { | ||
this.signedVelocity$handled = handled; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...abric/src/main/java/io/github/_4drian3d/signedvelocity/fabric/mixins/PlayerChatMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github._4drian3d.signedvelocity.fabric.mixins; | ||
|
||
import io.github._4drian3d.signedvelocity.fabric.model.SignedPlayerChatMessage; | ||
import net.minecraft.network.chat.PlayerChatMessage; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(PlayerChatMessage.class) | ||
public class PlayerChatMixin implements SignedPlayerChatMessage { | ||
@Unique | ||
public boolean signedVelocity$handled; | ||
|
||
@Override | ||
public boolean signedVelocity$handled() { | ||
return signedVelocity$handled; | ||
} | ||
|
||
@Override | ||
public void signedVelocity$handled(boolean handled) { | ||
signedVelocity$handled = handled; | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
...ain/java/io/github/_4drian3d/signedvelocity/fabric/mixins/PlayerListCancellableMixin.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...abric/src/main/java/io/github/_4drian3d/signedvelocity/fabric/mixins/PlayerListMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.github._4drian3d.signedvelocity.fabric.mixins; | ||
|
||
import io.github._4drian3d.signedvelocity.common.SignedResult; | ||
import io.github._4drian3d.signedvelocity.fabric.SignedVelocity; | ||
import io.github._4drian3d.signedvelocity.fabric.model.SignedPlayerChatMessage; | ||
import net.minecraft.network.chat.ChatType; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.PlayerChatMessage; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.players.PlayerList; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
@Mixin(value = PlayerList.class, priority = 1) | ||
public abstract class PlayerListMixin { | ||
@Shadow | ||
public abstract void broadcastChatMessage(PlayerChatMessage playerChatMessage, ServerPlayer serverPlayer, ChatType.Bound bound); | ||
|
||
@Inject( | ||
method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V", | ||
at = @At("HEAD"), cancellable = true) | ||
public void signedVelocity$handleChat( | ||
PlayerChatMessage playerChatMessage, | ||
ServerPlayer serverPlayer, | ||
ChatType.Bound bound, | ||
CallbackInfo ci | ||
) { | ||
requireNonNull(serverPlayer); | ||
if (!((SignedPlayerChatMessage)(Object)playerChatMessage).signedVelocity$handled()) { | ||
((SignedPlayerChatMessage)(Object)playerChatMessage).signedVelocity$handled(true); | ||
final SignedResult result = SignedVelocity.CHAT_QUEUE.dataFrom(serverPlayer.getUUID()) | ||
.nextResult().join(); | ||
// Cancelled Result | ||
if (result.cancelled()) { | ||
ci.cancel(); | ||
return; | ||
} | ||
final String modified = result.message(); | ||
// Modified Result | ||
if (modified != null) { | ||
this.broadcastChatMessage(playerChatMessage.withUnsignedContent(Component.literal(modified)), serverPlayer, bound); | ||
} | ||
} | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
...main/java/io/github/_4drian3d/signedvelocity/fabric/mixins/PlayerListModifiableMixin.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
...thub/_4drian3d/signedvelocity/fabric/mixins/ServerGamePacketListenerCancellableMixin.java
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
.../java/io/github/_4drian3d/signedvelocity/fabric/mixins/ServerGamePacketListenerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.github._4drian3d.signedvelocity.fabric.mixins; | ||
|
||
import io.github._4drian3d.signedvelocity.common.SignedResult; | ||
import io.github._4drian3d.signedvelocity.fabric.SignedVelocity; | ||
import io.github._4drian3d.signedvelocity.fabric.model.SignedChatCommandPacket; | ||
import net.minecraft.network.chat.LastSeenMessages; | ||
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(value = ServerGamePacketListenerImpl.class, priority = 1) | ||
public abstract class ServerGamePacketListenerMixin { | ||
@Shadow | ||
public ServerPlayer player; | ||
|
||
@Shadow | ||
protected abstract void performChatCommand(ServerboundChatCommandPacket serverboundChatCommandPacket, LastSeenMessages lastSeenMessages); | ||
|
||
@Inject( | ||
method = "performChatCommand", | ||
at = @At("HEAD"), | ||
cancellable = true) | ||
public void signedVelocity$handleChatCommand( | ||
ServerboundChatCommandPacket packet, | ||
LastSeenMessages lastSeenMessages, | ||
CallbackInfo ci | ||
) { | ||
if (!((SignedChatCommandPacket)(Object) packet).signedVelocity$handled()) { | ||
return; | ||
} | ||
((SignedChatCommandPacket)(Object) packet).signedVelocity$handled(true); | ||
final SignedResult result = SignedVelocity.COMMAND_QUEUE.dataFrom(player.getUUID()) | ||
.nextResult().join(); | ||
if (result.cancelled()) { | ||
ci.cancel(); | ||
return; | ||
} | ||
final String modified = result.toModify(); | ||
if (modified != null) { | ||
// TODO: verify | ||
this.performChatCommand( | ||
new ServerboundChatCommandPacket( | ||
modified, | ||
packet.timeStamp(), | ||
packet.salt(), | ||
packet.argumentSignatures(), | ||
packet.lastSeenMessages() | ||
), | ||
lastSeenMessages | ||
); | ||
} | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
...ithub/_4drian3d/signedvelocity/fabric/mixins/ServerGamePacketListenerModifiableMixin.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...rc/main/java/io/github/_4drian3d/signedvelocity/fabric/model/SignedChatCommandPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github._4drian3d.signedvelocity.fabric.model; | ||
|
||
public interface SignedChatCommandPacket { | ||
boolean signedVelocity$handled(); | ||
|
||
void signedVelocity$handled(boolean handled); | ||
} |
7 changes: 7 additions & 0 deletions
7
...rc/main/java/io/github/_4drian3d/signedvelocity/fabric/model/SignedPlayerChatMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github._4drian3d.signedvelocity.fabric.model; | ||
|
||
public interface SignedPlayerChatMessage { | ||
boolean signedVelocity$handled(); | ||
|
||
void signedVelocity$handled(boolean handled); | ||
} |
Oops, something went wrong.