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

Added a option to pay for enchanting a item from anvil, #331

This commit is contained in:
montlikadani 2019-02-06 19:57:58 +01:00
parent cee99ce850
commit 523ef32acd
5 changed files with 64 additions and 53 deletions

View File

@ -18,25 +18,14 @@
package com.gamingmesh.jobs.actions;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BaseActionInfo;
public class PotionDrinkInfo extends BaseActionInfo implements ActionInfo {
private String potion;
public PotionDrinkInfo(String potion, ActionType type) {
super(type);
this.potion = potion;
}
@Override
public String getName() {
return potion;
}
@Override
public String getNameWithSub() {
return getName();
}
public class PotionDrinkInfo extends MaterialActionInfo implements ActionInfo {
@SuppressWarnings("deprecation")
public PotionDrinkInfo(ItemStack potion, ActionType type) {
super(potion.getType(), potion.getData().getData(), type);
}
}

View File

@ -60,7 +60,6 @@ import com.gamingmesh.jobs.container.JobPermission;
import com.gamingmesh.jobs.container.Quest;
import com.gamingmesh.jobs.resources.jfep.Parser;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Debug;
import com.gamingmesh.jobs.CMILib.VersionChecker.Version;
public class ConfigManager {
@ -439,10 +438,10 @@ public class ConfigManager {
ConfigurationSection jobsSection = conf.getConfigurationSection("Jobs");
if (jobsSection == null) {
Jobs.getPluginLogger().severe("==================== Jobs ====================");
Jobs.getPluginLogger().severe("Jobs section not found in jobConfig file!");
Jobs.getPluginLogger().severe("Check the config for fix the issue.");
Jobs.getPluginLogger().severe("Jobs section not found in jobConfig file!");
Jobs.getPluginLogger().severe("Check the config for fix the issue.");
Jobs.getPluginLogger().severe("==============================================");
return;
return;
}
for (String jobKey : jobsSection.getKeys(false)) {
@ -776,13 +775,13 @@ public class ConfigManager {
name = itemSection.getString("name");
List<String> lore = new ArrayList<>();
if (itemSection.getStringList("lore") != null && !itemSection.getStringList("lore").isEmpty())
if (itemSection.contains("lore") && !itemSection.getStringList("lore").isEmpty())
for (String eachLine : itemSection.getStringList("lore")) {
lore.add(org.bukkit.ChatColor.translateAlternateColorCodes('&', eachLine));
}
HashMap<Enchantment, Integer> enchants = new HashMap<>();
if (itemSection.getStringList("enchants") != null && !itemSection.getStringList("enchants").isEmpty())
if (itemSection.contains("enchants") && !itemSection.getStringList("enchants").isEmpty())
for (String eachLine : itemSection.getStringList("enchants")) {
if (!eachLine.contains("="))
@ -833,13 +832,13 @@ public class ConfigManager {
name = itemSection.getString("name");
List<String> lore = new ArrayList<>();
if (itemSection.getStringList("lore") != null && !itemSection.getStringList("lore").isEmpty())
if (itemSection.contains("lore") && !itemSection.getStringList("lore").isEmpty())
for (String eachLine : itemSection.getStringList("lore")) {
lore.add(org.bukkit.ChatColor.translateAlternateColorCodes('&', eachLine));
}
HashMap<Enchantment, Integer> enchants = new HashMap<>();
if (itemSection.getStringList("enchants") != null && !itemSection.getStringList("enchants").isEmpty())
if (itemSection.contains("enchants") && !itemSection.getStringList("enchants").isEmpty())
for (String eachLine : itemSection.getStringList("enchants")) {
if (!eachLine.contains("="))

View File

@ -76,7 +76,7 @@ public class GeneralConfigManager {
// Limits
private HashMap<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>();
public boolean PayForRenaming, PayForEachCraft, SignsEnabled,
public boolean PayForRenaming, PayForEnchantingOnAnvil, PayForEachCraft, SignsEnabled,
SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse,
EnableAnounceMessage, useSilkTouchProtection, UseCustomNames,
UseJobsBrowse, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps,
@ -715,6 +715,9 @@ public class GeneralConfigManager {
"This is not a big issue, but if you want to disable it, you can");
PayForRenaming = c.get("Economy.Repair.PayForRenaming", true);
c.addComment("Economy.Enchant.PayForEnchantingOnAnvil", "Do you want to give money for enchanting items in anvil?");
PayForEnchantingOnAnvil = c.get("Economy.Enchant.PayForEnchantingOnAnvil", false);
c.addComment("Economy.Crafting.PayForEachCraft",
"With this true, player will get money for all crafted items instead of each crafting action (like with old payment mechanic)",
"By default its false, as you can make ALOT of money if prices kept from old payment mechanics");

View File

@ -206,8 +206,8 @@ public class NameTranslatorManager {
Set<String> keys = section.getKeys(false);
ListOfPotionNames.clear();
for (String one : keys) {
String id = String.valueOf(CMIMaterial.POTION.getId());
String meta = one.split("-")[0];
String id = one.split("-")[0];
String meta = "";
String MCName = one.split("-")[1];
String Name = ItemFile.getConfig().getString("PotionNamesList." + one);
ListOfPotionNames.add(new NameList(id, meta, Name, MCName));
@ -263,7 +263,7 @@ public class NameTranslatorManager {
ConfigReader c = null;
try {
c = new ConfigReader(f);
} catch (Exception e) {
} catch (Throwable e) {
e.printStackTrace();
}
if (c == null)

View File

@ -758,27 +758,29 @@ public class JobsPaymentListener implements Listener {
if (resultStack == null)
return;
// Checking if this is only item rename
ItemStack FirstSlot = null;
try {
FirstSlot = inv.getItem(0);
} catch (NullPointerException e) {
return;
}
if (FirstSlot == null)
return;
String OriginalName = null;
String NewName = null;
if (FirstSlot.hasItemMeta())
if (FirstSlot.getItemMeta().getDisplayName() != null)
OriginalName = FirstSlot.getItemMeta().getDisplayName();
if (resultStack.hasItemMeta())
if (resultStack.getItemMeta().getDisplayName() != null)
NewName = resultStack.getItemMeta().getDisplayName();
if (OriginalName != NewName && inv.getItem(1) == null)
if (!Jobs.getGCManager().PayForRenaming)
if (inv.getItem(1).getType() != Material.ENCHANTED_BOOK) {
// Checking if this is only item rename
ItemStack FirstSlot = null;
try {
FirstSlot = inv.getItem(0);
} catch (NullPointerException e) {
return;
}
if (FirstSlot == null)
return;
String OriginalName = null;
String NewName = null;
if (FirstSlot.hasItemMeta())
if (FirstSlot.getItemMeta().getDisplayName() != null)
OriginalName = FirstSlot.getItemMeta().getDisplayName();
if (resultStack.hasItemMeta())
if (resultStack.getItemMeta().getDisplayName() != null)
NewName = resultStack.getItemMeta().getDisplayName();
if (OriginalName != NewName && inv.getItem(1) == null)
if (!Jobs.getGCManager().PayForRenaming)
return;
}
// Check for world permissions
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
@ -791,7 +793,26 @@ public class JobsPaymentListener implements Listener {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null)
return;
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
if (Jobs.getGCManager().PayForEnchantingOnAnvil && inv.getItem(1).getType() == Material.ENCHANTED_BOOK) {
Map<Enchantment, Integer> enchants = resultStack.getEnchantments();
for (Entry<Enchantment, Integer> oneEnchant : enchants.entrySet()) {
Enchantment enchant = oneEnchant.getKey();
if (enchant == null)
continue;
String enchantName = enchant.getName();
if (enchantName == null)
continue;
Integer level = oneEnchant.getValue();
if (level == null)
continue;
Jobs.action(jPlayer, new EnchantActionInfo(enchantName, level, ActionType.ENCHANT));
}
} else
Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -1543,8 +1564,7 @@ public class JobsPaymentListener implements Listener {
return;
// Player drinking a potion
if (CMIMaterial.get(Jobs.getNms().getItemInMainHand(p).getType()).isPotion())
Jobs.action(jPlayer, new PotionDrinkInfo(CMIMaterial.get(Jobs.getNms().getItemInMainHand(p).getType()).name(), ActionType.DRINK));
Jobs.action(jPlayer, new PotionDrinkInfo(Jobs.getNms().getItemInMainHand(p), ActionType.DRINK));
}
@EventHandler