TFGuilds Rewrite (FS-164, FS-133, FS-244) (#7)

* TFGuilds rewrite almost completed (FS-164 FS-133 FS-244)

The rewrite is nearing completion - few modifications to TFGuilds and TFM and it will be ready for production

* Finalise few things

* Code cleanup

* Use empty list instead and true instead of false
This commit is contained in:
Nathan Curran 2021-05-22 14:26:48 +10:00 committed by GitHub
parent 8b16fc57e8
commit e6d3dc6b12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
96 changed files with 3018 additions and 4291 deletions

View file

@ -9,24 +9,6 @@
</value>
</option>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" alias="false" withSubpackages="false" />
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
<package name="io.ktor" alias="false" withSubpackages="true" />
</value>
</option>
<option name="PACKAGES_IMPORT_LAYOUT">
<value>
<package name="" alias="false" withSubpackages="true" />
<package name="java" alias="false" withSubpackages="true" />
<package name="javax" alias="false" withSubpackages="true" />
<package name="kotlin" alias="false" withSubpackages="true" />
<package name="" alias="true" withSubpackages="true" />
</value>
</option>
</JetCodeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="BRACE_STYLE" value="2" />
<option name="CLASS_BRACE_STYLE" value="2" />

View file

@ -11,7 +11,7 @@
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="TFGuilds" target="1.8" />
<module name="TFGuilds" target="11" />
</bytecodeTargetLevel>
</component>
</project>

View file

@ -6,35 +6,35 @@
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jitpack.io" />
<option name="name" value="jitpack.io" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="telesphoreo-repo" />
<option name="name" value="telesphoreo-repo" />
<option name="url" value="https://telesphoreo.me/repo/maven" />
</remote-repository>
<remote-repository>
<option name="id" value="spigotmc-repo" />
<option name="name" value="spigotmc-repo" />
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="sonatype" />
<option name="name" value="sonatype" />
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="spigotmc-repo" />
<option name="name" value="spigotmc-repo" />
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="telesphoreo-repo" />
<option name="name" value="telesphoreo-repo" />
<option name="url" value="https://telesphoreo.me/repo/maven" />
</remote-repository>
</component>
</project>

View file

@ -9,7 +9,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
@ -19,26 +19,13 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.5-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.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.totalfreedom:TotalFreedomMod:2020.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.7" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.commons:commons-lang3:3.11" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.TFPatches:TF-LibsDisguises:0cfa32159a" 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: 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.reflections:reflections:0.9.11" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.javassist:javassist:3.21.0-GA" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javassist:javassist:3.12.1.GA" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.27" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.AtlasMediaGroup:TotalFreedomMod:main-caaa067096-1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-artifact:3.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven:maven-core:3.0" level="project" />
@ -68,6 +55,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: xml-apis:xml-apis:1.3.04" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpclient:4.0.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.httpcomponents:httpcore:4.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-validator:commons-validator:1.3.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-digester:commons-digester:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.0.4" level="project" />
@ -87,6 +75,7 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.struts:struts-taglib:1.3.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.struts:struts-tiles:1.3.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.maven.doxia:doxia-integration-tools:1.6" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:1.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.codehaus.plexus:plexus-container-default:1.0-alpha-9" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: classworlds:classworlds:1.1-alpha-2" level="project" />
@ -105,6 +94,13 @@
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.14" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.junit.jupiter:junit-jupiter:5.4.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.junit.jupiter:junit-jupiter-api:5.4.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.opentest4j:opentest4j:1.1.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.junit.platform:junit-platform-commons:1.4.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.junit.jupiter:junit-jupiter-params:5.4.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.4.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.junit.platform:junit-platform-engine:1.4.2" level="project" />
</component>
</module>

14
pom.xml
View file

@ -63,29 +63,19 @@
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.AtlasMediaGroup</groupId>
<artifactId>TotalFreedomMod</artifactId>
<version>development-0be2aa718f-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<version>main-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View file

@ -1,37 +1,23 @@
package me.totalfreedom.tfguilds;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
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 final String NG = ChatColor.RED + "You aren't in a guild!";
public static final String PREFIX = ChatColor.AQUA + "TFGuilds " + ChatColor.DARK_GRAY + "\u00BB " + ChatColor.GRAY;
public static final String NOT_IN_GUILD = PREFIX + "You are not in a guild.";
public static final String IN_GUILD = PREFIX + "You are already in a guild.";
public static final String PLAYER_NOT_FOUND = PREFIX + "That player is not online.";
public static final String PLAYER_NOT_IN_GUILD = PREFIX + "That player is not in your guild.";
public static final String IN_GAME_ONLY = PREFIX + "You must be in-game to interact with guilds";
public static final String USAGE = PREFIX + "Correct usage: " + ChatColor.GOLD;
public static Map<Player, Guild> INVITES = new HashMap<>();
public static List<Player> IN_GUILD_CHAT = new ArrayList<>();
public static List<Player> CHAT_SPY = new ArrayList<>();
public static final TFMBridge tfmBridge = TFGuilds.getPlugin().getTfmBridge();
public static String tl(String in)
{
return in.replaceAll("%p%", PRIMARY + "").replaceAll("%s%", SECONDARY + "");
}
public static void broadcast(String msg)
{
Bukkit.broadcastMessage(msg);
}
public static List<Player> GUILD_CHAT = new ArrayList<>();
public static List<Player> GUILD_CHAT_SPY = new ArrayList<>();
}

View file

@ -1,91 +1,115 @@
package me.totalfreedom.tfguilds;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.totalfreedom.tfguilds.bridge.TFMBridge;
import me.totalfreedom.tfguilds.command.GuildChatCommand;
import me.totalfreedom.tfguilds.command.GuildChatSpyCommand;
import me.totalfreedom.tfguilds.command.GuildCommand;
import me.totalfreedom.tfguilds.command.TFGuildsCommand;
import me.totalfreedom.tfguilds.command.*;
import me.totalfreedom.tfguilds.config.Config;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildWarp;
import me.totalfreedom.tfguilds.guild.User;
import me.totalfreedom.tfguilds.listener.ChatListener;
import me.totalfreedom.tfguilds.listener.JoinListener;
import me.totalfreedom.tfguilds.sql.SQLDatabase;
import me.totalfreedom.tfguilds.sql.SQLGuildData;
import me.totalfreedom.tfguilds.sql.SQLRankData;
import me.totalfreedom.tfguilds.sql.SQLUserData;
import me.totalfreedom.tfguilds.sql.SQLWarpData;
import me.totalfreedom.tfguilds.sql.SQLWorldData;
import me.totalfreedom.tfguilds.util.GLog;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public final class TFGuilds extends JavaPlugin
public class TFGuilds extends JavaPlugin
{
// TEMP FIX UNTIL REWRITE
public Map<String, Guild> guilds;
public Map<String, GuildWarp> warps;
private static TFGuilds plugin;
private Config config;
private SQLDatabase sqlDatabase;
private TFMBridge tfmBridge;
private Map<String, SubCommand> subCommands = new HashMap<>();
public static TFGuilds getPlugin()
{
return plugin;
}
public Config config;
public TFMBridge bridge;
public SQLDatabase sql;
public SQLGuildData guildData;
public SQLRankData rankData;
public SQLUserData userData;
public SQLWarpData warpData;
public SQLWorldData worldData;
@Override
public void onEnable()
{
plugin = this;
this.plugin = this;
config = new Config("config.yml");
bridge = new TFMBridge();
guilds = new HashMap<>();
warps = new HashMap<>();
sql = new SQLDatabase();
guildData = new SQLGuildData();
rankData = new SQLRankData();
userData = new SQLUserData();
warpData = new SQLWarpData();
worldData = new SQLWorldData();
guildData.getAll();
warpData.getAll();
loadCommands();
loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName());
sqlDatabase = new SQLDatabase(this);
User.loadAll();
Guild.loadAll();
tfmBridge = new TFMBridge();
tfmBridge.getTfm();
new JoinListener(this);
new ChatListener(this);
loadSubCommands();
getCommand("tfguilds").setExecutor(new TFGuildsCommand());
getCommand("guild").setExecutor(new GuildCommand());
getCommand("guildchatspy").setExecutor(new GuildChatSpyCommand());
}
@Override
public void onDisable()
{
plugin = null;
config.save();
GLog.info("Disabled " + this.getDescription().getFullName());
this.plugin = null;
}
private void loadCommands()
public Config getConfig()
{
this.getCommand("guild").setExecutor(new GuildCommand());
this.getCommand("guildchat").setExecutor(new GuildChatCommand());
this.getCommand("tfguilds").setExecutor(new TFGuildsCommand());
this.getCommand("guildchatspy").setExecutor(new GuildChatSpyCommand());
return config;
}
private void loadListeners()
public SQLDatabase getSQL()
{
PluginManager manager = this.getServer().getPluginManager();
manager.registerEvents(new ChatListener(), this);
manager.registerEvents(new JoinListener(), this);
return sqlDatabase;
}
public TFMBridge getTfmBridge()
{
return tfmBridge;
}
public SubCommand getSubCommand(String name)
{
return subCommands.get(name);
}
public List<String> getSubCommands()
{
List<String> commands = new ArrayList<>(subCommands.keySet());
Collections.sort(commands);
return commands;
}
private void loadSubCommands()
{
subCommands.put("create", new CreateSubCommand());
subCommands.put("info", new InfoSubCommand());
subCommands.put("disband", new DisbandSubCommand());
subCommands.put("invite", new InviteSubCommand());
subCommands.put("join", new JoinSubCommand());
subCommands.put("leave", new LeaveSubCommand());
subCommands.put("warps", new WarpsSubCommand());
subCommands.put("setwarp", new SetWarpSubCommand());
subCommands.put("addmod", new AddModSubCommand());
subCommands.put("removemod", new RemoveModSubCommand());
subCommands.put("createrank", new CreateRankSubCommand());
subCommands.put("deleterank", new DeleteRankSubCommand());
subCommands.put("warp", new WarpSubCommand());
subCommands.put("setrank", new SetRankSubCommand());
subCommands.put("deletewarp", new DeleteWarpSubCommand());
subCommands.put("kick", new KickSubCommand());
subCommands.put("setowner", new SetOwnerSubCommand());
subCommands.put("setstate", new SetStateSubCommand());
subCommands.put("setdefaultrank", new SetDefaultRankSubCommand());
subCommands.put("home", new HomeSubCommand());
subCommands.put("tp", new TpSubCommand());
subCommands.put("roster", new RosterSubCommand());
subCommands.put("toggletag", new ToggleTagSubCommand());
subCommands.put("chat", new ChatSubCommand());
subCommands.put("motd", new MotdSubCommand());
subCommands.put("toggletags", new ToggleTagsSubCommand());
subCommands.put("tag", new TagSubCommand());
subCommands.put("list", new ListSubCommand());
subCommands.put("help", new HelpSubCommand());
}
}

View file

@ -0,0 +1,64 @@
package me.totalfreedom.tfguilds;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class TFMBridge
{
private final TFGuilds plugin = TFGuilds.getPlugin();
private TotalFreedomMod tfm = null;
public TotalFreedomMod getTfm()
{
if (tfm == null)
{
try
{
final Plugin tfmPlugin = plugin.getServer().getPluginManager().getPlugin("TotalFreedomMod");
if (tfmPlugin != null && tfmPlugin.isEnabled() && tfmPlugin instanceof TotalFreedomMod)
{
tfm = (TotalFreedomMod)tfmPlugin;
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
return tfm;
}
public boolean isAdmin(Player player)
{
if (getTfm() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return player.isOp();
}
return getTfm().al.isAdmin(player);
}
public boolean isAdmin(CommandSender sender)
{
if (getTfm() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return sender.isOp();
}
return getTfm().al.isAdmin(sender);
}
public boolean isVanished(Player player)
{
if (getTfm() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
return false;
}
return getTfm().al.isVanished(player.getName());
}
}

View file

@ -1,72 +0,0 @@
package me.totalfreedom.tfguilds.bridge;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class TFMBridge
{
private final TFGuilds plugin;
private TotalFreedomMod tfmPlugin;
public TFMBridge()
{
this.plugin = TFGuilds.getPlugin();
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)
{
if (getTFM() == null)
{
GLog.warn("TFM not detected on the server. Checking if player is OP...");
return player.isOp();
}
return getTFM().al.isAdmin(player);
}
public boolean isAdmin(CommandSender sender)
{
if (getTFM() == null)
{
GLog.warn("TFM not detected on the server. Checking if sender is OP...");
return sender.isOp();
}
return getTFM().al.isAdmin(sender);
}
public boolean isVanished(Player player)
{
if (getTFM() == null)
{
GLog.warn("TFM not detected on the server.");
return false;
}
return getTFM().al.isVanished(player.getName());
}
}

View file

@ -0,0 +1,70 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class AddModSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length != 2)
{
sender.sendMessage(USAGE + "/g addmod <player>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "You must be the guild owner to add moderators!");
return;
}
if (playerSender.equals(player))
{
sender.sendMessage(PREFIX + "You are the owner of your guild, you are already a moderator.");
return;
}
if (!guild.isMember(player))
{
sender.sendMessage(PLAYER_NOT_IN_GUILD);
return;
}
if (guild.isModerator(player))
{
sender.sendMessage(PREFIX + "That player is already a moderator!");
return;
}
guild.addModerator(player);
sender.sendMessage(PREFIX + "Successfully added " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as a moderator.");
player.sendMessage(PREFIX + "You are now a guild moderator for your guild!");
}
}

View file

@ -1,123 +0,0 @@
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 == 1 || args.length > 3)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g addmod <guild <player> | player>"));
return true;
}
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.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
if (guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "No need to make the owner a moderator!");
return true;
}
if (guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for this guild!");
return true;
}
guild.addModerator(player.getUniqueId());
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(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
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.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "No need to make yourself a moderator!");
return true;
}
if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
if (guild.hasModerator(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for your guild!");
return true;
}
guild.addModerator(n.getUniqueId());
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.CommandSender;
import org.bukkit.entity.Player;
public class ChatSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (args.length >= 2)
{
String message = StringUtils.join(args, " ", 1, args.length);
guild.chat(playerSender, message);
return;
}
if (GUILD_CHAT.contains(playerSender))
{
GUILD_CHAT.remove(playerSender);
sender.sendMessage(PREFIX + "Guild chat " + ChatColor.GOLD + "disabled");
return;
}
GUILD_CHAT.add(playerSender);
sender.sendMessage(PREFIX + "Guild chat " + ChatColor.GOLD + "enabled");
}
}

View file

@ -1,50 +0,0 @@
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(NG);
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

@ -0,0 +1,70 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class CreateRankSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + " /g createrank <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "Only the guild owner can create ranks for the guild!");
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (!StringUtils.isAlphanumericSpace(name) || name.isBlank())
{
sender.sendMessage(PREFIX + "The rank name must be alphanumeric!");
return;
}
if (name.length() > 15)
{
sender.sendMessage(PREFIX + "The rank name cannot go over 15 characters limit.");
return;
}
if (GUtil.containsBlacklistedWord(name))
{
sender.sendMessage(PREFIX + "The guild name contains a blacklisted word.");
return;
}
if (guild.hasRank(name))
{
sender.sendMessage(PREFIX + "That rank already exists!");
return;
}
guild.createRank(name);
sender.sendMessage(PREFIX + "Successfully created a new rank " + ChatColor.GOLD + name);
}
}

View file

@ -1,87 +0,0 @@
package me.totalfreedom.tfguilds.command;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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 CreateRankSubcommand 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)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g createrank <name>"));
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't create ranks for your guild!");
return true;
}
String rank = StringUtils.join(args, " ", 1, args.length);
for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
{
if (rank.equalsIgnoreCase(blacklisted))
{
if (!plugin.bridge.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
}
Pattern pattern = Pattern.compile("^[A-Za-z0-9? ,_-]+$");
Matcher matcher = pattern.matcher(rank);
if (!matcher.matches())
{
sender.sendMessage(ChatColor.RED + "Guild rank names must be alphanumeric.");
return true;
}
if (rank.length() > 15)
{
sender.sendMessage(ChatColor.RED + "Guild rank names may not be over 15 characters.");
return true;
}
if (guild.hasRank(rank))
{
sender.sendMessage(ChatColor.RED + "A rank of that name already exists in the guild!");
return true;
}
guild.addRank(rank);
sender.sendMessage(tl(PREFIX + "Created a new rank named %s%" + rank + "%p% for your guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,65 @@
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.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CreateSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g create <name>");
return;
}
if (Guild.isAlreadyMember(playerSender))
{
sender.sendMessage(IN_GUILD);
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (!StringUtils.isAlphanumericSpace(name) || name.isBlank())
{
sender.sendMessage(PREFIX + "The guild name must be alphanumeric.");
return;
}
if (name.length() > 30)
{
sender.sendMessage(PREFIX + "The guild name cannot go over 30 characters limit.");
return;
}
if (Guild.hasGuild(name))
{
sender.sendMessage(PREFIX + "The guild name is already taken.");
return;
}
if (GUtil.containsBlacklistedWord(name))
{
sender.sendMessage(PREFIX + "The guild name contains a blacklisted word.");
return;
}
Guild.create(playerSender, name);
sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + name + ChatColor.GRAY + " has been created.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has created a guild " + ChatColor.GOLD + name);
}
}

View file

@ -1,81 +0,0 @@
package me.totalfreedom.tfguilds.command;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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;
}
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g create <name>"));
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;
}
Pattern pattern = Pattern.compile("^[A-Za-z0-9? ,_-]+$");
Matcher matcher = pattern.matcher(name);
if (!matcher.matches())
{
sender.sendMessage(ChatColor.RED + "Guild names must be alphanumeric.");
return true;
}
if (name.length() > 30)
{
sender.sendMessage(ChatColor.RED + "Your guild name may not be over 30 characters.");
return true;
}
if (Guild.guildExists(identifier))
{
sender.sendMessage(ChatColor.RED + "A guild with a name similar to yours already exists!");
return true;
}
for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
{
if (name.equalsIgnoreCase(blacklisted))
{
if (!plugin.bridge.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
}
Guild.createGuild(identifier, name, player);
sender.sendMessage(tl(PREFIX + "Created a guild named \"" + GUtil.colorize(name) + "%p%\"!"));
broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has created guild %p%&l" + name)));
return true;
}
}

View file

@ -0,0 +1,51 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class DeleteRankSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g deleterank <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(PREFIX + "You are not in a guild!");
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "Only the guild owner can delete ranks for the guild!");
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (!guild.hasRank(name))
{
sender.sendMessage(PREFIX + "That rank does not exist!");
return;
}
guild.deleteRank(name);
sender.sendMessage(PREFIX + "Successfully deleted a rank " + ChatColor.GOLD + name);
}
}

View file

@ -1,63 +0,0 @@
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 DeleteRankSubcommand 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)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g deleterank <rank>"));
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't delete ranks from your guild!");
return true;
}
String rank = StringUtils.join(args, " ", 1, args.length);
if (!guild.hasRank(rank))
{
sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
return true;
}
guild.removeRank(rank);
if (guild.hasDefaultRank() && rank.equals(guild.getDefaultRank()))
{
guild.setDefaultRank(null);
guild.save();
}
sender.sendMessage(tl(PREFIX + "Deleted the rank named %s%" + rank + "%p% in your guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,51 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class DeleteWarpSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g deletewarp <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "You must be a guild moderator or owner to create a warp for the guild.");
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (!guild.hasWarp(name))
{
sender.sendMessage(PREFIX + "That warp does not exist.");
return;
}
guild.removeWarp(name);
sender.sendMessage(PREFIX + "Successfully removed a warp " + ChatColor.GOLD + name);
}
}

View file

@ -1,57 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildWarp;
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 DeleteWarpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g deletewarp <name>"));
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(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
return true;
}
String warpName = StringUtils.join(args, " ", 1, args.length);
if (!guild.warpExists(warpName))
{
sender.sendMessage(ChatColor.RED + "Warp not found.");
return true;
}
GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
plugin.warpData.delete(warp);
sender.sendMessage(tl(PREFIX + "Deleted guild warp \"" + warpName + "\"."));
return true;
}
}

View file

@ -0,0 +1,60 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class DisbandSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length >= 2)
{
if (!tfmBridge.isAdmin(sender))
{
sender.sendMessage(PREFIX + "You do not have permission.");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
return;
}
guild.disband();
sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName());
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "You are not the guild owner!");
return;
}
sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName());
guild.disband();
}
}

View file

@ -1,77 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GLog;
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 DisbandSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length > 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g disband [name]"));
return true;
}
if (args.length == 2)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
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;
}
String n = guild.getName();
GLog.info("Removing guild data for " + n);
guild.disband();
GLog.info(sender.getName() + " deleted guild " + guild.getName());
sender.sendMessage(tl(PREFIX + "Disbanded \"" + GUtil.colorize(n) + "%p%\"."));
broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has disbanded guild %p%&l" + guild.getName())));
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player)sender;
if (!Guild.isInGuild(player))
{
sender.sendMessage(NG);
return true;
}
Guild guild = Guild.getGuild(player);
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You are not the owner of this guild!");
return true;
}
GLog.info("Removing guild data for " + guild.getName());
guild.disband();
GLog.info(player.getName() + " deleted guild " + guild.getName());
sender.sendMessage(tl(PREFIX + "You have disbanded your guild!"));
broadcast(GUtil.colorize(tl("%p%&l" + guild.getName() + "%p% has been disbanded")));
return true;
}
}

View file

@ -1,50 +0,0 @@
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 GuildChatCommand 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(NG);
return true;
}
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

@ -1,39 +1,40 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
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 GuildChatSpyCommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (sender instanceof ConsoleCommandSender)
if (!(sender instanceof Player))
{
sender.sendMessage(NO_PERMS);
sender.sendMessage(PREFIX + "Console can already view guild chat.");
return true;
}
if (!plugin.bridge.isAdmin(sender))
if (!tfmBridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
sender.sendMessage(PREFIX + "You do not have the permission.");
return true;
}
Player player = (Player)sender;
if (CHAT_SPY.contains(player))
if (GUILD_CHAT_SPY.contains(player))
{
CHAT_SPY.remove(player);
sender.sendMessage(tl(PREFIX + "%p%Global guild chat spy disabled."));
GUILD_CHAT_SPY.remove(player);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled " + ChatColor.GRAY + "guild chat spy.");
return true;
}
CHAT_SPY.add(player);
sender.sendMessage(tl(PREFIX + "%p%Global guild chat spy enabled."));
GUILD_CHAT_SPY.add(player);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled " + ChatColor.GRAY + "guild chat spy.");
return true;
}
}

View file

