Search in sources :

Example 1 with PlayerInventory

use of net.minecraft.world.entity.player.PlayerInventory in project InventoryShare by the-sugar-tree.

the class Inventory method invApply.

@SuppressWarnings("ConstantConditions")
public static void invApply(@NotNull Player p) {
    if (!(teaminventory)) {
        invApplyAll(p);
        return;
    }
    if (plugin.getServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(p) == null) {
        invApplyAll(p);
        return;
    }
    String teamName = plugin.getServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(p).getName();
    NonNullList<ItemStack> itemsT;
    NonNullList<ItemStack> armorT;
    NonNullList<ItemStack> extraSlotsT;
    if (!InventoryList.containsKey(teamName)) {
        Map<String, NonNullList<ItemStack>> map = new HashMap<>();
        itemsT = NonNullList.a(36, ItemStack.b);
        armorT = NonNullList.a(4, ItemStack.b);
        extraSlotsT = NonNullList.a(1, ItemStack.b);
        map.put("items", itemsT);
        map.put("armor", armorT);
        map.put("extraSlots", extraSlotsT);
        InventoryList.put(teamName, map);
    } else {
        Map<String, NonNullList<ItemStack>> map = InventoryList.get(teamName);
        itemsT = map.get("items");
        armorT = map.get("armor");
        extraSlotsT = map.get("extraSlots");
    }
    List<NonNullList<ItemStack>> contentsT = ImmutableList.of(itemsT, armorT, extraSlotsT);
    EntityPlayer entityPlayer = ((CraftPlayer) p).getHandle();
    PlayerInventory playerInventory = entityPlayer.fq();
    try {
        setField(playerInventory, "h", itemsT);
        setField(playerInventory, "i", armorT);
        setField(playerInventory, "j", extraSlotsT);
        setField(playerInventory, "n", contentsT);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) NonNullList(net.minecraft.core.NonNullList) EntityPlayer(net.minecraft.server.level.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) PlayerInventory(net.minecraft.world.entity.player.PlayerInventory) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with PlayerInventory

use of net.minecraft.world.entity.player.PlayerInventory in project InventoryShare by the-sugar-tree.

the class Inventory method invApplyAll.

public static void invApplyAll(@NotNull Player p) {
    EntityPlayer entityPlayer = ((CraftPlayer) p).getHandle();
    PlayerInventory playerInventory = entityPlayer.fq();
    try {
        setField(playerInventory, "h", items);
        setField(playerInventory, "i", armor);
        setField(playerInventory, "j", extraSlots);
        setField(playerInventory, "n", contents);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : EntityPlayer(net.minecraft.server.level.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) PlayerInventory(net.minecraft.world.entity.player.PlayerInventory)

Example 3 with PlayerInventory

use of net.minecraft.world.entity.player.PlayerInventory in project InventoryShare by the-sugar-tree.

the class Inventory method savePlayerInventory.

public static void savePlayerInventory(@NotNull Player p) {
    PlayerInventory pinv = new PlayerInventory(null);
    try {
        setField(pinv, "h", ((CraftPlayer) p).getHandle().fq().h);
        setField(pinv, "i", ((CraftPlayer) p).getHandle().fq().i);
        setField(pinv, "j", ((CraftPlayer) p).getHandle().fq().j);
        setField(pinv, "n", ImmutableList.of(((CraftPlayer) p).getHandle().fq().h, ((CraftPlayer) p).getHandle().fq().i, ((CraftPlayer) p).getHandle().fq().j));
    } catch (Exception e) {
        e.printStackTrace();
    }
    invList.put(p.getUniqueId(), pinv);
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) PlayerInventory(net.minecraft.world.entity.player.PlayerInventory)

Example 4 with PlayerInventory

use of net.minecraft.world.entity.player.PlayerInventory in project InventoryShare by the-sugar-tree.

the class Inventory method invDisApply.

@SuppressWarnings("SuspiciousMethodCalls")
public static void invDisApply(@NotNull Player p) {
    EntityPlayer entityPlayer = ((CraftPlayer) p).getHandle();
    PlayerInventory playerInventory = entityPlayer.fq();
    if (invList.containsKey(entityPlayer.cm())) {
        try {
            NonNullList<ItemStack> items1 = invList.get(entityPlayer.cm()).h;
            NonNullList<ItemStack> armor1 = invList.get(entityPlayer.cm()).i;
            NonNullList<ItemStack> extraSlots1 = invList.get(entityPlayer.cm()).j;
            List<NonNullList<ItemStack>> contents1 = ImmutableList.of(items1, armor1, extraSlots1);
            setField(playerInventory, "h", items1);
            setField(playerInventory, "i", armor1);
            setField(playerInventory, "j", extraSlots1);
            setField(playerInventory, "n", contents1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        // 사용될 일이 없지만, 혹시 모른 버그 방지
        try {
            NonNullList<ItemStack> items1 = NonNullList.a(36, ItemStack.b);
            NonNullList<ItemStack> armor1 = NonNullList.a(36, ItemStack.b);
            NonNullList<ItemStack> extraSlots1 = NonNullList.a(36, ItemStack.b);
            List<NonNullList<ItemStack>> contents1 = ImmutableList.of(items1, armor1, extraSlots1);
            setField(playerInventory, "h", items1);
            setField(playerInventory, "i", armor1);
            setField(playerInventory, "j", extraSlots1);
            setField(playerInventory, "n", contents1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    invList.remove(entityPlayer);
}
Also used : NonNullList(net.minecraft.core.NonNullList) EntityPlayer(net.minecraft.server.level.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) PlayerInventory(net.minecraft.world.entity.player.PlayerInventory) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

PlayerInventory (net.minecraft.world.entity.player.PlayerInventory)4 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)4 EntityPlayer (net.minecraft.server.level.EntityPlayer)3 NonNullList (net.minecraft.core.NonNullList)2 ItemStack (net.minecraft.world.item.ItemStack)2 HashMap (java.util.HashMap)1