cn.nukkit.event.EventPriority Java Examples

The following examples show how to use cn.nukkit.event.EventPriority. 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: WorldEditListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
    final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
    final World world = player.getWorld();
    final WorldEdit we = WorldEdit.getInstance();
    final Block clickedBlock = event.getBlock();
    final WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
    if (we.handleBlockLeftClick(player, pos)) {
        event.setCancelled(true);
    }
    if (we.handleArmSwing(player)) {
        event.setCancelled(true);
    }
}
 
Example #2
Source File: BrushListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    if ((from.getYaw() != to.getYaw() &&  from.getPitch() != to.getPitch()) || from.getFloorX() != to.getFloorX() || from.getFloorZ() != to.getFloorZ() || from.getFloorY() != to.getFloorY()) {
        Player nukkitPlayer = event.getPlayer();
        FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
        com.sk89q.worldedit.entity.Player player = fp.getPlayer();
        LocalSession session = fp.getSession();
        Tool tool = session.getTool(player);
        if (tool != null) {
            if (tool instanceof MovableTool) {
                ((MovableTool) tool).move(player);
            }
        }
    }
}
 
Example #3
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * PlayerKickEvent Listener.
 * <p>
 * Adds processing information to the ProcessingQueue.
 * After KickEvent, the QuitEvent is automatically called.
 *
 * @param event Fired event
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
    try {
        if (!status.areKicksCounted() || event.isCancelled()) {
            return;
        }
        UUID uuid = event.getPlayer().getUniqueId();
        if (NukkitAFKListener.AFK_TRACKER.isAfk(uuid)) {
            return;
        }

        dbSystem.getDatabase().executeTransaction(new KickStoreTransaction(uuid));
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #4
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onMobDeath(EntityDeathEvent event) {
    long time = System.currentTimeMillis();
    Entity dead = event.getEntity();

    try {
        EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
        if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) {
            return;
        }

        EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent;
        Entity killerEntity = entityDamageByEntityEvent.getDamager();

        handleKill(time, /* Not a player */ null, killerEntity);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build());
    }
}
 
Example #5
Source File: DeathEventListener.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) {
    long time = System.currentTimeMillis();
    Player dead = event.getEntity();
    SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(Session::died);

    try {
        EntityDamageEvent entityDamageEvent = dead.getLastDamageCause();
        if (!(entityDamageEvent instanceof EntityDamageByEntityEvent)) {
            return;
        }

        EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entityDamageEvent;
        Entity killerEntity = entityDamageByEntityEvent.getDamager();

        UUID uuid = dead.getUniqueId();
        handleKill(time, uuid, killerEntity);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, dead).build());
    }
}
 
Example #6
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerPreLoginMonitor(PlayerAsyncPreLoginEvent e) {
    /* Listen to see if the event was cancelled after we initially handled the connection
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW.
    if (this.deniedAsyncLogin.remove(e.getUuid())) {
        // their data was never loaded at LOW priority, now check to see if they have been magically allowed since then.

        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (e.getLoginResult() == PlayerAsyncPreLoginEvent.LoginResult.SUCCESS) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getUuid());
            e.disAllow("");
        }
    }
}
 
Example #7
Source File: BrushListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
    Player nukkitPlayer = event.getPlayer();
    if (nukkitPlayer.isSneaking()) {
        if (event.getAction() == PlayerInteractEvent.Action.PHYSICAL) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
        com.sk89q.worldedit.entity.Player player = fp.getPlayer();
        LocalSession session = fp.getSession();
        Tool tool = session.getTool(player);
        if (tool instanceof ResettableTool) {
            if (((ResettableTool) tool).reset()) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example #8
Source File: WorldEditListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called when a player attempts to use a command
 *
 * @param event Relevant event details
 */
@EventHandler(ignoreCancelled = true,priority = EventPriority.MONITOR)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    String[] split = event.getMessage().split(" ");

    if (split.length > 0) {
        split[0] = split[0].substring(1);
        split = WorldEdit.getInstance().getPlatformManager().getCommandManager().commandDetection(split);
    }
    final String newMessage = "/" + StringUtil.joinString(split, " ");

    if (!newMessage.equals(event.getMessage())) {
        event.setMessage(newMessage);
        plugin.getServer().getPluginManager().callEvent(event);
        if (!event.isCancelled()) {
            if (!event.getMessage().isEmpty()) {
                plugin.getServer().dispatchCommand(event.getPlayer(), event.getMessage().substring(1));
            }

            event.setCancelled(true);
        }
    }
}
 
