v1.1.8 - Added additional checks to prevent items & armor from being overwritten in players inventories and instead moved when spawning in the prisoner armor and kits etc. Also added assets (buttons)
This commit is contained in:
parent
6822f23dcc
commit
1ef701b022
Binary file not shown.
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>me.NVus</groupId>
|
<groupId>me.NVus</groupId>
|
||||||
<artifactId>NVus_Prison</artifactId>
|
<artifactId>NVus_Prison</artifactId>
|
||||||
<version>1.1.6</version>
|
<version>1.1.8</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>NVus_PrisonSetup</name>
|
<name>NVus_PrisonSetup</name>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -65,44 +66,125 @@ public class KitManager {
|
||||||
|
|
||||||
ItemStack item = new ItemStack(material);
|
ItemStack item = new ItemStack(material);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
// Configure item meta (name, lore, enchantments)...
|
||||||
// Set the display name if available
|
|
||||||
if (itemSpec.containsKey("name")) {
|
if (itemSpec.containsKey("name")) {
|
||||||
String name = ChatColor.translateAlternateColorCodes('&', (String) itemSpec.get("name"));
|
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', (String) itemSpec.get("name")));
|
||||||
meta.setDisplayName(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set lore if available
|
|
||||||
if (itemSpec.containsKey("lore")) {
|
if (itemSpec.containsKey("lore")) {
|
||||||
List<String> lore = new ArrayList<>();
|
List<String> lore = new ArrayList<>();
|
||||||
for (String line : (List<String>) itemSpec.get("lore")) {
|
((List<String>) itemSpec.get("lore")).forEach(line -> lore.add(ChatColor.translateAlternateColorCodes('&', line)));
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', line));
|
|
||||||
}
|
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set enchantments if available
|
|
||||||
if (itemSpec.containsKey("enchantments")) {
|
if (itemSpec.containsKey("enchantments")) {
|
||||||
Map<String, Integer> enchantments = (Map<String, Integer>) itemSpec.get("enchantments");
|
((Map<String, Integer>) itemSpec.get("enchantments")).forEach((enchant, level) -> meta.addEnchant(Enchantment.getByName(enchant.toUpperCase()), level, true));
|
||||||
for (Map.Entry<String, Integer> enchantmentEntry : enchantments.entrySet()) {
|
|
||||||
Enchantment enchantment = Enchantment.getByName(enchantmentEntry.getKey());
|
|
||||||
if (enchantment != null) {
|
|
||||||
meta.addEnchant(enchantment, enchantmentEntry.getValue(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
// Set item in specified quickbar slot, if available
|
|
||||||
if (itemSpec.containsKey("slot")) {
|
if (itemSpec.containsKey("slot")) {
|
||||||
player.getInventory().setItem((Integer) itemSpec.get("slot"), item);
|
int slot = (Integer) itemSpec.get("slot");
|
||||||
|
ItemStack existingItem = player.getInventory().getItem(slot);
|
||||||
|
|
||||||
|
if (existingItem != null && existingItem.getType() != Material.AIR && !isPrisonerKitItem(existingItem)) {
|
||||||
|
moveItemToAvailableSlot(player, existingItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.getInventory().setItem(slot, item);
|
||||||
} else {
|
} else {
|
||||||
player.getInventory().addItem(item);
|
player.getInventory().addItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void moveItemToAvailableSlot(Player player, ItemStack item) {
|
||||||
|
// Attempt to move the existing item to an available slot
|
||||||
|
HashMap<Integer, ItemStack> overflow = player.getInventory().addItem(item);
|
||||||
|
if (!overflow.isEmpty()) {
|
||||||
|
// Check Ender Chest
|
||||||
|
if (player.getEnderChest().firstEmpty() != -1) {
|
||||||
|
player.getEnderChest().addItem(overflow.get(0));
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Your inventory was full, so an item was moved to your Ender Chest.");
|
||||||
|
} else {
|
||||||
|
// Drop the item at the player's location
|
||||||
|
player.getWorld().dropItemNaturally(player.getLocation(), overflow.get(0));
|
||||||
|
player.sendMessage(ChatColor.RED + "Your inventory and Ender Chest were full, so an item was dropped on the ground.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// public void givePrisonerKit(Player player) {
|
||||||
|
// if (!configManager.getBoolean("config.yml", "PrisonerKit", false)) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// FileConfiguration config = configManager.getConfig("config.yml");
|
||||||
|
// List<Map<?, ?>> kitItems = config.getMapList("PrisonerKitItems");
|
||||||
|
//
|
||||||
|
// for (Map<?, ?> itemSpec : kitItems) {
|
||||||
|
// Material material = Material.matchMaterial((String) itemSpec.get("item"));
|
||||||
|
// if (material == null) continue;
|
||||||
|
//
|
||||||
|
// ItemStack item = new ItemStack(material);
|
||||||
|
// ItemMeta meta = item.getItemMeta();
|
||||||
|
//
|
||||||
|
// // Configure item meta (name, lore, enchantments)...
|
||||||
|
// // This part remains the same as in your original method
|
||||||
|
//
|
||||||
|
// item.setItemMeta(meta);
|
||||||
|
//
|
||||||
|
// // Attempt to set the item in the specified slot
|
||||||
|
// if (itemSpec.containsKey("slot")) {
|
||||||
|
// int slot = (Integer) itemSpec.get("slot");
|
||||||
|
// ItemStack existingItem = player.getInventory().getItem(slot);
|
||||||
|
//
|
||||||
|
// // If the slot is occupied, try to find a new place for the existing item
|
||||||
|
// if (existingItem != null && existingItem.getType() != Material.AIR) {
|
||||||
|
// HashMap<Integer, ItemStack> failedItems = player.getInventory().addItem(existingItem);
|
||||||
|
//
|
||||||
|
// // If inventory is full, try ender chest or drop to the ground
|
||||||
|
// if (!failedItems.isEmpty()) {
|
||||||
|
// failedItems.forEach((integer, itemStack) -> {
|
||||||
|
// if (player.getEnderChest().firstEmpty() != -1) {
|
||||||
|
// player.getEnderChest().addItem(itemStack);
|
||||||
|
// player.sendMessage(ChatColor.YELLOW + "Some items were moved to your Ender Chest due to a full inventory.");
|
||||||
|
// } else {
|
||||||
|
// player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
|
||||||
|
// player.sendMessage(ChatColor.RED + "Your inventory and Ender Chest are full. Some items were dropped on the ground.");
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Now we can safely place the kit item in the intended slot
|
||||||
|
// player.getInventory().setItem(slot, item);
|
||||||
|
// } else {
|
||||||
|
// // Slot is empty, just place the item there
|
||||||
|
// player.getInventory().setItem(slot, item);
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// // No specific slot defined, just add to inventory
|
||||||
|
// HashMap<Integer, ItemStack> failedItems = player.getInventory().addItem(item);
|
||||||
|
//
|
||||||
|
// // Handle full inventory as above
|
||||||
|
// if (!failedItems.isEmpty()) {
|
||||||
|
// failedItems.forEach((integer, itemStack) -> {
|
||||||
|
// if (player.getEnderChest().firstEmpty() != -1) {
|
||||||
|
// player.getEnderChest().addItem(itemStack);
|
||||||
|
// player.sendMessage(ChatColor.YELLOW + "Some items were moved to your Ender Chest due to a full inventory.");
|
||||||
|
// } else {
|
||||||
|
// player.getWorld().dropItemNaturally(player.getLocation(), itemStack);
|
||||||
|
// player.sendMessage(ChatColor.RED + "Your inventory and Ender Chest are full. Some items were dropped on the ground.");
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class PlayerArmor implements Listener {
|
public class PlayerArmor implements Listener {
|
||||||
private final ConfigManager configManager;
|
private final ConfigManager configManager;
|
||||||
|
|
||||||
|
@ -27,47 +29,62 @@ public class PlayerArmor implements Listener {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission("nvus.prisoner") && configManager.getConfig("config.yml").getBoolean("PrisonerArmor")) {
|
if (player.hasPermission("nvus.prisoner") && configManager.getConfig("config.yml").getBoolean("PrisonerArmor")) {
|
||||||
PlayerInventory inv = player.getInventory();
|
PlayerInventory inv = player.getInventory();
|
||||||
inv.setArmorContents(new ItemStack[]{
|
ItemStack[] currentArmor = inv.getArmorContents();
|
||||||
createArmor(Material.LEATHER_BOOTS, "Prisoner Boots"),
|
|
||||||
createArmor(Material.LEATHER_LEGGINGS, "Prisoner Leggings"),
|
for (int slot = 0; slot < currentArmor.length; slot++) {
|
||||||
createArmor(Material.LEATHER_CHESTPLATE, "Prisoner Chestplate"),
|
ItemStack armorPiece = currentArmor[slot];
|
||||||
createArmor(Material.LEATHER_HELMET, "Prisoner Helmet")
|
|
||||||
});
|
// Check if current armor piece is not a prisoner armor, if it's null or AIR (empty slot), or if it's already a prisoner armor piece
|
||||||
|
if (armorPiece != null && armorPiece.getType() != Material.AIR && !isPrisonerArmorItem(armorPiece)) {
|
||||||
|
// Move the non-prisoner armor piece safely before replacing
|
||||||
|
moveArmorToAvailableSlot(player, armorPiece, slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// After safely moving existing armor, equip new prisoner armor
|
||||||
|
equipPrisonerArmor(player);
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cPer The Warden: &6&lYou have been equipped with standard issue prisoner armor!"));
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cPer The Warden: &6&lYou have been equipped with standard issue prisoner armor!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||||
|
|
||||||
Player player = (Player) event.getWhoClicked();
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
|
||||||
if (!player.hasPermission("nvus.prisoner")) return;
|
if (!player.hasPermission("nvus.prisoner")) return;
|
||||||
|
|
||||||
if (event.getClickedInventory() != null && (event.getClickedInventory().getType() == InventoryType.PLAYER || event.getClickedInventory().getType() == InventoryType.CRAFTING)) {
|
int slot = event.getSlot();
|
||||||
if (event.getSlotType() == InventoryType.SlotType.ARMOR || isArmorItem(event.getCurrentItem()) || isArmorItem(event.getCursor())) {
|
// Correct the slot checks for the inventory interaction
|
||||||
|
boolean isArmorInteraction = (slot >= 5 && slot <= 8) // Player inventory armor slots (1.8+)
|
||||||
boolean restrictArmor = configManager.getConfig("config.yml").getBoolean("RestrictArmor");
|
|| (event.getClickedInventory() instanceof PlayerInventory && (slot == 39 || slot == 38 || slot == 37 || slot == 36)); // Correct slots for armor
|
||||||
if (restrictArmor) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lPer The Warden: &c You cannot change your armor!"));
|
|
||||||
}
|
|
||||||
// If restrictArmor is false, allows the player to change armor freely.
|
|
||||||
|
|
||||||
|
if (isArmorInteraction && (isPrisonerArmorItem(event.getCurrentItem()) || isPrisonerArmorItem(event.getCursor()))) {
|
||||||
|
boolean restrictArmor = configManager.getConfig("config.yml").getBoolean("RestrictArmor");
|
||||||
|
if (restrictArmor) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lPer The Warden: &c You cannot change your armor!"));
|
||||||
}
|
}
|
||||||
|
// If restrictArmor is false, allows the player to change armor freely.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isArmorSlot(int slot) {
|
||||||
|
// Correct the method to align with how armor slots are identified in an InventoryClickEvent
|
||||||
|
return slot == 39 || slot == 38 || slot == 37 || slot == 36; // The slots for helmet, chestplate, leggings, and boots respectively.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Checks if the given item is a piece of prisoner armor.
|
// Checks if the given item is a piece of prisoner armor.
|
||||||
private boolean isArmorItem(ItemStack item) {
|
private boolean isPrisonerArmorItem(ItemStack item) {
|
||||||
if (item == null) {
|
if (item == null || !item.hasItemMeta()) return false;
|
||||||
return false;
|
|
||||||
}
|
String itemName = item.getItemMeta().getDisplayName();
|
||||||
Material type = item.getType();
|
// Adjust these checks based on how you identify prisoner armor items.
|
||||||
return type == Material.LEATHER_HELMET || type == Material.LEATHER_CHESTPLATE ||
|
return itemName != null && (itemName.contains("Prisoner Boots") || itemName.contains("Prisoner Leggings")
|
||||||
type == Material.LEATHER_LEGGINGS || type == Material.LEATHER_BOOTS ||
|
|| itemName.contains("Prisoner Chestplate") || itemName.contains("Prisoner Helmet"));
|
||||||
// Add checks for other armor materials if prisoners can have those
|
|
||||||
type == Material.CHAINMAIL_BOOTS || type == Material.IRON_HELMET;
|
|
||||||
// We can later add additional armor sets here if we allow customization of what is considered "prisoner armor".
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack createArmor(Material material, String name) {
|
private ItemStack createArmor(Material material, String name) {
|
||||||
|
@ -80,4 +97,37 @@ public class PlayerArmor implements Listener {
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void equipPrisonerArmor(Player player) {
|
||||||
|
ItemStack[] prisonerArmor = new ItemStack[]{
|
||||||
|
createArmor(Material.LEATHER_BOOTS, "Prisoner Boots"),
|
||||||
|
createArmor(Material.LEATHER_LEGGINGS, "Prisoner Leggings"),
|
||||||
|
createArmor(Material.LEATHER_CHESTPLATE, "Prisoner Chestplate"),
|
||||||
|
createArmor(Material.LEATHER_HELMET, "Prisoner Helmet")
|
||||||
|
};
|
||||||
|
player.getInventory().setArmorContents(prisonerArmor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveArmorToAvailableSlot(Player player, ItemStack armorPiece, int armorSlot) {
|
||||||
|
// Try to add the non-prisoner armor piece to the main inventory
|
||||||
|
HashMap<Integer, ItemStack> overflow = player.getInventory().addItem(armorPiece);
|
||||||
|
if (!overflow.isEmpty()) {
|
||||||
|
// Inventory was full, try the Ender Chest next
|
||||||
|
if (player.getEnderChest().firstEmpty() != -1) {
|
||||||
|
player.getEnderChest().addItem(overflow.get(0));
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Your inventory was full, so your " + armorPiece.getType() + " was moved to your Ender Chest.");
|
||||||
|
} else {
|
||||||
|
// Ender Chest was also full, drop the item at the player's location
|
||||||
|
player.getWorld().dropItemNaturally(player.getLocation(), overflow.get(0));
|
||||||
|
player.sendMessage(ChatColor.RED + "Your inventory and Ender Chest were full, so your " + armorPiece.getType() + " was dropped on the ground.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Clear the original armor slot now that we've moved the item
|
||||||
|
player.getInventory().setItem(armorSlot + 36, new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,11 @@ import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class PlayerSpawn implements Listener {
|
public class PlayerSpawn implements Listener {
|
||||||
private final ConfigManager configManager;
|
private final ConfigManager configManager;
|
||||||
|
|
||||||
|
@ -55,51 +58,72 @@ public class PlayerSpawn implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void equipPrisonerArmor(Player player) {
|
private void equipPrisonerArmor(Player player) {
|
||||||
// Create Prisoner Helmet
|
handleNonPrisonerArmorItems(player); // Ensure non-prisoner armor is handled before equipping new armor
|
||||||
ItemStack leatherHelmetPrison = new ItemStack(Material.LEATHER_HELMET);
|
|
||||||
LeatherArmorMeta helmetMeta = (LeatherArmorMeta) leatherHelmetPrison.getItemMeta();
|
|
||||||
if (helmetMeta != null) {
|
|
||||||
helmetMeta.setColor(Color.ORANGE);
|
|
||||||
helmetMeta.setDisplayName(ChatColor.GOLD + "Prisoner Helmet");
|
|
||||||
leatherHelmetPrison.setItemMeta(helmetMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Prisoner Chestplate
|
// Define and equip standard prisoner armor
|
||||||
ItemStack leatherChestplatePrison = new ItemStack(Material.LEATHER_CHESTPLATE);
|
ItemStack[] standardPrisonerArmor = new ItemStack[]{
|
||||||
LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) leatherChestplatePrison.getItemMeta();
|
createArmor(Material.LEATHER_BOOTS, "Prisoner Boots"),
|
||||||
if (chestplateMeta != null) {
|
createArmor(Material.LEATHER_LEGGINGS, "Prisoner Leggings"),
|
||||||
chestplateMeta.setColor(Color.ORANGE);
|
createArmor(Material.LEATHER_CHESTPLATE, "Prisoner Chestplate"),
|
||||||
chestplateMeta.setDisplayName(ChatColor.GOLD + "Prisoner Chestplate");
|
createArmor(Material.LEATHER_HELMET, "Prisoner Helmet")
|
||||||
leatherChestplatePrison.setItemMeta(chestplateMeta);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// Create Prisoner Leggings
|
player.getInventory().setArmorContents(standardPrisonerArmor);
|
||||||
ItemStack leatherLeggingsPrison = new ItemStack(Material.LEATHER_LEGGINGS);
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cPer The Warden: &6&lYou have been equipped with standard issue prisoner armor!"));
|
||||||
LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) leatherLeggingsPrison.getItemMeta();
|
|
||||||
if (leggingsMeta != null) {
|
|
||||||
leggingsMeta.setColor(Color.ORANGE);
|
|
||||||
leggingsMeta.setDisplayName(ChatColor.GOLD + "Prisoner Leggings");
|
|
||||||
leatherLeggingsPrison.setItemMeta(leggingsMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Prisoner Boots
|
|
||||||
ItemStack leatherBootsPrison = new ItemStack(Material.LEATHER_BOOTS);
|
|
||||||
LeatherArmorMeta bootsMeta = (LeatherArmorMeta) leatherBootsPrison.getItemMeta();
|
|
||||||
if (bootsMeta != null) {
|
|
||||||
bootsMeta.setColor(Color.ORANGE);
|
|
||||||
bootsMeta.setDisplayName(ChatColor.GOLD + "Prisoner Boots");
|
|
||||||
leatherBootsPrison.setItemMeta(bootsMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Equip Prisoner Armor
|
|
||||||
player.getInventory().setHelmet(leatherHelmetPrison);
|
|
||||||
player.getInventory().setChestplate(leatherChestplatePrison);
|
|
||||||
player.getInventory().setLeggings(leatherLeggingsPrison);
|
|
||||||
player.getInventory().setBoots(leatherBootsPrison);
|
|
||||||
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lPer The Warden: &6You've been given the default prisoner armor!"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ItemStack createArmor(Material material, String name) {
|
||||||
|
ItemStack item = new ItemStack(material);
|
||||||
|
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(name);
|
||||||
|
meta.setColor(Color.ORANGE); // Set the color for leather armor
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNonPrisonerArmorItems(Player player) {
|
||||||
|
ItemStack[] armorContents = player.getInventory().getArmorContents();
|
||||||
|
|
||||||
|
for (int i = 0; i < armorContents.length; i++) {
|
||||||
|
ItemStack armorPiece = armorContents[i];
|
||||||
|
// Check if the armor piece is not part of the prisoner kit
|
||||||
|
if (armorPiece != null && armorPiece.getType() != Material.AIR && !isPrisonerArmorItem(armorPiece)) {
|
||||||
|
moveArmorToAvailableSlot(player, armorPiece);
|
||||||
|
armorContents[i] = new ItemStack(Material.AIR); // Remove the non-prisoner armor from the armor slot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the player's armor contents after removals
|
||||||
|
player.getInventory().setArmorContents(armorContents);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPrisonerArmorItem(ItemStack item) {
|
||||||
|
if (item == null || !item.hasItemMeta()) return false;
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
String itemName = meta.getDisplayName();
|
||||||
|
// Adjust the check based on your naming convention for prisoner armor
|
||||||
|
return itemName != null && itemName.contains("Prisoner");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveArmorToAvailableSlot(Player player, ItemStack armorPiece) {
|
||||||
|
// Attempt to move the existing armor piece to an available slot
|
||||||
|
HashMap<Integer, ItemStack> overflow = player.getInventory().addItem(armorPiece);
|
||||||
|
if (!overflow.isEmpty()) {
|
||||||
|
// Check Ender Chest
|
||||||
|
if (player.getEnderChest().firstEmpty() != -1) {
|
||||||
|
player.getEnderChest().addItem(overflow.get(0));
|
||||||
|
player.sendMessage(ChatColor.YELLOW + "Your inventory was full, so your armor was moved to your Ender Chest.");
|
||||||
|
} else {
|
||||||
|
// Drop the item at the player's location
|
||||||
|
player.getWorld().dropItemNaturally(player.getLocation(), overflow.get(0));
|
||||||
|
player.sendMessage(ChatColor.RED + "Your inventory and Ender Chest were full, so your armor was dropped on the ground.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Destroy armor upon death etc.
|
// Destroy armor upon death etc.
|
||||||
private void destroyDefaultPrisonerArmor(Player player) {
|
private void destroyDefaultPrisonerArmor(Player player) {
|
||||||
|
|
Loading…
Reference in New Issue