@Nullable @Override protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { if (!args.hasNext() && this.self) { if (source instanceof RemoteSource) { return ((RemoteSource) source).getConnection().getAddress().getAddress(); } else { throw args.createError(Text.of("No IP address was specified!")); } } CommandArgs.Snapshot state = args.getSnapshot(); String s = args.next(); try { return InetAddress.getByName(s); } catch (UnknownHostException e) { try { return ((Player) this.possiblePlayer.parseValue(source, args)).getConnection().getAddress().getAddress(); } catch (ArgumentParseException ex) { if (this.self && source instanceof RemoteSource) { args.applySnapshot(state); return ((RemoteSource) source).getConnection().getAddress().getAddress(); } throw args.createError(Text.of("Invalid IP address!")); } } }
private int getPing(Player player) { return player.getConnection().getLatency(); }
public Account(Player player, String password) { this(player.getUniqueId(), player.getName(), password, player.getConnection().getAddress().getAddress()); }
public CachedPlayer(Player player) { super(player); this.uuid = UUID.fromString(player.getUniqueId().toString()); this.name = player.getName(); this.isOnline = true; this.location = new CachedLocation(player.getLocation()); this.rotation = player.getRotation().clone(); this.velocity = player.getVelocity().clone(); this.scale = player.getScale().clone(); this.address = player.getConnection().getAddress().toString(); this.latency = player.getConnection().getLatency(); // Collect unlocked advancements for (AdvancementTree tree : player.getUnlockedAdvancementTrees()) { addUnlockedAdvancements(player, tree.getRootAdvancement()); } // This will be moved to the other constructor once Sponge implements the offline inventory API this.helmet = player.getHelmet().map(ItemStack::copy).orElse(null); this.chestplate = player.getChestplate().map(ItemStack::copy).orElse(null); this.leggings = player.getLeggings().map(ItemStack::copy).orElse(null); this.boots = player.getBoots().map(ItemStack::copy).orElse(null); this.inventory = new CachedInventory(player.getInventory()); }
private void actOnJoinEvent(ClientConnectionEvent.Join event) { Player player = event.getTargetEntity(); UUID uuid = player.getUniqueId(); long time = System.currentTimeMillis(); SpongeAFKListener.AFK_TRACKER.performedAction(uuid, 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"); InetAddress address = player.getConnection().getAddress().getAddress(); String playerName = player.getName(); String displayName = player.getDisplayNameData().displayName().get().toPlain(); boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS); processing.submitCritical(() -> sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, world, gm))); runnableFactory.create("Player Register: " + uuid, processors.player().registerProcessor(uuid, () -> time, playerName, gatheringGeolocations ? processors.player().ipUpdateProcessor(uuid, address, time) : null, processors.player().nameProcessor(uuid, playerName, displayName), processors.info().playerPageUpdateProcessor(uuid) ) ).runTaskAsynchronously(); }
private void sendUpdateSelf() { receiver.getTabList().removeEntry(receiver.getUniqueId()); receiver.getTabList().addEntry(TabListEntry.builder() .displayName(receiver.getDisplayNameData().displayName().get()) .latency(receiver.getConnection().getLatency()) .list(receiver.getTabList()) .gameMode(receiver.getGameModeData().type().get()) .profile(receiver.getProfile()) .build()); Location<World> oldLocation = receiver.getLocation(); Vector3d rotation = receiver.getRotation(); World receiverWorld = receiver.getWorld(); Sponge.getServer().getWorlds() .stream() .filter(world -> !world.equals(receiverWorld)) .findFirst() .ifPresent(world -> { receiver.setLocation(world.getSpawnLocation()); receiver.setLocationAndRotation(oldLocation, rotation); }); } }
@Override public void run() { Optional<Account> optAccount = plugin.getDatabase().loadAccount(player); if (!optAccount.isPresent()) { src.sendMessage(plugin.getConfigManager().getText().getAccountNotFound()); return; } Account account = optAccount.get(); attemptManager.clearAttempts(player.getUniqueId()); account.setLoggedIn(true); //update the ip account.setIP(player.getConnection().getAddress().getAddress()); player.sendMessage(plugin.getConfigManager().getText().getLoggedIn()); src.sendMessage(plugin.getConfigManager().getText().getForceLoginSuccess()); Task.builder().execute(() -> protectionManager.unprotect(player)).submit(plugin); //flushes the ip update plugin.getDatabase().save(account); } }
account.setIP(player.getConnection().getAddress().getAddress()); account.setLoggedIn(true);
String name = player.getName(); if (!plugin.getDatabase().loadAccount(player).isPresent()) { int regByIp = plugin.getDatabase().getRegistrationsCount(player.getConnection().getAddress().getAddress()); if (regByIp > plugin.getConfigManager().getGeneral().getMaxIpReg()) { player.sendMessage(plugin.getConfigManager().getText().getMaxIPReg());