Added per item enchants limit.

This commit is contained in:
NeutralPlasma 2020-06-07 20:18:35 +02:00 committed by Brianna
parent 94efd34395
commit e79a37d297
5 changed files with 33 additions and 4 deletions

View File

@ -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());

View File

@ -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) {

View File

@ -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.

View File

@ -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

View File

@ -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