1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-30 21:07:48 +01:00

Add option to use negative values for boost calculation

This commit is contained in:
Zrips 2017-01-13 15:10:55 +02:00
parent ddf9fbb908
commit 2e68508b9b
8 changed files with 278 additions and 86 deletions

View File

@ -249,5 +249,12 @@ public class PermissionHandler {
}
return player.hasPermission("jobs.world." + world.toLowerCase());
}
public boolean hasWorldPermission(JobsPlayer player, String world) {
if (!Jobs.getPermissionManager().hasPermission(player, "jobs.use")) {
return false;
}
return Jobs.getPermissionManager().hasPermission(player, "jobs.world." + world.toLowerCase());
}
}

View File

@ -0,0 +1,166 @@
/**
* Jobs Plugin for Bukkit
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gamingmesh.jobs;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.Debug;
public class PermissionManager {
HashMap<String, Integer> permDelay = new HashMap<String, Integer>();
private enum prm {
// jobs_join_JOBNAME(remade("jobs.join.%JOBNAME%"), 60 * 1000),
// jobs_use(remade("jobs.use"), 60 * 1000),
// 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 * 1000),
jobs_boost_JOBNAME_exp_AMOUNT(remade("jobs.boost.%JOBNAME%.exp.%AMOUNT%"), 60 * 1000),
jobs_boost_JOBNAME_points_AMOUNT(remade("jobs.boost.%JOBNAME%.points.%AMOUNT%"), 60 * 1000),
jobs_boost_JOBNAME_all_AMOUNT(remade("jobs.boost.%JOBNAME%.all.%AMOUNT%"), 60 * 1000),
jobs_boost_all_money_AMOUNT(remade("jobs.boost.all.money.%AMOUNT%"), 60 * 1000),
jobs_boost_all_exp_AMOUNT(remade("jobs.boost.all.exp.%AMOUNT%"), 60 * 1000),
jobs_boost_all_points_AMOUNT(remade("jobs.boost.all.points.%AMOUNT%"), 60 * 1000),
jobs_boost_all_all_AMOUNT(remade("jobs.boost.all.all.%AMOUNT%"), 60 * 1000),
jobs_max_AMOUNT(remade("jobs.max.%AMOUNT%"), 60 * 1000),
// jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 60 * 1000)
;
private int reload;
private List<String> perms;
private prm(List<String> perms, int reload) {
this.perms = perms;
this.reload = reload;
}
public int getDelay() {
return reload;
}
private static List<String> remade(String perm) {
List<String> perms = new ArrayList<String>();
for (Job oneJ : Jobs.getJobs()) {
String t = perm;
if (t.contains("%JOBNAME%"))
t = t.replace("%JOBNAME%", oneJ.getName().toLowerCase());
if (t.contains("%AMOUNT%"))
t = t.replace("%AMOUNT%", "");
perms.add(t);
}
if (perm.contains("%WORLDNAME%"))
for (World oneJ : Bukkit.getWorlds()) {
String t = perm;
t = t.replace("%WORLDNAME%", oneJ.getName().toLowerCase());
perms.add(t);
}
return perms;
}
public List<String> getPerms() {
return perms;
}
}
private int getDelay(String perm) {
Integer delay = permDelay.get(perm);
return delay == null ? 1 : delay;
}
public PermissionManager() {
for (prm one : prm.values()) {
for (String oneP : one.getPerms()) {
permDelay.put(oneP, one.getDelay());
}
}
}
private static HashMap<String, Boolean> getAll(Player player) {
HashMap<String, Boolean> mine = new HashMap<String, Boolean>();
for (PermissionAttachmentInfo permission : player.getEffectivePermissions()) {
if (permission.getPermission().startsWith("jobs."))
mine.put(permission.getPermission(), permission.getValue());
}
return mine;
}
public Double getMaxPermission(JobsPlayer jPlayer, String perm) {
return getMaxPermission(jPlayer, perm, false);
}
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
perm = perm.toLowerCase();
if (!perm.endsWith("."))
perm += ".";
if (jPlayer == null)
return 0D;
if (jPlayer.getPlayer() == null)
return 0D;
HashMap<String, Boolean> permissions = jPlayer.getPermissionsCache();
if (force || permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
permissions = getAll(jPlayer.getPlayer());
jPlayer.setPermissionsCache(permissions);
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
}
Double amount = null;
for (Entry<String, Boolean> uno : permissions.entrySet()) {
if (uno.getKey().startsWith(perm)) {
Debug.D("start with " + uno.getKey());
try {
double t = Double.parseDouble(uno.getKey().replace(perm, ""));
Debug.D(t);
if (amount == null || t > amount)
amount = t;
} catch (Exception e) {
}
}
}
return amount;
}
public boolean hasPermission(JobsPlayer jPlayer, String perm) {
if (jPlayer == null)
return false;
if (jPlayer.getPlayer() == null)
return false;
HashMap<String, Boolean> permissions = jPlayer.getPermissionsCache();
if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
permissions = getAll(jPlayer.getPlayer());
jPlayer.setPermissionsCache(permissions);
jPlayer.setLastPermissionUpdate(System.currentTimeMillis());
}
Boolean resul = permissions.get(perm);
return resul == null ? false : resul;
}
}

View File

@ -550,20 +550,29 @@ public class PlayerManager {
* @param player
* @return True if he have permission
*/
public boolean getJobsLimit(Player player, Short currentCount) {
public boolean getJobsLimit(JobsPlayer jPlayer, Short currentCount) {
if (Perm.hasPermission(player, "jobs.max.*"))
Double max = Jobs.getPermissionManager().getMaxPermission(jPlayer, "jobs.max");
max = max == null ? Jobs.getGCManager().getMaxJobs() : max;
if (max > currentCount)
return true;
int totalJobs = Jobs.getJobs().size() + 1;
// Using new system to get max value from permission
short count = (short) Jobs.getGCManager().getMaxJobs();
for (short ctr = 0; ctr < totalJobs; ctr++) {
if (Perm.hasPermission(player, "jobs.max." + ctr))
count = ctr;
if (count > currentCount)
return true;
}
// if (Perm.hasPermission(player, "jobs.max.*"))
// return true;
//
// int totalJobs = Jobs.getJobs().size() + 1;
//
// short count = (short) Jobs.getGCManager().getMaxJobs();
// for (short ctr = 0; ctr < totalJobs; ctr++) {
// if (Perm.hasPermission(player, "jobs.max." + ctr))
// count = ctr;
// if (count > currentCount)
// return true;
// }
return false;
}
@ -740,7 +749,7 @@ public class PlayerManager {
if (one.getMaxSlots() != null && Jobs.getUsedSlots(one) >= one.getMaxSlots())
continue;
short PlayerMaxJobs = (short) jPlayer.getJobProgression().size();
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(player, PlayerMaxJobs))
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(jPlayer, PlayerMaxJobs))
break;
if (jPlayer.isInJob(one))
continue;

