Skip to content

Commit

Permalink
1.19.2 Add UUID Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Satxm committed Aug 18, 2024
1 parent dd2e9e1 commit 32cd34e
Show file tree
Hide file tree
Showing 27 changed files with 582 additions and 276 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[3]: https://img.shields.io/curseforge/dt/450250?label=CurseForge%0aDownloads&logo=curseforge&style=flat&color=E36639&labelcolor=2D2D2D
[4]: https://www.curseforge.com/minecraft/mc-mods/mcwifipnp

[5]: https://img.shields.io/badge/Available%20for-%201.15%20to%201.20-47376F?logo=files&color=377BCB&labelcolor=2D2D2D
[5]: https://img.shields.io/badge/Available%20for-%201.15%20to%201.21-47376F?logo=files&color=377BCB&labelcolor=2D2D2D
[6]: https://modrinth.com/mod/mcwifipnp/versions

[7]: https://img.shields.io/github/license/Satxm/mcwifipnp?label=License&logo=github&style=flat&color=E51050&labelcolor=2D2D2D
Expand Down Expand Up @@ -61,6 +61,8 @@ Modified from [TheGlitch76/mcpnp](https://github.com/TheGlitch76/mcpnp) project

## What Can It Do - 它的作用

添加了 UUID 修复模块,对于离线玩家,可以使离线玩家从mojang服务器获取对应的UUID,使UUID固定,不会因为客户端变化而变化。

Allows you to change the port number of the LAN world and choose whether to map this port to the public network using UPnP (if your router supports UPnP).

允许你修改局域网世界的端口号,并选择是否映射这个端口使用UPnP映射到公网(如果你的路由器支持UPnP)。
Expand Down
3 changes: 1 addition & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "com.google.code.findbugs:jsr305:3.0.2"
}

sourceSets {
Expand Down
14 changes: 3 additions & 11 deletions fabric/src/main/java/io/github/satxm/mcwifipnp/MCWiFiPnP.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.github.satxm.mcwifipnp;

import java.util.List;

import io.github.satxm.mcwifipnp.mixin.PlayerListAccessor;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.Screens;
Expand All @@ -13,7 +10,6 @@
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.BanIpCommands;
Expand All @@ -22,8 +18,8 @@
import net.minecraft.server.commands.DeOpCommands;
import net.minecraft.server.commands.OpCommand;
import net.minecraft.server.commands.WhitelistCommand;
import net.minecraft.server.players.PlayerList;

import java.util.List;

public class MCWiFiPnP implements ModInitializer {
public static final String MODID = "mcwifipnp";
Expand All @@ -41,7 +37,8 @@ public void onInitialize() {
BanIpCommands.register(dispatcher);
BanListCommands.register(dispatcher);
BanPlayerCommands.register(dispatcher);
});
OfflinePlayerCommand.register(dispatcher);
});
}

public static void afterScreenInit(Minecraft client, Screen screen, int i, int j) {
Expand Down Expand Up @@ -69,9 +66,4 @@ private void onServerStop(MinecraftServer server) {
MCWiFiPnPUnit.CloseUPnPPort(server);
}

public static void setMaxPlayers(IntegratedServer server, int num) {
PlayerList playerList = server.getPlayerList();
((PlayerListAccessor)playerList).setMaxPlayers(num);
}

}
12 changes: 0 additions & 12 deletions fabric/src/main/resources/mcwifipnp.mixins.json

This file was deleted.

14 changes: 12 additions & 2 deletions forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.spongepowered.mixin' version '0.7.+'
}

