Removed AutoSwitchTools and instead moved the tools into config.yml as PrisonerTools. Updated ToolSwitchListener with this change in mind. Preparing to stop prisoner tool damage and make it toggable via the main config.yml
|
@ -0,0 +1 @@
|
|||
/target/
|
|
@ -0,0 +1,5 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="nvus_prison_setup" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="NVus_Prison_Setup" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="papermc-repo" />
|
||||
<option name="name" value="papermc-repo" />
|
||||
<option name="url" value="https://repo.papermc.io/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="enginehub" />
|
||||
<option name="name" value="enginehub" />
|
||||
<option name="url" value="https://maven.enginehub.org/repo/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/nvus_prison_setup.iml" filepath="$PROJECT_DIR$/nvus_prison_setup.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
<?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>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
<projectReimportVersion>1</projectReimportVersion>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
After Width: | Height: | Size: 49 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 2.1 MiB |
After Width: | Height: | Size: 268 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 382 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 742 KiB |
After Width: | Height: | Size: 359 KiB |
|
@ -0,0 +1,90 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<name>NVus_PrisonSetup</name>
|
||||
<version>0.5.6</version>
|
||||
<url>https://FNGnation.net</url>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.github.wvengen</groupId>
|
||||
<artifactId>proguard-maven-plugin</artifactId>
|
||||
<version>2.6.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>proguard</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<obfuscate>true</obfuscate>
|
||||
<injar>${project.build.finalName}.jar</injar>
|
||||
<outjar>${project.build.finalName}-proguard.jar</outjar>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
<proguardInclude>${basedir}/proguard.conf</proguardInclude>
|
||||
<libs>
|
||||
<lib>${java.home}/jmods/java.base.jmod</lib>
|
||||
</libs>
|
||||
<options>
|
||||
<option>-keep public class me.nvus.nvus_prison_setup.PrisonSetup extends org.bukkit.plugin.java.JavaPlugin { *; }</option>
|
||||
<option>-keep public class me.nvus.nvus_prison_setup.PrisonSetup extends org.bukkit.plugin.java.JavaPlugin</option>
|
||||
<option>-overloadaggressively</option>
|
||||
<option>-repackageclasses</option>
|
||||
</options>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,140 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>me.NVus</groupId>
|
||||
<artifactId>NVus_Prison_Setup</artifactId>
|
||||
<version>0.7.5</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>NVus_PrisonSetup</name>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>https://FNGnation.net</url>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>com.github.wvengen</groupId>-->
|
||||
<!-- <artifactId>proguard-maven-plugin</artifactId>-->
|
||||
<!-- <version>2.6.1</version>-->
|
||||
<!-- <executions>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <phase>package</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>proguard</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <obfuscate>true</obfuscate>-->
|
||||
<!-- <injar>${project.build.finalName}.jar</injar>-->
|
||||
<!-- <outjar>${project.build.finalName}-proguard.jar</outjar>-->
|
||||
<!-- <outputDirectory>${project.build.directory}</outputDirectory>-->
|
||||
<!-- <proguardInclude>${basedir}/proguard.conf</proguardInclude>-->
|
||||
<!-- <libs>-->
|
||||
<!-- <lib>${java.home}/jmods/java.base.jmod</lib>-->
|
||||
<!-- </libs>-->
|
||||
<!-- <options>-->
|
||||
<!-- <option>-keep public class me.nvus.nvus_prison_setup.PrisonSetup extends org.bukkit.plugin.java.JavaPlugin { *; }</option>-->
|
||||
<!-- <option>-keep public class me.nvus.nvus_prison_setup.PrisonSetup extends org.bukkit.plugin.java.JavaPlugin</option>-->
|
||||
<!-- <option>-overloadaggressively</option>-->
|
||||
<!-- <option>-repackageclasses</option>-->
|
||||
<!-- </options>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>enginehub</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.intellectualsites.bom</groupId>
|
||||
<artifactId>bom-newest</artifactId> <!-- Ref: https://github.com/IntellectualSites/bom -->
|
||||
<version>1.42</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.20.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldguard</groupId>
|
||||
<artifactId>worldguard-bukkit</artifactId>
|
||||
<version>7.0.9</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fastasyncworldedit</groupId>
|
||||
<artifactId>FastAsyncWorldEdit-Core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.wvengen</groupId>-->
|
||||
<!-- <artifactId>proguard-maven-plugin</artifactId>-->
|
||||
<!-- <version>2.6.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,59 @@
|
|||
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);
|
||||
plugin.getLogger().info("banned_items.yml has been created.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> getBannedItems() {
|
||||
return getConfig().getStringList("BannedItems");
|
||||
}
|
||||
}
|
|
@ -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,129 @@
|
|||
package me.nvus.nvus_prison_setup.Configs;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
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.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SettingsMenu implements Listener {
|
||||
private final JavaPlugin plugin;
|
||||
private final ConfigManager configManager;
|
||||
private final Map<UUID, Consumer<Player>> playerTasks = new ConcurrentHashMap<>();
|
||||
|
||||
public SettingsMenu(JavaPlugin plugin, ConfigManager configManager) {
|
||||
this.plugin = plugin;
|
||||
this.configManager = configManager;
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
public void openSettingsMenu(Player player) {
|
||||
Inventory inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GREEN + "Settings Menu");
|
||||
FileConfiguration config = configManager.getConfig("config.yml");
|
||||
|
||||
inv.setItem(0, createToggleItem(Material.LEATHER_CHESTPLATE, "Toggle PrisonerArmor", config.getBoolean("PrisonerArmor", false)));
|
||||
inv.setItem(1, createToggleItem(Material.IRON_DOOR, "Toggle RestrictArmor", config.getBoolean("RestrictArmor", false)));
|
||||
inv.setItem(3, createToggleItem(Material.HOPPER, "Toggle AutoPickup", config.getBoolean("AutoPickup", false)));
|
||||
inv.setItem(4, createToggleItem(Material.LEVER, "Toggle AutoSwitch", config.getBoolean("AutoSwitch", false)));
|
||||
inv.setItem(7, createItem(Material.BOOK, ChatColor.GREEN + "Reload Configs"));
|
||||
|
||||
player.openInventory(inv);
|
||||
}
|
||||
|
||||
private ItemStack createToggleItem(Material material, String name, boolean isEnabled) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.GREEN + name + ": " + (isEnabled ? ChatColor.BLUE + "Enabled" : ChatColor.RED + "Disabled"));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
private ItemStack createItem(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!event.getView().getTitle().equals(ChatColor.DARK_GREEN + "Settings Menu")) return;
|
||||
event.setCancelled(true);
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
// Execute any pending tasks for this player before processing a new one
|
||||
playerTasks.computeIfPresent(playerUUID, (uuid, task) -> {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> task.accept(player));
|
||||
return null;
|
||||
});
|
||||
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
if (clickedItem == null || !clickedItem.hasItemMeta() || !clickedItem.getItemMeta().hasDisplayName()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String displayName = ChatColor.stripColor(clickedItem.getItemMeta().getDisplayName());
|
||||
scheduleConfigToggle(playerUUID, displayName);
|
||||
}
|
||||
|
||||
private void scheduleConfigToggle(UUID playerUUID, String displayName) {
|
||||
Consumer<Player> task = player -> {
|
||||
if (displayName.contains("Toggle PrisonerArmor")) {
|
||||
toggleConfigOption(player, "PrisonerArmor");
|
||||
} else if (displayName.contains("Toggle RestrictArmor")) {
|
||||
toggleConfigOption(player, "RestrictArmor");
|
||||
} else if (displayName.contains("Toggle AutoPickup")) {
|
||||
toggleConfigOption(player, "AutoPickup");
|
||||
} else if (displayName.contains("Toggle AutoSwitch")) {
|
||||
toggleConfigOption(player, "AutoSwitch");
|
||||
} else if (displayName.contains("Reload Configs")) {
|
||||
reloadConfigs(player);
|
||||
}
|
||||
};
|
||||
|
||||
playerTasks.put(playerUUID, task);
|
||||
}
|
||||
|
||||
private void toggleConfigOption(final Player player, String configKey) {
|
||||
// Close the inventory to prevent further clicks
|
||||
player.closeInventory();
|
||||
// Re-open menu, 10 tick delay
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> openSettingsMenu(player), 10L);
|
||||
|
||||
FileConfiguration config = configManager.getConfig("config.yml");
|
||||
boolean currentValue = config.getBoolean(configKey, false);
|
||||
|
||||
config.set(configKey, !currentValue);
|
||||
|
||||
configManager.saveConfig("config.yml");
|
||||
// Debug message
|
||||
//player.sendMessage(ChatColor.GREEN + configKey + " " + (!currentValue ? "enabled" : "disabled"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void reloadConfigs(final Player player) {
|
||||
configManager.reloadConfig("config.yml");
|
||||
configManager.reloadConfig("auto_switch.yml");
|
||||
configManager.reloadConfig("banned_items.yml");
|
||||
configManager.saveConfig("config.yml");
|
||||
player.sendMessage(ChatColor.GREEN + "Configuration files reloaded.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
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.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
private final PrisonSetup plugin;
|
||||
|
||||
private final Set<Material> storageBlocks = new HashSet<>(Arrays.asList(
|
||||
Material.CHEST,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.ACACIA_CHEST_BOAT,
|
||||
Material.BIRCH_CHEST_BOAT,
|
||||
Material.DARK_OAK_CHEST_BOAT,
|
||||
Material.JUNGLE_CHEST_BOAT,
|
||||
Material.OAK_CHEST_BOAT,
|
||||
Material.SPRUCE_CHEST_BOAT,
|
||||
Material.FURNACE,
|
||||
Material.BLAST_FURNACE,
|
||||
Material.SMOKER,
|
||||
Material.BARREL,
|
||||
Material.DISPENSER,
|
||||
Material.DROPPER,
|
||||
Material.HOPPER,
|
||||
Material.CAULDRON,
|
||||
Material.SHULKER_BOX,
|
||||
Material.CHEST_MINECART,
|
||||
Material.BARREL,
|
||||
Material.CHISELED_BOOKSHELF,
|
||||
Material.BUNDLE
|
||||
// Add more!
|
||||
));
|
||||
|
||||
public BlockListener(PrisonSetup plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (!isBlockBreakAllowed(player, block.getLocation())) {
|
||||
event.setCancelled(true); // Prevent the block from being broken
|
||||
event.setDropItems(false); // Prevent the block from dropping items
|
||||
//player.sendMessage("You cannot break blocks in this area.");
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (storageBlocks.contains(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.hasPermission("nvus.prisoner") && plugin.getConfigManager().getConfig("config.yml").getBoolean("AutoPickup")) {
|
||||
List<ItemStack> drops = block.getDrops().stream().toList();
|
||||
for (ItemStack drop : drops) {
|
||||
if (player.getInventory().addItem(drop).isEmpty()) {
|
||||
|
||||
event.setDropItems(false);
|
||||
} else {
|
||||
// Inventory is full, drop the item on the ground
|
||||
block.getWorld().dropItemNaturally(block.getLocation(), drop);
|
||||
player.sendMessage("Your inventory is currently full. The resource has been dropped on the ground!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBlockBreakAllowed(Player player, org.bukkit.Location bukkitLocation) {
|
||||
|
||||
if (player.hasPermission("worldguard.region.bypass." + bukkitLocation.getWorld().getName()) || player.hasPermission("worldguard.region.bypass.*")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
com.sk89q.worldedit.util.Location location = BukkitAdapter.adapt(bukkitLocation);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
com.sk89q.worldguard.LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
|
||||
if (query.testBuild(location, localPlayer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// region membership, ownership, and specific flags set on the region
|
||||
return query.testState(location, localPlayer, Flags.BLOCK_BREAK);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import me.nvus.nvus_prison_setup.Configs.SettingsMenu;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class CommandListener implements CommandExecutor {
|
||||
private final JavaPlugin plugin;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public CommandListener(JavaPlugin plugin, ConfigManager configManager) {
|
||||
this.plugin = plugin;
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if (!sender.hasPermission("nvus.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /nvus <reload|version|menu|autopickup|autoswitch> [arguments]");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "reload":
|
||||
handleReloadCommand(sender);
|
||||
break;
|
||||
case "version":
|
||||
handleVersionCommand(sender);
|
||||
break;
|
||||
case "menu":
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(ChatColor.RED + "This command can only be used by players.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
new SettingsMenu(plugin, configManager).openSettingsMenu(player);
|
||||
break;
|
||||
case "autopickup":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /nvus autopickup <true|false>");
|
||||
return true;
|
||||
}
|
||||
handleToggleConfigCommand(sender, "AutoPickup", args[1]);
|
||||
break;
|
||||
case "autoswitch":
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /nvus autoswitch <true|false>");
|
||||
return true;
|
||||
}
|
||||
handleToggleConfigCommand(sender, "AutoSwitch", args[1]);
|
||||
break;
|
||||
case "prisonerarmor": // New case for toggling PrisonerArmor
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /nvus prisonerarmor <true|false>");
|
||||
return true;
|
||||
}
|
||||
handleToggleConfigCommand(sender, "PrisonerArmor", args[1]);
|
||||
break;
|
||||
|
||||
case "restrictarmor": // New case for toggling RestrictArmor
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Usage: /nvus restrictarmor <true|false>");
|
||||
return true;
|
||||
}
|
||||
handleToggleConfigCommand(sender, "RestrictArmor", args[1]);
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "Invalid command. Use /nvus for help.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleReloadCommand(CommandSender sender) {
|
||||
configManager.reloadConfig("config.yml");
|
||||
configManager.reloadConfig("auto_switch.yml");
|
||||
configManager.reloadConfig("banned_items.yml");
|
||||
sender.sendMessage(ChatColor.GREEN + "Configuration files reloaded.");
|
||||
}
|
||||
|
||||
private void handleVersionCommand(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "Plugin version: " + plugin.getDescription().getVersion());
|
||||
}
|
||||
|
||||
private void handleToggleConfigCommand(CommandSender sender, String key, String value) {
|
||||
boolean boolValue = Boolean.parseBoolean(value);
|
||||
FileConfiguration config = configManager.getConfig("config.yml");
|
||||
config.set(key, boolValue);
|
||||
configManager.saveConfig("config.yml");
|
||||
sender.sendMessage(ChatColor.GREEN + key + " set to " + boolValue + ".");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
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.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
public class PlayerArmor implements Listener {
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public PlayerArmor(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("nvus.prisoner") && configManager.getConfig("config.yml").getBoolean("PrisonerArmor")) {
|
||||
PlayerInventory inv = player.getInventory();
|
||||
inv.setArmorContents(new ItemStack[]{
|
||||
createArmor(Material.LEATHER_BOOTS, "Prisoner Boots"),
|
||||
createArmor(Material.LEATHER_LEGGINGS, "Prisoner Leggings"),
|
||||
createArmor(Material.LEATHER_CHESTPLATE, "Prisoner Chestplate"),
|
||||
createArmor(Material.LEATHER_HELMET, "Prisoner Helmet")
|
||||
});
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lYou have been equipped with prisoner armor!"));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (!player.hasPermission("nvus.prisoner")) return;
|
||||
|
||||
if (event.getClickedInventory() != null && (event.getClickedInventory().getType() == InventoryType.PLAYER || event.getClickedInventory().getType() == InventoryType.CRAFTING)) {
|
||||
if (event.getSlotType() == InventoryType.SlotType.ARMOR || isArmorItem(event.getCurrentItem()) || isArmorItem(event.getCursor())) {
|
||||
|
||||
boolean restrictArmor = configManager.getConfig("config.yml").getBoolean("RestrictArmor");
|
||||
if (restrictArmor) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&c&lSorry inmate! &cYou're a &6&lprisoner &cand cannot change your armor!"));
|
||||
}
|
||||
// If restrictArmor is false, allows the player to change armor freely.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if the given item is a piece of prisoner armor.
|
||||
private boolean isArmorItem(ItemStack item) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
Material type = item.getType();
|
||||
return type == Material.LEATHER_HELMET || type == Material.LEATHER_CHESTPLATE ||
|
||||
type == Material.LEATHER_LEGGINGS || type == Material.LEATHER_BOOTS ||
|
||||
// Add checks for other armor materials if prisoners can have those
|
||||
type == Material.CHAINMAIL_BOOTS || type == Material.IRON_HELMET;
|
||||
// We can later add additional armor sets here if we allow customization of what is considered "prisoner armor".
|
||||
}
|
||||
|
||||
private ItemStack createArmor(Material material, String name) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(name);
|
||||
meta.setColor(Color.ORANGE); // Set the color for leather armor
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
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.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 ConfigManager configManager;
|
||||
|
||||
public PlayerItems(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@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.translateAlternateColorCodes('&',"&c&lSorry inmate! &cYou're a &6&lprisoner &cand cannot use this tool!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
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.translateAlternateColorCodes('&',"&c&lSorry inmate! &cYou're a &6&lprisoner &cand cannot use this tool!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isBannedItem(Material itemType) {
|
||||
List<String> bannedItems = configManager.getConfig("banned_items.yml").getStringList("BannedItems");
|
||||
|
||||
return bannedItems.contains(itemType.toString());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
package me.nvus.nvus_prison_setup.Listeners;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
public class PlayerSpawn implements Listener {
|
||||
private final ConfigManager configManager;
|
||||
|
||||
public PlayerSpawn(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player joinedPlayer = event.getPlayer();
|
||||
|
||||
// Check if the player has the permission and if PrisonerArmor is enabled in config
|
||||
if (joinedPlayer.hasPermission("nvus.prisoner") && configManager.getConfig("config.yml").getBoolean("PrisonerArmor", true)) {
|
||||
equipPrisonerArmor(joinedPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player deadPlayer = event.getEntity();
|
||||
|
||||
if (deadPlayer.hasPermission("nvus.prisoner") && configManager.getConfig("config.yml").getBoolean("PrisonerArmor", false)) {
|
||||
// Remove prisoner armor from the list of dropped items
|
||||
event.getDrops().removeIf(drop -> isPrisonerArmor(drop.getType()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player respawnedPlayer = event.getPlayer();
|
||||
|
||||
if (respawnedPlayer.hasPermission("nvus.prisoner") && configManager.getConfig("config.yml").getBoolean("PrisonerArmor", true)) {
|
||||
equipPrisonerArmor(respawnedPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
private void equipPrisonerArmor(Player player) {
|
||||
// Create Prisoner Helmet
|
||||
ItemStack leatherHelmetPrison = new ItemStack(Material.LEATHER_HELMET);
|
||||
LeatherArmorMeta helmetMeta = (LeatherArmorMeta) leatherHelmetPrison.getItemMeta();
|
||||
if (helmetMeta != null) {
|
||||
helmetMeta.setColor(Color.ORANGE);
|
||||
helmetMeta.setDisplayName(ChatColor.GOLD + "Prisoner Helmet");
|
||||
leatherHelmetPrison.setItemMeta(helmetMeta);
|
||||
}
|
||||
|
||||
// Create Prisoner Chestplate
|
||||
ItemStack leatherChestplatePrison = new ItemStack(Material.LEATHER_CHESTPLATE);
|
||||
LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) leatherChestplatePrison.getItemMeta();
|
||||
if (chestplateMeta != null) {
|
||||
chestplateMeta.setColor(Color.ORANGE);
|
||||
chestplateMeta.setDisplayName(ChatColor.GOLD + "Prisoner Chestplate");
|
||||
leatherChestplatePrison.setItemMeta(chestplateMeta);
|
||||
}
|
||||
|
||||
// Create Prisoner Leggings
|
||||
ItemStack leatherLeggingsPrison = new ItemStack(Material.LEATHER_LEGGINGS);
|
||||
LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) leatherLeggingsPrison.getItemMeta();
|
||||
if (leggingsMeta != null) {
|
||||
leggingsMeta.setColor(Color.ORANGE);
|
||||
leggingsMeta.setDisplayName(ChatColor.GOLD + "Prisoner Leggings");
|
||||
leatherLeggingsPrison.setItemMeta(leggingsMeta);
|
||||
}
|
||||
|
||||
// Create Prisoner Boots
|
||||
ItemStack leatherBootsPrison = new ItemStack(Material.LEATHER_BOOTS);
|
||||
LeatherArmorMeta bootsMeta = (LeatherArmorMeta) leatherBootsPrison.getItemMeta();
|
||||
if (bootsMeta != null) {
|
||||
bootsMeta.setColor(Color.ORANGE);
|
||||
bootsMeta.setDisplayName(ChatColor.GOLD + "Prisoner Boots");
|
||||
leatherBootsPrison.setItemMeta(bootsMeta);
|
||||
}
|
||||
|
||||
// Equip Prisoner Armor
|
||||
player.getInventory().setHelmet(leatherHelmetPrison);
|
||||
player.getInventory().setChestplate(leatherChestplatePrison);
|
||||
player.getInventory().setLeggings(leatherLeggingsPrison);
|
||||
player.getInventory().setBoots(leatherBootsPrison);
|
||||
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lYou're a prisoner! &6You've been given the default prisoner armor!"));
|
||||
}
|
||||
|
||||
|
||||
// Destroy armor upon death etc.
|
||||
private void destroyDefaultPrisonerArmor(Player player) {
|
||||
player.getInventory().setHelmet(null);
|
||||
player.getInventory().setChestplate(null);
|
||||
player.getInventory().setLeggings(null);
|
||||
player.getInventory().setBoots(null);
|
||||
|
||||
// Using this as a debug/check, will comment out later!
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lYour default prisoner armor has been destroyed!"));
|
||||
}
|
||||
|
||||
private boolean isPrisonerArmor(Material material) {
|
||||
return material == Material.LEATHER_HELMET ||
|
||||
material == Material.LEATHER_CHESTPLATE ||
|
||||
material == Material.LEATHER_LEGGINGS ||
|
||||
material == Material.LEATHER_BOOTS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
private void destroyDefaultPrisonerArmor(Player player) {
|
||||
player.getInventory().setHelmet(null);
|
||||
player.getInventory().setChestplate(null);
|
||||
player.getInventory().setLeggings(null);
|
||||
player.getInventory().setBoots(null);
|
||||
|
||||
// Using this as a debug/check, will comment out later!
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lYour default prisoner armor has been destroyed!"));
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Destroy armor upon death etc.
|
||||
private void destroyDefaultPrisonerArmor(Player player) {
|
||||
// Loop through the armor slots and remove any armor pieces
|
||||
for (ItemStack armor : player.getInventory().getArmorContents()) {
|
||||
if (armor != null && armor.getType() != Material.AIR) {
|
||||
player.getInventory().remove(armor);
|
||||
}
|
||||
}
|
||||
|
||||
// Using this as a debug/check, will comment out later!
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lYour default prisoner armor has been destroyed!"));
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
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.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 final ConfigManager configManager;
|
||||
|
||||
public ToolSwitchListener(ConfigManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != org.bukkit.event.block.Action.LEFT_CLICK_BLOCK) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
FileConfiguration mainConfig = configManager.getConfig("config.yml");
|
||||
FileConfiguration autoSwitchConfig = configManager.getConfig("auto_switch.yml");
|
||||
|
||||
if (!player.hasPermission("nvus.prisoner") || !mainConfig.getBoolean("AutoSwitch", true)) return;
|
||||
|
||||
Material blockType = event.getClickedBlock().getType();
|
||||
|
||||
Material bestTool = determineBestTool(blockType, player, mainConfig, autoSwitchConfig);
|
||||
if (bestTool != null) {
|
||||
switchToTool(player, bestTool);
|
||||
}
|
||||
}
|
||||
|
||||
private Material determineBestTool(Material blockType, Player player, FileConfiguration mainConfig, FileConfiguration autoSwitchConfig) {
|
||||
List<String> prisonTools = mainConfig.getStringList("PrisonerTools");
|
||||
|
||||
// Fetch block materials for tools from auto_switch.yml
|
||||
List<Material> pickaxeMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("PickaxeMaterials"));
|
||||
List<Material> axeMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("AxeMaterials"));
|
||||
List<Material> shovelMaterials = convertStringListToMaterial(autoSwitchConfig.getStringList("ShovelMaterials"));
|
||||
|
||||
Material requiredTool = getRequiredToolForBlock(blockType, pickaxeMaterials, axeMaterials, shovelMaterials);
|
||||
|
||||
if (requiredTool != null && prisonTools.contains(requiredTool.toString())) {
|
||||
return findBestToolInInventory(requiredTool, player);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Material getRequiredToolForBlock(Material blockType, List<Material> pickaxeMaterials, List<Material> axeMaterials, List<Material> shovelMaterials) {
|
||||
if (pickaxeMaterials.contains(blockType)) {
|
||||
return Material.IRON_PICKAXE;
|
||||
} else if (axeMaterials.contains(blockType)) {
|
||||
return Material.IRON_AXE;
|
||||
} else if (shovelMaterials.contains(blockType)) {
|
||||
return Material.IRON_SHOVEL;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Material findBestToolInInventory(Material toolType, Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
return inventory.all(toolType).values().stream()
|
||||
.findFirst()
|
||||
.map(ItemStack::getType)
|
||||
.orElse(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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package me.nvus.nvus_prison_setup;
|
||||
|
||||
import me.nvus.nvus_prison_setup.Configs.ConfigManager;
|
||||
import me.nvus.nvus_prison_setup.Listeners.CommandListener;
|
||||
import me.nvus.nvus_prison_setup.Configs.SettingsMenu;
|
||||
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 me.nvus.nvus_prison_setup.Updater.UpdateChecker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class PrisonSetup extends JavaPlugin {
|
||||
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Initialize the ConfigManager
|
||||
configManager = new ConfigManager(this);
|
||||
|
||||
// Save the default configs, if they doesn't exist
|
||||
configManager.saveDefaultConfig("config.yml");
|
||||
configManager.saveDefaultConfig("banned_items.yml");
|
||||
configManager.saveDefaultConfig("auto_switch.yml");
|
||||
|
||||
// Register event listeners
|
||||
getServer().getPluginManager().registerEvents(new PlayerSpawn(configManager), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerArmor(configManager), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerItems(configManager), this);
|
||||
getServer().getPluginManager().registerEvents(new BlockListener(this), this);
|
||||
getServer().getPluginManager().registerEvents(new ToolSwitchListener(configManager), this);
|
||||
this.getCommand("nvus").setExecutor(new CommandListener(this, configManager));
|
||||
//new SettingsMenu(this, configManager);
|
||||
getServer().getPluginManager().registerEvents(new SettingsMenu(this, configManager), this);
|
||||
|
||||
getLogger().info(ChatColor.translateAlternateColorCodes('&',"&a&lNVus Prison Setup has been successfully enabled!"));
|
||||
|
||||
new UpdateChecker(this, 12345).getVersion(version -> {
|
||||
if (!this.getDescription().getVersion().equals(version)) {
|
||||
getLogger().info("There is a new update available for NVus Prison Setup! Grab it from SpigotMC here: https://www.spigotmc.org/resources/nvus-prison-setup.115441/");
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (player.isOp() || player.hasPermission("nvus.admin")) {
|
||||
player.sendMessage(ChatColor.RED + "=====================================================");
|
||||
player.sendMessage(ChatColor.YELLOW + "An update for NVus Prison Setup is available! Grab it from SpigotMC here: https://www.spigotmc.org/resources/nvus-prison-setup.115441/");
|
||||
player.sendMessage(ChatColor.RED + "=====================================================");
|
||||
}
|
||||
}
|
||||
}, 20L * 60);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// 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!"));
|
||||
}
|
||||
|
||||
public ConfigManager getConfigManager() {
|
||||
return configManager;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package me.nvus.nvus_prison_setup.Updater;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
// From: https://www.spigotmc.org/wiki/creating-an-update-checker-that-checks-for-updates
|
||||
public class UpdateChecker {
|
||||
|
||||
private final JavaPlugin plugin;
|
||||
private final int resourceId;
|
||||
|
||||
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = 115441;
|
||||
}
|
||||
|
||||
public void getVersion(final Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (InputStream is = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId + "/~").openStream(); Scanner scann = new Scanner(is)) {
|
||||
if (scann.hasNext()) {
|
||||
consumer.accept(scann.next());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().info("Unable to check for DecorativeEndGateway updates: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#======================================================================================#
|
||||
# NVus PRISON SETUP #
|
||||
# by never2nv #
|
||||
# www.FNGnation.net #
|
||||
# Discord: FNGnation.net/discord #
|
||||
#======================================================================================#
|
||||
|
||||
# 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
|
|
@ -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 the permission ' nvus.prisoner ' and negate that permission for any
|
||||
# players that are not or no longer considered a prisoner.
|
||||
BannedItems:
|
||||
- DIAMOND_PICKAXE
|
||||
- NETHERITE_PICKAXE
|
|
@ -0,0 +1,31 @@
|
|||
#======================================================================================#
|
||||
# NVus PRISON SETUP #
|
||||
# by never2nv #
|
||||
# www.FNGnation.net #
|
||||
# Discord: FNGnation.net/discord #
|
||||
#======================================================================================#
|
||||
# Remember to give 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?
|
||||
# Use /nvus autopickup true|false to toggle this in-game! (Requires permission: nvus.admin)
|
||||
# DO NOT TURN THIS ON WHEN RUNNING THIS PLUGIN ON A LIVE/PRODUCTION SERVER! There may be bugs!
|
||||
AutoPickup: false
|
||||
# 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)
|
||||
# Use /nvus autoswitch true|false to toggle this in-game! (Requires permission: nvus.admin)
|
||||
AutoSwitch: true
|
||||
|
||||
# Should prisoners be given a default prisoner armor set (orange leather armor) when they join the server?
|
||||
PrisonerArmor: true
|
||||
# Should prisoners be able to remove/change their default prisoner armor?
|
||||
RestrictArmor: true
|
||||
|
||||
# What tools are considered Prisoner Tools? These are used for the ToolDamage toggle and for auto switching feature!
|
||||
# See auto_switch.yml to set up which blocks trigger the auto switch to these tools.
|
||||
PrisonerTools:
|
||||
- IRON_PICKAXE
|
||||
- IRON_AXE
|
||||
- IRON_SHOVEL
|
||||
# When set to FALSE it will prevent Prisoner Tools from receiving damage when mining etc.
|
||||
ToolDamage: false
|
|
@ -0,0 +1,23 @@
|
|||
name: NVus_PrisonSetup
|
||||
version: '${project.version}'
|
||||
main: me.nvus.nvus_prison_setup.PrisonSetup
|
||||
api-version: '1.20'
|
||||
prefix: NVus Prison
|
||||
authors: [never2nv]
|
||||
website: https://FNGnation.net
|
||||
|
||||
depends:
|
||||
- WorldGuard
|
||||
|
||||
commands:
|
||||
nvus:
|
||||
description: Base command to view NVus Prison Setup commands.
|
||||
usage: |
|
||||
/nvus reload - Reloads all configuration files.
|
||||
/nvus version - Shows the plugin version.
|
||||
/nvus menu - Opens the settings menu (player only).
|
||||
/nvus autopickup <true|false> - Toggles the auto item pickup feature.
|
||||
/nvus autoswitch <true|false> - Toggles the auto tool switch feature.
|
||||
/nvus prisonerarmor <true|false> - Toggles giving prisoners armor on join.
|
||||
/nvus restrictarmor <true|false> - Toggles the restriction on changing prisoner armor.
|
||||
aliases: [nvusmenu]
|