default guild ranks

it works!!!!!!!!!!!!!!
This commit is contained in:
speedxx 2020-08-10 23:39:36 -04:00
parent b8a07c0281
commit 50de5817e9
6 changed files with 102 additions and 5 deletions

View file

@ -48,6 +48,13 @@ public class DeleteRankSubcommand extends Common implements CommandExecutor
}
guild.removeRank(rank);
if (guild.hasDefaultRank() && rank.equals(guild.getDefaultRank()))
{
guild.setDefaultRank(null);
guild.save();
}
sender.sendMessage(tl(PREFIX + "Deleted the rank named %s%" + rank + "%p% in your guild."));
guild.save();
return true;

View file

@ -66,6 +66,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
return new HomeSubcommand().onCommand(sender, command, label, args);
case "roster":
return new RosterSubcommand().onCommand(sender, command, label, args);
case "setdefaultrank":
return new SetDefaultRankSubcommand().onCommand(sender, command, label, args);
}
return false;
}
@ -81,7 +83,7 @@ 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");
"roster", "setowner", "setrank", "setstate", "tag", "tp", "setdefaultrank");
}
else if (args.length == 2)
{
@ -116,6 +118,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
}
case "deleterank":
case "setdefaultrank":
{
if (guild.getOwner().equals(sender.getName()))
{

View file

@ -33,6 +33,7 @@ public class HelpSubcommand extends Common implements CommandExecutor
sender.sendMessage(tl("%s% - %p%chat [message]"));
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>"));
return true;
}
}

View file

@ -0,0 +1,63 @@
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.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SetDefaultRankSubcommand 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;
}
if (args.length == 0)
{
return false;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You do not have permissions to manage ranks in your guild!");
return true;
}
String rank = StringUtils.join(args, " ", 1, args.length);
if (rank.equalsIgnoreCase("members") || rank.equalsIgnoreCase("member") || rank.equalsIgnoreCase("none"))
{
guild.setDefaultRank(null);
guild.save();
sender.sendMessage(tl(PREFIX + "Removed the default guild rank."));
return true;
}
if (!guild.hasRank(rank))
{
sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
return true;
}
guild.setDefaultRank(rank);
guild.save();
sender.sendMessage(tl(PREFIX + "Set " + rank + " as the default rank for your guild."));
return true;
}
}

View file

@ -59,6 +59,10 @@ public class Guild
@Setter
private Location home;
@Getter
@Setter
private String defaultRank;
@Getter
private final long creation;
@ -72,7 +76,8 @@ public class Guild
List<GuildRank> ranks,
String motd,
Location home,
long creation)
long creation,
String defaultrank)
{
this.identifier = identifier;
this.name = name;
@ -85,6 +90,7 @@ public class Guild
this.motd = motd;
this.home = home;
this.creation = creation;
this.defaultRank = defaultrank;
}
public void save()
@ -102,11 +108,17 @@ public class Guild
plugin.guilds.set(identifier + ".motd", motd);
plugin.guilds.set(identifier + ".home", home);
plugin.guilds.set(identifier + ".creation", creation);
plugin.guilds.set(identifier + ".defaultrank", defaultRank);
plugin.guilds.save();
}
public void addMember(String name)
{
if (hasDefaultRank())
{
getRank(defaultRank).getMembers().add(name);
}
members.add(name);
}
@ -119,6 +131,10 @@ public class Guild
}
members.remove(name);
for (GuildRank gr : getRanks())
{
getRank(gr.getName()).getMembers().remove(name);
}
moderators.remove(name);
}
@ -211,6 +227,11 @@ public class Guild
return home != null;
}
public boolean hasDefaultRank()
{
return defaultRank != null;
}
public void broadcast(String message)
{
for (Player player : Bukkit.getOnlinePlayers())
@ -359,7 +380,8 @@ public class Guild
new ArrayList<>(),
null,
null,
System.currentTimeMillis());
System.currentTimeMillis(),
null);
guild.save();
GLog.info(owner.getName() + " has created guild " + name);
return guild;
@ -393,7 +415,8 @@ public class Guild
ranks,
plugin.guilds.getString(identifier + ".motd"),
plugin.guilds.getLocation(identifier + ".home"),
plugin.guilds.getLong(identifier + ".creation"));
plugin.guilds.getLong(identifier + ".creation"),
plugin.guilds.getString(identifier + ".defaultrank"));
}
public static Guild getGuild(Player player)