personal tag toggles & fix some more stuff

This commit is contained in:
speedxx 2020-08-13 16:55:00 -04:00
parent e8d95df46f
commit 64c587627f
17 changed files with 129 additions and 17 deletions

View file

@ -6,7 +6,7 @@
<groupId>me.totalfreedom</groupId> <groupId>me.totalfreedom</groupId>
<artifactId>TFGuilds</artifactId> <artifactId>TFGuilds</artifactId>
<version>0.2.10</version> <version>0.2.11</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>TFGuilds</name> <name>TFGuilds</name>

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import me.totalfreedom.tfguilds.config.ConfigEntry; import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,4 +28,9 @@ public class Common
{ {
return in.replaceAll("%p%", PRIMARY + "").replaceAll("%s%", SECONDARY + ""); return in.replaceAll("%p%", PRIMARY + "").replaceAll("%s%", SECONDARY + "");
} }
public static void broadcast(String msg)
{
Bukkit.broadcastMessage(msg);
}
} }

View file

@ -23,6 +23,7 @@ public final class TFGuilds extends JavaPlugin
public Config config; public Config config;
public Config guilds; public Config guilds;
public Config players;
public TFMBridge bridge; public TFMBridge bridge;
@Override @Override
@ -31,6 +32,7 @@ public final class TFGuilds extends JavaPlugin
plugin = this; plugin = this;
config = new Config("config.yml"); config = new Config("config.yml");
guilds = new Config("guilds.yml"); guilds = new Config("guilds.yml");
players = new Config("players.yml");
bridge = new TFMBridge(); bridge = new TFMBridge();
loadCommands(); loadCommands();
loadListeners(); loadListeners();
@ -43,6 +45,7 @@ public final class TFGuilds extends JavaPlugin
plugin = null; plugin = null;
config.save(); config.save();
guilds.save(); guilds.save();
players.save();
GLog.info("Disabled " + this.getDescription().getFullName()); GLog.info("Disabled " + this.getDescription().getFullName());
} }

View file

@ -75,8 +75,9 @@ public class CreateSubcommand extends Common implements CommandExecutor
} }
Guild.createGuild(identifier, name, player); Guild.createGuild(identifier, name, player);
plugin.players.set(player.getName() + ".tag", true);
sender.sendMessage(tl(PREFIX + "Created a guild named \"" + GUtil.colorize(name) + "%p%\"!")); sender.sendMessage(tl(PREFIX + "Created a guild named \"" + GUtil.colorize(name) + "%p%\"!"));
Bukkit.broadcastMessage(GUtil.colorize(tl("%p%" + sender.getName() + " has created guild %p%&l" + name))); broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has created guild %p%&l" + name)));
return true; return true;
} }
} }

View file

@ -4,6 +4,7 @@ import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GLog; import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GUtil; import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -30,7 +31,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
return true; return true;
} }
Guild guild = Guild.getGuild(args[1]); Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!"); sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
@ -42,6 +43,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
guild.disband(); guild.disband();
GLog.info(sender.getName() + " deleted guild " + guild.getName()); GLog.info(sender.getName() + " deleted guild " + guild.getName());
sender.sendMessage(tl(PREFIX + "Disbanded \"" + GUtil.colorize(n) + "%p%\".")); sender.sendMessage(tl(PREFIX + "Disbanded \"" + GUtil.colorize(n) + "%p%\"."));
broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has disbanded guild %p%&l" + guild.getName())));
return true; return true;
} }
@ -69,7 +71,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
guild.disband(); guild.disband();
GLog.info(player.getName() + " deleted guild " + guild.getName()); GLog.info(player.getName() + " deleted guild " + guild.getName());
sender.sendMessage(tl(PREFIX + "You have disbanded your guild!")); sender.sendMessage(tl(PREFIX + "You have disbanded your guild!"));
Bukkit.broadcastMessage(GUtil.colorize(tl("%p%&l" + guild.getName() + "%p% has been disbanded"))); broadcast(GUtil.colorize(tl("%p%&l" + guild.getName() + "%p% has been disbanded")));
return true; return true;
} }
} }

View file

