enderchest, enchantment table, piston and water permission close #26

This commit is contained in:
Flemmli97 2021-01-21 21:12:42 +01:00
parent 07c3c1a69f
commit 5078ace153
4 changed files with 30 additions and 25 deletions

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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) {