Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>simplexity</groupId>
<artifactId>AdminHax</artifactId>
<version>1.2.1</version>
<version>1.3.0</version>
<packaging>jar</packaging>

<name>AdminHax</name>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/simplexity/adminhax/AdminHax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
66 changes: 66 additions & 0 deletions src/main/java/simplexity/adminhax/commands/basic/Hat.java
Original file line number Diff line number Diff line change
@@ -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<Integer, ItemStack> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/simplexity/adminhax/config/ConfigHandler.java
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<Material> disabledHatItems = new HashSet<>();

public void reloadConfigValues() {
AdminHax.getInstance().reloadConfig();
Expand All @@ -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<String> 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) {
Expand Down Expand Up @@ -91,4 +108,12 @@ public boolean isGamemodeChangePersistentFlight() {
public int getMaxRenameCharacters() {
return maxRenameCharacters;
}

public boolean shouldRespectBindingCurse() {
return respectBindingCurse;
}

public HashSet<Material> getDisabledHatItems(){
return disabledHatItems;
}
}
7 changes: 6 additions & 1 deletion src/main/java/simplexity/adminhax/config/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ public enum Message {
ERROR_INVALID_NUMBER("error.invalid-number", "<red>Sorry, you did not enter a valid flyspeed, please try again</red>"),
ERROR_INVALID_PLAYER("error.invalid-player", "<red>That is not a valid player. Please check your spelling and try again</red>"),
ERROR_MUST_BE_PLAYER("error.must-be-player", "<red>You must be a player to run this command</red>"),
ERROR_MUST_HOLD_ITEM("error.must-hold-item", "<red>You must be holding item to rename</red>"),
ERROR_MUST_HOLD_ITEM_TO_RENAME("error.must-hold-item", "<red>You must be holding item to rename</red>"),
ERROR_NO_HAT_ITEMS("error.no-hat-items", "<red>You must be holding an item or have an item in your helmet slot to use this command</red>"),
ERROR_CURSE_OF_BINDING("error.curse-of-binding", "<red>You currently are wearing something with curse of binding! Sorry!</red>"),
ERROR_HAT_NOT_ALLOWED("error.hat-not-allowed", "<red>Hats of this type are not allowed</red>"),
ERROR_NAME_TOO_LONG("error.name-too-long", "<red>Sorry, that item name is too long! The max characters for an item name is <value></red>"),
ERROR_NO_PERMISSION("error.no-permission", "<red>You do not have permission to run this command</red>"),
ERROR_NOT_ENOUGH_ARGUMENTS("error.not-enough-arguments", "<red>You did not provide enough arguments. Please check your syntax and try again</red>"),
ERROR_NOT_IN_RANGE("error.not-in-range", "<red>Sorry, you must provide a number between <min> and <max></red>"),
HAT_SUCCESSFUL("hat.success", "<green>Enjoy your new hat!</green>"),
HAT_REMOVED("hat.removed", "<gray>Your hat has been returned to your inventory</gray>"),
FEED_OTHER("feed.other", "<green>You have fed <target></green>"),
FEED_SELF("feed.self", "<green>You have been fed</green>"),
FLY_SET_BY_OTHER("fly.by-other", "<green>Your fly has been <value></green>"),
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# tooltip going off the screen
hat:
respect-curse-of-binding: true
disabled-items:
- DEBUG_STICK
8 changes: 6 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading