Modification to SQL statements and fix invites (#8)

* Add primary key (rowid) to database

* Fix players not being able to join after being invited
This commit is contained in:
Nathan Curran 2021-06-04 09:21:23 +10:00 committed by GitHub
parent a1a1f8edb0
commit 8636c88f94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 11 deletions

View File

@ -73,7 +73,7 @@ public class InviteSubCommand extends Common implements SubCommand
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 + "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());
@ -86,7 +86,9 @@ public class InviteSubCommand extends Common implements SubCommand
{
return;
}
guild.removeInvite(player);
if (player.isOnline())
{
player.sendMessage(PREFIX + "The invite to " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has expired!");

View File

@ -46,7 +46,7 @@ public class JoinSubCommand extends Common implements SubCommand
if (guild.getState() == Guild.State.INVITE_ONLY)
{
if (guild.isInvited(playerSender))
if (!guild.isInvited(playerSender))
{
sender.sendMessage(PREFIX + "You must be invited to join the guild.");
return;

View File

@ -353,7 +353,7 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = connection.prepareStatement("INSERT INTO ranks (guild_id, name, members) VALUES (?, ?, ?)");
PreparedStatement statement = connection.prepareStatement("INSERT INTO ranks (`guild_id`, `name`, `members`) VALUES (?, ?, ?)");
statement.setString(1, id);
statement.setString(2, name);
statement.setString(3, null);
@ -475,7 +475,8 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds (`id`, `name`, `owner`, `moderators`, `members`, `tag`, `default_rank`, `state`, `motd`, `x`, `y`, `z`, `world`, `creation`)" +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
: connection.prepareStatement("UPDATE guilds SET owner=?," +
"moderators=?," +
"members=?," +
@ -559,7 +560,7 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = connection.prepareStatement("INSERT INTO warps VALUES (?, ?, ?, ?, ?, ?)");
PreparedStatement statement = connection.prepareStatement("INSERT INTO warps (`guild_id`, `name`, `x`, `y`, `z`, `world`) VALUES (?, ?, ?, ?, ?, ?)");
statement.setString(1, id);
statement.setString(2, name);
Location location = warps.get(name);

View File

@ -113,7 +113,7 @@ public class User
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users VALUES (?, ?, ?)")
PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users (`uuid`, `id`, `tag`) VALUES (?, ?, ?)")
: connection.prepareStatement("UPDATE users SET tag=? WHERE id=?");
if (newSave)
{

View File

@ -21,7 +21,6 @@ public class SQLDatabase
}
try
{
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(),
@ -47,7 +46,8 @@ public class SQLDatabase
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (" +
"`uuid` TEXT," +
"`id` INT," +
"`tag` BOOLEAN)")
"`tag` BOOLEAN," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (" +
"`guild_id` TEXT," +
@ -55,7 +55,8 @@ public class SQLDatabase
"`x` DOUBLE," +
"`y` DOUBLE," +
"`z` DOUBLE," +
"`world` TEXT)")
"`world` TEXT," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (" +
"`id` TEXT," +
@ -71,12 +72,14 @@ public class SQLDatabase
"`y` DOUBLE," +
"`z` DOUBLE," +
"`world` TEXT," +
"`creation` LONG)")
"`creation` LONG," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (" +
"`guild_id` TEXT," +
"`name` TEXT," +
"`members` TEXT)")
"`members` TEXT," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
}
}