Java Code Examples for org.bukkit.block.Block#getWorld()

The following examples show how to use org.bukkit.block.Block#getWorld() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonBlockEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
public void handleBlockSpread(Event event, Block fromBlock, BlockState newState) {
    if (!GDFlags.BLOCK_SPREAD) {
        return;
    }

    final World world = fromBlock.getWorld();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
        return;
    }

    final Location sourceLocation = fromBlock != null ? fromBlock.getLocation() : null;
    final GDPermissionUser user = CauseContextHelper.getEventUser(sourceLocation, PlayerTracker.Type.NOTIFIER);

    Location location = newState.getLocation();
    GDClaim targetClaim = this.storage.getClaimAt(location);

    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.BLOCK_SPREAD, fromBlock, newState.getBlock().isEmpty() ? newState.getType() : newState, user, TrustTypes.BUILDER, true);
    if (result == Tristate.FALSE) {
        ((Cancellable) event).setCancelled(true);
    }
}
 
Example 2
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.light = block.getLightLevel();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;
    // Cauldron start - save TE data
    TileEntity te = world.getHandle().getTileEntity(x, y, z);
    if (te != null)
    {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    }
    else nbt = null;
    // Cauldron end

    createData(block.getData());
}
 
Example 3
Source File: CraftBlockState.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public CraftBlockState(final Block block) {
    this.world = (CraftWorld) block.getWorld();
    this.x = block.getX();
    this.y = block.getY();
    this.z = block.getZ();
    this.type = block.getTypeId();
    this.chunk = (CraftChunk) block.getChunk();
    this.flag = 3;

    createData(block.getData());
    TileEntity te = world.getHandle().getTileEntity(new BlockPos(this.x, this.y, this.z));
    if (te != null) {
        nbt = new NBTTagCompound();
        te.writeToNBT(nbt);
    } else nbt = null;
}
 
Example 4
Source File: CoreMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void damageCheck(BlockDamageEvent event) {
  Block block = event.getBlock();
  if (block.getWorld() != this.match.getWorld()) return;
  MatchPlayer player = this.match.getPlayer(event.getPlayer());
  Vector center = BlockVectors.center(block).toVector();

  for (Core core : this.cores) {
    if (!core.hasLeaked()
        && core.getCasingRegion().contains(center)
        && player.getParty() == core.getOwner()) {
      event.setCancelled(true);
      player.sendWarning(TranslatableComponent.of("core.damageOwn"));
    }
  }
}
 
Example 5
Source File: FlagAnvilSpleef.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onEntityChangeBlockEvent(EntityChangeBlockEvent e) {
	EntityType type = e.getEntityType();
	if (type != EntityType.FALLING_BLOCK) {
		return;
	}
	
	Entity entity = e.getEntity();
	if (!fallingAnvils.contains(entity)) {
		return;
	}
	
	Block block = e.getBlock();
	Block under = block.getRelative(BlockFace.DOWN);
	
	fallingAnvils.remove(entity);
	e.setCancelled(true);		
	
	if (!game.canSpleef(under)) {
		entity.remove();
		return;
	}
	
	Material material = under.getType();
	under.setType(Material.AIR);
	World world = under.getWorld();

       Sound anvilLandSound = Game.getSoundEnumType("ANVIL_LAND");
       if (anvilLandSound != null) {
           world.playSound(block.getLocation(), anvilLandSound, 1.0f, 1.0f);
       }
	
	if (game.getPropertyValue(GameProperty.PLAY_BLOCK_BREAK)) {
		world.playEffect(under.getLocation(), Effect.STEP_SOUND, material.getId());
	}
}
 
Example 6
Source File: BlockMetadataStore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the metadata for a {@link Block}, ensuring the block being asked for actually belongs to this BlockMetadataStore's
 * owning world.
 *
 * @see MetadataStoreBase#getMetadata(Object, String)
 */
