fix guildtag, add guildchat

This commit is contained in:
speedxx 2020-06-18 14:05:49 -04:00
parent 521b4da919
commit b1df1c2ab2
7 changed files with 125 additions and 12 deletions

View file

@ -1,10 +1,14 @@
package totalfreedom.tfguilds;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import totalfreedom.tfguilds.bridge.TFMBridge;
import totalfreedom.tfguilds.command.CreateGuildCommand;
import totalfreedom.tfguilds.command.GuildChatCommand;
import totalfreedom.tfguilds.command.GuildTagCommand;
import totalfreedom.tfguilds.command.TfGuildsCommand;
import totalfreedom.tfguilds.config.Config;
import totalfreedom.tfguilds.listener.ChatManager;
import totalfreedom.tfguilds.util.GLog;
public final class TFGuilds extends JavaPlugin
@ -19,6 +23,7 @@ public final class TFGuilds extends JavaPlugin
{
plugin = this;
enableCommands();
enableListeners();
config = new Config(plugin, "config.yml");
guilds = new Config(plugin, "guilds.yml");
tfmb = new TFMBridge();
@ -37,5 +42,13 @@ public final class TFGuilds extends JavaPlugin
{
this.getCommand("tfguilds").setExecutor(new TfGuildsCommand());
this.getCommand("createguild").setExecutor(new CreateGuildCommand());
this.getCommand("guildtag").setExecutor(new GuildTagCommand());
this.getCommand("guildchat").setExecutor(new GuildChatCommand());
}
private void enableListeners()
{
PluginManager manager = this.getServer().getPluginManager();
manager.registerEvents(new ChatManager(), this);
}
}

View file

@ -41,7 +41,7 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
return true;
}
if (guild.equals(args[0]))
if (guild.equals(args[0].toLowerCase()))
{
player.sendMessage(ChatColor.RED + "A guild with that name already exists.");
return true;
@ -54,6 +54,16 @@ public class CreateGuildCommand extends GBase implements CommandExecutor
}
}
for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
{
if (args[0].toLowerCase().contains(blacklisted))
{
sender.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
GUtil.createGuild(sender, args[0]);
sender.sendMessage(ChatColor.GREEN + "Successfully created a guild named " + args[0]);
return true;

View file

@ -0,0 +1,40 @@
package totalfreedom.tfguilds.command;
import org.apache.commons.lang.StringUtils;
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 GuildChatCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0)
{
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;
}
GUtil.guildChat(sender, StringUtils.join(args, " "), guild);
return true;
}
}

View file

@ -44,8 +44,14 @@ public class GuildTagCommand extends GBase implements CommandExecutor
{
if (args[0].equalsIgnoreCase("set"))
{
GUtil.setTag(args[1], guild);
sender.sendMessage(ChatColor.GRAY + "Guild tag set to \"" + GUtil.color(args[1]) + ChatColor.GRAY + "\"");
if (!args[1].toLowerCase().equals(guild))
{
sender.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name.");
return true;
}
GUtil.setTag(GUtil.color(args[1]), guild);
sender.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.color(args[1]) + ChatColor.GREEN + "\"");
return true;
}
return false;
@ -55,7 +61,7 @@ public class GuildTagCommand extends GBase implements CommandExecutor
{
return false;
}
GUtil.setTag(null, guild);
GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r"), guild);
sender.sendMessage(ChatColor.GRAY + "Removed your guild's tag.");
return true;
}

View file

@ -24,7 +24,10 @@ public class ChatManager implements Listener
if (guild == null)
return;
if (!GUtil.hasTag(guild))
return;
{
GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r"), guild);
}
e.setFormat(GUtil.color(GUtil.getTag(guild)) + " " + ChatColor.RESET + e.getFormat());
}
}

View file

@ -1,5 +1,6 @@
package totalfreedom.tfguilds.util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@ -7,6 +8,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import totalfreedom.tfguilds.TFGuilds;
import java.util.Arrays;
import java.util.List;
public class GUtil
@ -53,13 +55,23 @@ public class GUtil
String g = "";
boolean a = false;
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
for (String guild : guildMembers.getKeys(false))
if (guildMembers != null)
{
List<String> members = plugin.guilds.getStringList("guilds." + guild + ".members");
if (members.contains(player.getName()))
try
{
a = true;
g = guild;
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)
@ -72,6 +84,31 @@ public class GUtil
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)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (isGuildMember(player, guildName))
{
player.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "GC" + ChatColor.DARK_GRAY + "] " + getTag(guildName) + " " + ChatColor.BLUE + sender
.getName() + ChatColor.GRAY + ": " + ChatColor.AQUA + message);
}
}
}
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);

View file

@ -17,3 +17,7 @@ commands:
description: Modify your guild's tag
usage: /<command> <set <tag> | clear>
aliases: [gtag]
guildchat:
description: Speak to your guild
usage: /<command> <message>
aliases: [gchat]