Skip to content

Commit

Permalink
Merge branch 'dev/feature' into dev/GhastSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAbsolutionism authored Mar 2, 2025
2 parents c99268c + 9af7c9e commit a340e6b
Show file tree
Hide file tree
Showing 34 changed files with 594 additions and 148 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ fabric.properties

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

# Exception for the icon
!.idea/icon.png

*.iml
modules.xml
.idea/misc.xml
Expand Down
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.parallel=true

groupid=ch.njol
name=skript
version=2.10.0
version=2.10.1
jarName=Skript.jar
testEnv=java21/paper-1.21.4
testEnvJavaVersion=21
44 changes: 12 additions & 32 deletions src/main/java/ch/njol/skript/classes/data/BukkitClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.PotionEffectUtils;
import ch.njol.skript.util.StringMode;
import ch.njol.skript.util.Utils;
import ch.njol.util.StringUtils;
import ch.njol.yggdrasil.Fields;
import io.papermc.paper.world.MoonPhase;
Expand Down Expand Up @@ -71,10 +72,7 @@ public class BukkitClasses {

public BukkitClasses() {}

public static final Pattern UUID_PATTERN = Pattern.compile("(?i)[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}");

static {
final boolean GET_ENTITY_METHOD_EXISTS = Skript.methodExists(Bukkit.class, "getEntity", UUID.class);
Classes.registerClass(new ClassInfo<>(Entity.class, "entity")
.user("entit(y|ies)")
.name("Entity")
Expand All @@ -91,25 +89,10 @@ public BukkitClasses() {}
.defaultExpression(new EventValueExpression<>(Entity.class))
.parser(new Parser<Entity>() {
@Override
@Nullable
public Entity parse(final String s, final ParseContext context) {
UUID uuid;
try {
uuid = UUID.fromString(s);
} catch (IllegalArgumentException iae) {
return null;
}
if (GET_ENTITY_METHOD_EXISTS) {
return Bukkit.getEntity(uuid);
} else {
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (entity.getUniqueId().equals(uuid)) {
return entity;
}
}
}
}
public @Nullable Entity parse(final String s, final ParseContext context) {
if (Utils.isValidUUID(s))
return Bukkit.getEntity(UUID.fromString(s));

return null;
}

Expand Down Expand Up @@ -643,8 +626,10 @@ public Player parse(String string, ParseContext context) {
if (context == ParseContext.COMMAND || context == ParseContext.PARSE) {
if (string.isEmpty())
return null;
if (UUID_PATTERN.matcher(string).matches())

if (Utils.isValidUUID(string))
return Bukkit.getPlayer(UUID.fromString(string));

String name = string.toLowerCase(Locale.ENGLISH);
int nameLength = name.length(); // caching
List<Player> players = new ArrayList<>();
Expand Down Expand Up @@ -709,16 +694,11 @@ public String getDebugMessage(final Player p) {
.after("string", "world")
.parser(new Parser<OfflinePlayer>() {
@Override
@Nullable
public OfflinePlayer parse(final String s, final ParseContext context) {
if (context == ParseContext.COMMAND || context == ParseContext.PARSE) {
if (UUID_PATTERN.matcher(s).matches())
return Bukkit.getOfflinePlayer(UUID.fromString(s));
else if (!SkriptConfig.playerNameRegexPattern.value().matcher(s).matches())
return null;
public @Nullable OfflinePlayer parse(final String s, final ParseContext context) {
if (Utils.isValidUUID(s))
return Bukkit.getOfflinePlayer(UUID.fromString(s));
else if (SkriptConfig.playerNameRegexPattern.value().matcher(s).matches())
return Bukkit.getOfflinePlayer(s);
}
assert false;
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.skriptlang.skript.lang.comparator.Relation;

import java.util.Objects;
import java.util.UUID;

@SuppressWarnings({"rawtypes"})
public class DefaultComparators {
Expand Down Expand Up @@ -665,6 +666,10 @@ public Relation compare(EntitySnapshot snap1, EntitySnapshot snap2) {
}
});
}

// UUID
Comparators.registerComparator(UUID.class, UUID.class, (one, two) -> Relation.get(one.equals(two)));
Comparators.registerComparator(UUID.class, String.class, (one, two) -> Relation.get(one.toString().equals(two)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.skriptlang.skript.lang.converter.Converters;
import org.skriptlang.skript.lang.script.Script;

import java.util.UUID;

public class DefaultConverters {

public DefaultConverters() {}
Expand Down Expand Up @@ -277,6 +279,9 @@ public void setAmount(Number amount) {
Converters.registerConverter(Script.class, Config.class, Script::getConfig);
Converters.registerConverter(Config.class, Node.class, Config::getMainNode);

// UUID -> String
Converters.registerConverter(UUID.class, String.class, UUID::toString);

// // Entity - String (UUID) // Very slow, thus disabled for now
// Converters.registerConverter(String.class, Entity.class, new Converter<String, Entity>() {
//
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/ch/njol/skript/classes/data/DefaultFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import ch.njol.skript.lang.util.SimpleLiteral;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.DefaultClasses;
import ch.njol.skript.util.Color;
import ch.njol.skript.util.ColorRGB;
import ch.njol.skript.util.Contract;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.*;
import ch.njol.util.Math2;
import ch.njol.util.StringUtils;
import ch.njol.util.coll.CollectionUtils;
Expand Down Expand Up @@ -544,9 +541,8 @@ public Player[] executeSimple(Object[][] params) {
boolean isExact = (boolean) params[1][0];
UUID uuid = null;
if (name.length() > 16 || name.contains("-")) { // shortcut
try {
if (Utils.isValidUUID(name))
uuid = UUID.fromString(name);
} catch (IllegalArgumentException ignored) {}
}
return CollectionUtils.array(uuid != null ? Bukkit.getPlayer(uuid) : (isExact ? Bukkit.getPlayerExact(name) : Bukkit.getPlayer(name)));
}
Expand All @@ -569,10 +565,8 @@ public OfflinePlayer[] executeSimple(Object[][] params) {
String name = (String) params[0][0];
UUID uuid = null;
if (name.length() > 16 || name.contains("-")) { // shortcut
try {
if (Utils.isValidUUID(name))
uuid = UUID.fromString(name);
} catch (IllegalArgumentException ignored) {
}
}
OfflinePlayer result;

Expand Down Expand Up @@ -711,6 +705,22 @@ public String[] executeSimple(Object[][] params) {
"\t\tset {_money} to formatNumber({money::%sender's uuid%})",
"\t\tsend \"Your balance: %{_money}%\" to sender")
.since("2.10");

Functions.registerFunction(new SimpleJavaFunction<>("uuid", new Parameter[]{
new Parameter<>("uuid", DefaultClasses.STRING, true, null)
}, Classes.getExactClassInfo(UUID.class), true) {
@Override
public UUID[] executeSimple(Object[][] params) {
String uuid = (String) params[0][0];
if (Utils.isValidUUID(uuid))
return CollectionUtils.array(UUID.fromString(uuid));
return new UUID[0];
}
}
.description("Returns a UUID from the given string. The string must be in the format of a UUID.")
.examples("uuid(\"069a79f4-44e9-4726-a5be-fca90e38aaf5\")")
.since("INSERT VERSION")
);
}

}
72 changes: 72 additions & 0 deletions src/main/java/ch/njol/skript/classes/data/JavaClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;

import java.io.StreamCorruptedException;
import java.util.UUID;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -325,6 +327,19 @@ public String toVariableNameString(Quaternionf quaternion) {
return null;
}
}));

Classes.registerClass(new ClassInfo<>(UUID.class, "uuid")
.user("uuids?")
.name("UUID")
.description(
"UUIDs are unique identifiers that ensure things can be reliably distinguished from each other. "
+ "They are generated in a way that makes it practically impossible for duplicates to occur.",
"Read more about UUIDs and how they are used in Minecraft "
+ "in <a href='https://minecraft.wiki/w/UUID'>the wiki entry about UUIDs</a>.")
.since("INSERT VERSION")
.parser(new UUIDParser())
.serializer(new UUIDSerializer())
);
}

/**
Expand Down Expand Up @@ -793,4 +808,61 @@ public boolean mustSyncDeserialization() {

}

private static class UUIDParser extends Parser<UUID> {

@Override
public @Nullable UUID parse(String string, ParseContext context) {
if (Utils.isValidUUID(string))
return UUID.fromString(string);
return null;
}

@Override
public String toString(UUID uuid, int flags) {
return uuid.toString();
}

@Override
public String toVariableNameString(UUID uuid) {
return uuid.toString();
}

}

private static class UUIDSerializer extends Serializer<UUID> {

@Override
public Fields serialize(UUID uuid) {
Fields fields = new Fields();

fields.putPrimitive("mostsignificantbits", uuid.getMostSignificantBits());
fields.putPrimitive("leastsignificantbits", uuid.getLeastSignificantBits());

return fields;
}

@Override
public void deserialize(UUID o, Fields f) {
assert false;
}

@Override
protected UUID deserialize(Fields fields) throws StreamCorruptedException {
long mostSignificantBits = fields.getAndRemovePrimitive("mostsignificantbits", long.class);
long leastSignificantBits = fields.getAndRemovePrimitive("leastsignificantbits", long.class);
return new UUID(mostSignificantBits, leastSignificantBits);
}

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

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

}

}
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
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
Loading

0 comments on commit a340e6b

Please sign in to comment.