Switched from plugin.getServer() to Bukkit.getServer() to enable tests

plugin.getServer() cannot be mocked because it is final.
This commit is contained in:
tastybento 2019-03-11 22:58:30 -07:00
parent adf0b8247f
commit cb09ec2e3a
5 changed files with 17 additions and 13 deletions

View File

@ -1,5 +1,7 @@
package world.bentobox.bentobox.database.mongodb;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
@ -11,10 +13,10 @@ public class MongoDBDatabase implements DatabaseSetup {
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
BentoBox plugin = BentoBox.getInstance();
// Check if the MongoDB plugin exists
if (plugin.getServer().getPluginManager().getPlugin("BsbMongo") == null) {
if (Bukkit.getServer().getPluginManager().getPlugin("BsbMongo") == null) {
plugin.logError("You must install BsbMongo plugin for MongoDB support!");
plugin.logError("See: https://github.com/tastybento/bsbMongo/releases/");
plugin.getServer().getPluginManager().disablePlugin(plugin);
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
return null;
}
return new MongoDBDatabaseHandler<>(plugin, type, new MongoDBDatabaseConnector(new DatabaseConnectionSettingsImpl(

View File

@ -720,8 +720,8 @@ public class Island implements DataObject {
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), "[uuid]", owner.toString());
// Fixes #getLastPlayed() returning 0 when it is the owner's first connection.
long lastPlayed = (plugin.getServer().getOfflinePlayer(owner).getLastPlayed() != 0) ?
plugin.getServer().getOfflinePlayer(owner).getLastPlayed() : plugin.getServer().getOfflinePlayer(owner).getFirstPlayed();
long lastPlayed = (Bukkit.getServer().getOfflinePlayer(owner).getLastPlayed() != 0) ?
Bukkit.getServer().getOfflinePlayer(owner).getLastPlayed() : Bukkit.getServer().getOfflinePlayer(owner).getFirstPlayed();
user.sendMessage("commands.admin.info.last-login","[date]", new Date(lastPlayed).toString());
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));

View File

@ -175,7 +175,7 @@ public class JoinLeaveListener implements Listener {
plugin.getIWM().getOverWorlds().forEach(w -> {
Island island = plugin.getIslands().getIsland(w, User.getInstance(event.getPlayer()));
// Are there any online players still for this island?
if (island != null && plugin.getServer().getOnlinePlayers().stream()
if (island != null && Bukkit.getServer().getOnlinePlayers().stream()
.filter(p -> !event.getPlayer().equals(p))
.noneMatch(p -> plugin.getIslands().getMembers(w, event.getPlayer().getUniqueId()).contains(p.getUniqueId()))) {
// No, there are no more players online on this island

View File

@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
@ -31,7 +32,7 @@ public class HeadGetter {
@SuppressWarnings("deprecation")
private void runPlayerHeadGetter() {
plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
synchronized(names) {
Iterator<Entry<String, PanelItem>> it = names.entrySet().iterator();
if (it.hasNext()) {
@ -46,7 +47,7 @@ public class HeadGetter {
if (headRequesters.containsKey(en.getKey())) {
for (HeadRequester req : headRequesters.get(en.getKey())) {
en.getValue().setHead(playerSkull.clone());
plugin.getServer().getScheduler().runTask(plugin, () -> req.setHead(en.getValue()));
Bukkit.getServer().getScheduler().runTask(plugin, () -> req.setHead(en.getValue()));
}
}
it.remove();
@ -55,7 +56,7 @@ public class HeadGetter {
}, 0L, 20L);
}
/**
/**
* @param panelItem - head to update
* @param requester - callback class
*/

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.versions;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
@ -119,7 +120,7 @@ public class ServerCompatibility {
public Compatibility checkCompatibility(BentoBox plugin) {
if (result == null) {
// Check the server version first
ServerVersion version = getServerVersion(plugin.getServer());
ServerVersion version = getServerVersion(Bukkit.getServer());
if (version == null || version.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
// 'Version = null' means that it's not listed. And therefore, it's implicitly incompatible.
@ -128,7 +129,7 @@ public class ServerCompatibility {
}
// Now, check the server software
ServerSoftware software = getServerSoftware(plugin.getServer());
ServerSoftware software = getServerSoftware(Bukkit.getServer());
if (software == null || software.getCompatibility().equals(Compatibility.INCOMPATIBLE)) {
// 'software = null' means that it's not listed. And therefore, it's implicitly incompatible.