guild warps (FS-1)

* adds guild warps
* some more message standardization
* formatting
* alphabetize help subcommand and guild command
This commit is contained in:
speed 2020-12-19 19:41:20 -05:00
parent 2701a5de4a
commit 13c6063474
45 changed files with 600 additions and 109 deletions

View file

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

View file

@ -19,6 +19,7 @@ public class Common
public static final String NO_PERMS = ChatColor.RED + "No permission."; public static final String NO_PERMS = ChatColor.RED + "No permission.";
public static final String PREFIX = "%s%[%p%TFGuilds%s%] %p%"; public static final String PREFIX = "%s%[%p%TFGuilds%s%] %p%";
public static final String PNF = ChatColor.RED + "Player not found."; public static final String PNF = ChatColor.RED + "Player not found.";
public static final String NG = ChatColor.RED + "You aren't in a guild!";
public static Map<Player, Guild> INVITES = new HashMap<>(); public static Map<Player, Guild> INVITES = new HashMap<>();
public static List<Player> IN_GUILD_CHAT = new ArrayList<>(); public static List<Player> IN_GUILD_CHAT = new ArrayList<>();

View file

@ -12,6 +12,7 @@ import me.totalfreedom.tfguilds.sql.SQLDatabase;
import me.totalfreedom.tfguilds.sql.SQLGuildData; import me.totalfreedom.tfguilds.sql.SQLGuildData;
import me.totalfreedom.tfguilds.sql.SQLRankData; import me.totalfreedom.tfguilds.sql.SQLRankData;
import me.totalfreedom.tfguilds.sql.SQLUserData; import me.totalfreedom.tfguilds.sql.SQLUserData;
import me.totalfreedom.tfguilds.sql.SQLWarpData;
import me.totalfreedom.tfguilds.sql.SQLWorldData; import me.totalfreedom.tfguilds.sql.SQLWorldData;
import me.totalfreedom.tfguilds.util.GLog; import me.totalfreedom.tfguilds.util.GLog;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -31,8 +32,9 @@ public final class TFGuilds extends JavaPlugin
public SQLDatabase sql; public SQLDatabase sql;
public SQLGuildData guildData; public SQLGuildData guildData;
public SQLRankData rankData; public SQLRankData rankData;
public SQLWorldData worldData;
public SQLUserData userData; public SQLUserData userData;
public SQLWarpData warpData;
public SQLWorldData worldData;
@Override @Override
public void onEnable() public void onEnable()
@ -43,8 +45,9 @@ public final class TFGuilds extends JavaPlugin
sql = new SQLDatabase(); sql = new SQLDatabase();
guildData = new SQLGuildData(); guildData = new SQLGuildData();
rankData = new SQLRankData(); rankData = new SQLRankData();
worldData = new SQLWorldData();
userData = new SQLUserData(); userData = new SQLUserData();
warpData = new SQLWarpData();
worldData = new SQLWorldData();
loadCommands(); loadCommands();
loadListeners(); loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName()); GLog.info("Enabled " + this.getDescription().getFullName());

View file

@ -79,7 +79,7 @@ public class AddModSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -25,7 +25,7 @@ public class ChatSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -34,7 +34,7 @@ public class CreateRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -31,7 +31,7 @@ public class DeleteRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -0,0 +1,57 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildWarp;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class DeleteWarpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g deletewarp <name>"));
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
return true;
}
String warpName = StringUtils.join(args, " ", 1, args.length);
if (!Guild.warpExists(guild.getIdentifier(), warpName))
{
sender.sendMessage(ChatColor.RED + "Warp not found.");
return true;
}
GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
plugin.warpData.delete(warp);
sender.sendMessage(tl(PREFIX + "Deleted guild warp \"" + warpName + "\"."));
return true;
}
}

View file

