Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
Expand Down Expand Up @@ -68,7 +68,7 @@
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>net.imprex.zip.metrics</shadedPattern>
<shadedPattern>dev.imprex.zip.metrics</shadedPattern>
</relocation>
</relocations>
<filters>
Expand Down
2 changes: 1 addition & 1 deletion zip-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip</artifactId>
<version>${revision}</version>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion zip-api/src/main/java/net/imprex/zip/api/ZIPBackpack.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

import java.util.List;

Expand Down
2 changes: 1 addition & 1 deletion zip-api/src/main/java/net/imprex/zip/api/ZIPHandler.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down
2 changes: 1 addition & 1 deletion zip-api/src/main/java/net/imprex/zip/api/ZIPRecipe.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

import org.bukkit.Keyed;
import org.bukkit.inventory.Recipe;
Expand Down
2 changes: 1 addition & 1 deletion zip-api/src/main/java/net/imprex/zip/api/ZIPRegistry.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

import java.util.Collection;

Expand Down
2 changes: 1 addition & 1 deletion zip-api/src/main/java/net/imprex/zip/api/ZIPService.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

public interface ZIPService {

Expand Down
2 changes: 1 addition & 1 deletion zip-api/src/main/java/net/imprex/zip/api/ZIPUniqueId.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.api;
package dev.imprex.zip.api;

public interface ZIPUniqueId {

Expand Down
4 changes: 2 additions & 2 deletions zip-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip</artifactId>
<version>${revision}</version>
</parent>
Expand All @@ -24,7 +24,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip-api</artifactId>
<version>${revision}</version>
<scope>compile</scope>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.common;
package dev.imprex.zip.common;

public class BPConstants {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.common;
package dev.imprex.zip.common;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author Imprex-Development
* @see <a href="https://github.com/Imprex-Development/orebfuscator/blob/master/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/MinecraftVersion.java">MinecraftVersion.java</a>
*/
package net.imprex.zip.common;
package dev.imprex.zip.common;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.common;
package dev.imprex.zip.common;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author Imprex-Development
* @see <a href="https://github.com/Imprex-Development/orebfuscator/blob/master/orebfuscator-nms/orebfuscator-nms-api/src/main/java/net/imprex/orebfuscator/util/ServerVersion.java">ServerVersion.java</a>
*/
package net.imprex.zip.common;
package dev.imprex.zip.common;

public class ServerVersion {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.common;
package dev.imprex.zip.common;

import java.net.NetworkInterface;
import java.net.SocketException;
Expand All @@ -9,7 +9,7 @@
import java.util.Enumeration;
import java.util.concurrent.atomic.AtomicInteger;

import net.imprex.zip.api.ZIPUniqueId;
import dev.imprex.zip.api.ZIPUniqueId;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @author Imprex-Development
* @see <a href="https://github.com/Imprex-Development/orebfuscator/blob/master/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/Version.java">Version.java</a>
*/
package net.imprex.zip.common;
package dev.imprex.zip.common;

import java.io.IOException;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.common;
package dev.imprex.zip.common;

import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down
2 changes: 1 addition & 1 deletion zip-nms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip</artifactId>
<version>${revision}</version>
</parent>
Expand Down
4 changes: 2 additions & 2 deletions zip-nms/zip-nms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip-nms</artifactId>
<version>${revision}</version>
</parent>
Expand All @@ -18,7 +18,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip-common</artifactId>
<version>${revision}</version>
<scope>compile</scope>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.nms.api;
package dev.imprex.zip.nms.api;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.nms.api;
package dev.imprex.zip.nms.api;

import org.bukkit.inventory.ItemStack;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package dev.imprex.zip.nms.api;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

import com.google.gson.JsonObject;

import dev.imprex.zip.common.ReflectionUtil;

public abstract class NmsManager {

private static final Class<?> CRAFT_ITEM_STACK_CLASS;

private static Method craftItemStackAsNmsCopy;
private static Method craftItemStackAsCraftMirror;

static {
try {
CRAFT_ITEM_STACK_CLASS = Class.forName(Bukkit.getServer().getClass().getPackageName() + ".inventory.CraftItemStack");
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
}

protected static <T> T asNmsCopy(ItemStack bukkitItem, Class<T> minecraftItemClass) {
try {
if (craftItemStackAsNmsCopy == null) {
Method method = ReflectionUtil.searchMethod(
CRAFT_ITEM_STACK_CLASS,
minecraftItemClass,
ItemStack.class);
method.setAccessible(true);
craftItemStackAsNmsCopy = method;
}

return minecraftItemClass.cast(craftItemStackAsNmsCopy.invoke(null, bukkitItem));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}

protected static <T> ItemStack asCraftMirror(T minecraftItem) {
try {
if (craftItemStackAsCraftMirror == null) {
Method method = ReflectionUtil.searchMethod(
CRAFT_ITEM_STACK_CLASS,
CRAFT_ITEM_STACK_CLASS,
minecraftItem.getClass());
method.setAccessible(true);
craftItemStackAsCraftMirror = method;
}

return (ItemStack) craftItemStackAsCraftMirror.invoke(null, minecraftItem);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}

public abstract JsonObject itemstackToJsonElement(ItemStack[] items);

public abstract ItemStackContainerResult jsonElementToItemStack(JsonObject jsonElement);

public abstract JsonObject migrateToJsonElement(byte[] binary);

public abstract void setSkullProfile(SkullMeta meta, String texture);

public abstract boolean isAir(Material material);
}

This file was deleted.

18 changes: 16 additions & 2 deletions zip-nms/zip-nms-v1_19_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip-nms</artifactId>
<version>${revision}</version>
</parent>
Expand All @@ -12,7 +12,7 @@

<dependencies>
<dependency>
<groupId>net.imprex</groupId>
<groupId>dev.imprex</groupId>
<artifactId>zip-nms-api</artifactId>
<version>${revision}</version>
<scope>provided</scope>
Expand All @@ -28,6 +28,20 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>mojang-mapped</shadedClassifierName>
<relocations>
<relocation>
<pattern>dev.imprex.zip.nms.v1_19_R1</pattern>
<shadedPattern>dev.imprex.zip.nms.v1_19_R1_mojang</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.imprex.zip.nms.v1_20_R1;
package dev.imprex.zip.nms.v1_19_R1;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -8,7 +8,6 @@
import java.util.UUID;

import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;

Expand All @@ -22,11 +21,11 @@
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps;

import net.imprex.zip.common.BPConstants;
import net.imprex.zip.common.ReflectionUtil;
import net.imprex.zip.nms.api.ItemStackContainerResult;
import net.imprex.zip.nms.api.ItemStackWithSlot;
import net.imprex.zip.nms.api.NmsManager;
import dev.imprex.zip.common.BPConstants;
import dev.imprex.zip.common.ReflectionUtil;
import dev.imprex.zip.nms.api.ItemStackContainerResult;
import dev.imprex.zip.nms.api.ItemStackWithSlot;
import dev.imprex.zip.nms.api.NmsManager;
import net.minecraft.SharedConstants;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
Expand All @@ -39,7 +38,7 @@
import net.minecraft.util.datafix.DataFixers;
import net.minecraft.util.datafix.fixes.References;

public class ZipNmsManager implements NmsManager {
public class ZipNmsManager extends NmsManager {

private static final Class<?> CRAFTMETASKULL_CLASS = ReflectionUtil.getCraftBukkitClass("inventory.CraftMetaSkull");
private static final Method CRAFTMETASKULL_SET_PROFILE = ReflectionUtil.getMethod(CRAFTMETASKULL_CLASS,
Expand All @@ -61,7 +60,7 @@ public JsonObject itemstackToJsonElement(ItemStack[] items) {
if (item == null || item.getType() == Material.AIR) {
continue;
}
net.minecraft.world.item.ItemStack minecraftItem = CraftItemStack.asNMSCopy(item);
net.minecraft.world.item.ItemStack minecraftItem = asNmsCopy(item, net.minecraft.world.item.ItemStack.class);

DataResult<JsonElement> result = net.minecraft.world.item.ItemStack.CODEC.encodeStart(DYNAMIC_OPS_JSON, minecraftItem);
JsonObject resultJson = result.getOrThrow(false, error -> {}).getAsJsonObject();
Expand Down Expand Up @@ -100,7 +99,7 @@ public ItemStackContainerResult jsonElementToItemStack(JsonObject json) {
.parse(DYNAMIC_OPS_JSON, dynamicItemFixed.getValue())
.getOrThrow(false, error -> {});

ItemStack bukkitItem = CraftItemStack.asCraftMirror(minecraftItem);
ItemStack bukkitItem = asCraftMirror(minecraftItem);
int slot = item.getAsJsonObject().get(BPConstants.KEY_INVENTORY_SLOT).getAsInt();

items.add(new ItemStackWithSlot(slot, bukkitItem));
Expand Down
Loading