mirror of
https://github.com/songoda/EpicEnchants.git
synced 2024-11-13 06:07:41 +01:00
Added per item enchants limit.
This commit is contained in:
parent
94efd34395
commit
e79a37d297
@ -38,11 +38,10 @@ public class BookListener extends ItemListener {
|
||||
if (!enchant.getItemWhitelist().contains(current.getItem().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get total amount of enchantments on item
|
||||
int currentEnchantmentTotal = instance.getEnchantUtils().getEnchants(toApply).size();
|
||||
int maxAllowedApply = instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
|
||||
|
||||
//int maxAllowedApply = instance.getEnchantUtils().getMaximumEnchantsCanApply((Player) event.getWhoClicked());
|
||||
int maxAllowedApply = instance.getEnchantUtils().getMaximumEnchantsCanApplyItem(toApply,(Player) event.getWhoClicked());
|
||||
// item is at max enchantments
|
||||
if (currentEnchantmentTotal >= maxAllowedApply) {
|
||||
instance.getLocale().getMessage("enchants.maxallowed").processPlaceholder("max_enchants", maxAllowedApply).sendPrefixedMessage(event.getWhoClicked());
|
||||
|
@ -79,7 +79,8 @@ public class FileManager extends Manager<String, FileConfiguration> {
|
||||
|
||||
of("groups.yml", true),
|
||||
of("items/special-items.yml", true, true),
|
||||
of("items/dusts.yml", true, true)
|
||||
of("items/dusts.yml", true, true),
|
||||
of("items/item-limits.yml", true, true)
|
||||
));
|
||||
|
||||
public FileManager(EpicEnchants instance) {
|
||||
|
@ -144,6 +144,17 @@ public class EnchantUtils {
|
||||
return output.build();
|
||||
}
|
||||
|
||||
public int getMaximumEnchantsCanApplyItem(ItemStack itemStack ,Player p) {
|
||||
int max;
|
||||
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
|
||||
if(instance.getFileManager().getConfiguration("items/item-limits").contains("limits." + itemStack.getType().toString())){
|
||||
max = instance.getFileManager().getConfiguration("items/item-limits").getInt("limits." + itemStack.getType().toString());
|
||||
}else{
|
||||
max = instance.getFileManager().getConfiguration("items/item-limits").getInt("default");
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public int getMaximumEnchantsCanApply(Player p) {
|
||||
int max = 0;
|
||||
if (p.isOp()) return 100; // in theory no single item will have 100 enchantments at a time.
|
||||
|
@ -0,0 +1,9 @@
|
||||
# each item that's not specified in limits category will use default value
|
||||
default: 5
|
||||
|
||||
# Example of some of the items
|
||||
limits:
|
||||
DIAMOND_SWORD: 5
|
||||
IRON_SWORD: 2
|
||||
STONE_SWORD: 1
|
||||
|
@ -0,0 +1,9 @@
|
||||
# each item that's not specified in limits category will use default value
|
||||
default: 5
|
||||
|
||||
# Example of some of the items
|
||||
limits:
|
||||
DIAMOND_SWORD: 5
|
||||
IRON_SWORD: 2
|
||||
STONE_SWORD: 1
|
||||
|
Loading…
Reference in New Issue
Block a user