Skip to content

Commit

Permalink
Remove Most Aliases (#7336)
Browse files Browse the repository at this point in the history
* Remove all old aliases and update skript-aliases to reference minimized branch.

* fix spigot bugs and load-bearing performance issues

this was so fuckin cursed

* slightly less jank fix

* rework alias parsing to allow __ block and __ item for appropriate materials

* Update src/test/skript/tests/regressions/6707-spawn-fish-types.sk

Co-authored-by: Patrick Miller <[email protected]>

* Update Aliases.java

* Clean up aliases file.
  • Loading branch information
sovdeeth authored Jan 1, 2025
1 parent 9c6cae0 commit 65f71a1
Show file tree
Hide file tree
Showing 40 changed files with 162 additions and 138 deletions.
2 changes: 1 addition & 1 deletion skript-aliases
18 changes: 9 additions & 9 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Unmodifiable;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;
import org.jetbrains.annotations.Unmodifiable;
import org.junit.After;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
import org.junit.runner.notification.Failure;
import org.skriptlang.skript.bukkit.SkriptMetrics;
import org.skriptlang.skript.bukkit.tags.TagModule;
import org.skriptlang.skript.bukkit.breeding.BreedingModule;
import org.skriptlang.skript.bukkit.displays.DisplayModule;
import org.skriptlang.skript.bukkit.furnace.FurnaceModule;
import org.skriptlang.skript.bukkit.fishing.FishingModule;
import org.skriptlang.skript.bukkit.furnace.FurnaceModule;
import org.skriptlang.skript.bukkit.input.InputModule;
import org.skriptlang.skript.bukkit.log.runtime.BukkitRuntimeErrorConsumer;
import org.skriptlang.skript.bukkit.loottables.LootTableModule;
import org.skriptlang.skript.bukkit.registration.BukkitRegistryKeys;
import org.skriptlang.skript.bukkit.registration.BukkitSyntaxInfos;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.converter.Converter;
Expand All @@ -87,9 +87,9 @@
import org.skriptlang.skript.lang.script.Script;
import org.skriptlang.skript.lang.structure.Structure;
import org.skriptlang.skript.lang.structure.StructureInfo;
import org.skriptlang.skript.registration.SyntaxInfo;
import org.skriptlang.skript.registration.SyntaxOrigin;
import org.skriptlang.skript.registration.SyntaxRegistry;
import org.skriptlang.skript.registration.SyntaxInfo;

import java.io.File;
import java.io.IOException;
Expand All @@ -116,7 +116,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -510,8 +509,6 @@ public void onEnable() {
RuntimeErrorManager.refresh();
getRuntimeErrorManager().addConsumer(new BukkitRuntimeErrorConsumer());

CompletableFuture<Boolean> aliases = Aliases.loadAsync();

// Now override the verbosity if test mode is enabled
if (TestMode.VERBOSITY != null)
SkriptLogger.setVerbosity(Verbosity.valueOf(TestMode.VERBOSITY));
Expand Down Expand Up @@ -564,6 +561,9 @@ public void onEnable() {
return;
}

// todo: remove completely 2.11 or 2.12
CompletableFuture<Boolean> aliases = Aliases.loadAsync();

Commands.registerListeners();

if (logNormal())
Expand Down Expand Up @@ -790,7 +790,7 @@ protected void afterErrors() {
Bukkit.getServer().shutdown();
}, shutdownDelay.get());
});
}, 5);
}, 20); // 20 ticks is necessary on 1.19.4 to allow the server time to properly load/start ticking, for some reason
}

