From 5078ace15340f312d298552c4a664eab6519d7d8 Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Thu, 21 Jan 2021 21:12:42 +0100 Subject: [PATCH] enderchest, enchantment table, piston and water permission close #26 --- .../flan/api/PermissionRegistry.java | 6 ++++- .../flan/claim/BlockToPermissionMap.java | 6 +++++ .../flan/event/BlockInteractEvents.java | 17 ++++++------ .../com/flemmli97/flan/event/WorldEvents.java | 26 ++++++++----------- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/flemmli97/flan/api/PermissionRegistry.java b/src/main/java/com/flemmli97/flan/api/PermissionRegistry.java index d045c08..547cbfa 100644 --- a/src/main/java/com/flemmli97/flan/api/PermissionRegistry.java +++ b/src/main/java/com/flemmli97/flan/api/PermissionRegistry.java @@ -30,7 +30,7 @@ public class PermissionRegistry { public static ClaimPermission EDITPERMS = register(new ClaimPermission("EDITPERMS", () -> new ItemStack(Items.COMMAND_BLOCK), "Gives permission to change the claims permissions")); 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 OPENCONTAINER = register(new ClaimPermission("OPENCONTAINER", () -> new ItemStack(Items.CHEST), "Permission to open containers", "(chest, furnace etc.)")); 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")); @@ -42,6 +42,8 @@ public class PermissionRegistry { public static ClaimPermission NOTEBLOCK = register(new ClaimPermission("NOTEBLOCK", () -> new ItemStack(Items.NOTE_BLOCK), "Permission to change noteblocks")); public static ClaimPermission REDSTONE = register(new ClaimPermission("REDSTONE", () -> new ItemStack(Items.REDSTONE), "Permission to change redstone components")); public static ClaimPermission JUKEBOX = register(new ClaimPermission("JUKEBOX", () -> new ItemStack(Items.JUKEBOX), "Permission to insert/take music discs")); + public static ClaimPermission ENDERCHEST = register(new ClaimPermission("ENDERCHEST", () -> new ItemStack(Items.ENDER_CHEST), "Permission to use enderchests")); + public static ClaimPermission ENCHANTMENTTABLE = register(new ClaimPermission("ENCHANTMENT", () -> new ItemStack(Items.ENCHANTING_TABLE), "Permission to use enchanting tables")); public static ClaimPermission ITEMFRAMEROTATE = register(new ClaimPermission("ITEMFRAMEROTATE", () -> new ItemStack(Items.ITEM_FRAME), "Permission to rotate items in item frames")); public static ClaimPermission LECTERNTAKE = register(new ClaimPermission("LECTERNTAKE", () -> new ItemStack(Items.LECTERN), "Permission to change books in a lectern")); public static ClaimPermission ENDCRYSTALPLACE = register(new ClaimPermission("ENDCRYSTALPLACE", () -> new ItemStack(Items.END_CRYSTAL), "Permission to place end crystals")); @@ -64,6 +66,8 @@ public class PermissionRegistry { public static ClaimPermission EXPLOSIONS = global(new ClaimPermission("EXPLOSIONS", () -> new ItemStack(Items.TNT), "Toggle explosions in claim")); public static ClaimPermission WITHER = global(new ClaimPermission("WITHER", () -> new ItemStack(Items.WITHER_SKELETON_SKULL), "Toggle wither breaking blocks in claim")); public static ClaimPermission FIRESPREAD = global(new ClaimPermission("FIRESPREAD", () -> new ItemStack(Items.BLAZE_POWDER), "Toggle firespread in claim")); + public static ClaimPermission WATERBORDER = global(new ClaimPermission("WATERBORDER", () -> new ItemStack(Items.WATER_BUCKET), "Toggle water crossing claim borders")); + public static ClaimPermission PISTONBORDER = global(new ClaimPermission("PISTONBORDER", () -> new ItemStack(Items.PISTON), "Toggle piston pull/push across claim borders")); public static ClaimPermission MOBSPAWN = global(new ClaimPermission("MOBSPAWN", () -> new ItemStack(Items.ZOMBIE_SPAWN_EGG), "Prevent mobspawn in claim")); private static ClaimPermission register(ClaimPermission perm) { diff --git a/src/main/java/com/flemmli97/flan/claim/BlockToPermissionMap.java b/src/main/java/com/flemmli97/flan/claim/BlockToPermissionMap.java index 53644db..a3a8f92 100644 --- a/src/main/java/com/flemmli97/flan/claim/BlockToPermissionMap.java +++ b/src/main/java/com/flemmli97/flan/claim/BlockToPermissionMap.java @@ -15,6 +15,8 @@ import net.minecraft.block.CampfireBlock; import net.minecraft.block.ChorusFlowerBlock; import net.minecraft.block.DaylightDetectorBlock; import net.minecraft.block.DoorBlock; +import net.minecraft.block.EnchantingTableBlock; +import net.minecraft.block.EnderChestBlock; import net.minecraft.block.FarmlandBlock; import net.minecraft.block.FenceGateBlock; import net.minecraft.block.JukeboxBlock; @@ -69,6 +71,10 @@ public class BlockToPermissionMap { if (block instanceof BellBlock || block instanceof CampfireBlock || block instanceof TntBlock || block instanceof ChorusFlowerBlock) blockToPermission.put(block, PermissionRegistry.PROJECTILES); + if (block instanceof EnderChestBlock) + blockToPermission.put(block, PermissionRegistry.ENDERCHEST); + if (block instanceof EnchantingTableBlock) + blockToPermission.put(block, PermissionRegistry.ENCHANTMENTTABLE); } } diff --git a/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java b/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java index 1de1f76..e9eab87 100644 --- a/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java +++ b/src/main/java/com/flemmli97/flan/event/BlockInteractEvents.java @@ -112,19 +112,18 @@ public class BlockInteractEvents { if (world.isClient) return false; ServerPlayerEntity player = null; - if(entity instanceof ServerPlayerEntity) + if (entity instanceof ServerPlayerEntity) player = (ServerPlayerEntity) entity; - else if(entity instanceof ProjectileEntity) { + else if (entity instanceof ProjectileEntity) { Entity owner = ((ProjectileEntity) entity).getOwner(); - if(owner instanceof ServerPlayerEntity) + if (owner instanceof ServerPlayerEntity) + player = (ServerPlayerEntity) owner; + } else if (entity instanceof ItemEntity) { + Entity owner = ((ServerWorld) world).getEntity(((ItemEntity) entity).getThrower()); + if (owner instanceof ServerPlayerEntity) player = (ServerPlayerEntity) owner; } - else if(entity instanceof ItemEntity) { - Entity owner = ((ServerWorld)world).getEntity(((ItemEntity) entity).getThrower()); - if(owner instanceof ServerPlayerEntity) - player = (ServerPlayerEntity) owner; - } - if(player == null) + if (player == null) return false; ClaimPermission perm = BlockToPermissionMap.getFromBlock(state.getBlock()); if (perm == null) diff --git a/src/main/java/com/flemmli97/flan/event/WorldEvents.java b/src/main/java/com/flemmli97/flan/event/WorldEvents.java index e7bc662..a3ed345 100644 --- a/src/main/java/com/flemmli97/flan/event/WorldEvents.java +++ b/src/main/java/com/flemmli97/flan/event/WorldEvents.java @@ -5,7 +5,6 @@ import com.flemmli97.flan.claim.ClaimStorage; import com.flemmli97.flan.claim.IPermissionContainer; import com.flemmli97.flan.config.ConfigHandler; import net.minecraft.block.BlockState; -import net.minecraft.block.piston.PistonBehavior; import net.minecraft.entity.mob.MobEntity; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -28,23 +27,23 @@ public class WorldEvents { } public static boolean pistonCanPush(BlockState state, World world, BlockPos blockPos, Direction direction, Direction pistonDir) { - if (world.isClient || direction == Direction.UP || direction == Direction.DOWN) + if (world.isClient || state.isAir()) return true; - boolean empty = state.isAir() || state.getPistonBehavior() == PistonBehavior.DESTROY; BlockPos dirPos = blockPos.offset(direction); ClaimStorage storage = ClaimStorage.get((ServerWorld) world); IPermissionContainer from = storage.getForPermissionCheck(blockPos); IPermissionContainer to = storage.getForPermissionCheck(dirPos); boolean flag = true; - if (!empty) { - if ((from != null && !from.equals(to)) || (from == null && to != null)) - flag = false; - } - if (from != null && from.equals(to)) { - IPermissionContainer opp = storage.getForPermissionCheck(blockPos.offset(direction.getOpposite())); - flag = from.equals(opp); - } + if (from.equals(to)) { + BlockPos oppPoos = blockPos.offset(direction.getOpposite()); + IPermissionContainer opp = storage.getForPermissionCheck(oppPoos); + if (!from.equals(opp)) + flag = from.canInteract(null, PermissionRegistry.PISTONBORDER, oppPoos); + } else + flag = from.canInteract(null, PermissionRegistry.PISTONBORDER, blockPos) && to.canInteract(null, PermissionRegistry.PISTONBORDER, dirPos); if (!flag) { + //Idk enough about piston behaviour to update more blocks when slime is involved. + //Ghost blocks appear when trying to push slime contraptions across border world.updateListeners(blockPos, state, state, 20); BlockState toState = world.getBlockState(dirPos); world.updateListeners(dirPos, toState, toState, 20); @@ -58,10 +57,7 @@ public class WorldEvents { ClaimStorage storage = ClaimStorage.get((ServerWorld) world); IPermissionContainer from = storage.getForPermissionCheck(blockPos); IPermissionContainer to = storage.getForPermissionCheck(blockPos.offset(direction)); - boolean fl = from == null && to == null; - if (from != null) - fl = from.equals(to); - return fl; + return from.equals(to) || to.canInteract(null, PermissionRegistry.WATERBORDER, blockPos); } public static boolean canStartRaid(ServerPlayerEntity player) {