1.10 API + cleanup

This commit is contained in:
Gabriele C 2016-06-11 17:46:24 +02:00
parent 2e269b6f5e
commit 01f297919d
9 changed files with 52 additions and 34 deletions

View File

@ -66,7 +66,7 @@
<bukkitplugin.authors>Xephi, sgdc3, DNx5, timvisee, games647, ljacqu</bukkitplugin.authors> <bukkitplugin.authors>Xephi, sgdc3, DNx5, timvisee, games647, ljacqu</bukkitplugin.authors>
<!-- Change Bukkit Version HERE! --> <!-- Change Bukkit Version HERE! -->
<bukkit.version>1.9.4-R0.1-SNAPSHOT</bukkit.version> <bukkit.version>1.10-R0.1-SNAPSHOT</bukkit.version>
</properties> </properties>
<!-- Jenkins profile (add the real buildNumber to the version string) --> <!-- Jenkins profile (add the real buildNumber to the version string) -->

View File

@ -313,9 +313,14 @@ public class PermissionsManager {
* False is also returned if this feature isn't supported for the current permissions system. * False is also returned if this feature isn't supported for the current permissions system.
*/ */
public boolean addGroup(Player player, String groupName) { public boolean addGroup(Player player, String groupName) {
// If no permissions system is used, return false if(groupName.isEmpty()) {
if (!isEnabled())
return false; return false;
}
// If no permissions system is used, return false
if (!isEnabled()) {
return false;
}
return handler.addToGroup(player, groupName); return handler.addToGroup(player, groupName);
} }

View File

