v0.2.3 - Default banned_items.yml config file doesn't generate properly. Investigating now.
This commit is contained in:
parent
cc09b1098b
commit
0d4a234483
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<version>0.1.9-SNAPSHOT</version>
|
||||
<version>0.2.3-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>PrisonSetup</name>
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package me.nvus.nvus_prison_setup.Configs;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class BannedItemsConfig {
|
||||
private final JavaPlugin plugin;
|
||||
private FileConfiguration config;
|
||||
private File configFile;
|
||||
|
||||
public BannedItemsConfig(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder(), "banned_items.yml");
|
||||
}
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (config == null) {
|
||||
reloadConfig();
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
if (config == null || configFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getConfig().save(configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (configFile == null) {
|
||||
configFile = new File(plugin.getDataFolder(), "banned_items.yml");
|
||||
}
|
||||
if (!configFile.exists()) {
|
||||
plugin.saveResource("banned_items.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getBannedItems() {
|
||||
return getConfig().getStringList("BannedItems");
|
||||
}
|
||||
}
|
|
@ -26,4 +26,6 @@ public class PlayerArmor implements Listener {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.PrisonSetup;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
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.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerItems implements Listener {
|
||||
|
||||
private final PrisonSetup plugin;
|
||||
|
||||
public PlayerItems(PrisonSetup plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getInventory().getItem(event.getNewSlot());
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
if (player.hasPermission("nvus.prisoner")) {
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package me.nvus.nvus_prison_setup;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.BannedItemsConfig;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerArmor;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerItems;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerSpawn;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -8,17 +10,32 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||
|
||||
public final class PrisonSetup extends JavaPlugin {
|
||||
|
||||
private BannedItemsConfig bannedItemsConfig;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
// Init the BannedItemsConfig
|
||||
bannedItemsConfig = new BannedItemsConfig(this);
|
||||
|
||||
// Save banned_items.yml config if it doesn't exist
|
||||
bannedItemsConfig.saveDefaultConfig();
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerSpawn(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerArmor(), this);
|
||||
getLogger().info(ChatColor.GREEN + "NVus Prison has been enabled successfully!");
|
||||
getServer().getPluginManager().registerEvents(new PlayerItems(this), this);
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
getLogger().info(ChatColor.RED + "NVus Prison has been disabled successfully!");
|
||||
// Saving config file, just in case it was changed prior to disabling plugin/shutdown?
|
||||
bannedItemsConfig.saveConfig();
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&c&lNVus Prison Setup has been successfully disabled!"));
|
||||
}
|
||||
|
||||
public BannedItemsConfig getBannedItemsConfig() {
|
||||
return bannedItemsConfig;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#======================================================================================#
|
||||
# NVus PRISON SETUP #
|
||||
# by never2nv #
|
||||
# www.FNGnation.net #
|
||||
# Discord: FNGnation.net/discord #
|
||||
#======================================================================================#
|
||||
|
||||
|
||||
# Place Item(s) here that prisoners should never be able to equip in their hands or move into their quickbar
|
||||
# Remember to give all prisoner ranks/groups that permission nvus.prisoner and negate that permission for any
|
||||
# players that are not or no longer considered a prisoner.
|
||||
Banned Items:
|
||||
- DIAMOND_PICKAXE
|
||||
- NETHERITE_PICKAXE
|
Loading…
Reference in New Issue