Skip to content

Commit

Permalink
Merge pull request #28 from demkom58/1.19-update
Browse files Browse the repository at this point in the history
feat: update to 1.19, bump version to 2.7.7
  • Loading branch information
demkom58 authored Jun 12, 2022
2 parents 2c6cefb + 82554cc commit 3ebdd1c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
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/
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.demkom58.divinedrop.version.V17R1.V17R1;
import com.demkom58.divinedrop.version.V18R1.V18R1;
import com.demkom58.divinedrop.version.V18R2.V18R2;
import com.demkom58.divinedrop.version.V19R1.V19R1;
import com.demkom58.divinedrop.version.V8R3.V8R3;
import com.demkom58.divinedrop.version.V8R3.V8ResourceClient;
import com.demkom58.divinedrop.version.V9R1.V9R1;
Expand Down Expand Up @@ -43,7 +44,8 @@ public enum SupportedVersion {
V16R3(V16R3.class, new V13ResourceClient("1.16.4"), "v1_16_R3", V16R3::new),
V17R1(V17R1.class, new V13ResourceClient("1.17"), "v1_17_R1", V17R1::new),
V18R1(V18R1.class, new V13ResourceClient("1.18"), "v1_18_R1", V18R1::new),
V18R2(V18R2.class, new V13ResourceClient("1.18.2"), "v1_18_R2", V18R2::new)
V18R2(V18R2.class, new V13ResourceClient("1.18.2"), "v1_18_R2", V18R2::new),
V19R1(V19R1.class, new V13ResourceClient("1.19"), "v1_19_R1", V19R1::new)
;

private static final Map<String, SupportedVersion> NMS_VERSION_MAP = new HashMap<String, SupportedVersion>(){{
Expand Down
97 changes: 97 additions & 0 deletions src/main/java/com/demkom58/divinedrop/version/V19R1/V19R1.java
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();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/cache.json

Large diffs are not rendered by default.

0 comments on commit 3ebdd1c

Please sign in to comment.