mirror of
https://github.com/Zrips/Jobs.git
synced 2025-02-08 08:21:41 +01:00
Improve job schedulers by using runTaskTimer instead of odd sync repeat
Fixes #928
This commit is contained in:
parent
674529e77a
commit
ac11fbed6a
@ -100,14 +100,11 @@ public class Jobs extends JavaPlugin {
|
||||
private static Job noneJob;
|
||||
private static WeakHashMap<Job, Integer> usedSlots = new WeakHashMap<>();
|
||||
private static HashMap<Integer, Job> jobsIds = new HashMap<>();
|
||||
// public static WeakHashMap<String, Double> GlobalBoost = new WeakHashMap<String, Double>();
|
||||
|
||||
private static BufferedEconomy economy;
|
||||
private static PermissionHandler permissionHandler;
|
||||
private static PermissionManager permissionManager;
|
||||
|
||||
// private static ItemManager itemManager;
|
||||
|
||||
public static BufferedPaymentThread paymentThread;
|
||||
private static DatabaseSaveThread saveTask;
|
||||
|
||||
@ -335,7 +332,7 @@ public class Jobs extends JavaPlugin {
|
||||
*/
|
||||
public CMIScoreboardManager getCMIScoreboardManager() {
|
||||
if (cmiScoreboardManager == null)
|
||||
cmiScoreboardManager = new CMIScoreboardManager();
|
||||
cmiScoreboardManager = new CMIScoreboardManager();
|
||||
|
||||
return cmiScoreboardManager;
|
||||
}
|
||||
@ -626,10 +623,6 @@ public class Jobs extends JavaPlugin {
|
||||
return permissionManager;
|
||||
}
|
||||
|
||||
// public static ItemManager getItemManager() {
|
||||
// return itemManager;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Sets the economy handler
|
||||
* @param eco - the economy handler
|
||||
@ -661,8 +654,6 @@ public class Jobs extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
// itemManager = new ItemManager(this);
|
||||
|
||||
try {
|
||||
Class<?> nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + Version.getCurrent().getShortVersion());
|
||||
if (NMS.class.isAssignableFrom(nmsClass)) {
|
||||
@ -693,8 +684,10 @@ public class Jobs extends JavaPlugin {
|
||||
|
||||
bbManager = new BossBarManager(this);
|
||||
|
||||
getCommand("jobs").setExecutor(getCommandManager());
|
||||
getCommand("jobs").setTabCompleter(new TabComplete());
|
||||
Optional.ofNullable(getCommand("jobs")).ifPresent(j -> {
|
||||
j.setExecutor(getCommandManager());
|
||||
j.setTabCompleter(new TabComplete());
|
||||
});
|
||||
|
||||
startup();
|
||||
|
||||
@ -1247,8 +1240,7 @@ public class Jobs extends JavaPlugin {
|
||||
}
|
||||
|
||||
private static int getPlayerExperience(Player player) {
|
||||
int bukkitExp = (ExpToLevel(player.getLevel()) + Math.round(deltaLevelToExp(player.getLevel()) * player.getExp()));
|
||||
return bukkitExp;
|
||||
return (ExpToLevel(player.getLevel()) + Math.round(deltaLevelToExp(player.getLevel()) * player.getExp()));
|
||||
}
|
||||
|
||||
// total xp calculation based by lvl
|
||||
@ -1325,11 +1317,9 @@ public class Jobs extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static boolean hasPermission(Object sender, String perm, boolean rawEnable) {
|
||||
if (!(sender instanceof Player))
|
||||
if (!(sender instanceof Player) || ((Player) sender).hasPermission(perm))
|
||||
return true;
|
||||
|
||||
if (((Player) sender).hasPermission(perm))
|
||||
return true;
|
||||
if (!rawEnable) {
|
||||
((Player) sender).sendMessage(lManager.getMessage("general.error.permission"));
|
||||
return false;
|
||||
|
@ -994,10 +994,12 @@ public class PlayerManager {
|
||||
|
||||
boost.add(BoostOf.Permission, getBoost(player, prog, force));
|
||||
boost.add(BoostOf.Global, prog.getBoost());
|
||||
|
||||
if (Jobs.getGCManager().useDynamicPayment)
|
||||
boost.add(BoostOf.Dynamic, new BoostMultiplier().add(prog.getBonus()));
|
||||
// boost.add(BoostOf.Item, Jobs.getPlayerManager().getItemBoost(player.getPlayer(), prog));
|
||||
|
||||
boost.add(BoostOf.Item, getItemBoostNBT(player.getPlayer(), prog));
|
||||
|
||||
if (!Jobs.getRestrictedAreaManager().getRestrictedAres().isEmpty())
|
||||
boost.add(BoostOf.Area, new BoostMultiplier().add(Jobs.getRestrictedAreaManager().getRestrictedMultiplier(player.getPlayer())));
|
||||
return boost;
|
||||
@ -1014,10 +1016,7 @@ public class PlayerManager {
|
||||
return;
|
||||
|
||||
JobsPlayer jPlayer = getJobsPlayer(player);
|
||||
if (jPlayer == null)
|
||||
return;
|
||||
|
||||
if (player.hasPermission("jobs.*"))
|
||||
if (jPlayer == null || player.hasPermission("jobs.*"))
|
||||
return;
|
||||
|
||||
int confMaxJobs = Jobs.getGCManager().getMaxJobs();
|
||||
|
@ -12,18 +12,19 @@ import com.gamingmesh.jobs.api.JobsScheduleStopEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.container.BoostMultiplier;
|
||||
import com.gamingmesh.jobs.container.CurrencyType;
|
||||
import com.gamingmesh.jobs.container.Job;
|
||||
import com.gamingmesh.jobs.container.Schedule;
|
||||
import com.gamingmesh.jobs.stuff.TimeManage;
|
||||
|
||||
public class ScheduleManager {
|
||||
|
||||
private Jobs plugin;
|
||||
private int autoTimerBukkitId = -1;
|
||||
|
||||
private BukkitTask timer;
|
||||
|
||||
public static final List<Schedule> BOOSTSCHEDULE = new ArrayList<>();
|
||||
|
||||
@ -36,16 +37,12 @@ public class ScheduleManager {
|
||||
return;
|
||||
|
||||
cancel();
|
||||
autoTimerBukkitId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::scheduler, 20, 30 * 20L);
|
||||
timer = Bukkit.getScheduler().runTaskTimer(plugin, this::scheduler, 20, 30 * 20L);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
if (autoTimerBukkitId != -1)
|
||||
Bukkit.getScheduler().cancelTask(autoTimerBukkitId);
|
||||
}
|
||||
|
||||
public int getDateByInt() {
|
||||
return TimeManage.timeInInt();
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
private boolean scheduler() {
|
||||
@ -53,14 +50,11 @@ public class ScheduleManager {
|
||||
return false;
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
Date date = new Date();
|
||||
|
||||
String currenttime = dateFormat.format(date);
|
||||
String currenttime = dateFormat.format(new Date());
|
||||
String CurrentDayName = getWeekDay();
|
||||
|
||||
int Current = Integer.parseInt(currenttime.replace(":", ""));
|
||||
|
||||
String CurrentDayName = getWeekDay();
|
||||
|
||||
for (Schedule one : BOOSTSCHEDULE) {
|
||||
|
||||
int From = one.getFrom();
|
||||
@ -143,9 +137,8 @@ public class ScheduleManager {
|
||||
case 1:
|
||||
return "sunday";
|
||||
default:
|
||||
break;
|
||||
return "all";
|
||||
}
|
||||
return "all";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +156,7 @@ public class ScheduleManager {
|
||||
|
||||
conf.options().copyDefaults(true);
|
||||
|
||||
if (!conf.contains("Boost"))
|
||||
if (!conf.isConfigurationSection("Boost"))
|
||||
return;
|
||||
|
||||
ArrayList<String> sections = new ArrayList<>(conf.getConfigurationSection("Boost").getKeys(false));
|
||||
@ -171,16 +164,13 @@ public class ScheduleManager {
|
||||
for (String OneSection : sections) {
|
||||
ConfigurationSection path = conf.getConfigurationSection("Boost." + OneSection);
|
||||
|
||||
if (!path.getBoolean("Enabled", false))
|
||||
if (path == null || !path.getBoolean("Enabled") || !path.getString("From", "").contains(":")
|
||||
|| !path.getString("Until", "").contains(":") || !path.isList("Days") || !path.isList("Jobs"))
|
||||
continue;
|
||||
|
||||
Schedule sched = new Schedule();
|
||||
|
||||
sched.setName(OneSection);
|
||||
|
||||
if (!path.getString("From", "").contains(":") || !path.getString("Until", "").contains(":")
|
||||
|| !path.isList("Days") || !path.isList("Jobs"))
|
||||
continue;
|
||||
|
||||
sched.setDays(path.getStringList("Days"));
|
||||
sched.setJobs(path.getStringList("Jobs"));
|
||||
sched.setFrom(Integer.valueOf(path.getString("From").replace(":", "")));
|
||||
|
@ -134,7 +134,7 @@ public class TitleManager {
|
||||
int levelReq = titleSection.getInt(titleKey + ".levelReq", -1);
|
||||
|
||||
if (titleSection.isString(titleKey + ".JobName"))
|
||||
jobName = titleSection.getString(titleKey + ".JobName");
|
||||
jobName = titleSection.getString(titleKey + ".JobName", "");
|
||||
|
||||
if (titleName.isEmpty()) {
|
||||
Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid Name property. Skipping!");
|
||||
|
@ -9,13 +9,7 @@ import com.gamingmesh.jobs.CMILib.CMIChatColor;
|
||||
|
||||
public class Schedule {
|
||||
|
||||
private int From = 0;
|
||||
private int Until = 235959;
|
||||
|
||||
private int nextFrom = 0;
|
||||
private int nextUntil = 235959;
|
||||
|
||||
private boolean nextDay = false;
|
||||
private int broadcastInterval = 0, From = 0, Until = 235959, nextFrom = 0, nextUntil = 235959;
|
||||
|
||||
private final BoostMultiplier BM = new BoostMultiplier();
|
||||
|
||||
@ -28,14 +22,9 @@ public class Schedule {
|
||||
MessageOnStop = new ArrayList<>(),
|
||||
MessageToBroadcast = new ArrayList<>();
|
||||
|
||||
private boolean started = false;
|
||||
private boolean stoped = true;
|
||||
|
||||
private boolean onStop = true;
|
||||
private boolean OnStart = true;
|
||||
private boolean nextDay = false, started = false, stoped = true, onStop = true, onStart = true;
|
||||
|
||||
private long broadcastInfoOn = 0L;
|
||||
private int broadcastInterval = 0;
|
||||
|
||||
public Schedule() {
|
||||
}
|
||||
@ -56,12 +45,12 @@ public class Schedule {
|
||||
return onStop;
|
||||
}
|
||||
|
||||
public void setBroadcastOnStart(boolean OnStart) {
|
||||
this.OnStart = OnStart;
|
||||
public void setBroadcastOnStart(boolean onStart) {
|
||||
this.onStart = onStart;
|
||||
}
|
||||
|
||||
public boolean isBroadcastOnStart() {
|
||||
return OnStart;
|
||||
return onStart;
|
||||
}
|
||||
|
||||
public void setStarted(boolean started) {
|
||||
|
@ -1616,10 +1616,8 @@ public class JobsPaymentListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = isBrewingStand ? Jobs.getLanguage().getMessage("general.info.blocks.brewingstand")
|
||||
: isFurnace ? Jobs.getLanguage().getMessage("general.info.blocks.furnace")
|
||||
: cmat == CMIMaterial.SMOKER ? Jobs.getLanguage().getMessage("general.info.blocks.smoker")
|
||||
: cmat == CMIMaterial.BLAST_FURNACE ? Jobs.getLanguage().getMessage("general.info.blocks.blastfurnace") : "";
|
||||
String name = Jobs.getLanguage().getMessage("general.info.blocks." + (isBrewingStand ? "brewingstand" : isFurnace
|
||||
? "furnace" : cmat == CMIMaterial.SMOKER ? "smoker" : cmat == CMIMaterial.BLAST_FURNACE ? "blastfurnace" : ""));
|
||||
ownershipFeedback done = blockOwner.register(p, block);
|
||||
if (done == ownershipFeedback.tooMany) {
|
||||
boolean report = false;
|
||||
|
@ -17,24 +17,18 @@ public class Loging {
|
||||
public void recordToLog(JobsPlayer jPlayer, String ActionName, String item, HashMap<CurrencyType, Double> amounts) {
|
||||
HashMap<String, Log> logList = jPlayer.getLog();
|
||||
Log l = logList.values().stream().findFirst().orElse(null);
|
||||
if (l != null && Jobs.getScheduleManager().getDateByInt() != l.getDate()) {
|
||||
if (l != null && TimeManage.timeInInt() != l.getDate()) {
|
||||
Jobs.getJobsDAO().saveLog(jPlayer);
|
||||
jPlayer.getLog().clear();
|
||||
}
|
||||
Log log = logList.get(ActionName);
|
||||
if (log == null){
|
||||
log = new Log(ActionName);
|
||||
}
|
||||
|
||||
Log log = logList.getOrDefault(ActionName, new Log(ActionName));
|
||||
log.add(item, amounts);
|
||||
logList.put(ActionName, log);
|
||||
}
|
||||
|
||||
public void loadToLog(JobsPlayer jPlayer, String ActionName, String item, int count, HashMap<CurrencyType, Double> amounts) {
|
||||
HashMap<String, Log> logList = jPlayer.getLog();
|
||||
|
||||
Log log = logList.get(ActionName);
|
||||
if (log == null)
|
||||
log = new Log(ActionName);
|
||||
Log log = jPlayer.getLog().getOrDefault(ActionName, new Log(ActionName));
|
||||
log.add(item, count, amounts);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# From and Until is in 24 hours format with : signs to separate minutes and seconds
|
||||
# Exp and Money determines how big is boost, to reset it. keep it at 1.0. so if you use 2.0 that means all money/exp is doubled
|
||||
# Days variables: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, All
|
||||
# Jobs can be any of your settup job or use All to give for all jobs at once
|
||||
# Jobs can be any of your setup job or use All to give for all jobs at once
|
||||
# BroadcastOnStart or BroadcastOnStop - set it false to disable message when boost starts/stops
|
||||
# MessageOnStart or MessageOnStop - optional messages, if not given, then message from locale file will be shown
|
||||
# BroadcastInterval - how often in minutes to broadcast message about money/exp boost for jobs
|
||||
@ -23,12 +23,12 @@ Boost:
|
||||
MessageOnStart:
|
||||
- '&e***********************************************'
|
||||
- '&e* All jobs got 2x rate for exp and money!'
|
||||
- '&e* For limited time only!'
|
||||
- '&e* For limited time only!'
|
||||
- '&e***********************************************'
|
||||
BroadcastOnStop: true
|
||||
MessageOnStop:
|
||||
- '&e***********************************************'
|
||||
- '&e* Boost time for jobs have beed stoped'
|
||||
- '&e* Boost time for jobs have been stopped'
|
||||
- '&e* All rates reseted to original ones'
|
||||
- '&e***********************************************'
|
||||
BroadcastInterval: 15
|
||||
@ -57,7 +57,7 @@ Boost:
|
||||
BroadcastOnStop: true
|
||||
MessageOnStop:
|
||||
- '&e***********************************************'
|
||||
- '&e* Boost time for Miner and Woodcutter have beed stoped'
|
||||
- '&e* Boost time for Miner and Woodcutter have been stopped'
|
||||
- '&e* Money rates reseted to original ones'
|
||||
- '&e***********************************************'
|
||||
BroadcastInterval: 15
|
||||
|
Loading…
Reference in New Issue
Block a user