add guild mods, delete unused config

This commit is contained in:
speedxx 2020-06-28 13:46:49 -04:00
parent bc7ca70e72
commit c8975e8576
11 changed files with 219 additions and 21 deletions

View file

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

View file

@ -12,7 +12,6 @@ public final class TFGuilds extends JavaPlugin
{
public static TFGuilds plugin;
public TFMBridge tfmb;
public Config config;
public Config guilds;
@Override
@ -21,7 +20,6 @@ public final class TFGuilds extends JavaPlugin
plugin = this;
enableCommands();
enableListeners();
config = new Config(plugin, "config.yml");
guilds = new Config(plugin, "guilds.yml");
tfmb = new TFMBridge();
GLog.info("Enabled");
@ -30,7 +28,6 @@ public final class TFGuilds extends JavaPlugin
@Override
public void onDisable()
{
config.save();
guilds.save();
GLog.info("Disabled");
}
@ -48,6 +45,8 @@ public final class TFGuilds extends JavaPlugin
this.getCommand("guildkick").setExecutor(new GuildKickCommand());
this.getCommand("guildinfo").setExecutor(new GuildInfoCommand());
this.getCommand("guildadmin").setExecutor(new GuildAdminCommand());
this.getCommand("guildsetmoderator").setExecutor(new GuildSetModeratorCommand());
this.getCommand("guildremovemoderator").setExecutor(new GuildRemoveModeratorCommand());
}
private void enableListeners()

View file

@ -17,7 +17,7 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
{
if (args.length == 0)
{
if (GUtil.isConsole(sender))
if (GUtil.isConsole(sender) || GUtil.getGuild((Player) sender) == null)
{
sender.sendMessage(GUtil.color("&cProvide a guild name."));
return true;
@ -25,14 +25,8 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
List<String> moderators = GUtil.getModerators(guild);
String tag = GUtil.getTag(guild);
String creation = GUtil.getTimeCreated(guild);
List<String> members = GUtil.getMember(guild);
@ -40,6 +34,7 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
player.sendMessage(GUtil.color("&2-=-=-=- &aGuild Information &2-=-=-=-"));
player.sendMessage(GUtil.color("&2Guild Name: &a" + guild));
player.sendMessage(GUtil.color("&2Guild Owner: &a" + owner));
player.sendMessage(GUtil.color("&2Guild Moderators: &a" + moderators));
player.sendMessage(GUtil.color("&2Guild Tag: &a" + tag));
player.sendMessage(GUtil.color("&2Guild Creation Date: &a" + creation));
player.sendMessage(GUtil.color("&2Member Count: &a" + members.size()));
@ -56,6 +51,7 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
}
String owner = GUtil.getOwner(guild);
List<String> moderators = GUtil.getModerators(guild);
String tag = GUtil.getTag(guild);
String creation = GUtil.getTimeCreated(guild);
List<String> members = GUtil.getMember(guild);
@ -63,6 +59,7 @@ public class GuildInfoCommand extends GBase implements CommandExecutor
sender.sendMessage(GUtil.color("&2-=-=-=- &aGuild Information &2-=-=-=-"));
sender.sendMessage(GUtil.color("&2Guild Name: &a" + guild));
sender.sendMessage(GUtil.color("&2Guild Owner: &a" + owner));
sender.sendMessage(GUtil.color("&2Guild Moderators: &a" + moderators));
sender.sendMessage(GUtil.color("&2Guild Tag: &a" + tag));
sender.sendMessage(GUtil.color("&2Guild Creation Date: &a" + creation));
sender.sendMessage(GUtil.color("&2Member Count: &a" + members.size()));

View file

@ -37,10 +37,9 @@ public class GuildKickCommand extends GBase implements CommandExecutor
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
if (!GUtil.isGuildModerator(player, guild))
{
player.sendMessage(GMessage.NOT_OWNER);
player.sendMessage(ChatColor.RED + "You must be a guild moderator in order to kick members.");
return true;
}
@ -57,6 +56,12 @@ public class GuildKickCommand extends GBase implements CommandExecutor
return true;
}
if (GUtil.isGuildModerator(target, guild))
{
player.sendMessage(ChatColor.RED + "This player is a moderator and therefore cannot be kicked.");
return true;
}
if (target == player)
{
player.sendMessage(ChatColor.RED + "You may not kick yourself.");

View file

@ -0,0 +1,86 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class GuildRemoveModeratorCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0)
{
return false;
}
if (GUtil.isConsole(sender))
{
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
player.sendMessage(GMessage.NOT_OWNER);
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null)
{
player.sendMessage(GMessage.PLAYER_NOT_FOUND);
return true;
}
if (!GUtil.isGuildMember(target, GUtil.getGuild(player)))
{
player.sendMessage(ChatColor.RED + "That player isn't in your guild.");
return true;
}
if (!GUtil.isGuildModerator(target, guild))
{
player.sendMessage(ChatColor.RED + "This player isn't a guild moderator.");
return true;
}
if (target == player)
{
player.sendMessage(ChatColor.RED + "You may not demote yourself.");
return true;
}
List<String> moderators = plugin.guilds.getStringList("guilds." + guild + ".moderators");
moderators.remove(target.getName());
plugin.guilds.set("guilds." + guild + ".moderators", moderators);
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.RED + target.getName() + " has been demoted to guild member");
}
}
player.sendMessage(ChatColor.GREEN + "Successfully demoted " + target.getName() + " to guild member");
return true;
}
}

View file

@ -0,0 +1,86 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class GuildSetModeratorCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0)
{
return false;
}
if (GUtil.isConsole(sender))
{
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
if (guild == null)
{
player.sendMessage(GMessage.NOT_IN_GUILD);
return true;
}
String owner = GUtil.getOwner(guild);
if (!owner.equalsIgnoreCase(player.getName()))
{
player.sendMessage(GMessage.NOT_OWNER);
return true;
}
Player target = Bukkit.getPlayer(args[0]);
if (target == null)
{
player.sendMessage(GMessage.PLAYER_NOT_FOUND);
return true;
}
if (!GUtil.isGuildMember(target, guild))
{
player.sendMessage(ChatColor.RED + "That player isn't in your guild.");
return true;
}
if (GUtil.isGuildModerator(target, guild))
{
player.sendMessage(ChatColor.RED + "This player is already a guild moderator.");
return true;
}
if (target == player)
{
player.sendMessage(ChatColor.RED + "You are already a moderator.");
return true;
}
List<String> moderators = plugin.guilds.getStringList("guilds." + guild + ".moderators");
moderators.add(target.getName());
plugin.guilds.set("guilds." + guild + ".moderators", moderators);
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.GREEN + target.getName() + " has been promoted to guild moderator");
}
}
player.sendMessage(ChatColor.GREEN + "Successfully promoted " + target.getName() + " to guild moderator");
return true;
}
}

View file

@ -33,6 +33,12 @@ public class InviteGuildCommand extends GBase implements CommandExecutor
if (target != null)
{
if (!GUtil.isGuildModerator(player, GUtil.getGuild(player)))
{
player.sendMessage(ChatColor.RED + "You must be a guild moderator in order to invite players.");
return true;
}
if (GUtil.isGuildMember(target, GUtil.getGuild(player)))
{
player.sendMessage(ChatColor.RED + "That player is already in a guild.");

View file

@ -32,10 +32,8 @@ public class TfGuildsCommand extends GBase implements CommandExecutor
sender.sendMessage(GMessage.NO_PERMISSION);
return true;
}
try
{
plugin.config.load();
plugin.guilds.load();
GLog.info("All configs reloaded successfully");
sender.sendMessage(GUtil.color("&aAll configuration files have been reloaded successfully."));

View file

@ -31,6 +31,10 @@ public class GUtil
plugin.guilds.set("guilds." + guildName, guildName);
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
List<String> moderators = plugin.guilds.getStringList("guilds." + guildName + ".moderators");
moderators.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".moderators", moderators);
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
players.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".members", players);
@ -159,6 +163,11 @@ public class GUtil
return plugin.guilds.getString("guilds." + guildName + ".owner");
}
public static List<String> getModerators(String guildName)
{
return plugin.guilds.getStringList("guilds." + guildName + ".moderators");
}
public static List<String> getMember(String guildName)
{
return plugin.guilds.getStringList("guilds." + guildName + ".members");
@ -166,7 +175,12 @@ public class GUtil
public static boolean isGuildMember(Player player, String guildName)
{
return getMember(guildName).contains(player.getName().toLowerCase());
return getMember(guildName).contains(player.getName());
}
public static boolean isGuildModerator(Player player, String guildName)
{
return getModerators(guildName).contains(player.getName());
}
public static void guildChat(CommandSender sender, String message, String guildName)

View file

@ -1 +0,0 @@
# TFGuilds Configuration File

View file

@ -12,7 +12,7 @@ commands:
aliases: [guilds, tfguildsinfo, tfginfo, guildsinfo]
createguild:
description: Creates a guild
usage: /<command> <name>
usage: /<command> <guild>
aliases: [guildcreate]
guildtag:
description: Modify your guild's tag
@ -46,4 +46,12 @@ commands:
usage: /<command> <guild>
guildadmin:
description: Guild commands only for admins
usage: /<command> <cleartag | disbandguild | join> <guild>
usage: /<command> <cleartag | disbandguild | join> <guild>
guildsetmoderator:
description: Promotes a player to guild mod
usage: /<command> <player>
aliases: [gsetmod, setguildmod, setguildmoderator, guildsetmod, guildpromote, gpromote]
guildremovemoderator:
description: /<command> <player>
usage: /<command> <player>
aliases: [gremovemod, removeguildmod, removeguildmoderator, guildremovemod, guilddemote, gdemote]