@Override
public List<MetadataValue> getMetadata(Block block, String metadataKey) {
    if (block.getWorld() == owningWorld) {
        return super.getMetadata(block, metadataKey);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example 7
Source File: NMSHandler.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setFlowerPotBlock(Block block, ItemStack itemStack) {
    Location loc = block.getLocation();
    CraftWorld cw = (CraftWorld)block.getWorld();
    BlockPosition bp = new BlockPosition(loc.getX(), loc.getY(), loc.getZ());
    TileEntityFlowerPot te = (TileEntityFlowerPot)cw.getHandle().getTileEntity(bp);
    //Bukkit.getLogger().info("Debug: flowerpot materialdata = " + (new ItemStack(potItem, 1,(short) potItemData).toString()));
    net.minecraft.server.v1_9_R1.ItemStack cis = CraftItemStack.asNMSCopy(itemStack);
    te.a(cis.getItem(), cis.getData());
    te.update();
}
 
Example 8
Source File: BlockMetadataStore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Removes metadata from from a {@link Block} belonging to a given {@link Plugin}, ensuring the block being deleted from belongs
 * to this BlockMetadataStore's owning world.
 *
 * @see MetadataStoreBase#removeMetadata(Object, String, Plugin)
 */
@Override
public void removeMetadata(Block block, String metadataKey, Plugin owningPlugin) {
    if (block.getWorld() == owningWorld) {
        super.removeMetadata(block, metadataKey, owningPlugin);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example 9
Source File: BlockMetadataStore.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets or overwrites a metadata value on a {@link Block} from a given {@link Plugin}, ensuring the target block belongs
 * to this BlockMetadataStore's owning world.
 *
 * @see MetadataStoreBase#setMetadata(Object, String, MetadataValue)
 */
@Override
public void setMetadata(Block block, String metadataKey, MetadataValue newMetadataValue) {
    if (block.getWorld() == owningWorld) {
        super.setMetadata(block, metadataKey, newMetadataValue);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example 10
Source File: CraftCommandBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public CraftCommandBlock(Block block) {
    super(block);

    CraftWorld world = (CraftWorld) block.getWorld();
    commandBlock = (TileEntityCommandBlock) world.getTileEntityAt(getX(), getY(), getZ());
    command = commandBlock.func_145993_a().field_145763_e;
    name = commandBlock.func_145993_a().getCommandSenderName();
}
 
Example 11
Source File: BlockMetadataStore.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the metadata for a {@link Block}, ensuring the block being asked for actually belongs to this BlockMetadataStore's
 * owning world.
 * @see MetadataStoreBase#getMetadata(Object, String)
 */
@Override
public List<MetadataValue> getMetadata(Block block, String metadataKey) {
    if(block.getWorld() == owningWorld) {
        return super.getMetadata(block, metadataKey);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example 12
Source File: CoreMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void damageCheck(BlockDamageEvent event) {
    Block block = event.getBlock();
    if(block.getWorld() != this.match.getWorld()) return;
    MatchPlayer player = this.match.getPlayer(event.getPlayer());
    Vector center = BlockUtils.center(block).toVector();

    for(Core core : this.cores) {
        if(!core.hasLeaked() && core.getCasingRegion().contains(center) && player.getParty() == core.getOwner()) {
            event.setCancelled(true);
            player.sendWarning(PGMTranslations.t("match.core.damageOwn", player), true);
        }
    }
}
 
Example 13
Source File: JoinSign.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
protected JoinSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxElements, int startIfElementsAtLeast) {
    super(plugin, startSign.getWorld(), id);

    this.startSign = startSign;
    dungeon = plugin.getDungeonRegistry().get(identifier);
    verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);

    this.maxElements = maxElements;
    if (startIfElementsAtLeast > 0 && startIfElementsAtLeast <= maxElements) {
        this.startIfElementsAtLeast = startIfElementsAtLeast;
    }

    update();
}
 
Example 14
Source File: BlockMetadataStore.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets or overwrites a metadata value on a {@link Block} from a given {@link Plugin}, ensuring the target block belongs
 * to this BlockMetadataStore's owning world.
 * @see MetadataStoreBase#setMetadata(Object, String, org.bukkit.metadata.MetadataValue)
 */
@Override
public void setMetadata(Block block, String metadataKey, MetadataValue newMetadataValue) {
    if(block.getWorld() == owningWorld) {
        super.setMetadata(block, metadataKey, newMetadataValue);
    } else {
        throw new IllegalArgumentException("Block does not belong to world " + owningWorld.getName());
    }
}
 
Example 15
Source File: FlagSplegg.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
	Projectile projectile = event.getEntity();
	if (!(projectile instanceof Egg)) {
		return;
	}
	
	ProjectileSource source = projectile.getShooter();
	
	if (!(source instanceof Player)) {
		return;
	}
	
	SpleefPlayer shooter = getHeavySpleef().getSpleefPlayer(source);
	Game game = getHeavySpleef().getGameManager().getGame(shooter);
	if (game != this.game) {
		return;
	}
	
	projectile.remove();
	
	if (game == null || game.getGameState() != GameState.INGAME) {
		return;
	}
	
	// Use a BlockIterator to determine where the arrow has hit the ground
	BlockIterator blockIter = new BlockIterator(projectile.getWorld(), 
			projectile.getLocation().toVector(), 
			projectile.getVelocity().normalize(), 
			0, 4);
	
	Block blockHit = null;
	
	while (blockIter.hasNext()) {
		blockHit = blockIter.next();
		
		if (blockHit.getType() != Material.AIR) {
			break;
		}
	}
	
	if (!game.canSpleef(blockHit)) {
		//Cannot remove this block
		return;
	}
	
	game.addBlockBroken(shooter, blockHit);
	Material type = blockHit.getType();
	blockHit.setType(Material.AIR);
	
	World world = blockHit.getWorld();
	
	if (type == Material.TNT) {
		Location spawnLocation = blockHit.getLocation().add(0.5, 0, 0.5);
		TNTPrimed tnt = (TNTPrimed) world.spawnEntity(spawnLocation, EntityType.PRIMED_TNT);
		tnt.setMetadata(TNT_METADATA_KEY, new FixedMetadataValue(getHeavySpleef().getPlugin(), game));
		tnt.setYield(3);
		tnt.setFuseTicks(0);
	} else {
           Sound chickenEggPopSound = Game.getSoundEnumType("CHICKEN_EGG_POP", "CHICKEN_EGG");
           if (chickenEggPopSound != null) {
               projectile.getWorld().playSound(blockHit.getLocation(), chickenEggPopSound, 1.0f, 0.7f);
           }
	}
}
 
Example 16
Source File: CraftChest.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public CraftChest(final Block block) {
    super(block);

    world = (CraftWorld) block.getWorld();
    chest = (TileEntityChest) world.getTileEntityAt(getX(), getY(), getZ());
}
 
Example 17
Source File: CraftDropper.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public CraftDropper(final Block block) {
    super(block);

    world = (CraftWorld) block.getWorld();
    dropper = (TileEntityDropper) world.getTileEntityAt(getX(), getY(), getZ());
}
 
Example 18
Source File: BlockEventQuery.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public BlockEventQuery(Event event, Block block) {
    this(event, block.getWorld(), block.getX(), block.getY(), block.getZ(), null);
}
 
Example 19
Source File: ContainerManager.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean canWorldBreak(Block b) {
    if (!RedProtect.get().config.configRoot().private_cat.use) {
        return true;
    }
    Region reg = RedProtect.get().rm.getTopRegion(b.getLocation());
    if (reg == null && !RedProtect.get().config.configRoot().private_cat.allow_outside) {
        return true;
    }
    int x = b.getX();
    int y = b.getY();
    int z = b.getZ();
    World w = b.getWorld();

    if (isSign(b) && validWorldBreak(b)) {
        RedProtect.get().logger.debug(LogLevel.DEFAULT, "Valid Sign on canWorldBreak!");
        return false;
    }

    String signbtype = b.getType().name();
    List<String> blocks = RedProtect.get().config.configRoot().private_cat.allowed_blocks;

    if (blocks.stream().anyMatch(signbtype::matches)) {
        for (int sx = -1; sx <= 1; sx++) {
            for (int sz = -1; sz <= 1; sz++) {
                Block bs = w.getBlockAt(x + sx, y, z + sz);
                if (isSign(bs) && validWorldBreak(bs)) {
                    return false;
                }

                String blocktype2 = b.getType().name();

                int x2 = bs.getX();
                int y2 = bs.getY();
                int z2 = bs.getZ();

                if (blocks.stream().anyMatch(blocktype2::matches)) {
                    for (int ux = -1; ux <= 1; ux++) {
                        for (int uz = -1; uz <= 1; uz++) {
                            Block bu = w.getBlockAt(x2 + ux, y2, z2 + uz);
                            if (isSign(bu) && validWorldBreak(bu)) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
 
Example 20
Source File: CraftCustomContainer.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public CraftCustomContainer(Block block) {
    super(block);
    world = (CraftWorld) block.getWorld();
    container = (IInventory)world.getTileEntityAt(getX(), getY(), getZ());
}