Skip to content

Commit

Permalink
Fixed startup error and added RANDOM RarityType for random item.
Browse files Browse the repository at this point in the history
  • Loading branch information
IamTheDefender committed Mar 20, 2023
1 parent 2070c2f commit 0d1fad1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@
</dependency>
<dependency>
<groupId>com.github.hakan-krgn.hCore</groupId>
<artifactId>bukkit-primary</artifactId>
<version>0.6.9.6</version>
<artifactId>hCore-bukkit</artifactId>
<version>0.7.0.3</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package me.defender.cosmetics.api.category.shopkeeperskins.items;

import me.defender.cosmetics.Cosmetics;
import me.defender.cosmetics.api.category.shopkeeperskins.ShopKeeperSkin;
import me.defender.cosmetics.api.enums.CosmeticsType;
import me.defender.cosmetics.api.enums.FieldsType;
import me.defender.cosmetics.api.enums.RarityType;
import me.defender.cosmetics.api.util.StartupUtils;
import me.defender.cosmetics.api.util.StringUtils;
import me.defender.cosmetics.api.configuration.ConfigManager;
import me.defender.cosmetics.api.category.shopkeeperskins.utils.ShopKeeperSkinsUtils;
Expand All @@ -11,7 +14,9 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ShopKeeperItems {

Expand Down Expand Up @@ -62,7 +67,17 @@ public RarityType getRarity() {

@Override
public void execute(Player player, Location shopLocation, Location upgradeLocation) {
ShopKeeperSkinsUtils.spawnShopKeeperNPC(player,shopLocation, upgradeLocation);
if (getField(FieldsType.RARITY, player) == RarityType.RANDOM){
List<ShopKeeperSkin> shopKeeperSkins = new ArrayList<>();
for (ShopKeeperSkin shopKeeperSkin : StartupUtils.shopKeeperSkinList) {
if(player.hasPermission(CosmeticsType.ShopKeeperSkin.getPermissionFormat() + "." + shopKeeperSkin.getIdentifier())){
shopKeeperSkins.add(shopKeeperSkin);
}
}
shopKeeperSkins.get(new Random().nextInt(shopKeeperSkins.size())).execute(player, shopLocation, upgradeLocation);
return;
}
ShopKeeperSkinsUtils.spawnShopKeeperNPC(player, shopLocation, upgradeLocation);
}
};
shopKeeperSkin.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public enum RarityType {
NONE(ChatColor.GREEN),
RANDOM(ChatColor.GREEN),
COMMON(ChatColor.GREEN),
RARE(ChatColor.AQUA),
EPIC(ChatColor.DARK_PURPLE),
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/me/defender/cosmetics/api/util/StartupUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,7 @@ public static void createFolders() {
* in the folder and remove the temp.zip.
*/
public static void downloadGlyphs() {

File folder = new File(Utility.plugin().getDataFolder().getPath() + "/Glyphs");
String[] filesInFolder = folder.list();
if(filesInFolder.length == 0){
return;
}

if (!folder.exists()) {
folder.mkdirs();
}
Expand All @@ -144,6 +138,10 @@ public static void downloadGlyphs() {
if (tempFile.exists()) {
tempFile.delete();
}
String[] filesInFolder = folder.list();
if(filesInFolder != null && filesInFolder.length == 0){
return;
}
try {
Cosmetics.downloadFile(new URL("https://dl.dropboxusercontent.com/s/ione3f01k1la6e8/Glyphs.zip"), temp);
} catch (IOException e) {
Expand Down Expand Up @@ -237,6 +235,7 @@ public static void loadCosmetics(){
new pigmissile().register();
new squidmissile().register();
new theif().register();
new random().register();

//Items From Config
new DeathCryItems().registerConfigItems();
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/me/defender/cosmetics/menu/CategoryMenu.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.defender.cosmetics.menu;

import com.andrei1058.bedwars.BedWars;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import com.hakan.core.HCore;
import com.hakan.core.ui.inventory.InventoryGui;
Expand Down Expand Up @@ -135,6 +136,7 @@ public boolean isFull(Inventory inventory){

public void addItemsAccordingToRarity(Map<ClickableItem, RarityType> rarityMap){
List<ClickableItem> noneItems = new ArrayList<>();
List<ClickableItem> randomItems = new ArrayList<>();
List<ClickableItem> commonItems = new ArrayList<>();
List<ClickableItem> rareItems = new ArrayList<>();
List<ClickableItem> epicItems = new ArrayList<>();
Expand All @@ -147,6 +149,9 @@ public void addItemsAccordingToRarity(Map<ClickableItem, RarityType> rarityMap){
case NONE:
noneItems.add(item);
break;
case RANDOM:
randomItems.add(item);
break;
case COMMON:
commonItems.add(item);
break;
Expand All @@ -162,6 +167,7 @@ public void addItemsAccordingToRarity(Map<ClickableItem, RarityType> rarityMap){
}
}
noneItems.sort(Comparator.comparing((ClickableItem item) -> ChatColor.stripColor(item.getItem().getItemMeta().getDisplayName())));
randomItems.sort(Comparator.comparing((ClickableItem item) -> ChatColor.stripColor(item.getItem().getItemMeta().getDisplayName())));
commonItems.sort(Comparator.comparing((ClickableItem item) -> ChatColor.stripColor(item.getItem().getItemMeta().getDisplayName())));
rareItems.sort(Comparator.comparing((ClickableItem item) -> ChatColor.stripColor(item.getItem().getItemMeta().getDisplayName())));
epicItems.sort(Comparator.comparing((ClickableItem item) -> ChatColor.stripColor(item.getItem().getItemMeta().getDisplayName())));
Expand All @@ -175,6 +181,12 @@ public void addItemsAccordingToRarity(Map<ClickableItem, RarityType> rarityMap){
}
}

for (ClickableItem clickableItem : randomItems) {
if(!isFull(toInventory())) {
super.setItem(findFirstEmptySlot(toInventory()), clickableItem);
}
}

for (ClickableItem clickableItem : commonItems) {
if(!isFull(toInventory())) {
super.setItem(findFirstEmptySlot(toInventory()), clickableItem);
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/ShopKeeperSkins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ shopkeeper-skins:
item: "BARRIER:0"
entity-type: "VILLAGER"
rarity: NONE

random:
price: 0
item: "ENDER_CHEST:0"
rarity: RANDOM

skeleton:
price: 5000
Expand Down

0 comments on commit 0d1fad1

Please sign in to comment.