@ -1,11 +1,10 @@
package me.totalfreedom.tfguilds.command;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -14,209 +13,36 @@ import org.bukkit.entity.Player;
public class GuildCommand extends Common implements CommandExecutor, TabCompleter
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
Player playerSender = null;
if (sender instanceof Player)
{
playerSender = (Player)sender;
}
if (args.length >= 1)
{
switch (args[0].toLowerCase())
String name = args[0].toLowerCase();
SubCommand command = TFGuilds.getPlugin().getSubCommand(name);
if (command != null)
{
// Please keep the commands here & in HelpSubcommand.java in alphabetical order
case "addmod":
return new AddModSubcommand().onCommand(sender, command, label, args);
case "chat":
return new ChatSubcommand().onCommand(sender, command, label, args);
case "createrank":
return new CreateRankSubcommand().onCommand(sender, command, label, args);
case "create":
return new CreateSubcommand().onCommand(sender, command, label, args);
case "deleterank":
return new DeleteRankSubcommand().onCommand(sender, command, label, args);
case "deletewarp":
return new DeleteWarpSubcommand().onCommand(sender, command, label, args);
case "disband":
return new DisbandSubcommand().onCommand(sender, command, label, args);
case "help":
return new HelpSubcommand().onCommand(sender, command, label, args);
case "home":
return new HomeSubcommand().onCommand(sender, command, label, args);
case "info":
return new InfoSubcommand().onCommand(sender, command, label, args);
case "invite":
return new InviteSubcommand().onCommand(sender, command, label, args);
case "join":
return new JoinSubcommand().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 "list":
return new ListSubcommand().onCommand(sender, command, label, args);
case "motd":
return new MOTDSubcommand().onCommand(sender, command, label, args);
case "removemod":
return new RemoveModSubcommand().onCommand(sender, command, label, args);
case "rename":
return new RenameSubcommand().onCommand(sender, command, label, args);
case "roster":
return new RosterSubcommand().onCommand(sender, command, label, args);
case "setdefaultrank":
return new SetDefaultRankSubcommand().onCommand(sender, command, label, args);
case "setmember":
return new SetMemberSubcommand().onCommand(sender, command, label, args);
case "setowner":
return new SetOwnerSubcommand().onCommand(sender, command, label, args);
case "setrank":
return new SetRankSubcommand().onCommand(sender, command, label, args);
case "setstate":
return new SetStateSubcommand().onCommand(sender, command, label, args);
case "setwarp":
return new SetWarpSubcommand().onCommand(sender, command, label, args);
case "tag":
return new TagSubcommand().onCommand(sender, command, label, args);
case "toggletags":
return new ToggleTagsSubcommand().onCommand(sender, command, label, args);
case "toggletag":
return new ToggleTagSubcommand().onCommand(sender, command, label, args);
case "tp":
return new TPSubcommand().onCommand(sender, command, label, args);
case "warps":
return new WarpsSubcommand().onCommand(sender, command, label, args);
case "warp":
return new WarpSubcommand().onCommand(sender, command, label, args);
command.execute(sender, playerSender, args);
}
else
{
sender.sendMessage(PREFIX + "Unknown subcommand, do " + ChatColor.GOLD + "/g help" + ChatColor.GRAY + " for help.");
}
sender.sendMessage(tl(PREFIX + "Unknown command - Run /g help if you need help"));
return true;
}
return new HelpSubcommand().onCommand(sender, command, label, args);
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args)
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
{
if (args.length == 1)
{
return Arrays.asList("addmod", "chat", "createrank", "create",
"deleterank", "deletewarp", "disband", "help", "home", "info", "invite",
"join", "kick", "leave", "list", "motd", "removemod", "rename",
"roster", "setdefaultrank", "setmember", "setowner", "setrank", "setstate",
"setwarp", "tag", "toggletags", "toggletag", "tp", "warps", "warp");
}
else if (args.length == 2)
{
switch (args[0])
{
case "home":
{
return Arrays.asList("set");
}
case "info":
case "join":
case "roster":
case "setmember":
{
return Guild.getGuildList();
}
case "toggletag":
{
if (!plugin.bridge.isAdmin(sender))
{
return Collections.emptyList();
}
return GUtil.getPlayerList();
}
case "motd":
case "tag":
{
return Arrays.asList("set", "clear");
}
case "setstate":
{
return Arrays.asList("OPEN", "INVITE", "CLOSED");
}
case "invite":
{
return GUtil.getPlayerList();
}
case "deleterank":
case "setdefaultrank":
{
if (sender instanceof Player)
{
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild.getOwner().equals(player.getUniqueId()))
{
return guild.getRankNames();
}
}
}
case "tp":
{
if (sender instanceof Player)
{
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
return guild.getOnlyMembers();
}
}
case "disband":
{
if (!plugin.bridge.isAdmin(sender))
{
return Collections.emptyList();
}
return Guild.getGuildList();
}
case "kick":
{
if (sender instanceof Player)
{
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild.hasModerator(player.getUniqueId()))
{
return guild.getOnlyMembers();
}
}
}
case "removemod":
case "addmod":
case "setowner":
{
if (sender instanceof Player)
{
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild.getOwner().equals(player.getUniqueId()))
{
return guild.getOnlyMembers();
}
}
}
case "deletewarp":
case "warp":
{
if (sender instanceof Player)
{
return Guild.getGuildWarps();
}
}
}
}
return Collections.emptyList();
}
}

View file

@ -0,0 +1,22 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HelpSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
sender.sendMessage(PREFIX + "Command List");
for (String command : TFGuilds.getPlugin().getSubCommands())
{
sender.sendMessage(ChatColor.GRAY + " - " + ChatColor.GOLD + command);
}
}
}

View file

@ -1,48 +0,0 @@
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)
{
// Please keep the commands here & in GuildCommand.java in alphabetical order
sender.sendMessage(tl("%s%[%p%TFGuilds%s%] %p%Command List"));
sender.sendMessage(tl("%s% - %p%addmod <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%chat [message]"));
sender.sendMessage(tl("%s% - %p%createrank <name>"));
sender.sendMessage(tl("%s% - %p%create <name>"));
sender.sendMessage(tl("%s% - %p%deleterank <rank>"));
sender.sendMessage(tl("%s% - %p%deletewarp <warp>"));
sender.sendMessage(tl("%s% - %p%disband [name]"));
sender.sendMessage(tl("%s% - %p%help"));
sender.sendMessage(tl("%s% - %p%home [set]"));
sender.sendMessage(tl("%s% - %p%info [guild | player]"));
sender.sendMessage(tl("%s% - %p%invite <player>"));
sender.sendMessage(tl("%s% - %p%join <guild>"));
sender.sendMessage(tl("%s% - %p%kick <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%leave"));
sender.sendMessage(tl("%s% - %p%list [page]"));
sender.sendMessage(tl("%s% - %p%motd <set <motd> | clear>"));
sender.sendMessage(tl("%s% - %p%removemod <guild <name> | name>"));
sender.sendMessage(tl("%s% - %p%rename <name>"));
sender.sendMessage(tl("%s% - %p%roster [guild | player]"));
sender.sendMessage(tl("%s% - %p%setdefaultrank <rank | none>"));
sender.sendMessage(tl("%s% - %p%setmember <guild> <player>"));
sender.sendMessage(tl("%s% - %p%setowner <guild <player> | player>"));
sender.sendMessage(tl("%s% - %p%setrank <player> <rank | none>"));
sender.sendMessage(tl("%s% - %p%setstate <open | invite | closed>"));
sender.sendMessage(tl("%s% - %p%setwarp <name>"));
sender.sendMessage(tl("%s% - %p%tag <set <tag> | clear [guild]>>"));
sender.sendMessage(tl("%s% - %p%toggletags"));
sender.sendMessage(tl("%s% - %p%toggletag [player]"));
sender.sendMessage(tl("%s% - %p%tp <player>"));
sender.sendMessage(tl("%s% - %p%warps"));
sender.sendMessage(tl("%s% - %p%warp <name>"));
return true;
}
}

View file

@ -0,0 +1,56 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class HomeSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length > 2)
{
sender.sendMessage(USAGE + "/g home [set]");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (args.length == 2)
{
if (args[1].equalsIgnoreCase("set"))
{
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "Only guild moderators can set guild's home location");
return;
}
guild.setHome(playerSender.getLocation());
sender.sendMessage(PREFIX + "Successfully set guild's home to your location");
}
else
{
sender.sendMessage(USAGE + "/g home [set]");
}
return;
}
playerSender.teleport(guild.getHome());
sender.sendMessage(PREFIX + "Teleported to your guild's home!");
}
}

View file

@ -1,65 +0,0 @@
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 HomeSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length > 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g home [set]"));
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(NG);
return true;
}
if (args.length == 2)
{
if (args[1].equalsIgnoreCase("set"))
{
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's home!");
return true;
}
guild.setHome(player.getLocation());
guild.save();
sender.sendMessage(tl(PREFIX + "Set your current location as the new home of your guild%p%."));
return true;
}
return false;
}
if (!guild.hasHome())
{
sender.sendMessage(ChatColor.RED + "Your guild doesn't have a home!");
return true;
}
player.teleport(guild.getHome());
sender.sendMessage(tl("%p%Teleported you to your guild's home!"));
return true;
}
}

View file

@ -0,0 +1,55 @@
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.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class InfoSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length >= 2)
{
Player player = Bukkit.getPlayer(args[1]);
if (player != null && !tfmBridge.isVanished(player))
{
Guild guild = Guild.getGuild(player);
if (guild != null)
{
sender.sendMessage(guild.toString());
return;
}
}
Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
return;
}
sender.sendMessage(guild.toString());
return;
}
if (!(sender instanceof Player))
{
sender.sendMessage(USAGE + "/g info <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
sender.sendMessage(guild.toString());
}
}

View file

@ -1,60 +0,0 @@
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.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 InfoSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length >= 2)
{
Player player = Bukkit.getPlayer(args[1]);
if (player != null)
{
Guild guild = Guild.getGuild(player);
if (guild != null)
{
sender.sendMessage(guild.getInformation());
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;
}
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(NG);
return true;
}
sender.sendMessage(guild.getInformation());
return true;
}
}

View file

@ -0,0 +1,98 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class InviteSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length != 2)
{
sender.sendMessage(USAGE + "/g invite <player>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (guild.getState() == Guild.State.CLOSED)
{
sender.sendMessage(PREFIX + "The guild is closed.");
return;
}
if (guild.getState() == Guild.State.OPEN)
{
sender.sendMessage(PREFIX + "The guild is open to public, tell your friends to join by " + ChatColor.GOLD + "/g join " + guild.getName());
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (player.equals(playerSender))
{
sender.sendMessage(PREFIX + "You cannot invite yourself.");
return;
}
if (Guild.getGuild(player) != null)
{
sender.sendMessage(PREFIX + "That player is already in a guild.");
return;
}
if (guild.isInvited(player))
{
sender.sendMessage(PREFIX + "That player is already been invited.");
return;
}
guild.invite(player);
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has sent you an invite to join " + ChatColor.GOLD + guild.getName());
player.sendMessage("Do " + ChatColor.GOLD + "/g join " + guild.getName() + ChatColor.GRAY + " to join!");
player.sendMessage(PREFIX + "The invite will expire in 90 seconds.");
sender.sendMessage(PREFIX + "The invite has been sent to " + ChatColor.GOLD + player.getName());
new BukkitRunnable()
{
@Override
public void run()
{
if (!guild.isInvited(player))
{
return;
}
guild.removeInvite(player);
if (player.isOnline())
{
player.sendMessage(PREFIX + "The invite to " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has expired!");
sender.sendMessage(PREFIX + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " has not accepted your invite.");
}
}
}.runTaskLater(TFGuilds.getPlugin(), 20 * 90);
}
}

View file

@ -1,92 +0,0 @@
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)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g invite <player>"));
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
Player invitee = Bukkit.getPlayer(args[1]);
if (invitee == null || plugin.bridge.isVanished(invitee))
{
sender.sendMessage(PNF);
return true;
}
if (Guild.getGuild(invitee) != null)
{
sender.sendMessage(ChatColor.RED + "This player is already in another guild!");
return true;
}
if (guild == null)
{
sender.sendMessage(NG);
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 + "It has been 90 seconds and " + invitee.getName() + " did not accept your invitation.");
}
}.runTaskLater(plugin, 20 * 90);
return true;
}
}

View file

@ -0,0 +1,60 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class JoinSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g join <name>");
return;
}
if (Guild.getGuild(playerSender) != null)
{
sender.sendMessage(IN_GUILD);
return;
}
Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
return;
}
if (guild.getState() == Guild.State.CLOSED)
{
sender.sendMessage(PREFIX + "That guild is currently closed.");
return;
}
if (guild.getState() == Guild.State.INVITE_ONLY)
{
if (guild.isInvited(playerSender))
{
sender.sendMessage(PREFIX + "You must be invited to join the guild.");
return;
}
guild.removeInvite(playerSender);
}
guild.addMember(playerSender);
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has joined the guild.");
}
}

View file

@ -1,67 +0,0 @@
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)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g join <guild>"));
return true;
}
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.getUniqueId());
guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,70 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class KickSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g kick <player>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "Only the guild owner and moderators can kick members.");
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (playerSender.equals(player))
{
sender.sendMessage(PREFIX + "You cannot kick yourself.");
return;
}
if (guild.getOwner().equals(player.getUniqueId()) || guild.isModerator(player) && !guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "You may not kick the guild owner or moderators from your guild.");
return;
}
if (!guild.isMember(player))
{
sender.sendMessage(PLAYER_NOT_IN_GUILD);
return;
}
guild.removeMember(player);
sender.sendMessage(PREFIX + "Successfully kicked " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " from your guild.");
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has kicked you from " + ChatColor.GOLD + guild.getName());
}
}

View file

@ -1,113 +0,0 @@
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)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g kick <guild <player> | player>"));
return true;
}
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.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
if (guild.getOwner().equals(player.getUniqueId()) || guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
return true;
}
guild.removeMember(player.getUniqueId());
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(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
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.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
if (guild.getOwner().equals(n.getUniqueId()) || guild.hasModerator(n.getUniqueId()) && !guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
return true;
}
guild.removeMember(n.getUniqueId());
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

@ -0,0 +1,38 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class LeaveSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "You may not leave your guild as the owner, please disband the guild instead.");
return;
}
guild.removeMember(playerSender);
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has left the guild.");
sender.sendMessage(PREFIX + "You have left the guild.");
}
}

View file

@ -1,50 +0,0 @@
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 (args.length > 1)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g leave"));
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(NG);
return true;
}
if (guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You cannot leave as you are the owner!");
return true;
}
guild.removeModerator(player.getUniqueId());
guild.removeMember(player.getUniqueId());
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,60 @@
package me.totalfreedom.tfguilds.command;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.PaginationList;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ListSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (args.length > 2)
{
sender.sendMessage(USAGE + "/g list [page]");
return;
}
List<String> guilds = Guild.getGuildNames();
if (guilds.isEmpty())
{
sender.sendMessage(PREFIX + "There are no guilds.");
return;
}
PaginationList<String> pagination = new PaginationList<>(10);
pagination.addAll(guilds);
int index = 1;
if (args.length == 2)
{
try
{
index = Integer.parseInt(args[1]);
}
catch (NumberFormatException ex)
{
sender.sendMessage(PREFIX + ChatColor.GOLD + args[1] + ChatColor.GRAY + " is not a valid number.");
return;
}
}
if (index < 1 || index > pagination.getPageCount())
{
sender.sendMessage(PREFIX + "Please pick a number between 1 and " + pagination.getPageCount());
return;
}
List<String> page = pagination.getPage(index);
sender.sendMessage(PREFIX + "Guild list (" + ChatColor.GOLD + index + "/" + pagination.getPageCount() + ChatColor.GRAY + ")");
for (String guild : page)
{
sender.sendMessage(ChatColor.GRAY + " - " + ChatColor.GOLD + guild);
}
}
}

View file

@ -1,65 +0,0 @@
package me.totalfreedom.tfguilds.command;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.PaginationList;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class ListSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length > 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g list [page]"));
return true;
}
List<String> guilds = Guild.getGuildList();
PaginationList<String> paged = new PaginationList<>(10);
if (guilds.isEmpty())
{
sender.sendMessage(ChatColor.RED + "Nobody has made a guild yet.");
return true;
}
paged.addAll(guilds);
int pageIndex = 1;
if (args.length >= 2)
{
try
{
pageIndex = Integer.parseInt(args[1]);
}
catch (NumberFormatException e)
{
sender.sendMessage(ChatColor.RED + "Invalid number.");
}
}
if (pageIndex < 1 || pageIndex > paged.getPageCount())
{
sender.sendMessage(ChatColor.RED + "Not a valid page number.");
return true;
}
paged.getPage(pageIndex);
List<String> page = paged.getPage(pageIndex);
sender.sendMessage(tl(PREFIX + "%s%Guild list (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
for (String guild : page)
{
sender.sendMessage(tl("%s%- %p%" + guild));
}
return true;
}
}

View file

@ -1,68 +0,0 @@
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 MOTDSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 1)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g motd <set <motd> | clear>"));
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(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's MOTD!");
return true;
}
if (args.length >= 3)
{
if (args[1].equalsIgnoreCase("set"))
{
String motd = StringUtils.join(args, " ", 2, args.length);
guild.setMotd(motd);
guild.save();
sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(motd) + "%p% as the new MOTD of your guild%p%."));
return true;
}
return false;
}
if (!args[1].equalsIgnoreCase("clear"))
{
return false;
}
guild.setMotd(null);
guild.save();
sender.sendMessage(tl(PREFIX + "Cleared your guild's MOTD."));
return true;
}
}

View file

@ -0,0 +1,66 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class MotdSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length == 1)
{
sender.sendMessage(USAGE + "/g motd <set <message> | clear>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "Only guild moderators can modify the guild's MOTD");
return;
}
if (args.length >= 3)
{
if (args[1].equalsIgnoreCase("set"))
{
String message = StringUtils.join(args, " ", 2, args.length);
guild.setMotd(message);
sender.sendMessage(PREFIX + "Set the guild's MOTD to " + ChatColor.GOLD + GUtil.colorize(message));
}
else
{
sender.sendMessage(USAGE + "/g motd <set <message> | clear>");
}
return;
}
if (!args[1].equalsIgnoreCase("clear"))
{
sender.sendMessage(USAGE + "/g motd <set <message> | clear>");
return;
}
guild.setMotd(null);
sender.sendMessage(PREFIX + "Successfully cleared the guild's MOTD");
}
}

View file

@ -0,0 +1,70 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class RemoveModSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length != 2)
{
sender.sendMessage(USAGE + "/g removemod <player>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "You must be the guild owner to remove moderators.");
return;
}
if (guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(PREFIX + "You are the owner of your guild, you cannot remove yourself.");
return;
}
if (!guild.isMember(player))
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(player))
{
sender.sendMessage(PREFIX + "That player is not a moderator.");
return;
}
guild.removeModerator(player);
sender.sendMessage(PREFIX + "Successfully removed " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as a moderator.");
player.sendMessage(PREFIX + "You are no longer a guild moderator for your guild.");
}
}

View file

@ -1,126 +0,0 @@
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 == 1 || args.length > 3)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g removemod <guild <name> | name>>"));
return true;
}
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 (sender instanceof Player)
{
if (guild.getModerators().contains(((Player)sender).getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
return true;
}
}
if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is not a moderator for this guild!");
return true;
}
guild.removeModerator(player.getUniqueId());
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(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
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 (n == player)
{
sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
return true;
}
if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
if (!guild.hasModerator(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is not a moderator for your guild!");
return true;
}
guild.removeModerator(n.getUniqueId());
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

@ -1,88 +0,0 @@
package me.totalfreedom.tfguilds.command;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
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 RenameSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g rename <name>"));
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
String newName = StringUtils.join(args, " ", 1, args.length);
String identifier = GUtil.flatten(newName);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change the name of your guild!");
return true;
}
Pattern pattern = Pattern.compile("^[A-Za-z0-9? ,_-]+$");
Matcher matcher = pattern.matcher(newName);
if (!matcher.matches())
{
sender.sendMessage(ChatColor.RED + "Guild names must be alphanumeric.");
return true;
}
if (identifier.length() > 30)
{
sender.sendMessage(ChatColor.RED + "Your new guild name may not be over 30 characters.");
return true;
}
if (Guild.guildExists(identifier))
{
sender.sendMessage(ChatColor.RED + "A guild with a name similar to yours already exists!");
return true;
}
for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
{
if (args[0].equalsIgnoreCase(blacklisted))
{
if (!plugin.bridge.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
}
guild.rename(newName);
sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(newName) + "%p% as the new name of your guild%p%."));
guild.broadcast(tl("%p%Your guild has been renamed to " + GUtil.colorize(newName) + "%p%."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,59 @@
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.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class RosterSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
Guild guild;
if (args.length >= 2)
{
Player player = Bukkit.getPlayer(args[1]);
if (player != null && !tfmBridge.isVanished(player))
{
guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(PLAYER_NOT_IN_GUILD);
return;
}
sender.sendMessage(guild.getRoster());
return;
}
guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
return;
}
sender.sendMessage(guild.getRoster());
return;
}
if (!(sender instanceof Player))
{
sender.sendMessage(USAGE + "/g roster <name>");
return;
}
guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
sender.sendMessage(guild.getRoster());
}
}

View file

@ -1,60 +0,0 @@
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.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 RosterSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length >= 2)
{
Player player = Bukkit.getPlayer(args[1]);
if (player != null)
{
Guild guild = Guild.getGuild(player);
if (guild != null)
{
sender.sendMessage(guild.getRoster());
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;
}
sender.sendMessage(guild.getRoster());
return true;
}
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild guild = Guild.getGuild((Player)sender);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
sender.sendMessage(guild.getRoster());
return true;
}
}

View file

@ -0,0 +1,71 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class SetDefaultRankSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g setdefaultrank <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "Only the guild owner can set default rank.");
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (name.equalsIgnoreCase("none"))
{
guild.setDefaultRank(null);
sender.sendMessage(PREFIX + "Removed default rank.");
return;
}
if (!StringUtils.isAlphanumericSpace(name) || name.isBlank())
{
sender.sendMessage(PREFIX + "The name must be alphanumeric.");
return;
}
if (name.length() > 15)
{
sender.sendMessage(PREFIX + "The rank name cannot go over 15 characters limit.");
return;
}
if (GUtil.containsBlacklistedWord(name))
{
sender.sendMessage(PREFIX + "The guild name contains a blacklisted word.");
return;
}
guild.setDefaultRank(name);
sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + name + ChatColor.GRAY + " as the default rank of your guild.");
}
}

View file

@ -1,64 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class SetDefaultRankSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (sender instanceof ConsoleCommandSender)
{
sender.sendMessage(NO_PERMS);
return true;
}
if (args.length == 0)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setdefaultrank <rank | none>"));
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You do not have permissions to manage ranks in your guild!");
return true;
}
String rank = StringUtils.join(args, " ", 1, args.length);
if (rank.equalsIgnoreCase("none"))
{
guild.setDefaultRank(null);
guild.save();
sender.sendMessage(tl(PREFIX + "Removed the default guild rank."));
return true;
}
if (!guild.hasRank(rank))
{
sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
return true;
}
guild.setDefaultRank(rank);
guild.save();
sender.sendMessage(tl(PREFIX + "Set %s%\"" + rank + "\"%p% as the default rank for your guild."));
return true;
}
}

View file

@ -1,54 +0,0 @@
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.entity.Player;
public class SetMemberSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 1 || args.length == 2 || args.length > 3)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setmember <guild> <player>"));
return true;
}
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.getGuild(player) != null)
{
sender.sendMessage(ChatColor.RED + "This player is already in another guild!");
return true;
}
guild.addMember(player.getUniqueId());
guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,65 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class SetOwnerSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g setowner <player>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "Only the guild owner can set the owner of the guild.");
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (playerSender.equals(player))
{
sender.sendMessage(PREFIX + "You are already the owner of the guild.");
return;
}
if (!guild.isMember(player))
{
sender.sendMessage(PREFIX + "That player is not in your guild.");
return;
}
guild.setOwner(player);
sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild.");
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild.");
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set you as the owner of " + ChatColor.GOLD + guild.getName());
}
}

View file

@ -1,113 +0,0 @@
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 == 1 || args.length > 3)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setowner <guild <player> | player>"));
return true;
}
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.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is already the owner of that guild!");
return true;
}
if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
guild.removeModerator(player.getUniqueId());
guild.setOwner(player.getUniqueId());
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(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
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 (n == player)
{
sender.sendMessage(ChatColor.RED + "You are already the owner of your guild.");
return true;
}
if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
guild.removeModerator(n.getUniqueId());
guild.setOwner(n.getUniqueId());
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,66 @@
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.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SetRankSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 3)
{
sender.sendMessage(USAGE + "/g setrank <player> <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "You must be a guild moderator to set player's rank for your guild.");
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (!guild.isMember(player))
{
sender.sendMessage(PLAYER_NOT_IN_GUILD);
return;
}
String name = StringUtils.join(args, " ", 2, args.length);
if (!guild.hasRank(name))
{
sender.sendMessage(PREFIX + "That rank does not exist.");
return;
}
guild.setPlayerRank(player, name);
sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + "'s guild rank to " + ChatColor.GOLD + name);
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set your guild rank to " + ChatColor.GOLD + name);
}
}

View file

@ -1,94 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank;
import org.apache.commons.lang.StringUtils;
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 SetRankSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length == 1)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setrank <player> <rank | none>"));
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(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change the ranks of your guild members!");
return true;
}
Player r = Bukkit.getPlayer(args[1]);
if (r == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.hasMember(r.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
String name = StringUtils.join(args, " ", 2, args.length).toLowerCase();
if (name.equals("none"))
{
for (GuildRank gr : guild.getRanks())
{
gr.getMembers().remove(r.getUniqueId());
gr.save();
}
sender.sendMessage(tl(PREFIX + "Removed the rank of %s%" + r.getName() + "%p% in your guild."));
r.sendMessage(tl("%p%Your rank in your guild has been removed."));
guild.save();
return true;
}
GuildRank rank = guild.getRank(name);
if (rank == null)
{
sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
return true;
}
for (GuildRank gr : guild.getRanks())
{
gr.getMembers().remove(r.getUniqueId());
gr.save();
}
rank.getMembers().add(r.getUniqueId());
rank.save();
sender.sendMessage(tl(PREFIX + "Set the rank of %s%" + r.getName() + "%p% in your guild to %s%" + rank.getName() + "%p%."));
r.sendMessage(tl("%p%Your rank in your guild has been set to %s%" + rank.getName() + "%p%."));
guild.save();
return true;
}
}

View file

@ -0,0 +1,53 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class SetStateSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length != 2)
{
sender.sendMessage(USAGE + "/g setstate <state>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "Only guild moderators can change the state.");
return;
}
Guild.State state = Guild.State.fromString(args[1]);
if (state == null)
{
sender.sendMessage(PREFIX + ChatColor.GOLD + args[1] + ChatColor.GRAY + " is not a valid state. Available options: "
+ ChatColor.GOLD + StringUtils.join(Guild.State.values(), ", "));
return;
}
guild.setState(state);
sender.sendMessage(PREFIX + "Successfully set the guild state to " + ChatColor.GOLD + state.name());
guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set the guild state to " + ChatColor.GOLD + state.name());
}
}

View file

@ -1,87 +0,0 @@
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 == 1)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setstate <open | invite | closed>"));
return true;
}
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(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
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,57 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class SetWarpSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g setwarp <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.isModerator(playerSender))
{
sender.sendMessage(PREFIX + "You must be a guild moderator or owner to create a warp for the guild.");
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (!StringUtils.isAlphanumericSpace(name))
{
sender.sendMessage(PREFIX + "The name must be alphanumeric.");
return;
}
if (guild.hasWarp(name))
{
sender.sendMessage(PREFIX + "A warp with that name already exist.");
return;
}
guild.addWarp(name, playerSender.getLocation());
sender.sendMessage(PREFIX + "A warp with the name " + ChatColor.GOLD + name + ChatColor.GRAY + " has been successfully created.");
}
}

View file

@ -1,55 +0,0 @@
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 SetWarpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g setwarp <name>"));
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(NG);
return true;
}
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
return true;
}
String warpName = StringUtils.join(args, " ", 1, args.length);
if (guild.warpExists(warpName))
{
sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
return true;
}
Guild.createWarp(guild.getIdentifier(), warpName, player);
sender.sendMessage(tl(PREFIX + "Successfully created new guild warp \"" + warpName + "\"."));
return true;
}
}

View file

@ -0,0 +1,10 @@
package me.totalfreedom.tfguilds.command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public interface SubCommand
{
void execute(CommandSender sender, Player playerSender, String[] args);
}

View file

@ -1,55 +1,50 @@
package me.totalfreedom.tfguilds.command;
import java.util.UUID;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.util.GLog;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class TFGuildsCommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (args.length > 1)
{
return false;
}
if (args.length == 1)
if (args.length == 1 && args[0].equalsIgnoreCase("reload"))
{
if (args[0].toLowerCase().equals("reload"))
if (!tfmBridge.isAdmin(sender))
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
try
{
plugin.config.load();
GLog.info("All configs reloaded successfully");
sender.sendMessage(tl(PREFIX + "All configuration files have been reloaded successfully."));
return true;
}
catch (Exception ex)
{
ex.printStackTrace();
}
sender.sendMessage(PREFIX + "You do not have the permission.");
return true;
}
try
{
TFGuilds.getPlugin().getConfig().load();
TFGuilds.getPlugin().getLogger().info("Successfully reload the configuration file.");
sender.sendMessage(PREFIX + "The configuration file have been reloaded successfully.");
return true;
}
catch (Exception ex)
{
ex.printStackTrace();
}
return true;
}
sender.sendMessage(tl("%p%TFGuilds %s%is a plugin which allows for players to make their own guilds, providing guild chat, guild teleportation, and more."));
sender.sendMessage(tl("%s%Version %p%v" + plugin.getDescription().getVersion()));
OfflinePlayer sp = Bukkit.getOfflinePlayer(UUID.fromString("d018f2b8-ce60-4672-a45f-e580e0331299"));
OfflinePlayer su = Bukkit.getOfflinePlayer(UUID.fromString("53b1512e-3481-4702-9f4f-63cb9c8be6a1"));
sender.sendMessage(tl("%s%Developed by %p%" + sp.getName() + " & " + su.getName()));
sender.sendMessage(tl("%s%https://github.com/AtlasMediaGroup/TFGuilds"));
sender.sendMessage(ChatColor.AQUA + "TFGuilds " + ChatColor.GRAY + "is a plugin which allows players to create their own guilds, provide guild chat, guild teleportation and many more.");
sender.sendMessage(ChatColor.GRAY + "Version " + ChatColor.GOLD + TFGuilds.getPlugin().getDescription().getVersion());
sender.sendMessage(ChatColor.GRAY + "Originally created by " + ChatColor.GOLD + "speednt " + ChatColor.GRAY + "and " + ChatColor.GOLD + "supernt");
sender.sendMessage(ChatColor.GRAY + "Developed by " + ChatColor.GOLD + "NotInSync");
sender.sendMessage(ChatColor.GRAY + "Source code " + ChatColor.GOLD + "https://github.com/AtlasMediaGroup/TFGuilds");
return true;
}
}

View file

@ -1,56 +0,0 @@
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)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g tp <player>"));
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
Player to = Bukkit.getPlayer(args[1]);
if (to == null)
{
sender.sendMessage(PNF);
return true;
}
if (!guild.getMembers().contains(to.getUniqueId()))
{
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,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.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TagSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g tag <set <tag> | clear [guild]>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (!guild.getOwner().equals(playerSender.getUniqueId()))
{
sender.sendMessage(PREFIX + "Only the guild owner can edit the guild's tag.");
return;
}
if (args.length >= 3)
{
if (args[1].equalsIgnoreCase("set"))
{
String tag = StringUtils.join(args, " ", 2, args.length);
tag = tag.replace("%tag%", guild.getName());
if (tag.length() > 15)
{
sender.sendMessage(PREFIX + "The guild tag cannot go over 15 characters limit.");
return;
}
if (GUtil.containsBlacklistedWord(tag) && tfmBridge.isAdmin(sender))
{
sender.sendMessage(PREFIX + "The guild tag contains forbidden word(s).");
return;
}
guild.setTag(tag);
sender.sendMessage(PREFIX + "The guild tag has been changed to " + ChatColor.GOLD + GUtil.colorize(tag).replace("%rank%", "Guild Owner"));
}
else
{
sender.sendMessage(USAGE + "/g tag <set <tag> | clear [guild]>");
}
return;
}
if (args[1].equalsIgnoreCase("clear"))
{
if (args.length >= 3)
{
if (!tfmBridge.isAdmin(sender))
{
sender.sendMessage(PREFIX + "You do not have the permission to use this command.");
return;
}
guild = Guild.getGuild(StringUtils.join(args, " ", 2, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
return;
}
guild.setTag(null);
sender.sendMessage(PREFIX + "Successfully cleared the guild tag for " + ChatColor.GOLD + guild.getName());
return;
}
guild.setTag(null);
sender.sendMessage(PREFIX + "Successfully cleared the guild tag.");
}
else
{
sender.sendMessage(USAGE + "/g tag <set <tag> | clear [guild]>");
}
}
}

View file

@ -1,107 +0,0 @@
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;
}
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g tag <set <tag> | clear [guild]>>"));
return true;
}
Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild == null)
{
sender.sendMessage(NG);
return true;
}
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's tag!");
return true;
}
if (args.length >= 3)
{
if (args[1].equalsIgnoreCase("set"))
{
String tag = StringUtils.join(args, " ", 2, args.length);
tag = tag.replace("%tag%", guild.getName());
if (tag.length() > 30)
{
player.sendMessage(ChatColor.RED + "Your guild tag must not be over 30 characters.");
return true;
}
for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
{
if (tag.equalsIgnoreCase(blacklisted))
{
if (!plugin.bridge.isAdmin(player))
{
player.sendMessage(ChatColor.RED + "You may not use that name.");
return true;
}
}
}
guild.setTag(tag);
guild.save();
sender.sendMessage(tl("%p%Your guild tag has been changed to be \"" + GUtil.colorize(tag).replace("%rank%", "Guild Owner") + "%p%\"."));
return true;
}
}
if (args[1].equalsIgnoreCase("clear"))
{
if (args.length >= 3)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Guild g = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 2, args.length)));
if (g == null)
{
sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
return true;
}
g.setTag(null);
g.save();
sender.sendMessage(tl("%p%Cleared guild tag for " + g.getName() + "."));
return true;
}
guild.setTag(null);
guild.save();
sender.sendMessage(tl("%p%Your guild tag has been cleared."));
}
return true;
}
}

