Skip to content

Commit 5192444

Browse files
committed
Adds the ability to use /hat to put stuff on your head - also removes an unintended child permission from the default permission
1 parent b246882 commit 5192444

8 files changed

Lines changed: 108 additions & 7 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>simplexity</groupId>
88
<artifactId>AdminHax</artifactId>
9-
<version>1.2.1</version>
9+
<version>1.2.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>AdminHax</name>

src/main/java/simplexity/adminhax/AdminHax.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.kyori.adventure.text.minimessage.MiniMessage;
44
import org.bukkit.plugin.java.JavaPlugin;
55
import simplexity.adminhax.commands.basic.BroadcastMsg;
6+
import simplexity.adminhax.commands.basic.Hat;
67
import simplexity.adminhax.commands.basic.ReloadPlugin;
78
import simplexity.adminhax.commands.basic.RenameItem;
89
import simplexity.adminhax.commands.hax.Feed;
@@ -41,6 +42,7 @@ public void onEnable() {
4142
this.getCommand("broadcastmsg").setExecutor(new BroadcastMsg());
4243
this.getCommand("adminhaxreload").setExecutor(new ReloadPlugin());
4344
this.getCommand("rename").setExecutor(new RenameItem());
45+
this.getCommand("hat").setExecutor(new Hat());
4446
this.getServer().getPluginManager().registerEvents(new FlyListeners(), this);
4547
}
4648

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package simplexity.adminhax.commands.basic;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.enchantments.Enchantment;
7+
import org.bukkit.entity.Player;
8+
import org.bukkit.inventory.ItemStack;
9+
import org.jetbrains.annotations.NotNull;
10+
import simplexity.adminhax.config.ConfigHandler;
11+
import simplexity.adminhax.config.Message;
12+
13+
import java.util.HashMap;
14+
15+
public class Hat implements CommandExecutor {
16+
17+
18+
@Override
19+
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
20+
if (!(sender instanceof Player player)) {
21+
sender.sendRichMessage(Message.ERROR_MUST_BE_PLAYER.getMessage());
22+
return false;
23+
}
24+
ItemStack itemInHand = player.getInventory().getItemInMainHand();
25+
ItemStack itemInHelmSlot = player.getInventory().getHelmet();
26+
if (itemInHelmSlot == null && itemInHand.isEmpty()) {
27+
player.sendRichMessage(Message.ERROR_NO_ITEMS_HAT.getMessage());
28+
return false;
29+
}
30+
if ((itemInHelmSlot != null && !itemInHelmSlot.isEmpty()) && (
31+
itemInHelmSlot.getItemMeta().hasEnchant(Enchantment.BINDING_CURSE) &&
32+
ConfigHandler.getInstance().isHatRespectsCurseOfBinding()
33+
)){
34+
player.sendRichMessage(Message.ERROR_CURSE_OF_BINDING.getMessage());
35+
return false;
36+
}
37+
if (ConfigHandler.getInstance().getDisabledHatItems().contains(itemInHand.getType())) {
38+
player.sendRichMessage(Message.ERROR_HAT_NOT_ALLOWED.getMessage());
39+
return false;
40+
}
41+
if (itemInHand.getAmount() > 1) {
42+
player.getInventory().setHelmet(itemInHand.asOne());
43+
int amt = itemInHand.getAmount() - 1;
44+
itemInHand.setAmount(amt);
45+
player.getInventory().setItemInMainHand(itemInHand);
46+
if (itemInHelmSlot != null) {
47+
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(itemInHelmSlot);
48+
if (!leftover.isEmpty()) {
49+
for (Integer integer : leftover.keySet()) {
50+
player.getWorld().dropItem(player.getLocation(), leftover.get(integer));
51+
}
52+
}
53+
}
54+
player.sendRichMessage(Message.HAT_SUCCESSFUL.getMessage());
55+
} else {
56+
player.getInventory().setHelmet(itemInHand);
57+
if (itemInHelmSlot != null) player.getInventory().setItemInMainHand(itemInHelmSlot);
58+
player.sendRichMessage(Message.HAT_SUCCESSFUL.getMessage());
59+
}
60+
return true;
61+
}
62+
}

src/main/java/simplexity/adminhax/commands/basic/RenameItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4040
}
4141
ItemStack heldItem = player.getInventory().getItemInMainHand();
4242
if (heldItem.isEmpty() || heldItem.getType().isEmpty()) {
43-
player.sendRichMessage(Message.ERROR_MUST_HOLD_ITEM.getMessage());
43+
player.sendRichMessage(Message.ERROR_MUST_HOLD_ITEM_TO_RENAME.getMessage());
4444
return false;
4545
}
4646
Component newName = parsedName(player, renameString);

src/main/java/simplexity/adminhax/config/ConfigHandler.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package simplexity.adminhax.config;
22

3+
import org.bukkit.Material;
34
import org.bukkit.configuration.file.FileConfiguration;
45
import simplexity.adminhax.AdminHax;
56

7+
import java.util.HashSet;
8+
import java.util.List;
69
import java.util.logging.Logger;
710

