mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-27 19:09:19 +00:00
Can now have hats / backpacks open dye-menu when they are equipped / clicked on in the menu
This commit is contained in:
@@ -190,6 +190,9 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
itemFlags(itemFlags).
|
||||
build();
|
||||
|
||||
final String openMenu = openMenuNode.getString(
|
||||
Utils.replaceIfNull(OPEN_MENU, ""));
|
||||
|
||||
try {
|
||||
final ArmorItem.Type cosmeticType = ArmorItem.Type.valueOf(
|
||||
Utils.replaceIfNull(
|
||||
@@ -201,6 +204,10 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
|
||||
return new ArmorItem(
|
||||
itemStack,
|
||||
event -> {
|
||||
final HMCCosmetics plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
plugin.getCosmeticsMenu().openMenu(openMenu, event.getWhoClicked());
|
||||
},
|
||||
Utils.replaceIfNull(idNode.getString(), ""),
|
||||
lockedLore,
|
||||
permission,
|
||||
@@ -208,9 +215,6 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
dyeable);
|
||||
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
final String openMenu = openMenuNode.getString(
|
||||
Utils.replaceIfNull(OPEN_MENU, ""));
|
||||
|
||||
return dev.triumphteam.gui.builder.item.ItemBuilder.from(
|
||||
itemStack).
|
||||
asGuiItem(event -> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.fisher2911.hmccosmetics.gui;
|
||||
|
||||
import dev.triumphteam.gui.components.GuiAction;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
@@ -13,6 +14,7 @@ import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@@ -99,7 +101,7 @@ public class CosmeticGui {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setUserArmor(player, user, armorItem);
|
||||
this.setUserArmor(player, user, armorItem, event, armorItem.getAction());
|
||||
}
|
||||
)
|
||||
);
|
||||
@@ -114,7 +116,9 @@ public class CosmeticGui {
|
||||
private void setUserArmor(
|
||||
final HumanEntity player,
|
||||
final User user,
|
||||
final ArmorItem armorItem) {
|
||||
final ArmorItem armorItem,
|
||||
final InventoryClickEvent event,
|
||||
final GuiAction<InventoryClickEvent> actionIfSet) {
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
@@ -123,8 +127,20 @@ public class CosmeticGui {
|
||||
final ArmorItem.Type type = armorItem.getType();
|
||||
|
||||
switch (type) {
|
||||
case HAT -> user.setOrUnsetHat(armorItem, this.messageHandler);
|
||||
case BACKPACK -> user.setOrUnsetBackpack(armorItem, this.messageHandler);
|
||||
case HAT -> {
|
||||
final boolean set = user.setOrUnsetHat(armorItem, this.messageHandler);
|
||||
if (set) {
|
||||
actionIfSet.execute(event);
|
||||
player.sendMessage("Set");
|
||||
}
|
||||
}
|
||||
case BACKPACK -> {
|
||||
final boolean set = user.setOrUnsetBackpack(armorItem, this.messageHandler);
|
||||
if (set) {
|
||||
actionIfSet.execute(event);
|
||||
player.sendMessage("Set");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,18 +74,18 @@ public class CosmeticsMenu {
|
||||
|
||||
if (!Path.of(this.plugin.getDataFolder().getPath(),
|
||||
"menus",
|
||||
MAIN_MENU).toFile().exists()) {
|
||||
MAIN_MENU + ".yml").toFile().exists()) {
|
||||
this.plugin.saveResource(
|
||||
new File("menus", MAIN_MENU).getPath(),
|
||||
new File("menus", MAIN_MENU + ".yml").getPath(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
if (!Path.of(this.plugin.getDataFolder().getPath(),
|
||||
"menus",
|
||||
DYE_MENU).toFile().exists()) {
|
||||
DYE_MENU + ".yml").toFile().exists()) {
|
||||
this.plugin.saveResource(
|
||||
new File("menus", DYE_MENU).getPath(),
|
||||
new File("menus", DYE_MENU + ".yml").getPath(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -42,12 +42,13 @@ public class User {
|
||||
this.playerArmor.setBackpack(backpack);
|
||||
}
|
||||
|
||||
public void setOrUnsetBackpack(final ArmorItem backpack, final MessageHandler messageHandler) {
|
||||
// return true if backpack was set
|
||||
public boolean setOrUnsetBackpack(final ArmorItem backpack, final MessageHandler messageHandler) {
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (backpack.getId().equals(this.playerArmor.getBackpack().getId())) {
|
||||
@@ -64,7 +65,7 @@ public class User {
|
||||
Messages.REMOVED_BACKPACK
|
||||
);
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.setBackpack(backpack);
|
||||
@@ -72,6 +73,8 @@ public class User {
|
||||
player,
|
||||
Messages.SET_BACKPACK
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,12 +83,13 @@ public class User {
|
||||
this.getPlayer().getEquipment().setHelmet(this.playerArmor.getHat().getItemStack());
|
||||
}
|
||||
|
||||
public void setOrUnsetHat(final ArmorItem hat, final MessageHandler messageHandler) {
|
||||
// return true if hat was set
|
||||
public boolean setOrUnsetHat(final ArmorItem hat, final MessageHandler messageHandler) {
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hat.getId().equals(this.playerArmor.getHat().getId())) {
|
||||
@@ -101,7 +105,7 @@ public class User {
|
||||
player,
|
||||
Messages.REMOVED_HAT
|
||||
);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.setHat(hat);
|
||||
@@ -109,6 +113,8 @@ public class User {
|
||||
player,
|
||||
Messages.SET_HAT
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
|
||||
Reference in New Issue
Block a user