Optional migration

This commit is contained in:
games647
2018-03-05 21:27:48 +01:00
parent 8272aeac69
commit f250f8071f
8 changed files with 18 additions and 28 deletions
@@ -4,6 +4,8 @@ import com.github.games647.fastlogin.core.PlayerProfile;
import com.github.games647.fastlogin.core.mojang.SkinProperties;
import com.github.games647.fastlogin.core.shared.LoginSession;
import java.util.Optional;
import org.apache.commons.lang.ArrayUtils;
/**
@@ -63,8 +65,8 @@ public class BukkitLoginSession extends LoginSession {
}
//todo: this should be optional for players without a skin at all
public synchronized SkinProperties getSkinProperty() {
return skinProperty;
public synchronized Optional<SkinProperties> getSkin() {
return Optional.ofNullable(skinProperty);
}
/**
@@ -36,7 +36,7 @@ public class CrackedCommand implements CommandExecutor {
plugin.getCore().sendLocaleMessage("remove-premium", sender);
profile.setPremium(false);
profile.setUuid(null);
profile.setId(null);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getCore().getStorage().save(profile);
});
@@ -44,11 +44,7 @@ public class SkinApplyListener implements Listener {
//loginEvent.getAddress is just a InetAddress not InetSocketAddress, so not unique enough
for (BukkitLoginSession session : plugin.getLoginSessions().values()) {
if (session.getUsername().equals(player.getName())) {
SkinProperties skinProperty = session.getSkinProperty();
if (skinProperty != null) {
applySkin(player, skinProperty.getValue(), skinProperty.getSignature());
}
session.getSkin().ifPresent(skin -> applySkin(player, skin.getValue(), skin.getSignature()));
break;
}
}