Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
33 changes: 15 additions & 18 deletions src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,28 +602,25 @@ public Long[] executeSimple(Object[][] params) {
}.description("Calculates the total amount of experience needed to achieve given level from scratch in Minecraft.")
.since("2.2-dev32"));

Functions.registerFunction(new SimpleJavaFunction<Color>("rgb", new Parameter[] {
new Parameter<>("red", DefaultClasses.LONG, true, null),
new Parameter<>("green", DefaultClasses.LONG, true, null),
new Parameter<>("blue", DefaultClasses.LONG, true, null),
new Parameter<>("alpha", DefaultClasses.LONG, true, new SimpleLiteral<>(255L,true))
}, DefaultClasses.COLOR, true) {
@Override
public ColorRGB[] executeSimple(Object[][] params) {
Long red = (Long) params[0][0];
Long green = (Long) params[1][0];
Long blue = (Long) params[2][0];
Long alpha = (Long) params[3][0];

return CollectionUtils.array(ColorRGB.fromRGBA(red.intValue(), green.intValue(), blue.intValue(), alpha.intValue()));
}
}).description("Returns a RGB color from the given red, green and blue parameters. Alpha values can be added optionally, " +
"but these only take affect in certain situations, like text display backgrounds.")
Functions.register(DefaultFunction.builder(skript, "rgb", Color.class)
.description("""
Returns a RGB color from the given red, green and blue parameters.
Alpha values can be added optionally but these only take affect in certain situations, like text display backgrounds.""")
.examples(
"dye player's leggings rgb(120, 30, 45)",
"set the colour of a text display to rgb(10, 50, 100, 50)"
)
.since("2.5, 2.10 (alpha)");
.since("2.5, 2.10 (alpha)")
.parameter("red", Long.class, Modifier.ranged(0, 255))
.parameter("green", Long.class, Modifier.ranged(0, 255))
.parameter("blue", Long.class, Modifier.ranged(0, 255))
.parameter("alpha", Long.class, Modifier.ranged(0, 255), Modifier.OPTIONAL)
.build(args -> ColorRGB.fromRGBA(
args.<Long>get("red").intValue(),
args.<Long>get("green").intValue(),
args.<Long>get("blue").intValue(),
args.getOrDefault("alpha", 255L).intValue()
)));

Functions.register(DefaultFunction.builder(skript, "player", Player.class)
.description(
Expand Down
21 changes: 2 additions & 19 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,15 @@ 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)));
.defaultExpression(new SimpleLiteral<>(TreeSpecies.TREE, true)));

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.

86 changes: 86 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,86 @@
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;

public enum TreeSpecies {
TREE(TreeType.values()),

REGULAR(TreeType.TREE, TreeType.BIG_TREE),
Comment thread
ShaneBeee marked this conversation as resolved.
Outdated
SMALL_REGULAR(TreeType.TREE),
BIG_REGULAR(TreeType.BIG_TREE),

REDWOOD(TreeType.REDWOOD, TreeType.TALL_REDWOOD),
SMALL_REDWOOD(TreeType.REDWOOD),
BIG_REDWOOD(TreeType.TALL_REDWOOD),
MEGA_REDWOOD(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;
}

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);
}

public void grow(Block block) {
grow(block.getLocation());
}

public TreeType[] getTypes() {
return types;
}

public boolean is(TreeType type) {
return CollectionUtils.contains(types, type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.inventory.ItemStack;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.event.Event;
import org.bukkit.event.world.LootGenerateEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxRegistry;
Expand All @@ -26,12 +25,11 @@
@Description("The loot that will be generated in a 'loot generate' event.")
@Example("""
on loot generate:
chance of %10
chance of 10%
add 64 diamonds to loot
send "You hit the jackpot!!"
""")
@Since("2.7")
@RequiredPlugins("MC 1.16+")
public class ExprLoot extends SimpleExpression<ItemStack> {

public static void register(SyntaxRegistry registry) {
Expand Down
Loading
Loading