diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 4dd7399..a9c2d05 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -23,8 +23,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
- java-version: '17'
- distribution: 'temurin'
+ java-version: '21'
+ distribution: 'corretto'
cache: maven
# Build and verify
@@ -41,4 +41,4 @@ jobs:
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
- name: Update dependency graph
- uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
\ No newline at end of file
+ uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
diff --git a/pom.xml b/pom.xml
index 8938572..41815ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
simplexity
AdminHax
- 1.2.1
+ 1.3.0
jar
AdminHax
diff --git a/src/main/java/simplexity/adminhax/AdminHax.java b/src/main/java/simplexity/adminhax/AdminHax.java
index 90a5c18..52f9c03 100644
--- a/src/main/java/simplexity/adminhax/AdminHax.java
+++ b/src/main/java/simplexity/adminhax/AdminHax.java
@@ -3,6 +3,7 @@
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.plugin.java.JavaPlugin;
import simplexity.adminhax.commands.basic.BroadcastMsg;
+import simplexity.adminhax.commands.basic.Hat;
import simplexity.adminhax.commands.basic.ReloadPlugin;
import simplexity.adminhax.commands.basic.RenameItem;
import simplexity.adminhax.commands.hax.Feed;
@@ -41,6 +42,7 @@ public void onEnable() {
this.getCommand("broadcastmsg").setExecutor(new BroadcastMsg());
this.getCommand("adminhaxreload").setExecutor(new ReloadPlugin());
this.getCommand("rename").setExecutor(new RenameItem());
+ this.getCommand("hat").setExecutor(new Hat());
this.getServer().getPluginManager().registerEvents(new FlyListeners(), this);
}
diff --git a/src/main/java/simplexity/adminhax/commands/basic/Hat.java b/src/main/java/simplexity/adminhax/commands/basic/Hat.java
new file mode 100644
index 0000000..12eb0ce
--- /dev/null
+++ b/src/main/java/simplexity/adminhax/commands/basic/Hat.java
@@ -0,0 +1,66 @@
+package simplexity.adminhax.commands.basic;
+
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.enchantments.Enchantment;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import simplexity.adminhax.config.ConfigHandler;
+import simplexity.adminhax.config.Message;
+
+import java.util.HashMap;
+
+public class Hat implements CommandExecutor {
+
+
+ @Override
+ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
+ if (!(sender instanceof Player player)) {
+ sender.sendRichMessage(Message.ERROR_MUST_BE_PLAYER.getMessage());
+ return false;
+ }
+ ItemStack itemToHat = player.getInventory().getItemInMainHand();
+ ItemStack previousHelm = player.getInventory().getHelmet();
+ boolean userHadHelmetBefore = (previousHelm != null && !previousHelm.isEmpty());
+ if (!userHadHelmetBefore && itemToHat.isEmpty()) {
+ player.sendRichMessage(Message.ERROR_NO_HAT_ITEMS.getMessage());
+ return false;
+ }
+ if (userHadHelmetBefore && (previousHelm.getItemMeta().hasEnchant(Enchantment.BINDING_CURSE) &&
+ ConfigHandler.getInstance().shouldRespectBindingCurse())) {
+ player.sendRichMessage(Message.ERROR_CURSE_OF_BINDING.getMessage());
+ return false;
+ }
+ if (ConfigHandler.getInstance().getDisabledHatItems().contains(itemToHat.getType())) {
+ player.sendRichMessage(Message.ERROR_HAT_NOT_ALLOWED.getMessage());
+ return false;
+ }
+ if (itemToHat.isEmpty()) {
+ player.getInventory().setHelmet(null);
+ player.getInventory().setItemInMainHand(previousHelm);
+ player.sendRichMessage(Message.HAT_REMOVED.getMessage());
+ return true;
+ }
+ player.getInventory().setHelmet(itemToHat.asOne());
+ itemToHat.subtract();
+ if (!userHadHelmetBefore) {
+ player.sendRichMessage(Message.HAT_SUCCESSFUL.getMessage());
+ return true;
+ }
+ if (player.getInventory().getItemInMainHand().isEmpty()) {
+ player.getInventory().setItemInMainHand(previousHelm);
+ player.sendRichMessage(Message.HAT_SUCCESSFUL.getMessage());
+ return true;
+ }
+ HashMap leftover = player.getInventory().addItem(previousHelm);
+ if (!leftover.isEmpty()) {
+ for (Integer index : leftover.keySet()) {
+ player.getWorld().dropItem(player.getLocation(), leftover.get(index));
+ }
+ }
+ player.sendRichMessage(Message.HAT_SUCCESSFUL.getMessage());
+ return true;
+ }
+}
diff --git a/src/main/java/simplexity/adminhax/commands/basic/RenameItem.java b/src/main/java/simplexity/adminhax/commands/basic/RenameItem.java
index 6c83386..88b7a9f 100644
--- a/src/main/java/simplexity/adminhax/commands/basic/RenameItem.java
+++ b/src/main/java/simplexity/adminhax/commands/basic/RenameItem.java
@@ -40,7 +40,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}
ItemStack heldItem = player.getInventory().getItemInMainHand();
if (heldItem.isEmpty() || heldItem.getType().isEmpty()) {
- player.sendRichMessage(Message.ERROR_MUST_HOLD_ITEM.getMessage());
+ player.sendRichMessage(Message.ERROR_MUST_HOLD_ITEM_TO_RENAME.getMessage());
return false;
}
Component newName = parsedName(player, renameString);
diff --git a/src/main/java/simplexity/adminhax/config/ConfigHandler.java b/src/main/java/simplexity/adminhax/config/ConfigHandler.java
index 7a6ff5a..8895b8c 100644
--- a/src/main/java/simplexity/adminhax/config/ConfigHandler.java
+++ b/src/main/java/simplexity/adminhax/config/ConfigHandler.java
@@ -1,8 +1,11 @@
package simplexity.adminhax.config;
+import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import simplexity.adminhax.AdminHax;
+import java.util.HashSet;
+import java.util.List;
import java.util.logging.Logger;
public class ConfigHandler {
@@ -19,8 +22,9 @@ public static ConfigHandler getInstance() {
private float maxWalkSpeed, minWalkSpeed, maxFlySpeed, minFlySpeed;
private boolean sessionPersistentFlight, worldChangePersistentFlight, respawnPersistentFlight,
- gamemodeChangePersistentFlight;
+ gamemodeChangePersistentFlight, respectBindingCurse;
private int maxRenameCharacters;
+ private static final HashSet disabledHatItems = new HashSet<>();
public void reloadConfigValues() {
AdminHax.getInstance().reloadConfig();
@@ -34,6 +38,19 @@ public void reloadConfigValues() {
respawnPersistentFlight = config.getBoolean("flight.persistent.respawn", true);
gamemodeChangePersistentFlight = config.getBoolean("flight.persistent.gamemode-change", true);
maxRenameCharacters = config.getInt("rename.max-characters", 50);
+ respectBindingCurse = config.getBoolean("hat.respect-curse-of-binding", true);
+ List disabledItems = config.getStringList("hat.disabled-items");
+ disabledHatItems.clear();
+ if (!disabledItems.isEmpty()) {
+ for (String disabledItem : disabledItems) {
+ Material itemType = Material.getMaterial(disabledItem);
+ if (itemType == null) {
+ logger.info(disabledItem + " is not a valid material, please check your syntax");
+ continue;
+ }
+ disabledHatItems.add(itemType);
+ }
+ }
}
private float checkFloat(float defaultValue, String configPath, FileConfiguration config) {
@@ -91,4 +108,12 @@ public boolean isGamemodeChangePersistentFlight() {
public int getMaxRenameCharacters() {
return maxRenameCharacters;
}
+
+ public boolean shouldRespectBindingCurse() {
+ return respectBindingCurse;
+ }
+
+ public HashSet getDisabledHatItems(){
+ return disabledHatItems;
+ }
}
diff --git a/src/main/java/simplexity/adminhax/config/Message.java b/src/main/java/simplexity/adminhax/config/Message.java
index bbaafb3..8edcb97 100644
--- a/src/main/java/simplexity/adminhax/config/Message.java
+++ b/src/main/java/simplexity/adminhax/config/Message.java
@@ -7,11 +7,16 @@ public enum Message {
ERROR_INVALID_NUMBER("error.invalid-number", "Sorry, you did not enter a valid flyspeed, please try again"),
ERROR_INVALID_PLAYER("error.invalid-player", "That is not a valid player. Please check your spelling and try again"),
ERROR_MUST_BE_PLAYER("error.must-be-player", "You must be a player to run this command"),
- ERROR_MUST_HOLD_ITEM("error.must-hold-item", "You must be holding item to rename"),
+ ERROR_MUST_HOLD_ITEM_TO_RENAME("error.must-hold-item", "You must be holding item to rename"),
+ ERROR_NO_HAT_ITEMS("error.no-hat-items", "You must be holding an item or have an item in your helmet slot to use this command"),
+ ERROR_CURSE_OF_BINDING("error.curse-of-binding", "You currently are wearing something with curse of binding! Sorry!"),
+ ERROR_HAT_NOT_ALLOWED("error.hat-not-allowed", "Hats of this type are not allowed"),
ERROR_NAME_TOO_LONG("error.name-too-long", "Sorry, that item name is too long! The max characters for an item name is "),
ERROR_NO_PERMISSION("error.no-permission", "You do not have permission to run this command"),
ERROR_NOT_ENOUGH_ARGUMENTS("error.not-enough-arguments", "You did not provide enough arguments. Please check your syntax and try again"),
ERROR_NOT_IN_RANGE("error.not-in-range", "Sorry, you must provide a number between and "),
+ HAT_SUCCESSFUL("hat.success", "Enjoy your new hat!"),
+ HAT_REMOVED("hat.removed", "Your hat has been returned to your inventory"),
FEED_OTHER("feed.other", "You have fed "),
FEED_SELF("feed.self", "You have been fed"),
FLY_SET_BY_OTHER("fly.by-other", "Your fly has been "),
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 949950d..7558f49 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -13,4 +13,8 @@ flight:
gamemode: true
rename:
max-characters: 50 #Going over 50 characters may cause unwanted visual effects such as the
- # tooltip going off the screen
\ No newline at end of file
+ # tooltip going off the screen
+hat:
+ respect-curse-of-binding: true
+ disabled-items:
+ - DEBUG_STICK
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 1516bfc..f73b8ec 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -6,6 +6,9 @@ author: Simplexity
api-version: '1.20'
commands:
+ hat:
+ permission: adminhax.commands.hat
+ description: Allows players to put items on their helmet slot
flyspeed:
permission: adminhax.commands.speed.fly
description: Change your flight speed
@@ -53,7 +56,6 @@ permissions:
adminhax.commands.godmode: true
adminhax.commands.broadcast: true
adminhax.commands.rename: true
- adminhax.reload: true
adminhax.commands.speed:
description: Permissions for speed commands
@@ -149,7 +151,9 @@ permissions:
adminhax.commands.rename.format.obfuscated:
default: op
description: Use obfuscated format
-
+ adminhax.commands.hat:
+ default: op
+ description: Allows a user to put items in their helmet slot with the /hat command
adminhax.reload:
default: op
description: Reload the plugin