Minor fixes

This commit is contained in:
Paldiu 2023-01-26 19:45:33 -06:00
parent 1054f5bd2f
commit f007e11530
3 changed files with 29 additions and 2 deletions

View File

@ -63,6 +63,8 @@ public class GroupCMD extends AbstractCommandBase {
RankManager manager = getPlugin().getRankManager();
OfflinePlayer player;
manager.unbake();
switch (target) {
case "player":
if (getPlugin().getServer().getPlayer(value) != null) {
@ -77,17 +79,25 @@ public class GroupCMD extends AbstractCommandBase {
if (actionType) {
manager.insertPlayer(rankContext.getContext(), player);
manager.bake();
manager.save();
return Component.text("Added player " + player.getName() + " to group " + group + "!").color(NamedTextColor.GREEN);
} else {
manager.ejectPlayer(rankContext.getContext(), player);
manager.bake();
manager.save();
return Component.text("Removed player " + player.getName() + " from group " + group + "!").color(NamedTextColor.GREEN);
}
case "permission":
if (actionType) {
manager.insertPermission(rankContext.getContext(), value);
manager.bake();
manager.save();
return Component.text("Added permission " + value + " to group " + group + "!").color(NamedTextColor.GREEN);
} else {
manager.ejectPermission(rankContext.getContext(), value);
manager.bake();
manager.save();
return Component.text("Removed permission " + value + " from group " + group + "!").color(NamedTextColor.GREEN);
}
default:

View File

@ -7,6 +7,7 @@ import mc.unraveled.reforged.plugin.Traverse;
import mc.unraveled.reforged.storage.DBGroup;
import mc.unraveled.reforged.util.Tuple;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -77,6 +78,22 @@ public class RankManager implements Baker, Locker {
.forEach(tuple -> tuple.getSecond().remove(player));
}
public void save() {
if (!baked) throw new IllegalStateException("You cannot save a rank manager that has not been baked!");
DBGroup groupHandler = new DBGroup(plugin.getSQLManager().establish());
bakedGroups.forEach(group -> {
for (OfflinePlayer p : group.getPlayers()) {
groupHandler.addPlayer(group.getRank(), p);
}
for (String arg : group.getPermissions()) {
groupHandler.addPermission(group.getRank(), arg);
}
});
groupHandler.close();
}
@Override
public void bake() {
if (baked) return;

View File

@ -56,14 +56,14 @@ public class DBGroup {
}
@SneakyThrows
public void addPlayer(Rank rank, Player player) {
public void addPlayer(Rank rank, OfflinePlayer player) {
PreparedStatement statement = getConnection().prepareStatement("INSERT INTO " + rank.getAttachment().getName() + " (uuid) VALUES (?);");
statement.setString(1, player.getUniqueId().toString());
statement.executeUpdate();
}
@SneakyThrows
public void removePlayer(Rank rank, Player player) {
public void removePlayer(Rank rank, OfflinePlayer player) {
PreparedStatement statement = getConnection().prepareStatement("DELETE FROM " + rank.getAttachment().getName() + " WHERE uuid = ?;");
statement.setString(1, player.getUniqueId().toString());
statement.executeUpdate();