v0.6.0
- Added AutoSwitch option in config.yml. - Added auto_switch.yml, when AutoSwitch is set to true in the main config it will check what tools server admins want prisoners to autoswitch to and they can even customize what blocks will automatically trigger switching to certain tools.
This commit is contained in:
parent
ec47789a8c
commit
95afbbd069
|
@ -1,3 +1,5 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
|
||||
</content>
|
||||
</component>
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<version>0.5.9</version>
|
||||
<version>0.6.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>NVus_PrisonSetup</name>
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ToolSwitchListener implements Listener {
|
||||
private ConfigManager configManager;
|
||||
|
||||
public ToolSwitchListener(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.LEFT_CLICK_BLOCK) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
FileConfiguration config = configManager.getConfig("config.yml");
|
||||
if (!config.getBoolean("AutoSwitch", true)) return;
|
||||
if (!player.hasPermission("nvus.prisoner")) return;
|
||||
|
||||
FileConfiguration autoSwitchConfig = configManager.getConfig("auto_switch.yml");
|
||||
Material blockType = event.getClickedBlock().getType();
|
||||
|
||||
// Determine the correct tool based on block type, pulled from auto_switch.yml
|
||||
Material bestTool = determineBestTool(blockType, player, autoSwitchConfig);
|
||||
if (bestTool != null) {
|
||||
switchToTool(player, bestTool);
|
||||
}
|
||||
}
|
||||
|
||||
private Material determineBestTool(Material blockType, Player player, FileConfiguration autoSwitchConfig) {
|
||||
List<String> autoSwitchTools = autoSwitchConfig.getStringList("AutoSwitchTools");
|
||||
List<Material> pickaxeMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("PickaxeMaterials"));
|
||||
List<Material> axeMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("AxeMaterials"));
|
||||
List<Material> shovelMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("ShovelMaterials"));
|
||||
|
||||
Material requiredTool = null;
|
||||
if (pickaxeMaterials.contains(blockType)) {
|
||||
requiredTool = Material.valueOf("IRON_PICKAXE");
|
||||
} else if (axeMaterials.contains(blockType)) {
|
||||
requiredTool = Material.valueOf("IRON_AXE");
|
||||
} else if (shovelMaterials.contains(blockType)) {
|
||||
requiredTool = Material.valueOf("IRON_SHOVEL");
|
||||
}
|
||||
|
||||
// Ensure the tool is in the list of tools that should auto switch
|
||||
if (requiredTool != null && autoSwitchTools.contains(requiredTool.name())) {
|
||||
return findBestToolInInventory(requiredTool, player);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Material findBestToolInInventory(Material toolType, Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
for (ItemStack item : inventory.getContents()) {
|
||||
if (item != null && item.getType() == toolType) {
|
||||
return toolType; // Further logic can be added to select the best tool if multiple are found
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Material> convertStringListToMaterial(List<String> stringList) {
|
||||
return stringList.stream().map(Material::valueOf).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void switchToTool(Player player, Material tool) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
int toolSlot = inventory.first(tool);
|
||||
if (toolSlot >= 0 && toolSlot < 9) { // If the tool is in the quickbar
|
||||
inventory.setHeldItemSlot(toolSlot);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ 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 me.nvus.nvus_prison_setup.Listeners.ToolSwitchListener;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -17,18 +18,18 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
// Initialize the ConfigManager
|
||||
configManager = new ConfigManager(this);
|
||||
|
||||
// Save the default config if it doesn't exist
|
||||
// Save the default configs, if they doesn't exist
|
||||
configManager.saveDefaultConfig("config.yml");
|
||||
configManager.saveDefaultConfig("banned_items.yml");
|
||||
configManager.saveDefaultConfig("config.yml"); // Add this line
|
||||
configManager.saveDefaultConfig("auto_switch.yml");
|
||||
|
||||
// Register event listeners
|
||||
getServer().getPluginManager().registerEvents(new PlayerSpawn(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerArmor(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerItems(configManager), this);
|
||||
getServer().getPluginManager().registerEvents(new BlockListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new ToolSwitchListener(configManager), this);
|
||||
|
||||
|
||||
// Log a success message
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
|
||||
}
|
||||
|
||||
|
@ -38,6 +39,7 @@ public final class PrisonSetup extends JavaPlugin {
|
|||
// Save the config when disabling the plugin
|
||||
configManager.saveConfig("config.yml");
|
||||
configManager.saveConfig("banned_items.yml");
|
||||
configManager.saveConfig("auto_switch.yml");
|
||||
|
||||
// Log a success message
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&c&lNVus Prison Setup has been successfully disabled!"));
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
#======================================================================================#
|
||||
# NVus PRISON SETUP #
|
||||
# by never2nv #
|
||||
# www.FNGnation.net #
|
||||
# Discord: FNGnation.net/discord #
|
||||
#======================================================================================#
|
||||
|
||||
# If AutoSwitch = true in the config.yml, what tools should the prisoner auto switch to?
|
||||
# I'd always keep some kind of pickaxe, axe and shovel in here even if you don't want to auto switch to them.
|
||||
# Just eliminate the Materials list for that tool(s) to disable that particular tool. Just to prevent conflicts/errors.
|
||||
AutoSwitchTools:
|
||||
- IRON_PICKAXE
|
||||
- IRON_AXE
|
||||
- IRON_SHOVEL
|
||||
|
||||
# What blocks/ores should cause the prisoner to auto switch to a pickaxe?
|
||||
PickaxeMaterials:
|
||||
- STONE
|
||||
- COBBLESTONE
|
||||
- ANDESITE
|
||||
- DIORITE
|
||||
- GRANITE
|
||||
- NETHERRACK
|
||||
- END_STONE
|
||||
- SANDSTONE
|
||||
- RED_SANDSTONE
|
||||
- OBSIDIAN
|
||||
# Here's all the ORES that will trigger switching to a piacke:
|
||||
- COAL_ORE
|
||||
- IRON_ORE
|
||||
- GOLD_ORE
|
||||
- DIAMOND_ORE
|
||||
- LAPIS_ORE
|
||||
- REDSTONE_ORE
|
||||
- EMERALD_ORE
|
||||
- NETHER_QUARTZ_ORE
|
||||
- ANCIENT_DEBRIS
|
||||
|
||||
# What blocks should cause the prisoner to auto switch to an axe?
|
||||
AxeMaterials:
|
||||
- OAK_LOG
|
||||
- OAK_PLANKS
|
||||
- BIRCH_LOG
|
||||
- BIRCH_PLANKS
|
||||
- SPRUCE_LOG
|
||||
- SPRUCE_PLANKS
|
||||
- JUNGLE_LOG
|
||||
- JUNGLE_PLANKS
|
||||
- ACACIA_LOG
|
||||
- ACACIA_PLANKS
|
||||
- DARK_OAK_LOG
|
||||
- DARK_OAK_PLANKS
|
||||
|
||||
# What blocks should cause the prisoner to auto switch to a shovel?
|
||||
ShovelMaterials:
|
||||
- GRASS_BLOCK
|
||||
- DIRT
|
||||
- COARSE_DIRT
|
||||
- PODZOL
|
||||
- SAND
|
||||
- RED_SAND
|
||||
- GRAVEL
|
||||
- CLAY
|
||||
- SNOW
|
||||
- SNOW_BLOCK
|
|
@ -9,3 +9,6 @@
|
|||
|
||||
# Should prisoners auto pickup blocks they have mined?
|
||||
AutoPickup: true
|
||||
# Should prisoners be able to auto switch to the correct tool for whatever they are mining?
|
||||
#i.e. If hitting dirt/clay with a pickaxe, they will auto switch to a shovel (if in their quickbar)
|
||||
AutoSwitch: true
|
||||
|
|
Loading…
Reference in New Issue