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();
}
}
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();
}
}
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);
}
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);
}
Aggregations