Search in sources :

Example 21 with EventHandler

use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.

the class PlayerListener method onPlayerJoin.

@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    teleportationService.teleportNewPlayerToFirstSpawn(player);
    management.performJoin(player);
}
Also used : Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 22 with EventHandler

use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.

the class PlayerListener method onPlayerLogin.

// Note #831: AsyncPlayerPreLoginEvent is not fired by all servers in offline mode
// e.g. CraftBukkit does not fire it. So we need to run crucial things with PlayerLoginEvent.
// Single session feature can be implemented for Spigot and CraftBukkit by canceling a kick
// event caused by "logged in from another location". The nicer way, but only for Spigot, would be
// to check in the AsyncPlayerPreLoginEvent. To support all servers, we use the less nice way.
@EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(PlayerLoginEvent event) {
    final Player player = event.getPlayer();
    final String name = player.getName();
    if (validationService.isUnrestricted(name)) {
        return;
    }
    if (onJoinVerifier.refusePlayerForFullServer(event)) {
        return;
    }
    if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
        return;
    }
    try {
        // Fast stuff
        onJoinVerifier.checkSingleSession(name);
        onJoinVerifier.checkIsValidName(name);
        // Get the auth later as this may cause the single session check to fail
        // Slow stuff
        final PlayerAuth auth = dataSource.getAuth(name);
        final boolean isAuthAvailable = auth != null;
        onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
        onJoinVerifier.checkAntibot(player, isAuthAvailable);
        onJoinVerifier.checkNameCasing(player, auth);
        onJoinVerifier.checkPlayerCountry(isAuthAvailable, event.getAddress().getHostAddress());
    } catch (FailedVerificationException e) {
        event.setKickMessage(m.retrieveSingle(e.getReason(), e.getArgs()));
        event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
        return;
    }
    teleportationService.teleportOnJoin(player);
}
Also used : Player(org.bukkit.entity.Player) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) EventHandler(org.bukkit.event.EventHandler)

Example 23 with EventHandler

use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.

the class PlayerListener method onJoinMessage.

@EventHandler(priority = EventPriority.HIGHEST)
public void onJoinMessage(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    if (settings.getProperty(RegistrationSettings.REMOVE_JOIN_MESSAGE)) {
        event.setJoinMessage(null);
        return;
    }
    String customJoinMessage = settings.getProperty(RegistrationSettings.CUSTOM_JOIN_MESSAGE);
    if (!customJoinMessage.isEmpty()) {
        event.setJoinMessage(customJoinMessage.replace("{PLAYERNAME}", player.getName()).replace("{DISPLAYNAME}", player.getDisplayName()));
    }
    if (!settings.getProperty(RegistrationSettings.DELAY_JOIN_MESSAGE)) {
        return;
    }
    String name = player.getName().toLowerCase();
    String joinMsg = event.getJoinMessage();
    // Remove the join message while the player isn't logging in
    if (joinMsg != null) {
        event.setJoinMessage(null);
        joinMessageService.putMessage(name, joinMsg);
    }
}
Also used : Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 24 with EventHandler

use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.

the class PlayerListener method onPlayerQuit.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    if (settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)) {
        event.setQuitMessage(null);
    } else if (settings.getProperty(RegistrationSettings.REMOVE_UNLOGGED_LEAVE_MESSAGE)) {
        if (listenerService.shouldCancelEvent(event)) {
            event.setQuitMessage(null);
        }
    }
    if (antiBotService.wasPlayerKicked(player.getName())) {
        return;
    }
    management.performQuit(player);
}
Also used : Player(org.bukkit.entity.Player) EventHandler(org.bukkit.event.EventHandler)

Example 25 with EventHandler

use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.

the class PlayerListener method onPlayerInventoryOpen.

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
    final HumanEntity player = event.getPlayer();
    if (listenerService.shouldCancelEvent(player)) {
        event.setCancelled(true);
        /*
             * @note little hack cause InventoryOpenEvent cannot be cancelled for
             * real, cause no packet is sent to server by client for the main inv
             */
        bukkitService.scheduleSyncDelayedTask(player::closeInventory, 1);
    }
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EventHandler (org.bukkit.event.EventHandler)409 Player (org.bukkit.entity.Player)126 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)67 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)62 Entity (org.bukkit.entity.Entity)58 Block (org.bukkit.block.Block)47 Location (org.bukkit.Location)43 Element (net.aufdemrand.denizencore.objects.Element)38 ItemStack (org.bukkit.inventory.ItemStack)33 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)31 Minigame (au.com.mineauz.minigames.minigame.Minigame)29 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)29 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)28 LivingEntity (org.bukkit.entity.LivingEntity)24 Projectile (org.bukkit.entity.Projectile)19 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)18 FPlayer (me.totalfreedom.totalfreedommod.player.FPlayer)15 BlockState (org.bukkit.block.BlockState)15 User (com.earth2me.essentials.User)14 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)14