1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-27 03:17:49 +01:00

Updating feedback messages processing in action and boss bar

New custom async event JobsInstancePaymentEvent to be fired with final
payment amounts for visualization and record purposes
This commit is contained in:
Zrips 2024-08-15 13:21:36 +03:00
parent b537ec4f36
commit 72098ca24c
14 changed files with 435 additions and 274 deletions

View File

@ -45,6 +45,7 @@ import com.gamingmesh.jobs.Placeholders.Placeholder;
import com.gamingmesh.jobs.Placeholders.PlaceholderAPIHook;
import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.api.JobsExpGainEvent;
import com.gamingmesh.jobs.api.JobsInstancePaymentEvent;
import com.gamingmesh.jobs.api.JobsPrePaymentEvent;
import com.gamingmesh.jobs.commands.JobsCommands;
import com.gamingmesh.jobs.config.BlockProtectionManager;
@ -70,7 +71,6 @@ import com.gamingmesh.jobs.container.Boost;
import com.gamingmesh.jobs.container.Convert;
import com.gamingmesh.jobs.container.CurrencyLimit;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.DBAction;
import com.gamingmesh.jobs.container.FastPayment;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo;
@ -101,6 +101,7 @@ import com.gamingmesh.jobs.listeners.JobsPayment1_16Listener;
import com.gamingmesh.jobs.listeners.JobsPayment1_20Listener;
import com.gamingmesh.jobs.listeners.JobsPayment1_9Listener;
import com.gamingmesh.jobs.listeners.JobsPaymentListener;
import com.gamingmesh.jobs.listeners.JobsPaymentVisualizationListener;
import com.gamingmesh.jobs.listeners.PistonProtectionListener;
import com.gamingmesh.jobs.listeners.PlayerSignEdit1_20Listeners;
import com.gamingmesh.jobs.selection.SelectionManager;
@ -115,10 +116,8 @@ import com.gamingmesh.jobs.stuff.complement.JobsChatEvent;
import com.gamingmesh.jobs.tasks.BufferedPaymentThread;
import com.gamingmesh.jobs.tasks.DatabaseSaveThread;
import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Logs.CMIDebug;
import net.Zrips.CMILib.Messages.CMIMessages;
import net.Zrips.CMILib.RawMessages.RawMessage;
import net.Zrips.CMILib.Version.Version;
@ -821,6 +820,7 @@ public final class Jobs extends JavaPlugin {
pm.registerEvents(new JobsListener(getInstance()), getInstance());
pm.registerEvents(new JobsPaymentListener(getInstance()), getInstance());
pm.registerEvents(new JobsPaymentVisualizationListener(getInstance()), getInstance());
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1))
pm.registerEvents(new JobsPayment1_9Listener(), getInstance());
@ -842,7 +842,7 @@ public final class Jobs extends JavaPlugin {
pm.registerEvents(new JobsChatEvent(getInstance()), getInstance());
if(HookManager.checkPyroFishingPro()) {
if (HookManager.checkPyroFishingPro()) {
HookManager.getPyroFishingProManager().registerListener();
}
if (HookManager.getMcMMOManager().CheckmcMMO()) {
@ -1071,8 +1071,7 @@ public final class Jobs extends JavaPlugin {
Boost boost = getPlayerManager().getFinalBonus(jPlayer, noneJob);
JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income,
pointAmount, block, ent, victim, info);
JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), noneJob, income, 0, pointAmount, block, ent, victim, info);
Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent);
// If event is canceled, don't do anything
if (jobsPrePaymentEvent.isCancelled()) {
@ -1145,6 +1144,8 @@ public final class Jobs extends JavaPlugin {
if (pointAmount != 0D)
payments.put(CurrencyType.POINTS, pointAmount);
// FinalPayment event
CMIScheduler.runTaskAsynchronously(() -> Bukkit.getServer().getPluginManager().callEvent(new JobsInstancePaymentEvent(jPlayer.getPlayer(), payments)));
economy.pay(jPlayer, payments);
if (gConfigManager.LoggingUse) {
@ -1207,17 +1208,18 @@ public final class Jobs extends JavaPlugin {
Boost boost = getPlayerManager().getFinalBonus(jPlayer, prog.getJob(), ent, victim);
JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), prog.getJob(), income,
pointAmount, block, ent, victim, info);
JobsPrePaymentEvent jobsPrePaymentEvent = new JobsPrePaymentEvent(jPlayer.getPlayer(), prog.getJob(), income, expAmount, pointAmount, block, ent, victim, info);
Bukkit.getServer().getPluginManager().callEvent(jobsPrePaymentEvent);
// If event is canceled, don't do anything
if (jobsPrePaymentEvent.isCancelled()) {
income = 0D;
pointAmount = 0D;
expAmount = 0D;
} else {
income = jobsPrePaymentEvent.getAmount();
pointAmount = jobsPrePaymentEvent.getPoints();
expAmount = jobsPrePaymentEvent.getExp();
}
// Calculate income
@ -1296,23 +1298,11 @@ public final class Jobs extends JavaPlugin {
continue;
// JobsPayment event
JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount,
block, ent, victim, info);
JobsExpGainEvent jobsExpGainEvent = new JobsExpGainEvent(jPlayer.getPlayer(), prog.getJob(), expAmount, block, ent, victim, info);
Bukkit.getServer().getPluginManager().callEvent(jobsExpGainEvent);
// If event is canceled, don't do anything
expAmount = jobsExpGainEvent.isCancelled() ? 0D : jobsExpGainEvent.getExp();
try {
if (expAmount != 0D && gConfigManager.BossBarEnabled)
if (gConfigManager.BossBarShowOnEachAction)
bbManager.ShowJobProgression(jPlayer, prog, expAmount);
else
jPlayer.getUpdateBossBarFor().add(prog.getJob().getName());
} catch (Throwable e) {
e.printStackTrace();
CMIMessages.consoleMessage("&c[Jobs] Some issues with boss bar feature accured, try disabling it to avoid it.");
}
Map<CurrencyType, Double> payments = new HashMap<>();
if (income != 0D)
payments.put(CurrencyType.MONEY, income);
@ -1321,8 +1311,10 @@ public final class Jobs extends JavaPlugin {
if (expAmount != 0D)
payments.put(CurrencyType.EXP, expAmount);
FASTPAYMENT.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog
.getJob()));
FASTPAYMENT.put(jPlayer.getUniqueId(), new FastPayment(jPlayer, info, new BufferedPayment(jPlayer.getPlayer(), payments), prog.getJob()));
// FinalPayment event
CMIScheduler.runTaskAsynchronously(() -> Bukkit.getServer().getPluginManager().callEvent(new JobsInstancePaymentEvent(jPlayer.getPlayer(), payments)));
economy.pay(jPlayer, payments);
int oldLevel = prog.getLevel();

View File

@ -7,12 +7,19 @@ public class BaseEvent extends Event {
private static final HandlerList handlers = new HandlerList();
public BaseEvent(boolean async) {
super(async);
}
public BaseEvent() {
}
@Override
public HandlerList getHandlers() {
return handlers;
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
return handlers;
}
}

View File

@ -0,0 +1,53 @@
package com.gamingmesh.jobs.api;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import com.gamingmesh.jobs.container.CurrencyType;
public final class JobsInstancePaymentEvent extends BaseEvent {
private OfflinePlayer offlinePlayer;
private Map<CurrencyType, Double> payments = new HashMap<>();
public JobsInstancePaymentEvent(OfflinePlayer offlinePlayer, Map<CurrencyType, Double> payments) {
super(true);
this.offlinePlayer = offlinePlayer;
this.payments = payments;
}
/**
* Returns the player who got payment.
*
* @return {@link OfflinePlayer}
*/
public OfflinePlayer getPlayer() {
return offlinePlayer;
}
/**
* Returns the primitive type of payment of the given
* currency type if exist, otherwise returns 0.
*
* @param type {@link CurrencyType}
* @return the amount of payment from specific {@link CurrencyType}
*/
public double get(CurrencyType type) {
return payments.getOrDefault(type, 0D);
}
/**
* Returns all cached payment returned as {@link Map}.
*
* @return {@link Map}
*/
public Map<CurrencyType, Double> getPayment() {
return payments;
}
}

View File

@ -1,7 +1,12 @@
package com.gamingmesh.jobs.api;
import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
@ -13,8 +18,7 @@ import org.bukkit.event.Cancellable;
*/
public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable {
private OfflinePlayer offlinePlayer;
private double money;
private double points;
Map<CurrencyType, Double> amounts = new HashMap<>();
private Job job;
private Block block;
private Entity entity;
@ -24,22 +28,27 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
@Deprecated
public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points) {
this.job = job;
this.offlinePlayer = offlinePlayer;
this.money = money;
this.points = points;
this.job = job;
this.offlinePlayer = offlinePlayer;
amounts.put(CurrencyType.MONEY, money);
amounts.put(CurrencyType.POINTS, points);
}
public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points, Block block,
Entity entity, LivingEntity living, ActionInfo info) {
this.job = job;
this.offlinePlayer = offlinePlayer;
this.money = money;
this.points = points;
this.block = block;
this.entity = entity;
this.living = living;
this.info = info;
@Deprecated
public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double points, Block block, Entity entity, LivingEntity living, ActionInfo info) {
this(offlinePlayer, job, money, 0, points, block, entity, living, info);
}
public JobsPrePaymentEvent(OfflinePlayer offlinePlayer, Job job, double money, double exp, double points, Block block, Entity entity, LivingEntity living, ActionInfo info) {
this.job = job;
this.offlinePlayer = offlinePlayer;
amounts.put(CurrencyType.MONEY, money);
amounts.put(CurrencyType.EXP, exp);
amounts.put(CurrencyType.POINTS, points);
this.block = block;
this.entity = entity;
this.living = living;
this.info = info;
}
/**
@ -48,7 +57,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return {@link OfflinePlayer}
*/
public OfflinePlayer getPlayer() {
return offlinePlayer;
return offlinePlayer;
}
/**
@ -57,7 +66,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return expected income before calculations
*/
public double getAmount() {
return money;
return amounts.getOrDefault(CurrencyType.MONEY, 0D);
}
/**
@ -66,7 +75,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return expected points before calculations
*/
public double getPoints() {
return points;
return amounts.getOrDefault(CurrencyType.POINTS, 0D);
}
/**
@ -75,7 +84,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return {@link Job}
*/
public Job getJob() {
return job;
return job;
}
/**
@ -84,7 +93,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @param money new amount
*/
public void setAmount(double money) {
this.money = money;
amounts.put(CurrencyType.MONEY, money);
}
/**
@ -93,7 +102,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @param points
*/
public void setPoints(double points) {
this.points = points;
amounts.put(CurrencyType.POINTS, points);
}
/**
@ -102,7 +111,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return {@link Block}
*/
public Block getBlock() {
return block;
return block;
}
/**
@ -113,7 +122,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return {@link Entity}
*/
public Entity getEntity() {
return entity;
return entity;
}
/**
@ -122,7 +131,7 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return {@link LivingEntity}
*/
public LivingEntity getLivingEntity() {
return living;
return living;
}
/**
@ -131,16 +140,34 @@ public final class JobsPrePaymentEvent extends BaseEvent implements Cancellable
* @return {@link ActionInfo}
*/
public ActionInfo getActionInfo() {
return info;
return info;
}
@Override
public boolean isCancelled() {
return cancelled;
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
this.cancelled = cancelled;
}
/**
* Returns the amount of expected exp.
*
* @return expected exp before calculations
*/
public double getExp() {
return amounts.getOrDefault(CurrencyType.EXP, 0D);
}
/**
* Sets a new exp amount before calculations.
*
* @param exp
*/
public void setExp(double exp) {
amounts.put(CurrencyType.EXP, exp);
}
}

View File

@ -1,6 +1,8 @@
package com.gamingmesh.jobs.commands.list;
import java.util.UUID;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -28,34 +30,31 @@ public class toggle implements Cmd {
}
Player player = (Player) sender;
String playerUUID = player.getUniqueId().toString();
UUID playerUUID = player.getUniqueId();
if (isActionbar) {
Boolean ex = ToggleBarHandling.getActionBarToggle().get(playerUUID);
boolean ex = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID, Jobs.getGCManager().ActionBarsMessageByDefault);
if (ex == null || ex.booleanValue()) {
ToggleBarHandling.getActionBarToggle().put(playerUUID, false);
if (ex) {
Language.sendMessage(sender, "command.toggle.output.off");
} else {
ToggleBarHandling.getActionBarToggle().put(playerUUID, true);
Language.sendMessage(sender, "command.toggle.output.on");
}
ToggleBarHandling.getActionBarToggle().put(playerUUID, !ex);
}
if (isBossbar) {
Boolean ex = ToggleBarHandling.getBossBarToggle().get(playerUUID);
boolean ex = ToggleBarHandling.getBossBarToggle().getOrDefault(playerUUID, Jobs.getGCManager().BossBarsMessageByDefault);
if (ex == null || ex.booleanValue()) {
ToggleBarHandling.getBossBarToggle().put(playerUUID, false);
if (ex) {
Language.sendMessage(sender, "command.toggle.output.off");
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player.getUniqueId());
if (jPlayer != null)
jPlayer.hideBossBars();
} else {
ToggleBarHandling.getBossBarToggle().put(playerUUID, true);
Language.sendMessage(sender, "command.toggle.output.on");
}
ToggleBarHandling.getBossBarToggle().put(playerUUID, !ex);
}
return true;

View File

@ -39,17 +39,13 @@ public class BossBarManager {
if (Version.getCurrent().isLower(Version.v1_9_R1) || !Jobs.getGCManager().BossBarsMessageByDefault)
return;
if (!ToggleBarHandling.getBossBarToggle().getOrDefault(player.getUniqueId().toString(), true))
if (!ToggleBarHandling.getBossBarToggle().getOrDefault(player.getUniqueId(), true))
return;
if (Jobs.getGCManager().isBossBarAsync()) {
CMIScheduler.get().runTaskAsynchronously(() -> ShowJobProgressionInTask(player, jobProg, expGain));
} else {
ShowJobProgressionInTask(player, jobProg, expGain);
}
showJobProgressionInTask(player, jobProg, expGain);
}
private synchronized void ShowJobProgressionInTask(final JobsPlayer player, final JobProgression jobProg, double expGain) {
private static synchronized void showJobProgressionInTask(final JobsPlayer player, final JobProgression jobProg, double expGain) {
BossBar bar = null;
BossBarInfo oldOne = null;
for (BossBarInfo one : player.getBossBarInfo()) {
@ -76,54 +72,7 @@ public class BossBarManager {
"%gain%", gain);
if (bar == null) {
BarColor color = getColor(jobProg.getJob());
if (color == null) {
switch (player.getBossBarInfo().size()) {
case 1:
color = BarColor.GREEN;
break;
case 2:
color = BarColor.RED;
break;
case 3:
color = BarColor.WHITE;
break;
case 4:
color = BarColor.YELLOW;
break;
case 5:
color = BarColor.PINK;
break;
case 6:
color = BarColor.PURPLE;
break;
default:
color = BarColor.BLUE;
break;
}
}
BarStyle style;
switch (Jobs.getGCManager().SegmentCount) {
case 1:
style = BarStyle.SOLID;
break;
case 6:
style = BarStyle.SEGMENTED_6;
break;
case 10:
style = BarStyle.SEGMENTED_10;
break;
case 12:
style = BarStyle.SEGMENTED_12;
break;
case 20:
style = BarStyle.SEGMENTED_20;
break;
default:
style = BarStyle.SOLID;
break;
}
bar = Bukkit.createBossBar(message, color, style);
bar = initBossBar(player, jobProg, message);
} else
bar.setTitle(message);
@ -157,6 +106,57 @@ public class BossBarManager {
jobProg.setLastExperience(0D);
}
private static BossBar initBossBar(final JobsPlayer player, final JobProgression jobProg, String message) {
BarColor color = getColor(jobProg.getJob());
if (color == null) {
switch (player.getBossBarInfo().size()) {
case 1:
color = BarColor.GREEN;
break;
case 2:
color = BarColor.RED;
break;
case 3:
color = BarColor.WHITE;
break;
case 4:
color = BarColor.YELLOW;
break;
case 5:
color = BarColor.PINK;
break;
case 6:
color = BarColor.PURPLE;
break;
default:
color = BarColor.BLUE;
break;
}
}
BarStyle style;
switch (Jobs.getGCManager().SegmentCount) {
case 1:
style = BarStyle.SOLID;
break;
case 6:
style = BarStyle.SEGMENTED_6;
break;
case 10:
style = BarStyle.SEGMENTED_10;
break;
case 12:
style = BarStyle.SEGMENTED_12;
break;
case 20:
style = BarStyle.SEGMENTED_20;
break;
default:
style = BarStyle.SOLID;
break;
}
return Bukkit.createBossBar(message, color, style);
}
private static BarColor getColor(Job job) {
if (job.getBossbar() == null)
return null;

View File

@ -104,15 +104,17 @@ public class GeneralConfigManager {
applyToNegativeIncome, useMinimumOveralPayment, useMinimumOveralPoints, useMinimumOveralExp, useBreederFinder,
CancelCowMilking, fixAtMaxLevel, TitleChangeChat, TitleChangeActionBar, LevelChangeChat,
LevelChangeActionBar, SoundLevelupUse, SoundTitleChangeUse, UseServerAccount, EmptyServerAccountChat,
EmptyServerAccountActionBar, ActionBarsMessageByDefault, aBarSilentMode, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment,
EmptyServerAccountActionBar, ActionBarsMessageByDefault, ShowTotalWorkers, ShowPenaltyBonus, useDynamicPayment,
JobsGUIOpenOnBrowse, JobsGUIShowChatBrowse, JobsGUISwitcheButtons, ShowActionNames, hideItemAttributes,
DisableJoiningJobThroughGui, FireworkLevelupUse, UseRandom, UsePerPermissionForLeaving,
EnableConfirmation, jobsInfoOpensBrowse, MonsterDamageUse, MonsterDamageIgnoreBosses, useMaxPaymentCurve, blockOwnershipTakeOver,
hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel, RomanNumbers,
BossBarEnabled = false, BossBarShowOnEachAction = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse,
BossBarEnabled = false, BossBarsMessageByDefault = false, ExploreCompact, ExploreSaveIntoDatabase = false, DBCleaningJobsUse, DBCleaningUsersUse,
DisabledWorldsUse, UseAsWhiteListWorldList, MythicMobsEnabled,
LoggingUse, payForCombiningItems, BlastFurnacesReassign = false, SmokerReassign = false, payForStackedEntities, payForAbove = false,
payForEachVTradeItem, allowEnchantingBoostedItems, bossBarAsync = false, preventShopItemEnchanting;
payForEachVTradeItem, allowEnchantingBoostedItems, preventShopItemEnchanting;
public int ActionBarsMessageKeepFor;
public boolean jobsshopenabled;
public boolean DailyQuestsEnabled;
@ -410,12 +412,6 @@ public class GeneralConfigManager {
c.addComment("Optimizations.RomanNumbers", "Enabling this option some places will indicate players level as XIV instead of 14", "Only or player levels");
RomanNumbers = c.get("Optimizations.RomanNumbers", false);
// c.addComment("Optimizations.UseLocalOfflinePlayersData", "With this set to true, offline player data will be taken from local player data files",
// "This will eliminate small lag spikes when request is being send to mojangs servers for offline players data",
// "Theroticali this should work without issues, but if you havving some, just disable",
// "But then you can feal some small (100-200ms) lag spikes while performings some jobs commands");
// LocalOfflinePlayersData = c.get("Optimizations.UseLocalOfflinePlayersData", true);
c.addComment("Optimizations.DisabledWorlds.Use", "By setting this to true, Jobs plugin will be disabled in given worlds",
"Only commands can be performed from disabled worlds with jobs.disabledworld.commands permission node");
DisabledWorldsUse = c.get("Optimizations.DisabledWorlds.Use", false);
@ -425,9 +421,9 @@ public class GeneralConfigManager {
DisabledWorldsList = c.get("Optimizations.DisabledWorlds.List", Arrays.asList("Example", "Worlds"));
CMIList.toLowerCase(DisabledWorldsList);
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
if (Version.isCurrentEqualOrHigher(Version.v1_16_R1)) {
c.addComment("Optimizations.Explore.NewMethod",
"Do you want to use new exploration tracking method. Only for 1.14+ servers");
"Do you want to use new exploration tracking method. Only for 1.16+ servers");
useNewExploration = c.get("Optimizations.Explore.NewMethod", true);
}
@ -993,8 +989,10 @@ public class GeneralConfigManager {
c.addComment("ActionBars.Messages.EnabledByDefault", "When this set to true player will see action bar messages by default",
"When false, players will see chat messages instead.");
ActionBarsMessageByDefault = c.get("ActionBars.Messages.EnabledByDefault", true);
c.addComment("ActionBars.Messages.SilentMode", "If true, should we mute the payment messages from appearing in chat if actionbar is disabled?");
aBarSilentMode = c.get("ActionBars.Messages.SilentMode", false);
c.addComment("ActionBars.Messages.KeepFor", "Time in seconds action bar will remain visible if enabled",
"This time is used to define for how long we will accumulate payments to be shown in action bar",
"If no payments are being issued in defined time then it will reset to 0 and remain hidden");
ActionBarsMessageKeepFor = c.get("ActionBars.Messages.KeepFor", 5);
if (Version.isCurrentEqualOrHigher(Version.v1_9_R1)) {
c.addComment("BossBar.Enabled", "Enables BossBar feature", "Works only from 1.9 mc version");
@ -1003,16 +1001,10 @@ public class GeneralConfigManager {
c.addComment("BossBar.Messages.EnabledByDefault", "When this set to true player will see Bossbar messages by default");
BossBarsMessageByDefault = c.get("BossBar.Messages.EnabledByDefault", true);
c.addComment("BossBar.ShowOnEachAction", "If enabled boss bar will update after each action",
"If disabled, BossBar will update only on each payment. This can save some server resources");
BossBarShowOnEachAction = c.get("BossBar.ShowOnEachAction", false);
c.addComment("BossBar.SegmentCount", "Defines in how many parts bossbar will be split visually", "Valid options: 1, 6, 10, 12, 20");
SegmentCount = c.get("BossBar.SegmentCount", 1);
c.addComment("BossBar.Timer", "How long in sec to show BossBar for player",
"If you have disabled ShowOnEachAction, then keep this number higher than payment interval for better experience");
BossBarTimer = c.get("BossBar.Timer", economyBatchDelay + 1);
c.addComment("BossBar.Async", "If enabled, bossbar creation and management will be asynchronous.", "This avoids TPS drops when the ShowOnEachAction option is activated.");
bossBarAsync = c.get("BossBar.Async", false);
c.addComment("BossBar.Timer", "How long in sec to show BossBar for player");
BossBarTimer = c.get("BossBar.Timer", 5);
}
c.addComment("ShowActionBars", "You can enable/disable message shown for players in action bar");
@ -1314,10 +1306,6 @@ public class GeneralConfigManager {
return InformDuplicates;
}
public boolean isBossBarAsync() {
return bossBarAsync;
}
public boolean isDailyQuestsUseGUI() {
return DailyQuestsUseGUI;
}

View File

@ -648,10 +648,11 @@ public class LanguageManager {
c.get("command.toggle.help.args", "actionbar/bossbar");
Jobs.getGCManager().getCommandArgs().put("toggle", Arrays.asList("actionbar%%bossbar"));
c.get("command.toggle.output.turnedoff", "&4This feature is turned off!");
c.get("command.toggle.output.paid.main", "&aYou got:");
c.get("command.toggle.output.paid.money", "&e[amount] money");
c.get("command.toggle.output.paid.exp", "&7[exp] exp");
c.get("command.toggle.output.paid.points", "&6[points] points");
c.get("command.toggle.output.paid.ACmoney", "&e+[amount]$ ");
c.get("command.toggle.output.paid.ACexp", "&7+[exp]XP ");
c.get("command.toggle.output.paid.ACpoints", "&6+[points]pts ");
c.get("command.toggle.output.on", "&aToggled: &aON");
c.get("command.toggle.output.off", "&aToggled: &4OFF");

View File

@ -351,7 +351,6 @@ public class Job {
if (!info.isInLevelRange(level)) {
break;
}
return info;
}

View File

@ -220,12 +220,6 @@ public class BufferedEconomy {
else
CMIScheduler.get().runTaskLater(new BufferedPaymentTask(this, economy, payment), i);
// Show players payment stuff
showPayment(payment);
if (Version.getCurrent().isHigher(Version.v1_8_R3) && payment.getOfflinePlayer().isOnline()) {
Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(payment.getOfflinePlayer().getUniqueId()));
}
} catch (Throwable e) {
e.printStackTrace();
}
@ -242,7 +236,6 @@ public class BufferedEconomy {
*/
@Deprecated
public void showActionBar(BufferedPayment payment) {
showPayment(payment);
}
/**
@ -250,43 +243,7 @@ public class BufferedEconomy {
*
* @param payment {@link BufferedPayment}
*/
@Deprecated
public void showPayment(BufferedPayment payment) {
if (payment.getOfflinePlayer() == null || !payment.getOfflinePlayer().isOnline()
|| !payment.containsPayment())
return;
UUID playerUUID = payment.getOfflinePlayer().getUniqueId();
Player abp = Bukkit.getPlayer(playerUUID);
if (abp == null) {
return;
}
String message = Jobs.getLanguage().getMessage("command.toggle.output.paid.main");
double money = payment.get(CurrencyType.MONEY);
if (money != 0D) {
message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.money", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(),
money));
}
double points = payment.get(CurrencyType.POINTS);
if (points != 0D) {
message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.points", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(),
points));
}
double exp = payment.get(CurrencyType.EXP);
if (exp != 0D) {
message += " " + Jobs.getLanguage().getMessage("command.toggle.output.paid.exp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(),
exp));
}
// Whether or not to show this on player actionbar or on chat
boolean showInActionbar = ToggleBarHandling.getActionBarToggle().getOrDefault(playerUUID.toString(),
Jobs.getGCManager().ActionBarsMessageByDefault);
if (showInActionbar) {
CMIActionBar.send(abp, message);
} else if (!Jobs.getGCManager().aBarSilentMode) {
abp.sendMessage(message);
}
}
}

View File

@ -76,6 +76,8 @@ import com.gamingmesh.jobs.Signs.SignUtil;
import com.gamingmesh.jobs.Signs.jobsSign;
import com.gamingmesh.jobs.api.JobsAreaSelectionEvent;
import com.gamingmesh.jobs.api.JobsChunkChangeEvent;
import com.gamingmesh.jobs.api.JobsInstancePaymentEvent;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobLimitedItems;
import com.gamingmesh.jobs.container.JobProgression;

View File

@ -0,0 +1,144 @@
/**
* 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.listeners;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.api.JobsInstancePaymentEvent;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.stuff.ToggleBarHandling;
import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Version.Version;
public class JobsPaymentVisualizationListener implements Listener {
private Jobs plugin;
public JobsPaymentVisualizationListener(Jobs plugin) {
this.plugin = plugin;
}
ConcurrentHashMap<UUID, paymentCache> paymentCaches = new ConcurrentHashMap<>();
class paymentCache {
private long lastAction = 0l;
private ConcurrentHashMap<CurrencyType, Double> accumulation = new ConcurrentHashMap<>();
private ConcurrentHashMap<CurrencyType, Double> lastPayment = new ConcurrentHashMap<>();
public long getLastAction() {
return lastAction;
}
public void setLastAction() {
this.lastAction = System.currentTimeMillis();
}
public ConcurrentHashMap<CurrencyType, Double> getPayments() {
return accumulation;
}
public void addPayments(Map<CurrencyType, Double> payments) {
if (lastAction + (Jobs.getGCManager().ActionBarsMessageKeepFor * 1000L) < System.currentTimeMillis()) {
accumulation.clear();
}
setLastAction();
payments.forEach((currency, amount) -> accumulation.merge(currency, amount, Double::sum));
lastPayment.clear();
lastPayment.putAll(payments);
}
}
private paymentCache getPaymentCache(UUID uuid, Map<CurrencyType, Double> payments) {
paymentCache cache = paymentCaches.computeIfAbsent(uuid, k -> new paymentCache());
cache.addPayments(payments);
return cache;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
paymentCaches.remove(event.getPlayer().getUniqueId());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJobsInstancePaymentBossEvent(JobsInstancePaymentEvent event) {
if (event.getPlayer() == null || !event.getPlayer().isOnline())
return;
if (!Version.getCurrent().isHigher(Version.v1_8_R3))
return;
Jobs.getBBManager().ShowJobProgression(Jobs.getPlayerManager().getJobsPlayer(event.getPlayer().getUniqueId()));
}
@EventHandler(priority = EventPriority.MONITOR)
public void onJobsInstancePaymentActionBarEvent(JobsInstancePaymentEvent event) {
if (event.getPlayer() == null || !event.getPlayer().isOnline())
return;
Player player = Bukkit.getPlayer(event.getPlayer().getUniqueId());
if (player == null)
return;
// Whether or not to show this on player actionbar or on chat
boolean showInActionbar = ToggleBarHandling.getActionBarToggle().getOrDefault(player.getUniqueId(), Jobs.getGCManager().ActionBarsMessageByDefault);
if (!showInActionbar)
return;
paymentCache cached = getPaymentCache(player.getUniqueId(), event.getPayment());
ConcurrentHashMap<CurrencyType, Double> payment = cached.getPayments();
StringBuilder message = new StringBuilder();
double money = payment.get(CurrencyType.MONEY);
if (money != 0D)
message.append(Jobs.getLanguage().getMessage("command.toggle.output.paid.ACmoney", "[amount]", String.format(Jobs.getGCManager().getDecimalPlacesMoney(), money)));
double exp = payment.get(CurrencyType.EXP);
if (exp != 0D)
message.append(Jobs.getLanguage().getMessage("command.toggle.output.paid.ACexp", "[exp]", String.format(Jobs.getGCManager().getDecimalPlacesExp(), exp)));
double points = payment.get(CurrencyType.POINTS);
if (points != 0D)
message.append(Jobs.getLanguage().getMessage("command.toggle.output.paid.ACpoints", "[points]", String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points)));
if (!message.toString().isEmpty())
CMIActionBar.send(player, message.toString(), Jobs.getGCManager().ActionBarsMessageKeepFor);
}
}

View File

@ -3,6 +3,7 @@ package com.gamingmesh.jobs.stuff;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
@ -12,96 +13,103 @@ import com.gamingmesh.jobs.config.YmlMaker;
public class ToggleBarHandling {
static Map<String, Boolean> actionBarToggle = new HashMap<>();
static Map<String, Boolean> bossBarToggle = new HashMap<>();
static Map<UUID, Boolean> actionBarToggle = new HashMap<>();
static Map<UUID, Boolean> bossBarToggle = new HashMap<>();
public static void load() {
YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml");
if (!f.exists())
return;
YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml");
if (!f.exists())
return;
FileConfiguration config = f.getConfig();
FileConfiguration config = f.getConfig();
if (Jobs.getGCManager().BossBarEnabled) {
ConfigurationSection section = config.getConfigurationSection("bossBar");
if (Jobs.getGCManager().BossBarEnabled) {
ConfigurationSection section = config.getConfigurationSection("bossBar");
if (section != null) {
for (String one : section.getKeys(false)) {
boolean boo = section.getBoolean(one);
if (!boo) {
bossBarToggle.put(one, boo);
}
}
}
}
if (section != null) {
for (String one : section.getKeys(false)) {
boolean boo = section.getBoolean(one);
if (boo)
continue;
if (Jobs.getGCManager().ActionBarsMessageByDefault) {
ConfigurationSection section = config.getConfigurationSection("actionBar");
try {
bossBarToggle.put(UUID.fromString(one), boo);
} catch (Throwable e) {
}
}
}
}
if (section != null) {
for (String one : section.getKeys(false)) {
boolean boo = section.getBoolean(one);
if (!boo) {
actionBarToggle.put(one, boo);
}
}
}
}
if (Jobs.getGCManager().ActionBarsMessageByDefault) {
ConfigurationSection section = config.getConfigurationSection("actionBar");
if (section != null) {
for (String one : section.getKeys(false)) {
boolean boo = section.getBoolean(one);
if (boo)
continue;
try {
actionBarToggle.put(UUID.fromString(one), boo);
} catch (Throwable e) {
}
}
}
}
}
public static void save() {
YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml");
YmlMaker f = new YmlMaker(Jobs.getFolder(), "actionBarBossbar.yml");
if (bossBarToggle.isEmpty() && actionBarToggle.isEmpty()) {
if (f.exists() && f.getConfigFile().length() == 0L) {
f.getConfigFile().delete();
}
if (bossBarToggle.isEmpty() && actionBarToggle.isEmpty()) {
if (f.exists() && f.getConfigFile().length() == 0L) {
f.getConfigFile().delete();
}
return;
}
return;
}
if (!f.exists())
f.createNewFile();
if (!f.exists())
f.createNewFile();
f.saveDefaultConfig();
f.saveDefaultConfig();
FileConfiguration config = f.getConfig();
FileConfiguration config = f.getConfig();
if (Jobs.getGCManager().BossBarEnabled) {
config.set("bossBar", null);
if (Jobs.getGCManager().BossBarEnabled) {
config.set("bossBar", null);
if (!bossBarToggle.isEmpty()) {
for (Entry<String, Boolean> one : bossBarToggle.entrySet()) {
if (!one.getValue()) {
config.set("bossBar." + one.getKey(), one.getValue());
}
}
}
}
if (!bossBarToggle.isEmpty()) {
for (Entry<UUID, Boolean> one : bossBarToggle.entrySet()) {
if (!one.getValue()) {
config.set("bossBar." + one.getKey().toString(), one.getValue());
}
}
}
}
if (Jobs.getGCManager().ActionBarsMessageByDefault) {
config.set("actionBar", null);
if (Jobs.getGCManager().ActionBarsMessageByDefault) {
config.set("actionBar", null);
if (!actionBarToggle.isEmpty()) {
for (Entry<String, Boolean> one : actionBarToggle.entrySet()) {
if (!one.getValue()) {
config.set("actionBar." + one.getKey(), one.getValue());
}
}
}
}
if (!actionBarToggle.isEmpty()) {
for (Entry<UUID, Boolean> one : actionBarToggle.entrySet()) {
if (!one.getValue()) {
config.set("actionBar." + one.getKey().toString(), one.getValue());
}
}
}
}
bossBarToggle.clear();
actionBarToggle.clear();
bossBarToggle.clear();
actionBarToggle.clear();
f.saveConfig();
f.saveConfig();
}
public static Map<String, Boolean> getActionBarToggle() {
return actionBarToggle;
public static Map<UUID, Boolean> getActionBarToggle() {
return actionBarToggle;
}
public static Map<String, Boolean> getBossBarToggle() {
return bossBarToggle;
public static Map<UUID, Boolean> getBossBarToggle() {
return bossBarToggle;
}
}

View File

@ -17,8 +17,6 @@ blocksTimer:
JUNGLE_LEAVES: 60
GRASS: 60
TALL_GRASS: 60
GRASS_BLOCK: 60
GRASS_PATH: 60
SEAGRASS: 60
DEAD_BUSH: 60
RAIL: 60
@ -37,18 +35,6 @@ blocksTimer:
TORCH: 60
REDSTONE_TORCH: 60
LADDER: 5
LIGHT_BLUE_CARPET: 60
LIGHT_GRAY_CARPET: 60
LIME_CARPET: 60
MAGENTA_CARPET: 60
ORANGE_CARPET: 60
PINK_CARPET: 60
BLACK_CARPET: 60
BLUE_CARPET: 60
BROWN_CARPET: 60
CYAN_CARPET: 60
GRAY_CARPET: 60
GREEN_CARPET: 60
OAK_BUTTON: 5
SPRUCE_BUTTON: 5
STONE_BUTTON: 60
@ -57,8 +43,6 @@ blocksTimer:
DARK_OAK_BUTTON: 60
JUNGLE_BUTTON: 60
LEVER: 60
SNOW: 60
SNOW_BLOCK: 60
TRIPWIRE_HOOK: 60
REPEATER: 60
COMPARATOR: 60