mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-29 18:27:36 +02:00
Migrate to Java 7 NIO files
This commit is contained in:
@ -6,22 +6,20 @@ import com.github.games647.fastlogin.bukkit.tasks.ForceLoginTask;
|
||||
import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
/**
|
||||
* Responsible for receiving messages from a BungeeCord instance.
|
||||
*
|
||||
@ -98,13 +96,13 @@ public class BungeeCordListener implements PluginMessageListener {
|
||||
}
|
||||
|
||||
public Set<UUID> loadBungeeCordIds() {
|
||||
File whitelistFile = new File(plugin.getDataFolder(), FILE_NAME);
|
||||
Path whitelistFile = plugin.getDataFolder().toPath().resolve(FILE_NAME);
|
||||
try {
|
||||
if (!whitelistFile.exists()) {
|
||||
whitelistFile.createNewFile();
|
||||
if (!Files.exists(whitelistFile)) {
|
||||
Files.createFile(whitelistFile);
|
||||
}
|
||||
|
||||
List<String> lines = Files.readAllLines(whitelistFile.toPath());
|
||||
List<String> lines = Files.readAllLines(whitelistFile);
|
||||
return lines.stream().map(String::trim).map(UUID::fromString).collect(Collectors.toSet());
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to create file for Proxy whitelist", ex);
|
||||
|
@ -13,11 +13,11 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
@ -92,16 +92,16 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
||||
sharedConfig = new SharedConfig(plugin.loadYamlFile(reader));
|
||||
reader.close();
|
||||
|
||||
reader = Files.newBufferedReader(new File(plugin.getDataFolder(), "config.yml").toPath());
|
||||
reader = Files.newBufferedReader(plugin.getDataFolder().toPath().resolve("config.yml"));
|
||||
sharedConfig.getConfigValues().putAll(plugin.loadYamlFile(reader));
|
||||
reader.close();
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("messages.yml")));
|
||||
reader = Files.newBufferedReader(new File(plugin.getDataFolder(), "messages.yml").toPath());
|
||||
reader = Files.newBufferedReader(plugin.getDataFolder().toPath().resolve("messages.yml"));
|
||||
Map<String, Object> messageConfig = plugin.loadYamlFile(reader);
|
||||
reader.close();
|
||||
|
||||
reader = Files.newBufferedReader(new File(plugin.getDataFolder(), "messages.yml").toPath());
|
||||
reader = Files.newBufferedReader(plugin.getDataFolder().toPath().resolve("messages.yml"));
|
||||
messageConfig.putAll(plugin.loadYamlFile(reader));
|
||||
for (Entry<String, Object> entry : messageConfig.entrySet()) {
|
||||
String message = plugin.translateColorCodes('&', (String) entry.getValue());
|
||||
@ -243,11 +243,11 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
||||
plugin.getDataFolder().mkdir();
|
||||
}
|
||||
|
||||
File configFile = new File(plugin.getDataFolder(), fileName);
|
||||
if (!configFile.exists()) {
|
||||
Path configFile = plugin.getDataFolder().toPath().resolve(fileName);
|
||||
if (!Files.exists(configFile)) {
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream(fileName);
|
||||
try {
|
||||
Files.copy(in, configFile.toPath());
|
||||
Files.copy(in, configFile);
|
||||
} catch (IOException ioExc) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Error saving default " + fileName, ioExc);
|
||||
} finally {
|
||||
|
Reference in New Issue
Block a user