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

Lets add separate option for reassign smokers & blast furnace

Closes #545

- Document JobsPaymentEvent about deprecated methods
This commit is contained in:
montlikadani 2020-08-18 19:08:43 +02:00
parent 466b1ce704
commit a1840098ba
7 changed files with 84 additions and 33 deletions

View File

@ -53,6 +53,8 @@ public class PermissionManager {
jobs_spawner_AMOUNT(remade("jobs.nearspawner.%AMOUNT%"), 60 * 1000),
jobs_petpay_AMOUNT(remade("jobs.petpay.%AMOUNT%"), 60 * 1000),
jobs_maxfurnaces_AMOUNT(remade("jobs.maxfurnaces.%AMOUNT%"), 2 * 1000),
jobs_maxblastfurnaces_AMOUNT(remade("jobs.maxblastfurnaces.%AMOUNT%"), 2 * 1000),
jobs_maxsmokers_AMOUNT(remade("jobs.maxsmokers.%AMOUNT%"), 2 * 1000),
jobs_maxbrewingstands_AMOUNT(remade("jobs.maxbrewingstands.%AMOUNT%"), 2 * 1000),
jobs_world_WORLDNAME(remade("jobs.world.%WORLDNAME%"), 2 * 1000);

View File

@ -15,6 +15,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.container.CurrencyType;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobProgression;
@ -409,7 +410,7 @@ public class Placeholder {
case user_furncount:
return Integer.toString(user.getFurnaceCount());
case user_maxfurncount:
return Integer.toString(user.getMaxFurnacesAllowed());
return Integer.toString(user.getMaxFurnacesAllowed(CMIMaterial.FURNACE));
case user_doneq:
return Integer.toString(user.getDoneQuests());
case user_seen:

View File

@ -14,7 +14,7 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
private OfflinePlayer offlinePlayer;
private boolean cancelled = false;
private HashMap<CurrencyType, Double> payments = new HashMap<CurrencyType, Double>();
private HashMap<CurrencyType, Double> payments = new HashMap<>();
@Deprecated
public JobsPaymentEvent(OfflinePlayer offlinePlayer, double money, double points) {
@ -34,35 +34,47 @@ public final class JobsPaymentEvent extends Event implements Cancellable {
return offlinePlayer;
}
/**
* @deprecated use {@link #get(CurrencyType)}
*/
@Deprecated
public Double getAmount() {
Double amount = this.payments.get(CurrencyType.MONEY);
return amount == null ? 0 : amount;
}
/**
* @deprecated use {@link #get(CurrencyType)}
*/
@Deprecated
public double getPoints() {
Double amount = this.payments.get(CurrencyType.POINTS);
return amount == null ? 0 : amount;
}
/**
* @deprecated use {@link #set(CurrencyType, double)
*/
@Deprecated
public void setAmount(double amount) {
this.payments.put(CurrencyType.MONEY, amount);
payments.put(CurrencyType.MONEY, amount);
}
/**
* @deprecated use {@link #set(CurrencyType, double)
*/
@Deprecated
public void setPoints(double points) {
this.payments.put(CurrencyType.POINTS, points);
}
public Double get(CurrencyType type) {
Double amount = this.payments.get(type);
Double amount = payments.get(type);
return amount == null ? 0 : amount;
}
public Double set(CurrencyType type, double amount) {
return this.payments.put(type, amount);
return payments.put(type, amount);
}
public HashMap<CurrencyType, Double> getPayment() {

View File

@ -69,7 +69,7 @@ public class GeneralConfigManager {
public int jobExpiryTime, BlockProtectionDays, FireworkPower, ShootTime,
globalblocktimer, CowMilkingTimer, InfoUpdateInterval, JobsTopAmount, PlaceholdersPage, ConfirmExpiryTime,
SegmentCount, BossBarTimer, AutoJobJoinDelay, DBCleaningJobsLvl, DBCleaningUsersDays;
SegmentCount, BossBarTimer, AutoJobJoinDelay, DBCleaningJobsLvl, DBCleaningUsersDays, BlastFurnacesMaxDefault, SmokersMaxDefault;
protected int savePeriod, maxJobs, economyBatchDelay;
private int ResetTimeHour, ResetTimeMinute, DailyQuestsSkips, FurnacesMaxDefault, BrewingStandsMaxDefault,
BrowseAmountToShow, JobsGUIRows, JobsGUIBackButton, JobsGUINextButton, JobsGUIStartPosition, JobsGUIGroupAmount, JobsGUISkipAmount;
@ -101,7 +101,7 @@ public class GeneralConfigManager {
hideJobsInfoWithoutPermission, UseTaxes, TransferToServerAccount, TakeFromPlayersPayment, AutoJobJoinUse, AllowDelevel,
BossBarEnabled, BossBarShowOnEachAction, BossBarsMessageByDefault, ExploreCompact, DBCleaningJobsUse, DBCleaningUsersUse,
DisabledWorldsUse, UseAsWhiteListWorldList, PaymentMethodsMoney, PaymentMethodsPoints, PaymentMethodsExp, MythicMobsEnabled,
LoggingUse, payForCombiningItems;
LoggingUse, payForCombiningItems, BlastFurnacesReassign, SmokerReassign;
public ItemStack guiBackButton, guiNextButton, guiFiller;
@ -785,6 +785,14 @@ public class GeneralConfigManager {
"This can be overridden with jobs.maxfurnaces.[amount] permission node");
FurnacesMaxDefault = c.get("ExploitProtections.Furnaces.MaxDefaultAvailable", 20);
if (Version.isCurrentEqualOrHigher(Version.v1_14_R1)) {
BlastFurnacesReassign = c.get("ExploitProtections.BlastFurnaces.Reassign", false);
BlastFurnacesMaxDefault = c.get("ExploitProtections.BlastFurnaces.MaxDefaultAvailable", 15);
SmokerReassign = c.get("ExploitProtections.Smokers.Reassign", false);
SmokersMaxDefault = c.get("ExploitProtections.Smokers.MaxDefaultAvailable", 15);
}
c.addComment("ExploitProtections.BrewingStands.Reassign",
"When enabled, players interacted brewing stands will be saved into file and will be reassigned after restart to keep giving out money",
"Players will no longer need to click on brewing stand to get paid from it after server restart");

View File

@ -33,6 +33,7 @@ import org.bukkit.entity.Player;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMILib.ActionBarManager;
import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.Signs.SignTopType;
import com.gamingmesh.jobs.dao.JobsDAO;
import com.gamingmesh.jobs.economy.PaymentData;
@ -318,9 +319,7 @@ public class JobsPlayer {
* Reloads max experience for this job.
*/
public void reloadMaxExperience() {
for (JobProgression prog : progression) {
prog.reloadMaxExperience();
}
progression.forEach(JobProgression::reloadMaxExperience);
}
/**
@ -668,16 +667,18 @@ public class JobsPlayer {
if (numJobs > 0) {
for (JobProgression prog : progression) {
DisplayMethod method = prog.getJob().getDisplayMethod();
if (method.equals(DisplayMethod.NONE))
if (method == DisplayMethod.NONE)
continue;
if (gotTitle) {
builder.append(Jobs.getGCManager().modifyChatSeparator);
gotTitle = false;
}
Title title = Jobs.gettitleManager().getTitle(prog.getLevel(), prog.getJob().getName());
if (numJobs == 1) {
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) {
if (method == DisplayMethod.FULL || method == DisplayMethod.TITLE) {
if (title != null) {
String honorificpart = title.getChatColor() + title.getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
@ -686,34 +687,39 @@ public class JobsPlayer {
gotTitle = true;
}
}
if (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) {
if (method == DisplayMethod.FULL || method == DisplayMethod.JOB) {
if (gotTitle) {
builder.append(" ");
}
String honorificpart = prog.getJob().getNameWithColor() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.TITLE)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(DisplayMethod.SHORT_TITLE)) {
if (numJobs > 1 && (method == DisplayMethod.FULL) || method == DisplayMethod.TITLE || method == DisplayMethod.SHORT_FULL || method == DisplayMethod.SHORT_TITLE) {
// add title to honorific
if (title != null) {
String honorificpart = title.getChatColor() + title.getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
}
if (numJobs > 1 && (method.equals(DisplayMethod.FULL) || method.equals(DisplayMethod.JOB)) || method.equals(DisplayMethod.SHORT_FULL) || method.equals(
DisplayMethod.SHORT_JOB)) {
if (numJobs > 1 && (method == DisplayMethod.FULL) || method == DisplayMethod.JOB || method == DisplayMethod.SHORT_FULL || method ==
DisplayMethod.SHORT_JOB) {
String honorificpart = prog.getJob().getChatColor() + prog.getJob().getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", String.valueOf(prog.getLevel()));
builder.append(honorificpart);
gotTitle = true;
}
@ -722,17 +728,19 @@ public class JobsPlayer {
Job nonejob = Jobs.getNoneJob();
if (nonejob != null) {
DisplayMethod metod = nonejob.getDisplayMethod();
if (metod.equals(DisplayMethod.FULL) || metod.equals(DisplayMethod.TITLE)) {
if (metod == DisplayMethod.FULL || metod == DisplayMethod.TITLE) {
String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", "");
builder.append(honorificpart);
}
if (metod.equals(DisplayMethod.SHORT_FULL) || metod.equals(DisplayMethod.SHORT_TITLE) || metod.equals(DisplayMethod.SHORT_JOB)) {
if (metod == DisplayMethod.SHORT_FULL || metod == DisplayMethod.SHORT_TITLE || metod == DisplayMethod.SHORT_JOB) {
String honorificpart = Jobs.getNoneJob().getChatColor() + Jobs.getNoneJob().getShortName() + ChatColor.WHITE;
if (honorificpart.contains("{level}"))
honorificpart = honorificpart.replace("{level}", "");
builder.append(honorificpart);
}
}
@ -1206,12 +1214,32 @@ public class JobsPlayer {
return maxV.intValue();
}
/**
* @deprecated use {@link #getMaxFurnacesAllowed(CMIMaterial)}
* @return
*/
@Deprecated
public int getMaxFurnacesAllowed() {
Double maxV = Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxfurnaces");
return getMaxFurnacesAllowed(CMIMaterial.FURNACE);
}
if (maxV == null || maxV == 0)
public int getMaxFurnacesAllowed(CMIMaterial type) {
String perm = "jobs.max" + (type == CMIMaterial.FURNACE || type == CMIMaterial.LEGACY_BURNING_FURNACE
? "furnaces" : type == CMIMaterial.BLAST_FURNACE ? "blastfurnaces" : type == CMIMaterial.SMOKER ? "smokers" : "");
if (perm.isEmpty())
return 0;
Double maxV = Jobs.getPermissionManager().getMaxPermission(this, perm);
if (maxV == 0 && (type == CMIMaterial.FURNACE || type == CMIMaterial.LEGACY_BURNING_FURNACE))
maxV = (double) Jobs.getGCManager().getFurnacesMaxDefault();
if (maxV == 0 && type == CMIMaterial.BLAST_FURNACE)
maxV = (double) Jobs.getGCManager().BlastFurnacesMaxDefault;
if (maxV == 0 && type == CMIMaterial.SMOKER)
maxV = (double) Jobs.getGCManager().SmokersMaxDefault;
return maxV.intValue();
}

View File

@ -1619,7 +1619,7 @@ public class JobsPaymentListener implements Listener {
if (cmat == CMIMaterial.FURNACE || cmat == CMIMaterial.LEGACY_BURNING_FURNACE
|| cmat == CMIMaterial.SMOKER || cmat == CMIMaterial.BLAST_FURNACE) {
ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(p, block);
if (done.equals(ownershipFeedback.tooMany)) {
if (done == ownershipFeedback.tooMany) {
boolean report = false;
if (block.hasMetadata(furnaceOwnerMetadata)) {
@ -1638,14 +1638,14 @@ public class JobsPaymentListener implements Listener {
if (report)
ActionBarManager.send(p, Jobs.getLanguage().getMessage("general.error.noFurnaceRegistration"));
} else if (done.equals(ownershipFeedback.newReg) && jPlayer != null) {
} else if (done == ownershipFeedback.newReg && jPlayer != null) {
ActionBarManager.send(p, Jobs.getLanguage().getMessage("general.error.newFurnaceRegistration",
"[current]", jPlayer.getFurnaceCount(),
"[max]", jPlayer.getMaxFurnacesAllowed() == 0 ? "-" : jPlayer.getMaxFurnacesAllowed()));
"[max]", jPlayer.getMaxFurnacesAllowed(cmat) == 0 ? "-" : jPlayer.getMaxFurnacesAllowed(cmat)));
}
} else if (cmat == CMIMaterial.BREWING_STAND || cmat == CMIMaterial.LEGACY_BREWING_STAND) {
ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(p, block);
if (done.equals(ownershipFeedback.tooMany)) {
if (done == ownershipFeedback.tooMany) {
boolean report = false;
if (block.hasMetadata(brewingOwnerMetadata)) {
@ -1664,7 +1664,7 @@ public class JobsPaymentListener implements Listener {
if (report)
ActionBarManager.send(p, Jobs.getLanguage().getMessage("general.error.noBrewingRegistration"));
} else if (done.equals(ownershipFeedback.newReg) && jPlayer != null) {
} else if (done == ownershipFeedback.newReg && jPlayer != null) {
ActionBarManager.send(p, Jobs.getLanguage().getMessage("general.error.newBrewingRegistration",
"[current]", jPlayer.getBrewingStandCount(),
"[max]", jPlayer.getMaxBrewingStandsAllowed() == 0 ? "-" : jPlayer.getMaxBrewingStandsAllowed()));

View File

@ -235,11 +235,11 @@ public class FurnaceBrewingHandling {
public static ownershipFeedback registerFurnaces(Player player, Block block) {
CMIMaterial cmat = CMIMaterial.get(block);
if (!cmat.equals(CMIMaterial.FURNACE) && !cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE) && !cmat.equals(CMIMaterial.SMOKER) && !cmat.equals(CMIMaterial.BLAST_FURNACE))
if (cmat != CMIMaterial.FURNACE && cmat != CMIMaterial.LEGACY_BURNING_FURNACE && cmat != CMIMaterial.SMOKER && cmat != CMIMaterial.BLAST_FURNACE)
return ownershipFeedback.invalid;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
int max = jPlayer.getMaxFurnacesAllowed();
int max = jPlayer.getMaxFurnacesAllowed(cmat);
int have = jPlayer.getFurnaceCount();
boolean owner = false;
@ -267,13 +267,13 @@ public class FurnaceBrewingHandling {
block.setMetadata(JobsPaymentListener.furnaceOwnerMetadata, new FixedMetadataValue(Jobs.getInstance(), player.getUniqueId().toString()));
if (!Jobs.getGCManager().isFurnacesReassign()) {
if (!Jobs.getGCManager().isFurnacesReassign() || !Jobs.getGCManager().BlastFurnacesReassign || !Jobs.getGCManager().SmokerReassign) {
return ownershipFeedback.newReg;
}
List<blockLoc> ls = furnaceMap.get(player.getUniqueId());
if (ls == null)
ls = new ArrayList<blockLoc>();
ls = new ArrayList<>();
ls.add(new blockLoc(block.getLocation()));
furnaceMap.put(player.getUniqueId(), ls);
@ -281,7 +281,7 @@ public class FurnaceBrewingHandling {
}
public static ownershipFeedback registerBrewingStand(Player player, Block block) {
if (!CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND) && !CMIMaterial.get(block).equals(CMIMaterial.LEGACY_BREWING_STAND))
if (CMIMaterial.get(block) != CMIMaterial.BREWING_STAND && CMIMaterial.get(block) != CMIMaterial.LEGACY_BREWING_STAND)
return ownershipFeedback.invalid;
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
@ -319,7 +319,7 @@ public class FurnaceBrewingHandling {
List<blockLoc> ls = brewingMap.get(player.getUniqueId());
if (ls == null)
ls = new ArrayList<blockLoc>();
ls = new ArrayList<>();
ls.add(new blockLoc(block.getLocation()));
brewingMap.put(player.getUniqueId(), ls);
@ -337,7 +337,7 @@ public class FurnaceBrewingHandling {
continue;
CMIMaterial cmat = CMIMaterial.get(block);
if (!cmat.equals(CMIMaterial.FURNACE) && !cmat.equals(CMIMaterial.LEGACY_BURNING_FURNACE) && !cmat.equals(CMIMaterial.SMOKER) && !cmat.equals(CMIMaterial.BLAST_FURNACE))
if (cmat != CMIMaterial.FURNACE && cmat != CMIMaterial.LEGACY_BURNING_FURNACE && cmat != CMIMaterial.SMOKER && cmat != CMIMaterial.BLAST_FURNACE)
continue;
block.removeMetadata(JobsPaymentListener.furnaceOwnerMetadata, Jobs.getInstance());
@ -356,7 +356,7 @@ public class FurnaceBrewingHandling {
if (block == null)
continue;
if (CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND))
if (CMIMaterial.get(block) == CMIMaterial.BREWING_STAND)
block.removeMetadata(JobsPaymentListener.brewingOwnerMetadata, Jobs.getInstance());
}