Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.2.2</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
62 changes: 62 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,62 @@
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 itemInHand = player.getInventory().getItemInMainHand();
ItemStack itemInHelmSlot = player.getInventory().getHelmet();
if (itemInHelmSlot == null && itemInHand.isEmpty()) {
player.sendRichMessage(Message.ERROR_NO_ITEMS_HAT.getMessage());
return false;
}
if ((itemInHelmSlot != null && !itemInHelmSlot.isEmpty()) && (
itemInHelmSlot.getItemMeta().hasEnchant(Enchantment.BINDING_CURSE) &&
ConfigHandler.getInstance().isHatRespectsCurseOfBinding()
)){
player.sendRichMessage(Message.ERROR_CURSE_OF_BINDING.getMessage());
return false;
}
if (ConfigHandler.getInstance().getDisabledHatItems().contains(itemInHand.getType())) {
player.sendRichMessage(Message.ERROR_HAT_NOT_ALLOWED.getMessage());
return false;
}
if (itemInHand.getAmount() > 1) {
player.getInventory().setHelmet(itemInHand.asOne());
int amt = itemInHand.getAmount() - 1;
itemInHand.setAmount(amt);
player.getInventory().setItemInMainHand(itemInHand);
if (itemInHelmSlot != null) {
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(itemInHelmSlot);
if (!leftover.isEmpty()) {
for (Integer integer : leftover.keySet()) {
player.getWorld().dropItem(player.getLocation(), leftover.get(integer));
}
}
}
player.sendRichMessage(Message.HAT_SUCCESSFUL.getMessage());
} else {
player.getInventory().setHelmet(itemInHand);
if (itemInHelmSlot != null) player.getInventory().setItemInMainHand(itemInHelmSlot);
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, hatRespectsCurseOfBinding;
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);
hatRespectsCurseOfBinding = config.getBoolean("hat.respect-curse-of-binding", true);
List<String> disabledItems = config.getStringList("hat.disabled-items");
disabledHatItems.clear();
if (!disabledItems.isEmpty()) {
for (String string : disabledItems) {
Material material = Material.getMaterial(string);
if (material == null) {
logger.info(string + " is not a valid material, please check your syntax");
continue;
}
disabledHatItems.add(material);
}
}
}

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 isHatRespectsCurseOfBinding() {
return hatRespectsCurseOfBinding;
}

public HashSet<Material> getDisabledHatItems(){
return disabledHatItems;
}
}
6 changes: 5 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,15 @@ 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_ITEMS_HAT("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>"),
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