Skip to content

Commit f736273

Browse files
committed
Forge 1.20.1
1 parent 9877d00 commit f736273

File tree

8 files changed

+337
-1
lines changed

8 files changed

+337
-1
lines changed

server/forge/1.20.1/build.gradle

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
maven { url = 'https://maven.minecraftforge.net' }
5+
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
6+
}
7+
dependencies {
8+
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
9+
}
10+
}
11+
12+
plugins {
13+
id 'eclipse'
14+
id 'idea'
15+
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
16+
}
17+
18+
version = "1.20.1"
19+
group = "me.minecraftauth"
20+
archivesBaseName = "${modid}"
21+
22+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
23+
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
24+
minecraft {
25+
// snapshot YYYYMMDD Snapshot are built nightly.
26+
// stable # Stables are built at the discretion of the MCP team.
27+
// official MCVersion Official field/method names from Mojang mapping files
28+
mappings channel: 'official', version: '1.20.1'
29+
//makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
30+
//accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
31+
32+
runs {
33+
server {
34+
properties 'mixin.env.remapRefMap': 'true'
35+
property 'mixin.env.refMapRemappingFile', "${project.projectDir}/build/createSrgToMcp/output.srg"
36+
workingDirectory project.file('run')
37+
arg "-mixin.config="+archivesBaseName+".mixins.json"
38+
39+
property 'forge.logging.console.level', 'debug'
40+
41+
mods {
42+
minecraftauth {
43+
source sourceSets.main
44+
}
45+
}
46+
}
47+
}
48+
}
49+
50+
repositories{
51+
mavenCentral()
52+
}
53+
54+
dependencies {
55+
shaded project(':common')
56+
minecraft 'net.minecraftforge:forge:1.20.1-47.2.20'
57+
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
58+
}
59+
60+
sourceSets {
61+
main.resources.srcDirs += 'src/generated/resources'
62+
}
63+
64+
jar {
65+
archivesBaseName = 'MinecraftAuth-Forge'
66+
67+
manifest {
68+
attributes([
69+
"Specification-Title": "${modid}",
70+
"Specification-Vendor": "minecraftauth",
71+
"Specification-Version": "1", // We are version 1 of ourselves
72+
"Implementation-Title": project.name,
73+
"Implementation-Version": "${version}",
74+
"Implementation-Vendor" :"minecraftauth",
75+
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
76+
"MixinConfigs": "${modid}.mixins.json"
77+
])
78+
}
79+
}
80+
81+
apply plugin: 'org.spongepowered.mixin'
82+
mixin {
83+
add sourceSets.main, "${modid}.refmap.json"
84+
}
85+
86+
// ensure shadowJar gets re-obfuscated
87+
tasks.shadowJar.dependsOn "reobfJar"
88+
reobf { shadowJar {} }
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2021-2024 MinecraftAuth.me
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package me.minecraftauth.forge.server;
18+
19+
import com.google.common.base.Suppliers;
20+
import com.mojang.brigadier.CommandDispatcher;
21+
import com.mojang.brigadier.context.CommandContext;
22+
import github.scarsz.configuralize.ParseException;
23+
import net.minecraft.ChatFormatting;
24+
import net.minecraft.commands.CommandSourceStack;
25+
import net.minecraft.commands.Commands;
26+
import net.minecraft.network.chat.Component;
27+
28+
import java.io.IOException;
29+
30+
public class Command {
31+
32+
public Command(CommandDispatcher<CommandSourceStack> dispatcher) {
33+
dispatcher.register(Commands.literal("minecraftauth")
34+
.then(Commands.literal("reload")
35+
.requires(cs -> cs.hasPermission(3))
36+
.executes(context -> reload(context, context.getSource()))
37+
)
38+
);
39+
}
40+
41+
private int reload(CommandContext<CommandSourceStack> context, CommandSourceStack source) {
42+
try {
43+
MinecraftAuthMod.getInstance().getService().fullReload();
44+
source.sendSuccess(Suppliers.ofInstance(Component.literal("MinecraftAuth config reloaded").withStyle(ChatFormatting.RED)), true);
45+
return 1;
46+
} catch (IOException e) {
47+
source.sendFailure(Component.literal("IO exception while reading config: " + e.getMessage()).withStyle(ChatFormatting.RED));
48+
e.printStackTrace();
49+
} catch (ParseException e) {
50+
source.sendFailure(Component.literal("Exception while parsing config: " + e.getMessage()).withStyle(ChatFormatting.RED));
51+
e.printStackTrace();
52+
}
53+
return -1;
54+
}
55+
56+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2021-2024 MinecraftAuth.me
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package me.minecraftauth.forge.server;
18+
19+
import github.scarsz.configuralize.DynamicConfig;
20+
import github.scarsz.configuralize.ParseException;
21+
import lombok.Getter;
22+
import me.minecraftauth.plugin.common.service.AuthenticationService;
23+
import net.minecraftforge.common.MinecraftForge;
24+
import net.minecraftforge.event.RegisterCommandsEvent;
25+
import net.minecraftforge.eventbus.api.SubscribeEvent;
26+
import net.minecraftforge.fml.IExtensionPoint;
27+
import net.minecraftforge.fml.ModLoadingContext;
28+
import net.minecraftforge.fml.common.Mod;
29+
import net.minecraftforge.network.NetworkConstants;
30+
import net.minecraftforge.server.command.ConfigCommand;
31+
import org.apache.logging.log4j.LogManager;
32+
import org.apache.logging.log4j.Logger;
33+
34+
import java.io.File;
35+
import java.io.IOException;
36+
37+
@Mod(MinecraftAuthMod.MOD_ID)
38+
public class MinecraftAuthMod {
39+
40+
public static final String MOD_ID = "minecraftauth";
41+
@Getter private static final Logger logger = LogManager.getLogger();
42+
@Getter private static MinecraftAuthMod instance;
43+
44+
@Getter private AuthenticationService service;
45+
46+
public MinecraftAuthMod() {
47+
MinecraftAuthMod.instance = this;
48+
MinecraftForge.EVENT_BUS.register(this);
49+
50+
// inform mod loader that this is a server-only mod and isn't required on clients
51+
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
52+
53+
DynamicConfig config = new DynamicConfig();
54+
try {
55+
config.addSource(MinecraftAuthMod.class, "game-config", new File("config", "MinecraftAuth.yml"));
56+
config.saveAllDefaults();
57+
config.loadAll();
58+
} catch (IOException | ParseException e) {
59+
e.printStackTrace();
60+
return;
61+
}
62+
63+
try {
64+
service = new AuthenticationService.Builder()
65+
.withConfig(config)
66+
.withLogger(new me.minecraftauth.plugin.common.abstracted.Logger() {
67+
@Override
68+
public void info(String message) {
69+
logger.info(message);
70+
}
71+
@Override
72+
public void warning(String message) {
73+
logger.warn(message);
74+
}
75+
@Override
76+
public void error(String message) {
77+
logger.error(message);
78+
}
79+
@Override
80+
public void debug(String message) {
81+
logger.debug(message);
82+
}
83+
})
84+
.build();
85+
} catch (IOException | ParseException e) {
86+
e.printStackTrace();
87+
}
88+
}
89+
90+
@SubscribeEvent
91+
public void onRegisterCommands(RegisterCommandsEvent event) {
92+
new Command(event.getDispatcher());
93+
ConfigCommand.register(event.getDispatcher());
94+
}
95+
96+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2021-2024 MinecraftAuth.me
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package me.minecraftauth.forge.server.mixin;
18+
19+
import com.mojang.authlib.GameProfile;
20+
import me.minecraftauth.forge.server.MinecraftAuthMod;
21+
import me.minecraftauth.lib.exception.LookupException;
22+
import me.minecraftauth.plugin.common.abstracted.event.RealmJoinEvent;
23+
import net.minecraft.ChatFormatting;
24+
import net.minecraft.network.chat.Component;
25+
import net.minecraft.network.chat.MutableComponent;
26+
import net.minecraft.server.players.PlayerList;
27+
import net.minecraftforge.server.ServerLifecycleHooks;
28+
import org.spongepowered.asm.mixin.Mixin;
29+
import org.spongepowered.asm.mixin.injection.At;
30+
import org.spongepowered.asm.mixin.injection.Inject;
31+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
32+
33+
import java.net.SocketAddress;
34+
35+
@Mixin(PlayerList.class)
36+
public abstract class LoginMixin {
37+
38+
@Inject(at = @At("RETURN"), method = "canPlayerLogin", cancellable = true)
39+
private void init(SocketAddress address, GameProfile profile, CallbackInfoReturnable<Component> returnedMessage) {
40+
if (returnedMessage.getReturnValue() == null) {
41+
// System.out.println("Player " + profile.getName() + "[" + profile.getId() + "] is logging in @ " + address);
42+
43+
try {
44+
MinecraftAuthMod.getInstance().getService().handleRealmJoinEvent(new RealmJoinEvent(
45+
profile.getId(),
46+
profile.getName(),
47+
ServerLifecycleHooks.getCurrentServer().getPlayerList().isOp(profile),
48+
null
49+
) {
50+
@Override
51+
public void disallow(String message) {
52+
returnedMessage.setReturnValue(errorComponent(message));
53+
}
54+
});
55+
} catch (LookupException e) {
56+
returnedMessage.setReturnValue(errorComponent("Unable to verify linked account"));
57+
e.printStackTrace();
58+
}
59+
}
60+
}
61+
62+
private MutableComponent errorComponent(String message) {
63+
return Component.literal(message).withStyle(ChatFormatting.RED);
64+
}
65+
66+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
modLoader="javafml"
2+
loaderVersion="[36,)"
3+
license="Apache License, Version 2.0"
4+
5+
[[mods]]
6+
modId="minecraftauth"
7+
version="1.20.1"
8+
displayName="Minecraft Authentication"
9+
description="Authenticate players in your Minecraft server to various services"
10+
authors="Minecraft Authentication"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"required": true,
3+
"package": "me.minecraftauth.forge.server.mixin",
4+
"compatibilityLevel": "JAVA_17",
5+
"refmap": "minecraftauth.refmap.json",
6+
"server": [
7+
"LoginMixin"
8+
],
9+
"injectors": {
10+
"defaultRequire": 1
11+
},
12+
"minVersion": "0.8"
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"pack": {
3+
"description": "MinecraftAuth resources",
4+
"pack_format": 6,
5+
"_comment": "A pack_format of 6 requires json lang files. Note: we require v6 pack meta for all mods."
6+
}
7+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ pluginManagement {
1515
rootProject.name = 'MinecraftAuthentication-Plugin'
1616

1717
include 'common'
18-
include 'server:bukkit', 'server:sponge', 'server:forge:1.16.5', 'server:forge:1.18.2', 'server:forge:1.19.3'
18+
include 'server:bukkit', 'server:sponge', 'server:forge:1.16.5', 'server:forge:1.18.2', 'server:forge:1.19.3', 'server:forge:1.20.1'
1919
include 'proxy:bungeecord', 'proxy:velocity'

0 commit comments

Comments
 (0)