Skip to content

Commit 6bd6758

Browse files
authored
Merge branch 'dev/feature' into feature/better-enchanted-condition
2 parents dc8885b + e36f264 commit 6bd6758

63 files changed

Lines changed: 1928 additions & 508 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/pull_request_template.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
### Description
2-
<!--- Describe your changes here. --->
1+
### Problem
2+
<!--- Why is this PR necessary? What problems exist that needed solving? --->
3+
4+
5+
### Solution
6+
<!--- Explain how your solution fixes the problem and summarize the major code changes. --->
7+
8+
9+
### Testing Completed
10+
<!--- List test scripts/unit tests and any manual testing that was performed. If no test scripts or unit tests are present, explain why. --->
11+
12+
13+
### Supporting Information
14+
<!--- Any related information, todos, breaking changes, or outstanding issues can be described here --->
15+
316

417
---
5-
**Target Minecraft Versions:** any <!-- 'any' means all supported versions -->
6-
**Requirements:** none <!-- Required plugins, server software... -->
7-
**Related Issues:** none <!-- Links to related issues -->
18+
**Completes:** none <!-- Links to issues or discussions that should be completed when this PR is merged. -->
19+
**Related:** none <!-- Links to issues or discussions with related information -->

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ allprojects {
2727
dependencies {
2828
shadow group: 'io.papermc', name: 'paperlib', version: '1.0.8'
2929
shadow group: 'org.bstats', name: 'bstats-bukkit', version: '3.1.0'
30-
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.3.4'
30+
shadow group: 'net.kyori', name: 'adventure-text-serializer-bungeecord', version: '4.4.0'
3131

3232
implementation group: 'io.papermc.paper', name: 'paper-api', version: '1.21.5-R0.1-SNAPSHOT'
3333
implementation group: 'com.google.code.findbugs', name: 'findbugs', version: '3.0.1'

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.parallel=true
55

66
groupid=ch.njol
77
name=skript
8-
version=2.11.1
8+
version=2.11.2
99
jarName=Skript.jar
1010
testEnv=java21/paper-1.21.5
1111
testEnvJavaVersion=21

src/main/java/ch/njol/skript/classes/data/BukkitClasses.java

Lines changed: 83 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
1111
import ch.njol.skript.classes.*;
1212
import ch.njol.skript.classes.registry.RegistryClassInfo;
1313
import ch.njol.skript.entity.EntityData;
14-
import ch.njol.skript.entity.WolfData;
14+
import ch.njol.skript.entity.PigData.PigVariantDummy;
15+
import ch.njol.skript.entity.WolfData.WolfVariantDummy;
1516
import ch.njol.skript.expressions.ExprDamageCause;
1617
import ch.njol.skript.expressions.base.EventValueExpression;
1718
import ch.njol.skript.lang.ParseContext;
1819
import ch.njol.skript.lang.util.SimpleLiteral;
1920
import ch.njol.skript.localization.Language;
2021
import ch.njol.skript.registrations.Classes;
21-
import ch.njol.skript.util.BlockUtils;
22-
import ch.njol.skript.util.PotionEffectUtils;
23-
import ch.njol.skript.util.StringMode;
24-
import ch.njol.skript.util.Utils;
22+
import ch.njol.skript.util.*;
2523
import ch.njol.yggdrasil.Fields;
2624
import io.papermc.paper.world.MoonPhase;
2725
import org.bukkit.*;
@@ -44,6 +42,7 @@
4442
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
4543
import org.bukkit.event.entity.EntityTransformEvent.TransformReason;
4644
import org.bukkit.event.entity.EntityUnleashEvent;
45+
import org.bukkit.event.entity.VillagerCareerChangeEvent;
4746
import org.bukkit.event.inventory.ClickType;
4847
import org.bukkit.event.inventory.InventoryAction;
4948
import org.bukkit.event.inventory.InventoryCloseEvent;
@@ -52,6 +51,7 @@
5251
import org.bukkit.event.player.PlayerQuitEvent.QuitReason;
5352
import org.bukkit.event.player.PlayerResourcePackStatusEvent.Status;
5453
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
54+
import org.bukkit.inventory.BlockInventoryHolder;
5555
import org.bukkit.inventory.*;
5656
import org.bukkit.metadata.Metadatable;
5757
import org.bukkit.potion.PotionEffect;
@@ -1410,14 +1410,15 @@ public String toVariableNameString(EnchantmentOffer eo) {
14101410
.description("Represents the cause of the action of a potion effect on an entity, e.g. arrow, command")
14111411
.since("2.10"));
14121412

1413-
ClassInfo<?> wolfVariantClassInfo;
1414-
if (Skript.classExists("org.bukkit.entity.Wolf$Variant") && BukkitUtils.registryExists("WOLF_VARIANT")) {
1415-
wolfVariantClassInfo = new RegistryClassInfo<>(Wolf.Variant.class, Registry.WOLF_VARIANT, "wolfvariant", "wolf variants");
1416-
} else {
1417-
/*
1418-
* Registers a dummy/placeholder class to ensure working operation on MC versions that do not have `Wolf.Variant`
1419-
*/
1420-
wolfVariantClassInfo = new ClassInfo<>(WolfData.VariantDummy.class, "wolfvariant");
1413+
ClassInfo<?> wolfVariantClassInfo = getRegistryClassInfo(
1414+
"org.bukkit.entity.Wolf$Variant",
1415+
"WOLF_VARIANT",
1416+
"wolfvariant",
1417+
"wolf variants"
1418+
);
1419+
if (wolfVariantClassInfo == null) {
1420+
// Registers a dummy/placeholder class to ensure working operation on MC versions that do not have 'Wolf.Variant' (1.20.4-)
1421+
wolfVariantClassInfo = new ClassInfo<>(WolfVariantDummy.class, "wolfvariant");
14211422
}
14221423
Classes.registerClass(wolfVariantClassInfo
14231424
.user("wolf ?variants?")
@@ -1550,14 +1551,82 @@ public String toVariableNameString(WorldBorder border) {
15501551
.changer(DefaultChangers.entityChanger)
15511552
);
15521553

1553-
15541554
Classes.registerClass(new EnumClassInfo<>(EquipmentSlot.class, "equipmentslot", "equipment slots")
15551555
.user("equipment ?slots?")
15561556
.name("Equipment Slot")
15571557
.description("Represents an equipment slot of an entity.")
15581558
.since("2.11")
15591559
);
15601560

1561+
ClassInfo<?> pigVariantClassInfo = getRegistryClassInfo(
1562+
"org.bukkit.entity.Pig$Variant",
1563+
"PIG_VARIANT",
1564+
"pigvariant",
1565+
"pig variants"
1566+
);
1567+
if (pigVariantClassInfo == null) {
1568+
// Registers a dummy/placeholder class to ensure working operation on MC versions that do not have 'Pig.Variant' (1.21.4-)
1569+
pigVariantClassInfo = new ClassInfo<>(PigVariantDummy.class, "pigvariant");
1570+
}
1571+
Classes.registerClass(pigVariantClassInfo
1572+
.user("pig ?variants?")
1573+
.name("Pig Variant")
1574+
.description("Represents the variant of a pig entity.",
1575+
"NOTE: Minecraft namespaces are supported, ex: 'minecraft:warm'.")
1576+
.since("INSERT VERSION")
1577+
.requiredPlugins("Minecraft 1.21.5+")
1578+
.documentationId("PigVariant"));
1579+
1580+
Classes.registerClass(new EnumClassInfo<>(VillagerCareerChangeEvent.ChangeReason.class, "villagercareerchangereason", "villager career change reasons")
1581+
.user("(villager )?career ?change ?reasons?")
1582+
.name("Villager Career Change Reason")
1583+
.description("Represents a reason why a villager changed its career.")
1584+
.since("INSERT VERSION")
1585+
);
1586+
1587+
}
1588+
1589+
/**
1590+
* Gets a {@link RegistryClassInfo} by checking if the {@link Class} from {@code classPath} exists
1591+
* and {@link Registry} or {@link io.papermc.paper.registry.RegistryKey} contains {@code registryName}.
1592+
* @param classPath The {@link String} representation of the desired {@link Class}.
1593+
* @param registryName The {@link String} representation of the desired {@link Registry}.
1594+
* @param codeName The name used in patterns.
1595+
* @param languageNode The language node of the type.
1596+
* @return {@link RegistryClassInfo} if the class and registry exists, otherwise {@code null}.
1597+
*/
1598+
private static <R extends Keyed> @Nullable RegistryClassInfo<?> getRegistryClassInfo(
1599+
String classPath,
1600+
String registryName,
1601+
String codeName,
1602+
String languageNode
1603+
) {
1604+
if (!Skript.classExists(classPath))
1605+
return null;
1606+
Registry<R> registry = null;
1607+
if (BukkitUtils.registryExists(registryName)) {
1608+
try {
1609+
//noinspection unchecked
1610+
registry = (Registry<R>) Registry.class.getField(registryName).get(null);
1611+
} catch (NoSuchFieldException | IllegalAccessException e) {
1612+
throw new RuntimeException(e);
1613+
}
1614+
} else if (PaperUtils.registryExists(registryName)) {
1615+
registry = PaperUtils.getBukkitRegistry(registryName);
1616+
}
1617+
if (registry != null) {
1618+
Class<R> registryClass;
1619+
try {
1620+
//noinspection unchecked
1621+
registryClass = (Class<R>) Class.forName(classPath);
1622+
} catch (ClassNotFoundException e) {
1623+
Skript.debug("Could not retrieve the class with the path: '" + classPath + "'.");
1624+
throw new RuntimeException(e);
1625+
}
1626+
return new RegistryClassInfo<>(registryClass, registry, codeName, languageNode);
1627+
}
1628+
Skript.debug("There were no registries found for '" + registryName + "'.");
1629+
return null;
15611630
}
15621631

15631632
}

src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import ch.njol.skript.util.*;
1414
import ch.njol.skript.util.slot.InventorySlot;
1515
import ch.njol.skript.util.slot.Slot;
16-
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
1716
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
1817
import com.destroystokyo.paper.event.entity.EndermanAttackPlayerEvent;
1918
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
@@ -33,6 +32,7 @@
3332
import org.bukkit.command.BlockCommandSender;
3433
import org.bukkit.command.CommandSender;
3534
import org.bukkit.entity.*;
35+
import org.bukkit.entity.Villager.Profession;
3636
import org.bukkit.event.block.*;
3737
import org.bukkit.event.enchantment.EnchantItemEvent;
3838
import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
@@ -547,8 +547,6 @@ else if (hand == EquipmentSlot.OFF_HAND)
547547
EventValues.registerEventValue(EntityMoveEvent.class, Location.class, EntityMoveEvent::getFrom);
548548
EventValues.registerEventValue(EntityMoveEvent.class, Location.class, EntityMoveEvent::getTo, TIME_FUTURE);
549549
}
550-
//PlayerToggleFlightEvent
551-
EventValues.registerEventValue(PlayerToggleFlightEvent.class, Player.class, PlayerEvent::getPlayer);
552550
//CreatureSpawnEvent
553551
EventValues.registerEventValue(CreatureSpawnEvent.class, SpawnReason.class, CreatureSpawnEvent::getSpawnReason);
554552
//FireworkExplodeEvent
@@ -773,6 +771,23 @@ public void set(VaultDisplayItemEvent event, @Nullable ItemStack itemStack) {
773771
});
774772
}
775773

