mirror of
https://github.com/SimplexDevelopment/Traverse.git
synced 2024-12-22 13:57:37 +00:00
Minor fixes
This commit is contained in:
parent
1054f5bd2f
commit
f007e11530
@ -63,6 +63,8 @@ public class GroupCMD extends AbstractCommandBase {
|
|||||||
RankManager manager = getPlugin().getRankManager();
|
RankManager manager = getPlugin().getRankManager();
|
||||||
OfflinePlayer player;
|
OfflinePlayer player;
|
||||||
|
|
||||||
|
manager.unbake();
|
||||||
|
|
||||||
switch (target) {
|
switch (target) {
|
||||||
case "player":
|
case "player":
|
||||||
if (getPlugin().getServer().getPlayer(value) != null) {
|
if (getPlugin().getServer().getPlayer(value) != null) {
|
||||||
@ -77,17 +79,25 @@ public class GroupCMD extends AbstractCommandBase {
|
|||||||
|
|
||||||
if (actionType) {
|
if (actionType) {
|
||||||
manager.insertPlayer(rankContext.getContext(), player);
|
manager.insertPlayer(rankContext.getContext(), player);
|
||||||
|
manager.bake();
|
||||||
|
manager.save();
|
||||||
return Component.text("Added player " + player.getName() + " to group " + group + "!").color(NamedTextColor.GREEN);
|
return Component.text("Added player " + player.getName() + " to group " + group + "!").color(NamedTextColor.GREEN);
|
||||||
} else {
|
} else {
|
||||||
manager.ejectPlayer(rankContext.getContext(), player);
|
manager.ejectPlayer(rankContext.getContext(), player);
|
||||||
|
manager.bake();
|
||||||
|
manager.save();
|
||||||
return Component.text("Removed player " + player.getName() + " from group " + group + "!").color(NamedTextColor.GREEN);
|
return Component.text("Removed player " + player.getName() + " from group " + group + "!").color(NamedTextColor.GREEN);
|
||||||
}
|
}
|
||||||
case "permission":
|
case "permission":
|
||||||
if (actionType) {
|
if (actionType) {
|
||||||
manager.insertPermission(rankContext.getContext(), value);
|
manager.insertPermission(rankContext.getContext(), value);
|
||||||
|
manager.bake();
|
||||||
|
manager.save();
|
||||||
return Component.text("Added permission " + value + " to group " + group + "!").color(NamedTextColor.GREEN);
|
return Component.text("Added permission " + value + " to group " + group + "!").color(NamedTextColor.GREEN);
|
||||||
} else {
|
} else {
|
||||||
manager.ejectPermission(rankContext.getContext(), value);
|
manager.ejectPermission(rankContext.getContext(), value);
|
||||||
|
manager.bake();
|
||||||
|
manager.save();
|
||||||
return Component.text("Removed permission " + value + " from group " + group + "!").color(NamedTextColor.GREEN);
|
return Component.text("Removed permission " + value + " from group " + group + "!").color(NamedTextColor.GREEN);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -7,6 +7,7 @@ import mc.unraveled.reforged.plugin.Traverse;
|
|||||||
import mc.unraveled.reforged.storage.DBGroup;
|
import mc.unraveled.reforged.storage.DBGroup;
|
||||||
import mc.unraveled.reforged.util.Tuple;
|
import mc.unraveled.reforged.util.Tuple;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -77,6 +78,22 @@ public class RankManager implements Baker, Locker {
|
|||||||
.forEach(tuple -> tuple.getSecond().remove(player));
|
.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
|
@Override
|
||||||
public void bake() {
|
public void bake() {
|
||||||
if (baked) return;
|
if (baked) return;
|
||||||
|
@ -56,14 +56,14 @@ public class DBGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@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 (?);");
|
PreparedStatement statement = getConnection().prepareStatement("INSERT INTO " + rank.getAttachment().getName() + " (uuid) VALUES (?);");
|
||||||
statement.setString(1, player.getUniqueId().toString());
|
statement.setString(1, player.getUniqueId().toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@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 = ?;");
|
PreparedStatement statement = getConnection().prepareStatement("DELETE FROM " + rank.getAttachment().getName() + " WHERE uuid = ?;");
|
||||||
statement.setString(1, player.getUniqueId().toString());
|
statement.setString(1, player.getUniqueId().toString());
|
||||||
statement.executeUpdate();
|
statement.executeUpdate();
|
||||||
|
Loading…
Reference in New Issue
Block a user