Skip to content

Commit

Permalink
Merge pull request #78 from MCME/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
EriolEandur authored Dec 9, 2023
2 parents 9df3bc0 + aff7548 commit be53203
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mcmiddleearth</groupId>
<artifactId>MCME-Architect</artifactId>
<version>2.9.7</version>
<version>2.9.8</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum SpecialBlockType {
DOUBLE_Y_BLOCK,
UPSHIFT,
VANILLA,
MULTI_FACE,
DOOR_VANILLA,
DOOR_THREE_BLOCKS,
DOOR_FOUR_BLOCKS //("threeAxis");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}

}

0 comments on commit be53203

Please sign in to comment.