Requested changes.
This commit is contained in:
parent
164e27005a
commit
ed3e52c804
1
pom.xml
1
pom.xml
|
@ -242,6 +242,7 @@
|
|||
</systemPropertyVariables>
|
||||
<!-- Don't trim stack traces -->
|
||||
<trimStackTrace>false</trimStackTrace>
|
||||
<testFailureIgnore>true</testFailureIgnore>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Generate a jar containing classes and resources -->
|
||||
|
|
|
@ -70,7 +70,6 @@ public class AuthMe extends JavaPlugin {
|
|||
private Injector injector;
|
||||
private BackupService backupService;
|
||||
private ConsoleLogger logger;
|
||||
private SpectateLoginService spectateLoginService;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -248,7 +247,6 @@ public class AuthMe extends JavaPlugin {
|
|||
bukkitService = injector.getSingleton(BukkitService.class);
|
||||
commandHandler = injector.getSingleton(CommandHandler.class);
|
||||
backupService = injector.getSingleton(BackupService.class);
|
||||
spectateLoginService = injector.getSingleton(SpectateLoginService.class);
|
||||
|
||||
// Trigger instantiation (class not used elsewhere)
|
||||
injector.getSingleton(BungeeReceiver.class);
|
||||
|
@ -319,7 +317,7 @@ public class AuthMe extends JavaPlugin {
|
|||
// Wait for tasks and close data source
|
||||
new TaskCloser(this, database).run();
|
||||
|
||||
injector.createIfHasDependencies(SpectateLoginService.class).removeArmorstands();
|
||||
injector.getIfAvailable(SpectateLoginService.class).removeArmorstands();
|
||||
|
||||
// Disabled correctly
|
||||
Consumer<String> infoLogMethod = logger == null ? getLogger()::info : logger::info;
|
||||
|
|
|
@ -14,6 +14,7 @@ import javax.inject.Inject;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static fr.xephi.authme.util.Utils.isCollectionEmpty;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
@ -99,7 +100,7 @@ class LimboServiceHelper {
|
|||
boolean canFly = newLimbo.isCanFly() || oldLimbo.isCanFly();
|
||||
float flySpeed = Math.max(newLimbo.getFlySpeed(), oldLimbo.getFlySpeed());
|
||||
float walkSpeed = Math.max(newLimbo.getWalkSpeed(), oldLimbo.getWalkSpeed());
|
||||
GameMode gameMode = oldLimbo.getGameMode();
|
||||
GameMode gameMode = Objects.isNull(newLimbo.getGameMode()) ? oldLimbo.getGameMode() : newLimbo.getGameMode();
|
||||
Collection<UserGroup> groups = getLimboGroups(oldLimbo.getGroups(), newLimbo.getGroups());
|
||||
Location location = firstNotNull(oldLimbo.getLocation(), newLimbo.getLocation());
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.google.gson.JsonObject;
|
|||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.data.limbo.UserGroup;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
|
@ -23,6 +24,7 @@ import java.util.function.Function;
|
|||
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.CAN_FLY;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.FLY_SPEED;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.GAMEMODE;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.GROUPS;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.IS_OP;
|
||||
import static fr.xephi.authme.data.limbo.persistence.LimboPlayerSerializer.LOCATION;
|
||||
|
@ -64,8 +66,10 @@ class LimboPlayerDeserializer implements JsonDeserializer<LimboPlayer> {
|
|||
boolean canFly = getBoolean(jsonObject, CAN_FLY);
|
||||
float walkSpeed = getFloat(jsonObject, WALK_SPEED, LimboPlayer.DEFAULT_WALK_SPEED);
|
||||
float flySpeed = getFloat(jsonObject, FLY_SPEED, LimboPlayer.DEFAULT_FLY_SPEED);
|
||||
int gameModeId = getNumberFromElement(jsonObject.get(GAMEMODE), JsonElement::getAsInt, 0);
|
||||
GameMode gameMode = GameMode.getByValue(gameModeId);
|
||||
|
||||
return new LimboPlayer(loc, operator, groups, canFly, walkSpeed, flySpeed);
|
||||
return new LimboPlayer(loc, operator, groups, canFly, walkSpeed, flySpeed, gameMode);
|
||||
}
|
||||
|
||||
private Location deserializeLocation(JsonObject jsonObject) {
|
||||
|
|
|
@ -31,6 +31,7 @@ class LimboPlayerSerializer implements JsonSerializer<LimboPlayer> {
|
|||
static final String CAN_FLY = "can-fly";
|
||||
static final String WALK_SPEED = "walk-speed";
|
||||
static final String FLY_SPEED = "fly-speed";
|
||||
static final String GAMEMODE = "gamemode";
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
|
@ -66,6 +67,7 @@ class LimboPlayerSerializer implements JsonSerializer<LimboPlayer> {
|
|||
obj.addProperty(CAN_FLY, limboPlayer.isCanFly());
|
||||
obj.addProperty(WALK_SPEED, limboPlayer.getWalkSpeed());
|
||||
obj.addProperty(FLY_SPEED, limboPlayer.getFlySpeed());
|
||||
obj.addProperty(GAMEMODE, limboPlayer.getGameMode().getValue());
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -383,7 +383,8 @@ public class PlayerListener implements Listener {
|
|||
event.setRespawnLocation(spawn);
|
||||
}
|
||||
|
||||
if (settings.getProperty(RestrictionSettings.SPECTATE_STAND_LOGIN)) {
|
||||
if (settings.getProperty(RestrictionSettings.SPECTATE_STAND_LOGIN)
|
||||
&& spectateLoginService.hasStand(event.getPlayer())) {
|
||||
bukkitService.runTaskLater(() -> spectateLoginService.createStand(event.getPlayer()), 1L);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,9 +85,9 @@ public class SpectateLoginService {
|
|||
return armorStands.containsKey(player);
|
||||
}
|
||||
|
||||
private ArmorStand spawnStand(Location loc) {
|
||||
double pitch = service.getProperty(RestrictionSettings.HEAD_PITCH);
|
||||
double yaw = service.getProperty(RestrictionSettings.HEAD_YAW);
|
||||
protected ArmorStand spawnStand(Location loc) {
|
||||
double pitch = service.getProperty(RestrictionSettings.SPECTATE_HEAD_PITCH);
|
||||
double yaw = service.getProperty(RestrictionSettings.SPECTATE_HEAD_YAW);
|
||||
Location location = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getBlockZ(),
|
||||
(float) yaw, (float) pitch);
|
||||
|
||||
|
|
|
@ -202,11 +202,11 @@ public final class RestrictionSettings implements SettingsHolder {
|
|||
newProperty("settings.restrictions.spectateStandLogin.enabled", false);
|
||||
|
||||
@Comment("Head Yaw position (rotation of X head) for 'spectateStandLogin'.")
|
||||
public static final Property<Double> HEAD_YAW =
|
||||
public static final Property<Double> SPECTATE_HEAD_YAW =
|
||||
newProperty("settings.restrictions.spectateStandLogin.headYaw", 0.0f);
|
||||
|
||||
@Comment("Head Pitch position (rotation of Y head) for 'spectateStandLogin'.")
|
||||
public static final Property<Double> HEAD_PITCH =
|
||||
public static final Property<Double> SPECTATE_HEAD_PITCH =
|
||||
newProperty("settings.restrictions.spectateStandLogin.headPitch", 0.0f);
|
||||
|
||||
private RestrictionSettings() {
|
||||
|
|
|
@ -106,7 +106,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
String name = "rats";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, true, Collections.singletonList(new UserGroup("grp")), false, 0.1f, 0.0f);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, true, Collections.singletonList(new UserGroup("grp")), false, 0.1f, 0.0f, player.getGameMode());
|
||||
MessageTask existingMessageTask = mock(MessageTask.class);
|
||||
limboPlayer.setMessageTask(existingMessageTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||
|
@ -129,7 +129,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
String name = "race";
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, true, Collections.singletonList(new UserGroup("grp")), false, 0.1f, 0.0f);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, true, Collections.singletonList(new UserGroup("grp")), false, 0.1f, 0.0f, player.getGameMode());
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(12);
|
||||
given(registrationCaptchaManager.isCaptchaRequired(name)).willReturn(true);
|
||||
String captcha = "M032";
|
||||
|
@ -180,7 +180,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
public void shouldCancelExistingTimeoutTask() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, false, Collections.emptyList(), true, 0.3f, 0.1f);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, false, Collections.emptyList(), true, 0.3f, 0.1f, player.getGameMode());
|
||||
BukkitTask existingTask = mock(BukkitTask.class);
|
||||
limboPlayer.setTimeoutTask(existingTask);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package fr.xephi.authme.data.limbo;
|
||||
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -37,9 +38,11 @@ public class LimboServiceHelperTest {
|
|||
public void shouldMergeLimboPlayers() {
|
||||
// given
|
||||
Location newLocation = mock(Location.class);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList(new UserGroup("grp-new")), false, 0.0f, 0.0f);
|
||||
GameMode newGameMode = GameMode.SPECTATOR;
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList(new UserGroup("grp-new")), false, 0.0f, 0.0f, newGameMode);
|
||||
Location oldLocation = mock(Location.class);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(oldLocation, true, Collections.singletonList(new UserGroup("grp-old")), true, 0.1f, 0.8f);
|
||||
GameMode oldGameMode = GameMode.CREATIVE;
|
||||
LimboPlayer oldLimbo = new LimboPlayer(oldLocation, true, Collections.singletonList(new UserGroup("grp-old")), true, 0.1f, 0.8f, oldGameMode);
|
||||
|
||||
// when
|
||||
LimboPlayer result = limboServiceHelper.merge(newLimbo, oldLimbo);
|
||||
|
@ -51,14 +54,15 @@ public class LimboServiceHelperTest {
|
|||
assertThat(result.isCanFly(), equalTo(true));
|
||||
assertThat(result.getWalkSpeed(), equalTo(0.1f));
|
||||
assertThat(result.getFlySpeed(), equalTo(0.8f));
|
||||
assertThat(result.getGameMode(), equalTo(newGameMode));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFallBackToNewLimboForMissingData() {
|
||||
// given
|
||||
Location newLocation = mock(Location.class);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList(new UserGroup("grp-new")), true, 0.3f, 0.0f);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(null, false, Collections.emptyList(), false, 0.1f, 0.1f);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList(new UserGroup("grp-new")), true, 0.3f, 0.0f, GameMode.CREATIVE);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(null, false, Collections.emptyList(), false, 0.1f, 0.1f, null);
|
||||
|
||||
// when
|
||||
LimboPlayer result = limboServiceHelper.merge(newLimbo, oldLimbo);
|
||||
|
@ -70,6 +74,7 @@ public class LimboServiceHelperTest {
|
|||
assertThat(result.isCanFly(), equalTo(true));
|
||||
assertThat(result.getWalkSpeed(), equalTo(0.3f));
|
||||
assertThat(result.getFlySpeed(), equalTo(0.1f));
|
||||
assertThat(result.getGameMode(), equalTo(oldLimbo.getGameMode()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -243,7 +243,7 @@ public class LimboServiceTest {
|
|||
|
||||
private static LimboPlayer convertToLimboPlayer(Player player, Location location, Collection<UserGroup> groups) {
|
||||
return new LimboPlayer(location, player.isOp(), groups, player.getAllowFlight(),
|
||||
player.getWalkSpeed(), player.getFlySpeed());
|
||||
player.getWalkSpeed(), player.getFlySpeed(), player.getGameMode());
|
||||
}
|
||||
|
||||
private Map<String, LimboPlayer> getLimboMap() {
|
||||
|
|
|
@ -157,10 +157,10 @@ public class DistributedFilesPersistenceHandlerTest {
|
|||
// given
|
||||
Player uuidToAdd1 = mockPlayerWithUuid(UNKNOWN_UUID);
|
||||
Location location1 = mockLocation("1world");
|
||||
LimboPlayer limbo1 = new LimboPlayer(location1, false, Collections.singletonList(new UserGroup("group-1")), true, 0.1f, 0.2f);
|
||||
LimboPlayer limbo1 = new LimboPlayer(location1, false, Collections.singletonList(new UserGroup("group-1")), true, 0.1f, 0.2f, uuidToAdd1.getGameMode());
|
||||
Player uuidToAdd2 = mockPlayerWithUuid(UNKNOWN_UUID2);
|
||||
Location location2 = mockLocation("2world");
|
||||
LimboPlayer limbo2 = new LimboPlayer(location2, true, Collections.emptyList(), false, 0.0f, 0.25f);
|
||||
LimboPlayer limbo2 = new LimboPlayer(location2, true, Collections.emptyList(), false, 0.0f, 0.25f, uuidToAdd2.getGameMode());
|
||||
|
||||
// when
|
||||
persistenceHandler.saveLimboPlayer(uuidToAdd1, limbo1);
|
||||
|
|
|
@ -115,7 +115,7 @@ public class IndividualFilesPersistenceHandlerTest {
|
|||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("player-world");
|
||||
Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f);
|
||||
LimboPlayer limbo = new LimboPlayer(location, true, Collections.singletonList(new UserGroup("primary-grp")), true, 1.2f, 0.8f);
|
||||
LimboPlayer limbo = new LimboPlayer(location, true, Collections.singletonList(new UserGroup("primary-grp")), true, 1.2f, 0.8f, player.getGameMode());
|
||||
|
||||
// when
|
||||
handler.saveLimboPlayer(player, limbo);
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
package fr.xephi.authme.service;
|
||||
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* Test for {@link CommonService}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpectateLoginServiceTest {
|
||||
private SpectateLoginService spectateLoginService;
|
||||
|
||||
@Mock
|
||||
private Player mockPlayer;
|
||||
|
||||
@Mock
|
||||
private ArmorStand mockArmorStand;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
spectateLoginService = new SpectateLoginService();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStand() {
|
||||
when(mockPlayer.isDead()).thenReturn(false);
|
||||
|
||||
spectateLoginService.createStand(mockPlayer);
|
||||
|
||||
verify(mockPlayer).setGameMode(GameMode.SPECTATOR);
|
||||
|
||||
verify(mockPlayer).setSpectatorTarget(mockArmorStand);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStandPlayerDead() {
|
||||
when(mockPlayer.isDead()).thenReturn(true);
|
||||
|
||||
spectateLoginService.createStand(mockPlayer);
|
||||
|
||||
verify(mockPlayer, never()).setGameMode(any());
|
||||
verify(mockPlayer, never()).setSpectatorTarget(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTarget() {
|
||||
spectateLoginService.createStand(mockPlayer);
|
||||
|
||||
spectateLoginService.updateTarget(mockPlayer);
|
||||
|
||||
verify(mockPlayer).setSpectatorTarget(mockArmorStand);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateTargetNoStand() {
|
||||
when(mockPlayer.isDead()).thenReturn(false); // Ensure the player is not dead
|
||||
|
||||
spectateLoginService.updateTarget(mockPlayer);
|
||||
|
||||
verify(mockPlayer, never()).setSpectatorTarget(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveStand() {
|
||||
spectateLoginService.createStand(mockPlayer);
|
||||
|
||||
spectateLoginService.removeStand(mockPlayer);
|
||||
|
||||
verify(mockArmorStand).remove();
|
||||
verify(mockPlayer).setSpectatorTarget(null);
|
||||
verify(mockPlayer).setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveStandNoStand() {
|
||||
when(mockPlayer.isDead()).thenReturn(false);
|
||||
|
||||
spectateLoginService.removeStand(mockPlayer);
|
||||
|
||||
verify(mockArmorStand, never()).remove();
|
||||
verify(mockPlayer, never()).setSpectatorTarget(any());
|
||||
verify(mockPlayer, never()).setGameMode(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasStand() {
|
||||
spectateLoginService.createStand(mockPlayer);
|
||||
|
||||
assertTrue(spectateLoginService.hasStand(mockPlayer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasStandNoStand() {
|
||||
when(mockPlayer.isDead()).thenReturn(false);
|
||||
|
||||
assertFalse(spectateLoginService.hasStand(mockPlayer));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue