本文整理汇总了Java中org.spongepowered.api.event.block.InteractBlockEvent.getTargetBlock方法的典型用法代码示例。如果您正苦于以下问题:Java InteractBlockEvent.getTargetBlock方法的具体用法?Java InteractBlockEvent.getTargetBlock怎么用?Java InteractBlockEvent.getTargetBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.block.InteractBlockEvent
的用法示例。
在下文中一共展示了InteractBlockEvent.getTargetBlock方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerClick
import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerClick(InteractBlockEvent event, @First Player player) {
if (state.equals(State.CLICK) && player.getUniqueId().equals(getParent().getUUID())) {
BlockSnapshot snapshot = event.getTargetBlock();
// Make sure the block was clicked twice
if (doubleClickCurrent == null) {
doubleClickTick = Sponge.getServer().getRunningTimeTicks();
doubleClickCurrent = snapshot;
} else {
if (doubleClickCurrent.equals(snapshot) && Sponge.getServer().getRunningTimeTicks() - doubleClickTick > 5) {
doubleClickCurrent = null;
doubleClickTick = 0;
player.sendMessage(messages.getMessage("creation.placecurrency"));
blockState = snapshot.getState();
state = State.CURRENCY;
} else {
doubleClickTick = Sponge.getServer().getRunningTimeTicks();
doubleClickCurrent = snapshot;
}
}
}
}
示例2: onBlockInteract
import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockInteract(InteractBlockEvent event, @First Player player) {
HandType hand = Utils.getEventHand(event);
BlockSnapshot blockSnapshot = event.getTargetBlock();
if (blockSnapshot == BlockSnapshot.NONE) {
return;
}
CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
Vector3i pos = blockSnapshot.getPosition();
BlockNature block = world.getBlock(pos);
if (block == null) {
return;
}
Direction side = event.getTargetSide();
Vector3d point = event.getInteractionPoint().orElse(null);
boolean allowInteract = !event.isCancelled();
if (event instanceof InteractBlockEvent.Primary) {
allowInteract = block.onBlockHit(world, pos, player, hand, side, point);
} else if (event instanceof InteractBlockEvent.Secondary) {
if (player.getItemInHand(hand).isPresent() && player.get(Keys.IS_SNEAKING).get()) {
// Pass on the item click without telling the block
allowInteract = true;
} else {
allowInteract = block.onBlockActivated(world, pos, player, hand, side, point);
}
}
event.setCancelled(!allowInteract);
}
示例3: onInteractBlock
import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
BlockSnapshot b = event.getTargetBlock();
Location<World> l = null;
RedProtect.get().logger.debug("player","RPBlockListener - Is InteractBlockEvent event");
if (!b.getState().getType().equals(BlockTypes.AIR)){
l = b.getLocation().get();
RedProtect.get().logger.debug("player","RPBlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
} else {
l = p.getLocation();
}
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null){
ItemType itemInHand = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()){
itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)){
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
event.setCancelled(true);
}
}
}
示例4: onClick
import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onClick(InteractBlockEvent event, @First Player player)
{
if (event instanceof InteractBlockEvent.Primary.MainHand || event instanceof InteractBlockEvent.Secondary.MainHand)
{
Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
if (itemInHand.isPresent() && itemInHand.get().get(LookupData.class).isPresent())
{
if (!player.hasPermission(toolPerm.getId()) || event.getTargetBlock() == BlockSnapshot.NONE)
{
return;
}
Location<World> loc;
if (event instanceof InteractBlockEvent.Primary)
{
loc = event.getTargetBlock().getLocation().get();
}
else
{
loc = event.getTargetBlock().getLocation().get().getRelative(event.getTargetSide());
}
qm.queryAndShow(new Lookup(itemInHand.get().get(LookupData.class).get()).with(loc), player);
event.setCancelled(true);
}
}
}
示例5: onInteract
import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteract(InteractBlockEvent event) {
Player player = SpongeUtil.getCause(event.getCause(), Player.class);
if (player == null) {
event.setCancelled(true);
return;
}
BlockSnapshot block = event.getTargetBlock();
if (block == null) {
return;
}
Optional<org.spongepowered.api.world.Location<World>> bloc = block.getLocation();
if (!bloc.isPresent()) {
return;
}
Location loc = SpongeUtil.getLocation(player.getWorld().getName(), bloc.get());
PlotArea area = loc.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getPlot(loc);
PlotPlayer pp = SpongeUtil.getPlayer(player);
if (plot == null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_ROAD, true)) {
event.setCancelled(true);
return;
}
return;
}
if (!plot.hasOwner()) {
if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_UNOWNED)) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_UNOWNED);
event.setCancelled(true);
return;
}
if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_INTERACT_OTHER)) {
return;
} else {
com.google.common.base.Optional<HashSet<PlotBlock>> flag = plot.getFlag(Flags.USE);
org.spongepowered.api.world.Location l = SpongeUtil.getLocation(loc);
if (flag.isPresent() && flag.get().contains(SpongeUtil.getPlotBlock(l.getBlock()))) {
return;
}
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_INTERACT_OTHER);
event.setCancelled(true);
return;
}
}
示例6: onInteract
import org.spongepowered.api.event.block.InteractBlockEvent; //导入方法依赖的package包/类
@Listener
public void onInteract(InteractBlockEvent event, @First Player player)
{
if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand))
{
return;
}
if (event.getTargetBlock() == BlockSnapshot.NONE)
{
return;
}
Location block = event.getTargetBlock().getLocation().get();
if ((int)block.getPosition().length() == 0)
{
return;
}
Optional<ItemStack> itemInHand = player.getItemInHand(HandTypes.MAIN_HAND);
if (!itemInHand.isPresent() || !"Selector-Tool".equals(itemInHand.get().get(Keys.DISPLAY_NAME).map(Text::toPlain).orElse("")))
{
return;
}
if (block.getBlockType() == AIR || !player.hasPermission(module.getSelectPerm().getId()))
{
return;
}
SelectorData data = selectorData.computeIfAbsent(player.getUniqueId(), k -> new SelectorData());
if (event instanceof InteractBlockEvent.Primary)
{
data.setPoint(0, block);
i18n.send(player, POSITIVE, "First position set to ({integer}, {integer}, {integer}).", block.getBlockX(), block.getBlockY(), block.getBlockZ());
}
else if (event instanceof InteractBlockEvent.Secondary)
{
data.setPoint(1, block);
i18n.send(player, POSITIVE, "Second position set to ({integer}, {integer}, {integer}).", block.getBlockX(), block.getBlockY(), block.getBlockZ());
}
event.setCancelled(true);
}