diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java index 101521b3a..bfc882199 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClient.java @@ -18,7 +18,7 @@ public class CoreClient private String _name; private UUID _uuid; private Player _player; - private PermissionGroup _primary, _lastPrimary; + private PermissionGroup _primary; private Set _extra = new HashSet<>(); /* @@ -114,15 +114,7 @@ public class CoreClient { return; } - if (_primary != null) - { - _lastPrimary = _primary; - } - else - { - _lastPrimary = group; - } - + _primary = group; } @@ -148,7 +140,6 @@ public class CoreClient { _disguisedName = null; _disguisedSkin = null; - _lastPrimary = _disguisedPrimary; _disguisedPrimary = null; _disguisedUUID = null; } @@ -187,14 +178,6 @@ public class CoreClient _disguisedName = name; _disguisedUUID = uuid; _disguisedPrimary = group; - if (_primary != null) - { - _lastPrimary = _primary; - } - else - { - _lastPrimary = group; - } } public PermissionGroup getRealOrDisguisedPrimaryGroup() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 531a8937b..01f8a72e1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -10,7 +10,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; @@ -36,8 +38,6 @@ import mineplex.core.MiniPlugin; import mineplex.core.account.command.RanksCommand; import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientWebResponseEvent; -import mineplex.core.account.event.OnlineGroupAddEvent; -import mineplex.core.account.event.OnlineGroupRemoveEvent; import mineplex.core.account.event.OnlinePrimaryGroupUpdateEvent; import mineplex.core.account.permissions.Permission; import mineplex.core.account.permissions.PermissionGroup; @@ -59,7 +59,6 @@ import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTasks; -import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.utils.UtilGameProfile; @@ -690,23 +689,7 @@ public class CoreClientManager extends MiniPlugin { _repository.setPrimaryGroup(accountId, group, after); } - - public void addAdditionalGroup(Player player, final PermissionGroup group, Consumer successCallback) - { - addAdditionalGroup(Get(player).getAccountId(), group, success -> - { - if (success) - { - Get(player).addAdditionalGroup(group); - UtilServer.CallEvent(new OnlineGroupAddEvent(player, group)); - } - if (successCallback != null) - { - successCallback.accept(success); - } - }); - } - + public void addAdditionalGroup(final int accountId, final PermissionGroup group, Consumer successCallback) { _repository.addAdditionalGroup(accountId, group, success -> @@ -717,23 +700,7 @@ public class CoreClientManager extends MiniPlugin } if (!success) { - System.out.println("Error adding additional group " + group.name() + " to account " + accountId + "!"); - } - }); - } - - public void removeAdditionalGroup(Player player, final PermissionGroup group, Consumer successCallback) - { - removeAdditionalGroup(Get(player).getAccountId(), group, success -> - { - if (success) - { - Get(player).removeAdditionalGroup(group); - UtilServer.CallEvent(new OnlineGroupRemoveEvent(player, group)); - } - if (successCallback != null) - { - successCallback.accept(success); + System.out.println("Error adding additional group " + group + " to account " + accountId + "!"); } }); } @@ -752,30 +719,7 @@ public class CoreClientManager extends MiniPlugin } }); } - - public void clearGroups(Player player, Consumer successCallback) - { - clearGroups(Get(player).getAccountId(), success -> - { - if (success) - { - PermissionGroup old = Get(player).getPrimaryGroup(); - Set cleared = Sets.newHashSet(Get(player).getAdditionalGroups()); - Get(player).setPrimaryGroup(PermissionGroup.PLAYER); - Get(player).getAdditionalGroups().clear(); - UtilServer.CallEvent(new OnlinePrimaryGroupUpdateEvent(player, old, PermissionGroup.PLAYER)); - for (PermissionGroup clr : cleared) - { - UtilServer.CallEvent(new OnlineGroupRemoveEvent(player, clr)); - } - } - if (successCallback != null) - { - successCallback.accept(success); - } - }); - } - + public void clearGroups(final int accountId, Consumer successCallback) { _repository.clearGroups(accountId, success -> @@ -795,42 +739,37 @@ public class CoreClientManager extends MiniPlugin { _repository.fetchGroups(accountId, (primaryGroup, additionalGroups) -> { - AtomicReference primaryReference = new AtomicReference<>(); - UUID uuid; - if (primaryGroup == null && (uuid = _repository.getClientUUID(accountId)) != null) + if (primaryGroup == null) { - runAsync(() -> - { - String legacy = loadOfflineClient(uuid).Rank; - PermissionGroup defaultGroup = PermissionGroup.PLAYER; - PermissionGroup loaded = PermissionGroupHelper.getGroupFromLegacy(legacy); - if (loaded == null) - { - primaryReference.compareAndSet(null, defaultGroup); - } - else - { - primaryReference.compareAndSet(null, loaded); - } - }); - long start = System.currentTimeMillis(); - while (primaryReference.get() == null && !UtilTime.elapsed(start, 5000)) {} - primaryReference.compareAndSet(null, PermissionGroup.PLAYER); + UtilServer.runSync(() -> resultCallback.accept(primaryGroup, additionalGroups)); + return; } - else + + UUID uuid; + if ((uuid = _repository.getClientUUID(accountId)) != null) { - PermissionGroup defaultGroup = PermissionGroup.PLAYER; - if (primaryGroup == null) + try { - primaryReference.set(defaultGroup); - } - else + PermissionGroup legacyPrimary = CompletableFuture.supplyAsync(() -> + { + String legacy = loadOfflineClient(uuid).Rank; + PermissionGroup defaultGroup = PermissionGroup.PLAYER; + PermissionGroup loaded = PermissionGroupHelper.getGroupFromLegacy(legacy); + + return loaded == null ? defaultGroup : loaded; + }).get(5, TimeUnit.SECONDS); + + UtilServer.runSync(() -> resultCallback.accept(legacyPrimary, additionalGroups)); + return; + + } catch (Exception e) { - primaryReference.set(primaryGroup); + System.out.println("Error fetching groups of account " + accountId + "!"); + e.printStackTrace(); } } - UtilServer.runSync(() -> resultCallback.accept(primaryReference.get(), additionalGroups)); + UtilServer.runSync(() -> resultCallback.accept(PermissionGroup.PLAYER, additionalGroups)); }, () -> { if (onError != null) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/command/ResetPlayerCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/account/command/ResetPlayerCommand.java index d11bf4153..f77107f66 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/command/ResetPlayerCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/command/ResetPlayerCommand.java @@ -50,7 +50,7 @@ public class ResetPlayerCommand extends CommandBase final CoreClient client = Plugin.Get(uuid); Plugin.clearGroups(client.getAccountId(), success -> { - if (success.booleanValue()) + if (success) { PermissionGroup old = client.getPrimaryGroup(); client.setPrimaryGroup(PermissionGroup.PLAYER); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/redis/ClearGroupsHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/account/redis/ClearGroupsHandler.java index 633cd4d01..fd2a571eb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/redis/ClearGroupsHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/redis/ClearGroupsHandler.java @@ -25,7 +25,7 @@ public class ClearGroupsHandler implements CommandCallback { _clientManager.runSync(() -> { - Optional opt = Bukkit.getOnlinePlayers().stream().map(Player.class::cast).filter(player -> _clientManager.getAccountId(player) == command.getAccountId()).findAny(); + Optional opt = Bukkit.getOnlinePlayers().stream().filter(player -> _clientManager.getAccountId(player) == command.getAccountId()).findAny(); if (opt.isPresent()) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 9493d762f..2b1e84881 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -96,33 +96,31 @@ public class AccountRepository extends MinecraftRepository { System.out.println(name + " Loaded Account ID From Cache [" + name + " - " + accountId + "]"); } - + + statement.execute("SELECT * FROM accountRanks WHERE accountId=" + accountId + ";"); + try (ResultSet rankSet = statement.getResultSet()) { - statement.execute("SELECT * FROM accountRanks WHERE accountId=" + accountId + ";"); - try (ResultSet rankSet = statement.getResultSet()) + boolean anyRows = false; + while (rankSet.next()) { - boolean anyRows = false; - while (rankSet.next()) + anyRows = true; + PermissionGroup group = PermissionGroup.valueOf(rankSet.getString("rankIdentifier")); + boolean primary = rankSet.getBoolean("primaryGroup"); + + if (primary) { - anyRows = true; - PermissionGroup group = PermissionGroup.valueOf(rankSet.getString("rankIdentifier")); - boolean primary = rankSet.getBoolean("primaryGroup"); - - if (primary) - { - primaryRank = group; - } - else - { - extraRanks.add(group); - } + primaryRank = group; } - - if (!anyRows) + else { - statement.execute(UPDATE_PRIMARY_RANK.replace("?", "" + accountId)); + extraRanks.add(group); } } + + if (!anyRows) + { + statement.execute(UPDATE_PRIMARY_RANK.replace("?", "" + accountId)); + } } final int finalId = accountId; @@ -399,7 +397,7 @@ public class AccountRepository extends MinecraftRepository Runnable r = () -> { AtomicBoolean errored = new AtomicBoolean(); - AtomicReference primary = new AtomicReference<>(); + AtomicReference primary = new AtomicReference<>(); Set additional = new HashSet<>(); executeQuery("SELECT * FROM accountRanks WHERE accountId=?;", rs -> @@ -408,7 +406,7 @@ public class AccountRepository extends MinecraftRepository { if (rs.getBoolean("primaryGroup")) { - primary.set(rs.getString("rankIdentifier")); + primary.set(PermissionGroup.valueOf(rs.getString("rankIdentifier"))); } else { @@ -428,7 +426,7 @@ public class AccountRepository extends MinecraftRepository { if (resultCallback != null) { - resultCallback.accept(PermissionGroup.valueOf(primary.get()), additional); + resultCallback.accept(primary.get(), additional); } } }; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AntihackLogger.java b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AntihackLogger.java index 3161efe73..bdc62aa9e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AntihackLogger.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/antihack/logging/AntihackLogger.java @@ -69,6 +69,7 @@ public class AntihackLogger extends MiniPlugin private void generatePermissions() { + PermissionGroup.ADMIN.setPermission(Perm.SAVE_METADATA_COMMAND, true, true); PermissionGroup.QA.setPermission(Perm.SAVE_METADATA_COMMAND, true, true); } diff --git a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/salesannouncements/SalesAnnouncementRepository.java b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/salesannouncements/SalesAnnouncementRepository.java index ea297e1b7..dfe9516af 100644 --- a/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/salesannouncements/SalesAnnouncementRepository.java +++ b/Plugins/Mineplex.Hub.Clans/src/mineplex/clanshub/salesannouncements/SalesAnnouncementRepository.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.account.permissions.PermissionGroupHelper; import mineplex.core.common.util.Callback; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; @@ -61,20 +62,20 @@ public class SalesAnnouncementRepository extends RepositoryBase { for (String rankStr : rankString.split(",")) { - PermissionGroup group = PermissionGroup.valueOf(rankStr); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankStr); ranks.add(group); } } else { - PermissionGroup group = PermissionGroup.valueOf(rankString); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankString); ranks.add(group); } PermissionGroup[] displayTo = ranks.toArray(new PermissionGroup[ranks.size()]); String message = resultSet.getString("message"); boolean enabled = resultSet.getBoolean("enabled"); - data.add(new SalesAnnouncementData(Integer.valueOf(id), displayTo, message, enabled)); + data.add(new SalesAnnouncementData(id, displayTo, message, enabled)); } runSync(() -> @@ -101,13 +102,13 @@ public class SalesAnnouncementRepository extends RepositoryBase { for (String rankStr : rankString.split(",")) { - PermissionGroup group = PermissionGroup.valueOf(rankStr); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankStr); ranks.add(group); } } else { - PermissionGroup group = PermissionGroup.valueOf(rankString); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankString); ranks.add(group); } PermissionGroup[] displayTo = ranks.toArray(new PermissionGroup[ranks.size()]); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/salesannouncements/SalesAnnouncementRepository.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/salesannouncements/SalesAnnouncementRepository.java index d66b024e2..f2fc92511 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/salesannouncements/SalesAnnouncementRepository.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/salesannouncements/SalesAnnouncementRepository.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.permissions.PermissionGroup; +import mineplex.core.account.permissions.PermissionGroupHelper; import mineplex.core.common.util.Callback; import mineplex.serverdata.database.DBPool; import mineplex.serverdata.database.RepositoryBase; @@ -61,20 +62,20 @@ public class SalesAnnouncementRepository extends RepositoryBase { for (String rankStr : rankString.split(",")) { - PermissionGroup group = PermissionGroup.valueOf(rankStr); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankStr); ranks.add(group); } } else { - PermissionGroup group = PermissionGroup.valueOf(rankString); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankString); ranks.add(group); } PermissionGroup[] displayTo = ranks.toArray(new PermissionGroup[ranks.size()]); String message = resultSet.getString("message"); boolean enabled = resultSet.getBoolean("enabled"); - data.add(new SalesAnnouncementData(Integer.valueOf(id), displayTo, message, enabled)); + data.add(new SalesAnnouncementData(id, displayTo, message, enabled)); } runSync(() -> @@ -101,20 +102,20 @@ public class SalesAnnouncementRepository extends RepositoryBase { for (String rankStr : rankString.split(",")) { - PermissionGroup group = PermissionGroup.valueOf(rankStr); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankStr); ranks.add(group); } } else { - PermissionGroup group = PermissionGroup.valueOf(rankString); + PermissionGroup group = PermissionGroupHelper.getGroupFromLegacy(rankString); ranks.add(group); } PermissionGroup[] displayTo = ranks.toArray(new PermissionGroup[ranks.size()]); String message = resultSet.getString("message"); boolean enabled = resultSet.getBoolean("enabled"); - final SalesAnnouncementData data = new SalesAnnouncementData(Integer.valueOf(aId), displayTo, message, enabled); + final SalesAnnouncementData data = new SalesAnnouncementData(aId, displayTo, message, enabled); runSync(() -> { callback.run(data);