Merge branch 'master' of https://github.com/TBMCPlugins/ButtonCore.git
This commit is contained in:
commit
88cab094ab
6 changed files with 118 additions and 2 deletions
|
@ -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,9 +28,28 @@ 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() {
|
||||
|
@ -35,5 +59,4 @@ public class MainPlugin extends JavaPlugin {
|
|||
}
|
||||
logger.info("Player data saved.");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
42
src/main/java/buttondevteam/lib/CPlayer.java
Normal file
42
src/main/java/buttondevteam/lib/CPlayer.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
7
src/main/java/buttondevteam/lib/db/CData.java
Normal file
7
src/main/java/buttondevteam/lib/db/CData.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package buttondevteam.lib.db;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface CData {
|
||||
public UUID getChromaID();
|
||||
}
|
34
src/main/java/buttondevteam/lib/db/DataManager.java
Normal file
34
src/main/java/buttondevteam/lib/db/DataManager.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
name: ButtonCore
|
||||
main: buttondevteam.core.MainPlugin
|
||||
version: 1.0
|
||||
author: TBMCPlugins
|
||||
author: TBMCPlugins
|
||||
database: true
|
Loading…
Reference in a new issue