org.bukkit.entity.Hanging Java Examples

The following examples show how to use org.bukkit.entity.Hanging. 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: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private void handleHangingBreak(Event event, Hanging hanging, Entity breaker) {
  BlockState blockState = getHangingBlockState(hanging);
  if (blockState == null) return;

  Query query = makeBlockQuery(event, breaker, blockState);

  for (RegionFilterApplication rfa : this.rfaContext.get(RFAScope.BLOCK_BREAK)) {
    if (rfa.region.contains(blockState)) {
      if (processQuery(rfa, query)) {
        sendCancelMessage(rfa, query);
        if (this.useRegionPriority || rfa.useRegionPriority) break;
      }
    }
  }
}
 
Example #2
Source File: ItemHanging.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
	if (l == 0) {
		return false;
	}
	if (l == 1) {
		return false;
	}
	int i1 = Direction.e[l];
	EntityHanging entityhanging = a(world, i, j, k, i1);
	if (!entityhuman.a(i, j, k, l, itemstack)) {
		return false;
	}
	if ((entityhanging != null) && (entityhanging.survives())) {
		if (!world.isStatic) {
			Player who = entityhuman == null ? null : (Player) entityhuman.getBukkitEntity();
			Block blockClicked = world.getWorld().getBlockAt(i, j, k);
			BlockFace blockFace = CraftBlock.notchToBlockFace(l);

			HangingPlaceEvent event = new HangingPlaceEvent((Hanging) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
			world.getServer().getPluginManager().callEvent(event);

			PaintingPlaceEvent paintingEvent = null;
			if ((entityhanging instanceof EntityPainting)) {
				paintingEvent = new PaintingPlaceEvent((Painting) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
				paintingEvent.setCancelled(event.isCancelled());
				world.getServer().getPluginManager().callEvent(paintingEvent);
			}
			if ((event.isCancelled()) || ((paintingEvent != null) && (paintingEvent.isCancelled()))) {
				return false;
			}
			world.addEntity(entityhanging);
		}
		itemstack.count -= 1;
	}
	return true;
}
 
Example #3
Source File: HangingListener.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHangingBreak(HangingBreakEvent event) {
  Hanging hanging = event.getEntity();
  if (event.getCause().equals(RemoveCause.OBSTRUCTION)) {
    hanging.getLocation().getBlock().breakNaturally();
    event.setCancelled(true);
  } else if (event.getCause().equals(RemoveCause.EXPLOSION)) {
    event.setCancelled(true);
  }

}
 
Example #4
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Material getHangingType(Hanging hanging) {
    if(hanging instanceof Painting) {
        return Material.PAINTING;
    } else if(hanging instanceof ItemFrame) {
        return Material.ITEM_FRAME;
    } else if(hanging instanceof LeashHitch) {
        return Material.LEASH;
    } else {
        return null;
    }
}
 
Example #5
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private void handleHangingBreak(Event event, Hanging hanging, Entity breaker) {
    BlockState blockState = getHangingBlockState(hanging);
    if(blockState == null) return;

    IEventQuery query = makeBlockQuery(event, breaker, blockState);

    for(EventRule rule : this.ruleContext.get(EventRuleScope.BLOCK_BREAK)) {
        if(rule.region().contains(blockState)) {
            if(processQuery(rule, query)) {
                sendCancelMessage(rule, query);
                if(this.useRegionPriority) break;
            }
        }
    }
}
 
Example #6
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameItemRemove(EntityDamageByEntityEvent event) {
    // This event is fired when popping an item out of an item frame, without breaking the frame itself
    if(event.getEntity() instanceof ItemFrame && ((ItemFrame) event.getEntity()).getItem() != null) {
        this.handleHangingBreak(event, (Hanging) event.getEntity(), event.getDamager());
    }
}
 
Example #7
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Material getHangingType(Hanging hanging) {
  if (hanging instanceof Painting) {
    return Material.PAINTING;
  } else if (hanging instanceof ItemFrame) {
    return Material.ITEM_FRAME;
  } else if (hanging instanceof LeashHitch) {
    return Material.LEASH;
  } else {
    return null;
  }
}
 
Example #8
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void checkItemFrameItemRemove(EntityDamageByEntityEvent event) {
  // This event is fired when popping an item out of an item frame, without breaking the frame
  // itself
  if (event.getEntity() instanceof ItemFrame
      && ((ItemFrame) event.getEntity()).getItem() != null) {
    this.handleHangingBreak(event, (Hanging) event.getEntity(), event.getDamager());
  }
}
 
Example #9
Source File: HangingBreakByEntityEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public HangingBreakByEntityEvent(final Hanging hanging, final Entity remover, final RemoveCause cause) {
    super(hanging, cause);
    this.remover = remover;
}
 
Example #10
Source File: HangingEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
protected HangingEvent(final Hanging painting) {
    this.hanging = painting;
}
 
Example #11
Source File: HangingBreakEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public HangingBreakEvent(final Hanging hanging, final RemoveCause cause) {
    super(hanging);
    this.cause = cause;
}
 
Example #12
Source File: HangingBreakByEntityEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public HangingBreakByEntityEvent(final Hanging hanging, final Entity remover) {
    this(hanging, remover, RemoveCause.ENTITY);
}
 
Example #13
Source File: HangingPlaceEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public HangingPlaceEvent(final Hanging hanging, final Player player, final Block block, final BlockFace blockFace) {
    super(hanging);
    this.player = player;
    this.block = block;
    this.blockFace = blockFace;
}
 
Example #14
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
private static BlockState getHangingBlockState(Hanging hanging) {
    Block block = hanging.getLocation().getBlock();
    Material type = getHangingType(hanging);
    return type == null ? null : BlockStateUtils.cloneWithMaterial(block, type);
}
 
Example #15
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
private static BlockState getHangingBlockState(Hanging hanging) {
  Block block = hanging.getLocation().getBlock();
  Material type = getHangingType(hanging);
  return type == null ? null : BlockStates.cloneWithMaterial(block, type);
}
 
Example #16
Source File: DGameWorld.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handles what happens when a player breaks a block.
 *
 * @param event the passed Bukkit event
 * @return if the event is cancelled
 */
public boolean onBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    Block block = event.getBlock();
    for (DungeonSign sign : getDungeonSigns()) {
        if (sign == null) {
            continue;
        }
        if ((block.equals(sign.getSign().getBlock()) || block.equals(BlockUtil.getAttachedBlock(sign.getSign().getBlock()))) && sign.isProtected()) {
            return true;
        }
    }

    for (GameBlock gameBlock : gameBlocks) {
        if (block.equals(gameBlock.getBlock())) {
            if (gameBlock.onBreak(event)) {
                return true;
            }

        } else if (gameBlock instanceof MultiBlock) {
            if (block.equals(((MultiBlock) gameBlock).getAttachedBlock())) {
                if (gameBlock.onBreak(event)) {
                    return true;
                }
            }
        }
    }

    Game game = getGame();
    if (game == null) {
        return true;
    }

    if (!getRules().getState(GameRule.BREAK_BLOCKS) && !getRules().getState(GameRule.BREAK_PLACED_BLOCKS)) {
        return true;
    }

    // Cancel if a protected entity is attached
    for (Entity entity : getWorld().getNearbyEntities(block.getLocation(), 2, 2, 2)) {
        if (!(entity instanceof Hanging)) {
            continue;
        }
        if (entity.getLocation().getBlock().getRelative(((Hanging) entity).getAttachedFace()).equals(block)) {
            Hanging hanging = (Hanging) entity;
            if (getRules().getState(GameRule.DAMAGE_PROTECTED_ENTITIES).contains(caliburn.getExMob(hanging))) {
                event.setCancelled(true);
                break;
            }
        }
    }

    Map<ExItem, HashSet<ExItem>> whitelist = getRules().getState(GameRule.BREAK_WHITELIST);
    ExItem material = VanillaItem.get(block.getType());
    ExItem breakTool = caliburn.getExItem(player.getItemInHand());

    if (getRules().getState(GameRule.BREAK_PLACED_BLOCKS) && placedBlocks.contains(block)) {
        return false;
    }
    if (whitelist != null && whitelist.containsKey(material)
            && (whitelist.get(material) == null
            || whitelist.get(material).isEmpty()
            || whitelist.get(material).contains(breakTool))) {
        return false;
    }

    return true;
}
 
Example #17
Source File: HangingEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the hanging entity involved in this event.
 *
 * @return the hanging entity
 */
public Hanging getEntity() {
    return hanging;
}