BREAKING: Renamed a few API classes to a more generic name

`BBConfig` to `Config`.
`BBDatabase` to `Database`.
`BBDbSetup` to `DatabaseSetup`.

Sorry @tastybento, hope it won't bother you too much :/
This commit is contained in:
Florian CUNY 2018-08-06 15:19:06 +02:00
parent ba557a1068
commit 5fa8f3997f
11 changed files with 35 additions and 40 deletions

View File

@ -5,13 +5,13 @@ import org.bukkit.World;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import world.bentobox.bentobox.api.configuration.BBConfig; import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent; import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.placeholders.PlaceholderHandler; import world.bentobox.bentobox.api.placeholders.PlaceholderHandler;
import world.bentobox.bentobox.api.user.Notifier; import world.bentobox.bentobox.api.user.Notifier;
import world.bentobox.bentobox.commands.BentoBoxCommand; import world.bentobox.bentobox.commands.BentoBoxCommand;
import world.bentobox.bentobox.database.BBDbSetup; import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.listeners.BannedVisitorCommands; import world.bentobox.bentobox.listeners.BannedVisitorCommands;
import world.bentobox.bentobox.listeners.BlockEndDragon; import world.bentobox.bentobox.listeners.BlockEndDragon;
import world.bentobox.bentobox.listeners.JoinLeaveListener; import world.bentobox.bentobox.listeners.JoinLeaveListener;
@ -78,7 +78,7 @@ public class BentoBox extends JavaPlugin {
flagsManager = new FlagsManager(instance); flagsManager = new FlagsManager(instance);
// Load settings from config.yml. This will check if there are any issues with it too. // Load settings from config.yml. This will check if there are any issues with it too.
settings = new BBConfig<>(this, Settings.class).loadConfigObject(""); settings = new Config<>(this, Settings.class).loadConfigObject("");
// Start Database managers // Start Database managers
playersManager = new PlayersManager(this); playersManager = new PlayersManager(this);
// Check if this plugin is now disabled (due to bad database handling) // Check if this plugin is now disabled (due to bad database handling)
@ -142,9 +142,6 @@ public class BentoBox extends JavaPlugin {
// Fire plugin ready event // Fire plugin ready event
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent()); Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
}); });
} }
@ -183,7 +180,7 @@ public class BentoBox extends JavaPlugin {
} }
// Save settings // Save settings
if (settings != null) { if (settings != null) {
new BBConfig<>(this, Settings.class).saveConfigObject(settings); new Config<>(this, Settings.class).saveConfigObject(settings);
} }
} }
@ -218,7 +215,7 @@ public class BentoBox extends JavaPlugin {
@Override @Override
public String getValue() { public String getValue() {
return BBDbSetup.getDatabase().toString(); return DatabaseSetup.getDatabase().toString();
} }
}); });
} }

View File

