Java 类org.bukkit.block.Dispenser 实例源码

项目:GamePlate    文件:TntTracker.java   
@EventHandler
    public void onEntityExplode(EntityExplodeEvent event) {
        if (event.getEntity() != null) {
            if (event.getEntity().getType() == EntityType.PRIMED_TNT) {
                for (Block block : event.blockList()) {
                    if (block.getType() == Material.TNT && getWhoPlaced(event.getEntity()) != null) {
                        Location location = block.getLocation();
                        tntPlaced.put(location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ(), getWhoPlaced(event.getEntity()));
                    }
                }

                for (Entity entity : event.getEntity().getNearbyEntities(8, 8, 8)) {
//                    F.debug("Found tnt");
                    if (entity instanceof TNTPrimed) {
                        UUID playerUUID = getWhoPlaced(event.getEntity());
                        if(playerUUID != null) {
                            Dispenser dispenser;
//                            F.debug("found placer: " + Bukkit.getServer().getPlayer(playerUUID));
                            entity.setMetadata("source", new FixedMetadataValue(GamePlate.getInstance(), playerUUID));
                        }
                    }
                }
            }
        }
    }
项目:ExilePearl    文件:PlayerListener.java   
/**
 * Updates the pearl holder
 * @param pearl The pearl to update
 * @param holder The pearl holder
 * @param event The event
 */
private void updatePearlHolder(ExilePearl pearl, InventoryHolder holder, Cancellable event) {

    if (holder instanceof Chest) {
        updatePearl(pearl, (Chest)holder);
    } else if (holder instanceof DoubleChest) {
        updatePearl(pearl, (Chest) ((DoubleChest) holder).getLeftSide());
    } else if (holder instanceof Furnace) {
        updatePearl(pearl, (Furnace) holder);
    } else if (holder instanceof Dispenser) {
        updatePearl(pearl, (Dispenser) holder);
    } else if (holder instanceof Dropper) {
        updatePearl(pearl, (Dropper) holder);
    } else if (holder instanceof Hopper) {
        updatePearl(pearl, (Hopper) holder);
    } else if (holder instanceof BrewingStand) {
        updatePearl(pearl, (BrewingStand) holder);
    } else if (holder instanceof Player) {
        updatePearl(pearl, (Player) holder);
    }else {
        event.setCancelled(true);
    }
}
项目:DispenserFill    文件:FillDispensersCommand.java   
private List<Location> getDispenserLocationFromRange(int radius, Location location) {
    List<Location> locations = new ArrayList<Location>();

    for (int x = (radius * -1); x <= radius; x++) {
        for (int y = (radius * -1); y <= radius; y++) {
            for (int z = (radius * -1); z <= radius; z++) {
                Block block = location.getWorld().getBlockAt(location.getBlockX() + x, location.getBlockY() + y, location.getBlockZ() + z);

                if (block.getType() == Material.DISPENSER) {
                    if (block.getState() instanceof Dispenser) {
                        locations.add(block.getLocation());
                    }
                }
            }
        }
    }

    return locations;
}
项目:StarQuestCode    文件:Turret.java   
protected boolean hasAmmo(Player p) {

        // This method is called after we already know that it is an advanced
        // turret
        Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
        if (b.getType() != Material.DISPENSER)
            return false;
        Dispenser d = (Dispenser) b.getState();
        Inventory i = d.getInventory();
        for (Ammo ammo : ammos) {
            if (i.contains(Material.SPLASH_POTION) && ammo.getName().equalsIgnoreCase("potion")){
                i.removeItem(i.getItem(i.first(Material.SPLASH_POTION)));
                return true;
            } else if (i.contains(Material.LINGERING_POTION) && ammo.getName().equalsIgnoreCase("potion")){
                i.removeItem(i.getItem(i.first(Material.LINGERING_POTION)));
                return true;
            } else if (i.contains(ammo.getItem().getType(), ammo.getItem().getAmount())) {
                i.removeItem(ammo.getItem());
                return true;
            }
        }
        return false;

    }
