-
Notifications
You must be signed in to change notification settings - Fork 0
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
6c5452e
commit b18c7bc
Showing
24 changed files
with
798 additions
and
2 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
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
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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ include("v1_16_R3") | |
include("v1_19_R3") | ||
include("v1_20") | ||
include("v1_21_1") | ||
include("v1_21_3") |
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,15 @@ | ||
plugins { | ||
id("io.papermc.paperweight.userdev") | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
} | ||
|
||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(21)) | ||
|
||
dependencies { | ||
compileOnly(project(":common")) | ||
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") | ||
paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") | ||
} |
31 changes: 31 additions & 0 deletions
31
v1_21_3/src/main/java/net/azisaba/loreeditor/v1_21_3/chat/ChatModifierImpl.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,31 @@ | ||
package net.azisaba.loreeditor.v1_21_3.chat; | ||
|
||
import net.azisaba.loreeditor.common.chat.ChatModifier; | ||
import net.azisaba.loreeditor.common.util.Reflected; | ||
import net.minecraft.network.chat.Style; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Objects; | ||
|
||
public record ChatModifierImpl(Style handle) implements ChatModifier { | ||
public ChatModifierImpl { | ||
Objects.requireNonNull(handle, "handle"); | ||
} | ||
|
||
@Contract(value = "_ -> new", pure = true) | ||
@Reflected | ||
public static @NotNull ChatModifierImpl getInstance(@NotNull Object handle) { | ||
return new ChatModifierImpl((Style) handle); | ||
} | ||
|
||
@Override | ||
public @NotNull Style handle() { | ||
return handle; | ||
} | ||
|
||
@Override | ||
public @NotNull ChatModifier setItalic(boolean italic) { | ||
return getInstance(handle.withItalic(italic)); // setItalic | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
v1_21_3/src/main/java/net/azisaba/loreeditor/v1_21_3/chat/ComponentImpl.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,72 @@ | ||
package net.azisaba.loreeditor.v1_21_3.chat; | ||
|
||
import net.azisaba.loreeditor.common.chat.ChatModifier; | ||
import net.azisaba.loreeditor.common.chat.Component; | ||
import net.azisaba.loreeditor.common.util.Reflected; | ||
import net.minecraft.core.RegistryAccess; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.network.chat.Style; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.craftbukkit.CraftServer; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.UnaryOperator; | ||
|
||
@Reflected | ||
public record ComponentImpl(MutableComponent handle) implements Component { | ||
public ComponentImpl(@Nullable net.minecraft.network.chat.Component handle) { | ||
this(handle == null ? null : handle.copy()); | ||
} | ||
|
||
@Contract(value = "_ -> new", pure = true) | ||
@Reflected | ||
public static @NotNull ComponentImpl getInstance(@Nullable Object component) { | ||
return new ComponentImpl((net.minecraft.network.chat.Component) component); | ||
} | ||
|
||
@Override | ||
public @NotNull MutableComponent handle() { | ||
return Objects.requireNonNull(handle, "cannot reference handle in static context"); | ||
} | ||
|
||
public static MutableComponent deserializeFromJson(@NotNull String input) { | ||
RegistryAccess registries = ((CraftServer) Bukkit.getServer()).getServer().registryAccess(); | ||
return net.minecraft.network.chat.Component.Serializer.fromJson(input, registries); | ||
} | ||
|
||
public static String serializeToJson(@NotNull net.minecraft.network.chat.Component component) { | ||
RegistryAccess registries = ((CraftServer) Bukkit.getServer()).getServer().registryAccess(); | ||
return net.minecraft.network.chat.Component.Serializer.toJson(component, registries); | ||
} | ||
|
||
@Override | ||
public @Nullable Component deserialize(@NotNull String input) { | ||
return getInstance(deserializeFromJson(input)); | ||
} | ||
|
||
@Override | ||
public @NotNull String serialize(@NotNull Component component) { | ||
return serializeToJson(((ComponentImpl) component).handle()); | ||
} | ||
|
||
@Override | ||
public @NotNull List<?> getSiblings() { | ||
return handle().getSiblings(); | ||
} | ||
|
||
@Override | ||
public void addSiblingText(@NotNull String text) { | ||
handle().append(deserializeFromJson(text)); | ||
} | ||
|
||
@Override | ||
public @NotNull Component modifyStyle(@NotNull UnaryOperator<ChatModifier> action) { | ||
ChatModifier cm = new ChatModifierImpl(handle().getStyle()); | ||
Style newChatModifier = ((ChatModifierImpl) action.apply(cm)).handle(); | ||
return getInstance(handle().setStyle(newChatModifier)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
v1_21_3/src/main/java/net/azisaba/loreeditor/v1_21_3/entity/CraftPlayer.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 net.azisaba.loreeditor.v1_21_3.entity; | ||
|
||
import net.azisaba.loreeditor.api.util.ReflectionUtil; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
import xyz.acrylicstyle.util.reflector.CastTo; | ||
import xyz.acrylicstyle.util.reflector.Reflector; | ||
import xyz.acrylicstyle.util.reflector.ReflectorHandler; | ||
|
||
import java.util.Objects; | ||
|
||
public interface CraftPlayer { | ||
static @NotNull CraftPlayer getInstance(@NotNull Player player) { | ||
return Reflector.newReflector(null, CraftPlayer.class, | ||
new ReflectorHandler(ReflectionUtil.getOBCClass("entity.CraftPlayer"), Objects.requireNonNull(player, "player"))); | ||
} | ||
|
||
@NotNull | ||
@CastTo(EntityPlayer.class) | ||
EntityPlayer getHandle(); | ||
} |
22 changes: 22 additions & 0 deletions
22
v1_21_3/src/main/java/net/azisaba/loreeditor/v1_21_3/entity/EntityPlayer.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,22 @@ | ||
package net.azisaba.loreeditor.v1_21_3.entity; | ||
|
||
import net.azisaba.loreeditor.api.util.ReflectionUtil; | ||
import net.azisaba.loreeditor.v1_21_3.network.ServerCommonPacketListenerImpl; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import xyz.acrylicstyle.util.reflector.CastTo; | ||
import xyz.acrylicstyle.util.reflector.FieldGetter; | ||
import xyz.acrylicstyle.util.reflector.Reflector; | ||
import xyz.acrylicstyle.util.reflector.ReflectorHandler; | ||
|
||
public interface EntityPlayer { | ||
static @NotNull EntityPlayer getInstance(@Nullable Object o) { | ||
return Reflector.newReflector(null, EntityPlayer.class, | ||
new ReflectorHandler(ReflectionUtil.getNMSClass("net.minecraft.server.level.EntityPlayer"), o)); | ||
} | ||
|
||
@NotNull | ||
@CastTo(value = ServerCommonPacketListenerImpl.class, createInstance = true) | ||
@FieldGetter("connection") | ||
ServerCommonPacketListenerImpl getPlayerConnection(); | ||
} |
27 changes: 27 additions & 0 deletions
27
v1_21_3/src/main/java/net/azisaba/loreeditor/v1_21_3/item/CraftItemStackImpl.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,27 @@ | ||
package net.azisaba.loreeditor.v1_21_3.item; | ||
|
||
import net.azisaba.loreeditor.api.item.CraftItemStack; | ||
import net.azisaba.loreeditor.api.item.ItemStack; | ||
import net.azisaba.loreeditor.common.util.Reflected; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class CraftItemStackImpl implements CraftItemStack { | ||
@Contract(value = "_ -> new", pure = true) | ||
@Reflected | ||
public static @NotNull CraftItemStackImpl getInstance(@Nullable Object item) { | ||
return new CraftItemStackImpl(); | ||
} | ||
|
||
@Override | ||
public @Nullable ItemStack asNMSCopy(org.bukkit.inventory.@Nullable ItemStack item) { | ||
return new ItemStackImpl(org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(item)); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public org.bukkit.inventory.ItemStack asCraftMirror(@NotNull ItemStack item) { | ||
return org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(((ItemStackImpl) item).handle()); | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
v1_21_3/src/main/java/net/azisaba/loreeditor/v1_21_3/item/ItemStackImpl.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,129 @@ | ||
package net.azisaba.loreeditor.v1_21_3.item; | ||
|
||
import net.azisaba.loreeditor.api.item.ItemStack; | ||
import net.azisaba.loreeditor.api.item.tag.CompoundTag; | ||
import net.azisaba.loreeditor.api.item.tag.ListTag; | ||
import net.azisaba.loreeditor.common.util.Reflected; | ||
import net.azisaba.loreeditor.v1_21_3.chat.ComponentImpl; | ||
import net.azisaba.loreeditor.v1_21_3.item.tag.CompoundTagImpl; | ||
import net.azisaba.loreeditor.v1_21_3.item.tag.ListTagImpl; | ||
import net.minecraft.core.component.DataComponentMap; | ||
import net.minecraft.core.component.DataComponents; | ||
import net.minecraft.nbt.StringTag; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.world.item.component.CustomData; | ||
import net.minecraft.world.item.component.ItemLore; | ||
import org.bukkit.craftbukkit.inventory.CraftItemStack; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public record ItemStackImpl(net.minecraft.world.item.ItemStack handle) implements ItemStack { | ||
public ItemStackImpl(net.minecraft.world.item.ItemStack handle) { | ||
this.handle = Objects.requireNonNull(handle, "handle"); | ||
} | ||
|
||
@Override | ||
public @NotNull net.minecraft.world.item.ItemStack handle() { | ||
return handle; | ||
} | ||
|
||
@Contract("_ -> new") | ||
@Reflected | ||
public static @NotNull ItemStackImpl getInstance(@NotNull Object item) { | ||
Objects.requireNonNull(item, "item"); | ||
return new ItemStackImpl((net.minecraft.world.item.ItemStack) item); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public @NotNull CompoundTag getOrCreateTag() { | ||
CustomData customData = handle.get(DataComponents.CUSTOM_DATA); | ||
if (customData == null) { | ||
customData = CustomData.of(new net.minecraft.nbt.CompoundTag()); | ||
handle.set(DataComponents.CUSTOM_DATA, customData); | ||
} | ||
return handleLore(new CompoundTagImpl(customData.getUnsafe())); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Override | ||
public @Nullable CompoundTag getTag() { | ||
CustomData customData = handle.get(DataComponents.CUSTOM_DATA); | ||
if (customData == null) { | ||
return handleLore(null); | ||
} | ||
return handleLore(new CompoundTagImpl(customData.getUnsafe())); | ||
} | ||
|
||
private CompoundTag handleLore(@Nullable CompoundTag base) { | ||
var handle = new net.minecraft.nbt.ListTag(); | ||
ListTag listTag = new ListTagImpl(handle); | ||
if (handle().has(DataComponents.LORE)) { | ||
Objects.requireNonNull(handle().get(DataComponents.LORE)).lines() | ||
.forEach(component -> handle.add(StringTag.valueOf(ComponentImpl.serializeToJson(component)))); | ||
} else { | ||
return base; | ||
} | ||
if (handle.isEmpty()) { | ||
return base; | ||
} | ||
if (base == null) { | ||
base = new CompoundTagImpl(new net.minecraft.nbt.CompoundTag()); | ||
} | ||
CompoundTag displayTag = base.getCompound("display"); | ||
displayTag.set("Lore", listTag); | ||
base.set("display", displayTag); | ||
return base; | ||
} | ||
|
||
@Override | ||
public void setTag(@Nullable CompoundTag tag) { | ||
handle.set(DataComponents.CUSTOM_DATA, tag == null ? null : CustomData.of(((CompoundTagImpl) tag).getHandle())); | ||
if (tag != null) { | ||
if (!tag.hasKeyOfType("display", 10)) { | ||
handle.set(DataComponents.LORE, ItemLore.EMPTY); | ||
return; | ||
} | ||
CompoundTag displayTag = tag.getCompound("display"); | ||
ListTag listTag = displayTag.getList("Lore", 8); | ||
if (listTag.size() > 0) { | ||
List<Component> lore = | ||
((ListTagImpl) listTag).getHandle() | ||
.stream() | ||
.map(Tag::getAsString) | ||
.map(ComponentImpl::deserializeFromJson) | ||
.collect(Collectors.toUnmodifiableList()); | ||
handle.set(DataComponents.LORE, new ItemLore(lore)); | ||
} else { | ||
handle.set(DataComponents.LORE, ItemLore.EMPTY); | ||
} | ||
} else { | ||
handle.set(DataComponents.LORE, ItemLore.EMPTY); | ||
} | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return handle.getCount(); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack copy() { | ||
org.bukkit.inventory.ItemStack originalStack = handle.getBukkitStack(); | ||
org.bukkit.inventory.ItemStack stack = new org.bukkit.inventory.ItemStack(originalStack.getType(), handle.getCount()); | ||
if (originalStack.hasItemMeta()) { | ||
stack.setItemMeta(originalStack.getItemMeta().clone()); | ||
} | ||
return new ItemStackImpl(CraftItemStack.asNMSCopy(stack)); | ||
} | ||
|
||
public DataComponentMap getComponents() { | ||
return handle.getComponents(); | ||
} | ||
} |
Oops, something went wrong.