mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 17:37:42 +01:00
Fix Inventory not using a Component as title
This commit is contained in:
parent
992f7feb77
commit
d6b6d41f41
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.data.type;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.data.DataType;
|
||||
import net.minestom.server.inventory.Inventory;
|
||||
import net.minestom.server.inventory.InventoryType;
|
||||
@ -15,7 +16,7 @@ public class InventoryData extends DataType<Inventory> {
|
||||
final int size = inventoryType.getSize();
|
||||
|
||||
// Inventory title & type
|
||||
writer.writeSizedString(value.getTitle());
|
||||
writer.writeComponent(value.getTitle());
|
||||
writer.writeSizedString(inventoryType.name());
|
||||
|
||||
// Write all item stacks
|
||||
@ -27,7 +28,7 @@ public class InventoryData extends DataType<Inventory> {
|
||||
@NotNull
|
||||
@Override
|
||||
public Inventory decode(@NotNull BinaryReader reader) {
|
||||
final String title = reader.readSizedString(Integer.MAX_VALUE);
|
||||
final Component title = reader.readComponent(Integer.MAX_VALUE);
|
||||
final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString(Integer.MAX_VALUE));
|
||||
final int size = inventoryType.getSize();
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.inventory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.inventory.click.ClickType;
|
||||
@ -37,8 +38,8 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
private final byte id;
|
||||
// the type of this inventory
|
||||
private final InventoryType inventoryType;
|
||||
// the title of this inventory)
|
||||
private String title;
|
||||
// the title of this inventory
|
||||
private Component title;
|
||||
|
||||
private final int offset;
|
||||
|
||||
@ -48,7 +49,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
// (player -> cursor item) map, used by the click listeners
|
||||
private final ConcurrentHashMap<Player, ItemStack> cursorPlayersItem = new ConcurrentHashMap<>();
|
||||
|
||||
public Inventory(@NotNull InventoryType inventoryType, @NotNull String title) {
|
||||
public Inventory(@NotNull InventoryType inventoryType, @NotNull Component title) {
|
||||
super(inventoryType.getSize());
|
||||
this.id = generateId();
|
||||
this.inventoryType = inventoryType;
|
||||
@ -57,6 +58,14 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
this.offset = getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link Inventory#Inventory(InventoryType, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Inventory(@NotNull InventoryType inventoryType, @NotNull String title) {
|
||||
this(inventoryType, Component.text(title));
|
||||
}
|
||||
|
||||
private static byte generateId() {
|
||||
byte newInventoryId = (byte) LAST_INVENTORY_ID.incrementAndGet();
|
||||
if (newInventoryId == Byte.MAX_VALUE)
|
||||
@ -80,7 +89,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
* @return the inventory title
|
||||
*/
|
||||
@NotNull
|
||||
public String getTitle() {
|
||||
public Component getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@ -89,7 +98,7 @@ public class Inventory extends AbstractInventory implements Viewable {
|
||||
*
|
||||
* @param title the new inventory title
|
||||
*/
|
||||
public void setTitle(@NotNull String title) {
|
||||
public void setTitle(@NotNull Component title) {
|
||||
this.title = title;
|
||||
|
||||
OpenWindowPacket packet = new OpenWindowPacket(title);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
@ -12,26 +11,27 @@ public class OpenWindowPacket implements ServerPacket {
|
||||
|
||||
public int windowId;
|
||||
public int windowType;
|
||||
public JsonMessage title = ColoredText.of("");
|
||||
public Component title = Component.text("");
|
||||
|
||||
public OpenWindowPacket() {}
|
||||
public OpenWindowPacket() {
|
||||
}
|
||||
|
||||
public OpenWindowPacket(String title) {
|
||||
this.title = ColoredText.of(title);
|
||||
public OpenWindowPacket(Component title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(windowId);
|
||||
writer.writeVarInt(windowType);
|
||||
writer.writeJsonMessage(title);
|
||||
writer.writeComponent(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
windowId = reader.readVarInt();
|
||||
windowType = reader.readVarInt();
|
||||
title = reader.readJsonMessage(Integer.MAX_VALUE);
|
||||
title = reader.readComponent(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,13 +57,13 @@ public class PlayerInit {
|
||||
instanceContainer.enableAutoChunkLoad(true);
|
||||
instanceContainer.setChunkGenerator(chunkGeneratorDemo);
|
||||
|
||||
inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||
inventory = new Inventory(InventoryType.CHEST_1_ROW, Component.text("Test inventory"));
|
||||
/*inventory.addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||
p.sendMessage("click type inventory: " + clickType);
|
||||
System.out.println("slot inv: " + slot)0;
|
||||
inventoryConditionResult.setCancel(slot == 3);
|
||||
});*/
|
||||
//inventory.setItemStack(3, new ItemStack(Material.DIAMOND, (byte) 34));
|
||||
inventory.setItemStack(3, ItemStack.of(Material.DIAMOND, 34));
|
||||
|
||||
{
|
||||
CompassMeta compassMeta = new CompassMeta.Builder()
|
||||
@ -245,6 +245,8 @@ public class PlayerInit {
|
||||
//inventory.setChestplate(item);
|
||||
}
|
||||
|
||||
player.openInventory(PlayerInit.inventory);
|
||||
|
||||
//player.getInventory().addItemStack(new ItemStack(Material.STONE, (byte) 32));
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user