|
| 1 | +package net.modgarden.flowerbed.mixin.showcase.griefing.prevent_modfest_1_20; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.sugar.Local; |
| 4 | +import com.mojang.brigadier.StringReader; |
| 5 | +import com.mojang.brigadier.exceptions.CommandSyntaxException; |
| 6 | +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; |
| 7 | +import net.minecraft.commands.arguments.EntityArgument; |
| 8 | +import net.minecraft.commands.arguments.selector.EntitySelector; |
| 9 | +import net.minecraft.commands.arguments.selector.EntitySelectorParser; |
| 10 | +import net.minecraft.network.chat.Component; |
| 11 | +import net.modgarden.flowerbed.duck.Duck_ExtESP; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Unique; |
| 14 | +import org.spongepowered.asm.mixin.injection.At; |
| 15 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 17 | + |
| 18 | +@Mixin(EntityArgument.class) |
| 19 | +public class Mixin_EntityArgument { |
| 20 | + @Unique |
| 21 | + private static final SimpleCommandExceptionType E_NOT_ALLOWED = new SimpleCommandExceptionType(Component.translatable("argument.flowerbed.e_not_allowed")); |
| 22 | + |
| 23 | + @Inject( |
| 24 | + method = "parse(Lcom/mojang/brigadier/StringReader;Z)Lnet/minecraft/commands/arguments/selector/EntitySelector;", |
| 25 | + at = @At("TAIL") |
| 26 | + ) |
| 27 | + private void flowerbed$preventModfest120( |
| 28 | + StringReader reader, |
| 29 | + boolean allowSelectors, |
| 30 | + CallbackInfoReturnable<EntitySelector> cir, |
| 31 | + @Local EntitySelector entitySelector, |
| 32 | + @Local EntitySelectorParser entitySelectorParser |
| 33 | + ) throws CommandSyntaxException { |
| 34 | + if (!entitySelector.includesEntities() || entitySelector.isSelfSelector()) return; |
| 35 | + |
| 36 | + boolean unaware = !((Duck_ExtESP) entitySelectorParser) |
| 37 | + .flowerbed$theUserUnderstandsTheConsequencesOfTheirActions(); |
| 38 | + if (unaware) { |
| 39 | + throw E_NOT_ALLOWED.createWithContext(reader); |
| 40 | + } |
| 41 | + } |
| 42 | +} |
0 commit comments