refactor: update anvilgui usage
This commit is contained in:
parent
0e41c927c9
commit
9b840ee53f
1 changed files with 29 additions and 27 deletions
|
@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class AnvilManager {
|
public class AnvilManager {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final AppearanceManager appearanceManager;
|
private final AppearanceManager appearanceManager;
|
||||||
|
@ -37,13 +40,13 @@ public class AnvilManager {
|
||||||
return new AnvilGUI.Builder()
|
return new AnvilGUI.Builder()
|
||||||
.plugin(NickoBukkit.getInstance())
|
.plugin(NickoBukkit.getInstance())
|
||||||
.itemLeft(getLeftItem(false))
|
.itemLeft(getLeftItem(false))
|
||||||
.onComplete((anvilPlayer, response) -> {
|
.onComplete((completion) -> {
|
||||||
if (MojangUtils.isUsernameInvalid(response)) {
|
if (MojangUtils.isUsernameInvalid(completion.getText())) {
|
||||||
return AnvilGUI.Response.text("Invalid username!");
|
return Collections.singletonList(AnvilGUI.ResponseAction.replaceInputText("Invalid username!"));
|
||||||
} else {
|
} else {
|
||||||
appearanceManager.setName(response);
|
appearanceManager.setName(completion.getText());
|
||||||
openSkinAnvil();
|
openSkinAnvil();
|
||||||
return AnvilGUI.Response.close();
|
return Collections.singletonList(AnvilGUI.ResponseAction.close());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.text("New name...");
|
.text("New name...");
|
||||||
|
@ -53,18 +56,13 @@ public class AnvilManager {
|
||||||
return new AnvilGUI.Builder()
|
return new AnvilGUI.Builder()
|
||||||
.plugin(NickoBukkit.getInstance())
|
.plugin(NickoBukkit.getInstance())
|
||||||
.itemLeft(getLeftItem(false))
|
.itemLeft(getLeftItem(false))
|
||||||
.onComplete((anvilPlayer, response) -> {
|
.onComplete((completion) -> {
|
||||||
if (MojangUtils.isUsernameInvalid(response)) {
|
if (MojangUtils.isUsernameInvalid(completion.getText())) {
|
||||||
return AnvilGUI.Response.text("Invalid username!");
|
return Collections.singletonList(AnvilGUI.ResponseAction.replaceInputText("Invalid username!"));
|
||||||
} else {
|
} else {
|
||||||
appearanceManager.setName(response);
|
appearanceManager.setName(completion.getText());
|
||||||
final ActionResult actionResult = appearanceManager.updatePlayer(false);
|
final ActionResult<Void> actionResult = appearanceManager.updatePlayer(false);
|
||||||
if (!actionResult.isError()) {
|
return sendResultAndClose(actionResult);
|
||||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.SUCCESS));
|
|
||||||
} else {
|
|
||||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
|
||||||
}
|
|
||||||
return AnvilGUI.Response.close();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.text("New name...");
|
.text("New name...");
|
||||||
|
@ -74,21 +72,25 @@ public class AnvilManager {
|
||||||
return new AnvilGUI.Builder()
|
return new AnvilGUI.Builder()
|
||||||
.plugin(NickoBukkit.getInstance())
|
.plugin(NickoBukkit.getInstance())
|
||||||
.itemLeft(getLeftItem(true))
|
.itemLeft(getLeftItem(true))
|
||||||
.onComplete((anvilPlayer, response) -> {
|
.onComplete((completion) -> {
|
||||||
if (MojangUtils.isUsernameInvalid(response)) {
|
if (MojangUtils.isUsernameInvalid(completion.getText())) {
|
||||||
return AnvilGUI.Response.text("Invalid username!");
|
return Collections.singletonList(AnvilGUI.ResponseAction.replaceInputText("Invalid username!"));
|
||||||
} else {
|
} else {
|
||||||
appearanceManager.setSkin(response);
|
appearanceManager.setSkin(completion.getText());
|
||||||
final ActionResult actionResult = appearanceManager.updatePlayer(true);
|
final ActionResult<Void> actionResult = appearanceManager.updatePlayer(true);
|
||||||
|
return sendResultAndClose(actionResult);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.text("New skin...");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<AnvilGUI.ResponseAction> sendResultAndClose(ActionResult<Void> actionResult) {
|
||||||
if (!actionResult.isError()) {
|
if (!actionResult.isError()) {
|
||||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.SUCCESS));
|
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.SUCCESS));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
||||||
}
|
}
|
||||||
return AnvilGUI.Response.close();
|
return Collections.singletonList(AnvilGUI.ResponseAction.close());
|
||||||
}
|
|
||||||
})
|
|
||||||
.text("New skin...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getLeftItem(boolean skin) {
|
private ItemStack getLeftItem(boolean skin) {
|
||||||
|
|
Loading…
Reference in a new issue