Adds some helper code mainly related to signs
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				KnarCraft/KnarLib/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	KnarCraft/KnarLib/pipeline/head This commit looks good
				
			This commit is contained in:
		@@ -240,16 +240,6 @@ public final class FormatBuilder {
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Builds the output of the performed replacements and formatting
 | 
			
		||||
     *
 | 
			
		||||
     * @return <p>The result</p>
 | 
			
		||||
     */
 | 
			
		||||
    @NotNull
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return this.toFormat;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Displays the result to the specified command sender as a success message
 | 
			
		||||
     *
 | 
			
		||||
@@ -289,4 +279,10 @@ public final class FormatBuilder {
 | 
			
		||||
        FormatBuilder.stringFormatter.displayNeutralMessage(commandSender, this.toFormat);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @NotNull
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return this.toFormat;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								src/main/java/net/knarcraft/knarlib/util/BlockHelper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/main/java/net/knarcraft/knarlib/util/BlockHelper.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
package net.knarcraft.knarlib.util;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A helper class for dealing with blocks
 | 
			
		||||
 */
 | 
			
		||||
public final class BlockHelper {
 | 
			
		||||
 | 
			
		||||
    private BlockHelper() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the block the player is currently looking at
 | 
			
		||||
     *
 | 
			
		||||
     * @param player <p>The player looking at a block</p>
 | 
			
		||||
     * @return <p>The block the player is looking at</p>
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public static Block getLookedAtBlock(@NotNull Player player) {
 | 
			
		||||
        return player.getTargetBlockExact(7);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										61
									
								
								src/main/java/net/knarcraft/knarlib/util/SignHelper.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								src/main/java/net/knarcraft/knarlib/util/SignHelper.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
package net.knarcraft.knarlib.util;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.block.Block;
 | 
			
		||||
import org.bukkit.block.Sign;
 | 
			
		||||
import org.bukkit.block.sign.Side;
 | 
			
		||||
import org.bukkit.block.sign.SignSide;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A helper class for dealing with sign sides
 | 
			
		||||
 */
 | 
			
		||||
@SuppressWarnings("unused")
 | 
			
		||||
public final class SignHelper {
 | 
			
		||||
 | 
			
		||||
    private SignHelper() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the side of the given sign the given player is standing on (which side the player clicked)
 | 
			
		||||
     *
 | 
			
		||||
     * @param sign   <p>The sign to check</p>
 | 
			
		||||
     * @param player <p>The player to check</p>
 | 
			
		||||
     * @return <p>The side of the sign the player is standing on</p>
 | 
			
		||||
     */
 | 
			
		||||
    @NotNull
 | 
			
		||||
    public static Side getSide(@NotNull Sign sign, @NotNull Player player) {
 | 
			
		||||
        SignSide standingOn = sign.getTargetSide(player);
 | 
			
		||||
        return sign.getSide(Side.FRONT).equals(standingOn) ? Side.FRONT : Side.BACK;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the opposite sign side from the given sign side
 | 
			
		||||
     *
 | 
			
		||||
     * @param side <p>The side to get the opposite of</p>
 | 
			
		||||
     * @return <p>The opposite side</p>
 | 
			
		||||
     */
 | 
			
		||||
    @NotNull
 | 
			
		||||
    public static Side getOpposite(@NotNull Side side) {
 | 
			
		||||
        return side == Side.FRONT ? Side.BACK : Side.FRONT;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the sign the player is currently looking at
 | 
			
		||||
     *
 | 
			
		||||
     * @param player <p>The player to check</p>
 | 
			
		||||
     * @return <p>The sign the player is looking at, or null if not looking at a sign</p>
 | 
			
		||||
     */
 | 
			
		||||
    @Nullable
 | 
			
		||||
    public static Sign getLookedAtSign(@NotNull Player player) {
 | 
			
		||||
        Block targetBlock = BlockHelper.getLookedAtBlock(player);
 | 
			
		||||
        if (targetBlock == null || !(targetBlock.getState() instanceof Sign sign)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        } else {
 | 
			
		||||
            return sign;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user