Files
src
build.gradle
manifest.kod
settings.gradle
Code
13 903
src/main/java/com/topcity/rp/TopCityPlugin.java
package com.topcity.rp;
import com.topcity.rp.bank.BankService;
import com.topcity.rp.character.CharacterRepository;
import com.topcity.rp.character.IdentitySetupListener;
import com.topcity.rp.command.TopCityCommand;
import com.topcity.rp.storage.Database;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.SQLException;
public final class TopCityPlugin extends JavaPlugin {
private Database database;
private CharacterRepository characterRepository;
private BankService bankService;
@Override
public void onEnable() {
saveDefaultConfig();
try {
database = new Database(this);
characterRepository = new CharacterRepository(this, database);
bankService = new BankService(database);
} catch (SQLException exception) {
getLogger().severe("تعذر فتح قاعدة بيانات Top City: " + exception.getMessage());
getServer().getPluginManager().disablePlugin(this);
return;
}
getServer().getPluginManager().registerEvents(
new IdentitySetupListener(this, characterRepository), this);
TopCityCommand commandHandler = new TopCityCommand(this, characterRepository, bankService);
registerCommand("topcity", commandHandler);
registerCommand("identity", commandHandler);
registerCommand("balance", commandHandler);
registerCommand("pay", commandHandler);
registerCommand("bankhistory", commandHandler);
getLogger().info("تم تشغيل TopCityRP — المرحلة الأولى.");
}
private void registerCommand(String name, TopCityCommand handler) {
PluginCommand command = getCommand(name);
if (command != null) {
command.setExecutor(handler);
command.setTabCompleter(handler);
}
}
@Override
public void onDisable() {
if (database != null) {
try {
database.close();
} catch (SQLException exception) {
getLogger().severe("تعذر إغلاق قاعدة البيانات: " + exception.getMessage());
}
}
}
}