Skip to content

Commit

Permalink
1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jul 28, 2022
1 parent 0485ddb commit 07d8fc6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private static void execute(ServerPlayer player, List<String> commandTree) {

player.closeContainer();

player.getServer().getCommands().performCommand(player.createCommandSourceStack(), builder.toString());
player.getServer().getCommands().performPrefixedCommand(player.createCommandSourceStack(), builder.toString());
} catch (IllegalArgumentException e) {
player.sendSystemMessage(Component.literal(e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,53 @@
import com.google.gson.JsonParseException;
import com.mojang.brigadier.StringReader;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.ChatSender;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.FilteredText;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList;
import org.samo_lego.taterzens.interfaces.ITaterzenEditor;
import org.samo_lego.taterzens.npc.TaterzenNPC;
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 java.util.function.Predicate;

import static org.samo_lego.taterzens.Taterzens.config;
import static org.samo_lego.taterzens.util.TextUtil.successText;
import static org.samo_lego.taterzens.util.TextUtil.translate;

@Mixin(ServerGamePacketListenerImpl.class)
@Mixin(PlayerList.class)
public class ServerGamePacketListenerImplMixin_MsgEditor {
@Shadow public ServerPlayer player;

/**
* Catches messages; if player is in
* message edit mode, messages sent to chat
* will be saved to taterzen instead.
*
* @param message message sent by player
*/
@Inject(
method = "handleChat(Lnet/minecraft/network/protocol/game/ServerboundChatPacket;Lnet/minecraft/server/network/FilteredText;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/protocol/game/ServerboundChatPacket;signedPreview()Z"
),
method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Ljava/util/function/Predicate;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatSender;Lnet/minecraft/network/chat/ChatType$Bound;)V",
at = @At(value = "HEAD"),
cancellable = true
)
private void onMessage(ServerboundChatPacket packet, FilteredText<String> message, CallbackInfo ci) {
ITaterzenEditor editor = (ITaterzenEditor) this.player;
private void taterzens_chatBroadcast(PlayerChatMessage playerChatMessage, Predicate<ServerPlayer> predicate, ServerPlayer player, ChatSender chatSender, ChatType.Bound bound, CallbackInfo ci) {
if (player == null) return;

ITaterzenEditor editor = (ITaterzenEditor) player;
TaterzenNPC taterzen = editor.getNpc();
String msg = message.filtered();
String msg = playerChatMessage.serverContent().getString();

if (taterzen != null && ((ITaterzenEditor) this.player).getEditorMode() == ITaterzenEditor.EditorMode.MESSAGES && msg != null && !msg.startsWith("/")) {
if (taterzen != null && ((ITaterzenEditor) player).getEditorMode() == ITaterzenEditor.EditorMode.MESSAGES && msg != null && !msg.startsWith("/")) {
if (msg.startsWith("delay")) {
String[] split = msg.split(" ");
if (split.length > 1) {
try {
int delay = Integer.parseInt(split[1]);
taterzen.setMessageDelay(editor.getEditingMessageIndex(), delay);
this.player.displayClientMessage(successText("taterzens.command.message.delay", String.valueOf(delay)), false);
player.displayClientMessage(successText("taterzens.command.message.delay", String.valueOf(delay)), false);
} catch (NumberFormatException ignored) {

}
Expand All @@ -76,7 +74,7 @@ private void onMessage(ServerboundChatPacket packet, FilteredText<String> messag

// Exiting the editor
if(config.messages.exitEditorAfterMsgEdit) {
((ITaterzenEditor) this.player).setEditorMode(ITaterzenEditor.EditorMode.NONE);
((ITaterzenEditor) player).setEditorMode(ITaterzenEditor.EditorMode.NONE);
(editor).setEditingMessageIndex(-1);
player.displayClientMessage(translate("taterzens.command.equipment.exit").withStyle(ChatFormatting.LIGHT_PURPLE), false);
}
Expand All @@ -89,4 +87,4 @@ private void onMessage(ServerboundChatPacket packet, FilteredText<String> messag
ci.cancel();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.samo_lego.taterzens.mixin.network;

import com.mojang.authlib.GameProfile;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.network.Connection;
import net.minecraft.network.PacketSendListener;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
Expand All @@ -16,6 +15,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.samo_lego.taterzens.interfaces.ITaterzenEditor;
import org.samo_lego.taterzens.mixin.accessors.ClientboundAddPlayerPacketAccessor;
import org.samo_lego.taterzens.mixin.accessors.ClientboundPlayerInfoPacketAccessor;
Expand Down Expand Up @@ -48,13 +48,18 @@
@Mixin(value = ServerGamePacketListenerImpl.class, priority = 900)
public abstract class ServerGamePacketListenerImplMixin_PacketFaker {

@Shadow public ServerPlayer player;
@Shadow
public ServerPlayer player;

@Final
@Shadow
public Connection connection;

@Shadow public abstract void send(Packet<?> packet);
@Shadow
public abstract void send(Packet<?> packet, @Nullable PacketSendListener packetSendListener);

@Shadow
public abstract void send(Packet<?> packet);

@Unique
private boolean taterzens$skipCheck;
Expand All @@ -65,24 +70,21 @@ public abstract class ServerGamePacketListenerImplMixin_PacketFaker {

/**
* Changes entity type if entity is an instance of {@link TaterzenNPC}.
*
* @param packet packet to change
* @param listener
*/
@Inject(
method = "send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V",
method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V"
target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V"
),
cancellable = true
)
private void changeEntityType(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> listener, CallbackInfo ci) {
private void changeEntityType(Packet<?> packet, PacketSendListener listener, CallbackInfo ci) {
Level world = player.getLevel();
if(packet instanceof ClientboundAddPlayerPacket && !this.taterzens$skipCheck) {
if (packet instanceof ClientboundAddPlayerPacket && !this.taterzens$skipCheck) {
Entity entity = world.getEntity(((ClientboundAddPlayerPacketAccessor) packet).getId());

if(!(entity instanceof TaterzenNPC npc))
if (!(entity instanceof TaterzenNPC npc))
return;

GameProfile profile = npc.getGameProfile();
Expand All @@ -91,13 +93,13 @@ private void changeEntityType(Packet<?> packet, GenericFutureListener<? extends
((ClientboundPlayerInfoPacketAccessor) playerAddPacket).setEntries(
Arrays.asList(new ClientboundPlayerInfoPacket.PlayerUpdate(profile, 0, GameType.SURVIVAL, npc.getTabListName(), null))
);
this.send(playerAddPacket);
this.send(playerAddPacket, listener);

// Before we send this packet, we have
// added player to tablist, otherwise client doesn't
// show it ... :mojank:
this.taterzens$skipCheck = true;
this.send(packet);
this.send(packet, listener);
this.taterzens$skipCheck = false;

// And now we can remove it from tablist
Expand Down Expand Up @@ -143,14 +145,14 @@ private void removeTaterzenFromTablist(CallbackInfo ci) {
taterzens$queueTick++;

List<ClientboundPlayerInfoPacket.PlayerUpdate> toRemove = new ArrayList<>();
for(var iterator = taterzens$tablistQueue.values().iterator(); iterator.hasNext(); ) {
for (var iterator = taterzens$tablistQueue.values().iterator(); iterator.hasNext(); ) {
var current = iterator.next();
if(current.removeAt() > taterzens$queueTick) break;
if (current.removeAt() > taterzens$queueTick) break;

iterator.remove();
toRemove.add(new ClientboundPlayerInfoPacket.PlayerUpdate(current.profile(), 0, GameType.SURVIVAL, current.displayName(), null));
}
if(toRemove.isEmpty()) return;
if (toRemove.isEmpty()) return;

ClientboundPlayerInfoPacket taterzensRemovePacket = new ClientboundPlayerInfoPacket(REMOVE_PLAYER);
//noinspection ConstantConditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public MinecraftCommand() {

@Override
public void execute(TaterzenNPC npc, Player player) {
npc.getServer().getCommands().performCommand(
npc.getServer().getCommands().performPrefixedCommand(
npc.createCommandSourceStack(), command.replaceAll(CLICKER_PLACEHOLDER, player.getGameProfile().getName()));
}

Expand Down
4 changes: 2 additions & 2 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
carpet_core_version=d27767ba98
translations_api=1.4.14+1.19-rc2
carpet_core_version=1.4.83
translations_api=1.4.16+1.19
22 changes: 11 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
# Fabric Properties
minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.7
minecraft_version=1.19.1
yarn_mappings=1.19.1+build.1
loader_version=0.14.8
#Fabric api
fabric_version=0.56.0+1.19
#Quilt Mappings
quilt_mappings=1
fabric_version=0.58.5+1.19.1
#Forge
forge_version=41.0.1
enable_forge=true
forge_version=42.0.0
enable_forge=false
# Mod Properties
mod_version=1.10.5
mod_version=1.11.0
maven_group=org.samo_lego
archives_base_name=taterzens
#Quilt Mappings
quilt_mappings=1
# Dependencies
disguiselib_version=1.3.1
c2b_version=1.1.4
sgui_version=1.1.0+1.19
c2b_version=1.2.1
sgui_version=1.1.3+1.19.1

0 comments on commit 07d8fc6

Please sign in to comment.