Optimized most mining enchantments

This commit is contained in:
Auxilor
2021-11-13 10:32:41 +00:00
parent b5df0a9031
commit e7788403e5
13 changed files with 32 additions and 20 deletions

View File

@@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@SuppressWarnings({"unchecked", "deprecation"})
@SuppressWarnings("deprecation")
public class CommandDebug extends Subcommand {
/**
* Instantiate a new /ecoenchants debug command handler.

View File

@@ -53,7 +53,7 @@ public class Arborist extends EcoEnchant {
List<Material> materials = new ArrayList<>();
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "items")) {
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "items", false)) {
Material material = Material.getMaterial(materialName.toUpperCase());
if (material != null) {
materials.add(material);

View File

@@ -42,7 +42,7 @@ public class Drill extends EcoEnchant {
Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(simplified));
block1.setMetadata("block-ignore", this.getPlugin().getMetadataValueFactory().create(true));
if (this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks").contains(block1.getType().name().toLowerCase())) {
if (this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks", false).contains(block1.getType().name().toLowerCase())) {
continue;
}

View File

@@ -45,7 +45,7 @@ public class Instantaneous extends EcoEnchant {
List<Material> blacklist = new ArrayList<>();
for (String s : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks")) {
for (String s : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks", false)) {
blacklist.add(Material.getMaterial(s));
}

View File

@@ -18,12 +18,25 @@ import java.util.List;
import java.util.Set;
public class Lumberjack extends EcoEnchant {
private final List<Material> materials = new ArrayList<>();
public Lumberjack() {
super(
"lumberjack", EnchantmentType.NORMAL
);
}
@Override
protected void postUpdate() {
materials.clear();
for (String string : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "whitelisted-blocks", false)) {
Material match = Material.getMaterial(string.toUpperCase());
if (match != null) {
materials.add(match);
}
}
}
@Override
public void onBlockBreak(@NotNull final Player player,
@NotNull final Block block,
@@ -37,9 +50,6 @@ public class Lumberjack extends EcoEnchant {
return;
}
List<Material> materials = new ArrayList<>();
this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "whitelisted-blocks").forEach(name -> materials.add(Material.getMaterial(name.toUpperCase())));
if (!materials.contains(block.getType())) {
return;
}

View File

@@ -72,7 +72,7 @@ public class Spearfishing extends EcoEnchant {
}
List<Material> potentialDrops = new ArrayList<>();
this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "drops").forEach(material -> {
this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "drops", false).forEach(material -> {
potentialDrops.add(Material.getMaterial(material.toUpperCase()));
});

View File

@@ -39,7 +39,7 @@ public class Transfuse extends EcoEnchant {
return;
}
if (!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "works-on").contains(block.getType().toString().toLowerCase())) {
if (!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "works-on", false).contains(block.getType().toString().toLowerCase())) {
return;
}
@@ -47,10 +47,10 @@ public class Transfuse extends EcoEnchant {
Material material;
double random = NumberUtils.randFloat(0, 1);
double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size();
double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false).size();
int selectedIndex = (int) Math.floor(random / band);
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1);
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex);
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false).size() - 1);
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false).get(selectedIndex);
material = Material.getMaterial(materialName.toUpperCase());
if (material == null) {
material = Material.COBBLESTONE;

View File

@@ -39,7 +39,9 @@ public class Vein extends EcoEnchant {
List<Material> materials = Collections.singletonList(block.getType());
if (!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "whitelisted-blocks").contains(block.getType().toString().toLowerCase())) {
if (!this.getConfig()
.getStrings(EcoEnchants.CONFIG_LOCATION + "whitelisted-blocks", false)
.contains(block.getType().toString().toLowerCase())) {
return;
}

View File

@@ -48,10 +48,10 @@ public class WoodSwitcher extends EcoEnchant {
Material material;
double random = NumberUtils.randFloat(0, 1);
double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size();
double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false).size();
int selectedIndex = (int) Math.floor(random / band);
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1);
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex);
selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false).size() - 1);
String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false).get(selectedIndex);
material = Material.getMaterial(materialName.toUpperCase());
if (material == null) {

View File

@@ -55,7 +55,7 @@ public class Dynamite extends Spell {
}
Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(x, y, z));
if (this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks").contains(block1.getType().name().toLowerCase())) {
if (this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks", false).contains(block1.getType().name().toLowerCase())) {
continue;
}

View File

@@ -48,7 +48,7 @@ public class Rainbow extends EcoEnchant {
List<Material> materials = new ArrayList<>();
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "items")) {
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "items", false)) {
Material material = Material.getMaterial(materialName.toUpperCase());
if (material != null) {
materials.add(material);

View File

@@ -67,7 +67,7 @@ public class SoftTouch extends EcoEnchant {
name = name.replace("[", "").replace("]", "");
meta.setDisplayName(name);
List<String> lore = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "lore");
List<String> lore = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "lore", false);
lore.replaceAll(s -> s.replace("%type%", entityName));
meta.setLore(lore);

View File

@@ -56,7 +56,7 @@ public class Xray extends Spell {
List<Material> materials = new ArrayList<>();
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks")) {
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks", false)) {
Material material = Material.getMaterial(materialName.toUpperCase());
if (material != null) {
materials.add(material);