Search in sources :

Example 1 with StoredInventory

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();
}
Also used : StoredInventory(combatlogx.expansion.compatibility.citizens.object.StoredInventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with StoredInventory

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);
}
Also used : StoredInventory(combatlogx.expansion.compatibility.citizens.object.StoredInventory) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) ArmorType(com.github.sirblobman.api.item.ArmorType)

Example 3 with StoredInventory

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);
}
Also used : StoredInventory(combatlogx.expansion.compatibility.citizens.object.StoredInventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) UUID(java.util.UUID) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) CitizensExpansion(combatlogx.expansion.compatibility.citizens.CitizensExpansion) PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 4 with StoredInventory

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);
        }
    }
}
Also used : StoredInventory(combatlogx.expansion.compatibility.citizens.object.StoredInventory) Equipment(net.citizensnpcs.api.trait.trait.Equipment) EquipmentSlot(net.citizensnpcs.api.trait.trait.Equipment.EquipmentSlot) ItemStack(org.bukkit.inventory.ItemStack) ArmorType(com.github.sirblobman.api.item.ArmorType)

Aggregations

StoredInventory (combatlogx.expansion.compatibility.citizens.object.StoredInventory)4 ItemStack (org.bukkit.inventory.ItemStack)3 ArmorType (com.github.sirblobman.api.item.ArmorType)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 PlayerDataManager (com.github.sirblobman.api.configuration.PlayerDataManager)1 CitizensExpansion (combatlogx.expansion.compatibility.citizens.CitizensExpansion)1 UUID (java.util.UUID)1 Equipment (net.citizensnpcs.api.trait.trait.Equipment)1 EquipmentSlot (net.citizensnpcs.api.trait.trait.Equipment.EquipmentSlot)1 World (org.bukkit.World)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1