java类org.bukkit.event.player.PlayerEvent的实例源码

FuncCooldown.java 文件源码 项目:GenericTools 阅读 25 收藏 0 点赞 0 评论 0
@Override
public WrappedEvent<?> accept(WrappedEvent<?> we) {
    long cdEndTime = 0;
    if (we.wis.hasKey("giSection.cooldown-" + cooldownId))
        cdEndTime = Long.parseLong(we.wis.getString("giSection.cooldown-" + cooldownId));
    long sysTime = System.currentTimeMillis();
    long delta = sysTime - cdEndTime;
    if (delta < 0) {
        if (we.event instanceof PlayerEvent) {
            ((PlayerEvent) we.event).getPlayer().sendMessage(I18n.format("function_help.cooldown.cd_not_end", -delta/1000.0));
        }
        we.cancelled = true;
    } else {
        we.wis.setString("giSection.cooldown-" + cooldownId, Long.toString(sysTime + cooldown * 1000));
    }
    return we;
}
InventoryListener.java 文件源码 项目:RPGInventory 阅读 28 收藏 0 点赞 0 评论 0
private void onItemDisappeared(PlayerEvent event, ItemStack item) {
    final Player player = event.getPlayer();
    final PlayerInventory inventory = player.getInventory();
    final int slotId = inventory.getHeldItemSlot();

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    if (ItemUtils.isEmpty(inventory.getItemInMainHand()) || item.equals(inventory.getItemInMainHand())) {
        final Slot slot = InventoryManager.getQuickSlot(slotId);
        if (slot != null) {
            new BukkitRunnable() {
                @Override
                public void run() {
                    InventoryUtils.heldFreeSlot(player, slotId, InventoryUtils.SearchType.NEXT);
                    inventory.setItem(slotId, slot.getCup());
                }
            }.runTaskLater(RPGInventory.getInstance(), 1);
        }
    }
}
ArenaEventForwarder.java 文件源码 项目:PV-Star 阅读 27 收藏 0 点赞 0 评论 0
@Override
protected void onPlayerEvent(PlayerEvent event) {

    if (event instanceof PlayerInteractEvent) {
        PlayerInteractEvent interactEvent = (PlayerInteractEvent) event;

        if (interactEvent.hasBlock()) {
            callEvent(interactEvent.getClickedBlock(), event);
        } else {
            callEvent(interactEvent.getPlayer(), event);
        }
    }
    else {
        callEvent(event.getPlayer(), event);
    }
}
ListenerServiceTest.java 文件源码 项目:AuthMeReloaded 阅读 26 收藏 0 点赞 0 评论 0
@Test
// This simply forwards to shouldCancelEvent(Player), so the rest is already tested
public void shouldHandlePlayerEvent() {
    // given
    String playerName = "example";
    Player player = mockPlayerWithName(playerName);
    PlayerEvent event = new TestPlayerEvent(player);
    given(playerCache.isAuthenticated(playerName)).willReturn(true);

    // when
    boolean result = listenerService.shouldCancelEvent(event);

    // then
    assertThat(result, equalTo(false));
    verify(playerCache).isAuthenticated(playerName);
    verifyZeroInteractions(dataSource);
}
EventAttachment.java 文件源码 项目:Lukkit 阅读 27 收藏 0 点赞 0 评论 0
public void call(Event event) {
    for (Map.Entry<Class<?>, LuaValue> entry : eventListeners.entrySet()) {
        if (entry.getKey() == event.getClass()) {
            if (event instanceof PlayerEvent) {
                entry.getValue().call(new PlayerEventType((PlayerEvent) event));
            } else {
                entry.getValue().call(new EventType(event));
            }
        }
    }
}
ProfileListener.java 文件源码 项目:Chambers 阅读 26 收藏 0 点赞 0 评论 0
private void removeProfile(PlayerEvent event) {
    Player player = event.getPlayer();
    Game game = plugin.getGameManager().getGame();
    Profile profile = plugin.getProfileManager().getProfileByUuid(player.getUniqueId());
    if (profile != null && profile.getTeam() != null) {
        if (game.hasStarted()) {
            plugin.getGameManager().getGame().getOffline().add(player.getName());
            profile.getTeam().getOffline().add(player.getName());
        }
        profile.getTeam().removeMember(profile);
    }
    plugin.getProfileManager().removeProfile(profile);
}
UserQuitJoinListener.java 文件源码 项目:Minecordbot 阅读 34 收藏 0 点赞 0 评论 0
private boolean check(PlayerEvent e) {
    boolean allowIncog = configsManager.getBroadcastConfig().getBoolean("Hide_Incognito_Player");
    if (isVanished(e.getPlayer())) {
        return false;
    } else if (allowIncog) {
        if (e.getPlayer().hasPermission("minecordbot.incognito")) {
            return false;
        }
    }
    return true;
}
UserQuitJoinListener.java 文件源码 项目:Minecordbot 阅读 23 收藏 0 点赞 0 评论 0
private boolean safeToProceed(PlayerEvent event) {
    boolean safe = true;
    if (event instanceof PlayerJoinEvent) {
        if (((PlayerJoinEvent) event).getJoinMessage() == null && ((PlayerJoinEvent) event).getJoinMessage().isEmpty()) {
            safe = false;
            Logger.warn("The previous PlayerJoinEvent message was missing!");
        }
    } else if (event instanceof PlayerQuitEvent) {
        if (((PlayerQuitEvent) event).getQuitMessage() == null && ((PlayerQuitEvent) event).getQuitMessage().isEmpty()) {
            safe = false;
            Logger.warn("The previous PlayerQuitEvent message was missing!");
        }
    }
    return safe;
}
EventCanceler.java 文件源码 项目:BeeLogin 阅读 27 收藏 0 点赞 0 评论 0
@EventHandler(priority = EventPriority.LOWEST)
public void anyPlayerEvent(PlayerEvent event){
    if(!(event instanceof Cancellable))
        return;
    if (!usingBeeLoginMod)
        return;
    Player player = event.getPlayer();
    if (!loginStatus.get(player.getName().toLowerCase())) {
        ((Cancellable) event).setCancelled(true);
    }
}
GamemodeManager.java 文件源码 项目:Spigot-Plus 阅读 27 收藏 0 点赞 0 评论 0
private void forceGamemode(PlayerEvent evt) {
    if (!evt.getPlayer().hasPermission("spigotplus.gamemode.exempt")) {
        GameMode gamemode = getWorldGamemode(evt.getPlayer().getWorld().getName());
        if (!evt.getPlayer().getGameMode().equals(gamemode)) {
            evt.getPlayer().setGameMode(gamemode);
        }
    }
}
BukkitEventForwarder.java 文件源码 项目:NucleusFramework 阅读 27 收藏 0 点赞 0 评论 0
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);
            }
        }
