diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class index 07c1288a..dbd6f3ea 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/ActionSerializer.class differ diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.class index 507bdbd6..226bd6e1 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/config/WardrobeSettings.class differ diff --git a/common/build/resources/main/config.yml b/common/build/resources/main/config.yml index 1a3fb2d0..a00ca065 100644 --- a/common/build/resources/main/config.yml +++ b/common/build/resources/main/config.yml @@ -36,7 +36,7 @@ wardrobe: # how long in ticks until the wardrobe should be despawned despawn-delay: 40 # if cosmetics that the user have permissions for should be applied on close of wardrobe - apply-cosmetcics-on-close: true + apply-cosmetics-on-close: true open-sound: sound: # Play a sound name: "minecraft:block.chain.break" diff --git a/common/build/tmp/compileJava/previous-compilation-data.bin b/common/build/tmp/compileJava/previous-compilation-data.bin index 471523ed..6e89b7b9 100644 Binary files a/common/build/tmp/compileJava/previous-compilation-data.bin and b/common/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ActionSerializer.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ActionSerializer.java index e0a70ca6..186707ca 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ActionSerializer.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/ActionSerializer.java @@ -1,11 +1,9 @@ package io.github.fisher2911.hmccosmetics.config; -import com.comphenix.protocol.wrappers.EnumWrappers; import dev.triumphteam.gui.guis.GuiItem; import io.github.fisher2911.hmccosmetics.HMCCosmetics; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.CosmeticGui; -import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; import io.github.fisher2911.hmccosmetics.message.Message; import io.github.fisher2911.hmccosmetics.message.MessageHandler; import io.github.fisher2911.hmccosmetics.message.Placeholder; diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/TokenLoader.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/TokenLoader.java index 12e01dbf..ef402ea5 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/config/TokenLoader.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/config/TokenLoader.java @@ -11,12 +11,14 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import java.io.File; import java.nio.file.Path; +import java.util.List; public class TokenLoader { private static final String FILE_NAME = "tokens.yml"; private static final String TOKEN_PATH = "tokens"; private static final String ID_PATH = "id"; + private static final String COMMANDS_PATH = "commands"; private final HMCCosmetics plugin; private final CosmeticManager cosmeticManager; @@ -46,7 +48,8 @@ public class TokenLoader { if (armorItem == null) { this.plugin.getLogger().severe("Could not find armor item for token: " + id + " with id: " + id); } - this.cosmeticManager.addToken(new Token(itemStack, armorItem)); + final List commands = node.node(COMMANDS_PATH).getList(String.class); + this.cosmeticManager.addToken(new Token(itemStack, armorItem, commands)); } } catch (final ConfigurateException exception) { this.plugin.getLogger().severe("Error loading tokens!"); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/Token.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/Token.java index df5af81e..ca65ecff 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/Token.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/Token.java @@ -4,14 +4,18 @@ import io.github.fisher2911.hmccosmetics.util.Keys; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; +import java.util.List; + public class Token { private final ItemStack itemStack; private final ArmorItem armorItem; + private final List commands; - public Token(final ItemStack itemStack, final ArmorItem armorItem) { + public Token(final ItemStack itemStack, final ArmorItem armorItem, final List commands) { this.itemStack = itemStack; this.armorItem = armorItem; + this.commands = commands; Keys.setKey(this.itemStack, Keys.TOKEN_KEY, PersistentDataType.STRING, this.armorItem.getId()); } @@ -26,4 +30,8 @@ public class Token { public ArmorItem getArmorItem() { return armorItem; } + + public List getCommands() { + return commands; + } } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/TokenGui.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/TokenGui.java index 55ed98ca..87320e29 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/TokenGui.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/gui/TokenGui.java @@ -6,6 +6,7 @@ import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager; import io.github.fisher2911.hmccosmetics.message.Messages; import io.github.fisher2911.hmccosmetics.message.Placeholder; import io.github.fisher2911.hmccosmetics.user.User; +import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -72,7 +73,14 @@ public class TokenGui extends CosmeticGui { return; } final ArmorItem item = token.getArmorItem(); - inventory.setItem(this.cosmeticSlot, item.getItemStack(ArmorItem.Status.ALLOWED)); + inventory.setItem(this.cosmeticSlot, + this.applyPlaceholders( + user, + player, + item, + true + ) + ); return; } if (inHand != null && inHand.getType() != Material.AIR) { @@ -81,7 +89,7 @@ public class TokenGui extends CosmeticGui { } tokenItem = inventory.getItem(this.tokenSlot); token = this.cosmeticManager.getToken(tokenItem); - if (token == null) { + if (tokenItem == null || token == null) { event.setCancelled(true); return; } @@ -100,7 +108,12 @@ public class TokenGui extends CosmeticGui { tokenItem.setAmount(tokenItem.getAmount() - 1); inventory.setItem(this.tokenSlot, tokenItem); clicked.setAmount(0); - player.addAttachment(this.plugin, armorItem.getPermission(), true); + for (final String command : token.getCommands()) { + Bukkit.dispatchCommand( + Bukkit.getConsoleSender(), + command.replace(Placeholder.PLAYER, player.getName()) + ); + } this.messageHandler.sendMessage( player, Messages.TRADED_TOKEN, diff --git a/common/src/main/resources/tokens.yml b/common/src/main/resources/tokens.yml index 9d4f7543..25716c19 100644 --- a/common/src/main/resources/tokens.yml +++ b/common/src/main/resources/tokens.yml @@ -2,4 +2,6 @@ tokens: 1: id: colorful_hat material: emerald - name: "Colorful hat token" \ No newline at end of file + name: "Colorful hat token" + commands: + - "lp user %player% permission set cosmetics.colorful_hat"op \ No newline at end of file