Skip to content

Commit

Permalink
make arrays final
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 6, 2024
1 parent f1d9d2b commit c4e2228
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,15 @@

public class IncompatibleEnchants extends IllegalItemModule {

private static final Enchantment[] DAMAGE_ENCHANTS = {
SHARPNESS.getEnchant(),
SMITE.getEnchant(),
BANE_OF_ARTHROPODS.getEnchant()};

private static final Enchantment[] PROTECTION_ENCHANTS = {
PROTECTION.getEnchant(),
BLAST_PROTECTION.getEnchant(),
FIRE_PROTECTION.getEnchant(),
PROJECTILE_PROTECTION.getEnchant()};

private final Set<Material> whitelistedTypes;
private final Enchantment[] damageEnchants, protectionEnchants;
private final boolean useWhitelist, blacklistMode, checkStored;

public IncompatibleEnchants() {
super("illegals.enchantments.incompatible-enchants", AEFPermission.BYPASS_ILLEGAL_ENCHANT_INCOMPATIBLE);
this.damageEnchants = new Enchantment[]{SHARPNESS.getEnchant(), SMITE.getEnchant(), BANE_OF_ARTHROPODS.getEnchant()};
this.protectionEnchants = new Enchantment[]{PROTECTION.getEnchant(), BLAST_PROTECTION.getEnchant(),
FIRE_PROTECTION.getEnchant(), PROJECTILE_PROTECTION.getEnchant()};
config.addComment(configPath + ".enable",
"Bypass permission: " + bypassPermission.string() + "\n" +
"Reverts or prevents usage of ItemStacks with Enchantments that\n" +
Expand Down Expand Up @@ -107,7 +100,7 @@ public ItemLegality legalityOf(ItemStack itemStack) {
return ItemLegality.ILLEGAL;

int dmgEnchCount = 0;
for (Enchantment damageEnchant : DAMAGE_ENCHANTS) {
for (Enchantment damageEnchant : damageEnchants) {
if (enchantments.contains(damageEnchant)) {
dmgEnchCount++;
if (dmgEnchCount > 1) {
Expand All @@ -117,7 +110,7 @@ public ItemLegality legalityOf(ItemStack itemStack) {
}

int protEnchCount = 0;
for (Enchantment protectEnchant : PROTECTION_ENCHANTS) {
for (Enchantment protectEnchant : protectionEnchants) {
if (enchantments.contains(protectEnchant)) {
protEnchCount++;
if (protEnchCount > 1) {
Expand Down Expand Up @@ -161,7 +154,7 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) {
itemStack.removeEnchantment(RIPTIDE.getEnchant());

if (enchantments.contains(SHARPNESS.getEnchant())) { // Prefer keeping sharpness enchantment if present
for (Enchantment dmgEnchant : DAMAGE_ENCHANTS) {
for (Enchantment dmgEnchant : damageEnchants) {
if (dmgEnchant != SHARPNESS.getEnchant()) {
itemStack.removeEnchantment(dmgEnchant);
}
Expand All @@ -171,13 +164,13 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) {
}

if (enchantments.contains(PROTECTION.getEnchant())) { // Prefer keeping protection enchantment if present
for (Enchantment protEnchant : PROTECTION_ENCHANTS) {
for (Enchantment protEnchant : protectionEnchants) {
if (protEnchant != PROTECTION.getEnchant()) {
itemStack.removeEnchantment(protEnchant);
}
}
} else if (enchantments.contains(BLAST_PROTECTION.getEnchant())) { // If protection isn't present, prefer blast protection
for (Enchantment protEnchant : PROTECTION_ENCHANTS) {
for (Enchantment protEnchant : protectionEnchants) {
if (protEnchant != BLAST_PROTECTION.getEnchant()) {
itemStack.removeEnchantment(protEnchant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,15 @@

public class IncompatibleEnchants extends IllegalItemModule {

private static final Enchantment[] DAMAGE_ENCHANTS = {
SHARPNESS.getEnchant(),
SMITE.getEnchant(),
BANE_OF_ARTHROPODS.getEnchant()};

private static final Enchantment[] PROTECTION_ENCHANTS = {
PROTECTION.getEnchant(),
BLAST_PROTECTION.getEnchant(),
FIRE_PROTECTION.getEnchant(),
PROJECTILE_PROTECTION.getEnchant()};

private final Set<Material> whitelistedTypes;
private final Enchantment[] damageEnchants, protectionEnchants;
private final boolean useWhitelist, blacklistMode, checkStored;

public IncompatibleEnchants() {
super("illegals.enchantments.incompatible-enchants", AEFPermission.BYPASS_ILLEGAL_ENCHANT_INCOMPATIBLE);
this.damageEnchants = new Enchantment[]{SHARPNESS.getEnchant(), SMITE.getEnchant(), BANE_OF_ARTHROPODS.getEnchant()};
this.protectionEnchants = new Enchantment[]{PROTECTION.getEnchant(), BLAST_PROTECTION.getEnchant(),
FIRE_PROTECTION.getEnchant(), PROJECTILE_PROTECTION.getEnchant()};
config.addComment(configPath + ".enable",
"Bypass permission: " + bypassPermission.string() + "\n" +
"Reverts or prevents usage of ItemStacks with Enchantments that\n" +
Expand Down Expand Up @@ -111,7 +104,7 @@ public ItemLegality legalityOf(ItemStack itemStack) {
}

int dmgEnchCount = 0;
for (Enchantment damageEnchant : DAMAGE_ENCHANTS) {
for (Enchantment damageEnchant : damageEnchants) {
if (enchantments.contains(damageEnchant)) {
dmgEnchCount++;
if (dmgEnchCount > 1) {
Expand All @@ -121,7 +114,7 @@ public ItemLegality legalityOf(ItemStack itemStack) {
}

int protEnchCount = 0;
for (Enchantment protectEnchant : PROTECTION_ENCHANTS) {
for (Enchantment protectEnchant : protectionEnchants) {
if (enchantments.contains(protectEnchant)) {
protEnchCount++;
if (protEnchCount > 1) {
Expand Down Expand Up @@ -170,7 +163,7 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) {
}

if (enchantments.contains(SHARPNESS.getEnchant())) { // Prefer keeping sharpness enchantment if present
for (Enchantment dmgEnchant : DAMAGE_ENCHANTS) {
for (Enchantment dmgEnchant : damageEnchants) {
if (dmgEnchant != SHARPNESS.getEnchant()) {
itemStack.removeEnchantment(dmgEnchant);
}
Expand All @@ -180,13 +173,13 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) {
}

if (enchantments.contains(PROTECTION.getEnchant())) { // Prefer keeping protection enchantment if present
for (Enchantment protEnchant : PROTECTION_ENCHANTS) {
for (Enchantment protEnchant : protectionEnchants) {
if (protEnchant != PROTECTION.getEnchant()) {
itemStack.removeEnchantment(protEnchant);
}
}
} else if (enchantments.contains(BLAST_PROTECTION.getEnchant())) { // If protection isn't present, prefer blast protection
for (Enchantment protEnchant : PROTECTION_ENCHANTS) {
for (Enchantment protEnchant : protectionEnchants) {
if (protEnchant != BLAST_PROTECTION.getEnchant()) {
itemStack.removeEnchantment(protEnchant);
}
Expand Down

0 comments on commit c4e2228

Please sign in to comment.