@ -8,7 +8,7 @@ import java.util.Set;
import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.api.configuration.ConfigEntry; import world.bentobox.bentobox.api.configuration.ConfigEntry;
import world.bentobox.bentobox.api.configuration.StoreAt; import world.bentobox.bentobox.api.configuration.StoreAt;
import world.bentobox.bentobox.database.BBDbSetup.DatabaseType; import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
import world.bentobox.bentobox.database.objects.DataObject; import world.bentobox.bentobox.database.objects.DataObject;
/** /**

View File

@ -17,17 +17,17 @@ import world.bentobox.bentobox.database.flatfile.FlatFileDatabase;
* *
* @param <T> * @param <T>
*/ */
public class BBConfig<T> { public class Config<T> {
private AbstractDatabaseHandler<T> handler; private AbstractDatabaseHandler<T> handler;
private Logger logger; private Logger logger;
public BBConfig(BentoBox plugin, Class<T> type) { public Config(BentoBox plugin, Class<T> type) {
this.logger = plugin.getLogger(); this.logger = plugin.getLogger();
handler = new FlatFileDatabase().getHandler(type); handler = new FlatFileDatabase().getHandler(type);
} }
public BBConfig(Addon addon, Class<T> type) { public Config(Addon addon, Class<T> type) {
this.logger = addon.getLogger(); this.logger = addon.getLogger();
handler = new FlatFileDatabase().getHandler(type); handler = new FlatFileDatabase().getHandler(type);
} }

View File

@ -15,20 +15,19 @@ import world.bentobox.bentobox.api.addons.Addon;
* *
* @param <T> * @param <T>
*/ */
public class BBDatabase<T> { public class Database<T> {
private AbstractDatabaseHandler<T> handler; private AbstractDatabaseHandler<T> handler;
private Logger logger; private Logger logger;
public BBDatabase(BentoBox plugin, Class<T> type) { public Database(BentoBox plugin, Class<T> type) {
this.logger = plugin.getLogger(); this.logger = plugin.getLogger();
handler = BBDbSetup.getDatabase().getHandler(type); handler = DatabaseSetup.getDatabase().getHandler(type);
} }
public BBDatabase(Addon addon, Class<T> type) { public Database(Addon addon, Class<T> type) {
this.logger = addon.getLogger(); this.logger = addon.getLogger();
handler = BBDbSetup.getDatabase().getHandler(type); handler = DatabaseSetup.getDatabase().getHandler(type);
} }
/** /**
@ -106,5 +105,4 @@ public class BBDatabase<T> {
handler.close(); handler.close();
} }
} }

View File

@ -5,14 +5,14 @@ import world.bentobox.bentobox.database.flatfile.FlatFileDatabase;
import world.bentobox.bentobox.database.mongodb.MongoDBDatabase; import world.bentobox.bentobox.database.mongodb.MongoDBDatabase;
import world.bentobox.bentobox.database.mysql.MySQLDatabase; import world.bentobox.bentobox.database.mysql.MySQLDatabase;
public abstract class BBDbSetup { public abstract class DatabaseSetup {
/** /**
* Gets the type of database being used. Currently supported options are * Gets the type of database being used. Currently supported options are
* FLATFILE and MYSQL. Default is FLATFILE * FLATFILE and MYSQL. Default is FLATFILE
* @return Database type * @return Database type
*/ */
public static BBDbSetup getDatabase(){ public static DatabaseSetup getDatabase(){
for(DatabaseType type : DatabaseType.values()){ for(DatabaseType type : DatabaseType.values()){
if(type == BentoBox.getInstance().getSettings().getDatabaseType()) { if(type == BentoBox.getInstance().getSettings().getDatabaseType()) {
return type.database; return type.database;
@ -26,9 +26,9 @@ public abstract class BBDbSetup {
MYSQL(new MySQLDatabase()), MYSQL(new MySQLDatabase()),
MONGO(new MongoDBDatabase()); MONGO(new MongoDBDatabase());
BBDbSetup database; DatabaseSetup database;
DatabaseType(BBDbSetup database){ DatabaseType(DatabaseSetup database){
this.database = database; this.database = database;
} }
} }

View File

@ -2,9 +2,9 @@ package world.bentobox.bentobox.database.flatfile;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.AbstractDatabaseHandler; import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.BBDbSetup; import world.bentobox.bentobox.database.DatabaseSetup;
public class FlatFileDatabase extends BBDbSetup{ public class FlatFileDatabase extends DatabaseSetup {
/** /**
* Get the config * Get the config

View File

@ -2,10 +2,10 @@ package world.bentobox.bentobox.database.mongodb;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.AbstractDatabaseHandler; import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.BBDbSetup; import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl; import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
public class MongoDBDatabase extends BBDbSetup{ public class MongoDBDatabase extends DatabaseSetup {
@Override @Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) { public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {

View File

@ -2,10 +2,10 @@ package world.bentobox.bentobox.database.mysql;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.AbstractDatabaseHandler; import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.BBDbSetup; import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl; import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
public class MySQLDatabase extends BBDbSetup{ public class MySQLDatabase extends DatabaseSetup {
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -25,7 +25,7 @@ import org.bukkit.util.Vector;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.BBDatabase; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags; import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.island.IslandCache; import world.bentobox.bentobox.managers.island.IslandCache;
@ -50,7 +50,7 @@ public class IslandsManager {
*/ */
private Map<World, Island> spawn; private Map<World, Island> spawn;
private BBDatabase<Island> handler; private Database<Island> handler;
/** /**
* The last locations where an island were put. * The last locations where an island were put.
@ -73,7 +73,7 @@ public class IslandsManager {
public IslandsManager(BentoBox plugin){ public IslandsManager(BentoBox plugin){
this.plugin = plugin; this.plugin = plugin;
// Set up the database handler to store and retrieve Island classes // Set up the database handler to store and retrieve Island classes
handler = new BBDatabase<>(plugin, Island.class); handler = new Database<>(plugin, Island.class);
islandCache = new IslandCache(); islandCache = new IslandCache();
spawn = new HashMap<>(); spawn = new HashMap<>();
last = new HashMap<>(); last = new HashMap<>();

View File

@ -14,15 +14,15 @@ import org.bukkit.World;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.BBDatabase; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Names; import world.bentobox.bentobox.database.objects.Names;
import world.bentobox.bentobox.database.objects.Players; import world.bentobox.bentobox.database.objects.Players;
public class PlayersManager { public class PlayersManager {
private BentoBox plugin; private BentoBox plugin;
private BBDatabase<Players> handler; private Database<Players> handler;
private BBDatabase<Names> names; private Database<Names> names;
private Map<UUID, Players> playerCache; private Map<UUID, Players> playerCache;
private Set<UUID> inTeleport; private Set<UUID> inTeleport;
@ -37,9 +37,9 @@ public class PlayersManager {
public PlayersManager(BentoBox plugin){ public PlayersManager(BentoBox plugin){
this.plugin = plugin; this.plugin = plugin;
// Set up the database handler to store and retrieve Players classes // Set up the database handler to store and retrieve Players classes
handler = new BBDatabase<>(plugin, Players.class); handler = new Database<>(plugin, Players.class);
// Set up the names database // Set up the names database
names = new BBDatabase<>(plugin, Names.class); names = new Database<>(plugin, Names.class);
playerCache = new HashMap<>(); playerCache = new HashMap<>();
inTeleport = new HashSet<>(); inTeleport = new HashSet<>();
} }
@ -48,7 +48,7 @@ public class PlayersManager {
* Used only for testing. Sets the database to a mock database. * Used only for testing. Sets the database to a mock database.
* @param handler - handler * @param handler - handler
*/ */
public void setHandler(BBDatabase<Players> handler) { public void setHandler(Database<Players> handler) {
this.handler = handler; this.handler = handler;
} }

View File

@ -34,7 +34,7 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.BBDatabase; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Players; import world.bentobox.bentobox.database.objects.Players;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -54,7 +54,7 @@ public class PlayersManagerTest {
private World nether; private World nether;
private World end; private World end;
@Mock @Mock
private BBDatabase<Players> db; private Database<Players> db;
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception