Skip to content

Commit

Permalink
Merge branch 'dev/feature' into angle
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth authored Dec 15, 2024
2 parents 28742ef + 0c8aa27 commit abd2873
Show file tree
Hide file tree
Showing 41 changed files with 2,128 additions and 329 deletions.
6 changes: 6 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 @@ -91,6 +91,7 @@
import org.bukkit.inventory.BlockInventoryHolder;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.Metadatable;
import org.bukkit.potion.PotionEffect;
Expand Down Expand Up @@ -1529,6 +1530,11 @@ public String toVariableNameString(EnchantmentOffer eo) {
.description("Represents a transform reason of an <a href='events.html#entity transform'>entity transform event</a>.")
.since("2.8.0"));

Classes.registerClass(new EnumClassInfo<>(ItemFlag.class, "itemflag", "item flags")
.user("item ?flags?")
.name("Item Flag")
.description("Represents flags that may be applied to hide certain attributes of an item.")
.since("INSERT VERSION"));

Classes.registerClass(new EnumClassInfo<>(EntityPotionEffectEvent.Cause.class, "entitypotioncause", "entity potion causes")
.user("(entity )?potion ?effect ?cause")
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Getter;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.Color;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.ColorRGB;
import ch.njol.skript.util.slot.InventorySlot;
import ch.njol.skript.util.slot.Slot;
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
Expand Down Expand Up @@ -1638,6 +1641,26 @@ public FireworkEffect get(FireworkExplodeEvent e) {
return effects.get(0);
}
}, 0);
EventValues.registerEventValue(FireworkExplodeEvent.class, Color[].class, new Getter<Color[], FireworkExplodeEvent>() {
@Override
public Color @Nullable [] get(FireworkExplodeEvent event) {
List<FireworkEffect> effects = event.getEntity().getFireworkMeta().getEffects();
if (effects.isEmpty())
return null;
List<Color> colors = new ArrayList<>();
for (FireworkEffect fireworkEffect : effects) {
for (org.bukkit.Color color : fireworkEffect.getColors()) {
if (SkriptColor.fromBukkitColor(color) != null)
colors.add(SkriptColor.fromBukkitColor(color));
else
colors.add(ColorRGB.fromBukkitColor(color));
}
}
if (colors.isEmpty())
return null;
return colors.toArray(Color[]::new);
}
}, EventValues.TIME_NOW);
//PlayerRiptideEvent
EventValues.registerEventValue(PlayerRiptideEvent.class, ItemStack.class, new Getter<ItemStack, PlayerRiptideEvent>() {
@Override
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondFromMobSpawner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Entity;

@Name("Is From A Mob Spawner")
@Description("Checks if an entity was spawned from a mob spawner.")
@Examples("send whether target is from a mob spawner")
@RequiredPlugins("PaperMC")
@Since("INSERT VERSION")
public class CondFromMobSpawner extends PropertyCondition<Entity> {

static {
if (Skript.methodExists(Entity.class, "fromMobSpawner"))
Skript.registerCondition(CondFromMobSpawner.class,
"%entities% (is|are) from a [mob] spawner",
"%entities% (isn't|aren't|is not|are not) from a [mob] spawner",
"%entities% (was|were) spawned (from|by) a [mob] spawner",
"%entities% (wasn't|weren't|was not|were not) spawned (from|by) a [mob] spawner");
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(matchedPattern == 1 || matchedPattern == 3);
setExpr((Expression<Entity>) exprs[0]);
return true;
}

@Override
public boolean check(Entity entity) {
return entity.fromMobSpawner();
}

@Override
protected String getPropertyName() {
return "from a mob spawner";
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.entity.Entity;

@Name("Is Custom Name Visible")
@Description("Checks if an entity's custom name is visible.")
@Examples("send true if target's custom name is visible")
@Since("INSERT VERSION")
public class CondIsCustomNameVisible extends PropertyCondition<Entity> {

static {
Skript.registerCondition(CondIsCustomNameVisible.class,
"%entities%'[s] custom name[s] (is|are) visible",
"%entities%'[s] custom name[s] (isn't|is not|are not|aren't) visible",
"custom name of %entities% (is|are) visible",
"custom name of %entities% (isn't|is not|are not|aren't) visible");
}

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
setNegated(matchedPattern == 1 || matchedPattern == 3);
setExpr((Expression<Entity>) exprs[0]);
return true;
}

@Override
public boolean check(Entity entity) {
return entity.isCustomNameVisible();
}

@Override
protected String getPropertyName() {
return "custom name";
}

}

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

import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.util.Kleenean;
import org.bukkit.Material;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Steerable;
import org.bukkit.inventory.ItemStack;

@Name("Is Saddled")
@Description({
"Checks whether a given entity (horse or steerable) is saddled.",
"If 'properly' is used, this will only return true if the entity is wearing specifically a saddle item."
})
@Examples("send whether {_horse} is saddled")
@Since("INSERT VERSION")
public class CondIsSaddled extends PropertyCondition<LivingEntity> {

static {
register(CondIsSaddled.class, "[:properly] saddled", "livingentities");
}

private boolean properly;

@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
properly = parseResult.hasTag("properly");
return super.init(exprs, matchedPattern, isDelayed, parseResult);
}

@Override
public boolean check(LivingEntity entity) {
if (entity instanceof Steerable steerable) {
return steerable.hasSaddle();
} else if (entity instanceof AbstractHorse horse) {
ItemStack saddle = horse.getInventory().getSaddle();
return properly ? (saddle != null && saddle.equals(new ItemStack(Material.SADDLE))) : (saddle != null);
}
return false;
}

@Override
protected String getPropertyName() {
return properly ? "properly saddled" : "saddled";
}

}
31 changes: 31 additions & 0 deletions src/main/java/ch/njol/skript/conditions/CondIsTicking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.doc.*;
import org.bukkit.entity.Entity;

@Name("Is Ticking")
@Description("Checks if an entity is ticking.")
@Examples("send true if target is ticking")
@RequiredPlugins("PaperMC")
@Since("INSERT VERSION")
public class CondIsTicking extends PropertyCondition<Entity> {

static {
if (Skript.methodExists(Entity.class, "isTicking"))
register(CondIsTicking.class, "ticking", "entities");
}

@Override
public boolean check(Entity entity) {
return entity.isTicking();
}

@Override
protected String getPropertyName() {
return "ticking";
}

}

93 changes: 42 additions & 51 deletions src/main/java/ch/njol/skript/conditions/CondIsWearing.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.conditions;

import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
Expand All @@ -34,57 +10,72 @@
import ch.njol.skript.lang.Condition;
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 org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;

/**
* @author Peter Güttinger
*/
@Name("Is Wearing")
@Description("Checks whether a player is wearing some armour.")
@Examples({"player is wearing an iron chestplate and iron leggings",
"player is wearing all diamond armour"})
@Description("Checks whether an entity is wearing some items (usually armor).")
@Examples({
"player is wearing an iron chestplate and iron leggings",
"player is wearing all diamond armour",
"target is wearing wolf armor"
})
@Since("1.0")
public class CondIsWearing extends Condition {

static {
PropertyCondition.register(CondIsWearing.class, "wearing %itemtypes%", "livingentities");
}

@SuppressWarnings("null")
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<LivingEntity> entities;
@SuppressWarnings("null")
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<ItemType> types;

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
public boolean init(Expression<?>[] vars, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
entities = (Expression<LivingEntity>) vars[0];
types = (Expression<ItemType>) vars[1];
setNegated(matchedPattern == 1);
return true;
}

@Override
public boolean check(final Event e) {
return entities.check(e,
en -> types.check(e,
t -> {
EntityEquipment equip = en.getEquipment();
if (equip == null)
return false; // No equipment -> not wearing anything
for (final ItemStack is : equip.getArmorContents()) {
if (t.isOfType(is) ^ t.isAll())
return !t.isAll();
}
return t.isAll();
}),
isNegated());
public boolean check(Event event) {
ItemType[] cachedTypes = types.getAll(event);

return entities.check(event, entity -> {
EntityEquipment equipment = entity.getEquipment();
if (equipment == null)
return false; // spigot nullability, no identifier as to why this occurs

ItemStack[] contents = Arrays.stream(EquipmentSlot.values())
.map(equipment::getItem)
.toArray(ItemStack[]::new);

return SimpleExpression.check(cachedTypes, type -> {
for (ItemStack content : contents) {
if (type.isOfType(content) ^ type.isAll())
return !type.isAll();
}
return type.isAll();
}, false, false);
}, isNegated());
}

@Override
public String toString(final @Nullable Event e, final boolean debug) {
return PropertyCondition.toString(this, PropertyType.BE, e, debug, entities,
"wearing " + types.toString(e, debug));
public String toString(@Nullable Event event, boolean debug) {
return PropertyCondition.toString(this, PropertyType.BE, event, debug, entities,
"wearing " + types.toString(event, debug));
}

}
Loading

0 comments on commit abd2873

Please sign in to comment.