@ -56,7 +56,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
Player player = (Player)sender; Player player = (Player)sender;
if (!Guild.isInGuild(player)) if (!Guild.isInGuild(player))
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -25,7 +25,7 @@ public class GuildChatCommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -21,60 +21,69 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
{ {
switch (args[0].toLowerCase()) switch (args[0].toLowerCase())
{ {
case "list": // Please keep the commands here & in HelpSubcommand.java in alphabetical order
return new ListSubcommand().onCommand(sender, command, label, args);
case "help":
return new HelpSubcommand().onCommand(sender, command, label, args);
case "create":
return new CreateSubcommand().onCommand(sender, command, label, args);
case "disband":
return new DisbandSubcommand().onCommand(sender, command, label, args);
case "invite":
return new InviteSubcommand().onCommand(sender, command, label, args);
case "addmod": case "addmod":
return new AddModSubcommand().onCommand(sender, command, label, args); return new AddModSubcommand().onCommand(sender, command, label, args);
case "removemod": case "chat":
return new RemoveModSubcommand().onCommand(sender, command, label, args); return new ChatSubcommand().onCommand(sender, command, label, args);
case "setowner": case "createrank":
return new SetOwnerSubcommand().onCommand(sender, command, label, args); return new CreateRankSubcommand().onCommand(sender, command, label, args);
case "setstate": case "create":
return new SetStateSubcommand().onCommand(sender, command, label, args); return new CreateSubcommand().onCommand(sender, command, label, args);
case "deleterank":
return new DeleteRankSubcommand().onCommand(sender, command, label, args);
case "deletewarp":
return new DeleteWarpSubcommand().onCommand(sender, command, label, args);
case "disband":
return new DisbandSubcommand().onCommand(sender, command, label, args);
case "help":
return new HelpSubcommand().onCommand(sender, command, label, args);
case "home":
return new HomeSubcommand().onCommand(sender, command, label, args);
case "info":
return new InfoSubcommand().onCommand(sender, command, label, args);
case "invite":
return new InviteSubcommand().onCommand(sender, command, label, args);
case "join":
return new JoinSubcommand().onCommand(sender, command, label, args);
case "kick": case "kick":
return new KickSubcommand().onCommand(sender, command, label, args); return new KickSubcommand().onCommand(sender, command, label, args);
case "leave": case "leave":
return new LeaveSubcommand().onCommand(sender, command, label, args); return new LeaveSubcommand().onCommand(sender, command, label, args);
case "tp": case "list":
return new TPSubcommand().onCommand(sender, command, label, args); return new ListSubcommand().onCommand(sender, command, label, args);
case "info":
return new InfoSubcommand().onCommand(sender, command, label, args);
case "tag":
return new TagSubcommand().onCommand(sender, command, label, args);
case "chat":
return new ChatSubcommand().onCommand(sender, command, label, args);
case "join":
return new JoinSubcommand().onCommand(sender, command, label, args);
case "rename":
return new RenameSubcommand().onCommand(sender, command, label, args);
case "createrank":
return new CreateRankSubcommand().onCommand(sender, command, label, args);
case "deleterank":
return new DeleteRankSubcommand().onCommand(sender, command, label, args);
case "setrank":
return new SetRankSubcommand().onCommand(sender, command, label, args);
case "motd": case "motd":
return new MOTDSubcommand().onCommand(sender, command, label, args); return new MOTDSubcommand().onCommand(sender, command, label, args);
case "home": case "removemod":
return new HomeSubcommand().onCommand(sender, command, label, args); return new RemoveModSubcommand().onCommand(sender, command, label, args);
case "rename":
return new RenameSubcommand().onCommand(sender, command, label, args);
case "roster": case "roster":
return new RosterSubcommand().onCommand(sender, command, label, args); return new RosterSubcommand().onCommand(sender, command, label, args);
case "setdefaultrank": case "setdefaultrank":
return new SetDefaultRankSubcommand().onCommand(sender, command, label, args); return new SetDefaultRankSubcommand().onCommand(sender, command, label, args);
case "setmember":
return new SetMemberSubcommand().onCommand(sender, command, label, args);
case "setowner":
return new SetOwnerSubcommand().onCommand(sender, command, label, args);
case "setrank":
return new SetRankSubcommand().onCommand(sender, command, label, args);
case "setstate":
return new SetStateSubcommand().onCommand(sender, command, label, args);
case "setwarp":
return new SetWarpSubcommand().onCommand(sender, command, label, args);
case "tag":
return new TagSubcommand().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": case "toggletag":
return new ToggleTagSubcommand().onCommand(sender, command, label, args); return new ToggleTagSubcommand().onCommand(sender, command, label, args);
case "setmember": case "tp":
return new SetMemberSubcommand().onCommand(sender, command, label, args); return new TPSubcommand().onCommand(sender, command, label, args);
case "warps":
return new WarpsSubcommand().onCommand(sender, command, label, args);
case "warp":
return new WarpSubcommand().onCommand(sender, command, label, args);
} }
sender.sendMessage(tl(PREFIX + "Unknown command - Run /g help if you need help")); sender.sendMessage(tl(PREFIX + "Unknown command - Run /g help if you need help"));
return true; return true;
@ -88,10 +97,10 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
if (args.length == 1) if (args.length == 1)
{ {
return Arrays.asList("addmod", "chat", "createrank", "create", return Arrays.asList("addmod", "chat", "createrank", "create",
"deleterank", "disband", "help", "home", "info", "invite", "deleterank", "deletewarp", "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", "roster", "setdefaultrank", "setmember", "setowner", "setrank", "setstate",
"toggletags", "toggletag", "setmember"); "setwarp", "tag", "toggletags", "toggletag", "tp", "warps", "warp");
} }
else if (args.length == 2) else if (args.length == 2)
{ {
@ -197,6 +206,15 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
} }
} }
} }
case "deletewarp":
case "warp":
{
if (sender instanceof Player)
{
return Guild.getGuildWarps();
}
}
} }
} }
return Collections.emptyList(); return Collections.emptyList();

