com.velocitypowered.api.proxy.ProxyServer Java Examples

The following examples show how to use com.velocitypowered.api.proxy.ProxyServer. 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: VelocityPlayerInfo.java    From AntiVPN with MIT License 6 votes vote down vote up
VelocityPlayerInfo(String name, ProxyServer proxy) throws IOException {
    this.name = name;

    Optional<UUID> uuid = Optional.ofNullable(nameCache.getIfPresent(name));
    if (!uuid.isPresent()) {
        synchronized (nameCacheLock) {
            uuid = Optional.ofNullable(nameCache.getIfPresent(name));
            if (!uuid.isPresent()) {
                uuid = Optional.ofNullable(uuidExpensive(name, proxy));
                uuid.ifPresent(v -> nameCache.put(name, v));
            }
        }
    }

    this.uuid = uuid.orElse(null);
}
 
Example #2
Source File: VelocityPlayerInfo.java    From AntiVPN with MIT License 6 votes vote down vote up
VelocityPlayerInfo(UUID uuid, ProxyServer proxy) throws IOException {
    this.uuid = uuid;

    Optional<String> name = Optional.ofNullable(uuidCache.getIfPresent(uuid));
    if (!name.isPresent()) {
        synchronized (uuidCacheLock) {
            name = Optional.ofNullable(uuidCache.getIfPresent(uuid));
            if (!name.isPresent()) {
                name = Optional.ofNullable(nameExpensive(uuid, proxy));
                name.ifPresent(v -> uuidCache.put(uuid, v));
            }
        }
    }

    this.name = name.orElse(null);
}
 
Example #3
Source File: VelocityPlayerInfo.java    From AntiVPN with MIT License 5 votes vote down vote up
private static String nameExpensive(UUID uuid, ProxyServer proxy) throws IOException {
    // Currently-online lookup
    Optional<Player> player = proxy.getPlayer(uuid);
    if (player.isPresent()) {
        nameCache.put(player.get().getUsername(), uuid);
        return player.get().getUsername();
    }

    // Network lookup
    HttpURLConnection conn = JSONWebUtil.getConnection(new URL("https://api.mojang.com/user/profiles/" + uuid.toString().replace("-", "") + "/names"), "GET", 5000, "egg82/PlayerInfo", headers);;
    int status = conn.getResponseCode();

    if (status == 204) {
        // No data exists
        return null;
    } else if (status == 200) {
        try {
            JSONArray json = getJSONArray(conn, status);
            JSONObject last = (JSONObject) json.get(json.size() - 1);
            String name = (String) last.get("name");
            nameCache.put(name, uuid);
            return name;
        } catch (ParseException | ClassCastException ex) {
            throw new IOException(ex.getMessage(), ex);
        }
    }

    throw new IOException("Could not load player data from Mojang (rate-limited?)");
}
 
Example #4
Source File: VelocityServerProperties.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public VelocityServerProperties(ProxyServer server, PlanConfig config) {
    super(
            "Velocity",
            server.getBoundAddress().getPort(),
            server.getClass().getPackage().getImplementationVersion(),
            server.getClass().getPackage().getImplementationVersion(),
            () -> config.get(ProxySettings.IP),
            -1
    );
}
 
Example #5
Source File: VelocityPingCounterTest.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeEach
void setUp() {
    PlanVelocityMocker mocker = PlanVelocityMocker.setUp()
            .withProxy();
    plugin = mocker.getPlanMock();

    player = Mockito.mock(Player.class);
    when(player.getPing()).thenReturn(5L);
    when(player.getUniqueId()).thenReturn(TestConstants.PLAYER_ONE_UUID);

    ProxyServer proxy = plugin.getProxy();
    when(proxy.getPlayer(TestConstants.PLAYER_ONE_UUID)).thenReturn(Optional.empty());
}
 
Example #6
Source File: PlanVelocityMocker.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PlanVelocityMocker withProxy() {
    ProxyServer server = Mockito.mock(ProxyServer.class);

    InetSocketAddress ip = new InetSocketAddress(25565);

    doReturn(new ArrayList<>()).when(server).getAllServers();
    doReturn(ip).when(server).getBoundAddress();

    doReturn(server).when(planMock).getProxy();
    return this;
}
 