@ -6,10 +6,12 @@ import java.util.List;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil; import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
public class GuildCommand extends Common implements CommandExecutor, TabCompleter public class GuildCommand extends Common implements CommandExecutor, TabCompleter
{ {
@ -70,6 +72,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
return new SetDefaultRankSubcommand().onCommand(sender, command, label, args); return new SetDefaultRankSubcommand().onCommand(sender, command, label, args);
case "toggletags": case "toggletags":
return new ToggleTagsSubcommand().onCommand(sender, command, label, args); return new ToggleTagsSubcommand().onCommand(sender, command, label, args);
case "toggletag":
return new ToggleTagSubcommand().onCommand(sender, command, label, args);
} }
return false; return false;
} }
@ -85,7 +89,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
return Arrays.asList("addmod", "chat", "createrank", "create", return Arrays.asList("addmod", "chat", "createrank", "create",
"deleterank", "disband", "help", "home", "info", "invite", "deleterank", "disband", "help", "home", "info", "invite",
"join", "kick", "leave", "list", "motd", "removemod", "rename", "join", "kick", "leave", "list", "motd", "removemod", "rename",
"roster", "setowner", "setrank", "setstate", "tag", "tp", "setdefaultrank", "toggletags"); "roster", "setowner", "setrank", "setstate", "tag", "tp", "setdefaultrank",
"toggletags", "toggletag");
} }
else if (args.length == 2) else if (args.length == 2)
{ {
@ -130,7 +135,13 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "tp": case "tp":
{ {
return guild.getMembers(); for (Player player : Bukkit.getOnlinePlayers())
{
if (guild.getMembers().contains(player.getName()))
{
return guild.getMembers();
}
}
} }
case "disband": case "disband":
@ -145,9 +156,15 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "kick": case "kick":
{ {
if (guild.hasModerator(sender.getName())) for (Player player : Bukkit.getOnlinePlayers())
{ {
return guild.getOnlyMembers(); if (guild.getOnlyMembers().contains(player.getName()))
{
if (guild.hasModerator(sender.getName()))
{
return guild.getOnlyMembers();
}
}
} }
} }
@ -155,9 +172,15 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "addmod": case "addmod":
case "setowner": case "setowner":
{ {
if (guild.getOwner().equals(sender.getName())) for (Player player : Bukkit.getOnlinePlayers())
{ {
return guild.getMembers(); if (guild.getMembers().contains(player.getName()))
{
if (guild.getOwner().equals(sender.getName()))
{
return guild.getMembers();
}
}
} }
} }
} }

View file

@ -77,6 +77,7 @@ public class RenameSubcommand extends Common implements CommandExecutor
guild.setIdentifier(GUtil.flatten(newName)); guild.setIdentifier(GUtil.flatten(newName));
guild.setName(newName); guild.setName(newName);
guild.updateRankIdentifiers(); guild.updateRankIdentifiers();
guild.setTag(GUtil.colorize("&8[&7" + newName + "&8]"));
sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(newName) + "%p% as the new name of your guild%p%.")); sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(newName) + "%p% as the new name of your guild%p%."));
guild.broadcast(tl("%p%Your guild has been renamed to " + GUtil.colorize(newName) + "%p%.")); guild.broadcast(tl("%p%Your guild has been renamed to " + GUtil.colorize(newName) + "%p%."));
guild.save(); guild.save();

View file

@ -57,7 +57,7 @@ public class SetDefaultRankSubcommand extends Common implements CommandExecutor
guild.setDefaultRank(rank); guild.setDefaultRank(rank);
guild.save(); guild.save();
sender.sendMessage(tl(PREFIX + "Set " + rank + " as the default rank for your guild.")); sender.sendMessage(tl(PREFIX + "Set %s%\"" + rank + "\"%p% as the default rank for your guild."));
return true; return true;
} }
} }

View file

@ -33,6 +33,7 @@ public class TFGuildsCommand extends Common implements CommandExecutor
{ {
plugin.config.load(); plugin.config.load();
plugin.guilds.load(); plugin.guilds.load();
plugin.players.load();
GLog.info("All configs reloaded successfully"); GLog.info("All configs reloaded successfully");
sender.sendMessage(tl(PREFIX + "All configuration files have been reloaded successfully.")); sender.sendMessage(tl(PREFIX + "All configuration files have been reloaded successfully."));
return true; return true;

View file

@ -0,0 +1,45 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class ToggleTagSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
boolean enabled = plugin.players.getBoolean(player.getName() + ".tag");
if (!plugin.players.contains(player.getName()) || enabled)
{
plugin.players.set(player.getName() + ".tag", false);
plugin.players.save();
sender.sendMessage(tl(PREFIX + "Disabled personal guild tag."));
return true;
}
plugin.players.set(player.getName() + ".tag", true);
plugin.players.save();
sender.sendMessage(tl(PREFIX + "Enabled personal guild tag."));
return true;
}
}

View file