View file

@ -10,34 +10,39 @@ public class HelpSubcommand extends Common implements CommandExecutor
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{ {
// Please keep the commands here & in GuildCommand.java in alphabetical order
sender.sendMessage(tl("%s%[%p%TFGuilds%s%] %p%Command List")); sender.sendMessage(tl("%s%[%p%TFGuilds%s%] %p%Command List"));
sender.sendMessage(tl("%s% - %p%list"));
sender.sendMessage(tl("%s% - %p%help"));
sender.sendMessage(tl("%s% - %p%create <name>"));
sender.sendMessage(tl("%s% - %p%join <guild>"));
sender.sendMessage(tl("%s% - %p%disband [name]"));
sender.sendMessage(tl("%s% - %p%invite <player>"));
sender.sendMessage(tl("%s% - %p%addmod <guild <player> | player>")); sender.sendMessage(tl("%s% - %p%addmod <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%removemod <guild <name> | name>")); sender.sendMessage(tl("%s% - %p%chat [message]"));
sender.sendMessage(tl("%s% - %p%setowner <guild <player> | player>")); sender.sendMessage(tl("%s% - %p%createrank <name>"));
sender.sendMessage(tl("%s% - %p%create <name>"));
sender.sendMessage(tl("%s% - %p%deleterank <rank>"));
sender.sendMessage(tl("%s% - %p%deletewarp <warp>"));
sender.sendMessage(tl("%s% - %p%disband [name]"));
sender.sendMessage(tl("%s% - %p%help"));
sender.sendMessage(tl("%s% - %p%home [set]"));
sender.sendMessage(tl("%s% - %p%info [guild | player]"));
sender.sendMessage(tl("%s% - %p%invite <player>"));
sender.sendMessage(tl("%s% - %p%join <guild>"));
sender.sendMessage(tl("%s% - %p%kick <guild <player> | player>")); sender.sendMessage(tl("%s% - %p%kick <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%leave")); sender.sendMessage(tl("%s% - %p%leave"));
sender.sendMessage(tl("%s% - %p%tp <player>")); sender.sendMessage(tl("%s% - %p%list [page]"));
sender.sendMessage(tl("%s% - %p%info [guild | player]"));
sender.sendMessage(tl("%s% - %p%tag <set <tag> | clear>"));
sender.sendMessage(tl("%s% - %p%rename <name>"));
sender.sendMessage(tl("%s% - %p%createrank <name>"));
sender.sendMessage(tl("%s% - %p%deleterank <rank>"));
sender.sendMessage(tl("%s% - %p%setrank <player> <rank | none>"));
sender.sendMessage(tl("%s% - %p%motd <set <motd> | clear>")); sender.sendMessage(tl("%s% - %p%motd <set <motd> | clear>"));
sender.sendMessage(tl("%s% - %p%home [set]")); sender.sendMessage(tl("%s% - %p%removemod <guild <name> | name>"));
sender.sendMessage(tl("%s% - %p%chat [message]")); sender.sendMessage(tl("%s% - %p%rename <name>"));
sender.sendMessage(tl("%s% - %p%roster [guild | player]")); sender.sendMessage(tl("%s% - %p%roster [guild | player]"));
sender.sendMessage(tl("%s% - %p%setstate <open | invite | closed>"));
sender.sendMessage(tl("%s% - %p%setdefaultrank <rank | none>")); sender.sendMessage(tl("%s% - %p%setdefaultrank <rank | none>"));
sender.sendMessage(tl("%s% - %p%setmember <guild> <player>"));
sender.sendMessage(tl("%s% - %p%setowner <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%setrank <player> <rank | none>"));
sender.sendMessage(tl("%s% - %p%setstate <open | invite | closed>"));
sender.sendMessage(tl("%s% - %p%setwarp <name>"));
sender.sendMessage(tl("%s% - %p%tag <set <tag> | clear [guild]>>"));
sender.sendMessage(tl("%s% - %p%toggletags")); sender.sendMessage(tl("%s% - %p%toggletags"));
sender.sendMessage(tl("%s% - %p%toggletag [player]")); sender.sendMessage(tl("%s% - %p%toggletag [player]"));
sender.sendMessage(tl("%s% - %p%setmember <guild> <player>")); sender.sendMessage(tl("%s% - %p%tp <player>"));
sender.sendMessage(tl("%s% - %p%warps"));
sender.sendMessage(tl("%s% - %p%warp <name>"));
return true; return true;
} }
} }

View file

@ -30,7 +30,7 @@ public class HomeSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -50,7 +50,7 @@ public class InfoSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild((Player)sender); Guild guild = Guild.getGuild((Player)sender);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -47,7 +47,7 @@ public class InviteSubcommand extends Common implements CommandExecutor
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -74,7 +74,7 @@ public class KickSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -30,7 +30,7 @@ public class LeaveSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -41,20 +41,20 @@ public class ListSubcommand extends Common implements CommandExecutor
} }
catch (NumberFormatException e) catch (NumberFormatException e)
{ {
sender.sendMessage(ChatColor.RED + "Invalid number"); sender.sendMessage(ChatColor.RED + "Invalid number.");
} }
} }
if (pageIndex < 1 || pageIndex > paged.getPageCount()) if (pageIndex < 1 || pageIndex > paged.getPageCount())
{ {
sender.sendMessage(ChatColor.RED + "Not a valid page number"); sender.sendMessage(ChatColor.RED + "Not a valid page number.");
return true; return true;
} }
paged.getPage(pageIndex); paged.getPage(pageIndex);
List<String> page = paged.getPage(pageIndex); List<String> page = paged.getPage(pageIndex);
sender.sendMessage(tl(PREFIX + "%s%Guild List (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]")); sender.sendMessage(tl(PREFIX + "%s%Guild list (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
for (String guild : page) for (String guild : page)
{ {

View file

@ -32,7 +32,7 @@ public class MOTDSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -82,7 +82,7 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -36,7 +36,7 @@ public class RenameSubcommand extends Common implements CommandExecutor
String identifier = GUtil.flatten(newName); String identifier = GUtil.flatten(newName);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -50,7 +50,7 @@ public class RosterSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild((Player)sender); Guild guild = Guild.getGuild((Player)sender);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -31,7 +31,7 @@ public class SetDefaultRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -74,7 +74,7 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -33,7 +33,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -61,7 +61,7 @@ public class SetStateSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -0,0 +1,56 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildWarp;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SetWarpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setwarp <name>"));
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
return true;
}
String warpName = StringUtils.join(args, " ", 1, args.length);
if (Guild.warpExists(guild.getIdentifier(), warpName))
{
sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
return true;
}
Guild.createWarp(guild.getIdentifier(), warpName, player);
sender.sendMessage(tl(PREFIX + "Successfully created new guild warp \"" + warpName + "\"."));
return true;
}
}

View file

@ -31,7 +31,7 @@ public class TPSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -32,7 +32,7 @@ public class TagSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -53,7 +53,7 @@ public class ToggleTagSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player); Guild guild = Guild.getGuild(player);
if (guild == null) if (guild == null)
{ {
sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); sender.sendMessage(NG);
return true; return true;
} }

