Skip to content

Commit

Permalink
Rename more fields to eliminate prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
astei committed Oct 29, 2023
1 parent 1b7214b commit 95cd4c4
Show file tree
Hide file tree
Showing 41 changed files with 196 additions and 195 deletions.
30 changes: 15 additions & 15 deletions api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,30 @@ public interface ProxyServer extends Audience {
* @param username the username to search for
* @return an {@link Optional} with the player, which may be empty
*/
Optional<Player> getPlayer(String username);
Optional<Player> player(String username);

/**
* Retrieves the player currently connected to this proxy by their Minecraft UUID.
*
* @param uuid the UUID
* @return an {@link Optional} with the player, which may be empty
*/
Optional<Player> getPlayer(UUID uuid);
Optional<Player> player(UUID uuid);

/**
* Retrieves all players currently connected to this proxy. This call may or may not be a snapshot
* of all players online.
*
* @return the players online on this proxy
*/
Collection<Player> getAllPlayers();
Collection<Player> onlinePlayers();

/**
* Returns the number of players currently connected to this proxy.
*
* @return the players on this proxy
*/
int getPlayerCount();
int onlinePlayerCount();

/**
* Retrieves a registered {@link RegisteredServer} instance by its name. The search is
Expand All @@ -86,14 +86,14 @@ public interface ProxyServer extends Audience {
* @param name the name of the server
* @return the registered server, which may be empty
*/
Optional<RegisteredServer> getServer(String name);
Optional<RegisteredServer> server(String name);

/**
* Retrieves all {@link RegisteredServer}s registered with this proxy.
*
* @return the servers registered with this proxy
*/
Collection<RegisteredServer> getAllServers();
Collection<RegisteredServer> registeredServers();

/**
* Matches all {@link Player}s whose names start with the provided partial name.
Expand Down Expand Up @@ -142,64 +142,64 @@ public interface ProxyServer extends Audience {
*
* @return the console command invoker
*/
ConsoleCommandSource getConsoleCommandSource();
ConsoleCommandSource console();

/**
* Gets the {@link PluginManager} instance.
*
* @return the plugin manager instance
*/
PluginManager getPluginManager();
PluginManager pluginManager();

/**
* Gets the {@link EventManager} instance.
*
* @return the event manager instance
*/
EventManager getEventManager();
EventManager eventManager();

/**
* Gets the {@link CommandManager} instance.
*
* @return the command manager
*/
CommandManager getCommandManager();
CommandManager commandManager();

/**
* Gets the {@link Scheduler} instance.
*
* @return the scheduler instance
*/
Scheduler getScheduler();
Scheduler scheduler();

/**
* Gets the {@link ChannelRegistrar} instance.
*
* @return the channel registrar
*/
ChannelRegistrar getChannelRegistrar();
ChannelRegistrar channelRegistrar();

/**
* Gets the address that this proxy is bound to. This does not necessarily indicate the external
* IP address of the proxy.
*
* @return the address the proxy is bound to
*/
SocketAddress getBoundAddress();
SocketAddress boundAddress();

/**
* Gets the {@link ProxyConfig} instance.
*
* @return the proxy config
*/
ProxyConfig getConfiguration();
ProxyConfig configuration();

/**
* Returns the version of the proxy.
*
* @return the proxy version
*/
ProxyVersion getVersion();
ProxyVersion version();

/**
* Creates a builder to build a {@link ResourcePackInfo} instance for use with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public interface ProxyConfig {
/**
* Get a Map of all servers registered in <code>velocity.toml</code>. This method does
* <strong>not</strong> return all the servers currently in memory, although in most cases it
* does. For a view of all registered servers, see {@link ProxyServer#getAllServers()}.
* does. For a view of all registered servers, see {@link ProxyServer#registeredServers()}.
*
* @return registered servers map
*/
Expand Down
8 changes: 4 additions & 4 deletions proxy/src/main/java/com/velocitypowered/proxy/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ static void startMetrics(VelocityServer server, VelocityConfiguration.Metrics me
Metrics metrics = new Metrics(logger, 4752, metricsConfig.isEnabled());

metrics.addCustomChart(
new SingleLineChart("players", server::getPlayerCount)
new SingleLineChart("players", server::onlinePlayerCount)
);
metrics.addCustomChart(
new SingleLineChart("managed_servers", () -> server.getAllServers().size())
new SingleLineChart("managed_servers", () -> server.registeredServers().size())
);
metrics.addCustomChart(
new SimplePie("online_mode",
() -> server.getConfiguration().isOnlineMode() ? "online" : "offline")
() -> server.configuration().isOnlineMode() ? "online" : "offline")
);
metrics.addCustomChart(new SimplePie("velocity_version",
() -> server.getVersion().version()));
() -> server.version().version()));

