mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 15:03:36 +01:00
feat(tops): add possibility to be hidder from tops
To do that, the part of the command 'top' and 'gtop' has been moved into an asynchronous thread because of 'unsafe Vault lookups from LuckPerms'. If it enable, LP prevent a plugin to check a perm of an online player on the main thread. Two new nodes perms have been added : - `jobs.hidetop.<job>`: to be hidden from a specific job top (replace <job> by * to be hidden from all). - `jobs.hidegtop`: to be hidden from the jobs global top.
This commit is contained in:
parent
96cfcf78e9
commit
72f745aeb3
@ -1,21 +1,21 @@
|
||||
package com.gamingmesh.jobs.commands.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.commands.Cmd;
|
||||
import com.gamingmesh.jobs.container.TopList;
|
||||
import com.gamingmesh.jobs.i18n.Language;
|
||||
|
||||
import net.Zrips.CMILib.Container.PageInfo;
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.Scoreboards.CMIScoreboard;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class gtop implements Cmd {
|
||||
|
||||
@ -52,10 +52,17 @@ public class gtop implements Cmd {
|
||||
int amount = Jobs.getGCManager().JobsTopAmount;
|
||||
PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page);
|
||||
|
||||
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () -> showGlobalTop(sender, pi, amount));
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void showGlobalTop(CommandSender sender, PageInfo pi, int amount) {
|
||||
Player player = (Player) sender;
|
||||
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart())
|
||||
.stream().filter(gtop::hasToBeSeenInGlobalTop).collect(Collectors.toList());
|
||||
if (FullList.isEmpty()) {
|
||||
Language.sendMessage(sender, "command.gtop.error.nojob");
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
|
||||
@ -93,6 +100,16 @@ public class gtop implements Cmd {
|
||||
}
|
||||
|
||||
pi.autoPagination(sender, "jobs gtop");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean hasToBeSeenInGlobalTop(TopList topList) {
|
||||
Player player = topList.getPlayerInfo().getJobsPlayer().getPlayer();
|
||||
if (player != null)
|
||||
return !player.hasPermission("jobs.hidegtop");
|
||||
return !Jobs.getVaultPermission().playerHas(
|
||||
null,
|
||||
Bukkit.getOfflinePlayer(topList.getPlayerInfo().getUuid()),
|
||||
"jobs.hidegtop"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
package com.gamingmesh.jobs.commands.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.commands.Cmd;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.TopList;
|
||||
import com.gamingmesh.jobs.i18n.Language;
|
||||
|
||||
import net.Zrips.CMILib.Container.PageInfo;
|
||||
import net.Zrips.CMILib.Locale.LC;
|
||||
import net.Zrips.CMILib.Messages.CMIMessages;
|
||||
import net.Zrips.CMILib.Scoreboards.CMIScoreboard;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class top implements Cmd {
|
||||
|
||||
@ -56,11 +57,19 @@ public class top implements Cmd {
|
||||
|
||||
int workingIn = Jobs.getUsedSlots(job);
|
||||
PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page);
|
||||
final int finalPage = page;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Jobs.getInstance(), () ->showTop(sender, job, pi, finalPage) );
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void showTop(CommandSender sender, Job job, PageInfo pi, int page) {
|
||||
Player player = (Player) sender;
|
||||
List<TopList> fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart())
|
||||
.stream().filter(topList -> hasToBeSeenInTop(topList, job)).collect(Collectors.toList());
|
||||
|
||||
List<TopList> fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart());
|
||||
if (fullList.isEmpty()) {
|
||||
CMIMessages.sendMessage(sender, LC.info_NoInformation);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
int place = 1;
|
||||
@ -69,6 +78,7 @@ public class top implements Cmd {
|
||||
Language.sendMessage(sender, "command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount);
|
||||
|
||||
for (TopList one : fullList) {
|
||||
System.out.println(one.getPlayerInfo().getName());
|
||||
if (place > Jobs.getGCManager().JobsTopAmount)
|
||||
break;
|
||||
|
||||
@ -96,6 +106,16 @@ public class top implements Cmd {
|
||||
|
||||
pi.autoPagination(sender, "jobs top " + job.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean hasToBeSeenInTop(TopList topList, Job job) {
|
||||
Player player = topList.getPlayerInfo().getJobsPlayer().getPlayer();
|
||||
if (player != null)
|
||||
return !player.hasPermission("jobs.hidetop.*") || !player.hasPermission("jobs.hidetop." + job.getName().toLowerCase());
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(topList.getPlayerInfo().getUuid());
|
||||
return !
|
||||
(Jobs.getVaultPermission().playerHas(null, offlinePlayer, "jobs.hidetop.*")
|
||||
|| Jobs.getVaultPermission().playerHas(null, offlinePlayer, "jobs.hidetop." + job.getName().toLowerCase()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -232,3 +232,9 @@ permissions:
|
||||
jobs.area.remove:
|
||||
description: Grants access to the area remove command
|
||||
default: op
|
||||
jobs.hidetop.*:
|
||||
description: Prevent player to be shown in all job top
|
||||
default: false
|
||||
jobs.hidegtop:
|
||||
description: Prevent player to be shown in the global jobs top
|
||||
default: false
|
||||
|
Loading…
Reference in New Issue
Block a user