Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove StructureType #5473

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import ch.njol.util.coll.CollectionUtils;
import ch.njol.util.coll.iterator.ArrayIterator;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.ConfigurationSerializer;
Expand All @@ -50,6 +51,7 @@
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.SoundCategory;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.attribute.Attribute;
Expand Down Expand Up @@ -1495,5 +1497,13 @@ public String toVariableNameString(EnchantmentOffer eo) {
.since("INSERT VERSION")
.requiredPlugins("Paper 1.16+"));
}
Classes.registerClass(new EnumClassInfo<>(TreeType.class, "treetype", "tree types")
.user("tree ?types?", "trees?", /*structuretype is a deprecated name*/ "structure ?types?")
.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='./effects.html#EffTree'>generate tree</a> effect.")
.examples("grow any regular tree at the block", "grow a huge red mushroom above the block")
.since("1.0")
.supplier(TreeType.values()));
}

}
60 changes: 23 additions & 37 deletions src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,51 @@
*/
package ch.njol.skript.classes.data;

import java.util.Objects;

import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.EnchantmentOffer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.comparator.Relation;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
import ch.njol.skript.aliases.Aliases;
import ch.njol.skript.aliases.ItemData;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.classes.ClassInfo;
import org.skriptlang.skript.lang.comparator.Comparator;
import ch.njol.skript.entity.BoatChestData;
import ch.njol.skript.entity.BoatData;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.entity.RabbitData;
import org.skriptlang.skript.lang.comparator.Comparators;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Experience;
import ch.njol.skript.util.WeatherType;
import ch.njol.skript.util.GameruleValue;
import ch.njol.skript.util.StructureType;
import ch.njol.skript.util.Time;
import ch.njol.skript.util.Timeperiod;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.WeatherType;
import ch.njol.skript.util.slot.EquipmentSlot;
import ch.njol.skript.util.slot.Slot;
import ch.njol.skript.util.slot.SlotWithIndex;
import ch.njol.util.StringUtils;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.EnchantmentOffer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Wither;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.skriptlang.skript.lang.comparator.Relation;

import java.util.Objects;

@SuppressWarnings({"rawtypes"})
public class DefaultComparators {
Expand Down Expand Up @@ -466,20 +465,7 @@ public boolean supportsOrdering() {
return false;
}
});

// 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
31 changes: 1 addition & 30 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ch.njol.skript.classes.data;

import java.io.StreamCorruptedException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -55,7 +56,6 @@
import ch.njol.skript.util.Experience;
import ch.njol.skript.util.GameruleValue;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.StructureType;
import ch.njol.skript.util.Time;
import ch.njol.skript.util.Timeperiod;
import ch.njol.skript.util.Timespan;
Expand All @@ -66,8 +66,6 @@
import ch.njol.skript.util.visual.VisualEffects;
import ch.njol.yggdrasil.Fields;

import java.util.Arrays;

/**
* @author Peter Güttinger
*/
Expand Down Expand Up @@ -625,33 +623,6 @@ public String toVariableNameString(Color color) {
}
}));