项目:StarQuestCode    文件:Turret.java   
protected Ammo getLoadedAmmo(Player p) {

        // This method returns the ammo type we are using
        Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
        Dispenser d = (Dispenser) b.getState();
        Inventory i = d.getInventory();
        for (Ammo ammo : this.getAmmos()) {
            if (i.contains(Material.SPLASH_POTION) && ammo.getName().equalsIgnoreCase("potion")){
                ammo.setItem(i.getItem(i.first(Material.SPLASH_POTION)));
                return ammo;
            } else if (i.contains(Material.LINGERING_POTION) && ammo.getName().equalsIgnoreCase("potion")){
                ammo.setItem(i.getItem(i.first(Material.LINGERING_POTION)));
                return ammo;
            } else if (i.contains(ammo.getItem().getType())) {
                ItemStack stack = new ItemStack(i.getItem(i.first(ammo.getItem().getType())));
                stack.setAmount(ammo.getItem().getAmount());
                ammo.setItem(stack);
                return ammo;
            }
        }
        return null;

    }
项目:Zeus    文件:ZeusEventHandler.java   
@EventHandler
public void onBlockDispense(BlockDispenseEvent event) {
    if (event.getBlock().getType() == Material.DISPENSER) {
        Dispenser diq = (Dispenser) event.getBlock().getState();
        Block maybeSign = event
                .getBlock()
                .getWorld()
                .getBlockAt(event.getBlock().getX(),
                        event.getBlock().getY() - 1,
                        event.getBlock().getZ()); // TODO
        if (maybeSign.getState() instanceof Sign) {
            if (plugin.isUnlimitedSign(((Sign) maybeSign.getState())
                    .getLine(0))) {
                diq.getInventory().addItem(new ItemStack(event.getItem()));
            }
        }
    }
}
项目:xEssentials-deprecated-bukkit    文件:DispenseSignEvent.java   
@EventHandler
public void onPower(BlockDispenseEvent e) {
        if(e.getBlock().getType() == Material.DISPENSER) {
            if(hasNearbySign(e.getBlock())) {
                org.bukkit.block.Sign sign = getSign(e.getBlock());
                if(sign.getLine(0).equalsIgnoreCase(ChatColor.BLUE + "[Dispense]")) {
                    Dispenser disp = (Dispenser) e.getBlock().getState();
                    for(ItemStack stack : disp.getInventory().getContents()) {
                        if(stack != null) {
                            ItemStack clone = stack.clone();
                            clone.setAmount(64);
                            disp.getInventory().addItem(clone);
                        }
                    }
                }
            }
        }
}
项目:MachineFactory    文件:OreGin.java   
/**
 * Checks if a specific material of given amount is available in dispenser
 */
public static boolean isMaterialAvailable(int amount, Material material, Location machineLocation)
{
    if (machineLocation.getBlock().getType() == Material.DISPENSER)
    {
        Dispenser dispenserBlock = (Dispenser)((BlockState)machineLocation.getBlock().getState());
        Inventory dispenserInventory = dispenserBlock.getInventory();

        HashMap<Integer,? extends ItemStack> upgradeMaterials = dispenserInventory.all(material);

        int totalMaterial = 0;
        for(Entry<Integer,? extends ItemStack> entry : upgradeMaterials.entrySet())
        {
            totalMaterial += entry.getValue().getAmount();
        }

        return (totalMaterial >= amount);
    }
    else
    {
        return false;
    }
}
项目:MachineFactory    文件:OreGin.java   
/**
    * Returns how much of a specified material is available in dispenser
 */
public static int getMaterialAvailableAmount(Material material, Location machineLocation)
{
    if (machineLocation.getBlock().getType() == Material.DISPENSER)
    {
        Dispenser dispenserBlock = (Dispenser)((BlockState)machineLocation.getBlock().getState());
        Inventory dispenserInventory = dispenserBlock.getInventory();

        HashMap<Integer,? extends ItemStack> upgradeMaterials = dispenserInventory.all(material);

        int totalMaterial = 0;
        for(Entry<Integer,? extends ItemStack> entry : upgradeMaterials.entrySet())
        {
            totalMaterial += entry.getValue().getAmount();
        }

        return totalMaterial;
    }
    else
    {
        return 0;
    }
}
项目:MachineFactory    文件:MachineObject.java   
/**
 * Initializes the inventory for this machine
 */
public void initializeInventory()
{
    switch(machineType)
    {
    case OREGIN:
        Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
        machineInventory = dispenserBlock.getInventory();
        break;
    case CLOAKER:
        machineInventory = Bukkit.getServer().createInventory(null, 27, "Cloaker Inventory");
        break;
    case SMELTER:
        break;
    }
}
项目:MachineFactory    文件:MachineObject.java   
/**
 * 'cloakerInventory' public accessor
 */
