fix lilypad ignoring permission #69

This commit is contained in:
Flemmli97 2021-06-29 18:07:39 +02:00
parent c6921fbf58
commit ec626d78db
3 changed files with 20 additions and 5 deletions

View File

@ -63,8 +63,8 @@ public class ObjectToPermissionMap {
return blockToPermission.get(block);
}
public static ClaimPermission getFromItem(Item block) {
return itemToPermission.get(block);
public static ClaimPermission getFromItem(Item item) {
return itemToPermission.get(item);
}
/**
@ -113,5 +113,6 @@ public class ObjectToPermissionMap {
registerItemPredicateMap(item -> item instanceof BucketItem, () -> PermissionRegistry.BUCKET);
registerItemPredicateMap(item -> item == Items.END_CRYSTAL, () -> PermissionRegistry.ENDCRYSTALPLACE);
registerItemPredicateMap(item -> item == Items.CHORUS_FRUIT, () -> PermissionRegistry.CHORUSFRUIT);
registerItemPredicateMap(item -> item == Items.LILY_PAD, () -> PermissionRegistry.PLACE);
}
}

View File

@ -33,7 +33,7 @@ public class PermissionRegistry {
public static ClaimPermission BREAK = register(new ClaimPermission("BREAK", () -> new ItemStack(Items.DIAMOND_PICKAXE), "Permission to break blocks in the claim"));
public static ClaimPermission PLACE = register(new ClaimPermission("PLACE", () -> new ItemStack(Items.GRASS_BLOCK), "Permission to place blocks in the claim"));
public static ClaimPermission OPENCONTAINER = register(new ClaimPermission("OPENCONTAINER", () -> new ItemStack(Items.CHEST), "Permission to open containers", "(chest, furnace etc.)"));
public static ClaimPermission INTERACTBLOCK = register(new ClaimPermission("INTERACTBLOCK", () -> new ItemStack(Items.CHEST), "Generic permission for block interaction.", "Fallback to OPENCONTAINER", "Gets used for all blocks OPENCONTAINER doesn't check for"));
public static ClaimPermission INTERACTBLOCK = register(new ClaimPermission("INTERACTBLOCK", () -> new ItemStack(Items.GOLD_NUGGET), "Generic permission for block interaction.", "Fallback to OPENCONTAINER", "Gets used for all blocks OPENCONTAINER doesn't check for"));
public static ClaimPermission ANVIL = register(new ClaimPermission("ANVIL", () -> new ItemStack(Items.ANVIL), "Permission to use anvils"));
public static ClaimPermission BED = register(new ClaimPermission("BED", () -> new ItemStack(Items.RED_BED), "Permission to use beds"));
public static ClaimPermission BEACON = register(new ClaimPermission("BEACON", () -> new ItemStack(Items.BEACON), "Permission to use beacons"));

View File

@ -74,8 +74,22 @@ public class ItemInteractEvents {
if (claim == null)
return TypedActionResult.pass(stack);
ClaimPermission perm = ObjectToPermissionMap.getFromItem(stack.getItem());
if (perm != null)
return claim.canInteract(player, perm, pos, true) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
if (perm != null) {
boolean success = claim.canInteract(player, perm, pos, true);
if (success)
return TypedActionResult.pass(stack);
if (perm == PermissionRegistry.PLACE) {
BlockPos update = pos;
if (stack.getItem() == Items.LILY_PAD) {
BlockHitResult upResult = hitResult.withBlockPos(hitResult.getBlockPos().up());
update = new ItemPlacementContext(new ItemUsageContext(player, hand, upResult)).getBlockPos();
}
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(update, world.getBlockState(update)));
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
updateHeldItem(player);
}
return TypedActionResult.fail(stack);
}
return TypedActionResult.pass(stack);
}