本文整理汇总了Java中org.spongepowered.api.event.cause.NamedCause.SOURCE属性的典型用法代码示例。如果您正苦于以下问题:Java NamedCause.SOURCE属性的具体用法?Java NamedCause.SOURCE怎么用?Java NamedCause.SOURCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.spongepowered.api.event.cause.NamedCause
的用法示例。
在下文中一共展示了NamedCause.SOURCE属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onItemDrop
@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();
}
示例2: onItemDrop
@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());
}
}
示例3: onEntityDrop
@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);
}
示例4: onBlockPlace
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType originalType = transaction.getFinal().getState().getType();
BlockType finalType = transaction.getFinal().getState().getType();
if (isRedstoneTransition(originalType, finalType)) {
continue;
}
event.setCancelled(true);
break;
}
}
示例5: onItemDrop
@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;
}
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
List<ItemStackSnapshot> itemStacks = new ArrayList<>();
event.getEntities().forEach((entity -> {
if (entity instanceof Item) {
ItemStackSnapshot snapshot = ((Item) entity).item().get();
itemStacks.add(getPoolItemDrop(snapshot));
}
}));
addPool(loc, () -> itemStacks);
}
示例6: onBlockBreak
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
if (!isApplicable(srcEnt)) {
return;
}
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> block : transactions) {
BlockSnapshot original = block.getOriginal();
if (original.getCreator().isPresent()) {
continue;
}
Optional<Location<World>> optLoc = original.getLocation();
if (!optLoc.isPresent()) {
continue;
}
Location<World> loc = optLoc.get();
BlockState state = original.getState();
// Prevent item dupe glitch by removing the position before subsequent breaks
markedOrePoints.remove(loc);
if (config.getDropModification().blocks(state)) {
markedOrePoints.add(loc);
}
}
}
示例7: onPistonMove
@Listener
public void onPistonMove(ChangeBlockEvent event, @Named(NamedCause.SOURCE) Piston piston) {
event.getTransactions().stream().map(Transaction::getFinal).forEach(block -> {
BlockType finalType = block.getState().getType();
if (RAIL_BLOCKS.contains(finalType)) {
Location<World> location = block.getLocation().get();
Task.builder().execute(() -> {
location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
}).delayTicks(1).submit(SkreePlugin.inst());
}
});
}
示例8: onEntityDrop
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
Entity entity = spawnCause.getEntity();
if (!Creature.class.isAssignableFrom(entity.getType().getEntityClass())) {
return;
}
if (isApplicable(entity.getLocation())) {
event.setCancelled(true);
}
}
示例9: onRightClick
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @Named(NamedCause.SOURCE) Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (CustomItemTypes.PHANTOM_HYMN != optHeldItem.get().getItem()) {
return;
}
event.setUseBlockResult(Tristate.FALSE);
Optional<FreakyFourInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
FreakyFourInstance inst = optInst.get();
FreakyFourBoss boss = inst.getCurrentboss().orElse(null);
if (boss == null) {
inst.setCurrentboss(FreakyFourBoss.CHARLOTTE);
player.sendMessage(Text.of(TextColors.RED, "You think you can beat us? Ha! we'll see about that..."));
} else if (!inst.isSpawned(boss)) {
switch (boss) {
case CHARLOTTE:
inst.setCurrentboss(FreakyFourBoss.FRIMUS);
break;
case FRIMUS:
inst.setCurrentboss(FreakyFourBoss.DA_BOMB);
break;
case DA_BOMB:
inst.setCurrentboss(FreakyFourBoss.SNIPEE);
break;
case SNIPEE:
inst.setCurrentboss(null);
inst.forceEnd();
return;
}
} else {
return;
}
boss = inst.getCurrentboss().orElse(null);
if (!inst.getRegion(boss).contains(player.getLocation().getPosition())) {
player.setLocation(new Location<>(inst.getRegion().getExtent(), inst.getCenter(boss)));
}
inst.spawnBoss(boss);
}
示例10: onBlockBreak
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
CursedMineInstance inst = optInst.get();
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
event.setCancelled(true);
return;
}
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockType originalType = block.getOriginal().getState().getType();
if (cursedOres.contains(originalType)) {
// Check to see if the block has already been broken
// we were having some multi-firing problems
if (inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()))) {
/*if (Probability.getChance(3000)) {
ChatUtil.send(player, "You feel as though a spirit is trying to tell you something...");
player.getInventory().addItem(BookUtil.Lore.Areas.theGreatMine());
}*/
ExperienceOrb xpOrb = (ExperienceOrb) player.getWorld().createEntity(EntityTypes.EXPERIENCE_ORB, block.getOriginal().getLocation().get().getPosition());
xpOrb.offer(Keys.CONTAINED_EXPERIENCE, (70 - player.getLocation().getBlockY()) / 2);
inst.eatFood(player);
inst.poison(player, 6);
inst.ghost(player, originalType);
}
} else if (stealableFluids.contains(originalType)) {
inst.recordBlockBreak(player, new BlockRecord(block.getOriginal()));
} else {
block.setCustom(block.getOriginal());
}
}
}
示例11: onOreDrop
@Listener
public void onOreDrop(
DropItemEvent.Destruct event,
@Named(NamedCause.SOURCE) BlockSpawnCause spawnCause,
@Named(NamedCause.NOTIFIER) Player player
) {
if (!Probability.getChance(4)) {
return;
}
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> loc = optLocation.get();
Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);
if (!optInst.isPresent()) {
return;
}
CursedMineInstance inst = optInst.get();
if (!inst.hasrecordForPlayerAt(player, loc)) {
return;
}
List<ItemStackSnapshot> itemStacks = new ArrayList<>();
Iterator<Entity> entityIterator = event.getEntities().iterator();
while (entityIterator.hasNext()) {
Entity entity = entityIterator.next();
if (entity instanceof Item) {
ItemStackSnapshot snapshot = ((Item) entity).item().get();
itemStacks.add(snapshot);
entityIterator.remove();
}
}
int times = 1;
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
if (optService.isPresent()) {
ModifierService service = optService.get();
if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
times *= 2;
}
}
for (ItemStackSnapshot stackSnapshot : itemStacks) {
int quantity = Math.min(
stackSnapshot.getCount() * Probability.getRangedRandom(4, 8),
stackSnapshot.getType().getMaxStackQuantity()
);
for (int i = 0; i < times; ++i) {
ItemStack stack = stackSnapshot.createStack();
stack.setQuantity(quantity);
player.getInventory().offer(stack);
}
}
}