Skip to content

Commit

Permalink
Changed mappings checking to be done against a remote server instead …
Browse files Browse the repository at this point in the history
…of hardcoded values
  • Loading branch information
OmerBenGera committed Aug 6, 2022
1 parent afc2959 commit e122819
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 28 deletions.
1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -57,6 +57,7 @@ dependencies {

implementation 'com.bgsoftware.common.config:CommentedConfiguration:1.0.3'
implementation 'com.bgsoftware.common.updater:Updater:latest'
implementation 'com.bgsoftware.common.mappings:MappingsChecker:1.0.0'
implementation 'com.bgsoftware.common.reflection:ReflectionUtils:1.0.2'
implementation 'com.bgsoftware.common.executors:Executors:1.0.1'

Expand Down
@@ -1,5 +1,6 @@
package com.bgsoftware.superiorskyblock;

import com.bgsoftware.common.mappings.MappingsChecker;
import com.bgsoftware.common.updater.Updater;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblock;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
Expand Down Expand Up @@ -68,6 +69,7 @@
import com.bgsoftware.superiorskyblock.nms.NMSPlayers;
import com.bgsoftware.superiorskyblock.nms.NMSTags;
import com.bgsoftware.superiorskyblock.nms.NMSWorld;
import com.bgsoftware.superiorskyblock.nms.mapping.TestRemaps;
import com.bgsoftware.superiorskyblock.player.PlayersManagerImpl;
import com.bgsoftware.superiorskyblock.player.container.DefaultPlayersContainer;
import com.bgsoftware.superiorskyblock.service.ServicesHandler;
Expand Down Expand Up @@ -382,11 +384,11 @@ private boolean loadNMSAdapter() {
try {
nmsAlgorithms = loadNMSClass("NMSAlgorithmsImpl", version);

if (!nmsAlgorithms.isMappingsSupported()) {
new ManagerLoadException(
"The plugin doesn't support your version mappings.\n" +
"Please try a different version.",
ManagerLoadException.ErrorLevel.SERVER_SHUTDOWN).printStackTrace();
String mappingVersionHash = nmsAlgorithms.getMappingsHash();

if (mappingVersionHash != null && !MappingsChecker.checkMappings(mappingVersionHash, version)) {
new ManagerLoadException("The plugin doesn't support your version mappings.\nPlease try a different version.\n" +
"Mappings Hash: " + mappingVersionHash, ManagerLoadException.ErrorLevel.SERVER_SHUTDOWN).printStackTrace();
return false;
}

Expand All @@ -406,6 +408,16 @@ private boolean loadNMSAdapter() {
return false;
}

File mappingsFile = new File("mappings");
if (mappingsFile.exists()) {
try {
TestRemaps.testRemapsForClassesInPackage(mappingsFile,
plugin.getClassLoader(), "com.bgsoftware.superiorskyblock.nms." + version);
} catch (Exception error) {
error.printStackTrace();
}
}

return true;
}

Expand Down
Expand Up @@ -18,7 +18,8 @@

public interface NMSAlgorithms {

boolean isMappingsSupported();
@Nullable
String getMappingsHash();

void registerCommand(BukkitCommand command);

Expand Down
Expand Up @@ -29,6 +29,8 @@
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionEffect;

import javax.annotation.Nullable;

public class NMSAlgorithmsImpl implements NMSAlgorithms {

private final SuperiorSkyblockPlugin plugin;
Expand All @@ -37,9 +39,10 @@ public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Nullable
@Override
public boolean isMappingsSupported() {
return true;
public String getMappingsHash() {
return null;
}

@Override
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;

import javax.annotation.Nullable;
import java.util.EnumMap;
import java.util.function.BiFunction;

Expand All @@ -57,9 +58,10 @@ public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Nullable
@Override
public boolean isMappingsSupported() {
return true;
public String getMappingsHash() {
return null;
}

@Override
Expand Down
Expand Up @@ -51,17 +51,15 @@ public class NMSAlgorithmsImpl implements NMSAlgorithms {
MENUS_HOLDER_CREATORS.put(InventoryType.SMOKER, MenuTileEntityFurnace::new);
}

private static final String BUILT_AGAINST_MAPPING = "acd6e6c27e5a0a9440afba70a96c27c9";

private final SuperiorSkyblockPlugin plugin;

public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
public String getMappingsHash() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion();
}

@Override
Expand Down
Expand Up @@ -51,17 +51,15 @@ public final class NMSAlgorithmsImpl implements NMSAlgorithms {
MENUS_HOLDER_CREATORS.put(InventoryType.SMOKER, MenuTileEntityFurnace::new);
}

private static final String BUILT_AGAINST_MAPPING = "20b026e774dbf715e40a0b2afe114792";

private final SuperiorSkyblockPlugin plugin;

public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
public String getMappingsHash() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion();
}

@Override
Expand Down
Expand Up @@ -51,17 +51,15 @@ public final class NMSAlgorithmsImpl implements NMSAlgorithms {
MENUS_HOLDER_CREATORS.put(InventoryType.SMOKER, MenuTileEntityFurnace::new);
}

private static final String BUILT_AGAINST_MAPPING = "eaeedbff51b16ead3170906872fda334";

private final SuperiorSkyblockPlugin plugin;

public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
public String getMappingsHash() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion();
}

@Override
Expand Down
Expand Up @@ -51,17 +51,15 @@ public final class NMSAlgorithmsImpl implements NMSAlgorithms {
MENUS_HOLDER_CREATORS.put(InventoryType.SMOKER, MenuTileEntityFurnace::new);
}

private static final String BUILT_AGAINST_MAPPING = "4cc0cc97cac491651bff3af8b124a214";

private final SuperiorSkyblockPlugin plugin;

public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Override
public boolean isMappingsSupported() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion().equals(BUILT_AGAINST_MAPPING);
public String getMappingsHash() {
return ((CraftMagicNumbers) CraftMagicNumbers.INSTANCE).getMappingsVersion();
}

@Override
Expand Down
Expand Up @@ -29,6 +29,8 @@
import org.bukkit.material.MaterialData;
import org.bukkit.potion.PotionEffect;

import javax.annotation.Nullable;

public class NMSAlgorithmsImpl implements NMSAlgorithms {

private final SuperiorSkyblockPlugin plugin;
Expand All @@ -37,9 +39,10 @@ public NMSAlgorithmsImpl(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
}

@Nullable
@Override
public boolean isMappingsSupported() {
return true;
public String getMappingsHash() {
return null;
}

@Override
Expand Down

0 comments on commit e122819

Please sign in to comment.