1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-29 14:05:25 +01:00

We can use different method to get permissions on player login as its

slightly faster
This commit is contained in:
Zrips 2017-01-15 11:39:12 +02:00
parent 1b00b90df8
commit d518b0b8a8
6 changed files with 60 additions and 51 deletions

View File

@ -10,3 +10,4 @@
/PlayerManager$BoostOf.class
/PermissionManager.class
/PermissionManager$prm.class
/PlayerManager$2.class

View File

@ -35,6 +35,7 @@ import com.gamingmesh.jobs.container.JobConditions;
import com.gamingmesh.jobs.container.JobPermission;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;
public class PermissionHandler {
private Jobs plugin;
@ -45,6 +46,7 @@ public class PermissionHandler {
public void recalculatePermissions(JobsPlayer jPlayer) {
// long time = System.nanoTime();
if (jPlayer == null)
return;
@ -63,7 +65,7 @@ public class PermissionHandler {
}
// Permissions should only apply if we have permission to use jobs in this world
if (hasWorldPermission(player, player.getWorld().getName())) {
if (hasWorldPermission2(player, player.getWorld().getName())) {
List<JobProgression> progression = jPlayer.getJobProgression();
// calculate new permissions
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
@ -250,6 +252,26 @@ public class PermissionHandler {
return player.hasPermission("jobs.world." + world.toLowerCase());
}
public boolean hasWorldPermission2(Player player, String world) {
boolean foundMain = false;
boolean foundWorld = false;
for (PermissionAttachmentInfo one : player.getEffectivePermissions()) {
if (one.getPermission().equalsIgnoreCase("jobs.use")) {
foundMain = true;
if (foundWorld)
break;
}
if (one.getPermission().equalsIgnoreCase("jobs.world." + world.toLowerCase())) {
foundWorld = true;
if (foundMain)
break;
}
}
if (!foundMain || !foundWorld)
return false;
return true;
}
public boolean hasWorldPermission(JobsPlayer player, String world) {
if (!Jobs.getPermissionManager().hasPermission(player, "jobs.use")) {
return false;

View File

@ -12,6 +12,7 @@ import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
public class bonus implements Cmd {
@ -46,60 +47,37 @@ public class bonus implements Cmd {
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.topline"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.permission",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.item",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.EXP, true))));
if (!job.getJobInfo(ActionType.KILL).isEmpty() || !job.getJobInfo(ActionType.MMKILL).isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.nearspawner",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.NearSpawner, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.NearSpawner, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.NearSpawner, CurrencyType.EXP, true))));
}
if (!job.getJobInfo(ActionType.KILL).isEmpty() || !job.getJobInfo(ActionType.MMKILL).isEmpty()) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.petpay",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.PetPay, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.PetPay, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.PetPay, CurrencyType.EXP, true))));
}
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.global",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Global, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Global, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Global, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.dynamic",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Dynamic, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Dynamic, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Dynamic, CurrencyType.EXP, true))));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.area",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Area, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Area, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Area, CurrencyType.EXP, true))));
printBoost(sender, boost, BoostOf.Permission);
printBoost(sender, boost, BoostOf.Item);
printBoost(sender, boost, BoostOf.NearSpawner);
printBoost(sender, boost, BoostOf.PetPay);
printBoost(sender, boost, BoostOf.Global);
printBoost(sender, boost, BoostOf.Dynamic);
printBoost(sender, boost, BoostOf.Area);
if (Jobs.getMcMMOlistener().mcMMOPresent && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D)
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.mcmmo",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.McMMO, CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.McMMO, CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.McMMO, CurrencyType.EXP, true))));
printBoost(sender, boost, BoostOf.McMMO);
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.final",
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.getFinal(CurrencyType.MONEY, true)),
"%points%", ChatColor.GOLD.toString() + formatText(boost.getFinal(CurrencyType.POINTS, true)),
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.getFinal(CurrencyType.EXP, true))));
"%money%", mc + formatText(boost.getFinal(CurrencyType.MONEY, true)),
"%points%", pc + formatText(boost.getFinal(CurrencyType.POINTS, true)),
"%exp%", ec + formatText(boost.getFinal(CurrencyType.EXP, true))));
return true;
}
String mc = ChatColor.DARK_GREEN.toString();
String pc = ChatColor.GOLD.toString();
String ec = ChatColor.YELLOW.toString();
private void printBoost(CommandSender sender, Boost boost, BoostOf type) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output." + type.name().toLowerCase(),
"%money%", mc + formatText(boost.get(type, CurrencyType.MONEY, true)),
"%points%", pc + formatText(boost.get(type, CurrencyType.POINTS, true)),
"%exp%", ec + formatText(boost.get(type, CurrencyType.EXP, true))));
}
private static String formatText(double amount) {
return ((amount > 0 ? "+" : "") + amount + "%");
}

View File

@ -162,7 +162,7 @@ public class JobsListener implements Listener {
Jobs.getGUIManager().GuiList.remove(player.getName());
}
@EventHandler(priority = EventPriority.MONITOR)
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(final PlayerJoinEvent event) {
// make sure plugin is enabled

View File

@ -267,8 +267,16 @@ public class JobsPaymentListener implements Listener {
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
return;
long time = System.nanoTime();
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return;
Debug.D("time in " + (System.nanoTime() - time));
time = System.nanoTime();
if (!Jobs.getPermissionHandler().hasWorldPermission2(player, player.getLocation().getWorld().getName()))
return;
Debug.D("time in " + (System.nanoTime() - time));
BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.BREAK);
FastPayment fp = Jobs.FastPayment.get(player.getName());

View File

@ -1,7 +1,7 @@
name: Jobs
description: Jobs Plugin for the BukkitAPI
main: com.gamingmesh.jobs.Jobs
version: 3.7.6
version: 3.7.7
author: phrstbrn
softdepend: [Vault, iConomy, MythicMobs, McMMO]
commands: