1
0
mirror of https://github.com/Zrips/Jobs.git synced 2025-02-21 14:51:19 +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; package com.gamingmesh.jobs.actions;
import org.bukkit.inventory.ItemStack;
import com.gamingmesh.jobs.container.ActionInfo; import com.gamingmesh.jobs.container.ActionInfo;
import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BaseActionInfo;
public class PotionDrinkInfo extends BaseActionInfo implements ActionInfo { public class PotionDrinkInfo extends MaterialActionInfo implements ActionInfo {
private String potion; @SuppressWarnings("deprecation")
public PotionDrinkInfo(ItemStack potion, ActionType type) {
public PotionDrinkInfo(String potion, ActionType type) { super(potion.getType(), potion.getData().getData(), type);
super(type); }
this.potion = potion;
}
@Override
public String getName() {
return potion;
}
@Override
public String getNameWithSub() {
return getName();
}
} }

View File

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

View File

@ -76,7 +76,7 @@ public class GeneralConfigManager {
// Limits // Limits
private HashMap<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>(); private HashMap<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>();
public boolean PayForRenaming, PayForEachCraft, SignsEnabled, public boolean PayForRenaming, PayForEnchantingOnAnvil, PayForEachCraft, SignsEnabled,
SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse, SignsColorizeJobName, ShowToplistInScoreboard, useGlobalTimer, useCoreProtect, BlockPlaceUse,
EnableAnounceMessage, useSilkTouchProtection, UseCustomNames, EnableAnounceMessage, useSilkTouchProtection, UseCustomNames,
UseJobsBrowse, PreventSlimeSplit, PreventMagmaCubeSplit, PreventHopperFillUps, PreventBrewingStandFillUps, 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"); "This is not a big issue, but if you want to disable it, you can");
PayForRenaming = c.get("Economy.Repair.PayForRenaming", true); 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", 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)", "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"); "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); Set<String> keys = section.getKeys(false);
ListOfPotionNames.clear(); ListOfPotionNames.clear();
for (String one : keys) { for (String one : keys) {
String id = String.valueOf(CMIMaterial.POTION.getId()); String id = one.split("-")[0];
String meta = one.split("-")[0]; String meta = "";
String MCName = one.split("-")[1]; String MCName = one.split("-")[1];
String Name = ItemFile.getConfig().getString("PotionNamesList." + one); String Name = ItemFile.getConfig().getString("PotionNamesList." + one);
ListOfPotionNames.add(new NameList(id, meta, Name, MCName)); ListOfPotionNames.add(new NameList(id, meta, Name, MCName));
@ -263,7 +263,7 @@ public class NameTranslatorManager {
ConfigReader c = null; ConfigReader c = null;
try { try {
c = new ConfigReader(f); c = new ConfigReader(f);
} catch (Exception e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
} }
if (c == null) if (c == null)

View File

@ -758,27 +758,29 @@ public class JobsPaymentListener implements Listener {
if (resultStack == null) if (resultStack == null)
return; return;
// Checking if this is only item rename if (inv.getItem(1).getType() != Material.ENCHANTED_BOOK) {
ItemStack FirstSlot = null; // Checking if this is only item rename
try { ItemStack FirstSlot = null;
FirstSlot = inv.getItem(0); try {
} catch (NullPointerException e) { FirstSlot = inv.getItem(0);
return; } catch (NullPointerException e) {
}
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; 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 // Check for world permissions
if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
@ -791,7 +793,26 @@ public class JobsPaymentListener implements Listener {
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jPlayer == null) if (jPlayer == null)
return; 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) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -1543,8 +1564,7 @@ public class JobsPaymentListener implements Listener {
return; return;
// Player drinking a potion // Player drinking a potion
if (CMIMaterial.get(Jobs.getNms().getItemInMainHand(p).getType()).isPotion()) Jobs.action(jPlayer, new PotionDrinkInfo(Jobs.getNms().getItemInMainHand(p), ActionType.DRINK));
Jobs.action(jPlayer, new PotionDrinkInfo(CMIMaterial.get(Jobs.getNms().getItemInMainHand(p).getType()).name(), ActionType.DRINK));
} }
@EventHandler @EventHandler