diff --git a/pom.xml b/pom.xml index e3501e4..0db0f17 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.mcmiddleearth MCME-Architect - 2.9.7 + 2.9.8 jar UTF-8 diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/SpecialBlockType.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/SpecialBlockType.java index 1982deb..923a351 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/SpecialBlockType.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/SpecialBlockType.java @@ -62,6 +62,7 @@ public enum SpecialBlockType { DOUBLE_Y_BLOCK, UPSHIFT, VANILLA, + MULTI_FACE, DOOR_VANILLA, DOOR_THREE_BLOCKS, DOOR_FOUR_BLOCKS //("threeAxis"); diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java index 8be82f8..82d2d72 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/data/SpecialBlockInventoryData.java @@ -294,6 +294,9 @@ private static void loadFromFile(String rpName, File file) { case UPSHIFT: blockData = SpecialBlockUpshift.loadFromConfig(section, fullName(rpName, itemKey)); break; + case MULTI_FACE: + blockData = SpecialBlockMultiFace.loadFromConfig(section, fullName(rpName, itemKey)); + break; case VANILLA: blockData = SpecialBlockVanilla.loadFromConfig(section, fullName(rpName, itemKey)); break; diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/LightBlockListener.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/LightBlockListener.java index e9708b0..894574e 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/LightBlockListener.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/LightBlockListener.java @@ -15,15 +15,16 @@ public void changeLightLevel(PlayerInteractEvent event) { Block block = event.getClickedBlock(); if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock()!=null - && TheGafferUtil.checkGafferPermission(event.getPlayer(),event.getClickedBlock().getLocation()) && block!=null && block.getBlockData() instanceof Light lightData) { event.setCancelled(true); - if(event.getPlayer().isSneaking()) { - lightData.setLevel((lightData.getLevel() + 15)%16); - } else { - lightData.setLevel((lightData.getLevel() + 1)%16); + if(TheGafferUtil.checkGafferPermission(event.getPlayer(),event.getClickedBlock().getLocation())) { + if (event.getPlayer().isSneaking()) { + lightData.setLevel((lightData.getLevel() + 15) % 16); + } else { + lightData.setLevel((lightData.getLevel() + 1) % 16); + } + block.setBlockData(lightData, true); } - block.setBlockData(lightData,true); } } } diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/SpecialBlockListener.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/SpecialBlockListener.java index 52b5766..39cf954 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/SpecialBlockListener.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/listener/SpecialBlockListener.java @@ -153,30 +153,24 @@ public void run() { player.getInventory().setItemInOffHand(offHandItem); } }.runTaskLater(ArchitectPlugin.getPluginInstance(), 1); -//Logger.getGlobal().info("get Block"); Block blockPlace = data.getBlock(event.getClickedBlock(), event.getBlockFace(), event.getInteractionPoint(), player); +//Logger.getGlobal().info("get Block: "+blockPlace.getLocation()); /*if(data instanceof SpecialBlockOnWater) { blockPlace = player.getTargetBlockExact(4, FluidCollisionMode.ALWAYS).getRelative(BlockFace.UP); } else { blockPlace = event.getClickedBlock().getRelative(event.getBlockFace()); }*/ - if(!(player.isSneaking() && data.isEditOnSneaking()) - && (!blockPlace.isEmpty() - && !blockPlace.getType().equals(Material.GRASS) - && !blockPlace.getType().equals(Material.FIRE) - && !blockPlace.getType().equals(Material.LAVA) - && !blockPlace.getType().equals(Material.WATER) - )) { - return; - } - Location permissionLocation = ((player.isSneaking() && data.isEditOnSneaking())? - event.getClickedBlock().getLocation(): - blockPlace.getLocation()); - if(!TheGafferUtil.hasGafferPermission(player,blockPlace.getLocation())) { - return; - } + if((player.isSneaking() && data.isEditOnSneaking()) + || data.canPlace(blockPlace)) { + Location permissionLocation = ((player.isSneaking() && data.isEditOnSneaking())? + event.getClickedBlock().getLocation(): + blockPlace.getLocation()); + if(!TheGafferUtil.hasGafferPermission(player,blockPlace.getLocation())) { + return; + } //Logger.getGlobal().info("Block place"); - data.placeBlock(blockPlace, event.getBlockFace(), event.getClickedBlock(), event.getInteractionPoint(), player); + data.placeBlock(blockPlace, event.getBlockFace(), event.getClickedBlock(), event.getInteractionPoint(), player); + } } /** diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlock.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlock.java index c532271..a7aaec2 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlock.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlock.java @@ -168,7 +168,15 @@ protected BlockState getBlockState(Block blockPlace, Block clicked, BlockFace bl state.setBlockData(blockData); return state; } - + + public boolean canPlace(Block blockPlace) { + return blockPlace.isEmpty() + || blockPlace.getType().equals(Material.GRASS) + || blockPlace.getType().equals(Material.FIRE) + || blockPlace.getType().equals(Material.LAVA) + || blockPlace.getType().equals(Material.WATER); + } + protected static Material matchMaterial(String identifier) { if(NumericUtil.isInt(identifier)) { return LegacyMaterialUtil.getMaterial(NumericUtil.getInt(identifier)); diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockBranchTwigs.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockBranchTwigs.java index 297d679..a79250e 100644 --- a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockBranchTwigs.java +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockBranchTwigs.java @@ -42,6 +42,8 @@ protected SpecialBlockBranchTwigs(String id, String[] variants, super(id,variants, data, SpecialBlockType.BRANCH_TWIGS); if(lowerShift!=null) { this.lowerShift = lowerShift; + } + if(upperShift!=null) { this.upperShift = upperShift; } } @@ -55,7 +57,7 @@ public Block getBlock(Block clicked, BlockFace blockFace, Location interactionPo @Override public Shift getLower(BlockFace orientation, Block clicked, Player player, Location interactionPoint) { -Logger.getGlobal().info("Shift twig: "+lowerShift.getX()+" "+lowerShift.getY()+" "+lowerShift.getZ()); +//Logger.getGlobal().info("Shift twig: "+lowerShift.getX()+" "+lowerShift.getY()+" "+lowerShift.getZ()); Shift shift = lowerShift; if(getVariant(null, null, null, player, interactionPoint)==1) { shift = upperShift; diff --git a/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockMultiFace.java b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockMultiFace.java new file mode 100644 index 0000000..d8a70a7 --- /dev/null +++ b/src/main/java/com/mcmiddleearth/architect/specialBlockHandling/specialBlocks/SpecialBlockMultiFace.java @@ -0,0 +1,104 @@ +package com.mcmiddleearth.architect.specialBlockHandling.specialBlocks; + +import com.mcmiddleearth.architect.specialBlockHandling.SpecialBlockType; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.MultipleFacing; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +public class SpecialBlockMultiFace extends SpecialBlock { + + protected SpecialBlockMultiFace(String id, BlockData data) { + super(id, data, SpecialBlockType.MULTI_FACE); + } + + public static SpecialBlock loadFromConfig(ConfigurationSection config, String id) { + BlockData data; + try { + String configData = config.getString("blockData", ""); + data = Bukkit.getServer().createBlockData(null,configData); +//Logger.getGlobal().info("configData: "+configData); +//Logger.getGlobal().info("LoadData: "+data.getClass().getSimpleName()+ " "+(data instanceof MultipleFacing)); + if(data instanceof MultipleFacing multiData) { + /*for(BlockFace face: multiData.getAllowedFaces()) { + multiData.setFace(face,false); + }*/ + return new SpecialBlockMultiFace(id, data); + } else { + return null; + } + } catch(IllegalArgumentException e) { + return null; + } + } + + @Override + protected BlockState getBlockState(Block blockPlace, Block clicked, BlockFace blockFace, + Player player, Location interactionPoint) { + BlockData data = blockPlace.getBlockData(); + boolean newBlock = false; +//Logger.getGlobal().info("BlockData1: "+data); + if(!data.getMaterial().equals(getBlockData().getMaterial())) { + data = getBlockData().clone(); + newBlock = true; + } +//Logger.getGlobal().info("BlockData2: "+data); + if(data instanceof MultipleFacing multiData) { + BlockFace opposite = blockFace.getOppositeFace(); +//Logger.getGlobal().info("Edit data: "+opposite.name()); + if(multiData.getAllowedFaces().contains(opposite)) { +//Logger.getGlobal().info("set true"); + multiData.setFace(opposite, true); + } else { + if(newBlock) { + data = Bukkit.getServer().createBlockData(Material.AIR); + } + } +//Logger.getGlobal().info("MultiData: "+multiData); + } + final BlockState state = blockPlace.getState(); + state.setBlockData(data); +//Logger.getGlobal().info("BlockData3: "+data); + return state; + } + + @Override + public void placeBlock(final Block blockPlace, final BlockFace blockFace, final Block clicked, + final Location interactionPoint, final Player player) { + if(player.isSneaking()) { +//Logger.getGlobal().info("Sneak!"); + BlockData data = clicked.getBlockData(); +//Logger.getGlobal().info("Data: "+data.getMaterial()+" "+(data instanceof MultipleFacing)); + if(data.getMaterial().equals(getBlockData().getMaterial()) + && data instanceof MultipleFacing multiData) { + BlockFace opposite = blockFace.getOppositeFace(); +//Logger.getGlobal().info("Opposite: "+opposite.name()); + if(multiData.getAllowedFaces().contains(opposite)) { +//Logger.getGlobal().info("Set: "+!multiData.hasFace(opposite)); + multiData.setFace(opposite,!multiData.hasFace(opposite)); + clicked.setBlockData(multiData,true); + } + } + } else { + super.placeBlock(blockPlace,blockFace,clicked,interactionPoint,player); + } + } + + @Override + public boolean isEditOnSneaking() { + return true; + } + + @Override + public boolean canPlace(Block blockPlace) { + return super.canPlace(blockPlace) + || blockPlace.getType().equals(getBlockData().getMaterial()); + } + +}