811
public class ConfigHandler {
@@ -19,8 +22,9 @@ public static ConfigHandler getInstance() {
1922

2023
private float maxWalkSpeed, minWalkSpeed, maxFlySpeed, minFlySpeed;
2124
private boolean sessionPersistentFlight, worldChangePersistentFlight, respawnPersistentFlight,
22-
gamemodeChangePersistentFlight;
25+
gamemodeChangePersistentFlight, hatRespectsCurseOfBinding;
2326
private int maxRenameCharacters;
27+
private static final HashSet<Material> disabledHatItems = new HashSet<>();
2428

2529
public void reloadConfigValues() {
2630
AdminHax.getInstance().reloadConfig();
@@ -34,6 +38,19 @@ public void reloadConfigValues() {
3438
respawnPersistentFlight = config.getBoolean("flight.persistent.respawn", true);
3539
gamemodeChangePersistentFlight = config.getBoolean("flight.persistent.gamemode-change", true);
3640
maxRenameCharacters = config.getInt("rename.max-characters", 50);
41+
hatRespectsCurseOfBinding = config.getBoolean("hat.respect-curse-of-binding", true);
42+
List<String> disabledItems = config.getStringList("hat.disabled-items");
43+
disabledHatItems.clear();
44+
if (!disabledItems.isEmpty()) {
45+
for (String string : disabledItems) {
46+
Material material = Material.getMaterial(string);
47+
if (material == null) {
48+
logger.info(string + " is not a valid material, please check your syntax");
49+
continue;
50+
}
51+
disabledHatItems.add(material);
52+
}
53+
}
3754
}
3855

3956
private float checkFloat(float defaultValue, String configPath, FileConfiguration config) {
@@ -91,4 +108,12 @@ public boolean isGamemodeChangePersistentFlight() {
91108
public int getMaxRenameCharacters() {
92109
return maxRenameCharacters;
93110
}
111+
112+
public boolean isHatRespectsCurseOfBinding() {
113+
return hatRespectsCurseOfBinding;
114+
}
115+
116+
public HashSet<Material> getDisabledHatItems(){
117+
return disabledHatItems;
118+
}
94119
}

src/main/java/simplexity/adminhax/config/Message.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ public enum Message {
77
ERROR_INVALID_NUMBER("error.invalid-number", "<red>Sorry, you did not enter a valid flyspeed, please try again</red>"),
88
ERROR_INVALID_PLAYER("error.invalid-player", "<red>That is not a valid player. Please check your spelling and try again</red>"),
99
ERROR_MUST_BE_PLAYER("error.must-be-player", "<red>You must be a player to run this command</red>"),
10-
ERROR_MUST_HOLD_ITEM("error.must-hold-item", "<red>You must be holding item to rename</red>"),
10+
ERROR_MUST_HOLD_ITEM_TO_RENAME("error.must-hold-item", "<red>You must be holding item to rename</red>"),
11+
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>"),
12+
ERROR_CURSE_OF_BINDING("error.curse-of-binding", "<red>You currently are wearing something with curse of binding! Sorry!</red>"),
13+
ERROR_HAT_NOT_ALLOWED("error.hat-not-allowed", "<red>Hats of this type are not allowed</red>"),
1114
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>"),
1215
ERROR_NO_PERMISSION("error.no-permission", "<red>You do not have permission to run this command</red>"),
1316
ERROR_NOT_ENOUGH_ARGUMENTS("error.not-enough-arguments", "<red>You did not provide enough arguments. Please check your syntax and try again</red>"),
1417
ERROR_NOT_IN_RANGE("error.not-in-range", "<red>Sorry, you must provide a number between <min> and <max></red>"),
18+
HAT_SUCCESSFUL("hat.success", "<green>Enjoy your new hat!</green>"),
1519
FEED_OTHER("feed.other", "<green>You have fed <target></green>"),
1620
FEED_SELF("feed.self", "<green>You have been fed</green>"),
1721
FLY_SET_BY_OTHER("fly.by-other", "<green>Your fly has been <value></green>"),

src/main/resources/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ flight:
1313
gamemode: true
1414
rename:
1515
max-characters: 50 #Going over 50 characters may cause unwanted visual effects such as the
16-
# tooltip going off the screen
16+
# tooltip going off the screen
17+
hat:
18+
respect-curse-of-binding: true
19+
disabled-items:
20+
- DEBUG_STICK

src/main/resources/plugin.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ author: Simplexity
66
api-version: '1.20'
77

88
commands:
9+
hat:
10+
permission: adminhax.commands.hat
11+
description: Allows players to put items on their helmet slot
912
flyspeed:
1013
permission: adminhax.commands.speed.fly
1114
description: Change your flight speed
@@ -53,7 +56,6 @@ permissions:
5356
adminhax.commands.godmode: true
5457
adminhax.commands.broadcast: true
5558
adminhax.commands.rename: true
56-
adminhax.reload: true
5759

5860
adminhax.commands.speed:
5961
description: Permissions for speed commands
@@ -149,7 +151,9 @@ permissions:
149151
adminhax.commands.rename.format.obfuscated:
150152
default: op
151153
description: Use obfuscated format
152-
154+
adminhax.commands.hat:
155+
default: op
156+
description: Allows a user to put items in their helmet slot with the /hat command
153157
adminhax.reload:
154158
default: op
155159
description: Reload the plugin

0 commit comments

Comments
 (0)