use of org.inventivetalent.update.spiget.SpigetUpdate in project SkinsRestorerX by DoNotSpamPls.
the class SkinsRestorer method onEnable.
public void onEnable() {
ConsoleCommandSender console = getServer().getConsoleSender();
@SuppressWarnings("unused") MetricsLite metrics = new MetricsLite(this);
SpigetUpdate updater = new SpigetUpdate(this, 2124);
updater.setVersionComparator(VersionComparator.EQUAL);
updater.setVersionComparator(VersionComparator.SEM_VER);
instance = this;
factory = new UniversalSkinFactory();
Config.load(getResource("config.yml"));
Locale.load();
console.sendMessage("§e[§2SkinsRestorer§e] §aDetected Minecraft §e" + ReflectionUtil.serverVersion + "§a, using §e" + factory.getClass().getSimpleName() + "§a.");
// Detect ChangeSkin
if (getServer().getPluginManager().getPlugin("ChangeSkin") != null) {
console.sendMessage("§e[§2SkinsRestorer§e] §cWe have detected ChangeSkin on your server, disabling SkinsRestorer.");
Bukkit.getPluginManager().disablePlugin(this);
}
// Bungeecord stuff
try {
bungeeEnabled = getServer().spigot().getConfig().getBoolean("settings.bungeecord");
} catch (Exception e) {
bungeeEnabled = false;
}
if (bungeeEnabled) {
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "SkinsRestorer", (channel, player, message) -> {
if (!channel.equals("SkinsRestorer"))
return;
Bukkit.getScheduler().runTaskAsynchronously(getInstance(), () -> {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
try {
String subchannel = in.readUTF();
if (subchannel.equalsIgnoreCase("SkinUpdate")) {
try {
factory.applySkin(player, SkinStorage.createProperty(in.readUTF(), in.readUTF(), in.readUTF()));
} catch (IOException e) {
e.printStackTrace();
}
factory.updateSkin(player);
}
} catch (Exception e) {
e.printStackTrace();
}
});
});
if (Config.UPDATER_ENABLED) {
updater.checkForUpdate(new UpdateCallback() {
@Override
public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
if (hasDirectDownload) {
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a | SkinsRestorer |");
console.sendMessage("§e[§2SkinsRestorer§e] §a |---------------|");
console.sendMessage("§e[§2SkinsRestorer§e] §a | §eBungee Mode§a |");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §b Current version: §c" + getVersion());
console.sendMessage("§e[§2SkinsRestorer§e] A new version is available! Downloading it now...");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
if (updater.downloadUpdate()) {
console.sendMessage("§e[§2SkinsRestorer§e] Update downloaded successfully, it will be applied on the next restart.");
} else {
// Update failed
console.sendMessage("§e[§2SkinsRestorer§e] §cCould not download the update, reason: " + updater.getFailReason());
}
}
}
@Override
public void upToDate() {
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a | SkinsRestorer |");
console.sendMessage("§e[§2SkinsRestorer§e] §a |---------------|");
console.sendMessage("§e[§2SkinsRestorer§e] §a | §eBungee Mode§a |");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §b Current version: §a" + getVersion());
console.sendMessage("§e[§2SkinsRestorer§e] §a This is the latest version!");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
}
});
}
return;
}
// Initialise MySQL
if (Config.USE_MYSQL)
SkinStorage.init(mysql = new MySQL(Config.MYSQL_HOST, Config.MYSQL_PORT, Config.MYSQL_DATABASE, Config.MYSQL_USERNAME, Config.MYSQL_PASSWORD));
else
SkinStorage.init(getDataFolder());
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new CooldownStorage(), 0, 20);
// Commands
getCommand("skinsrestorer").setExecutor(new SrCommand());
getCommand("skin").setExecutor(new SkinCommand());
getCommand("skins").setExecutor(new GUICommand());
Bukkit.getPluginManager().registerEvents(new SkinsGUI(), this);
Bukkit.getPluginManager().registerEvents(new Listener() {
// LoginEvent happens on attemptLogin so its the best place to set the skin
@EventHandler
public void onLogin(PlayerJoinEvent e) {
Bukkit.getScheduler().runTaskAsynchronously(SkinsRestorer.getInstance(), () -> {
try {
if (Config.DISABLE_ONJOIN_SKINS) {
// shouldn't it just skip it if it's true?
return;
}
if (Config.DEFAULT_SKINS_ENABLED)
if (SkinStorage.getPlayerSkin(e.getPlayer().getName()) == null) {
List<String> skins = Config.DEFAULT_SKINS;
int randomNum = (int) (Math.random() * skins.size());
factory.applySkin(e.getPlayer(), SkinStorage.getOrCreateSkinForPlayer(skins.get(randomNum)));
return;
}
factory.applySkin(e.getPlayer(), SkinStorage.getOrCreateSkinForPlayer(e.getPlayer().getName()));
} catch (SkinRequestException ex) {
ex.printStackTrace();
}
});
}
}, this);
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
if (Config.UPDATER_ENABLED) {
updater.checkForUpdate(new UpdateCallback() {
@Override
public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
if (hasDirectDownload) {
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a | SkinsRestorer |");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §b Current version: §c" + getVersion());
console.sendMessage("§e[§2SkinsRestorer§e] A new version is available! Downloading it now...");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
if (updater.downloadUpdate()) {
console.sendMessage("§e[§2SkinsRestorer§e] Update downloaded successfully, it will be applied on the next restart.");
} else {
// Update failed
console.sendMessage("§e[§2SkinsRestorer§e] §cCould not download the update, reason: " + updater.getFailReason());
}
}
}
@Override
public void upToDate() {
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a | SkinsRestorer |");
console.sendMessage("§e[§2SkinsRestorer§e] §a +===============+");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
console.sendMessage("§e[§2SkinsRestorer§e] §b Current version: §a" + getVersion());
console.sendMessage("§e[§2SkinsRestorer§e] §a This is the latest version!");
console.sendMessage("§e[§2SkinsRestorer§e] §a----------------------------------------------");
}
});
}
if (Config.DEFAULT_SKINS_ENABLED)
for (String skin : Config.DEFAULT_SKINS) try {
SkinStorage.setSkinData(skin, MojangAPI.getSkinProperty(MojangAPI.getUUID(skin)));
} catch (SkinRequestException e) {
if (SkinStorage.getSkinData(skin) == null)
console.sendMessage("§e[§2SkinsRestorer§e] §cDefault Skin '" + skin + "' request error: " + e.getReason());
}
});
}
use of org.inventivetalent.update.spiget.SpigetUpdate in project ServerSelectorX by ServerSelectorX.
the class Main method checkForUpdates.
private void checkForUpdates() {
if (!getConfig().getBoolean("updater")) {
getLogger().info("The update checker is disabled.");
return;
}
CURRENT_VERSION = Main.this.getDescription().getVersion();
if (CURRENT_VERSION.equals("custom")) {
getLogger().info("You are using a custom version so the update checker is disabled.");
return;
}
SpigetUpdate updater = new SpigetUpdate(this, 32853).setVersionComparator(VersionComparator.EQUAL);
updater.checkForUpdate(new UpdateCallback() {
@Override
public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
UPDATE_AVAILABLE = true;
NEW_VERSION = newVersion;
getLogger().info("An update is available!");
getLogger().info("Your version: " + CURRENT_VERSION);
getLogger().info("Latest version: " + NEW_VERSION);
}
@Override
public void upToDate() {
UPDATE_AVAILABLE = false;
getLogger().info("You are running the latest version.");
}
});
}
Aggregations