mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-18 21:32:04 +01:00
Fixes #2240 Makes locations default to island center in IslandBaseEvent
This commit is contained in:
parent
54ebf2dfd2
commit
f256c3af8d
@ -24,78 +24,92 @@ public abstract class IslandBaseEvent extends BentoBoxEvent implements Cancellab
|
|||||||
protected IslandBaseEvent newEvent;
|
protected IslandBaseEvent newEvent;
|
||||||
|
|
||||||
public IslandBaseEvent(Island island) {
|
public IslandBaseEvent(Island island) {
|
||||||
super();
|
super();
|
||||||
this.island = island;
|
this.island = island;
|
||||||
playerUUID = island == null ? null : island.getOwner();
|
playerUUID = island == null ? null : island.getOwner();
|
||||||
admin = false;
|
admin = false;
|
||||||
location = island == null ? null : island.getCenter();
|
location = island == null ? null : island.getCenter();
|
||||||
rawEvent = null;
|
rawEvent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param island - island
|
* @param island - island
|
||||||
* @param playerUUID - the player's UUID
|
* @param playerUUID - the player's UUID
|
||||||
* @param admin - true if ths is due to an admin event
|
* @param admin - true if ths is due to an admin event
|
||||||
* @param location - the location
|
* @param location - the location
|
||||||
*/
|
*/
|
||||||
public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location) {
|
public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location) {
|
||||||
super();
|
super();
|
||||||
this.island = island;
|
this.island = island;
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = playerUUID;
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
this.location = location;
|
if (location != null) {
|
||||||
rawEvent = null;
|
this.location = location;
|
||||||
|
} else if (island != null) {
|
||||||
|
this.location = island.getCenter();
|
||||||
|
} else {
|
||||||
|
this.location = null;
|
||||||
|
}
|
||||||
|
rawEvent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param island - island
|
* @param island - island
|
||||||
* @param playerUUID - the player's UUID
|
* @param playerUUID - the player's UUID
|
||||||
* @param admin - true if ths is due to an admin event
|
* @param admin - true if ths is due to an admin event
|
||||||
* @param location - the location
|
* @param location - the location
|
||||||
* @param rawEvent - the raw event
|
* @param rawEvent - the raw event
|
||||||
*/
|
*/
|
||||||
public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location, Event rawEvent) {
|
public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location, Event rawEvent) {
|
||||||
super();
|
super();
|
||||||
this.island = island;
|
this.island = island;
|
||||||
this.playerUUID = playerUUID;
|
this.playerUUID = playerUUID;
|
||||||
this.admin = admin;
|
this.admin = admin;
|
||||||
this.location = location;
|
if (location != null) {
|
||||||
this.rawEvent = rawEvent;
|
this.location = location;
|
||||||
|
} else if (island != null) {
|
||||||
|
this.location = island.getCenter();
|
||||||
|
} else {
|
||||||
|
this.location = null;
|
||||||
|
}
|
||||||
|
this.rawEvent = rawEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the island involved in this event. This may be null in the case of deleted islands, so use location instead
|
* @return the island involved in this event. This may be null in the case of
|
||||||
|
* deleted islands, so use location instead
|
||||||
*/
|
*/
|
||||||
public Island getIsland(){
|
public Island getIsland() {
|
||||||
return island;
|
return island;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the owner of the island
|
* @return the owner of the island
|
||||||
*/
|
*/
|
||||||
public UUID getOwner() {
|
public UUID getOwner() {
|
||||||
return island.getOwner();
|
return island.getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the playerUUID
|
* @return the playerUUID
|
||||||
*/
|
*/
|
||||||
public UUID getPlayerUUID() {
|
public UUID getPlayerUUID() {
|
||||||
return playerUUID;
|
return playerUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the admin
|
* @return the admin
|
||||||
*/
|
*/
|
||||||
public boolean isAdmin() {
|
public boolean isAdmin() {
|
||||||
return admin;
|
return admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the location
|
* @return the location
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,32 +117,34 @@ public abstract class IslandBaseEvent extends BentoBoxEvent implements Cancellab
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Event getRawEvent() {
|
public Event getRawEvent() {
|
||||||
return rawEvent;
|
return rawEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
cancelled = cancel;
|
cancelled = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get new event if this event is deprecated
|
* Get new event if this event is deprecated
|
||||||
|
*
|
||||||
* @return optional newEvent or empty if there is none
|
* @return optional newEvent or empty if there is none
|
||||||
*/
|
*/
|
||||||
public Optional<IslandBaseEvent> getNewEvent() {
|
public Optional<IslandBaseEvent> getNewEvent() {
|
||||||
return Optional.ofNullable(newEvent);
|
return Optional.ofNullable(newEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the newer event so it can be obtained if this event is deprecated
|
* Set the newer event so it can be obtained if this event is deprecated
|
||||||
|
*
|
||||||
* @param newEvent the newEvent to set
|
* @param newEvent the newEvent to set
|
||||||
*/
|
*/
|
||||||
public void setNewEvent(IslandBaseEvent newEvent) {
|
public void setNewEvent(IslandBaseEvent newEvent) {
|
||||||
this.newEvent = newEvent;
|
this.newEvent = newEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,10 @@ import java.util.Optional;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -43,7 +45,7 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class})
|
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class })
|
||||||
public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
|
public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
@ -59,94 +61,100 @@ public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
|
|||||||
private AdminSetrankCommand c;
|
private AdminSetrankCommand c;
|
||||||
|
|
||||||
private UUID targetUUID;
|
private UUID targetUUID;
|
||||||
|
@Mock
|
||||||
|
private @NonNull Location location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
Util.setPlugin(plugin);
|
Util.setPlugin(plugin);
|
||||||
|
|
||||||
// Ranks Manager
|
// Ranks Manager
|
||||||
rm = new RanksManager();
|
rm = new RanksManager();
|
||||||
when(plugin.getRanksManager()).thenReturn(rm);
|
when(plugin.getRanksManager()).thenReturn(rm);
|
||||||
|
|
||||||
// Players Manager
|
// Players Manager
|
||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Islands manager
|
// Islands manager
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Target
|
// Target
|
||||||
targetUUID = UUID.randomUUID();
|
targetUUID = UUID.randomUUID();
|
||||||
Player p = mock(Player.class);
|
Player p = mock(Player.class);
|
||||||
when(p.getUniqueId()).thenReturn(targetUUID);
|
when(p.getUniqueId()).thenReturn(targetUUID);
|
||||||
User.getInstance(p);
|
User.getInstance(p);
|
||||||
|
|
||||||
// Online players
|
// Online players
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getOnlinePlayerList(any())).thenReturn(Collections.singletonList("tastybento"));
|
when(Util.getOnlinePlayerList(any())).thenReturn(Collections.singletonList("tastybento"));
|
||||||
when(Util.getUUID(anyString())).thenCallRealMethod();
|
when(Util.getUUID(anyString())).thenCallRealMethod();
|
||||||
|
|
||||||
// Translations
|
// Translations
|
||||||
when(user.getTranslation(anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
when(user.getTranslation(anyString()))
|
||||||
|
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
c = new AdminSetrankCommand(ac);
|
c = new AdminSetrankCommand(ac);
|
||||||
|
|
||||||
// Plugin Manager
|
// Plugin Manager
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
PluginManager pim = mock(PluginManager.class);
|
PluginManager pim = mock(PluginManager.class);
|
||||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#AdminSetrankCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#AdminSetrankCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAdminSetrankCommand() {
|
public void testAdminSetrankCommand() {
|
||||||
assertEquals("setrank", c.getLabel());
|
assertEquals("setrank", c.getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#setup()}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#setup()}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetup() {
|
public void testSetup() {
|
||||||
assertEquals("admin.setrank", c.getPermission());
|
assertEquals("admin.setrank", c.getPermission());
|
||||||
assertFalse(c.isOnlyPlayer());
|
assertFalse(c.isOnlyPlayer());
|
||||||
assertEquals("commands.admin.setrank.parameters", c.getParameters());
|
assertEquals("commands.admin.setrank.parameters", c.getParameters());
|
||||||
assertEquals("commands.admin.setrank.description", c.getDescription());
|
assertEquals("commands.admin.setrank.description", c.getDescription());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteNoArgs() {
|
public void testCanExecuteNoArgs() {
|
||||||
assertFalse(c.canExecute(user, "", Collections.emptyList()));
|
assertFalse(c.canExecute(user, "", Collections.emptyList()));
|
||||||
verify(user).getTranslation("commands.help.console");
|
verify(user).getTranslation("commands.help.console");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteOneArg() {
|
public void testCanExecuteOneArg() {
|
||||||
assertFalse(c.canExecute(user, "", Collections.singletonList("test")));
|
assertFalse(c.canExecute(user, "", Collections.singletonList("test")));
|
||||||
verify(user).getTranslation("commands.help.console");
|
verify(user).getTranslation("commands.help.console");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteUnknownPlayer() {
|
public void testCanExecuteUnknownPlayer() {
|
||||||
assertFalse(c.canExecute(user, "", Arrays.asList("tastybento", "member")));
|
assertFalse(c.canExecute(user, "", Arrays.asList("tastybento", "member")));
|
||||||
verify(user).sendMessage("general.errors.unknown-player",
|
verify(user).sendMessage("general.errors.unknown-player", "[name]", "tastybento");
|
||||||
"[name]",
|
|
||||||
"tastybento");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,38 +199,35 @@ public class AdminSetrankCommandTest extends RanksManagerBeforeClassTest {
|
|||||||
assertTrue(c.canExecute(user, "", Arrays.asList("tastybento", "ranks.member")));
|
assertTrue(c.canExecute(user, "", Arrays.asList("tastybento", "ranks.member")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecuteUserStringListOfString() {
|
public void testExecuteUserStringListOfString() {
|
||||||
// Set the target
|
// Set the target
|
||||||
testCanExecuteKnownPlayerHasIslandSuccess();
|
testCanExecuteKnownPlayerHasIslandSuccess();
|
||||||
Island island = mock(Island.class);
|
Island island = mock(Island.class);
|
||||||
when(island.getRank(any(User.class))).thenReturn(RanksManager.SUB_OWNER_RANK);
|
when(island.getRank(any(User.class))).thenReturn(RanksManager.SUB_OWNER_RANK);
|
||||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||||
assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member")));
|
when(island.getCenter()).thenReturn(location);
|
||||||
verify(user).sendMessage(eq("commands.admin.setrank.rank-set"),
|
assertTrue(c.execute(user, "", Arrays.asList("tastybento", "member")));
|
||||||
eq("[from]"),
|
verify(user).sendMessage(eq("commands.admin.setrank.rank-set"), eq("[from]"), eq("ranks.sub-owner"), eq("[to]"),
|
||||||
eq("ranks.sub-owner"),
|
eq("ranks.member"), eq("[name]"), eq(null));
|
||||||
eq("[to]"),
|
|
||||||
eq("ranks.member"),
|
|
||||||
eq("[name]"),
|
|
||||||
eq(null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
* Test method for
|
||||||
|
* {@link world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testTabCompleteUserStringListOfString() {
|
public void testTabCompleteUserStringListOfString() {
|
||||||
Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", ""));
|
Optional<List<String>> result = c.tabComplete(user, "", Arrays.asList("setrank", ""));
|
||||||
assertTrue(result.isPresent());
|
assertTrue(result.isPresent());
|
||||||
result.ifPresent(list -> {
|
result.ifPresent(list -> {
|
||||||
assertEquals(1, list.size());
|
assertEquals(1, list.size());
|
||||||
assertEquals("tastybento", list.get(0));
|
assertEquals("tastybento", list.get(0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user