-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary support for tags in block lists (closes #100)
I still think this feature should wait until Bukkit's Tag API is improved and BlockType and ItemType are better integrated into the API. But for now this should at least work as expected.
- Loading branch information
Showing
5 changed files
with
94 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
veinminer-bukkit/src/main/java/wtf/choco/veinminer/block/VeinMinerBlockTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package wtf.choco.veinminer.block; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.Tag; | ||
import org.bukkit.block.data.BlockData; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A type of {@link VeinMinerBlock} backed by a block {@link Tag}. | ||
*/ | ||
public final class VeinMinerBlockTag implements VeinMinerBlock { | ||
|
||
private final Tag<Material> tag; | ||
|
||
/** | ||
* Construct a new {@link VeinMinerBlockTag}. | ||
* | ||
* @param tag the block tag | ||
*/ | ||
public VeinMinerBlockTag(Tag<Material> tag) { | ||
this.tag = tag; | ||
} | ||
|
||
public Tag<Material> getTag() { | ||
return tag; | ||
} | ||
|
||
@Override | ||
public boolean matchesType(@NotNull Material type) { | ||
return tag.isTagged(type); | ||
} | ||
|
||
@Override | ||
public boolean matchesState(@NotNull BlockData state, boolean exact) { | ||
return matchesType(state.getMaterial()); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String toStateString() { | ||
return "#" + tag.getKey().toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return tag.getKey().hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return obj == this || (obj instanceof VeinMinerBlockTag other && tag.getKey().equals(other.tag.getKey())); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("VeinMinerBlockTag[type=\"%s\"]", tag.getKey().toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters