Persistence - how do I Make a plugin open anothers db

Discussion in 'Plugin Development' started by Sammy, Apr 23, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Sammy

    Can someone tell me how do I access a database of a plugin with other plugins ?
    Here is the method that I want another plugin to use

    Code:
        public void RemoveBounty(String ply) {
            PersistenceDataBase plyReg = OpenDataBase(ply);
        }
    The OpenDataBase method is this one
    Code:
        private PersistenceDataBase OpenDataBase(String ply) {
            PersistenceDataBase persistenceClass = plugin.getDatabase().find(PersistenceDataBase.class).where().ieq("playerName", ply).findUnique();
            if (persistenceClass == null) {
                persistenceClass = new PersistenceDataBase();
            }
            return persistenceClass;
        }
    And this is how I declare the variable
    Code:
        sdLaw plugin;
    
        public BountyHandler(sdLaw plugin) {
            this.plugin = plugin;
        }
    When the 2nd plugin runs the method from the first I get a null error here:
    Code:
    plugin.getDatabase().find(PersistenceDataBase.class).where().ieq("playerName", 
     
  2. Offline

    cjc343

    Plugin 1 should provide an interface for plugin 2 to modify plugin 1's database. Plugin 2 should hook into plugin 1 and use this interface.
     
  3. Offline

    petteyg359

    Mr. Plugin was dating Miss Plugin, but when Miss Plugin found Mr. Plugin digging in her lingerie drawer, she broke his jaw.

    If a plugin's data should be accessible to another plugin, it should provide API functions. One plugin should never be directly accessing the data of another plugin.
     
  4. Offline

    Sammy

    Well the problem is here:
    Code:
     PersistenceDataBase persistenceClass = plugin.getDatabase().find(PersistenceDataBase.class).where().ieq("playerName", ply).findUnique();
    
    Then debugging I found that the second plugin.getDatabase() doesn't come with Ebean configuration...
    That configuration only works if I'm using the first plugin to get the database.

    Well I solved it, thank people =)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 14, 2016
Thread Status:
Not open for further replies.

Share This Page