diff --git a/src/main/java/ca/tweetzy/skulls/guis/MainGUI.java b/src/main/java/ca/tweetzy/skulls/guis/MainGUI.java index 238f382..b95c006 100644 --- a/src/main/java/ca/tweetzy/skulls/guis/MainGUI.java +++ b/src/main/java/ca/tweetzy/skulls/guis/MainGUI.java @@ -27,6 +27,7 @@ import ca.tweetzy.skulls.Skulls; import ca.tweetzy.skulls.api.enums.BaseCategory; import ca.tweetzy.skulls.api.enums.ViewMode; +import ca.tweetzy.skulls.api.interfaces.Skull; import ca.tweetzy.skulls.guis.abstraction.SkullsBaseGUI; import ca.tweetzy.skulls.model.SkullItem; import ca.tweetzy.skulls.model.StringHelper; @@ -115,6 +116,34 @@ public boolean onResult(String string) { click.manager.showGUI(click.player, new PlayerHeadGUI(this, Skulls.getPlayerManager().findOrCreate(click.player))); }); + if (Settings.RANDOM_HEAD_BUTTON_ENABLED.getBoolean()) + setButton(Settings.GUI_MAIN_ITEMS_RANDOM_HEAD_SLOT.getInt(), QuickItem.of(SkullItem.get("skulls:5171")) + .name(TranslationManager.string(Translations.GUI_MAIN_ITEMS_RANDOM_HEAD_NAME)) + .lore(TranslationManager.list(Translations.GUI_MAIN_ITEMS_RANDOM_HEAD_LORE, "price", String.format("%,.2f", Settings.RANDOM_HEAD_BUTTON_PRICE.getDouble()))) + .make(), click -> { + + if (!Skulls.getPlayerManager().playerCanClaim(player)) { + return; + } + + final double price = player.hasPermission("skulls.freeskulls") ? 0 : Settings.RANDOM_HEAD_BUTTON_PRICE.getDouble(); + final Skull skull = Skulls.getSkullManager().getRandomAllowedSkull(click.player); + + if (price <= 0) { + player.getInventory().addItem(skull.getItemStack()); + Common.tell(player, TranslationManager.string(Translations.RECEIVED_RANDOM_SKULL, "skull_name", skull.getName())); return; + } + + if (!Skulls.getEconomyManager().has(player, price)) { + Common.tell(player, TranslationManager.string(Translations.NO_MONEY)); + return; + } + + Skulls.getEconomyManager().withdraw(player, price); + player.getInventory().addItem(skull.getItemStack()); + Common.tell(player, TranslationManager.string(Translations.RECEIVED_RANDOM_SKULL, "skull_name", skull.getName())); + }); + setButton(Settings.GUI_MAIN_ITEMS_FAVOURITES_SLOT.getInt(), QuickItem.of(SkullItem.get("skulls:39696")) .name(TranslationManager.string(Translations.GUI_MAIN_ITEMS_FAVOURITES_NAME)) .lore(TranslationManager.list(Translations.GUI_MAIN_ITEMS_FAVOURITES_LORE)) diff --git a/src/main/java/ca/tweetzy/skulls/manager/SkullManager.java b/src/main/java/ca/tweetzy/skulls/manager/SkullManager.java index 5cd77b4..768dfb8 100644 --- a/src/main/java/ca/tweetzy/skulls/manager/SkullManager.java +++ b/src/main/java/ca/tweetzy/skulls/manager/SkullManager.java @@ -35,6 +35,7 @@ import lombok.Setter; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; @@ -110,7 +111,14 @@ public Skull getRandomSkull() { return enabledSkulls.get(random.nextInt(enabledSkulls.size())); } - public List getSkullsBySearch(Player player, String phrase) { + public Skull getRandomAllowedSkull(Player player) { + final List enabledSkulls = getSkulls().values().stream().filter(skull -> player.hasPermission("skulls.category." + BaseCategory.getById(skull.getCategory()).getId().toLowerCase().replace(" ", "").replace("&", "")) && BaseCategory.getById(skull.getCategory()).isEnabled() && !skull.isBlocked()).toList(); + return enabledSkulls.get(random.nextInt(enabledSkulls.size())); + } + + public List getSkullsBySearch(Player player, String phraseOriginal) { + String phrase = ChatColor.stripColor(phraseOriginal); + int id = -1; if (phrase.startsWith("id:")) { if (NumberUtils.isNumber(phrase.split(":")[1])) { diff --git a/src/main/java/ca/tweetzy/skulls/settings/Settings.java b/src/main/java/ca/tweetzy/skulls/settings/Settings.java index 8b8ca9d..ae5a9eb 100644 --- a/src/main/java/ca/tweetzy/skulls/settings/Settings.java +++ b/src/main/java/ca/tweetzy/skulls/settings/Settings.java @@ -44,6 +44,8 @@ public final class Settings extends FlightSettings { public static final ConfigEntry GENERAL_USAGE_REQUIRES_NO_PERM = create("general usage requires no permission", false, "If true, no permission is required to use except for admin stuff"); public static final ConfigEntry TELL_OP_PATREON_LINK = create("tell ops patron on join", true); public static final ConfigEntry SKULL_TRACKING = create("track skull placement", true, "If disabled skulls will no longer drop in creative"); + public static final ConfigEntry RANDOM_HEAD_BUTTON_ENABLED = create("random head button.enabled", false, "If enabled players can click to receive a random head (only from categories they have access too)"); + public static final ConfigEntry RANDOM_HEAD_BUTTON_PRICE = create("random head button.price", 1.0, "The price for using the random head button"); public static final ConfigEntry CATEGORIES_ALPHABET_ENABLED = create("enabled categories.alphabet", true); public static final ConfigEntry CATEGORIES_ANIMALS_ENABLED = create("enabled categories.animals", true); @@ -57,6 +59,7 @@ public final class Settings extends FlightSettings { public static final ConfigEntry CATEGORIES_PLANTS_ENABLED = create("enabled categories.plants", true); public static final ConfigEntry CATEGORIES_PLAYER_HEADS_ENABLED = create("enabled categories.player heads", false); + public static final ConfigEntry PLAYER_HEAD_NAME = create("player head.name", "&e%player_name%"); public static final ConfigEntry PLAYER_HEAD_DROP = create("player head.drop enabled", true); public static final ConfigEntry PLAYER_HEAD_DROP_CHANCE = create("player head.drop chance", 50); @@ -79,7 +82,7 @@ public final class Settings extends FlightSettings { public static final ConfigEntry GUI_MAIN_ITEMS_SEARCH_SLOT = create("gui.main.items.search.slot", 41, "-1 to disable it"); public static final ConfigEntry GUI_MAIN_ITEMS_CUSTOM_CATEGORIES_SLOT = create("gui.main.items.custom categories.slot", 38, "-1 to disable it"); public static final ConfigEntry GUI_MAIN_ITEMS_PLAYER_HEADS_SLOT = create("gui.main.items.player heads.slot", 39, "-1 to disable it"); - + public static final ConfigEntry GUI_MAIN_ITEMS_RANDOM_HEAD_SLOT = create("gui.main.items.random head.slot", 40, "-1 to disable or turn off completely under 'random head button'"); public static final ConfigEntry GUI_MAIN_ITEMS_ALPHABET_SLOT = create("gui.main.items.alphabet.slot", 11); public static final ConfigEntry GUI_MAIN_ITEMS_ANIMALS_SLOT = create("gui.main.items.animals.slot", 12); diff --git a/src/main/java/ca/tweetzy/skulls/settings/Translations.java b/src/main/java/ca/tweetzy/skulls/settings/Translations.java index c3aeda8..5ff4f81 100644 --- a/src/main/java/ca/tweetzy/skulls/settings/Translations.java +++ b/src/main/java/ca/tweetzy/skulls/settings/Translations.java @@ -40,8 +40,8 @@ public Translations(@NonNull JavaPlugin plugin) { public static final TranslationEntry NO_SKULL_INFO = create("misc.no skull info", "&cCould not determine ID of that skull"); public static final TranslationEntry SKULL_TITLE = create("skull.name", "&e%skull_name%"); public static final TranslationEntry ID_TAKEN = create("misc.id taken", "&cThat category id is already in use!"); - public static final TranslationEntry LOADING = create("misc.loading", "&cPlease wait a bit longer, still loading heads."); public static final TranslationEntry CLAIM_DELAY = create("misc.claim delay", "&cYou can claim another head in &7(&e%time_difference%&7)"); + public static final TranslationEntry RECEIVED_RANDOM_SKULL = create("misc.received random skull", "&aYou received a random skull &F(&E%skull_name%&f)"); public static final TranslationEntry ALPHABET = create("categories.alphabet", "Alphabet"); @@ -174,6 +174,17 @@ public Translations(@NonNull JavaPlugin plugin) { "&e&lClick &8» &7To view your favourites" ); + public static final TranslationEntry GUI_MAIN_ITEMS_RANDOM_HEAD_NAME = create("gui.main.items.random head.name", "&lRandom Head"); + + public static final TranslationEntry GUI_MAIN_ITEMS_RANDOM_HEAD_LORE = create("gui.main.items.random head.lore", + "&7Used to receive a random head from", + "&7a random category that you have access too.", + "", + "&7Cost: &a$%price%", + "", + "&e&lClick &8» &7To receive a random head" + ); + public static final TranslationEntry GUI_MAIN_ITEMS_SEARCH_NAME = create("gui.main.items.search.name", "&lSearch"); public static final TranslationEntry GUI_MAIN_ITEMS_SEARCH_LORE = create("gui.main.items.search.lore",