Added messages to config files

This commit is contained in:
Elikill58 committed 2024-11-24 12:49:11 +01:00
1 parent 4b0c8ef6ff
commit b1dac86e96
4 files changed
+50 -22

No files matched your search

+18 -14
View File
@@ -3,22 +3,22 @@ package me.dadus33.chatitem;
import java.util.List;
import me.dadus33.chatitem.chatmanager.ChatManager;
import me.dadus33.chatitem.utils.Colors;
public enum ItemSlot {
HAND(true, "", false),
HELMET(false, "helmet", false),
CHESTPLATE(false, "chestplate", false),
LEGGINGS(false, "leggings", false),
BOOTS(false, "boots", false),
INVENTORY(false, "inventory", true),
ENDERCHEST(false, "enderchest", true);
HAND("", false),
HELMET("helmet", false),
CHESTPLATE("chestplate", false),
LEGGINGS("leggings", false),
BOOTS("boots", false),
INVENTORY("inventory", true),
ENDERCHEST("enderchest", true);
private final boolean basic, command;
private final boolean command;
private final String key;
private ItemSlot(boolean basic, String key, boolean command) {
this.basic = basic;
private ItemSlot(String key, boolean command) {
this.command = command;
this.key = key;
}
@@ -28,7 +28,7 @@ public enum ItemSlot {
}
public boolean isBasic() {
return basic;
return key.equalsIgnoreCase("");
}
public boolean isCommand() {
@@ -36,15 +36,19 @@ public enum ItemSlot {
}
public List<String> getPlaceholders() {
return ChatItem.getInstance().getConfig().getStringList(basic ? "general.placeholders" : "general.other-placeholders." + key + ".keys");
return ChatItem.getInstance().getConfig().getStringList(isBasic() ? "general.placeholders" : "general.other-placeholders." + key + ".keys");
}
public boolean isEnabled() {
return basic || ChatItem.getInstance().getConfig().getBoolean("general.other-placeholders." + key + ".enabled", true);
return isBasic() || ChatItem.getInstance().getConfig().getBoolean("general.other-placeholders." + key + ".enabled", true);
}
public boolean isDenyIfNoItem() {
return ChatItem.getInstance().getConfig().getBoolean("general" + (basic ? "" : ".other-placeholders." + key) + ".deny-if-no-item", true);
return ChatItem.getInstance().getConfig().getBoolean("general" + (isBasic() ? "" : ".other-placeholders." + key) + ".deny-if-no-item", true);
}
public String getShowMessage() {
return Colors.color(ChatItem.getInstance().getConfig().getString("general" + (isBasic() ? "" : ".other-placeholders." + key) + ".show", ""));
}
public boolean hasPlaceholders(String message) {
@@ -51,4 +51,9 @@ public class ChatAction {
public ItemStack getItem() {
return item == null ? new ItemStack(Material.AIR) : item;
}
@Override
public String toString() {
return "ChatAction[slot=" + slot + ",command=" + command + ",item=" + item + ",origin=" + origin + "]";
}
}
@@ -13,7 +13,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.dadus33.chatitem.ChatItem;
import me.dadus33.chatitem.ItemSlot;
@@ -23,6 +22,7 @@ import me.dadus33.chatitem.chatmanager.ChatManager;
import me.dadus33.chatitem.invsee.InvShower;
import me.dadus33.chatitem.listeners.InventoryListener;
import me.dadus33.chatitem.utils.Colors;
import me.dadus33.chatitem.utils.ItemUtils;
import me.dadus33.chatitem.utils.Messages;
import me.dadus33.chatitem.utils.Utils;
import net.md_5.bungee.api.chat.ClickEvent;
@@ -58,9 +58,9 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
} else if (args[0].equalsIgnoreCase("inv") && ChatItem.getInstance().getStorage().cmdShow) {
sendCommandFormatFrom(p, ItemSlot.INVENTORY, Bukkit.getOnlinePlayers());
} else if (args[0].equalsIgnoreCase("show") && ChatItem.getInstance().getStorage().cmdShow) {
sendCommandFormatFrom(p, ItemSlot.getItemSlotByKey(args.length == 0 ? "" : args[1]), Arrays.asList(p));
sendCommandFormatFrom(p, ItemSlot.getItemSlotByKey(args.length <= 1 ? "" : args[1]), Arrays.asList(p));
} else if (args[0].equalsIgnoreCase("broadcast") && ChatItem.getInstance().getStorage().cmdBroadcast) {
sendCommandFormatFrom(p, ItemSlot.getItemSlotByKey(args.length == 0 ? "" : args[1]), Bukkit.getOnlinePlayers());
sendCommandFormatFrom(p, ItemSlot.getItemSlotByKey(args.length <= 1 ? "" : args[1]), Bukkit.getOnlinePlayers());
} else if (args[0].equalsIgnoreCase("link") || args[0].equalsIgnoreCase("links")) {
ConfigurationSection config = ChatItem.getInstance().getConfig()
.getConfigurationSection("messages.chatitem-cmd.links");
@@ -126,9 +126,18 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
}
private void sendCommandFormatFrom(Player p, ItemSlot slot, Collection<? extends Player> receivers) {
ItemStack item = ChatManager.getUsableItem(p, slot);
if(slot == null) {
Messages.sendMessage(p, "chatitem-cmd.help");
return;
}
ChatAction action = ChatManager.getChatAction(slot, p);
ChatItem.debug("Action: " + action);
if(action.isItem() && ItemUtils.isEmpty(action.getItem())) {
Messages.sendMessage(p, "empty-item");
return;
}
for(Player all : receivers)
ChatItem.getPlatform().sendMessage(all, p, new ChatAction(slot, p, item), ChatItem.getInstance().getStorage().commandFormat.replace("%name%", p.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
ChatItem.getPlatform().sendMessage(all, p, action, slot.getShowMessage().replace("%name%", p.getName()).replace("%item%", ChatManager.SEPARATOR + ""));
}
private void sendCheckSelectMessage(Player p, String testing) {
@@ -156,7 +165,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] arg) {
List<String> list = new ArrayList<>();
String prefix = arg[arg.length - 1].toLowerCase(Locale.ROOT);
if(arg.length <= 2) {
if(arg.length <= 1) {
if(sender.hasPermission("chatitem.reload")) {
for (String s : Arrays.asList("admin", "reload", "select"))
if (prefix.isEmpty() || s.startsWith(prefix))
@@ -172,7 +181,7 @@ public class ChatItemCommand implements CommandExecutor, TabExecutor {
for (String s : Arrays.asList("help", "link"))
if (prefix.isEmpty() || s.startsWith(prefix))
list.add(s);
} else if(arg[1].equalsIgnoreCase("show") || arg[1].equalsIgnoreCase("broadcast")) {
} else if(arg[0].equalsIgnoreCase("show") || arg[0].equalsIgnoreCase("broadcast")) {
for (ItemSlot slot : ItemSlot.values())
if (prefix.isEmpty() || slot.getKey().startsWith(prefix))
list.add(slot.getKey());
+11 -1
View File
@@ -38,6 +38,7 @@ general:
keys:
- "[head]"
- "{head}"
show: "&6%name%'s helmet is %item%"
# Show the CHESTPLATE not the enderchest or whatever
chestplate:
enabled: true
@@ -45,6 +46,7 @@ general:
keys:
- "[chest]"
- "{chest}"
show: "&6%name%'s chestplate is %item%"
# Show leggings
leggings:
enabled: true
@@ -52,6 +54,7 @@ general:
keys:
- "[legs]"
- "{legs}"
show: "&6%name%'s leggings are %item%"
# Show what is their feets
boots:
enabled: true
@@ -59,6 +62,7 @@ general:
keys:
- "[feet]"
- "{feet}"
show: "&6%name%'s boots are %item%"
inventory:
enabled: true
deny-if-no-item: true
@@ -67,6 +71,7 @@ general:
keys:
- "[inv]"
- "{inv}"
show: "&6%name%'s inventory is %item%"
enderchest:
enabled: true
deny-if-no-item: true
@@ -75,6 +80,7 @@ general:
keys:
- "[ec]"
- "{ec}"
show: "&6%name%'s enderchest is %item%"
# The format of the item placeholders.
name-format: "&b&l&o{name}{amount}&r"
@@ -118,7 +124,7 @@ general:
- "&7Failed to parse item for your client"
# Format used with using /chatitem show
command-format: "&6%name%'s item is %item%"
show: "&6%name%'s item is %item%"
# Here you can set when the players should see the no-permission message (defined in the 'Messages' section bellow).
# 'normal' dictates whether the user should see the message when using the placeholder in normal chat, and 'command'
@@ -145,8 +151,10 @@ general:
sub-commands:
broadcast: true
show: true
# This part of config is in WIP. Please ignore it.
ownformatter:
format: "%name%: %message%"
# End of WIP config section.
@@ -155,6 +163,8 @@ messages:
# The message sent if showing off hands is disabled and the user isn't holding an item.
# Only works if 'General.deny-if-no-item' is set to true!
deny-message: "&c&lYou have no item in hand!"
# Send for some command to prevent wrong messages
empty-item: "&cCan't show empty item"
# The message sent after the configuration file is successfully reloaded.
reload-success: "&b&lSuccessful reload!"
# The message sent if the player is on cooldown from sending a placeholder.