mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
Use try-with-resources, attempt space optimizations.
This commit is contained in:
parent
8da933a585
commit
6b5e25f18c
@ -72,7 +72,7 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
* @return a Set with all players found
|
* @return a Set with all players found
|
||||||
*/
|
*/
|
||||||
public static Set<String> getPlayers() {
|
public static Set<String> getPlayers() {
|
||||||
Set<String> players = Sets.newHashSet();
|
List<String> players = Lists.newArrayList();
|
||||||
for (ProxiedPlayer pp : plugin.getProxy().getPlayers()) {
|
for (ProxiedPlayer pp : plugin.getProxy().getPlayers()) {
|
||||||
players.add(pp.getName());
|
players.add(pp.getName());
|
||||||
}
|
}
|
||||||
@ -162,20 +162,20 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
}
|
}
|
||||||
uct = new UpdateCountTask(this);
|
uct = new UpdateCountTask(this);
|
||||||
getProxy().getScheduler().schedule(this, uct, 1, 3, TimeUnit.SECONDS);
|
getProxy().getScheduler().schedule(this, uct, 1, 3, TimeUnit.SECONDS);
|
||||||
getProxy().getPluginManager().registerCommand(this, new Command("glist") {
|
getProxy().getPluginManager().registerCommand(this, new Command("glist", "bungeecord.command.glist", "redisbungee") {
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + String.valueOf(getCount()) + " player(s) are currently online.");
|
sender.sendMessage(ChatColor.YELLOW + String.valueOf(getCount()) + " player(s) are currently online.");
|
||||||
if (args.length > 0 && args[0].equals("showall")) {
|
if (args.length > 0 && args[0].equals("showall")) {
|
||||||
if (canonicalGlist) {
|
if (canonicalGlist) {
|
||||||
Multimap<String, String> serverToPlayers = HashMultimap.create();
|
Multimap<String, String> serverToPlayers = HashMultimap.create(getProxy().getServers().size(), count);
|
||||||
for (String p : getPlayers()) {
|
for (String p : getPlayers()) {
|
||||||
ServerInfo si = getServerFor(p);
|
ServerInfo si = getServerFor(p);
|
||||||
if (si != null)
|
if (si != null)
|
||||||
serverToPlayers.put(si.getName(), p);
|
serverToPlayers.put(si.getName(), p);
|
||||||
}
|
}
|
||||||
if (serverToPlayers.size() == 0) return;
|
if (serverToPlayers.size() == 0) return;
|
||||||
List<String> sortedServers = Lists.newArrayList(serverToPlayers.keySet());
|
List<String> sortedServers = new ArrayList<>(serverToPlayers.keySet());
|
||||||
Collections.sort(sortedServers);
|
Collections.sort(sortedServers);
|
||||||
for (String server : sortedServers)
|
for (String server : sortedServers)
|
||||||
sender.sendMessage(ChatColor.GREEN + "[" + server + "] " + ChatColor.YELLOW + "("
|
sender.sendMessage(ChatColor.GREEN + "[" + server + "] " + ChatColor.YELLOW + "("
|
||||||
@ -206,8 +206,8 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
} finally {
|
} finally {
|
||||||
pool.returnResource(tmpRsc);
|
pool.returnResource(tmpRsc);
|
||||||
}
|
}
|
||||||
|
pool.destroy();
|
||||||
}
|
}
|
||||||
pool.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadConfig() throws IOException {
|
private void loadConfig() throws IOException {
|
||||||
@ -215,23 +215,26 @@ public class RedisBungee extends Plugin implements Listener {
|
|||||||
getDataFolder().mkdir();
|
getDataFolder().mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
File exampleConfig = new File(getDataFolder(), "config.yml");
|
File file = new File(getDataFolder(), "config.yml");
|
||||||
if (!exampleConfig.exists()) {
|
|
||||||
exampleConfig.createNewFile();
|
if (!file.exists()) {
|
||||||
InputStream in = getResourceAsStream("example_config.yml");
|
file.createNewFile();
|
||||||
OutputStream out = new FileOutputStream(exampleConfig);
|
try (InputStream in = getResourceAsStream("example_config.yml");
|
||||||
byte[] buf = new byte[1024];
|
OutputStream out = new FileOutputStream(file)) {
|
||||||
int len;
|
byte[] buf = new byte[1024];
|
||||||
while ((len = in.read(buf)) > 0) {
|
int len;
|
||||||
out.write(buf, 0, len);
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out.close();
|
|
||||||
in.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = new File(getDataFolder() + File.separator + "config.yml");
|
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
Map rawYaml = (Map) yaml.load(new FileInputStream(file));
|
Map rawYaml;
|
||||||
|
|
||||||
|
try (InputStream in = new FileInputStream(file)) {
|
||||||
|
rawYaml = (Map) yaml.load(new FileInputStream(file));
|
||||||
|
}
|
||||||
|
|
||||||
String redisServer = "localhost";
|
String redisServer = "localhost";
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user