JoinRequester.java 文件源码 项目:HeavySpleef 阅读 24 收藏 0 点赞 0 评论 0
private void handleQuit(PlayerEvent event) {
    SpleefPlayer player = heavySpleef.getSpleefPlayer(event.getPlayer());
    if (!checking.containsKey(player)) {
        return;
    }

    handleFail(player, FailCause.QUIT, null);
}
EventReplacer.java 文件源码 项目:ScoreboardStats 阅读 26 收藏 0 点赞 0 评论 0
private void executeUnsafe(ReplacerAPI replaceManager, T event) {
    String variable = replacer.getVariable();
    for (Function<T, Integer> function : scoreFunctions) {
        int newScore = function.apply(event);
        if (replacer.isGlobal()) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                replaceManager.forceUpdate(player, variable, newScore);
            }
        } else if (event instanceof PlayerEvent) {
            replaceManager.forceUpdate(((PlayerEvent) event).getPlayer(), variable, newScore);
        }
    }
}
SpectatorsInteractionsListener.java 文件源码 项目:SpectatorPlus 阅读 26 收藏 0 点赞 0 评论 0
@FutureEventHandler(event = "player.PlayerSwapHandItemsEvent", priority = EventPriority.HIGHEST)
public void onPlayerSwapHandItems(WrappedEvent ev)
{
    if(SpectatorPlus.get().getPlayerData(((PlayerEvent) ev.getEvent()).getPlayer()).isSpectating())
    {
        ev.setCancelled(true);
    }
}
EventCancelVerifier.java 文件源码 项目:AuthMeReloaded 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 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());
    }
}
ListenerServiceTest.java 文件源码 项目:AuthMeReloaded 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void shouldHandlePlayerEventWithNullPlayer() {
    // given
    PlayerEvent event = new TestPlayerEvent(null);

    // when
    boolean result = listenerService.shouldCancelEvent(event);

    // then
    assertThat(result, equalTo(false));
}
BukkitGroupManager.java 文件源码 项目:Core-Bukkit 阅读 35 收藏 0 点赞 0 评论 0
private synchronized void processEvent(PlayerEvent event) {

    MQPlayer player = Managers.getPlatform().toPlayer(event.getPlayer());

    long team = indexOf(player);
    if (team != -1) {
        try {
            groups.get(team).remove(player);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
PlayerEventType.java 文件源码 项目:Lukkit 阅读 19 收藏 0 点赞 0 评论 0
public PlayerEventType(PlayerEvent e) {
    super(e);
    set("player", new PlayerType(new LuaAccessor(e.getPlayer())));
}
MatchPlayerEventRouter.java 文件源码 项目:ProjectAres 阅读 42 收藏 0 点赞 0 评论 0
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))
            )
        )
    );
}
ClaimProfileListener.java 文件源码 项目:Chambers 阅读 36 收藏 0 点赞 0 评论 0
public void removeClaimProfile(PlayerEvent event) {
    Profile profile = Chambers.getInstance().getProfileManager().getProfileByUuid(event.getPlayer().getUniqueId());
    if (Chambers.getInstance().getClaimManager().isClaiming(profile)) {
        Chambers.getInstance().getClaimManager().removeClaimProfile(profile);
    }
}
SessionHelperInterface.java 文件源码 项目:Blur 阅读 32 收藏 0 点赞 0 评论 0
default boolean isSession(@Nonnull PlayerEvent playerEvent) {
    Preconditions.checkNotNull(playerEvent, "playerEvent cannot be null.");
    return isSession(getPlayer(playerEvent.getPlayer()).getSession());
}
InPlot.java 文件源码 项目:ConditionalPerms 阅读 24 收藏 0 点赞 0 评论 0
@Override
public void setup(TerminableConsumer consumer) {
    Events.merge(PlayerEvent.class, PlayerEnterPlotEvent.class, PlayerLeavePlotEvent.class)
            .handler(e -> getPlugin().refreshPlayer(e.getPlayer(), 5L))
            .bindWith(consumer);
}
InOwnPlot.java 文件源码 项目:ConditionalPerms 阅读 36 收藏 0 点赞 0 评论 0
@Override
public void setup(TerminableConsumer consumer) {
    Events.merge(PlayerEvent.class, PlayerEnterPlotEvent.class, PlayerLeavePlotEvent.class)
            .handler(e -> getPlugin().refreshPlayer(e.getPlayer(), 5L))
            .bindWith(consumer);
}
InRegion.java 文件源码 项目:ConditionalPerms 阅读 27 收藏 0 点赞 0 评论 0
@Override
public void setup(TerminableConsumer consumer) {
    Events.merge(PlayerEvent.class, PlayerEnterRegionEvent.class, PlayerLeaveRegionEvent.class)
            .handler(e -> getPlugin().refreshPlayer(e.getPlayer(), 1L))
            .bindWith(consumer);
}
CauseFilter.java 文件源码 项目:Cardinal 阅读 22 收藏 0 点赞 0 评论 0
@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;
    }
  }
}
Messenger.java 文件源码 项目:Minecordbot-v0-obsolete 阅读 22 收藏 0 点赞 0 评论 0
public void relayToDiscord(Event e, String msg) {
    String author = ((PlayerEvent) e).getPlayer().getName();
    for (String s : instance.getBotConfig().BINDED_CHANNELS)
        instance.getJda().getTextChannelById(s).sendMessage("**" + instance.getBotConfig().MESSAGE_PREFIX_DISCORD + " ~ " + "[" + author + "]:**  " + msg).queue();
    instance.getLogger().info(author + " > discord: " + msg);
}
SessionHelperInterface.java 文件源码 项目:Blur 阅读 25 收藏 0 点赞 0 评论 0
default boolean isSession(@Nonnull PlayerEvent playerEvent) {
    Preconditions.checkNotNull(playerEvent, "playerEvent cannot be null.");
    return isSession(getPlayer(playerEvent.getPlayer()).getSession());
}
BukkitImageListener.java 文件源码 项目:FastAsyncWorldedit 阅读 25 收藏 0 点赞 0 评论 0
private void handleInteract(PlayerEvent event, Entity entity, boolean primary) {
    handleInteract(event, event.getPlayer(), entity, primary);
}
ArenaBase.java 文件源码 项目:quick-game-framework 阅读 23 收藏 0 点赞 0 评论 0
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerEvent(PlayerEvent evt) {
    checkLocation(evt.getPlayer().getLocation(), evt);
}
CauseFilter.java 文件源码 项目:CardinalPGM 阅读 22 收藏 0 点赞 0 评论 0
private Boolean evaluate(Event event) {
    if (!(event instanceof EntityDamageEvent)) {
        switch (cause) {
            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 || event instanceof BlockPlaceEvent || event instanceof BlockBreakEvent;

            case PUNCH:
                return event instanceof PlayerInteractEvent
                        && ((PlayerInteractEvent) event).getAction().equals(Action.LEFT_CLICK_BLOCK);
            case TRAMPLE:
                return event instanceof PlayerMoveEvent;
            case MINE:
                return event instanceof BlockBreakEvent;

            case EXPLOSION:
                return event instanceof EntityExplodeEvent;
        }
    } else {
        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);
        }
    }
    return null;
}


问题


面经


文章

微信
公众号

扫码关注公众号