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:
parent
1b00b90df8
commit
d518b0b8a8
1
com/gamingmesh/jobs/.gitignore
vendored
1
com/gamingmesh/jobs/.gitignore
vendored
@ -10,3 +10,4 @@
|
|||||||
/PlayerManager$BoostOf.class
|
/PlayerManager$BoostOf.class
|
||||||
/PermissionManager.class
|
/PermissionManager.class
|
||||||
/PermissionManager$prm.class
|
/PermissionManager$prm.class
|
||||||
|
/PlayerManager$2.class
|
||||||
|
@ -35,6 +35,7 @@ import com.gamingmesh.jobs.container.JobConditions;
|
|||||||
import com.gamingmesh.jobs.container.JobPermission;
|
import com.gamingmesh.jobs.container.JobPermission;
|
||||||
import com.gamingmesh.jobs.container.JobProgression;
|
import com.gamingmesh.jobs.container.JobProgression;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
|
|
||||||
public class PermissionHandler {
|
public class PermissionHandler {
|
||||||
private Jobs plugin;
|
private Jobs plugin;
|
||||||
@ -45,6 +46,7 @@ public class PermissionHandler {
|
|||||||
|
|
||||||
public void recalculatePermissions(JobsPlayer jPlayer) {
|
public void recalculatePermissions(JobsPlayer jPlayer) {
|
||||||
|
|
||||||
|
// long time = System.nanoTime();
|
||||||
if (jPlayer == null)
|
if (jPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -63,7 +65,7 @@ public class PermissionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Permissions should only apply if we have permission to use jobs in this world
|
// 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();
|
List<JobProgression> progression = jPlayer.getJobProgression();
|
||||||
// calculate new permissions
|
// calculate new permissions
|
||||||
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
|
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
|
||||||
@ -250,6 +252,26 @@ public class PermissionHandler {
|
|||||||
return player.hasPermission("jobs.world." + world.toLowerCase());
|
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) {
|
public boolean hasWorldPermission(JobsPlayer player, String world) {
|
||||||
if (!Jobs.getPermissionManager().hasPermission(player, "jobs.use")) {
|
if (!Jobs.getPermissionManager().hasPermission(player, "jobs.use")) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -12,6 +12,7 @@ import com.gamingmesh.jobs.container.CurrencyType;
|
|||||||
import com.gamingmesh.jobs.container.Job;
|
import com.gamingmesh.jobs.container.Job;
|
||||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||||
import com.gamingmesh.jobs.stuff.ChatColor;
|
import com.gamingmesh.jobs.stuff.ChatColor;
|
||||||
|
import com.gamingmesh.jobs.stuff.Debug;
|
||||||
|
|
||||||
public class bonus implements Cmd {
|
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.topline"));
|
||||||
|
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.permission",
|
printBoost(sender, boost, BoostOf.Permission);
|
||||||
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.MONEY, true)),
|
printBoost(sender, boost, BoostOf.Item);
|
||||||
"%points%", ChatColor.GOLD.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.POINTS, true)),
|
printBoost(sender, boost, BoostOf.NearSpawner);
|
||||||
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.get(BoostOf.Permission, CurrencyType.EXP, true))));
|
printBoost(sender, boost, BoostOf.PetPay);
|
||||||
|
printBoost(sender, boost, BoostOf.Global);
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.item",
|
printBoost(sender, boost, BoostOf.Dynamic);
|
||||||
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.get(BoostOf.Item, CurrencyType.MONEY, true)),
|
printBoost(sender, boost, BoostOf.Area);
|
||||||
"%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))));
|
|
||||||
|
|
||||||
if (Jobs.getMcMMOlistener().mcMMOPresent && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D)
|
if (Jobs.getMcMMOlistener().mcMMOPresent && boost.get(BoostOf.McMMO, CurrencyType.EXP) != 0D)
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.mcmmo",
|
printBoost(sender, boost, BoostOf.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))));
|
|
||||||
|
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
|
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
|
||||||
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.final",
|
sender.sendMessage(Jobs.getLanguage().getMessage("command.bonus.output.final",
|
||||||
"%money%", ChatColor.DARK_GREEN.toString() + formatText(boost.getFinal(CurrencyType.MONEY, true)),
|
"%money%", mc + formatText(boost.getFinal(CurrencyType.MONEY, true)),
|
||||||
"%points%", ChatColor.GOLD.toString() + formatText(boost.getFinal(CurrencyType.POINTS, true)),
|
"%points%", pc + formatText(boost.getFinal(CurrencyType.POINTS, true)),
|
||||||
"%exp%", ChatColor.YELLOW.toString() + formatText(boost.getFinal(CurrencyType.EXP, true))));
|
"%exp%", ec + formatText(boost.getFinal(CurrencyType.EXP, true))));
|
||||||
|
|
||||||
return 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) {
|
private static String formatText(double amount) {
|
||||||
return ((amount > 0 ? "+" : "") + amount + "%");
|
return ((amount > 0 ? "+" : "") + amount + "%");
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ public class JobsListener implements Listener {
|
|||||||
Jobs.getGUIManager().GuiList.remove(player.getName());
|
Jobs.getGUIManager().GuiList.remove(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||||
|
|
||||||
// make sure plugin is enabled
|
// make sure plugin is enabled
|
||||||
|
@ -267,8 +267,16 @@ public class JobsPaymentListener implements Listener {
|
|||||||
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
|
if (player.getGameMode() == GameMode.CREATIVE && !Jobs.getGCManager().payInCreative())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
long time = System.nanoTime();
|
||||||
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
|
||||||
return;
|
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);
|
BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.BREAK);
|
||||||
FastPayment fp = Jobs.FastPayment.get(player.getName());
|
FastPayment fp = Jobs.FastPayment.get(player.getName());
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: Jobs
|
name: Jobs
|
||||||
description: Jobs Plugin for the BukkitAPI
|
description: Jobs Plugin for the BukkitAPI
|
||||||
main: com.gamingmesh.jobs.Jobs
|
main: com.gamingmesh.jobs.Jobs
|
||||||
version: 3.7.6
|
version: 3.7.7
|
||||||
author: phrstbrn
|
author: phrstbrn
|
||||||
softdepend: [Vault, iConomy, MythicMobs, McMMO]
|
softdepend: [Vault, iConomy, MythicMobs, McMMO]
|
||||||
commands:
|
commands:
|
||||||
|
Loading…
Reference in New Issue
Block a user