diff --git a/pom.xml b/pom.xml index e941539..fe0860a 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,14 @@ + + jitpack.io + https://jitpack.io + + + papermc + https://papermc.io/repo/repository/maven-public/ + spigotmc-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ @@ -78,5 +86,17 @@ 1.18.12 provided + + com.github.TFPatches + TotalFreedomMod + 5.5 + provided + + + com.github.Pravian + Aero + 5f82926 + provided + \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java index 0584024..7cc68e6 100644 --- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java +++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java @@ -1,18 +1,17 @@ package me.totalfreedom.tfguilds; +import me.totalfreedom.tfguilds.bridge.TFMBridge; +import me.totalfreedom.tfguilds.command.*; import me.totalfreedom.tfguilds.util.GLog; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import me.totalfreedom.tfguilds.command.CreateGuildCommand; -import me.totalfreedom.tfguilds.command.GuildChatCommand; -import me.totalfreedom.tfguilds.command.GuildTagCommand; -import me.totalfreedom.tfguilds.command.TfGuildsCommand; import me.totalfreedom.tfguilds.config.Config; import me.totalfreedom.tfguilds.listener.ChatManager; public final class TFGuilds extends JavaPlugin { public static TFGuilds plugin; + public TFMBridge tfmb; public Config config; public Config guilds; @@ -24,6 +23,7 @@ public final class TFGuilds extends JavaPlugin enableListeners(); config = new Config(plugin, "config.yml"); guilds = new Config(plugin, "guilds.yml"); + tfmb = new TFMBridge(); GLog.info("Enabled"); } @@ -41,6 +41,7 @@ public final class TFGuilds extends JavaPlugin this.getCommand("createguild").setExecutor(new CreateGuildCommand()); this.getCommand("guildtag").setExecutor(new GuildTagCommand()); this.getCommand("guildchat").setExecutor(new GuildChatCommand()); + this.getCommand("disbandguild").setExecutor(new DisbandGuildCommand()); } private void enableListeners() diff --git a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java new file mode 100644 index 0000000..dca3819 --- /dev/null +++ b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java @@ -0,0 +1,43 @@ +package me.totalfreedom.tfguilds.bridge; + +import me.totalfreedom.tfguilds.TFGuilds; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +public class TFMBridge +{ + private TFGuilds plugin; + private TotalFreedomMod tfmPlugin; + + public TFMBridge() + { + this.plugin = TFGuilds.plugin; + this.tfmPlugin = null; + } + + public TotalFreedomMod getTFM() + { + if (tfmPlugin == null) + { + try + { + final Plugin tfm = plugin.getServer().getPluginManager().getPlugin("TotalFreedomMod"); + if (tfm != null && tfm instanceof TotalFreedomMod) + { + tfmPlugin = (TotalFreedomMod) tfm; + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + return tfmPlugin; + } + + public boolean isAdmin(Player player) + { + return getTFM().al.isAdmin(player); + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java new file mode 100644 index 0000000..8929a75 --- /dev/null +++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandGuildCommand.java @@ -0,0 +1,53 @@ +package me.totalfreedom.tfguilds.command; + +import me.totalfreedom.tfguilds.util.GLog; +import me.totalfreedom.tfguilds.util.GUtil; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class DisbandGuildCommand implements CommandExecutor +{ + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) + { + Player player = (Player) sender; + String guild = GUtil.getGuild(player); + + if (args.length == 0) + { + if (GUtil.isConsole(player)) + { + sender.sendMessage(ChatColor.RED + "You are not allowed to run this command."); + return true; + } + + if (guild == null) + { + sender.sendMessage(ChatColor.RED + "You aren't in a guild!"); + return true; + } + + String owner = GUtil.getOwner(guild); + if (!owner.equalsIgnoreCase(player.getName())) + { + sender.sendMessage(ChatColor.RED + "You aren't the owner of your guild!"); + return true; + } + + sender.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type 'CONFIRM' to continue."); + return true; + } + + if (args[0].toLowerCase().equalsIgnoreCase("confirm")) + { + GUtil.deleteGuild(player); + sender.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + "."); + GLog.info(player.getName() + " deleted guild " + guild); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java index 7e2ddbd..e8bb2e0 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildTagCommand.java @@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command; import me.totalfreedom.tfguilds.util.GBase; import me.totalfreedom.tfguilds.util.GUtil; +import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -44,13 +45,13 @@ public class GuildTagCommand extends GBase implements CommandExecutor { if (args[0].equalsIgnoreCase("set")) { - if (!args[1].toLowerCase().equals(guild)) + if (!args[1].toLowerCase().contains(guild)) { sender.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name."); return true; } - GUtil.setTag(GUtil.color(args[1]), guild); + GUtil.setTag(GUtil.color(StringUtils.join(args, " ")), guild); sender.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.color(args[1]) + ChatColor.GREEN + "\""); return true; } diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TfGuildsCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TfGuildsCommand.java index 1b53df7..fe701fe 100644 --- a/src/main/java/me/totalfreedom/tfguilds/command/TfGuildsCommand.java +++ b/src/main/java/me/totalfreedom/tfguilds/command/TfGuildsCommand.java @@ -1,19 +1,49 @@ package me.totalfreedom.tfguilds.command; import me.totalfreedom.tfguilds.util.GBase; +import me.totalfreedom.tfguilds.util.GLog; import me.totalfreedom.tfguilds.util.GUtil; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class TfGuildsCommand extends GBase implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - sender.sendMessage(GUtil.color("&aTFGuilds &2is a plugin which allows for players to make their own guilds, providing guild chat and guild teleportation.")); - sender.sendMessage(String.format(GUtil.color("&2Version &av%s"), plugin.getDescription().getVersion())); - sender.sendMessage(GUtil.color("&2Developed by &aspeednt & supernt")); - return true; + if (args.length == 0) + { + sender.sendMessage(GUtil.color("&aTFGuilds &2is a plugin which allows for players to make their own guilds, providing guild chat and guild teleportation.")); + sender.sendMessage(String.format(GUtil.color("&2Version &av%s"), plugin.getDescription().getVersion())); + sender.sendMessage(GUtil.color("&2Developed by &aspeednt & supernt")); + return true; + } + + if (args[0].toLowerCase().equals("reload")) + { + if (!plugin.tfmb.isAdmin((Player) sender)) + { + sender.sendMessage(ChatColor.RED + "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.")); + return true; + } + catch (Exception ex) + { + ex.printStackTrace(); + } + return true; + } + return false; } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java index 2307c71..a0f29e4 100644 --- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java +++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java @@ -24,7 +24,6 @@ public class GUtil { plugin.guilds.set("guilds." + guildName, guildName); plugin.guilds.set("guilds." + guildName + ".owner", owner.getName()); - plugin.guilds.set("guilds." + guildName + ".members", owner.getName()); List players = plugin.guilds.getStringList("guilds." + guildName + ".members"); players.add(owner.getName()); @@ -34,6 +33,15 @@ public class GUtil GLog.info(owner.getName() + " has created a new guild: " + guildName); } + public static void deleteGuild(CommandSender owner) + { + GLog.info("Removing guilds.yml data for " + getGuild((Player) owner)); + plugin.guilds.set("guilds." + getGuild((Player) owner), null); + plugin.guilds.set("guilds." + getGuild((Player) owner) + ".owner", null); + plugin.guilds.set("guilds." + getGuild((Player) owner) + ".members", null); + plugin.guilds.save(); + } + public static void setTag(String tag, String guildName) { plugin.guilds.set("guilds." + guildName + ".tag", tag); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e3d2aea..c150d2f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,10 +4,11 @@ main: me.totalfreedom.tfguilds.TFGuilds api-version: 1.15 authors: [speednt] description: Plugin which allows for players to make their own guilds on the server +depend: [TotalFreedomMod, Aero] commands: tfguilds: description: Plugin info - usage: / + usage: / aliases: [guilds, tfguildsinfo, tfginfo, guildsinfo] createguild: description: Creates a guild @@ -20,4 +21,8 @@ commands: guildchat: description: Speak to your guild usage: / - aliases: [gchat] \ No newline at end of file + aliases: [gchat] + disbandguild: + description: Deletes your guild + usage: / + aliases: [deleteguild] \ No newline at end of file