View file

@ -0,0 +1,36 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.User;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ToggleTagSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (args.length > 1)
{
sender.sendMessage(USAGE + "/g toggletag");
return;
}
User user = User.getUserFromPlayer(playerSender);
if (user == null)
{
user = User.create(playerSender);
}
user.setDisplayTag(!user.displayTag());
sender.sendMessage(PREFIX + ChatColor.GOLD + (user.displayTag() ? "Enabled" : "Disabled") + ChatColor.GRAY + " personal guild tag.");
}
}

View file

@ -1,66 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.user.User;
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 ToggleTagSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length > 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g toggletag [player]"));
return true;
}
if (args.length == 2)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null)
{
sender.sendMessage(PNF);
return true;
}
User user = plugin.userData.get(player.getUniqueId());
user.setTag(!user.isTag());
user.save();
sender.sendMessage(tl(PREFIX + (user.isTag() ? "Enabled" : "Disabled") + " personal guild tag for " + player.getName() + "."));
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(NG);
return true;
}
User user = plugin.userData.get(player.getUniqueId());
user.setTag(!user.isTag());
user.save();
sender.sendMessage(tl(PREFIX + (user.isTag() ? "Enabled" : "Disabled") + " personal guild tag."));
return true;
}
}

View file

@ -0,0 +1,36 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ToggleTagsSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!tfmBridge.isAdmin(sender))
{
sender.sendMessage(PREFIX + "You do not have the permission.");
return;
}
boolean enabled = ConfigEntry.GUILD_TAGS.getBoolean();
if (enabled)
{
ConfigEntry.GUILD_TAGS.setBoolean(false);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled " + ChatColor.GRAY + "global guild tags.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has globally disabled guild tags.");
}
else
{
ConfigEntry.GUILD_TAGS.setBoolean(true);
sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled " + ChatColor.GRAY + " global guild tags.");
Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has globally enabled guild tags.");
}
}
}

View file

@ -1,36 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class ToggleTagsSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (!plugin.bridge.isAdmin(sender))
{
sender.sendMessage(NO_PERMS);
return true;
}
boolean enabled = ConfigEntry.GUILD_TAGS_ENABLED.getBoolean();
if (enabled)
{
ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(false);
sender.sendMessage(tl(PREFIX + "Globally disabled guild tags."));
broadcast(ChatColor.RED + sender.getName() + " - Globally disabling guild tags");
}
else
{
ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(true);
sender.sendMessage(tl(PREFIX + "Globally enabled guild tags."));
broadcast(ChatColor.RED + sender.getName() + " - Globally enabling guild tags");
}
return true;
}
}

View file

@ -0,0 +1,51 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class TpSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length != 2)
{
sender.sendMessage(USAGE + "/g tp <player>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null || tfmBridge.isVanished(player))
{
sender.sendMessage(PLAYER_NOT_FOUND);
return;
}
if (!guild.isMember(player))
{
sender.sendMessage(PLAYER_NOT_IN_GUILD);
return;
}
playerSender.teleport(player);
sender.sendMessage(PREFIX + "Successfully teleported to " + ChatColor.GOLD + player.getName());
}
}

View file

@ -0,0 +1,47 @@
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.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class WarpSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
if (args.length < 2)
{
sender.sendMessage(USAGE + "/g warp <name>");
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
String name = StringUtils.join(args, " ", 1, args.length);
if (!guild.hasWarp(name))
{
sender.sendMessage(PREFIX + "The guild does not have the warp named " + ChatColor.GOLD + name);
return;
}
Location location = guild.getWarp(name);
playerSender.teleport(location);
sender.sendMessage(PREFIX + "Successfully warped to " + ChatColor.GOLD + name);
}
}

View file

@ -1,53 +0,0 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildWarp;
import org.apache.commons.lang.StringUtils;
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.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class WarpSubcommand extends Common implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
if (args.length < 2)
{
sender.sendMessage(tl(PREFIX + "Proper usage: /g warp <name>"));
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(NG);
return true;
}
String warpName = StringUtils.join(args, " ", 1, args.length);
if (!guild.warpExists(warpName))
{
sender.sendMessage(ChatColor.RED + "Warp not found.");
return true;
}
GuildWarp warp = guild.getWarp(warpName);
Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
player.teleport(warpLoc);
sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
return true;
}
}

View file

@ -0,0 +1,37 @@
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.CommandSender;
import org.bukkit.entity.Player;
public class WarpsSubCommand extends Common implements SubCommand
{
@Override
public void execute(CommandSender sender, Player playerSender, String[] args)
{
if (!(sender instanceof Player))
{
sender.sendMessage(IN_GAME_ONLY);
return;
}
Guild guild = Guild.getGuild(playerSender);
if (guild == null)
{
sender.sendMessage(NOT_IN_GUILD);
return;
}
if (guild.getWarps().isEmpty())
{
sender.sendMessage(PREFIX + "There are no warps.");
return;
}
sender.sendMessage(PREFIX + "Warps (" + guild.getWarps().size() + "): " + ChatColor.GOLD + StringUtils.join(guild.getWarpNames(), ", "));
}
}

View file

@ -1,36 +0,0 @@
package me.totalfreedom.tfguilds.command;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import org.apache.commons.lang.StringUtils;
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 WarpsSubcommand 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(NG);
return true;
}
List<String> warps = Guild.getGuildWarps();
sender.sendMessage(tl(PREFIX + "%s%Guild warps (%p%" + warps.size() + " total%s%)\n%p%" + StringUtils.join(warps, "%s%,%p% ")));
return true;
}
}

View file

@ -1,37 +1,29 @@
package me.totalfreedom.tfguilds.config;
import java.io.File;
import java.io.IOException;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
public class Config extends YamlConfiguration
{
private final TFGuilds plugin;
private final File file;
public Config(String name)
public Config(String fileName)
{
this.plugin = TFGuilds.getPlugin();
this.file = new File(plugin.getDataFolder(), name);
this.file = new File(plugin.getDataFolder(), fileName);
if (!file.exists())
{
options().copyDefaults(true);
plugin.saveResource(name, false);
plugin.saveResource(fileName, false);
}
load();
}
public void load()
{
try
{
super.load(file);
}
catch (Exception e)
{
e.printStackTrace();
}
load();
}
public void save()
@ -40,9 +32,21 @@ public class Config extends YamlConfiguration
{
super.save(file);
}
catch (Exception e)
catch (IOException ex)
{
e.printStackTrace();
ex.printStackTrace();
}
}
public void load()
{
try
{
super.load(file);
}
catch (IOException | InvalidConfigurationException ex)
{
ex.printStackTrace();
}
}
}

View file

@ -1,22 +1,25 @@
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"),
// Server
GUILD_CHAT_LOGGING_ENABLED("server.guild_chat_logging.enabled"),
GUILD_TAGS_ENABLED("server.guild_tags_enabled.enabled");
GUILD_CHAT_LOGGING("server.guild_chat_logging"),
GUILD_TAGS("server.guild_tags"),
MYSQL_HOST("mysql.host"),
MYSQL_PORT("mysql.port"),
MYSQL_USERNAME("mysql.username"),
MYSQL_PASSWORD("mysql.password"),
MYSQL_DATABASE("mysql.database");
private final String path;
private final Config config;
ConfigEntry(String path)
{
this.path = path;
this.config = TFGuilds.getPlugin().config;
this.config = TFGuilds.getPlugin().getConfig();
}
public boolean getBoolean()
@ -30,8 +33,13 @@ public enum ConfigEntry
config.save();
}
public ChatColor getChatColor()
public int getInteger()
{
return ChatColor.valueOf(config.getString(path).toUpperCase());
return config.getInt(path);
}
public String getString()
{
return config.getString(path);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,69 +0,0 @@
package me.totalfreedom.tfguilds.guild;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.Getter;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class GuildRank
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
@Getter
private String iguild;
// identifier
@Getter
private final String identifier;
// name
@Getter
private final String name;
// members of this rank
@Getter
private final List<UUID> members;
public GuildRank(String iguild, String identifier, String name, List<UUID> members)
{
this.iguild = iguild;
this.identifier = identifier;
this.name = name;
this.members = members;
}
public List<String> getMemberNames()
{
List<String> only = new ArrayList<>();
for (UUID member : members)
{
OfflinePlayer player = Bukkit.getOfflinePlayer(member);
only.add(player.getName());
}
return only;
}
public static GuildRank createGuildRank(String guildIdentifier, String identifier, String name)
{
return plugin.rankData.create(guildIdentifier, identifier, name);
}
public void save()
{
plugin.rankData.save(this);
}
public void updateGuildIdentifier(String newIdentifier)
{
plugin.rankData.updateGuildIdentifier(this, newIdentifier);
this.iguild = newIdentifier;
}
public void delete()
{
plugin.rankData.delete(this);
}
}

View file

@ -1,41 +0,0 @@
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)
{
if (string == null)
{
return null;
}
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

@ -1,44 +0,0 @@
package me.totalfreedom.tfguilds.guild;
import lombok.Getter;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.World;
import org.bukkit.entity.Player;
@Getter
public class GuildWarp
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private final String iguild;
private final String warpName;
private final double x;
private final double y;
private final double z;
private final World world;
public GuildWarp(String iguild, String warpName, double x, double y, double z, World world)
{
this.iguild = iguild;
this.warpName = warpName;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
}
public static GuildWarp createGuildWarp(String identifier, String name, Player player)
{
return plugin.warpData.create(identifier, name, player);
}
public void save()
{
plugin.warpData.save(this);
}
public void delete()
{
plugin.warpData.delete(this);
}
}

View file

@ -0,0 +1,141 @@
package me.totalfreedom.tfguilds.guild;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.entity.Player;
public class User
{
private static Map<Integer, User> users = new HashMap<>();
//
private final int id;
private final UUID uuid;
private boolean tag;
public User(int id, UUID uuid, boolean tag)
{
this.id = id;
this.uuid = uuid;
this.tag = tag;
}
public static User create(Player player)
{
int id = users.size() + 1;
User user = new User(id, player.getUniqueId(), true);
users.put(id, user);
user.save(true);
return user;
}
public static void loadAll()
{
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
ResultSet set = connection.prepareStatement("SELECT * FROM users").executeQuery();
while (set.next())
{
int id = set.getInt("id");
UUID uuid = UUID.fromString(set.getString("uuid"));
boolean tag = set.getBoolean("tag");
users.put(id, new User(id, uuid, tag));
}
TFGuilds.getPlugin().getLogger().info(users.size() + " users loaded!");
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public static boolean hasUser(int id)
{
return users.get(id) != null;
}
public static User getUserFromId(int id)
{
if (hasUser(id))
{
return users.get(id);
}
return null;
}
public static User getUserFromUuid(UUID uuid)
{
for (User user : users.values())
{
if (user.getUuid().equals(uuid))
{
return user;
}
}
return null;
}
public static User getUserFromPlayer(Player player)
{
return getUserFromUuid(player.getUniqueId());
}
public int getId()
{
return id;
}
public UUID getUuid()
{
return uuid;
}
public boolean displayTag()
{
return tag;
}
public void setDisplayTag(boolean tag)
{
this.tag = tag;
save();
}
public void save(boolean newSave)
{
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users VALUES (?, ?, ?)")
: connection.prepareStatement("UPDATE users SET tag=? WHERE id=?");
if (newSave)
{
statement.setString(1, uuid.toString());
statement.setInt(2, id);
statement.setBoolean(3, tag);
}
else
{
statement.setBoolean(1, tag);
statement.setInt(2, id);
}
statement.execute();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void save()
{
save(false);
}
}

View file

@ -4,8 +4,7 @@ import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank;
import me.totalfreedom.tfguilds.user.User;
import me.totalfreedom.tfguilds.guild.User;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -16,75 +15,55 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
public ChatListener(TFGuilds plugin)
{
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent e)
public void onPlayerChat(AsyncPlayerChatEvent event)
{
Player player = e.getPlayer();
Player player = event.getPlayer();
Guild guild = Guild.getGuild(player);
if (guild == null)
{
return;
}
if (Common.IN_GUILD_CHAT.contains(player))
if (Common.GUILD_CHAT.contains(player))
{
guild.chat(player.getName(), e.getMessage());
e.setCancelled(true);
event.setCancelled(true);
guild.chat(player, event.getMessage());
return;
}
GuildRank rank = null;
for (GuildRank r : guild.getRanks())
if (!ConfigEntry.GUILD_TAGS.getBoolean())
{
if (r != null)
{
if (r.getMembers() != null)
{
if (r.getMembers().contains(player.getUniqueId()))
{
rank = r;
}
}
}
return;
}
String display;
if (rank == null)
String display = guild.getPlayerRank(player);
if (display == guild.getDefaultRank())
{
if (guild.getOwner().equals(player.getUniqueId()))
{
display = "Guild Owner";
}
else if (guild.hasModerator(player.getUniqueId()))
else if (guild.isModerator(player))
{
display = "Guild Moderator";
}
else
{
display = "Guild Member";
}
}
else
else if (display == null)
{
display = rank.getName();
display = "Guild Member";
}
if (!ConfigEntry.GUILD_TAGS_ENABLED.getBoolean())
User user = User.getUserFromPlayer(player);
if (guild.getTag() != null && user.displayTag())
{
return;
}
User user = plugin.userData.get(player.getUniqueId());
if (!user.isTag())
{
return;
}
if (guild.hasTag())
{
e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
event.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + event.getFormat());
}
}
}

