Search in sources :

Example 1 with org.bukkit.craftbukkit.v1_18_R2.block

use of org.bukkit.craftbukkit.v1_18_R2.block in project Denizen-For-Bukkit by DenizenScript.

the class BlockHelperImpl method ringBell.

@Override
public void ringBell(Bell block) {
    org.bukkit.block.data.type.Bell bellData = (org.bukkit.block.data.type.Bell) block.getBlockData();
    Direction face = Direction.byName(bellData.getFacing().name());
    Direction dir = Direction.NORTH;
    switch(bellData.getAttachment()) {
        case DOUBLE_WALL:
        case SINGLE_WALL:
            switch(face) {
                case NORTH:
                case SOUTH:
                    dir = Direction.EAST;
                    break;
            }
            break;
        case FLOOR:
            dir = face;
            break;
    }
    CraftBlock craftBlock = (CraftBlock) block.getBlock();
    ((BellBlock) Blocks.BELL).attemptToRing(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition(), dir);
}
Also used : BellBlock(net.minecraft.world.level.block.BellBlock) org.bukkit.block(org.bukkit.block) org.bukkit.craftbukkit.v1_17_R1.block(org.bukkit.craftbukkit.v1_17_R1.block) Direction(net.minecraft.core.Direction)

Example 2 with org.bukkit.craftbukkit.v1_18_R2.block

use of org.bukkit.craftbukkit.v1_18_R2.block in project java-docs-samples by GoogleCloudPlatform.

the class Detect method detectDocumentText.

// [START vision_detect_document]
/**
 * Performs document text detection on a local image file.
 *
 * @param filePath The path to the local file to detect document text on.
 * @param out A {@link PrintStream} to write the results to.
 * @throws Exception on errors while closing the client.
 * @throws IOException on Input/Output errors.
 */
public static void detectDocumentText(String filePath, PrintStream out) throws Exception, IOException {
    List<AnnotateImageRequest> requests = new ArrayList<>();
    ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
    Image img = Image.newBuilder().setContent(imgBytes).build();
    Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build();
    AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
    requests.add(request);
    try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
        BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
        List<AnnotateImageResponse> responses = response.getResponsesList();
        client.close();
        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                out.printf("Error: %s\n", res.getError().getMessage());
                return;
            }
            // For full list of available annotations, see http://g.co/cloud/vision/docs
            TextAnnotation annotation = res.getFullTextAnnotation();
            for (Page page : annotation.getPagesList()) {
                String pageText = "";
                for (Block block : page.getBlocksList()) {
                    String blockText = "";
                    for (Paragraph para : block.getParagraphsList()) {
                        String paraText = "";
                        for (Word word : para.getWordsList()) {
                            String wordText = "";
                            for (Symbol symbol : word.getSymbolsList()) {
                                wordText = wordText + symbol.getText();
                                out.format("Symbol text: %s (confidence: %f)\n", symbol.getText(), symbol.getConfidence());
                            }
                            out.format("Word text: %s (confidence: %f)\n\n", wordText, word.getConfidence());
                            paraText = String.format("%s %s", paraText, wordText);
                        }
                        // Output Example using Paragraph:
                        out.println("\nParagraph: \n" + paraText);
                        out.format("Paragraph Confidence: %f\n", para.getConfidence());
                        blockText = blockText + paraText;
                    }
                    pageText = pageText + blockText;
                }
            }
            out.println("\nComplete annotation:");
            out.println(annotation.getText());
        }
    }
}
Also used : Word(com.google.cloud.vision.v1.Word) ByteString(com.google.protobuf.ByteString) Symbol(com.google.cloud.vision.v1.Symbol) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) ArrayList(java.util.ArrayList) WebPage(com.google.cloud.vision.v1.WebDetection.WebPage) Page(com.google.cloud.vision.v1.Page) ByteString(com.google.protobuf.ByteString) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) FileInputStream(java.io.FileInputStream) Paragraph(com.google.cloud.vision.v1.Paragraph) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) Block(com.google.cloud.vision.v1.Block) TextAnnotation(com.google.cloud.vision.v1.TextAnnotation) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Example 3 with org.bukkit.craftbukkit.v1_18_R2.block

use of org.bukkit.craftbukkit.v1_18_R2.block in project java-docs-samples by GoogleCloudPlatform.

the class Detect method detectDocumentTextGcs.

// [END vision_detect_document]
// [START vision_detect_document_uri]
/**
 * Performs document text detection on a remote image on Google Cloud Storage.
 *
 * @param gcsPath The path to the remote file on Google Cloud Storage to detect document text on.
 * @param out A {@link PrintStream} to write the results to.
 * @throws Exception on errors while closing the client.
 * @throws IOException on Input/Output errors.
 */
