Started a better player storage
Too tired rn.
This commit is contained in:
parent
9afc2f8a96
commit
1e4c0df93d
5 changed files with 15 additions and 107 deletions
|
@ -4,16 +4,11 @@ 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;
|
||||
|
@ -28,29 +23,10 @@ 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...");
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
15
src/main/java/buttondevteam/lib/TBMCPlayerBase.java
Normal file
15
src/main/java/buttondevteam/lib/TBMCPlayerBase.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package buttondevteam.lib;
|
||||
|
||||
public abstract class TBMCPlayerBase {
|
||||
/**
|
||||
* This method returns the filename for this player data. For example, for Minecraft-related data, use MC UUIDs, for Discord data, use Discord IDs, etc.
|
||||
*/
|
||||
public abstract String getFileName();
|
||||
|
||||
/**
|
||||
* This method returns the folder the file is in. For example, for Minecraft data, this should be "minecraft", for Discord, "discord", etc.
|
||||
*/
|
||||
public abstract String getFolder();
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package buttondevteam.lib.db;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface CData {
|
||||
public UUID getChromaID();
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue