2020-06-18 22:24:02 +00:00
|
|
|
package me.totalfreedom.tfguilds.util;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import me.totalfreedom.tfguilds.TFGuilds;
|
2020-06-20 21:55:33 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2020-06-18 22:24:02 +00:00
|
|
|
|
2020-06-22 17:51:32 +00:00
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
2020-06-18 22:24:02 +00:00
|
|
|
import java.util.Arrays;
|
2020-06-22 17:51:32 +00:00
|
|
|
import java.util.Date;
|
2020-06-20 21:23:53 +00:00
|
|
|
import java.util.HashMap;
|
2020-06-18 22:24:02 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class GUtil
|
|
|
|
{
|
|
|
|
public static TFGuilds plugin = TFGuilds.plugin;
|
2020-06-20 21:55:33 +00:00
|
|
|
public static HashMap<String, String> invitedPlayers = new HashMap<>();
|
2020-06-18 22:24:02 +00:00
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
|
|
|
|
players.add(owner.getName());
|
|
|
|
plugin.guilds.set("guilds." + guildName + ".members", players);
|
2020-06-22 17:51:32 +00:00
|
|
|
plugin.guilds.set("guilds." + guildName + ".tag", GUtil.color("&8[&7" + guildName + "&8]&r "));
|
|
|
|
|
|
|
|
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
|
|
|
Date date = new Date();
|
|
|
|
plugin.guilds.set("guilds." + guildName + ".created", dateFormat.format(date));
|
2020-06-18 22:24:02 +00:00
|
|
|
|
|
|
|
plugin.guilds.save();
|
|
|
|
GLog.info(owner.getName() + " has created a new guild: " + guildName);
|
|
|
|
}
|
|
|
|
|
2020-06-19 02:59:47 +00:00
|
|
|
public static void deleteGuild(CommandSender owner)
|
|
|
|
{
|
|
|
|
GLog.info("Removing guilds.yml data for " + getGuild((Player) owner));
|
|
|
|
plugin.guilds.set("guilds." + getGuild((Player) owner), null);
|
|
|
|
plugin.guilds.save();
|
|
|
|
}
|
|
|
|
|
2020-06-20 21:55:33 +00:00
|
|
|
public static void invitePlayer(Player player, String guild, int seconds)
|
2020-06-20 21:23:53 +00:00
|
|
|
{
|
|
|
|
if (seconds > 0)
|
|
|
|
{
|
2020-06-20 21:55:33 +00:00
|
|
|
invitedPlayers.put(player.getName(), guild);
|
2020-06-20 21:23:53 +00:00
|
|
|
player.sendMessage(ChatColor.GREEN + "To accept or decline, type /inviteguild accept or /inviteguild deny");
|
|
|
|
player.sendMessage(ChatColor.GREEN + "You have " + seconds + " seconds to accept the request before it gets declined automatically.");
|
|
|
|
}
|
2020-06-20 21:55:33 +00:00
|
|
|
new BukkitRunnable()
|
2020-06-20 21:23:53 +00:00
|
|
|
{
|
2020-06-20 21:55:33 +00:00
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
invitedPlayers.remove(player.getName());
|
|
|
|
player.sendMessage(ChatColor.RED + "Your invitation has expired.");
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, seconds * 20);
|
2020-06-20 21:23:53 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 22:24:02 +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");
|
|
|
|
}
|
|
|
|
|
2020-06-22 17:51:32 +00:00
|
|
|
public static String getTimeCreated(String guildName)
|
|
|
|
{
|
|
|
|
return plugin.guilds.getString("guilds." + guildName + ".created");
|
|
|
|
}
|
|
|
|
|
2020-06-18 22:24:02 +00:00
|
|
|
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");
|
|
|
|
if (guildMembers != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!a)
|
|
|
|
return null;
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
2020-06-22 21:48:42 +00:00
|
|
|
public static String getGuild(String arg)
|
|
|
|
{
|
|
|
|
String g = "";
|
|
|
|
boolean a = false;
|
|
|
|
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
|
|
|
|
if (guildMembers != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for (String guild : guildMembers.getKeys(false))
|
|
|
|
{
|
|
|
|
if (guild.equals(arg))
|
|
|
|
{
|
|
|
|
a = true;
|
|
|
|
g = guild;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.fillInStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!a)
|
|
|
|
return null;
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
2020-06-18 22:24:02 +00:00
|
|
|
public static String getOwner(String guildName)
|
|
|
|
{
|
|
|
|
return plugin.guilds.getString("guilds." + guildName + ".owner");
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
if (isGuildMember(player, guildName))
|
|
|
|
{
|
|
|
|
player.sendMessage(sent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
|
|
|
|
"admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "tca", "sta", "sa");
|
|
|
|
|
|
|
|
public static String color(String s)
|
|
|
|
{
|
|
|
|
return ChatColor.translateAlternateColorCodes('&', s);
|
|
|
|
}
|
2020-06-15 21:39:52 +00:00
|
|
|
}
|