use of eu.pb4.armorstandeditor.config.ArmorStandPreset in project ArmorStandEditor by Patbox.
the class EditorGuis method openPresetSelector.
public static void openPresetSelector(ServerPlayerEntity player) {
List<ArmorStandPreset> presets = new ArrayList<>(ConfigManager.PRESETS.values());
final int presetsSize = presets.size();
AtomicInteger page = new AtomicInteger();
final int maxPage = (int) Math.ceil((double) presetsSize / 18);
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false) {
@Override
public void onUpdate(boolean firstUpdate) {
super.onUpdate(firstUpdate);
if (firstUpdate) {
for (int x = 0; x < 9; x++) {
this.setSlot(x + 18, new GuiElementBuilder(Items.GRAY_STAINED_GLASS_PANE).setName(new LiteralText("")));
}
}
for (int x = 0; x < 18; x++) {
this.clearSlot(x);
if (page.get() * 18 + x < presetsSize) {
final ArmorStandPreset preset = presets.get(page.get() * 18 + x);
this.setSlot(x, new GuiElementBuilder(Items.ARMOR_STAND).setName(new LiteralText(preset.name).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GREEN))).addLoreLine(new TranslatableText("armorstandeditor.gui.preset-author", preset.author).setStyle(Style.EMPTY.withItalic(false).withColor(Formatting.GRAY))).setCallback((t1, t2, t3) -> {
((SPEInterface) this.player).setArmorStandEditorData(preset.asData());
((SPEInterface) this.player).setArmorStandEditorAction(EditorActions.PASTE);
player.sendMessage(new TranslatableText("armorstandeditor.message.copied"), true);
this.close();
}));
}
}
this.setSlot(this.size - 5, new GuiElementBuilder(Items.BARRIER).setName(new TranslatableText("dataPack.validation.back").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
this.close();
}));
this.setSlot(this.size - 8, new GuiElementBuilder(page.get() != 0 ? Items.ARROW : Items.LIGHT_GRAY_STAINED_GLASS_PANE).setName(new TranslatableText("spectatorMenu.previous_page").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
if (page.addAndGet(-1) < 0) {
page.set(0);
}
this.onUpdate(false);
}));
this.setSlot(this.size - 2, new GuiElementBuilder(page.get() != maxPage - 1 ? Items.ARROW : Items.LIGHT_GRAY_STAINED_GLASS_PANE).setName(new TranslatableText("spectatorMenu.next_page").setStyle(Style.EMPTY.withItalic(false))).setCallback((index, type, action) -> {
if (page.addAndGet(1) >= maxPage) {
page.set(maxPage - 1);
}
this.onUpdate(false);
}));
}
};
gui.setTitle(new TranslatableText("armorstandeditor.gui.presets_title"));
gui.open();
}
use of eu.pb4.armorstandeditor.config.ArmorStandPreset in project ArmorStandEditor by Patbox.
the class GeneralCommands method savePreset.
private static int savePreset(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
SPEInterface spei = (SPEInterface) player;
String id = context.getArgument("id", String.class);
String name = context.getArgument("name", String.class);
if (ConfigManager.INVALID_CHAR.matcher(id).matches()) {
context.getSource().sendFeedback(new TranslatableText("armorstandeditor.command.invalid-id", id).formatted(Formatting.RED), false);
return 0;
}
if (spei.getArmorStandEditorData() != null) {
ArmorStandPreset preset = new ArmorStandPreset(id, name, player.getGameProfile().getName());
preset.fromData(spei.getArmorStandEditorData());
ConfigManager.savePreset(preset);
context.getSource().sendFeedback(new TranslatableText("armorstandeditor.command.save-preset.success", name, id), false);
} else {
context.getSource().sendFeedback(new TranslatableText("armorstandeditor.command.save-preset.fail", name, id).formatted(Formatting.RED), false);
}
return 0;
}
use of eu.pb4.armorstandeditor.config.ArmorStandPreset in project ArmorStandEditor by Patbox.
the class GeneralCommands method listPresets.
private static int listPresets(CommandContext<ServerCommandSource> context) {
MutableText text = new LiteralText("").formatted(Formatting.DARK_GRAY);
Iterator<ArmorStandPreset> iterator = ConfigManager.PRESETS.values().iterator();
while (iterator.hasNext()) {
ArmorStandPreset preset = iterator.next();
if (preset.id.startsWith("$")) {
text.append(new LiteralText(preset.name).formatted(Formatting.YELLOW).append(new LiteralText(" (").formatted(Formatting.GRAY).append(new LiteralText("buildin/" + preset.id.substring(1)).formatted(Formatting.RED)).append(new LiteralText(")").formatted(Formatting.GRAY))));
} else {
text.append(new LiteralText(preset.name).formatted(Formatting.WHITE).append(new LiteralText(" (").formatted(Formatting.GRAY).append(new LiteralText(preset.id).formatted(Formatting.BLUE)).append(new LiteralText(")").formatted(Formatting.GRAY))));
}
if (iterator.hasNext()) {
text.append(new LiteralText(", "));
}
}
context.getSource().sendFeedback(text, false);
return 0;
}
Aggregations