Skip to content

Commit 32d3f48

Browse files
authored
Merge branch 'dev/feature' into feature/better-enchanted-condition
2 parents a254884 + 5dce04a commit 32d3f48

76 files changed

Lines changed: 1437 additions & 534 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.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Update the gradle wrapper to the latest version
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0'
6+
7+
jobs:
8+
update-gradle-wrapper:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
submodules: recursive
16+
- name: Set up JDK 21
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '21'
20+
distribution: 'adopt'
21+
cache: gradle
22+
- name: Grant execute permission for gradlew
23+
run: chmod +x gradlew
24+
- name: Get latest Gradle version
25+
id: get_latest_gradle
26+
run: |
27+
response=$(curl -s https://services.gradle.org/versions/current)
28+
latest_version=$(echo $response | jq -r '.version')
29+
echo "LATEST_GRADLE_VERSION=$latest_version" >> $GITHUB_ENV
30+
latest_download_url=$(echo $response | jq -r '.downloadUrl')
31+
echo "LATEST_GRADLE_DOWNLOAD_URL=$latest_download_url" >> $GITHUB_ENV
32+
- name: Update gradle-wrapper.properties
33+
run: |
34+
sed -i "s|^distributionUrl=.*$|distributionUrl=${LATEST_GRADLE_DOWNLOAD_URL}|" gradle/wrapper/gradle-wrapper.properties
35+
./gradlew wrapper --gradle-version ${LATEST_GRADLE_VERSION}
36+
- name: Validate gradle wrapper
37+
uses: gradle/wrapper-validation-action@v2
38+
- name: Build Skript and run test scripts
39+
run: ./gradlew clean quickTest
40+
- name: Commit and push changes
41+
if: success()
42+
run: |
43+
git config --global user.name 'github-actions[bot]'
44+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
45+
git add gradle/wrapper/
46+
git commit -m "Update Gradle wrapper to ${LATEST_GRADLE_VERSION}"
47+
git push

src/main/java/ch/njol/skript/Skript.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ public void onEnable() {
396396
File config = new File(getDataFolder(), "config.sk");
397397
File features = new File(getDataFolder(), "features.sk");
398398
File lang = new File(getDataFolder(), "lang");
399-
if (!scriptsFolder.isDirectory() || !config.exists() || !features.exists() || !lang.exists()) {
399+
File aliasesFolder = new File(getDataFolder(), "aliases");
400+
if (!scriptsFolder.isDirectory() || !config.exists() || !features.exists() || !lang.exists() || !aliasesFolder.exists()) {
400401
ZipFile f = null;
401402
try {
402403
boolean populateExamples = false;
@@ -413,6 +414,11 @@ public void onEnable() {
413414
populateLanguageFiles = true;
414415
}
415416

417+
if (!aliasesFolder.isDirectory()) {
418+
if (!aliasesFolder.mkdirs())
419+
throw new IOException("Could not create the directory " + aliasesFolder);
420+
}
421+
416422
f = new ZipFile(getFile());
417423
for (ZipEntry e : new EnumerationIterable<ZipEntry>(f.entries())) {
418424
if (e.isDirectory())

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ch.njol.skript.aliases.ItemType;
55
import ch.njol.skript.bukkitutil.InventoryUtils;
66
import ch.njol.skript.command.CommandEvent;
7+
import ch.njol.skript.entity.EntityData;
78
import ch.njol.skript.events.bukkit.ScriptEvent;
89
import ch.njol.skript.events.bukkit.SkriptStartEvent;
910
import ch.njol.skript.events.bukkit.SkriptStopEvent;
@@ -170,6 +171,8 @@ public final class BukkitEventValues {
170171
"Use 'attacker' and/or 'victim' in damage/death events", EntityDamageEvent.class, EntityDeathEvent.class);
171172
EventValues.registerEventValue(EntityEvent.class, World.class, event -> event.getEntity().getWorld());
172173
EventValues.registerEventValue(EntityEvent.class, Location.class, event -> event.getEntity().getLocation());
174+
EventValues.registerEventValue(EntityEvent.class, EntityData.class, event -> EntityData.fromEntity(event.getEntity()),
175+
TIME_NOW, "Use 'type of attacker/victim' in damage/death events.", EntityDamageEvent.class, EntityDeathEvent.class);
173176
// EntityDamageEvent
174177
EventValues.registerEventValue(EntityDamageEvent.class, DamageCause.class, EntityDamageEvent::getCause);
175178
EventValues.registerEventValue(EntityDamageByEntityEvent.class, Projectile.class, event -> {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.bukkit.block.Block;
3434
import org.bukkit.block.data.BlockData;
3535
import org.bukkit.command.CommandSender;
36+
import org.bukkit.enchantments.Enchantment;
3637
import org.bukkit.enchantments.EnchantmentOffer;
3738
import org.bukkit.entity.*;
3839
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -588,6 +589,10 @@ public Relation compare(EnchantmentOffer eo, Experience exp) {
588589
}
589590
});
590591

592+
//EnchantmentType - Enchantment
593+
Comparators.registerComparator(EnchantmentType.class, Enchantment.class, ((enchantmentType, enchantment) ->
594+
Relation.get(enchantmentType.getType().equals(enchantment))));
595+
591596
Comparators.registerComparator(Inventory.class, InventoryType.class, new Comparator<Inventory, InventoryType>() {
592597
@Override
593598
public Relation compare(Inventory inventory, InventoryType inventoryType) {

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public class JavaClasses {
2929

3030
public static final int VARIABLENAME_NUMBERACCURACY = 8;
3131

32+
/**
33+
* The pattern for scientific notation.
34+
* <p>
35+
* The pattern is the letter {@code e} or {@code E} followed by a sign and one or more digits.
36+
* </p>
37+
*/
38+
public static final String SCIENTIFIC_PATTERN = "(?:[eE][+-]?\\d+)?";
39+
3240
/**
3341
* The format of an integer.
3442
* <p>
@@ -49,8 +57,8 @@ public class JavaClasses {
4957
* </p>
5058
*/
5159
public static final Pattern INTEGER_PATTERN =
52-
Pattern.compile("(?<num>" + INTEGER_NUMBER_PATTERN + ")" +
53-
"(?: (?:in )?(?:(?<rad>rad(?:ian)?s?)|deg(?:ree)?s?))?");
60+
Pattern.compile("(?<num>%s%s)(?: (?:in )?(?:(?<rad>rad(?:ian)?)|deg(?:ree)?)s?)?"
61+
.formatted(INTEGER_NUMBER_PATTERN, SCIENTIFIC_PATTERN));
5462

5563
/**
5664
* The format of a decimal number.
@@ -74,8 +82,8 @@ public class JavaClasses {
7482
* </p>
7583
*/
7684
public static final Pattern DECIMAL_PATTERN =
77-
Pattern.compile("(?<num>" + DECIMAL_NUMBER_PATTERN + ")" +
78-
"(?: (?:in )?(?:(?<rad>rad(?:ian)?s?)|deg(?:ree)?s?))?");
85+
Pattern.compile("(?<num>%s%s)(?: (?:in )?(?:(?<rad>rad(?:ian)?)|deg(?:ree)?)s?)?"
86+
.formatted(DECIMAL_NUMBER_PATTERN, SCIENTIFIC_PATTERN));
7987

8088
static {
8189
Classes.registerClass(new ClassInfo<>(Object.class, "object")
@@ -94,7 +102,7 @@ public class JavaClasses {
94102
"Please note that many expressions only need integers, i.e. " +
95103
"will discard any fractional parts of any numbers without producing an error.",
96104
"Radians will be converted to degrees.")
97-
.usage("[-]###[.###] [[in ](rad[ian][s]|deg[ree][s])]</code> (any amount of digits; very large numbers will be truncated though)")
105+
.usage("[-]###[.###] [e[+|-]###] [[in ](rad[ian][s]|deg[ree][s])]")
98106
.examples(
99107
"set the player's health to 5.5",
100108
"set {_temp} to 2*{_temp} - 2.5",

src/main/java/ch/njol/skript/conditions/base/PropertyCondition.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import ch.njol.skript.lang.SkriptParser.ParseResult;
88
import ch.njol.util.Kleenean;
99
import org.bukkit.event.Event;
10+
import org.jetbrains.annotations.ApiStatus;
1011
import org.jetbrains.annotations.NotNull;
1112
import org.jetbrains.annotations.Nullable;
12-
13-
import java.util.function.Predicate;
14-
import org.jetbrains.annotations.ApiStatus;
1513
import org.skriptlang.skript.registration.SyntaxInfo;
1614
import org.skriptlang.skript.registration.SyntaxRegistry;
1715
import org.skriptlang.skript.util.Priority;
@@ -206,6 +204,13 @@ protected PropertyType getPropertyType() {
206204
return PropertyType.BE;
207205
}
208206

207+
/**
208+
* Gets the expression this condition checks a property of.
209+
*/
210+
public final Expression<? extends T> getExpr() {
211+
return expr;
212+
}
213+
209214
/**
210215
* Sets the expression this condition checks a property of. No reference to the expression should be kept.
211216
*

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

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,59 @@
11
package ch.njol.skript.effects;
22

3+
import ch.njol.skript.doc.*;
4+
import ch.njol.skript.lang.EventRestrictedSyntax;
5+
import ch.njol.util.coll.CollectionUtils;
6+
import org.bukkit.entity.Item;
37
import org.bukkit.event.Event;
48
import org.bukkit.event.block.BlockBreakEvent;
9+
import org.bukkit.event.block.BlockDropItemEvent;
510
import org.bukkit.event.entity.EntityDeathEvent;
11+
import org.bukkit.event.player.PlayerHarvestBlockEvent;
612
import org.jetbrains.annotations.Nullable;
713

814
import ch.njol.skript.Skript;
9-
import ch.njol.skript.doc.Description;
10-
import ch.njol.skript.doc.Events;
11-
import ch.njol.skript.doc.Examples;
12-
import ch.njol.skript.doc.Name;
13-
import ch.njol.skript.doc.RequiredPlugins;
14-
import ch.njol.skript.doc.Since;
1515
import ch.njol.skript.lang.Effect;
1616
import ch.njol.skript.lang.Expression;
1717
import ch.njol.skript.lang.SkriptParser.ParseResult;
1818
import ch.njol.util.Kleenean;
1919

2020
@Name("Cancel Drops")
21-
@Description("Cancels drops of items or experiences in a death or block break event. " +
22-
"Please note that this doesn't keep items or experiences of a dead player. If you want to do that, " +
23-
"use the <a href='effects.html#EffKeepInventory'>Keep Inventory / Experience</a> effect.")
24-
@Examples({"on death of a zombie:",
25-
"\tif name of the entity is \"&cSpecial\":",
26-
"\t\tcancel drops of items",
27-
"",
28-
"on break of a coal ore:",
29-
"\tcancel the experience drops"})
30-
@Since("2.4")
21+
@Description({
22+
"Cancels drops of items in a death, block break, block drop, and block harvest events.",
23+
"The dropped experience can be cancelled in a death and block break events.",
24+
"Please note that using this in a death event doesn't keep items or experience of a dead player. If you want to do that, "
25+
+ "use the <a href='effects.html#EffKeepInventory'>Keep Inventory / Experience</a> effect."
26+
})
27+
@Example("""
28+
on death of a zombie:
29+
if name of the entity is "&cSpecial":
30+
cancel drops of items
31+
""")
32+
@Example("""
33+
on break of a coal ore:
34+
cancel the experience drops
35+
""")
36+
@Example("""
37+
on player block harvest:
38+
cancel the item drops
39+
""")
40+
@Since("2.4, INSERT VERSION (harvest event)")
3141
@RequiredPlugins("1.12.2 or newer (cancelling item drops of blocks)")
32-
@Events({"death", "break / mine"})
33-
public class EffCancelDrops extends Effect {
34-
35-
private static final boolean CAN_CANCEL_BLOCK_ITEM_DROPS = Skript.methodExists(BlockBreakEvent.class, "setDropItems", boolean.class);
42+
@Events({"death", "break / mine", "block drop", "harvest"})
43+
public class EffCancelDrops extends Effect implements EventRestrictedSyntax {
3644

3745
static {
3846
Skript.registerEffect(EffCancelDrops.class,
39-
"(cancel|clear|delete) [the] drops [of (items|2¦[e]xp[erience][s])]",
40-
"(cancel|clear|delete) [the] (item|[e]xp[erience]) drops");
47+
"(cancel|clear|delete) [the] drops [of (items:items|xp:[e]xp[erience][s])]",
48+
"(cancel|clear|delete) [the] (items:item|xp:[e]xp[erience]) drops");
4149
}
4250

4351
private boolean cancelItems, cancelExps;
4452

4553
@Override
4654
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
47-
cancelItems = parseResult.mark == 0 || parseResult.mark == 1;
48-
cancelExps = parseResult.mark == 0 || parseResult.mark == 2;
49-
if (getParser().isCurrentEvent(BlockBreakEvent.class)) {
50-
if (cancelItems && !CAN_CANCEL_BLOCK_ITEM_DROPS) {
51-
Skript.error("Cancelling drops of items in a block break event requires Minecraft 1.12 or newer");
52-
return false;
53-
}
54-
} else if (!getParser().isCurrentEvent(EntityDeathEvent.class)) {
55-
Skript.error("The cancel drops effect can't be used outside of a death" +
56-
(CAN_CANCEL_BLOCK_ITEM_DROPS ? " or block break" : "") + " event");
57-
return false;
58-
}
55+
cancelItems = !parseResult.hasTag("xp");
56+
cancelExps = !parseResult.hasTag("items");
5957
if (isDelayed.isTrue()) {
6058
Skript.error("Can't cancel the drops anymore after the event has already passed");
6159
return false;
@@ -64,24 +62,31 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
6462
}
6563

6664
@Override
67-
protected void execute(Event e) {
68-
if (e instanceof EntityDeathEvent) {
69-
EntityDeathEvent event = (EntityDeathEvent) e;
65+
public Class<? extends Event>[] supportedEvents() {
66+
return CollectionUtils.array(EntityDeathEvent.class, BlockBreakEvent.class, BlockDropItemEvent.class, PlayerHarvestBlockEvent.class);
67+
}
68+
69+
@Override
70+
protected void execute(Event event) {
71+
if (event instanceof EntityDeathEvent deathEvent) {
7072
if (cancelItems)
71-
event.getDrops().clear();
73+
deathEvent.getDrops().clear();
7274
if (cancelExps)
73-
event.setDroppedExp(0);
74-
} else if (e instanceof BlockBreakEvent) {
75-
BlockBreakEvent event = (BlockBreakEvent) e;
75+
deathEvent.setDroppedExp(0);
76+
} else if (event instanceof BlockBreakEvent breakEvent) {
7677
if (cancelItems)
77-
event.setDropItems(false);
78+
breakEvent.setDropItems(false);
7879
if (cancelExps)
79-
event.setExpToDrop(0);
80+
breakEvent.setExpToDrop(0);
81+
} else if (event instanceof BlockDropItemEvent dropItemEvent) {
82+
dropItemEvent.getItems().forEach(Item::remove);
83+
} else if (event instanceof PlayerHarvestBlockEvent harvestBlockEvent) {
84+
harvestBlockEvent.getItemsHarvested().clear();
8085
}
8186
}
8287

8388
@Override
84-
public String toString(@Nullable Event e, boolean debug) {
89+
public String toString(@Nullable Event event, boolean debug) {
8590
if (cancelItems && !cancelExps)
8691
return "cancel the drops of items";
8792
else if (cancelExps && !cancelItems)

0 commit comments

Comments
 (0)