1313import net .minecraft .util .Util ;
1414import dev .xpple .seedmapper .render .esp .EspStyle ;
1515
16+ import java .net .SocketAddress ;
1617import java .util .EnumSet ;
1718import java .util .HashMap ;
1819import java .util .Map ;
20+ import java .util .Objects ;
1921import java .util .function .Supplier ;
2022
2123import static dev .xpple .seedmapper .util .ChatBuilder .*;
@@ -34,10 +36,52 @@ public static void save() {
3436 @ Config (putter = @ Config .Putter ("none" ), adder = @ Config .Adder (value = "addSavedSeed" , type = long .class ))
3537 public static Map <String , Long > SavedSeeds = new HashMap <>();
3638 private static void addSavedSeed (long seed ) {
37- String key = Minecraft .getInstance ().getConnection ().getConnection ().getRemoteAddress ().toString ();
39+ String key = getCurrentServerKey ();
40+ if (key == null ) {
41+ return ;
42+ }
3843 SavedSeeds .put (key , seed );
3944 }
4045
46+ @ Config
47+ public static boolean AutoApplySeedCrackerSeed = true ;
48+
49+ private static String getCurrentServerKey () {
50+ Minecraft minecraft = Minecraft .getInstance ();
51+ if (minecraft == null || minecraft .getConnection () == null || minecraft .getConnection ().getConnection () == null ) {
52+ return null ;
53+ }
54+ SocketAddress remoteAddress = minecraft .getConnection ().getConnection ().getRemoteAddress ();
55+ return remoteAddress != null ? remoteAddress .toString () : null ;
56+ }
57+
58+ public static void applySeedForCurrentServer (long seed , boolean storeAsSavedSeed ) {
59+ String key = getCurrentServerKey ();
60+ boolean changed = false ;
61+ if (storeAsSavedSeed && key != null && !Objects .equals (SavedSeeds .get (key ), seed )) {
62+ SavedSeeds .put (key , seed );
63+ changed = true ;
64+ }
65+ if (!Objects .equals (Seed , seed )) {
66+ Seed = seed ;
67+ changed = true ;
68+ }
69+ if (changed ) {
70+ save ();
71+ }
72+ }
73+
74+ public static void loadSavedSeedForCurrentServer () {
75+ String key = getCurrentServerKey ();
76+ if (key == null ) {
77+ return ;
78+ }
79+ Long savedSeed = SavedSeeds .get (key );
80+ if (savedSeed != null ) {
81+ applySeedForCurrentServer (savedSeed , false );
82+ }
83+ }
84+
4185 @ Config
4286 public static SeedResolutionArgument .SeedResolution SeedResolutionOrder = new SeedResolutionArgument .SeedResolution ();
4387
0 commit comments