complete overhaul

This commit is contained in:
Super_ 2020-07-12 20:40:11 -04:00
parent 66ff1fc2b5
commit 6dfe381787
50 changed files with 1597 additions and 1335 deletions

View file

@ -15,24 +15,28 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TFPatches:TotalFreedomMod:development-8a60ae2235-1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.libraryaddict:LibsDisguises:31672fce7b" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:7.3.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.protocol:ProtocolLib:4.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.rayzr522:jsonmessage:1.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.16.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.16.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
<orderEntry type="library" name="Maven: com.github.TFPatches:TotalFreedomMod:development-f9e8a4c8ba-1" level="project" />
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
<orderEntry type="library" name="Maven: com.github.TFPatches:TF-LibsDisguises:0cfa32159a" level="project" />
<orderEntry type="library" name="Maven: org.ow2.asm:asm:7.3.1" level="project" />
<orderEntry type="library" name="Maven: com.comphenix.protocol:ProtocolLib:4.5.0" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" name="Maven: com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.16-R0.1" level="project" />
<orderEntry type="library" name="Maven: me.rayzr522:jsonmessage:1.0.0" level="project" />
</component>
</module>

28
pom.xml
View file

@ -4,16 +4,15 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.totalfreedom</groupId>
<groupId>TFGuilds</groupId>
<artifactId>TFGuilds</artifactId>
<version>0.1.8</version>
<version>0.2</version>
<packaging>jar</packaging>
<name>TFGuilds</name>
<description>Plugin which allows for players to make their own guilds on the server</description>
<description>A guilds plugin for the TotalFreedom server.</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@ -25,8 +24,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
@ -45,6 +44,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>C:\Users\Jax\Desktop\STUFF\116test\plugins</outputDirectory>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
@ -60,8 +67,8 @@
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
<repository>
<id>sonatype</id>
@ -71,8 +78,8 @@
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@ -80,7 +87,6 @@
<groupId>com.github.TFPatches</groupId>
<artifactId>TotalFreedomMod</artifactId>
<version>development-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,30 @@
package me.totalfreedom.tfguilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Common
{
protected static TFGuilds plugin = TFGuilds.getPlugin();
public static final ChatColor PRIMARY = ConfigEntry.SCHEME_PRIMARY.getChatColor();
public static final ChatColor SECONDARY = ConfigEntry.SCHEME_SECONDARY.getChatColor();
public static final String NO_PERMS = ChatColor.RED + "No permission.";
public static final String PREFIX = "%s%[%p%TFGuilds%s%] %p%";
public static final String PNF = ChatColor.RED + "Player not found.";
public static Map<Player, Guild> INVITES = new HashMap<>();
public static List<Player> IN_GUILD_CHAT = new ArrayList<>();
public static String tl(String in)
{
return in.replaceAll("%p%", PRIMARY + "").replaceAll("%s%", SECONDARY + "");
}
}

View file

@ -1,58 +1,53 @@
package me.totalfreedom.tfguilds;
import me.totalfreedom.tfguilds.bridge.TFMBridge;
import me.totalfreedom.tfguilds.command.*;
import me.totalfreedom.tfguilds.command.GuildChatCommand;
import me.totalfreedom.tfguilds.command.GuildCommand;
import me.totalfreedom.tfguilds.command.TFGuildsCommand;
import me.totalfreedom.tfguilds.config.Config;
import me.totalfreedom.tfguilds.listener.ChatListener;
import me.totalfreedom.tfguilds.util.GLog;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
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;
private static TFGuilds plugin;
public static TFGuilds getPlugin()
{
return plugin;
}
public Config config;
public Config guilds;
public TFMBridge bridge;
@Override
public void onEnable()
{
plugin = this;
enableCommands();
enableListeners();
guilds = new Config(plugin, "guilds.yml");
tfmb = new TFMBridge();
GLog.info("Enabled");
config = new Config("config.yml");
guilds = new Config("guilds.yml");
bridge = new TFMBridge();
this.getCommand("guild").setExecutor(new GuildCommand());
this.getCommand("guildchat").setExecutor(new GuildChatCommand());
this.getCommand("tfguilds").setExecutor(new TFGuildsCommand());
loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName());
}
@Override
public void onDisable()
{
plugin = null;
config.save();
guilds.save();
GLog.info("Disabled");
GLog.info("Disabled " + this.getDescription().getFullName());
}
private void enableCommands()
{
this.getCommand("tfguilds").setExecutor(new TfGuildsCommand());
this.getCommand("createguild").setExecutor(new CreateGuildCommand());
this.getCommand("guildtag").setExecutor(new GuildTagCommand());
this.getCommand("guildchat").setExecutor(new GuildChatCommand());
this.getCommand("disbandguild").setExecutor(new DisbandGuildCommand());
this.getCommand("guildteleport").setExecutor(new GuildTeleportCommand());
this.getCommand("inviteguild").setExecutor(new InviteGuildCommand());
this.getCommand("leaveguild").setExecutor(new LeaveGuildCommand());
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());
this.getCommand("guildlist").setExecutor(new GuildListCommand());
}
private void enableListeners()
private void loadListeners()
{
PluginManager manager = this.getServer().getPluginManager();
manager.registerEvents(new ChatManager(), this);
manager.registerEvents(new ChatListener(), this);
}
}

View file

@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.bridge;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -12,7 +13,7 @@ public class TFMBridge
public TFMBridge()
{
this.plugin = TFGuilds.plugin;
this.plugin = TFGuilds.getPlugin();
this.tfmPlugin = null;
}
@ -38,6 +39,19 @@ public class TFMBridge
public boolean isAdmin(Player player)
{
if (getTFM() == null)
{
return player.isOp();
}
return getTFM().al.isAdmin(player);
}
public boolean isAdmin(CommandSender sender)
{
if (getTFM() == null)
{
return sender.isOp();
}
return getTFM().al.isAdmin(sender);
}
}

View file

@ -0,0 +1,103 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class AddModSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 3)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild(args[1]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
Player player = Bukkit.getPlayer(args[2]);
if (player == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
if (guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "No need to make the owner a moderator!");
return true;
}
if (guild.hasModerator(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for this guild!");
return true;
}
guild.addModerator(player.getName());
sender.sendMessage(tl(PREFIX + "Added %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a moderator of your guild."));
guild.save();
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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
return true;
}
Player n = Bukkit.getPlayer(args[1]);
if (n == null)
{
sender.sendMessage(PNF);
return true;
}
if (guild.getOwner().equals(n.getName()))
{
sender.sendMessage(ChatColor.RED + "No need to make yourself a moderator!");
return true;
}
if (!guild.hasMember(n.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
if (guild.hasModerator(n.getName()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for your guild!");
return true;
}
guild.addModerator(n.getName());
sender.sendMessage(tl(PREFIX + "Added %s%" + n.getName() + "%p% as a moderator for your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a moderator of your guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,46 @@
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 ChatSubcommand 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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (args.length >= 2)
{
String message = StringUtils.join(args, " ", 1, args.length);
guild.chat(player.getName(), message);
return true;
}
if (IN_GUILD_CHAT.contains(player))
{
IN_GUILD_CHAT.remove(player);
sender.sendMessage(tl("%p%Guild chat toggled off."));
return true;
}
IN_GUILD_CHAT.add(player);
sender.sendMessage(tl("%p%Guild chat toggled on."));
return true;
}
}

View file

@ -1,84 +0,0 @@
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.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import java.util.Objects;
public class CreateGuildCommand 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;
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
if (guildMembers != null)
{
try
{
for (String guild : guildMembers.getKeys(false))
{
if (Objects.requireNonNull(plugin.guilds.getString("guilds." + guild + ".members")).contains(player.getName()))
{
player.sendMessage(GMessage.IN_GUILD);
return true;
}
if (guild.equalsIgnoreCase(args[0]))
{
player.sendMessage(ChatColor.RED + "A guild with that name already exists.");
return true;
}
if (args[0].length() > 24)
{
player.sendMessage(ChatColor.RED + "Guild name must not be over 24 characters.");
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
{
if (args[0].equalsIgnoreCase(blacklisted))
{
if (!plugin.tfmb.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
}
GUtil.createGuild(player, args[0]);
Bukkit.broadcastMessage(GUtil.color("&a" + player.getName() + " has created guild &a&l" + args[0]));
player.sendMessage(ChatColor.GREEN + "Successfully created a guild named " + args[0]);
return true;
}
}

View file

@ -0,0 +1,41 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class CreateSubcommand 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;
String name = StringUtils.join(args, " ", 1, args.length);
String identifier = GUtil.flatten(name);
if (Guild.isInGuild(player))
{
sender.sendMessage(ChatColor.RED + "You are already in a guild!");
return true;
}
if (Guild.guildExists(identifier))
{
sender.sendMessage(ChatColor.RED + "A guild with a name similar to yours already exists!");
return true;
}
Guild.createGuild(identifier, name, player);
sender.sendMessage(tl(PREFIX + "Created a guild named \"" + GUtil.colorize(name) + "%p%\"!"));
return true;
}
}

View file

@ -1,56 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GLog;
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;
public class DisbandGuildCommand implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
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;
}
if (args.length == 0)
{
player.sendMessage(ChatColor.RED + "Are you sure you want to delete your guild? Type '/disbandguild CONFIRM' or '/deleteguild CONFIRM' to continue.");
return true;
}
if (args[0].equalsIgnoreCase("confirm"))
{
GUtil.deleteGuild(player, guild);
Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded"));
player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
GLog.info(player.getName() + " deleted guild " + guild);
return true;
}
return false;
}
}

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.util.GUtil;
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 DisbandSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 2)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild(args[1]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
String n = guild.getName();
guild.disband();
sender.sendMessage(tl(PREFIX + "Disbanded \"" + GUtil.colorize(n) + "%p%\"."));
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player) sender;
if (!Guild.isInGuild(player))
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
Guild guild = Guild.getGuild(player);
if (!guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You are not the owner of this guild!");
return true;
}
guild.disband();
sender.sendMessage(tl(PREFIX + "You have disbanded your guild!"));
return true;
}
}

View file

@ -1,85 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GLog;
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 GuildAdminCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
Player player = (Player) sender;
if (!plugin.tfmb.isAdmin(player))
{
player.sendMessage(GMessage.NO_PERMISSION);
return true;
}
if (args.length != 2)
{
return false;
}
String guild = GUtil.getGuild(args[1]);
if (guild == null)
{
player.sendMessage(GMessage.GUILD_NOT_FOUND);
return true;
}
if (args[0].equalsIgnoreCase("cleartag"))
{
GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r "), guild);
player.sendMessage(ChatColor.GREEN + "Successfully cleared tag for guild " + guild);
return true;
}
if (args[0].equalsIgnoreCase("disbandguild"))
{
GUtil.deleteGuild(guild);
Bukkit.broadcastMessage(GUtil.color("&c&l" + guild + " &chas been disbanded"));
player.sendMessage(ChatColor.GREEN + "Successfully deleted and cleared data for " + guild + ".");
GLog.info(player.getName() + " deleted guild " + guild);
return true;
}
if (args[0].equalsIgnoreCase("join"))
{
if (GUtil.isConsole(sender))
{
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
if (GUtil.isGuildMember(player, GUtil.getGuild(player)))
{
player.sendMessage(GMessage.IN_GUILD);
return true;
}
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.add(player.getName());
plugin.guilds.set("guilds." + guild + ".members", players);
plugin.guilds.save();
player.sendMessage(ChatColor.GREEN + "You have successfully joined " + guild);
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.GREEN + player.getName() + " has joined the guild");
}
}
}
return true;
}
}

View file

@ -1,40 +1,46 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
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 GuildChatCommand extends GBase implements CommandExecutor
public class GuildChatCommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0)
if (sender instanceof ConsoleCommandSender)
{
return false;
}
if (GUtil.isConsole(sender))
{
sender.sendMessage(GMessage.PLAYER_ONLY);
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(GMessage.NOT_IN_GUILD);
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
GUtil.guildChat(sender, StringUtils.join(args, " "), guild);
if (args.length >= 1)
{
String message = StringUtils.join(args, " ", 0, args.length);
guild.chat(player.getName(), message);
return true;
}
if (IN_GUILD_CHAT.contains(player))
{
IN_GUILD_CHAT.remove(player);
sender.sendMessage(tl("%p%Guild chat toggled off."));
return true;
}
IN_GUILD_CHAT.add(player);
sender.sendMessage(tl("%p%Guild chat toggled on."));
return true;
}
}

View file

@ -0,0 +1,39 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class GuildCommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length >= 1)
{
switch (args[0].toLowerCase())
{
case "list": 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": return new AddModSubcommand().onCommand(sender, command, label, args);
case "removemod": return new RemoveModSubcommand().onCommand(sender, command, label, args);
case "setowner": return new SetOwnerSubcommand().onCommand(sender, command, label, args);
case "setstate": return new SetStateSubcommand().onCommand(sender, command, label, args);
case "kick": return new KickSubcommand().onCommand(sender, command, label, args);
case "leave": return new LeaveSubcommand().onCommand(sender, command, label, args);
case "tp": return new TPSubcommand().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 "saveconfig": return new SaveConfigSubcommand().onCommand(sender, command, label, args);
case "join": return new JoinSubcommand().onCommand(sender, command, label, args);
}
return false;
}
return new HelpSubcommand().onCommand(sender, command, label, args);
}
}

View file

@ -1,70 +0,0 @@
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.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
public class GuildInfoCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 0)
{
if (GUtil.isConsole(sender) || GUtil.getGuild((Player) sender) == null)
{
sender.sendMessage(GUtil.color("&cProvide a guild name."));
return true;
}
Player player = (Player) sender;
String guild = GUtil.getGuild(player);
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);
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()));
player.sendMessage(GUtil.color("&2Members: &a" + members));
player.sendMessage(GUtil.color("&2-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"));
return true;
}
String guild = GUtil.getGuild(args[0]);
if (guild == null)
{
sender.sendMessage(GMessage.GUILD_NOT_FOUND);
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);
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()));
sender.sendMessage(GUtil.color("&2Members: &a" + members));
sender.sendMessage(GUtil.color("&2-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"));
return true;
}
}

View file

@ -1,86 +0,0 @@
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 GuildKickCommand 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;
}
if (!GUtil.isGuildModerator(player, guild))
{
player.sendMessage(ChatColor.RED + "You must be a guild moderator in order to kick members.");
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 is a moderator and therefore cannot be kicked.");
return true;
}
if (target == player)
{
player.sendMessage(ChatColor.RED + "You may not kick yourself.");
return true;
}
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.remove(target.getName());
plugin.guilds.set("guilds." + guild + ".members", players);
plugin.guilds.save();
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.RED + target.getName() + " has been kicked from the guild");
}
}
player.sendMessage(ChatColor.GREEN + "Successfully kicked " + target.getName() + " from the guild");
target.sendMessage(ChatColor.RED + "You have been kicked from guild " + guild);
return true;
}
}

View file

@ -1,31 +0,0 @@
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;
import org.bukkit.command.CommandSender;
import java.util.List;
public class GuildListCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
List<String> guilds = GUtil.getGuilds();
if (guilds.isEmpty())
{
sender.sendMessage(ChatColor.RED + "Nobody has made a guild yet.");
return true;
}
sender.sendMessage(GUtil.color("&2-=-=-=- &aGuild List (Total: " + guilds.size() + ") &2-=-=-=-"));
sender.sendMessage(GUtil.color("&2- &a" + StringUtils.join(guilds, ",\n&2- &a")));
sender.sendMessage(GUtil.color("&2-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"));
return true;
}
}

View file

@ -1,86 +0,0 @@
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

@ -1,86 +0,0 @@
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

@ -1,70 +0,0 @@
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.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.entity.Player;
public class GuildTagCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
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;
}
if (args.length >= 2)
{
String tag = StringUtils.join(args, " ", 1, args.length);
if (args[0].equalsIgnoreCase("set"))
{
if (!tag.contains("%tag%"))
{
player.sendMessage(ChatColor.RED + "Your guild tag must contain your guild name. Use %tag% to specify where you want your tag.");
return true;
}
tag = tag.replace("%tag%", guild);
GUtil.setTag(GUtil.translateHexColorCodes(tag) + " ", guild);
player.sendMessage(ChatColor.GREEN + "Guild tag set to \"" + GUtil.translateHexColorCodes(tag) + ChatColor.GREEN + "\"");
return true;
}
}
if (args.length == 1)
{
if (args[0].equalsIgnoreCase("clear"))
{
GUtil.setTag(GUtil.color("&8[&7" + guild + "&8]&r "), guild);
player.sendMessage(ChatColor.GREEN + "Removed your guild's tag.");
return true;
}
}
return false;
}
}

View file

@ -1,58 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
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.entity.Player;
public class GuildTeleportCommand 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;
}
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;
}
Location targetLoc = target.getLocation();
player.teleport(targetLoc);
sender.sendMessage(ChatColor.GREEN + "Teleported to " + target.getName() + " successfully.");
target.sendMessage(ChatColor.GREEN + player.getName() + " has teleported to you.");
return true;
}
}

View file

@ -0,0 +1,29 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class HelpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
sender.sendMessage(tl("%s%[%p%TFGuilds%s%] %p%Command List"));
sender.sendMessage(tl("%s% - %p%list [guild]"));
sender.sendMessage(tl("%s% - %p%help"));
sender.sendMessage(tl("%s% - %p%create <name>"));
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%removemod <guild <name> | name>"));
sender.sendMessage(tl("%s% - %p%setowner <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%kick <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%leave"));
sender.sendMessage(tl("%s% - %p%tp <player>"));
sender.sendMessage(tl("%s% - %p%info [guild]"));
sender.sendMessage(tl("%s% - %p%tag <set <tag> | clear>"));
return true;
}
}

View file

@ -0,0 +1,44 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class InfoSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length >= 2)
{
Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
sender.sendMessage(guild.getInformation());
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild((Player) sender);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
sender.sendMessage(guild.getInformation());
return true;
}
}

View file

@ -1,85 +0,0 @@
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 InviteGuildCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length != 1)
{
return false;
}
if (GUtil.isConsole(sender))
{
sender.sendMessage(GMessage.PLAYER_ONLY);
return true;
}
Player player = (Player) sender;
Player target = Bukkit.getPlayer(args[0]);
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.");
return true;
}
target.sendMessage(GUtil.color("&a" + player.getName() + " has invited you to join &a&l" + GUtil.getGuild(player) + "&a."));
GUtil.invitePlayer(target, GUtil.getGuild(player), 60);
player.sendMessage(GUtil.color("&aSent an invitation to " + target.getName()));
return true;
}
if (GUtil.invitedPlayers.containsKey(player.getName()))
{
String guild = GUtil.invitedPlayers.get(player.getName());
if (args[0].equalsIgnoreCase("accept"))
{
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.add(player.getName());
plugin.guilds.set("guilds." + guild + ".members", players);
plugin.guilds.save();
GUtil.invitedPlayers.remove(player.getName());
player.sendMessage(ChatColor.GREEN + "You have successfully joined " + guild);
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.GREEN + player.getName() + " has joined the guild");
}
}
}
if (args[0].equalsIgnoreCase("deny"))
{
GUtil.invitedPlayers.remove(player.getName());
player.sendMessage(ChatColor.GREEN + "You have declined to join " + guild);
}
return true;
}
player.sendMessage(ChatColor.RED + "Player not found.");
return true;
}
}

View file

@ -0,0 +1,78 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildState;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class InviteSubcommand 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 < 2)
return false;
Player player = (Player) sender;
Guild guild = Guild.getGuild(player);
Player invitee = Bukkit.getPlayer(args[1]);
if (invitee == null)
{
sender.sendMessage(PNF);
return true;
}
if (Guild.getGuild(invitee) != null)
{
sender.sendMessage(ChatColor.RED + "This player is already in another guild!");
}
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (guild.getState() == GuildState.CLOSED)
{
sender.sendMessage(ChatColor.RED + "The guild is currently closed!");
return true;
}
if (guild.getState() == GuildState.OPEN)
{
sender.sendMessage(ChatColor.RED + "The guild is open! Tell your friend to join using \"/g join\"!");
return true;
}
if (INVITES.containsKey(invitee))
{
sender.sendMessage(ChatColor.RED + "They have already been invited to your guild!");
return true;
}
INVITES.put(invitee, guild);
invitee.sendMessage(tl("%p%You have been invited to join %s%" + GUtil.colorize(guild.getName())) + "%p% through %s%" + player.getName() + "%p%'s invite!");
invitee.sendMessage(tl("%p%Do %s%/g join " + ChatColor.stripColor(GUtil.colorize(guild.getName())) + "%p% to join!"));
invitee.sendMessage(tl("%p%This invite will expire in 90 seconds."));
sender.sendMessage(tl("%p%Invite sent!"));
new BukkitRunnable()
{
public void run()
{
if (!INVITES.containsKey(invitee))
return;
INVITES.remove(player);
invitee.sendMessage(ChatColor.RED + "Invite expired.");
sender.sendMessage(ChatColor.RED + "Invite expired.");
}
}.runTaskLater(plugin, 20 * 90);
return true;
}
}

View file

@ -0,0 +1,58 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildState;
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;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class JoinSubcommand 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 < 2)
return false;
Player player = (Player) sender;
if (Guild.getGuild(player) != null)
{
sender.sendMessage(ChatColor.RED + "You are already in a guild!");
return true;
}
Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
if (guild.getState() == GuildState.CLOSED)
{
sender.sendMessage(ChatColor.RED + "That guild is currently closed!");
return true;
}
if (guild.getState() == GuildState.INVITE_ONLY)
{
if (!INVITES.containsKey(player))
{
sender.sendMessage(ChatColor.RED + "You have not been invited to this guild!");
return true;
}
INVITES.remove(player);
}
guild.addMember(player.getName());
guild.broadcast(tl("%s%" + player.getName() + " %p%has joined your guild!"));
guild.save();
return true;
}
}

View file

@ -0,0 +1,100 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class KickSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 3)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild(args[1]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
Player player = Bukkit.getPlayer(args[2]);
if (player == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
if (guild.getOwner().equals(player.getName()) || guild.hasModerator(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
return true;
}
guild.removeMember(player.getName());
sender.sendMessage(tl(PREFIX + "Kicked %s%" + player.getName() + "%p% from %s%" + GUtil.colorize(guild.getName()) + "%p%."));
player.sendMessage(tl("%s%You have been kicked from your guild."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been kicked from your guild."));
guild.save();
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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.hasModerator(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You can't kick people from your guild!");
return true;
}
Player n = Bukkit.getPlayer(args[1]);
if (n == null)
{
sender.sendMessage(PNF);
return true;
}
if (guild.getOwner().equals(n.getName()))
{
sender.sendMessage(ChatColor.RED + "No need to make yourself a moderator!");
return true;
}
if (!guild.hasMember(n.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
if ((guild.getOwner().equals(n.getName()) || guild.hasModerator(n.getName())) && !guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
return true;
}
guild.removeMember(n.getName());
sender.sendMessage(tl(PREFIX + "Kicked %s%" + n.getName() + "%p% from your guild."));
n.sendMessage(tl("%s%You have been kicked from your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been kicked from your guild."));
guild.save();
return true;
}
}

View file

@ -1,66 +0,0 @@
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 LeaveGuildCommand extends GBase implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
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(ChatColor.RED + "You may not leave your guild. However, if you want to delete it run /disbandguild");
return true;
}
if (args.length == 0)
{
player.sendMessage(ChatColor.RED + "Are you sure you want to leave your guild? Type '/leaveguild CONFIRM' or '/guildleave CONFIRM' to continue.");
return true;
}
if (args[0].equalsIgnoreCase("confirm"))
{
List<String> players = plugin.guilds.getStringList("guilds." + guild + ".members");
players.remove(player.getName());
plugin.guilds.set("guilds." + guild + ".members", players);
plugin.guilds.save();
for (Player p : Bukkit.getOnlinePlayers())
{
if (GUtil.isGuildMember(p, guild))
{
p.sendMessage(ChatColor.RED + player.getName() + " has left the guild");
}
}
player.sendMessage(ChatColor.GREEN + "Successfully left " + guild + ".");
return true;
}
return true;
}
}

View file

@ -0,0 +1,43 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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 LeaveSubcommand 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 > 1)
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 cannot leave as you are the owner!");
return true;
}
guild.removeModerator(player.getName());
guild.removeMember(player.getName());
guild.save();
sender.sendMessage(tl("%p%You left your guild."));
guild.broadcast(tl("%s%" + sender.getName() + " %p%left the guild."));
return true;
}
}