View file

@ -0,0 +1,53 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildWarp;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
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 WarpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g warp <name>"));
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
String warpName = StringUtils.join(args, " ", 1, args.length);
if (!Guild.warpExists(guild.getIdentifier(), warpName))
{
sender.sendMessage(ChatColor.RED + "Warp not found.");
return true;
}
GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
player.teleport(warpLoc);
sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
return true;
}
}

View file

@ -0,0 +1,36 @@
package me.totalfreedom.tfguilds.command;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils;
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 WarpsSubcommand 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(NG);
return true;
}
List<String> warps = Guild.getGuildWarps();
sender.sendMessage(tl(PREFIX + "%s%Guild warps (%p%" + warps.size() + " total%s%)\n%p%" + StringUtils.join(warps, "%s%,%p% ")));
return true;
}
}

View file

@ -234,7 +234,9 @@ public class Guild
for (UUID moderator : moderators) for (UUID moderator : moderators)
{ {
if (moderator.equals(owner)) if (moderator.equals(owner))
{
continue; continue;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(moderator); OfflinePlayer player = Bukkit.getOfflinePlayer(moderator);
only.add(player.getName()); only.add(player.getName());
} }
@ -288,10 +290,22 @@ public class Guild
{ {
List<String> g = new ArrayList<>(); List<String> g = new ArrayList<>();
for (Guild guild : plugin.guildData.getAll()) for (Guild guild : plugin.guildData.getAll())
{
g.add(guild.getName()); g.add(guild.getName());
}
return g; return g;
} }
public static List<String> getGuildWarps()
{
List<String> warps = new ArrayList<>();
for (GuildWarp warp : plugin.warpData.getAll())
{
warps.add(warp.getWarpName());
}
return warps;
}
public String getInformation() public String getInformation()
{ {
return Common.tl(Common.PREFIX + "Guild Information\n" + return Common.tl(Common.PREFIX + "Guild Information\n" +
@ -339,7 +353,9 @@ public class Guild
{ {
Player player = Bukkit.getPlayer(member); Player player = Bukkit.getPlayer(member);
if (player == null) if (player == null)
{
continue; continue;
}
Common.IN_GUILD_CHAT.remove(player); Common.IN_GUILD_CHAT.remove(player);
} }
plugin.guildData.delete(this); plugin.guildData.delete(this);
@ -358,13 +374,17 @@ public class Guild
public void updateRankIdentifiers() public void updateRankIdentifiers()
{ {
for (GuildRank rank : ranks) for (GuildRank rank : ranks)
{
rank.updateGuildIdentifier(identifier); rank.updateGuildIdentifier(identifier);
} }
}
public static Guild createGuild(String identifier, String name, Player owner) public static Guild createGuild(String identifier, String name, Player owner)
{ {
if (plugin.guildData.exists(identifier)) if (plugin.guildData.exists(identifier))
{
return getGuild(identifier); return getGuild(identifier);
}
Guild guild = plugin.guildData.create(identifier, name, owner); Guild guild = plugin.guildData.create(identifier, name, owner);
GLog.info(owner.getName() + " has created guild " + name); GLog.info(owner.getName() + " has created guild " + name);
@ -390,4 +410,14 @@ public class Guild
{ {
return getGuild(player) != null; return getGuild(player) != null;
} }
public static GuildWarp createWarp(String identifier, String warpName, Player player)
{
return GuildWarp.createGuildWarp(identifier, warpName, player);
}
public static boolean warpExists(String identifier, String warpName)
{
return plugin.warpData.exists(identifier, warpName);
}
} }

View file

@ -0,0 +1,44 @@
package me.totalfreedom.tfguilds.guild;
import lombok.Getter;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.World;
import org.bukkit.entity.Player;
@Getter
public class GuildWarp
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private final String iguild;
private final String warpName;
private final double x;
private final double y;
private final double z;
private final World world;
public GuildWarp(String iguild, String warpName, double x, double y, double z, World world)
{
this.iguild = iguild;
this.warpName = warpName;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
}
public static GuildWarp createGuildWarp(String identifier, String name, Player player)
{
return plugin.warpData.create(identifier, name, player);
}
public void save()
{
plugin.warpData.save(this);
}
public void delete()
{
plugin.warpData.delete(this);
}
}

View file

@ -71,7 +71,10 @@ public class ChatListener implements Listener
} }
User user = plugin.userData.get(player.getUniqueId()); User user = plugin.userData.get(player.getUniqueId());
if (!user.isTag()) return; if (!user.isTag())
{
return;
}
if (guild.hasTag()) if (guild.hasTag())
{ {

View file

@ -69,6 +69,14 @@ public class SQLDatabase
"\t`default_rank` TEXT,\n" + "\t`default_rank` TEXT,\n" +
"\t`creation` BIGINT\n" + "\t`creation` BIGINT\n" +
");").execute(); ");").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (\n" +
"\t`identifier` TEXT,\n" +
"\t`warp_name` TEXT,\n" +
"\t`x` DOUBLE,\n" +
"\t`y` DOUBLE,\n" +
"\t`z` DOUBLE,\n" +
"\t`world` SMALLINT\n" +
");").execute();
return connection; return connection;
} }
catch (SQLException ex) catch (SQLException ex)

