mirror of
https://github.com/TotalFreedomMC/TFGuilds.git
synced 2024-12-22 07:55:03 +00:00
Merge pull request #6 from AtlasMediaGroup/FS-151
Improve plugin performance (FS-151)
This commit is contained in:
commit
a23247d70f
12 changed files with 162 additions and 129 deletions
|
@ -1,11 +1,15 @@
|
||||||
package me.totalfreedom.tfguilds;
|
package me.totalfreedom.tfguilds;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import me.totalfreedom.tfguilds.bridge.TFMBridge;
|
import me.totalfreedom.tfguilds.bridge.TFMBridge;
|
||||||
import me.totalfreedom.tfguilds.command.GuildChatCommand;
|
import me.totalfreedom.tfguilds.command.GuildChatCommand;
|
||||||
import me.totalfreedom.tfguilds.command.GuildChatSpyCommand;
|
import me.totalfreedom.tfguilds.command.GuildChatSpyCommand;
|
||||||
import me.totalfreedom.tfguilds.command.GuildCommand;
|
import me.totalfreedom.tfguilds.command.GuildCommand;
|
||||||
import me.totalfreedom.tfguilds.command.TFGuildsCommand;
|
import me.totalfreedom.tfguilds.command.TFGuildsCommand;
|
||||||
import me.totalfreedom.tfguilds.config.Config;
|
import me.totalfreedom.tfguilds.config.Config;
|
||||||
|
import me.totalfreedom.tfguilds.guild.Guild;
|
||||||
|
import me.totalfreedom.tfguilds.guild.GuildWarp;
|
||||||
import me.totalfreedom.tfguilds.listener.ChatListener;
|
import me.totalfreedom.tfguilds.listener.ChatListener;
|
||||||
import me.totalfreedom.tfguilds.listener.JoinListener;
|
import me.totalfreedom.tfguilds.listener.JoinListener;
|
||||||
import me.totalfreedom.tfguilds.sql.SQLDatabase;
|
import me.totalfreedom.tfguilds.sql.SQLDatabase;
|
||||||
|
@ -20,6 +24,11 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class TFGuilds extends JavaPlugin
|
public final class TFGuilds extends JavaPlugin
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// TEMP FIX UNTIL REWRITE
|
||||||
|
public Map<String, Guild> guilds;
|
||||||
|
public Map<String, GuildWarp> warps;
|
||||||
|
|
||||||
private static TFGuilds plugin;
|
private static TFGuilds plugin;
|
||||||
|
|
||||||
public static TFGuilds getPlugin()
|
public static TFGuilds getPlugin()
|
||||||
|
@ -42,12 +51,16 @@ public final class TFGuilds extends JavaPlugin
|
||||||
plugin = this;
|
plugin = this;
|
||||||
config = new Config("config.yml");
|
config = new Config("config.yml");
|
||||||
bridge = new TFMBridge();
|
bridge = new TFMBridge();
|
||||||
|
guilds = new HashMap<>();
|
||||||
|
warps = new HashMap<>();
|
||||||
sql = new SQLDatabase();
|
sql = new SQLDatabase();
|
||||||
guildData = new SQLGuildData();
|
guildData = new SQLGuildData();
|
||||||
rankData = new SQLRankData();
|
rankData = new SQLRankData();
|
||||||
userData = new SQLUserData();
|
userData = new SQLUserData();
|
||||||
warpData = new SQLWarpData();
|
warpData = new SQLWarpData();
|
||||||
worldData = new SQLWorldData();
|
worldData = new SQLWorldData();
|
||||||
|
guildData.getAll();
|
||||||
|
warpData.getAll();
|
||||||
loadCommands();
|
loadCommands();
|
||||||
loadListeners();
|
loadListeners();
|
||||||
GLog.info("Enabled " + this.getDescription().getFullName());
|
GLog.info("Enabled " + this.getDescription().getFullName());
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class DeleteWarpSubcommand extends Common implements CommandExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
String warpName = StringUtils.join(args, " ", 1, args.length);
|
String warpName = StringUtils.join(args, " ", 1, args.length);
|
||||||
if (!Guild.warpExists(guild.getIdentifier(), warpName))
|
if (!guild.warpExists(warpName))
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "Warp not found.");
|
sender.sendMessage(ChatColor.RED + "Warp not found.");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class SetWarpSubcommand extends Common implements CommandExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
String warpName = StringUtils.join(args, " ", 1, args.length);
|
String warpName = StringUtils.join(args, " ", 1, args.length);
|
||||||
if (Guild.warpExists(guild.getIdentifier(), warpName))
|
if (guild.warpExists(warpName))
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
|
sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -38,13 +38,13 @@ public class WarpSubcommand extends Common implements CommandExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
String warpName = StringUtils.join(args, " ", 1, args.length);
|
String warpName = StringUtils.join(args, " ", 1, args.length);
|
||||||
if (!Guild.warpExists(guild.getIdentifier(), warpName))
|
if (!guild.warpExists(warpName))
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "Warp not found.");
|
sender.sendMessage(ChatColor.RED + "Warp not found.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
|
GuildWarp warp = guild.getWarp(warpName);
|
||||||
Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
|
Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
|
||||||
player.teleport(warpLoc);
|
player.teleport(warpLoc);
|
||||||
sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
|
sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
|
||||||
|
|
|
@ -289,7 +289,7 @@ public class Guild
|
||||||
public static List<String> getGuildList()
|
public static List<String> getGuildList()
|
||||||
{
|
{
|
||||||
List<String> g = new ArrayList<>();
|
List<String> g = new ArrayList<>();
|
||||||
for (Guild guild : plugin.guildData.getAll())
|
for (Guild guild : plugin.guilds.values())
|
||||||
{
|
{
|
||||||
g.add(guild.getName());
|
g.add(guild.getName());
|
||||||
}
|
}
|
||||||
|
@ -299,13 +299,23 @@ public class Guild
|
||||||
public static List<String> getGuildWarps()
|
public static List<String> getGuildWarps()
|
||||||
{
|
{
|
||||||
List<String> warps = new ArrayList<>();
|
List<String> warps = new ArrayList<>();
|
||||||
for (GuildWarp warp : plugin.warpData.getAll())
|
for (GuildWarp warp : plugin.warps.values())
|
||||||
{
|
{
|
||||||
warps.add(warp.getWarpName());
|
warps.add(warp.getWarpName());
|
||||||
}
|
}
|
||||||
return warps;
|
return warps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GuildWarp getWarp(String warpName)
|
||||||
|
{
|
||||||
|
GuildWarp warp = plugin.warps.get(identifier);
|
||||||
|
if (warp != null && warp.getWarpName().equalsIgnoreCase(warpName))
|
||||||
|
{
|
||||||
|
return warp;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getInformation()
|
public String getInformation()
|
||||||
{
|
{
|
||||||
return Common.tl(Common.PREFIX + "Guild Information\n" +
|
return Common.tl(Common.PREFIX + "Guild Information\n" +
|
||||||
|
@ -393,7 +403,7 @@ public class Guild
|
||||||
|
|
||||||
public static Guild getGuild(String identifier)
|
public static Guild getGuild(String identifier)
|
||||||
{
|
{
|
||||||
return plugin.guildData.get(identifier);
|
return plugin.guilds.get(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Guild getGuild(Player player)
|
public static Guild getGuild(Player player)
|
||||||
|
@ -416,7 +426,7 @@ public class Guild
|
||||||
return GuildWarp.createGuildWarp(identifier, warpName, player);
|
return GuildWarp.createGuildWarp(identifier, warpName, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean warpExists(String identifier, String warpName)
|
public boolean warpExists(String warpName)
|
||||||
{
|
{
|
||||||
return plugin.warpData.exists(identifier, warpName);
|
return plugin.warpData.exists(identifier, warpName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,6 @@ public class ChatListener implements Listener
|
||||||
|
|
||||||
if (guild.hasTag())
|
if (guild.hasTag())
|
||||||
{
|
{
|
||||||
// This seems to result in the entry being logged twice on the console, which is silly... Not sure if there was a good reason for it.
|
|
||||||
//System.out.println(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
|
|
||||||
e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
|
e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,79 +10,80 @@ import me.totalfreedom.tfguilds.TFGuilds;
|
||||||
public class SQLDatabase
|
public class SQLDatabase
|
||||||
{
|
{
|
||||||
private static final String DATABASE_FILENAME = "database.db";
|
private static final String DATABASE_FILENAME = "database.db";
|
||||||
private static final TFGuilds plugin = TFGuilds.getPlugin();
|
private Connection connection;
|
||||||
|
|
||||||
private final File file;
|
|
||||||
|
|
||||||
public SQLDatabase()
|
public SQLDatabase()
|
||||||
{
|
{
|
||||||
File file = new File(plugin.getDataFolder(), DATABASE_FILENAME);
|
File file = new File(TFGuilds.getPlugin().getDataFolder(), DATABASE_FILENAME);
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
plugin.saveResource(DATABASE_FILENAME, false);
|
TFGuilds.getPlugin().saveResource(DATABASE_FILENAME, false);
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection()
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Connection connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
|
connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
|
||||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (\n" +
|
createTables();
|
||||||
"\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();
|
|
||||||
return connection;
|
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
public Connection getConnection()
|
||||||
|
{
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class SQLGuildData
|
public class SQLGuildData
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final TFGuilds plugin = TFGuilds.getPlugin();
|
private static final TFGuilds plugin = TFGuilds.getPlugin();
|
||||||
private static final String TABLE_NAME = "guilds";
|
private static final String TABLE_NAME = "guilds";
|
||||||
|
|
||||||
|
@ -34,23 +35,13 @@ public class SQLGuildData
|
||||||
|
|
||||||
public boolean exists(String identifier)
|
public boolean exists(String identifier)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
return plugin.guilds.containsKey(identifier);
|
||||||
{
|
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
|
||||||
statement.setString(1, identifier);
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
return set.next();
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guild get(String identifier)
|
public Guild get(String identifier)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, identifier);
|
statement.setString(1, identifier);
|
||||||
|
@ -103,7 +94,7 @@ public class SQLGuildData
|
||||||
|
|
||||||
public Guild get(Player player)
|
public Guild get(Player player)
|
||||||
{
|
{
|
||||||
for (Guild guild : getAll())
|
for (Guild guild : plugin.guilds.values())
|
||||||
{
|
{
|
||||||
if (guild.getMembers().contains(player.getUniqueId()))
|
if (guild.getMembers().contains(player.getUniqueId()))
|
||||||
{
|
{
|
||||||
|
@ -113,29 +104,29 @@ public class SQLGuildData
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Guild> getAll()
|
public void getAll()
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
|
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
List<Guild> guilds = new ArrayList<>();
|
|
||||||
while (set.next())
|
while (set.next())
|
||||||
{
|
{
|
||||||
guilds.add(get(set.getString("identifier")));
|
String identifier = set.getString("identifier");
|
||||||
|
plugin.guilds.put(identifier, get(identifier));
|
||||||
}
|
}
|
||||||
return guilds;
|
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Guild create(String identifier, String name, Player owner)
|
public Guild create(String identifier, String name, Player owner)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(INSERT);
|
PreparedStatement statement = connection.prepareStatement(INSERT);
|
||||||
statement.setString(1, identifier);
|
statement.setString(1, identifier);
|
||||||
|
@ -156,9 +147,11 @@ public class SQLGuildData
|
||||||
long creation = System.currentTimeMillis();
|
long creation = System.currentTimeMillis();
|
||||||
statement.setLong(15, creation);
|
statement.setLong(15, creation);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
return new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
|
Guild guild = new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
|
||||||
ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
|
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);
|
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)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
@ -169,7 +162,8 @@ public class SQLGuildData
|
||||||
|
|
||||||
public void save(Guild guild, String identifier)
|
public void save(Guild guild, String identifier)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
||||||
statement.setString(1, guild.getIdentifier());
|
statement.setString(1, guild.getIdentifier());
|
||||||
|
@ -204,6 +198,7 @@ public class SQLGuildData
|
||||||
statement.setString(14, guild.getDefaultRank());
|
statement.setString(14, guild.getDefaultRank());
|
||||||
statement.setString(15, identifier);
|
statement.setString(15, identifier);
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
plugin.guilds.put(identifier, guild);
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
@ -218,11 +213,13 @@ public class SQLGuildData
|
||||||
|
|
||||||
public void delete(Guild guild)
|
public void delete(Guild guild)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(DELETE);
|
PreparedStatement statement = connection.prepareStatement(DELETE);
|
||||||
statement.setString(1, guild.getIdentifier());
|
statement.setString(1, guild.getIdentifier());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
plugin.guilds.remove(guild.getIdentifier());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,8 @@ public class SQLRankData
|
||||||
|
|
||||||
public boolean exists(String guildIdentifier, String identifier)
|
public boolean exists(String guildIdentifier, String identifier)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, guildIdentifier);
|
statement.setString(1, guildIdentifier);
|
||||||
|
@ -42,7 +43,8 @@ public class SQLRankData
|
||||||
|
|
||||||
public GuildRank get(String guildIdentifier, String identifier)
|
public GuildRank get(String guildIdentifier, String identifier)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, guildIdentifier);
|
statement.setString(1, guildIdentifier);
|
||||||
|
@ -72,7 +74,8 @@ public class SQLRankData
|
||||||
|
|
||||||
public GuildRank create(String guildIdentifier, String identifier, String name)
|
public GuildRank create(String guildIdentifier, String identifier, String name)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(INSERT);
|
PreparedStatement statement = connection.prepareStatement(INSERT);
|
||||||
statement.setString(1, guildIdentifier);
|
statement.setString(1, guildIdentifier);
|
||||||
|
@ -91,7 +94,8 @@ public class SQLRankData
|
||||||
|
|
||||||
public void save(GuildRank rank)
|
public void save(GuildRank rank)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
||||||
statement.setString(1, rank.getName());
|
statement.setString(1, rank.getName());
|
||||||
|
@ -113,7 +117,8 @@ public class SQLRankData
|
||||||
|
|
||||||
public void updateGuildIdentifier(GuildRank rank, String newIdentifier)
|
public void updateGuildIdentifier(GuildRank rank, String newIdentifier)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
|
PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
|
||||||
statement.setString(1, newIdentifier);
|
statement.setString(1, newIdentifier);
|
||||||
|
@ -129,7 +134,8 @@ public class SQLRankData
|
||||||
|
|
||||||
public void delete(GuildRank rank)
|
public void delete(GuildRank rank)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(DELETE);
|
PreparedStatement statement = connection.prepareStatement(DELETE);
|
||||||
statement.setString(1, rank.getIguild());
|
statement.setString(1, rank.getIguild());
|
||||||
|
|
|
@ -22,7 +22,8 @@ public class SQLUserData
|
||||||
|
|
||||||
public boolean exists(UUID uuid)
|
public boolean exists(UUID uuid)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
|
@ -38,7 +39,8 @@ public class SQLUserData
|
||||||
|
|
||||||
public boolean existsID(int id)
|
public boolean existsID(int id)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
|
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, id);
|
||||||
|
@ -58,7 +60,8 @@ public class SQLUserData
|
||||||
{
|
{
|
||||||
create(uuid);
|
create(uuid);
|
||||||
}
|
}
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
|
@ -77,7 +80,8 @@ public class SQLUserData
|
||||||
|
|
||||||
public User get(int id)
|
public User get(int id)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
|
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, id);
|
||||||
|
@ -96,7 +100,8 @@ public class SQLUserData
|
||||||
|
|
||||||
public User create(UUID uuid)
|
public User create(UUID uuid)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(INSERT);
|
PreparedStatement statement = connection.prepareStatement(INSERT);
|
||||||
int id = getUserCount() + 1;
|
int id = getUserCount() + 1;
|
||||||
|
@ -115,7 +120,8 @@ public class SQLUserData
|
||||||
|
|
||||||
public void save(User user)
|
public void save(User user)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
||||||
statement.setBoolean(1, user.isTag());
|
statement.setBoolean(1, user.isTag());
|
||||||
|
@ -130,7 +136,8 @@ public class SQLUserData
|
||||||
|
|
||||||
public int getUserCount()
|
public int getUserCount()
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(COUNT);
|
PreparedStatement statement = connection.prepareStatement(COUNT);
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
|
|
|
@ -24,24 +24,14 @@ public class SQLWarpData
|
||||||
|
|
||||||
public boolean exists(String identifier, String warpName)
|
public boolean exists(String identifier, String warpName)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
GuildWarp warp = plugin.warps.get(identifier);
|
||||||
{
|
return warp != null && warp.getWarpName().equalsIgnoreCase(warpName);
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
|
||||||
statement.setString(1, identifier);
|
|
||||||
statement.setString(2, warpName);
|
|
||||||
ResultSet set = statement.executeQuery();
|
|
||||||
return set.next();
|
|
||||||
}
|
|
||||||
catch (SQLException ex)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuildWarp get(String identifier, String warpName)
|
public GuildWarp get(String identifier, String warpName)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, identifier);
|
statement.setString(1, identifier);
|
||||||
|
@ -60,29 +50,29 @@ public class SQLWarpData
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GuildWarp> getAll()
|
public void getAll()
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
|
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
List<GuildWarp> warps = new ArrayList<>();
|
|
||||||
while (set.next())
|
while (set.next())
|
||||||
{
|
{
|
||||||
warps.add(get(set.getString("identifier"), set.getString("warp_name")));
|
String identifier = set.getString("identifier");
|
||||||
|
plugin.warps.put(identifier, get(identifier, set.getString("warp_name")));
|
||||||
}
|
}
|
||||||
return warps;
|
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuildWarp create(String identifier, String warpName, Player player)
|
public GuildWarp create(String identifier, String warpName, Player player)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(INSERT);
|
PreparedStatement statement = connection.prepareStatement(INSERT);
|
||||||
statement.setString(1, identifier);
|
statement.setString(1, identifier);
|
||||||
|
@ -92,8 +82,10 @@ public class SQLWarpData
|
||||||
statement.setDouble(5, player.getLocation().getZ());
|
statement.setDouble(5, player.getLocation().getZ());
|
||||||
statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
|
statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
|
||||||
statement.execute();
|
statement.execute();
|
||||||
return new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
|
GuildWarp warp = new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
|
||||||
player.getLocation().getZ(), player.getWorld());
|
player.getLocation().getZ(), player.getWorld());
|
||||||
|
plugin.warps.put(identifier, warp);
|
||||||
|
return warp;
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
@ -104,7 +96,8 @@ public class SQLWarpData
|
||||||
|
|
||||||
public void save(GuildWarp warp)
|
public void save(GuildWarp warp)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
PreparedStatement statement = connection.prepareStatement(UPDATE);
|
||||||
statement.setString(1, warp.getIguild());
|
statement.setString(1, warp.getIguild());
|
||||||
|
@ -114,6 +107,7 @@ public class SQLWarpData
|
||||||
statement.setDouble(5, warp.getZ());
|
statement.setDouble(5, warp.getZ());
|
||||||
statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
|
statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
plugin.warps.put(warp.getIguild(), warp);
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
@ -123,12 +117,14 @@ public class SQLWarpData
|
||||||
|
|
||||||
public void delete(GuildWarp warp)
|
public void delete(GuildWarp warp)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(DELETE);
|
PreparedStatement statement = connection.prepareStatement(DELETE);
|
||||||
statement.setString(1, warp.getIguild());
|
statement.setString(1, warp.getIguild());
|
||||||
statement.setString(2, warp.getWarpName());
|
statement.setString(2, warp.getWarpName());
|
||||||
statement.execute();
|
statement.execute();
|
||||||
|
plugin.warps.remove(warp.getIguild());
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,7 +19,8 @@ public class SQLWorldData
|
||||||
|
|
||||||
public boolean exists(World world)
|
public boolean exists(World world)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT);
|
PreparedStatement statement = connection.prepareStatement(SELECT);
|
||||||
statement.setString(1, world.getName());
|
statement.setString(1, world.getName());
|
||||||
|
@ -35,7 +36,8 @@ public class SQLWorldData
|
||||||
|
|
||||||
public boolean existsID(int id)
|
public boolean existsID(int id)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
|
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
|
||||||
statement.setInt(1, id);
|
statement.setInt(1, id);
|
||||||
|
@ -51,7 +53,8 @@ public class SQLWorldData
|
||||||
|
|
||||||
public int getWorldID(World world)
|
public int getWorldID(World world)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!exists(world))
|
if (!exists(world))
|
||||||
{
|
{
|
||||||
|
@ -77,7 +80,8 @@ public class SQLWorldData
|
||||||
|
|
||||||
public World getWorld(int id)
|
public World getWorld(int id)
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (!existsID(id))
|
if (!existsID(id))
|
||||||
{
|
{
|
||||||
|
@ -100,7 +104,8 @@ public class SQLWorldData
|
||||||
|
|
||||||
public int getWorldCount()
|
public int getWorldCount()
|
||||||
{
|
{
|
||||||
try (Connection connection = plugin.sql.getConnection())
|
Connection connection = plugin.sql.getConnection();
|
||||||
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement statement = connection.prepareStatement(COUNT);
|
PreparedStatement statement = connection.prepareStatement(COUNT);
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
|
|
Loading…
Reference in a new issue