Skip to content

Commit

Permalink
Add getBrush helper for use with instanceof pattern matching (#1926)
Browse files Browse the repository at this point in the history
Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
  • Loading branch information
rainbowdashlabs and octylFractal committed Nov 21, 2021
1 parent 09bdf0a commit de6fa17
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/CommonJavaConfig.kt
Expand Up @@ -32,7 +32,7 @@ fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, banSlf4j: Boolean

configure<CheckstyleExtension> {
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
toolVersion = "8.34"
toolVersion = "9.1"
}

tasks.withType<Test>().configureEach {
Expand Down
Expand Up @@ -243,8 +243,8 @@ public ListTag getListTag(String key) {
*
* @param key the key
* @param listType the class of the contained type
* @return a list of tags
* @param <T> the type of list
* @return a list of tags
*/
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
Expand Down
2 changes: 1 addition & 1 deletion worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java
Expand Up @@ -301,8 +301,8 @@ public ListTag getListTag(int index) {
*
* @param index the index
* @param listType the class of the contained type
* @return a list of tags
* @param <T> the NBT type
* @return a list of tags
*/
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(int index, Class<T> listType) {
Expand Down
Expand Up @@ -671,13 +671,14 @@ public Tool getTool(ItemType item) {

/**
* Get the brush tool assigned to the item. If there is no tool assigned
* or the tool is not assigned, the slot will be replaced with the
* or the tool is not a brush tool, the slot will be replaced with the
* brush tool.
*
* @param item the item type
* @return the tool, or {@code null}
* @throws InvalidToolBindException if the item can't be bound to that item
*/
@Deprecated
public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException {
Tool tool = getTool(item);

Expand All @@ -689,6 +690,17 @@ public BrushTool getBrushTool(ItemType item) throws InvalidToolBindException {
return (BrushTool) tool;
}

/**
* Get the brush tool assigned to this item.
*
* @param item the item type
* @return the brush tool assigned to the item type
*/
@Nullable
public BrushTool getBrush(ItemType item) {
return getTool(item) instanceof BrushTool tool ? tool : null;
}

/**
* Set the tool.
*
Expand Down
Expand Up @@ -36,9 +36,8 @@ public interface BlockTool extends Tool {
* Perform the primary action of this tool.
*
* @return true to cancel the original event which triggered this action (if possible)
* @deprecated New subclasses should override
* {@link #actPrimary(Platform, LocalConfiguration, Player, LocalSession, Location, Direction)}
* instead
* @deprecated New subclasses should override {@link #actPrimary(Platform, LocalConfiguration, Player, LocalSession,
* Location, Direction)} instead
*/
@Deprecated
default boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
Expand Down
Expand Up @@ -39,9 +39,8 @@ public interface DoubleActionBlockTool extends BlockTool {
* Perform the secondary action of this block tool.
*
* @return true to cancel the original event which triggered this action (if possible)
* @deprecated New subclasses must override
* {@link #actSecondary(Platform, LocalConfiguration, Player, LocalSession, Location, Direction)}
* instead
* @deprecated New subclasses must override {@link #actSecondary(Platform, LocalConfiguration, Player, LocalSession,
* Location, Direction)} instead
*/
@Deprecated
default boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
Expand Down
Expand Up @@ -284,8 +284,7 @@ default Location getBlockIn() {
* @param pos where to move them
* @param pitch the pitch (up/down) of the player's view in degrees
* @param yaw the yaw (left/right) of the player's view in degrees
* @deprecated This method may fail without indication. Use
* {@link #trySetPosition(Vector3, float, float)} instead
* @deprecated This method may fail without indication. Use {@link #trySetPosition(Vector3, float, float)} instead
*/
@Deprecated
default void setPosition(Vector3 pos, float pitch, float yaw) {
Expand Down
Expand Up @@ -132,9 +132,8 @@ public <T> Optional<AssetLoader<T>> getAssetLoader(Class<T> assetClass, String f
* Get the Asset Loaders for the given type.
*
* @param assetClass The class to get the loaders of
* @return The list of asset loaders
*
* @param <T> The asset type
* @return The list of asset loaders
*/
@SuppressWarnings("unchecked")
public <T> List<AssetLoader<T>> getAssetLoaders(Class<T> assetClass) {
Expand Down

0 comments on commit de6fa17

Please sign in to comment.