use of combatlogx.expansion.compatibility.citizens.object.StoredInventory in project CombatLogX by SirBlobman.
the class InventoryManager method restoreInventory.
public void restoreInventory(Player player) {
Validate.notNull(player, "player must not be null!");
if (player.hasMetadata("NPC")) {
throw new IllegalArgumentException("player must not be an NPC!");
}
StoredInventory storedInventory = getStoredInventory(player);
if (storedInventory == null) {
return;
}
PlayerInventory playerInventory = player.getInventory();
playerInventory.clear();
for (int slot = 0; slot < 36; slot++) {
ItemStack item = storedInventory.getItem(slot);
playerInventory.setItem(slot, item);
}
playerInventory.setHelmet(storedInventory.getArmor(ArmorType.HELMET));
playerInventory.setChestplate(storedInventory.getArmor(ArmorType.CHESTPLATE));
playerInventory.setLeggings(storedInventory.getArmor(ArmorType.LEGGINGS));
playerInventory.setBoots(storedInventory.getArmor(ArmorType.BOOTS));
int minorVersion = VersionUtility.getMinorVersion();
if (minorVersion < 9) {
restoreHandsLegacy(storedInventory, playerInventory);
} else {
restoreHandsModern(storedInventory, playerInventory);
}
removeStoredInventory(player);
player.updateInventory();
}
use of combatlogx.expansion.compatibility.citizens.object.StoredInventory in project CombatLogX by SirBlobman.
the class InventoryManager method dropInventory.
public void dropInventory(OfflinePlayer player, Location location) {
Validate.notNull(player, "player must not be null!");
Validate.notNull(location, "location must not be null!");
World world = location.getWorld();
Validate.notNull(world, "location must have a valid world!");
StoredInventory storedInventory = getStoredInventory(player);
if (storedInventory == null) {
return;
}
for (int slot = 0; slot < 36; slot++) {
ItemStack item = storedInventory.getItem(slot);
dropItem(item, player, location, CitizensSlotType.INVENTORY);
}
ArmorType[] armorTypeArray = ArmorType.values();
for (ArmorType armorType : armorTypeArray) {
ItemStack item = storedInventory.getArmor(armorType);
dropItem(item, player, location, CitizensSlotType.ARMOR);
}
ItemStack item = storedInventory.getOffHandItem();
dropItem(item, player, location, CitizensSlotType.OFFHAND);
removeStoredInventory(player);
}
use of combatlogx.expansion.compatibility.citizens.object.StoredInventory in project CombatLogX by SirBlobman.
the class InventoryManager method storeInventory.
public void storeInventory(Player player) {
Validate.notNull(player, "player must not be null!");
if (player.hasMetadata("NPC")) {
throw new IllegalArgumentException("player must not be an NPC!");
}
PlayerInventory playerInventory = player.getInventory();
StoredInventory storedInventory = StoredInventory.createFrom(playerInventory);
UUID playerId = player.getUniqueId();
this.storedInventoryMap.put(playerId, storedInventory);
PlayerDataManager playerDataManager = getPlayerDataManager();
YamlConfiguration configuration = playerDataManager.get(player);
ConfigurationSection section = configuration.createSection("citizens-compatibility.stored-inventory");
CitizensExpansion expansion = getExpansion();
storedInventory.save(expansion, section);
playerDataManager.save(player);
}
use of combatlogx.expansion.compatibility.citizens.object.StoredInventory in project CombatLogX by SirBlobman.
the class InventoryManager method equipNPC.
public void equipNPC(OfflinePlayer player, NPC npc) {
Validate.notNull(player, "player must not be null!");
Validate.notNull(npc, "npc must not be null!");
Equipment equipmentTrait = npc.getOrAddTrait(Equipment.class);
StoredInventory storedInventory = getStoredInventory(player);
if (storedInventory == null) {
return;
}
ItemStack mainHandItem = storedInventory.getMainHandItem();
if (mainHandItem != null) {
equipmentTrait.set(EquipmentSlot.HAND, mainHandItem);
}
if (VersionUtility.getMinorVersion() > 8) {
ItemStack offHandItem = storedInventory.getOffHandItem();
if (offHandItem != null) {
equipmentTrait.set(EquipmentSlot.OFF_HAND, offHandItem);
}
}
ArmorType[] armorTypeArray = ArmorType.values();
for (ArmorType armorType : armorTypeArray) {
ItemStack item = storedInventory.getArmor(armorType);
if (item != null) {
org.bukkit.inventory.EquipmentSlot bukkitSlot = armorType.getSlot();
EquipmentSlot slot = getNpcSlotFromBukkitSlot(bukkitSlot);
equipmentTrait.set(slot, item);
}
}
}
Aggregations