public static void detectDocumentTextGcs(String gcsPath, PrintStream out) throws Exception, IOException {
    List<AnnotateImageRequest> requests = new ArrayList<>();
    ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
    Image img = Image.newBuilder().setSource(imgSource).build();
    Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build();
    AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
    requests.add(request);
    try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
        BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
        List<AnnotateImageResponse> responses = response.getResponsesList();
        client.close();
        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                out.printf("Error: %s\n", res.getError().getMessage());
                return;
            }
            // For full list of available annotations, see http://g.co/cloud/vision/docs
            TextAnnotation annotation = res.getFullTextAnnotation();
            for (Page page : annotation.getPagesList()) {
                String pageText = "";
                for (Block block : page.getBlocksList()) {
                    String blockText = "";
                    for (Paragraph para : block.getParagraphsList()) {
                        String paraText = "";
                        for (Word word : para.getWordsList()) {
                            String wordText = "";
                            for (Symbol symbol : word.getSymbolsList()) {
                                wordText = wordText + symbol.getText();
                                out.format("Symbol text: %s (confidence: %f)\n", symbol.getText(), symbol.getConfidence());
                            }
                            out.format("Word text: %s (confidence: %f)\n\n", wordText, word.getConfidence());
                            paraText = String.format("%s %s", paraText, wordText);
                        }
                        // Output Example using Paragraph:
                        out.println("\nParagraph: \n" + paraText);
                        out.format("Paragraph Confidence: %f\n", para.getConfidence());
                        blockText = blockText + paraText;
                    }
                    pageText = pageText + blockText;
                }
            }
            out.println("\nComplete annotation:");
            out.println(annotation.getText());
        }
    }
}
Also used : Word(com.google.cloud.vision.v1.Word) Symbol(com.google.cloud.vision.v1.Symbol) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) ArrayList(java.util.ArrayList) WebPage(com.google.cloud.vision.v1.WebDetection.WebPage) Page(com.google.cloud.vision.v1.Page) ByteString(com.google.protobuf.ByteString) WebImage(com.google.cloud.vision.v1.WebDetection.WebImage) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) Paragraph(com.google.cloud.vision.v1.Paragraph) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) Block(com.google.cloud.vision.v1.Block) ImageSource(com.google.cloud.vision.v1.ImageSource) TextAnnotation(com.google.cloud.vision.v1.TextAnnotation) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Example 4 with org.bukkit.craftbukkit.v1_18_R2.block

use of org.bukkit.craftbukkit.v1_18_R2.block in project MagicPlugin by elBukkit.

the class CompatibilityUtils method clearItems.

@Override
public void clearItems(Location location) {
    if (location == null)
        return;
    // Block-specific behaviors
    Block block = location.getBlock();
    BlockState blockState = block.getState();
    if (blockState instanceof Lootable) {
        Lootable lootable = (Lootable) blockState;
        lootable.setLootTable(null);
        blockState.update();
    }
    if (blockState instanceof Lectern) {
        Lectern lectern = (Lectern) blockState;
        lectern.getInventory().setItem(0, new ItemStack(Material.AIR));
        blockState.update();
    }
    if (blockState instanceof Jukebox) {
        ((Jukebox) blockState).setRecord(null);
        blockState.update();
    }
    // TODO: Just clear inventory instead?
    BlockEntity tileEntity = getTileEntity(location);
    if (tileEntity == null)
        return;
    CompoundTag tag = tileEntity.saveWithFullMetadata();
    // Is there really not an enum for these NBT types?
    ListTag itemList = tag.getList("Items", CompatibilityConstants.NBT_TYPE_COMPOUND);
    // Is it really necessary to clear the list before removing it?
    if (itemList != null) {
        itemList.clear();
        tag.remove("Items");
        tileEntity.load(tag);
        tileEntity.setChanged();
    }
}
Also used : Jukebox(org.bukkit.block.Jukebox) BlockState(org.bukkit.block.BlockState) Lootable(org.bukkit.loot.Lootable) FallingBlock(org.bukkit.entity.FallingBlock) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) Lectern(org.bukkit.block.Lectern) ItemStack(org.bukkit.inventory.ItemStack) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) SignBlockEntity(net.minecraft.world.level.block.entity.SignBlockEntity)

Example 5 with org.bukkit.craftbukkit.v1_18_R2.block

use of org.bukkit.craftbukkit.v1_18_R2.block in project MagicPlugin by elBukkit.

the class CompatibilityUtils method forceUpdate.

@Override
public boolean forceUpdate(Block block, boolean physics) {
    if (block == null)
        return false;
    net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
    if (blockState == null)
        return false;
    net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
    net.minecraft.world.level.block.state.BlockState blockData = nmsBlock.defaultBlockState();
    ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
    BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
    world.setBlock(blockPosition, blockData, 11);
    return false;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockPos(net.minecraft.core.BlockPos) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Aggregations

CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)24 CraftBlock (org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)24 Block (org.bukkit.block.Block)23 BlockPos (net.minecraft.core.BlockPos)18 ArrayList (java.util.ArrayList)15 ServerLevel (net.minecraft.server.level.ServerLevel)14 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)14 Player (org.bukkit.entity.Player)14 ServerPlayer (net.minecraft.server.level.ServerPlayer)13 BlockState (net.minecraft.world.level.block.state.BlockState)11 FallingBlock (org.bukkit.entity.FallingBlock)11 Block (net.minecraft.server.v1_12_R1.Block)9 CraftBlockState (org.bukkit.craftbukkit.v1_18_R2.block.CraftBlockState)9 ByteString (com.google.protobuf.ByteString)8 Direction (net.minecraft.core.Direction)8 Block (net.minecraft.server.v1_10_R1.Block)8 Block (net.minecraft.server.v1_11_R1.Block)8 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)8 Block (net.minecraft.server.v1_8_R3.Block)8 HashMap (java.util.HashMap)7