mirror of
https://github.com/PaperMC/Paper.git
synced 2025-09-01 12:53:52 -07:00
Added support for an update on load feature for plugins. Thanks Raphfrk!
Any files placed in the new (optional) update folder are automatically copied into the plugins directory the next time a reload happens. This allows safe updating of the plugin .jar files. By: EvilSeph <evilseph@unaligned.org>
This commit is contained in:
59
paper-api/src/main/java/org/bukkit/util/FileUtil.java
Normal file
59
paper-api/src/main/java/org/bukkit/util/FileUtil.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package org.bukkit.util;
|
||||
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Class containing file utilities
|
||||
*/
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
/**
|
||||
* This method copies one file to another location
|
||||
*
|
||||
* @param inFile the source filename
|
||||
* @param outFile the target filename
|
||||
* @return true on success
|
||||
*/
|
||||
|
||||
public static boolean copy(File inFile, File outFile) {
|
||||
if (!inFile.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FileChannel in = null;
|
||||
FileChannel out = null;
|
||||
|
||||
try {
|
||||
in = new FileInputStream(inFile).getChannel();
|
||||
out = new FileOutputStream(outFile).getChannel();
|
||||
|
||||
long pos = 0;
|
||||
long size = in.size();
|
||||
|
||||
while (pos < size) {
|
||||
pos += in.transferTo(pos, 10*1024*1024, out);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
return false;
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user