Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,6 @@ public boolean supportsOrdering() {
}
});

// StructureType - StructureType
Comparators.registerComparator(StructureType.class, StructureType.class, new Comparator<StructureType, StructureType>() {
@Override
public Relation compare(StructureType s1, StructureType s2) {
return Relation.get(CollectionUtils.containsAll(s2.getTypes(), s2.getTypes()));
}

@Override
public boolean supportsOrdering() {
return false;
}
});

// Object - ClassInfo
Comparators.registerComparator(Object.class, ClassInfo.class, new Comparator<Object, ClassInfo>() {
@Override
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,32 +374,13 @@ public String toVariableNameString(Color color) {
}
}));

Classes.registerClass(new ClassInfo<>(StructureType.class, "structuretype")
Classes.registerClass(new EnumClassInfo<>(TreeSpecies.class, "treetype", "tree types")
.user("tree ?types?", "trees?")
.name("Tree Type")
.description("A tree type represents a tree species or a huge mushroom species. These can be generated in a world with the <a href='#EffTree'>generate tree</a> effect.")
.usage("[any] <general tree/mushroom type>, e.g. tree/any jungle tree/etc.", "<specific tree/mushroom species>, e.g. red mushroom/small jungle tree/big regular tree/etc.")
.examples("grow any regular tree at the block",
"grow a huge red mushroom above the block")
.since("")
.defaultExpression(new SimpleLiteral<>(StructureType.TREE, true))
.parser(new Parser<StructureType>() {
@Override
@Nullable
public StructureType parse(final String s, final ParseContext context) {
return StructureType.fromName(s);
}

@Override
public String toString(final StructureType o, final int flags) {
return o.toString(flags);
}

@Override
public String toVariableNameString(final StructureType o) {
return "" + o.name().toLowerCase(Locale.ENGLISH);
}
}).serializer(new EnumSerializer<>(StructureType.class)));
.since("1.0"));

