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

Fixing permissions

This commit is contained in:
Zrips 2023-01-05 18:14:50 +02:00
parent 2d71e67318
commit 2da51e65b1
8 changed files with 315 additions and 241 deletions

View File

@ -997,6 +997,8 @@ public final class Jobs extends JavaPlugin {
if (jPlayer == null)
return;
CMIDebug.d("action");
List<JobProgression> progression = jPlayer.getJobProgression();
int numjobs = progression.size();

View File

@ -38,88 +38,88 @@ public class PermissionManager {
private enum prm {
// jobs_join_JOBNAME(remade("jobs.join.%JOBNAME%"), 60 * 1000),
jobs_use(remade("jobs.use"), 2),
jobs_paycreative(remade("jobs.paycreative"), 2),
jobs_use(remade("jobs.use"), 2),
jobs_paycreative(remade("jobs.paycreative"), 2),
// jobs_boost_JOBNAME_money(remade("jobs.boost.%JOBNAME%.money"), 60 * 1000),
// jobs_boost_JOBNAME_exp(remade("jobs.boost.%JOBNAME%.exp"), 60 * 1000),
// jobs_boost_JOBNAME_points(remade("jobs.boost.%JOBNAME%.points"), 60 * 1000),
// jobs_boost_JOBNAME_all(remade("jobs.boost.%JOBNAME%.all"), 60 * 1000),
// jobs_leave_JOBNAME(remade("jobs.leave.%JOBNAME%"), 60 * 1000),
jobs_boost_JOBNAME_money_AMOUNT(remade("jobs.boost.%JOBNAME%.money.%AMOUNT%"), 60),
jobs_boost_JOBNAME_exp_AMOUNT(remade("jobs.boost.%JOBNAME%.exp.%AMOUNT%"), 60),
jobs_boost_JOBNAME_points_AMOUNT(remade("jobs.boost.%JOBNAME%.points.%AMOUNT%"), 60),
jobs_boost_JOBNAME_all_AMOUNT(remade("jobs.boost.%JOBNAME%.all.%AMOUNT%"), 60),
jobs_boost_all_money_AMOUNT(remade("jobs.boost.all.money.%AMOUNT%"), 60),
jobs_boost_all_exp_AMOUNT(remade("jobs.boost.all.exp.%AMOUNT%"), 60),
jobs_boost_all_points_AMOUNT(remade("jobs.boost.all.points.%AMOUNT%"), 60),
jobs_boost_all_all_AMOUNT(remade("jobs.boost.all.all.%AMOUNT%"), 60),
jobs_spawner_AMOUNT(remade("jobs.nearspawner.%AMOUNT%"), 60),
jobs_petpay_AMOUNT(remade("jobs.petpay.%AMOUNT%"), 60),
jobs_maxfurnaces_AMOUNT(remade("jobs.maxfurnaces.%AMOUNT%"), 2),
jobs_maxblastfurnaces_AMOUNT(remade("jobs.maxblastfurnaces.%AMOUNT%"), 2),
jobs_maxsmokers_AMOUNT(remade("jobs.maxsmokers.%AMOUNT%"), 2),
jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 2),
jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2);
jobs_boost_JOBNAME_money_AMOUNT(remade("jobs.boost.%JOBNAME%.money.%AMOUNT%"), 60),
jobs_boost_JOBNAME_exp_AMOUNT(remade("jobs.boost.%JOBNAME%.exp.%AMOUNT%"), 60),
jobs_boost_JOBNAME_points_AMOUNT(remade("jobs.boost.%JOBNAME%.points.%AMOUNT%"), 60),
jobs_boost_JOBNAME_all_AMOUNT(remade("jobs.boost.%JOBNAME%.all.%AMOUNT%"), 60),
jobs_boost_all_money_AMOUNT(remade("jobs.boost.all.money.%AMOUNT%"), 60),
jobs_boost_all_exp_AMOUNT(remade("jobs.boost.all.exp.%AMOUNT%"), 60),
jobs_boost_all_points_AMOUNT(remade("jobs.boost.all.points.%AMOUNT%"), 60),
jobs_boost_all_all_AMOUNT(remade("jobs.boost.all.all.%AMOUNT%"), 60),
jobs_spawner_AMOUNT(remade("jobs.nearspawner.%AMOUNT%"), 60),
jobs_petpay_AMOUNT(remade("jobs.petpay.%AMOUNT%"), 60),
jobs_maxfurnaces_AMOUNT(remade("jobs.maxfurnaces.%AMOUNT%"), 2),
jobs_maxblastfurnaces_AMOUNT(remade("jobs.maxblastfurnaces.%AMOUNT%"), 2),
jobs_maxsmokers_AMOUNT(remade("jobs.maxsmokers.%AMOUNT%"), 2),
jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 2),
jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2);
private int reload;
private List<String> perms;
private int reload;
private List<String> perms;
prm(List<String> perms, int reload) {
this.perms = perms;
this.reload = reload * 1000;
}
prm(List<String> perms, int reload) {
this.perms = perms;
this.reload = reload * 1000;
}
public int getDelay() {
return reload;
}
public int getDelay() {
return reload;
}
private static List<String> remade(String perm) {
List<String> perms = new ArrayList<>();
private static List<String> remade(String perm) {
List<String> perms = new ArrayList<>();
for (Job oneJ : Jobs.getJobs()) {
String t = perm;
for (Job oneJ : Jobs.getJobs()) {
String t = perm;
if (t.contains("%JOBNAME%"))
t = t.replace("%JOBNAME%", oneJ.getName().toLowerCase());
if (t.contains("%JOBNAME%"))
t = t.replace("%JOBNAME%", oneJ.getName().toLowerCase());
t = t.replace("%AMOUNT%", "");
t = t.replace("%AMOUNT%", "");
perms.add(t);
}
perms.add(t);
}
if (perm.contains("%WORLDNAME%"))
for (World oneJ : Bukkit.getWorlds()) {
perms.add(perm.replace("%WORLDNAME%", oneJ.getName().toLowerCase()));
}
if (perm.contains("%WORLDNAME%"))
for (World oneJ : Bukkit.getWorlds()) {
perms.add(perm.replace("%WORLDNAME%", oneJ.getName().toLowerCase()));
}
return perms;
}
return perms;
}
public List<String> getPerms() {
return perms;
}
public List<String> getPerms() {
return perms;
}
}
private int getDelay(String perm) {
return permDelay.getOrDefault(perm, 1);
return permDelay.getOrDefault(perm, 1);
}
public PermissionManager() {
for (prm one : prm.values()) {
for (String oneP : one.getPerms()) {
permDelay.put(oneP, one.getDelay());
}
}
for (prm one : prm.values()) {
for (String oneP : one.getPerms()) {
permDelay.put(oneP, one.getDelay());
}
}
}
private static Map<String, Boolean> getAll(Player player) {
Map<String, Boolean> mine = new HashMap<>();
for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) {
if (permission.getPermission().startsWith("jobs."))
mine.put(permission.getPermission(), permission.getValue());
}
private static Map<String, Boolean> getAll(Player player, String perm) {
Map<String, Boolean> mine = new HashMap<>();
for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) {
if (permission.getPermission().startsWith(perm))
mine.put(permission.getPermission(), permission.getValue());
}
return mine;
return mine;
}
/**
@ -131,7 +131,7 @@ public class PermissionManager {
* @return the max value
*/
public double getMaxPermission(JobsPlayer jPlayer, String perm) {
return getMaxPermission(jPlayer, perm, false, false);
return getMaxPermission(jPlayer, perm, false, false);
}
/**
@ -144,7 +144,7 @@ public class PermissionManager {
* @return the max value
*/
public double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
return getMaxPermission(jPlayer, perm, force, false);
return getMaxPermission(jPlayer, perm, force, false);
}
/**
@ -159,68 +159,68 @@ public class PermissionManager {
* @return the max value
*/
public double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force, boolean cumulative) {
if (jPlayer == null)
return 0D;
if (jPlayer == null)
return 0D;
Player player = jPlayer.getPlayer();
if (player == null)
return 0D;
Player player = jPlayer.getPlayer();
if (player == null)
return 0D;
perm = perm.toLowerCase();
if (!perm.endsWith("."))
perm += ".";
perm = perm.toLowerCase();
if (!perm.endsWith("."))
perm += ".";
Map<String, Boolean> permissions = jPlayer.getPermissionsCache();
if (force || permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
if (permissions == null) {
permissions = getAll(player);
} else {
permissions.clear();
permissions.putAll(getAll(player));
}
jPlayer.setPermissionsCache(permissions);
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
}
double amount = Double.NEGATIVE_INFINITY;
double amount = Double.NEGATIVE_INFINITY;
permissionInfo permInfo = jPlayer.getPermissionsCache(perm);
if (force || getDelay(perm) + permInfo.getTime() < System.currentTimeMillis()) {
for (Map.Entry<String, Boolean> permission : permissions.entrySet()) {
if (!permission.getKey().startsWith(perm) || !permission.getValue())
continue;
try {
double temp = Double.parseDouble(permission.getKey().replace(perm, ""));
if (cumulative)
amount += temp;
else if (temp > amount)
amount = temp;
} catch (NumberFormatException ex) {
Jobs.getPluginLogger().log(java.util.logging.Level.WARNING, ex.getLocalizedMessage());
}
}
Map<String, Boolean> perms = getAll(player, perm);
return amount == Double.NEGATIVE_INFINITY ? 0D : amount;
for (Map.Entry<String, Boolean> permission : perms.entrySet()) {
if (!permission.getKey().startsWith(perm) || !permission.getValue())
continue;
try {
double temp = Double.parseDouble(permission.getKey().replace(perm, ""));
if (cumulative)
amount += temp;
else if (temp > amount)
amount = temp;
} catch (NumberFormatException ex) {
Jobs.getPluginLogger().log(java.util.logging.Level.WARNING, ex.getLocalizedMessage());
}
}
permInfo.setTime(System.currentTimeMillis());
permInfo.setValue(amount == Double.NEGATIVE_INFINITY ? 0D : amount);
jPlayer.addToPermissionsCache(perm, permInfo);
}
CMIDebug.d("Max: ", permInfo.getValue());
return permInfo.getValue();
}
public boolean hasPermission(JobsPlayer jPlayer, String perm) {
if (jPlayer == null)
return false;
if (jPlayer == null)
return false;
Player player = jPlayer.getPlayer();
if (player == null)
return false;
Player player = jPlayer.getPlayer();
if (player == null)
return false;
Map<String, Boolean> permissions = jPlayer.getPermissionsCache();
permissionInfo permInfo = jPlayer.getPermissionsCache(perm);
if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
if (permissions == null) {
permissions = new HashMap<>();
jPlayer.setPermissionsCache(permissions);
}
permissions.put(perm, player.hasPermission(perm));
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
}
if (getDelay(perm) + permInfo.getTime() < System.currentTimeMillis()) {
permInfo.setState(player.hasPermission(perm));
permInfo.setTime(System.currentTimeMillis());
jPlayer.addToPermissionsCache(perm, permInfo);
}
return permissions.getOrDefault(perm, false);
CMIDebug.d("this return");
return permInfo.getState();
}
}

View File

@ -22,22 +22,22 @@ import net.Zrips.CMILib.Chat.ChatMessageListEdit;
import net.Zrips.CMILib.Chat.ChatMessageListEdit.ChatEditType;
import net.Zrips.CMILib.Chat.ChatMessageObjectEdit;
import net.Zrips.CMILib.Colors.CMIChatColor;
import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Container.CMINumber;
import net.Zrips.CMILib.Container.CMIText;
import net.Zrips.CMILib.Container.PageInfo;
import net.Zrips.CMILib.FileHandler.ConfigReader;
import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.RawMessages.RawMessage;
import net.Zrips.CMILib.RawMessages.RawMessageCommand;
public class editquests implements Cmd {
private enum Action {
update, editline, moveup, movedown, createnew, addline, info, deleteLine, gui, list, delete, editCommands;
list;
public static Action getByName(String name) {
if (name.equalsIgnoreCase("new"))
return Action.createnew;
for (Action one : Action.values()) {
if (one.name().equalsIgnoreCase(name))
return one;
@ -46,8 +46,8 @@ public class editquests implements Cmd {
}
}
HashMap<String, Quest> tempQuests = new HashMap<String, Quest>();
HashMap<String, List<String>> tempObjectives = new HashMap<String, List<String>>();
static HashMap<String, Quest> tempQuests = new HashMap<String, Quest>();
static HashMap<String, List<String>> tempObjectives = new HashMap<String, List<String>>();
@Override
public boolean perform(Jobs plugin, final CommandSender sender, String[] args) {
@ -81,47 +81,59 @@ public class editquests implements Cmd {
switch (action) {
case list:
Set<Quest> quests = new LinkedHashSet<Quest>();
for (Job job : Jobs.getJobs()) {
quests.addAll(job.getQuests());
}
PageInfo pi = new PageInfo(10, quests.size(), page);
ChatMessageObjectEdit CMOE = new ChatMessageObjectEdit(sender, pi) {
@Override
public void newAdd(String message) {
Quest q = new Quest(message, null);
tempQuests.put(sender.getName(), q);
mainWindow(sender, q);
}
};
for (Quest quest : quests) {
if (!pi.isEntryOk())
continue;
ChatEditorObject CEO = new ChatEditorObject(Jobs.getLanguage().getMessage("command.editquests.help.output.list", "[jobName]", quest.getJob()
.getDisplayName(), "[questName]", quest.getQuestName())) {
@Override
public void onDelete() {
}
@Override
public void onClick() {
mainWindow(sender, quest);
}
};
CEO.setHover(LC.modify_editSymbolHover.getLocale("[text]", quest.getQuestName()));
CMOE.addline(CEO);
}
CMOE.print();
pi.autoPagination(sender, JobsCommands.LABEL + " " + editquests.class.getSimpleName());
listQuests(sender, page);
break;
}
return true;
}
private List<String> getRecords(Quest quest, String section) {
private static void listQuests(CommandSender sender, int page) {
LC.info_Spliter.sendMessage(sender);
Set<Quest> quests = new LinkedHashSet<Quest>();
for (Job job : Jobs.getJobs()) {
quests.addAll(job.getQuests());
}
PageInfo pi = new PageInfo(10, quests.size(), page);
ChatMessageObjectEdit CMOE = new ChatMessageObjectEdit(sender, pi) {
@Override
public void newAdd(String message) {
Quest q = new Quest(message, null);
tempQuests.put(sender.getName(), q);
mainWindow(sender, q);
}
};
for (Quest quest : quests) {
if (!pi.isEntryOk())
continue;
ChatEditorObject CEO = new ChatEditorObject(Jobs.getLanguage().getMessage("command.editquests.help.output.list", "[jobName]", quest.getJob()
.getDisplayName(), "[questName]", quest.getQuestName())) {
@Override
public void onDelete() {
if (quest.getJob() != null) {
removeQuestInFile(quest.getConfigName(), quest.getJob().getName());
quest.getJob().getQuests().remove(quest);
}
listQuests(sender, page);
}
@Override
public void onClick() {
mainWindow(sender, quest);
}
};
CEO.setHover(LC.modify_editSymbolHover.getLocale("[text]", quest.getQuestName()));
CMOE.addline(CEO);
}
CMOE.print();
pi.autoPagination(sender, JobsCommands.LABEL + " " + editquests.class.getSimpleName());
}
private static List<String> getRecords(Quest quest, String section) {
List<String> objectives = new ArrayList<String>();
if (quest.getJob() == null)
@ -155,7 +167,7 @@ public class editquests implements Cmd {
return objectives;
}
private ConfigReader getQuestConfig(String jobName) {
private static ConfigReader getQuestConfig(String jobName) {
ConfigReader cfg = null;
@ -185,7 +197,10 @@ public class editquests implements Cmd {
return cfg;
}
private boolean removeQuestInFile(CommandSender sender, String questName, String jobName) {
private static boolean removeQuestInFile(String questName, String jobName) {
if (questName == null)
return false;
ConfigReader cfg = getQuestConfig(jobName);
@ -199,7 +214,7 @@ public class editquests implements Cmd {
return true;
}
private boolean updateQuestInFile(CommandSender sender, Quest quest) {
private static boolean updateQuestInFile(CommandSender sender, Quest quest) {
if (quest.getJob() == null)
return false;
@ -247,8 +262,9 @@ public class editquests implements Cmd {
return true;
}
private void objectivesWindow(CommandSender sender, Quest quest) {
private static void objectivesWindow(CommandSender sender, Quest quest) {
LC.info_Spliter.sendMessage(sender);
RawMessage rm = new RawMessage();
rm.addText(quest.getQuestName() + " objectives");
@ -274,8 +290,9 @@ public class editquests implements Cmd {
cmle.print();
}
private void rewardCommandsWindow(CommandSender sender, Quest quest) {
private static void rewardCommandsWindow(CommandSender sender, Quest quest) {
LC.info_Spliter.sendMessage(sender);
RawMessage rm = new RawMessage();
rm.addText(quest.getQuestName() + " reward commmands");
@ -297,8 +314,9 @@ public class editquests implements Cmd {
cmle.print();
}
private void rewardDescWindow(CommandSender sender, Quest quest) {
private static void rewardDescWindow(CommandSender sender, Quest quest) {
LC.info_Spliter.sendMessage(sender);
RawMessage rm = new RawMessage();
rm.addText(quest.getQuestName() + " reward description");
@ -320,8 +338,9 @@ public class editquests implements Cmd {
cmle.print();
}
private void restrictedAreaWindow(CommandSender sender, Quest quest) {
private static void restrictedAreaWindow(CommandSender sender, Quest quest) {
LC.info_Spliter.sendMessage(sender);
RawMessage rm = new RawMessage();
rm.addText(quest.getQuestName() + " restricted areas");
@ -343,13 +362,13 @@ public class editquests implements Cmd {
cmle.print();
}
private void mainWindow(CommandSender sender, Quest quest) {
private static void mainWindow(CommandSender sender, Quest quest) {
LC.info_Spliter.sendMessage(sender);
RawMessage rm = new RawMessage();
rm.addText("&eName: &f" + quest.getQuestName());
rm.addText("&7Name: &f" + quest.getQuestName());
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", quest.getQuestName()));
RawMessageCommand rmc = new RawMessageCommand() {
@Override
@ -372,59 +391,8 @@ public class editquests implements Cmd {
};
rm.addCommand(rmc);
rm.addText("\n");
List<String> objectives = getRecords(quest, "Objectives");
if (!tempObjectives.containsKey(sender.getName()))
tempObjectives.put(sender.getName(), objectives);
else
objectives = tempObjectives.get(sender.getName());
rm.addText((objectives.isEmpty() ? "&c" : "&e") + "Objectives");
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Objectives"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
objectivesWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.addText("\n");
rm.addText((quest.getRewardCmds().isEmpty() ? "&c" : "&e") + "Reward commands");
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Reward commands"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
rewardCommandsWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.addText("\n");
rm.addText("&eDescription");
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Description"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
rewardDescWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.addText("\n");
rm.addText("&eRestricted areas");
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Restricted areas"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
restrictedAreaWindow(sender, quest);
}
};
rm.addCommand(rmc);
String jobName = quest.getJob() == null ? "&c-" : quest.getJob().getName();
rm.addText("\n");
rm.addText("&eJob: &f" + jobName);
rm.addText(" &7Job: &f" + jobName);
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", jobName));
rmc = new RawMessageCommand() {
@Override
@ -446,7 +414,7 @@ public class editquests implements Cmd {
if (quest.getJob() != j) {
if (quest.getJob() != null) {
removeQuestInFile(sender, quest.getConfigName(), quest.getJob().getName());
removeQuestInFile(quest.getConfigName(), quest.getJob().getName());
quest.getJob().getQuests().remove(quest);
}
j.getQuests().add(quest);
@ -469,8 +437,7 @@ public class editquests implements Cmd {
};
rm.addCommand(rmc);
rm.addText("\n");
rm.addText("&eChance: &f" + quest.getChance());
rm.addText(" &7Chance: &f" + quest.getChance());
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", quest.getChance()));
rmc = new RawMessageCommand() {
@Override
@ -503,7 +470,7 @@ public class editquests implements Cmd {
rm.addText("\n");
rm.addText("&eFrom level: &f" + quest.getMinLvl());
rm.addText("&7Level from: &f" + quest.getMinLvl());
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", quest.getMinLvl()));
rmc = new RawMessageCommand() {
@Override
@ -538,8 +505,7 @@ public class editquests implements Cmd {
};
rm.addCommand(rmc);
rm.addText("\n");
rm.addText("&eTo level: &f" + (quest.getMaxLvl() == null ? "-" : quest.getMaxLvl()));
rm.addText(" &7to: &f" + (quest.getMaxLvl() == null ? "-" : quest.getMaxLvl()));
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", (quest.getMaxLvl() == null ? "-" : quest.getMaxLvl())));
rmc = new RawMessageCommand() {
@Override
@ -574,6 +540,71 @@ public class editquests implements Cmd {
};
rm.addCommand(rmc);
rm.addText("\n");
List<String> objectives = getRecords(quest, "Objectives");
if (!tempObjectives.containsKey(sender.getName()))
tempObjectives.put(sender.getName(), objectives);
else
objectives = tempObjectives.get(sender.getName());
String objectiveString = CMIList.listToString(objectives, " ");
if (objectiveString.length() > 32)
objectiveString = objectiveString.substring(0, 32) + "..";
rm.addText((objectives.isEmpty() ? "&c" : "&7") + "Objectives" + (objectiveString.isBlank() ? "" : " - &f" + objectiveString));
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Objectives"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
objectivesWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.addText("\n");
String rewardsString = CMIList.listToString(quest.getRewardCmds(), " ");
if (rewardsString.length() > 32)
rewardsString = rewardsString.substring(0, 30) + "..";
rm.addText((quest.getRewardCmds().isEmpty() ? "&c" : "&7") + "Reward commands" + (rewardsString.isBlank() ? "" : " - &f" + rewardsString));
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Reward commands"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
rewardCommandsWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.addText("\n");
String descString = CMIList.listToString(quest.getDescription(), " ");
if (descString.length() > 32)
descString = descString.substring(0, 30) + "..";
rm.addText("&7Description" + (rewardsString.isBlank() ? "" : " - &f" + descString));
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Description"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
rewardDescWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.addText("\n");
String restrictedString = CMIList.listToString(quest.getRestrictedAreas(), " ");
if (restrictedString.length() > 32)
restrictedString = restrictedString.substring(0, 30) + "..";
rm.addText("&7Restricted areas" + (restrictedString.isBlank() ? "" : " - &f" + restrictedString));
rm.addHover(LC.modify_editSymbolHover.getLocale("[text]", "Restricted areas"));
rmc = new RawMessageCommand() {
@Override
public void run(CommandSender sender) {
restrictedAreaWindow(sender, quest);
}
};
rm.addCommand(rmc);
rm.show(sender);
}
}

View File

@ -1430,6 +1430,7 @@ public class ConfigManager {
quest.setRewardCmds(sqsection.getStringList("RewardCommands"));
quest.setDescription(sqsection.getStringList("RewardDesc"));
quest.setRestrictedArea(sqsection.getStringList("RestrictedAreas"));
quest.setEnabled(sqsection.getBoolean("Enabled", true));
quests.add(quest);
} catch (Exception e) {

View File

@ -34,6 +34,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.permissionInfo;
import com.gamingmesh.jobs.Signs.SignTopType;
import com.gamingmesh.jobs.api.JobsLevelUpEvent;
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
@ -85,8 +86,7 @@ public class JobsPlayer {
private long seen = System.currentTimeMillis();
private Map<String, Boolean> permissionsCache;
private long lastPermissionUpdate = -1L;
private Map<String, permissionInfo> permissionsCache = new HashMap<>();
private final Map<String, Map<String, QuestProgression>> qProgression = new HashMap<>();
private int doneQuests = 0;
@ -924,6 +924,9 @@ public class JobsPlayer {
clearBossMaps();
isOnline = false;
blockOwnerShipInform = null;
permissionsCache.clear();
Jobs.getPlayerManager().addPlayerToCache(this);
}
@ -961,24 +964,16 @@ public class JobsPlayer {
this.seen = seen;
}
public Map<String, Boolean> getPermissionsCache() {
public Map<String, permissionInfo> getPermissionsCache() {
return permissionsCache;
}
public void setPermissionsCache(Map<String, Boolean> permissionsCache) {
this.permissionsCache = permissionsCache;
public permissionInfo getPermissionsCache(String perm) {
return permissionsCache.getOrDefault(perm, new permissionInfo());
}
public void setPermissionsCache(String permission, Boolean state) {
permissionsCache.put(permission, state);
}
public long getLastPermissionUpdate() {
return lastPermissionUpdate;
}
public void setLastPermissionUpdate(Long lastPermissionUpdate) {
this.lastPermissionUpdate = lastPermissionUpdate;
public void addToPermissionsCache(String permission, permissionInfo permInfo) {
permissionsCache.put(permission, permInfo);
}
/**

View File

@ -20,6 +20,8 @@ public class Quest {
private int chance = 100, minLvl = 0;
private Integer maxLvl;
private boolean enabled = false;
private final List<String> rewardCmds = new ArrayList<>(), rewards = new ArrayList<>(), area = new ArrayList<>();
private boolean stopped = false;
@ -217,4 +219,12 @@ public class Quest {
public boolean hasAction(ActionType action) {
return actions.contains(action);
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -419,6 +419,7 @@ public final class JobsPaymentListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
final Block block = event.getBlock();
if (!Jobs.getGCManager().canPerformActionInWorld(block.getWorld()))
@ -433,9 +434,12 @@ public final class JobsPaymentListener implements Listener {
if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle())
return;
CMIDebug.d("BlockBreakEvent2");
// check if in creative
if (!payIfCreative(player))
return;
CMIDebug.d("BlockBreakEvent3");
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
return;
@ -721,14 +725,14 @@ public final class JobsPaymentListener implements Listener {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return;
if (y == 2 && first == second && third == second) {
if (Jobs.getGCManager().payForCombiningItems && third == first) {
Jobs.action(jPlayer, new ItemActionInfo(event.getCurrentItem(), ActionType.REPAIR));
} else {
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
}
return;
return;
}
// Check Dyes
@ -897,9 +901,9 @@ public final class JobsPaymentListener implements Listener {
default:
break;
}
if (!event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) &&
!event.getAction().equals(InventoryAction.PICKUP_ALL) &&
if (!event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) &&
!event.getAction().equals(InventoryAction.PICKUP_ALL) &&
!event.getAction().equals(InventoryAction.PICKUP_HALF))
return;
@ -1895,12 +1899,7 @@ public final class JobsPaymentListener implements Listener {
}
public static boolean payIfCreative(Player player) {
if (Jobs.getGCManager().payInCreative() && player.getGameMode() == GameMode.CREATIVE)
return true;
if (player.getGameMode() == GameMode.CREATIVE && Jobs.getPermissionManager().hasPermission(Jobs.getPlayerManager().getJobsPlayer(player), "jobs.paycreative"))
return true;
return player.getGameMode() != GameMode.CREATIVE;
return player.getGameMode() != GameMode.CREATIVE || Jobs.getGCManager().payInCreative() || Jobs.getPermissionManager().hasPermission(Jobs.getPlayerManager().getJobsPlayer(player), "jobs.paycreative");
}
// Prevent item durability loss

View File

@ -0,0 +1,36 @@
package com.gamingmesh.jobs;
public class permissionInfo {
private long time = 0L;
private boolean state = false;
private double value = 0D;
public long getTime() {
return time;
}
public permissionInfo setTime(long time) {
this.time = time;
return this;
}
public boolean getState() {
return state;
}
public permissionInfo setState(boolean state) {
this.state = state;
return this;
}
public double getValue() {
return value;
}
public permissionInfo setValue(double value) {
this.value = value;
return this;
}
}