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.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.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.placeholders.PlaceholderHandler;
import world.bentobox.bentobox.api.user.Notifier;
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.BlockEndDragon;
import world.bentobox.bentobox.listeners.JoinLeaveListener;
@ -78,7 +78,7 @@ public class BentoBox extends JavaPlugin {
flagsManager = new FlagsManager(instance);
// 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
playersManager = new PlayersManager(this);
// 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
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
});
}
@ -183,7 +180,7 @@ public class BentoBox extends JavaPlugin {
}
// Save settings
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
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.ConfigEntry;
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;
/**

View File

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

View File

@ -15,20 +15,19 @@ import world.bentobox.bentobox.api.addons.Addon;
*
* @param <T>
*/
public class BBDatabase<T> {
public class Database<T> {
private AbstractDatabaseHandler<T> handler;
private Logger logger;
public BBDatabase(BentoBox plugin, Class<T> type) {
public Database(BentoBox plugin, Class<T> type) {
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();
handler = BBDbSetup.getDatabase().getHandler(type);
handler = DatabaseSetup.getDatabase().getHandler(type);
}
/**
@ -106,5 +105,4 @@ public class BBDatabase<T> {
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.mysql.MySQLDatabase;
public abstract class BBDbSetup {
public abstract class DatabaseSetup {
/**
* Gets the type of database being used. Currently supported options are
* FLATFILE and MYSQL. Default is FLATFILE
* @return Database type
*/
public static BBDbSetup getDatabase(){
public static DatabaseSetup getDatabase(){
for(DatabaseType type : DatabaseType.values()){
if(type == BentoBox.getInstance().getSettings().getDatabaseType()) {
return type.database;
@ -26,9 +26,9 @@ public abstract class BBDbSetup {
MYSQL(new MySQLDatabase()),
MONGO(new MongoDBDatabase());
BBDbSetup database;
DatabaseSetup database;
DatabaseType(BBDbSetup database){
DatabaseType(DatabaseSetup 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.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

View File

@ -2,10 +2,10 @@ package world.bentobox.bentobox.database.mongodb;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.BBDbSetup;
import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
public class MongoDBDatabase extends BBDbSetup{
public class MongoDBDatabase extends DatabaseSetup {
@Override
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.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.BBDbSetup;
import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
public class MySQLDatabase extends BBDbSetup{
public class MySQLDatabase extends DatabaseSetup {
/* (non-Javadoc)

View File

@ -25,7 +25,7 @@ import org.bukkit.util.Vector;
import world.bentobox.bentobox.BentoBox;
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.lists.Flags;
import world.bentobox.bentobox.managers.island.IslandCache;
@ -50,7 +50,7 @@ public class IslandsManager {
*/
private Map<World, Island> spawn;
private BBDatabase<Island> handler;
private Database<Island> handler;
/**
* The last locations where an island were put.
@ -73,7 +73,7 @@ public class IslandsManager {
public IslandsManager(BentoBox plugin){
this.plugin = plugin;
// 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();
spawn = new HashMap<>();
last = new HashMap<>();

View File

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

View File

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