Search in sources :

Example 1 with LinkedChestsContainer

use of com.bgsoftware.wildchests.objects.containers.LinkedChestsContainer in project WildChests by BG-Software-LLC.

the class WLinkedChest method linkIntoChest.

@Override
public void linkIntoChest(LinkedChest linkedChest) {
    if (linkedChest == null) {
        if (linkedChestsContainer != null)
            linkedChestsContainer.unlinkChest(this);
        linkedChestsContainer = null;
        saveLinkedChest();
        return;
    }
    LinkedChestsContainer otherContainer = ((WLinkedChest) linkedChest).linkedChestsContainer;
    if (otherContainer == null) {
        linkedChest.onBreak(new BlockBreakEvent(null, null));
        if (linkedChestsContainer == null)
            linkedChestsContainer = new LinkedChestsContainer(this);
        ((WLinkedChest) linkedChest).linkedChestsContainer = linkedChestsContainer;
        linkedChestsContainer.linkChest(linkedChest);
    } else {
        if (otherContainer.isLinkedChest(this))
            return;
        otherContainer.linkChest(this);
        if (linkedChestsContainer != null)
            linkedChestsContainer.unlinkChest(this);
        linkedChestsContainer = otherContainer;
    }
    ((WLinkedChest) linkedChest).saveLinkedChest();
    saveLinkedChest();
}
Also used : LinkedChestsContainer(com.bgsoftware.wildchests.objects.containers.LinkedChestsContainer) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent)

Example 2 with LinkedChestsContainer

use of com.bgsoftware.wildchests.objects.containers.LinkedChestsContainer in project WildChests by BG-Software-LLC.

the class WLinkedChest method loadFromData.

public void loadFromData(String serialized, String linkedChest) {
    super.loadFromData(serialized);
    if (!linkedChest.isEmpty()) {
        Location linkedChestLocation = LocationUtils.fromString(linkedChest);
        Executor.sync(() -> {
            LinkedChest sourceChest = plugin.getChestsManager().getLinkedChest(linkedChestLocation);
            if (sourceChest != null) {
                if (((WLinkedChest) sourceChest).linkedChestsContainer == null)
                    ((WLinkedChest) sourceChest).linkedChestsContainer = new LinkedChestsContainer(sourceChest);
                this.linkedChestsContainer = ((WLinkedChest) sourceChest).linkedChestsContainer;
                this.linkedChestsContainer.linkChest(this);
            }
        }, 1L);
    }
}
Also used : LinkedChestsContainer(com.bgsoftware.wildchests.objects.containers.LinkedChestsContainer) LinkedChest(com.bgsoftware.wildchests.api.objects.chests.LinkedChest) Location(org.bukkit.Location)

Aggregations

LinkedChestsContainer (com.bgsoftware.wildchests.objects.containers.LinkedChestsContainer)2 LinkedChest (com.bgsoftware.wildchests.api.objects.chests.LinkedChest)1 Location (org.bukkit.Location)1 BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)1