v0.5.1 - Merged TEST -> MAIN
This commit is contained in:
parent
0dd883536a
commit
e1dfacfe65
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<version>0.4.0</version>
|
||||
<version>0.5.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>NVus_PrisonSetup</name>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,14 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
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.inventory.InventoryType;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
@ -17,10 +16,10 @@ import java.util.List;
|
|||
|
||||
public class PlayerItems implements Listener {
|
||||
|
||||
private final PrisonSetup plugin;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public PlayerItems(PrisonSetup plugin) {
|
||||
this.plugin = plugin;
|
||||
public PlayerItems(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
|
@ -54,41 +53,8 @@ public class PlayerItems implements Listener {
|
|||
}
|
||||
|
||||
private boolean isBannedItem(Material itemType) {
|
||||
FileConfiguration config = plugin.getBannedItemsConfig().getConfig();
|
||||
List<String> bannedItems = config.getStringList("BannedItems");
|
||||
List<String> bannedItems = configManager.getConfig("banned_items.yml").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());
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
@ -1,41 +1,49 @@
|
|||
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.PlayerItems;
|
||||
import me.nvus.nvus_prison_setup.Listeners.PlayerSpawn;
|
||||
import me.nvus.nvus_prison_setup.Listeners.BlockListener;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class PrisonSetup extends JavaPlugin {
|
||||
|
||||
private BannedItemsConfig bannedItemsConfig;
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Initialize the ConfigManager
|
||||
configManager = new ConfigManager(this);
|
||||
|
||||
// Init the BannedItemsConfig
|
||||
bannedItemsConfig = new BannedItemsConfig(this);
|
||||
|
||||
// Save banned_items.yml config if it doesn't exist
|
||||
bannedItemsConfig.saveDefaultConfig();
|
||||
// Save the default config if it doesn't exist
|
||||
configManager.saveDefaultConfig("banned_items.yml");
|
||||
configManager.saveDefaultConfig("config.yml"); // Add this line
|
||||
|
||||
// Register event listeners
|
||||
getServer().getPluginManager().registerEvents(new PlayerSpawn(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerArmor(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerItems(this), this);
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
|
||||
getServer().getPluginManager().registerEvents(new PlayerItems(configManager), this);
|
||||
getServer().getPluginManager().registerEvents(new BlockListener(this), this);
|
||||
|
||||
|
||||
// Log a success message
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Saving config file, just in case it was changed prior to disabling plugin/shutdown?
|
||||
bannedItemsConfig.saveConfig();
|
||||
// Save the config when disabling the plugin
|
||||
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!"));
|
||||
}
|
||||
|
||||
public BannedItemsConfig getBannedItemsConfig() {
|
||||
return bannedItemsConfig;
|
||||
public ConfigManager getConfigManager() {
|
||||
return configManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
# 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.
|
||||
BannedItems:
|
||||
- DIAMOND_PICKAXE
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue