cn.nukkit.event.EventHandler Java Examples

The following examples show how to use cn.nukkit.event.EventHandler. 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: 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 #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 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 #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 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 #6
Source File: NukkitPingCounter.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPlayerJoin(PlayerJoinEvent joinEvent) {
    Player player = joinEvent.getPlayer();
    Long pingDelay = config.get(TimeSettings.PING_PLAYER_LOGIN_DELAY);
    if (pingDelay >= TimeUnit.HOURS.toMillis(2L)) {
        return;
    }
    runnableFactory.create("Add Player to Ping list", new AbsRunnable() {
        @Override
        public void run() {
            if (player.isOnline()) {
                addPlayer(player);
            }
        }
    }).runTaskLater(TimeAmount.toTicks(pingDelay, TimeUnit.MILLISECONDS));
}
 
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
Source File: EventListener.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    for (Player p : api.getServer().getOnlinePlayers().values()) {
        if (api.isVanished(p)) {
            player.hidePlayer(p);
        }
        if (api.isVanished(player)) {
            p.hidePlayer(player);
        }
    }
}
 
Example #13
Source File: FaweNukkit.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
	Player player = event.getPlayer();
       FawePlayer fp = Fawe.get().getCachedPlayer(player.getName());
       if (fp != null) {
           fp.unregister();
       }
       Fawe.get().unregister(event.getPlayer().getName());
}
 
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: EventListener.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
    Player player = event.getPlayer();
    if (api.isMuted(player)) {
        event.setCancelled();
        player.sendMessage(Language.translate("commands.generic.muted", api.getUnmuteTimeMessage(player)));
    }
}
 
Example #18
Source File: EventListener.java    From EssentialsNK with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerChat(PlayerChatEvent event) {
    Player player = event.getPlayer();
    if (api.isMuted(player)) {
        event.setCancelled();
        player.sendMessage(Language.translate("commands.generic.muted", api.getUnmuteTimeMessage(player)));
    }
}
 
Example #19
Source File: NukkitCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsoleCommand(ServerCommandEvent e) {
    if (!(e.getSender() instanceof ConsoleCommandSender)) {
        return;
    }

    String buffer = e.getCommand();
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        return;
    }

    buffer = buffer.substring(1);

    String commandLabel;
    int firstSpace = buffer.indexOf(' ');
    if (firstSpace == -1) {
        commandLabel = buffer;
    } else {
        commandLabel = buffer.substring(0, firstSpace);
    }

    Command command = this.plugin.getBootstrap().getServer().getCommandMap().getCommand(commandLabel);
    if (command != this.command) {
        return;
    }

    e.setCommand(buffer);
}
 
Example #20
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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
Source File: EconomyAPI.java    From EconomyAPI with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onJoin(PlayerJoinEvent event){
	this.createAccount(event.getPlayer());
}