Example #7
Source File: VelocityCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
public void register() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getCommandManager().register(this, ALIASES);

    // register slash aliases so the console can run '/lpv' in the same way as 'lpv'.
    proxy.getCommandManager().register(new ForwardingCommand(this) {
        @Override
        public boolean hasPermission(CommandSource source, @NonNull String[] args) {
            return source instanceof ConsoleCommandSource;
        }
    }, SLASH_ALIASES);
}
 
Example #8
Source File: VelocityPluginModule.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void configure(Binder binder) {
  binder.bind(description.getMainClass()).in(Scopes.SINGLETON);

  binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.getId()));
  binder.bind(ProxyServer.class).toInstance(server);
  binder.bind(Path.class).annotatedWith(DataDirectory.class)
      .toInstance(basePluginPath.resolve(description.getId()));
  binder.bind(PluginDescription.class).toInstance(description);
  binder.bind(PluginManager.class).toInstance(server.getPluginManager());
  binder.bind(EventManager.class).toInstance(server.getEventManager());
  binder.bind(CommandManager.class).toInstance(server.getCommandManager());
}
 
Example #9
Source File: PlayerEvents.java    From AntiVPN with MIT License 5 votes vote down vote up
private UUID getPlayerUUID(String name, ProxyServer proxy) {
    PlayerInfo info;
    try {
        info = PlayerLookup.get(name, proxy);
    } catch (IOException ex) {
        logger.warn("Could not fetch player UUID. (rate-limited?)", ex);
        return null;
    }
    return info.getUUID();
}
 
Example #10
Source File: PlayerEvents.java    From AntiVPN with MIT License 5 votes vote down vote up
public PlayerEvents(Object plugin, ProxyServer proxy) {
    this.proxy = proxy;

    events.add(
            VelocityEvents.subscribe(plugin, proxy, PreLoginEvent.class, PostOrder.LATE)
                    .handler(this::cachePlayer)
    );

    events.add(
            VelocityEvents.subscribe(plugin, proxy, PostLoginEvent.class, PostOrder.FIRST)
                    .handler(this::checkPlayer)
    );
}
 
Example #11
Source File: VelocityPlayerInfo.java    From AntiVPN with MIT License 5 votes vote down vote up
private static UUID uuidExpensive(String name, ProxyServer proxy) throws IOException {
    // Currently-online lookup
    Optional<Player> player = proxy.getPlayer(name);
    if (player.isPresent()) {
        uuidCache.put(player.get().getUniqueId(), name);
        return player.get().getUniqueId();
    }

    // Network lookup
    HttpURLConnection conn = JSONWebUtil.getConnection(new URL("https://api.mojang.com/users/profiles/minecraft/" + name), "GET", 5000, "egg82/PlayerInfo", headers);
    int status = conn.getResponseCode();

    if (status == 204) {
        // No data exists
        return null;
    } else if (status == 200) {
        try {
            JSONObject json = getJSONObject(conn, status);
            UUID uuid = UUID.fromString(((String) json.get("id")).replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"));
            name = (String) json.get("name");
            uuidCache.put(uuid, name);
            return uuid;
        } catch (ParseException | ClassCastException ex) {
            throw new IOException(ex.getMessage(), ex);
        }
    }

    throw new IOException("Could not load player data from Mojang (rate-limited?)");
}
 
Example #12
Source File: PlayerLookup.java    From AntiVPN with MIT License 5 votes vote down vote up
public static PlayerInfo get(String name, ProxyServer proxy) throws IOException {
    if (name == null) {
        throw new IllegalArgumentException("name cannot be null.");
    }
    if (proxy == null) {
        throw new IllegalArgumentException("proxy cannot be null.");
    }

    return new VelocityPlayerInfo(name, proxy);
}
 
Example #13
Source File: PlayerLookup.java    From AntiVPN with MIT License 5 votes vote down vote up
public static PlayerInfo get(UUID uuid, ProxyServer proxy) throws IOException {
    if (uuid == null) {
        throw new IllegalArgumentException("uuid cannot be null.");
    }
    if (proxy == null) {
        throw new IllegalArgumentException("proxy cannot be null.");
    }

    return new VelocityPlayerInfo(uuid, proxy);
}
 
Example #14
Source File: AntiVPN.java    From AntiVPN with MIT License 5 votes vote down vote up
public AntiVPN(Object plugin, ProxyServer proxy, PluginDescription description) {
    if (plugin == null) {
        throw new IllegalArgumentException("plugin cannot be null.");
    }
    if (proxy == null) {
        throw new IllegalArgumentException("proxy cannot be null.");
    }
    if (description == null) {
        throw new IllegalArgumentException("description cannot be null.");
    }

    this.plugin = plugin;
    this.proxy = proxy;
    this.description = description;
}
 
Example #15
Source File: CheckCommand.java    From AntiVPN with MIT License 5 votes vote down vote up
private UUID getPlayerUUID(String name, ProxyServer proxy) {
    PlayerInfo info;
    try {
        info = PlayerLookup.get(name, proxy);
    } catch (IOException ex) {
        logger.warn("Could not fetch player UUID. (rate-limited?)", ex);
        return null;
    }
    return info.getUUID();
}
 
Example #16
Source File: ReloadCommand.java    From AntiVPN with MIT License 5 votes vote down vote up
public ReloadCommand(Object plugin, ProxyServer proxy, PluginDescription description, StorageMessagingHandler handler, CommandIssuer issuer) {
    this.plugin = plugin;
    this.proxy = proxy;
    this.description = description;
    this.handler = handler;
    this.issuer = issuer;
}
 
Example #17
Source File: JavaPluginLoader.java    From Velocity with MIT License 4 votes vote down vote up
public JavaPluginLoader(ProxyServer server, Path baseDirectory) {
  this.server = server;
  this.baseDirectory = baseDirectory;
}
 
Example #18
Source File: LPVelocityBootstrap.java    From LuckPerms with MIT License 4 votes vote down vote up
public ProxyServer getProxy() {
    return this.proxy;
}
 
Example #19
Source File: VelocityScheduler.java    From NuVotifier with GNU General Public License v3.0 4 votes vote down vote up
public VelocityScheduler(ProxyServer server, VotifierPlugin plugin) {
    this.server = server;
    this.plugin = plugin;
}
 
Example #20
Source File: PluginMessageMessenger.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public void close() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getChannelRegistrar().unregister(CHANNEL);
    proxy.getEventManager().unregisterListener(this.plugin.getBootstrap(), this);
}
 
