Fix tests.
This commit is contained in:
parent
af3c0a874c
commit
500f7292c6
|
@ -10,9 +10,7 @@ import java.util.Map;
|
|||
import java.util.Objects;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
|
||||
/**
|
||||
|
@ -23,14 +21,6 @@ import world.bentobox.bentobox.BentoBox;
|
|||
*/
|
||||
public abstract class BentoBoxEvent extends Event {
|
||||
|
||||
/**
|
||||
* Event handler list
|
||||
* @deprecated This field will be removed from BentoBoxEvent.
|
||||
* Events must provide their own handlers.
|
||||
*/
|
||||
@Deprecated
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* The default constructor is defined for cleaner code.
|
||||
* This constructor assumes the BentoBoxEvent is synchronous.
|
||||
|
@ -48,29 +38,6 @@ public abstract class BentoBoxEvent extends Event {
|
|||
super(async);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HandlerList
|
||||
* @deprecated this method will no longer be in future versions of the BentoBoxEvent.
|
||||
* Each event must declare its own static handler and handler methods.
|
||||
* Will be removed by https://github.com/BentoBoxWorld/BentoBox/pull/1615
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public @NonNull HandlerList getHandlers() {
|
||||
return getHandlerList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HandlerList
|
||||
* @deprecated this method will no longer be in future versions of the BentoBoxEvent.
|
||||
* Each event must declare its own static handler and handler methods.
|
||||
* Will be removed by https://github.com/BentoBoxWorld/BentoBox/pull/1615
|
||||
*/
|
||||
@Deprecated
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a map of key value pairs derived from the fields of this class by reflection.
|
||||
* @return map
|
||||
|
|
|
@ -25,54 +25,6 @@ public class AddonEvent {
|
|||
return new AddonEventBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.addon.AddonEnableEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AddonEnableEvent extends AddonBaseEvent {
|
||||
private AddonEnableEvent(Addon addon, Map<String, Object> keyValues) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(addon, keyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.addon.AddonDisableEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AddonDisableEvent extends AddonBaseEvent {
|
||||
private AddonDisableEvent(Addon addon, Map<String, Object> keyValues) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(addon, keyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.addon.AddonLoadEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AddonLoadEvent extends AddonBaseEvent {
|
||||
private AddonLoadEvent(Addon addon, Map<String, Object> keyValues) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(addon, keyValues);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.addon.AddonGeneralEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class AddonGeneralEvent extends AddonBaseEvent {
|
||||
private AddonGeneralEvent(Addon addon, Map<String, Object> keyValues) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(addon, keyValues);
|
||||
}
|
||||
}
|
||||
|
||||
public class AddonEventBuilder {
|
||||
// Here field are NOT final. They are just used for the building.
|
||||
private Addon addon;
|
||||
|
@ -99,21 +51,12 @@ public class AddonEvent {
|
|||
return this;
|
||||
}
|
||||
|
||||
private AddonBaseEvent getDeprecatedEvent() {
|
||||
return switch (reason) {
|
||||
case ENABLE -> new AddonEnableEvent(addon, keyValues);
|
||||
case DISABLE -> new AddonDisableEvent(addon, keyValues);
|
||||
case LOAD -> new AddonLoadEvent(addon, keyValues);
|
||||
default -> new AddonGeneralEvent(addon, keyValues);
|
||||
};
|
||||
}
|
||||
|
||||
private AddonBaseEvent getEvent() {
|
||||
return switch (reason) {
|
||||
case ENABLE -> new world.bentobox.bentobox.api.events.addon.AddonEnableEvent(addon, keyValues);
|
||||
case DISABLE -> new world.bentobox.bentobox.api.events.addon.AddonDisableEvent(addon, keyValues);
|
||||
case LOAD -> new world.bentobox.bentobox.api.events.addon.AddonLoadEvent(addon, keyValues);
|
||||
default -> new world.bentobox.bentobox.api.events.addon.AddonGeneralEvent(addon, keyValues);
|
||||
case ENABLE -> new AddonEnableEvent(addon, keyValues);
|
||||
case DISABLE -> new AddonDisableEvent(addon, keyValues);
|
||||
case LOAD -> new AddonLoadEvent(addon, keyValues);
|
||||
default -> new AddonGeneralEvent(addon, keyValues);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -125,12 +68,7 @@ public class AddonEvent {
|
|||
// Call new event
|
||||
AddonBaseEvent newEvent = getEvent();
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
// Get the old event
|
||||
AddonBaseEvent e = getDeprecatedEvent();
|
||||
e.setNewEvent(newEvent);
|
||||
// Call deprecated event
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
return e;
|
||||
return newEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,161 +36,6 @@ public class TeamEvent {
|
|||
return new TeamEventBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamJoinEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamJoinEvent extends IslandBaseEvent {
|
||||
private TeamJoinEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after a player has joined an island
|
||||
* @since 1.3.0
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamJoinedEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
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);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamInviteEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
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
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamLeaveEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamLeaveEvent extends IslandBaseEvent {
|
||||
private TeamLeaveEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamRejectEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamRejectEvent extends IslandBaseEvent {
|
||||
private TeamRejectEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamKickEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamKickEvent extends IslandBaseEvent {
|
||||
private TeamKickEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Event fires before a setowner is performed on an island.
|
||||
* To get the old owner, get from the island object. The new owner is the player's UUID.
|
||||
* @author tastybento
|
||||
*
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamSetownerEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamSetownerEvent extends IslandBaseEvent {
|
||||
private TeamSetownerEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
/**
|
||||
* Convenience method to get the old owner of the island
|
||||
* @return UUID of old owner
|
||||
*/
|
||||
public UUID getOldOwner() {
|
||||
return island.getOwner();
|
||||
}
|
||||
/**
|
||||
* Convenience method to get the new owner of the island
|
||||
* @return UUID of new owner
|
||||
*/
|
||||
public UUID getNewOwner() {
|
||||
return playerUUID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamInfoEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamInfoEvent extends IslandBaseEvent {
|
||||
private TeamInfoEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamDeleteEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamDeleteEvent extends IslandBaseEvent {
|
||||
private TeamDeleteEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamUninviteEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamUninviteEvent extends IslandBaseEvent {
|
||||
private TeamUninviteEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constructor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This event is moving to its own class.
|
||||
* Use {@link world.bentobox.bentobox.api.events.team.TeamGeneralEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public static class TeamGeneralEvent extends IslandBaseEvent {
|
||||
private TeamGeneralEvent(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 TeamEventBuilder {
|
||||
private Island island;
|
||||
private UUID player;
|
||||
|
@ -236,35 +81,20 @@ public class TeamEvent {
|
|||
return this;
|
||||
}
|
||||
|
||||
private IslandBaseEvent getDeprecatedEvent() {
|
||||
return switch (reason) {
|
||||
case JOIN -> new TeamJoinEvent(island, player, admin, location);
|
||||
case JOINED -> new TeamJoinedEvent(island, player, admin, location);
|
||||
case INVITE -> new TeamInviteEvent(island, player, admin, location);
|
||||
case LEAVE -> new TeamLeaveEvent(island, player, admin, location);
|
||||
case REJECT -> new TeamRejectEvent(island, player, admin, location);
|
||||
case KICK -> new TeamKickEvent(island, player, admin, location);
|
||||
case SETOWNER -> new TeamSetownerEvent(island, player, admin, location);
|
||||
case INFO -> new TeamInfoEvent(island, player, admin, location);
|
||||
case DELETE -> new TeamDeleteEvent(island, player, admin, location);
|
||||
case UNINVITE -> new TeamUninviteEvent(island, player, admin, location);
|
||||
default -> new TeamGeneralEvent(island, player, admin, location);
|
||||
};
|
||||
}
|
||||
|
||||
private IslandBaseEvent getEvent() {
|
||||
return switch (reason) {
|
||||
case JOIN -> new world.bentobox.bentobox.api.events.team.TeamJoinEvent(island, player, admin, location);
|
||||
case JOINED -> new world.bentobox.bentobox.api.events.team.TeamJoinedEvent(island, player, admin, location);
|
||||
case INVITE -> new world.bentobox.bentobox.api.events.team.TeamInviteEvent(island, player, admin, location);
|
||||
case LEAVE -> new world.bentobox.bentobox.api.events.team.TeamLeaveEvent(island, player, admin, location);
|
||||
case REJECT -> new world.bentobox.bentobox.api.events.team.TeamRejectEvent(island, player, admin, location);
|
||||
case KICK -> new world.bentobox.bentobox.api.events.team.TeamKickEvent(island, player, admin, location);
|
||||
case SETOWNER -> new world.bentobox.bentobox.api.events.team.TeamSetownerEvent(island, player, admin, location);
|
||||
case INFO -> new world.bentobox.bentobox.api.events.team.TeamInfoEvent(island, player, admin, location);
|
||||
case DELETE -> new world.bentobox.bentobox.api.events.team.TeamDeleteEvent(island, player, admin, location);
|
||||
case UNINVITE -> new world.bentobox.bentobox.api.events.team.TeamUninviteEvent(island, player, admin, location);
|
||||
default -> new world.bentobox.bentobox.api.events.team.TeamGeneralEvent(island, player, admin, location);
|
||||
case JOIN -> new TeamJoinEvent(island, player, admin, location);
|
||||
case JOINED -> new TeamJoinedEvent(island, player, admin, location);
|
||||
case INVITE -> new TeamInviteEvent(island, player, admin, location);
|
||||
case LEAVE -> new TeamLeaveEvent(island, player, admin, location);
|
||||
case REJECT -> new TeamRejectEvent(island, player, admin, location);
|
||||
case KICK -> new TeamKickEvent(island, player, admin, location);
|
||||
case SETOWNER -> new TeamSetownerEvent(island, player, admin, location);
|
||||
case INFO -> new TeamInfoEvent(island, player, admin, location);
|
||||
case DELETE -> new TeamDeleteEvent(island, player, admin, location);
|
||||
case UNINVITE -> new TeamUninviteEvent(island, player, admin, location);
|
||||
default -> new TeamGeneralEvent(island, player, admin, location);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -276,11 +106,7 @@ public class TeamEvent {
|
|||
// Generate new event
|
||||
IslandBaseEvent newEvent = getEvent();
|
||||
Bukkit.getPluginManager().callEvent(newEvent);
|
||||
// Generate deprecated events
|
||||
IslandBaseEvent e = getDeprecatedEvent();
|
||||
e.setNewEvent(newEvent);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
return e;
|
||||
return newEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ public class AdminTeamDisbandCommandTest {
|
|||
verify(user).sendMessage("commands.admin.team.disband.success", TextVariables.NAME, name[0]);
|
||||
verify(p).sendMessage("commands.admin.team.disband.disbanded");
|
||||
verify(p2).sendMessage("commands.admin.team.disband.disbanded");
|
||||
// 2 * 2
|
||||
verify(pim, times(4)).callEvent(any());
|
||||
// 2 + 1
|
||||
verify(pim, times(3)).callEvent(any());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ public class IslandResetCommandTest {
|
|||
// TODO Verify that panel was shown
|
||||
// verify(bpm).showPanel(any(), eq(user), eq(irc.getLabel()));
|
||||
// Verify event (13 * 2)
|
||||
verify(pim, times(26)).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim, times(14)).callEvent(any(IslandBaseEvent.class));
|
||||
// Verify messaging
|
||||
verify(user).sendMessage("commands.island.create.creating-island");
|
||||
verify(user, never()).sendMessage(eq("commands.island.reset.kicked-from-island"), eq(TextVariables.GAMEMODE), anyString());
|
||||
|
@ -447,7 +447,7 @@ public class IslandResetCommandTest {
|
|||
assertTrue(irc.execute(user, irc.getLabel(), Collections.singletonList("custom")));
|
||||
verify(user).sendMessage("commands.island.create.creating-island");
|
||||
// Verify event (13 * 2)
|
||||
verify(pim, times(26)).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim, times(14)).callEvent(any(IslandBaseEvent.class));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -223,7 +222,7 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
|
||||
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
||||
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
|
||||
verify(pim, times(2)).callEvent(any());
|
||||
verify(pim).callEvent(any());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -250,7 +249,7 @@ public class IslandTeamInviteAcceptCommandTest {
|
|||
assertTrue(c.canExecute(user, "accept", Collections.emptyList()));
|
||||
verify(user, never()).sendMessage("commands.island.team.invite.errors.you-already-are-in-team");
|
||||
verify(user, never()).sendMessage("commands.island.team.invite.errors.invalid-invite");
|
||||
verify(pim, times(2)).callEvent(any());
|
||||
verify(pim).callEvent(any());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,6 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -296,7 +295,7 @@ public class IslandTeamInviteCommandTest {
|
|||
when(im.hasIsland(any(), eq(notUUID))).thenReturn(true);
|
||||
testCanExecuteSuccess();
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target")));
|
||||
verify(pim, times(2)).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim).callEvent(any(IslandBaseEvent.class));
|
||||
verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite"));
|
||||
verify(ic).addInvite(eq(Invite.Type.TEAM), eq(uuid), eq(notUUID));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.invitation-sent"), eq(TextVariables.NAME), eq("target"));
|
||||
|
@ -313,7 +312,7 @@ public class IslandTeamInviteCommandTest {
|
|||
public void testExecuteSuccessTargetHasNoIsland() {
|
||||
testCanExecuteSuccess();
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target")));
|
||||
verify(pim, times(2)).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim).callEvent(any(IslandBaseEvent.class));
|
||||
verify(user, never()).sendMessage(eq("commands.island.team.invite.removing-invite"));
|
||||
verify(ic).addInvite(eq(Invite.Type.TEAM), eq(uuid), eq(notUUID));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.invitation-sent"), eq(TextVariables.NAME), eq("target"));
|
||||
|
@ -337,7 +336,7 @@ public class IslandTeamInviteCommandTest {
|
|||
when(invite.getType()).thenReturn(Type.TEAM);
|
||||
when(ic.getInvite(eq(notUUID))).thenReturn(invite);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("target")));
|
||||
verify(pim, times(2)).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim).callEvent(any(IslandBaseEvent.class));
|
||||
verify(ic).removeInvite(eq(notUUID));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.removing-invite"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue