Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.5 Support #6617

Merged
merged 23 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
87d0be6
Internal support for aliases item components
APickledWalrus Apr 26, 2024
69a779d
Update aliases submodule
APickledWalrus Apr 27, 2024
9625ea8
Update isRunningMethod check
APickledWalrus Apr 27, 2024
68fbfbc
Add ability to opt out of deduplication
APickledWalrus Apr 27, 2024
c073ccc
Update skript-aliases
APickledWalrus Apr 27, 2024
20d18ad
Merge branch 'dev/patch' into patch/1.20.5-support
Moderocky Apr 27, 2024
0a10072
Update skript-aliases
APickledWalrus Apr 30, 2024
45ef181
Update skript-aliases
APickledWalrus Apr 30, 2024
0437153
Update Gradle to 8.7
APickledWalrus Apr 30, 2024
bdd19cd
Update Paper to 1.20.6
APickledWalrus Apr 30, 2024
dff1ab7
Merge branch 'dev/patch' into patch/1.20.5-support
APickledWalrus Apr 30, 2024
a69e518
Fix latest env for testing
APickledWalrus Apr 30, 2024
46f9db2
Fix AreaEffectCloudApplyEvent event value
APickledWalrus Apr 30, 2024
822cf42
Fix vehicle dismount events
APickledWalrus Apr 30, 2024
822c8c4
Fix potions
APickledWalrus Apr 30, 2024
314d72c
Get visual effects building
APickledWalrus Apr 30, 2024
2d96d8e
Fix unused AbstractList implementation
APickledWalrus Apr 30, 2024
dcf806d
Fix remaining Java 17 references
APickledWalrus Apr 30, 2024
337fcba
Fix 1.17 testing
APickledWalrus Apr 30, 2024
442e5f2
Add missing PotionDataUtils check
APickledWalrus Apr 30, 2024
0ebd6d2
Add missing lang entries
APickledWalrus Apr 30, 2024
2f6f093
Rework Test Environments
APickledWalrus Apr 30, 2024
16a8ecc
Update workflow names
APickledWalrus May 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "skript-aliases"]
path = skript-aliases
url = https://github.com/SkriptLang/skript-aliases
branch = patch/1.20.5-support
2 changes: 1 addition & 1 deletion skript-aliases
Submodule skript-aliases updated 4 files
+128 −0 +global-variations.sk
+4 −71 brewing.sk
+184 −49 combat.sk
+67 −26 misc.sk
4 changes: 3 additions & 1 deletion src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,9 @@ public void onPluginDisable(PluginDisableEvent event) {
// 1.19 mapping is u and 1.18 is v
String isRunningMethod = "isRunning";

if (Skript.isRunningMinecraft(1, 20)) {
if (Skript.isRunningMinecraft(1, 20, 5)) {
isRunningMethod = "x";
} else if (Skript.isRunningMinecraft(1, 20)) {
isRunningMethod = "v";
} else if (Skript.isRunningMinecraft(1, 19)) {
isRunningMethod = "u";
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/aliases/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

public abstract class Aliases {

static final boolean USING_ITEM_COMPONENTS = Skript.isRunningMinecraft(1, 20, 5);

private static final AliasesProvider provider = createProvider(10000, null);
private static final AliasesParser parser = createParser(provider);

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/ch/njol/skript/aliases/AliasesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,20 @@ protected Variation parseVariation(String item) {
throw new AssertionError("missing space between id and tags in " + item);
}
id = item.substring(0, firstBracket - 1);
String json = item.substring(firstBracket);
assert json != null;
tags = provider.parseMojangson(json);
String json;
int jsonEndIndex = item.indexOf("} ["); // may also have block states/data
if (jsonEndIndex == -1) {
json = item.substring(firstBracket);
} else {
json = item.substring(firstBracket, jsonEndIndex + 1);
id = id + item.substring(jsonEndIndex + 2); // essentially rips out json part
}
if (Aliases.USING_ITEM_COMPONENTS) {
json = "[" + json.substring(1, json.length() - 1) + "]"; // replace brackets (not json :))
tags = Collections.singletonMap("components", json);
} else {
tags = provider.parseMojangson(json);
}
}

// Separate block state from id
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/ch/njol/skript/aliases/AliasesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,18 @@ public int applyTags(ItemStack stack, Map<String, Object> tags) {
return flags;

// Apply random tags using JSON
String json = gson.toJson(tags);
assert json != null;
BukkitUnsafe.modifyItemStack(stack, json);
if (Aliases.USING_ITEM_COMPONENTS) {
String components = (String) tags.get("components"); // only components are supported for modifying a stack
assert components != null;
// for modifyItemStack to work, you have to include an item id ... e.g. "minecraft:dirt[<components>]"
// just to be safe we use the same one as the provided stack
components = stack.getType().getKey() + components;
BukkitUnsafe.modifyItemStack(stack, components);
} else {
String json = gson.toJson(tags);
assert json != null;
BukkitUnsafe.modifyItemStack(stack, json);
}
flags |= ItemFlags.CHANGED_TAGS;

return flags;
Expand Down Expand Up @@ -269,6 +278,14 @@ public void addAlias(AliasName name, String id, @Nullable Map<String, Object> ta
ItemType typeOfId = getAlias(id);
EntityData<?> related = null;
List<ItemData> datas;

// check whether deduplication will occur
boolean deduplicate = true;
String deduplicateFlag = blockStates.remove("deduplicate");
if (deduplicateFlag != null) {
deduplicate = !deduplicateFlag.equals("false");
}

if (typeOfId != null) { // If it exists, use datas from it
datas = typeOfId.getTypes();
} else { // ... but quite often, we just got Vanilla id
Expand Down Expand Up @@ -301,11 +318,13 @@ public void addAlias(AliasName name, String id, @Nullable Map<String, Object> ta
data.itemFlags = itemFlags;

// Deduplicate item data if this has been loaded before
AliasesMap.Match canonical = aliasesMap.exactMatch(data);
if (canonical.getQuality().isAtLeast(MatchQuality.EXACT)) {
AliasesMap.AliasData aliasData = canonical.getData();
assert aliasData != null; // Match quality guarantees this
data = aliasData.getItem();
if (deduplicate) {
AliasesMap.Match canonical = aliasesMap.exactMatch(data);
if (canonical.getQuality().isAtLeast(MatchQuality.EXACT)) {
AliasesMap.AliasData aliasData = canonical.getData();
assert aliasData != null; // Match quality guarantees this
data = aliasData.getItem();
}
}

datas = Collections.singletonList(data);
Expand Down
Loading