Skip to content

Commit

Permalink
Merge branch '1.20.3' into 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
DrexHD committed Jan 17, 2024
2 parents 5c1c56e + 46675e8 commit 48a4ff0
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.5.1] - 2024-01-17
### Added
- `vanish_on_join` meta key
- Hide vanished players from maps

### Changed
- Improved vanish lookup performance

## [1.5.0] - 2023-12-01
### Added
- Config option to toggle fake join/disconnect messages
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ You need to be an operator or have these permissions to be able to use the mod
- `vanish.command.vanish.other` - Set the vanish-status of others
- `vanish.feature.view` - See vanished player

## [Meta keys](https://luckperms.net/wiki/Prefixes,-Suffixes-&-Meta#meta)
- `vanish_on_join`:`true` - Always join vanished

## [Placeholders](https://placeholders.pb4.eu/)
- `vanish:vanished` - Displays a text (configurable via config) if a player is vanished
- `vanish:online` - The number of players that the player viewing the placeholder can see
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ org.gradle.jvmargs=-Xmx1G
minecraft_version=23w51b
loader_version=0.15.3
# Mod Properties
mod_version=1.5.0
mod_version=1.5.1
maven_group=me.drex
archives_base_name=vanish
# Dependencies
fabric_version=0.91.1+1.20.3
fabric_version=0.92.1+1.20.4
permission_api_version=0.3-SNAPSHOT
placeholder_api_version=2.3.0+1.20.3
player_data_api_version=0.4.0+1.20.3
translations_version=2.2.0+1.20.3-rc1
configurate_hocon_version=4.1.2
# Compat
expanded_storage_version=12.0.0-beta.2
expanded_storage_version=12.0.0
bluemap_api_version=v2.5.1
styled_chat_version=2.3.0+1.20.2
styled_chat_version=2.4.0+1.20.3
dynmap_api_version=3.5
11 changes: 4 additions & 7 deletions src/main/java/me/drex/vanish/api/VanishAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public interface VanishAPI {
* @return the result of the check
*/
static boolean isVanished(@NotNull Entity entity) {
if (entity instanceof ServerPlayer player) {
return isVanished(player.server, player.getUUID());
}
return false;
return VanishManager.isVanished(entity);
}

static boolean isVanished(@NotNull MinecraftServer server, @NotNull UUID uuid) {
Expand All @@ -44,7 +41,7 @@ static boolean isVanished(@NotNull MinecraftServer server, @NotNull UUID uuid) {
* @return true if the vanish-status changed
*/
static boolean setVanish(@NotNull ServerPlayer player, boolean status) {
return VanishManager.setVanished(player, status);
return VanishManager.setVanished(player.getGameProfile(), player.server, status);
}

/**
Expand All @@ -55,7 +52,7 @@ static boolean setVanish(@NotNull ServerPlayer player, boolean status) {
* @return the result of the check
*/
static boolean canSeePlayer(@NotNull ServerPlayer actor, @NotNull ServerPlayer observer) {
return canSeePlayer(actor.server, actor.getUUID(), observer);
return VanishManager.canSeePlayer(actor, observer.createCommandSourceStack());
}

static boolean canSeePlayer(@NotNull MinecraftServer server, @NotNull UUID uuid, @NotNull ServerPlayer observer) {
Expand All @@ -81,7 +78,7 @@ static List<ServerPlayer> getVisiblePlayers(@NotNull CommandSourceStack observer
MinecraftServer server = observer.getServer();
ObjectArrayList<ServerPlayer> list = new ObjectArrayList<>();
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
if (canSeePlayer(server, player.getUUID(), observer)) {
if (VanishManager.canSeePlayer(player, observer)) {
list.add(player);
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/me/drex/vanish/mixin/MapItemSavedDataMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package me.drex.vanish.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import me.drex.vanish.api.VanishAPI;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(MapItemSavedData.class)
public abstract class MapItemSavedDataMixin {

@Shadow
protected abstract void removeDecoration(String string);

@WrapOperation(
method = "tickCarriedBy",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;trackingPosition:Z"
)
)
private boolean vanish_hideFromMap(MapItemSavedData instance, Operation<Boolean> original, @Local MapItemSavedData.HoldingPlayer holdingPlayer) {
if (VanishAPI.isVanished(holdingPlayer.player)) {
removeDecoration(holdingPlayer.player.getName().getString());
return false;
} else {
return original.call(instance);
}
}

}
16 changes: 16 additions & 0 deletions src/main/java/me/drex/vanish/mixin/PlayerListMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import eu.pb4.playerdata.api.PlayerDataApi;
import me.drex.vanish.VanishMod;
import me.drex.vanish.api.VanishAPI;
import me.drex.vanish.util.VanishData;
import me.drex.vanish.util.VanishedEntity;
import me.lucko.fabric.api.permissions.v0.Options;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
Expand All @@ -20,6 +24,8 @@

import java.util.List;

import static me.drex.vanish.util.VanishManager.VANISH_DATA_STORAGE;

@Mixin(PlayerList.class)
public abstract class PlayerListMixin {

Expand All @@ -31,6 +37,16 @@ public abstract class PlayerListMixin {
)
)
public void vanish_hideJoinMessage(PlayerList playerList, Component component, boolean bl, Operation<Void> original, Connection connection, ServerPlayer actor) {
Boolean vanishOnJoin = Options.get(actor, "vanish_on_join", Boolean::valueOf).orElse(false);
if (vanishOnJoin) {
VanishData data = PlayerDataApi.getCustomDataFor(actor.server, actor.getUUID(), VANISH_DATA_STORAGE);
if (data == null) data = new VanishData();
data.vanished = true;
PlayerDataApi.setCustomDataFor(actor.server, actor.getUUID(), VANISH_DATA_STORAGE, data);
((VanishedEntity) actor).vanish$setDirty();
}


if (VanishAPI.isVanished(actor)) {
VanishAPI.broadcastHiddenMessage(actor, component);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void vanish_modifyPackets(Packet<?> packet, PacketSendListener packetSend
ObjectArrayList<ServerPlayer> modifiedEntries = new ObjectArrayList<>();
int visible = 0;
for (ClientboundPlayerInfoUpdatePacket.Entry playerUpdate : playerInfoPacket.entries()) {
if (VanishAPI.canSeePlayer(server, playerUpdate.profileId(), listener.player)) {
ServerPlayer player = server.getPlayerList().getPlayer(playerUpdate.profileId());
if (VanishAPI.canSeePlayer(player, listener.player)) {
visible++;
ServerPlayer player = server.getPlayerList().getPlayer(playerUpdate.profileId());
if (player != null) modifiedEntries.add(player);
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/me/drex/vanish/mixin/VanishedServerPlayerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package me.drex.vanish.mixin;

import com.mojang.authlib.GameProfile;
import eu.pb4.playerdata.api.PlayerDataApi;
import me.drex.vanish.util.VanishData;
import me.drex.vanish.util.VanishedEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

import static me.drex.vanish.util.VanishManager.VANISH_DATA_STORAGE;

@Mixin(ServerPlayer.class)
public abstract class VanishedServerPlayerMixin extends Player implements VanishedEntity {

@Shadow
@Final
public MinecraftServer server;
@Unique
private boolean vanished$dirty = true;

@Unique
private boolean vanished$vanished;

public VanishedServerPlayerMixin(Level level, BlockPos blockPos, float f, GameProfile gameProfile) {
super(level, blockPos, f, gameProfile);
}

@Override
public boolean vanish$isVanished() {
if (vanished$dirty) {
VanishData data = PlayerDataApi.getCustomDataFor(server, uuid, VANISH_DATA_STORAGE);
vanished$vanished = data != null && data.vanished;
vanished$dirty = false;
}
return vanished$vanished;
}

@Override
public void vanish$setDirty() {
vanished$dirty = true;
}

}
33 changes: 26 additions & 7 deletions src/main/java/me/drex/vanish/util/VanishManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import net.minecraft.world.entity.Entity;

import java.util.Collections;
import java.util.UUID;
Expand All @@ -32,14 +33,14 @@ public static void init() {
ServerTickEvents.START_SERVER_TICK.register(server -> {
if (ConfigManager.vanish().actionBar) {
for (ServerPlayer player : server.getPlayerList().getPlayers()) {
if (VanishAPI.isVanished(player)) {
if (isVanished(player)) {
player.sendSystemMessage(Component.translatable("text.vanish.general.vanished"), true);
}
}
}
});
ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) -> {
if (VanishAPI.isVanished(sender) && ConfigManager.vanish().disableChat) {
if (isVanished(sender) && ConfigManager.vanish().disableChat) {
sender.sendSystemMessage(Component.translatable("text.vanish.chat.disabled").withStyle(ChatFormatting.RED));
return false;
} else {
Expand All @@ -49,7 +50,7 @@ public static void init() {
ServerMessageEvents.ALLOW_COMMAND_MESSAGE.register((message, source, params) -> {
ServerPlayer sender = source.getPlayer();
if (sender != null) {
if (VanishAPI.isVanished(sender) && ConfigManager.vanish().disableChat) {
if (isVanished(sender) && ConfigManager.vanish().disableChat) {
sender.sendSystemMessage(Component.translatable("text.vanish.chat.disabled").withStyle(ChatFormatting.RED));
return false;
}
Expand All @@ -60,6 +61,13 @@ public static void init() {
PlayerDataApi.register(VANISH_DATA_STORAGE);
}

public static boolean isVanished(Entity entity) {
if (entity instanceof VanishedEntity vanishedEntity) {
return vanishedEntity.vanish$isVanished();
}
return false;
}

public static boolean isVanished(MinecraftServer server, UUID uuid) {
VanishData data = PlayerDataApi.getCustomDataFor(server, uuid, VANISH_DATA_STORAGE);
return data != null && data.vanished;
Expand All @@ -69,6 +77,18 @@ public static boolean canViewVanished(SharedSuggestionProvider observer) {
return Permissions.check(observer, "vanish.feature.view", 2);
}

public static boolean canSeePlayer(ServerPlayer actor, CommandSourceStack observer) {
if (isVanished(actor)) {
if (observer.getEntity() != null && actor.equals(observer.getEntity())) {
return true;
} else {
return canViewVanished(observer);
}
} else {
return true;
}
}

public static boolean canSeePlayer(MinecraftServer server, UUID actor, CommandSourceStack observer) {
if (isVanished(server, actor)) {
if (observer.getEntity() != null && actor.equals(observer.getEntity().getUUID())) {
Expand All @@ -81,10 +101,6 @@ public static boolean canSeePlayer(MinecraftServer server, UUID actor, CommandSo
}
}

public static boolean setVanished(ServerPlayer player, boolean vanish) {
return setVanished(player.getGameProfile(), player.server, vanish);
}

public static boolean setVanished(GameProfile profile, MinecraftServer server, boolean vanish) {
if (isVanished(server, profile.getId()) == vanish) return false;
ServerPlayer player = server.getPlayerList().getPlayer(profile.getId());
Expand All @@ -96,6 +112,9 @@ public static boolean setVanished(GameProfile profile, MinecraftServer server, b
if (data == null) data = new VanishData();
data.vanished = vanish;
PlayerDataApi.setCustomDataFor(server, profile.getId(), VANISH_DATA_STORAGE, data);
if (isOnline) {
((VanishedEntity) player).vanish$setDirty();
}
if (!vanish && isOnline) {
unVanish(player);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/me/drex/vanish/util/VanishedEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.drex.vanish.util;

public interface VanishedEntity {

boolean vanish$isVanished();

void vanish$setDirty();

}
2 changes: 2 additions & 0 deletions src/main/resources/vanish.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"EntitySelectorMixin",
"ListPlayersCommandMixin",
"LivingEntityMixin",
"MapItemSavedDataMixin",
"MinecraftServerMixin",
"MsgCommandMixin",
"PlayerAdvancementsMixin",
Expand All @@ -24,6 +25,7 @@
"ServerLevelMixin",
"ServerPlayerMixin",
"SleepStatusMixin",
"VanishedServerPlayerMixin",
"WardenMixin",
"compat.expandedstorage.ContainerMixin",
"interaction.ChunkMapMixin",
Expand Down

0 comments on commit 48a4ff0

Please sign in to comment.