Java Code Examples for org.spongepowered.api.event.network.ClientConnectionEvent#Join

The following examples show how to use org.spongepowered.api.event.network.ClientConnectionEvent#Join . 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: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST)
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    GDTimings.PLAYER_JOIN_EVENT.startTimingIfSync();
    Player player = event.getTargetEntity();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        GDTimings.PLAYER_JOIN_EVENT.stopTimingIfSync();
        return;
    }

    UUID playerID = player.getUniqueId();

    final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), playerID);
    final GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    if (claim.isInTown()) {
        playerData.inTown = true;
    }

    GDTimings.PLAYER_JOIN_EVENT.stopTimingIfSync();
}
 
Example 2
Source File: VirtualChestPlugin.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onClientConnectionJoin(ClientConnectionEvent.Join event)
{
    Server server = Sponge.getServer();
    if (server.getOnlineMode())
    {
        // prefetch the profile when a player joins the server
        // TODO: maybe we should also prefetch player profiles in offline mode
        GameProfile profile = event.getTargetEntity().getProfile();
        server.getGameProfileManager().fill(profile).thenRun(() ->
        {
            String message = "Successfully loaded the game profile for {} (player {})";
            this.logger.debug(message, profile.getUniqueId(), profile.getName().orElse("null"));
        });
    }
}
 
Example 3
Source File: SpongePingCounter.java    From Plan with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join joinEvent) {
    Player player = joinEvent.getTargetEntity();
    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 4
Source File: JailListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join event) {
    Player p = event.getTargetEntity();
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (up.get(JailKeys.JAIL).isPresent()) {
        if (Modules.JAIL.get().getConfig().get().get().getNode("teleport-on-join").getBoolean()) {
            JailData data = up.get(JailKeys.JAIL).get();
            Jail jail = GlobalData.get(JailKeys.JAILS).get().stream().filter(j -> j.getName().equalsIgnoreCase(data.getJail())).findAny().orElse(null);
            if (jail != null && jail.getLocation().isPresent()) {
                Teleportation tp = UltimateCore.get().getTeleportService().createTeleportation(p, Arrays.asList(p), jail.getLocation().get(), tel -> {
                }, (tel, reason) -> {
                }, false, true);
                tp.start();
            }
        }
    }
}
 
Example 5
Source File: DefaultListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onJoin(ClientConnectionEvent.Join event) {
    Player p = event.getTargetEntity();

    //Player file
    PlayerDataFile config = new PlayerDataFile(event.getTargetEntity().getUniqueId());
    CommentedConfigurationNode node = config.get();
    node.getNode("lastconnect").setValue(System.currentTimeMillis());
    String ip = event.getTargetEntity().getConnection().getAddress().getAddress().toString().replace("/", "");
    node.getNode("lastip").setValue(ip);
    config.save(node);

    //Ipcache file
    GlobalDataFile file = new GlobalDataFile("ipcache");
    CommentedConfigurationNode node2 = file.get();
    node2.getNode(ip, "name").setValue(p.getName());
    node2.getNode(ip, "uuid").setValue(p.getUniqueId().toString());
    file.save(node2);
}
 
Example 6
Source File: UCListener.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join e, @Getter("getTargetEntity") Player p) {
    if (!UChat.get().getConfig().root().general.persist_channels) {
        UChat.get().getDefChannel(p.getWorld().getName()).addMember(p);
    }
    if (p.hasPermission("uchat.auto-msgtoggle")) {
        UChat.get().msgTogglePlayers.remove(p.getName());
    }

    if (UChat.get().getUCJDA() != null && !p.hasPermission(UChat.get().getConfig().root().discord.vanish_perm)) {
        Task.builder().async().execute(() ->
                UChat.get().getUCJDA().sendRawToDiscord(UChat.get().getLang().get("discord.join").replace("{player}", p.getName())));
    }
    if (UChat.get().getConfig().root().general.spy_enabled_onjoin && p.hasPermission("uchat.cmd.spy") && !UChat.get().isSpy.contains(p.getName())) {
        UChat.get().isSpy.add(p.getName());
        UChat.get().getLang().sendMessage(p, "cmd.spy.enabled");
    }
}
 
Example 7
Source File: FlyListeners.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join event) {
    Player p = event.getTargetEntity();
    UltimateUser user = UltimateCore.get().getUserService().getUser(p);
    if (p.hasPermission(FlyPermissions.UC_FLY_FLY_BASE.get()) && user.get(FlyKeys.FLY).orElse(false)) {
        if (p.getLocation().add(0, -1, 0).getBlockType().equals(BlockTypes.AIR)) {
            p.offer(Keys.CAN_FLY, true);
            p.offer(Keys.IS_FLYING, true);
        }
    }
}
 
Example 8
Source File: MailListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join event) {
    UltimateUser up = UltimateCore.get().getUserService().getUser(event.getTargetEntity());
    int unreadCount = up.get(MailKeys.UNREAD_MAIL).get();
    if (unreadCount == 0) return;
    event.getTargetEntity().sendMessage(Messages.getFormatted(event.getTargetEntity(), "mail.command.mail.newmail", "%count%", unreadCount).toBuilder().onHover(TextActions.showText(Messages.getFormatted(event.getTargetEntity(), "mail.command.mail.newmail.hover"))).onClick(TextActions.runCommand("/mail read")).build());
}
 
Example 9
Source File: EntityListener.java    From Prism with MIT License 5 votes vote down vote up
/**
 * Saves event records when a player joins.
 *
 * @param event ClientConnectionEvent.Join
 */
