本文整理汇总了Java中org.spongepowered.api.event.item.inventory.DropItemEvent类的典型用法代码示例。如果您正苦于以下问题:Java DropItemEvent类的具体用法?Java DropItemEvent怎么用?Java DropItemEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DropItemEvent类属于org.spongepowered.api.event.item.inventory包,在下文中一共展示了DropItemEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemDrop
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Dispense event, @Root Player player) {
PermHandler ph = PermHandler.getInstance();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
ItemType itemType = item.getItemType();
String itemId = itemType.getId();
if (!ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".dispense")) {
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to drop " + itemType.getName() + '!'));
return false;
}
}
return true;
});
}
示例2: fireDropItemEvent
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
private void fireDropItemEvent(World world, Vector3i pos) {
List<ItemStack> stacks = getDroppedItems();
if (stacks.isEmpty()) {
return;
}
List<Entity> entities = Lists.newArrayList();
for (ItemStack stack : stacks) {
Entity drop = createItemDrop(world, pos, stack);
entities.add(drop);
}
Cause cause = Cause.source(BlockSpawnCause.builder()
.type(SpawnTypes.DROPPED_ITEM)
.block(world.createSnapshot(pos))
.build())
.build();
DropItemEvent.Destruct harvestEvent = SpongeEventFactory.createDropItemEventDestruct(cause, entities);
if (Sponge.getEventManager().post(harvestEvent)) {
return;
}
for (Entity entity : harvestEvent.getEntities()) {
world.spawnEntity(entity, cause);
}
}
示例3: onEntityDropItemDeath
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDropItemDeath(DropItemEvent.Destruct event, @Root Living livingEntity) {
if (!GPFlags.ITEM_DROP || event.getEntities().isEmpty()) {
return;
}
final World world = event.getEntities().get(0).getWorld();
if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
return;
}
GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.startTimingIfSync();
// special rule for creative worlds: killed entities don't drop items or experience orbs
if (GriefPreventionPlugin.instance.claimModeIsActive(livingEntity.getLocation().getExtent().getProperties(), ClaimsMode.Creative)) {
event.setCancelled(true);
GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync();
return;
}
GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync();
}
示例4: onDropItem
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDropItem(DropItemEvent.Dispense event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
event.filterEntities(e -> {
if (e.get(RepresentedItemData.class).isPresent())
{
RepresentedItemData itemData = e.get(RepresentedItemData.class).get();
boolean blacklisted = Utils.getBlacklistItems().contains(itemData.item().get().getType().getId());
if (blacklisted)
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, itemData.item().get().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
}
return !blacklisted;
}
return false;
});
}
}
示例5: onItemDrop
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> loc = optLocation.get();
if (!markedOrePoints.remove(loc)) {
return;
}
event.getEntities().clear();
}
示例6: onItemDrop
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
if (event.getCause().containsType(Player.class)) {
return;
}
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> location = optLocation.get();
while (true) {
location = location.add(0, -1, 0);
if (location.getBlockType() != BlockTypes.CACTUS) {
break;
}
location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
}
}
示例7: onDropItem
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDropItem(DropItemEvent.Dispense event) {
event.getEntities().stream().filter(entity -> entity instanceof Item).forEach(entity -> {
ItemStack stack = ((EntityItem) entity).getEntityItem();
if (isZoneSlaveItem(stack)) {
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
if (!notifyGroupOwner(stack, player, false)) {
// TODO Log this, as it shouldn't happen
}
player.sendMessage(
Text.of(TextColors.RED, "You've declined your group invite.")
);
}
entity.remove();
}
});
}
示例8: onEntityDrop
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
Entity entity = spawnCause.getEntity();
if (!(entity instanceof Animal)) {
return;
}
Optional<TheButcherShopInstance> optInst = manager.getApplicableZone(entity);
if (!optInst.isPresent()) {
return;
}
event.getEntities().clear();
Item item = (Item) entity.getLocation().createEntity(EntityTypes.ITEM);
item.offer(Keys.REPRESENTED_ITEM, newItemStack("skree:unpackaged_meat").createSnapshot());
event.getEntities().add(item);
}
示例9: onDrop
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDrop(DropItemEvent.Dispense event, @Root EntitySpawnCause cause) {
if (cause.getEntity() instanceof Player) {
//TODO exempt check
}
ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
CommentedConfigurationNode hnode = config.get();
for (Entity en : event.getEntities()) {
if (!(en instanceof Item)) continue;
Item item = (Item) en;
CommentedConfigurationNode node = hnode.getNode("items", item.getItemType().getId());
if (!node.isVirtual()) {
if (node.getNode("deny-drop").getBoolean()) {
event.setCancelled(true);
}
}
}
}
示例10: onDropItem
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDropItem(DropItemEvent event, @Root @Has(ViewerData.class) Player player) {
Optional<String> camId = player.get(VigilateKeys.CAMERA);
if(camId.isPresent() && Vigilate.getInstance().getCameras().containsKey(camId.get())){
Vigilate.getInstance().getCameras().get(camId.get()).endViewCamera(player);
} else {
Camera.resetPlayer(player);
}
event.setCancelled(true);
}
示例11: onDropItem
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDropItem(final DropItemEvent.Dispense event, @First Player player) {
if (player.hasPermission("safeguard.mod")) {
return;
}
if (!SafeGuard.getZoneManager().allows(player, flag, player.getLocation())) {
player.sendMessage(Format.error("Sorry, this zone doesn't allow you to do that."));
event.setCancelled(true);
}
}
示例12: onDropItem
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDropItem(DropItemEvent.Destruct event) {
java.util.Optional<Player> player = event.getCause().first(Player.class);
if (player.isPresent() && event.getCause().root() instanceof BlockSpawnCause) {
Optional<Challenger> challenger = Main.getMinigame().getChallenger(player.get().getUniqueId());
if (challenger.isPresent()) {
event.setCancelled(true);
}
}
}
示例13: onItemDropDeath
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onItemDropDeath(DropItemEvent.Destruct event, @Root Player player) {
PermHandler ph = PermHandler.getInstance();
event.filterEntities(entity -> {
if (entity.getType().equals(EntityTypes.ITEM)) {
Item item = (Item) entity;
String itemId = item.getItemType().getId();
return ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".death");
}
return true;
});
}
示例14: onDropItem
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onDropItem(DropItemEvent event) {
Optional<Player> clicker = event.getCause().first(Player.class);
if (!clicker.isPresent()) return;
if (!VillagerShops.openShops.containsKey(clicker.get().getUniqueId())) return;
event.setCancelled(true);
}
示例15: onBlockDropItems
import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入依赖的package包/类
@Listener
public void onBlockDropItems(DropItemEvent.Destruct event, @Root BlockSpawnCause blockCause) {
if (blockCause.getType() != SpawnTypes.DROPPED_ITEM) {
return;
}
BlockSnapshot blockSnapshot = blockCause.getBlockSnapshot();
CustomWorld world = WorldManager.toCustomWorld(blockSnapshot.getLocation().get().getExtent());
Vector3i pos = blockSnapshot.getPosition();
BlockNature block = world.getBlock(pos);
if (block == null) {
return;
}
boolean allowDrop = block.onBlockHarvest(world, pos, event.getEntities());
event.setCancelled(!allowDrop);
}