This commit is contained in:
Ajneb97 2024-05-29 08:54:41 -04:00
parent ff9dd28802
commit fb79222c98
3 changed files with 17 additions and 5 deletions

View file

@ -49,7 +49,7 @@ public class KitsManager {
public Kit getKitByName(String name){ public Kit getKitByName(String name){
for(Kit kit : kits){ for(Kit kit : kits){
if(kit.getName().equals(name)){ if(kit.getName().equalsIgnoreCase(name)){
return kit; return kit;
} }
} }
@ -226,7 +226,7 @@ public class KitsManager {
ArrayList<KitItem> items = kit.getItems(); ArrayList<KitItem> items = kit.getItems();
//Check amount of free slots, including auto-armor //Check amount of free slots, including auto-armor
int usedSlots = PlayerUtils.getUsedSlots(player); int usedSlots = PlayerUtils.getUsedSlots(player); //storage contents, 36 slots
int freeSlots = 36-usedSlots; int freeSlots = 36-usedSlots;
int inventoryKitItems = 0; //Items that will be put in the player inventory (not equipment) int inventoryKitItems = 0; //Items that will be put in the player inventory (not equipment)
@ -245,18 +245,22 @@ public class KitsManager {
if((id.contains("_HELMET") || id.contains("PLAYER_HEAD") || id.contains("SKULL_ITEM")) && itemHelmet == null && (playerInventory.getHelmet() == null if((id.contains("_HELMET") || id.contains("PLAYER_HEAD") || id.contains("SKULL_ITEM")) && itemHelmet == null && (playerInventory.getHelmet() == null
|| playerInventory.getHelmet().getType().equals(Material.AIR))){ || playerInventory.getHelmet().getType().equals(Material.AIR))){
itemHelmet = item; itemHelmet = item;
freeSlots++;
continue; continue;
}else if((id.contains("_CHESTPLATE") || id.contains("ELYTRA")) && itemChestplate == null && (playerInventory.getChestplate() == null }else if((id.contains("_CHESTPLATE") || id.contains("ELYTRA")) && itemChestplate == null && (playerInventory.getChestplate() == null
|| playerInventory.getChestplate().getType().equals(Material.AIR))){ || playerInventory.getChestplate().getType().equals(Material.AIR))){
itemChestplate = item; itemChestplate = item;
freeSlots++;
continue; continue;
}else if(id.contains("_LEGGINGS") && itemLeggings == null && (playerInventory.getLeggings() == null }else if(id.contains("_LEGGINGS") && itemLeggings == null && (playerInventory.getLeggings() == null
|| playerInventory.getLeggings().getType().equals(Material.AIR))){ || playerInventory.getLeggings().getType().equals(Material.AIR))){
itemLeggings = item; itemLeggings = item;
freeSlots++;
continue; continue;
}else if(id.contains("_BOOTS") && itemBoots == null && (playerInventory.getBoots() == null }else if(id.contains("_BOOTS") && itemBoots == null && (playerInventory.getBoots() == null
|| playerInventory.getBoots().getType().equals(Material.AIR))){ || playerInventory.getBoots().getType().equals(Material.AIR))){
itemBoots = item; itemBoots = item;
freeSlots++;
continue; continue;
} }
} }
@ -264,6 +268,7 @@ public class KitsManager {
if(item.isOffhand() && itemOffhand == null && (playerInventory.getItemInOffHand() == null if(item.isOffhand() && itemOffhand == null && (playerInventory.getItemInOffHand() == null
|| playerInventory.getItemInOffHand().getType().equals(Material.AIR))){ || playerInventory.getItemInOffHand().getType().equals(Material.AIR))){
itemOffhand = item; itemOffhand = item;
freeSlots++;
continue; continue;
} }
@ -276,7 +281,6 @@ public class KitsManager {
} }
} }
boolean enoughSpace = freeSlots < inventoryKitItems; boolean enoughSpace = freeSlots < inventoryKitItems;
boolean dropItemsIfFullInventory = configFile.getBoolean("drop_items_if_full_inventory"); boolean dropItemsIfFullInventory = configFile.getBoolean("drop_items_if_full_inventory");

View file

@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
public class PlayerUtils { public class PlayerUtils {
@ -33,7 +34,14 @@ public class PlayerUtils {
} }
public static int getUsedSlots(Player player){ public static int getUsedSlots(Player player){
ItemStack[] contents = getAllInventoryContents(player); //ItemStack[] contents = getAllInventoryContents(player);
ItemStack[] contents = null;
if(Bukkit.getVersion().contains("1.8")) {
contents = player.getInventory().getContents();
}else{
contents = player.getInventory().getStorageContents();
}
int usedSlots = 0; int usedSlots = 0;
for(int i=0;i<contents.length;i++) { for(int i=0;i<contents.length;i++) {
if(contents[i] != null && !contents[i].getType().equals(Material.AIR)) { if(contents[i] != null && !contents[i].getType().equals(Material.AIR)) {

View file

@ -1,5 +1,5 @@
main: pk.ajneb97.PlayerKits2 main: pk.ajneb97.PlayerKits2
version: 1.11.2 version: 1.11.3
name: PlayerKits2 name: PlayerKits2
api-version: 1.13 api-version: 1.13
softdepend: [Vault,PlaceholderAPI] softdepend: [Vault,PlaceholderAPI]