-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: anti build module + update: github wiki
- Loading branch information
1 parent
393d9e7
commit 4e6bad9
Showing
10 changed files
with
300 additions
and
46 deletions.
There are no files selected for viewing
Submodule fuji-fabric.wiki
updated
from f64745 to 2ebbe2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/io/github/sakurawald/module/mixin/anti_build/BlockMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.sakurawald.module.mixin.anti_build; | ||
|
||
import io.github.sakurawald.config.Configs; | ||
import io.github.sakurawald.util.IdentifierUtil; | ||
import io.github.sakurawald.util.MessageUtil; | ||
import me.lucko.fabric.api.permissions.v0.Permissions; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(BlockItem.class) | ||
public class BlockMixin { | ||
|
||
@Inject(method = "canPlace", at = @At("RETURN"), cancellable = true) | ||
public void $canPlace(ItemPlacementContext itemPlacementContext, BlockState blockState, CallbackInfoReturnable<Boolean> cir) { | ||
PlayerEntity player = itemPlacementContext.getPlayer(); | ||
if (player == null) return; | ||
|
||
String id = IdentifierUtil.getItemStackIdentifier(itemPlacementContext.getStack()); | ||
if (Configs.configHandler.model().modules.anti_build.anti.place_block.id.contains(id) | ||
&& !Permissions.check(player, "fuji.anti_build.%s.bypass.%s".formatted("place_block", id)) | ||
) { | ||
MessageUtil.sendMessageToPlayerEntity(player, "anti_build.disallow"); | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/io/github/sakurawald/module/mixin/anti_build/EntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.sakurawald.module.mixin.anti_build; | ||
|
||
import io.github.sakurawald.config.Configs; | ||
import io.github.sakurawald.util.IdentifierUtil; | ||
import io.github.sakurawald.util.MessageUtil; | ||
import lombok.extern.slf4j.Slf4j; | ||
import me.lucko.fabric.api.permissions.v0.Permissions; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.math.Vec3d; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
|
||
@Mixin(Entity.class) | ||
public class EntityMixin { | ||
@Inject(method = "interact", at = @At("HEAD"), cancellable = true) | ||
void $interact(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir){ | ||
Entity entity = (Entity) (Object) this; | ||
String id = IdentifierUtil.getEntityTypeIdentifier(entity); | ||
|
||
if (Configs.configHandler.model().modules.anti_build.anti.interact_entity.id.contains(id) | ||
&& !Permissions.check(player, "fuji.anti_build.%s.bypass.%s".formatted("interact_entity", id)) | ||
) { | ||
|
||
if (hand == Hand.MAIN_HAND) { | ||
MessageUtil.sendMessageToPlayerEntity(player, "anti_build.disallow"); | ||
} | ||
|
||
cir.setReturnValue(ActionResult.FAIL); | ||
} | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...ava/io/github/sakurawald/module/mixin/anti_build/ServerPlayerInteractionManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.github.sakurawald.module.mixin.anti_build; | ||
|
||
import io.github.sakurawald.config.Configs; | ||
import io.github.sakurawald.util.IdentifierUtil; | ||
import io.github.sakurawald.util.MessageUtil; | ||
import me.lucko.fabric.api.permissions.v0.Permissions; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.server.network.ServerPlayerInteractionManager; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(ServerPlayerInteractionManager.class) | ||
public class ServerPlayerInteractionManagerMixin { | ||
|
||
@Shadow | ||
protected ServerWorld world; | ||
|
||
@Shadow | ||
@Final | ||
protected ServerPlayerEntity player; | ||
|
||
@Inject(method = "tryBreakBlock", at = @At("HEAD"), cancellable = true) | ||
void $tryBreak(BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) { | ||
BlockState blockState = this.world.getBlockState(blockPos); | ||
|
||
String id = IdentifierUtil.getBlockStateIdentifier(blockState); | ||
if (Configs.configHandler.model().modules.anti_build.anti.break_block.id.contains(id) | ||
&& !Permissions.check(player, "fuji.anti_build.%s.bypass.%s".formatted("break_block", id)) | ||
) { | ||
MessageUtil.sendMessage(player, "anti_build.disallow"); | ||
cir.setReturnValue(false); | ||
} | ||
|
||
} | ||
|
||
@Inject(method = "interactItem", at = @At("HEAD"), cancellable = true) | ||
void $interactItem(ServerPlayerEntity serverPlayerEntity, World world, ItemStack itemStack, Hand hand, CallbackInfoReturnable<ActionResult> cir) { | ||
String id = IdentifierUtil.getItemStackIdentifier(itemStack); | ||
|
||
if (Configs.configHandler.model().modules.anti_build.anti.interact_item.id.contains(id) | ||
&& !Permissions.check(player, "fuji.anti_build.%s.bypass.%s".formatted("interact_item", id)) | ||
) { | ||
MessageUtil.sendMessage(player, "anti_build.disallow"); | ||
cir.setReturnValue(ActionResult.FAIL); | ||
} | ||
} | ||
|
||
@Inject(method = "interactBlock", at = @At("HEAD"), cancellable = true) | ||
void $interactBlock(ServerPlayerEntity serverPlayerEntity, World world, ItemStack itemStack, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable<ActionResult> cir) { | ||
BlockPos blockPos = blockHitResult.getBlockPos(); | ||
BlockState blockState = world.getBlockState(blockPos); | ||
String id = IdentifierUtil.getBlockStateIdentifier(blockState); | ||
|
||
if (Configs.configHandler.model().modules.anti_build.anti.interact_block.id.contains(id) | ||
&& !Permissions.check(player, "fuji.anti_build.%s.bypass.%s".formatted("interact_block", id)) | ||
) { | ||
MessageUtil.sendMessage(player, "anti_build.disallow"); | ||
cir.setReturnValue(ActionResult.FAIL); | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/sakurawald/util/IdentifierUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.sakurawald.util; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.registry.Registries; | ||
|
||
@UtilityClass | ||
public class IdentifierUtil { | ||
|
||
public static String getItemStackIdentifier(ItemStack itemStack) { | ||
Item item = itemStack.getItem().asItem(); | ||
return Registries.ITEM.getId(item).toString(); | ||
} | ||
|
||
public static String getBlockStateIdentifier(BlockState blockState) { | ||
return getBlockIdentifier(blockState.getBlock()); | ||
} | ||
|
||
public static String getBlockIdentifier(Block block) { | ||
return Registries.BLOCK.getId(block).toString(); | ||
} | ||
public static String getEntityTypeIdentifier(Entity entity) { | ||
return Registries.ENTITY_TYPE.getId(entity.getType()).toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.