Use tab indentation in Java plugin
This commit is contained in:
parent
54785a3b02
commit
571b5b9ef4
@ -23,107 +23,107 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import org.dynmap.DynmapAPI;
|
import org.dynmap.DynmapAPI;
|
||||||
|
|
||||||
public class LiveAtlasMain extends JavaPlugin {
|
public class LiveAtlasMain extends JavaPlugin {
|
||||||
private static Logger log;
|
private static Logger log;
|
||||||
Plugin dynmap;
|
Plugin dynmap;
|
||||||
DynmapAPI api;
|
DynmapAPI api;
|
||||||
FileConfiguration cfg;
|
FileConfiguration cfg;
|
||||||
|
|
||||||
int updates_per_tick = 20;
|
int updates_per_tick = 20;
|
||||||
int vupdates_per_tick = 20;
|
int vupdates_per_tick = 20;
|
||||||
|
|
||||||
HashMap<String, Integer> lookup_cache = new HashMap<String, Integer>();
|
HashMap<String, Integer> lookup_cache = new HashMap<String, Integer>();
|
||||||
HashMap<String, Integer> vlookup_cache = new HashMap<String, Integer>();
|
HashMap<String, Integer> vlookup_cache = new HashMap<String, Integer>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
log = this.getLogger();
|
log = this.getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(String msg) {
|
public static void info(String msg) {
|
||||||
log.log(Level.INFO, msg);
|
log.log(Level.INFO, msg);
|
||||||
}
|
}
|
||||||
public static void severe(String msg) {
|
public static void severe(String msg) {
|
||||||
log.log(Level.SEVERE, msg);
|
log.log(Level.SEVERE, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LiveAtlasServierListener implements Listener {
|
private class LiveAtlasServierListener implements Listener {
|
||||||
@EventHandler(priority=EventPriority.MONITOR)
|
@EventHandler(priority=EventPriority.MONITOR)
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
Plugin p = event.getPlugin();
|
Plugin p = event.getPlugin();
|
||||||
String name = p.getDescription().getName();
|
String name = p.getDescription().getName();
|
||||||
if (name.equals("dynmap")) {
|
if (name.equals("dynmap")) {
|
||||||
activate();
|
activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
info("initializing");
|
info("initializing");
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
/* Get dynmap */
|
/* Get dynmap */
|
||||||
dynmap = pm.getPlugin("dynmap");
|
dynmap = pm.getPlugin("dynmap");
|
||||||
if (dynmap == null) {
|
if (dynmap == null) {
|
||||||
severe("Cannot find dynmap!");
|
severe("Cannot find dynmap!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new LiveAtlasServierListener(), this);
|
getServer().getPluginManager().registerEvents(new LiveAtlasServierListener(), this);
|
||||||
|
|
||||||
/* If enabled, activate */
|
/* If enabled, activate */
|
||||||
if (dynmap.isEnabled())
|
if (dynmap.isEnabled())
|
||||||
activate();
|
activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void activate() {
|
private void activate() {
|
||||||
String version = this.getDescription().getVersion();
|
String version = this.getDescription().getVersion();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Path dynmapWebFolderPath = Paths.get(dynmap.getDataFolder().toURI()).resolve("web");
|
Path dynmapWebFolderPath = Paths.get(dynmap.getDataFolder().toURI()).resolve("web");
|
||||||
File sourceDirectory = Paths.get(this.getDataFolder().toURI()).toFile();
|
File sourceDirectory = Paths.get(this.getDataFolder().toURI()).toFile();
|
||||||
File destinationDirectory = dynmapWebFolderPath.toFile();
|
File destinationDirectory = dynmapWebFolderPath.toFile();
|
||||||
copyDirectory(sourceDirectory, destinationDirectory);
|
copyDirectory(sourceDirectory, destinationDirectory);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Material Dynmap v" + version + " installation failed", e);
|
throw new RuntimeException("Material Dynmap v" + version + " installation failed", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
info("Material Dynmap v" + version + " installation succeeded");
|
info("Material Dynmap v" + version + " installation succeeded");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException {
|
private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException {
|
||||||
if (!destinationDirectory.exists()) {
|
if (!destinationDirectory.exists()) {
|
||||||
destinationDirectory.mkdir();
|
destinationDirectory.mkdir();
|
||||||
}
|
}
|
||||||
for (String f : sourceDirectory.list()) {
|
for (String f : sourceDirectory.list()) {
|
||||||
copyDirectoryCompatibityMode(new File(sourceDirectory, f), new File(destinationDirectory, f));
|
copyDirectoryCompatibityMode(new File(sourceDirectory, f), new File(destinationDirectory, f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyDirectoryCompatibityMode(File sourceDirectory, File destinationDirectory) throws IOException {
|
public static void copyDirectoryCompatibityMode(File sourceDirectory, File destinationDirectory) throws IOException {
|
||||||
if (sourceDirectory.getName() == "io" || sourceDirectory.getName() == "META-INF") {
|
if (sourceDirectory.getName() == "io" || sourceDirectory.getName() == "META-INF") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (sourceDirectory.isDirectory()) {
|
if (sourceDirectory.isDirectory()) {
|
||||||
copyDirectory(sourceDirectory, destinationDirectory);
|
copyDirectory(sourceDirectory, destinationDirectory);
|
||||||
} else {
|
} else {
|
||||||
copyFile(sourceDirectory, destinationDirectory);
|
copyFile(sourceDirectory, destinationDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyFile(File sourceFile, File destinationFile) throws IOException {
|
private static void copyFile(File sourceFile, File destinationFile) throws IOException {
|
||||||
if (sourceFile.getName() == "plugin.yml") {
|
if (sourceFile.getName() == "plugin.yml") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (InputStream in = new FileInputStream(sourceFile);
|
try (InputStream in = new FileInputStream(sourceFile);
|
||||||
OutputStream out = new FileOutputStream(destinationFile)) {
|
OutputStream out = new FileOutputStream(destinationFile)) {
|
||||||
byte[] buf = new byte[1024];
|
byte[] buf = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
while ((length = in.read(buf)) > 0) {
|
while ((length = in.read(buf)) > 0) {
|
||||||
out.write(buf, 0, length);
|
out.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user