mirror of
https://github.com/5vl/CorePlugin.git
synced 2025-07-09 04:27:01 +00:00
1.1.0
This update has an update checker!
This commit is contained in:
parent
7324461fdf
commit
832a94ea64
@ -12,14 +12,17 @@ import coreplugin.coreplugin.commands.punish.kick;
|
|||||||
import coreplugin.coreplugin.commands.punish.unban;
|
import coreplugin.coreplugin.commands.punish.unban;
|
||||||
import coreplugin.coreplugin.events.OnPlayerJoin;
|
import coreplugin.coreplugin.events.OnPlayerJoin;
|
||||||
import coreplugin.coreplugin.events.OnPlayerLeave;
|
import coreplugin.coreplugin.events.OnPlayerLeave;
|
||||||
|
import coreplugin.coreplugin.utils.UpdateChecker;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class Core extends JavaPlugin {
|
public final class Core extends JavaPlugin {
|
||||||
private static Core instance;
|
private static Core instance;
|
||||||
|
public String updatemsg;
|
||||||
|
String version = this.getDescription().getVersion();
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
System.out.println("Enabed Core Plugin 1.0.0");
|
System.out.println("Enabed Core Plugin " + version);
|
||||||
instance = this;
|
instance = this;
|
||||||
this.getConfig().options().copyDefaults();
|
this.getConfig().options().copyDefaults();
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
@ -27,6 +30,14 @@ public final class Core extends JavaPlugin {
|
|||||||
plm.registerEvents(new OnPlayerJoin(), this);
|
plm.registerEvents(new OnPlayerJoin(), this);
|
||||||
plm.registerEvents(new OnPlayerLeave(), this);
|
plm.registerEvents(new OnPlayerLeave(), this);
|
||||||
registerCMD();
|
registerCMD();
|
||||||
|
new UpdateChecker(this, 87756).getLatestVersion(version -> {
|
||||||
|
if (this.getDescription().getVersion().equalsIgnoreCase(version)) {
|
||||||
|
Logger.log(Logger.LogLevel.SUCCESS, "Core Plugin is up to date.");
|
||||||
|
} else {
|
||||||
|
Logger.log(Logger.LogLevel.ERROR, "Plugin is out of date, please download the new version at https://www.spigotmc.org/resources/core-plugin.87756/");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public static Core getInstance() {
|
public static Core getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
|
30
java/coreplugin/coreplugin/Logger.java
Normal file
30
java/coreplugin/coreplugin/Logger.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package coreplugin.coreplugin;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
public static void log(LogLevel level, String message) {
|
||||||
|
if (message == null) return;
|
||||||
|
|
||||||
|
switch (level) {
|
||||||
|
case ERROR:
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&c&lERROR&r&8] &f" + message));
|
||||||
|
break;
|
||||||
|
case WARNING:
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&6&lWARNING&r&8] &f" + message));
|
||||||
|
break;
|
||||||
|
case INFO:
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&e&lINFO&r&8] &f" + message));
|
||||||
|
break;
|
||||||
|
case SUCCESS:
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&a&lSUCCESS&r&8] &f" + message));
|
||||||
|
break;
|
||||||
|
case OUTLINE:
|
||||||
|
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&7" + message));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LogLevel { ERROR, WARNING, INFO, SUCCESS, OUTLINE }
|
||||||
|
}
|
33
java/coreplugin/coreplugin/utils/UpdateChecker.java
Normal file
33
java/coreplugin/coreplugin/utils/UpdateChecker.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package coreplugin.coreplugin.utils;
|
||||||
|
|
||||||
|
import coreplugin.coreplugin.Core;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class UpdateChecker {
|
||||||
|
|
||||||
|
private Core plugin;
|
||||||
|
private int resourceID;
|
||||||
|
|
||||||
|
public UpdateChecker (Core plugin, int resourceID) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceID = resourceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLatestVersion(Consumer<String> consumer) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
|
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceID).openStream();
|
||||||
|
Scanner scanner = new Scanner(inputStream)) {
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
consumer.accept(scanner.next());
|
||||||
|
}
|
||||||
|
} catch (IOException exception){
|
||||||
|
plugin.getLogger().info("Core Plugin Update Checker does not work." + exception.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
name: CorePlugin
|
name: CorePlugin
|
||||||
version: 1.0.0
|
version: 1.1.0
|
||||||
main: coreplugin.coreplugin.Core
|
main: coreplugin.coreplugin.Core
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
authors: [ 5vl ]
|
authors: [ 5vl ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user