Fixed lore from SearchUIValues, expanded SettingsUI
This commit is contained in:
1 parent
2d635263c2
commit
d73662b4b3
10 files changed
+121
-46
No files matched your search
@@ -94,7 +94,7 @@ public class TextGeneratorCommand extends Command {
|
||||
private boolean checkSettingsMenu(Player player, String[] args) {
|
||||
if (!(args.length == 1 && args[0].equalsIgnoreCase("settings"))) return false;
|
||||
if (!currentEditedTexts.containsKey(player.getUniqueId())) {
|
||||
new SettingsUI(player, "TextGenerator settings");
|
||||
new SettingsUI(player);
|
||||
} else {
|
||||
player.sendMessage(MessagesManager.getMessage("openSettingsMenu.denied",
|
||||
currentEditedTexts.get(player.getUniqueId()).getTextInstance().getText()));
|
||||
@@ -127,7 +127,7 @@ public class TextGeneratorCommand extends Command {
|
||||
if (!currentEditedTexts.containsKey(player.getUniqueId())) {
|
||||
player.sendMessage(MessagesManager.getMessage("edit.openMenuDenied"));
|
||||
} else {
|
||||
new SettingsUI(player, "TextGenerator edit menu");
|
||||
new SettingsUI(player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.philw.textgenerator.ui;
|
||||
import de.philw.textgenerator.TextGenerator;
|
||||
import de.philw.textgenerator.manager.ConfigManager;
|
||||
import de.philw.textgenerator.ui.value.Block;
|
||||
import de.philw.textgenerator.utils.UIUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -12,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockSearchUI extends SearchUI {
|
||||
@@ -47,22 +47,20 @@ public class BlockSearchUI extends SearchUI {
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + display);
|
||||
if (TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().containsKey(uuid)) {
|
||||
if (block == TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().get(uuid).getTextInstance().getBlock()) {
|
||||
itemMeta.setDisplayName(ChatColor.RED + display);
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GRAY + "You have already assigned this value"));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.RED, "You have already assigned this value"));
|
||||
itemMeta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
} else {
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.YELLOW + "Click to change the block from you " +
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Click to change the block of your " +
|
||||
"current edited text to " + display));
|
||||
}
|
||||
} else {
|
||||
if (block == ConfigManager.getBlock()) {
|
||||
itemMeta.setDisplayName(ChatColor.RED + display);
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GRAY + "You have already assigned this value"));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.RED, "You have already assigned this value"));
|
||||
itemMeta.addEnchant(Enchantment.ARROW_DAMAGE, 1, true);
|
||||
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
} else {
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.YELLOW + "Click to change the default Block to " + display));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Click to change the default Block to " + display));
|
||||
}
|
||||
}
|
||||
itemMeta.setLocalizedName(SearchUI.BLOCK_SEARCH_UI + ";" + block.name());
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public class FontSizeSearchUI extends SearchUI {
|
||||
@@ -47,18 +46,16 @@ public class FontSizeSearchUI extends SearchUI {
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + String.valueOf(size));
|
||||
if (TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().containsKey(uuid)) {
|
||||
if (size == TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().get(uuid).getTextInstance().getFontSize()) {
|
||||
itemMeta.setDisplayName(String.valueOf(ChatColor.RED) + size);
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GRAY + "You have already assigned this value"));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.RED, "You have already assigned this value"));
|
||||
} else {
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.YELLOW + "Click to change the font size from you" +
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Click to change the font size of your" +
|
||||
" current edited text to " + size));
|
||||
}
|
||||
} else {
|
||||
if (size == ConfigManager.getFontSize()) {
|
||||
itemMeta.setDisplayName(String.valueOf(ChatColor.RED) + size);
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GRAY + "You have already assigned this value"));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.RED, "You have already assigned this value"));
|
||||
} else {
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.YELLOW + "Click to change the default font size " +
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Click to change the default font size " +
|
||||
"to " + size));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LineSpacingSearchUI extends SearchUI {
|
||||
@@ -49,18 +48,16 @@ public class LineSpacingSearchUI extends SearchUI {
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + String.valueOf(lineSpacingNumber));
|
||||
if (TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().containsKey(uuid)) {
|
||||
if (lineSpacingNumber == TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().get(uuid).getTextInstance().getLineSpacing()) {
|
||||
itemMeta.setDisplayName(String.valueOf(ChatColor.RED) + lineSpacingNumber);
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GRAY + "You have already assigned this value"));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.RED, "You have already assigned this value"));
|
||||
} else {
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.YELLOW + "Click to change the font size from you" +
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Click to change the line spacing of your" +
|
||||
" current edited text to " + lineSpacingNumber));
|
||||
}
|
||||
} else {
|
||||
if (lineSpacingNumber == ConfigManager.getLineSpacing()) {
|
||||
itemMeta.setDisplayName(String.valueOf(ChatColor.RED) + lineSpacingNumber);
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.GRAY + "You have already assigned this value"));
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.RED, "You have already assigned this value"));
|
||||
} else {
|
||||
itemMeta.setLore(Collections.singletonList(ChatColor.YELLOW + "Click to change the default font size " +
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Click to change the default line spacing " +
|
||||
"to " + lineSpacingNumber));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class SearchUI {
|
||||
for (int index : SPACE_INDEXES) {
|
||||
ItemStack itemStack = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName("Space");
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(" ");
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
inventory.setItem(index, itemStack);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public abstract class SearchUI {
|
||||
} else {
|
||||
nextPageItemStack = UIUtil.getSkullByString(SkullData.NEXT_PAGE_DISALLOWED);
|
||||
ItemMeta itemMeta = Objects.requireNonNull(nextPageItemStack).getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.RED + "Next Page");
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + "Next Page");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.GRAY + "(" + currentPage + "/" + UIUtil.getMaxPage(searchedItems, SPACES) + ")");
|
||||
lore.add("");
|
||||
@@ -114,7 +114,7 @@ public abstract class SearchUI {
|
||||
} else {
|
||||
previousPageItemStack = UIUtil.getSkullByString(SkullData.PREVIOUS_PAGE_DISALLOWED);
|
||||
ItemMeta itemMeta = Objects.requireNonNull(previousPageItemStack).getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.RED + "Previous Page");
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + "Previous Page");
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add(ChatColor.GRAY + "(" + currentPage + "/" + UIUtil.getMaxPage(searchedItems, SPACES) + ")");
|
||||
lore.add("");
|
||||
|
||||
@@ -50,11 +50,7 @@ public class SearchUIListener implements Listener {
|
||||
e.setCancelled(true);
|
||||
switch (e.getRawSlot()) {
|
||||
case SearchUI.RETURN_ARROW_INDEX:
|
||||
if (TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().containsKey(player.getUniqueId())) {
|
||||
new SettingsUI(player, "TextGenerator edit menu");
|
||||
} else {
|
||||
new SettingsUI(player, "TextGenerator settings");
|
||||
}
|
||||
new SettingsUI(player);
|
||||
searchUISToListenTo.remove(player.getUniqueId());
|
||||
break;
|
||||
case SearchUI.PREVIOUS_PAGE_INDEX:
|
||||
|
||||
@@ -1,33 +1,101 @@
|
||||
package de.philw.textgenerator.ui;
|
||||
|
||||
import de.philw.textgenerator.TextGenerator;
|
||||
import de.philw.textgenerator.manager.ConfigManager;
|
||||
import de.philw.textgenerator.utils.SkullData;
|
||||
import de.philw.textgenerator.utils.UIUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SettingsUI {
|
||||
|
||||
protected final static int FONT_SIZE_INDEX = 0;
|
||||
protected final static int LINE_SPACING_INDEX = 1;
|
||||
protected final static int BLOCKS_INDEX = 2;
|
||||
protected final static int DRAG_PREVIEW_INDEX = 3;
|
||||
protected final static int DRAG_TO_MOVE_INDEX = 3;
|
||||
|
||||
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
|
||||
public SettingsUI(Player player, String display) {
|
||||
inventory = Bukkit.createInventory(null, 54, ChatColor.GREEN + display);
|
||||
public SettingsUI(Player player) {
|
||||
this.player = player;
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, ChatColor.GREEN + (isEditMode() ? "TextGenerator edit menu" : "TextGenerator settings"));
|
||||
|
||||
inventory.setItem(FONT_SIZE_INDEX, UIUtil.getSkullByString(SkullData.FONT_SIZE));
|
||||
inventory.setItem(LINE_SPACING_INDEX, UIUtil.getSkullByString(SkullData.LINE_SPACING));
|
||||
inventory.setItem(BLOCKS_INDEX, UIUtil.getSkullByString(SkullData.CHANGE_BLOCKS));
|
||||
inventory.setItem(DRAG_PREVIEW_INDEX, UIUtil.getSkullByString(SkullData.DRAG_PREVIEW));
|
||||
inventory.setItem(FONT_SIZE_INDEX, getFontSizeItemStack());
|
||||
inventory.setItem(LINE_SPACING_INDEX, getLineSpacingItemStack());
|
||||
inventory.setItem(BLOCKS_INDEX, getChangeBlocksItemStack());
|
||||
inventory.setItem(DRAG_TO_MOVE_INDEX, getDragToMoveItemStack());
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
private boolean isEditMode() {
|
||||
return TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
private ItemStack getFontSizeItemStack() {
|
||||
ItemStack itemStack = UIUtil.getSkullByString(SkullData.FONT_SIZE);
|
||||
ItemMeta itemMeta = Objects.requireNonNull(itemStack).getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + "Font size");
|
||||
if (!isEditMode()) {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Change the default size from your texts"));
|
||||
} else {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Change the size of your current edited text"));
|
||||
}
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private ItemStack getLineSpacingItemStack() {
|
||||
ItemStack itemStack = UIUtil.getSkullByString(SkullData.LINE_SPACING);
|
||||
ItemMeta itemMeta = Objects.requireNonNull(itemStack).getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + "Line spacing");
|
||||
if (!isEditMode()) {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Change the default distance between lines"));
|
||||
} else {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Change the distance between lines of your current edited text"));
|
||||
}
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private ItemStack getChangeBlocksItemStack() {
|
||||
ItemStack itemStack = UIUtil.getSkullByString(SkullData.CHANGE_BLOCKS);
|
||||
ItemMeta itemMeta = Objects.requireNonNull(itemStack).getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + "Block");
|
||||
if (!isEditMode()) {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Change the default block your texts consist of"));
|
||||
} else {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Change the block of your current edited text consists of"));
|
||||
}
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private ItemStack getDragToMoveItemStack() {
|
||||
ItemStack itemStack = UIUtil.getSkullByString(SkullData.DRAG_TO_MOVE);
|
||||
ItemMeta itemMeta = Objects.requireNonNull(itemStack).getItemMeta();
|
||||
Objects.requireNonNull(itemMeta).setDisplayName(ChatColor.GREEN + "Drag to move");
|
||||
if (isEditMode()) {
|
||||
if (TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().get(player.getUniqueId()).getTextInstance().isDragToMove()) {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Stop your current edited text follow your view"));
|
||||
} else {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Make your current edited text follow your view"));
|
||||
}
|
||||
} else {
|
||||
if (ConfigManager.isDragToMove(false)) {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Stop default texts follow your view"));
|
||||
} else {
|
||||
itemMeta.setLore(UIUtil.getLore(ChatColor.YELLOW, "Make default texts follow your view"));
|
||||
}
|
||||
}
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class SettingsUIListener implements Listener {
|
||||
case SettingsUI.BLOCKS_INDEX:
|
||||
new BlockSearchUI(player);
|
||||
break;
|
||||
case SettingsUI.DRAG_PREVIEW_INDEX:
|
||||
case SettingsUI.DRAG_TO_MOVE_INDEX:
|
||||
toggleDragToMove(player);
|
||||
break;
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class SettingsUIListener implements Listener {
|
||||
if (!TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().containsKey(player.getUniqueId())) {
|
||||
boolean dragToMove = !ConfigManager.isDragToMove(false);
|
||||
ConfigManager.setDragToMove(dragToMove);
|
||||
new SettingsUI(player);
|
||||
} else {
|
||||
CurrentEditedText currentEditedText =
|
||||
TextGenerator.getInstance().getTextGeneratorCommand().getCurrentEditedTexts().get(player.getUniqueId());
|
||||
|
||||
@@ -21,7 +21,7 @@ public class SkullData {
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjk3MWJmNTA1YzM0MzcxNDQyZmViNDg2NWZiZGI4OWY3ODYzZWM5OGRiMDBjZTI1NjIzNjRiNjE5Y2ViMjBmNiJ9fX0=";
|
||||
public static final String CHANGE_BLOCKS =
|
||||
"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWE0YzQ2OGE2ZGZiZWU5OTdhMmM1MmQzMDY3YTc4ODUzM2ZhNmQ4NmE5MzBlMTM0ODQ4ODBhMzlkNTU4NmZlOSJ9fX0=";
|
||||
public static final String DRAG_PREVIEW =
|
||||
public static final String DRAG_TO_MOVE =
|
||||
"";
|
||||
|
||||
// Numbers
|
||||
|
||||
@@ -2,15 +2,13 @@ package de.philw.textgenerator.utils;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class UIUtil {
|
||||
|
||||
@@ -61,4 +59,24 @@ public class UIUtil {
|
||||
return newItems;
|
||||
}
|
||||
|
||||
public static List<String> getLore(ChatColor chatColor, String lore) {
|
||||
List<String> realLore = new ArrayList<>();
|
||||
|
||||
String[] words = lore.split(" ");
|
||||
String[] lines = new String[words.length % 4 == 0 ? words.length/4 : words.length/4+1];
|
||||
Arrays.fill(lines, String.valueOf(chatColor));
|
||||
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
int lineFromWord = i / 4;
|
||||
lines[lineFromWord] = lines[lineFromWord] + (i % 4 == 0 ? "" : " ") + word;
|
||||
}
|
||||
|
||||
for (String line: lines) {
|
||||
line.substring(0, line.length()-1);
|
||||
realLore.add(line);
|
||||
}
|
||||
return realLore;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user