Example #9
Source File: WorldEditListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true,priority = EventPriority.LOWEST)
public void onPlayerChat(PlayerChatEvent event) {
    String message = event.getMessage();
    if (message.charAt(0) == '.') {
        String[] split = event.getMessage().split(" ");
        if (split.length > 0) {
            split[0] = split[0].substring(1).replace('.', '/');
            CommandManager cmdMan = WorldEdit.getInstance().getPlatformManager().getCommandManager();
            split = cmdMan.commandDetection(split);
            CommandEvent cmdEvent = new CommandEvent(plugin.wrapCommandSender(event.getPlayer()), Joiner.on(" ").join(Arrays.asList(split)));
            if (cmdMan.getDispatcher().contains(split[0])) {
                WorldEdit.getInstance().getEventBus().post(cmdEvent);
                event.setCancelled(true);
            }
        }
    }
}
 
Example #10
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLoginMonitor(PlayerLoginEvent e) {
    /* Listen to see if the event was cancelled after we initially handled the login
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
    if (this.deniedLogin.remove(e.getPlayer().getUniqueId())) {
        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (!e.isCancelled()) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getPlayer().getUniqueId());
            e.setCancelled();
        }
    }
}
 
Example #11
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
    final Player player = e.getPlayer();

    // https://github.com/lucko/LuckPerms/issues/2269
    if (player.getUniqueId() == null) {
        return;
    }

    handleDisconnect(player.getUniqueId());

    // perform unhooking from nukkit objects 1 tick later.
    // this allows plugins listening after us on MONITOR to still have intact permissions data
    this.plugin.getBootstrap().getServer().getScheduler().scheduleDelayedTask(this.plugin.getBootstrap(), () -> {
        // Remove the custom permissible
        try {
            PermissibleInjector.uninject(player, true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // Handle auto op
        if (this.plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
            player.setOp(false);
        }

        // remove their contexts cache
        this.plugin.getContextManager().onPlayerQuit(player);
    }, 1, true);
}
 
Example #12
Source File: BrushListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) {
    Player nukkitPlayer = event.getPlayer();
    if (nukkitPlayer.isSneaking()) {
        return;
    }
    FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
    com.sk89q.worldedit.entity.Player player = fp.getPlayer();
    LocalSession session = fp.getSession();
    Tool tool = session.getTool(player);
    if (tool instanceof ScrollTool) {
        final int slot = event.getInventorySlot();
        final int oldSlot = event.getSlot();
        final int ri;
        if ((((slot - oldSlot) <= 4) && ((slot - oldSlot) > 0)) || (((slot - oldSlot) < -4))) {
            ri = 1;
        } else {
            ri = -1;
        }
        ScrollTool scrollable = (ScrollTool) tool;
        if (scrollable.increment(player, ri)) {
            final PlayerInventory inv = nukkitPlayer.getInventory();
            final Item item = inv.getItem(slot);
            final Item newItem = inv.getItem(oldSlot);
            inv.setItem(slot, newItem);
            inv.setItem(oldSlot, item);
            inv.sendContents(nukkitPlayer);
        }
    }
}
 
Example #13
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPlayerPreLogin(PlayerAsyncPreLoginEvent e) {
    /* Called when the player first attempts a connection with the server.
       Listening on LOW priority to allow plugins to modify username / UUID data here. (auth plugins)
       Also, give other plugins a chance to cancel the event. */

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing pre-login for " + e.getUuid() + " - " + e.getName());
    }

    if (e.getLoginResult() != PlayerAsyncPreLoginEvent.LoginResult.SUCCESS) {
        // another plugin has disallowed the login.
        this.plugin.getLogger().info("Another plugin has cancelled the connection for " + e.getUuid() + " - " + e.getName() + ". No permissions data will be loaded.");
        this.deniedAsyncLogin.add(e.getUuid());
        return;
    }

    /* Actually process the login for the connection.
       We do this here to delay the login until the data is ready.
       If the login gets cancelled later on, then this will be cleaned up.

       This includes:
       - loading uuid data
       - loading permissions
       - creating a user instance in the UserManager for this connection.
       - setting up cached data. */
    try {
        User user = loadUser(e.getUuid(), e.getName());
        recordConnection(e.getUuid());
        this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUuid(), e.getName(), user);
    } catch (Exception ex) {
        this.plugin.getLogger().severe("Exception occurred whilst loading data for " + e.getUuid() + " - " + e.getName());
        ex.printStackTrace();

        // deny the connection
        this.deniedAsyncLogin.add(e.getUuid());
        e.disAllow(Message.LOADING_DATABASE_ERROR.asString(this.plugin.getLocaleManager()));
        this.plugin.getEventDispatcher().dispatchPlayerLoginProcess(e.getUuid(), e.getName(), null);
    }
}
 
Example #14
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
    try {
        actOnJoinEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #15
Source File: WorldCalculator.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldChange(EntityLevelChangeEvent e) {
    if (e.getEntity() instanceof Player) {
        Player player = (Player) e.getEntity();
        this.plugin.getContextManager().signalContextUpdate(player);
    }
}
 
Example #16
Source File: GameModeChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onGameModeChange(PlayerGameModeChangeEvent event) {
    if (event.isCancelled()) {
        return;
    }
    try {
        actOnEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event, event.getPlayer().getGamemode() + "->" + event.getNewGamemode()).build());
    }
}
 
Example #17
Source File: ChatListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onChat(PlayerChatEvent event) {
    if (event.isCancelled()) {
        return;
    }

    try {
        actOnChatEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #18
Source File: WorldChangeListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldChange(EntityLevelChangeEvent event) {
    if (event.getEntity() instanceof Player) {
        try {
            actOnEvent(event);
        } catch (Exception e) {
            errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
        }
    }
}
 
Example #19
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
    try {
        actOnQuitEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #20
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void beforePlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_LEAVE));
}
 
Example #21
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
    try {
        UUID playerUUID = event.getPlayer().getUniqueId();
        boolean operator = event.getPlayer().isOp();
        dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, operator));
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #22
Source File: NukkitAFKListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
    event(event);
    boolean isAfkCommand = event.getMessage().substring(1).toLowerCase().startsWith("afk");
    if (isAfkCommand) {
        UUID uuid = event.getPlayer().getUniqueId();
        AFK_TRACKER.usedAfkCommand(uuid, System.currentTimeMillis());
    }
}
 
Example #23
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #24
Source File: PluginManager.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #25
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #26
Source File: RegisteredListener.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #27
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public EventPriority getPriority() {
    return priority;
}
 
Example #28
Source File: WorldEditListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGamemode(PlayerGameModeChangeEvent event) {
    // this will automatically refresh their session, we don't have to do anything
    WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
}
 
Example #29
Source File: NukkitConnectionListener.java    From LuckPerms with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerLogin(PlayerLoginEvent e) {
    /* Called when the player starts logging into the server.
       At this point, the users data should be present and loaded. */

    final Player player = e.getPlayer();

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing login for " + player.getUniqueId() + " - " + player.getName());
    }

    final User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());

    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(player.getUniqueId());

        if (!getUniqueConnections().contains(player.getUniqueId())) {
            this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
                    " doesn't have data pre-loaded, they have never been processed during pre-login in this session." +
                    " - denying login.");
        } else {
            this.plugin.getLogger().warn("User " + player.getUniqueId() + " - " + player.getName() +
                    " doesn't currently have data pre-loaded, but they have been processed before in this session." +
                    " - denying login.");
        }

        e.setCancelled();
        e.setKickMessage(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager()));
        return;
    }

    // User instance is there, now we can inject our custom Permissible into the player.
    // Care should be taken at this stage to ensure that async tasks which manipulate nukkit data check that the player is still online.
    try {
        // Make a new permissible for the user
        LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this.plugin);

        // Inject into the player
        PermissibleInjector.inject(player, lpPermissible);

    } catch (Throwable t) {
        this.plugin.getLogger().warn("Exception thrown when setting up permissions for " +
                player.getUniqueId() + " - " + player.getName() + " - denying login.");
        t.printStackTrace();

        e.setCancelled();
        e.setKickMessage(Message.LOADING_SETUP_ERROR.asString(this.plugin.getLocaleManager()));
        return;
    }

    this.plugin.getContextManager().signalContextUpdate(player);
}
 
Example #30
Source File: NukkitAFKListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onLeave(PlayerQuitEvent event) {
    ignorePermissionInfo.remove(event.getPlayer().getUniqueId());
}