-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from demkom58/1.19-update
feat: update to 1.19, bump version to 2.7.7
- Loading branch information
Showing
4 changed files
with
102 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pluginGroup = com.demkom58.divinedrop | ||
pluginDesc = Awesome removal of items from the ground | ||
pluginVersion = 2.7.6 | ||
pluginVersion = 2.7.7 | ||
url = https://www.spigotmc.org/members/98068/ |
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
97 changes: 97 additions & 0 deletions
97
src/main/java/com/demkom58/divinedrop/version/V19R1/V19R1.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,97 @@ | ||
package com.demkom58.divinedrop.version.V19R1; | ||
|
||
import com.demkom58.divinedrop.drop.ItemHandler; | ||
import com.demkom58.divinedrop.lang.Language; | ||
import com.demkom58.divinedrop.version.V12R1.V12Listener; | ||
import com.demkom58.divinedrop.version.Version; | ||
import lombok.SneakyThrows; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.ItemMeta; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
|
||
public class V19R1 implements Version { | ||
private final ResourceClient client; | ||
private final ItemHandler manager; | ||
|
||
private MethodHandle asNMSCopyHandle; | ||
private MethodHandle getItemHandle; | ||
private MethodHandle getNameHandle; | ||
|
||
{ | ||
try { | ||
asNMSCopyHandle = MethodHandles.lookup() | ||
.findStatic( | ||
Class.forName("org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack"), | ||
"asNMSCopy", | ||
MethodType.methodType(net.minecraft.world.item.ItemStack.class, ItemStack.class) | ||
); | ||
getItemHandle = MethodHandles.lookup() | ||
.findVirtual( | ||
Class.forName("net.minecraft.world.item.ItemStack"), | ||
"c", | ||
MethodType.methodType(net.minecraft.world.item.Item.class) | ||
); | ||
getNameHandle = MethodHandles.lookup() | ||
.findVirtual( | ||
Class.forName("net.minecraft.world.item.Item"), | ||
"a", | ||
MethodType.methodType(String.class) | ||
); | ||
} catch (NoSuchMethodException | ClassNotFoundException | IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public V19R1(@NotNull final ResourceClient client, @NotNull final ItemHandler manager) { | ||
this.client = client; | ||
this.manager = manager; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Version.ResourceClient getClient() { | ||
return client; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public String getI18NDisplayName(@Nullable ItemStack item) { | ||
if (item == null) | ||
return null; | ||
|
||
return getName(item); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Listener createListener() { | ||
return new V12Listener(manager); | ||
} | ||
|
||
@NotNull | ||
@SneakyThrows | ||
private String getName(ItemStack bItemStack) { | ||
if (bItemStack.hasItemMeta()) { | ||
final ItemMeta itemMeta = bItemStack.getItemMeta(); | ||
if (itemMeta.hasDisplayName()) | ||
return itemMeta.getDisplayName(); | ||
} | ||
|
||
return getLangNameNMS((net.minecraft.world.item.ItemStack) asNMSCopyHandle.invokeExact(bItemStack)); | ||
} | ||
|
||
@NotNull | ||
@SneakyThrows | ||
private String getLangNameNMS(net.minecraft.world.item.ItemStack itemStack) { | ||
final net.minecraft.world.item.Item item = | ||
(net.minecraft.world.item.Item) getItemHandle.bindTo(itemStack).invokeExact(); | ||
final String name = (String) getNameHandle.bindTo(item).invokeExact(); | ||
return Language.getInstance().getLocName(name).trim(); | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.