1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-18 05:11:32 +01:00

Different aproach to old item boost conversion

Lets show itembonus even if you are not in that job
This commit is contained in:
Zrips 2019-02-04 12:27:53 +02:00
parent 82f5ad0fd4
commit 46c2406ced
4 changed files with 71 additions and 18 deletions

View File

@ -21,7 +21,8 @@ import com.gamingmesh.jobs.container.JobItems;
public class ItemBoostManager {
private static HashMap<String, JobItems> items = new HashMap<>();
private static HashMap<String, JobItems> items = new HashMap<String, JobItems>();
private static HashMap<String, JobItems> legacy = new HashMap<String, JobItems>();
public ItemBoostManager() {
@ -39,24 +40,28 @@ public class ItemBoostManager {
if (cfg == null)
return;
items.clear();
legacy.clear();
// Converting from existing records in Jobs from old format which was located in jobConfig.yml file
boolean save = false;
for (Job one : Jobs.getJobs()) {
for (Entry<String, JobItems> oneI : one.getItemBonus().entrySet()) {
JobItems item = oneI.getValue();
cfg.getC().set(oneI.getKey() + ".id", CMIMaterial.get(item.getItemStack(null)).toString());
cfg.getC().set(oneI.getKey() + ".jobs", Arrays.asList(one.getName()));
String name = one.getName() + "_" + oneI.getKey();
cfg.getC().set(name + ".id", CMIMaterial.get(item.getItemStack(null)).toString());
cfg.getC().set(name + ".jobs", Arrays.asList(one.getName()));
if (item.getItemStack(null).hasItemMeta()) {
cfg.getC().set(oneI.getKey() + ".name", item.getItemStack(null).getItemMeta().hasDisplayName() ? CMIChatColor.deColorize(item.getItemStack(null).getItemMeta().getDisplayName()) : null);
cfg.getC().set(oneI.getKey() + ".lore", item.getItemStack(null).getItemMeta().hasLore() ? CMIChatColor.deColorize(item.getItemStack(null).getItemMeta().getLore()) : null);
cfg.getC().set(name + ".name", item.getItemStack(null).getItemMeta().hasDisplayName() ? CMIChatColor.deColorize(item.getItemStack(null).getItemMeta().getDisplayName()) : null);
cfg.getC().set(name + ".lore", item.getItemStack(null).getItemMeta().hasLore() ? CMIChatColor.deColorize(item.getItemStack(null).getItemMeta().getLore()) : null);
}
List<String> ench = new ArrayList<>();
for (Entry<Enchantment, Integer> oneE : item.getItemStack(null).getEnchantments().entrySet()) {
ench.add(oneE.getKey().getName() + "=" + oneE.getValue());
}
cfg.getC().set(oneI.getKey() + ".enchants", ench);
cfg.getC().set(name + ".enchants", ench);
for (CurrencyType oneC : CurrencyType.values()) {
cfg.getC().set(oneI.getKey() + "." + oneC.toString().toLowerCase() + "Boost", ((int) (item.getBoost().get(oneC) * 100D) / 100D) + 1D);
cfg.getC().set(name + "." + oneC.toString().toLowerCase() + "Boost", ((int) (item.getBoost().get(oneC) * 100D) / 100D) + 1D);
}
save = true;
}
@ -81,7 +86,10 @@ public class ItemBoostManager {
Set<String> keys = cfg.getC().getKeys(false);
cfg.addComment("exampleBoost", "Name which will be used to identify this particular item boost",
cfg.addComment("exampleBoost", "Attention! If category name has _ in it, that means its legacy item which was converted from jobConfig.yml file",
"Keep this format until you will be sure that all legacy items have been converted throw usage, which is automatic process when player uses items with boost in them",
"",
"Name which will be used to identify this particular item boost",
"This is EXAMPLE boost and will be ignored");
cfg.addComment("exampleBoost.id", "Item Id which can be any material name as of 1.13 update",
"This is only used when performing command like /jobs give, but boost itself is not dependent on item type",
@ -100,7 +108,7 @@ public class ItemBoostManager {
}
cfg.addComment("exampleBoost.jobs", "[Required] Jobs which should receive this boost",
"Can be specific jobs or use 'all' to give this boost for every job");
cfg.get("exampleBoost.jobs", Arrays.asList("Miner", "Woodcutter", "All"));
cfg.get("exampleBoost.jobs", Arrays.asList("Miner", "Woodcutter", "all"));
cfg.addComment("exampleBoost.levelFrom", "(Optional) Defines level of job from which this boost should be applied",
"Keep in mind that if boost have multiple jobs, then level will be checked by job which is requesting boost value");
@ -190,6 +198,11 @@ public class ItemBoostManager {
oneJ.getItemBonus().put(one.toLowerCase(), item);
}
// Lets add into legacy map
if (one.contains("_")) {
item.setLegacyKey((one.split("_")[1]).toLowerCase());
legacy.put(item.getLegacyKey(), item);
}
items.put(one.toLowerCase(), item);
}
@ -216,13 +229,21 @@ public class ItemBoostManager {
}
public static JobItems getItemByKey(String key) {
return items.get(key.toLowerCase());
JobItems item = items.get(key.toLowerCase());
if (item != null) {
return item;
}
return legacy.get(key.toLowerCase());
}
public static HashMap<String, JobItems> getItems() {
return items;
}
public static HashMap<String, JobItems> getLegacyItems() {
return legacy;
}
public static void setItems(HashMap<String, JobItems> items) {
ItemBoostManager.items = items;
}

View File

@ -17,6 +17,7 @@ import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobItems;
import com.gamingmesh.jobs.container.JobsPlayer;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
import com.gamingmesh.jobs.CMILib.RawMessage;
public class itembonus implements Cmd {
@ -59,7 +60,13 @@ public class itembonus implements Cmd {
if (jitem == null)
continue;
for (Job one : jitem.getJobs()) {
BoostMultiplier boost = jitem.getBoost(jPlayer.getJobProgression(one));
BoostMultiplier boost = null;
if (!jPlayer.isInJob(one))
boost = jitem.getBoost();
else
boost = jitem.getBoost(jPlayer.getJobProgression(one));
boolean any = false;
for (CurrencyType oneC : CurrencyType.values()) {
if (boost.get(oneC) != 0D)
@ -67,14 +74,28 @@ public class itembonus implements Cmd {
}
if (!any)
continue;
String msg = Jobs.getLanguage().getMessage("command.itembonus.output.list",
"[jobname]", one.getName(),
"%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)),
"%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)),
"%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100)));
String msg = null;
if (jPlayer.isInJob(one))
msg = Jobs.getLanguage().getMessage("command.itembonus.output.list",
"[jobname]", one.getName(),
"%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)),
"%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)),
"%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100)));
else
msg = Jobs.getLanguage().getMessage("command.itembonus.output.notAplyingList",
"[jobname]", one.getName(),
"%money%", mc + formatText((int) (boost.get(CurrencyType.MONEY) * 100)),
"%points%", pc + formatText((int) (boost.get(CurrencyType.POINTS) * 100)),
"%exp%", ec + formatText((int) (boost.get(CurrencyType.EXP) * 100)));
RawMessage rm = new RawMessage();
String name = oneI.getType().name().replace("_", " ").toLowerCase();
name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
String name = CMIMaterial.get(oneI.getType()).getName();
if (jitem.getFromLevel() != 0 || jitem.getUntilLevel() != Integer.MAX_VALUE)
name += " \n" + Jobs.getLanguage().getMessage("command.itembonus.output.hoverLevelLimits",
"%from%", jitem.getFromLevel(),
"%until%", jitem.getUntilLevel());
rm.add(msg, name);
rm.show(sender);
}

View File

@ -206,6 +206,8 @@ public class LanguageManager {
c.get("command.itembonus.help.info", "Check item bonus");
c.get("command.itembonus.help.args", "");
c.get("command.itembonus.output.list", "&e[jobname]: %money% %points% %exp%");
c.get("command.itembonus.output.hover", "&7%itemtype%");
c.get("command.itembonus.output.hoverLevelLimits", "&7From level: %from% \n&7Until level: %until%");
c.get("command.edititembonus.help.info", "Edit item boost bonus");
c.get("command.edititembonus.help.args", "list/add/remove [jobname] [itemBoostName]");

View File

@ -35,6 +35,7 @@ import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial;
public class JobItems {
private String node;
private String legacyKey = null;
ItemStack item;
private BoostMultiplier boostMultiplier = new BoostMultiplier();
private List<Job> jobs = new ArrayList<Job>();
@ -136,4 +137,12 @@ public class JobItems {
public void setUntilLevel(int untilLevel) {
this.untilLevel = untilLevel;
}
public String getLegacyKey() {
return legacyKey;
}
public void setLegacyKey(String legacyKey) {
this.legacyKey = legacyKey;
}
}