View file

@ -56,26 +56,35 @@ public class SQLGuildData
statement.setString(1, identifier); statement.setString(1, identifier);
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
boolean next = set.next(); boolean next = set.next();
if (!next) return null; if (!next)
{
return null;
}
String name = set.getString("name"); String name = set.getString("name");
UUID owner = plugin.userData.get(set.getInt("owner")).getUuid(); UUID owner = plugin.userData.get(set.getInt("owner")).getUuid();
List<UUID> members = new ArrayList<>(); List<UUID> members = new ArrayList<>();
for (String stringMember : set.getString("members").split(",")) for (String stringMember : set.getString("members").split(","))
{
members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid()); members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
}
List<UUID> moderators = new ArrayList<>(); List<UUID> moderators = new ArrayList<>();
if (set.getString("moderators") != null) if (set.getString("moderators") != null)
{ {
for (String stringModerator : set.getString("moderators").split(",")) for (String stringModerator : set.getString("moderators").split(","))
{
moderators.add(plugin.userData.get(Integer.parseInt(stringModerator)).getUuid()); moderators.add(plugin.userData.get(Integer.parseInt(stringModerator)).getUuid());
} }
}
String tag = set.getString("tag"); String tag = set.getString("tag");
GuildState state = GuildState.values()[set.getInt("state")]; GuildState state = GuildState.values()[set.getInt("state")];
List<GuildRank> ranks = new ArrayList<>(); List<GuildRank> ranks = new ArrayList<>();
if (set.getString("ranks") != null) if (set.getString("ranks") != null)
{ {
for (String rankString : set.getString("ranks").split(",")) for (String rankString : set.getString("ranks").split(","))
{
ranks.add(plugin.rankData.get(identifier, rankString)); ranks.add(plugin.rankData.get(identifier, rankString));
} }
}
String motd = set.getString("motd"); String motd = set.getString("motd");
Location home = new Location(plugin.worldData.getWorld(set.getInt("world")), Location home = new Location(plugin.worldData.getWorld(set.getInt("world")),
set.getDouble("x"), set.getDouble("x"),
@ -97,8 +106,10 @@ public class SQLGuildData
for (Guild guild : getAll()) for (Guild guild : getAll())
{ {
if (guild.getMembers().contains(player.getUniqueId())) if (guild.getMembers().contains(player.getUniqueId()))
{
return guild; return guild;
} }
}
return null; return null;
} }
@ -110,7 +121,9 @@ public class SQLGuildData
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
List<Guild> guilds = new ArrayList<>(); List<Guild> guilds = new ArrayList<>();
while (set.next()) while (set.next())
{
guilds.add(get(set.getString("identifier"))); guilds.add(get(set.getString("identifier")));
}
return guilds; return guilds;
} }
catch (SQLException ex) catch (SQLException ex)
@ -164,17 +177,23 @@ public class SQLGuildData
statement.setString(3, "" + plugin.userData.get(guild.getOwner()).getId()); statement.setString(3, "" + plugin.userData.get(guild.getOwner()).getId());
List<String> members = new ArrayList<>(); List<String> members = new ArrayList<>();
for (UUID member : guild.getMembers()) for (UUID member : guild.getMembers())
{
members.add("" + plugin.userData.get(member).getId()); members.add("" + plugin.userData.get(member).getId());
}
statement.setString(4, members.size() == 0 ? null : StringUtils.join(members, ",")); statement.setString(4, members.size() == 0 ? null : StringUtils.join(members, ","));
List<String> moderators = new ArrayList<>(); List<String> moderators = new ArrayList<>();
for (UUID moderator : guild.getModerators()) for (UUID moderator : guild.getModerators())
{
moderators.add("" + plugin.userData.get(moderator).getId()); moderators.add("" + plugin.userData.get(moderator).getId());
}
statement.setString(5, moderators.size() == 0 ? null : StringUtils.join(moderators, ",")); statement.setString(5, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
statement.setString(6, guild.getTag()); statement.setString(6, guild.getTag());
statement.setInt(7, guild.getState().ordinal()); statement.setInt(7, guild.getState().ordinal());
List<String> stringRanks = new ArrayList<>(); List<String> stringRanks = new ArrayList<>();
for (GuildRank rank : guild.getRanks()) for (GuildRank rank : guild.getRanks())
{
stringRanks.add(rank.getIdentifier()); stringRanks.add(rank.getIdentifier());
}
statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ",")); statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
statement.setString(9, guild.getMotd()); statement.setString(9, guild.getMotd());
Location home = guild.getHome(); Location home = guild.getHome();

