Search in sources :

Example 1 with ClaimLandCommand

use of romeplugin.zoning.claims.ClaimLandCommand in project rome-plugin by christianbookout.

the class RomePlugin method onEnable.

// runs when the plugin is enabled on the server startup
@Override
public void onEnable() {
    this.saveDefaultConfig();
    FileConfiguration config = this.getConfig();
    MysqlDataSource dataSource = new MysqlConnectionPoolDataSource();
    // we set our credentials
    dataSource.setServerName(config.getString("database.host"));
    dataSource.setPortNumber(config.getInt("database.port"));
    dataSource.setDatabaseName(config.getString("database.database"));
    dataSource.setUser(config.getString("database.username"));
    dataSource.setPassword(config.getString("database.password"));
    Material claimMaterial;
    String claimMaterialStr = config.getString("claims.claimMaterial");
    var protectedMaterialStrings = config.getStringList("claims.autoLockedBlocks");
    try {
        claimMaterial = Material.valueOf(claimMaterialStr.toUpperCase().strip());
    } catch (IllegalArgumentException e) {
        this.getLogger().log(Level.WARNING, "error getting minecraft material from " + claimMaterialStr);
        claimMaterial = LandEventListener.DEFAULT_MATERIAL;
    }
    var protectedMaterials = new HashSet<Material>();
    protectedMaterialStrings.forEach(matStr -> protectedMaterials.add(Material.valueOf(matStr)));
    var lockManager = new LockManager(this);
    SQLConn.setSource(dataSource);
    try (Connection conn = SQLConn.getConnection()) {
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS titles (" + "uuid CHAR(36) NOT NULL PRIMARY KEY," + "title " + TITLE_ENUM + " NOT NULL);").execute();
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS builders (" + "uuid CHAR(36) NOT NULL PRIMARY KEY);").execute();
        // (x0, y0) must be the top-left point and (x1, y1) must be the bottom-right
        // point
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS cityClaims (" + "x0 INT NOT NULL," + "y0 INT NOT NULL," + "x1 INT NOT NULL," + "y1 INT NOT NULL," + "owner_uuid CHAR(36) NOT NULL);").execute();
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS strawberry (" + "x0 INT NOT NULL," + "y0 INT NOT NULL," + "x1 INT NOT NULL," + "y1 INT NOT NULL," + "added_player_uuid CHAR(36) NOT NULL);").execute();
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS usernames (" + "uuid CHAR(36) NOT NULL PRIMARY KEY," + "username CHAR(32) NOT NULL);").execute();
        // all players extra claim blocks
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS extraClaimBlocks (" + "uuid CHAR(36) NOT NULL PRIMARY KEY," + "blocks INT NOT NULL DEFAULT 0);").execute();
        // fun lock stuff
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS lockedBlocks (" + "x INT NOT NULL," + "y INT NOT NULL," + "z INT NOT NULL," + "keyId INT NOT NULL);").execute();
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS lockKeys (" + "keyId INT NOT NULL AUTO_INCREMENT PRIMARY KEY," + "creator_uuid CHAR(36) NOT NULL);").execute();
        conn.prepareStatement("CREATE TABLE IF NOT EXISTS banished (" + "uuid CHAR(36) NOT NULL PRIMARY KEY);").execute();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    var roleHandler = new RoleHandler();
    var cityManager = new CityManager(config.getInt("land.initialCitySize"), config.getInt("land.cityMultiplier"), config.getInt("land.suburbsMultiplier"), config.getInt("claims.defaultClaimBlocks"), roleHandler);
    LandEventListener landListener = new LandEventListener(cityManager, lockManager, claimMaterial, protectedMaterials, config.getLong("claims.claimTimeoutMS"));
    var titles = new TitleHandler(this);
    PartyHandler partyHandler = new PartyHandler();
    var empireHandler = new EmpireHandler(partyHandler);
    SwearFilter filter = new SwearFilter(cityManager, SwearLevel.valueOf(config.getString("messages.useSwearFilter").toUpperCase()));
    var landEnterListener = new LandEnterListener(cityManager);
    var peeController = new PeeController(this);
    // var itemBank = new ItemBank(this);
    var notifications = new NotificationQueue();
    getCommand("city").setExecutor(new CityCommand(cityManager));
    getCommand("claim").setExecutor(new ClaimLandCommand(cityManager));
    getCommand("claiminfo").setExecutor(new ClaimInfoCommand());
    getCommand("removetitle").setExecutor(new RemoveTitleCommand(titles));
    getCommand("settitle").setExecutor(new SetTitleCommand(titles));
    // getCommand("bal").setExecutor(new BalanceCommand(ledger));
    getServer().getPluginManager().registerEvents(new RemovePopeListener(roleHandler), this);
    getCommand("builder").setExecutor(new BuilderCommand());
    getCommand("shout").setExecutor(new ShoutCommand(partyHandler, roleHandler));
    getCommand("pee").setExecutor(peeController);
    // getCommand("makekey").setExecutor(new MakeKeyCommand(lockManager));
    getCommand("getblocks").setExecutor(new GetClaimBlocksCommand(cityManager));
    getCommand("elections").setExecutor(new ElectionCommand(new ElectionHandler(notifications, this, roleHandler), empireHandler, roleHandler));
    getCommand("elections").setTabCompleter(new ElectionTabCompleter());
    getCommand("titles").setExecutor(new TitlesCommand());
    getCommand("parties").setExecutor(new PartyCommand(partyHandler));
    // getCommand("itembank").setExecutor(itemBank);
    getCommand("notification").setExecutor(new NotificationCommand(notifications));
    // getServer().getPluginManager().registerEvents(itemBank, this);
    getCommand("spawn").setExecutor(new SpawnCommand(cityManager));
    getCommand("banish").setExecutor(new BanishCommand(landEnterListener, roleHandler));
    getServer().getPluginManager().registerEvents(peeController, this);
    getServer().getPluginManager().registerEvents(new RoleEventListener(roleHandler, partyHandler), this);
    getServer().getPluginManager().registerEvents(new DistanceListener(config.getInt("messages.messageDistance"), filter, cityManager), this);
    // getServer().getPluginManager().registerEvents(new BlockchainEventListener(this, ledger), this);
    getServer().getPluginManager().registerEvents(landListener, this);
    getServer().getPluginManager().registerEvents(lockManager, this);
    getServer().getPluginManager().registerEvents(landEnterListener, this);
}
Also used : EmpireHandler(romeplugin.empires.EmpireHandler) SQLException(java.sql.SQLException) RoleHandler(romeplugin.empires.role.RoleHandler) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) SpawnCommand(romeplugin.misc.SpawnCommand) HashSet(java.util.HashSet) Connection(java.sql.Connection) Material(org.bukkit.Material) LockManager(romeplugin.zoning.locks.LockManager) GetClaimBlocksCommand(romeplugin.zoning.claims.GetClaimBlocksCommand) ClaimInfoCommand(romeplugin.zoning.claims.ClaimInfoCommand) RoleEventListener(romeplugin.empires.role.RoleEventListener) ClaimLandCommand(romeplugin.zoning.claims.ClaimLandCommand) MysqlDataSource(com.mysql.cj.jdbc.MysqlDataSource) MysqlConnectionPoolDataSource(com.mysql.cj.jdbc.MysqlConnectionPoolDataSource) PeeController(romeplugin.misc.PeeController)

Aggregations

MysqlConnectionPoolDataSource (com.mysql.cj.jdbc.MysqlConnectionPoolDataSource)1 MysqlDataSource (com.mysql.cj.jdbc.MysqlDataSource)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 Material (org.bukkit.Material)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 EmpireHandler (romeplugin.empires.EmpireHandler)1 RoleEventListener (romeplugin.empires.role.RoleEventListener)1 RoleHandler (romeplugin.empires.role.RoleHandler)1 PeeController (romeplugin.misc.PeeController)1 SpawnCommand (romeplugin.misc.SpawnCommand)1 ClaimInfoCommand (romeplugin.zoning.claims.ClaimInfoCommand)1 ClaimLandCommand (romeplugin.zoning.claims.ClaimLandCommand)1 GetClaimBlocksCommand (romeplugin.zoning.claims.GetClaimBlocksCommand)1 LockManager (romeplugin.zoning.locks.LockManager)1