Skip to content

Commit

Permalink
allow predicate stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
LemmaEOF committed Feb 9, 2024
1 parent 38559a0 commit dce0cfa
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import net.minecraft.command.EntitySelector;
import net.minecraft.command.EntitySelectorReader;
import net.minecraft.entity.Entity;
import net.minecraft.predicate.NumberRange;
import net.minecraft.text.Text;
import net.modfest.fireblanket.mixinsupport.ForceableArgument;
Expand All @@ -14,6 +15,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.function.Predicate;

/**
* Prevents foot-gunning by using an unlimited @e selector without forcing to assure you know what you're doing
*/
Expand Down Expand Up @@ -41,9 +44,16 @@ public boolean isForced() {
@Inject(method = "read", at = @At("RETURN"))
private void preventFootgun(CallbackInfoReturnable<EntitySelector> info) throws CommandSyntaxException {
if (this.includesNonPlayers
&& (this.limit > 1 && (this.limit > 50 || this.distance == NumberRange.DoubleRange.ANY))
//main anti-footgun: don't allow someone to affect every single entity on the server at once
&& (this.limit > 50 && this.distance == NumberRange.DoubleRange.ANY)
&& !forced) {
throw LIMIT_UNFORCED.create(this.limit);
}
}

@Inject(method = "setPredicate", at = @At("HEAD"))
private void forceWithPredicate(Predicate<Entity> predicate, CallbackInfo info) {
//predicates are a Limiting Factor so it should be good if anything sets them
this.forced = true;
}
}

0 comments on commit dce0cfa

Please sign in to comment.