View File

@ -78,7 +78,7 @@ public class join implements Cmd {
int confMaxJobs = Jobs.getGCManager().getMaxJobs();
short PlayerMaxJobs = (short) jPlayer.getJobProgression().size();
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(pSender, PlayerMaxJobs)) {
if (confMaxJobs > 0 && PlayerMaxJobs >= confMaxJobs && !Jobs.getPlayerManager().getJobsLimit(jPlayer, PlayerMaxJobs)) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.join.error.maxjobs"));
return true;
}

View File

@ -1,50 +1,50 @@
package com.gamingmesh.jobs.commands.list;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
public class stats implements Cmd {
@Override
@JobCommand(400)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
JobsPlayer jPlayer = null;
if (args.length >= 1) {
if (!sender.hasPermission("jobs.command.admin.stats")) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission"));
return true;
}
jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
} else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
}
if (jPlayer == null) {
if (args.length >= 1)
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfo"));
else
Jobs.getCommandManager().sendUsage(sender, "stats");
return true;
}
if (jPlayer.getJobProgression().size() == 0) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.stats.error.nojob"));
return true;
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getUserName()));
for (JobProgression jobProg : jPlayer.getJobProgression()) {
String[] msg = Jobs.getCommandManager().jobStatsMessage(jobProg).split("\n");
sender.sendMessage(msg);
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
return true;
}
}
package com.gamingmesh.jobs.commands.list;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
public class stats implements Cmd {
@Override
@JobCommand(400)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
JobsPlayer jPlayer = null;
if (args.length >= 1) {
if (!sender.hasPermission("jobs.command.admin.stats")) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.permission"));
return true;
}
jPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
} else if (sender instanceof Player) {
jPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
}
if (jPlayer == null) {
if (args.length >= 1)
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfo"));
else
Jobs.getCommandManager().sendUsage(sender, "stats");
return true;
}
if (jPlayer.getJobProgression().size() == 0) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.stats.error.nojob"));
return true;
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.toplineseparator", "%playername%", jPlayer.getUserName()));
for (JobProgression jobProg : jPlayer.getJobProgression()) {
String[] msg = Jobs.getCommandManager().jobStatsMessage(jobProg).split("\n");
sender.sendMessage(msg);
}
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.separator"));
return true;
}
}

View File

