Java 类org.bukkit.event.block.BlockBreakEvent 实例源码

项目:bskyblock    文件:NetherEvents.java   
/**
 * Prevents blocks from being broken
 *
 * @param e
 */
@EventHandler(priority = EventPriority.LOW)
public void onBlockBreak(final BlockBreakEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    // plugin.getLogger().info("Block break");
    if ((e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName + "_nether") && !Settings.netherIslands)
            || e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName + "_the_end")) {
        if (VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        if (DEBUG)
            plugin.getLogger().info("Block break in island nether");
        if (!awayFromSpawn(e.getPlayer()) && !e.getPlayer().isOp()) {
            Util.sendMessage(e.getPlayer(), plugin.getLocale(e.getPlayer().getUniqueId()).get("nether.spawnisprotected"));
            e.setCancelled(true);
        }
    }

}
项目:HCFCore    文件:DeathSignListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event) {
    Block block = event.getBlock();
    if (isDeathSign(block)) {
        BlockState state = block.getState();
        Sign sign = (Sign) state;
        ItemStack stack = new ItemStack(Material.SIGN, 1);
        ItemMeta meta = stack.getItemMeta();
        meta.setDisplayName(DEATH_SIGN_ITEM_NAME);
        meta.setLore(Arrays.asList(sign.getLines()));
        stack.setItemMeta(meta);

        Player player = event.getPlayer();
        World world = player.getWorld();
        if (player.getGameMode() != GameMode.CREATIVE && world.isGameRule("doTileDrops")) {
            world.dropItemNaturally(block.getLocation(), stack);
        }

        // Manually handle the dropping
        event.setCancelled(true);
        block.setType(Material.AIR);
        state.update();
    }
}
项目:CropControl    文件:CropControlEventHandler.java   
/**
 * So far specifically handles these cases:
 * 
 * 1) Block broken is tracked
 * 2) Block breaks by not-players
 * 3) Block breaks by players
 * 4) Indirect block breaks -- destroying block supporting a crop or collapsible tree, or under mushrooms
 * 5) Indirect block break of cocoa bearing logs
 * 6) Block broken had mushroom on top and cocoa on the sides
 * 
 * @param e The event
 */
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
    Block block = e.getBlock();
    Player player = e.getPlayer();
    BreakType type = player != null ? BreakType.PLAYER : BreakType.NATURAL;
    UUID uuid = player != null ? player.getUniqueId() : null;
    if (maybeSideTracked(block)) {
        trySideBreak(block, type, uuid);
    }
    if (maybeBelowTracked(block)) {
        block = block.getRelative(BlockFace.UP);
    }
    Location loc = block.getLocation();
    if (!pendingChecks.contains(loc)) {
        pendingChecks.add(loc);
        handleBreak(block, type, uuid, null);
    }
}
项目:Warzone    文件:BuildFilterType.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    for (Region region : regions) {
        if (region.contains(event.getBlock().getLocation())) {
            for (MatchTeam matchTeam : teams) {
                if (matchTeam.containsPlayer(event.getPlayer())) {
                    FilterResult filterResult = evaluator.evaluate(event.getPlayer());
                    if (filterResult == FilterResult.DENY) {
                        event.setCancelled(true);
                        event.getPlayer().sendMessage(message);
                    } else if (filterResult == FilterResult.ALLOW) {
                        event.setCancelled(false);
                    }
                }
            }
        }
    }
}
项目:Slimefun4-Chinese-Version    文件:TalismanListener.java   
/**
 *
 * @param e BlockBreakEvent
 * @since 4.2.0
 */
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
    List<ItemStack> drops = new ArrayList<ItemStack>();
    ItemStack item = e.getPlayer().getInventory().getItemInMainHand();
    int fortune = 1;

    if (item != null) {
        if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) {
            fortune = SlimefunStartup.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1;
            if (fortune <= 0) fortune = 1;
            fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + SlimefunStartup.randomize(5) : 1) * (fortune + 1);
        }

        if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && e.getBlock().getType().toString().endsWith("_ORE")) {
            if (Talisman.checkFor(e, SlimefunItem.getByID("MINER_TALISMAN"))) {
                if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops();
                for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
                    if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
                }
            }
        }
    }
}
项目:SuperiorCraft    文件:CustomBlock.java   
public void removeBlock(BlockBreakEvent e) {
        for (Entity en : e.getBlock().getWorld().getEntities()) {
            if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
                en.remove();
                en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);

                ItemStack block = new ItemStack(Material.MONSTER_EGG, 1);

                ItemMeta bmeta = block.getItemMeta();

                bmeta.setDisplayName(name);

                block.setItemMeta(bmeta);

                if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
                    e.getPlayer().getInventory().addItem(block);
                } else {
                    e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), block);
                }
            }
        }
    //}
}
项目:SuperiorCraft    文件:CustomTexturedBlock.java   
@Override
public void removeBlock(BlockBreakEvent e) {
        if (e.getPlayer() == null) {return;}
        for (Entity en : e.getPlayer().getNearbyEntities(10, 10, 10)) {
            System.out.println("Removal has Begun");
            if (en.getCustomName() != null && en.getCustomName().equals(getName()) && /*en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())*/ en.getLocation().distance(e.getBlock().getLocation()) < 2) {
                for (Entity ent : en.getNearbyEntities(0.5, 0.5, 0.5)) {
                    if (ent.getCustomName().equals("CustomBlock")) {
                        ent.remove();
                        break;
                    }
                }
                en.remove();
                //en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
                if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
                    e.getPlayer().getInventory().addItem(getItem());
                } else {
                    e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), getItem());
                }

                return;
            }
        }
}
项目:SurvivalPlus    文件:Chairs.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockBreak(BlockBreakEvent event)
{
    if(event.isCancelled()) return;
    if(Survival.allowedBlocks.contains(event.getBlock().getType()))
    {
        ArmorStand drop = dropSeat(event.getBlock(), (Stairs)event.getBlock().getState().getData());

        for(Entity e : drop.getNearbyEntities(0.5, 0.5, 0.5))
        {
            if(e != null && e instanceof ArmorStand && e.getCustomName() == "Chair")
                e.remove();
        }

        drop.remove();
    }
}
项目:Stats4    文件:BlockBreakStat.java   
@EventHandler
private void onBlockBreak(final BlockBreakEvent event) {
    Material material = event.getBlock().getType();
    byte data = event.getBlock().getData();
    ItemStack mainHandItem = event.getPlayer().getInventory().getItemInMainHand();
    DatabaseQueryWorker.getInstance().submit(() -> {
        try {
            BlockBreakDAO.storeRecord(
                    event.getPlayer().getUniqueId(), event.getPlayer().getType().name(),
                    material, data,
                    event.getBlock().getLocation(), mainHandItem
            );
        } catch (SQLException e) {
            e.printStackTrace();
        }
    });
}
项目:mczone    文件:KitEvents.java   
@EventHandler
public void Woodcutter(BlockBreakEvent event) {
    if (State.PRE)
        return;

    Player p = event.getPlayer();
    if (Kit.getKit(p).getName().equalsIgnoreCase("woodcutter")
            && event.getBlock().getType().equals(Material.LOG)
            && (p.getItemInHand().getType().toString().contains("AXE"))) {
        for (int i = 0; i <= 50; i++) {
            Location loc = event.getBlock().getLocation();
            loc.setY(loc.getY() + i);
            if (loc.getBlock().getType().equals(Material.LOG))
                loc.getBlock().breakNaturally();
            else
                break;
        }
    }
}
项目:HCFCore    文件:GlowstoneListener.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
    Player p = e.getPlayer();
    Faction faction = hcf.getFactionManager().getFactionAt(e.getBlock());
    if(e.getBlock().getType().equals(Material.GLOWSTONE) && e.getBlock().getLocation().getWorld().getName().equalsIgnoreCase("world_nether")) {
        if(faction.getName().equalsIgnoreCase("GlowstoneMountain")) {
            e.setCancelled(true);
            e.getBlock().setType(Material.BEDROCK);
            Bukkit.getScheduler().scheduleSyncDelayedTask(hcf, new Runnable() {
                public void run() {
                    if(e.getBlock().getType().equals(Material.BEDROCK)) {
                        e.getBlock().setType(Material.GLOWSTONE);
                    }
                }
            }, 20L*60L*10L);
            p.getInventory().addItem(new ItemStack(Material.GLOWSTONE));
        }
    }
}
项目:Mega-Walls    文件:BlockBreakListener.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent e)
{
    User user = MWAPI.getUserHandler().findById(e.getPlayer().getUniqueId());

    if (user.getGame() != null)
    {
        if (user.getGame().getSpectators().contains(user) || user.getGame().getState().equals(GameState.LOBBY))
        {
            e.setCancelled(true);
            return;
        }

        // TODO handle other stuff like the castles and walls
    }
}
项目:ArchersBattle    文件:WorldListener.java   
@EventHandler
public void onBreak(BlockBreakEvent e) {
    if (e.isCancelled()) {
        return;
    }
    if (!Utils.isInArena(e.getPlayer())) {
        return;
    }
    if (!Utils.isArenaWorld(e.getBlock().getWorld())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    e.setCancelled(true);
}
项目:SurvivalAPI    文件:PersonalBlocksModule.java   
/**
 * Private block breaking handling
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event)
{
    if (this.blocksOwner.containsKey(event.getBlock().getLocation()) && this.blocksOwner.get(event.getBlock().getLocation()) != event.getPlayer().getUniqueId())
    {
        UUID id = this.blocksOwner.get(event.getBlock().getLocation());

        if (id == null || id.equals(event.getPlayer().getUniqueId()) || (this.game instanceof SurvivalTeamGame && ((SurvivalTeamGame) this.game).getPlayerTeam(id) == ((SurvivalTeamGame) this.game).getPlayerTeam(event.getPlayer().getUniqueId())))
        {
            this.blocksOwner.remove(event.getBlock().getLocation());
        }
        else if (!this.game.isPvPActivated())
        {
            event.getPlayer().sendMessage(ChatColor.RED + "Ce bloc appartient à " + Bukkit.getOfflinePlayer(this.blocksOwner.get(event.getBlock().getLocation())).getName()  + ". Vous ne pouvez pas le casser actuellement !");
            event.setCancelled(true);
        }
    }
}
项目:SurvivalAPI    文件:ParanoidModule.java   
/**
 * Write a message when a player mine a diamond
 *
 * @param event Event
 */
@EventHandler(ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event)
{
    if (event.getBlock().getType() != Material.DIAMOND_ORE)
        return;

    Location location = event.getBlock().getLocation();

    StringBuilder builder = new StringBuilder();
    builder.append(ChatColor.GOLD).append("[").append(ChatColor.YELLOW);
    builder.append("Paranoïa");
    builder.append(ChatColor.GOLD).append("]").append(ChatColor.YELLOW);
    builder.append(" Le joueur ").append(ChatColor.GOLD).append(event.getPlayer().getName()).append(ChatColor.YELLOW);
    builder.append(" a miné un bloc de diamant aux coordonnées ").append(ChatColor.GOLD);
    builder.append(location.getBlockX()).append("; ").append(location.getBlockY()).append("; ").append(location.getBlockZ());
    builder.append(ChatColor.YELLOW).append(" !");

    Bukkit.broadcastMessage(builder.toString());
}
项目:Kineticraft    文件:Xray.java   
@EventHandler(priority = EventPriority.LOW)
public void onBlockBreak(BlockBreakEvent evt) {
    Location at = evt.getBlock().getLocation();
    if (at.getY() > 20 || !at.getWorld().equals(Core.getMainWorld()))
        return;

    // Remember mined blocks.
    BrokenBlock bk = new BrokenBlock(evt.getPlayer(), evt.getBlock());
    blocks.add(bk);
    if ((bk.getType() == Material.DIAMOND_ORE || Utils.randChance(20))
            && (getBlockScore(evt.getPlayer()) >= 20 || getTimeScore(evt.getPlayer()) >= 20))
            blocks.detect(bk);

    // Handle suspicious ascending / descending.
    if (elevation.getDetections(evt.getPlayer()).stream().noneMatch(b -> b.getLocation().getY() == at.getY()))
        elevation.detect(bk);
}
项目:GhostScavengerHunt    文件:GhostSkull.java   
@EventHandler
public void onSkullBreak(BlockBreakEvent event) {
    if(!LocationUtils.center(event.getBlock().getLocation()).equals(LocationUtils.center(this.location))) return;
    if(!event.getPlayer().hasPermission("ghostskull.break")) {
        event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', this.getPlugin().getMessageFile().getString("cannot-break-skull-message")));
        event.setCancelled(true);
    } else {
        HandlerList.unregisterAll(this);
        plugin.getGhostSkulls().remove(this);
        plugin.getDataFile().set(this.uuid.toString(), null);
        try {
            plugin.getDataFile().save(plugin.getF_dataFile());
        } catch (IOException e) {
            e.printStackTrace();
        }
        event.getPlayer().sendMessage(ChatColor.GREEN + "Ghost Skull has been deleted.");
    }
}
项目:MT_Core    文件:SupplyDropListener.java   
@EventHandler
public void onSupplyDropBreak(BlockBreakEvent e) {
    SupplyDropObject sd = core.getSupplyDropManager().getSupplyDropByLocation(e.getBlock().getLocation());

    if (sd == null)
        return;

    sd.setLooted(true);
    core.getSupplyDropManager().removeSupplyDrop(e.getBlock().getLocation());
}
项目:CropControl    文件:CitadelEventHandler.java   
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void handleAcidBreak(AcidBlockEvent e) {
    try {
        Location acided = e.getDestroyedBlockReinforcement().getLocation();

        CropControl.getPlugin().getEventHandler().onBlockBreak(new BlockBreakEvent( acided.getBlock(), e.getPlayer() ) );
    } catch (Exception g) {
        CropControl.getPlugin().warning("Failed to handle Citadel Acid Block Event:", g);
    }
}
项目:VoxelGamesLibv2    文件:NoBlockBreakFeature.java   
@SuppressWarnings({"JavaDoc", "Duplicates"})
@GameEvent
public void onBlockBreak(@Nonnull BlockBreakEvent event) {
    if (blacklist.length != 0) {
        if (Arrays.stream(blacklist).anyMatch(m -> m.equals(event.getBlock().getType()))) {
            event.setCancelled(true);
        }
    } else if (whitelist.length != 0) {
        if (Arrays.stream(whitelist).noneMatch(m -> m.equals(event.getBlock().getType()))) {
            event.setCancelled(true);
        }
    } else {
        event.setCancelled(true);
    }
}
项目:Warzone    文件:WoolChestModule.java   
@EventHandler
public void onBreak(BlockBreakEvent event) {
    if (event.getBlock().getType() == Material.CHEST) {
        if (scannedChests.contains(((Chest) event.getBlock().getState()).getBlockInventory().getHolder())) {
            event.setCancelled(true);
            event.getPlayer().sendMessage(ChatColor.RED + "You cannot break the wool chest!");
        }
    }
}
项目:Warzone    文件:DispenserListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (!this.tracker.isEnabled(event.getBlock().getWorld())) return;

    if (event.getBlock().getType() == Material.DISPENSER) {
        this.tracker.clearPlacer(event.getBlock());
    }
}
项目:Warzone    文件:AnvilListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (!this.tracker.isEnabled(event.getBlock().getWorld())) return;

    if (event.getBlock().getType() == Material.ANVIL) {
        this.tracker.clearPlacer(event.getBlock());
    }
}
项目:HCFCore    文件:BorderListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onBlockBreak(final BlockBreakEvent event) {
    if (!isWithinBorder(event.getBlock().getLocation())) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(ChatColor.RED + "You cannot break blocks past the border.");
    }
}
项目:AntiCheat    文件:OrebfuscatorBlockListener.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
        return;
    }

    BlockUpdate.Update(event.getBlock());
    BlockHitManager.breakBlock(event.getPlayer(), event.getBlock());
}
项目:ZentrelaRPG    文件:EnvironmentManager.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    PlayerDataRPG pd = plugin.getPD(event.getPlayer());
    if (pd == null)
        event.setCancelled(true);
    if (event.getPlayer().getGameMode() != GameMode.CREATIVE)
        event.setCancelled(true);
    if (!canBuild(pd))
        event.setCancelled(true);
}
项目:HCFCore    文件:ExpMultiplierListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event) {
    double amount = event.getExpToDrop();
    Player player = event.getPlayer();
    ItemStack stack = player.getItemInHand();
    if (stack != null && stack.getType() != Material.AIR && amount > 0) {
        int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS);
        if (enchantmentLevel > 0) {
            double multiplier = enchantmentLevel * SettingsYML.EXP_MULTIPLIER_FORTUNE_PER_LEVEL;
            int result = (int) Math.ceil(amount * multiplier);
            event.setExpToDrop(result);
        }
    }
}
项目:EscapeLag    文件:AntiBreakUsingChest.java   
@EventHandler
public void CheckNoBreakChest(BlockBreakEvent e) {
    if (ConfigPatch.protectUsingChest) {
        Player p = e.getPlayer();
        if (e.getBlock().getState() instanceof InventoryHolder) {
            InventoryHolder ih = (InventoryHolder) e.getBlock().getState();
            if (ih.getInventory().getViewers().isEmpty() == false) {
                e.setCancelled(true);
                AzureAPI.log(p, ConfigPatch.AntiBreakUsingChestWarnMessage);
            }
        }
    }
}
项目:Arcadia-Spigot    文件:SpleefGame.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if(this.getAPI().getGameManager().isAlive(event.getPlayer())) {
        if(event.getBlock().getType() == Material.SNOW_BLOCK) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.SNOW_BALL, 2));
            event.setDropItems(false);
        }
    }
}
项目:Arcadia-Spigot    文件:WorldListener.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    ArcadiaAPI api = Arcadia.getPlugin(Arcadia.class).getAPI();
    if(!api.getGameManager().isAlive(event.getPlayer())) event.setCancelled(true);
    if(api.getGameManager().getCurrentGame() != null) {
        MaterialData materialData = new MaterialData(event.getBlock().getType(), event.getBlock().getData());
        if(!api.getGameManager().getCurrentGame().breakableBlocks.contains(materialData)) {
            event.setCancelled(true);
        }
    }
}
项目:HCFCore    文件:FoundDiamondsListener.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBlockBreak(final BlockBreakEvent event) {
    final Player player = event.getPlayer();
    if(player.getGameMode() == GameMode.CREATIVE) {
        return;
    }
    if(player.getItemInHand().getEnchantments().containsKey(Enchantment.SILK_TOUCH)) return;;
    final Block block = event.getBlock();
    final Location blockLocation = block.getLocation();
    if(block.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(blockLocation.toString())) {
        int count = 1;
        for(int x = -5; x < 5; ++x) {
            for(int y = -5; y < 5; ++y) {
                for(int z = -5; z < 5; ++z) {
                    final Block otherBlock = blockLocation.clone().add((double) x, (double) y, (double) z).getBlock();
                    if(!otherBlock.equals(block) && otherBlock.getType() == FoundDiamondsListener.SEARCH_TYPE && this.foundLocations.add(otherBlock.getLocation().toString())) {
                        ++count;
                    }
                }
            }
        }

        String message;
        for(Player on : Bukkit.getOnlinePlayers()) {
            if(plugin.getFactionManager().getPlayerFaction(player.getUniqueId()) != null) {
                 message = plugin.getFactionManager().getPlayerFaction(player.getUniqueId()).getRelation(on).toChatColour() + player.getName() + ChatColor.GRAY + " has found " + ChatColor.AQUA + count + ChatColor.GRAY + " diamond(s).";
                on.sendMessage(message);
            }else{
                message = ChatColor.AQUA + "[" + ChatColor.GRAY + "♠" + ChatColor.AQUA + "]" + ChatColor.GRAY + " " + ChatColor.AQUA + player.getName() + ChatColor.GRAY + " has just spotted " + ChatColor.BLUE + count + ChatColor.GRAY +" diamonds!";
                on.sendMessage(message);
            }
        }
    }
}
项目:AsgardAscension    文件:AbilityListener.java   
private void handleLuckyRepair(BlockBreakEvent event) {
    ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
    if(Utility.getRandom(1, 10000) > 2 || item == null ||!ItemStackGenerator.isRepairable(item)) {
        return;
    }
    item.setDurability((short)0);
}
项目:AddGun    文件:RailGun.java   
/**
 * Prevent using the gun-item to break blocks
 * @param event the break event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void preventBlockBreakWithGun(BlockBreakEvent event) {
    if (event.getPlayer() != null && isGun(event.getPlayer().getInventory().getItemInMainHand())) {
        event.setCancelled(true);
    }
}
项目:prisonPicks    文件:Events.java   
@EventHandler
public void onBlockBreak(BlockBreakEvent event)
{

    Player player = event.getPlayer();
    ItemStack item = player.getInventory().getItemInMainHand();

    if (aoepick)
    {
        //stop our event recurring
        return;
    }

    //Are we using one of our picks
    if (Xpick.isPick(item))
    {
        aoepick = true;
        //this is an Xpick
        Xpick x = new Xpick();
        x.breakBlock(event);
    }else if (Pickoplenty.isPick(item))
    {
        Pickoplenty pop = new Pickoplenty();
        pop.breakBlock(event);
    }else if (XPickoPlenty.isPick(item))
    {
        aoepick = true;
        XPickoPlenty xpop = new XPickoPlenty();
        xpop.breakBlock(event);
    }

    aoepick = false;
}
项目:prisonPicks    文件:Xpickoplentytest.java   
@Test
public void testBreakBlock()
{
    //TODO: update this test to be more comprehensive
    BlockBreakEvent bbe = new BlockBreakEvent(block, player);
    XPickoPlenty xpick = new XPickoPlenty();

    xpick.breakBlock(bbe);
    verify(block, atLeastOnce()).setType(Material.AIR);
}
项目:prisonPicks    文件:XpickTest.java   
@Test
public void testBreakBlock()
{
    BlockBreakEvent bbe = new BlockBreakEvent(block, player);
    Xpick xpick = new Xpick();

    xpick.breakBlock(bbe);
    verify(block, atLeastOnce()).setType(Material.AIR);
}
项目:prisonPicks    文件:PickoplentyTest.java   
@Test
public void testBreakBlock()
{
    BlockBreakEvent bbe = new BlockBreakEvent(block, player);
    Pickoplenty pickoplenty = new Pickoplenty();

    pickoplenty.breakBlock(bbe);
    verify(block, atLeastOnce()).setType(Material.AIR);
}
项目:SuperiorCraft    文件:RealBreakBlock.java   
@SuppressWarnings("deprecation")
@EventHandler
public void onBlockbreak(BlockBreakEvent e) {
    if (e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) return;

    for (BlockBreakRule r : BlockBreakRule.rules) {
        if (r.getMaterial().equals(e.getBlock().getType()) && (e.getPlayer().getEquipment().getItemInMainHand() == null || !r.getLevel().canBreakWith(e.getPlayer().getEquipment().getItemInMainHand()))) {
            e.setCancelled(true);
            return;
        }
    }

    for (CustomItem it : CustomItem.items) {
        if (it instanceof CustomTool) {
            if (e.getPlayer().getItemInHand() != null && e.getPlayer().getItemInHand().getType() != null && e.getPlayer().getItemInHand().hasItemMeta() && e.getPlayer().getItemInHand().getItemMeta().hasDisplayName() && it.getItem().getItemMeta().getDisplayName().equals(e.getPlayer().getItemInHand().getItemMeta().getDisplayName())) {
                if (!e.getPlayer().getItemInHand().getItemMeta().isUnbreakable()) {
                    //e.getPlayer().sendMessage(e.getPlayer().getItemInHand().getType().name());
                    int maxDamage = e.getPlayer().getItemInHand().getType().getMaxDurability(); // btw, this value is 0 for items that don't have durability bar
                    int damage = e.getPlayer().getItemInHand().getDurability() + ((CustomTool) it).getDamagePerUse();

                    if(damage > maxDamage) // calculated damage exceeds max damage
                    {
                        e.getPlayer().getInventory().remove(e.getPlayer().getItemInHand());
                    }
                    else
                    {
                        e.getPlayer().getItemInHand().setDurability((short) damage);
                    }
                }
            }
        }
    }
}
项目:SuperiorCraft    文件:Flag.java   
@Override
public void removeBlock(BlockBreakEvent e) {
        for (Entity en : e.getPlayer().getWorld().getEntities()) {
            if (en.getCustomName() != null && en.getCustomName().equals("flag") && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
                en.remove();
                e.getPlayer().sendMessage(ChatColor.GRAY + "Flag removed");
            }
    }
}
项目:SuperiorCraft    文件:Elevator.java   
@Override
public CustomBlockInstance getInstance(ArmorStand s) {
    ElevatorInstance ei = new ElevatorInstance(s, getTextureEntity(s), getTexture());
    Bukkit.getScheduler().scheduleSyncRepeatingTask(SuperiorCraft.plugin, new Runnable() {
        @Override
        public void run() {
            if (s.getCustomName() != null && s.getCustomName().equals(getName()) && s.getLocation().add(-0.5, 0, -0.5).getBlock().getType() == Material.AIR) {
                removeBlock(new BlockBreakEvent(s.getLocation().add(-0.5, 0, -0.5).getBlock(), null));
                //System.out.println("A");
            }
        }
    }, 0, 0);
    SuperiorCraft.plugin.getServer().getPluginManager().registerEvents(ei, SuperiorCraft.plugin);
    return ei;
}