@Listener(order = Order.POST)
public void onClientConnectionJoin(ClientConnectionEvent.Join event, @Getter("getTargetEntity") Player player) {
    if (!Prism.getInstance().getConfig().getEventCategory().isPlayerJoin()) {
        return;
    }

    PrismRecord.create()
            .player(player)
            .event(PrismEvents.PLAYER_JOIN)
            .location(player.getLocation())
            .buildAndSave();
}
 
Example 10
Source File: ServerlistListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LATE)
public void onJoin(ClientConnectionEvent.Join event) {
    try {
        Player p = event.getTargetEntity();
        ModuleConfig config = Modules.SERVERLIST.get().getConfig().get();
        //Join motd
        if (config.get().getNode("joinmessage", "enable").getBoolean()) {
            List<String> joinmsgs = config.get().getNode("joinmessage", "joinmessages").getList(TypeToken.of(String.class));
            Text joinmsg = VariableUtil.replaceVariables(Messages.toText(joinmsgs.get(random.nextInt(joinmsgs.size()))), p);
            p.sendMessage(joinmsg);
        }
    } catch (ObjectMappingException e) {
        ErrorLogger.log(e, "Failed to construct join message.");
    }
}
 
Example 11
Source File: TablistListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join event) {
    Sponge.getScheduler().createTaskBuilder().delayTicks(20L).execute(() -> {
        TablistModule module = (TablistModule) Modules.TABLIST.get();
        NamesHandler runnable = module.getRunnable();
        runnable.update();
    }).submit(UltimateCore.get());
}
 
Example 12
Source File: UpdateListener.java    From ViaVersion with MIT License 5 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join join) {
    if (join.getTargetEntity().hasPermission("viaversion.update")
            && Via.getConfig().isCheckForUpdates()) {
        UpdateUtil.sendUpdateMessage(join.getTargetEntity().getUniqueId());
    }
}
 
Example 13
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.POST)
public void onJoin(ClientConnectionEvent.Join event) {
    try {
        actOnJoinEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example 14
Source File: PlayerJoinListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
    public void onPlayerJoin(final ClientConnectionEvent.Join event, final @Root Player player)
    {
        CompletableFuture.runAsync(() -> {
            if (player.hasPermission(PluginPermissions.VERSION_NOTIFY) && !VersionChecker.isLatest(PluginInfo.VERSION))
                player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.A_NEW_VERSION_OF + " ", TextColors.AQUA, "Eagle Factions", TextColors.GREEN, " " + Messages.IS_AVAILABLE));

            //Create player file and set power if player does not exist.
            if (!super.getPlugin().getPlayerManager().getFactionPlayer(player.getUniqueId()).isPresent())
                super.getPlugin().getPlayerManager().addPlayer(player.getUniqueId(), player.getName()); //Maybe we could add loadCache method instead?

//            super.getPlugin().getPlayerManager().addPlayer(player.getUniqueId(), player.getName());

//            super.getPlugin().getPlayerManager().updatePlayerName(player.getUniqueId(), player.getName());
            super.getPlugin().getPowerManager().startIncreasingPower(player.getUniqueId());


            //Check if the world that player is connecting to is already in the config file
            if (!this.protectionConfig.getDetectedWorldNames().contains(player.getWorld().getName()))
                this.protectionConfig.addWorld(player.getWorld().getName());

            //Send motd
            final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
            if(optionalPlayerFaction.isPresent() && !optionalPlayerFaction.get().getMessageOfTheDay().equals(""))
            {
                player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.FACTION_MESSAGE_OF_THE_DAY, TextColors.RESET, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, optionalPlayerFaction.get().getName()))), Text.of(optionalPlayerFaction.get().getMessageOfTheDay())));
            }
        });
    }
 
Example 15
Source File: SpongePlugin.java    From BungeeTabListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Listener
public void onConnect(ClientConnectionEvent.Join event) {
    bridge.onPlayerConnect(event.getTargetEntity());
}
 
Example 16
Source File: WebHookService.java    From Web-API with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    notifyHooks(WebHookService.WebHookType.PLAYER_JOIN, event);
}
 
Example 17
Source File: CacheService.java    From Web-API with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    updatePlayer(event.getTargetEntity());
}
 
Example 18
Source File: Sponge4ArmorListener.java    From ViaVersion with MIT License 4 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join e) {
    sendArmorUpdate(e.getTargetEntity());
}
 
Example 19
Source File: Sponge5ArmorListener.java    From ViaVersion with MIT License 4 votes vote down vote up
@Listener
public void onJoin(ClientConnectionEvent.Join e) {
    sendArmorUpdate(e.getTargetEntity());
}
 
Example 20
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void actOnJoinEvent(ClientConnectionEvent.Join event) {
    Player player = event.getTargetEntity();

    UUID playerUUID = player.getUniqueId();
    UUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    JSONCache.invalidate(DataID.SERVER_OVERVIEW, serverUUID);
    JSONCache.invalidate(DataID.GRAPH_PERFORMANCE, serverUUID);

    SpongeAFKListener.AFK_TRACKER.performedAction(playerUUID, time);

    String world = player.getWorld().getName();
    Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
    String gm = gameMode.map(mode -> mode.getName().toUpperCase()).orElse("ADVENTURE");

    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));

    InetAddress address = player.getConnection().getAddress().getAddress();

    String playerName = player.getName();
    String displayName = player.getDisplayNameData().displayName().get().toPlain();

    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(
                new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
        );
    }

    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time, playerName, serverUUID));
    Session session = new Session(playerUUID, serverUUID, time, world, gm);
    session.putRawData(SessionKeys.NAME, playerName);
    session.putRawData(SessionKeys.SERVER_NAME, serverInfo.getServer().getIdentifiableName());
    sessionCache.cacheSession(playerUUID, session)
            .ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));

    database.executeTransaction(new NicknameStoreTransaction(
            playerUUID, new Nickname(displayName, time, serverUUID),
            (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)
    ));

    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}