Classes.registerClass(new ClassInfo<>(EnchantmentType.class, "enchantmenttype")
.user("enchant(ing|ment) types?")
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ch/njol/skript/effects/EffTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Direction;
import ch.njol.skript.util.StructureType;
import ch.njol.skript.util.TreeSpecies;
import ch.njol.util.Kleenean;

/**
Expand All @@ -28,26 +28,26 @@ public class EffTree extends Effect {

static {
Skript.registerEffect(EffTree.class,
"(grow|create|generate) tree [of type %structuretype%] %directions% %locations%",
"(grow|create|generate) %structuretype% %directions% %locations%");
"(grow|create|generate) tree [of type %treetype%] %directions% %locations%",
"(grow|create|generate) %treetype% %directions% %locations%");
}

@SuppressWarnings("null")
private Expression<Location> blocks;
@SuppressWarnings("null")
private Expression<StructureType> type;
private Expression<TreeSpecies> type;

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
type = (Expression<StructureType>) exprs[0];
type = (Expression<TreeSpecies>) exprs[0];
blocks = Direction.combine((Expression<? extends Direction>) exprs[1], (Expression<? extends Location>) exprs[2]);
return true;
}

@Override
public void execute(final Event e) {
final StructureType type = this.type.getSingle(e);
final TreeSpecies type = this.type.getSingle(e);
if (type == null)
return;
for (final Location l : blocks.getArray(e)) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ch/njol/skript/events/EvtGrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ch.njol.skript.lang.LiteralList;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.StructureType;
import ch.njol.skript.util.TreeSpecies;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.Material;
import org.bukkit.TreeType;
Expand All @@ -32,10 +32,10 @@ public class EvtGrow extends SkriptEvent {

static {
Skript.registerEvent("Grow", EvtGrow.class, CollectionUtils.array(StructureGrowEvent.class, BlockGrowEvent.class),
"grow[th] [of (1:%-structuretypes%|2:%-itemtypes/blockdatas%)]",
"grow[th] [of (1:%-treetypes%|2:%-itemtypes/blockdatas%)]",
"grow[th] from %itemtypes/blockdatas%",
"grow[th] [in]to (1:%structuretypes%|2:%itemtypes/blockdatas%)",
"grow[th] from %itemtypes/blockdatas% [in]to (1:%structuretypes%|2:%itemtypes/blockdatas%)"
"grow[th] [in]to (1:%treetypes%|2:%itemtypes/blockdatas%)",
"grow[th] from %itemtypes/blockdatas% [in]to (1:%treetypes%|2:%itemtypes/blockdatas%)"
)
.description(
"Called when a tree, giant mushroom or plant grows to next stage.",
Expand Down Expand Up @@ -174,8 +174,8 @@ private static boolean checkTo(Event event, Literal<Object> types) {
if (event instanceof StructureGrowEvent) {
TreeType species = ((StructureGrowEvent) event).getSpecies();
return types.check(event, type -> {
if (type instanceof StructureType) {
return ((StructureType) type).is(species);
if (type instanceof TreeSpecies) {
return ((TreeSpecies) type).is(species);
}
return false;
});
Expand Down
103 changes: 0 additions & 103 deletions src/main/java/ch/njol/skript/util/StructureType.java

This file was deleted.

116 changes: 116 additions & 0 deletions src/main/java/ch/njol/skript/util/TreeSpecies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package ch.njol.skript.util;

import ch.njol.util.coll.CollectionUtils;
import org.bukkit.Location;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.Block;

/**
* Repesents a grouping of Bukkkit {@link TreeType TreeTypes}
*/
public enum TreeSpecies {
Comment thread
ShaneBeee marked this conversation as resolved.
TREE(TreeType.values()),

OAK(TreeType.TREE, TreeType.BIG_TREE),
SMALL_OAK(TreeType.TREE),
BIG_OAK(TreeType.BIG_TREE),

SPRUCE(TreeType.REDWOOD, TreeType.TALL_REDWOOD),
SMALL_SPRUCE(TreeType.REDWOOD),
BIG_SPRUCE(TreeType.TALL_REDWOOD),
MEGA_SPRUCE(TreeType.MEGA_REDWOOD),

BIRCH(TreeType.BIRCH, TreeType.TALL_BIRCH),
SMALL_BIRCH(TreeType.BIRCH),
TALL_BIRCH(TreeType.TALL_BIRCH),

JUNGLE(TreeType.SMALL_JUNGLE, TreeType.JUNGLE, TreeType.COCOA_TREE),
SMALL_JUNGLE(TreeType.SMALL_JUNGLE),
BIG_JUNGLE(TreeType.JUNGLE),
COCOA_TREE(TreeType.COCOA_TREE),

JUNGLE_BUSH(TreeType.JUNGLE_BUSH),

ACACIA(TreeType.ACACIA),
DARK_OAK(TreeType.DARK_OAK),
SWAMP(TreeType.SWAMP),

MUSHROOM(TreeType.RED_MUSHROOM, TreeType.BROWN_MUSHROOM),
RED_MUSHROOM(TreeType.RED_MUSHROOM),
BROWN_MUSHROOM(TreeType.BROWN_MUSHROOM),

MANGROVE(TreeType.MANGROVE, TreeType.TALL_MANGROVE),
SMALL_MANGROVE(TreeType.MANGROVE),
BIG_MANGROVE(TreeType.TALL_MANGROVE),

AZALEA(TreeType.AZALEA),

PALE_OAK(TreeType.PALE_OAK, TreeType.PALE_OAK_CREAKING),
PALE_OAK_NORMAL(TreeType.PALE_OAK),
PALE_OAK_CREAKING(TreeType.PALE_OAK_CREAKING),

CHERRY(TreeType.CHERRY),

CRIMSON_FUNGUS(TreeType.CRIMSON_FUNGUS),
WARPED_FUNGUS(TreeType.WARPED_FUNGUS),

CHORUS_PLANT(TreeType.CHORUS_PLANT),
;

private final TreeType[] types;

TreeSpecies(TreeType... types) {
this.types = types;
}

/**
* Grow a tree at a location.
* <p>
* If the species is a group, a random tree type is selected.
* </p>
*
* @param location Location to grow the tree at
*/
public void grow(Location location) {
TreeType tree = CollectionUtils.getRandom(types);
assert tree != null; // No enum member causes empty types
World world = location.getWorld();
if (world == null) {
return;
}
world.generateTree(location, tree);
}

/**
* Grow a tree at a location.
* <p>
* If the species is a group, a random tree type is selected.
* </p>
*
* @param block Block to grow the tree at
*/
public void grow(Block block) {
grow(block.getLocation());
}

/**
* Get the TreeTypes that make up this species.
*
* @return TreeTypes that make up this species
*/
public TreeType[] getTypes() {
return types;
}

/**
* Check if this species contains a specific tree type.
*
* @param type TreeType to check for
* @return True if the species contains the type, false otherwise
*/
public boolean is(TreeType type) {
return CollectionUtils.contains(types, type);
}

}
Loading