Move some hardcoded strings to MagicValues class

This commit is contained in:
GeorgH93 2020-10-11 20:05:21 +02:00
parent 39229f921e
commit 3d5f29c1f6
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 13 additions and 9 deletions

View File

@ -26,6 +26,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.ExtendedAPI.MinepacksCommand;
import at.pcgamingfreaks.Minepacks.Bukkit.Item.ItemConfig;
import at.pcgamingfreaks.Minepacks.Bukkit.Listener.ItemShortcut;
import at.pcgamingfreaks.Minepacks.Bukkit.MagicValues;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Minepacks.Bukkit.Permissions;
import at.pcgamingfreaks.StringUtils;
@ -78,8 +79,8 @@ public ShortcutCommand(final @NotNull Minepacks plugin, final @NotNull ItemShort
if(playerChoice)
{
validShortcutStyles = plugin.getBackpacksConfig().getBackpackItems().stream().map(ItemConfig::getName).collect(Collectors.toSet());
validShortcutStyles.add("default");
if(allowPlayerDisable) validShortcutStyles.add("none");
validShortcutStyles.add(MagicValues.BACKPACK_STYLE_NAME_DEFAULT);
if(allowPlayerDisable) validShortcutStyles.add(MagicValues.BACKPACK_STYLE_NAME_DISABLED);
gui = buildGui(plugin);
}
@ -111,14 +112,14 @@ public ShortcutCommand(final @NotNull Minepacks plugin, final @NotNull ItemShort
}
//endregion
//region set default button
ItemStack item = new ItemConfig("default", "BARRIER", 1, "default", null, -1, null).make();
guiBuilder.addButton(new GuiButton(item, (player, clickType, cursor) -> { player.performCommand(setCommandBase + "default"); player.closeInventory(); }));
ItemStack item = new ItemConfig(MagicValues.BACKPACK_STYLE_NAME_DEFAULT, "BARRIER", 1, MagicValues.BACKPACK_STYLE_NAME_DEFAULT, null, -1, null).make();
guiBuilder.addButton(new GuiButton(item, (player, clickType, cursor) -> { player.performCommand(setCommandBase + MagicValues.BACKPACK_STYLE_NAME_DEFAULT); player.closeInventory(); }));
//endregion
//region set disable button
if(allowPlayerDisable)
{
item = new ItemStack(Material.BARRIER);
guiBuilder.addButton(new GuiButton(item, (player, clickType, cursor) -> { player.performCommand(setCommandBase + "none"); player.closeInventory(); }));
guiBuilder.addButton(new GuiButton(item, (player, clickType, cursor) -> { player.performCommand(setCommandBase + MagicValues.BACKPACK_STYLE_NAME_DISABLED); player.closeInventory(); }));
}
//endregion
return guiBuilder.build();

View File

@ -22,6 +22,7 @@
import at.pcgamingfreaks.Minepacks.Bukkit.API.Backpack;
import at.pcgamingfreaks.Minepacks.Bukkit.ExtendedAPI.MinepacksPlayerExtended;
import at.pcgamingfreaks.Minepacks.Bukkit.Item.ItemConfig;
import at.pcgamingfreaks.Minepacks.Bukkit.MagicValues;
import at.pcgamingfreaks.UUIDConverter;
import org.bukkit.Bukkit;
@ -43,7 +44,7 @@ public class MinepacksPlayerData implements MinepacksPlayerExtended, ICacheableP
private final @NotNull UUID uuid;
private final int hash;
@Getter private final @NotNull OfflinePlayer player;
@Getter private String backpackStyleName = "default";
@Getter private String backpackStyleName = MagicValues.BACKPACK_STYLE_NAME_DEFAULT;
private ItemConfig backpackStyle = null;
@Getter @Setter private Backpack backpack = null;
@Getter @Setter private Object databaseKey = null;
@ -116,16 +117,16 @@ public boolean canBeUncached()
@Override
public void setBackpackStyle(@NotNull String style)
{
if(style.equals("none"))
if(style.equals(MagicValues.BACKPACK_STYLE_NAME_DISABLED))
{
backpackStyleName = style;
backpackStyle = null;
}
else
{
if(style.equals("default") || !BackpacksConfig.getInstance().getValidShortcutStyles().contains(style))
if(style.equals(MagicValues.BACKPACK_STYLE_NAME_DEFAULT) || !BackpacksConfig.getInstance().getValidShortcutStyles().contains(style))
{
backpackStyleName = "default";
backpackStyleName = MagicValues.BACKPACK_STYLE_NAME_DEFAULT;
style = BackpacksConfig.getInstance().getDefaultBackpackItem();
}
else backpackStyleName = style;

View File

@ -20,4 +20,6 @@
public class MagicValues
{
public static final String MIN_PCGF_PLUGIN_LIB_VERSION = "1.0.30-SNAPSHOT";
public static final String BACKPACK_STYLE_NAME_DEFAULT = "default";
public static final String BACKPACK_STYLE_NAME_DISABLED = "none";
}