Search in sources :

Example 46 with PublicCraftingInventory

use of io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method move.

@Override
public PublicCraftingInventory move(Location location) {
    display.stop();
    if (manager.get(bloc) == this) {
        manager.benches.remove(bloc);
    }
    bloc = location;
    CustomInventoryCrafting whatsHere = manager.put(location, this);
    display = new CraftDisplay(this);
    display.update();
    return whatsHere;
}
Also used : CraftDisplay(io.github.bananapuncher714.crafters.display.CraftDisplay)

Example 47 with PublicCraftingInventory

use of io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method move.

@Override
public PublicCraftingInventory move(Location location) {
    display.stop();
    if (manager.get(bloc) == this) {
        manager.benches.remove(bloc);
    }
    bloc = location;
    CustomInventoryCrafting whatsHere = manager.put(location, this);
    display = new CraftDisplay(this);
    display.update();
    return whatsHere;
}
Also used : CraftDisplay(io.github.bananapuncher714.crafters.display.CraftDisplay)

Example 48 with PublicCraftingInventory

use of io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_11_R1 method remove.

@Override
public void remove(Location location) {
    if (benches.containsKey(location)) {
        PublicCraftingInventory bench = benches.get(location);
        bench.remove();
        benches.remove(location);
    }
}
Also used : PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory)

Example 49 with PublicCraftingInventory

use of io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory in project PublicCrafters by BananaPuncher714.

the class CraftBlockListener method onPistonRetractEvent.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPistonRetractEvent(BlockPistonRetractEvent event) {
    BlockFace face = event.getDirection();
    Set<PublicCraftingInventory> moveThese = new HashSet<PublicCraftingInventory>();
    Set<Location> newLocations = new HashSet<Location>();
    for (Block block : event.getBlocks()) {
        PublicCraftingInventory crafting = plugin.getManager().get(block.getLocation());
        if (crafting != null) {
            moveThese.add(crafting);
        }
        if (plugin.getAdminTables().remove(block.getLocation())) {
            newLocations.add(block.getRelative(face).getLocation());
        }
    }
    plugin.getAdminTables().addAll(newLocations);
    for (PublicCraftingInventory crafting : moveThese) {
        crafting.move(crafting.getLocation().getBlock().getRelative(face).getLocation());
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory) Block(org.bukkit.block.Block) HashSet(java.util.HashSet) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 50 with PublicCraftingInventory

use of io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory in project PublicCrafters by BananaPuncher714.

the class CraftBlockListener method onPistonExtendEvent.

/**
 * These are a bit more complicated; First, get all the blocks BEFORE moving them
 * Then, you can safely move them; This is to prevent overwriting crafting tables at their new location
 * @param event
 * The BlockPistonExtendEvent
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPistonExtendEvent(BlockPistonExtendEvent event) {
    BlockFace face = event.getDirection();
    Set<PublicCraftingInventory> moveThese = new HashSet<PublicCraftingInventory>();
    Set<Location> newLocations = new HashSet<Location>();
    for (Block block : event.getBlocks()) {
        PublicCraftingInventory crafting = plugin.getManager().get(block.getLocation());
        if (crafting != null) {
            moveThese.add(crafting);
        }
        if (plugin.getAdminTables().remove(block.getLocation())) {
            newLocations.add(block.getRelative(face).getLocation());
        }
    }
    plugin.getAdminTables().addAll(newLocations);
    for (PublicCraftingInventory crafting : moveThese) {
        crafting.move(crafting.getLocation().getBlock().getRelative(face).getLocation());
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory) Block(org.bukkit.block.Block) HashSet(java.util.HashSet) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PublicCraftingInventory (io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory)34 CraftDisplay (io.github.bananapuncher714.crafters.display.CraftDisplay)16 HashSet (java.util.HashSet)2 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2 BlockFace (org.bukkit.block.BlockFace)2 EventHandler (org.bukkit.event.EventHandler)2