-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implemented Biome Shop - registered /is biomes command - added menu option - added config file - added plugin messages for biomes & co. - basically a carbon copy of IridiumTeams shop, localized for IridiumSkyblock * Changes * Remove DI * Early Return Pattern * Cleanup * More Cleanup * Added TabComplete * Inventory Changes * Fixed Issues with island permissions * Changed configs --------- Co-authored-by: Peaches_MLG <[email protected]>
- Loading branch information
1 parent
3a90628
commit e0e0d4c
Showing
12 changed files
with
526 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.iridium.iridiumskyblock.commands; | ||
|
||
import com.iridium.iridiumcore.utils.StringUtils; | ||
import com.iridium.iridiumskyblock.IridiumSkyblock; | ||
import com.iridium.iridiumskyblock.database.Island; | ||
import com.iridium.iridiumskyblock.database.User; | ||
import com.iridium.iridiumskyblock.gui.BiomeCategoryGUI; | ||
import com.iridium.iridiumskyblock.gui.BiomeOverviewGUI; | ||
import com.iridium.iridiumteams.IridiumTeams; | ||
import com.iridium.iridiumteams.commands.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class BiomeCommand extends Command<Island, User> { | ||
|
||
public BiomeCommand() { | ||
super(Collections.singletonList("biomes"), "Refresh your Island Biome", "%prefix% &7/is biomes <biome>", "", 10); | ||
} | ||
|
||
@Override | ||
public boolean execute(User user, Island island, String[] args, IridiumTeams<Island, User> iridiumTeams) { | ||
Player player = user.getPlayer(); | ||
if (args.length == 0) { | ||
player.openInventory(new BiomeOverviewGUI(player.getOpenInventory().getTopInventory()).getInventory()); | ||
return false; | ||
} else { | ||
Optional<String> categoryName = getCategoryName(String.join(" ", args)); | ||
|
||
if (!categoryName.isPresent()) { | ||
player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noBiomeCategory | ||
.replace("%prefix%", iridiumTeams.getConfiguration().prefix) | ||
)); | ||
return false; | ||
} | ||
|
||
player.openInventory(new BiomeCategoryGUI(categoryName.get(), player.getOpenInventory().getTopInventory()).getInventory()); | ||
return false; | ||
} | ||
} | ||
|
||
private Optional<String> getCategoryName(String name) { | ||
for (String category : IridiumSkyblock.getInstance().getBiomes().categories.keySet()) { | ||
if (category.equalsIgnoreCase(name)) { | ||
return Optional.of(category); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender commandSender, String[] args, IridiumTeams<Island, User> iridiumTeams) { | ||
return new ArrayList<>(IridiumSkyblock.getInstance().getBiomes().categories.keySet()); | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
src/main/java/com/iridium/iridiumskyblock/configs/Biomes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package com.iridium.iridiumskyblock.configs; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.iridium.iridiumcore.Item; | ||
import com.iridium.iridiumcore.dependencies.fasterxml.annotation.JsonIgnore; | ||
import com.iridium.iridiumcore.dependencies.xseries.XBiome; | ||
import com.iridium.iridiumcore.dependencies.xseries.XMaterial; | ||
import com.iridium.iridiumcore.dependencies.xseries.XSound; | ||
import lombok.AllArgsConstructor; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.*; | ||
|
||
public class Biomes { | ||
|
||
public Map<String, BiomeCategory> categories = ImmutableMap.<String, BiomeCategory>builder() | ||
.put("Overworld", new BiomeCategory(new Item(XMaterial.GRASS_BLOCK, 11, 1, "&9&lOverworld", Collections.emptyList()), 27)) | ||
.put("Nether", new BiomeCategory(new Item(XMaterial.CRIMSON_NYLIUM, 13, 1, "&9&lNether", Collections.emptyList()), 27)) | ||
.put("End", new BiomeCategory(new Item(XMaterial.END_STONE, 15, 1, "&9&lEnd", Collections.emptyList()), 27)) | ||
.build(); | ||
public Map<String, List<BiomeItem>> items = ImmutableMap.<String, List<BiomeItem>>builder() | ||
.put("Overworld", Arrays.asList( | ||
new BiomeItem( | ||
"&9&lPlains", | ||
XMaterial.GRASS_BLOCK, | ||
XBiome.PLAINS, | ||
1, | ||
11, | ||
new Cost(100, new HashMap<>()) | ||
), | ||
new BiomeItem( | ||
"&9&lSnowy Plains", | ||
XMaterial.SNOW_BLOCK, | ||
XBiome.SNOWY_PLAINS, | ||
1, | ||
13, | ||
new Cost(50, new HashMap<>()) | ||
), | ||
new BiomeItem( | ||
"&9&lSavanna", | ||
XMaterial.TALL_GRASS, | ||
XBiome.SAVANNA, | ||
1, | ||
15, | ||
new Cost(100, new HashMap<>()) | ||
) | ||
)) | ||
.put("Nether", Arrays.asList( | ||
new BiomeItem( | ||
"&9&lNether Wastes", | ||
XMaterial.NETHERRACK, | ||
XBiome.NETHER_WASTES, | ||
1, | ||
11, | ||
new Cost(50, new HashMap<>()) | ||
), | ||
new BiomeItem( | ||
"&9&lCrimson Forest", | ||
XMaterial.CRIMSON_NYLIUM, | ||
XBiome.CRIMSON_FOREST, | ||
1, | ||
13, | ||
new Cost(1000, new HashMap<>()) | ||
), | ||
new BiomeItem( | ||
"&9&lWarped Forest", | ||
XMaterial.WARPED_NYLIUM, | ||
XBiome.WARPED_FOREST, | ||
1, | ||
15, | ||
new Cost(100, new HashMap<>()) | ||
) | ||
) | ||
) | ||
.put("End", Arrays.asList( | ||
new BiomeItem( | ||
"&9&lTHE END", | ||
XMaterial.END_STONE, | ||
XBiome.THE_END, | ||
1, | ||
11, | ||
new Cost(100, new HashMap<>()) | ||
), | ||
new BiomeItem( | ||
"&9&lEnd Highlands", | ||
XMaterial.PURPUR_BLOCK, | ||
XBiome.END_HIGHLANDS, | ||
1, | ||
13, | ||
new Cost(150, new HashMap<>()) | ||
), | ||
new BiomeItem( | ||
"&9&lEnd Barrens", | ||
XMaterial.ENDER_EYE, | ||
XBiome.END_BARRENS, | ||
1, | ||
15, | ||
new Cost(150, new HashMap<>()) | ||
) | ||
) | ||
) | ||
.build(); | ||
public String buyPriceLore = "&aBuy Price: $%vault_cost%"; | ||
public String notPurchasableLore = "&cThis item cannot be purchased!"; | ||
public boolean abbreviatePrices = true; | ||
public XSound failSound = XSound.BLOCK_ANVIL_LAND; | ||
public XSound successSound = XSound.ENTITY_PLAYER_LEVELUP; | ||
public List<String> biomeItemLore = Arrays.asList( | ||
"&9&l[!] " + "&9Left-Click to Purchase" | ||
); | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class BiomeCategory { | ||
public Item item; | ||
public int inventorySize; | ||
} | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class BiomeItem { | ||
public String name; | ||
public XMaterial type; | ||
public XBiome biome; | ||
public List<String> lore; | ||
public int defaultAmount; | ||
public int slot; | ||
public int page; | ||
public Cost buyCost; | ||
|
||
public BiomeItem(String name, XMaterial type, XBiome biome, int defaultAmount, int slot, Cost buyCost) { | ||
this.name = name; | ||
this.type = type; | ||
this.biome = biome; | ||
this.lore = Collections.emptyList(); | ||
this.defaultAmount = defaultAmount; | ||
this.slot = slot; | ||
this.page = 1; | ||
this.buyCost = buyCost; | ||
} | ||
} | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class Cost { | ||
public double money; | ||
public Map<String, Double> bankItems; | ||
|
||
@JsonIgnore | ||
public boolean canPurchase() { | ||
return money > 0 || bankItems.values().stream().anyMatch(value -> value > 0); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/java/com/iridium/iridiumskyblock/gui/BiomeCategoryGUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.iridium.iridiumskyblock.gui; | ||
|
||
import com.iridium.iridiumcore.gui.BackGUI; | ||
import com.iridium.iridiumcore.utils.Placeholder; | ||
import com.iridium.iridiumcore.utils.StringUtils; | ||
import com.iridium.iridiumskyblock.IridiumSkyblock; | ||
import com.iridium.iridiumskyblock.configs.Biomes; | ||
import com.iridium.iridiumteams.configs.inventories.NoItemGUI; | ||
import lombok.Getter; | ||
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.*; | ||
|
||
public class BiomeCategoryGUI extends BackGUI { | ||
|
||
@Getter | ||
private final String categoryName; | ||
private final Biomes.BiomeCategory biomeCategory; | ||
|
||
public BiomeCategoryGUI(String categoryName, Inventory previousInventory) { | ||
super(IridiumSkyblock.getInstance().getInventories().biomeCategoryGUI.background, previousInventory, IridiumSkyblock.getInstance().getInventories().backButton); | ||
this.categoryName = categoryName; | ||
this.biomeCategory = IridiumSkyblock.getInstance().getBiomes().categories.get(categoryName); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Inventory getInventory() { | ||
NoItemGUI biomeCategoryGUI = IridiumSkyblock.getInstance().getInventories().biomeCategoryGUI; | ||
Inventory inventory = Bukkit.createInventory(this, biomeCategory.inventorySize, StringUtils.color(biomeCategoryGUI.title.replace("%biome_category_name%", categoryName))); | ||
addContent(inventory); | ||
return inventory; | ||
} | ||
|
||
@Override | ||
public void addContent(Inventory inventory) { | ||
super.addContent(inventory); | ||
|
||
if (!IridiumSkyblock.getInstance().getBiomes().items.containsKey(categoryName)) { | ||
IridiumSkyblock.getInstance().getLogger().warning("Biome Category " + categoryName + " Is not configured with any items!"); | ||
return; | ||
} | ||
for (Biomes.BiomeItem biomeItem : IridiumSkyblock.getInstance().getBiomes().items.get(categoryName)) { | ||
ItemStack itemStack = biomeItem.type.parseItem(); | ||
ItemMeta itemMeta = itemStack.getItemMeta(); | ||
|
||
itemStack.setAmount(biomeItem.defaultAmount); | ||
itemMeta.setDisplayName(StringUtils.color(biomeItem.name)); | ||
itemMeta.setLore(getBiomeLore(biomeItem)); | ||
|
||
itemStack.setItemMeta(itemMeta); | ||
inventory.setItem(biomeItem.slot, itemStack); | ||
} | ||
} | ||
|
||
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("vault_cost", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(item.buyCost.money)) | ||
)); | ||
for (Map.Entry<String, Double> bankItem : item.buyCost.bankItems.entrySet()) { | ||
placeholders.add(new Placeholder(bankItem.getKey() + "_cost", IridiumSkyblock.getInstance().getBiomeManager().formatPrice(bankItem.getValue()))); | ||
} | ||
return placeholders; | ||
} | ||
|
||
private List<String> getBiomeLore(Biomes.BiomeItem item) { | ||
List<String> lore = item.lore == null ? new ArrayList<>() : new ArrayList<>(StringUtils.color(item.lore)); | ||
List<Placeholder> placeholders = getBiomeLorePlaceholders(item); | ||
|
||
if (item.buyCost.canPurchase()) { | ||
lore.add(IridiumSkyblock.getInstance().getBiomes().buyPriceLore); | ||
} else { | ||
lore.add(IridiumSkyblock.getInstance().getBiomes().notPurchasableLore); | ||
} | ||
|
||
lore.addAll(IridiumSkyblock.getInstance().getBiomes().biomeItemLore); | ||
|
||
return StringUtils.color(StringUtils.processMultiplePlaceholders(lore, placeholders)); | ||
} | ||
|
||
@Override | ||
public void onInventoryClick(InventoryClickEvent event) { | ||
super.onInventoryClick(event); | ||
Optional<Biomes.BiomeItem> biomeItem = IridiumSkyblock.getInstance().getBiomes().items.get(categoryName).stream() | ||
.filter(item -> item.slot == event.getSlot()) | ||
.findAny(); | ||
|
||
if (!biomeItem.isPresent()) { | ||
return; | ||
} | ||
|
||
Player player = (Player) event.getWhoClicked(); | ||
if (event.isLeftClick() && biomeItem.get().buyCost.canPurchase()) { | ||
IridiumSkyblock.getInstance().getBiomeManager().buy(player, biomeItem.get()); | ||
player.closeInventory(); | ||
} else { | ||
IridiumSkyblock.getInstance().getBiomes().failSound.play(player); | ||
} | ||
} | ||
} |
Oops, something went wrong.