Skip to content

Commit

Permalink
MinecraftTag - disable (now in Skript)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee committed Jan 1, 2025
1 parent b2dc354 commit 94c335d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/shanebeestudios/skbee/AddonLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ private void loadParticleElements() {
}

private void loadTagElements() {
if (Util.IS_RUNNING_SKRIPT_2_10) {
Util.logLoading("&5Minecraft Tag elements &cdisabled &r(&7now in Skript&r)");
return;
}
if (!this.config.ELEMENTS_MINECRAFT_TAG) {
Util.logLoading("&5Minecraft Tag elements &cdisabled via config");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.util.LiteralUtils;
import ch.njol.util.Kleenean;
import com.shanebeestudios.skbee.SkBee;
import com.shanebeestudios.skbee.api.recipe.RecipeUtil;
import com.shanebeestudios.skbee.elements.tag.type.Types;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.event.Event;
Expand All @@ -25,34 +24,31 @@

@Name("Recipe Choice - Material Choice")
@Description({"A material choice is a list of items or a minecraft tag, that can be used as an option in some recipes.",
"Will return as a RecipeChoice.",
"When using the 'every' item type, this will grab all relatable items in a list, ie: 'every sword'.",
"This allows you to have one specific slot of a recipe to accept multiple items, without having to create multiple recipes.",
"Do note that material choices do not accept custom items (ie: items with names, lore, enchants, etc). Requires Minecraft 1.13+"})
"Will return as a RecipeChoice.",
"When using the 'every' item type, this will grab all relatable items in a list, ie: 'every sword'.",
"This allows you to have one specific slot of a recipe to accept multiple items, without having to create multiple recipes.",
"Do note that material choices do not accept custom items (ie: items with names, lore, enchants, etc). Requires Minecraft 1.13+"})
@Examples({"set {_a} to material choice of diamond sword, diamond shovel and diamond hoe",
"set {_choice} to material choice of every sword",
"set {_choice} to material choice of every sword and every axe",
"set {_choice} to material choice of minecraft tag \"minecraft:planks\""})
"set {_choice} to material choice of every sword",
"set {_choice} to material choice of every sword and every axe",
"set {_choice} to material choice of minecraft tag \"minecraft:planks\""})
@Since("1.10.0")
public class ExprMaterialChoice extends SimpleExpression<MaterialChoice> {

private static final boolean HAS_TAGS = SkBee.getPlugin().getPluginConfig().ELEMENTS_MINECRAFT_TAG && Types.HAS_TAG;

static {
Skript.registerExpression(ExprMaterialChoice.class, MaterialChoice.class, ExpressionType.COMBINED,
HAS_TAGS ? "material choice of %itemtypes/minecrafttags%" : "material choice of %itemtypes%");
"material choice of %itemtypes/minecrafttags%");
}

private Expression<?> objects;

@SuppressWarnings("NullableProblems")
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
this.objects = exprs[0];
this.objects = LiteralUtils.defendExpression(exprs[0]);
return true;
}

@SuppressWarnings({"NullableProblems", "unchecked"})
@SuppressWarnings("unchecked")
@Override
protected MaterialChoice @Nullable [] get(Event event) {
List<Material> materials = new ArrayList<>();
Expand All @@ -62,7 +58,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
Material material = itemStack.getType();
if (!materials.contains(material)) materials.add(material);
});
} else if (HAS_TAGS && RecipeUtil.isMaterialTag(object)) {
} else if (RecipeUtil.isMaterialTag(object)) {
MaterialChoice materialChoice = new MaterialChoice((Tag<Material>) object);
materialChoice.getChoices().forEach(material -> {
if (!materials.contains(material)) materials.add(material);
Expand All @@ -80,13 +76,11 @@ public boolean isSingle() {
return true;
}

@SuppressWarnings("NullableProblems")
@Override
public Class<? extends MaterialChoice> getReturnType() {
return MaterialChoice.class;
}

@SuppressWarnings("NullableProblems")
@Override
public String toString(@Nullable Event e, boolean d) {
return "material choice of " + this.objects.toString(e, d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class Types {
.description("Represents a Minecraft Tag.")
.since("2.6.0")
.parser(new Parser<>() {

@SuppressWarnings("NullableProblems")
@Override
public boolean canParse(ParseContext context) {
return false;
Expand Down

0 comments on commit 94c335d

Please sign in to comment.