This commit is contained in:
Super_ 2020-06-17 17:08:35 -04:00
parent 00c0bd26ae
commit 2e16d257e5
4 changed files with 139 additions and 1 deletions

View file

@ -0,0 +1,62 @@
package totalfreedom.tfguilds.command;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import totalfreedom.tfguilds.util.GBase;
import totalfreedom.tfguilds.util.GUtil;
public class GuildTagCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0 || args.length > 2)
{
return false;
}
Player player = (Player) sender;
if (GUtil.isConsole(player))
{
sender.sendMessage(ChatColor.RED + "You are not allowed to run this command.");
return true;
}
String guild = GUtil.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You aren't the owner of your guild!");
return true;
}
if (args.length == 2)
{
if (args[0].equalsIgnoreCase("set"))
{
GUtil.setTag(args[1], guild);
sender.sendMessage(ChatColor.GRAY + "Guild tag set to \"" + GUtil.color(args[1]) + ChatColor.GRAY + "\"");
return true;
}
return false;
}
if (!args[0].equalsIgnoreCase("clear"))
{
return false;
}
GUtil.setTag(null, guild);
sender.sendMessage(ChatColor.GRAY + "Removed your guild's tag.");
return true;
}
}

View file

@ -0,0 +1,30 @@
package totalfreedom.tfguilds.listener;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import totalfreedom.tfguilds.TFGuilds;
import totalfreedom.tfguilds.util.GUtil;
public class ChatManager implements Listener
{
private final TFGuilds plugin;
public ChatManager()
{
this.plugin = TFGuilds.plugin;
}
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent e)
{
Player player = e.getPlayer();
String guild = GUtil.getGuild(player);
if (guild == null)
return;
if (!GUtil.hasTag(guild))
return;
e.setFormat(GUtil.color(GUtil.getTag(guild)) + " " + ChatColor.RESET + e.getFormat());
}
}

View file

@ -3,6 +3,8 @@ package totalfreedom.tfguilds.util;
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 totalfreedom.tfguilds.TFGuilds;
import java.util.List;
@ -30,6 +32,46 @@ public class GUtil
GLog.info(owner.getName() + " has created a new guild: " + guildName);
}
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");
for (String guild : guildMembers.getKeys(false))
{
List<String> members = plugin.guilds.getStringList("guilds." + guild + ".members");
if (members.contains(player.getName()))
{
a = true;
g = guild;
}
}
if (!a)
return null;
return g;
}
public static String getOwner(String guildName)
{
return plugin.guilds.getString("guilds." + guildName + ".owner");
}
public static String color(String s)
{
return ChatColor.translateAlternateColorCodes('&', s);

View file

@ -12,4 +12,8 @@ commands:
createguild:
description: Creates a guild
usage: /<command> <name>
aliases: [guildcreate]
aliases: [guildcreate]
guildtag:
description: Modify your guild's tag
usage: /<command> <set <tag> | clear>
aliases: [gtag]