From 6566c7f305c4cbf43e950a5a8741b8fdc6acd4eb Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Fri, 7 Apr 2023 16:22:43 -0500 Subject: [PATCH] Fixed some dumb shit --- .../command/Command_mbconfig.java | 40 ++++++------------- .../totalfreedommod/perms/UserWrapper.java | 17 ++++---- .../totalfreedommod/rank/Hierarchy.java | 19 ++++----- 3 files changed, 31 insertions(+), 45 deletions(-) diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java index f7125ee3..2e3b9fa4 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java @@ -1,13 +1,11 @@ package me.totalfreedom.totalfreedommod.command; -import com.earth2me.essentials.commands.PlayerNotFoundException; import me.totalfreedom.totalfreedommod.player.PlayerData; import me.totalfreedom.totalfreedommod.rank.GroupProvider; import me.totalfreedom.totalfreedommod.rank.Hierarchy; import me.totalfreedom.totalfreedommod.util.FUtil; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; -import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -148,34 +146,22 @@ public class Command_mbconfig extends FreedomCommand return noPerms(); } - try + Player player = getPlayer(args[1]); + PlayerData data = plugin.pl.getData(args[1]); + + if (player == null || data == null || !data.isMasterBuilder()) { - OfflinePlayer player = getOfflinePlayer(args[1]); - PlayerData data = plugin.pl.getData(args[1]); - - if (data == null || !data.isMasterBuilder()) - { - msgNew("Master Builder not found: ", arg(args[1])); - return true; - } - - FUtil.adminAction(sender.getName(), "Removing " + data.getName() + " from the Master Builder list", true); - Hierarchy.getHierarchy().dropUserFromAll(Hierarchy.getHierarchy().builder(), player); - data.setMasterBuilder(false); - plugin.pl.save(data); - - if (player.isOnline()) - { - // This is not null because the player is online, so we can safely call this method. - plugin.rm.updateDisplay(player.getPlayer()); - } - - return true; - } catch (PlayerNotFoundException e) - { - msgNew("Player not found: ", arg(args[1])); + msgNew("Master Builder not found: ", arg(args[1])); return true; } + + FUtil.adminAction(sender.getName(), "Removing " + data.getName() + " from the Master Builder list", true); + Hierarchy.getHierarchy().dropUserFromAll(Hierarchy.getHierarchy().builder(), player); + data.setMasterBuilder(false); + plugin.pl.save(data); + plugin.rm.updateDisplay(player); + + return true; } default: { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java index b4cf794d..9495dd89 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/perms/UserWrapper.java @@ -7,7 +7,6 @@ import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.UserManager; import net.luckperms.api.platform.PlayerAdapter; import net.luckperms.api.query.QueryOptions; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import java.util.HashSet; @@ -17,11 +16,11 @@ import java.util.concurrent.CompletableFuture; public class UserWrapper { private final UserManager manager; - private final PlayerAdapter playerAdapter; + private final PlayerAdapter playerAdapter; private final Set userSet; private final Set userDataSet; - public UserWrapper(UserManager manager, PlayerAdapter adapter) + public UserWrapper(UserManager manager, PlayerAdapter adapter) { this.manager = manager; this.userSet = manager.getLoadedUsers(); @@ -29,7 +28,7 @@ public class UserWrapper this.userDataSet = new HashSet<>(); } - public CompletableFuture addUserData(OfflinePlayer player) + public CompletableFuture addUserData(Player player) { User user = playerAdapter.getUser(player); CachedPermissionData permissionData = playerAdapter.getPermissionData(player); @@ -41,7 +40,7 @@ public class UserWrapper return CompletableFuture.runAsync(() -> userDataSet.add(userData)); } - public CompletableFuture getUser(OfflinePlayer player) + public CompletableFuture getUser(Player player) { if (!manager.isLoaded(player.getUniqueId()) || !userSet.contains(manager.getUser(player.getUniqueId()))) { @@ -51,7 +50,7 @@ public class UserWrapper return CompletableFuture.supplyAsync(() -> manager.getUser(player.getUniqueId())); } - public CompletableFuture removeUser(OfflinePlayer player) + public CompletableFuture removeUser(Player player) { return getUser(player).thenAccept(a -> { @@ -60,7 +59,7 @@ public class UserWrapper }); } - public CompletableFuture getUserData(OfflinePlayer player) + public CompletableFuture getUserData(Player player) { return getUser(player).thenApply(user -> { @@ -75,12 +74,12 @@ public class UserWrapper }); } - public CompletableFuture removeUserData(OfflinePlayer player) + public CompletableFuture removeUserData(Player player) { return getUserData(player).thenAccept(userDataSet::remove); } - public CompletableFuture updateUserData(OfflinePlayer player) + public CompletableFuture updateUserData(Player player) { return getUserData(player).thenApply(userData -> { diff --git a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java index 9ddc0c37..35564afc 100644 --- a/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java +++ b/commons/src/main/java/me/totalfreedom/totalfreedommod/rank/Hierarchy.java @@ -12,7 +12,7 @@ import net.luckperms.api.node.types.InheritanceNode; import net.luckperms.api.track.DemotionResult; import net.luckperms.api.track.PromotionResult; import net.luckperms.api.track.Track; -import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; @@ -29,7 +29,7 @@ public class Hierarchy this.groupWrapper = new GroupWrapper(TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager()); this.trackWrapper = new TrackWrapper(TotalFreedomMod.getPlugin().lpb.getAPI().getTrackManager()); this.userWrapper = new UserWrapper(TotalFreedomMod.getPlugin().lpb.getAPI().getUserManager(), - TotalFreedomMod.getPlugin().lpb.getAPI().getPlayerAdapter(OfflinePlayer.class)); + TotalFreedomMod.getPlugin().lpb.getAPI().getPlayerAdapter(Player.class)); } public static Hierarchy getHierarchy() @@ -37,7 +37,7 @@ public class Hierarchy return hierarchy; } - public boolean isUserOnAdminTrack(OfflinePlayer player) + public boolean isUserOnAdminTrack(Player player) { AtomicBoolean isOnAdminTrack = new AtomicBoolean(false); userWrapper.getUser(player).thenAccept(user -> @@ -95,7 +95,8 @@ public class Hierarchy }); } - public Group getGroup(String name) { + public Group getGroup(String name) + { return groupWrapper.getGroup(name).join(); } @@ -114,19 +115,19 @@ public class Hierarchy }); } - public CompletableFuture promoteUser(Track track, OfflinePlayer player) + public CompletableFuture promoteUser(Track track, Player player) { return userWrapper.getUserData(player).thenApply(data -> track.promote(data.getUser(), data.getContextSet())); } - public CompletableFuture demoteUser(Track track, OfflinePlayer player) + public CompletableFuture demoteUser(Track track, Player player) { return userWrapper.getUserData(player).thenApply(data -> - track.demote(data.getUser(), data.getContextSet())); + track.demote(data.getUser(), data.getContextSet())); } - public void addUserToGroup(DisplayableGroup group, OfflinePlayer player) + public void addUserToGroup(DisplayableGroup group, Player player) { userWrapper.getUserData(player).thenAccept(user -> { @@ -147,7 +148,7 @@ public class Hierarchy }); } - public void dropUserFromAll(Track track, OfflinePlayer player) + public void dropUserFromAll(Track track, Player player) { userWrapper.getUserData(player).thenAccept(data -> {