Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@

# EntityData
/src/main/java/ch/njol/skript/entity @Absolutionism @skriptlang/core-developers

# Particles/Effects
/src/main/java/org/skriptlang/skript/bukkit/particles @sovdeeth @skriptlang/core-developers
6 changes: 4 additions & 2 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import org.skriptlang.skript.bukkit.itemcomponents.ItemComponentModule;
import org.skriptlang.skript.bukkit.log.runtime.BukkitRuntimeErrorConsumer;
import org.skriptlang.skript.bukkit.loottables.LootTableModule;
import org.skriptlang.skript.bukkit.particles.ParticleModule;
import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
import org.skriptlang.skript.bukkit.tags.TagModule;
Expand Down Expand Up @@ -444,7 +445,7 @@ public void onEnable() {
if (!aliasesFolder.mkdirs())
throw new IOException("Could not create the directory " + aliasesFolder);
}

f = new ZipFile(getFile());
for (ZipEntry e : new EnumerationIterable<ZipEntry>(f.entries())) {
if (e.isDirectory())
Expand Down Expand Up @@ -599,7 +600,8 @@ public void onEnable() {
new DamageSourceModule(),
new ItemComponentModule(),
new BrewingModule(),
new CommonModule()
new CommonModule(),
new ParticleModule()
);
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/classes/EnumParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class EnumParser<E extends Enum<E>> extends PatternedParser<E> implements
private final Class<E> enumClass;
private final String languageNode;
private String[] names;
private final Map<String, E> parseMap = new HashMap<>();
protected final Map<String, E> parseMap = new HashMap<>();
private String[] patterns;

/**
Expand Down
58 changes: 28 additions & 30 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import ch.njol.skript.localization.RegexMessage;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.*;
import ch.njol.skript.util.visual.VisualEffect;
import ch.njol.skript.util.visual.VisualEffects;
import ch.njol.yggdrasil.Fields;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -475,34 +473,34 @@ public String toVariableNameString(final Experience xp) {
})
.serializer(new YggdrasilSerializer<>()));

Classes.registerClass(new ClassInfo<>(VisualEffect.class, "visualeffect")
.name("Visual Effect")
.description("A visible effect, e.g. particles.")
.examples("show wolf hearts on the clicked wolf",
"play mob spawner flames at the targeted block to the player")
.usage(VisualEffects.getAllNames())
.since("2.1")
.user("(visual|particle) effects?")
.after("itemtype")
.parser(new Parser<VisualEffect>() {
@Override
@Nullable
public VisualEffect parse(String s, ParseContext context) {
return VisualEffects.parse(s);
}

@Override
public String toString(VisualEffect e, int flags) {
return e.toString(flags);
}

@Override
public String toVariableNameString(VisualEffect e) {
return e.toString();
}

})
.serializer(new YggdrasilSerializer<>()));
// Classes.registerClass(new ClassInfo<>(VisualEffect.class, "visualeffect")
// .name("Visual Effect")
// .description("A visible effect, e.g. particles.")
// .examples("show wolf hearts on the clicked wolf",
// "play mob spawner flames at the targeted block to the player")
// .usage(VisualEffects.getAllNames())
// .since("2.1")
// .user("(visual|particle) effects?")
// .after("itemtype")
// .parser(new Parser<VisualEffect>() {
// @Override
// @Nullable
// public VisualEffect parse(String s, ParseContext context) {
// return VisualEffects.parse(s);
// }
//
// @Override
// public String toString(VisualEffect e, int flags) {
// return e.toString(flags);
// }
//
// @Override
// public String toVariableNameString(VisualEffect e) {
// return e.toString();
// }
//
// })
// .serializer(new YggdrasilSerializer<>()));

Classes.registerClass(new ClassInfo<>(GameruleValue.class, "gamerulevalue")
.user("gamerule values?")
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ch/njol/skript/effects/EffVisualEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
public class EffVisualEffect extends Effect {

static {
Skript.registerEffect(EffVisualEffect.class,
"(play|show) %visualeffects% (on|%directions%) %entities/locations% [(to %-players%|in (radius|range) of %-number%)]",
"(play|show) %number% %visualeffects% (on|%directions%) %entities/locations% [(to %-players%|in (radius|range) of %-number%)]");
// Skript.registerEffect(EffVisualEffect.class,
// "(play|show) %visualeffects% (on|%directions%) %entities/locations% [(to %-players%|in (radius|range) of %-number%)]",
// "(play|show) %number% %visualeffects% (on|%directions%) %entities/locations% [(to %-players%|in (radius|range) of %-number%)]");
}

@SuppressWarnings("NotNullFieldNotInitialized")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private static void addSuperEntity(String codeName, Class<? extends Entity> enti
addSuperEntity("mob", Mob.class);
addSuperEntity("creature", Creature.class);
addSuperEntity("animal", Animals.class);
addSuperEntity("tameable", Tameable.class);
addSuperEntity("fish", Fish.class);
addSuperEntity("golem", Golem.class);
addSuperEntity("projectile", Projectile.class);
Expand Down
112 changes: 72 additions & 40 deletions src/main/java/ch/njol/skript/expressions/ExprVelocity.java
Original file line number Diff line number Diff line change
@@ -1,68 +1,100 @@
package ch.njol.skript.expressions;

import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.entity.Entity;
import org.bukkit.event.Event;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3d;
import org.skriptlang.skript.bukkit.particles.particleeffects.DirectionalEffect;

/**
* @author Sashie
*/
@Name("Vectors - Velocity")
@Description("Gets or changes velocity of an entity.")
@Examples({"set player's velocity to {_v}"})
// TODO: replace with type property expression
@Name("Velocity")
@Description({
"Gets or changes velocity of an entity or particle.",
"Setting the velocity of a particle will remove its random dispersion and force it to be a single particle."
})
@Example("set player's velocity to {_v}")
@Example("set the velocity of {_particle} to vector(0, 1, 0)")
@Example("""
if the vector length of the player's velocity is greater than 5:
send "You're moving fast!" to the player
""")
@Since("2.2-dev31")
public class ExprVelocity extends SimplePropertyExpression<Entity, Vector> {
public class ExprVelocity extends SimplePropertyExpression<Object, Vector> {

static {
register(ExprVelocity.class, Vector.class, "velocit(y|ies)", "entities");
register(ExprVelocity.class, Vector.class, "velocit(y|ies)", "entities/directionalparticles");
}

@Override
@Nullable
public Vector convert(Entity e) {
return e.getVelocity();
public @Nullable Vector convert(Object object) {
if (object instanceof Entity entity)
return entity.getVelocity();
if (object instanceof DirectionalEffect particleEffect && particleEffect.hasVelocity())
return Vector.fromJOML(particleEffect.velocity());
return null;
}

@Override
@Nullable
@SuppressWarnings("null")
public Class<?>[] acceptChange(ChangeMode mode) {
public Class<?> @Nullable [] acceptChange(ChangeMode mode) {
if ((mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET))
return CollectionUtils.array(Vector.class);
return null;
}

@Override
@SuppressWarnings("null")
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
public void change(Event event, Object @Nullable [] delta, ChangeMode mode) {
assert mode == ChangeMode.DELETE || mode == ChangeMode.RESET || delta != null;
for (final Entity entity : getExpr().getArray(e)) {
if (entity == null)
return;
switch (mode) {
case ADD:
entity.setVelocity(entity.getVelocity().add((Vector) delta[0]));
break;
case REMOVE:
entity.setVelocity(entity.getVelocity().subtract((Vector) delta[0]));
break;
case REMOVE_ALL:
break;
case DELETE:
case RESET:
entity.setVelocity(new Vector());
break;
case SET:
entity.setVelocity((Vector) delta[0]);
for (Object object : getExpr().getArray(event)) {
// entities
if (object instanceof Entity entity) {
switch (mode) {
case ADD:
entity.setVelocity(entity.getVelocity().add((Vector) delta[0]));
break;
case REMOVE:
entity.setVelocity(entity.getVelocity().subtract((Vector) delta[0]));
break;
case REMOVE_ALL:
break;
case DELETE:
case RESET:
entity.setVelocity(new Vector());
break;
case SET:
entity.setVelocity((Vector) delta[0]);
}
// particles (don't allow add/remove if no velocity is set)
} else if (object instanceof DirectionalEffect particleEffect) {
switch (mode) {
case ADD:
if (!particleEffect.hasVelocity())
continue;
particleEffect.velocity(particleEffect.velocity().add(((Vector) delta[0]).toVector3d()));
break;
case REMOVE:
if (!particleEffect.hasVelocity())
continue;
particleEffect.velocity(particleEffect.velocity().sub(((Vector) delta[0]).toVector3d()));
break;
case REMOVE_ALL:
break;
case DELETE:
case RESET:
if (!particleEffect.hasVelocity())
continue;
particleEffect.velocity(new Vector3d());
break;
case SET:
particleEffect.velocity(((Vector) delta[0]).toVector3d());
}
}
}
}
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/ch/njol/skript/expressions/ExprXOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Keywords;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.doc.*;
import ch.njol.skript.entity.EntityType;
import ch.njol.skript.expressions.base.PropertyExpression;
import ch.njol.skript.lang.Expression;
Expand All @@ -18,6 +14,7 @@
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.bukkit.particles.particleeffects.ParticleEffect;

import java.lang.reflect.Array;
import java.util.ArrayList;
Expand All @@ -33,7 +30,7 @@ public class ExprXOf extends PropertyExpression<Object, Object> {

static {
Skript.registerExpression(ExprXOf.class, Object.class, ExpressionType.PATTERN_MATCHES_EVERYTHING,
"%number% of %itemstacks/itemtypes/entitytype%");
"%number% of %itemstacks/itemtypes/entitytypes/particles%");
}

private Class<?>[] possibleReturnTypes;
Expand Down Expand Up @@ -63,6 +60,9 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
if (type.canReturn(EntityType.class)) {
possibleReturnTypes.add(EntityType.class);
}
if (type.canReturn(ParticleEffect.class)) {
possibleReturnTypes.add(ParticleEffect.class);
}
this.possibleReturnTypes = possibleReturnTypes.toArray(new Class[0]);

return true;
Expand All @@ -74,20 +74,27 @@ protected Object[] get(Event event, Object[] source) {
if (amount == null)
return (Object[]) Array.newInstance(getReturnType(), 0);

long absAmount = Math.abs(amount.longValue());

return get(source, object -> {
if (object instanceof ItemStack itemStack) {
itemStack = itemStack.clone();
itemStack.setAmount(amount.intValue());
itemStack.setAmount((int) absAmount);
return itemStack;
} else if (object instanceof ItemType itemType) {
ItemType type = itemType.clone();
type.setAmount(amount.intValue());
type.setAmount(absAmount);
return type;
} else {
EntityType entityType = ((EntityType) object).clone();
entityType.amount = amount.intValue();
} else if (object instanceof EntityType ogType) {
EntityType entityType = ogType.clone();
entityType.amount = (int) absAmount;
return entityType;
} else if (object instanceof ParticleEffect particleEffect) {
ParticleEffect effect = particleEffect.copy();
effect.count((int) absAmount);
return effect;
}
return null;
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/ch/njol/skript/lang/SyntaxStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public SyntaxStringBuilder append(@NotNull Object... objects) {
* {@link Debuggable#toString(Event, boolean)}.
*
* @param condition The condition.
* @param object The object to add.
* @param object The object to add. Ensure this is not null.
* @return The builder.
* @see #append(Object)
*/
public SyntaxStringBuilder appendIf(boolean condition, @NotNull Object object) {
public SyntaxStringBuilder appendIf(boolean condition, Object object) {
if (condition) {
append(object);
}
Expand All @@ -87,11 +87,11 @@ public SyntaxStringBuilder appendIf(boolean condition, @NotNull Object object) {
* Spaces are automatically added between the provided objects.
*
* @param condition The condition.
* @param objects The objects to add.
* @param objects The objects to add. Ensure this is not null.
* @return The builder.
* @see #append(Object...)
*/
public SyntaxStringBuilder appendIf(boolean condition, @NotNull Object... objects) {
public SyntaxStringBuilder appendIf(boolean condition, Object... objects) {
if (condition) {
append(objects);
}
Expand Down
Loading
Loading