public Inventory getInventory()
{
    switch (machineType)
    {
    case OREGIN:
        Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
        machineInventory = dispenserBlock.getInventory();
        return machineInventory;
    case CLOAKER:
        return machineInventory;
    case SMELTER:
        return machineInventory;
    default:
        return machineInventory;
    }
}
项目:ProjectAres    文件:TNTMatchModule.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void dispenserNukes(BlockTransformEvent event) {
    BlockState oldState = event.getOldState();
    if(oldState instanceof Dispenser &&
       this.properties.dispenserNukeLimit > 0 &&
       this.properties.dispenserNukeMultiplier > 0 &&
       event.getCause() instanceof EntityExplodeEvent) {

        EntityExplodeEvent explodeEvent = (EntityExplodeEvent) event.getCause();
        Dispenser dispenser = (Dispenser) oldState;
        int tntLimit = Math.round(this.properties.dispenserNukeLimit / this.properties.dispenserNukeMultiplier);
        int tntCount = 0;

        for(ItemStack stack : dispenser.getInventory().contents()) {
            if(stack != null && stack.getType() == Material.TNT) {
                int transfer = Math.min(stack.getAmount(), tntLimit - tntCount);
                if(transfer > 0) {
                    stack.setAmount(stack.getAmount() - transfer);
                    tntCount += transfer;
                }
            }
        }

        tntCount = (int) Math.ceil(tntCount * this.properties.dispenserNukeMultiplier);

        for(int i = 0; i < tntCount; i++) {
            TNTPrimed tnt = this.getMatch().getWorld().spawn(BlockUtils.base(dispenser), TNTPrimed.class);

            tnt.setFuseTicks(10 + this.getMatch().getRandom().nextInt(10)); // between 0.5 and 1.0 seconds, same as vanilla TNT chaining

            Random random = this.getMatch().getRandom();
            Vector velocity = new Vector(random.nextGaussian(), random.nextGaussian(), random.nextGaussian()); // uniform random direction
            velocity.normalize().multiply(0.5 + 0.5 * random.nextDouble());
            tnt.setVelocity(velocity);

            callPrimeEvent(tnt, explodeEvent.getEntity(), false);
        }
    }
}
项目:NeverLag    文件:WorldInfo.java   
public WorldInfo(World world) {
    this.worldName = world.getName();
    this.totalOnline = world.getPlayers().size();
    for (Entity entity : world.getEntities()) {
        this.totalEntity++;
        if (entity instanceof Animals) {
            this.totalAnimals++;
        } else if (entity instanceof Monster) {
            this.totalMonsters++;
        } else if (entity instanceof Item) {
            this.totalDropItem++;
        }
    }
    for (Chunk loadedChunk : world.getLoadedChunks()) {
        this.totalChunk++;
        for (BlockState tiles : loadedChunk.getTileEntities()) {
            this.totalTiles++;
            if (tiles instanceof Hopper) {
                this.totalHopper++;
            } else if (tiles instanceof Chest) {
                this.totalChest++;
            } else if (tiles instanceof Dispenser) {
                this.totalDispenser++;
            } else if (tiles instanceof Dropper) {
                this.totalDropper++;
            } else if (tiles instanceof BrewingStand) {
                this.totalBrewingStand++;
            }
        }

    }
}
项目:civcraft    文件:WarRegen.java   
public static void destroyThisBlock(Block blk, Town town) {

    WarRegen.saveBlock(blk, town.getName(), false);

    switch (blk.getType()) {
    case TRAPPED_CHEST:
        ((Chest)blk.getState()).getBlockInventory().clear();
        break;
    case CHEST:
        ((Chest)blk.getState()).getBlockInventory().clear();
        break;
    case DISPENSER:
        ((Dispenser)blk.getState()).getInventory().clear();
        break;
    case BURNING_FURNACE:
    case FURNACE:
        ((Furnace)blk.getState()).getInventory().clear();
        break;
    case DROPPER:
        ((Dropper)blk.getState()).getInventory().clear();
        break;
    case HOPPER:
        ((Hopper)blk.getState()).getInventory().clear();
        break;
    default:
        break;
    }

    ItemManager.setTypeId(blk, CivData.AIR);
    ItemManager.setData(blk, 0x0, true);

}
项目:SyncChest    文件:SyncManager.java   
public Inventory getInventory(Location loc) {

if (loc.getBlock().getState() instanceof MainChest) {
    return ((MainChest) loc.getBlock().getState()).getInventory();
}

if (loc.getBlock().getState() instanceof RelatedChest) {
    return ((RelatedChest) loc.getBlock().getState()).getInventory();
}

if (loc.getBlock().getState() instanceof Chest) {
    return ((Chest) loc.getBlock().getState()).getInventory();
}

if (loc.getBlock().getState() instanceof DoubleChest) {
    return ((DoubleChest) loc.getBlock().getState()).getInventory();
}

if (loc.getBlock().getState() instanceof BrewingStand) {
    return ((BrewingStand) loc.getBlock().getState()).getInventory();
}

if (loc.getBlock().getState() instanceof Dispenser) {
    return ((Dispenser) loc.getBlock().getState()).getInventory();
}

if (loc.getBlock().getState() instanceof Dropper) {
    return ((Dropper) loc.getBlock().getState()).getInventory();
}
return null;
   }
