1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-01-02 14:29:07 +01:00

Deprecated short description in jobs now we should use FullDescription

Now the FullDescription list will be printed to the gui items instead of short description. In fact, some type didn’t make sense, as even simple strings could solve new lines, but many were lazy to do it, with just two characters. So the FullDescription list will be visible on new servers that have just installed jobs or are updating the file manually.

- Added potion effect support to jobs shop to give potion item to player with the given effect type.

Closes #1064
This commit is contained in:
montlikadani 2021-02-03 18:12:20 +01:00
parent c858b53340
commit 7ecb265484
22 changed files with 181 additions and 71 deletions

View File

@ -102,7 +102,12 @@ public class GuiManager {
else
lore.add(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100)));
lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n")));
if (job.getDescription().isEmpty()) {
for (String desc : job.getFullDescription()) {
lore.add(desc);
}
} else
lore.addAll(Arrays.asList(job.getDescription().split("/n|\\n")));
if (job.getMaxSlots() != null)
lore.add(Jobs.getLanguage().getMessage("command.info.gui.leftSlots") + ((job.getMaxSlots() - Jobs.getUsedSlots(job)) > 0 ? (job.getMaxSlots() - Jobs

View File

@ -70,6 +70,11 @@ public class browse implements Cmd {
if (!one.getDescription().isEmpty())
hoverMsg += Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", one.getDescription().replaceAll("/n|\n", ""));
else {
for (String desc : one.getFullDescription()) {
hoverMsg += Jobs.getLanguage().getMessage("command.browse.output.description", "[description]", desc);
}
}
if (one.getMaxLevel(sender) > 0) {
if (!hoverMsg.isEmpty())
@ -143,6 +148,11 @@ public class browse implements Cmd {
if (!one.getDescription().isEmpty())
msg += Jobs.getLanguage().getMessage("command.browse.output.console.description", "[description]", one.getDescription().replaceAll("/n|\n", ""));
else {
for (String desc : one.getFullDescription()) {
msg += Jobs.getLanguage().getMessage("command.browse.output.console.description", "[description]", desc);
}
}
if (one.getMaxLevel(sender) > 0)
msg += Jobs.getLanguage().getMessage("command.browse.output.console.newMax", "[max]", one.getMaxLevel(sender));
@ -212,6 +222,11 @@ public class browse implements Cmd {
lines.add(builder.toString());
if (!job.getDescription().isEmpty())
lines.add(" - " + job.getDescription().replaceAll("/n|\n", ""));
else {
for (String desc : job.getFullDescription()) {
lines.add(" - " + desc);
}
}
}
if (lines.isEmpty()) {

View File

@ -573,9 +573,8 @@ public class GeneralConfigManager {
"jobstotalplayers: The number of people in that particular job",
"Exponential equation: totalworkers / totaljobs / jobstotalplayers - 1",
"Linear equation: ((totalworkers / totaljobs) - jobstotalplayers)/10.0");
String maxExpEquationInput = c.get("Economy.DynamicPayment.equation", "totalworkers / totaljobs / jobstotalplayers - 1");
try {
DynamicPaymentEquation = new Parser(maxExpEquationInput);
DynamicPaymentEquation = new Parser(c.get("Economy.DynamicPayment.equation", "totalworkers / totaljobs / jobstotalplayers - 1"));
DynamicPaymentEquation.setVariable("totalworkers", 100);
DynamicPaymentEquation.setVariable("totaljobs", 10);
DynamicPaymentEquation.setVariable("jobstotalplayers", 10);
@ -627,11 +626,10 @@ public class GeneralConfigManager {
"You can always use simple number to set money limit",
"Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have",
"So player with 2 jobs with level 15 and 22 will have 685 limit");
String MoneyLimit = c.get("Economy.Limit.Money.MoneyLimit", "500+500*(totallevel/100)");
try {
Parser Equation = new Parser(MoneyLimit);
Equation.setVariable("totallevel", 1);
limit.setMaxEquation(Equation);
Parser equation = new Parser(c.get("Economy.Limit.Money.MoneyLimit", "500+500*(totallevel/100)"));
equation.setVariable("totallevel", 1);
limit.setMaxEquation(equation);
} catch (Throwable e) {
Jobs.getPluginLogger().warning("MoneyLimit has an invalid value. Disabling money limit!");
limit.setEnabled(false);
@ -660,11 +658,10 @@ public class GeneralConfigManager {
"You can always use simple number to set limit",
"Default equation is: 500+500*(totallevel/100), this will add 1% from 500 for each level player have",
"So player with 2 jobs with level 15 and 22 will have 685 limit");
String PointLimit = c.get("Economy.Limit.Point.Limit", "500+500*(totallevel/100)");
try {
Parser Equation = new Parser(PointLimit);
Equation.setVariable("totallevel", 1);
limit.setMaxEquation(Equation);
Parser equation = new Parser(c.get("Economy.Limit.Point.Limit", "500+500*(totallevel/100)"));
equation.setVariable("totallevel", 1);
limit.setMaxEquation(equation);
} catch (Throwable e) {
Jobs.getPluginLogger().warning("PointLimit has an invalid value. Disabling money limit!");
limit.setEnabled(false);
@ -693,11 +690,10 @@ public class GeneralConfigManager {
"You can always use simple number to set exp limit",
"Default equation is: 5000+5000*(totallevel/100), this will add 1% from 5000 for each level player have",
"So player with 2 jobs with level 15 and 22 will have 6850 limit");
String expLimit = c.get("Economy.Limit.Exp.Limit", "5000+5000*(totallevel/100)");
try {
Parser Equation = new Parser(expLimit);
Equation.setVariable("totallevel", 1);
limit.setMaxEquation(Equation);
Parser equation = new Parser(c.get("Economy.Limit.Exp.Limit", "5000+5000*(totallevel/100)"));
equation.setVariable("totallevel", 1);
limit.setMaxEquation(equation);
} catch (Throwable e) {
Jobs.getPluginLogger().warning("ExpLimit has an invalid value. Disabling money limit!");
limit.setEnabled(false);

View File

@ -54,7 +54,7 @@ public class NameTranslatorManager {
materialName = materialName.replace(" ", "");
CMIMaterial mat = CMIMaterial.get(materialName.replace(" ", ""));
CMIMaterial mat = CMIMaterial.get(materialName);
NameList nameLs = ListOfNames.get(mat);
if (nameLs != null) {
@ -66,7 +66,7 @@ public class NameTranslatorManager {
}
if (name != null && !name.isEmpty()) {
mat = CMIMaterial.get(materialName.replace(" ", ""));
mat = CMIMaterial.get(materialName);
nameLs = ListOfNames.get(mat);
if (nameLs != null) {

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
@ -17,6 +18,9 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.CMIGUI.CMIGui;
@ -26,6 +30,7 @@ import com.gamingmesh.jobs.CMIGUI.GUIManager.GUIRows;
import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.CMILib.Version;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobItems;
@ -35,6 +40,7 @@ import com.gamingmesh.jobs.container.PlayerPoints;
import com.gamingmesh.jobs.container.ShopItem;
import com.gamingmesh.jobs.stuff.GiveItem;
@SuppressWarnings("deprecation")
public class ShopManager {
private final List<ShopItem> list = new ArrayList<>();
@ -195,7 +201,6 @@ public class ShopManager {
if (item.isHeadOwner()) {
Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer());
} else {
@SuppressWarnings("deprecation")
OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(item.getCustomHead());
Jobs.getNms().setSkullOwner(skullMeta, offPlayer);
}
@ -321,9 +326,7 @@ public class ShopManager {
continue;
}
double price = nameSection.getDouble("Price");
ShopItem sItem = new ShopItem(category, price);
ShopItem sItem = new ShopItem(category, nameSection.getDouble("Price"));
if (nameSection.isString("Icon.Id"))
sItem.setIconMaterial(nameSection.getString("Icon.Id"));
@ -409,39 +412,49 @@ public class ShopManager {
}
int amount = itemSection.getInt("Amount", 1);
String name = null;
if (itemSection.isString("Name"))
name = CMIChatColor.translate(itemSection.getString("Name"));
String name = CMIChatColor.translate(itemSection.getString("Name"));
List<String> lore = new ArrayList<>();
if (itemSection.contains("Lore"))
for (String eachLine : itemSection.getStringList("Lore")) {
lore.add(CMIChatColor.translate(eachLine));
}
for (String eachLine : itemSection.getStringList("Lore")) {
lore.add(CMIChatColor.translate(eachLine));
}
HashMap<Enchantment, Integer> enchants = new HashMap<>();
if (itemSection.contains("Enchants"))
for (String eachLine : itemSection.getStringList("Enchants")) {
if (!eachLine.contains("="))
Map<Enchantment, Integer> enchants = new HashMap<>();
for (String eachLine : itemSection.getStringList("Enchants")) {
if (!eachLine.contains("="))
continue;
String[] split = eachLine.split("=");
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Integer level = 1;
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
String[] split = eachLine.split("=");
Enchantment ench = CMIEnchantment.getEnchantment(split[0]);
Integer level = 1;
if (split.length > 1) {
try {
level = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
continue;
}
}
if (ench != null)
enchants.put(ench, level);
}
items.add(new JobItems(node, id == null ? CMIMaterial.STONE : CMIMaterial.get(id), amount, name, lore, enchants, new BoostMultiplier(), new ArrayList<Job>()));
if (ench != null)
enchants.put(ench, level);
}
Object potionData = null;
if (itemSection.contains("potion-type")) {
PotionType type = PotionType.valueOf(itemSection.getString("potion-type", "speed").toUpperCase());
if (type == null) {
type = PotionType.SPEED;
}
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) {
potionData = new PotionData(type);
} else {
potionData = new Potion(type, 1, false);
}
}
items.add(new JobItems(node, id == null ? CMIMaterial.STONE : CMIMaterial.get(id), amount, name, lore,
enchants, new BoostMultiplier(), new ArrayList<Job>(), potionData));
}
sItem.setitems(items);
}

View File

@ -91,13 +91,23 @@ public class Job {
private int maxDailyQuests = 1;
private int id = 0;
@Deprecated
public Job(String jobName, String fullName, String jobShortName, String description, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems,
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
this(jobName, fullName, jobShortName, jobColour, maxExpEquation, displayMethod, maxLevel,
vipmaxLevel, maxSlots, jobPermissions, jobCommands, jobConditions, jobItems,
jobLimitedItems, cmdOnJoin, cmdOnLeave, guiItem, guiSlot, bossbar, rejoinCD, worldBlacklist);
this.description = description;
}
public Job(String jobName, String fullName, String jobShortName, CMIChatColor jobColour, Parser maxExpEquation, DisplayMethod displayMethod, int maxLevel,
int vipmaxLevel, Integer maxSlots, List<JobPermission> jobPermissions, List<JobCommands> jobCommands, List<JobConditions> jobConditions, HashMap<String, JobItems> jobItems,
HashMap<String, JobLimitedItems> jobLimitedItems, List<String> cmdOnJoin, List<String> cmdOnLeave, ItemStack guiItem, int guiSlot, String bossbar, Long rejoinCD, List<String> worldBlacklist) {
this.jobName = jobName == null ? "" : jobName;
this.fullName = fullName == null ? "" : fullName;
this.jobShortName = jobShortName;
this.description = description;
this.jobColour = jobColour;
this.maxExpEquation = maxExpEquation;
this.displayMethod = displayMethod;
@ -291,6 +301,7 @@ public class Job {
/**
* Get the shortened version of the jobName
*
* @return the shortened version of the jobName
*/
public String getShortName() {
@ -299,8 +310,11 @@ public class Job {
/**
* Gets the description
*
* @return description
* @deprecated Not used anymore, use {@link #getFullDescription()} instead
*/
@Deprecated
public String getDescription() {
return description;
}
@ -483,7 +497,10 @@ public class Job {
public void setFullDescription(List<String> fDescription) {
this.fDescription.clear();
this.fDescription.addAll(fDescription == null ? new ArrayList<>() : fDescription);
if (fDescription != null) {
this.fDescription.addAll(fDescription);
}
}
public List<Quest> getQuests() {

View File

@ -21,6 +21,7 @@ package com.gamingmesh.jobs.container;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.enchantments.Enchantment;
@ -28,31 +29,45 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffectType;
import com.gamingmesh.jobs.CMILib.CMIChatColor;
import com.gamingmesh.jobs.CMILib.CMIMaterial;
import com.gamingmesh.jobs.CMILib.CMIReflections;
import com.gamingmesh.jobs.CMILib.Version;
@SuppressWarnings("deprecation")
public class JobItems {
private String node;
private String legacyKey;
private ItemStack item;
private HashMap<Enchantment, Integer> enchants;
private Object potion;
private final Map<Enchantment, Integer> enchants = new HashMap<>();
private BoostMultiplier boostMultiplier = new BoostMultiplier();
private List<Job> jobs = new ArrayList<>();
private final List<Job> jobs = new ArrayList<>();
private int fromLevel = 0;
private int untilLevel = Integer.MAX_VALUE;
public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, HashMap<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs) {
this(node, mat, amount, name, lore, enchants, boostMultiplier, jobs, null);
}
public JobItems(String node, CMIMaterial mat, int amount, String name, List<String> lore, Map<Enchantment, Integer> enchants, BoostMultiplier boostMultiplier, List<Job> jobs,
Object potion) {
if (mat == null) {
mat = CMIMaterial.STONE;
}
this.enchants = enchants;
if (enchants != null) {
this.enchants.putAll(enchants);
}
this.node = node;
if (boostMultiplier != null) {
@ -62,6 +77,21 @@ public class JobItems {
setJobs(jobs);
ItemMeta meta = (item = mat.newItemStack()).getItemMeta();
if (CMIMaterial.isPotion(mat.getMaterial()) && potion != null && meta instanceof PotionMeta) {
PotionMeta potionMeta = (PotionMeta) meta;
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && potion instanceof org.bukkit.potion.PotionData) {
potionMeta.setBasePotionData((org.bukkit.potion.PotionData) potion);
} else if (potion instanceof org.bukkit.potion.Potion) {
PotionEffectType effectType = ((org.bukkit.potion.Potion) potion).getType().getEffectType();
if (effectType != null) {
potionMeta.setMainEffect(effectType);
}
}
meta = potionMeta;
}
if (meta != null) {
if (name != null)
meta.setDisplayName(CMIChatColor.translate(name));
@ -103,6 +133,21 @@ public class JobItems {
return item;
}
if (CMIMaterial.isPotion(item.getType()) && potion != null && meta instanceof PotionMeta) {
PotionMeta potionMeta = (PotionMeta) meta;
if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && potion instanceof org.bukkit.potion.PotionData) {
potionMeta.setBasePotionData((org.bukkit.potion.PotionData) potion);
} else if (potion instanceof org.bukkit.potion.Potion) {
PotionEffectType effectType = ((org.bukkit.potion.Potion) potion).getType().getEffectType();
if (effectType != null) {
potionMeta.setMainEffect(effectType);
}
}
meta = potionMeta;
}
if (meta.hasDisplayName())
meta.setDisplayName(CMIChatColor.translate(meta.getDisplayName().replace("[player]", player.getName())));
@ -148,10 +193,11 @@ public class JobItems {
}
public void setJobs(List<Job> jobs) {
this.jobs = jobs == null ? new ArrayList<>() : jobs;
this.jobs.clear();
this.jobs.addAll(jobs);
}
public HashMap<Enchantment, Integer> getEnchants() {
public Map<Enchantment, Integer> getEnchants() {
return enchants;
}

View File

@ -728,9 +728,8 @@ public class JobsPlayer {
*/
public void reloadHonorific() {
StringBuilder builder = new StringBuilder();
int numJobs = progression.size();
if (numJobs > 0) {
if (progression.size() > 0) {
for (JobProgression prog : progression) {
DisplayMethod method = prog.getJob().getDisplayMethod();
if (method == DisplayMethod.NONE)
@ -744,8 +743,7 @@ public class JobsPlayer {
} else {
Job nonejob = Jobs.getNoneJob();
if (nonejob != null) {
DisplayMethod method = nonejob.getDisplayMethod();
processesChat(method, builder, -1, null, nonejob);
processesChat(nonejob.getDisplayMethod(), builder, -1, null, nonejob);
}
}

View File

@ -18,10 +18,13 @@ exampleJob:
shortname: W
# The short description of job
description: Earns money felling and planting trees
# Please try to not use this, use FullDescription below
#description: Earns money felling and planting trees
# Full description of job to be shown in job browse command
FullDescription:
- "&7Earns money felling and planting trees"
- ""
- "&2Get money for:"
- " &7Planting trees"
- " &7Cutting down trees"

View File

@ -1,7 +1,8 @@
Brewer:
fullname: Brewer
shortname: Br
description: Earns money brewing potions.
FullDescription:
- "Earns money brewing potions."
ChatColour: LIGHT_PURPLE
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Builder:
fullname: Builder
shortname: B
description: Earns money for building structures.
FullDescription:
- "Earns money for building structures."
ChatColour: WHITE
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Crafter:
fullname: Crafter
shortname: Cr
description: Earns money from crafting items.
FullDescription:
- "Earns money from crafting items."
ChatColour: RED
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Digger:
fullname: Digger
shortname: D
description: Earns money for terraforming the world.
FullDescription:
- "Earns money for terraforming the world."
ChatColour: GOLD
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Enchanter:
fullname: Enchanter
shortname: E
description: Earns money enchanting weapons.
FullDescription:
- "Earns money enchanting weapons."
ChatColour: DARK_BLUE
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Explorer:
fullname: Explorer
shortname: Ex
description: Earns money from exploring map.
FullDescription:
- "Earns money from exploring map."
ChatColour: AQUA
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Farmer:
fullname: Farmer
shortname: Fa
description: Earns money farming crops.
FullDescription:
- "Earns money farming crops."
ChatColour: BLUE
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Fisherman:
fullname: Fisherman
shortname: Fi
description: Earns money from fishing.
FullDescription:
- "Earns money from fishing."
ChatColour: AQUA
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Hunter:
fullname: Hunter
shortname: H
description: Earns money killing animals and monsters.
FullDescription:
- "Earns money killing animals and monsters."
ChatColour: RED
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Miner:
fullname: Miner
shortname: M
description: Earns money mining minerals and ores.
FullDescription:
- "Earns money mining minerals and ores."
ChatColour: DARK_GRAY
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Weaponsmith:
fullname: Weaponsmith
shortname: W
description: Earns money from crafting and repairing weapons.
FullDescription:
- "Earns money from crafting and repairing weapons."
ChatColour: DARK_PURPLE
chat-display: full
max-level: 200

View File

@ -1,7 +1,8 @@
Woodcutter:
fullname: Woodcutter
shortname: W
description: Earns money felling and planting trees
FullDescription:
- "Earns money felling and planting trees"
ChatColour: GREEN
chat-display: full
max-level: 200

View File

@ -55,6 +55,11 @@ Items:
Enchants:
- DIG_SPEED=5
- DURABILITY=3
Giving-Potion:
Id: potion
Amount: 1
Name: "&6Jump boost"
potion-type: jump
# Can be any word
Apple:
# (Required) Item name