Skip to content

Commit 116c766

Browse files
authored
Remove 1.16-1.18 Reflection Checks (#7832)
* cleanup 1.17 & 1.18 * 1.16 * rollback clamp
1 parent e15eb9d commit 116c766

31 files changed

+217
-341
lines changed

src/main/java/ch/njol/skript/aliases/AliasesProvider.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package ch.njol.skript.aliases;
22

3-
import ch.njol.skript.Skript;
43
import ch.njol.skript.bukkitutil.BukkitUnsafe;
54
import ch.njol.skript.bukkitutil.ItemUtils;
65
import ch.njol.skript.bukkitutil.block.BlockCompat;
@@ -11,7 +10,6 @@
1110
import java.util.ArrayList;
1211
import java.util.Collections;
1312
import java.util.HashMap;
14-
import java.util.HashSet;
1513
import java.util.List;
1614
import java.util.Map;
1715
import java.util.Set;
@@ -24,9 +22,6 @@
2422
*/
2523
public class AliasesProvider {
2624

27-
// not supported on Spigot versions older than 1.18
28-
private static final boolean FASTER_SET_SUPPORTED = Skript.classExists("it.unimi.dsi.fastutil.objects.ObjectOpenHashSet");
29-
3025
/**
3126
* When an alias is not found, it will requested from this provider.
3227
* Null when this is global aliases provider.
@@ -66,13 +61,7 @@ public AliasesProvider(int expectedCount, @Nullable AliasesProvider parent) {
6661
this.aliases = new HashMap<>(expectedCount);
6762
this.variations = new HashMap<>(expectedCount / 20);
6863
this.aliasesMap = new AliasesMap();
69-
70-
if (FASTER_SET_SUPPORTED) {
71-
this.materials = new ObjectOpenHashSet<>();
72-
} else {
73-
this.materials = new HashSet<>();
74-
}
75-
64+
this.materials = new ObjectOpenHashSet<>();
7665
this.gson = new Gson();
7766
}
7867

src/main/java/ch/njol/skript/bukkitutil/WorldUtils.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969

7070
public class BukkitClasses {
7171

72+
// TODO - remove unnecessary classExists checks when Spigot support is dropped
73+
7274
public BukkitClasses() {}
7375

7476
static {
@@ -1262,39 +1264,36 @@ public String toVariableNameString(FireworkEffect effect) {
12621264
"See the <a href='#EffPlaySound'>play sound</a> and <a href='#EffStopSound'>stop sound</a> effects.")
12631265
.since("2.4"));
12641266

1265-
if (Skript.classExists("org.bukkit.entity.Panda$Gene")) {
1266-
Classes.registerClass(new EnumClassInfo<>(Gene.class, "gene", "genes")
1267-
.user("(panda )?genes?")
1268-
.name("Gene")
1269-
.description("Represents a Panda's main or hidden gene. " +
1270-
"See <a href='https://minecraft.wiki/w/Panda#Genetics'>genetics</a> for more info.")
1271-
.since("2.4")
1272-
.requiredPlugins("Minecraft 1.14 or newer"));
1273-
}
1267+
Classes.registerClass(new EnumClassInfo<>(Gene.class, "gene", "genes")
1268+
.user("(panda )?genes?")
1269+
.name("Gene")
1270+
.description("Represents a Panda's main or hidden gene. " +
1271+
"See <a href='https://minecraft.wiki/w/Panda#Genetics'>genetics</a> for more info.")
1272+
.since("2.4")
1273+
.requiredPlugins("Minecraft 1.14 or newer"));
12741274

12751275
Classes.registerClass(new EnumClassInfo<>(RegainReason.class, "healreason", "heal reasons")
12761276
.user("(regen|heal) (reason|cause)")
12771277
.name("Heal Reason")
12781278
.description("The health regain reason in a <a href='#heal'>heal</a> event.")
12791279
.since("2.5"));
12801280

1281-
if (Skript.classExists("org.bukkit.entity.Cat$Type")) {
1282-
ClassInfo<Cat.Type> catTypeClassInfo;
1283-
if (BukkitUtils.registryExists("CAT_VARIANT")) {
1284-
catTypeClassInfo = new RegistryClassInfo<>(Cat.Type.class, Registry.CAT_VARIANT, "cattype", "cat types");
1285-
} else {
1286-
//noinspection unchecked, rawtypes - it is an enum on other versions
1287-
catTypeClassInfo = new EnumClassInfo<>((Class) Cat.Type.class, "cattype", "cat types");
1288-
}
1289-
Classes.registerClass(catTypeClassInfo
1290-
.user("cat ?(type|race)s?")
1291-
.name("Cat Type")
1292-
.description("Represents the race/type of a cat entity.",
1293-
"NOTE: Minecraft namespaces are supported, ex: 'minecraft:british_shorthair'.")
1294-
.since("2.4")
1295-
.requiredPlugins("Minecraft 1.14 or newer")
1296-
.documentationId("CatType"));
1281+
ClassInfo<Cat.Type> catTypeClassInfo;
1282+
if (BukkitUtils.registryExists("CAT_VARIANT")) {
1283+
catTypeClassInfo = new RegistryClassInfo<>(Cat.Type.class, Registry.CAT_VARIANT, "cattype", "cat types");
1284+
} else {
1285+
//noinspection unchecked, rawtypes - it is an enum on other versions
1286+
catTypeClassInfo = new EnumClassInfo<>((Class) Cat.Type.class, "cattype", "cat types");
12971287
}
1288+
Classes.registerClass(catTypeClassInfo
1289+
.user("cat ?(type|race)s?")
1290+
.name("Cat Type")
1291+
.description("Represents the race/type of a cat entity.",
1292+
"NOTE: Minecraft namespaces are supported, ex: 'minecraft:british_shorthair'.")
1293+
.since("2.4")
1294+
.requiredPlugins("Minecraft 1.14 or newer")
1295+
.documentationId("CatType"));
1296+
12981297

12991298
Classes.registerClass(new ClassInfo<>(GameRule.class, "gamerule")
13001299
.user("gamerules?")

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,15 @@ public Player[] executeSimple(Object[][] params) {
541541
}
542542
return CollectionUtils.array(uuid != null ? Bukkit.getPlayer(uuid) : (isExact ? Bukkit.getPlayerExact(name) : Bukkit.getPlayer(name)));
543543
}
544-
}).description("Returns an online player from their name or UUID, if player is offline function will return nothing.", "Setting 'getExactPlayer' parameter to true will return the player whose name is exactly equal to the provided name instead of returning a player that their name starts with the provided name.")
545-
.examples("set {_p} to player(\"Notch\") # will return an online player whose name is or starts with 'Notch'", "set {_p} to player(\"Notch\", true) # will return the only online player whose name is 'Notch'", "set {_p} to player(\"069a79f4-44e9-4726-a5be-fca90e38aaf5\") # <none> if player is offline")
544+
}).description("Returns an online player from their name or UUID, if player is offline function will return nothing.",
545+
"Setting 'getExactPlayer' parameter to true will return the player whose name is exactly equal to the provided name instead of returning a player that their name starts with the provided name.")
546+
.examples("set {_p} to player(\"Notch\") # will return an online player whose name is or starts with 'Notch'",
547+
"set {_p} to player(\"Notch\", true) # will return the only online player whose name is 'Notch'",
548+
"set {_p} to player(\"069a79f4-44e9-4726-a5be-fca90e38aaf5\") # <none> if player is offline")
546549
.since("2.8.0");
547550

548551
{ // offline player function
552+
// TODO - remove this when Spigot support is dropped
549553
boolean hasIfCached = Skript.methodExists(Bukkit.class, "getOfflinePlayerIfCached", String.class);
550554

551555
List<Parameter<?>> params = new ArrayList<>();

src/main/java/ch/njol/skript/conditions/CondAnchorWorks.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
public class CondAnchorWorks extends Condition {
2323

2424
static {
25-
if (Skript.classExists("org.bukkit.block.data.type.RespawnAnchor"))
26-
Skript.registerCondition(CondAnchorWorks.class, "respawn anchors [do[1:(n't| not)]] work in %worlds%");
25+
Skript.registerCondition(CondAnchorWorks.class, "respawn anchors [do[1:(n't| not)]] work in %worlds%");
2726
}
2827

2928
@SuppressWarnings("NotNullFieldNotInitialized")

src/main/java/ch/njol/skript/conditions/CondEntityIsInLiquid.java

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ public class CondEntityIsInLiquid extends PropertyCondition<Entity> {
2222

2323
static {
2424
StringBuilder patterns = new StringBuilder();
25-
if (Skript.methodExists(Entity.class, "isInWater")) {
26-
patterns.append("1¦water");
27-
if (Skript.methodExists(Entity.class, "isInLava")) // Paper - All added at the same time + isInWater
28-
patterns.append("|2¦lava|3¦[a] bubble[ ]column|4¦rain");
29-
register(CondEntityIsInLiquid.class, "in (" + patterns + ")", "entities");
30-
}
25+
patterns.append("1¦water");
26+
if (Skript.methodExists(Entity.class, "isInLava")) // TODO - remove this when Spigot support is dropped
27+
patterns.append("|2¦lava|3¦[a] bubble[ ]column|4¦rain");
28+
register(CondEntityIsInLiquid.class, "in (" + patterns + ")", "entities");
3129
}
3230

3331
private static final int IN_WATER = 1, IN_LAVA = 2, IN_BUBBLE_COLUMN = 3, IN_RAIN = 4;
@@ -45,34 +43,24 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
4543

4644
@Override
4745
public boolean check(Entity entity) {
48-
switch (mark) {
49-
case IN_WATER:
50-
return entity.isInWater();
51-
case IN_LAVA:
52-
return entity.isInLava();
53-
case IN_BUBBLE_COLUMN:
54-
return entity.isInBubbleColumn();
55-
case IN_RAIN:
56-
return entity.isInRain();
57-
default:
58-
throw new IllegalStateException();
59-
}
46+
return switch (mark) {
47+
case IN_WATER -> entity.isInWater();
48+
case IN_LAVA -> entity.isInLava();
49+
case IN_BUBBLE_COLUMN -> entity.isInBubbleColumn();
50+
case IN_RAIN -> entity.isInRain();
51+
default -> throw new IllegalStateException();
52+
};
6053
}
6154

6255
@Override
6356
protected String getPropertyName() {
64-
switch (mark) {
65-
case IN_WATER:
66-
return "in water";
67-
case IN_LAVA:
68-
return "in lava";
69-
case IN_BUBBLE_COLUMN:
70-
return "in bubble column";
71-
case IN_RAIN:
72-
return "in rain";
73-
default:
74-
throw new IllegalStateException();
75-
}
57+
return switch (mark) {
58+
case IN_WATER -> "in water";
59+
case IN_LAVA -> "in lava";
60+
case IN_BUBBLE_COLUMN -> "in bubble column";
61+
case IN_RAIN -> "in rain";
62+
default -> throw new IllegalStateException();
63+
};
7664
}
7765

7866
}

src/main/java/ch/njol/skript/conditions/CondEntityIsWet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
public class CondEntityIsWet extends PropertyCondition<Entity> {
1414

1515
static {
16+
// TODO - remove this when Spigot support is dropped
1617
if (Skript.methodExists(Entity.class, "isInWaterOrRainOrBubbleColumn"))
1718
register(CondEntityIsWet.class, "wet", "entities");
1819
}

src/main/java/ch/njol/skript/conditions/CondIsClimbing.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package ch.njol.skript.conditions;
22

3+
import ch.njol.skript.doc.*;
34
import org.bukkit.entity.LivingEntity;
45

5-
import ch.njol.skript.Skript;
66
import ch.njol.skript.conditions.base.PropertyCondition;
7-
import ch.njol.skript.doc.Description;
8-
import ch.njol.skript.doc.Examples;
9-
import ch.njol.skript.doc.Name;
10-
import ch.njol.skript.doc.RequiredPlugins;
11-
import ch.njol.skript.doc.Since;
127

138
@Name("Is Climbing")
149
@Description("Whether a living entity is climbing, such as a spider up a wall or a player on a ladder.")
@@ -23,8 +18,7 @@
2318
public class CondIsClimbing extends PropertyCondition<LivingEntity> {
2419

2520
static {
26-
if (Skript.methodExists(LivingEntity.class, "isClimbing"))
27-
register(CondIsClimbing.class, "climbing", "livingentities");
21+
register(CondIsClimbing.class, "climbing", "livingentities");
2822
}
2923

3024
@Override

src/main/java/ch/njol/skript/conditions/CondIsLeftHanded.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
@RequiredPlugins("Paper 1.17.1+ (entities)")
3030
public class CondIsLeftHanded extends PropertyCondition<LivingEntity> {
3131

32+
// TODO - remove this when Spigot support is dropped
3233
private static final boolean CAN_USE_ENTITIES = Skript.methodExists(Mob.class, "isLeftHanded");
3334

3435
static {

src/main/java/ch/njol/skript/conditions/CondIsPreferredTool.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
public class CondIsPreferredTool extends Condition {
3636

3737
static {
38+
// TODO - remove this when Spigot support is dropped
3839
String types = "blocks";
3940
if (Skript.methodExists(BlockData.class, "isPreferredTool", ItemStack.class))
4041
types += "/blockdatas";

0 commit comments

Comments
 (0)