Skip to content

Commit

Permalink
Update to Minecraft 1.20.6
Browse files Browse the repository at this point in the history
Closes #87.
  • Loading branch information
Gegy committed Jun 8, 2024
1 parent 3dfa2c9 commit b3303f5
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 59 deletions.
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.2-SNAPSHOT" apply false
id 'fabric-loom' version '1.6.+' apply false
id "maven-publish"
}

Expand All @@ -11,13 +11,13 @@ allprojects {
group = project.maven_group

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
toolchain.languageVersion = JavaLanguageVersion.of(21)
withSourcesJar()
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
it.options.release = 21
}

dependencies {
Expand Down Expand Up @@ -86,8 +86,6 @@ dependencies {

modImplementation include("xyz.nucleoid:more-codecs:0.3.3+1.20.2")

implementation include(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.2.0-rc.5"))

testImplementation platform("org.junit:junit-bom:5.7.0")
testImplementation "org.junit.jupiter:junit-jupiter"
}
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.1
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.10

#Fabric api
fabric_version=0.91.2+1.20.4
# Fabric api
fabric_version=0.99.0+1.20.6

# Mod Properties
mod_version=1.6.9
mod_version=1.6.10
maven_group=dev.gegy
archives_base_name=player-roles
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.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 5 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/gegy/roles/PlayerRoles.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.gegy.roles;

import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
import dev.gegy.roles.api.PlayerRolesApi;
import dev.gegy.roles.api.RoleLookup;
Expand All @@ -25,15 +26,14 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

import java.util.UUID;

public final class PlayerRoles implements ModInitializer {
public static final String ID = "player_roles";
public static final Logger LOGGER = LogManager.getLogger(ID);
public static final Logger LOGGER = LogUtils.getLogger();

public static final String EVERYONE = "everyone";

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dev/gegy/roles/command/RoleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import static net.minecraft.server.command.CommandManager.literal;

public final class RoleCommand {
public static final DynamicCommandExceptionType ROLE_NOT_FOUND = new DynamicCommandExceptionType(arg -> {
return Text.translatable("Role with name '%s' was not found!", arg);
});
public static final DynamicCommandExceptionType ROLE_NOT_FOUND = new DynamicCommandExceptionType(arg ->
Text.stringifiedTranslatable("Role with name '%s' was not found!", arg)
);

public static final SimpleCommandExceptionType ROLE_POWER_TOO_LOW = new SimpleCommandExceptionType(
Text.literal("You do not have sufficient power to manage this role")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public interface ConfigErrorConsumer {
void report(String message);

default void report(String message, DataResult.PartialResult<?> error) {
default void report(String message, DataResult.Error<?> error) {
this.report(message + ": " + error.message());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/gegy/roles/config/RoleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public final class RoleConfig {
public static final Codec<RoleConfig> CODEC = RecordCodecBuilder.create(i -> i.group(
Codec.intRange(0, Integer.MAX_VALUE).optionalFieldOf("level", 0).forGetter(c -> c.level),
MoreCodecs.propagatingOptionalFieldOf(RoleOverrideMap.CODEC, "overrides", (Supplier<RoleOverrideMap>) RoleOverrideMap::new).forGetter(c -> c.overrides),
RoleOverrideMap.CODEC.optionalFieldOf("overrides", new RoleOverrideMap()).forGetter(c -> c.overrides),
MoreCodecs.arrayOrUnit(Codec.STRING, String[]::new).optionalFieldOf("includes", new String[0]).forGetter(c -> c.includes),
RoleApplyConfig.CODEC.optionalFieldOf("apply").forGetter(c -> Optional.ofNullable(c.apply))
).apply(i, RoleConfig::new));
Expand All @@ -25,7 +25,7 @@ public final class RoleConfig {

private RoleConfig(int level, RoleOverrideMap overrides, String[] includes, Optional<RoleApplyConfig> apply) {
this.level = level;
this.overrides = overrides;
this.overrides = new RoleOverrideMap(overrides);
this.includes = includes;
this.apply = apply.orElse(null);
}
Expand Down
20 changes: 6 additions & 14 deletions src/main/java/dev/gegy/roles/config/RoleConfigMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,19 @@ public final class RoleConfigMap implements Iterable<Pair<String, RoleConfig>> {
this.roleOrder = roleOrder;
}

public static <T> RoleConfigMap parse(Dynamic<T> root, ConfigErrorConsumer error) {
var roleEntries = root.asMapOpt().result().orElse(Stream.empty())
.collect(Collectors.toList());
public static <T> RoleConfigMap parse(Dynamic<T> root, ConfigErrorConsumer errorConsumer) {
var roleEntries = root.asMapOpt().result().orElse(Stream.empty()).toList();

var roleBuilder = new Builder();

for (var entry : roleEntries) {
var name = entry.getFirst().asString(PlayerRoles.EVERYONE).toLowerCase(Locale.ROOT);
var roleRoot = entry.getSecond();

var roleConfigResult = RoleConfig.CODEC.parse(roleRoot);
if (roleConfigResult.error().isPresent()) {
error.report("Failed to parse role config for '" + name + "'", roleConfigResult.error().get());
continue;
}

var role = roleConfigResult.result().get();
roleBuilder.add(name, role);
RoleConfig.CODEC.parse(entry.getSecond())
.ifSuccess(role -> roleBuilder.add(name, role))
.ifError(error -> errorConsumer.report("Failed to parse role config for '" + name + "'", error));
}

return roleBuilder.build(error);
return roleBuilder.build(errorConsumer);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -21,8 +22,8 @@ private ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfil

@Inject(method = "readCustomDataFromNbt", at = @At("RETURN"))
private void readCustomDataFromTag(NbtCompound tag, CallbackInfo ci) {
if (tag.contains("roles", NbtType.LIST)) {
PlayerRoleManager.get().addLegacyRoles((ServerPlayerEntity) (Object) this, tag.getList("roles", NbtType.STRING));
if (tag.contains("roles", NbtElement.LIST_TYPE)) {
PlayerRoleManager.get().addLegacyRoles((ServerPlayerEntity) (Object) this, tag.getList("roles", NbtElement.STRING_TYPE));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public abstract class MinecraftServerMixin {
@Inject(method = "getPermissionLevel", at = @At("HEAD"), cancellable = true)
public void getPermissionLevel(GameProfile profile, CallbackInfoReturnable<Integer> ci) {
var roles = PlayerRoleManager.get().peekRoles((MinecraftServer)(Object)this, profile.getId());
var roles = PlayerRoleManager.get().peekRoles((MinecraftServer) (Object) this, profile.getId());
var permissionLevel = roles.overrides().select(PlayerRoles.PERMISSION_LEVEL);
if (permissionLevel != null) {
ci.setReturnValue(permissionLevel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package dev.gegy.roles.override;

import com.google.gson.JsonObject;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.text.*;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.dynamic.Codecs;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.codecs.MoreCodecs;

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/dev/gegy/roles/override/RoleOverrideMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public final class RoleOverrideMap implements RoleOverrideReader {
@SuppressWarnings("unchecked")
public static final Codec<RoleOverrideMap> CODEC = MoreCodecs.dispatchByMapKey(RoleOverrideType.REGISTRY, t -> MoreCodecs.listOrUnit((Codec<Object>) t.getCodec()))
public static final Codec<RoleOverrideMap> CODEC = Codec.dispatchedMap(RoleOverrideType.REGISTRY, t -> MoreCodecs.listOrUnit((Codec<Object>) t.getCodec()))
.xmap(RoleOverrideMap::new, m -> m.overrides);

private final Map<RoleOverrideType<?>, List<Object>> overrides;
Expand All @@ -27,6 +27,10 @@ public RoleOverrideMap() {
this.overrides = new Reference2ObjectOpenHashMap<>();
}

public RoleOverrideMap(RoleOverrideMap map) {
this(map.overrides);
}

private RoleOverrideMap(Map<RoleOverrideType<?>, List<Object>> overrides) {
this.overrides = new Reference2ObjectOpenHashMap<>(overrides);
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/dev/gegy/roles/store/db/PlayerRoleDatabase.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package dev.gegy.roles.store.db;

import com.mojang.logging.LogUtils;
import dev.gegy.roles.config.PlayerRolesConfig;
import dev.gegy.roles.store.PlayerRoleSet;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtTagSizeTracker;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.minecraft.nbt.NbtSizeTracker;
import org.slf4j.Logger;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -18,7 +18,7 @@
import java.util.UUID;

public final class PlayerRoleDatabase implements Closeable {
private static final Logger LOGGER = LogManager.getLogger(PlayerRoleDatabase.class);
private static final Logger LOGGER = LogUtils.getLogger();

private final Uuid2BinaryDatabase binary;

Expand Down Expand Up @@ -74,8 +74,8 @@ private static void deserializeRoles(PlayerRoleSet roles, ByteBuffer bytes) thro
var config = PlayerRolesConfig.get();

try (var input = new ByteArrayInputStream(bytes.array())) {
var nbt = NbtIo.readCompressed(input, NbtTagSizeTracker.ofUnlimitedBytes());
roles.deserialize(config, nbt.getList("roles", NbtType.STRING));
var nbt = NbtIo.readCompressed(input, NbtSizeTracker.ofUnlimitedBytes());
roles.deserialize(config, nbt.getList("roles", NbtElement.STRING_TYPE));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"mixins": ["roles.mixins.json"],
"depends": {
"fabricloader": ">=0.14",
"fabric": ">=0.83",
"minecraft": ">=1.20",
"fabricloader": ">=0.15",
"fabric": ">=0.99",
"minecraft": "1.20.6",
"java": ">=17"
}
}
2 changes: 1 addition & 1 deletion src/main/resources/roles.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"required": true,
"minVersion": "0.8",
"package": "dev.gegy.roles.mixin",
"compatibilityLevel": "JAVA_16",
"compatibilityLevel": "JAVA_17",
"mixins": [
"CommandBlockExecutorMixin",
"CommandFunctionMixin",
Expand Down

0 comments on commit b3303f5

Please sign in to comment.