fix: replace vavr's either with in-house implementation

This commit is contained in:
aroooo 2022-11-03 09:17:50 +01:00
parent a1a0b04471
commit c217db98e8
7 changed files with 74 additions and 31 deletions

View file

@ -65,7 +65,7 @@ public class AppearanceManager {
updatePlayer(true);
}
public void updatePlayer(boolean skinChange) {
NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
public UpdateResult updatePlayer(boolean skinChange) {
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
}
}

View file

@ -0,0 +1,25 @@
package net.artelnatif.nicko.disguise;
import net.artelnatif.nicko.i18n.I18NDict;
public class UpdateResult {
private final I18NDict.Error errorMessage;
private boolean error = false;
public UpdateResult(I18NDict.Error errorMessage) {
this.error = true;
this.errorMessage = errorMessage;
}
public UpdateResult() {
this.errorMessage = null;
}
public boolean isError() {
return error;
}
public I18NDict.Error getErrorMessage() {
return errorMessage;
}
}

View file

@ -2,6 +2,9 @@ package net.artelnatif.nicko.event;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.AppearanceManager;
import net.artelnatif.nicko.disguise.UpdateResult;
import net.artelnatif.nicko.i18n.I18N;
import net.artelnatif.nicko.i18n.I18NDict;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -17,7 +20,12 @@ public class PlayerJoinListener implements Listener {
if (appearanceManager.hasData()) {
final boolean skinChange = !player.getName().equals(appearanceManager.getSkin());
appearanceManager.updatePlayer(skinChange);
final UpdateResult updateResult = appearanceManager.updatePlayer(skinChange);
if (updateResult.isError()) {
player.sendMessage(I18N.translate(player, I18NDict.Event.DISGUISE_FAIL.getKey(), I18N.translate(player, updateResult.getErrorMessage().getKey())));
} else {
player.sendMessage(I18N.translate(player, I18NDict.Event.DISGUISE_SUCCESS.getKey()));
}
}
}, 20L);
}

View file

@ -1,6 +1,7 @@
package net.artelnatif.nicko.impl;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.UpdateResult;
import org.bukkit.entity.Player;
public interface Internals {
@ -8,5 +9,5 @@ public interface Internals {
void updateOthers(Player player);
void updateProfile(Player player, NickoProfile profile, boolean skinChange);
UpdateResult updateProfile(Player player, NickoProfile profile, boolean skinChange);
}

View file

@ -5,6 +5,8 @@ import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.UpdateResult;
import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*;
@ -82,7 +84,7 @@ public class v1_18_R1 implements Internals {
}
@Override
public void updateProfile(Player player, NickoProfile profile, boolean skinChange) {
public UpdateResult updateProfile(Player player, NickoProfile profile, boolean skinChange) {
final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle();
Optional<MojangSkin> skin;
@ -103,13 +105,13 @@ public class v1_18_R1 implements Internals {
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
updateSelf(player);
} else {
return;
return new UpdateResult(I18NDict.Error.SKIN_FAIL_MOJANG);
}
} else {
return;
return new UpdateResult(I18NDict.Error.NAME_FAIL_MOJANG);
}
} catch (IOException | ExecutionException e) {
return;
return new UpdateResult(I18NDict.Error.UNEXPECTED_ERROR);
}
}
@ -125,5 +127,6 @@ public class v1_18_R1 implements Internals {
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
return new UpdateResult();
}
}

View file

@ -5,6 +5,8 @@ import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.UpdateResult;
import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.IChatBaseComponent;
@ -82,7 +84,7 @@ public class v1_18_R2 implements Internals {
}
@Override
public void updateProfile(Player player, NickoProfile profile, boolean skinChange) {
public UpdateResult updateProfile(Player player, NickoProfile profile, boolean skinChange) {
final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle();
Optional<MojangSkin> skin;
@ -103,13 +105,13 @@ public class v1_18_R2 implements Internals {
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
updateSelf(player);
} else {
return;
return new UpdateResult(I18NDict.Error.SKIN_FAIL_MOJANG);
}
} else {
return;
return new UpdateResult(I18NDict.Error.NAME_FAIL_MOJANG);
}
} catch (IOException | ExecutionException e) {
return;
return new UpdateResult(I18NDict.Error.UNEXPECTED_ERROR);
}
}
@ -125,5 +127,6 @@ public class v1_18_R2 implements Internals {
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
return new UpdateResult();
}
}

View file

@ -5,6 +5,8 @@ import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.disguise.UpdateResult;
import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*;
@ -83,7 +85,7 @@ public class v1_19_R1 implements Internals {
}
@Override
public void updateProfile(Player player, NickoProfile profile, boolean skinChange) {
public UpdateResult updateProfile(Player player, NickoProfile profile, boolean skinChange) {
final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle();
Optional<MojangSkin> skin;
@ -104,13 +106,14 @@ public class v1_19_R1 implements Internals {
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
updateSelf(player);
} else {
return;
return new UpdateResult(I18NDict.Error.SKIN_FAIL_MOJANG);
}
} else {
return;
return new UpdateResult(I18NDict.Error.NAME_FAIL_MOJANG);
}
} catch (IOException | ExecutionException e) {
return;
return new UpdateResult(I18NDict.Error.UNEXPECTED_ERROR);
}
}
add.b().clear();
@ -127,6 +130,6 @@ public class v1_19_R1 implements Internals {
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
}
return new UpdateResult();
}
}