-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d5037f
commit 3ab572c
Showing
2 changed files
with
105 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
TradeSystem-Spigot/src/main/java/de/codingair/tradesystem/spigot/utils/EntityItemUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.codingair.tradesystem.spigot.utils; | ||
|
||
import de.codingair.codingapi.server.reflections.IReflection; | ||
import de.codingair.codingapi.server.reflections.PacketUtils; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Item; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class EntityItemUtils { | ||
private static final Class<?> ENTITY_ITEM_CLASS = IReflection.getClass(IReflection.ServerPacket.MINECRAFT_PACKAGE("net.minecraft.world.entity.item"), "EntityItem"); | ||
private static final IReflection.ConstructorAccessor ENTITY_ITEM = IReflection.getConstructor(ENTITY_ITEM_CLASS, PacketUtils.WorldClass, double.class, double.class, double.class, PacketUtils.ItemStackClass); | ||
|
||
@NotNull | ||
public static Item create(@NotNull Location location, @NotNull ItemStack item) { | ||
assert ENTITY_ITEM != null; | ||
Object entityItem = ENTITY_ITEM.newInstance(PacketUtils.getWorldServer(location.getWorld()), location.getX(), location.getY(), location.getZ(), PacketUtils.getItemStack(item)); | ||
return (Item) PacketUtils.getBukkitEntity(entityItem); | ||
} | ||
|
||
} |