TFGuilds/src/main/java/totalfreedom/tfguilds/util/GUtil.java

118 lines
3.8 KiB
Java
Raw Normal View History

2020-06-15 21:39:52 +00:00
package totalfreedom.tfguilds.util;
2020-06-18 18:05:49 +00:00
import org.bukkit.Bukkit;
2020-06-16 02:50:29 +00:00
import org.bukkit.ChatColor;
2020-06-15 21:39:52 +00:00
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
2020-06-17 21:08:35 +00:00
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
2020-06-15 21:39:52 +00:00
import totalfreedom.tfguilds.TFGuilds;
2020-06-18 18:05:49 +00:00
import java.util.Arrays;
2020-06-15 21:39:52 +00:00
import java.util.List;
public class GUtil
{
public static TFGuilds plugin = TFGuilds.plugin;
public static boolean isConsole(CommandSender sender)
{
return sender instanceof ConsoleCommandSender;
}
public static void createGuild(CommandSender owner, String guildName)
{
plugin.guilds.set("guilds." + guildName, guildName);
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
plugin.guilds.set("guilds." + guildName + ".members", owner.getName());
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
players.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".members", players);
plugin.guilds.save();
GLog.info(owner.getName() + " has created a new guild: " + guildName);
}
2020-06-16 02:50:29 +00:00
2020-06-17 21:08:35 +00:00
public static void setTag(String tag, String guildName)
{
plugin.guilds.set("guilds." + guildName + ".tag", tag);
plugin.guilds.save();
}
public static String getTag(String guildName)
{
return plugin.guilds.getString("guilds." + guildName + ".tag");
}
public static boolean hasTag(String guildName)
{
return plugin.guilds.contains("guilds." + guildName + ".tag");
}
public static String getGuild(Player player)
{
String g = "";
boolean a = false;
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
2020-06-18 18:05:49 +00:00
if (guildMembers != null)
2020-06-17 21:08:35 +00:00
{
2020-06-18 18:05:49 +00:00
try
2020-06-17 21:08:35 +00:00
{
2020-06-18 18:05:49 +00:00
for (String guild : guildMembers.getKeys(false))
{
List<String> members = plugin.guilds.getStringList("guilds." + guild + ".members");
if (members.contains(player.getName()))
{
a = true;
g = guild;
}
}
}
catch (Exception e)
{
e.fillInStackTrace();
2020-06-17 21:08:35 +00:00
}
}
if (!a)
return null;
return g;
}
public static String getOwner(String guildName)
{
return plugin.guilds.getString("guilds." + guildName + ".owner");
}
2020-06-18 18:05:49 +00:00
public static List<String> getMember(String guildName)
{
return plugin.guilds.getStringList("guilds." + guildName + ".members");
}
public static boolean isGuildMember(Player player, String guildName)
{
return getMember(guildName).contains(player.getName().toLowerCase());
}
public static void guildChat(CommandSender sender, String message, String guildName)
{
2020-06-18 20:56:26 +00:00
String sent = ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "GC" + ChatColor.DARK_GRAY + "] " + getTag(guildName) + ChatColor.BLUE + sender
.getName() + ChatColor.GRAY + ": " + ChatColor.AQUA + message;
GLog.info(sent);
2020-06-18 18:05:49 +00:00
for (Player player : Bukkit.getOnlinePlayers())
{
if (isGuildMember(player, guildName))
{
2020-06-18 20:56:26 +00:00
player.sendMessage(sent);
2020-06-18 18:05:49 +00:00
}
}
}
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
"admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "tca", "sta", "sa");
2020-06-16 02:50:29 +00:00
public static String color(String s)
{
return ChatColor.translateAlternateColorCodes('&', s);
}
2020-06-15 21:39:52 +00:00
}