forked from Upstream/CitizensCMD
Merge pull request #4 from darbyjack/master
Why disable when you can enable?
This commit is contained in:
commit
5aabe43e83
@ -31,13 +31,16 @@ import me.mattmoreira.citizenscmd.schedulers.CooldownScheduler;
|
|||||||
import me.mattmoreira.citizenscmd.schedulers.UpdateScheduler;
|
import me.mattmoreira.citizenscmd.schedulers.UpdateScheduler;
|
||||||
import me.mattmoreira.citizenscmd.updater.SpigotUpdater;
|
import me.mattmoreira.citizenscmd.updater.SpigotUpdater;
|
||||||
import me.mattmoreira.citizenscmd.utility.DisplayFormat;
|
import me.mattmoreira.citizenscmd.utility.DisplayFormat;
|
||||||
|
import me.mattmoreira.citizenscmd.utility.Util;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.*;
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@ -67,21 +70,24 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
|
|
||||||
private static HashMap<String, Boolean> waitingList;
|
private static HashMap<String, Boolean> waitingList;
|
||||||
|
|
||||||
|
public void onLoad() {
|
||||||
|
if (!hasCitizensFile()) {
|
||||||
|
info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
||||||
|
info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
||||||
|
info(color(TAG + "&cDownloading Citizens jar..."));
|
||||||
|
Util.downloadCitizens();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
|
if (!hasCitizens()) Util.loadCitizens();
|
||||||
|
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
|
||||||
commandHandler = new CommandHandler();
|
commandHandler = new CommandHandler();
|
||||||
commandHandler.enable();
|
commandHandler.enable();
|
||||||
|
|
||||||
if (!hasCitizens()) {
|
|
||||||
info(color(TAG + "&cCitizens &7is needed for this plugin to work!"));
|
|
||||||
info(color(TAG + "&cCitizens.jar &7is not installed on the server!"));
|
|
||||||
info(color(TAG + "&cDisabling CitizensCMD..."));
|
|
||||||
getServer().getPluginManager().disablePlugin(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkOldConfig();
|
checkOldConfig();
|
||||||
|
|
||||||
new Metrics(this);
|
new Metrics(this);
|
||||||
@ -221,6 +227,10 @@ public final class CitizensCMD extends JavaPlugin {
|
|||||||
*
|
*
|
||||||
* @return Returns true if Citizens is found and false if not
|
* @return Returns true if Citizens is found and false if not
|
||||||
*/
|
*/
|
||||||
|
private boolean hasCitizensFile() {
|
||||||
|
return Util.doesCitizensExist();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasCitizens() {
|
private boolean hasCitizens() {
|
||||||
return Bukkit.getPluginManager().isPluginEnabled("Citizens");
|
return Bukkit.getPluginManager().isPluginEnabled("Citizens");
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,14 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class Util {
|
public class Util {
|
||||||
@ -246,4 +251,30 @@ public class Util {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void downloadCitizens() {
|
||||||
|
try {
|
||||||
|
Files.copy(new URL("http://ci.citizensnpcs.co/job/Citizens2/lastSuccessfulBuild/artifact/dist/target/citizens-2.0.24-SNAPSHOT.jar").openStream(), new File(Bukkit.getServer().getUpdateFolderFile().getParentFile(), "Citizens.jar").toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadCitizens() {
|
||||||
|
File pluginFolder = Bukkit.getServer().getUpdateFolderFile().getParentFile();
|
||||||
|
Plugin loadedPlugin;
|
||||||
|
try {
|
||||||
|
loadedPlugin = Bukkit.getPluginManager().loadPlugin(new File(pluginFolder, "Citizens.jar"));
|
||||||
|
loadedPlugin.onLoad();
|
||||||
|
Bukkit.getPluginManager().enablePlugin(loadedPlugin);
|
||||||
|
} catch (InvalidPluginException | InvalidDescriptionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean doesCitizensExist() {
|
||||||
|
File pluginFolder = Bukkit.getServer().getUpdateFolderFile().getParentFile();
|
||||||
|
File citizens = new File(pluginFolder, "Citizens.jar");
|
||||||
|
return citizens.exists();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user