1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Now you can use negative boosts

Fixes #365

- Locale files now accepts hex colors
This commit is contained in:
montlikadani 2020-07-25 13:40:17 +02:00
parent 0a6a2648c8
commit 2a9c72ea7c
11 changed files with 120 additions and 149 deletions

View File

@ -32,7 +32,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class PermissionManager {
private HashMap<String, Integer> permDelay = new HashMap<>();
private final HashMap<String, Integer> permDelay = new HashMap<>();
private enum prm {
// jobs_join_JOBNAME(remade("jobs.join.%JOBNAME%"), 60 * 1000),
@ -54,8 +54,7 @@ public class PermissionManager {
jobs_petpay_AMOUNT(remade("jobs.petpay.%AMOUNT%"), 60 * 1000),
jobs_maxfurnaces_AMOUNT(remade("jobs.maxfurnaces.%AMOUNT%"), 2 * 1000),
jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 2 * 1000),
jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2 * 1000)
;
jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2 * 1000);
private int reload;
private List<String> perms;
@ -111,6 +110,7 @@ public class PermissionManager {
if (permission.getPermission().startsWith("jobs."))
mine.put(permission.getPermission(), permission.getValue());
}
return mine;
}
@ -119,10 +119,7 @@ public class PermissionManager {
}
public Double getMaxPermission(JobsPlayer jPlayer, String perm, boolean force) {
if (jPlayer == null)
return 0D;
if (jPlayer.getPlayer() == null)
if (jPlayer == null || jPlayer.getPlayer() == null)
return 0D;
perm = perm.toLowerCase();
@ -143,12 +140,15 @@ public class PermissionManager {
Double amount = null;
for (Entry<String, Boolean> uno : permissions.entrySet()) {
if (uno.getKey().startsWith(perm)) {
double t = 0d;
try {
double t = Double.parseDouble(uno.getKey().replace(perm, ""));
if (amount == null || t > amount)
amount = t;
} catch (Exception e) {
t = Double.parseDouble(uno.getKey().replace(perm, ""));
} catch (NumberFormatException e) {
continue;
}
amount = t;
break;
}
}
@ -156,10 +156,9 @@ public class PermissionManager {
}
public boolean hasPermission(JobsPlayer jPlayer, String perm) {
if (jPlayer == null)
return false;
if (jPlayer.getPlayer() == null)
if (jPlayer == null || jPlayer.getPlayer() == null)
return false;
HashMap<String, Boolean> permissions = jPlayer.getPermissionsCache();
if (permissions == null || getDelay(perm) + jPlayer.getLastPermissionUpdate() < System.currentTimeMillis()) {
permissions = getAll(jPlayer.getPlayer());

View File

@ -471,9 +471,8 @@ public class Placeholder {
case user_jmaxlvl_$1:
return j == null ? "0" : Integer.toString(j.getJob().getMaxLevel(user));
case user_boost_$1_$2:
if (vals.size() < 2)
return "";
return j == null ? "" : simplifyDouble(user.getBoost(j.getJob().getName(), CurrencyType.getByName(vals.get(1))));
return vals.size() < 2 || j == null ? "" : simplifyDouble(user.getBoost(j.getJob().getName(),
CurrencyType.getByName(vals.get(1))));
case user_isin_$1:
vals = placeHolder.getComplexValues(value);
if (vals.isEmpty())

View File

@ -25,7 +25,7 @@ public class limit implements Cmd {
if (args.length >= 1)
JPlayer = Jobs.getPlayerManager().getJobsPlayer(args[0]);
else if (sender instanceof Player)
JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
JPlayer = Jobs.getPlayerManager().getJobsPlayer((Player) sender);
boolean disabled = true;
for (CurrencyType type : CurrencyType.values()) {

View File

@ -7,17 +7,12 @@ import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
public class reload implements Cmd {
@Override
@JobCommand(2900)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
try {
Jobs.reload();
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
} catch (Throwable e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.error"));
Jobs.consoleMsg("&4There was an error when performing a reload: ");
e.printStackTrace();
}
Jobs.reload();
sender.sendMessage(Jobs.getLanguage().getMessage("general.admin.success"));
return true;
}
}

View File

@ -58,12 +58,12 @@ public class top implements Cmd {
PageInfo pi = new PageInfo(Jobs.getGCManager().JobsTopAmount, workingIn, page);
List<TopList> FullList = Jobs.getJobsDAO().toplist(job.getName(), pi.getStart() - 1);
if (FullList.size() <= 0) {
if (FullList.isEmpty()) {
player.sendMessage(Jobs.getLanguage().getMessage("general.error.noinfo"));
return true;
}
player.sendMessage(Jobs.getLanguage().getMessage("command.top.help.info", "%amount%", Jobs.getGCManager().JobsTopAmount));
player.sendMessage(Jobs.getLanguage().getMessage("command.top.help.info"));
if (!Jobs.getGCManager().ShowToplistInScoreboard) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.output.topline", "%jobname%", job.getName(), "%amount%", Jobs.getGCManager().JobsTopAmount));

View File

@ -36,7 +36,7 @@ public class ScheduleManager {
return;
cancel();
autoTimerBukkitId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, autoTimer, 20, 30 * 20L);
autoTimerBukkitId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::scheduler, 20, 30 * 20L);
}
public void cancel() {
@ -44,8 +44,6 @@ public class ScheduleManager {
Bukkit.getScheduler().cancelTask(autoTimerBukkitId);
}
private Runnable autoTimer = this::scheduler;
public int getDateByInt() {
return TimeManage.timeInInt();
}
@ -59,25 +57,23 @@ public class ScheduleManager {
String currenttime = dateFormat.format(date);
int Current = Integer.valueOf(currenttime.replace(":", "")).intValue();
int Current = Integer.valueOf(currenttime.replace(":", ""));
String CurrentDayName = GetWeekDay();
String CurrentDayName = getWeekDay();
for (Schedule one : BOOSTSCHEDULE) {
int From = one.GetFrom();
int Until = one.GetUntil();
int From = one.getFrom();
int Until = one.getUntil();
List<String> days = one.GetDays();
List<String> days = one.getDays();
if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.GetBroadcastInterval() > 0) {
one.setBroadcastInfoOn(System.currentTimeMillis() + one.GetBroadcastInterval() * 60 * 1000);
for (String oneMsg : one.GetMessageToBroadcast()) {
Bukkit.broadcastMessage(oneMsg);
}
if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.getBroadcastInterval() > 0) {
one.setBroadcastInfoOn(System.currentTimeMillis() + one.getBroadcastInterval() * 60 * 1000);
one.getMessageToBroadcast().forEach(Bukkit::broadcastMessage);
}
if (((one.isNextDay() && (Current >= From && Current < Until || Current >= one.GetNextFrom() && Current < one.GetNextUntil()) && !one
if (((one.isNextDay() && (Current >= From && Current < Until || Current >= one.getNextFrom() && Current < one.getNextUntil()) && !one
.isStarted()) || !one.isNextDay() && (Current >= From && Current < Until)) && (days.contains(CurrentDayName) || days.contains("all")) && !one
.isStarted()) {
@ -86,40 +82,40 @@ public class ScheduleManager {
if (event.isCancelled()) {
continue;
}
if (one.isBroadcastOnStart())
if (one.GetMessageOnStart().size() == 0)
if (one.getMessageOnStart().isEmpty())
Bukkit.broadcastMessage(Jobs.getLanguage().getMessage("message.boostStarted"));
else
for (String oneMsg : one.GetMessageOnStart()) {
Bukkit.broadcastMessage(oneMsg);
}
one.getMessageOnStart().forEach(Bukkit::broadcastMessage);
for (Job onejob : one.GetJobs()) {
for (Job onejob : one.getJobs()) {
onejob.setBoost(one.getBoost());
}
one.setBroadcastInfoOn(System.currentTimeMillis() + one.GetBroadcastInterval() * 60 * 1000);
one.setBroadcastInfoOn(System.currentTimeMillis() + one.getBroadcastInterval() * 60 * 1000);
one.setStarted(true);
one.setStoped(false);
break;
} else if (((one.isNextDay() && Current > one.GetNextUntil() && Current < one.GetFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until
} else if (((one.isNextDay() && Current > one.getNextUntil() && Current < one.getFrom() && !one.isStoped()) || !one.isNextDay() && Current > Until
&& ((days.contains(CurrentDayName)) || days.contains("all"))) && !one.isStoped()) {
JobsScheduleStopEvent event = new JobsScheduleStopEvent(one);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
continue;
}
if (one.isBroadcastOnStop())
if (one.GetMessageOnStop().size() == 0)
if (one.getMessageOnStop().isEmpty())
Bukkit.broadcastMessage(Jobs.getLanguage().getMessage("message.boostStoped"));
else
for (String oneMsg : one.GetMessageOnStop()) {
Bukkit.broadcastMessage(oneMsg);
}
for (Job onejob : one.GetJobs()) {
one.getMessageOnStop().forEach(Bukkit::broadcastMessage);
for (Job onejob : one.getJobs()) {
onejob.setBoost(new BoostMultiplier());
}
one.setStoped(true);
one.setStarted(false);
}
@ -128,7 +124,7 @@ public class ScheduleManager {
return true;
}
public static String GetWeekDay() {
public static String getWeekDay() {
Calendar c = Calendar.getInstance();
int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
switch (dayOfWeek) {
@ -175,22 +171,14 @@ public class ScheduleManager {
for (String OneSection : sections) {
ConfigurationSection path = conf.getConfigurationSection("Boost." + OneSection);
if (!path.contains("Enabled") || !conf.getConfigurationSection("Boost." + OneSection).getBoolean("Enabled"))
if (!path.getBoolean("Enabled", false))
continue;
Schedule sched = new Schedule();
sched.setName(OneSection);
if (!path.contains("From") || !path.getString("From").contains(":"))
continue;
if (!path.contains("Until") || !path.getString("Until").contains(":"))
continue;
if (!path.contains("Days") || !path.isList("Days"))
continue;
if (!path.contains("Jobs") || !path.isList("Jobs"))
if (!path.getString("From", "").contains(":") || !path.getString("Until", "").contains(":")
|| !path.isList("Days") || !path.isList("Jobs"))
continue;
sched.setDays(path.getStringList("Days"));
@ -198,13 +186,13 @@ public class ScheduleManager {
sched.setFrom(Integer.valueOf(path.getString("From").replace(":", "")));
sched.setUntil(Integer.valueOf(path.getString("Until").replace(":", "")));
if (path.contains("MessageOnStart") && path.isList("MessageOnStart"))
if (path.isList("MessageOnStart"))
sched.setMessageOnStart(path.getStringList("MessageOnStart"), path.getString("From"), path.getString("Until"));
if (path.contains("BroadcastOnStart"))
sched.setBroadcastOnStart(path.getBoolean("BroadcastOnStart"));
if (path.contains("MessageOnStop") && path.isList("MessageOnStop"))
if (path.isList("MessageOnStop"))
sched.setMessageOnStop(path.getStringList("MessageOnStop"), path.getString("From"), path.getString("Until"));
if (path.contains("BroadcastOnStop"))
@ -213,14 +201,14 @@ public class ScheduleManager {
if (path.contains("BroadcastInterval"))
sched.setBroadcastInterval(path.getInt("BroadcastInterval"));
if (path.contains("BroadcastMessage") && path.isList("BroadcastMessage"))
if (path.isList("BroadcastMessage"))
sched.setMessageToBroadcast(path.getStringList("BroadcastMessage"), path.getString("From"), path.getString("Until"));
if (path.contains("Exp") && path.isDouble("Exp"))
if (path.isDouble("Exp"))
sched.setBoost(CurrencyType.EXP, path.getDouble("Exp", 0D));
if (path.contains("Money") && path.isDouble("Money"))
if (path.isDouble("Money"))
sched.setBoost(CurrencyType.MONEY, path.getDouble("Money", 0D));
if (path.contains("Points") && path.isDouble("Points"))
if (path.isDouble("Points"))
sched.setBoost(CurrencyType.POINTS, path.getDouble("Points", 0D));
BOOSTSCHEDULE.add(sched);

View File

@ -250,9 +250,8 @@ public class JobsPlayer {
public double getBoost(String JobName, CurrencyType type, boolean force) {
double Boost = 0D;
if (!isOnline())
return Boost;
if (type == null)
if (!isOnline() || type == null)
return Boost;
long time = System.currentTimeMillis();
@ -262,14 +261,17 @@ public class JobsPlayer {
for (BoostCounter counter : counterList) {
if (counter.getType() != type)
continue;
if (force || time - counter.getTime() > 1000 * 60) {
Boost = getPlayerBoostNew(JobName, type);
counter.setBoost(Boost);
counter.setTime(time);
return Boost;
}
return counter.getBoost();
}
Boost = getPlayerBoostNew(JobName, type);
counterList.add(new BoostCounter(type, Boost, time));
return Boost;
@ -285,19 +287,22 @@ public class JobsPlayer {
}
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;
Double Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost." + JobName + ".all");
if (Boost == null || v1 != null && v1 > Boost)
Boost = v1;
//if (v1 > Boost)
// Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all.all");
if (Boost == null || v1 != null && v1 > Boost)
Boost = v1;
//if (v1 > Boost)
// Boost = v1;
v1 = Jobs.getPermissionManager().getMaxPermission(this, "jobs.boost.all." + type.getName().toLowerCase());
if (Boost == null || v1 != null && v1 > Boost)
Boost = v1;
return Boost == null ? 0D : Boost;
//if (v1 > Boost)
// Boost = v1;
return Boost;
}
// New method is in use
@ -824,7 +829,7 @@ public class JobsPlayer {
}
public void setPermissionsCache(String permission, Boolean state) {
this.permissionsCache.put(permission, state);
permissionsCache.put(permission, state);
}
public Long getLastPermissionUpdate() {
@ -926,9 +931,7 @@ public class JobsPlayer {
}
public void resetQuests() {
for (JobProgression one : getJobProgression()) {
resetQuests(one.getJob());
}
getJobProgression().forEach(one -> resetQuests(one.getJob()));
}
public void getNewQuests() {
@ -961,7 +964,7 @@ public class JobsPlayer {
HashMap<String, QuestProgression> prog = qProgression.get(q.getJob().getName());
if (prog == null) {
prog = new HashMap<String, QuestProgression>();
prog = new HashMap<>();
qProgression.put(q.getJob().getName(), prog);
}
@ -995,7 +998,8 @@ public class JobsPlayer {
public List<QuestProgression> getQuestProgressions(Job job, ActionType type) {
if (!isInJob(job))
return new ArrayList<QuestProgression>();
return new ArrayList<>();
HashMap<String, QuestProgression> g = new HashMap<>();
if (qProgression.get(job.getName()) != null)
@ -1127,7 +1131,7 @@ public class JobsPlayer {
HashMap<String, QuestProgression> currentProgression = qProgression.get(job.getName());
if (currentProgression == null) {
currentProgression = new HashMap<String, QuestProgression>();
currentProgression = new HashMap<>();
qProgression.put(job.getName(), currentProgression);
}

View File

@ -98,7 +98,7 @@ public class Schedule {
this.Name = Name;
}
public String GetName() {
public String getName() {
return Name;
}
@ -106,15 +106,15 @@ public class Schedule {
this.From = From;
}
public int GetFrom() {
public int getFrom() {
return From;
}
public int GetNextFrom() {
public int getNextFrom() {
return nextFrom;
}
public int GetNextUntil() {
public int getNextUntil() {
return nextUntil;
}
@ -133,7 +133,7 @@ public class Schedule {
}
}
public int GetUntil() {
public int getUntil() {
return Until;
}
@ -150,7 +150,6 @@ public class Schedule {
}
Job jb = Jobs.getJob(JobsNameList.get(z));
if (jb == null)
continue;
@ -158,7 +157,7 @@ public class Schedule {
}
}
public List<Job> GetJobs() {
public List<Job> getJobs() {
return JobsList;
}
@ -166,10 +165,11 @@ public class Schedule {
for (int z = 0; z < Days.size(); z++) {
Days.set(z, Days.get(z).toLowerCase());
}
this.Days = Days;
}
public List<String> GetDays() {
public List<String> getDays() {
return Days;
}
@ -181,7 +181,7 @@ public class Schedule {
MessageOnStart.addAll(temp);
}
public List<String> GetMessageOnStart() {
public List<String> getMessageOnStart() {
return MessageOnStart;
}
@ -193,7 +193,7 @@ public class Schedule {
MessageOnStop.addAll(temp);
}
public List<String> GetMessageOnStop() {
public List<String> getMessageOnStop() {
return MessageOnStop;
}
@ -205,7 +205,7 @@ public class Schedule {
MessageToBroadcast.addAll(temp);
}
public List<String> GetMessageToBroadcast() {
public List<String> getMessageToBroadcast() {
return MessageToBroadcast;
}
@ -213,7 +213,7 @@ public class Schedule {
this.broadcastInterval = broadcastInterval;
}
public int GetBroadcastInterval() {
public int getBroadcastInterval() {
return broadcastInterval;
}

View File

@ -2490,13 +2490,10 @@ public abstract class JobsDAO {
Job job = Jobs.getJob(jobsname);
if (job == null)
return jobs;
PreparedStatement prest = null;
ResultSet res = null;
if (limit < 0) {
limit = 0;
}
try {
prest = conn.prepareStatement("SELECT `" + JobsTableFields.userid.getCollumn() + "`, `" + JobsTableFields.level.getCollumn() + "`, `" + JobsTableFields.experience.getCollumn() + "` FROM `"
+ getJobsTableName() + "` WHERE `" + JobsTableFields.jobid.getCollumn() + "` LIKE ? ORDER BY `" + JobsTableFields.level.getCollumn() + "` DESC, LOWER("
@ -2506,10 +2503,8 @@ public abstract class JobsDAO {
while (res.next()) {
PlayerInfo info = Jobs.getPlayerManager().getPlayerInfo(res.getInt(JobsTableFields.userid.getCollumn()));
if (info == null)
continue;
jobs.add(new TopList(info, res.getInt(JobsTableFields.level.getCollumn()), res.getInt(JobsTableFields.experience.getCollumn())));
if (info != null)
jobs.add(new TopList(info, res.getInt(JobsTableFields.level.getCollumn()), res.getInt(JobsTableFields.experience.getCollumn())));
}
} catch (SQLException e) {
e.printStackTrace();

View File

@ -25,10 +25,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.config.YmlMaker;
public class Language {
@ -65,9 +65,9 @@ public class Language {
String msg = "";
try {
if (customlocale == null || !customlocale.contains(key))
msg = enlocale.isString(key) ? Colors(enlocale.getString(key)) : missing;
msg = enlocale.isString(key) ? CMIChatColor.translate(enlocale.getString(key)) : missing;
else
msg = customlocale.isString(key) ? Colors(customlocale.getString(key)) : missing;
msg = customlocale.isString(key) ? CMIChatColor.translate(customlocale.getString(key)) : missing;
} catch (Throwable e) {
Jobs.consoleMsg("&e[Jobs] &2Can't read language file for: " + key);
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
@ -129,7 +129,7 @@ public class Language {
msg = msg.replace(String.valueOf(variables[y]), String.valueOf(variables[y + 1]));
}
msg = filterNewLine(msg);
ls.set(i, Colors(msg));
ls.set(i, CMIChatColor.translate(msg));
}
return ls;
@ -144,28 +144,24 @@ public class Language {
return msg;
}
public List<String> ColorsArray(List<String> text, Boolean colorize) {
public List<String> ColorsArray(List<String> text, boolean colorize) {
List<String> temp = new ArrayList<>();
for (String part : text) {
if (colorize)
part = Colors(part);
temp.add(Colors(part));
part = CMIChatColor.translate(part);
temp.add(CMIChatColor.translate(part));
}
return temp;
}
private String Colors(String text) {
return ChatColor.translateAlternateColorCodes('&', text);
}
/**
* Get the message with the correct key
* @param key - the key of the message
* @return the message
*/
public String getDefaultMessage(String key) {
return enlocale.contains(key) ? Colors(enlocale.getString(key)) : "Can't find locale";
return enlocale.contains(key) ? CMIChatColor.translate(enlocale.getString(key)) : "Can't find locale";
}
/**

View File

@ -2,20 +2,19 @@ package com.gamingmesh.jobs.stuff;
public class PageInfo {
private int totalEntries = 0;
private int totalPages = 0;
private int start = 0;
private int end = 0;
private int currentPage = 0;
private int currentEntry = 0;
private int perPage = 6;
private int totalEntries = 0,
totalPages = 0,
start = 0,
end = 0,
currentPage = 0,
currentEntry = 0,
perPage = 6;
public PageInfo(int perPage, int totalEntries, int currentPage) {
this.perPage = perPage;
this.totalEntries = totalEntries;
this.currentPage = currentPage < 1 ? 1 : currentPage;
calculate();
}
@ -24,21 +23,21 @@ public class PageInfo {
}
public int getPositionForOutput(int place) {
return this.start + place + 1;
return start + place + 1;
}
private void calculate() {
this.start = (this.currentPage - 1) * this.perPage;
this.end = this.start + this.perPage - 1;
if (this.end + 1 > this.totalEntries)
this.end = this.totalEntries - 1;
this.totalPages = (int) Math.ceil((double) this.totalEntries / (double) this.perPage);
start = (currentPage - 1) * perPage;
end = start + perPage - 1;
if (end + 1 > totalEntries)
end = totalEntries - 1;
totalPages = (int) Math.ceil((double) totalEntries / (double) perPage);
}
public boolean isInRange(int place) {
if (place >= start && place <= end)
return true;
return false;
return place >= start && place <= end ? true : false;
}
public boolean isEntryOk() {
@ -59,15 +58,11 @@ public class PageInfo {
}
public boolean isPageOk() {
return isPageOk(this.currentPage);
return isPageOk(currentPage);
}
public boolean isPageOk(int page) {
if (this.totalPages < page)
return false;
if (page < 1)
return false;
return true;
return totalPages < page || page < 1 ? false : true;
}
public int getStart() {
@ -91,10 +86,10 @@ public class PageInfo {
}
public int getNextPageNumber() {
return this.getCurrentPage() + 1 > this.getTotalPages() ? this.getTotalPages() : this.getCurrentPage() + 1;
return currentPage + 1 > totalPages ? totalPages : currentPage + 1;
}
public int getPrevPageNumber() {
return this.getCurrentPage() - 1 < 1 ? 1 : this.getCurrentPage() - 1;
return currentPage - 1 < 1 ? 1 : currentPage - 1;
}
}