View file

@ -0,0 +1,44 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class ListSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length >= 2)
{
Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
sender.sendMessage(guild.getList());
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild((Player) sender);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
return true;
}
sender.sendMessage(guild.getList());
return true;
}
}

View file

@ -0,0 +1,93 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class RemoveModSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 3)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild(args[1]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
Player player = Bukkit.getPlayer(args[2]);
if (player == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
if (!guild.hasModerator(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This member is not a moderator for this guild!");
return true;
}
guild.removeModerator(player.getName());
sender.sendMessage(tl(PREFIX + "Removed %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a member of your guild."));
guild.save();
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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
return true;
}
Player n = Bukkit.getPlayer(args[1]);
if (n == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(n.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
if (!guild.hasModerator(n.getName()))
{
sender.sendMessage(ChatColor.RED + "This member is not a moderator for your guild!");
return true;
}
guild.removeModerator(n.getName());
sender.sendMessage(tl(PREFIX + "Removed %s%" + n.getName() + "%p% as a moderator for your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a member of your guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,32 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SaveConfigSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length != 1)
return false;
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
plugin.config.load();
plugin.guilds.load();
plugin.config.save();
plugin.guilds.save();
sender.sendMessage(tl(PREFIX + "Saved all configuration files in their current state."));
return true;
}
}

View file

@ -0,0 +1,85 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SetOwnerSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 3)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild(args[1]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
Player player = Bukkit.getPlayer(args[2]);
if (player == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(player.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
guild.removeModerator(player.getName());
guild.setOwner(player.getName());
sender.sendMessage(tl(PREFIX + "Ownership has been transferred to %s%" + player.getName() + "%p% in %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made the owner of your guild."));
guild.save();
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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is the owner of your guild!");
return true;
}
Player n = Bukkit.getPlayer(args[1]);
if (n == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(n.getName()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
guild.removeModerator(n.getName());
guild.setOwner(n.getName());
sender.sendMessage(tl(PREFIX + "Ownership has been transferred to %s%" + n.getName() + "%p% in your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made the owner of your guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,73 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildState;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SetStateSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 3)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild(args[1]);
if (guild == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
GuildState state = GuildState.findState(args[2]);
if (state == null)
{
sender.sendMessage(ChatColor.RED + "That is not a valid state!");
return true;
}
guild.setState(state);
sender.sendMessage(tl(PREFIX + "Set the guild state to %s%" + state.getDisplay().toLowerCase() + "%p% in %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%p%The guild is now %s%" + state.getDisplay().toLowerCase() + "%p%."));
guild.save();
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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.hasModerator(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You can't change the state of the guild!");
return true;
}
GuildState state = GuildState.findState(args[1]);
if (state == null)
{
sender.sendMessage(ChatColor.RED + "That is not a valid state!");
return true;
}
guild.setState(state);
sender.sendMessage(tl(PREFIX + "Set the guild state to %s%" + state.getDisplay().toLowerCase() + "%p% in your guild."));
guild.broadcast(tl("%p%The guild is now %s%" + state.getDisplay().toLowerCase() + "%p%."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,26 @@
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 TFGuildsCommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length != 0)
return false;
sender.sendMessage(tl(PREFIX + "Plugin Information"));
sender.sendMessage(tl("%s%Programmers%p%: speed and super"));
sender.sendMessage(tl("%s%Version%p%: " + plugin.getDescription().getVersion()));
sender.sendMessage(tl("%s%Special Thanks%p%: ron (testing)"));
return true;
}
}

View file

@ -0,0 +1,48 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class TPSubcommand 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 != 2)
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;
}
Player to = Bukkit.getPlayer(args[1]);
if (to == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.getMembers().contains(to.getName()))
{
sender.sendMessage(ChatColor.RED + "That player is not in your guild.");
return true;
}
player.teleport(to.getLocation());
sender.sendMessage(tl("%p%Teleported to %s%" + to.getName() + "%p%."));
to.sendMessage(tl("%s%" + sender.getName() + " %p%has teleported to you."));
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.util.GUtil;
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 TagSubcommand 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(ChatColor.RED + "You aren't in a guild!");
return true;
}
if (!guild.getOwner().equals(player.getName()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's tag!");
return true;
}
if (args.length >= 3)
{
if (args[1].toLowerCase().equals("set"))
{
String tag = StringUtils.join(args, " ", 2, args.length);
guild.setTag(tag);
guild.save();
sender.sendMessage(tl("%p%Your guild tag has been changed to be \"" + GUtil.colorize(tag) + "%p%\"."));
return true;
}
return false;
}
if (args[1].toLowerCase().equals("clear"))
{
guild.setTag(null);
guild.save();
sender.sendMessage(tl("%p%Your guild tag has been cleared."));
return true;
}
return true;
}
}

View file

@ -1,50 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.util.GBase;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GMessage;
import me.totalfreedom.tfguilds.util.GUtil;
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)
{
if (args.length == 0)
{
sender.sendMessage(GUtil.color("&aTFGuilds &2is a plugin which allows for players to make their own guilds, providing guild chat, guild teleportation, and more."));
sender.sendMessage(String.format(GUtil.color("&2Version &av%s"), plugin.getDescription().getVersion()));
sender.sendMessage(GUtil.color("&2Developed by &aspeednt"));
sender.sendMessage(GUtil.color("&2Contributors"));
sender.sendMessage(GUtil.color("&a- supernt"));
sender.sendMessage(GUtil.color("&2https://github.com/TFPatches/TFGuilds"));
return true;
}
if (args[0].toLowerCase().equals("reload"))
{
if (!plugin.tfmb.isAdmin((Player) sender))
{
sender.sendMessage(GMessage.NO_PERMISSION);
return true;
}
try
{
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

@ -10,9 +10,9 @@ public class Config extends YamlConfiguration
private final TFGuilds plugin;
private final File file;
public Config(TFGuilds plugin, String name)
public Config(String name)
{
this.plugin = plugin;
this.plugin = TFGuilds.getPlugin();
this.file = new File(plugin.getDataFolder(), name);
if (!file.exists())

View file

@ -0,0 +1,24 @@
package me.totalfreedom.tfguilds.config;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.ChatColor;
public enum ConfigEntry
{
SCHEME_PRIMARY("scheme.primary"),
SCHEME_SECONDARY("scheme.secondary");
private final String path;
ConfigEntry(String path)
{
this.path = path;
}
private static Config config = TFGuilds.getPlugin().config;
public ChatColor getChatColor()
{
return ChatColor.valueOf(config.getString(path).toUpperCase());
}
}

View file

@ -0,0 +1,226 @@
package me.totalfreedom.tfguilds.guild;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Guild
{
private static TFGuilds plugin = TFGuilds.getPlugin();
@Getter
private final String identifier;
@Getter
private final String name;
@Getter
@Setter
private String owner;
@Getter
private List<String> moderators;
@Getter
private List<String> members;
@Getter
@Setter
private String tag;
@Getter
@Setter
private GuildState state;
@Getter
private final long creation;
public Guild(String identifier, String name, String owner, List<String> members, List<String> moderators, String tag, GuildState state, long creation)
{
this.identifier = identifier;
this.name = name;
this.owner = owner;
this.members = members;
this.moderators = moderators;
this.tag = tag;
this.state = state;
this.creation = creation;
}
public void save()
{
plugin.guilds.set(identifier + ".name", name);
plugin.guilds.set(identifier + ".owner", owner);
plugin.guilds.set(identifier + ".members", members);
plugin.guilds.set(identifier + ".moderators", moderators);
plugin.guilds.set(identifier + ".tag", tag);
plugin.guilds.set(identifier + ".state", state.name());
plugin.guilds.set(identifier + ".creation", creation);
plugin.guilds.save();
}
public void addMember(String name)
{
members.add(name);
}
public void removeMember(String name)
{
Player player = Bukkit.getPlayer(name);
if (player != null)
Common.IN_GUILD_CHAT.remove(player);
members.remove(name);
moderators.remove(name);
}
public boolean hasMember(String name)
{
return members.contains(name);
}
public void addModerator(String name)
{
moderators.add(name);
}
public void removeModerator(String name)
{
moderators.remove(name);
}
public boolean hasModerator(String name)
{
if (owner.equals(name))
return true;
return moderators.contains(name);
}
public boolean hasTag()
{
return tag != null;
}
public void broadcast(String message)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (members.contains(player.getName()))
{
player.sendMessage(message);
}
}
}
public List<String> getOnlyMembers()
{
List<String> only = new ArrayList<>();
for (String member : members)
{
if (member.equals(owner) || moderators.contains(member))
continue;
only.add(member);
}
return only;
}
public String getList()
{
return Common.tl(Common.PREFIX + "Guild Roster\n" +
"%s%Owner%p% - " + owner + "\n" +
"%s%Moderators%p% - " + StringUtils.join(moderators, ", ") + "\n" +
"%s%Members%p% - " + StringUtils.join(getOnlyMembers(), ", ") + "\n");
}
public String getInformation()
{
return Common.tl(Common.PREFIX + "Guild Information\n" +
"%s%Name%p%: " + GUtil.colorize(name) + "\n" +
"%s%Owner%p%: " + owner + "\n" +
"%s%Moderators%p%: " + StringUtils.join(moderators, ", ") + "\n" +
"%s%Members%p%: " + StringUtils.join(getOnlyMembers(), ", ") + "\n" +
"%s%Tag%p%: " + (tag == null ? "None" : GUtil.colorize(tag)) + "\n" +
"%s%State%p%: " + state.getDisplay() + "\n" +
"%s%Creation%p%: " + GUtil.format(creation) + "\n" +
"%s%Identifier (Technical)%p%: " + identifier + "\n");
}
public void chat(String as, String msg)
{
broadcast(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg));
}
public void disband()
{
for (String member : members)
{
Player player = Bukkit.getPlayer(member);
if (player == null)
continue;
Common.IN_GUILD_CHAT.remove(player);
}
plugin.guilds.set(identifier, null);
plugin.guilds.save();
}
public static Guild createGuild(String identifier, String name, Player owner)
{
if (plugin.guilds.contains(identifier))
return getGuild(identifier);
Guild guild = new Guild(identifier, name, owner.getName(), Collections.singletonList(owner.getName()), new ArrayList<>(), null, GuildState.INVITE_ONLY, System.currentTimeMillis());
guild.save();
return guild;
}
public static Guild getGuild(String identifier)
{
if (!plugin.guilds.contains(identifier))
return null;
return new Guild(identifier,
plugin.guilds.getString(identifier + ".name"),
plugin.guilds.getString(identifier + ".owner"),
plugin.guilds.getStringList(identifier + ".members"),
plugin.guilds.getStringList(identifier + ".moderators"),
plugin.guilds.getString(identifier + ".tag"),
GuildState.valueOf(plugin.guilds.getString(identifier + ".state")),
plugin.guilds.getLong(identifier + ".creation"));
}
public static Guild getGuild(Player player)
{
Guild guild = null;
for (String key : plugin.guilds.getKeys(false))
{
Guild kg = getGuild(key);
if (kg.getMembers().contains(player.getName()))
guild = kg;
}
return guild;
}
public static boolean guildExists(String identifier)
{
return plugin.guilds.contains(identifier);
}
public static boolean isInGuild(Player player)
{
for (String key : plugin.guilds.getKeys(false))
{
Guild guild = getGuild(key);
if (guild.getMembers().contains(player.getName()))
return true;
}
return false;
}
}

View file

@ -0,0 +1,36 @@
package me.totalfreedom.tfguilds.guild;
import lombok.Getter;
public enum GuildState
{
OPEN("Open"),
INVITE_ONLY("Invite-only"),
CLOSED("Closed");
@Getter
private final String display;
GuildState(String display)
{
this.display = display;
}
public static GuildState findState(String string)
{
switch (string.toLowerCase())
{
case "open":
case "opened":
return OPEN;
case "invite":
case "inviteonly":
case "invite_only":
return INVITE_ONLY;
case "closed":
case "close":
return CLOSED;
}
return null;
}
}

View file

@ -0,0 +1,31 @@
package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener
{
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent e)
{
Player player = e.getPlayer();
Guild guild = Guild.getGuild(player);
if (guild == null)
return;
if (Common.IN_GUILD_CHAT.contains(player))
{
e.setCancelled(true);
guild.chat(player.getName(), e.getMessage());
}
if (guild.hasTag())
{
e.setFormat(GUtil.colorize(guild.getTag()) + ChatColor.RESET + " " + e.getFormat());
}
}
}

View file

@ -1,31 +0,0 @@
package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatManager implements Listener
{
private final TFGuilds plugin;
public ChatManager()
{
this.plugin = TFGuilds.plugin;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent e)
{
Player player = e.getPlayer();
String guild = GUtil.getGuild(player);
if (guild == null)
{
return;
}
e.setFormat(GUtil.color(GUtil.getTag(guild)) + ChatColor.RESET + e.getFormat());
}
}

View file

@ -1,8 +0,0 @@
package me.totalfreedom.tfguilds.util;
import me.totalfreedom.tfguilds.TFGuilds;
public class GBase
{
protected static TFGuilds plugin = TFGuilds.plugin;
}

View file

@ -5,26 +5,26 @@ import java.util.logging.Logger;
public class GLog
{
private static final Logger log = Logger.getLogger("Minecraft");
private static final String prefix = "[TFGuilds] ";
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private static final String PREFIX = "[TFGuilds]";
private static void log(String s, Level l)
private static void log(Object o, Level l)
{
log.log(l, prefix + s);
LOGGER.log(l, PREFIX + " " + o);
}
public static void info(String s)
public static void info(Object o)
{
log(s, Level.INFO);
log(o, Level.INFO);
}
public static void warn(String s)
public static void warn(Object o)
{
log(s, Level.WARNING);
log(o, Level.WARNING);
}
public static void severe(String s)
public static void severe(Object o)
{
log(s, Level.SEVERE);
log(o, Level.SEVERE);
}
}

View file

@ -1,14 +0,0 @@
package me.totalfreedom.tfguilds.util;
import org.bukkit.ChatColor;
public class GMessage
{
public static String NO_PERMISSION = ChatColor.RED + "No permission.";
public static String PLAYER_ONLY = ChatColor.RED + "You are not allowed to run this command.";
public static String IN_GUILD = ChatColor.RED + "You are already in a guild!";
public static String NOT_OWNER = ChatColor.RED + "You aren't the owner of your guild.";
public static String GUILD_NOT_FOUND = ChatColor.RED + "Guild not found.";
public static String NOT_IN_GUILD = ChatColor.RED + "You aren't in a guild!";
public static String PLAYER_NOT_FOUND = ChatColor.RED + "Player not found.";
}

View file

@ -1,249 +1,43 @@
package me.totalfreedom.tfguilds.util;
import org.bukkit.Bukkit;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.scheduler.BukkitRunnable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class GUtil
{
public static TFGuilds plugin = TFGuilds.plugin;
public static HashMap<String, String> invitedPlayers = new HashMap<>();
private static final SimpleDateFormat STANDARD = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
public static boolean isConsole(CommandSender sender)
public static String flatten(String s)
{
return sender instanceof ConsoleCommandSender;
String[] split = s.split(" ");
for (int i = 0; i < split.length; i++)
{
split[i] = ChatColor.stripColor(colorize(split[i].toLowerCase()));
}
return StringUtils.join(split, "_");
}
public static void createGuild(CommandSender owner, String guildName)
public static String colorize(String string)
{
// Set guild name & owner
plugin.guilds.set("guilds." + guildName, guildName);
plugin.guilds.set("guilds." + guildName + ".owner", owner.getName());
// Set guild moderator
List<String> moderators = plugin.guilds.getStringList("guilds." + guildName + ".moderators");
moderators.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".moderators", moderators);
// Set guild player
List<String> players = plugin.guilds.getStringList("guilds." + guildName + ".members");
players.add(owner.getName());
plugin.guilds.set("guilds." + guildName + ".members", players);
plugin.guilds.set("guilds." + guildName + ".tag", GUtil.color("&8[&7" + guildName + "&8]&r "));
// Set time guild was created
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date = new Date();
plugin.guilds.set("guilds." + guildName + ".created", dateFormat.format(date));
// Add guild to guild list
List<String> guilds = plugin.guilds.getStringList("list");
guilds.add(guildName);
plugin.guilds.set("list", guilds);
// Save everything & log guild creation
plugin.guilds.save();
GLog.info(owner.getName() + " has created a new guild: " + guildName);
}
public static void deleteGuild(CommandSender owner, String guildName)
{
GLog.info("Removing guilds.yml data for " + guildName);
plugin.guilds.set("guilds." + guildName, null);
List<String> guilds = plugin.guilds.getStringList("list");
guilds.remove(guildName);
plugin.guilds.set("list", guilds);
plugin.guilds.save();
}
public static void deleteGuild(String guildName)
{
GLog.info("Removing guilds.yml data for " + guildName);
plugin.guilds.set("guilds." + guildName, null);
List<String> guilds = plugin.guilds.getStringList("list");
guilds.remove(guildName);
plugin.guilds.set("list", guilds);
plugin.guilds.save();
}
public static void invitePlayer(Player player, String guild, int seconds)
{
if (seconds > 0)
{
invitedPlayers.put(player.getName(), guild);
player.sendMessage(ChatColor.GREEN + "To accept or decline, type /inviteguild accept or /inviteguild deny");
player.sendMessage(ChatColor.GREEN + "You have " + seconds + " seconds to accept the request before it gets declined automatically.");
}
new BukkitRunnable()
{
public void run()
{
if (!invitedPlayers.containsKey(player.getName()))
{
return;
}
invitedPlayers.remove(player.getName());
player.sendMessage(ChatColor.RED + "Your invitation has expired.");
}
}.runTaskLater(plugin, seconds * 20);
}
public static void setTag(String tag, String guildName)
{
plugin.guilds.set("guilds." + guildName + ".tag", tag);
plugin.guilds.save();
}
public static String getTag(String guildName)
{
return plugin.guilds.getString("guilds." + guildName + ".tag");
}
public static String getTimeCreated(String guildName)
{
return plugin.guilds.getString("guilds." + guildName + ".created");
}
public static boolean hasTag(String guildName)
{
return plugin.guilds.contains("guilds." + guildName + ".tag");
}
public static String getGuild(Player player)
{
String g = "";
boolean a = false;
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
if (guildMembers != null)
{
try
{
for (String guild : guildMembers.getKeys(false))
{
List<String> members = plugin.guilds.getStringList("guilds." + guild + ".members");
if (members.contains(player.getName()))
{
a = true;
g = guild;
}
}
}
catch (Exception e)
{
e.fillInStackTrace();
}
}
if (!a)
return null;
return g;
}
public static String getGuild(String arg)
{
String g = "";
boolean a = false;
ConfigurationSection guildMembers = plugin.guilds.getConfigurationSection("guilds");
if (guildMembers != null)
{
try
{
for (String guild : guildMembers.getKeys(false))
{
if (guild.equals(arg))
{
a = true;
g = guild;
}
}
}
catch (Exception e)
{
e.fillInStackTrace();
}
}
if (!a)
return null;
return g;
}
public static List<String> getGuilds()
{
return plugin.guilds.getStringList("list");
}
public static String getOwner(String guildName)
{
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");
}
public static boolean isGuildMember(Player player, String guildName)
{
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)
{
String sent = ChatColor.DARK_GRAY + "[" + ChatColor.BLUE + "GC" + ChatColor.DARK_GRAY + "] " + getTag(guildName) + ChatColor.BLUE + sender
.getName() + ChatColor.GRAY + ": " + ChatColor.AQUA + message;
GLog.info(sent);
for (Player player : Bukkit.getOnlinePlayers())
{
if (isGuildMember(player, guildName))
{
player.sendMessage(sent);
}
}
}
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
"admin", "owner", "moderator", "developer", "console", "dev", "staff", "mod", "sra", "tca", "sta", "sa");
public static String color(String s)
{
return ChatColor.translateAlternateColorCodes('&', s);
}
public static String translateHexColorCodes(String message)
{
Pattern pattern = Pattern.compile("&#[a-f0-9A-F]{6}");
Matcher matcher = pattern.matcher(message);
Matcher matcher = Pattern.compile("&#[a-f0-9A-F]{6}").matcher(string);
while (matcher.find())
{
String color = matcher.group().replace("&", "");
message = message.replace("&" + color, net.md_5.bungee.api.ChatColor.of(color) + "");
String code = matcher.group().replace("&", "");
string = string.replace("&" + code, net.md_5.bungee.api.ChatColor.of(code) + "");
}
message = ChatColor.translateAlternateColorCodes('&', message);
return message;
string = ChatColor.translateAlternateColorCodes('&', string);
return string;
}
public static String format(long time)
{
Date date = new Date(time);
return STANDARD.format(date);
}
}

View file

@ -0,0 +1,7 @@
#
# TFGuilds - Configuration
#
scheme:
primary: GREEN
secondary: DARK_GREEN

View file

@ -1,61 +1,20 @@
name: TFGuilds
version: ${project.version}
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]
api-version: 1.13
softdepend: [TotalFreedomMod]
authors: [speed, super]
description: A guilds plugin for the TotalFreedom server.
commands:
tfguilds:
description: Plugin info
usage: /<command> <reload>
aliases: [guilds, tfguildsinfo, tfginfo, guildsinfo]
createguild:
description: Creates a guild
usage: /<command> <guild>
aliases: [guildcreate]
guildtag:
description: Modify your guild's tag
usage: /<command> <set <tag> | clear>
aliases: [gtag]
guild:
description: The main command of TFGuilds.
usage: /<command> [list [guild] | help | create <name> | disband [name] | invite <player> | addmod <guild <player> | player> | removemod <guild <name> | name> | createrole <name> | setowner <guild <player> | player> | kick <guild <player> | player> | leave | setstate <guild <state> | state> | tp <player> | info [guild] | tag <set <tag> | clear> | join <guild> | chat [message] | saveconfig]
aliases: [g]
guildchat:
description: Speak to your guild
usage: /<command> <message>
aliases: [gchat]
disbandguild:
description: Deletes your guild
usage: /<command> <confirm>
aliases: [deleteguild]
guildteleport:
description: Teleport to other guild members
usage: /<command> <player>
aliases: [guildtp, tpguild]
inviteguild:
description: If invited, allows you to join a guild
usage: /<command> <player>
aliases: [guildinvite]
leaveguild:
description: Leave your guild
usage: /<command> <confirm>
aliases: [guildleave]
guildkick:
description: Kicks a player from the guild
usage: /<command> <player>
guildinfo:
description: Gives you information about any guild
usage: /<command> <guild>
guildadmin:
description: Guild commands only for admins
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: Demotes a guild mod
usage: /<command> <player>
aliases: [gremovemod, removeguildmod, removeguildmoderator, guildremovemod, guilddemote, gdemote]
guildlist:
description: Lists all guilds
description: Talk in chat with your guild.
usage: /<command> [message]
aliases: [gchat, gc]
tfguilds:
description: Information about the plugin.
usage: /<command>
aliases: [listguilds]
aliases: [tfg]