Fires team and island events. Adds new events.

A lot of the commands were not firing events. These events are now
needed by addons.

Added new JOINED, REGISTERED, UNREGISTERED reasons for events.

Switched to using Bukkit.getServer() instead of plugin.getServer() in a
number of classes because the former can be mocked but the latter cannot
be because it's marked as a final method in JavaPlugin.
This commit is contained in:
tastybento 2019-02-02 20:40:44 -08:00
parent 360cda5a1c
commit f60a39a543
30 changed files with 291 additions and 45 deletions

View File

@ -150,7 +150,7 @@ public abstract class Addon {
* @return the server object
*/
public Server getServer() {
return getPlugin().getServer();
return Bukkit.getServer();
}
public boolean isEnabled() {

View File

@ -5,11 +5,14 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
@ -69,6 +72,13 @@ public class AdminRegisterCommand extends ConfirmableCommand {
getIslands().setOwner(user, targetUUID, i);
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
user.sendMessage("general.success");
IslandBaseEvent event = IslandEvent.builder()
.island(i)
.reason(IslandEvent.Reason.REGISTERED)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
return true;
}).orElse(false)) {
// Island does not exist
@ -80,6 +90,13 @@ public class AdminRegisterCommand extends ConfirmableCommand {
getWorld().getBlockAt(i.getCenter()).setType(Material.BEDROCK);
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
user.sendMessage("general.success");
IslandBaseEvent event = IslandEvent.builder()
.island(i)
.reason(IslandEvent.Reason.CREATED)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
});
return false;
}

View File

@ -5,9 +5,14 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.island.IslandEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
public class AdminUnregisterCommand extends CompositeCommand {
@ -42,10 +47,18 @@ public class AdminUnregisterCommand extends CompositeCommand {
}
// Unregister island
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(getIslands().getIsland(getWorld(), targetUUID).getCenter().toVector()));
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
user.sendMessage("commands.admin.unregister.unregistered-island", "[xyz]", Util.xyz(oldIsland.getCenter().toVector()));
getIslands().removePlayer(getWorld(), targetUUID);
getPlayers().clearHomeLocations(getWorld(), targetUUID);
user.sendMessage("general.success");
IslandBaseEvent event = IslandEvent.builder()
.island(oldIsland)
.reason(IslandEvent.Reason.UNREGISTERED)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
return true;
}

View File

@ -3,7 +3,11 @@ package world.bentobox.bentobox.api.commands.admin.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
@ -65,6 +69,13 @@ public class AdminTeamAddCommand extends CompositeCommand {
if (teamIsland != null) {
getIslands().setJoinTeam(teamIsland, targetUUID);
user.sendMessage("general.success");
IslandBaseEvent event = TeamEvent.builder()
.island(teamIsland)
.reason(TeamEvent.Reason.JOINED)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
return true;
} else {
user.sendMessage("general.errors.player-has-no-island");

View File

@ -3,16 +3,21 @@ package world.bentobox.bentobox.api.commands.admin.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
public class AdminTeamDisbandCommand extends CompositeCommand {
public AdminTeamDisbandCommand(CompositeCommand parent) {
super(parent, "disband");
}
@Override
public void setup() {
setPermission("admin.team");
@ -46,11 +51,19 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
return false;
}
// Disband team
Island island = getIslands().getIsland(getWorld(), targetUUID);
getIslands().getMembers(getWorld(), targetUUID).forEach(m -> {
User.getInstance(m).sendMessage("commands.admin.team.disband.disbanded");
// The owner gets to keep the island
if (!m.equals(targetUUID)) {
getIslands().setLeaveTeam(getWorld(), m);
IslandBaseEvent event = TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.KICK)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
}
});
user.sendMessage("general.success");

View File

@ -3,9 +3,14 @@ package world.bentobox.bentobox.api.commands.admin.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
public class AdminTeamKickCommand extends CompositeCommand {
@ -50,6 +55,15 @@ public class AdminTeamKickCommand extends CompositeCommand {
User.getInstance(targetUUID).sendMessage("commands.admin.team.kick.admin-kicked");
getIslands().removePlayer(getWorld(), targetUUID);
user.sendMessage("general.success");
// Fire event so add-ons know
Island island = getIslands().getIsland(getWorld(), targetUUID);
IslandBaseEvent event = TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.KICK)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
return true;
}

View File

@ -1,12 +1,17 @@
package world.bentobox.bentobox.api.commands.admin.team;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
public class AdminTeamSetownerCommand extends CompositeCommand {
public AdminTeamSetownerCommand(CompositeCommand parent) {
@ -44,6 +49,15 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
// Make new owner
getIslands().setOwner(getWorld(), user, targetUUID);
user.sendMessage("general.success");
// Fire event so add-ons know
Island island = getIslands().getIsland(getWorld(), targetUUID);
IslandBaseEvent event = TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.SETOWNER)
.involvedPlayer(targetUUID)
.admin(true)
.build();
Bukkit.getServer().getPluginManager().callEvent(event);
return true;
}
}

View File

@ -4,6 +4,8 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
@ -74,7 +76,7 @@ public class IslandTeamCommand extends CompositeCommand {
.reason(TeamEvent.Reason.INFO)
.involvedPlayer(user.getUniqueId())
.build();
getPlugin().getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
return event.isCancelled();
}

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
@ -59,7 +60,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
.reason(TeamEvent.Reason.JOIN)
.involvedPlayer(playerUUID)
.build();
getPlugin().getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
@ -113,6 +114,14 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
}
getIslands().save(teamIsland);
// Fire event
IslandBaseEvent e = TeamEvent.builder()
.island(getIslands()
.getIsland(getWorld(), prospectiveOwnerUUID))
.reason(TeamEvent.Reason.JOINED)
.involvedPlayer(playerUUID)
.build();
Bukkit.getServer().getPluginManager().callEvent(e);
});
return true;

