本文整理汇总了Java中org.bukkit.event.entity.EntityEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityEvent类的具体用法?Java EntityEvent怎么用?Java EntityEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityEvent类属于org.bukkit.event.entity包,在下文中一共展示了EntityEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldAllowAuthenticatedPlayer
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldAllowAuthenticatedPlayer() {
// given
String playerName = "Bobby";
Player player = mockPlayerWithName(playerName);
given(playerCache.isAuthenticated(playerName)).willReturn(true);
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(player);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
verify(playerCache).isAuthenticated(playerName);
verifyZeroInteractions(dataSource);
}
示例2: shouldDenyUnLoggedPlayer
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldDenyUnLoggedPlayer() {
// given
String playerName = "Tester";
Player player = mockPlayerWithName(playerName);
given(playerCache.isAuthenticated(playerName)).willReturn(false);
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(player);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(true));
verify(playerCache).isAuthenticated(playerName);
// makes sure the setting is checked first = avoid unnecessary DB operation
verifyZeroInteractions(dataSource);
}
示例3: shouldAllowUnloggedPlayerForOptionalRegistration
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldAllowUnloggedPlayerForOptionalRegistration() {
// given
String playerName = "myPlayer1";
Player player = mockPlayerWithName(playerName);
given(playerCache.isAuthenticated(playerName)).willReturn(false);
given(settings.getProperty(RegistrationSettings.FORCE)).willReturn(false);
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(player);
listenerService.reload(settings);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
verify(playerCache).isAuthenticated(playerName);
verify(dataSource).isAuthAvailable(playerName);
}
示例4: shouldAllowUnrestrictedName
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldAllowUnrestrictedName() {
// given
String playerName = "Npc2";
Player player = mockPlayerWithName(playerName);
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(player);
given(validationService.isUnrestricted(playerName)).willReturn(true);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
verifyZeroInteractions(dataSource);
}
示例5: shouldAllowNpcPlayer
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldAllowNpcPlayer() {
// given
String playerName = "other_npc";
Player player = mockPlayerWithName(playerName);
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(player);
given(player.hasMetadata("NPC")).willReturn(true);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
verify(player).hasMetadata("NPC");
}
示例6: getLoggableEntityEvent
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
private LoggableCreatureEvent getLoggableEntityEvent(EntityEventAction action, EntityEvent event) {
final Entity entity = event.getEntity();
final Location location = entity.getLocation();
final World world = entity.getWorld();
Point3d coordinates = new Point3d(location.getX(), location.getY(), location.getZ());
LoggableCreatureEvent entityEvent = new LoggableCreatureEvent(world.getFullTime(), minecraft_server, world.getName(), action);
LivingEntity spCreature = new LivingEntity();
spCreature.setType("creature");
spCreature.setCurrentHealth(((org.bukkit.entity.LivingEntity)entity).getHealth());
spCreature.setMaxHealth(((org.bukkit.entity.LivingEntity)entity).getMaxHealth());
spCreature.setLocation(coordinates);
for (PotionEffect potion : (((org.bukkit.entity.LivingEntity)entity).getActivePotionEffects())) {
spCreature.addPotions(potion.getType().getName() + ":" + potion.getAmplifier());
}
if (event.getEntityType() == EntityType.SKELETON) {
Skeleton skeleton = (org.bukkit.entity.Skeleton) event.getEntity();
spCreature.setName(skeleton.getSkeletonType() + "_SKELETON");
} else {
spCreature.setName(event.getEntityType().name());
}
entityEvent.setEntity(spCreature);
return entityEvent;
}
示例7: get
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Override
@Nullable
protected Entity[] get(final Event e) {
final Entity[] one = (Entity[]) Array.newInstance(type.getType(), 1);
final Entity entity = ((EntityEvent) e).getEntity();
if (type.isInstance(entity)) {
one[0] = entity;
return one;
}
return null;
}
示例8: onEntityEvent
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Override
protected void onEntityEvent(EntityEvent event) {
Entity entity = event.getEntity();
if (entity != null) {
callEvent(entity, event);
}
else if (event instanceof EntityExplodeEvent) {
callEvent(((EntityExplodeEvent) event).getLocation(), event);
}
else {
Msg.debug("Failed to forward bukkit EntityEvent event because it has no entity.");
}
}
示例9: on
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
public void on(Object e) {
if (!(e instanceof Event))
return;
Event event = (Event) e;
onEvent(event);
if (event instanceof PlayerEvent) {
onPlayerEvent((PlayerEvent)event);
}
else if (event instanceof BlockEvent) {
onBlockEvent((BlockEvent)event);
}
else if (event instanceof HangingEvent) {
onHangingEvent((HangingEvent)event);
}
else if (event instanceof InventoryEvent) {
onInventoryEvent((InventoryEvent) event);
}
else if (event instanceof VehicleEvent) {
onVehicleEvent((VehicleEvent) event);
}
else if (event instanceof EntityEvent) {
onEntityEvent((EntityEvent) event);
}
}
示例10: mockShouldCancel
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
/**
* Mocks, based on the given event, the correct method in {@link ListenerService} to return
* the provided {@code result}.
*
* @param result the result the service should return
* @param listenerService the service to mock
* @param event the event
*/
private static void mockShouldCancel(boolean result, ListenerService listenerService, Event event) {
if (event instanceof PlayerEvent) {
given(listenerService.shouldCancelEvent((PlayerEvent) event)).willReturn(result);
} else if (event instanceof EntityEvent) {
given(listenerService.shouldCancelEvent((EntityEvent) event)).willReturn(result);
} else {
throw new IllegalStateException("Found event with unsupported type: " + event.getClass());
}
}
示例11: shouldHandleEventWithNullEntity
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldHandleEventWithNullEntity() {
// given
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(null);
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
}
示例12: shouldHandleEntityEventWithNonPlayerEntity
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Test
public void shouldHandleEntityEventWithNonPlayerEntity() {
// given
EntityEvent event = mock(EntityEvent.class);
given(event.getEntity()).willReturn(mock(Entity.class));
// when
boolean result = listenerService.shouldCancelEvent(event);
// then
assertThat(result, equalTo(false));
}
示例13: contexts
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
protected Stream<? extends BukkitFacetContext<?>> contexts(Object event) {
// Try to get some online players from the event, either directly
// through MatchPlayerEvent, or indirectly through entities.
final Set<MatchPlayer> players;
if(event instanceof MatchPlayerEvent) {
players = ((MatchPlayerEvent) event).players().collect(Collectors.toImmutableSet());
} else {
final Set<Entity> entities = new HashSet<>();
if(event instanceof EntityAction) entities.add(((EntityAction) event).getActor());
if(event instanceof EntityEvent) entities.add(((EntityEvent) event).getEntity());
if(event instanceof PlayerAction) entities.add(((PlayerAction) event).getActor());
if(event instanceof PlayerEvent) entities.add(((PlayerEvent) event).getPlayer());
players = entities.stream()
.flatMap(entity -> Streams.ofNullable(finder.getPlayer(entity)))
.collect(Collectors.toImmutableSet());
}
// If we have one or more MatchPlayers, return them along with their user contexts
if(!players.isEmpty()) {
return Stream.concat(
players.stream(),
players.stream().map(player -> player.userContext)
);
}
// If we couldn't derive any online players from the event, try for offline player UUIDs
final Set<UUID> uuids;
if(event instanceof MatchUserEvent) {
uuids = ((MatchUserEvent) event).users().collect(Collectors.toImmutableSet());
} else if(event instanceof UserEvent) {
uuids = ImmutableSet.of(((UserEvent) event).getUser().uuid());
} else {
return Stream.empty();
}
// Restrict to a specific match, if possible
final Stream<Match> matches = finder.match((Event) event)
.map(Stream::of)
.orElseGet(() -> finder.currentMatches().stream());
// Search the selected matches for both users and players
// with the selected UUIDs.
return matches.flatMap(
match -> uuids.stream().flatMap(
uuid -> Stream.concat(
Optionals.stream(match.player(uuid)),
Optionals.stream(match.userContext(uuid))
)
)
);
}
示例14: evaluate
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
@Override
public Boolean evaluate(Event event) {
if (!(event instanceof EntityDamageEvent)) {
switch (cause) {
/* Actor Type */
case WORLD:
return event instanceof WorldEvent;
case LIVING:
return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof LivingEntity;
case MOB:
return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof Creature;
case PLAYER:
return event instanceof PlayerEvent;
/* Block action */
case PUNCH:
return event instanceof BlockDamageEvent;
case TRAMPLE:
return event instanceof PlayerMoveEvent;
case MINE:
return event instanceof BlockBreakEvent;
case EXPLOSION:
return event instanceof EntityExplodeEvent;
default:
return null;
}
} else {
/* Damage Type */
EntityDamageEvent.DamageCause damageCause = ((EntityDamageEvent) event).getCause();
switch (cause) {
case MELEE:
return damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK);
case PROJECTILE:
return damageCause.equals(EntityDamageEvent.DamageCause.PROJECTILE);
case POTION:
return damageCause.equals(EntityDamageEvent.DamageCause.MAGIC)
|| damageCause.equals(EntityDamageEvent.DamageCause.POISON)
|| damageCause.equals(EntityDamageEvent.DamageCause.WITHER)
|| damageCause.equals(EntityDamageEvent.DamageCause.DRAGON_BREATH);
case EXPLOSION:
return damageCause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
|| damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
case COMBUSTION:
return damageCause.equals(EntityDamageEvent.DamageCause.FIRE)
|| damageCause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)
|| damageCause.equals(EntityDamageEvent.DamageCause.MELTING)
|| damageCause.equals(EntityDamageEvent.DamageCause.LAVA)
|| damageCause.equals(EntityDamageEvent.DamageCause.HOT_FLOOR);
case FALL:
return damageCause.equals(EntityDamageEvent.DamageCause.FALL);
case GRAVITY:
return damageCause.equals(EntityDamageEvent.DamageCause.FALL)
|| damageCause.equals(EntityDamageEvent.DamageCause.VOID);
case VOID:
return damageCause.equals(EntityDamageEvent.DamageCause.VOID);
case SQUASH:
return damageCause.equals(EntityDamageEvent.DamageCause.FALLING_BLOCK);
case SUFFOCATION:
return damageCause.equals(EntityDamageEvent.DamageCause.SUFFOCATION);
case DROWNING:
return damageCause.equals(EntityDamageEvent.DamageCause.DROWNING);
case STARVATION:
return damageCause.equals(EntityDamageEvent.DamageCause.STARVATION);
case LIGHTNING:
return damageCause.equals(EntityDamageEvent.DamageCause.LIGHTNING);
case CACTUS:
return damageCause.equals(EntityDamageEvent.DamageCause.CONTACT);
case THORNS:
return damageCause.equals(EntityDamageEvent.DamageCause.THORNS);
default:
return null;
}
}
}
示例15: callHandlers
import org.bukkit.event.entity.EntityEvent; //导入依赖的package包/类
protected void callHandlers(String eventName, EntityEvent event) {
callHandlers(eventName, event, event.getEntity());
}