Skript.metrics = new Metrics(Skript.getInstance(), 722); // 722 is our bStats plugin ID
Expand Down
70 changes: 36 additions & 34 deletions src/main/java/ch/njol/skript/aliases/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ public abstract class Aliases {
private static final boolean noHardExceptions = SkriptConfig.apiSoftExceptions.value();
static String itemSingular = "item";
static String itemPlural = "items";
@Nullable
static String itemGender = null;
static String blockSingular = "block";
static String blockPlural = "blocks";
@Nullable
static String blockGender = null;

static {
everything.setAll(true);
Expand Down Expand Up @@ -310,47 +306,53 @@ private static ItemType parseType(final String s, final ItemType t, final boolea
/**
* Gets an alias from the aliases defined in the config.
*
* @param s The alias to get, case does not matter
* @param rawInput The alias to get, case does not matter
* @return A copy of the ItemType represented by the given alias or null if no such alias exists.
*/
@Nullable
private static ItemType getAlias(final String s) {
ItemType i;
String lc = "" + s.toLowerCase(Locale.ENGLISH);
final Matcher m = p_any.matcher(lc);
if (m.matches()) {
lc = "" + m.group(m.groupCount());
}
if ((i = getAlias_i(lc)) != null)
return i.clone();
boolean b;
if ((b = lc.endsWith(" " + blockSingular)) || lc.endsWith(" " + blockPlural)) {
if ((i = getAlias_i("" + s.substring(0, s.length() - (b ? blockSingular.length() : blockPlural.length()) - 1))) != null) {
i = i.clone();
for (int j = 0; j < i.numTypes(); j++) {
final ItemData d = i.getTypes().get(j);
if (d.getType().isBlock()) {
i.remove(d);
private static ItemType getAlias(final String rawInput) {
String input = rawInput.toLowerCase(Locale.ENGLISH).trim();
ItemType itemType = getAlias_i(input);
if (itemType != null)
return itemType.clone();

// try to parse `ACTUALNAME block` as ACTUALNAME
if (input.endsWith(" " + blockSingular) || input.endsWith(" " + blockPlural)) {
String stripped = input.substring(0, input.lastIndexOf(" "));
itemType = getAlias_i(stripped);
if (itemType != null) {
itemType = itemType.clone();
// remove all non-block datas and types that already end with "block"
for (int j = 0; j < itemType.numTypes(); j++) {
ItemData d = itemType.getTypes().get(j);
if (!d.getType().isBlock() || d.getType().getKey().getKey().endsWith(blockSingular)) {
itemType.remove(d);
j--;
}
}
if (i.getTypes().isEmpty())
// if no block itemdatas were found, return null
if (itemType.getTypes().isEmpty())
return null;
return i;
return itemType;
}
} else if ((b = lc.endsWith(" " + itemSingular)) || lc.endsWith(" " + itemPlural)) {
if ((i = getAlias_i("" + s.substring(0, s.length() - (b ? itemSingular.length() : itemPlural.length()) - 1))) != null) {
i = i.clone();
for (int j = 0; j < i.numTypes(); j++) {
final ItemData d = i.getTypes().get(j);
if (!d.isAnything && d.getType().isBlock()) {
i.remove(d);
j--;
// do the same for items
} else if (input.endsWith(" " + itemSingular) || input.endsWith(" " + itemPlural)) {
String stripped = input.substring(0, input.lastIndexOf(" "));
itemType = getAlias_i(stripped);
if (itemType != null) {
itemType = itemType.clone();
// remove all non-item datas
for (int j = 0; j < itemType.numTypes(); j++) {
ItemData data = itemType.getTypes().get(j);
if (!data.isAnything && !data.getType().isItem()) {
itemType.remove(data);
--j;
}
}
if (i.getTypes().isEmpty())
// if no item itemdatas were found, return null
if (itemType.getTypes().isEmpty())
return null;
return i;
return itemType;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.bukkitutil.InventoryUtils;
import ch.njol.skript.command.CommandEvent;
import ch.njol.skript.command.ScriptCommandEvent;
import ch.njol.skript.events.bukkit.ScriptEvent;
import ch.njol.skript.events.bukkit.SkriptStartEvent;
import ch.njol.skript.events.bukkit.SkriptStopEvent;
Expand Down Expand Up @@ -445,7 +444,8 @@ else if (hand == EquipmentSlot.OFF_HAND)
return inventories.toArray(new Inventory[0]);
});
// PrepareAnvilEvent
EventValues.registerEventValue(PrepareAnvilEvent.class, ItemStack.class, PrepareResultEvent::getResult);
if (Skript.classExists("com.destroystokyo.paper.event.inventory.PrepareResultEvent"))
EventValues.registerEventValue(PrepareAnvilEvent.class, ItemStack.class, PrepareResultEvent::getResult);
EventValues.registerEventValue(PrepareAnvilEvent.class, Inventory.class, PrepareAnvilEvent::getInventory);
// AnvilDamagedEvent
if (Skript.classExists("com.destroystokyo.paper.event.block.AnvilDamagedEvent")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@Examples({
"on spread:",
"\tif the source block is a grass block:",
"\t\tset the source block to a dirt block"
"\t\tset the source block to dirt"
})
@Since("2.7")
public class ExprSourceBlock extends SimpleExpression<Block> {
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/ch/njol/skript/sections/EffSecShoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private enum CaseUsage {
},
PROJECTILE_NO_WORLD_NO_TRIGGER {
@Override
public @Nullable Entity shootHandler(EntityData<?> entityData, LivingEntity shooter, Location location, Class<? extends Entity> type, Vector vector, Consumer<?> consumer) {
public @NotNull Entity shootHandler(EntityData<?> entityData, LivingEntity shooter, Location location, Class<? extends Entity> type, Vector vector, Consumer<?> consumer) {
//noinspection unchecked
Projectile projectile = shooter.launchProjectile((Class<? extends Projectile>) type);
set(projectile, entityData);
Expand All @@ -84,7 +84,7 @@ private enum CaseUsage {
},
PROJECTILE_WORLD_NO_TRIGGER {
@Override
public @Nullable Entity shootHandler(EntityData<?> entityData, LivingEntity shooter, Location location, Class<? extends Entity> type, Vector vector, Consumer<?> consumer) {
public @NotNull Entity shootHandler(EntityData<?> entityData, LivingEntity shooter, Location location, Class<? extends Entity> type, Vector vector, Consumer<?> consumer) {
Projectile projectile = (Projectile) shooter.getWorld().spawn(location, type);
projectile.setShooter(shooter);
return projectile;
Expand Down Expand Up @@ -152,9 +152,7 @@ public Entity getProjectile() {
if (!Skript.isRunningMinecraft(1, 20, 3)) {
try {
launchWithBukkitConsumer = LivingEntity.class.getMethod("launchProjectile", Class.class, Vector.class, org.bukkit.util.Consumer.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
} catch (NoSuchMethodException ignored) {}
}
boolean launchHasJavaConsumer = Skript.methodExists(LivingEntity.class, "launchProjectile", Class.class, Vector.class, Consumer.class);
RUNNING_PAPER = launchWithBukkitConsumer != null || launchHasJavaConsumer;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/structures/StructAliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Examples({
"aliases:",
"\tblacklisted items = TNT, bedrock, obsidian, mob spawner, lava, lava bucket",
"\tshiny swords = gold sword, iron sword, diamond sword"
"\tshiny swords = golden sword, iron sword, diamond sword"
})
@Since("1.0")
public class StructAliases extends Structure {
Expand Down
5 changes: 3 additions & 2 deletions src/test/skript/tests/misc/boats.sk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

test "boats":
set {_boats::*} to "oak boat", "birch boat", "spruce boat", "jungle boat", "acacia boat", "dark oak boat", and "mangrove boat"
parse if running minecraft "1.20.4":
Expand All @@ -14,7 +15,7 @@ test "boats":

assert {_boat} is set with "Failed to spawn %loop-value%"
set {_a boat} to "a boat" parsed as entity type
set {_a boat item} to "a boat" parsed as item type
set {_a boat item} to "%loop-value%" parsed as item type
assert {_boat} is {_a boat} with "%loop-value% was not a boat"
assert {_boat} is {_a boat item} with "%loop-value% did not match a boat item"

Expand All @@ -40,7 +41,7 @@ test "chest boats":

assert {_boat} is set with "Failed to spawn %loop-value%"
set {_a chest boat} to "a chest boat" parsed as entity type
set {_a chest boat item} to "a chest boat" parsed as item type
set {_a chest boat item} to "%loop-value%" parsed as item type
assert {_boat} is {_a chest boat} with "%loop-value% was not a chest boat"
assert {_boat} is {_a chest boat item} with "%loop-value% did not match a chest boat item"

Expand Down
2 changes: 1 addition & 1 deletion src/test/skript/tests/misc/item data serialization.sk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test "item data serialization":

# No assertion needed, it will be done internally
set {a::1} to a dirt block named "DIRT" with lore "LORE1" and "LORE2"
set {a::1} to a dirt named "DIRT" with lore "LORE1" and "LORE2"

delete {a::1}
7 changes: 6 additions & 1 deletion src/test/skript/tests/regressions/2711-item-compares.sk
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
aliases:
closed birch door = minecraft:birch_door[open=false]
any door = birch door, closed birch door
any wood door = birch door, closed birch door

test "item comparison":
set {_test} to a dragon head
assert {_test} is a dragon head with "failed to compare against a head"
set {_test} to a door
set {_test} to any door
assert {_test} is any door, any wood door, birch door or a closed birch door with "failed to compare against a door"
56 changes: 28 additions & 28 deletions src/test/skript/tests/regressions/3419-item comparisons.sk
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ test "item comparisons":

# Basic Material Comparisons

set {_a} to a dirt block
set {_a} to dirt
set {_b} to a diamond block

assert {_a} is a dirt block with "{_a} is not a dirt block (it should be)"
assert {_a} is dirt with "{_a} is not dirt (it should be)"
assert {_a} is not a diamond block with "{_a} is a diamond block (it shouldn't be)"

assert {_b} is not a dirt block with "{_b} is a dirt block (it shouldn't be)"
assert {_b} is not dirt with "{_b} is dirt (it shouldn't be)"
assert {_b} is a diamond block with "{_b} is not a diamond block (it should be)"

assert {_a} is not {_b} with "{_a} is {_b} (it shouldn't be) (Basic Material Comparisons)"
Expand All @@ -32,18 +32,18 @@ test "item comparisons":

# Different Enchantment Comparisons

set {_a} to a dirt block of sharpness 1
set {_b} to a dirt block of sharpness 2
set {_a} to dirt of sharpness 1
set {_b} to dirt of sharpness 2

assert {_a} is a dirt block with "{_a} is not a dirt block (it should be)"
assert {_a} is a dirt block of sharpness 1 with "{_a} is not a dirt block of sharpness 1 (it should be)"
assert {_a} is not a dirt block of sharpness 2 with "{_a} is a dirt block of sharpness 2 (it shouldn't be)"
assert a dirt block of sharpness 1 is {_a} with "a dirt block of sharpness 1 is not {_a} (it should be)"
assert {_a} is dirt with "{_a} is not dirt (it should be)"
assert {_a} is dirt of sharpness 1 with "{_a} is not dirt of sharpness 1 (it should be)"
assert {_a} is not dirt of sharpness 2 with "{_a} is dirt of sharpness 2 (it shouldn't be)"
assert dirt of sharpness 1 is {_a} with "dirt of sharpness 1 is not {_a} (it should be)"

assert {_b} is a dirt block with "{_b} is not a dirt block (it should be)"
assert {_b} is not a dirt block of sharpness 1 with "{_b} is a dirt block of sharpness 1 (it shouldn't be)"
assert {_b} is a dirt block of sharpness 2 with "{_b} is not a dirt block of sharpness 2 (it should be)"
assert a dirt block of sharpness 1 is not {_b} with "a dirt block of sharpness 1 is {_b} (it shouldn't be)"
assert {_b} is dirt with "{_b} is not dirt (it should be)"
assert {_b} is not dirt of sharpness 1 with "{_b} is dirt of sharpness 1 (it shouldn't be)"
assert {_b} is dirt of sharpness 2 with "{_b} is not dirt of sharpness 2 (it should be)"
assert dirt of sharpness 1 is not {_b} with "dirt of sharpness 1 is {_b} (it shouldn't be)"

assert {_a} is not {_b} with "{_a} is {_b} (it shouldn't be) (Different Enchantment Comparisons"
assert {_b} is not {_a} with "{_b} is {_a} (it shouldn't be) (Different Enchantment Comparisons)"
Expand All @@ -65,42 +65,42 @@ test "item comparisons":
# Skull Comparisons

set {_a} to a skeleton skull named "Skulliest Skull"
set {_b} to an ender dragon skull named "Skully Skull"
set {_b} to a dragon head named "Skully Skull"

assert {_a} is a skeleton skull with "{_a} is not a skeleton skull (it should be)"
assert {_a} is not a plain skeleton skull with "{_a} is an unnamed skeleton skull (it shouldn't be)"
assert {_a} is a skeleton skull named "Skulliest Skull" with "{_a} is not a skeleton skull named ""Skulliest Skull"" (it should be)"

assert {_a} is not an ender dragon skull with "{_a} is an ender dragon skull (it should't be)"
assert {_a} is not an ender dragon skull named "Skulliest Skull" with "{_a} is an ender dragon skull named ""Skulliest Skull"" (it shouldn't be)"
assert {_a} is not a dragon head with "{_a} is a dragon head (it should't be)"
assert {_a} is not a dragon head named "Skulliest Skull" with "{_a} is a dragon head named ""Skulliest Skull"" (it shouldn't be)"

assert {_b} is an ender dragon skull with "{_b} is not an ender dragon skull (it should be)"
assert {_b} is not a plain ender dragon skull with "{_b} is an unnamed ender dragon skull (it shouldn't be)"
assert {_b} is an ender dragon skull named "Skully Skull" with "{_b} is not an ender dragon skull named ""Skully Skull"" (it should be)"
assert {_b} is a dragon head with "{_b} is not a dragon head (it should be)"
assert {_b} is not a plain dragon head with "{_b} is an unnamed dragon head (it shouldn't be)"
assert {_b} is a dragon head named "Skully Skull" with "{_b} is not a dragon head named ""Skully Skull"" (it should be)"

assert {_b} is not a skeleton skull with "{_b} is a skeleton skull (it shouldn't be)"
assert {_b} is not a skeleton skull named "Skully Skull" with "{_b} is a skeleton skull named ""Skully Skull"" (it shouldn't be)"

assert {_a} is not {_b} with "{_a} is {_b} (it shouldn't be) (Skull Comparisons)"
assert {_b} is not {_a} with "{_b} is {_a} (it shouldn't be) (Skull Comparisons)"

# Player Skull Comparisons
# Player Head Comparisons

set {_p1} to "APickledWalrus" parsed as an offlineplayer
set {_p2} to "ShaneBee" parsed as an offlineplayer
set {_a} to skull of {_p1}
set {_b} to skull of {_p2}

assert {_a} is a player skull with "{_a} is not a player skull (it should be)"
assert {_a} is a player head with "{_a} is not a player head (it should be)"
assert {_a} is the skull of {_p1} with "{_a} is not the skull of {_p1} (it should be)"
assert {_a} is not the skull of {_p2} with "{_a} is the skull of {_p2} (it shouldn't be)"

assert {_b} is a player skull with "{_b} is not a player skull (it should be)"
assert {_b} is a player head with "{_b} is not a player head (it should be)"
assert {_b} is the skull of {_p2} with "{_b} is not the skull of {_p2} (it should be)"
assert {_b} is not the skull of {_p1} with "{_b} is the skull of {_p1} (it shouldn't be)"

assert {_a} is not {_b} with "{_a} is {_b} (it shouldn't be) (Player Skull Comparisons)"
assert {_b} is not {_a} with "{_b} is {_a} (it shouldn't be) (Player Skull Comparisons)"
assert {_a} is not {_b} with "{_a} is {_b} (it shouldn't be) (Player Head Comparisons)"
assert {_b} is not {_a} with "{_b} is {_a} (it shouldn't be) (Player Head Comparisons)"

# Remove / Remove All Tests

Expand Down Expand Up @@ -133,11 +133,11 @@ test "item comparisons":
assert {_one} is {_two} with "a diamond sword of sharpness 1 named ""TEST"" should be a diamond sword of sharpness 1"
assert {_two} is not {_one} with "a diamond sword of sharpness 1 should NOT be a diamond sword of sharpness 1 named ""TEST"""

set {_three} to a sand block of unbreaking 3 with lore "Sandy Block"
set {_four} to a sand block of unbreaking 3
set {_three} to sand of unbreaking 3 with lore "Sandy Block"
set {_four} to sand of unbreaking 3

assert {_three} is {_four} with "a sand block of unbreaking 3 with lore ""Sandy Block"" should be a sand block of unbreaking 3"
assert {_four} is not {_three} with "a sand block of unbreaking 3 should NOT be a sand block of unbreaking 3 with lore ""Sandy Block"""
assert {_three} is {_four} with "sand of unbreaking 3 with lore ""Sandy Block"" should be sand of unbreaking 3"
assert {_four} is not {_three} with "sand of unbreaking 3 should NOT be sand of unbreaking 3 with lore ""Sandy Block"""

# Same material but different data values (1.12 and below) (see https://github.com/SkriptLang/Skript/issues/4643)

Expand Down
Loading

0 comments on commit 65f71a1

Please sign in to comment.