View File

@ -6,6 +6,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import com.google.common.collect.BiMap;
@ -51,7 +52,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
if (args.isEmpty() || args.size() > 1) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
if (inviteList.containsKey(playerUUID)) {
OfflinePlayer inviter = getPlugin().getServer().getOfflinePlayer(inviteList.get(playerUUID));
OfflinePlayer inviter = Bukkit.getServer().getOfflinePlayer(inviteList.get(playerUUID));
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, inviter.getName());
return true;
}
@ -105,7 +106,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
.reason(TeamEvent.Reason.INVITE)
.involvedPlayer(invitedPlayer.getUniqueId())
.build();
getPlugin().getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}

View File

@ -3,6 +3,8 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
@ -10,7 +12,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
public class IslandTeamInviteRejectCommand extends CompositeCommand {
private IslandTeamCommand itc;
public IslandTeamInviteRejectCommand(IslandTeamCommand islandTeamCommand) {
@ -37,7 +39,7 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
.reason(TeamEvent.Reason.REJECT)
.involvedPlayer(playerUUID)
.build();
getPlugin().getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}

View File

@ -3,10 +3,15 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
public class IslandTeamKickCommand extends ConfirmableCommand {
@ -64,6 +69,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
private void kick(User user, UUID targetUUID) {
User target = User.getInstance(targetUUID);
target.sendMessage("commands.island.team.kick.owner-kicked");
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
getIslands().removePlayer(getWorld(), targetUUID);
// Remove money inventory etc.
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
@ -76,6 +82,13 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
}
user.sendMessage("general.success");
// Fire event
IslandBaseEvent e = TeamEvent.builder()
.island(oldIsland)
.reason(TeamEvent.Reason.KICK)
.involvedPlayer(targetUUID)
.build();
Bukkit.getServer().getPluginManager().callEvent(e);
// Add cooldown for this player and target
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {

View File

@ -3,10 +3,15 @@ package world.bentobox.bentobox.api.commands.island.team;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
public class IslandTeamLeaveCommand extends ConfirmableCommand {
@ -41,6 +46,7 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
}
private void leave(User user) {
Island island = getIslands().getIsland(getWorld(), user);
UUID ownerUUID = getIslands().getOwner(getWorld(), user.getUniqueId());
if (ownerUUID != null) {
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
@ -57,6 +63,13 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
}
user.sendMessage("general.success");
// Fire event
IslandBaseEvent e = TeamEvent.builder()
.island(island)
.reason(TeamEvent.Reason.LEAVE)
.involvedPlayer(user.getUniqueId())
.build();
Bukkit.getServer().getPluginManager().callEvent(e);
}
}

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
@ -66,7 +68,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
.reason(TeamEvent.Reason.SETOWNER)
.involvedPlayer(targetUUID)
.build();
getPlugin().getServer().getPluginManager().callEvent(event);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
@ -81,7 +83,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
List<String> options = new ArrayList<>();
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
for (UUID member : getPlugin().getIslands().getMembers(getWorld(), user.getUniqueId())) {
options.add(getPlugin().getServer().getOfflinePlayer(member).getName());
options.add(Bukkit.getServer().getOfflinePlayer(member).getName());
}
return Optional.of(Util.tabLimit(options, lastArg));
}

View File

@ -61,6 +61,7 @@ public class Config<T> {
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| ClassNotFoundException | IntrospectionException | NoSuchMethodException | SecurityException e) {
logger.severe(() -> "Could not load config object! " + e.getMessage());
e.printStackTrace();
}
return null;

View File

@ -6,8 +6,8 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.database.objects.IslandDeletion;
import world.bentobox.bentobox.lists.Flags;
/**
@ -107,7 +107,17 @@ public class IslandEvent extends IslandBaseEvent {
/**
* Reserved
*/
UNKNOWN
UNKNOWN,
/**
* Player was unregistered from the island by admin
* @since 1.3.0
*/
UNREGISTERED,
/**
* Player was registered to the island by admin
* @since 1.3.0
*/
REGISTERED
}
public static IslandEventBuilder builder() {
@ -209,6 +219,27 @@ public class IslandEvent extends IslandBaseEvent {
return deletedIslandInfo;
}
}
/**
* Fired when a player is unregistered from an island.
* @since 1.3.0
*/
public static class IslandUnregisteredEvent extends IslandBaseEvent {
private IslandUnregisteredEvent(Island island, UUID player, boolean admin, Location location) {
super(island, player, admin, location);
}
}
/**
* Fired when a player is registered from an island.
* @since 1.3.0
*/
public static class IslandRegisteredEvent extends IslandBaseEvent {
private IslandRegisteredEvent(Island island, UUID player, boolean admin, Location location) {
super(island, player, admin, location);
}
}
/**
* Fired when an a player enters an island.
* Cancellation has no effect.
@ -389,6 +420,14 @@ public class IslandEvent extends IslandBaseEvent {
IslandUnlockEvent unlock = new IslandUnlockEvent(island, player, admin, location);
Bukkit.getServer().getPluginManager().callEvent(unlock);
return unlock;
case REGISTERED:
IslandRegisteredEvent reg = new IslandRegisteredEvent(island, player, admin, location);
Bukkit.getServer().getPluginManager().callEvent(reg);
return reg;
case UNREGISTERED:
IslandUnregisteredEvent unreg = new IslandUnregisteredEvent(island, player, admin, location);
Bukkit.getServer().getPluginManager().callEvent(unreg);
return unreg;
default:
IslandGeneralEvent general = new IslandGeneralEvent(island, player, admin, location);
Bukkit.getServer().getPluginManager().callEvent(general);

View File

@ -24,7 +24,8 @@ public class TeamEvent {
INFO,
DELETE,
UNKNOWN,
UNINVITE
UNINVITE,
JOINED
}
public static TeamEventBuilder builder() {
@ -37,6 +38,24 @@ public class TeamEvent {
super(island, player, admin, location);
}
}
/**
* Called after a player has joined an island
* @since 1.3.0
*/
public static class TeamJoinedEvent extends IslandBaseEvent {
/**
* Called after a player has joined an island
* @param island - island
* @param player - player
* @param admin - whether this was due to an admin action
* @param location - location
* @since 1.3.0
*/
private TeamJoinedEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
super(island, player, admin, location);
}
}
public static class TeamInviteEvent extends IslandBaseEvent {
private TeamInviteEvent(Island island, UUID player, boolean admin, Location location) {
// Final variables have to be declared in the constructor
@ -161,6 +180,8 @@ public class TeamEvent {
switch (reason) {
case JOIN:
return new TeamJoinEvent(island, player, admin, location);
case JOINED:
return new TeamJoinedEvent(island, player, admin, location);
case INVITE:
return new TeamInviteEvent(island, player, admin, location);
case LEAVE:

View File

@ -47,8 +47,8 @@ public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHan
// enableComplexMapKeySerialization - forces GSON to use TypeAdapters even for Map keys
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization();
// Register adapters
builder.registerTypeAdapter(Location.class, new LocationAdapter(plugin)) ;
builder.registerTypeAdapter(World.class, new WorldAdapter(plugin));
builder.registerTypeAdapter(Location.class, new LocationAdapter()) ;
builder.registerTypeAdapter(World.class, new WorldAdapter());
builder.registerTypeAdapter(Flag.class, new FlagAdapter(plugin));
builder.registerTypeAdapter(PotionEffectType.class, new PotionEffectTypeAdapter());
builder.registerTypeAdapter(ItemStack.class, new ItemStackTypeAdapter());

View File

@ -2,9 +2,9 @@ package world.bentobox.bentobox.database.json.adapters;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
@ -13,12 +13,6 @@ import com.google.gson.stream.JsonWriter;
public class LocationAdapter extends TypeAdapter<Location> {
private Plugin plugin;
public LocationAdapter(Plugin plugin) {
this.plugin = plugin;
}
@Override
public void write(JsonWriter out, Location location) throws IOException {
if (location == null || location.getWorld() == null) {
@ -42,7 +36,7 @@ public class LocationAdapter extends TypeAdapter<Location> {
return null;
}
in.beginArray();
World world = plugin.getServer().getWorld(in.nextString());
World world = Bukkit.getServer().getWorld(in.nextString());
double x = in.nextDouble();
double y = in.nextDouble();
double z = in.nextDouble();

View File

@ -2,8 +2,8 @@ package world.bentobox.bentobox.database.json.adapters;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.plugin.Plugin;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
@ -12,12 +12,6 @@ import com.google.gson.stream.JsonWriter;
public class WorldAdapter extends TypeAdapter<World> {
private Plugin plugin;
public WorldAdapter(Plugin plugin) {
this.plugin = plugin;
}
@Override
public void write(JsonWriter out, World value) throws IOException {
if (value == null) {
@ -27,13 +21,13 @@ public class WorldAdapter extends TypeAdapter<World> {
out.value(value.getName());
}
@Override
public World read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
return plugin.getServer().getWorld(reader.nextString());
return Bukkit.getServer().getWorld(reader.nextString());
}
}

View File

@ -177,6 +177,7 @@ public class AddonsManager {
addon.setState(Addon.State.ERROR);
plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
plugin.logError("STACKTRACE: " + throwable.getClass().getSimpleName() + " - " + throwable.getMessage() + " - " + throwable.getCause());
throwable.printStackTrace();
if (plugin.getConfig().getBoolean("debug")) {
plugin.logDebug(throwable.toString());
plugin.logDebug(throwable.getStackTrace());

View File

@ -43,10 +43,11 @@ public class AddonTest {
@Mock
static BentoBox plugin;
static JavaPlugin javaPlugin;
private Server server;
@Before
public void setUp() throws Exception {
Server server = mock(Server.class);
server = mock(Server.class);
World world = mock(World.class);
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
when(server.getWorld("world")).thenReturn(world);
@ -134,7 +135,7 @@ public class AddonTest {
@Test
public void testGetServer() {
TestClass test = new TestClass();
assertEquals(plugin.getServer(), test.getServer());
assertEquals(server, test.getServer());
}
@Test

View File

@ -13,7 +13,9 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.Vector;
import org.junit.Before;
@ -118,6 +120,13 @@ public class AdminRegisterCommandTest {
idm = mock(IslandDeletionManager.class);
when(idm.inDeletion(Mockito.any())).thenReturn(false);
when(plugin.getIslandDeletionManager()).thenReturn(idm);
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}

View File

@ -12,7 +12,9 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.Vector;
import org.junit.Before;
@ -109,6 +111,13 @@ public class AdminUnregisterCommandTest {
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}

View File

@ -13,7 +13,9 @@ import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
@ -114,6 +116,13 @@ public class AdminTeamAddCommandTest {
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}

View File

@ -15,7 +15,9 @@ import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
@ -114,6 +116,13 @@ public class AdminTeamDisbandCommandTest {
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}

View File

@ -17,7 +17,9 @@ import java.util.Optional;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
@ -116,6 +118,13 @@ public class AdminTeamKickCommandTest {
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}

View File

@ -14,7 +14,9 @@ import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
@ -110,6 +112,13 @@ public class AdminTeamSetownerCommandTest {
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}

View File

@ -14,9 +14,11 @@ import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
@ -124,6 +126,13 @@ public class IslandTeamKickCommandTest {
// Addon
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}
/**

View File

@ -10,9 +10,11 @@ import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
@ -80,7 +82,7 @@ public class IslandTeamLeaveCommandTest {
ic = mock(CompositeCommand.class);
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
// Player has island to begin with
// Player has island to begin with
im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
when(im.isOwner(Mockito.any(), Mockito.any())).thenReturn(true);
@ -99,6 +101,12 @@ public class IslandTeamLeaveCommandTest {
// Island World Manager
iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Plugin Manager
Server server = mock(Server.class);
PluginManager pim = mock(PluginManager.class);
when(server.getPluginManager()).thenReturn(pim);
when(Bukkit.getServer()).thenReturn(server);
}
/**
@ -111,7 +119,7 @@ public class IslandTeamLeaveCommandTest {
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.no-team"));
}
/**
* Test method for .
*/
@ -121,7 +129,7 @@ public class IslandTeamLeaveCommandTest {
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage(Mockito.eq("commands.island.team.leave.cannot-leave"));
}
/**
* Test method for .
*/
@ -138,7 +146,7 @@ public class IslandTeamLeaveCommandTest {
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
}
/**
* Test method for .
*/
@ -168,7 +176,7 @@ public class IslandTeamLeaveCommandTest {
when(im.isOwner(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
// Add a team owner - null
when(im.getOwner(Mockito.any(), Mockito.any())).thenReturn(null);
// Require resets
when(iwm.isOnLeaveResetEnderChest(Mockito.any())).thenReturn(true);
Inventory enderChest = mock(Inventory.class);
@ -182,7 +190,7 @@ public class IslandTeamLeaveCommandTest {
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
Mockito.verify(im).setLeaveTeam(Mockito.any(), Mockito.eq(uuid));
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
Mockito.verify(enderChest).clear();
Mockito.verify(inv).clear();
}