From 0d1fad121b39ed278d3cd41e8b54e4850477ef43 Mon Sep 17 00:00:00 2001
From: IamTheDefender <72926871+IamTheDefender@users.noreply.github.com>
Date: Mon, 20 Mar 2023 18:27:24 +0530
Subject: [PATCH] Fixed startup error and added RANDOM RarityType for random
item.
---
pom.xml | 4 ++--
.../shopkeeperskins/items/ShopKeeperItems.java | 17 ++++++++++++++++-
.../cosmetics/api/enums/RarityType.java | 1 +
.../cosmetics/api/util/StartupUtils.java | 11 +++++------
.../defender/cosmetics/menu/CategoryMenu.java | 12 ++++++++++++
src/main/resources/ShopKeeperSkins.yml | 5 +++++
6 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/pom.xml b/pom.xml
index f1dd4f97..117af2c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -145,8 +145,8 @@
com.github.hakan-krgn.hCore
- bukkit-primary
- 0.6.9.6
+ hCore-bukkit
+ 0.7.0.3
me.clip
diff --git a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java
index d4b8116a..5a5d37d7 100644
--- a/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java
+++ b/src/main/java/me/defender/cosmetics/api/category/shopkeeperskins/items/ShopKeeperItems.java
@@ -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;
@@ -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 {
@@ -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 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();
diff --git a/src/main/java/me/defender/cosmetics/api/enums/RarityType.java b/src/main/java/me/defender/cosmetics/api/enums/RarityType.java
index f3a7f6e1..136896a7 100644
--- a/src/main/java/me/defender/cosmetics/api/enums/RarityType.java
+++ b/src/main/java/me/defender/cosmetics/api/enums/RarityType.java
@@ -4,6 +4,7 @@
public enum RarityType {
NONE(ChatColor.GREEN),
+ RANDOM(ChatColor.GREEN),
COMMON(ChatColor.GREEN),
RARE(ChatColor.AQUA),
EPIC(ChatColor.DARK_PURPLE),
diff --git a/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java b/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java
index cdccae89..a004afb4 100644
--- a/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java
+++ b/src/main/java/me/defender/cosmetics/api/util/StartupUtils.java
@@ -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();
}
@@ -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) {
@@ -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();
diff --git a/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java b/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java
index 3b1b0662..c903165e 100644
--- a/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java
+++ b/src/main/java/me/defender/cosmetics/menu/CategoryMenu.java
@@ -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;
@@ -135,6 +136,7 @@ public boolean isFull(Inventory inventory){
public void addItemsAccordingToRarity(Map rarityMap){
List noneItems = new ArrayList<>();
+ List randomItems = new ArrayList<>();
List commonItems = new ArrayList<>();
List rareItems = new ArrayList<>();
List epicItems = new ArrayList<>();
@@ -147,6 +149,9 @@ public void addItemsAccordingToRarity(Map rarityMap){
case NONE:
noneItems.add(item);
break;
+ case RANDOM:
+ randomItems.add(item);
+ break;
case COMMON:
commonItems.add(item);
break;
@@ -162,6 +167,7 @@ public void addItemsAccordingToRarity(Map 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())));
@@ -175,6 +181,12 @@ public void addItemsAccordingToRarity(Map 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);
diff --git a/src/main/resources/ShopKeeperSkins.yml b/src/main/resources/ShopKeeperSkins.yml
index 40efc6f2..b9100fb7 100644
--- a/src/main/resources/ShopKeeperSkins.yml
+++ b/src/main/resources/ShopKeeperSkins.yml
@@ -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