Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from superischroma/sql
Browse files Browse the repository at this point in the history
move player and guild data to a SQL database
  • Loading branch information
speed authored Dec 8, 2020
2 parents 3bf03d8 + b13ac97 commit ffd0e11
Show file tree
Hide file tree
Showing 39 changed files with 963 additions and 288 deletions.
13 changes: 11 additions & 2 deletions .idea/TFGuilds.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import me.totalfreedom.tfguilds.config.Config;
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.SQLWorldData;
import me.totalfreedom.tfguilds.util.GLog;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -22,18 +27,24 @@ public static TFGuilds getPlugin()
}

public Config config;
public Config guilds;
public Config players;
public TFMBridge bridge;
public SQLDatabase sql;
public SQLGuildData guildData;
public SQLRankData rankData;
public SQLWorldData worldData;
public SQLUserData userData;

@Override
public void onEnable()
{
plugin = this;
config = new Config("config.yml");
guilds = new Config("guilds.yml");
players = new Config("players.yml");
bridge = new TFMBridge();
sql = new SQLDatabase();
guildData = new SQLGuildData();
rankData = new SQLRankData();
worldData = new SQLWorldData();
userData = new SQLUserData();
loadCommands();
loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName());
Expand All @@ -44,8 +55,6 @@ public void onDisable()
{
plugin = null;
config.save();
guilds.save();
players.save();
GLog.info("Disabled " + this.getDescription().getFullName());
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public boolean isAdmin(CommandSender 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (!guild.hasMember(player.getName()))
if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
Expand All @@ -56,13 +56,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (guild.hasModerator(player.getName()))
if (guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for this guild!");
return true;
}

guild.addModerator(player.getName());
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();
Expand All @@ -83,7 +83,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (!guild.getOwner().equals(player.getName()))
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
return true;
Expand All @@ -96,25 +96,25 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (guild.getOwner().equals(n.getName()))
if (guild.getOwner().equals(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "No need to make yourself a moderator!");
return true;
}

if (!guild.hasMember(n.getName()))
if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}

if (guild.hasModerator(n.getName()))
if (guild.hasModerator(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for your guild!");
return true;
}

guild.addModerator(n.getName());
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (!guild.getOwner().equals(player.getName()))
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't create ranks for your guild!");
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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.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 java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CreateSubcommand extends Common implements CommandExecutor
{
@Override
Expand All @@ -32,7 +30,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

Player player = (Player)sender;
Player player = (Player) sender;
String name = StringUtils.join(args, " ", 1, args.length);
String identifier = GUtil.flatten(name);

Expand Down Expand Up @@ -76,7 +74,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

Guild.createGuild(identifier, name, player);
plugin.players.set(player.getName() + ".tag", true);
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

if (!guild.getOwner().equals(player.getName()))
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't delete ranks from your guild!");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import me.totalfreedom.tfguilds.util.GLog;
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;
Expand Down Expand Up @@ -40,7 +39,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

String n = guild.getName();
GLog.info("Removing guilds.yml data for " + n);
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%\"."));
Expand All @@ -62,13 +61,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}

Guild guild = Guild.getGuild(player);
if (!guild.getOwner().equals(player.getName()))
if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You are not the owner of this guild!");
return true;
}

GLog.info("Removing guilds.yml data for " + guild.getName());
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!"));
Expand Down
36 changes: 28 additions & 8 deletions src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

public class GuildCommand extends Common implements CommandExecutor, TabCompleter
{
Expand Down Expand Up @@ -84,7 +85,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args)
{
Guild guild = Guild.getGuild(sender);
if (args.length == 1)
{
return Arrays.asList("addmod", "chat", "createrank", "create",
Expand Down Expand Up @@ -139,15 +139,25 @@ else if (args.length == 2)
case "deleterank":
case "setdefaultrank":
{
if (guild.getOwner().equals(sender.getName()))
if (sender instanceof Player)
{
return guild.getRankNames();
Player player = (Player) sender;
Guild guild = Guild.getGuild(player);
if (guild.getOwner().equals(player.getUniqueId()))
{
return guild.getRankNames();
}
}
}

case "tp":
{
return guild.getMembers();
if (sender instanceof Player)
{
Player player = (Player) sender;
Guild guild = Guild.getGuild(player);
return guild.getOnlyMembers();
}
}

case "disband":
Expand All @@ -162,19 +172,29 @@ else if (args.length == 2)

case "kick":
{
if (guild.hasModerator(sender.getName()))
if (sender instanceof Player)
{
return guild.getOnlyMembers();
Player player = (Player) sender;
Guild guild = Guild.getGuild(player);
if (guild.hasModerator(player.getUniqueId()))
{
return guild.getOnlyMembers();
}
}
}

case "removemod":
case "addmod":
case "setowner":
{
if (guild.getOwner().equals(sender.getName()))
if (sender instanceof Player)
{
return guild.getMembers();
Player player = (Player) sender;
Guild guild = Guild.getGuild(player);
if (guild.getOwner().equals(player.getUniqueId()))
{
return guild.getOnlyMembers();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
{
if (args[1].equalsIgnoreCase("set"))
{
if (!guild.hasModerator(player.getName()))
if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's home!");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
INVITES.remove(player);
}

guild.addMember(player.getName());
guild.addMember(player.getUniqueId());
guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
guild.save();
return true;
Expand Down
Loading

0 comments on commit ffd0e11

Please sign in to comment.