uh oh stupid idiot me

This commit is contained in:
super 2020-12-03 02:02:05 -05:00
parent dd1a740252
commit 16cc2c2921
3 changed files with 25 additions and 22 deletions

View file

@ -347,21 +347,18 @@ public class Guild
public void rename(String name)
{
String oldIdentifier = this.identifier;
this.identifier = GUtil.flatten(name);
updateRankIdentifiers();
this.name = name;
this.tag = GUtil.colorize("&8[&7" + name + "&8]");
this.save();
plugin.guildData.save(this, oldIdentifier);
}
public void updateRankIdentifiers()
{
for (GuildRank rank : ranks)
{
rank.delete();
rank.updateGuildIdentifier(identifier);
rank.save();
}
}
public static Guild createGuild(String identifier, String name, Player owner)

View file

@ -27,7 +27,7 @@ public class SQLGuildData
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 name=?, owner=?, members=?, moderators=?, tag=?, state=?, ranks=?, motd=?, x=?, y=?, z=?, world=?, default_rank=? WHERE identifier=?";
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`) " +
@ -170,35 +170,36 @@ public class SQLGuildData
return null;
}
public void save(Guild guild)
public void save(Guild guild, String identifier)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, guild.getName());
statement.setString(2, "" + plugin.userData.get(guild.getOwner()).getId());
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(3, members.size() == 0 ? null : StringUtils.join(members, ","));
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(4, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
statement.setString(5, guild.getTag());
statement.setInt(6, guild.getState().ordinal());
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(7, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
statement.setString(8, guild.getMotd());
statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
statement.setString(9, guild.getMotd());
Location home = guild.getHome();
statement.setDouble(9, home == null ? 0.0 : home.getX());
statement.setDouble(10, home == null ? 100.0 : home.getY());
statement.setDouble(11, home == null ? 0.0 : home.getZ());
statement.setInt(12, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
statement.setString(13, guild.getDefaultRank());
statement.setString(14, guild.getIdentifier());
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();
}
catch (SQLException ex)
@ -207,6 +208,11 @@ public class SQLGuildData
}
}
public void save(Guild guild)
{
save(guild, guild.getIdentifier());
}
public void delete(Guild guild)
{
try (Connection connection = plugin.sql.getConnection())

View file

@ -24,7 +24,7 @@ public class SQLRankData
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 `" + TABLE_NAME + "` 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 (?, ?, ?, ?);";