Skip to content

Commit

Permalink
Update to 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Oct 19, 2024
1 parent 052cc22 commit c2697cb
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 93 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ See [this page](https://github.com/Patbox/PredicateAPI/blob/1.19.4/BUILTIN.md) f
},
// Modifies how player name is displayed
"player": {
// Toggles this feature.
// Toggles changing of player name on the list.
"modify_name": false,
// Toggles modification of text on right of player name
// Toggles modification of text on right of player name. Available since 3.3.0+1.20.3
"modify_right_text": false,
// Toggles setting of different player positions on player list with a sorting index. Available since 3.6.0+1.21.2
"modify_list_order": false,
// Toggles modification of player name visibility on player list through hidden parameter. Available since 3.6.0+1.21.2, always enabled before.
"modify_visibility": false,
// Hides player name from player list. Doesn't have any effect on commands, suggestions or entity visibility!
"hidden": false,
// Disables this formatting, forcing it to use vanilla one.
"passthrough": false,
// Default format of player name
"format": "%player:displayname%",
// Text displayed on right of the name
// Text displayed on right of the name. Available since 3.3.0+1.20.3
"right_text": "",
// Enables sending updates when player sends a message
"update_on_chat_message": false,
Expand All @@ -60,10 +64,12 @@ See [this page](https://github.com/Patbox/PredicateAPI/blob/1.19.4/BUILTIN.md) f
{
// Requirement of style, used for applying
"require": {/* PREDICATE */},
// Applied formatting, same as one above
// (Optional) Applied formatting, same as one above. If not set defaults to next valid one.
"format": "...",
// Text displayed on right of the name
// (Optional) Text displayed on right of the name. If not set defaults to next valid one.
"right_text": "",
// Optional. Sorting index for player list. If not set defaults to next valid one, with 0 being default one. Available since 3.6.0+1.21.2
"sorting_index": 0,
// Optional. Disables this formatting, forcing it to use vanilla one.
"passthrough": false,
// Optional, hides player name from player list. Doesn't have any effect on commands, suggestions or entity visibility!
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6.+'
id 'fabric-loom' version '1.7.+'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id 'com.matthewprenger.cursegradle' version '1.4.0'
Expand Down Expand Up @@ -32,8 +32,8 @@ dependencies {
modCompileOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")
modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}")

modImplementation include("eu.pb4:predicate-api:0.5.0+1.21")
modImplementation include("eu.pb4:placeholder-api:2.4.0+1.21")
modImplementation include("eu.pb4:predicate-api:0.6.0+1.21.2")
modImplementation include("eu.pb4:placeholder-api:2.5.0+1.21.2")
modImplementation include("me.lucko:fabric-permissions-api:0.3.1")
modImplementation include("eu.pb4:player-data-api:0.6.0+1.21")

Expand Down Expand Up @@ -62,7 +62,7 @@ tasks.withType(JavaCompile).configureEach {
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
it.options.release = 16
it.options.release = 21
}

java {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
minecraft_version=1.21.2-rc1
yarn_mappings=1.21.2-rc1+build.1
loader_version=0.16.7

#Fabric api
fabric_version=0.100.1+1.21
fabric_version=0.105.4+1.21.2

# Mod Properties
mod_version = 3.5.1+1.21
mod_version = 3.6.0+1.21.2
maven_group = eu.pb4
archives_base_name = styledplayerlist

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
70 changes: 0 additions & 70 deletions src/main/java/eu/pb4/styledplayerlist/MicroScheduler.java

This file was deleted.

20 changes: 14 additions & 6 deletions src/main/java/eu/pb4/styledplayerlist/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import eu.pb4.placeholders.api.ParserContext;
import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.PatternPlaceholderParser;
import eu.pb4.placeholders.api.parsers.StaticPreParser;
import eu.pb4.placeholders.api.parsers.TextParserV1;
import eu.pb4.predicate.api.BuiltinPredicates;
import eu.pb4.predicate.api.MinecraftPredicate;
import eu.pb4.predicate.api.PredicateContext;
Expand Down Expand Up @@ -55,7 +51,7 @@ public Config(ConfigData data) {

for (ConfigData.PermissionNameFormat entry : data.playerName.permissionNameFormat) {
this.permissionNameFormat.add(new PermissionNameFormat(entry.require != null ? entry.require : BuiltinPredicates.operatorLevel(5),
parseText(entry.format), parseText(entry.rightTextFormat), entry.ignoreFormatting, entry.hidePlayer != null ? entry.hidePlayer : isHiddenDefault));
parseText(entry.format), parseText(entry.rightTextFormat), entry.index, entry.ignoreFormatting, entry.hidePlayer != null ? entry.hidePlayer : isHiddenDefault));
}
}

Expand Down Expand Up @@ -105,7 +101,19 @@ public boolean isPlayerHidden(ServerPlayerEntity player) {
return this.isHiddenDefault;
}

@Nullable
public Integer sortingIndex(ServerPlayerEntity player) {
var context = PredicateContext.of(player);
for (PermissionNameFormat entry : this.permissionNameFormat) {
if (entry.index != null && entry.predicate.test(context).success()) {
return entry.index;
}
}

return null;
}


record PermissionNameFormat(MinecraftPredicate predicate, @Nullable TextNode name, @Nullable TextNode right, boolean passthrough, boolean hidden) {
record PermissionNameFormat(MinecraftPredicate predicate, @Nullable TextNode name, @Nullable TextNode right, @Nullable Integer index, boolean passthrough, boolean hidden) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static class PlayerName {
public boolean changePlayerName = false;
@SerializedName("modify_right_text")
public boolean changeRightText = false;
@SerializedName("modify_list_order")
public boolean modifyListOrder = false;
@SerializedName("modify_visibility")
public boolean changeVisiblity = false;
@SerializedName("passthrough")
public boolean ignoreFormatting = false;
@SerializedName("hidden")
Expand All @@ -59,6 +63,8 @@ public static class PermissionNameFormat {
public String format = null;
@SerializedName("right_text")
public String rightTextFormat = null;
@SerializedName("sorting_index")
public Integer index = null;
@SerializedName("passthrough")
public boolean ignoreFormatting = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
public class PlayerListS2CPacketEntryMixin {
@ModifyConstant(method = "<init>(Lnet/minecraft/server/network/ServerPlayerEntity;)V", constant = @Constant(intValue = 1, ordinal = 0))
private static int styledPlayerList$hideRealPlayer(int constant, ServerPlayerEntity player) {
return ConfigManager.getConfig().isPlayerHidden(player) ? 0 : 1;
return ConfigManager.getConfig().configData.playerName.changeVisiblity ? (ConfigManager.getConfig().isPlayerHidden(player) ? 0 : 1) : constant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,21 @@ public ServerPlayNetworkManagerMixin(MinecraftServer server, ClientConnection co
return;
}

var list = EnumSet.noneOf(PlayerListS2CPacket.Action.class);
if (ConfigManager.getConfig().configData.playerName.changePlayerName) {
PlayerListS2CPacket packet = new PlayerListS2CPacket(EnumSet.of(PlayerListS2CPacket.Action.UPDATE_DISPLAY_NAME, PlayerListS2CPacket.Action.UPDATE_LISTED), List.of(this.player));
list.add(PlayerListS2CPacket.Action.UPDATE_DISPLAY_NAME);
}

if (ConfigManager.getConfig().configData.playerName.modifyListOrder) {
list.add(PlayerListS2CPacket.Action.UPDATE_LIST_ORDER);
}

if (ConfigManager.getConfig().configData.playerName.changeVisiblity) {
list.add(PlayerListS2CPacket.Action.UPDATE_LISTED);
}

if (!list.isEmpty()) {
PlayerListS2CPacket packet = new PlayerListS2CPacket(list, List.of(this.player));
this.server.getPlayerManager().sendToAll(packet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,18 @@ public class ServerPlayerEntityMixin {

}
}

@Inject(method = "getPlayerListOrder", at = @At("HEAD"), cancellable = true)
private void styledPlayerList$getPlayerListIndex(CallbackInfoReturnable<Integer> cir) {
try {
if (ConfigManager.isEnabled() && ConfigManager.getConfig().configData.playerName.modifyListOrder) {
var x = ConfigManager.getConfig().sortingIndex((ServerPlayerEntity) (Object) this);
if (x != null) {
cir.setReturnValue(x);
}
}
} catch (Exception ignored) {

}
}
}

0 comments on commit c2697cb

Please sign in to comment.