Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Updated CommandAPI
Browse files Browse the repository at this point in the history
 -> Untested 1.20.3/1.20.4 support
 Removed deprecated stuff
 Config consistency
  • Loading branch information
Timongcraft committed Dec 15, 2023
1 parent 8f217e9 commit 54ad854
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 183 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>dev.jorel</groupId>
<artifactId>commandapi-bukkit-core</artifactId>
<version>9.2.0</version>
<version>9.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/timongcraft/system/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Main extends JavaPlugin {
private static Main instance;
private final String prefix = getConfig().getString("prefix.pluginPrefix");
private DataConfigHandler dataConfigHandler;
private AutoSaveHandler autoSaveHandler;
private boolean noLoad;

@Override
Expand All @@ -27,9 +26,9 @@ public void onLoad() {

noLoad = !new File(getDataFolder(), "config.yml").exists();

if (noLoad || Main.get().getConfig().getBoolean("CommandAPI.autoDownload")) {
if (noLoad || Main.get().getConfig().getBoolean("commandAPI.autoDownload")) {
try {
CommandAPILoader.load("9.2.0", noLoad);
CommandAPILoader.load("9.3.0", noLoad);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand All @@ -44,24 +43,19 @@ public void onEnable() {
configVersionCheck();
if (noLoad) return;

PluginCommand.disablePluginsOnBoot();

if (getConfig().getBoolean("newUpdateNotifications.console"))
UpdateCheckHandler.checkForUpdate(Double.parseDouble(getDescription().getVersion()));

registerCommandsInOnEnable();

registerEvents();

enableAutoSave();
}

@Override
public void onDisable() {
if (noLoad) return;

if (dataConfigHandler != null) dataConfigHandler.save();
if (getConfig().getBoolean("autoSave.enabled")) autoSaveHandler.cancel();
}

private void configVersionCheck() {
Expand Down Expand Up @@ -92,7 +86,6 @@ private void registerCommandsInOnEnable() {
MaintenanceCommand.register();
if (Main.get().getConfig().getBoolean("permissionSystem.enabled"))
PermissionManagerCommand.register();
PluginCommand.register();
RebootCommand.register();
ReloadConfigsCommand.register();
ResourcePackCommand.register();
Expand All @@ -116,12 +109,6 @@ private void registerEvents() {
pluginManager.registerEvents(new HopperFilterHandler(), this);
}

private void enableAutoSave() {
autoSaveHandler = new AutoSaveHandler();
if (getConfig().getBoolean("autoSave.enabled"))
autoSaveHandler.runTaskTimer(this, autoSaveHandler.parseInterval(Main.get().getConfig().getString("autoSave.time")), autoSaveHandler.parseInterval(Main.get().getConfig().getString("autoSave.time")));
}

private void loadConfigs() {
if (!new File(getDataFolder(), "config.yml").exists()) {
saveDefaultConfig();
Expand Down
127 changes: 0 additions & 127 deletions src/main/java/timongcraft/system/commands/PluginCommand.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/java/timongcraft/system/util/AutoSaveHandler.java

This file was deleted.

6 changes: 4 additions & 2 deletions src/main/java/timongcraft/system/util/CommandAPILoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import java.util.stream.Stream;

public class CommandAPILoader {

public static void load(String version, boolean noConfig) throws IOException, InvalidPluginException, InvalidDescriptionException {
try (Stream<Path> pathStream = Files.list(Path.of("plugins"))) {
if (pathStream.anyMatch(file -> {
if (!(file.getFileName().toString().toLowerCase().contains("commandapi") && file.getFileName().toString().endsWith(".jar")))
return false;

if (!file.getFileName().toString().toLowerCase().equals("commandapi-" + version + ".jar")) {
if (noConfig || Main.get().getConfig().getBoolean("CommandAPI.warnings")) {
if (noConfig || Main.get().getConfig().getBoolean("commandAPI.warnings")) {
Main.get().getLogger().warning("You may have loaded an incompatible version of CommandAPI. For best compatibility, use version " + version + ".");
}
}
Expand All @@ -36,7 +37,7 @@ public static void load(String version, boolean noConfig) throws IOException, In

int responseCode = con.getResponseCode();
if (responseCode != 200) {
Main.get().getLogger().warning("Failed to check for updates. Response code: " + responseCode);
Main.get().getLogger().warning("Failed to load required library CommandAPI. Response code: " + responseCode);
}

Path commandAPIPath = Path.of("plugins/CommandAPI-" + version + ".jar");
Expand All @@ -45,4 +46,5 @@ public static void load(String version, boolean noConfig) throws IOException, In
con.disconnect();
Bukkit.getPluginManager().loadPlugin(commandAPIPath.toFile());
}

}
9 changes: 2 additions & 7 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Do not edit config version or things might break!
configVersion: 1.8
configVersion: 1.9

prefix:
pluginPrefix: '§7[§1System§7] §f'
Expand Down Expand Up @@ -101,11 +101,6 @@ maintenance:
#Must be called maintenance-icon.png
icon: false

#Auto save your world if your hoster doesn't have that functionality
autoSave:
enabled: false
time: '1h'

#This makes to so if you right-click on wheat, potatoes, carrots, beetroots and cocoa beans
easyHarvest:
enabled: false
Expand All @@ -121,7 +116,7 @@ blockedCommands: []
#These prefixes are blocked e.g. 'bukkit:'
blockedPrefixes: []

CommandAPI:
commandAPI:
#Warns if an incompatible version of CommandAPI is loaded etc.
warnings: true
#Automaticly downloads and loads the CommandAPI if it isn't present
Expand Down

0 comments on commit 54ad854

Please sign in to comment.