@ -83,7 +83,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
// Prevent player collisions in 1.9 // Prevent player collisions in 1.9
if (DISABLE_COLLISIONS) { if (DISABLE_COLLISIONS) {
((LivingEntity) player).setCollidable(false); player.setCollidable(false);
} }
if (service.getProperty(RestrictionSettings.FORCE_SURVIVAL_MODE) if (service.getProperty(RestrictionSettings.FORCE_SURVIVAL_MODE)
@ -133,6 +133,12 @@ public class AsynchronousJoin implements AsynchronousProcess {
// TODO: continue cleanup from this -sgdc3 // TODO: continue cleanup from this -sgdc3
if (isAuthAvailable) { if (isAuthAvailable) {
// Registered
// Groups logic
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
// Spawn logic
if (!service.getProperty(RestrictionSettings.NO_TELEPORT)) { if (!service.getProperty(RestrictionSettings.NO_TELEPORT)) {
if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
bukkitService.scheduleSyncDelayedTask(new Runnable() { bukkitService.scheduleSyncDelayedTask(new Runnable() {
@ -149,9 +155,11 @@ public class AsynchronousJoin implements AsynchronousProcess {
} }
} }
placePlayerSafely(player, spawnLoc); placePlayerSafely(player, spawnLoc);
// Limbo cache
limboCache.updateLimboPlayer(player); limboCache.updateLimboPlayer(player);
// protect inventory // Protect inventory
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN) && plugin.inventoryProtector != null) { if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN) && plugin.inventoryProtector != null) {
ProtectInventoryEvent ev = new ProtectInventoryEvent(player); ProtectInventoryEvent ev = new ProtectInventoryEvent(player);
plugin.getServer().getPluginManager().callEvent(ev); plugin.getServer().getPluginManager().callEvent(ev);
@ -163,6 +171,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
} }
} }
// Session logic
if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (playerCache.isAuthenticated(name) || database.isLogged(name))) { if (service.getProperty(PluginSettings.SESSIONS_ENABLED) && (playerCache.isAuthenticated(name) || database.isLogged(name))) {
if (plugin.sessions.containsKey(name)) { if (plugin.sessions.containsKey(name)) {
plugin.sessions.get(name).cancel(); plugin.sessions.get(name).cancel();
@ -180,13 +189,17 @@ public class AsynchronousJoin implements AsynchronousProcess {
} }
} }
} else { } else {
if (!Settings.unRegisteredGroup.isEmpty()) { // Not Registered
Utils.setGroup(player, Utils.GroupType.UNREGISTERED);
} // Groups logic
Utils.setGroup(player, GroupType.UNREGISTERED);
// Skip if registration is optional
if (!service.getProperty(RegistrationSettings.FORCE)) { if (!service.getProperty(RegistrationSettings.FORCE)) {
return; return;
} }
// Spawn logic
if (!Settings.noTeleport && !needFirstSpawn(player) && Settings.isTeleportToSpawnEnabled if (!Settings.noTeleport && !needFirstSpawn(player) && Settings.isTeleportToSpawnEnabled
|| (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
bukkitService.scheduleSyncDelayedTask(new Runnable() { bukkitService.scheduleSyncDelayedTask(new Runnable() {
@ -202,37 +215,33 @@ public class AsynchronousJoin implements AsynchronousProcess {
}); });
} }
} }
// The user is not logged in
if (!limboCache.hasLimboPlayer(name)) { if (!limboCache.hasLimboPlayer(name)) {
limboCache.addLimboPlayer(player); limboCache.addLimboPlayer(player);
} }
Utils.setGroup(player, isAuthAvailable ? GroupType.NOTLOGGEDIN : GroupType.UNREGISTERED);
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * 20; final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
bukkitService.scheduleSyncDelayedTask(new Runnable() { // Apply effects
@Override // TODO: clenup!
public void run() { player.setOp(false);
player.setOp(false); if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) && service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
&& service.getProperty(RestrictionSettings.REMOVE_SPEED)) { player.setFlySpeed(0.0f);
player.setFlySpeed(0.0f); player.setWalkSpeed(0.0f);
player.setWalkSpeed(0.0f); }
} player.setNoDamageTicks(registrationTimeout);
player.setNoDamageTicks(registrationTimeout); if (pluginHooks.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
if (pluginHooks.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { player.performCommand("motd");
player.performCommand("motd"); }
} if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { // Allow infinite blindness effect
// Allow infinite blindness effect int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout;
int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout; player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2)); }
}
}
}); // Timeout task
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
if (registrationTimeout > 0) { if (registrationTimeout > 0) {
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout); BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), registrationTimeout);
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name); LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
@ -241,6 +250,8 @@ public class AsynchronousJoin implements AsynchronousProcess {
} }
} }
// Message task
int msgInterval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
MessageKey msg; MessageKey msg;
if (isAuthAvailable) { if (isAuthAvailable) {
msg = MessageKey.LOGIN_MESSAGE; msg = MessageKey.LOGIN_MESSAGE;

View File

@ -50,7 +50,6 @@ public class CommandConsistencyTest {
* *
* @return collection of all base command labels * @return collection of all base command labels
*/ */
@SuppressWarnings("unchecked")
private static Collection<List<String>> initializeCommands() { private static Collection<List<String>> initializeCommands() {
CommandInitializer initializer = new CommandInitializer(); CommandInitializer initializer = new CommandInitializer();
Collection<List<String>> commandLabels = new ArrayList<>(); Collection<List<String>> commandLabels = new ArrayList<>();

View File

@ -81,13 +81,13 @@ public class CommandHandlerTest {
* <p> * <p>
* The {@link CommandMapper} is mocked in {@link #initializeCommandMapper()} to return certain test classes. * The {@link CommandMapper} is mocked in {@link #initializeCommandMapper()} to return certain test classes.
*/ */
@SuppressWarnings("unchecked")
private void setInjectorToMockExecutableCommandClasses() { private void setInjectorToMockExecutableCommandClasses() {
given(initializer.newInstance(any(Class.class))).willAnswer(new Answer<Object>() { given(initializer.newInstance(any(Class.class))).willAnswer(new Answer<Object>() {
@Override @Override
public Object answer(InvocationOnMock invocation) throws Throwable { public Object answer(InvocationOnMock invocation) throws Throwable {
Class<?> clazz = (Class<?>) invocation.getArguments()[0]; Class<?> clazz = (Class<?>) invocation.getArguments()[0];
if (ExecutableCommand.class.isAssignableFrom(clazz)) { if (ExecutableCommand.class.isAssignableFrom(clazz)) {
@SuppressWarnings("unchecked")
Class<? extends ExecutableCommand> commandClass = (Class<? extends ExecutableCommand>) clazz; Class<? extends ExecutableCommand> commandClass = (Class<? extends ExecutableCommand>) clazz;
ExecutableCommand mock = mock(commandClass); ExecutableCommand mock = mock(commandClass);
mockedCommands.put(commandClass, mock); mockedCommands.put(commandClass, mock);

View File

@ -33,7 +33,6 @@ public class CommandInitializerTest {
private static Set<CommandDescription> commands; private static Set<CommandDescription> commands;
@SuppressWarnings("unchecked")
@BeforeClass @BeforeClass
public static void initializeCommandCollection() { public static void initializeCommandCollection() {
CommandInitializer commandInitializer = new CommandInitializer(); CommandInitializer commandInitializer = new CommandInitializer();

View File

@ -280,6 +280,7 @@ public class CommandMapperTest {
assertThat(result.getArguments(), contains(parts.get(2))); assertThat(result.getArguments(), contains(parts.get(2)));
} }
@SuppressWarnings("unchecked")
@Test @Test
public void shouldReturnExecutableCommandClasses() { public void shouldReturnExecutableCommandClasses() {
// given / when // given / when

View File

@ -38,6 +38,7 @@ public class PlayerCommandTest {
// given // given
Player player = mock(Player.class); Player player = mock(Player.class);
List<String> arguments = Arrays.asList("arg1", "testarg2"); List<String> arguments = Arrays.asList("arg1", "testarg2");
@SuppressWarnings("unused")
CommandService service = mock(CommandService.class); CommandService service = mock(CommandService.class);
PlayerCommandImpl command = new PlayerCommandImpl(); PlayerCommandImpl command = new PlayerCommandImpl();

View File

@ -85,6 +85,7 @@ public class ReloadCommandTest {
public void shouldHandleReloadError() { public void shouldHandleReloadError() {
// given // given
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
@SuppressWarnings("unused")
CommandService service = mock(CommandService.class); CommandService service = mock(CommandService.class);
doThrow(IllegalStateException.class).when(initializer).performReloadOnServices(); doThrow(IllegalStateException.class).when(initializer).performReloadOnServices();
given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL); given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
@ -104,6 +105,7 @@ public class ReloadCommandTest {
public void shouldIssueWarningForChangedDatasourceSetting() { public void shouldIssueWarningForChangedDatasourceSetting() {
// given // given
CommandSender sender = mock(CommandSender.class); CommandSender sender = mock(CommandSender.class);
@SuppressWarnings("unused")
CommandService service = mock(CommandService.class); CommandService service = mock(CommandService.class);
given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL); given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
given(dataSource.getType()).willReturn(DataSourceType.SQLITE); given(dataSource.getType()).willReturn(DataSourceType.SQLITE);