diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java index 6eaab9cd..5a70aa0d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java @@ -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 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 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) { @@ -67,11 +74,11 @@ public class gtop implements Cmd { break; Language.sendMessage(sender, "command.gtop.output.list", - "%number%", pi.getPositionForOutput(i), - "%playername%", One.getPlayerInfo().getName(), - "%playerdisplayname%", One.getPlayerInfo().getDisplayName(), - "%level%", One.getLevel(), - "%exp%", One.getExp()); + "%number%", pi.getPositionForOutput(i), + "%playername%", One.getPlayerInfo().getName(), + "%playerdisplayname%", One.getPlayerInfo().getDisplayName(), + "%level%", One.getLevel(), + "%exp%", One.getExp()); ++i; } } else { @@ -82,10 +89,10 @@ public class gtop implements Cmd { break; ls.add(Jobs.getLanguage().getMessage("scoreboard.line", - "%number%", pi.getPositionForOutput(i), - "%playername%", one.getPlayerInfo().getName(), - "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), - "%level%", one.getLevel())); + "%number%", pi.getPositionForOutput(i), + "%playername%", one.getPlayerInfo().getName(), + "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), + "%level%", one.getLevel())); ++i; } @@ -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" + ); } } diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/top.java b/src/main/java/com/gamingmesh/jobs/commands/list/top.java index 09dc77b5..d2f7abcd 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/top.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/top.java @@ -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 fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart()) + .stream().filter(topList -> hasToBeSeenInTop(topList, job)).collect(Collectors.toList()); - List fullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart()); if (fullList.isEmpty()) { CMIMessages.sendMessage(sender, LC.info_NoInformation); - return true; + return; } int place = 1; @@ -69,15 +78,16 @@ 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; Language.sendMessage(sender, "command.top.output.list", - "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, - "%playername%", one.getPlayerInfo().getName(), - "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), - "%level%", one.getLevel(), - "%exp%", one.getExp()); + "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, + "%playername%", one.getPlayerInfo().getName(), + "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), + "%level%", one.getLevel(), + "%exp%", one.getExp()); place++; } pi.autoPagination(sender, "jobs top " + job.getName()); @@ -88,7 +98,7 @@ public class top implements Cmd { if (place > Jobs.getGCManager().JobsTopAmount) break; ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", ((page - 1) * Jobs.getGCManager().JobsTopAmount) + place, - "%playername%", one.getPlayerInfo().getName(), "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), "%level%", one.getLevel())); + "%playername%", one.getPlayerInfo().getName(), "%playerdisplayname%", one.getPlayerInfo().getDisplayName(), "%level%", one.getLevel())); place++; } @@ -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())); + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b3c422a8..4c90794d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -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