mirror of
https://github.com/PaperMC/Paper.git
synced 2025-09-02 05:13:51 -07:00
Added callback line of sight methods. Thanks xZise!
By: EvilSeph <evilseph@gmail.com>
This commit is contained in:
19
paper-api/src/main/java/org/bukkit/util/Callback.java
Normal file
19
paper-api/src/main/java/org/bukkit/util/Callback.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.bukkit.util;
|
||||
|
||||
/**
|
||||
* Primitive callback class, to allow specific callback handling. For example to determine if a block in sight is invisible.
|
||||
*
|
||||
* @param <Result> This is the type it will return.
|
||||
* @param <Parameter> This is the type it has as parameter.
|
||||
*/
|
||||
public interface Callback<Result, Parameter> {
|
||||
|
||||
/**
|
||||
* This method will be called on each step.
|
||||
*
|
||||
* @param parameter The parameter of this step.
|
||||
* @return The result of the step.
|
||||
*/
|
||||
public Result call(Parameter parameter);
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
package org.bukkit.util;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
/**
|
||||
* Default transparent call back. This class as callback acts like the normal
|
||||
* line of sight methods.
|
||||
*
|
||||
* To implement own handler override {@link TransparentCallback#call(Block)} and
|
||||
* call it via super.
|
||||
*/
|
||||
public class TransparentCallback implements Callback<Boolean, Block> {
|
||||
|
||||
private final Set<Byte> transparent;
|
||||
|
||||
/**
|
||||
* Creates a new callback class which returns by default for every block in
|
||||
* the transparent list true. Otherwise false. Could be expanded by override
|
||||
* the {@link Callback#call(Block)} method.
|
||||
*
|
||||
* @param transparent
|
||||
* The list of transparent blocks.
|
||||
*/
|
||||
public TransparentCallback(Set<Byte> transparent) {
|
||||
this.transparent = transparent;
|
||||
}
|
||||
|
||||
public Boolean call(Block parameter) {
|
||||
return this.transparent.contains((byte) parameter.getTypeId());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user