Example #21
Source File: PluginMessageMessenger.java    From LuckPerms with MIT License 4 votes vote down vote up
public void init() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getChannelRegistrar().register(CHANNEL);
    proxy.getEventManager().register(this.plugin.getBootstrap(), this);
}
 
Example #22
Source File: VelocityBackendServer.java    From NuVotifier with GNU General Public License v3.0 4 votes vote down vote up
VelocityBackendServer(ProxyServer server, RegisteredServer rs) {
    this.server = server;
    this.rs = rs;
}
 
Example #23
Source File: VelocityPlugin.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
public String getPlatformVersion() {
    String version = ProxyServer.class.getPackage().getImplementationVersion();
    return (version != null) ? version : "Unknown";
}
 
Example #24
Source File: VelocityPlugin.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
public String getPlatformName() {
    String proxyImpl = ProxyServer.class.getPackage().getImplementationTitle();
    return (proxyImpl != null) ? proxyImpl : "Velocity";
}
 
Example #25
Source File: VotifierPlugin.java    From NuVotifier with GNU General Public License v3.0 4 votes vote down vote up
public ProxyServer getServer() {
    return server;
}
 
Example #26
Source File: VelocityCommandSender.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
VelocityCommandSender(ProxyServer proxy, CommandSource source) {
    this.proxy = proxy;
    this.source = source;
}
 
Example #27
Source File: VelocityPlugin.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Inject
public VelocityPlugin(Logger logger, ProxyServer proxy, @DataDirectory Path pluginFolder) {
    this.logger = logger;
    this.proxy = proxy;
    this.pluginFolder = pluginFolder;
}
 
Example #28
Source File: PlanVelocity.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@com.google.inject.Inject
public PlanVelocity(ProxyServer proxy, Logger slf4jLogger, @DataDirectory Path dataFolderPath) {
    super(proxy, slf4jLogger, dataFolderPath);
}
 
Example #29
Source File: SkinsRestorer.java    From SkinsRestorerX with GNU General Public License v3.0 4 votes vote down vote up
@Inject
public SkinsRestorer(ProxyServer proxy, Logger logger, @DataDirectory Path dataFolder) {
    this.proxy = proxy;
    this.logger = new SRLogger();
    this.dataFolder = dataFolder;
}
 
Example #30
Source File: ServerCommand.java    From Velocity with MIT License 4 votes vote down vote up
public ServerCommand(ProxyServer server) {
  this.server = server;
}