Skip to content

Commit

Permalink
Merge branch 'dev/patch' into fix/regex-highlight-runtime-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus authored Feb 1, 2025
2 parents c533546 + aa19393 commit aff68dc
Show file tree
Hide file tree
Showing 25 changed files with 295 additions and 49 deletions.
12 changes: 8 additions & 4 deletions src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,19 @@ public String toVariableNameString(final Timeperiod o) {
@Override
public Fields serialize(Date date) {
Fields fields = new Fields();
fields.putPrimitive("time", date.getTime());
fields.putPrimitive("timestamp", date.getTime());
return fields;
}


@Override
protected Date deserialize(Fields fields)
throws StreamCorruptedException {
long time = fields.getPrimitive("time", long.class);
protected Date deserialize(Fields fields) throws StreamCorruptedException {
long time;
if (fields.hasField("time")) { // compatibility for 2.10.0 (#7542)
time = fields.getPrimitive("time", long.class);
} else {
time = fields.getPrimitive("timestamp", long.class);
}
return new Date(time);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ private void refresh() {
String namespace = namespacedKey.getNamespace();
String key = namespacedKey.getKey();
String keyWithSpaces = key.replace("_", " ");
String languageKey = languageNode + "." + key;
String languageKey;

// Put the full namespaced key as a pattern
parseMap.put(namespacedKey.toString(), registryObject);

// If the object is a vanilla Minecraft object, we'll add the key with spaces as a pattern
if (namespace.equalsIgnoreCase(NamespacedKey.MINECRAFT)) {
parseMap.put(keyWithSpaces, registryObject);
languageKey = languageNode + "." + key;
} else {
languageKey = namespacedKey.toString();
}

String[] options = Language.getList(languageKey);
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/ch/njol/skript/conditions/CondIsWearing.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.njol.skript.conditions;

import ch.njol.skript.Skript;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.conditions.base.PropertyCondition.PropertyType;
Expand All @@ -12,7 +13,7 @@
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.entity.*;
import org.bukkit.event.Event;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
Expand All @@ -30,6 +31,9 @@
})
@Since("1.0")
public class CondIsWearing extends Condition {

private static final boolean HAS_CAN_USE_SLOT_METHOD = Skript.methodExists(LivingEntity.class, "canUseEquipmentSlot", EquipmentSlot.class);
private static final boolean HAS_BODY_SLOT = Skript.fieldExists(EquipmentSlot.class, "BODY");

static {
PropertyCondition.register(CondIsWearing.class, "wearing %itemtypes%", "livingentities");
Expand Down Expand Up @@ -59,6 +63,21 @@ public boolean check(Event event) {
return false; // spigot nullability, no identifier as to why this occurs

ItemStack[] contents = Arrays.stream(EquipmentSlot.values())
.filter(slot -> {
// this method was added in 1.20.6
if (HAS_CAN_USE_SLOT_METHOD)
return entity.canUseEquipmentSlot(slot);

// body slot was added in 1.20.5
if (HAS_BODY_SLOT && slot == EquipmentSlot.BODY)
// this may change in the future, but for now this is the only way to figure out
// if the entity can use the body slot
return entity instanceof Horse
|| entity instanceof Wolf
|| entity instanceof Llama;

return true;
})
.map(equipment::getItem)
.toArray(ItemStack[]::new);

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ch/njol/skript/effects/EffConnect.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class EffConnect extends Effect {

static {
Skript.registerEffect(EffConnect.class,
"(send|connect) %players% to [proxy|bungeecord] [server] %string%",
"connect %players% to [proxy|bungeecord] [server] %string%",
"send %players% to [proxy|bungeecord] server %string%",
"transfer %players% to server %string% [on port %-number%]"
);
}
Expand All @@ -51,7 +52,7 @@ public class EffConnect extends Effect {
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
players = (Expression<Player>) exprs[0];
server = (Expression<String>) exprs[1];
transfer = matchedPattern == 1;
transfer = matchedPattern == 2;

if (transfer) {
port = (Expression<Number>) exprs[2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class ExprExperienceCooldown extends SimplePropertyExpression<Player, Timespan> {

static {
register(ExprExperienceCooldown.class, Timespan.class, "[the] (experience|[e]xp) [pickup|collection] cooldown", "players");
register(ExprExperienceCooldown.class, Timespan.class, "(experience|[e]xp) [pickup|collection] cooldown", "players");
}

private static final int maxTicks = Integer.MAX_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ExprExperienceCooldownChangeReason extends EventValueExpression<ChangeReason> {

static {
register(ExprExperienceCooldownChangeReason.class, ChangeReason.class, "[the] (experience|[e]xp) cooldown change (reason|cause|type)");
register(ExprExperienceCooldownChangeReason.class, ChangeReason.class, "(experience|[e]xp) cooldown change (reason|cause|type)");
}

public ExprExperienceCooldownChangeReason() {
Expand Down
21 changes: 5 additions & 16 deletions src/main/java/ch/njol/skript/expressions/ExprNewBannerPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,23 @@
"remove {_pattern} from banner patterns of {_banneritem}",
"set the 1st banner pattern of block at location(0,0,0) to {_pattern}",
"clear the 1st banner pattern of block at location(0,0,0)",
"",
"set {_pattern} to a red mojang banner pattern"
})
@Since("2.10")
public class ExprNewBannerPattern extends SimpleExpression<Pattern> {

static {
Skript.registerExpression(ExprNewBannerPattern.class, Pattern.class, ExpressionType.PATTERN_MATCHES_EVERYTHING,
"[a] %bannerpatterntype% colo[u]red %color%",
"[a] %*color% %bannerpatterntype%");
Skript.registerExpression(ExprNewBannerPattern.class, Pattern.class, ExpressionType.COMBINED,
"[a] %bannerpatterntype% colo[u]red %color%");
}

private Expression<PatternType> selectedPattern;
private Expression<Color> selectedColor;

@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
if (matchedPattern == 0) {
//noinspection unchecked
selectedPattern = (Expression<PatternType>) exprs[0];
//noinspection unchecked
selectedColor = (Expression<Color>) exprs[1];
} else {
//noinspection unchecked
selectedPattern = (Expression<PatternType>) exprs[1];
//noinspection unchecked
selectedColor = (Expression<Color>) exprs[0];
}
selectedPattern = (Expression<PatternType>) exprs[0];
selectedColor = (Expression<Color>) exprs[1];
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/sections/SecFor.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean init(Expression<?>[] exprs,
}
//</editor-fold>
this.loadOptionalCode(sectionNode);
super.setNext(this);
this.setInternalNext(this);
return true;
}

Expand Down
17 changes: 12 additions & 5 deletions src/main/java/ch/njol/skript/sections/SecLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public boolean init(Expression<?>[] exprs,

guaranteedToLoop = guaranteedToLoop(expression);
loadOptionalCode(sectionNode);
super.setNext(this);
this.setInternalNext(this);

return true;
}
Expand All @@ -130,11 +130,11 @@ public boolean init(Expression<?>[] exprs,
if (iter == null) {
if (iterableSingle) {
Object value = expression.getSingle(event);
if (value instanceof Iterable<?> iterable) {
iter = iterable.iterator();
// Guaranteed to be ordered so we try it first
} else if (value instanceof Container<?> container) {
if (value instanceof Container<?> container) {
// Container may have special behaviour over regular iterator
iter = container.containerIterator();
} else if (value instanceof Iterable<?> iterable) {
iter = iterable.iterator();
} else {
iter = Collections.singleton(value).iterator();
}
Expand Down Expand Up @@ -210,6 +210,13 @@ public SecLoop setNext(@Nullable TriggerItem next) {
return this;
}

/**
* @see LoopSection#setNext(TriggerItem)
*/
protected void setInternalNext(TriggerItem item) {
super.setNext(item);
}

@Nullable
@Override
public TriggerItem getActualNext() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/test/platform/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public TestResults runTests(Path runnerRoot, Path testsRoot, boolean devMode, bo
args.add("-Ddisable.watchdog=true");
if (debug)
args.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000");
args.add("-Duser.language=en");
args.add("-Duser.country=US");
args.addAll(jvmArgs);
args.addAll(Arrays.asList(commandLine));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Description("Checks if the lure enchantment is applied to the current fishing event.")
@Examples({
"on fishing line cast:",
"\tif lure enchantment is applied:",
"\tif lure enchantment bonus is applied:",
"\t\tcancel event"
})
@Events("Fishing")
Expand Down Expand Up @@ -49,7 +49,7 @@ public boolean check(Event event) {

@Override
public String toString(@Nullable Event event, boolean debug) {
return "lure enchantment " + (isNegated() ? "is" : "isn't") + " applied";
return "lure enchantment bonus " + (isNegated() ? "is" : "isn't") + " applied";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
})
@Examples({
"on fish approach:",
"\tif fishing approach angle is bigger than 300.5 degrees or fishing approach angle is smaller than 59.5 degrees:",
"\tif any:",
"\t\tmaximum fishing approach angle is bigger than 300.5 degrees",
"\t\tmin fishing approach angle is smaller than 59.5 degrees",
"\tthen:",
"\t\tcancel event"
})
@Events("Fishing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
})
@Examples({
"on fish approach:",
"\tset fishing bite time to 5 seconds",
"\tset fishing bite time to 5 seconds",
})
@RequiredPlugins("Paper 1.20.6")
@Events("Fishing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
})
@Examples({
"on fishing line cast:",
"\tset min waiting time to 10 seconds",
"\tset max waiting time to 20 seconds",
"\tset min fish waiting time to 10 seconds",
"\tset max fishing waiting time to 20 seconds",
})
@Events("Fishing")
@Since("2.10")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.EventValues;
import ch.njol.yggdrasil.Fields;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
Expand All @@ -18,6 +20,7 @@
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.StreamCorruptedException;

public class LootTableModule {

Expand Down Expand Up @@ -53,6 +56,42 @@ public String toVariableNameString(LootTable o) {
return "loot table:" + o.getKey();
}
})
.serializer(new Serializer<>() {
@Override
public Fields serialize(LootTable lootTable) {
Fields fields = new Fields();
fields.putObject("key", lootTable.getKey().toString());
return fields;
}

@Override
public void deserialize(LootTable lootTable, Fields fields) {
assert false;
}

@Override
protected LootTable deserialize(Fields fields) throws StreamCorruptedException {
String key = fields.getAndRemoveObject("key", String.class);
if (key == null)
throw new StreamCorruptedException();

NamespacedKey namespacedKey = NamespacedKey.fromString(key);
if (namespacedKey == null)
throw new StreamCorruptedException();

return Bukkit.getLootTable(namespacedKey);
}

@Override
public boolean mustSyncDeserialization() {
return true;
}

@Override
protected boolean canBeInstantiated() {
return false;
}
})
);

Classes.registerClass(new ClassInfo<>(LootContext.class, "lootcontext")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,22 @@ public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean is

@Override
public boolean check(Event event) {
Tag<Keyed>[] tags = this.tags.getArray(event);
Tag<Keyed>[] tags = this.tags.getAll(event);
if (tags.length == 0)
return isNegated();
boolean and = this.tags.getAnd();
return elements.check(event, element -> {
boolean isAny = (element instanceof ItemType itemType && !itemType.isAll());
Keyed[] values = TagModule.getKeyed(element);
if (values == null)
if (values == null || values.length == 0)
return false;

Class<? extends Keyed> valueClass = values[0].getClass();

for (Tag<Keyed> tag : tags) {
// cursed check to ensure the tag is the same type as the values
if (!tag.getValues().iterator().next().getClass().isAssignableFrom(valueClass))
return false;
if (isTagged(tag, values, !isAny)) {
if (!and)
return true;
Expand Down
Loading

0 comments on commit aff68dc

Please sign in to comment.