readd tfm bridge and add guild deletion

This commit is contained in:
speedxx 2020-06-18 22:59:47 -04:00
parent f55e2ebb72
commit 9f2fd4ad87
8 changed files with 175 additions and 14 deletions

20
pom.xml
View file

@ -55,6 +55,14 @@
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
@ -78,5 +86,17 @@
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TFPatches</groupId>
<artifactId>TotalFreedomMod</artifactId>
<version>5.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Pravian</groupId>
<artifactId>Aero</artifactId>
<version>5f82926</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -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()

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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;
}
}
}

View file

@ -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<String> 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);

View file

@ -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: /<command>
usage: /<command> <reload>
aliases: [guilds, tfguildsinfo, tfginfo, guildsinfo]
createguild:
description: Creates a guild
@ -20,4 +21,8 @@ commands:
guildchat:
description: Speak to your guild
usage: /<command> <message>
aliases: [gchat]
aliases: [gchat]
disbandguild:
description: Deletes your guild
usage: /<command>
aliases: [deleteguild]