refactor: much cleaner internals
This commit is contained in:
parent
a72b67be06
commit
c7d6c57320
7 changed files with 110 additions and 169 deletions
|
@ -2,9 +2,10 @@ package net.artelnatif.nicko.disguise;
|
|||
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
|
||||
public class ActionResult {
|
||||
public class ActionResult<R> {
|
||||
private final I18NDict errorMessage;
|
||||
private boolean error = false;
|
||||
private R result;
|
||||
|
||||
public ActionResult(I18NDict errorMessage) {
|
||||
this.error = true;
|
||||
|
@ -15,6 +16,14 @@ public class ActionResult {
|
|||
this.errorMessage = null;
|
||||
}
|
||||
|
||||
public void setResult(R result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public R getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isError() {
|
||||
return error;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,44 @@
|
|||
package net.artelnatif.nicko.impl;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.disguise.ActionResult;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public interface Internals {
|
||||
void updateSelf(Player player);
|
||||
|
||||
void updateOthers(Player player);
|
||||
|
||||
ActionResult updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset);
|
||||
ActionResult<Void> updateProfile(Player player, NickoProfile profile, boolean skinChange, boolean reset);
|
||||
|
||||
default ActionResult<MojangSkin> fetchSkinTextures(NickoProfile profile, boolean reset) {
|
||||
Optional<MojangSkin> skin;
|
||||
try {
|
||||
final MojangAPI mojang = NickoBukkit.getInstance().getMojangAPI();
|
||||
final Optional<String> uuid = mojang.getUUID(profile.getSkin());
|
||||
if (uuid.isPresent()) {
|
||||
skin = (reset ? mojang.getSkinWithoutCaching(uuid.get()) : mojang.getSkin(uuid.get()));
|
||||
if (skin.isEmpty()) {
|
||||
return new ActionResult<>(I18NDict.Error.SKIN_FAIL_MOJANG);
|
||||
}
|
||||
|
||||
final ActionResult<MojangSkin> actionResult = new ActionResult<>();
|
||||
actionResult.setResult(skin.get());
|
||||
return actionResult;
|
||||
}
|
||||
return new ActionResult<>(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||
} catch (ExecutionException e) {
|
||||
return new ActionResult<>(I18NDict.Error.SKIN_FAIL_CACHE);
|
||||
} catch (IOException e) {
|
||||
return new ActionResult<>(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue