Remaining tickets completed

FS-96, FS-270, FS-271, FS-272, FS-282 and FS-303 are included in this commit
This commit is contained in:
Nathan Curran 2021-06-15 23:19:25 +10:00
parent 8263e8b20f
commit b0f4017cde
No known key found for this signature in database
GPG key ID: B3A964B30C2E56B8
17 changed files with 441 additions and 82 deletions

View file

@ -111,5 +111,8 @@ public class TFGuilds extends JavaPlugin
subCommands.put("tag", new TagSubCommand());
subCommands.put("list", new ListSubCommand());
subCommands.put("help", new HelpSubCommand());
subCommands.put("mchat", new ModChatSubCommand());
subCommands.put("notag", new NoTagSubCommand());
subCommands.put("togglechat", new ToggleChatSubCommand());
}
}

View file

@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -61,4 +62,22 @@ public class TFMBridge
}
return getTfm().al.isVanished(player.getName());
}
public String getTag(Player player)
{
if (getTfm() == null)
{
return null;
}
return ChatColor.stripColor(getTfm().pl.getPlayer(player).getTag());
}
public void clearTag(Player player)
{
if (getTfm() == null)
{
return;
}
getTfm().pl.getPlayer(player).setTag(null);
}
}

View file

@ -29,7 +29,7 @@ public class ChatSubCommand extends Common implements SubCommand
if (args.length >= 2)
{
String message = StringUtils.join(args, " ", 1, args.length);
guild.chat(playerSender, message);
guild.chat(playerSender, message, false);
return;
}

View file

@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -27,7 +28,7 @@ public class DisbandSubCommand extends Common implements SubCommand
return;
}
Guild guild = Guild.getGuild(playerSender);
Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");

View file

@ -1,9 +1,12 @@
package me.totalfreedom.tfguilds.command;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@ -43,6 +46,100 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
{
Guild guild = null;
if (sender instanceof Player)
{
guild = Guild.getGuild((Player)sender);
}
if (args.length == 1)
{
return TFGuilds.getPlugin().getSubCommands();
}
else if (args.length == 2)
{
switch (args[0])
{
case "home":
{
return Collections.singletonList("set");
}
case "info":
case "join":
case "roster":
{
return Guild.getGuildNames();
}
case "toggletag":
{
if (!tfmBridge.isAdmin(sender))
{
return Collections.emptyList();
}
return GUtil.getPlayerNames();
}
case "motd":
case "tag":
{
return Arrays.asList("set", "clear");
}
case "setstate":
{
return Arrays.asList("OPEN", "CLOSED", "INVITE_ONLY");
}
case "invite":
{
return GUtil.getPlayerNames();
}
case "deleterank":
case "setdefaultrank":
{
if (guild != null && guild.getOwner().equals(((Player)sender).getUniqueId()))
{
return guild.getRankNames();
}
}
case "tp":
{
return guild != null ? guild.getMemberNames() : Collections.emptyList();
}
case "disband":
{
if (!tfmBridge.isAdmin(sender))
{
return Collections.emptyList();
}
return Guild.getGuildNames();
}
case "kick":
{
if (guild != null && guild.isModerator((Player)sender))
{
return guild.getMemberOnlyNames();
}
}
case "removemod":
case "addmod":
case "setowner":
{
if (guild != null && guild.getOwner().equals(((Player)sender).getUniqueId()))
{
return guild.getMemberNames();
}
}
}
}
return Collections.emptyList();
}
}

View file

@ -0,0 +1,37 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ModChatSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (args.length == 1)
{
sender.sendMessage(USAGE + "/g mchat <message>");
return;
}
String message = StringUtils.join(args, " ", 1, args.length);
guild.chat(playerSender, message, true);
}
}

View file

@ -0,0 +1,49 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class NoTagSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!tfmBridge.isAdmin(sender))
{
sender.sendMessage(PREFIX + "You do not have the permission.");
return;
}
if (args.length == 1)
{
sender.sendMessage(USAGE + "/g edittag <guild>");
return;
}
Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
return;
}
boolean enabled = guild.canUseTag();
if (enabled)
{
guild.setUseTag(false);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled " + ChatColor.GRAY + "guild tags for " + ChatColor.GOLD + guild.getName());
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disabled guild tags for your guild.");
}
else
{
guild.setUseTag(true);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled " + ChatColor.GRAY + "guild tags for " + ChatColor.GOLD + guild.getName());
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has enabled guild tags for your guild.");
}
}
}

View file

@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
@ -39,15 +40,22 @@ public class TagSubCommand extends Common implements SubCommand
return;
}
if (!guild.canUseTag())
{
sender.sendMessage(PREFIX + "You may not edit or clear your guild tag, please contact an admin if this is an error.");
return;
}
if (args.length >= 3)
{
if (args[1].equalsIgnoreCase("set"))
{
int length = ConfigEntry.GUILD_TAG_MAX_LENGTH.getInteger();
String tag = StringUtils.join(args, " ", 2, args.length);
tag = tag.replace("%tag%", guild.getName());
if (tag.length() > 15)
if (GUtil.removeColorCodes(tag).length() > length && length > 0)
{
sender.sendMessage(PREFIX + "The guild tag cannot go over 15 characters limit.");
sender.sendMessage(PREFIX + "The guild tag cannot go over " + length + " characters limit.");
return;
}
@ -60,16 +68,7 @@ public class TagSubCommand extends Common implements SubCommand
guild.setTag(tag);
sender.sendMessage(PREFIX + "The guild tag has been changed to " + ChatColor.GOLD + GUtil.colorize(tag).replace("%rank%", "Guild Owner"));
}
else
{
sender.sendMessage(USAGE + "/g tag <set <tag> | clear [guild]>");
}
return;
}
if (args[1].equalsIgnoreCase("clear"))
{
if (args.length >= 3)
else if (args[1].equalsIgnoreCase("clear"))
{
if (!tfmBridge.isAdmin(sender))
{
@ -88,7 +87,15 @@ public class TagSubCommand extends Common implements SubCommand
sender.sendMessage(PREFIX + "Successfully cleared the guild tag for " + ChatColor.GOLD + guild.getName());
return;
}
else
{
sender.sendMessage(USAGE + "/g tag <set <tag> | clear [guild]>");
}
return;
}
if (args[1].equalsIgnoreCase("clear"))
{
guild.setTag(null);
sender.sendMessage(PREFIX + "Successfully cleared the guild tag.");
}

View file

@ -0,0 +1,46 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.User;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ToggleChatSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (args.length > 1)
{
sender.sendMessage(USAGE + "/g togglechat");
return;
}
User user = User.getUserFromPlayer(playerSender);
if (user == null)
{
user = User.create(playerSender);
}
// Must use this otherwise the subcommand will not work properly, unlike ToggleTagSubCommand.java
boolean enabled = user.displayChat();
if (enabled)
{
user.setDisplayChat(false);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled" + ChatColor.GRAY + " personal guild chat.");
}
else
{
user.setDisplayChat(true);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled" + ChatColor.GRAY + " personal guild chat.");
}
}
}

View file

@ -7,6 +7,8 @@ public enum ConfigEntry
GUILD_CHAT_LOGGING("server.guild_chat_logging"),
GUILD_TAGS("server.guild_tags"),
GUILD_TAG_MAX_LENGTH("server.guild_tag_max_length"),
GLOBAL_TAG_MAX_LENGTH("server.global_tag_max_length"),
MYSQL_HOST("mysql.host"),
MYSQL_PORT("mysql.port"),
MYSQL_USERNAME("mysql.username"),

View file

@ -39,6 +39,7 @@ public class Guild
private State state;
private String motd;
private Location home;
private boolean useTag;
public Guild(String name,
UUID owner,
@ -54,7 +55,8 @@ public class Guild
double y,
double z,
String world,
long createdAt)
long createdAt,
boolean useTag)
{
this.id = name.toLowerCase().replaceAll(" ", "_");
this.name = name;
@ -82,6 +84,7 @@ public class Guild
}
this.home = new Location(w, x, y, z);
this.createdAt = createdAt;
this.useTag = useTag;
}
public Guild(Player player, String name)
@ -100,7 +103,8 @@ public class Guild
50,
0,
null,
System.currentTimeMillis());
System.currentTimeMillis(),
true);
save(true);
}
@ -145,13 +149,12 @@ public class Guild
}
}
List<UUID> members = new ArrayList<>();
members.add(owner);
if (set.getString("members") != null)
{
for (String string : set.getString("members").split(","))
{
User user = User.getUserFromId(Integer.parseInt(string));
if (user != null)
if (user != null && !user.equals(User.getUserFromUuid(owner)))
{
members.add(user.getUuid());
}
@ -212,7 +215,8 @@ public class Guild
set.getDouble("y"),
set.getDouble("z"),
set.getString("world"),
set.getLong("creation"));
set.getLong("creation"),
set.getBoolean("usetag"));
guilds.put(id, guild);
}
TFGuilds.getPlugin().getLogger().info(guilds.size() + " guilds loaded!");
@ -282,7 +286,7 @@ public class Guild
{
if (isModerator(player))
{
moderators.remove(player);
moderators.remove(player.getUniqueId());
}
members.remove(player.getUniqueId());
save();
@ -430,7 +434,18 @@ public class Guild
return rank;
}
}
return defaultRank;
if (owner.equals(player.getUniqueId()))
{
return "Guild Owner";
}
if (moderators.contains(player.getUniqueId()))
{
return "Guild Moderator";
}
return defaultRank != null ? defaultRank : "Guild Member";
}
public String getModeratorIds()
@ -479,8 +494,8 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds (`id`, `name`, `owner`, `moderators`, `members`, `tag`, `default_rank`, `state`, `motd`, `x`, `y`, `z`, `world`, `creation`)" +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds (`id`, `name`, `owner`, `moderators`, `members`, `tag`, `default_rank`, `state`, `motd`, `x`, `y`, `z`, `world`, `creation`, `usetag`)" +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
: connection.prepareStatement("UPDATE guilds SET owner=?," +
"moderators=?," +
"members=?," +
@ -491,7 +506,8 @@ public class Guild
"x=?," +
"y=?," +
"z=?," +
"world=? WHERE id=?");
"world=?," +
"usetag=? WHERE id=?");
if (newSave)
{
statement.setString(1, id);
@ -508,6 +524,7 @@ public class Guild
statement.setDouble(12, home.getZ());
statement.setString(13, home.getWorld().getName());
statement.setLong(14, createdAt);
statement.setBoolean(15, useTag);
}
else
{
@ -522,7 +539,8 @@ public class Guild
statement.setDouble(9, home.getY());
statement.setDouble(10, home.getZ());
statement.setString(11, home.getWorld().getName());
statement.setString(12, id);
statement.setBoolean(12, useTag);
statement.setString(13, id);
}
statement.execute();
}
@ -647,6 +665,19 @@ public class Guild
return names;
}
public List<String> getMemberNames()
{
List<String> names = new ArrayList<>();
for (UUID uuid : members)
{
if (GUtil.getPlayerNames().contains(Bukkit.getOfflinePlayer(uuid).getName()))
{
names.add(Bukkit.getOfflinePlayer(uuid).getName());
}
}
return names;
}
public List<String> getNamesByRank(String name)
{
List<String> names = new ArrayList<>();
@ -665,10 +696,7 @@ public class Guild
public List<String> getRankNames()
{
List<String> names = new ArrayList<>();
ranks.keySet().forEach(rank ->
names.add(rank));
return names;
return new ArrayList<>(ranks.keySet());
}
public Map<String, Location> getWarps()
@ -678,10 +706,7 @@ public class Guild
public List<String> getWarpNames()
{
List<String> names = new ArrayList<>();
warps.keySet().forEach(name ->
names.add(name));
return names;
return new ArrayList<>(warps.keySet());
}
public Location getWarp(String name)
@ -737,6 +762,17 @@ public class Guild
save();
}
public boolean canUseTag()
{
return useTag;
}
public void setUseTag(boolean useTag)
{
this.useTag = useTag;
save();
}
public void disband()
{
if (hasGuild(name))
@ -773,18 +809,21 @@ public class Guild
}
}
public void chat(Player player, String message)
public void chat(Player player, String message, boolean modChat)
{
broadcast(GUtil.colorize("&7[&bGuild Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
if (ConfigEntry.GUILD_CHAT_LOGGING.getBoolean())
{
Bukkit.getServer().getLogger().info("[Guild Chat | " + name + "] " + player.getName() + " \u00BB " + message);
Bukkit.getServer().getLogger().info("[Guild " + (modChat ? "Mod " : "") + "Chat | " + name + "] " + player.getName() + " \u00BB " + message);
}
for (Player p : Bukkit.getOnlinePlayers())
{
if (Common.GUILD_CHAT_SPY.contains(p) && player != p)
if (User.getUserFromPlayer(p).displayChat() && isMember(p))
{
p.sendMessage(GUtil.colorize("&7[&bGuild " + (modChat ? "Mod " : "") + "Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
}
if (Common.GUILD_CHAT_SPY.contains(p) && player != p && !isMember(p))
{
p.sendMessage(GUtil.colorize("&7[&bGuild Chat Spy &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
}
@ -814,18 +853,16 @@ public class Guild
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.AQUA).append("Guild Information").append("\n").append(ChatColor.GRAY)
.append(" Identifier: ").append(ChatColor.GOLD).append(id).append("\n")
.append(ChatColor.GRAY).append(" Name: ").append(ChatColor.GOLD).append(name).append("\n")
.append(ChatColor.GRAY).append(" Owner: ").append(ChatColor.GOLD).append(Bukkit.getOfflinePlayer(owner).getName()).append("\n")
.append(ChatColor.GRAY).append(" Moderators (").append(getModerators().size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getModeratorNames(), ", ")).append("\n")
.append(ChatColor.GRAY).append(" Members (").append(getMembers().size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getMemberOnlyNames(), ", ")).append("\n")
.append(ChatColor.GRAY).append(" Tag: ").append(ChatColor.GOLD).append(tag != null ? GUtil.colorize(tag) : "None").append("\n")
.append(ChatColor.GRAY).append(" State: ").append(ChatColor.GOLD).append(state.name()).append("\n")
.append(ChatColor.GRAY).append(" Ranks (").append(ranks.size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getRankNames(), ", ")).append("\n")
.append(ChatColor.GRAY).append(" Created At: ").append(ChatColor.GOLD).append(GUtil.formatTime(createdAt));
return builder.toString();
return ChatColor.AQUA + "Guild Information" + "\n" + ChatColor.GRAY +
" Identifier: " + ChatColor.GOLD + id + "\n" +
ChatColor.GRAY + " Name: " + ChatColor.GOLD + name + "\n" +
ChatColor.GRAY + " Owner: " + ChatColor.GOLD + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
ChatColor.GRAY + " Moderators: " + ChatColor.GOLD + moderators.size() + "\n" +
ChatColor.GRAY + " Members: " + ChatColor.GOLD + members.size() + "\n" +
ChatColor.GRAY + " Tag: " + ChatColor.GOLD + (tag != null ? GUtil.colorize(tag) : "None") + "\n" +
ChatColor.GRAY + " State: " + ChatColor.GOLD + state.name() + "\n" +
ChatColor.GRAY + " Ranks (" + ranks.size() + "): " + ChatColor.GOLD + StringUtils.join(getRankNames(), ", ") + "\n" +
ChatColor.GRAY + " Created At: " + ChatColor.GOLD + GUtil.formatTime(createdAt);
}
public long getCreatedAt()
@ -849,7 +886,7 @@ public class Guild
{
return valueOf(string.toUpperCase());
}
catch (Exception ex)
catch (Exception ignored)
{
}
return null;

View file

@ -18,18 +18,20 @@ public class User
private final int id;
private final UUID uuid;
private boolean tag;
private boolean chat;
public User(int id, UUID uuid, boolean tag)
public User(int id, UUID uuid, boolean tag, boolean chat)
{
this.id = id;
this.uuid = uuid;
this.tag = tag;
this.chat = chat;
}
public static User create(Player player)
{
int id = users.size() + 1;
User user = new User(id, player.getUniqueId(), true);
User user = new User(id, player.getUniqueId(), true, true);
users.put(id, user);
user.save(true);
return user;
@ -43,10 +45,11 @@ public class User
ResultSet set = connection.prepareStatement("SELECT * FROM users").executeQuery();
while (set.next())
{
int id = set.getInt("id");
int id = set.getInt("rowid");
UUID uuid = UUID.fromString(set.getString("uuid"));
boolean tag = set.getBoolean("tag");
users.put(id, new User(id, uuid, tag));
boolean chat = set.getBoolean("chat");
users.put(id, new User(id, uuid, tag, chat));
}
TFGuilds.getPlugin().getLogger().info(users.size() + " users loaded!");
}
@ -108,23 +111,35 @@ public class User
save();
}
public boolean displayChat()
{
return chat;
}
public void setDisplayChat(boolean chat)
{
this.chat = chat;
save();
}
public void save(boolean newSave)
{
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users (`uuid`, `id`, `tag`) VALUES (?, ?, ?)")
: connection.prepareStatement("UPDATE users SET tag=? WHERE id=?");
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users (`uuid`, `tag`, `chat`) VALUES (?, ?, ?)")
: connection.prepareStatement("UPDATE users SET tag=?, chat=? WHERE rowid=?");
if (newSave)
{
statement.setString(1, uuid.toString());
statement.setInt(2, id);
statement.setBoolean(3, tag);
statement.setBoolean(2, tag);
statement.setBoolean(3, chat);
}
else
{
statement.setBoolean(1, tag);
statement.setInt(2, id);
statement.setBoolean(2, chat);
statement.setInt(3, id);
}
statement.execute();
}

View file

@ -34,7 +34,7 @@ public class ChatListener implements Listener
if (Common.GUILD_CHAT.contains(player))
{
event.setCancelled(true);
guild.chat(player, event.getMessage());
guild.chat(player, event.getMessage(), false);
return;
}
@ -43,27 +43,20 @@ public class ChatListener implements Listener
return;
}
String display = guild.getPlayerRank(player);
if (display == guild.getDefaultRank())
{
if (guild.getOwner().equals(player.getUniqueId()))
{
display = "Guild Owner";
}
else if (guild.isModerator(player))
{
display = "Guild Moderator";
}
}
else if (display == null)
{
display = "Guild Member";
}
User user = User.getUserFromPlayer(player);
if (guild.getTag() != null && user.displayTag())
{
event.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + event.getFormat());
int maxLength = ConfigEntry.GLOBAL_TAG_MAX_LENGTH.getInteger();
String tfmTag = TFGuilds.getPlugin().getTfmBridge().getTag(player);
if (tfmTag != null && maxLength > 0)
{
int length = GUtil.removeColorCodes(tfmTag).length() + GUtil.removeColorCodes(guild.getTag()).length();
if (length > maxLength)
{
TFGuilds.getPlugin().getTfmBridge().clearTag(player);
}
}
event.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", guild.getPlayerRank(player))) + ChatColor.RESET + " " + event.getFormat());
}
}
}

View file

@ -1,8 +1,10 @@
package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.User;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -17,7 +19,7 @@ public class JoinListener implements Listener
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
@ -38,5 +40,16 @@ public class JoinListener implements Listener
{
player.sendMessage(guild.getMotd());
}
int maxLength = ConfigEntry.GLOBAL_TAG_MAX_LENGTH.getInteger();
String tfmTag = TFGuilds.getPlugin().getTfmBridge().getTag(player);
if (user.displayTag() && tfmTag != null && guild.getTag() != null && maxLength > 0)
{
int length = GUtil.removeColorCodes(tfmTag).length() + GUtil.removeColorCodes(guild.getTag()).length();
if (length > maxLength)
{
TFGuilds.getPlugin().getTfmBridge().clearTag(player);
}
}
}
}

View file

@ -5,7 +5,6 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import org.bukkit.Bukkit;
public class SQLDatabase
{
@ -45,8 +44,8 @@ public class SQLDatabase
{
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (" +
"`uuid` TEXT," +
"`id` INT," +
"`tag` BOOLEAN," +
"`chat` BOOLEAN," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (" +
@ -73,6 +72,7 @@ public class SQLDatabase
"`z` DOUBLE," +
"`world` TEXT," +
"`creation` LONG," +
"`usetag` BOOLEAN," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (" +

View file

@ -1,12 +1,16 @@
package me.totalfreedom.tfguilds.util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.totalfreedom.tfguilds.TFGuilds;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class GUtil
{
@ -16,6 +20,7 @@ public class GUtil
"admin", "owner", "moderator", "developer", "console", "dev", "staff",
"mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin",
"trial mod", "trial moderator", "trialmod", "trialmoderator");
private static final Pattern CHAT_COLOR_FORMAT = Pattern.compile("&[a-fk-or0-9]", Pattern.CASE_INSENSITIVE);
public static String colorize(String string)
{
@ -33,6 +38,19 @@ public class GUtil
return string;
}
public static String removeColorCodes(String string)
{
if (string != null)
{
Matcher matcher = CHAT_COLOR_FORMAT.matcher(string);
while (matcher.find())
{
string = string.replaceAll(matcher.group(), "");
}
}
return string;
}
public static boolean containsBlacklistedWord(String string)
{
for (String blacklist : BLACKLISTED_NAMES_AND_TAGS)
@ -45,6 +63,19 @@ public class GUtil
return false;
}
public static List<String> getPlayerNames()
{
List<String> names = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers())
{
if (!TFGuilds.getPlugin().getTfmBridge().isVanished(player))
{
names.add(player.getName());
}
}
return names;
}
public static String formatTime(long time)
{
Date date = new Date(time);

View file

@ -9,6 +9,15 @@ server:
# Enable guild tags globally?
guild_tags_enabled: true
# Maximum guild tag length - 0 for unlimited.
# Note: chat colors are ignored
guild_tag_max_length: 20
# Maximum overall tag length - requires TotalFreedomMod.
# If the player's tag and guild tag combined exceeds the maximum overall length, guild tag will take priority. 0 for unlimited.
# Note: chat colors are ignored
global_tag_max_length: 30
# MySQL configuration
mysql:
host: localhost