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>
<artifactId>TFGuilds</artifactId>
<version>0.2.10</version>
<version>0.2.11</version>
<packaging>jar</packaging>
<name>TFGuilds</name>

View file

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -27,4 +28,9 @@ public class Common
{
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 guilds;
public Config players;
public TFMBridge bridge;
@Override
@ -31,6 +32,7 @@ public final class TFGuilds extends JavaPlugin
plugin = this;
config = new Config("config.yml");
guilds = new Config("guilds.yml");
players = new Config("players.yml");
bridge = new TFMBridge();
loadCommands();
loadListeners();
@ -43,6 +45,7 @@ public final class TFGuilds extends JavaPlugin
plugin = null;
config.save();
guilds.save();
players.save();
GLog.info("Disabled " + this.getDescription().getFullName());
}

View file

@ -75,8 +75,9 @@ public class CreateSubcommand extends Common implements CommandExecutor
}
Guild.createGuild(identifier, name, player);
plugin.players.set(player.getName() + ".tag", true);
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;
}
}

View file

@ -4,6 +4,7 @@ import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
@ -30,7 +31,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
return true;
}
Guild guild = Guild.getGuild(args[1]);
Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
@ -42,6 +43,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
guild.disband();
GLog.info(sender.getName() + " deleted guild " + guild.getName());
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;
}
@ -69,7 +71,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
guild.disband();
GLog.info(player.getName() + " deleted guild " + guild.getName());
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;
}
}

View file

@ -6,10 +6,12 @@ import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
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);
case "toggletags":
return new ToggleTagsSubcommand().onCommand(sender, command, label, args);
case "toggletag":
return new ToggleTagSubcommand().onCommand(sender, command, label, args);
}
return false;
}
@ -85,7 +89,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
return Arrays.asList("addmod", "chat", "createrank", "create",
"deleterank", "disband", "help", "home", "info", "invite",
"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)
{
@ -129,9 +134,15 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
}
case "tp":
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (guild.getMembers().contains(player.getName()))
{
return guild.getMembers();
}
}
}
case "disband":
{
@ -144,16 +155,26 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
}
case "kick":
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (guild.getOnlyMembers().contains(player.getName()))
{
if (guild.hasModerator(sender.getName()))
{
return guild.getOnlyMembers();
}
}
}
}
case "removemod":
case "addmod":
case "setowner":
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (guild.getMembers().contains(player.getName()))
{
if (guild.getOwner().equals(sender.getName()))
{
@ -162,6 +183,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
}
}
}
}
}
return Collections.emptyList();
}
}

View file

@ -77,6 +77,7 @@ public class RenameSubcommand extends Common implements CommandExecutor
guild.setIdentifier(GUtil.flatten(newName));
guild.setName(newName);
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%."));
guild.broadcast(tl("%p%Your guild has been renamed to " + GUtil.colorize(newName) + "%p%."));
guild.save();

View file

@ -57,7 +57,7 @@ public class SetDefaultRankSubcommand extends Common implements CommandExecutor
guild.setDefaultRank(rank);
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;
}
}

View file

@ -33,6 +33,7 @@ public class TFGuildsCommand extends Common implements CommandExecutor
{
plugin.config.load();
plugin.guilds.load();
plugin.players.load();
GLog.info("All configs reloaded successfully");
sender.sendMessage(tl(PREFIX + "All configuration files have been reloaded successfully."));
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.config.ConfigEntry;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -21,12 +22,14 @@ public class ToggleTagsSubcommand extends Common implements CommandExecutor
if (enabled)
{
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
{
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;
}

View file

@ -8,7 +8,7 @@ public enum ConfigEntry
SCHEME_PRIMARY("scheme.primary"),
SCHEME_SECONDARY("scheme.secondary"),
// 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");
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));
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));
}

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank;
@ -15,6 +16,8 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent e)
{
@ -75,8 +78,21 @@ public class ChatListener implements Listener
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:
# Log guild chat to console?
guild_chat_logging:
enabled: true
# Enable guild tags globally?
guild_tags_enabled:
enabled: true
# Color scheme used for TFGuilds
scheme:
# Primary color
primary: GREEN
# Secondary color
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:
guild:
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]
guildchat:
description: Talk in chat with your guild.