9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-31 12:56:39 +00:00

Fixed placeholders

This commit is contained in:
Fisher2911
2022-03-06 17:02:48 -05:00
parent 8da9100dd3
commit 1fcbe27d6a
9 changed files with 33 additions and 9 deletions

View File

@@ -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"

View File

@@ -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;

View File

@@ -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<String> 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!");

View File

@@ -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<String> commands;
public Token(final ItemStack itemStack, final ArmorItem armorItem) {
public Token(final ItemStack itemStack, final ArmorItem armorItem, final List<String> 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<String> getCommands() {
return commands;
}
}

View File

@@ -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,

View File

@@ -2,4 +2,6 @@ tokens:
1:
id: colorful_hat
material: emerald
name: "<green>Colorful hat token"
name: "<green>Colorful hat token"
commands:
- "lp user %player% permission set cosmetics.colorful_hat"op