View file

@ -48,14 +48,19 @@ public class SQLRankData
statement.setString(1, guildIdentifier); statement.setString(1, guildIdentifier);
statement.setString(2, identifier); statement.setString(2, identifier);
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
if (!set.next()) return null; if (!set.next())
{
return null;
}
String name = set.getString("name"); String name = set.getString("name");
List<UUID> members = new ArrayList<>(); List<UUID> members = new ArrayList<>();
if (set.getString("members") != null) if (set.getString("members") != null)
{ {
for (String stringMember : set.getString("members").split(",")) for (String stringMember : set.getString("members").split(","))
{
members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid()); members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
} }
}
return new GuildRank(guildIdentifier, identifier, name, members); return new GuildRank(guildIdentifier, identifier, name, members);
} }
catch (SQLException ex) catch (SQLException ex)
@ -92,7 +97,9 @@ public class SQLRankData
statement.setString(1, rank.getName()); statement.setString(1, rank.getName());
List<String> members = new ArrayList<>(); List<String> members = new ArrayList<>();
for (UUID member : rank.getMembers()) for (UUID member : rank.getMembers())
{
members.add("" + plugin.userData.get(member).getId()); members.add("" + plugin.userData.get(member).getId());
}
statement.setString(2, members.size() == 0 ? null : StringUtils.join(members, ",")); statement.setString(2, members.size() == 0 ? null : StringUtils.join(members, ","));
statement.setString(3, rank.getIguild()); statement.setString(3, rank.getIguild());
statement.setString(4, rank.getIdentifier()); statement.setString(4, rank.getIdentifier());

View file

