v0.5.1 - Merged TEST -> MAIN

This commit is contained in:
WildInterloper 2024-03-05 14:57:03 -05:00
parent 0dd883536a
commit e1dfacfe65
7 changed files with 140 additions and 56 deletions

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.4.0</version> <version>0.5.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>NVus_PrisonSetup</name> <name>NVus_PrisonSetup</name>

View File

@ -0,0 +1,61 @@
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.HashMap;
import java.util.Map;
public class ConfigManager {
private final JavaPlugin plugin;
private final Map<String, FileConfiguration> configs;
private final Map<String, File> configFiles;
public ConfigManager(JavaPlugin plugin) {
this.plugin = plugin;
this.configs = new HashMap<>();
this.configFiles = new HashMap<>();
}
public void reloadConfig(String configName) {
File configFile = getConfigFile(configName);
FileConfiguration config = YamlConfiguration.loadConfiguration(configFile);
configs.put(configName, config);
}
public FileConfiguration getConfig(String configName) {
if (!configs.containsKey(configName)) {
reloadConfig(configName);
}
return configs.get(configName);
}
public void saveConfig(String configName) {
FileConfiguration config = getConfig(configName);
File configFile = getConfigFile(configName);
try {
config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
public void saveDefaultConfig(String configName) {
File configFile = getConfigFile(configName);
if (!configFile.exists()) {
plugin.saveResource(configName, false);
plugin.getLogger().info(configName + " has been created.");
}
}
private File getConfigFile(String configName) {
if (!configFiles.containsKey(configName)) {
File configFile = new File(plugin.getDataFolder(), configName);
configFiles.put(configName, configFile);
}
return configFiles.get(configName);
}
}

View File

@ -0,0 +1,38 @@
package me.nvus.nvus_prison_setup.Listeners;
import me.nvus.nvus_prison_setup.PrisonSetup;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
public class BlockListener implements Listener {
private final PrisonSetup plugin;
public BlockListener(PrisonSetup plugin) {
this.plugin = plugin;
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
// Check if the player is a prisoner and auto-pickup is enabled
if (player.hasPermission("nvus.prisoner") && plugin.getConfigManager().getConfig("config.yml").getBoolean("AutoPickup")) {
ItemStack itemStack = new ItemStack(block.getType());
if (player.getInventory().addItem(itemStack).isEmpty()) {
// Inventory has enough space, remove the dropped item
event.setDropItems(false);
} else {
// Inventory is full, drop the item on the ground
block.getWorld().dropItemNaturally(block.getLocation(), itemStack);
player.sendMessage("Your inventory is currently full. The resource has been dropped on the ground!");
}
}
}
}

View File

@ -1,15 +1,14 @@
package me.nvus.nvus_prison_setup.Listeners; package me.nvus.nvus_prison_setup.Listeners;
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
import me.nvus.nvus_prison_setup.PrisonSetup; import me.nvus.nvus_prison_setup.PrisonSetup;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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;
@ -17,10 +16,10 @@ import java.util.List;
public class PlayerItems implements Listener { public class PlayerItems implements Listener {
private final PrisonSetup plugin; private final ConfigManager configManager;
public PlayerItems(PrisonSetup plugin) { public PlayerItems(ConfigManager configManager) {
this.plugin = plugin; this.configManager = configManager;
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
@ -54,41 +53,8 @@ public class PlayerItems implements Listener {
} }
private boolean isBannedItem(Material itemType) { private boolean isBannedItem(Material itemType) {
FileConfiguration config = plugin.getBannedItemsConfig().getConfig(); List<String> bannedItems = configManager.getConfig("banned_items.yml").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());
}
*/
} }

View File

@ -1,41 +1,49 @@
package me.nvus.nvus_prison_setup; package me.nvus.nvus_prison_setup;
import me.nvus.nvus_prison_setup.Configs.BannedItemsConfig; import me.nvus.nvus_prison_setup.Configs.ConfigManager;
import me.nvus.nvus_prison_setup.Listeners.PlayerArmor; import me.nvus.nvus_prison_setup.Listeners.PlayerArmor;
import me.nvus.nvus_prison_setup.Listeners.PlayerItems; import me.nvus.nvus_prison_setup.Listeners.PlayerItems;
import me.nvus.nvus_prison_setup.Listeners.PlayerSpawn; import me.nvus.nvus_prison_setup.Listeners.PlayerSpawn;
import me.nvus.nvus_prison_setup.Listeners.BlockListener;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class PrisonSetup extends JavaPlugin { public final class PrisonSetup extends JavaPlugin {
private BannedItemsConfig bannedItemsConfig; private ConfigManager configManager;
@Override @Override
public void onEnable() { public void onEnable() {
// Initialize the ConfigManager
configManager = new ConfigManager(this);
// Init the BannedItemsConfig // Save the default config if it doesn't exist
bannedItemsConfig = new BannedItemsConfig(this); configManager.saveDefaultConfig("banned_items.yml");
configManager.saveDefaultConfig("config.yml"); // Add this line
// Save banned_items.yml config if it doesn't exist
bannedItemsConfig.saveDefaultConfig();
// Register event listeners
getServer().getPluginManager().registerEvents(new PlayerSpawn(), this); getServer().getPluginManager().registerEvents(new PlayerSpawn(), this);
getServer().getPluginManager().registerEvents(new PlayerArmor(), this); getServer().getPluginManager().registerEvents(new PlayerArmor(), this);
getServer().getPluginManager().registerEvents(new PlayerItems(this), this); getServer().getPluginManager().registerEvents(new PlayerItems(configManager), this);
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!")); getServer().getPluginManager().registerEvents(new BlockListener(this), this);
// Log a success message
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
} }
@Override @Override
public void onDisable() { public void onDisable() {
// Saving config file, just in case it was changed prior to disabling plugin/shutdown? // Save the config when disabling the plugin
bannedItemsConfig.saveConfig(); configManager.saveConfig("config.yml");
configManager.saveConfig("banned_items.yml");
// Log a success message
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&c&lNVus Prison Setup has been successfully disabled!")); getLogger().info(ChatColor.translateAlternateColorCodes('&',"&c&lNVus Prison Setup has been successfully disabled!"));
} }
public BannedItemsConfig getBannedItemsConfig() { public ConfigManager getConfigManager() {
return bannedItemsConfig; return configManager;
} }
} }

View File

@ -7,7 +7,7 @@
# Place Item(s) here that prisoners should never be able to equip in their hands or move into their quickbar # 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 # Remember to give all prisoner ranks/groups the permission ' nvus.prisoner ' and negate that permission for any
# players that are not or no longer considered a prisoner. # players that are not or no longer considered a prisoner.
BannedItems: BannedItems:
- DIAMOND_PICKAXE - DIAMOND_PICKAXE

View File

@ -0,0 +1,11 @@
#======================================================================================#
# NVus PRISON SETUP #
# by never2nv #
# www.FNGnation.net #
# Discord: FNGnation.net/discord #
#======================================================================================#
# Remember to give all prisoner ranks/groups the permission ' nvus.prisoner ' and negate that permission for any
# players that are not or no longer considered a prisoner.
# Should prisoners auto pickup blocks they have mined?
AutoPickup: true