@ -106,8 +106,6 @@ public class GeneralConfigManager {
public boolean MonsterDamageUse = false;
public double MonsterDamagePercentage;
public HashMap<CurrencyType, Double> Boost = new HashMap<CurrencyType, Double>();
public double DynamicPaymentMaxPenalty;
public double DynamicPaymentMaxBonus;
public double TaxesAmount;
@ -749,15 +747,11 @@ public class GeneralConfigManager {
"If you are not using breeding payment, you can disable this to save little resources. Really little.");
useBreederFinder = c.get("use-breeder-finder", true);
c.getW().addComment("boost", "Money exp boost with special permision.",
c.getW().addComment("boost", "[Removed]", "Money exp boost with special permision.",
"You will need to add special permision for groups or players to have money/exp/points boost.",
"Use: jobs.boost.[jobname].money or jobs.boost.[jobname].exp or jobs.boost.[jobname].points or jobs.boost.[jobname].all for all of them with specific jobs name.",
"Use: jobs.boost.all.money or jobs.boost.all.exp or jobs.boost.all.points or jobs.boost.all.all to get boost for all jobs",
"1.25 means that player will get 25% more than others, you can set less than 1 to get less from anothers");
Boost.put(CurrencyType.EXP, (int) ((c.get("boost.exp", 1D) * 100) - 100) / 100D);
Boost.put(CurrencyType.MONEY, (int) ((c.get("boost.money", 1D) * 100) - 100) / 100D);
Boost.put(CurrencyType.POINTS, (int) ((c.get("boost.points", 1D) * 100) - 100) / 100D);
"Use: jobs.boost.[jobname].money.[amount] or jobs.boost.[jobname].exp.[amount] or jobs.boost.[jobname].points.[amount] or jobs.boost.[jobname].all.[amount] for all of them with specific jobs name.",
"Use: jobs.boost.all.money.[amount] or jobs.boost.all.exp.[amount] or jobs.boost.all.points.[amount] or jobs.boost.all.all.[amount] to get boost for all jobs",
"In example: jobs.boost.miner.exp.0.25 means that player will get 25% more than others, you can set less than 1 to get less from anothers");
c.getW().addComment("old-job", "Old job save", "Players can leave job and return later with some level loss during that",
"You can fix players level if hes job level is at max level");

View File

@ -220,20 +220,19 @@ public class JobsPlayer {
if (counter.getType() != type)
continue;
if (force || time - counter.getTime() > 1000 * 60) {
Debug.D("updating perm");
Boost = getPlayerBoost(JobName, type);
Boost = getPlayerBoostNew(JobName, type);
counter.setBoost(Boost);
counter.setTime(time);
return Boost;
}
return counter.getBoost();
}
Boost = getPlayerBoost(JobName, type);
Boost = getPlayerBoostNew(JobName, type);
counterList.add(new BoostCounter(type, Boost, time));
return Boost;
}
Boost = getPlayerBoost(JobName, type);
Boost = getPlayerBoostNew(JobName, type);
ArrayList<BoostCounter> counterList = new ArrayList<BoostCounter>();
counterList.add(new BoostCounter(type, Boost, time));
@ -242,17 +241,35 @@ public class JobsPlayer {
return Boost;
}
private Double getPlayerBoost(String JobName, CurrencyType type) {
double Boost = 0D;
if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) ||
Perm.hasPermission(player, "jobs.boost." + JobName + ".all") ||
Perm.hasPermission(player, "jobs.boost.all.all") ||
Perm.hasPermission(player, "jobs.boost.all." + type.getName().toLowerCase())) {
Boost = Jobs.getGCManager().Boost.get(type);
}
return Boost;
private Double getPlayerBoostNew(String JobName, CurrencyType type) {
Double Boost = null;
Double v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + "." + type.getName().toLowerCase(), true);
Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all");
if (Boost == null ||v1 != null && v1 > Boost)
Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all");
if (Boost == null ||v1 != null && v1 > Boost)
Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName().toLowerCase());
if (Boost == null ||v1 != null &&v1 > Boost)
Boost = v1;
Debug.D("boost " + Boost);
return Boost == null ? 0D : Boost;
}
// New method is in use
// private Double getPlayerBoost(String JobName, CurrencyType type) {
// double Boost = 0D;
// if (Perm.hasPermission(player, "jobs.boost." + JobName + "." + type.getName().toLowerCase()) ||
// Perm.hasPermission(player, "jobs.boost." + JobName + ".all") ||
// Perm.hasPermission(player, "jobs.boost.all.all") ||
// Perm.hasPermission(player, "jobs.boost.all." + type.getName().toLowerCase())) {
// Boost = Jobs.getGCManager().Boost.get(type);
// }
// return Boost;
// }
/**
* Reloads max experience for this job.
*/

View File

@ -87,7 +87,6 @@ import com.gamingmesh.jobs.container.FastPayment;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
import com.google.common.base.Objects;
public class JobsPaymentListener implements Listener {