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

Mod Material support, for Hybrid Server #7126

Merged
merged 20 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
8 changes: 6 additions & 2 deletions src/main/java/ch/njol/skript/aliases/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import ch.njol.skript.config.Node;
import ch.njol.skript.config.SectionNode;
import ch.njol.skript.entity.EntityData;
import org.bukkit.entity.EntityType;
import org.skriptlang.skript.lang.script.Script;
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.skript.localization.ArgsMessage;
Expand Down Expand Up @@ -403,7 +402,12 @@ private static void loadMissingAliases() {
for (Material material : Material.values()) {
if (!material.isLegacy() && !provider.hasAliasForMaterial(material)) {
NamespacedKey key = material.getKey();
String name = key.getKey().replace("_", " ");
String name = (key.getNamespace().equals(NamespacedKey.MINECRAFT)
? key.getKey()
: key.getNamespace() + "'s " + key.getKey()
).replace("_", " ");
// mod:an_item → mod:an item
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
// minecraft:dirt → dirt
parser.loadAlias(name + "¦s", key.toString());
Skript.debug(ChatColor.YELLOW + "Creating temporary alias for: " + key);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/aliases/AliasesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public void addAlias(AliasName name, String id, @Nullable Map<String, Object> ta
datas = typeOfId.getTypes();
} else { // ... but quite often, we just got Vanilla id
// Prepare and modify ItemStack (using somewhat Unsafe methods)
Material material = BukkitUnsafe.getMaterialFromMinecraftId(id);
Material material = BukkitUnsafe.getMaterialFromNamespacedId(id);
if (material == null) { // If server doesn't recognize id, do not proceed
throw new InvalidMinecraftIdException(id);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/ch/njol/skript/bukkitutil/BukkitUnsafe.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.UnsafeValues;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
Expand All @@ -39,7 +37,6 @@
import com.google.gson.reflect.TypeToken;
import ch.njol.util.EnumTypeAdapter;
import ch.njol.skript.Skript;
import ch.njol.skript.util.Version;

/**
* Contains helpers for Bukkit's not so safe stuff.
Expand Down Expand Up @@ -69,8 +66,11 @@ public class BukkitUnsafe {
private static Map<Integer,Material> idMappings;

@Nullable
public static Material getMaterialFromMinecraftId(String id) {
return Material.matchMaterial(id);
public static Material getMaterialFromNamespacedId(String id) {
0XPYEX0 marked this conversation as resolved.
Show resolved Hide resolved
return Material.matchMaterial(id.toLowerCase().startsWith(NamespacedKey.MINECRAFT + ":")
? id
: id.replace(":", "_") //For Hybrid Server
);
}

public static void modifyItemStack(ItemStack stack, String arguments) {
Expand Down