Skip to content

Commit

Permalink
fix Forestry mail offline uuid issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzinsel64 committed Mar 5, 2024
1 parent e878592 commit c8179b3
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
*/
dependencies {
api("com.github.GTNewHorizons:GTNHLib:0.2.3:dev")
implementation("com.github.GTNewHorizons:ForestryMC:4.8.5:dev")
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ apiPackage =
accessTransformersFile = pilzmcsammelsorium_at.cfg

# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
usesMixins = true
# Adds some debug arguments like verbose output and export
usesMixinDebug = false
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/de/pilz/sammelsorium/LateMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.pilz.sammelsorium;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.gtnewhorizon.gtnhmixins.ILateMixinLoader;
import com.gtnewhorizon.gtnhmixins.LateMixin;

@LateMixin
public class LateMixinPlugin implements ILateMixinLoader {

@Override
public String getMixinConfig() {
return "mixins.pilzmcsammelsorium.late.json";
}

@Override
public List<String> getMixins(Set<String> loadedMods) {
List<String> list = new ArrayList<String>();

// Forestry
if (loadedMods.contains("Forestry")) {
// Offline UUID Fix
list.add("MixinForestryPlayerUtils");
list.add("MixinForestryPostRegistry");
}

return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public class ModIntegrationConfigs {
@Config.DefaultBoolean(true)
@Config.RequiresMcRestart
public static boolean registerModOres;

@Config.Comment("Overwrites Forestrys method to get the players user profile and always return a offline UUID. Only enable this, if your server runs in offline mode.")
@Config.DefaultBoolean(false)
@Config.RequiresMcRestart
public static boolean forestryMailFixOfflineUUDID;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package de.pilz.sammelsorium.mixins;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.mojang.authlib.GameProfile;

import de.pilz.sammelsorium.configuration.ModIntegrationConfigs;
import forestry.core.utils.PlayerUtil;

@Mixin(PlayerUtil.class)
public abstract class MixinForestryPlayerUtils {

// @Inject(
// method = "getRecipient(Ljava/lang/String;Lforestry/api/mail/EnumAddressee;)Lforestry/api/mail/IMailAddress;",
// at = @At("HEAD"),
// cancellable = true,
// remap = false)
// private static void pilzmcsammelsorium$fixOfflineUUID(String recipientName, EnumAddressee type,
// CallbackInfoReturnable<IMailAddress> callback) {
// if (ModIntegrationConfigs.forestryMailFixOfflineUUDID && type == EnumAddressee.PLAYER) {
// UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + recipientName).getBytes(Charsets.UTF_8));
// GameProfile gameProfile = new GameProfile(uuid, recipientName);
// IMailAddress address = PostManager.postRegistry.getMailAddress(gameProfile);
// callback.setReturnValue(address);
// callback.cancel();
// }
// }

@Inject(
method = "isSameGameProfile(Lcom/mojang/authlib/GameProfile;Lcom/mojang/authlib/GameProfile;)Z",
at = @At("RETURN"),
cancellable = true,
remap = false)
private static void pilzmcsammelsorium$fixOfflineUUID(GameProfile player1, GameProfile player2,
CallbackInfoReturnable<Boolean> callback) {
if (ModIntegrationConfigs.forestryMailFixOfflineUUDID && !callback.getReturnValueZ()
&& player1 != null
&& player2 != null) {
String name1 = player1.getName();
String name2 = player2.getName();
if (name1 != null && name2 != null && !name1.equals("") && !name2.equals("") && name1.equals(name2)) {
callback.setReturnValue(true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.pilz.sammelsorium.mixins;

import java.util.Locale;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import de.pilz.sammelsorium.configuration.ModIntegrationConfigs;
import forestry.api.mail.EnumAddressee;
import forestry.api.mail.IMailAddress;
import forestry.mail.MailAddress;

@Mixin(MailAddress.class)
public abstract class MixinForestryPostRegistry implements IMailAddress {

@Inject(method = "toString()Ljava/lang/String;", at = @At("HEAD"), cancellable = true, remap = false)
public void pilzmcsammelsorium$fixOfflineUUID(CallbackInfoReturnable<String> callback) {
if (ModIntegrationConfigs.forestryMailFixOfflineUUDID && isPlayer()) {
MailAddress $this = (MailAddress) (Object) this;
String name = $this.getName()
.toLowerCase(Locale.ENGLISH);
callback.setReturnValue(EnumAddressee.PLAYER.toString() + "-" + name);
callback.cancel();
}
}
}
12 changes: 12 additions & 0 deletions src/main/resources/mixins.pilzmcsammelsorium.late.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8.5-GTNH",
"package": "de.pilz.sammelsorium.mixins",
"refmap": "mixins.pilzmcsammelsorium.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [],
"server": []
}

0 comments on commit c8179b3

Please sign in to comment.