Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Island Level Configuration #818

Merged
merged 12 commits into from
Jun 10, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ public boolean execute(User user, Island island, String[] args, IridiumTeams<Isl

Schematics.SchematicConfig schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.get(schematic.get());

if(island.getLevel() < schematicConfig.minLevel) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notHighEnoughLevel
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
.replace("%level%", String.valueOf(schematicConfig.minLevel))));
return false;
}

if (schematicConfig.regenCost.money != 0 || !schematicConfig.regenCost.bankItems.isEmpty()) {
if (!IridiumSkyblock.getInstance().getSchematicManager().buy(player, schematicConfig)) {
return false;
Expand Down
34 changes: 23 additions & 11 deletions src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ public class Biomes {
XBiome.PLAINS,
1,
11,
new Cost(100, new HashMap<>())
new Cost(100, new HashMap<>()),
1
),
new BiomeItem(
"&9&lSnowy Plains",
XMaterial.SNOW_BLOCK,
XBiome.SNOWY_PLAINS,
1,
13,
new Cost(50, new HashMap<>())
new Cost(50, new HashMap<>()),
1
),
new BiomeItem(
"&9&lSavanna",
XMaterial.TALL_GRASS,
XBiome.SAVANNA,
1,
15,
new Cost(100, new HashMap<>())
new Cost(100, new HashMap<>()),
1
)
))
.put("Nether", Arrays.asList(
Expand All @@ -52,23 +55,26 @@ public class Biomes {
XBiome.NETHER_WASTES,
1,
11,
new Cost(50, new HashMap<>())
new Cost(50, new HashMap<>()),
1
),
new BiomeItem(
"&9&lCrimson Forest",
XMaterial.CRIMSON_NYLIUM,
XBiome.CRIMSON_FOREST,
1,
13,
new Cost(1000, new HashMap<>())
new Cost(1000, new HashMap<>()),
1
),
new BiomeItem(
"&9&lWarped Forest",
XMaterial.WARPED_NYLIUM,
XBiome.WARPED_FOREST,
1,
15,
new Cost(100, new HashMap<>())
new Cost(100, new HashMap<>()),
1
)
)
)
Expand All @@ -79,29 +85,33 @@ public class Biomes {
XBiome.THE_END,
1,
11,
new Cost(100, new HashMap<>())
new Cost(100, new HashMap<>()),
1
),
new BiomeItem(
"&9&lEnd Highlands",
XMaterial.PURPUR_BLOCK,
XBiome.END_HIGHLANDS,
1,
13,
new Cost(150, new HashMap<>())
new Cost(150, new HashMap<>()),
1
),
new BiomeItem(
"&9&lEnd Barrens",
XMaterial.ENDER_EYE,
XBiome.END_BARRENS,
1,
15,
new Cost(150, new HashMap<>())
)
new Cost(150, new HashMap<>()),
1
)
)
)
.build();
public String buyPriceLore = "&aBuy Price: $%vault_cost%";
public String notPurchasableLore = "&cThis item cannot be purchased!";
public String levelRequirementLore = "&9[!] &7Must be level %level% to purchase";
public boolean abbreviatePrices = true;
public XSound failSound = XSound.BLOCK_ANVIL_LAND;
public XSound successSound = XSound.ENTITY_PLAYER_LEVELUP;
Expand All @@ -127,8 +137,9 @@ public static class BiomeItem {
public int slot;
public int page;
public Cost buyCost;
public int minLevel;

public BiomeItem(String name, XMaterial type, XBiome biome, int defaultAmount, int slot, Cost buyCost) {
public BiomeItem(String name, XMaterial type, XBiome biome, int defaultAmount, int slot, Cost buyCost, int minLevel) {
this.name = name;
this.type = type;
this.biome = biome;
Expand All @@ -137,6 +148,7 @@ public BiomeItem(String name, XMaterial type, XBiome biome, int defaultAmount, i
this.slot = slot;
this.page = 1;
this.buyCost = buyCost;
this.minLevel = minLevel;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Configuration() {
public boolean clearEnderChestOnRegen = false;
public boolean allowPvPOnIslands = false;
public boolean islandCreateOnJoin = false;
public boolean islandCreationCost = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is going to confuse things even more. I understand there are alot of people asking this in the Discord, but if we want to remove the creation cost, I feel setting the default cost to 0 for everything is a better aproach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was more for the fact that we could allow pricing for creation and regen to be different (as in, when you create the island, it doesn't cost anything, but when you regen, it does) - we could change it to be free but honestly i dont care about those people lol

public boolean spawnOnIsland = false;
public int distance = 151;
public int netherUnlockLevel = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ public Enhancements() {
"&9&lInformation:",
"&9&l * &7Current Level: &9%current_level%",
"&9&l * &7Current Size: &9%size%x%size% Blocks",
"&9&l * &7Upgrade Cost: &9%cost%",
"&9&l * &7Upgrade Cost: &9%vault_cost%, %Crystals_cost% Island Crystals",
"&9&lLevels:",
"&9&l * &7Level 1: &950x50 Blocks",
"&9&l * &7Level 2: &975x75 Blocks",
"&9&l * &7Level 3: &9100x100 Blocks",
"&9&l * &7Level 4: &9125x125 Blocks",
"&9&l * &7Level 5: &9150x150 Blocks",
"",
"&9[!] &7Must be level %minLevel% to purchase",
"&9&l[!] " + "&9Left Click to Purchase Level %next_level%."
)), new ImmutableMap.Builder<Integer, SizeEnhancementData>()
.put(0, new SizeEnhancementData(5, 10000, new ImmutableMap.Builder<String, Double>().put("Crystals", 5.00).build(), 50))
Expand All @@ -63,7 +64,7 @@ public Enhancements() {
"",
"&9&lInformation:",
"&9&l * &7Current Level: &9%current_level%",
"&9&l * &7Upgrade Cost: &9%cost%",
"&9&l * &7Upgrade Cost: &9%vault_cost%, %Crystals_cost% Island Crystals",
"&9&lLevels:",
"&9&l * &7Level 1: &9No Void Teleport",
"&9&l * &7Level 2: &9100% Item Loss",
Expand All @@ -72,6 +73,7 @@ public Enhancements() {
"&9&l * &7Level 5: &925% Item Loss",
"&9&l * &7Level 6: &90% Item Loss",
"",
"&9[!] &7Must be level %minLevel% to purchase",
"&9&l[!] " + "&9Left Click to Purchase Level %next_level%."
)), new ImmutableMap.Builder<Integer, VoidEnhancementData>()
.put(0, new VoidEnhancementData(5, 10000, new ImmutableMap.Builder<String, Double>().put("Crystals", 5.00).build(), true, 0.00))
Expand All @@ -83,8 +85,9 @@ public Enhancements() {
"",
"&9&lInformation:",
"&9&l * &7Current Level: &9%current_level%",
"&9&l * &7Upgrade Cost: &9%cost%",
"&9&l * &7Upgrade Cost: &9%vault_cost%, %Crystals_cost% Island Crystals",
"",
"&9[!] &7Must be level %minLevel% to purchase",
"&9&l[!] " + "&9Left Click to Purchase Level %next_level%."
)), new ImmutableMap.Builder<Integer, GeneratorEnhancementData>()
.put(0, new GeneratorEnhancementData(5, 10000, new ImmutableMap.Builder<String, Double>().put("Crystals", 5.00).build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public class Schematics {

public Map<String, SchematicConfig> schematics = ImmutableMap.<String, SchematicConfig>builder()
.put("desert", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 11, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGY0OTNkZDgwNjUzM2Q5ZDIwZTg0OTUzOTU0MzY1ZjRkMzY5NzA5Y2ViYzlkZGVmMDIyZDFmZDQwZDg2YTY4ZiJ9fX0=", 1, "&9&lDesert Island", Arrays.asList("&7A starter desert island.", "", "&9&l[!] &7Costs $1000")),
new Schematics.Cost(1000, new HashMap<>()), -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT,
new Schematics.Cost(0, new HashMap<>()), 1, -0.5, 89, -0.5, 90, new SchematicWorld(Biome.DESERT,
"desert.schem", 90.0, true
), new SchematicWorld(XMaterial.supports(16) ? Biome.NETHER_WASTES : Biome.valueOf("NETHER"),
"desert_nether.schem", 90.0, true
), new SchematicWorld(Biome.THE_END,
"desert_end.schem", 90.0, true
)))
.put("jungle", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 13, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjgzYWRmNDU2MGRlNDc0MTQwNDA5M2FjNjFjMzNmYjU1NmIzZDllZTUxNDBmNjIwMzYyNTg5ZmRkZWRlZmEyZCJ9fX0=", 1, "&9&lJungle Island", Arrays.asList("&7A starter jungle island.", "", "&9&l[!] &7Costs $1000")),
new Schematics.Cost(1000, new HashMap<>()), 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE,
new Schematics.Cost(0, new HashMap<>()), 1, 1.5, 83, 1.5, 90, new SchematicWorld(Biome.JUNGLE,
"jungle.schem", 90.0, true
), new SchematicWorld(XMaterial.supports(16) ? Biome.NETHER_WASTES : Biome.valueOf("NETHER"),
"jungle_nether.schem", 90.0, true
), new SchematicWorld(Biome.THE_END,
"jungle_end.schem", 90.0, true
)))
.put("mushroom", new SchematicConfig(new Item(XMaterial.PLAYER_HEAD, 15, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWE0NWQxYjQxN2NiZGRjMjE3NjdiMDYwNDRlODk5YjI2NmJmNzhhNjZlMjE4NzZiZTNjMDUxNWFiNTVkNzEifX19", 1, "&9&lMushroom Island", Arrays.asList("&7A starter mushroom island.", "", "&9&l[!] &7Costs $1000")),
new Schematics.Cost(1000, new HashMap<>()), 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS,
new Schematics.Cost(0, new HashMap<>()), 1, 0.5, 89, -0.5, 90, new SchematicWorld(Biome.MUSHROOM_FIELDS,
"mushroom.schem", 90.0, true
), new SchematicWorld(XMaterial.supports(16) ? Biome.NETHER_WASTES : Biome.valueOf("NETHER"),
"mushroom_nether.schem", 90.0, true
Expand All @@ -42,6 +42,9 @@ public class Schematics {
)))
.build();
public boolean abbreviatePrices = true;
public String buyPriceLore = "&9Buy Price: &7%vault_cost%";
public String levelRequirementLore = "&9[!] &7Must be level %level% to purchase";
public String regenDisclaimer = "&9[!] &7Applies to regeneration only";
public XSound failSound = XSound.BLOCK_ANVIL_LAND;
public XSound successSound = XSound.ENTITY_PLAYER_LEVELUP;

Expand All @@ -50,6 +53,7 @@ public class Schematics {
public static class SchematicConfig {
public Item item;
public Cost regenCost;
public int minLevel;
public double xHome;
public double yHome;
public double zHome;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.configs.Biomes;
import com.iridium.iridiumskyblock.configs.Schematics;
import com.iridium.iridiumteams.configs.inventories.NoItemGUI;
import lombok.Getter;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void addContent(Inventory inventory) {

private List<Placeholder> getBiomeLorePlaceholders(Biomes.BiomeItem item) {
List<Placeholder> placeholders = new ArrayList<>(Arrays.asList(
new Placeholder("amount", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(item.defaultAmount)),
new Placeholder("minLevel", String.valueOf(item.minLevel)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need the Amount placeholder anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this allows us to fetch the price of the schematic from the config directly without having to set the lore manually every time

new Placeholder("vault_cost", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(item.buyCost.money))
));
for (Map.Entry<String, Double> bankItem : item.buyCost.bankItems.entrySet()) {
Expand All @@ -80,6 +81,10 @@ private List<String> getBiomeLore(Biomes.BiomeItem item) {
lore.add(IridiumSkyblock.getInstance().getBiomes().notPurchasableLore);
}

if(item.minLevel > 1){
lore.add(IridiumSkyblock.getInstance().getBiomes().levelRequirementLore);
}

lore.addAll(IridiumSkyblock.getInstance().getBiomes().biomeItemLore);

return StringUtils.color(StringUtils.processMultiplePlaceholders(lore, placeholders));
Expand Down
59 changes: 56 additions & 3 deletions src/main/java/com/iridium/iridiumskyblock/gui/SchematicGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
import com.iridium.iridiumcore.gui.BackGUI;
import com.iridium.iridiumcore.utils.InventoryUtils;
import com.iridium.iridiumcore.utils.ItemStackUtils;
import com.iridium.iridiumcore.utils.Placeholder;
import com.iridium.iridiumcore.utils.StringUtils;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.configs.Schematics;
import com.iridium.iridiumskyblock.database.User;
import com.iridium.iridiumteams.bank.BankItem;
import com.iridium.iridiumteams.configs.Shop;
import com.iridium.iridiumteams.configs.inventories.NoItemGUI;
import com.iridium.iridiumteams.database.TeamBank;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.Collections.addAll;

public abstract class SchematicGUI extends BackGUI {

Expand All @@ -39,8 +49,51 @@ public void addContent(Inventory inventory) {
super.addContent(inventory);

for (Map.Entry<String, Schematics.SchematicConfig> entry : IridiumSkyblock.getInstance().getSchematics().schematics.entrySet()) {
inventory.setItem(entry.getValue().item.slot, ItemStackUtils.makeItem(entry.getValue().item));

ItemStack itemStack = ItemStackUtils.makeItem(entry.getValue().item);
ItemMeta itemMeta = itemStack.getItemMeta();

if (itemMeta != null) {
itemMeta.setLore(getSchematicLore(entry.getValue()));

itemStack.setItemMeta(itemMeta);
}

inventory.setItem(entry.getValue().item.slot, itemStack);
}
}

private List<String> getSchematicLore(Schematics.SchematicConfig item) {
List<Placeholder> placeholders = getSchematicLorePlaceholders(item);

List<String> lore = new ArrayList<>(item.item.lore);

if (item.regenCost.canPurchase()) {
lore.add(String.valueOf(IridiumSkyblock.getInstance().getSchematics().buyPriceLore));
}

if (item.minLevel > 1) {
lore.add(IridiumSkyblock.getInstance().getSchematics().levelRequirementLore);
}

if (!IridiumSkyblock.getInstance().getConfiguration().islandCreationCost) {
lore.add(IridiumSkyblock.getInstance().getSchematics().regenDisclaimer);
}

return StringUtils.color(StringUtils.processMultiplePlaceholders(lore, placeholders));
}

private List<Placeholder> getSchematicLorePlaceholders(Schematics.SchematicConfig item) {
List<Placeholder> placeholders = new ArrayList<>(Arrays.asList(
new Placeholder("vault_cost", IridiumSkyblock.getInstance().getSchematicManager().formatPrice(item.regenCost.money)),
new Placeholder("level", String.valueOf(item.minLevel))
));

for (Map.Entry<String, Double> bankItem : item.regenCost.bankItems.entrySet()) {
placeholders.add(new Placeholder(bankItem.getKey() + "_cost", IridiumSkyblock.getInstance().getSchematicManager().formatPrice(bankItem.getValue())));
}

return placeholders;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public void buy(Player player, Biomes.BiomeItem biomeItem) {
Optional<XBiome> biomeOptional = XBiome.matchXBiome(biomeItem.biome.toString());

if (!canPurchase(player, biomeItem)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
));
IridiumSkyblock.getInstance().getBiomes().failSound.play(player);
return;
}
Expand Down Expand Up @@ -78,14 +75,40 @@ private void setBankBalance(Player player, String bankItem, double amount) {
}

private boolean canPurchase(Player player, Biomes.BiomeItem biomeItem) {

if(biomeItem.minLevel > 1) {
User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
Optional<Island> island = IridiumSkyblock.getInstance().getIslandManager().getTeamViaID(user.getTeamID());

if(!island.isPresent()) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().dontHaveTeam
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)));
return false;
}

if(island.get().getLevel() < biomeItem.minLevel) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notHighEnoughLevel
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
.replace("%level%", String.valueOf(biomeItem.minLevel))));
return false;
}
}

double moneyCost = biomeItem.buyCost.money;
Economy economy = IridiumSkyblock.getInstance().getEconomy();
for (String bankItem : biomeItem.buyCost.bankItems.keySet()) {
double cost = biomeItem.buyCost.bankItems.get(bankItem);
if (getBankBalance(player, bankItem) < cost) return false;
}

return moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost;
if(!(moneyCost == 0 || economy != null && economy.getBalance(player) >= moneyCost)) {
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford
.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)
));
return false;
}

return true;
}

private void purchase(Player player, Biomes.BiomeItem biomeItem) {
Expand Down
Loading
Loading