@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.config.ConfigEntry; import me.totalfreedom.tfguilds.config.ConfigEntry;
import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -21,12 +22,14 @@ public class ToggleTagsSubcommand extends Common implements CommandExecutor
if (enabled) if (enabled)
{ {
ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(false); ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(false);
sender.sendMessage(tl(PREFIX + "Disabled guild tags.")); sender.sendMessage(tl(PREFIX + "Globally disabled guild tags."));
broadcast(ChatColor.RED + sender.getName() + " - Globally disabling guild tags");
} }
else else
{ {
ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(true); ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(true);
sender.sendMessage(tl(PREFIX + "Enabled guild tags.")); sender.sendMessage(tl(PREFIX + "Globally enabled guild tags."));
broadcast(ChatColor.RED + sender.getName() + " - Globally enabling guild tags");
} }
return true; return true;
} }

View file

@ -8,7 +8,7 @@ public enum ConfigEntry
SCHEME_PRIMARY("scheme.primary"), SCHEME_PRIMARY("scheme.primary"),
SCHEME_SECONDARY("scheme.secondary"), SCHEME_SECONDARY("scheme.secondary"),
// Server // Server
SERVER_GUILD_CHAT_LOGGING_ENABLED("server.guild_chat_logging.enabled"), GUILD_CHAT_LOGGING_ENABLED("server.guild_chat_logging.enabled"),
GUILD_TAGS_ENABLED("server.guild_tags.enabled"); GUILD_TAGS_ENABLED("server.guild_tags.enabled");
private final String path; private final String path;

View file

@ -314,7 +314,7 @@ public class Guild
{ {
broadcast(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg)); broadcast(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg));
if (ConfigEntry.SERVER_GUILD_CHAT_LOGGING_ENABLED.getBoolean()) if (ConfigEntry.GUILD_CHAT_LOGGING_ENABLED.getBoolean())
{ {
GLog.info(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg)); GLog.info(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg));
} }

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.listener; package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.Common; import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry; import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild; import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank; import me.totalfreedom.tfguilds.guild.GuildRank;
@ -15,6 +16,8 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener public class ChatListener implements Listener
{ {
private static final TFGuilds plugin = TFGuilds.getPlugin();
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent e) public void onPlayerChat(AsyncPlayerChatEvent e)
{ {
@ -75,9 +78,22 @@ public class ChatListener implements Listener
if (guild.hasTag()) if (guild.hasTag())
{ {
e.setFormat(e.getFormat().replace(g.getTag(), "")); e.setFormat(e.getFormat().substring(g.getTag().length()));
} }
} }
} }
if (!plugin.players.getBoolean(player.getName() + ".tag") && plugin.players.contains(player.getName()))
{
if (!ConfigEntry.GUILD_TAGS_ENABLED.getBoolean())
{
return;
}
if (guild.hasTag())
{
e.setFormat(e.getFormat().substring(guild.getTag().length()));
}
}
} }
} }

View file

@ -3,12 +3,20 @@
# #
server: server:
# Log guild chat to console?
guild_chat_logging: guild_chat_logging:
enabled: true enabled: true
# Enable guild tags globally?
guild_tags_enabled: guild_tags_enabled:
enabled: true enabled: true
# Color scheme used for TFGuilds
scheme: scheme:
# Primary color
primary: GREEN primary: GREEN
# Secondary color
secondary: DARK_GREEN secondary: DARK_GREEN

View file

@ -0,0 +1,3 @@
#
# Player data for TFGuilds
#

View file

@ -7,7 +7,7 @@ description: A guilds plugin for the TotalFreedom server.
commands: commands:
guild: guild:
description: The main command of TFGuilds. description: The main command of TFGuilds.
usage: /<command> [list | help | create <name> | disband [name] | invite <player> | addmod <guild <player> | player> | removemod <guild <name> | name> | createrank <name> | setowner <guild <player> | player> | kick <guild <player> | player> | leave | setstate <guild <state> | state> | tp <player> | info [guild | player] | tag <set <tag> | clear> | join <guild> | chat [message] | roster [guild] | rename <name> | createrank <name> | deleterank <rank> | setrank <player> <rank | none> motd <set <motd> | clear> | home [set] | chat [message] | setdefaultrank <rank | none> | toggletags] usage: /<command> [list | help | create <name> | disband [name] | invite <player> | addmod <guild <player> | player> | removemod <guild <name> | name> | createrank <name> | setowner <guild <player> | player> | kick <guild <player> | player> | leave | setstate <guild <state> | state> | tp <player> | info [guild | player] | tag <set <tag> | clear> | join <guild> | chat [message] | roster [guild] | rename <name> | createrank <name> | deleterank <rank> | setrank <player> <rank | none> motd <set <motd> | clear> | home [set] | chat [message] | setdefaultrank <rank | none> | toggletags | toggletag]
aliases: [g] aliases: [g]
guildchat: guildchat:
description: Talk in chat with your guild. description: Talk in chat with your guild.