Validate mod ids

This commit is contained in:
ichttt 2019-01-20 17:36:38 +01:00 committed by cpw
parent 7c840dce35
commit 276d0c49c1
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7

View file

@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.regex.Pattern;
/**
* The container that wraps around mods in the system.
@ -45,13 +46,17 @@ import java.util.function.Supplier;
public abstract class ModContainer
{
private static final Pattern VALID_MODIDS = Pattern.compile("^[a-z0-9_-]{3,64}$");
protected final String modId;
protected final IModInfo modInfo;
protected ModLoadingStage modLoadingStage;
protected final Map<ModLoadingStage, Consumer<LifecycleEventProvider.LifecycleEvent>> triggerMap;
protected final Map<ExtensionPoint, Supplier<?>> extensionPoints = new IdentityHashMap<>();
public ModContainer(IModInfo info)
{
if (!VALID_MODIDS.matcher(info.getModId()).matches())
throw new IllegalArgumentException("Invalid modid " + info.getModId() + "! Mod ids need to be lowercase alphanumeric characters or '-'/'_' and need to be between 3 and 64 chars long.");
this.modId = info.getModId();
this.modInfo = info;
this.triggerMap = new HashMap<>();