archivesBaseName = project.archives_base_name
Expand All @@ -16,7 +16,6 @@ println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty '
minecraft {
mappings channel: 'official', version: project.minecraft_version

accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

runs {
client {
Expand All @@ -35,6 +34,7 @@ minecraft {

dependencies {
minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
}

afterEvaluate {
Expand All @@ -54,6 +54,15 @@ sourceSets {
}
}

mixin {
// MixinGradle Settings
add sourceSets.main, 'mcwifipnp.refmap.json'
config 'mcwifipnp.mixins.json'

debug.verbose = true
debug.export = true
}

jar {
manifest {
attributes([
Expand All @@ -64,6 +73,7 @@ jar {
"Implementation-Version": "${version}",
"Implementation-Vendor": "Satxm",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"MixinConfigs": "mcwifipnp.mixins.json"
])
}
from("../LICENSE") {
Expand Down
8 changes: 1 addition & 7 deletions forge/src/main/java/io/github/satxm/mcwifipnp/MCWiFiPnP.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.network.chat.Component;
import net.minecraft.server.commands.BanIpCommands;
import net.minecraft.server.commands.BanListCommands;
import net.minecraft.server.commands.BanPlayerCommands;
import net.minecraft.server.commands.DeOpCommands;
import net.minecraft.server.commands.OpCommand;
import net.minecraft.server.commands.WhitelistCommand;
import net.minecraft.server.players.PlayerList;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.server.ServerStartingEvent;
Expand Down Expand Up @@ -58,16 +56,12 @@ public void onServerStarting(ServerStartingEvent event) {
BanIpCommands.register(event.getServer().getCommands().getDispatcher());
BanListCommands.register(event.getServer().getCommands().getDispatcher());
BanPlayerCommands.register(event.getServer().getCommands().getDispatcher());
OfflinePlayerCommand.register(event.getServer().getCommands().getDispatcher());
}

@SubscribeEvent
public void onServerStopping(ServerStoppingEvent event) {
MCWiFiPnPUnit.CloseUPnPPort(event.getServer());
}

public static void setMaxPlayers(IntegratedServer server, int num) {
PlayerList playerList = server.getPlayerList();
playerList.maxPlayers = num;
}

}
1 change: 0 additions & 1 deletion forge/src/main/resources/META-INF/accesstransformer.cfg

This file was deleted.

12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ org.gradle.jvmargs = -Xmx4G
org.gradle.daemon = false

# Mod Properties
mod_version = 1.7.1
mod_version = 1.7.2
maven_group = io.github.satxm.mcwifipnp
archives_base_name = mcwifipnp

minecraft_version = 1.19.2

# Forge Properties on https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json
forge_version = 43.3.7
forge_version = 43.4.0

# Fabric Properties on https://fabricmc.net/develop/
fabric_loader_version = 0.15.6
fabric_loader_version = 0.15.11
fabric_version = 0.77.0+1.19.2

# Quilt Properties on https://lambdaurora.dev/tools/import_quilt.html
quilt_loader_version = 0.23.1
qsl_version = 3.0.0-beta.29
quilted_fabric_api_version = 4.0.0-beta.30+0.76.0
quilted_fabric_api_version = 4.0.0-beta.30+0.77.0-1.19.2

# QSL on https://maven.quiltmc.org/repository/release/org/quiltmc/qsl/maven-metadata.xml
qsl_version = 3.0.0-beta.29+1.19.2

# Mod Config
# Forge
Expand Down
11 changes: 10 additions & 1 deletion quilt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ dependencies {
officialMojangMappings()
}
modImplementation "org.quiltmc:quilt-loader:${project.quilt_loader_version}"
modImplementation "org.quiltmc:qsl:${qsl_version}+${minecraft_version}"
modImplementation "org.quiltmc:qsl:${project.qsl_version}"
modImplementation "com.google.code.findbugs:jsr305:3.0.2"
}

loom {
mods {
"mcwifipnp" {
sourceSet sourceSets.main
}
}
}

sourceSets {
Expand Down
8 changes: 0 additions & 8 deletions quilt/src/main/java/io/github/satxm/mcwifipnp/MCWiFiPnP.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import org.quiltmc.qsl.lifecycle.api.event.ServerLifecycleEvents;
import org.quiltmc.qsl.screen.api.client.ScreenEvents;

import io.github.satxm.mcwifipnp.mixin.PlayerListAccessor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.PauseScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.BanIpCommands;
Expand All @@ -23,7 +21,6 @@
import net.minecraft.server.commands.DeOpCommands;
import net.minecraft.server.commands.OpCommand;
import net.minecraft.server.commands.WhitelistCommand;
import net.minecraft.server.players.PlayerList;

public class MCWiFiPnP implements ModInitializer {
public static final String MODID = "mcwifipnp";
Expand Down Expand Up @@ -68,9 +65,4 @@ private void onServerStop(MinecraftServer server) {
MCWiFiPnPUnit.CloseUPnPPort(server);
}

public static void setMaxPlayers(IntegratedServer server, int num) {
PlayerList playerList = server.getPlayerList();
((PlayerListAccessor)playerList).setMaxPlayers(num);
}

}

This file was deleted.

12 changes: 0 additions & 12 deletions quilt/src/main/resources/mcwifipnp.mixins.json

This file was deleted.

26 changes: 11 additions & 15 deletions src/main/java/io/github/satxm/mcwifipnp/MCWiFiPnPUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.WeakHashMap;
import java.util.*;

import io.github.satxm.mcwifipnp.mixin.PlayerListAccessor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -66,13 +61,15 @@ public static void OpenToLan() {
: Component.translatable("commands.publish.failed");
client.gui.getChat().addMessage(component);

MCWiFiPnP.setMaxPlayers(server, cfg.maxPlayers);
((PlayerListAccessor) playerList).setMaxPlayers(cfg.maxPlayers);
server.setUsesAuthentication(cfg.OnlineMode);
server.setPvpAllowed(cfg.PvP);
server.setEnforceWhitelist(cfg.Whitelist);
playerList.setUsingWhiteList(cfg.Whitelist);
playerList.getOps().add(new ServerOpListEntry(client.player.getGameProfile(), 4, playerList.canBypassPlayerLimit(client.player.getGameProfile())));
playerList.setAllowCheatsForAllPlayers(cfg.AllPlayersCheats);
UUIDFixer.EnableUUIDFix = cfg.EnableUUIDFix;
UUIDFixer.alwaysOfflinePlayers = cfg.alwaysOfflinePlayers;

new Thread(() -> {
MCWiFiPnPUnit.UseUPnP(cfg, client);
Expand Down Expand Up @@ -104,8 +101,7 @@ public static void CopyToClipboard(Config cfg, Minecraft client) {
for (int i = 0; i < IPAddressList().size(); i++) {
Map<String, String> NewMap = IPAddressList().get(i);
if (NewMap.get("Type") == "IPv4") {
IPComponentList.add(
IPComponent(
IPComponentList.add(IPComponent(
Component.translatable(NewMap.get("Local")).getString() + " " + NewMap.get("Type"),
NewMap.get("IP") + ":" + cfg.port));
} else {
Expand All @@ -123,10 +119,8 @@ public static void CopyToClipboard(Config cfg, Minecraft client) {
IPList.add(GetGlobalIPv4().get("IP"));
}
if (!GetGlobalIPv6().isEmpty() && !IPList.contains(GetGlobalIPv6().get("IP"))) {
IPComponentList.add(IPComponent(
Component.translatable(GetGlobalIPv6().get("Local")).getString() + " "
+ GetGlobalIPv6().get("Type"),
"[" + GetGlobalIPv6().get("IP") + "]:" + cfg.port));
IPComponentList.add(IPComponent(Component.translatable(GetGlobalIPv6().get("Local")).getString() + " "
+ GetGlobalIPv6().get("Type"),"[" + GetGlobalIPv6().get("IP") + "]:" + cfg.port));
IPList.add(GetGlobalIPv4().get("IP"));
}
if (cfg.UseUPnP && UPnP.getExternalIP() != null && !IPList.contains(GetGlobalIPv6().get("IP"))) {
Expand Down Expand Up @@ -177,7 +171,7 @@ public static void CloseUPnPPort(MinecraftServer server) {
}
}

static void saveConfig(Config cfg) {
public static void saveConfig(Config cfg) {
if (!cfg.needsDefaults) {
try {
Files.write(cfg.location, toPrettyFormat(cfg).getBytes("utf-8"), StandardOpenOption.TRUNCATE_EXISTING,
Expand All @@ -198,6 +192,8 @@ public static class Config {
public boolean UseUPnP = true;
public boolean AllowCommands = false;
public boolean OnlineMode = true;
public boolean EnableUUIDFix = false;
public List<String> alwaysOfflinePlayers = Collections.emptyList();
public boolean PvP = true;
public boolean CopyToClipboard = true;
public transient Path location;
Expand Down
Loading

0 comments on commit 32cd34e

Please sign in to comment.