mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 17:18:47 +01:00
Made database classes available to add-ons.
This commit is contained in:
parent
4c1f7f24a5
commit
01b7b04dfc
@ -20,11 +20,7 @@ commands:
|
|||||||
description: Admin commands
|
description: Admin commands
|
||||||
usage: |
|
usage: |
|
||||||
/bsadmin help
|
/bsadmin help
|
||||||
bsc:
|
|
||||||
description: Game challenges
|
|
||||||
aliases: [c, challenge, bschallenge, challenges]
|
|
||||||
usage: |
|
|
||||||
/challenge
|
|
||||||
permissions:
|
permissions:
|
||||||
bskyblock.*:
|
bskyblock.*:
|
||||||
default: false
|
default: false
|
||||||
|
@ -29,7 +29,7 @@ import us.tastybento.bskyblock.util.Util;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin = BSkyBlock.getPlugin();
|
||||||
|
|
||||||
public final Map<String, ArgumentHandler> argumentsMap;
|
public final Map<String, ArgumentHandler> argumentsMap;
|
||||||
public final Set<ArgumentHandler> handlers;
|
public final Set<ArgumentHandler> handlers;
|
||||||
@ -47,8 +47,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
protected AbstractCommand(BSkyBlock plugin, String label, String[] aliases, boolean help) {
|
protected AbstractCommand(String label, String[] aliases, boolean help) {
|
||||||
this.plugin = plugin;
|
|
||||||
this.argumentsMap = new LinkedHashMap<>();
|
this.argumentsMap = new LinkedHashMap<>();
|
||||||
this.handlers = new HashSet<>();
|
this.handlers = new HashSet<>();
|
||||||
this.label = label;
|
this.label = label;
|
||||||
|
@ -34,7 +34,7 @@ public class AdminCommand extends AbstractCommand {
|
|||||||
* @param plugin
|
* @param plugin
|
||||||
*/
|
*/
|
||||||
public AdminCommand(BSkyBlock plugin) {
|
public AdminCommand(BSkyBlock plugin) {
|
||||||
super(plugin, Settings.ADMINCOMMAND, new String[0], true);
|
super(Settings.ADMINCOMMAND, new String[0], true);
|
||||||
plugin.getCommand(Settings.ADMINCOMMAND).setExecutor(this);
|
plugin.getCommand(Settings.ADMINCOMMAND).setExecutor(this);
|
||||||
plugin.getCommand(Settings.ADMINCOMMAND).setTabCompleter(this);
|
plugin.getCommand(Settings.ADMINCOMMAND).setTabCompleter(this);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -53,7 +53,7 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
protected Set<UUID> kickingPlayers = new HashSet<>();
|
protected Set<UUID> kickingPlayers = new HashSet<>();
|
||||||
|
|
||||||
public IslandCommand(BSkyBlock plugin) {
|
public IslandCommand(BSkyBlock plugin) {
|
||||||
super(plugin, Settings.ISLANDCOMMAND, new String[]{"is"}, true);
|
super(Settings.ISLANDCOMMAND, new String[]{"is"}, true);
|
||||||
plugin.getCommand(Settings.ISLANDCOMMAND).setExecutor(this);
|
plugin.getCommand(Settings.ISLANDCOMMAND).setExecutor(this);
|
||||||
plugin.getCommand(Settings.ISLANDCOMMAND).setTabCompleter(this);
|
plugin.getCommand(Settings.ISLANDCOMMAND).setTabCompleter(this);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package us.tastybento.bskyblock.database;
|
package us.tastybento.bskyblock.database;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
|
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
@ -41,6 +42,6 @@ public abstract class BSBDatabase {
|
|||||||
* @param dataObjectClass
|
* @param dataObjectClass
|
||||||
* @return database handler
|
* @return database handler
|
||||||
*/
|
*/
|
||||||
public abstract AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> dataObjectClass);
|
public abstract AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> dataObjectClass);
|
||||||
|
|
||||||
}
|
}
|
@ -1,13 +1,14 @@
|
|||||||
package us.tastybento.bskyblock.database.flatfile;
|
package us.tastybento.bskyblock.database.flatfile;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
|
|
||||||
public class FlatFileDatabase extends BSBDatabase{
|
public class FlatFileDatabase extends BSBDatabase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
|
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) {
|
||||||
return new FlatFileDatabaseHandler<>(plugin, type, new FlatFileDatabaseConnecter(plugin, null));
|
return new FlatFileDatabaseHandler<>(plugin, type, new FlatFileDatabaseConnecter(plugin, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
|
||||||
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
||||||
import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
|
import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
|
||||||
|
|
||||||
@ -15,11 +15,11 @@ public class FlatFileDatabaseConnecter implements DatabaseConnecter {
|
|||||||
|
|
||||||
private static final int MAX_LOOPS = 100;
|
private static final int MAX_LOOPS = 100;
|
||||||
private static final String DATABASE_FOLDER_NAME = "database";
|
private static final String DATABASE_FOLDER_NAME = "database";
|
||||||
private BSkyBlock plugin;
|
private Plugin plugin;
|
||||||
private File dataFolder;
|
private File dataFolder;
|
||||||
|
|
||||||
|
|
||||||
public FlatFileDatabaseConnecter(BSkyBlock plugin, DatabaseConnectionSettingsImpl databaseConnectionSettingsImpl) {
|
public FlatFileDatabaseConnecter(Plugin plugin, DatabaseConnectionSettingsImpl databaseConnectionSettingsImpl) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
|
dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.MemorySection;
|
import org.bukkit.configuration.MemorySection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
|
||||||
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
@ -39,7 +39,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
|
|
||||||
private static final String DATABASE_FOLDER_NAME = "database";
|
private static final String DATABASE_FOLDER_NAME = "database";
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
public FlatFileDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
|
public FlatFileDatabaseHandler(Plugin plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
|
||||||
super(plugin, type, databaseConnecter);
|
super(plugin, type, databaseConnecter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,6 +269,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
if (propertyDescriptor.getPropertyType().equals(HashMap.class) || propertyDescriptor.getPropertyType().equals(Map.class)) {
|
if (propertyDescriptor.getPropertyType().equals(HashMap.class) || propertyDescriptor.getPropertyType().equals(Map.class)) {
|
||||||
// Maps need to have keys serialized
|
// Maps need to have keys serialized
|
||||||
//plugin.getLogger().info("DEBUG: Map for " + field.getName());
|
//plugin.getLogger().info("DEBUG: Map for " + field.getName());
|
||||||
|
if (value != null) {
|
||||||
Map<Object, Object> result = new HashMap<Object, Object>();
|
Map<Object, Object> result = new HashMap<Object, Object>();
|
||||||
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
||||||
// Serialize all key types
|
// Serialize all key types
|
||||||
@ -277,15 +278,19 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
}
|
}
|
||||||
// Save the list in the config file
|
// Save the list in the config file
|
||||||
config.set(field.getName(), result);
|
config.set(field.getName(), result);
|
||||||
|
}
|
||||||
} else if (propertyDescriptor.getPropertyType().equals(Set.class)) {
|
} else if (propertyDescriptor.getPropertyType().equals(Set.class)) {
|
||||||
// Sets need to be serialized as string lists
|
// Sets need to be serialized as string lists
|
||||||
//plugin.getLogger().info("DEBUG: Set for " + field.getName());
|
if (DEBUG)
|
||||||
|
plugin.getLogger().info("DEBUG: Set for " + field.getName());
|
||||||
|
if (value != null) {
|
||||||
List<Object> list = new ArrayList<Object>();
|
List<Object> list = new ArrayList<Object>();
|
||||||
for (Object object : (Set<Object>)value) {
|
for (Object object : (Set<Object>)value) {
|
||||||
list.add(serialize(object));
|
list.add(serialize(object));
|
||||||
}
|
}
|
||||||
// Save the list in the config file
|
// Save the list in the config file
|
||||||
config.set(field.getName(), list);
|
config.set(field.getName(), list);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// For all other data that doesn't need special serialization
|
// For all other data that doesn't need special serialization
|
||||||
config.set(field.getName(), serialize(value));
|
config.set(field.getName(), serialize(value));
|
||||||
|
@ -5,6 +5,8 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ public abstract class AbstractDatabaseHandler<T> {
|
|||||||
protected final String deleteQuery;
|
protected final String deleteQuery;
|
||||||
|
|
||||||
|
|
||||||
protected BSkyBlock plugin;
|
protected Plugin plugin;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,7 +50,7 @@ public abstract class AbstractDatabaseHandler<T> {
|
|||||||
* Contains the settings to create a connection to the database
|
* Contains the settings to create a connection to the database
|
||||||
* like host/port/database/user/password
|
* like host/port/database/user/password
|
||||||
*/
|
*/
|
||||||
protected AbstractDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
|
protected AbstractDatabaseHandler(Plugin plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.databaseConnecter = databaseConnecter;
|
this.databaseConnecter = databaseConnecter;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package us.tastybento.bskyblock.database.mongodb;
|
package us.tastybento.bskyblock.database.mongodb;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
|
|
||||||
public class MongoDBDatabase extends BSBDatabase{
|
public class MongoDBDatabase extends BSBDatabase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
|
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) {
|
||||||
return null; //TODO
|
return null; //TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package us.tastybento.bskyblock.database.mysql;
|
package us.tastybento.bskyblock.database.mysql;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
|
import us.tastybento.bskyblock.database.DatabaseConnectionSettingsImpl;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
@ -8,7 +9,7 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
|||||||
public class MySQLDatabase extends BSBDatabase{
|
public class MySQLDatabase extends BSBDatabase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
|
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) {
|
||||||
return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl()));
|
return new MySQLDatabaseHandler<>(plugin, type, new MySQLDatabaseConnecter(new DatabaseConnectionSettingsImpl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
|
||||||
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
import us.tastybento.bskyblock.database.DatabaseConnecter;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
@ -99,7 +99,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
* @param type - the type of class to be stored in the database. Must inherit DataObject
|
* @param type - the type of class to be stored in the database. Must inherit DataObject
|
||||||
* @param databaseConnecter - authentication details for the database
|
* @param databaseConnecter - authentication details for the database
|
||||||
*/
|
*/
|
||||||
public MySQLDatabaseHandler(BSkyBlock plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
|
public MySQLDatabaseHandler(Plugin plugin, Class<T> type, DatabaseConnecter databaseConnecter) {
|
||||||
super(plugin, type, databaseConnecter);
|
super(plugin, type, databaseConnecter);
|
||||||
try {
|
try {
|
||||||
connection = databaseConnecter.createConnection();
|
connection = databaseConnecter.createConnection();
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package us.tastybento.bskyblock.database.sqlite;
|
package us.tastybento.bskyblock.database.sqlite;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
|
|
||||||
public class SQLiteDatabase extends BSBDatabase{
|
public class SQLiteDatabase extends BSBDatabase{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractDatabaseHandler<?> getHandler(BSkyBlock plugin, Class<?> type) {
|
public AbstractDatabaseHandler<?> getHandler(Plugin plugin, Class<?> type) {
|
||||||
// return new SQLLiteDatabaseHandler<Island>(plugin, Island.class, new FlatFileDatabaseConnecter(plugin, null));
|
// return new SQLLiteDatabaseHandler<Island>(plugin, Island.class, new FlatFileDatabaseConnecter(plugin, null));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user