Java Code Examples for cn.nukkit.event.EventPriority#MONITOR

The following examples show how to use cn.nukkit.event.EventPriority#MONITOR . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
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());
}
 
Example 18
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 onPlayerChat(PlayerChatEvent event) {
    event(event);
}
 
Example 19
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 20
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 onMove(PlayerMoveEvent event) {
    event(event);
}