feat: revert either impl

This commit is contained in:
aroooo 2022-11-02 11:45:53 +01:00
parent 6314fe81b6
commit a1a0b04471
9 changed files with 47 additions and 63 deletions

View file

@ -1,6 +1,5 @@
package net.artelnatif.nicko.disguise;
import io.vavr.control.Either;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.storage.PlayerDataStore;
import org.bukkit.Bukkit;
@ -66,7 +65,7 @@ public class AppearanceManager {
updatePlayer(true);
}
public Either<String, Void> updatePlayer(boolean skinChange) {
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
public void updatePlayer(boolean skinChange) {
NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
}
}

View file

@ -2,8 +2,6 @@ package net.artelnatif.nicko.event;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.AppearanceManager;
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;
@ -19,9 +17,7 @@ public class PlayerJoinListener implements Listener {
if (appearanceManager.hasData()) {
final boolean skinChange = !player.getName().equals(appearanceManager.getSkin());
appearanceManager.updatePlayer(skinChange)
.peek(unused -> player.sendMessage(I18N.translate(player, I18NDict.Event.PREVIOUS_SKIN_APPLIED.getKey())))
.peekLeft(s -> player.sendMessage(I18N.translate(player, s)));
appearanceManager.updatePlayer(skinChange);
}
}, 20L);
}

View file

@ -2,6 +2,8 @@ package net.artelnatif.nicko.i18n;
public class I18NDict {
public enum Event {
DISGUISE_SUCCESS("disguise.success"),
DISGUISE_FAIL("disguise.fail"),
PREVIOUS_SKIN_APPLIED("previous_skin_applied.ok"),
PREVIOUS_SKIN_APPLY_FAIL("previous_skin_applied.fail");

View file

@ -1,11 +1,12 @@
package net.artelnatif.nicko.impl;
import io.vavr.control.Either;
import net.artelnatif.nicko.disguise.NickoProfile;
import org.bukkit.entity.Player;
public interface Internals {
void updateSelf(Player player);
void updateOthers(Player player);
Either<String, Void> updateProfile(Player player, NickoProfile profile, boolean skinChange);
void updateProfile(Player player, NickoProfile profile, boolean skinChange);
}

View file

@ -1,7 +1,9 @@
event.previous_skin_applied.ok=§2Applied your previous disguise back.
event.previous_skin_applied.fail=§cFailed to apply your §2previous §cdisguise back.
event.previous_skin_applied.ok=§aApplied your previous disguise back.
event.previous_skin_applied.fail=§cFailed to apply your previous disguise back.
player.offline=§c{0} §fis offline, please try again.
error.generic=§cAn unknown error occured. Please contact the developer.
error.couldnt_get_name_from_mojang=§cFailed to get username from Mojang. Does the user exists?
error.couldnt_get_skin_from_mojang=§cFailed to get skin from Mojang.
error.couldnt_get_skin_from_cache=§cFailed to get skin from cache.
event.disguise.ok=§aDisguise applied.
event.disguise.fail=§cUnable to apply your disguise.

View file

@ -1,7 +1,9 @@
event.previous_skin_applied.ok=§2Déguisement précédent appliqué.
event.previous_skin_applied.ok=§aDéguisement précédent appliqué.
event.previous_skin_applied.fail=§cImpossible d'appliquer votre déguisement précédent.
player.offline=§c{0} §fest hors-ligne, veuillez réessayer.
error.generic=§cUne erreur inconnue est survenue. Veuillez contacter le développeur.
error.couldnt_get_name_from_mojang=§cImpossible de récupérer le nom d'utilisateur depuis Mojang. Cet utilisateur existe-il?
error.couldnt_get_skin_from_mojang=§cImpossible de récupérer le skin depuis Mojang.
error.couldnt_get_skin_from_cache=§cImpossible de récupérer le skin depuis le cache.
event.disguise.ok=§aDéguisement appliqué.
event.disguise.fail=§cImpossible d'appliquer votre déguisement.

View file

@ -3,10 +3,8 @@ package net.artelnatif.nicko.impl;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import io.vavr.control.Either;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*;
@ -84,7 +82,7 @@ public class v1_18_R1 implements Internals {
}
@Override
public Either<String, Void> updateProfile(Player player, NickoProfile profile, boolean skinChange) {
public void updateProfile(Player player, NickoProfile profile, boolean skinChange) {
final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle();
Optional<MojangSkin> skin;
@ -104,17 +102,14 @@ public class v1_18_R1 implements Internals {
final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
updateSelf(player);
return Either.right(null);
} else {
return Either.left(I18NDict.Error.SKIN_FAIL_MOJANG.getKey());
return;
}
} else {
return Either.left(I18NDict.Error.NAME_FAIL_MOJANG.getKey());
return;
}
} catch (IOException e) {
return Either.left(I18NDict.Error.UNEXPECTED_ERROR.getKey());
} catch (ExecutionException e) {
return Either.left(I18NDict.Error.SKIN_FAIL_CACHE.getKey());
} catch (IOException | ExecutionException e) {
return;
}
}
@ -130,6 +125,5 @@ public class v1_18_R1 implements Internals {
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
return Either.right(null);
}
}