774+
EventValues.registerEventValue(VillagerCareerChangeEvent.class, VillagerCareerChangeEvent.ChangeReason.class, VillagerCareerChangeEvent::getReason);
775+
EventValues.registerEventValue(VillagerCareerChangeEvent.class, Villager.Profession.class, new EventConverter<>() {
776+
@Override
777+
public void set(VillagerCareerChangeEvent event, @Nullable Profession profession) {
778+
if (profession == null)
779+
return;
780+
event.setProfession(profession);
781+
}
782+
783+
@Override
784+
public Profession convert(VillagerCareerChangeEvent event) {
785+
return event.getProfession();
786+
}
787+
});
788+
EventValues.registerEventValue(VillagerCareerChangeEvent.class, Villager.Profession.class,
789+
event -> event.getEntity().getProfession(), TIME_PAST);
790+
776791
}
777792

778793
}

src/main/java/ch/njol/skript/classes/data/DefaultOperations.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import ch.njol.skript.util.Timespan;
55
import ch.njol.skript.util.Timespan.TimePeriod;
66
import ch.njol.skript.util.Utils;
7-
import ch.njol.util.Math2;
87
import org.bukkit.util.Vector;
98
import org.skriptlang.skript.lang.arithmetic.Arithmetics;
109
import org.skriptlang.skript.lang.arithmetic.Operator;
@@ -91,9 +90,9 @@ public class DefaultOperations {
9190
});
9291

