mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-28 05:05:21 +01:00
SLightly more atomic locations.yml saving to guard against ctrl+c'ing users
This commit is contained in:
parent
2c225a05e7
commit
98860ffd02
@ -20,7 +20,8 @@ public class YamlReconnectHandler implements ReconnectHandler
|
|||||||
{
|
{
|
||||||
|
|
||||||
private final Yaml yaml = new Yaml();
|
private final Yaml yaml = new Yaml();
|
||||||
private final File file = new File( "locations.yml" );
|
private final File readFile = new File( "locations.yml" );
|
||||||
|
private final File writeFile = new File( "locations.yml~" );
|
||||||
/*========================================================================*/
|
/*========================================================================*/
|
||||||
private Map<String, String> data;
|
private Map<String, String> data;
|
||||||
|
|
||||||
@ -29,8 +30,8 @@ public class YamlReconnectHandler implements ReconnectHandler
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file.createNewFile();
|
readFile.createNewFile();
|
||||||
try ( FileReader rd = new FileReader( file ) )
|
try ( FileReader rd = new FileReader( readFile ) )
|
||||||
{
|
{
|
||||||
data = yaml.loadAs( rd, Map.class );
|
data = yaml.loadAs( rd, Map.class );
|
||||||
}
|
}
|
||||||
@ -85,9 +86,11 @@ public class YamlReconnectHandler implements ReconnectHandler
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void save()
|
public synchronized void save()
|
||||||
{
|
{
|
||||||
try ( FileWriter wr = new FileWriter( file ) )
|
try ( FileWriter wr = new FileWriter( writeFile ) )
|
||||||
{
|
{
|
||||||
yaml.dump( data, wr );
|
yaml.dump( data, wr );
|
||||||
|
readFile.delete();
|
||||||
|
writeFile.renameTo( readFile );
|
||||||
} catch ( IOException ex )
|
} catch ( IOException ex )
|
||||||
{
|
{
|
||||||
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not save reconnect locations", ex );
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not save reconnect locations", ex );
|
||||||
|
Loading…
Reference in New Issue
Block a user