v0.3.1 - Finalizing banned_items.yml and cancelling their events.

This commit is contained in:
WildInterloper 2024-03-05 10:51:09 -05:00
parent 0d4a234483
commit ad81bce92a
5 changed files with 53 additions and 15 deletions

View File

@ -2,5 +2,7 @@ A useful plugin for Minecraft prison servers.\
**PLANNED FEATURES, SO FAR** **PLANNED FEATURES, SO FAR**
- Set newly joined & respawned players in orange leather armor. - Set newly joined & respawned players in orange leather armor.
- Prevent prisoners from equipping new armor and unequipping the prisoner orange leather armor. - Prevent prisoners from equipping new armor and unequipping the prisoner orange leather armor.
- Give newly joined & respawned prisoners with the default prisoner tools. - Prevent prisoners from equipping or moving banned items into their QUICKBAR.
- Main permission to tell a player is a prisoner or not is **nvus.prisoner** - Banned items can be configured in a banned_items.yml file within the plugin directory (PrisonSetup/banned_items.yml)
- Give newly joined & respawned prisoners the default prisoner tools? Maybe, not sure. Might just use a kit plugin for this?
- Main permission to tell a player is a prisoner or not is **nvus.prisoner** this permission should be **NEGATED** for any players that are not or no longer a prisoner, just in case.

View File

@ -6,7 +6,7 @@
<groupId>me.NVus</groupId> <groupId>me.NVus</groupId>
<artifactId>NVus_Prison_Setup</artifactId> <artifactId>NVus_Prison_Setup</artifactId>
<version>0.2.3-SNAPSHOT</version> <version>0.3.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>PrisonSetup</name> <name>PrisonSetup</name>

View File

@ -48,9 +48,11 @@ public class BannedItemsConfig {
} }
if (!configFile.exists()) { if (!configFile.exists()) {
plugin.saveResource("banned_items.yml", false); plugin.saveResource("banned_items.yml", false);
plugin.getLogger().info("banned_items.yml has been created.");
} }
} }
public List<String> getBannedItems() { public List<String> getBannedItems() {
return getConfig().getStringList("BannedItems"); return getConfig().getStringList("BannedItems");
} }

View File

@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -30,31 +31,64 @@ public class PlayerItems implements Listener {
if (item != null && isBannedItem(item.getType())) { if (item != null && isBannedItem(item.getType())) {
if (player.hasPermission("nvus.prisoner")) { if (player.hasPermission("nvus.prisoner")) {
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(ChatColor.RED + "Sorry inmate! You're a prisoner and cannot use this tool!"); player.sendMessage(ChatColor.translateAlternateColorCodes('&',"&c&lSorry inmate! &cYou're a prisoner and cannot use this tool!"));
} }
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if (event.getClickedInventory() != null && event.getClickedInventory().getType() == org.bukkit.event.inventory.InventoryType.PLAYER) {
if (event.getSlotType() == org.bukkit.event.inventory.InventoryType.SlotType.QUICKBAR) {
ItemStack item = event.getCurrentItem();
if (item != null && isBannedItem(item.getType())) {
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
ItemStack clickedItem = event.getCurrentItem();
// Check if the clicked item is a banned item
if (clickedItem != null && isBannedItem(clickedItem.getType())) {
// Check if the player is a prisoner
if (player.hasPermission("nvus.prisoner")) { if (player.hasPermission("nvus.prisoner")) {
// Cancel the event to prevent interaction with banned items
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(ChatColor.RED + "Sorry inmate! You're a prisoner and cannot use this tool!"); player.sendMessage(ChatColor.RED + "Sorry inmate! You're a prisoner and cannot use this tool!");
} }
} }
} }
}
}
private boolean isBannedItem(Material itemType) { private boolean isBannedItem(Material itemType) {
FileConfiguration config = plugin.getBannedItemsConfig().getConfig(); FileConfiguration config = plugin.getBannedItemsConfig().getConfig();
List<String> bannedItems = config.getStringList("BannedItems"); List<String> bannedItems = config.getStringList("BannedItems");
return bannedItems.contains(itemType.toString()); return bannedItems.contains(itemType.toString());
} }
/*
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) {
if (event.getClickedInventory() != null && event.getClickedInventory().getType() == InventoryType.PLAYER) {
if (event.getSlotType() == InventoryType.SlotType.QUICKBAR) {
ItemStack item = event.getCurrentItem();
Player player = (Player) event.getWhoClicked();
// Check if the clicked item is a banned item
if (item != null && isBannedItem(item.getType())) {
// Check if the player is a prisoner
if (player.hasPermission("nvus.prisoner")) {
// Cancel the event to prevent the banned item from being moved to the quickbar
event.setCancelled(true);
player.sendMessage(ChatColor.translateAlternateColorCodes('&',"&c&lSorry inmate! &cYou're a prisoner and cannot use this tool!"));
}
}
}
}
}
private boolean isBannedItem(Material itemType) {
FileConfiguration config = plugin.getBannedItemsConfig().getConfig();
List<String> bannedItems = config.getStringList("BannedItems");
return bannedItems.contains(itemType.toString());
}
*/
} }