v0.3.1 - Finalizing banned_items.yml and cancelling their events.
This commit is contained in:
parent
0d4a234483
commit
ad81bce92a
|
@ -2,5 +2,7 @@ A useful plugin for Minecraft prison servers.\
|
|||
**PLANNED FEATURES, SO FAR**
|
||||
- Set newly joined & respawned players in 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.
|
||||
- Main permission to tell a player is a prisoner or not is **nvus.prisoner**
|
||||
- Prevent prisoners from equipping or moving banned items into their QUICKBAR.
|
||||
- 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.
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<version>0.2.3-SNAPSHOT</version>
|
||||
<version>0.3.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PrisonSetup</name>
|
||||
|
|
|
@ -48,9 +48,11 @@ public class BannedItemsConfig {
|
|||
}
|
||||
if (!configFile.exists()) {
|
||||
plugin.saveResource("banned_items.yml", false);
|
||||
plugin.getLogger().info("banned_items.yml has been created.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> getBannedItems() {
|
||||
return getConfig().getStringList("BannedItems");
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -30,31 +31,64 @@ public class PlayerItems implements Listener {
|
|||
if (item != null && isBannedItem(item.getType())) {
|
||||
if (player.hasPermission("nvus.prisoner")) {
|
||||
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)
|
||||
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();
|
||||
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")) {
|
||||
// Cancel the event to prevent interaction with banned items
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.RED + "Sorry inmate! You'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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@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());
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue