164 lines
3.9 KiB
Java
164 lines
3.9 KiB
Java
package com.rsscripting.rswarehouse;
|
|
|
|
import com.rsscripting.rswarehouse.dao.admin.PurgeVariantsDAO;
|
|
import com.rsscripting.rswarehouse.chestautoprocess.ChestAutoProcessingTask;
|
|
import com.rsscripting.rswarehouse.commands.RSPluginCommand;
|
|
import com.rsscripting.rswarehouse.commands.RSTabCompleter;
|
|
import com.rsscripting.rswarehouse.commands.ShopCommand;
|
|
import com.rsscripting.rswarehouse.config.ConfigManager;
|
|
import com.rsscripting.rswarehouse.database.DatabaseManager;
|
|
import com.rsscripting.rswarehouse.registration.ListenerRegistration;
|
|
import com.rsscripting.rswarehouse.constants.RSConstants;
|
|
import com.rsscripting.rswarehouse.updatechecker.GitHubUpdateChecker;
|
|
import org.bukkit.command.PluginCommand;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
public class RSWarehouse
|
|
extends JavaPlugin {
|
|
|
|
private static RSWarehouse instance;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
|
|
saveDefaultConfig();
|
|
|
|
instance = this;
|
|
|
|
/* CONFIG */
|
|
ConfigManager.setup();
|
|
|
|
/* Database */
|
|
DatabaseManager.initialize(
|
|
this
|
|
);
|
|
|
|
PurgeVariantsDAO
|
|
.purgeAll();
|
|
|
|
/* REGISTER LISTENERS */
|
|
ListenerRegistration.registerAll(
|
|
this
|
|
);
|
|
|
|
/* REGISTER COMMANDS */
|
|
registerCommands();
|
|
|
|
/* UPDATE CHECKER */
|
|
GitHubUpdateChecker.checkForUpdates();
|
|
|
|
/* ENABLE MESSAGE */
|
|
logEnabledMessage();
|
|
|
|
/* Start Chest Auto-Processing Tasks */
|
|
startChestAutoProcessingTask();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
|
|
getLogger().info(
|
|
RSConstants.PLUGIN_NAME
|
|
+ " Disabled"
|
|
);
|
|
|
|
}
|
|
|
|
/* Register Commands method */
|
|
private void registerCommands() {
|
|
|
|
/* rswarehous command */
|
|
PluginCommand command =
|
|
getCommand(
|
|
RSConstants.COMMAND_ALIAS
|
|
);
|
|
|
|
if (command != null) {
|
|
|
|
command.setExecutor(
|
|
new RSPluginCommand()
|
|
);
|
|
|
|
command.setTabCompleter(
|
|
new RSTabCompleter()
|
|
);
|
|
|
|
}
|
|
|
|
/* Shop Comment */
|
|
PluginCommand shopCommand = getCommand("shop");
|
|
|
|
if (shopCommand != null) {
|
|
shopCommand.setExecutor(new ShopCommand());
|
|
}
|
|
|
|
}
|
|
|
|
/* Start Chest Auto Processing Task method */
|
|
private void startChestAutoProcessingTask() {
|
|
|
|
boolean chestAutoProcessingEnabled =
|
|
ConfigManager.get()
|
|
.getBoolean(
|
|
"chest-auto-processing.enabled"
|
|
);
|
|
|
|
if (!chestAutoProcessingEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int intervalSeconds =
|
|
ConfigManager.get()
|
|
.getInt(
|
|
"chest-auto-processing.interval-seconds"
|
|
);
|
|
|
|
if (intervalSeconds < 15) {
|
|
|
|
getLogger().warning(
|
|
"Chest auto processing interval "
|
|
+ "cannot be less than 15 seconds. "
|
|
+ "Using 15 seconds."
|
|
);
|
|
|
|
intervalSeconds = 15;
|
|
|
|
}
|
|
|
|
new ChestAutoProcessingTask()
|
|
.runTaskTimer(
|
|
this,
|
|
intervalSeconds * 20L,
|
|
intervalSeconds * 20L
|
|
);
|
|
|
|
getLogger().info(
|
|
"Chest auto processing enabled. "
|
|
+ "Interval: "
|
|
+ intervalSeconds
|
|
+ " seconds."
|
|
);
|
|
|
|
}
|
|
|
|
/* Log Enabled Message */
|
|
private void logEnabledMessage() {
|
|
|
|
getLogger().info(
|
|
RSConstants.PLUGIN_NAME
|
|
+ " Enabled"
|
|
);
|
|
|
|
}
|
|
|
|
/* Get Instance */
|
|
public static RSWarehouse getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
} |