View file

@ -1,27 +1,42 @@
package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import me.totalfreedom.tfguilds.guild.User;
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.PlayerJoinEvent;
public class JoinListener implements Listener
{
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e)
public JoinListener(TFGuilds plugin)
{
Player player = e.getPlayer();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
User user = User.getUserFromPlayer(player);
if (user == null)
{
User.create(player);
}
Guild guild = Guild.getGuild(player);
if (guild == null)
{
return;
}
if (guild.hasMOTD())
if (guild.getMotd() != null && !guild.getMotd().isEmpty())
{
player.sendMessage(GUtil.colorize(guild.getMotd()));
player.sendMessage(guild.getMotd());
}
}
}

View file

@ -1,40 +1,39 @@
package me.totalfreedom.tfguilds.sql;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import org.bukkit.Bukkit;
public class SQLDatabase
{
private static final String DATABASE_FILENAME = "database.db";
private Connection connection;
public SQLDatabase()
public SQLDatabase(TFGuilds plugin)
{
File file = new File(TFGuilds.getPlugin().getDataFolder(), DATABASE_FILENAME);
if (!file.exists())
String password = ConfigEntry.MYSQL_PASSWORD.getString();
if (password == null)
{
try
{
file.createNewFile();
TFGuilds.getPlugin().saveResource(DATABASE_FILENAME, false);
}
catch (IOException ex)
{
ex.printStackTrace();
}
password = "";
}
try
{
connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
Bukkit.getLogger().info(ConfigEntry.MYSQL_USERNAME.getString());
connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
ConfigEntry.MYSQL_HOST.getString(),
ConfigEntry.MYSQL_PORT.getInteger(),
ConfigEntry.MYSQL_DATABASE.getString()),
ConfigEntry.MYSQL_USERNAME.getString(),
password);
createTables();
plugin.getLogger().info("Connection to the MySQL server established!");
}
catch (SQLException ex)
{
ex.printStackTrace();
plugin.getLogger().severe("Could not connect to MySQL server!");
}
}
@ -45,45 +44,39 @@ public class SQLDatabase
private void createTables() throws SQLException
{
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (\n" +
"\t`id` INT,\n" +
"\t`uuid` TINYTEXT,\n" +
"\t`tag` BOOL\n" +
");").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `worlds` (\n" +
"\t`id` SMALLINT,\n" +
"\t`name` TINYTEXT\n" +
");").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (\n" +
"\t`guild_identifier` TEXT,\n" +
"\t`identifier` TEXT,\n" +
"\t`name` TEXT,\n" +
"\t`members` TEXT\n" +
");").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (\n" +
"\t`identifier` TEXT,\n" +
"\t`name` TEXT,\n" +
"\t`owner` INT,\n" +
"\t`moderators` TEXT,\n" +
"\t`members` TEXT,\n" +
"\t`tag` TEXT,\n" +
"\t`state` TINYINT,\n" +
"\t`ranks` TEXT,\n" +
"\t`motd` TEXT,\n" +
"\t`x` DOUBLE,\n" +
"\t`y` DOUBLE,\n" +
"\t`z` DOUBLE,\n" +
"\t`world` SMALLINT,\n" +
"\t`default_rank` TEXT,\n" +
"\t`creation` BIGINT\n" +
");").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (\n" +
"\t`identifier` TEXT,\n" +
"\t`warp_name` TEXT,\n" +
"\t`x` DOUBLE,\n" +
"\t`y` DOUBLE,\n" +
"\t`z` DOUBLE,\n" +
"\t`world` SMALLINT\n" +
");").execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (" +
"`uuid` TEXT," +
"`id` INT," +
"`tag` BOOLEAN)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (" +
"`guild_id` TEXT," +
"`name` TEXT," +
"`x` DOUBLE," +
"`y` DOUBLE," +
"`z` DOUBLE," +
"`world` TEXT)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (" +
"`id` TEXT," +
"`name` TEXT," +
"`owner` INT," +
"`moderators` TEXT," +
"`members` TEXT," +
"`tag` TEXT," +
"`default_rank` TEXT," +
"`state` INT," +
"`motd` TEXT," +
"`x` DOUBLE," +
"`y` DOUBLE," +
"`z` DOUBLE," +
"`world` TEXT," +
"`creation` LONG)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (" +
"`guild_id` TEXT," +
"`name` TEXT," +
"`members` TEXT)")
.execute();
}
}

View file

@ -1,229 +0,0 @@
package me.totalfreedom.tfguilds.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank;
import me.totalfreedom.tfguilds.guild.GuildState;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class SQLGuildData
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private static final String TABLE_NAME = "guilds";
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=?";
private final String SELECT_MEMBER = "SELECT * FROM `" + TABLE_NAME + "` WHERE members LIKE ?";
private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET identifier=?, name=?, owner=?, members=?, moderators=?, tag=?, state=?, ranks=?, motd=?, x=?, y=?, z=?, world=?, default_rank=? WHERE identifier=?";
private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `name`, `owner`, `members`, " +
"`moderators`, `tag`, `state`, `ranks`, `motd`, `x`, `y`, `z`, `world`, `default_rank`, `creation`) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
public boolean exists(String identifier)
{
return plugin.guilds.containsKey(identifier);
}
public Guild get(String identifier)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, identifier);
ResultSet set = statement.executeQuery();
boolean next = set.next();
if (!next)
{
return null;
}
String name = set.getString("name");
UUID owner = plugin.userData.get(set.getInt("owner")).getUuid();
List<UUID> members = new ArrayList<>();
for (String stringMember : set.getString("members").split(","))
{
members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
}
List<UUID> moderators = new ArrayList<>();
if (set.getString("moderators") != null)
{
for (String stringModerator : set.getString("moderators").split(","))
{
moderators.add(plugin.userData.get(Integer.parseInt(stringModerator)).getUuid());
}
}
String tag = set.getString("tag");
GuildState state = GuildState.values()[set.getInt("state")];
List<GuildRank> ranks = new ArrayList<>();
if (set.getString("ranks") != null)
{
for (String rankString : set.getString("ranks").split(","))
{
ranks.add(plugin.rankData.get(identifier, rankString));
}
}
String motd = set.getString("motd");
Location home = new Location(plugin.worldData.getWorld(set.getInt("world")),
set.getDouble("x"),
set.getDouble("y"),
set.getDouble("z"));
String defaultRank = set.getString("default_rank");
long creation = set.getLong("creation");
return new Guild(identifier, name, owner, members, moderators, tag, state, ranks, motd, home, creation, defaultRank);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public Guild get(Player player)
{
for (Guild guild : plugin.guilds.values())
{
if (guild.getMembers().contains(player.getUniqueId()))
{
return guild;
}
}
return null;
}
public void getAll()
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
ResultSet set = statement.executeQuery();
while (set.next())
{
String identifier = set.getString("identifier");
plugin.guilds.put(identifier, get(identifier));
}
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public Guild create(String identifier, String name, Player owner)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, identifier);
statement.setString(2, name);
int ownerID = plugin.userData.get(owner.getUniqueId()).getId();
statement.setInt(3, ownerID);
statement.setString(4, "" + ownerID);
statement.setString(5, null);
statement.setString(6, "&8[&7" + name + "&8]");
statement.setInt(7, GuildState.INVITE_ONLY.ordinal());
statement.setString(8, null);
statement.setString(9, null);
statement.setDouble(10, 0.0);
statement.setDouble(11, 100.0);
statement.setDouble(12, 0.0);
statement.setInt(13, plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)));
statement.setString(14, null);
long creation = System.currentTimeMillis();
statement.setLong(15, creation);
statement.execute();
Guild guild = new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
GuildState.INVITE_ONLY, new ArrayList<>(), null, new Location(Bukkit.getWorlds().get(0), 0.0, 100.0, 0.0), creation, null);
plugin.guilds.put(identifier, guild);
return guild;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public void save(Guild guild, String identifier)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, guild.getIdentifier());
statement.setString(2, guild.getName());
statement.setString(3, "" + plugin.userData.get(guild.getOwner()).getId());
List<String> members = new ArrayList<>();
for (UUID member : guild.getMembers())
{
members.add("" + plugin.userData.get(member).getId());
}
statement.setString(4, members.size() == 0 ? null : StringUtils.join(members, ","));
List<String> moderators = new ArrayList<>();
for (UUID moderator : guild.getModerators())
{
moderators.add("" + plugin.userData.get(moderator).getId());
}
statement.setString(5, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
statement.setString(6, guild.getTag());
statement.setInt(7, guild.getState().ordinal());
List<String> stringRanks = new ArrayList<>();
for (GuildRank rank : guild.getRanks())
{
stringRanks.add(rank.getIdentifier());
}
statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
statement.setString(9, guild.getMotd());
Location home = guild.getHome();
statement.setDouble(10, home == null ? 0.0 : home.getX());
statement.setDouble(11, home == null ? 100.0 : home.getY());
statement.setDouble(12, home == null ? 0.0 : home.getZ());
statement.setInt(13, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
statement.setString(14, guild.getDefaultRank());
statement.setString(15, identifier);
statement.execute();
plugin.guilds.put(identifier, guild);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void save(Guild guild)
{
save(guild, guild.getIdentifier());
}
public void delete(Guild guild)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, guild.getIdentifier());
statement.execute();
plugin.guilds.remove(guild.getIdentifier());
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}

View file

@ -1,150 +0,0 @@
package me.totalfreedom.tfguilds.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.GuildRank;
import org.apache.commons.lang.StringUtils;
public class SQLRankData
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private static final String TABLE_NAME = "ranks";
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET name=?, members=? WHERE guild_identifier=? AND identifier=?";
private final String UPDATE_GUILD = "UPDATE `" + TABLE_NAME + "` SET guild_identifier=? WHERE guild_identifier=? AND identifier=?";
private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`guild_identifier`, `identifier`, `name`, `members`) " +
"VALUES (?, ?, ?, ?);";
public boolean exists(String guildIdentifier, String identifier)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, guildIdentifier);
statement.setString(2, identifier);
ResultSet set = statement.executeQuery();
return set.next();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return false;
}
public GuildRank get(String guildIdentifier, String identifier)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, guildIdentifier);
statement.setString(2, identifier);
ResultSet set = statement.executeQuery();
if (!set.next())
{
return null;
}
String name = set.getString("name");
List<UUID> members = new ArrayList<>();
if (set.getString("members") != null)
{
for (String stringMember : set.getString("members").split(","))
{
members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
}
}
return new GuildRank(guildIdentifier, identifier, name, members);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public GuildRank create(String guildIdentifier, String identifier, String name)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, guildIdentifier);
statement.setString(2, identifier);
statement.setString(3, name);
statement.setString(4, null);
statement.execute();
return new GuildRank(guildIdentifier, identifier, name, new ArrayList<>());
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public void save(GuildRank rank)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, rank.getName());
List<String> members = new ArrayList<>();
for (UUID member : rank.getMembers())
{
members.add("" + plugin.userData.get(member).getId());
}
statement.setString(2, members.size() == 0 ? null : StringUtils.join(members, ","));
statement.setString(3, rank.getIguild());
statement.setString(4, rank.getIdentifier());
statement.execute();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void updateGuildIdentifier(GuildRank rank, String newIdentifier)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
statement.setString(1, newIdentifier);
statement.setString(2, rank.getIguild());
statement.setString(3, rank.getIdentifier());
statement.execute();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void delete(GuildRank rank)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, rank.getIguild());
statement.setString(2, rank.getIdentifier());
statement.execute();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}

View file

@ -1,155 +0,0 @@
package me.totalfreedom.tfguilds.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.user.User;
public class SQLUserData
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private static final String TABLE_NAME = "users";
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE uuid=?";
private final String SELECT_ID = "SELECT * FROM `" + TABLE_NAME + "` WHERE id=?";
private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET tag=? WHERE uuid=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`id`, `uuid`, `tag`) " +
"VALUES (?, ?, ?);";
private final String COUNT = "SELECT COUNT(*) AS rows FROM `" + TABLE_NAME + "`";
public boolean exists(UUID uuid)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, uuid.toString());
ResultSet set = statement.executeQuery();
return set.next();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return false;
}
public boolean existsID(int id)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
ResultSet set = statement.executeQuery();
return set.next();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return false;
}
public User get(UUID uuid)
{
if (!exists(uuid))
{
create(uuid);
}
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, uuid.toString());
ResultSet set = statement.executeQuery();
set.next();
int id = set.getInt("id");
boolean tag = set.getBoolean("tag");
return new User(id, uuid, tag);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public User get(int id)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
ResultSet set = statement.executeQuery();
set.next();
UUID uuid = UUID.fromString(set.getString("uuid"));
boolean tag = set.getBoolean("tag");
return new User(id, uuid, tag);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public User create(UUID uuid)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
int id = getUserCount() + 1;
statement.setInt(1, id);
statement.setString(2, uuid.toString());
statement.setBoolean(3, true);
statement.execute();
return new User(id, uuid, true);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public void save(User user)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setBoolean(1, user.isTag());
statement.setString(2, user.getUuid().toString());
statement.execute();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public int getUserCount()
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(COUNT);
ResultSet set = statement.executeQuery();
set.next();
int count = set.getInt("rows");
set.close();
return count;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return 0;
}
}

View file

@ -1,134 +0,0 @@
package me.totalfreedom.tfguilds.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.GuildWarp;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class SQLWarpData
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private static final String TABLE_NAME = "warps";
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
private final String UPDATE = "UPDATE `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=? SET x=?, y=?, z=?, world=?";
private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `warp_name`, `x`, `y`, `z`, `world`) VALUES (?, ?, ?, ?, ?, ?);";
public boolean exists(String identifier, String warpName)
{
GuildWarp warp = plugin.warps.get(identifier);
return warp != null && warp.getWarpName().equalsIgnoreCase(warpName);
}
public GuildWarp get(String identifier, String warpName)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, identifier);
statement.setString(2, warpName);
ResultSet set = statement.executeQuery();
double x = set.getDouble("x");
double y = set.getDouble("y");
double z = set.getDouble("z");
World world = plugin.worldData.getWorld(set.getInt("world"));
return new GuildWarp(identifier, warpName, x, y, z, world);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public void getAll()
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
ResultSet set = statement.executeQuery();
while (set.next())
{
String identifier = set.getString("identifier");
plugin.warps.put(identifier, get(identifier, set.getString("warp_name")));
}
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public GuildWarp create(String identifier, String warpName, Player player)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, identifier);
statement.setString(2, warpName);
statement.setDouble(3, player.getLocation().getX());
statement.setDouble(4, player.getLocation().getY());
statement.setDouble(5, player.getLocation().getZ());
statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
statement.execute();
GuildWarp warp = new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
player.getLocation().getZ(), player.getWorld());
plugin.warps.put(identifier, warp);
return warp;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public void save(GuildWarp warp)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, warp.getIguild());
statement.setString(2, warp.getWarpName());
statement.setDouble(3, warp.getX());
statement.setDouble(4, warp.getY());
statement.setDouble(5, warp.getZ());
statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
statement.execute();
plugin.warps.put(warp.getIguild(), warp);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
public void delete(GuildWarp warp)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, warp.getIguild());
statement.setString(2, warp.getWarpName());
statement.execute();
plugin.warps.remove(warp.getIguild());
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
}

View file

@ -1,123 +0,0 @@
package me.totalfreedom.tfguilds.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.Bukkit;
import org.bukkit.World;
public class SQLWorldData
{
private static final TFGuilds plugin = TFGuilds.getPlugin();
private final String SELECT = "SELECT * FROM `worlds` WHERE name=?";
private final String SELECT_ID = "SELECT * FROM `worlds` WHERE id=?";
private final String INSERT = "INSERT INTO `worlds` (`id`, `name`) VALUES (?, ?);";
private final String COUNT = "SELECT COUNT(*) AS rows FROM `worlds`";
public boolean exists(World world)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, world.getName());
ResultSet set = statement.executeQuery();
return set.next();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return false;
}
public boolean existsID(int id)
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
ResultSet set = statement.executeQuery();
return set.next();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return false;
}
public int getWorldID(World world)
{
Connection connection = plugin.sql.getConnection();
try
{
if (!exists(world))
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setInt(1, getWorldCount() + 1);
statement.setString(2, world.getName());
statement.execute();
}
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, world.getName());
ResultSet set = statement.executeQuery();
set.next();
int id = set.getInt("id");
set.close();
return id;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return -1;
}
public World getWorld(int id)
{
Connection connection = plugin.sql.getConnection();
try
{
if (!existsID(id))
{
return null;
}
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
ResultSet set = statement.executeQuery();
set.next();
String name = set.getString("name");
set.close();
return Bukkit.getWorld(name);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return null;
}
public int getWorldCount()
{
Connection connection = plugin.sql.getConnection();
try
{
PreparedStatement statement = connection.prepareStatement(COUNT);
ResultSet set = statement.executeQuery();
set.next();
int count = set.getInt("rows");
set.close();
return count;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return 0;
}
}

View file

@ -1,28 +0,0 @@
package me.totalfreedom.tfguilds.user;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.tfguilds.TFGuilds;
@Getter
public class User
{
private final int id;
private final UUID uuid;
@Setter
private boolean tag;
public User(int id, UUID uuid, boolean tag)
{
this.id = id;
this.uuid = uuid;
this.tag = tag;
}
public void save()
{
TFGuilds.getPlugin().userData.save(this);
}
}

View file

@ -1,30 +0,0 @@
package me.totalfreedom.tfguilds.util;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GLog
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private static final String PREFIX = "[TFGuilds]";
private static void log(Object o, Level l)
{
LOGGER.log(l, PREFIX + " " + o);
}
public static void info(Object o)
{
log(o, Level.INFO);
}
public static void warn(Object o)
{
log(o, Level.WARNING);
}
public static void severe(Object o)
{
log(o, Level.SEVERE);
}
}

View file

@ -1,67 +1,53 @@
package me.totalfreedom.tfguilds.util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.totalfreedom.tfguilds.TFGuilds;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import net.md_5.bungee.api.ChatColor;
public class GUtil
{
private static final SimpleDateFormat STANDARD = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss");
private static final TFGuilds plugin = TFGuilds.getPlugin();
public static String flatten(String s)
{
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 String colorize(String string)
{
Matcher matcher = Pattern.compile("&#[a-f0-9A-F]{6}").matcher(string);
while (matcher.find())
{
String code = matcher.group().replace("&", "");
string = string.replace("&" + code, net.md_5.bungee.api.ChatColor.of(code) + "");
}
string = ChatColor.translateAlternateColorCodes('&', string);
return string;
}
public static String format(long time)
{
Date date = new Date(time);
return STANDARD.format(date);
}
public static List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE d MMM yyyy HH:mm:ss");
private static final List<String> BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
"admin", "owner", "moderator", "developer", "console", "dev", "staff",
"mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin",
"trial mod", "trial moderator", "trialmod", "trialmoderator");
public static List<String> getPlayerList()
public static String colorize(String string)
{
List<String> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers())
if (string != null)
{
if (!plugin.bridge.isVanished(player))
Matcher matcher = Pattern.compile("&#[a-f0-9A-F]{6}").matcher(string);
while (matcher.find())
{
players.add(player.getName());
String code = matcher.group().replace("&", "");
string = string.replace("&" + code, ChatColor.of(code) + "");
}
string = ChatColor.translateAlternateColorCodes('&', string);
}
return string;
}
public static boolean containsBlacklistedWord(String string)
{
for (String blacklist : BLACKLISTED_NAMES_AND_TAGS)
{
if (string.contains(blacklist))
{
return true;
}
}
return players;
return false;
}
public static String formatTime(long time)
{
Date date = new Date(time);
return DATE_FORMAT.format(date);
}
}

View file

@ -6,6 +6,7 @@ import java.util.List;
public class PaginationList<T> extends ArrayList<T>
{
private final int epp;
/**

View file

@ -3,20 +3,16 @@
#
server:
# Log guild chat to console?
guild_chat_logging:
enabled: true
guild_chat_logging: true
# Enable guild tags globally?
guild_tags_enabled:
enabled: true
guild_tags_enabled: true
# Color scheme used for TFGuilds
scheme:
# Primary color
primary: GREEN
# Secondary color
secondary: DARK_GREEN
# MySQL configuration
mysql:
host: localhost
port: 3306
username: root
password: password
database: TFGuilds

View file

@ -2,22 +2,20 @@ name: TFGuilds
version: ${project.version}
main: me.totalfreedom.tfguilds.TFGuilds
api-version: 1.16
authors: [ speed, super ]
authors: [ Fleek, super, speed ]
description: A guilds plugin for the TotalFreedom server.
softdepend:
- TotalFreedomMod
commands:
guild:
description: The main command of TFGuilds.
usage: /<command> <help>
description: A command to manage guilds
usage: /<command> help
aliases: [ g ]
guildchat:
description: Talk in chat with your guild.
usage: /<command> [message]
aliases: [ gchat ]
tfguilds:
description: Information about the plugin.
usage: /<command>
description: An information of TFGuilds plugin
usage: /<command> [reload]
aliases: [ tfg ]
guildchatspy:
description: An admin only command which allows for spying on guild chat.
description: Spy on guild chat
usage: /<command>
aliases: [ gchatspy, gcs ]