generated from Fallen-Breath/fabric-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
RestrictiveMixinConfigPlugin.java
54 lines (46 loc) · 1.77 KB
/
RestrictiveMixinConfigPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package me.fallenbreath.conditionalmixin.api.mixin;
import me.fallenbreath.conditionalmixin.api.annotation.Restriction;
import me.fallenbreath.conditionalmixin.api.checker.RestrictionChecker;
import me.fallenbreath.conditionalmixin.api.checker.RestrictionCheckers;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
/**
* A simple class that handle the {@link me.fallenbreath.conditionalmixin.api.annotation.Restriction} annotation
* Make your custom MixinConfigPlugin extends this class and that's it, you have conditional mixin now
*/
public abstract class RestrictiveMixinConfigPlugin implements IMixinConfigPlugin
{
protected final RestrictionChecker restrictionChecker = RestrictionCheckers.memorized();
private final AnnotationCleaner annotationCleaner = AnnotationCleaner.create(Restriction.class);
public RestrictiveMixinConfigPlugin()
{
this.restrictionChecker.setFailureCallback(this::onRestrictionCheckFailed);
}
@Override
public void onLoad(String mixinPackage)
{
// in case
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName)
{
return this.restrictionChecker.checkRestriction(mixinClassName);
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo)
{
this.annotationCleaner.onPreApply(targetClass);
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo)
{
this.annotationCleaner.onPostApply(targetClass);
}
/**
* go override it and do something you want, e.g. logging
*/
protected void onRestrictionCheckFailed(String mixinClassName, String reason)
{
}
}