View file

@ -3,10 +3,8 @@ package net.artelnatif.nicko.impl;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import io.vavr.control.Either;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.IChatBaseComponent;
@ -84,7 +82,7 @@ public class v1_18_R2 implements Internals {
}
@Override
public Either<String, Void> updateProfile(Player player, NickoProfile profile, boolean skinChange) {
public void updateProfile(Player player, NickoProfile profile, boolean skinChange) {
final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle();
Optional<MojangSkin> skin;
@ -104,17 +102,14 @@ public class v1_18_R2 implements Internals {
final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
updateSelf(player);
return Either.right(null);
} else {
return Either.left(I18NDict.Error.SKIN_FAIL_MOJANG.getKey());
return;
}
} else {
return Either.left(I18NDict.Error.NAME_FAIL_MOJANG.getKey());
return;
}
} catch (IOException e) {
return Either.left(I18NDict.Error.UNEXPECTED_ERROR.getKey());
} catch (ExecutionException e) {
return Either.left(I18NDict.Error.SKIN_FAIL_CACHE.getKey());
} catch (IOException | ExecutionException e) {
return;
}
}
@ -130,6 +125,5 @@ public class v1_18_R2 implements Internals {
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
return null;
}
}

View file

@ -3,10 +3,8 @@ package net.artelnatif.nicko.impl;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import io.vavr.control.Either;
import net.artelnatif.nicko.NickoBukkit;
import net.artelnatif.nicko.disguise.NickoProfile;
import net.artelnatif.nicko.i18n.I18NDict;
import net.artelnatif.nicko.mojang.MojangSkin;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.protocol.game.*;
@ -85,7 +83,7 @@ public class v1_19_R1 implements Internals {
}
@Override
public Either<String, Void> updateProfile(Player player, NickoProfile profile, boolean skinChange) {
public void updateProfile(Player player, NickoProfile profile, boolean skinChange) {
final CraftPlayer craftPlayer = (CraftPlayer) player;
final EntityPlayer entityPlayer = craftPlayer.getHandle();
Optional<MojangSkin> skin;
@ -105,34 +103,30 @@ public class v1_19_R1 implements Internals {
final PropertyMap properties = gameProfile.getProperties();
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
updateSelf(player);
return Either.right(null);
} else {
return Either.left(I18NDict.Error.SKIN_FAIL_MOJANG.getKey());
return;
}
} else {
return Either.left(I18NDict.Error.NAME_FAIL_MOJANG.getKey());
return;
}
} catch (IOException e) {
return Either.left(I18NDict.Error.UNEXPECTED_ERROR.getKey());
} catch (ExecutionException e) {
return Either.left(I18NDict.Error.SKIN_FAIL_CACHE.getKey());
} catch (IOException | ExecutionException e) {
return;
}
add.b().clear();
add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile,
player.getPing(),
EnumGamemode.a(player.getGameMode().ordinal()),
IChatBaseComponent.a(profile.getName()),
entityPlayer.fz().b()));
entityPlayer.b.a(add);
Bukkit.getOnlinePlayers().forEach(online -> {
EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle();
onlineEntityPlayer.b.a(remove);
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
}
add.b().clear();
add.b().add(new PacketPlayOutPlayerInfo.PlayerInfoData(gameProfile,
player.getPing(),
EnumGamemode.a(player.getGameMode().ordinal()),
IChatBaseComponent.a(profile.getName()),
entityPlayer.fz().b()));
entityPlayer.b.a(add);
Bukkit.getOnlinePlayers().forEach(online -> {
EntityPlayer onlineEntityPlayer = ((CraftPlayer) online).getHandle();
onlineEntityPlayer.b.a(remove);
onlineEntityPlayer.b.a(add);
});
updateOthers(player);
return Either.right(null);
}
}