mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
More fixes
This commit is contained in:
parent
198f1d3acf
commit
3dde5ef578
@ -48,7 +48,7 @@ public class Command_deop extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.wasSuccessful()) {
|
||||
if (result == null || !result.wasSuccessful()) {
|
||||
msgNew("<red><player> is already non-op.", Placeholder.unparsed("player", player.getName()));
|
||||
return;
|
||||
}
|
||||
@ -60,6 +60,7 @@ public class Command_deop extends FreedomCommand
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "De-opping " + player.getName(), false);
|
||||
}
|
||||
Hierarchy.getHierarchy().updateUserData(player);
|
||||
});
|
||||
|
||||
return true;
|
||||
|
@ -29,13 +29,14 @@ public class Command_deopall extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.wasSuccessful()) {
|
||||
if (result == null || !result.wasSuccessful()) {
|
||||
msgNew("<red><player> is already non-OP.", Placeholder.unparsed("player", player.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_NOT_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
Hierarchy.getHierarchy().updateUserData(player);
|
||||
}));
|
||||
|
||||
return true;
|
||||
|
@ -48,13 +48,18 @@ public class Command_op extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.wasSuccessful())
|
||||
if (result == null) {
|
||||
msgNew("<red><player> was not on the track! Added.", player(player));
|
||||
}
|
||||
else if (!result.wasSuccessful())
|
||||
{
|
||||
msgNew("<red><player> is already OP!", player(player));
|
||||
return;
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
Hierarchy.getHierarchy().updateUserData(player);
|
||||
if (!atomicBoolean.get())
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false);
|
||||
|
@ -17,7 +17,7 @@ public class Command_opall extends FreedomCommand
|
||||
FUtil.adminAction(sender.getName(), "Opping all players on the server", true);
|
||||
|
||||
server.getOnlinePlayers().forEach(player ->
|
||||
Hierarchy.getHierarchy().promoteUser(Hierarchy.getHierarchy().op(), player).whenComplete((ignored, throwable) ->
|
||||
Hierarchy.getHierarchy().promoteUser(Hierarchy.getHierarchy().op(), player).whenComplete((result, throwable) ->
|
||||
{
|
||||
if (throwable != null)
|
||||
{
|
||||
@ -27,8 +27,16 @@ public class Command_opall extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
msgNew("<red><player> was not present on the track! Added.", player(player));
|
||||
} else if (!result.wasSuccessful()) {
|
||||
msgNew("<red>Player is already OP!", player(player));
|
||||
return;
|
||||
}
|
||||
|
||||
msg(player, YOU_ARE_OP);
|
||||
plugin.rm.updateDisplay(player);
|
||||
Hierarchy.getHierarchy().updateUserData(player);
|
||||
}));
|
||||
|
||||
return true;
|
||||
|
@ -24,8 +24,14 @@ public class Command_opme extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (result != null && !result.wasSuccessful()) {
|
||||
msgNew("<red>You are already op!");
|
||||
return;
|
||||
}
|
||||
|
||||
msg(YOU_ARE_OP);
|
||||
plugin.rm.updateDisplay(playerSender);
|
||||
Hierarchy.getHierarchy().updateUserData(playerSender);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -90,12 +90,14 @@ public class Command_saconfig extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.wasSuccessful() || result.getGroupTo().isEmpty())
|
||||
if (result == null) {
|
||||
msgNew("<green>Added <player> to the ADMIN group.", player(player));
|
||||
}
|
||||
else if (!result.wasSuccessful() || result.getGroupTo().isEmpty())
|
||||
{
|
||||
msgNew("<red>Failed to promote <player> to the next rank.", player(player));
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
result.getGroupTo().ifPresentOrElse(group ->
|
||||
{
|
||||
Admin admin = plugin.al.getAdmin(player);
|
||||
@ -138,10 +140,13 @@ public class Command_saconfig extends FreedomCommand
|
||||
msgNew(player, "You have been unfrozen.");
|
||||
}
|
||||
|
||||
Hierarchy.getHierarchy().updateUserData(player);
|
||||
|
||||
msgNew("<gold>Admin <player> has been promoted to <rank>",
|
||||
player(player),
|
||||
Placeholder.unparsed("rank", group));
|
||||
}, () -> msgNew("<red>Failed to promote <player> to the next rank.", player(player)));
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
@ -168,7 +173,7 @@ public class Command_saconfig extends FreedomCommand
|
||||
|
||||
if (admin == null)
|
||||
{
|
||||
msgNew("Unknown admin: <player>", Placeholder.unparsed("player", args[1]));
|
||||
msgNew("Unknown admin: <arg>", arg(args[1]));
|
||||
return true;
|
||||
} else
|
||||
{
|
||||
@ -207,7 +212,7 @@ public class Command_saconfig extends FreedomCommand
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.wasSuccessful() || result.getGroupTo().isEmpty())
|
||||
if (result == null || !result.wasSuccessful() || result.getGroupTo().isEmpty())
|
||||
{
|
||||
msgNew("<red>Failed to demote <player> to the next rank.", player(player));
|
||||
return;
|
||||
@ -253,6 +258,8 @@ public class Command_saconfig extends FreedomCommand
|
||||
msgNew(player, "You have been unfrozen.");
|
||||
}
|
||||
|
||||
Hierarchy.getHierarchy().updateUserData(player);
|
||||
|
||||
msgNew("<gold>Admin <player> has been demoted to <rank>",
|
||||
Placeholder.unparsed("player", player.getName()),
|
||||
Placeholder.unparsed("rank", group));
|
||||
|
@ -17,13 +17,11 @@ public class UserWrapper
|
||||
{
|
||||
private final UserManager manager;
|
||||
private final PlayerAdapter<Player> playerAdapter;
|
||||
private final Set<User> userSet;
|
||||
private final Set<UserData> userDataSet;
|
||||
|
||||
public UserWrapper(UserManager manager, PlayerAdapter<Player> adapter)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.userSet = manager.getLoadedUsers();
|
||||
this.playerAdapter = adapter;
|
||||
this.userDataSet = new HashSet<>();
|
||||
}
|
||||
@ -42,7 +40,7 @@ public class UserWrapper
|
||||
|
||||
public CompletableFuture<User> getUser(Player player)
|
||||
{
|
||||
if (!manager.isLoaded(player.getUniqueId()) || !userSet.contains(manager.getUser(player.getUniqueId())))
|
||||
if (!manager.isLoaded(player.getUniqueId()) || !manager.getLoadedUsers().contains(manager.getUser(player.getUniqueId())))
|
||||
{
|
||||
return manager.loadUser(player.getUniqueId());
|
||||
}
|
||||
@ -50,15 +48,6 @@ public class UserWrapper
|
||||
return CompletableFuture.supplyAsync(() -> manager.getUser(player.getUniqueId()));
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> removeUser(Player player)
|
||||
{
|
||||
return getUser(player).thenAccept(a ->
|
||||
{
|
||||
manager.cleanupUser(a);
|
||||
userSet.remove(a);
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<UserData> getUserData(Player player)
|
||||
{
|
||||
return getUser(player).thenApply(user ->
|
||||
|
@ -7,8 +7,6 @@ import me.totalfreedom.totalfreedommod.util.FConverter;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -115,16 +115,87 @@ public class Hierarchy
|
||||
});
|
||||
}
|
||||
|
||||
public void addUserData(Player player) {
|
||||
userWrapper.addUserData(player).whenComplete((a, b) ->
|
||||
{
|
||||
if (b != null)
|
||||
{
|
||||
FLog.severe(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void updateUserData(Player player) {
|
||||
userWrapper.updateUserData(player).whenComplete((a, b) ->
|
||||
{
|
||||
if (b != null)
|
||||
{
|
||||
FLog.severe(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void dropUserData(Player player) {
|
||||
userWrapper.removeUserData(player).whenComplete((a, b) ->
|
||||
{
|
||||
if (b != null)
|
||||
{
|
||||
FLog.severe(b);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<PromotionResult> promoteUser(Track track, Player player)
|
||||
{
|
||||
return userWrapper.getUserData(player).thenApply(data ->
|
||||
track.promote(data.getUser(), data.getContextSet()));
|
||||
{
|
||||
boolean isOnTrack = false;
|
||||
for (String trackGroup : track.getGroups())
|
||||
{
|
||||
for (Group userGroup : data.getUser().getInheritedGroups(data.getQueryOptions()))
|
||||
{
|
||||
if (userGroup.getName().equals(trackGroup))
|
||||
{
|
||||
isOnTrack = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isOnTrack)
|
||||
{
|
||||
return track.promote(data.getUser(), data.getContextSet());
|
||||
} else
|
||||
{
|
||||
addUserToGroup(GroupProvider.fromString(track.getGroups().get(0)).getGroup(), player);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CompletableFuture<DemotionResult> demoteUser(Track track, Player player)
|
||||
{
|
||||
return userWrapper.getUserData(player).thenApply(data ->
|
||||
track.demote(data.getUser(), data.getContextSet()));
|
||||
{
|
||||
boolean isOnTrack = false;
|
||||
for (String trackGroup : track.getGroups())
|
||||
{
|
||||
for (Group userGroup : data.getUser().getInheritedGroups(data.getQueryOptions()))
|
||||
{
|
||||
if (userGroup.getName().equals(trackGroup))
|
||||
{
|
||||
isOnTrack = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isOnTrack)
|
||||
{
|
||||
return track.demote(data.getUser(), data.getContextSet());
|
||||
} else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void addUserToGroup(DisplayableGroup group, Player player)
|
||||
@ -145,6 +216,8 @@ public class Hierarchy
|
||||
{
|
||||
FLog.severe(b);
|
||||
}
|
||||
|
||||
updateUserData(player);
|
||||
});
|
||||
}
|
||||
|
||||
@ -175,6 +248,8 @@ public class Hierarchy
|
||||
{
|
||||
FLog.severe(b);
|
||||
}
|
||||
|
||||
updateUserData(player);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
@ -187,10 +188,18 @@ public class RankManager extends FreedomService
|
||||
updatePlayerTeam(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
Hierarchy.getHierarchy().dropUserData(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
Hierarchy.getHierarchy().addUserData(player);
|
||||
|
||||
PlayerData target = plugin.pl.getData(player);
|
||||
|
||||
boolean isAdmin = plugin.al.isAdmin(player);
|
||||
|
Loading…
Reference in New Issue
Block a user