项目:TatsuCraftMod    文件:Command_dispfill.java   
private static void setDispenserContents(Block targetBlock, ItemStack[] items)
{
    Dispenser dispenser = (Dispenser) targetBlock.getState();
    Inventory disp_inv = dispenser.getInventory();
    disp_inv.clear();
    disp_inv.addItem(items);
}
项目:CardinalPGM    文件:Tnt.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityExplode(EntityExplodeEvent event) {
    if (GameHandler.getGameHandler().getMatch().isRunning() && event.getEntity() instanceof TNTPrimed) {
        if (!blockDamage) {
            event.blockList().clear();
        } else if (yield != 0.3){
            event.setYield((float)yield);
        }
        UUID player = TntTracker.getWhoPlaced(event.getEntity());
        for (Block block : event.blockList()) {
            if (block.getState() instanceof Dispenser) {
                Inventory inventory = ((Dispenser) block.getState()).getInventory();
                Location location = block.getLocation();
                double tntCount = 0;
                for (ItemStack itemstack : inventory.getContents()) {
                    if (itemstack != null && itemstack.getType() == Material.TNT) tntCount += itemstack.getAmount() * multiplier;
                    if (tntCount >= limit) {
                        tntCount = limit;
                        break;
                    }
                }
                inventory.remove(Material.TNT);
                if (tntCount > 0) {
                    Random random = new Random();
                    for (double i = tntCount; i > 0; i--) {
                        TNTPrimed tnt = event.getWorld().spawn(location, TNTPrimed.class);
                        Vector velocity = new Vector((1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75, (1.5 * random.nextDouble()) - 0.75);
                        tnt.setVelocity(velocity);
                        tnt.setFuseTicks(random.nextInt(10) + 10);
                        if (player != null) {
                            tnt.setMetadata("source", new FixedMetadataValue(Cardinal.getInstance(), player));
                        }
                    }
                }
            }
        }
    }
}
项目:MondoChest    文件:BankSet.java   
public boolean add(BlockState block, boolean allow_restack) {
    if (MondoConstants.CHEST_MATERIALS.match(block)) {
        return addChest((Chest) block, allow_restack);
    } else if (MondoConstants.DISPENSER_MATERIALS.match(block)) {
        return addDispenser((Dispenser) block, allow_restack);
    } else {
        return false;
    }
}
项目:MachineFactory    文件:OreGinListener.java   
/**
 * Checks to see if an OreGin (dispenser or light) is being destroyed (block broken)
 */
@EventHandler
public void oreGinBroken(BlockBreakEvent event)
{
    Block destroyed = event.getBlock();

    if ((destroyed.getState() instanceof Dispenser) || destroyed.getType().equals(MachineFactoryPlugin.LIGHT_ON)
            || destroyed.getType().equals(MachineFactoryPlugin.LIGHT_OFF))
    {
        if (oreGinMan.machineExistsAt(destroyed.getLocation()) || oreGinMan.oreGinLightExistsAt(destroyed.getLocation()))
        {
            OreGin oreGin = (OreGin) oreGinMan.getMachine(destroyed.getLocation());
            if (oreGinMan.oreGinLightExistsAt(destroyed.getLocation()))
                oreGin = (OreGin) oreGinMan.getMachine(destroyed.getRelative(BlockFace.DOWN).getLocation());

            event.setCancelled(true);

            if ( (MachineFactoryPlugin.CITADEL_ENABLED && !isReinforced(oreGin.getLocation().getBlock()) 
                    && !isReinforced(oreGin.getLocation().getBlock().getRelative(BlockFace.UP)))
                || !MachineFactoryPlugin.CITADEL_ENABLED)
            {
                ItemStack dropItem = new ItemStack(Material.DISPENSER, 1);
                oreGin.destroy(dropItem);
                oreGinMan.removeMachine(oreGin);
            }
        }
    }
}
项目:MachineFactory    文件:OreGin.java   
/**
 * Adds a specific material to a given dispenser and returns left overs
 */
public static HashMap<Integer,ItemStack> addMaterial(int amount, Material material, Location machineLocation)
{
    if (machineLocation.getBlock().getType() == Material.DISPENSER)
    {
        Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
        Inventory dispenserInventory = dispenserBlock.getInventory();

        HashMap<Integer,ItemStack> leftOvers = dispenserInventory.addItem(new ItemStack(material, amount));
        return leftOvers;
    }

    return null;
}
项目:ExilePearl    文件:ExileListenerTest.java   
@Test
public void testOnInventoryMoveTnt() {
    when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
    ItemStack item = new ItemStack(Material.TNT, 1);


    Inventory top = mock(Inventory.class);
    when(top.getHolder()).thenReturn(mock(Dropper.class));
    when(top.getSize()).thenReturn(9);

    Inventory bottom = mock(Inventory.class);
    when(bottom.getHolder()).thenReturn(mock(Player.class));
    when(bottom.getSize()).thenReturn(45);

    InventoryView view = mock(InventoryView.class);
    when(view.getPlayer()).thenReturn(player);
    when(view.getTopInventory()).thenReturn(top);
    when(view.getBottomInventory()).thenReturn(bottom);
    when(view.getCursor()).thenReturn(item);
    when(view.getItem(eq(5))).thenReturn(item);
    when(view.getItem(eq(40))).thenReturn(item);

    InventoryClickEvent e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
    when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(true);
    dut.onInventoryClick(e);
    assertFalse(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
    when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(false);
    dut.onInventoryClick(e);
    assertFalse(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
    when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(true);
    when(pearlApi.isPlayerExiled(uid)).thenReturn(true);
    dut.onInventoryClick(e);
    assertFalse(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
    when(config.canPerform(ExileRule.PLACE_TNT)).thenReturn(false);
    dut.onInventoryClick(e);
    assertTrue(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_SOME);
    when(top.getHolder()).thenReturn(mock(Chest.class));
    dut.onInventoryClick(e);
    assertFalse(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_ALL);
    when(top.getHolder()).thenReturn(mock(Hopper.class));
    dut.onInventoryClick(e);
    assertTrue(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.LEFT, InventoryAction.PLACE_ONE);
    when(top.getHolder()).thenReturn(mock(Dispenser.class));
    dut.onInventoryClick(e);
    assertTrue(e.isCancelled());

    e = new InventoryClickEvent(view, null, 5, ClickType.SHIFT_LEFT, InventoryAction.MOVE_TO_OTHER_INVENTORY);
    dut.onInventoryClick(e);
    assertFalse(e.isCancelled());

    e = new InventoryClickEvent(view, null, 40, ClickType.LEFT, InventoryAction.PLACE_SOME);
    dut.onInventoryClick(e);
    assertFalse(e.isCancelled());

    e = new InventoryClickEvent(view, null, 40, ClickType.SHIFT_LEFT, InventoryAction.MOVE_TO_OTHER_INVENTORY);
    when(view.getType()).thenReturn(InventoryType.DISPENSER);
    assertEquals(e.getCurrentItem(), item);
    dut.onInventoryClick(e);
    assertTrue(e.isCancelled());

}
项目:DispenserFill    文件:FillDispensersCommand.java   
@Override
public void run(CommandSender commandSender, String label, String[] args) {
    int radius = DispenserFill.getInstance().getConfig().getInt("defaultRange", 10);

    if (args.length >= 1) {
        if (commandSender.hasPermission("dispenserfill.custom")) {
            if (isAllowedNumber(args[0])) {
                radius = Integer.valueOf(args[0]);
            } else {
                Messages.sendMessage(commandSender, DispenserFill.getInstance().getMessages().getMessage("invalidNumber"));
                return;
            }
        } else {
            Messages.sendMessage(commandSender, DispenserFill.getInstance().getMessages().getMessage("noPermission"));
            return;
        }
    }

    if (radius > DispenserFill.getInstance().getConfig().getInt("maximumRange")) {
        if (!commandSender.hasPermission("dispenserfill.bypass")) {
            Messages.sendMessage(commandSender, DispenserFill.getInstance().getMessages().getMessage("maximumRange"));
            return;
        }
    }

    Player player = (Player) commandSender;

    if (player.getItemInHand() == null ||
            player.getItemInHand().getType() == Material.AIR) {
        Messages.sendMessage(player, DispenserFill.getInstance().getMessages().getMessage("noItemInHand"));
        return;
    }

    List<Location> dispensers = getDispenserLocationFromRange(radius, ((Player) commandSender).getLocation());

    if (dispensers.isEmpty()) {
        Messages.sendMessage(commandSender, DispenserFill.getInstance().getMessages().getMessage("noDispensersFound"));
        return;
    }

    int filled = 0;

    loop:
    for (int x = player.getItemInHand().getAmount(); x > 0; ) {
        for (Location location : dispensers) {
            if (location.getBlock().getState() instanceof Dispenser) {
                Dispenser dispenser = (Dispenser) location.getBlock().getState();

                if (dispenser.getInventory().addItem(new ItemStack(player.getItemInHand().getType(), 1)).isEmpty()) {
                    x--;
                    dispenser.update(true, true);
                    player.getItemInHand().setAmount(x);

                    if (x == 0) {
                        player.getItemInHand().setType(Material.AIR);
                        player.setItemInHand(null);
                        player.updateInventory();
                    }
                } else {
                    filled++;

                    if (filled == dispensers.size()) {
                        break loop;
                    }
                }
            }
        }
    }

    Messages.sendMessage(player, DispenserFill.getInstance().getMessages().getMessage("dispensersFilled").replace("{range}", String.valueOf(radius)).replace("{amount}", String.valueOf(dispensers.size())));
}
项目:civcraft    文件:WarRegen.java   
private static String blockToString(Block blk, boolean save_as_air) {
    if (save_as_air) { 
        return blockAsAir(blk);
    }
    else {
        String str = blockBasicString(blk);

        Inventory inv = null;
        switch (blk.getType()) {
        case TRAPPED_CHEST:
        case CHEST:
            inv = ((Chest)blk.getState()).getBlockInventory();
            str += blockInventoryString(inv);
            break;
        case DISPENSER:
            inv = ((Dispenser)blk.getState()).getInventory();
            str += blockInventoryString(inv);
            break;
        case BURNING_FURNACE:
        case FURNACE:
            inv = ((Furnace)blk.getState()).getInventory();
            str += blockInventoryString(inv);
            break;
        case DROPPER:
            inv = ((Dropper)blk.getState()).getInventory();
            str += blockInventoryString(inv);
            break;
        case HOPPER:
            inv = ((Hopper)blk.getState()).getInventory();
            str += blockInventoryString(inv);
            break;
        case SIGN:
        case SIGN_POST:
        case WALL_SIGN:
            Sign sign = (Sign)blk.getState();
            str += blockSignString(sign);
            break;
        default:
            break;
        }

        return str;
    }
}
项目:civcraft    文件:WarRegen.java   
private static void restoreBlockFromString(String line) {
    String[] split = line.split(":");

    int type = Integer.valueOf(split[0]);
    byte data = Byte.valueOf(split[1]);
    int x = Integer.valueOf(split[2]);
    int y = Integer.valueOf(split[3]);
    int z = Integer.valueOf(split[4]);
    String world = split[5];

    Block block = BukkitObjects.getWorld(world).getBlockAt(x,y,z);

    ItemManager.setTypeId(block, type);
    ItemManager.setData(block, data, false);

    // End of basic block info, try to get more now.
    Inventory inv = null;
    switch (block.getType()) {
    case TRAPPED_CHEST:
        inv = ((Chest)block.getState()).getBlockInventory();
        InventorySerializer.StringToInventory(inv, split[6]);
        break;
    case CHEST:
        inv = ((Chest)block.getState()).getBlockInventory();
        InventorySerializer.StringToInventory(inv, split[6]);
        break;
    case DISPENSER:         
        inv = ((Dispenser)block.getState()).getInventory();
        InventorySerializer.StringToInventory(inv, split[6]);
        break;
    case BURNING_FURNACE:
    case FURNACE:
        inv = ((Furnace)block.getState()).getInventory();
        InventorySerializer.StringToInventory(inv, split[6]);
        break;
    case DROPPER:
        inv = ((Dropper)block.getState()).getInventory();
        InventorySerializer.StringToInventory(inv, split[6]);
        break;
    case HOPPER:
        inv = ((Hopper)block.getState()).getInventory();
        InventorySerializer.StringToInventory(inv, split[6]);
        break;
    case SIGN:
    case SIGN_POST:
    case WALL_SIGN:
        Sign sign = (Sign)block.getState();
        String[] messages = split[6].split(",");
        for (int i = 0; i < 4; i++) {
            if (messages[i] != null) {
                sign.setLine(i, messages[i]);
            }
        }
        sign.update();
        break;
    default:
        break;
    }


}
项目:StarQuestCode    文件:MissileListener.java   
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {

    if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
        return;

    if (e.getClickedBlock().getState() instanceof Sign) {

        Sign s = (Sign) e.getClickedBlock().getState();
        if (s.getLine(0).equalsIgnoreCase("[hsmissile]")) {
            if (MissileDetection.detectLauncher(s.getBlock())) {
                s.setLine(0, "");
                s.setLine(1, ChatColor.LIGHT_PURPLE + "[" + ChatColor.GOLD + "Missile" + ChatColor.LIGHT_PURPLE + "]");
                s.setLine(2, ChatColor.LIGHT_PURPLE + "[" + ChatColor.RED + "Heat Seeking" + ChatColor.LIGHT_PURPLE + "]");
                s.setLine(3, "");
                s.update();
                return;
            }
        }


        if (s.getLine(1).equals(ChatColor.LIGHT_PURPLE + "[" + ChatColor.GOLD + "Missile" + ChatColor.LIGHT_PURPLE + "]")
                && s.getLine(2).equals(ChatColor.LIGHT_PURPLE + "[" + ChatColor.RED + "Heat Seeking" + ChatColor.LIGHT_PURPLE + "]")) {

            Block ammoDispenserBlock = MissileDetection.getAmmoDispenser(s.getBlock());
            Dispenser ammoDispenser = (Dispenser) ammoDispenserBlock.getState();
            Inventory dispenserInv = ammoDispenser.getInventory();

            //Checks if the dispenser does not have missile ammo, if it does not, then it returns.
            if (!dispenserInv.containsAtLeast(Missile.standardMissileAmmo(), 1) && !dispenserInv.containsAtLeast(Missile.EMPMissileAmmo(), 1)) return;

            if (Missile.missileCoolDownList.contains(e.getPlayer())) {
                e.getPlayer().sendMessage(ChatColor.RED + "You are still on cooldown...");
                return;
            }

            // Fires the missile
            if (dispenserInv.containsAtLeast(Missile.standardMissileAmmo(), 1)) {
                if (MissileMovement.activateMissile(ammoDispenserBlock, s, e.getPlayer(), "standard")) {
                    dispenserInv.removeItem(Missile.standardMissileAmmo());
                    // Removes one ammo from the dispenser
                }
                return;
            }
            if (dispenserInv.containsAtLeast(Missile.EMPMissileAmmo(), 1)) {
                if (MissileMovement.activateMissile(ammoDispenserBlock, s, e.getPlayer(), "emp")) {
                    dispenserInv.removeItem(Missile.EMPMissileAmmo());
                    // Removes one ammo from the dispenser
                }
                return;
            }

        }
    }

}
项目:CardinalPGM    文件:ObserverModule.java   
@EventHandler
public void onInteraction(PlayerInteractEvent event) {
    if (testObserver(event.getPlayer())) {
        event.setCancelled(true);
        if ((event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (event.getPlayer().getInventory().getItemInMainHand() != null && event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WRITTEN_BOOK))){
            event.setUseInteractedBlock(Event.Result.DENY);
            event.setUseItemInHand(Event.Result.ALLOW);
        }
        if (event.getClickedBlock() != null && !event.getPlayer().isSneaking() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if (event.getClickedBlock().getType().equals(Material.CHEST) || event.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)) {
                Inventory chest = Bukkit.createInventory(null, ((Chest) event.getClickedBlock().getState()).getInventory().getSize());
                for (int i = 0; i < ((Chest) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    chest.setItem(i, ((Chest) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(chest);
            }
            if (event.getClickedBlock().getType().equals(Material.FURNACE) || event.getClickedBlock().getType().equals(Material.BURNING_FURNACE)) {
                Inventory furnace = Bukkit.createInventory(null, InventoryType.FURNACE);
                for (int i = 0; i < ((Furnace) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    furnace.setItem(i, ((Furnace) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(furnace);
            }
            if (event.getClickedBlock().getType().equals(Material.DISPENSER)) {
                Inventory dispenser = Bukkit.createInventory(null, InventoryType.DISPENSER);
                for (int i = 0; i < ((Dispenser) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    dispenser.setItem(i, ((Dispenser) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(dispenser);
            }
            if (event.getClickedBlock().getType().equals(Material.DROPPER)) {
                Inventory dropper = Bukkit.createInventory(null, InventoryType.DROPPER);
                for (int i = 0; i < ((Dropper) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    dropper.setItem(i, ((Dropper) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(dropper);
            }
            if (event.getClickedBlock().getType().equals(Material.HOPPER)) {
                Inventory hopper = Bukkit.createInventory(null, InventoryType.HOPPER);
                for (int i = 0; i < ((Hopper) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    hopper.setItem(i, ((Hopper) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(hopper);
            }
            if (event.getClickedBlock().getType().equals(Material.BREWING_STAND)) {
                Inventory brewingStand = Bukkit.createInventory(null, InventoryType.BREWING);
                for (int i = 0; i < ((BrewingStand) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    brewingStand.setItem(i, ((BrewingStand) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(brewingStand);
            }
            if (event.getClickedBlock().getType().equals(Material.BEACON)) {
                Inventory beacon = Bukkit.createInventory(null, InventoryType.BEACON);
                for (int i = 0; i < ((Beacon) event.getClickedBlock().getState()).getInventory().getSize(); i++) {
                    beacon.setItem(i, ((Beacon) event.getClickedBlock().getState()).getInventory().getItem(i));
                }
                event.getPlayer().openInventory(beacon);
            }
        }
    }
}
项目:MondoChest    文件:BankSet.java   
public boolean addDispenser(Dispenser block, boolean allow_restack) {
    // TODO Auto-generated method stub
    return false;
}
项目:MachineFactory    文件:OreGin.java   
/**
 * Attempts to remove a specific material of given amount from dispenser
 */
public static boolean removeMaterial(int amount, Material material, Location machineLocation)
{
    if (machineLocation.getBlock().getType() == Material.DISPENSER)
    {
        Dispenser dispenserBlock = (Dispenser)machineLocation.getBlock().getState();
        Inventory dispenserInventory = dispenserBlock.getInventory();

        HashMap<Integer,? extends ItemStack> upgradeMaterials = dispenserInventory.all(material);

        int materialsToRemove = amount;
        for(Entry<Integer,? extends ItemStack> entry : upgradeMaterials.entrySet())
        {
            if (materialsToRemove <= 0)
                break;

            if(entry.getValue().getAmount() == materialsToRemove)
            {
                dispenserInventory.setItem(entry.getKey(), new ItemStack(Material.AIR, 0));
                materialsToRemove = 0;
            }
            else if(entry.getValue().getAmount() > materialsToRemove)
            {
                dispenserInventory.setItem(entry.getKey(), new ItemStack(material, (entry.getValue().getAmount() - materialsToRemove)));
                materialsToRemove = 0;
            }
            else
            {
                int inStack = entry.getValue().getAmount();
                dispenserInventory.setItem(entry.getKey(), new ItemStack(Material.AIR, 0));
                materialsToRemove -= inStack;
            }
        }

        return materialsToRemove == 0;
    }
    else
    {
        return false;
    }
}
项目:Slimefun4-Chinese-Version    文件:AutonomousToolHandler.java   
public abstract boolean onBlockDispense(BlockDispenseEvent blockdispenseevent, Block block, Dispenser dispenser, Block block1, Block block2, int i);
项目:Slimefun4-Chinese-Version    文件:AutonomousMachineHandler.java   
public abstract boolean onBlockDispense(BlockDispenseEvent blockdispenseevent, Block block, Dispenser dispenser, Block block1, Block block2, SlimefunItem slimefunitem);
项目:Slimefun4    文件:AutonomousToolHandler.java   
public abstract boolean onBlockDispense(BlockDispenseEvent e, Block dispenser, Dispenser d, Block block, Block chest, int i);
项目:Slimefun4    文件:AutonomousMachineHandler.java   
public abstract boolean onBlockDispense(BlockDispenseEvent e, Block dispenser, Dispenser d, Block block, Block chest, SlimefunItem machine);