37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
package party._2a03.mc.mixin;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
import net.minecraft.text.Text;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
import party._2a03.mc.util.Config;
|
|
import party._2a03.mc.util.Database;
|
|
import party._2a03.mc.util.PlayerData;
|
|
|
|
import java.util.UUID;
|
|
|
|
@Mixin(value = GameProfile.class, remap = false)
|
|
public class MixinGameProfile {
|
|
int ready = 0;
|
|
String server_name = "";
|
|
|
|
@Inject(method = "getName", at = @At("RETURN"), cancellable = true)
|
|
public void replaceName(CallbackInfoReturnable<String> ci) {
|
|
if (ready++ < 2) // wait until authenticated
|
|
return;
|
|
UUID uuid = ((GameProfile)(Object)this).getId();
|
|
if (uuid == null) // wait until UUID is set
|
|
return;
|
|
if (!Config.getBool("overrideNames"))
|
|
return;
|
|
if (this.server_name == "") {
|
|
PlayerData playerdata = Database.getPlayer(uuid.toString());
|
|
this.server_name = playerdata.getName();
|
|
}
|
|
ci.setReturnValue(this.server_name);
|
|
}
|
|
}
|