metrics.addCustomChart(new DrilldownPie("java_version", () -> {
Map<String, Map<String, Integer>> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static void main(String... args) {

double bootTime = (System.currentTimeMillis() - startTime) / 1000d;
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
server.getConsoleCommandSource().start();
server.console().start();

// If we don't have a console available (because SimpleTerminalConsole returned), then we still
// need to wait, otherwise the JVM will reap us as no non-daemon threads will be active once the
Expand Down
40 changes: 20 additions & 20 deletions proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ public KeyPair getServerKeyPair() {
}

@Override
public VelocityConfiguration getConfiguration() {
public VelocityConfiguration configuration() {
return this.configuration;
}

@Override
public ProxyVersion getVersion() {
public ProxyVersion version() {
Package pkg = VelocityServer.class.getPackage();
String implName;
String implVersion;
Expand All @@ -190,7 +190,7 @@ public ProxyVersion getVersion() {
}

@Override
public VelocityCommandManager getCommandManager() {
public VelocityCommandManager commandManager() {
return commandManager;
}

Expand All @@ -201,7 +201,7 @@ void awaitProxyShutdown() {
@EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler",
"console", "cm", "configuration"})
void start() {
logger.info("Booting up {} {}...", getVersion().name(), getVersion().version());
logger.info("Booting up {} {}...", version().name(), version().version());
console.setupStreams();

registerTranslations();
Expand Down Expand Up @@ -640,13 +640,13 @@ public void unregisterConnection(ConnectedPlayer connection) {
}

@Override
public Optional<Player> getPlayer(String username) {
public Optional<Player> player(String username) {
Preconditions.checkNotNull(username, "username");
return Optional.ofNullable(connectionsByName.get(username.toLowerCase(Locale.US)));
}

@Override
public Optional<Player> getPlayer(UUID uuid) {
public Optional<Player> player(UUID uuid) {
Preconditions.checkNotNull(uuid, "uuid");
return Optional.ofNullable(connectionsByUuid.get(uuid));
}
Expand All @@ -655,7 +655,7 @@ public Optional<Player> getPlayer(UUID uuid) {
public Collection<Player> matchPlayer(String partialName) {
Objects.requireNonNull(partialName);

return getAllPlayers().stream().filter(p -> p.username()
return onlinePlayers().stream().filter(p -> p.username()
.regionMatches(true, 0, partialName, 0, partialName.length()))
.collect(Collectors.toList());
}
Expand All @@ -664,28 +664,28 @@ public Collection<Player> matchPlayer(String partialName) {
public Collection<RegisteredServer> matchServer(String partialName) {
Objects.requireNonNull(partialName);

return getAllServers().stream().filter(s -> s.serverInfo().name()
return registeredServers().stream().filter(s -> s.serverInfo().name()
.regionMatches(true, 0, partialName, 0, partialName.length()))
.collect(Collectors.toList());
}

@Override
public Collection<Player> getAllPlayers() {
public Collection<Player> onlinePlayers() {
return ImmutableList.copyOf(connectionsByUuid.values());
}

@Override
public int getPlayerCount() {
public int onlinePlayerCount() {
return connectionsByUuid.size();
}

@Override
public Optional<RegisteredServer> getServer(String name) {
public Optional<RegisteredServer> server(String name) {
return servers.getServer(name);
}

@Override
public Collection<RegisteredServer> getAllServers() {
public Collection<RegisteredServer> registeredServers() {
return servers.getAllServers();
}

Expand All @@ -705,32 +705,32 @@ public void unregisterServer(ServerInfo server) {
}

@Override
public VelocityConsole getConsoleCommandSource() {
public VelocityConsole console() {
return console;
}

@Override
public PluginManager getPluginManager() {
public PluginManager pluginManager() {
return pluginManager;
}

@Override
public VelocityEventManager getEventManager() {
public VelocityEventManager eventManager() {
return eventManager;
}

@Override
public VelocityScheduler getScheduler() {
public VelocityScheduler scheduler() {
return scheduler;
}

@Override
public VelocityChannelRegistrar getChannelRegistrar() {
public VelocityChannelRegistrar channelRegistrar() {
return channelRegistrar;
}

@Override
public SocketAddress getBoundAddress() {
public SocketAddress boundAddress() {
if (configuration == null) {
throw new IllegalStateException(
"No configuration"); // even though you'll never get the chance... heh, heh
Expand All @@ -740,9 +740,9 @@ public SocketAddress getBoundAddress() {

@Override
public @NonNull Iterable<? extends Audience> audiences() {
Collection<Audience> audiences = new ArrayList<>(this.getPlayerCount() + 1);
Collection<Audience> audiences = new ArrayList<>(this.onlinePlayerCount() + 1);
audiences.add(this.console);
audiences.addAll(this.getAllPlayers());
audiences.addAll(this.onlinePlayers());
return audiences;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private BuiltinCommandUtil() {
}

static List<RegisteredServer> sortedServerList(ProxyServer proxy) {
List<RegisteredServer> servers = new ArrayList<>(proxy.getAllServers());
List<RegisteredServer> servers = new ArrayList<>(proxy.registeredServers());
servers.sort(Comparator.comparing(RegisteredServer::serverInfo));
return Collections.unmodifiableList(servers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void register() {
ArgumentCommandNode<CommandSource, String> serverNode = RequiredArgumentBuilder
.<CommandSource, String>argument(SERVER_ARG, StringArgumentType.string())
.suggests((context, builder) -> {
for (RegisteredServer server : server.getAllServers()) {
for (RegisteredServer server : server.registeredServers()) {
builder.suggest(server.serverInfo().name());
}
builder.suggest("all");
Expand All @@ -75,7 +75,7 @@ public void register() {
.executes(this::serverCount)
.build();
totalNode.addChild(serverNode);
server.getCommandManager().register(new BrigadierCommand(totalNode));
server.commandManager().register(new BrigadierCommand(totalNode));
}

private int totalCount(final CommandContext<CommandSource> context) {
Expand All @@ -95,7 +95,7 @@ private int serverCount(final CommandContext<CommandSource> context) {
}
sendTotalProxyCount(source);
} else {
Optional<RegisteredServer> registeredServer = server.getServer(serverName);
Optional<RegisteredServer> registeredServer = server.server(serverName);
if (!registeredServer.isPresent()) {
source.sendMessage(Identity.nil(),
CommandMessages.SERVER_DOES_NOT_EXIST.args(Component.text(serverName)));
Expand All @@ -107,7 +107,7 @@ private int serverCount(final CommandContext<CommandSource> context) {
}

private void sendTotalProxyCount(CommandSource target) {
int online = server.getPlayerCount();
int online = server.onlinePlayerCount();
TranslatableComponent msg = online == 1
? Component.translatable("velocity.command.glist-player-singular")
: Component.translatable("velocity.command.glist-player-plural");
Expand Down
Loading

0 comments on commit 95cd4c4

Please sign in to comment.