This commit is contained in:
alisolarflare 2016-11-25 19:59:31 -05:00
commit 88cab094ab
6 changed files with 118 additions and 2 deletions

View file

@ -4,11 +4,16 @@ import java.util.Map.Entry;
import java.util.UUID;
import java.util.logging.Logger;
import javax.persistence.PersistenceException;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import buttondevteam.lib.CPlayer;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCPlayer;
import buttondevteam.lib.db.CData;
import buttondevteam.lib.db.DataManager;
public class MainPlugin extends JavaPlugin {
public static MainPlugin Instance;
@ -23,10 +28,29 @@ public class MainPlugin extends JavaPlugin {
pdfFile = getDescription();
logger = getLogger();
setupDatabase();
DataManager.setDatabase(getDatabase());
final UUID cid = UUID.randomUUID();
final UUID mcid = UUID.randomUUID();
System.out.println(cid);
System.out.println(mcid);
System.out.println("----");
DataManager.save(new CPlayer(cid, mcid));
System.out.println("----");
System.out.println(DataManager.load(CPlayer.class, cid).getMinecraftID());
logger.info(pdfFile.getName() + " has been Enabled (V." + pdfFile.getVersion() + ").");
TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this);
}
private void setupDatabase() {
try {
getDatabase().find(CPlayer.class).findRowCount();
} catch (PersistenceException ex) {
System.out.println("Installing database for ButtonCore due to first time usage");
installDDL();
}
}
@Override
public void onDisable() {
logger.info("Saving player data...");
@ -35,5 +59,4 @@ public class MainPlugin extends JavaPlugin {
}
logger.info("Player data saved.");
}
}

View file

@ -0,0 +1,42 @@
package buttondevteam.lib;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import buttondevteam.lib.db.CData;
@Entity
public class CPlayer implements CData {
public CPlayer() {
}
public CPlayer(UUID chromaid, UUID mcid) {
id = chromaid;
this.mcid = mcid;
}
@Id
private UUID id;
@Column(unique = true)
private UUID mcid;
@Override
public UUID getChromaID() {
return id;
}
public void setChromaID(UUID id) {
this.id = id;
}
public UUID getMinecraftID() {
return mcid;
}
public void setMinecraftID(UUID mcid) {
this.mcid = mcid;
}
}

View file

@ -6,6 +6,7 @@ public class Gary extends DebugPotato {
public Gary() {
super.setMessage("I'M A POTATO");
super.setType("Gary");
}
/**
@ -31,4 +32,12 @@ public class Gary extends DebugPotato {
public DebugPotato setMessage(String[] message) {
return this;
}
/**
* Gary has it's name already, therefore this method has no effect.
*/
@Override
public DebugPotato setType(String type) {
return this;
}
}

View file

@ -0,0 +1,7 @@
package buttondevteam.lib.db;
import java.util.UUID;
public interface CData {
public UUID getChromaID();
}

View file

@ -0,0 +1,34 @@
package buttondevteam.lib.db;
import java.util.UUID;
import javax.persistence.PersistenceException;
import org.bukkit.plugin.java.JavaPlugin;
import com.avaje.ebean.EbeanServer;
import buttondevteam.core.MainPlugin;
public final class DataManager {
private static EbeanServer database;
/**
* Can be only used once and is used by {@link MainPlugin}
*
* @param database
* The database to set
*/
public static void setDatabase(EbeanServer database) {
DataManager.database = database;
}
public static <T extends CData> T load(Class<T> cl, UUID id) {
return database.find(cl, id);
}
public static <T extends CData> void save(T obj) {
database.save(obj);
}
}

View file

@ -2,3 +2,4 @@ name: ButtonCore
main: buttondevteam.core.MainPlugin
version: 1.0
author: TBMCPlugins
database: true