Skip to content

Commit

Permalink
Enforced the "Creative Bypass" config option when testing player for …
Browse files Browse the repository at this point in the history
…Creative mode in "Can player do" method

Removed a redundant Claims check
  • Loading branch information
GStefanowich committed Apr 20, 2021
1 parent 7e8c695 commit 7823a46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx2G
loader_version=0.11.0

# Mod Properties
mod_version = 1.3.1
mod_version = 1.3.2
maven_group = net.fabricmc
archives_base_name = theelm-mod

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,32 @@ private static ActionResult blockInteract(ServerPlayerEntity player, World world
return ActionResult.FAIL;
}

// If claiming is enabled, check the players permission
if (!(player.isCreative() && SewConfig.get(SewConfig.CLAIM_CREATIVE_BYPASS)) && (SewConfig.get(SewConfig.DO_CLAIMS))) {
// If the block is something that can be accessed (Like a chest)
if ( (!player.isSneaking() || (!(itemStack.getItem() instanceof BlockItem || itemStack.getItem() instanceof BucketItem))) ) {
if ( player.isSpectator() || (blockEntity instanceof EnderChestBlockEntity))
return ActionResult.PASS;
// If the block is something that can be accessed (Like a chest)
if ( (!player.isSneaking() || (!(itemStack.getItem() instanceof BlockItem || itemStack.getItem() instanceof BucketItem))) ) {
if ( player.isSpectator() || (blockEntity instanceof EnderChestBlockEntity))
return ActionResult.PASS;

if ((((blockPermission = EntityUtils.getLockPermission(blockEntity)) != null) || ((blockPermission = EntityUtils.getLockPermission(block)) != null))) {
WorldChunk claimedChunkInfo = player.getEntityWorld().getWorldChunk(blockPos);

if ((((blockPermission = EntityUtils.getLockPermission(blockEntity)) != null) || ((blockPermission = EntityUtils.getLockPermission( block )) != null))) {
WorldChunk claimedChunkInfo = player.getEntityWorld().getWorldChunk(blockPos);

// Check if allowed to open storages in this location
if (ChunkUtils.canPlayerDoInChunk(blockPermission, player, claimedChunkInfo, blockPos)) {
// Check if the chest is NOT part of a shop, Or the player owns that shop
ShopSignBlockEntity shopSign;
if ((!EntityUtils.isValidShopContainer(blockEntity)) || ((shopSign = EntityUtils.getAttachedShopSign(world, blockPos)) == null) || player.getUuid().equals(shopSign.getShopOwner()))
return ActionResult.PASS;
}

// Play a sound to the player
world.playSound(null, blockPos, EntityUtils.getLockSound(block, blockState, blockEntity), SoundCategory.BLOCKS, 0.5f, 1f);

// Display that this item can't be opened
TitleUtils.showPlayerAlert(player, Formatting.WHITE, TranslatableServerSide.text(player, "claim.block.locked",
EntityUtils.getLockedName(block),
(claimedChunkInfo == null ? new LiteralText("unknown player").formatted(Formatting.LIGHT_PURPLE) : ((IClaimedChunk) claimedChunkInfo).getOwnerName(player, blockPos))
));

return ActionResult.FAIL;
// Check if allowed to open storages in this location
if (ChunkUtils.canPlayerDoInChunk(blockPermission, player, claimedChunkInfo, blockPos)) {
// Check if the chest is NOT part of a shop, Or the player owns that shop
ShopSignBlockEntity shopSign;
if ((!EntityUtils.isValidShopContainer(blockEntity)) || ((shopSign = EntityUtils.getAttachedShopSign(world, blockPos)) == null) || player.getUuid().equals(shopSign.getShopOwner()))
return ActionResult.PASS;
}

// Play a sound to the player
world.playSound(null, blockPos, EntityUtils.getLockSound(block, blockState, blockEntity), SoundCategory.BLOCKS, 0.5f, 1f);

// Display that this item can't be opened
TitleUtils.showPlayerAlert(player, Formatting.WHITE, TranslatableServerSide.text(player, "claim.block.locked",
EntityUtils.getLockedName(block),
(claimedChunkInfo == null ? new LiteralText("unknown player").formatted(Formatting.LIGHT_PURPLE) : ((IClaimedChunk) claimedChunkInfo).getOwnerName(player, blockPos))
));

return ActionResult.FAIL;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/TheElm/project/utilities/ChunkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static boolean canPlayerDoInChunk(@Nullable ClaimPermissions perm, @NotNu
}
public static boolean canPlayerDoInChunk(@Nullable ClaimPermissions perm, @Nullable PlayerEntity player, @Nullable WorldChunk chunk, @NotNull BlockPos blockPos) {
// If claims are disabled
if ((!SewConfig.get(SewConfig.DO_CLAIMS)) || (player != null && player.isCreative())) return true;
if ((!SewConfig.get(SewConfig.DO_CLAIMS)) || (player != null && player.isCreative() && SewConfig.get(SewConfig.CLAIM_CREATIVE_BYPASS)))
return true;

// Check if player can do action in chunk
return ChunkUtils.canPlayerDoInChunk( perm, EntityUtils.getUUID(player), chunk, blockPos );
Expand Down

0 comments on commit 7823a46

Please sign in to comment.