@ -54,7 +54,10 @@ public class SQLUserData
public User get(UUID uuid) public User get(UUID uuid)
{ {
if (!exists(uuid)) create(uuid); if (!exists(uuid))
{
create(uuid);
}
try (Connection connection = plugin.sql.getConnection()) try (Connection connection = plugin.sql.getConnection())
{ {
PreparedStatement statement = connection.prepareStatement(SELECT); PreparedStatement statement = connection.prepareStatement(SELECT);

View file

@ -0,0 +1,138 @@
package me.totalfreedom.tfguilds.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.GuildWarp;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class SQLWarpData
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private static final String TABLE_NAME = "warps";
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
private final String UPDATE = "UPDATE `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=? SET x=?, y=?, z=?, world=?";
private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `warp_name`, `x`, `y`, `z`, `world`) VALUES (?, ?, ?, ?, ?, ?);";
public boolean exists(String identifier, String warpName)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, identifier);
statement.setString(2, warpName);
ResultSet set = statement.executeQuery();
return set.next();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return false;
}
public GuildWarp get(String identifier, String warpName)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, identifier);
statement.setString(2, warpName);
ResultSet set = statement.executeQuery();
double x = set.getDouble("x");
double y = set.getDouble("y");
double z = set.getDouble("z");
World world = plugin.worldData.getWorld(set.getInt("world"));
return new GuildWarp(identifier, warpName, x, y, z, world);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public List<GuildWarp> getAll()
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
ResultSet set = statement.executeQuery();
List<GuildWarp> warps = new ArrayList<>();
while (set.next())
{
warps.add(get(set.getString("identifier"), set.getString("warp_name")));
}
return warps;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public GuildWarp create(String identifier, String warpName, Player player)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, identifier);
statement.setString(2, warpName);
statement.setDouble(3, player.getLocation().getX());
statement.setDouble(4, player.getLocation().getY());
statement.setDouble(5, player.getLocation().getZ());
statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
statement.execute();
return new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
player.getLocation().getZ(), player.getWorld());
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public void save(GuildWarp warp)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, warp.getIguild());
statement.setString(2, warp.getWarpName());
statement.setDouble(3, warp.getX());
statement.setDouble(4, warp.getY());
statement.setDouble(5, warp.getZ());
statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
statement.execute();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void delete(GuildWarp warp)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, warp.getIguild());
statement.setString(2, warp.getWarpName());
statement.execute();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}

View file

@ -79,7 +79,10 @@ public class SQLWorldData
{ {
try (Connection connection = plugin.sql.getConnection()) try (Connection connection = plugin.sql.getConnection())
{ {
if (!existsID(id)) return null; if (!existsID(id))
{
return null;
}
PreparedStatement statement = connection.prepareStatement(SELECT_ID); PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id); statement.setInt(1, id);
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();

View file

@ -10,6 +10,7 @@ public class User
{ {
private final int id; private final int id;
private final UUID uuid; private final UUID uuid;
@Setter @Setter
private boolean tag; private boolean tag;

View file

@ -10,6 +10,7 @@ public class PaginationList<T> extends ArrayList<T>
/** /**
* Defines a new Pagination List. * Defines a new Pagination List.
*
* @param epp Elements per page - how many elements will be included on a page of the list. * @param epp Elements per page - how many elements will be included on a page of the list.
*/ */
public PaginationList(int epp) public PaginationList(int epp)
@ -20,6 +21,7 @@ public class PaginationList<T> extends ArrayList<T>
/** /**
* Defines a new Pagination List. * Defines a new Pagination List.
*
* @param epp Elements per page - how many elements will be included on a page of the list. * @param epp Elements per page - how many elements will be included on a page of the list.
* @param elements Elements to add to the list immediately. * @param elements Elements to add to the list immediately.
*/ */
@ -40,12 +42,16 @@ public class PaginationList<T> extends ArrayList<T>
/** /**
* Get a page from the list. * Get a page from the list.
*
* @param page Page you want to access. * @param page Page you want to access.
* @return A sublist of only the elements from that page. * @return A sublist of only the elements from that page.
*/ */
public List<T> getPage(int page) public List<T> getPage(int page)
{ {
if (page < 1 || page > getPageCount()) return null; if (page < 1 || page > getPageCount())
{
return null;
}
int startIndex = (page - 1) * epp; int startIndex = (page - 1) * epp;
int endIndex = Math.min(startIndex + (epp - 1), this.size() - 1); int endIndex = Math.min(startIndex + (epp - 1), this.size() - 1);
return subList(startIndex, endIndex + 1); return subList(startIndex, endIndex + 1);