use of com.loohp.interactivechat.objectholders.ICPlaceholder in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class DiscordCommands method reload.
public void reload() {
try {
Guild guild = discordsrv.getMainGuild();
String memberLabel = InteractiveChatDiscordSrvAddon.plugin.discordMemberLabel;
String memberDescription = InteractiveChatDiscordSrvAddon.plugin.discordMemberDescription;
String slotLabel = InteractiveChatDiscordSrvAddon.plugin.discordSlotLabel;
String slotDescription = InteractiveChatDiscordSrvAddon.plugin.discordSlotDescription;
guild.retrieveCommands().complete().forEach(each -> {
switch(each.getName()) {
case RESOURCEPACK_LABEL:
if (InteractiveChatDiscordSrvAddon.plugin.resourcepackCommandIsMainServer) {
each.delete().complete();
}
break;
case PLAYERLIST_LABEL:
if (InteractiveChatDiscordSrvAddon.plugin.playerlistCommandIsMainServer) {
each.delete().complete();
}
break;
case ITEM_LABEL:
case ITEM_OTHER_LABEL:
if (InteractiveChatDiscordSrvAddon.plugin.shareItemCommandIsMainServer) {
each.delete().complete();
}
break;
case INVENTORY_LABEL:
case INVENTORY_OTHER_LABEL:
if (InteractiveChatDiscordSrvAddon.plugin.shareInvCommandIsMainServer) {
each.delete().complete();
}
break;
case ENDERCHEST_LABEL:
case ENDERCHEST_OTHER_LABEL:
if (InteractiveChatDiscordSrvAddon.plugin.shareEnderCommandIsMainServer) {
each.delete().complete();
}
break;
}
});
if (InteractiveChatDiscordSrvAddon.plugin.resourcepackCommandEnabled && InteractiveChatDiscordSrvAddon.plugin.resourcepackCommandIsMainServer) {
guild.upsertCommand(RESOURCEPACK_LABEL, ChatColorUtils.stripColor(InteractiveChatDiscordSrvAddon.plugin.resourcepackCommandDescription)).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.resourcepackCommandRoles))).queue();
});
}
if (InteractiveChatDiscordSrvAddon.plugin.playerlistCommandEnabled && InteractiveChatDiscordSrvAddon.plugin.playerlistCommandIsMainServer) {
guild.upsertCommand(PLAYERLIST_LABEL, ChatColorUtils.stripColor(InteractiveChatDiscordSrvAddon.plugin.playerlistCommandDescription)).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.playerlistCommandRoles))).queue();
});
}
Optional<ICPlaceholder> optItemPlaceholder = InteractiveChat.placeholderList.values().stream().filter(each -> each.getKeyword().equals(InteractiveChat.itemPlaceholder)).findFirst();
if (InteractiveChatDiscordSrvAddon.plugin.shareItemCommandEnabled && optItemPlaceholder.isPresent() && InteractiveChatDiscordSrvAddon.plugin.shareItemCommandIsMainServer) {
String itemDescription = ChatColorUtils.stripColor(optItemPlaceholder.get().getDescription());
SubcommandData mainhandSubcommand = new SubcommandData("mainhand", itemDescription);
SubcommandData offhandSubcommand = new SubcommandData("offhand", itemDescription);
SubcommandData hotbarSubcommand = new SubcommandData("hotbar", itemDescription).addOptions(new OptionData(OptionType.INTEGER, slotLabel, slotDescription, true).setRequiredRange(1, 9));
SubcommandData inventorySubcommand = new SubcommandData("inventory", itemDescription).addOptions(new OptionData(OptionType.INTEGER, slotLabel, slotDescription, true).setRequiredRange(1, 41));
SubcommandData armorSubcommand = new SubcommandData("armor", itemDescription).addOptions(new OptionData(OptionType.STRING, slotLabel, slotDescription, true).addChoice("head", "head").addChoice("chest", "chest").addChoice("legs", "legs").addChoice("feet", "feet"));
SubcommandData enderSubcommand = new SubcommandData("ender", itemDescription).addOptions(new OptionData(OptionType.INTEGER, slotLabel, slotDescription, true).setRequiredRange(1, 27));
guild.upsertCommand(ITEM_LABEL, ChatColorUtils.stripColor(optItemPlaceholder.get().getDescription())).addSubcommands(mainhandSubcommand).addSubcommands(offhandSubcommand).addSubcommands(hotbarSubcommand).addSubcommands(inventorySubcommand).addSubcommands(armorSubcommand).addSubcommands(enderSubcommand).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.shareItemCommandSelfRoles))).queue();
});
if (InteractiveChatDiscordSrvAddon.plugin.shareItemCommandAsOthers) {
SubcommandData mainhandOtherSubcommand = new SubcommandData("mainhand", itemDescription).addOption(OptionType.USER, memberLabel, memberDescription, true);
SubcommandData offhandOtherSubcommand = new SubcommandData("offhand", itemDescription).addOption(OptionType.USER, memberLabel, memberDescription, true);
SubcommandData hotbarOtherSubcommand = new SubcommandData("hotbar", itemDescription).addOptions(new OptionData(OptionType.INTEGER, slotLabel, slotDescription, true).setRequiredRange(1, 9)).addOption(OptionType.USER, memberLabel, memberDescription, true);
SubcommandData inventoryOtherSubcommand = new SubcommandData("inventory", itemDescription).addOptions(new OptionData(OptionType.INTEGER, slotLabel, slotDescription, true).setRequiredRange(1, 41)).addOption(OptionType.USER, memberLabel, memberDescription, true);
SubcommandData armorOtherSubcommand = new SubcommandData("armor", itemDescription).addOptions(new OptionData(OptionType.STRING, slotLabel, slotDescription, true).addChoice("head", "head").addChoice("chest", "chest").addChoice("legs", "legs").addChoice("feet", "feet")).addOption(OptionType.USER, memberLabel, memberDescription, true);
SubcommandData enderOtherSubcommand = new SubcommandData("ender", itemDescription).addOptions(new OptionData(OptionType.INTEGER, slotLabel, slotDescription, true).setRequiredRange(1, 27)).addOption(OptionType.USER, memberLabel, memberDescription, true);
guild.upsertCommand(ITEM_OTHER_LABEL, ChatColorUtils.stripColor(optItemPlaceholder.get().getDescription())).addSubcommands(mainhandOtherSubcommand).addSubcommands(offhandOtherSubcommand).addSubcommands(hotbarOtherSubcommand).addSubcommands(inventoryOtherSubcommand).addSubcommands(armorOtherSubcommand).addSubcommands(enderOtherSubcommand).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.shareItemCommandOthersRoles))).queue();
});
}
}
Optional<ICPlaceholder> optInvPlaceholder = InteractiveChat.placeholderList.values().stream().filter(each -> each.getKeyword().equals(InteractiveChat.invPlaceholder)).findFirst();
if (InteractiveChatDiscordSrvAddon.plugin.shareInvCommandEnabled && optInvPlaceholder.isPresent() && InteractiveChatDiscordSrvAddon.plugin.shareInvCommandIsMainServer) {
guild.upsertCommand(INVENTORY_LABEL, ChatColorUtils.stripColor(optInvPlaceholder.get().getDescription())).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.shareInvCommandSelfRoles))).queue();
});
if (InteractiveChatDiscordSrvAddon.plugin.shareInvCommandAsOthers) {
guild.upsertCommand(INVENTORY_OTHER_LABEL, ChatColorUtils.stripColor(optInvPlaceholder.get().getDescription())).addOption(OptionType.USER, memberLabel, memberDescription, true).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.shareInvCommandOthersRoles))).queue();
});
}
}
Optional<ICPlaceholder> optEnderPlaceholder = InteractiveChat.placeholderList.values().stream().filter(each -> each.getKeyword().equals(InteractiveChat.enderPlaceholder)).findFirst();
if (InteractiveChatDiscordSrvAddon.plugin.shareEnderCommandEnabled && optEnderPlaceholder.isPresent() && InteractiveChatDiscordSrvAddon.plugin.shareEnderCommandIsMainServer) {
guild.upsertCommand(ENDERCHEST_LABEL, ChatColorUtils.stripColor(optEnderPlaceholder.get().getDescription())).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.shareEnderCommandSelfRoles))).queue();
});
if (InteractiveChatDiscordSrvAddon.plugin.shareEnderCommandAsOthers) {
guild.upsertCommand(ENDERCHEST_OTHER_LABEL, ChatColorUtils.stripColor(optEnderPlaceholder.get().getDescription())).addOption(OptionType.USER, memberLabel, memberDescription, true).setDefaultEnabled(false).queue(command -> {
command.updatePrivileges(guild, JDAUtils.toWhitelistedCommandPrivileges(guild, JDAUtils.toRoles(guild, InteractiveChatDiscordSrvAddon.plugin.shareEnderCommandOthersRoles))).queue();
});
}
}
} catch (ErrorResponseException e) {
if (e.getResponse().code == 50001) {
throw new DiscordCommandRegistrationException("Scope \"applications.commands\" missing in discord bot application.\nCheck the Q&A section in https://www.spigotmc.org/resources/83917/ for more information", e);
}
throw new DiscordCommandRegistrationException(e);
}
}
use of com.loohp.interactivechat.objectholders.ICPlaceholder in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class OutboundToDiscordEvents method onDiscordToGame.
@Subscribe(priority = ListenerPriority.LOW)
public void onDiscordToGame(DiscordGuildMessagePostProcessEvent event) {
Debug.debug("Triggering onDiscordToGame");
InteractiveChatDiscordSrvAddon.plugin.messagesCounter.incrementAndGet();
github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component component = event.getMinecraftMessage();
if (InteractiveChatDiscordSrvAddon.plugin.escapePlaceholdersFromDiscord) {
Debug.debug("onDiscordToGame escaping placeholders");
for (ICPlaceholder placeholder : InteractiveChat.placeholderList.values()) {
component = component.replaceText(github.scarsz.discordsrv.dependencies.kyori.adventure.text.TextReplacementConfig.builder().match(placeholder.getKeyword()).replacement("\\" + placeholder.getKeyword()).build());
}
event.setMinecraftMessage(component);
}
}
use of com.loohp.interactivechat.objectholders.ICPlaceholder in project InteractiveChat by LOOHP.
the class InteractiveChatVelocity method onBungeeChat.
@Subscribe(order = PostOrder.LATE)
public void onBungeeChat(PlayerChatEvent event) {
if (!event.getResult().isAllowed()) {
return;
}
Player player = event.getPlayer();
UUID uuid = player.getUniqueId();
String message = event.getMessage();
if (!player.getCurrentServer().isPresent()) {
return;
}
String newMessage = event.getMessage();
boolean hasInteractiveChat = false;
BackendInteractiveChatData data = serverInteractiveChatInfo.get(player.getCurrentServer().get().getServerInfo().getName());
if (data != null) {
hasInteractiveChat = data.hasInteractiveChat();
}
boolean usage = false;
outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
for (ICPlaceholder icplaceholder : serverPlaceholders) {
if (icplaceholder.getKeyword().matcher(message).find()) {
usage = true;
break outer;
}
}
}
if (newMessage.startsWith("/")) {
if (usage && hasInteractiveChat) {
for (String parsecommand : InteractiveChatVelocity.parseCommands) {
if (newMessage.matches(parsecommand)) {
String command = newMessage.trim();
outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
for (ICPlaceholder icplaceholder : serverPlaceholders) {
Pattern placeholder = icplaceholder.getKeyword();
Matcher matcher = placeholder.matcher(command);
if (matcher.find()) {
String uuidmatch = "<cmd=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(command.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
command = command.substring(0, matcher.start()) + uuidmatch + command.substring(matcher.end());
if (command.length() > 256) {
command = command.substring(0, 256);
}
event.setResult(ChatResult.message(command));
break outer;
}
}
}
break;
}
}
}
} else {
if (usage && InteractiveChatBungee.useAccurateSenderFinder && hasInteractiveChat) {
outer: for (List<ICPlaceholder> serverPlaceholders : placeholderList.values()) {
for (ICPlaceholder icplaceholder : serverPlaceholders) {
Pattern placeholder = icplaceholder.getKeyword();
Matcher matcher = placeholder.matcher(message);
if (matcher.find()) {
String uuidmatch = "<chat=" + uuid + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
if (message.length() > 256) {
message = message.substring(0, 256);
}
event.setResult(ChatResult.message(message));
break outer;
}
}
}
}
proxyServer.getScheduler().buildTask(plugin, () -> {
Map<String, Long> messages = forwardedMessages.get(uuid);
if (messages != null && messages.remove(newMessage) != null) {
try {
PluginMessageSendingVelocity.sendMessagePair(uuid, newMessage);
} catch (IOException e) {
e.printStackTrace();
}
}
}).delay(100, TimeUnit.MILLISECONDS).schedule();
}
}
use of com.loohp.interactivechat.objectholders.ICPlaceholder in project InteractiveChat by LOOHP.
the class Commands method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!label.equalsIgnoreCase("interactivechat") && !label.equalsIgnoreCase("ic")) {
return true;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.AQUA + "InteractiveChat written by LOOHP!");
sender.sendMessage(ChatColor.GOLD + "You are running InteractiveChat version: " + InteractiveChat.plugin.getDescription().getVersion());
return true;
}
if (args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("interactivechat.reload")) {
InteractiveChat.closeSharedInventoryViews();
ConfigManager.reloadConfig();
InteractiveChat.placeholderCooldownManager.reloadPlaceholders();
PlayerUtils.resetAllPermissionCache();
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> InteractiveChat.playerDataManager.reload());
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.reloadBungeeConfig(System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
}
}
sender.sendMessage(InteractiveChat.reloadPluginMessage);
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("update")) {
if (sender.hasPermission("interactivechat.update")) {
sender.sendMessage(ChatColor.AQUA + "[InteractiveChat] InteractiveChat written by LOOHP!");
sender.sendMessage(ChatColor.GOLD + "[InteractiveChat] You are running InteractiveChat version: " + InteractiveChat.plugin.getDescription().getVersion());
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
UpdaterResponse version = Updater.checkUpdate();
if (version.getResult().equals("latest")) {
if (version.isDevBuildLatest()) {
sender.sendMessage(ChatColor.GREEN + "[InteractiveChat] You are running the latest version!");
} else {
Updater.sendUpdateMessage(sender, version.getResult(), version.getSpigotPluginId(), true);
}
} else {
Updater.sendUpdateMessage(sender, version.getResult(), version.getSpigotPluginId());
}
});
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("mentiontoggle")) {
if (sender.hasPermission("interactivechat.mention.toggle")) {
if (args.length == 1) {
if (sender instanceof Player) {
Player player = (Player) sender;
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
if (pd.isMentionDisabled()) {
pd.setMentionDisabled(false);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
sender.sendMessage(InteractiveChat.mentionEnable);
} else {
pd.setMentionDisabled(true);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
sender.sendMessage(InteractiveChat.mentionDisable);
}
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.signalPlayerDataReload(System.currentTimeMillis(), player.getUniqueId());
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
sender.sendMessage(InteractiveChat.noConsoleMessage);
}
} else {
if (sender.hasPermission("interactivechat.mention.toggle.others")) {
Player player = Bukkit.getPlayer(args[1]);
if (player != null) {
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
if (pd.isMentionDisabled()) {
pd.setMentionDisabled(false);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
sender.sendMessage(InteractiveChat.mentionEnable);
} else {
pd.setMentionDisabled(true);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
sender.sendMessage(InteractiveChat.mentionDisable);
}
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.signalPlayerDataReload(System.currentTimeMillis(), player.getUniqueId());
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
sender.sendMessage(InteractiveChat.invalidPlayerMessage);
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("setinvdisplaylayout")) {
if (sender.hasPermission("interactivechat.module.inventory.setlayout")) {
try {
if (args.length == 1) {
sender.sendMessage(InteractiveChat.notEnoughArgs);
} else if (args.length == 2) {
if (sender instanceof Player) {
int layout = Integer.parseInt(args[1]);
if (!InventoryDisplay.LAYOUTS.contains(layout)) {
throw new NumberFormatException();
}
Player player = (Player) sender;
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
pd.setInventoryDisplayLayout(layout);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
sender.sendMessage(InteractiveChat.setInvDisplayLayout.replace("{Layout}", layout + ""));
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.signalPlayerDataReload(System.currentTimeMillis(), player.getUniqueId());
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
sender.sendMessage(InteractiveChat.noConsoleMessage);
}
} else {
if (sender.hasPermission("interactivechat.module.inventory.setlayout.others")) {
Player player = Bukkit.getPlayer(args[2]);
if (player != null) {
int layout = Integer.parseInt(args[1]);
if (!InventoryDisplay.LAYOUTS.contains(layout)) {
throw new NumberFormatException();
}
PlayerData pd = InteractiveChat.playerDataManager.getPlayerData(player);
pd.setInventoryDisplayLayout(layout);
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> pd.save());
sender.sendMessage(InteractiveChat.setInvDisplayLayout.replace("{Layout}", layout + ""));
if (InteractiveChat.bungeecordMode) {
try {
BungeeMessageSender.signalPlayerDataReload(System.currentTimeMillis(), player.getUniqueId());
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
sender.sendMessage(InteractiveChat.invalidPlayerMessage);
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
}
} catch (NumberFormatException e) {
sender.sendMessage(InteractiveChat.invalidArgs);
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("list")) {
try {
if (sender.hasPermission("interactivechat.list")) {
int start = 0;
int end = InteractiveChat.placeholderList.size();
if (args.length > 1) {
start = Integer.parseInt(args[1]) - 1;
if (start < 0) {
start = 0;
}
}
if (args.length > 2) {
end = Integer.parseInt(args[2]);
if (end < 0) {
end = InteractiveChat.placeholderList.size();
}
}
InteractiveChatAPI.sendMessageUnprocessed(sender, LegacyComponentSerializer.legacySection().deserialize(InteractiveChat.listPlaceholderHeader));
String body = InteractiveChat.listPlaceholderBody;
List<Component> items = new ArrayList<>();
if (sender.hasPermission("interactivechat.list.all")) {
int i = 0;
for (ICPlaceholder placeholder : InteractiveChat.placeholderList.values()) {
i++;
String text = body.replace("{Order}", i + "").replace("{Keyword}", placeholder.getName()).replace("{Description}", placeholder.getDescription());
items.add(LegacyComponentSerializer.legacySection().deserialize(text));
}
} else {
int i = 0;
for (ICPlaceholder placeholder : InteractiveChat.placeholderList.values()) {
if ((placeholder.isBuildIn() && sender.hasPermission(placeholder.getPermission())) || (!placeholder.isBuildIn() && (sender.hasPermission(placeholder.getPermission()) || !InteractiveChat.useCustomPlaceholderPermissions))) {
i++;
String text = body.replace("{Order}", i + "").replace("{Keyword}", placeholder.getName()).replace("{Description}", placeholder.getDescription());
items.add(LegacyComponentSerializer.legacySection().deserialize(text));
}
}
}
for (int i = start; i < end && i < items.size(); i++) {
InteractiveChatAPI.sendMessageUnprocessed(sender, items.get(i));
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
} catch (Exception e) {
sender.sendMessage(InteractiveChat.invalidArgs);
}
return true;
}
if (args[0].equalsIgnoreCase("parse")) {
if (sender.hasPermission("interactivechat.parse")) {
if (sender instanceof Player) {
String str = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
Player player = (Player) sender;
Optional<ICPlayer> icplayer = Optional.of(ICPlayerFactory.getICPlayer(player));
Bukkit.getScheduler().runTaskAsynchronously(InteractiveChat.plugin, () -> {
String text = str;
try {
long unix = System.currentTimeMillis();
if (InteractiveChat.chatAltColorCode.isPresent() && player.hasPermission("interactivechat.chatcolor.translate")) {
text = ChatColorUtils.translateAlternateColorCodes(InteractiveChat.chatAltColorCode.get(), str);
}
Component component = Component.text(text);
if (InteractiveChat.usePlayerName) {
component = PlayernameDisplay.process(component, icplayer, player, unix);
}
if (InteractiveChat.useItem) {
component = ItemDisplay.process(component, icplayer, player, unix);
}
if (InteractiveChat.useInventory) {
component = InventoryDisplay.process(component, icplayer, player, unix);
}
if (InteractiveChat.useEnder) {
component = EnderchestDisplay.process(component, icplayer, player, unix);
}
component = CustomPlaceholderDisplay.process(component, icplayer, player, InteractiveChat.placeholderList.values(), unix);
if (InteractiveChat.clickableCommands) {
component = CommandsDisplay.process(component);
}
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_16) && InteractiveChat.fontTags) {
if (PlayerUtils.hasPermission(player.getUniqueId(), "interactivechat.customfont.translate", true, 250)) {
component = ComponentFont.parseFont(component);
}
}
String json = InteractiveChatComponentSerializer.gson().serialize(component);
if (json.length() > InteractiveChat.packetStringMaxLength) {
InteractiveChatAPI.sendMessageUnprocessed(sender, Component.text(text));
} else {
InteractiveChatAPI.sendMessageUnprocessed(sender, component);
}
} catch (Exception e) {
e.printStackTrace();
}
});
} else {
sender.sendMessage(String.join(" ", Arrays.copyOfRange(args, 1, args.length)));
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (args[0].equalsIgnoreCase("chat")) {
if (sender.hasPermission("interactivechat.chat")) {
if (args.length > 1) {
if (sender instanceof Player) {
String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
PacketContainer packet = InteractiveChat.protocolManager.createPacket(PacketType.Play.Client.CHAT);
packet.getStrings().write(0, message);
try {
InteractiveChat.protocolManager.recieveClientPacket((Player) sender, packet);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} else {
sender.sendMessage(InteractiveChat.noConsoleMessage);
}
}
} else {
sender.sendMessage(InteractiveChat.noPermissionMessage);
}
return true;
}
if (sender instanceof Player && args.length > 1) {
Player player = (Player) sender;
switch(args[0].toLowerCase()) {
case "viewinv":
{
PlayerData data = InteractiveChat.playerDataManager.getPlayerData(player);
String hash = args[1];
if (data == null || data.getInventoryDisplayLayout() == 0) {
Inventory inv = InteractiveChat.inventoryDisplay.get(hash);
if (inv != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.openInventory(inv));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
} else {
Inventory inv = InteractiveChat.inventoryDisplay1Upper.get(hash);
Inventory inv2 = InteractiveChat.inventoryDisplay1Lower.get(hash);
if (inv != null && inv2 != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> {
player.openInventory(inv);
InventoryUtils.sendFakePlayerInventory(player, inv2, true, false);
InteractiveChat.viewingInv1.put(player.getUniqueId(), hash);
});
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
}
break;
}
case "viewender":
{
Inventory inv = InteractiveChat.enderDisplay.get(args[1]);
if (inv != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.openInventory(inv));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
break;
}
case "viewitem":
{
Inventory inv = InteractiveChat.itemDisplay.get(args[1]);
if (inv != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> player.openInventory(inv));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
break;
}
case "viewmap":
ItemStack map = InteractiveChat.mapDisplay.get(args[1]);
if (map != null) {
Bukkit.getScheduler().runTask(InteractiveChat.plugin, () -> MapViewer.showMap(player, map));
} else {
player.sendMessage(PlaceholderAPI.setPlaceholders(player, InteractiveChat.invExpiredMessage));
}
break;
}
return true;
}
sender.sendMessage(ChatColorUtils.translateAlternateColorCodes('&', Bukkit.spigot().getConfig().getString("messages.unknown-command")));
return true;
}
use of com.loohp.interactivechat.objectholders.ICPlaceholder in project InteractiveChat by LOOHP.
the class InteractiveChatAPI method markSender.
/**
* Marks a message with a tag that InteractiveChat understands which identifies the sender of the message.<br>
* Only have an effect if UseAccurateSenderParser is enabled in the config.
*
* @param message
* @param sender The {@link UUID} of the {@link Player} or {@link ICPlayer}
* @return the sender marked message
* @throws IllegalStateException if a sender is already marked in the given message
*/
public static String markSender(String message, UUID sender) {
if (InteractiveChat.useAccurateSenderFinder) {
if (Registry.ID_PATTERN.matcher(message).find()) {
throw new IllegalStateException("Sender is already marked in the given message: " + message);
}
for (ICPlaceholder icplaceholder : InteractiveChat.placeholderList.values()) {
Pattern placeholder = icplaceholder.getKeyword();
Matcher matcher = placeholder.matcher(message);
if (matcher.find()) {
int start = matcher.start();
if ((start < 1 || message.charAt(start - 1) != '\\') || (start > 1 && message.charAt(start - 1) == '\\' && message.charAt(start - 2) == '\\')) {
String uuidmatch = "<chat=" + sender + ":" + Registry.ID_ESCAPE_PATTERN.matcher(message.substring(matcher.start(), matcher.end())).replaceAll("\\>") + ":>";
message = message.substring(0, matcher.start()) + uuidmatch + message.substring(matcher.end());
break;
}
}
}
}
return message;
}
Aggregations