use of net.md_5.bungee.api.chat.BaseComponent in project Statz by Staartvin.
the class CommandsManager method onCommand.
/* (non-Javadoc)
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (args.length == 0) {
// If admin has predefined a list of stats, show that instead of the list view of all stats.
if (plugin.getConfigHandler().useCustomList() && sender instanceof Player) {
Player player = (Player) sender;
// Show custom stats that admin has provided in the config.
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
private String playerName;
private UUID uuid;
private int pageNumber;
private Runnable init(String playerName, UUID uuid, int pageNumber) {
this.playerName = playerName;
this.uuid = uuid;
this.pageNumber = pageNumber - 1;
return this;
}
public void run() {
plugin.getDataManager().sendStatisticsList(sender, playerName, uuid, pageNumber, plugin.getConfigHandler().getCustomList());
}
}.init(sender.getName(), player.getUniqueId(), 0));
return true;
} else {
// Just show information about the plugin.
sender.sendMessage(ChatColor.BLUE + "-----------------------------------------------------");
sender.sendMessage(ChatColor.GOLD + "Developed by: " + ChatColor.GRAY + plugin.getDescription().getAuthors());
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.GRAY + plugin.getDescription().getVersion());
sender.sendMessage(Lang.STATZ_HELP_COMMAND.getConfigValue());
}
return true;
}
final String action = args[0];
List<String> suggestions = new ArrayList<>();
List<String> bestSuggestions = new ArrayList<>();
// Go through every list and check if that action is in there.
for (final Entry<List<String>, StatzCommand> entry : registeredCommands.entrySet()) {
String suggestion = StatzUtil.findClosestSuggestion(action, entry.getKey());
if (suggestion != null) {
suggestions.add(suggestion);
}
for (final String actionString : entry.getKey()) {
if (actionString.equalsIgnoreCase(action)) {
// Check if player has proper permission
if (!this.hasPermission(entry.getValue().getPermission(), sender)) {
return true;
}
return entry.getValue().onCommand(sender, cmd, label, args);
}
}
}
// Search for suggestions if argument was not found
for (String suggestion : suggestions) {
String[] split = suggestion.split(";");
int editDistance = Integer.parseInt(split[1]);
// Only give suggestion if edit distance is small
if (editDistance <= 2) {
bestSuggestions.add(split[0]);
}
}
sender.sendMessage(Lang.COMMAND_NOT_RECOGNIZED.getConfigValue());
if (!bestSuggestions.isEmpty()) {
BaseComponent[] builder = new ComponentBuilder("Did you perhaps mean ").color(net.md_5.bungee.api.ChatColor.DARK_AQUA).append("/statz ").color(net.md_5.bungee.api.ChatColor.GREEN).append(StatzUtil.seperateList(bestSuggestions, "or")).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("These are suggestions based on your input.").create())).append("?").color(net.md_5.bungee.api.ChatColor.DARK_AQUA).create();
if (sender instanceof Player) {
Player p = (Player) sender;
p.spigot().sendMessage(builder);
} else {
sender.sendMessage(ChatColor.DARK_AQUA + "Did you perhaps mean " + ChatColor.GREEN + "/statz " + StatzUtil.seperateList(bestSuggestions, "or") + ChatColor.DARK_AQUA + "?");
}
}
sender.sendMessage(Lang.STATZ_HELP_COMMAND.getConfigValue());
return true;
}
use of net.md_5.bungee.api.chat.BaseComponent in project Minigames by AddstarMC.
the class MessageManager method sendClickedCommandMessage.
public static void sendClickedCommandMessage(CommandSender target, String command, String identifier, String key, Object... args) {
BaseComponent init = getMessageStart(MinigameMessageType.INFO);
TextComponent message = new TextComponent(getMessage(identifier, key, args));
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
sendMessage(target, init, message);
}
use of net.md_5.bungee.api.chat.BaseComponent in project Minigames by AddstarMC.
the class MessageManager method sendMessage.
public static void sendMessage(CommandSender target, MinigameMessageType type, String identifier, String key, Object... args) {
BaseComponent init = getMessageStart(type);
TextComponent message = new TextComponent(getMessage(identifier, key, args));
sendMessage(target, init, message);
}
use of net.md_5.bungee.api.chat.BaseComponent in project Minigames by AddstarMC.
the class MessageManager method broadcast.
/**
* Broadcasts a server message without a permission.
*
* @param message - The message to be broadcasted (Can be manipulated with MinigamesBroadcastEvent)
* @param minigame - The Minigame this broadcast is related to.
* @param prefixColor - The color to be used in the prefix.
*/
public static void broadcast(String message, Minigame minigame, org.bukkit.ChatColor prefixColor) {
BaseComponent init = new TextComponent("[Minigames]");
init.setColor(prefixColor.asBungee());
TextComponent m = new TextComponent(" " + message);
MinigamesBroadcastEvent ev = new MinigamesBroadcastEvent(prefixColor + "[Minigames]" + org.bukkit.ChatColor.WHITE, message, minigame);
Bukkit.getPluginManager().callEvent(ev);
// Only send broadcast if event was not cancelled and is not empty
if (!ev.isCancelled() && !ev.getMessage().isEmpty()) {
if (PaperLib.isPaper()) {
Bukkit.getServer().broadcast(init, m);
} else {
Bukkit.getServer().spigot().broadcast(init, m);
}
}
}
use of net.md_5.bungee.api.chat.BaseComponent in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method getLore.
@Override
public List<String> getLore(ItemTag item) {
if (!item.getItemMeta().hasLore()) {
return null;
}
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
ListTag list = ((net.minecraft.nbt.CompoundTag) nmsItemStack.getTag().get("display")).getList("Lore", 8);
List<String> outList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
BaseComponent[] lineComponent = ComponentSerializer.parse(list.getString(i));
outList.add(FormattedTextHelper.stringify(lineComponent, ChatColor.WHITE));
}
return outList;
}
Aggregations