9392
// Timespan - Timespan
94-
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, (left, right) -> new Timespan(Math2.addClamped(left.getAs(TimePeriod.MILLISECOND), right.getAs(TimePeriod.MILLISECOND))));
95-
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, (left, right) -> new Timespan(Math.max(0, left.getAs(TimePeriod.MILLISECOND) - right.getAs(TimePeriod.MILLISECOND))));
96-
Arithmetics.registerDifference(Timespan.class, (left, right) -> new Timespan(Math.abs(left.getAs(TimePeriod.MILLISECOND) - right.getAs(TimePeriod.MILLISECOND))));
93+
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, Timespan::add);
94+
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, Timespan::subtract);
95+
Arithmetics.registerDifference(Timespan.class, Timespan::difference);
9796
Arithmetics.registerDefaultValue(Timespan.class, Timespan::new);
9897

9998
// Timespan - Number
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ch.njol.skript.conditions;
2+
3+
import ch.njol.skript.conditions.base.PropertyCondition;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import org.bukkit.entity.LivingEntity;
9+
import org.bukkit.entity.Strider;
10+
11+
@Name("Strider Is Shivering")
12+
@Description("Whether a strider is shivering.")
13+
@Example("""
14+
if last spawned strider is shivering:
15+
make last spawned strider stop shivering
16+
""")
17+
@Since("INSERT VERSION")
18+
public class CondStriderIsShivering extends PropertyCondition<LivingEntity> {
19+
20+
static {
21+
register(CondStriderIsShivering.class, "shivering", "livingentities");
22+
}
23+
24+
@Override
25+
public boolean check(LivingEntity entity) {
26+
return entity instanceof Strider strider && strider.isShivering();
27+
}
28+
29+
@Override
30+
protected String getPropertyName() {
31+
return "shivering";
32+
}
33+
34+
}

src/main/java/ch/njol/skript/effects/EffExit.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
101101
debug(event, false);
102102
for (SectionExitHandler section : sectionsToExit)
103103
section.exit(event);
104-
if (outerSection == null)
104+
if (outerSection == null) // "stop trigger"
105105
return null;
106106
return outerSection instanceof LoopSection loopSection ? loopSection.getActualNext() : outerSection.getNext();
107107
}
@@ -113,11 +113,15 @@ protected void execute(Event event) {
113113

114114
@Override
115115
public @Nullable ExecutionIntent executionIntent() {
116+
if (outerSection == null)
117+
return ExecutionIntent.stopTrigger();
116118
return ExecutionIntent.stopSections(breakLevels);
117119
}
118120

119121
@Override
120122
public String toString(@Nullable Event event, boolean debug) {
123+
if (outerSection == null)
124+
return "stop trigger";
121125
return "stop " + breakLevels + " " + names[type];
122126
}
123127

0 commit comments

Comments
 (0)