Classes.registerClass(new ClassInfo<>(StructureType.class, "structuretype")
.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='./effects.html#EffTree'>generate tree</a> effect.")
.usage("[any] &lt;general tree/mushroom type&gt;, e.g. tree/any jungle tree/etc.", "&lt;specific tree/mushroom species&gt;, 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)));

Classes.registerClass(new ClassInfo<>(EnchantmentType.class, "enchantmenttype")
.user("enchant(ing|ment) types?")
.name("Enchantment Type")
Expand Down
58 changes: 30 additions & 28 deletions src/main/java/ch/njol/skript/effects/EffTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package ch.njol.skript.effects;

import org.bukkit.Location;
import org.bukkit.TreeType;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

Expand All @@ -31,52 +33,52 @@
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.util.Kleenean;

/**
* @author Peter Güttinger
*/
@Name("Tree")
@Description({"Creates a tree.",
"This may require that there is enough space above the given location and that the block below is dirt/grass, but it is possible that the tree will just grow anyways, possibly replacing every block in its path."})
@Examples({"grow a tall redwood tree above the clicked block"})
@Description({
"Creates a tree.",
"This may require that there is enough space above the given location and that the block below is dirt/grass,",
"but it is possible that the tree will just grow anyways, possibly replacing every block in its path."
})
@Examples({
"grow a tall redwood tree above the clicked block"
})
@Since("1.0")
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;

@SuppressWarnings({"unchecked", "null"})
private Expression<TreeType> type;

@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
type = (Expression<StructureType>) exprs[0];
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
type = (Expression<TreeType>) 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);
public void execute(Event event) {
TreeType type = this.type.getSingle(event);
if (type == null)
return;
for (final Location l : blocks.getArray(e)) {
assert l != null : blocks;
type.grow(l.getBlock());
for (Location location : blocks.getArray(event)) {
Block block = location.getBlock();
block.getWorld().generateTree(block.getLocation(), type);
}
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return "grow tree of type " + type.toString(e, debug) + " " + blocks.toString(e, debug);
public String toString(@Nullable Event event, boolean debug) {
return "grow tree of type " + type.toString(event, debug) + " " + blocks.toString(event, debug);
}

}
84 changes: 36 additions & 48 deletions src/main/java/ch/njol/skript/events/EvtGrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package ch.njol.skript.events;

import org.bukkit.TreeType;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockGrowEvent;
import org.bukkit.event.world.StructureGrowEvent;
Expand All @@ -28,76 +29,63 @@
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.StructureType;
import ch.njol.util.Checker;
import ch.njol.util.coll.CollectionUtils;

public class EvtGrow extends SkriptEvent {

/**
* Growth event restriction.
*
* ANY means any grow event goes.
*
* Structure/block restrict for structure/block grow events only.
*/
public static final int ANY = 0, STRUCTURE = 1, BLOCK = 2;


static {
Skript.registerEvent("Grow", EvtGrow.class, CollectionUtils.array(StructureGrowEvent.class, BlockGrowEvent.class),
"grow [of (1¦%-structuretype%|2¦%-itemtype%)]")
Class<? extends Event>[] events = CollectionUtils.array(StructureGrowEvent.class, BlockGrowEvent.class);
Skript.registerEvent("Grow", EvtGrow.class, events, "grow [of (tree:%-treetypes%|%-itemtype%)]")
.description("Called when a tree, giant mushroom or plant grows to next stage.")
.examples("on grow:", "on grow of a tree:", "on grow of a huge jungle tree:")
.examples("on grow:", "on grow of every tree:", "on grow of a huge jungle tree:")
.since("1.0 (2.2-dev20 for plants)");
}

@Nullable
private Literal<StructureType> types;
private Literal<TreeType> types;

@Nullable
private Literal<ItemType> blocks;
private int evtType;

@SuppressWarnings("unchecked")
private boolean isTree;

@Override
public boolean init(final Literal<?>[] args, final int matchedPattern, final ParseResult parser) {
evtType = parser.mark; // ANY, STRUCTURE or BLOCK
if (evtType == STRUCTURE)
types = (Literal<StructureType>) args[0];
else if (evtType == BLOCK)
blocks = (Literal<ItemType>) args[1]; // Arg 1 may not be present... but it is in the array still, as null
// Else: no type restrictions specified
@SuppressWarnings("unchecked")
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult) {
isTree = parseResult.hasTag("tree");
if (isTree) {
types = (Literal<TreeType>) args[0];
} else {
blocks = (Literal<ItemType>) args[1];
}
return true;
}

@Override
public boolean check(final Event e) {
if (evtType == STRUCTURE && types != null && e instanceof StructureGrowEvent) {
return types.check(e, new Checker<StructureType>() {
public boolean check(Event event) {
if (isTree && types != null && event instanceof StructureGrowEvent) {
return types.check(event, new Checker<TreeType>() {
@Override
public boolean check(final StructureType t) {
return t.is(((StructureGrowEvent) e).getSpecies());
public boolean check(TreeType type) {
return type.equals(((StructureGrowEvent) event).getSpecies());
}
});
} else if (evtType == BLOCK && blocks != null && e instanceof BlockGrowEvent) {
assert blocks != null;
return blocks.check(e, new Checker<ItemType>() {
} else if (blocks != null && event instanceof BlockGrowEvent) {
return blocks.check(event, new Checker<ItemType>() {
@Override
public boolean check(final ItemType t) {
return t.isOfType(((BlockGrowEvent) e).getBlock());
public boolean check(ItemType type) {
return type.isOfType(((BlockGrowEvent) event).getBlock());
}
});
}

return false;
return true;
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
if (evtType == STRUCTURE)
return "grow" + (types != null ? " of " + types.toString(e, debug) : "");
else if (evtType == BLOCK)
return "grow" + (blocks != null ? " of " + blocks.toString(e, debug) : "");
return "grow";
public String toString(@Nullable Event event, boolean debug) {
if (isTree)
return "grow" + (types != null ? " of " + types.toString(event, debug) : "");
return "grow" + (blocks != null ? " of " + blocks.toString(event, debug) : "");
}
}

}
Loading