Skip to content

Commit

Permalink
Remove vanish on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzy299 committed Oct 22, 2021
1 parent 6a20585 commit da85246
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.quiltservertools.wires.StaffChat;
import net.quiltservertools.wires.command.MuteCommands;
import net.quiltservertools.wires.command.VanishCommand;
import net.quiltservertools.wires.config.Config;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.server.MinecraftServer;
Expand All @@ -20,17 +21,15 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayNetworkHandler.class)
public class MixinServerPlayNetworkHandler {
public abstract class MixinServerPlayNetworkHandler {

private static final Text muted = new LiteralText("Unable to send message: you have been muted. Contact a moderator if you believe this is a mistake.").formatted(Formatting.RED);
private static final Text serverMuted = new LiteralText("Unable to send message: the chat has been server muted. You can still use commands. Contact a moderator if you believe this is a mistake.").formatted(Formatting.YELLOW);

@Shadow
public ServerPlayerEntity player;

@Final
@Shadow
private MinecraftServer server;
@Shadow public abstract ServerPlayerEntity getPlayer();

@Inject(method = "onGameMessage(Lnet/minecraft/network/packet/c2s/play/ChatMessageC2SPacket;)V", at = @At("HEAD"), cancellable = true)
public void interceptChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci) {
Expand All @@ -48,4 +47,9 @@ public void interceptChatMessage(ChatMessageC2SPacket packet, CallbackInfo ci) {
ci.cancel();
}
}

@Inject(method = "onDisconnected", at = @At("HEAD"))
public void removeFromVanish(Text reason, CallbackInfo ci) {
VanishCommand.INSTANCE.removePlayer(this.getPlayer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ object VanishCommand {
}
}

fun removePlayer(player: ServerPlayerEntity) {
if (players.contains(player)) {
addOrRemove(player)
}
}

private const val name = "vanish"
private val EFFECT_INSTANCE = StatusEffectInstance(StatusEffects.INVISIBILITY, Int.MAX_VALUE, 1, false, false, false)

Expand Down

0 comments on commit da85246

Please sign in to comment.