fix: replace vavr's either with in-house implementation
This commit is contained in:
parent
a1a0b04471
commit
c217db98e8
7 changed files with 74 additions and 31 deletions
|
@ -65,7 +65,7 @@ public class AppearanceManager {
|
||||||
updatePlayer(true);
|
updatePlayer(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePlayer(boolean skinChange) {
|
public UpdateResult updatePlayer(boolean skinChange) {
|
||||||
NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
|
return NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,9 @@ package net.artelnatif.nicko.event;
|
||||||
|
|
||||||
import net.artelnatif.nicko.NickoBukkit;
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -17,7 +20,12 @@ public class PlayerJoinListener implements Listener {
|
||||||
|
|
||||||
if (appearanceManager.hasData()) {
|
if (appearanceManager.hasData()) {
|
||||||
final boolean skinChange = !player.getName().equals(appearanceManager.getSkin());
|
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);
|
}, 20L);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.artelnatif.nicko.impl;
|
package net.artelnatif.nicko.impl;
|
||||||
|
|
||||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||||
|
import net.artelnatif.nicko.disguise.UpdateResult;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public interface Internals {
|
public interface Internals {
|
||||||
|
@ -8,5 +9,5 @@ public interface Internals {
|
||||||
|
|
||||||
void updateOthers(Player player);
|
void updateOthers(Player player);
|
||||||
|
|
||||||
void updateProfile(Player player, NickoProfile profile, boolean skinChange);
|
UpdateResult updateProfile(Player player, NickoProfile profile, boolean skinChange);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import net.artelnatif.nicko.NickoBukkit;
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
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.artelnatif.nicko.mojang.MojangSkin;
|
||||||
import net.minecraft.network.chat.IChatBaseComponent;
|
import net.minecraft.network.chat.IChatBaseComponent;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
|
@ -82,7 +84,7 @@ public class v1_18_R1 implements Internals {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
final EntityPlayer entityPlayer = craftPlayer.getHandle();
|
final EntityPlayer entityPlayer = craftPlayer.getHandle();
|
||||||
Optional<MojangSkin> skin;
|
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()));
|
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
|
||||||
updateSelf(player);
|
updateSelf(player);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.SKIN_FAIL_MOJANG);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||||
}
|
}
|
||||||
} catch (IOException | ExecutionException e) {
|
} 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);
|
onlineEntityPlayer.b.a(add);
|
||||||
});
|
});
|
||||||
updateOthers(player);
|
updateOthers(player);
|
||||||
|
return new UpdateResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import net.artelnatif.nicko.NickoBukkit;
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
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.artelnatif.nicko.mojang.MojangSkin;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.network.chat.IChatBaseComponent;
|
import net.minecraft.network.chat.IChatBaseComponent;
|
||||||
|
@ -82,7 +84,7 @@ public class v1_18_R2 implements Internals {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
final EntityPlayer entityPlayer = craftPlayer.getHandle();
|
final EntityPlayer entityPlayer = craftPlayer.getHandle();
|
||||||
Optional<MojangSkin> skin;
|
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()));
|
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
|
||||||
updateSelf(player);
|
updateSelf(player);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.SKIN_FAIL_MOJANG);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||||
}
|
}
|
||||||
} catch (IOException | ExecutionException e) {
|
} 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);
|
onlineEntityPlayer.b.a(add);
|
||||||
});
|
});
|
||||||
updateOthers(player);
|
updateOthers(player);
|
||||||
|
return new UpdateResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import com.mojang.authlib.properties.Property;
|
||||||
import com.mojang.authlib.properties.PropertyMap;
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
import net.artelnatif.nicko.NickoBukkit;
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
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.artelnatif.nicko.mojang.MojangSkin;
|
||||||
import net.minecraft.network.chat.IChatBaseComponent;
|
import net.minecraft.network.chat.IChatBaseComponent;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
|
@ -83,7 +85,7 @@ public class v1_19_R1 implements Internals {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||||
final EntityPlayer entityPlayer = craftPlayer.getHandle();
|
final EntityPlayer entityPlayer = craftPlayer.getHandle();
|
||||||
Optional<MojangSkin> skin;
|
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()));
|
properties.put("textures", new Property("textures", skin.get().value(), skin.get().signature()));
|
||||||
updateSelf(player);
|
updateSelf(player);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.SKIN_FAIL_MOJANG);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.NAME_FAIL_MOJANG);
|
||||||
}
|
}
|
||||||
} catch (IOException | ExecutionException e) {
|
} catch (IOException | ExecutionException e) {
|
||||||
return;
|
return new UpdateResult(I18NDict.Error.UNEXPECTED_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add.b().clear();
|
add.b().clear();
|
||||||
|
@ -127,6 +130,6 @@ public class v1_19_R1 implements Internals {
|
||||||
onlineEntityPlayer.b.a(add);
|
onlineEntityPlayer.b.a(add);
|
||||||
});
|
});
|
||||||
updateOthers(player);
|
updateOthers(player);
|
||||||
}
|
return new UpdateResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue