This commit is contained in:
TeamHR 2024-03-24 21:30:58 +05:30 committed by GitHub
commit b3d946a3d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 71 additions and 31 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.craftaro</groupId> <groupId>com.craftaro</groupId>
<artifactId>EpicEnchants</artifactId> <artifactId>EpicEnchants</artifactId>
<version>2.0.0</version> <version>2.0.1</version>
<name>EpicEnchants</name> <name>EpicEnchants</name>
<description>Unlock the potential of your weapons, tools and armor by making your own custom enchants.</description> <description>Unlock the potential of your weapons, tools and armor by making your own custom enchants.</description>

View File

@ -8,6 +8,7 @@ import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Placeholder; import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.utils.objects.FastInv; import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder; import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.utils.settings.Settings;
import com.craftaro.epicenchants.utils.single.GeneralUtils; import com.craftaro.epicenchants.utils.single.GeneralUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -202,7 +203,7 @@ public class AlchemistMenu extends FastInv {
NBTItem rightItem = new NBTItem(getInventory().getItem(this.RIGHT_SLOT)); NBTItem rightItem = new NBTItem(getInventory().getItem(this.RIGHT_SLOT));
int ecoCost; int ecoCost;
int expCost; int expCost;
String Mode = Settings.MODE.getString();
if (leftItem.hasTag("book-item")) { if (leftItem.hasTag("book-item")) {
int level = leftItem.getInteger("level"); int level = leftItem.getInteger("level");
Enchant enchant = this.instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!")); Enchant enchant = this.instance.getEnchantManager().getValue(leftItem.getString("enchant")).orElseThrow(() -> new IllegalStateException("Book without enchant!"));
@ -268,18 +269,33 @@ public class AlchemistMenu extends FastInv {
Placeholder.of("eco_cost", ecoCost), Placeholder.of("eco_cost", ecoCost),
Placeholder.of("exp_cost", expCost) Placeholder.of("exp_cost", expCost)
).build(), event -> { ).build(), event -> {
if (!EconomyManager.hasBalance(event.getPlayer(), ecoCost) || getExp(event.getPlayer()) < expCost) {
if (EconomyManager.isEnabled() && Mode.equalsIgnoreCase("ECO") && EconomyManager.getBalance(event.getPlayer()) < ecoCost){
this.instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
return;
}
if (Mode.equalsIgnoreCase("EXP") && getExp(event.getPlayer()) < expCost) {
this.instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer()); this.instance.getLocale().getMessage("alchemist.cannotafford").sendPrefixedMessage(event.getPlayer());
return; return;
} }
EconomyManager.withdrawBalance(event.getPlayer(), ecoCost); switch (Mode.toUpperCase()) {
changeExp(event.getPlayer(), -expCost); case "ECO":
this.instance.getLocale().getMessage("alchemist.success") EconomyManager.withdrawBalance(event.getPlayer(), ecoCost);
.processPlaceholder("eco_cost", ecoCost) this.instance.getLocale().getMessage("alchemist.successeco")
.processPlaceholder("exp_cost", expCost) .processPlaceholder("eco_cost", ecoCost)
.sendPrefixedMessage(event.getPlayer()); .sendPrefixedMessage(event.getPlayer());
break;
case "EXP":
changeExp(event.getPlayer(), -expCost);
this.instance.getLocale().getMessage("alchemist.successexp")
.processPlaceholder("exp_cost", expCost)
.sendPrefixedMessage(event.getPlayer());
break;
default:
System.out.println("Wrong MODE value detected. Use ECO or EXP.");
break;
}
event.getPlayer().getInventory().addItem(getInventory().getItem(this.PREVIEW_SLOT)); event.getPlayer().getInventory().addItem(getInventory().getItem(this.PREVIEW_SLOT));
clear(this.RIGHT_SLOT); clear(this.RIGHT_SLOT);
clear(this.LEFT_SLOT); clear(this.LEFT_SLOT);

View File

@ -1,11 +1,14 @@
package com.craftaro.epicenchants.menus; package com.craftaro.epicenchants.menus;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.hooks.EconomyManager; import com.craftaro.core.hooks.EconomyManager;
import com.craftaro.epicenchants.EpicEnchants; import com.craftaro.epicenchants.EpicEnchants;
import com.craftaro.epicenchants.objects.Group; import com.craftaro.epicenchants.objects.Group;
import com.craftaro.epicenchants.objects.Placeholder; import com.craftaro.epicenchants.objects.Placeholder;
import com.craftaro.epicenchants.utils.objects.FastInv; import com.craftaro.epicenchants.utils.objects.FastInv;
import com.craftaro.epicenchants.utils.objects.ItemBuilder; import com.craftaro.epicenchants.utils.objects.ItemBuilder;
import com.craftaro.epicenchants.utils.settings.Settings;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -28,7 +31,7 @@ public class EnchanterMenu extends FastInv {
if (config.isConfigurationSection("fill")) { if (config.isConfigurationSection("fill")) {
fill(new ItemBuilder(config.getConfigurationSection("fill")).build()); fill(new ItemBuilder(config.getConfigurationSection("fill")).build());
} }
String Mode = Settings.MODE.getString();
config.getConfigurationSection("contents").getKeys(false) config.getConfigurationSection("contents").getKeys(false)
.stream() .stream()
.map(s -> "contents." + s) .map(s -> "contents." + s)
@ -39,7 +42,7 @@ public class EnchanterMenu extends FastInv {
int ecoCost = section.getInt("eco-cost"); int ecoCost = section.getInt("eco-cost");
int xpLeft = Math.max(expCost - player.getLevel(), 0); int xpLeft = Math.max(expCost - player.getLevel(), 0);
double ecoLeft = 0.0d; double ecoLeft = 0.0d;
if (EconomyManager.isEnabled()) if (EconomyManager.isEnabled() && Mode.equalsIgnoreCase("ECO"))
ecoLeft = ecoCost - EconomyManager.getBalance(player) < 0 ? 0 : ecoCost - EconomyManager.getBalance(player); ecoLeft = ecoCost - EconomyManager.getBalance(player) < 0 ? 0 : ecoCost - EconomyManager.getBalance(player);
Group group = instance.getGroupManager().getValue(section.getString("group").toUpperCase()) Group group = instance.getGroupManager().getValue(section.getString("group").toUpperCase())
.orElseThrow(() -> new IllegalArgumentException("Invalid group set in enchanter: " + section.getString("group"))); .orElseThrow(() -> new IllegalArgumentException("Invalid group set in enchanter: " + section.getString("group")));
@ -50,27 +53,40 @@ public class EnchanterMenu extends FastInv {
Placeholder.of("eco_left", ecoLeft)).build(); Placeholder.of("eco_left", ecoLeft)).build();
addItem(getSlots(section.getString("slot")), itemStack, event -> { addItem(getSlots(section.getString("slot")), itemStack, event -> {
// Todo: wanna change this
if (this.delay.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) { if (this.delay.getOrDefault(player.getUniqueId(), 0L) > System.currentTimeMillis()) {
return; return;
} }
if (EconomyManager.isEnabled() && !EconomyManager.hasBalance((player), ecoCost) || getExp(player) < expCost) { if (EconomyManager.isEnabled() && Mode.equalsIgnoreCase("ECO") && EconomyManager.getBalance(player) < ecoCost) {
instance.getLocale().getMessage("enchanter.cannotafford").sendPrefixedMessage(player); instance.getLocale().getMessage("enchanter.cannotafford").sendPrefixedMessage(player);
return; return;
} }
if (EconomyManager.isEnabled()) { if (Mode.equalsIgnoreCase("EXP") && getExp(player) < expCost) {
EconomyManager.withdrawBalance(player, ecoCost); instance.getLocale().getMessage("enchanter.cannotafford").sendPrefixedMessage(player);
event.getPlayer().sendMessage(instance.getLocale().getMessage("enchanter.success") return;
.processPlaceholder("group_name", group.getName()) }
.processPlaceholder("group_color", group.getColor()) switch (Mode.toUpperCase()) {
.processPlaceholder("eco_cost", ecoCost) case "ECO":
.processPlaceholder("exp_cost", expCost) EconomyManager.withdrawBalance(player, ecoCost);
.getPrefixedMessage()); event.getPlayer().sendMessage(instance.getLocale().getMessage("enchanter.successeco")
.processPlaceholder("group_name", group.getName())
.processPlaceholder("group_color", group.getColor())
.processPlaceholder("eco_cost", ecoCost)
.getPrefixedMessage());
break;
case "EXP":
changeExp(player, -expCost);
event.getPlayer().sendMessage(instance.getLocale().getMessage("enchanter.successexp")
.processPlaceholder("group_name", group.getName())
.processPlaceholder("group_color", group.getColor())
.processPlaceholder("exp_cost", expCost)
.getPrefixedMessage());
break;
default:
System.out.println("Wrong MODE value detected. Use ECO or EXP.");
break;
} }
changeExp(player, -expCost);
player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group)); player.getInventory().addItem(instance.getSpecialItems().getMysteryBook(group));
this.delay.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120); this.delay.put(event.getPlayer().getUniqueId(), System.currentTimeMillis() + 120);
}); });

View File

@ -14,6 +14,7 @@ public class Settings {
public static final ConfigSetting BLACK_MIN = new ConfigSetting(CONFIG, "Main.Black Scroll Min", 20); public static final ConfigSetting BLACK_MIN = new ConfigSetting(CONFIG, "Main.Black Scroll Min", 20);
public static final ConfigSetting BLACK_MAX = new ConfigSetting(CONFIG, "Main.Black Scroll Max", 100); public static final ConfigSetting BLACK_MAX = new ConfigSetting(CONFIG, "Main.Black Scroll Max", 100);
public static final ConfigSetting MODE = new ConfigSetting(CONFIG, "Main.Mode", "EXP", "Can be ECO or EXP");
public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(CONFIG, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(), public static final ConfigSetting ECONOMY_PLUGIN = new ConfigSetting(CONFIG, "Main.Economy", EconomyManager.getEconomy() == null ? "Vault" : EconomyManager.getEconomy().getName(),
"Which economy plugin should be used?", "Which economy plugin should be used?",

View File

@ -39,7 +39,8 @@ whitescroll:
applied: '&7This item is now protected!' applied: '&7This item is now protected!'
enchanter: enchanter:
cannotafford: '&cYou cannot afford this purchase.' cannotafford: '&cYou cannot afford this purchase.'
success: '&7Purchased &6{group_color}{group_name} &7book for &6{exp_cost} experience&7.' successexp: '&7Purchased &6{group_color}{group_name} &7book for &6{exp_cost} experience&7.'
successeco: '&7Purchased &6{group_color}{group_name} &7book for &6${eco_cost}&7.'
tinkerer: tinkerer:
open: '&7Trading with the tinkerer.' open: '&7Trading with the tinkerer.'
cancelled: '&cCancelled.' cancelled: '&cCancelled.'
@ -56,7 +57,8 @@ alchemist:
differentlevels: '&cThe alchemist can only combine books of the same level...' differentlevels: '&cThe alchemist can only combine books of the same level...'
differentgroups: '&cThe alchemist can only combine dust of the same group...' differentgroups: '&cThe alchemist can only combine dust of the same group...'
cannotafford: '&cYou cannot afford this exchange...' cannotafford: '&cYou cannot afford this exchange...'
success: '&7Exchanged for &6{exp_cost} &7experience.' successeco: '&7Exchanged for &6${eco_cost}.'
successexp: '&7Exchanged for &6{exp_cost} &7experience.'
enchants: enchants:
invalidmaterial: '&cYou can not apply &4{enchant}&r &cto that item...' invalidmaterial: '&cYou can not apply &4{enchant}&r &cto that item...'
failure: '&4{enchant}&r &cfailed to apply...' failure: '&4{enchant}&r &cfailed to apply...'

View File

@ -14,12 +14,12 @@ accept-slot: 31
book: book:
success-rate-formula: "({left_success_rate} + {right_success_rate}) / 4" success-rate-formula: "({left_success_rate} + {right_success_rate}) / 4"
destroy-rate-formula: "({left_destroy_rate} + {right_destroy_rate}) / 4 + {max_destroy_rate}" destroy-rate-formula: "({left_destroy_rate} + {right_destroy_rate}) / 4 + {max_destroy_rate}"
eco-cost-formula: "0" eco-cost-formula: "({group_order_index} + 1) * {final_success_rate} * 4"
exp-cost-formula: "({group_order_index} + 1) * {final_success_rate}" exp-cost-formula: "({group_order_index} + 1) * {final_success_rate}"
dust: dust:
percentage-formula: "({left_percentage} + {right_percentage}) / 2" percentage-formula: "({left_percentage} + {right_percentage}) / 2"
eco-cost-formula: "0" eco-cost-formula: "({group_order_index} + 1) * {final_success_rate} * 4"
exp-cost-formula: "({group_order_index} + 1) * {final_success_rate}" exp-cost-formula: "({group_order_index} + 1) * {final_success_rate}"
contents: contents:
@ -37,14 +37,14 @@ contents:
display-name: "&cWaiting for you..." display-name: "&cWaiting for you..."
lore: lore:
- "&7The alchemist is waiting" - "&7The alchemist is waiting"
- "&7for your enchange..." - "&7for your exchange..."
accept-after: accept-after:
material: INK_SACK material: INK_SACK
data: 10 data: 10
display-name: "&eClick to confirm" display-name: "&eClick to confirm"
lore: lore:
- "&cCost: {exp_cost} EXP" - "&cCost: {exp_cost} EXP"
- "" - "&cCost: ${eco_cost}"
- "&7Click to confirm the exchange" - "&7Click to confirm the exchange"
- "&7after which you will receive" - "&7after which you will receive"
- "&7the item displayed above." - "&7the item displayed above."
@ -73,4 +73,4 @@ contents:
material: STAINED_GLASS_PANE material: STAINED_GLASS_PANE
data: 3 data: 3
display-name: "&r" display-name: "&r"
slot: "2,3,5,6,18,26,38,39,40,41,42" slot: "2,3,5,6,18,26,38,39,40,41,42"

View File

@ -19,6 +19,7 @@ contents:
- "&fof possible enchants you could unlock!" - "&fof possible enchants you could unlock!"
- "" - ""
- "&b&lCOST &r&f{exp_cost} EXP" - "&b&lCOST &r&f{exp_cost} EXP"
- "&b&lCOST &r&f${eco_cost}"
group: SIMPLE group: SIMPLE
exp-cost: 400 exp-cost: 400
eco-cost: 0 eco-cost: 0
@ -35,6 +36,7 @@ contents:
- "&fof possible enchants you could unlock!" - "&fof possible enchants you could unlock!"
- "" - ""
- "&b&lCOST &r&f{exp_cost} EXP" - "&b&lCOST &r&f{exp_cost} EXP"
- "&b&lCOST &r&f${eco_cost}"
group: UNIQUE group: UNIQUE
exp-cost: 800 exp-cost: 800
eco-cost: 0 eco-cost: 0
@ -51,6 +53,7 @@ contents:
- "&fof possible enchants you could unlock!" - "&fof possible enchants you could unlock!"
- "" - ""
- "&b&lCOST &r&f{exp_cost} EXP" - "&b&lCOST &r&f{exp_cost} EXP"
- "&b&lCOST &r&f${eco_cost}"
group: ELITE group: ELITE
exp-cost: 2500 exp-cost: 2500
eco-cost: 0 eco-cost: 0
@ -67,6 +70,7 @@ contents:
- "&fof possible enchants you could unlock!" - "&fof possible enchants you could unlock!"
- "" - ""
- "&b&lCOST &r&f{exp_cost} EXP" - "&b&lCOST &r&f{exp_cost} EXP"
- "&b&lCOST &r&f${eco_cost}"
group: ULTIMATE group: ULTIMATE
exp-cost: 5000 exp-cost: 5000
eco-cost: 0 eco-cost: 0
@ -83,6 +87,7 @@ contents:
- "&fof possible enchants you could unlock!" - "&fof possible enchants you could unlock!"
- "" - ""
- "&b&lCOST &r&f{exp_cost} EXP" - "&b&lCOST &r&f{exp_cost} EXP"
- "&b&lCOST &r&f${eco_cost}"
group: LEGENDARY group: LEGENDARY
exp-cost: 25000 exp-cost: 25000
eco-cost: 0 eco-cost: 0