mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-16 04:31:22 +01:00
Improved Codestyle (5/?)
This commit is contained in:
parent
d3f59c7f23
commit
e5baa4f895
@ -26,7 +26,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
int level = '\uffff' & compound.getShort("lvl");
|
||||
|
||||
Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key));
|
||||
if(found != null) foundEnchantments.put(found, level);
|
||||
if(found != null) {
|
||||
foundEnchantments.put(found, level);
|
||||
}
|
||||
}
|
||||
return foundEnchantments;
|
||||
}
|
||||
@ -40,8 +42,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
if(!key.equals(enchantment.getKey().toString()))
|
||||
if(!key.equals(enchantment.getKey().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return '\uffff' & compound.getShort("lvl");
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
int level = '\uffff' & compound.getShort("lvl");
|
||||
|
||||
Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key));
|
||||
if(found != null) foundEnchantments.put(found, level);
|
||||
if (found != null) {
|
||||
foundEnchantments.put(found, level);
|
||||
}
|
||||
}
|
||||
return foundEnchantments;
|
||||
}
|
||||
@ -40,8 +42,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
if(!key.equals(enchantment.getKey().toString()))
|
||||
if (!key.equals(enchantment.getKey().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return '\uffff' & compound.getShort("lvl");
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
int level = '\uffff' & compound.getShort("lvl");
|
||||
|
||||
Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key));
|
||||
if(found != null) foundEnchantments.put(found, level);
|
||||
if (found != null) {
|
||||
foundEnchantments.put(found, level);
|
||||
}
|
||||
}
|
||||
return foundEnchantments;
|
||||
}
|
||||
@ -40,8 +42,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
if(!key.equals(enchantment.getKey().toString()))
|
||||
if (!key.equals(enchantment.getKey().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return '\uffff' & compound.getShort("lvl");
|
||||
}
|
||||
|
@ -26,7 +26,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
int level = '\uffff' & compound.getShort("lvl");
|
||||
|
||||
Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key));
|
||||
if(found != null) foundEnchantments.put(found, level);
|
||||
if(found != null) {
|
||||
foundEnchantments.put(found, level);
|
||||
}
|
||||
}
|
||||
return foundEnchantments;
|
||||
}
|
||||
@ -40,8 +42,9 @@ public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
if(!key.equals(enchantment.getKey().toString()))
|
||||
if (!key.equals(enchantment.getKey().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return '\uffff' & compound.getShort("lvl");
|
||||
}
|
||||
|
@ -3,8 +3,11 @@ package com.willfp.ecoenchants.config;
|
||||
import com.willfp.eco.util.injection.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -20,8 +23,12 @@ import java.nio.charset.StandardCharsets;
|
||||
*/
|
||||
public abstract class EnchantmentYamlConfig extends PluginDependent {
|
||||
private final String name;
|
||||
public YamlConfiguration config;
|
||||
protected File configFile;
|
||||
|
||||
@Getter
|
||||
private YamlConfiguration config;
|
||||
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private File configFile;
|
||||
private final File directory;
|
||||
private final Class<?> source;
|
||||
private final EnchantmentType type;
|
||||
@ -33,14 +40,18 @@ public abstract class EnchantmentYamlConfig extends PluginDependent {
|
||||
* @param source The class of the main class of source or extension
|
||||
* @param type The enchantment type
|
||||
*/
|
||||
protected EnchantmentYamlConfig(String name, Class<?> source, EnchantmentType type) {
|
||||
protected EnchantmentYamlConfig(@NotNull final String name,
|
||||
@NotNull final Class<?> source,
|
||||
@NotNull final EnchantmentType type) {
|
||||
super(AbstractEcoPlugin.getInstance());
|
||||
this.name = name;
|
||||
this.source = source;
|
||||
this.type = type;
|
||||
|
||||
File basedir = new File(this.getPlugin().getDataFolder(), "enchants/");
|
||||
if (!basedir.exists()) basedir.mkdirs();
|
||||
if (!basedir.exists()) {
|
||||
basedir.mkdirs();
|
||||
}
|
||||
|
||||
File dir = new File(basedir, type.getName() + "/");
|
||||
if (!dir.exists()) {
|
||||
@ -105,8 +116,9 @@ public abstract class EnchantmentYamlConfig extends PluginDependent {
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
newConfig.load(reader);
|
||||
|
||||
if (newConfig.getKeys(true).equals(config.getKeys(true)))
|
||||
if (newConfig.getKeys(true).equals(config.getKeys(true))) {
|
||||
return;
|
||||
}
|
||||
|
||||
newConfig.getKeys(true).forEach((s -> {
|
||||
if (!config.getKeys(true).contains(s)) {
|
||||
|
@ -9,6 +9,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
@ -21,7 +22,9 @@ import java.util.Set;
|
||||
public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
private final String name;
|
||||
|
||||
public EnchantmentConfig(String name, Class<?> plugin, EnchantmentType type) {
|
||||
public EnchantmentConfig(@NotNull final String name,
|
||||
@NotNull final Class<?> plugin,
|
||||
@NotNull final EnchantmentType type) {
|
||||
super(name, plugin, type);
|
||||
this.name = name;
|
||||
}
|
||||
@ -30,53 +33,55 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
public int getInt(@NotNull final String path) {
|
||||
return this.getConfig().getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
public int getInt(@NotNull final String path,
|
||||
final int def) {
|
||||
return this.getConfig().getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
return this.getConfig().getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
public boolean getBool(@NotNull final String path) {
|
||||
return this.getConfig().getBoolean(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path, boolean def) {
|
||||
return config.getBoolean(path, def);
|
||||
public boolean getBool(@NotNull final String path,
|
||||
final boolean def) {
|
||||
return this.getConfig().getBoolean(path, def);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
public List<Boolean> getBools(@NotNull final String path) {
|
||||
return this.getConfig().getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
public String getString(@NotNull final String path) {
|
||||
return this.getConfig().getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
return this.getConfig().getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
public double getDouble(@NotNull final String path) {
|
||||
return this.getConfig().getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
public List<Double> getDoubles(@NotNull final String path) {
|
||||
return this.getConfig().getDoubleList(path);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path) {
|
||||
return config.getItemStack(path);
|
||||
public ItemStack getItemStack(@NotNull final String path) {
|
||||
return this.getConfig().getItemStack(path);
|
||||
}
|
||||
|
||||
public Set<Enchantment> getEnchantments(String path) {
|
||||
public Set<Enchantment> getEnchantments(@NotNull final String path) {
|
||||
Set<Enchantment> enchantments = new HashSet<>();
|
||||
List<String> enchantmentKeys = config.getStringList(path);
|
||||
List<String> enchantmentKeys = this.getConfig().getStringList(path);
|
||||
enchantmentKeys.forEach((key -> enchantments.add(Enchantment.getByKey(NamespacedKey.minecraft(key)))));
|
||||
return enchantments;
|
||||
}
|
||||
@ -87,8 +92,10 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
}
|
||||
|
||||
public Set<EnchantmentTarget> getTargets() {
|
||||
List<String> targetNames = config.getStringList(EcoEnchants.GENERAL_LOCATION + "targets");
|
||||
if (targetNames.isEmpty()) return new HashSet<>();
|
||||
List<String> targetNames = this.getConfig().getStringList(EcoEnchants.GENERAL_LOCATION + "targets");
|
||||
if (targetNames.isEmpty()) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
Set<EnchantmentTarget> targets = new HashSet<>();
|
||||
|
||||
targetNames.forEach((s -> {
|
||||
@ -102,13 +109,14 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
}
|
||||
|
||||
public void loadFromLang() {
|
||||
if (!Configs.LANG.config.contains("enchantments." + this.getName()))
|
||||
if (!Configs.LANG.getConfig().contains("enchantments." + this.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
config.set("name", Configs.LANG.getString("enchantments." + this.getName() + ".name"));
|
||||
config.set("description", Configs.LANG.getString("enchantments." + this.getName() + ".description"));
|
||||
this.getConfig().set("name", Configs.LANG.getString("enchantments." + this.getName() + ".name"));
|
||||
this.getConfig().set("description", Configs.LANG.getString("enchantments." + this.getName() + ".description"));
|
||||
try {
|
||||
this.config.save(this.configFile);
|
||||
this.getConfig().save(this.getConfigFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -7,8 +7,11 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -17,13 +20,24 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class EnchantmentCache implements Updatable {
|
||||
private static final Set<CacheEntry> CACHE = new HashSet<>();
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
public static CacheEntry getEntry(Enchantment enchantment) {
|
||||
public static CacheEntry getEntry(@NotNull final Enchantment enchantment) {
|
||||
Optional<CacheEntry> matching = CACHE.stream().filter(entry -> entry.getEnchantment().getKey().getKey().equals(enchantment.getKey().getKey())).findFirst();
|
||||
return matching.orElse(new CacheEntry(enchantment, EnchantDisplay.PREFIX + "§7" + enchantment.getKey().getKey(), enchantment.getKey().getKey(), Collections.singletonList(EnchantDisplay.PREFIX + "No Description Found"), EnchantmentType.NORMAL, EnchantmentRarity.values().stream().findFirst().get()));
|
||||
return matching.orElse(
|
||||
new CacheEntry(
|
||||
enchantment,
|
||||
EnchantDisplay.PREFIX + "§7" + enchantment.getKey().getKey(),
|
||||
enchantment.getKey().getKey(),
|
||||
Collections.singletonList(EnchantDisplay.PREFIX + "No Description Found"),
|
||||
EnchantmentType.NORMAL,
|
||||
EnchantmentRarity.values().stream().findFirst().get()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static Set<CacheEntry> getCache() {
|
||||
@ -71,7 +85,7 @@ public class EnchantmentCache implements Updatable {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ToString
|
||||
public static class CacheEntry {
|
||||
private final Enchantment enchantment;
|
||||
private final String name;
|
||||
@ -81,7 +95,12 @@ public class EnchantmentCache implements Updatable {
|
||||
private final EnchantmentType type;
|
||||
private final EnchantmentRarity rarity;
|
||||
|
||||
public CacheEntry(Enchantment enchantment, String name, String rawName, List<String> description, EnchantmentType type, EnchantmentRarity rarity) {
|
||||
public CacheEntry(@NotNull final Enchantment enchantment,
|
||||
@NotNull final String name,
|
||||
@NotNull final String rawName,
|
||||
@NotNull final List<String> description,
|
||||
@NotNull final EnchantmentType type,
|
||||
@NotNull final EnchantmentRarity rarity) {
|
||||
this.enchantment = enchantment;
|
||||
this.name = name;
|
||||
this.rawName = rawName;
|
||||
@ -128,16 +147,5 @@ public class EnchantmentCache implements Updatable {
|
||||
public EnchantmentRarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CacheEntry{" +
|
||||
"enchantment=" + enchantment +
|
||||
"§f, name='" + name + '\'' +
|
||||
"§f, rawName='" + rawName + '\'' +
|
||||
"§f, description=" + description +
|
||||
"§f, stringDescription='" + stringDescription + '\'' +
|
||||
"§f}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EnchantmentSorter {
|
||||
void sortEnchantments(final List<Enchantment> toSort);
|
||||
void sortEnchantments(@NotNull List<Enchantment> toSort);
|
||||
SortParameters[] getParameters();
|
||||
}
|
||||
|
@ -4,12 +4,13 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,14 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class LengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -12,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class RarityAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = toSort.stream()
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -13,7 +14,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class RarityLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = toSort.stream()
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -12,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class RarityTypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -13,7 +14,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class RarityTypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -12,7 +13,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class TypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
@ -13,7 +14,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class TypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
|
@ -227,7 +227,6 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Quake;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Vitalize;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -13,4 +13,4 @@ public class EnchantmentArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.ENCHANTMENT_TABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class EndArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.END_ROD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,4 +13,4 @@ public class FireArtifact extends Artifact {
|
||||
public Particle getParticle() {
|
||||
return Particle.FLAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FragilityCurse extends EcoEnchant {
|
||||
public FragilityCurse() {
|
||||
@ -19,12 +20,16 @@ public class FragilityCurse extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onItemDamage(PlayerItemDamageEvent event) {
|
||||
public void onItemDamage(@NotNull final PlayerItemDamageEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
if (!EnchantChecks.item(item, this)) return;
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(event.getPlayer().getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(event.getPlayer().getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int min = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "minimum-extra-durability");
|
||||
int max = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "maximum-extra-durability");
|
||||
|
@ -8,6 +8,8 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Electroshock extends EcoEnchant {
|
||||
public Electroshock() {
|
||||
super(
|
||||
@ -18,11 +20,15 @@ public class Electroshock extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) {
|
||||
public void onDeflect(@NotNull final Player blocker,
|
||||
@NotNull final LivingEntity attacker,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage");
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LightningUtils.strike(attacker, damage);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EndInfusion extends EcoEnchant {
|
||||
public EndInfusion() {
|
||||
@ -18,9 +19,13 @@ public class EndInfusion extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if(!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END))
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
public class EnderSlayer extends EcoEnchant {
|
||||
@ -18,7 +19,7 @@ public class EnderSlayer extends EcoEnchant {
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
private static final Set<EntityType> endMobs = new ImmutableSet.Builder<EntityType>()
|
||||
private static final Set<EntityType> END_MOBS = new ImmutableSet.Builder<EntityType>()
|
||||
.add(EntityType.ENDERMITE)
|
||||
.add(EntityType.ENDERMAN)
|
||||
.add(EntityType.ENDER_DRAGON)
|
||||
@ -27,9 +28,13 @@ public class EnderSlayer extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if (!endMobs.contains(victim.getType()))
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!END_MOBS.contains(victim.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Enderism extends EcoEnchant {
|
||||
public Enderism() {
|
||||
@ -22,9 +23,14 @@ public class Enderism extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
|
||||
if(!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END))
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
@ -32,21 +38,28 @@ public class Enderism extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHit(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Arrow))
|
||||
public void onHit(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Arrow)) {
|
||||
return;
|
||||
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player))
|
||||
}
|
||||
if (!(((Arrow) event.getDamager()).getShooter() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) ((Arrow) event.getDamager()).getShooter();
|
||||
Arrow arrow = (Arrow) event.getDamager();
|
||||
|
||||
assert player != null;
|
||||
if(!player.getWorld().getEnvironment().equals(World.Environment.THE_END))
|
||||
if (!player.getWorld().getEnvironment().equals(World.Environment.THE_END)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantChecks.arrow(arrow, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (!EnchantChecks.arrow(arrow, this)) {
|
||||
return;
|
||||
}
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getArrowLevel(arrow, this);
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
@ -5,6 +5,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Evasion extends EcoEnchant {
|
||||
public Evasion() {
|
||||
super(
|
||||
@ -16,10 +18,13 @@ public class Evasion extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {
|
||||
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Extinguishing extends EcoEnchant {
|
||||
public Extinguishing() {
|
||||
super(
|
||||
@ -15,13 +17,16 @@ public class Extinguishing extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {
|
||||
if(!event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK))
|
||||
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
if (!event.getCause().equals(EntityDamageEvent.DamageCause.FIRE_TICK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
victim.setFireTicks(0);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Extract extends EcoEnchant {
|
||||
public Extract() {
|
||||
super(
|
||||
@ -18,7 +20,11 @@ public class Extract extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level");
|
||||
double amountToHeal = level * multiplier;
|
||||
double newHealth = attacker.getHealth() + amountToHeal;
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Famine extends EcoEnchant {
|
||||
public Famine() {
|
||||
@ -23,14 +24,18 @@ public class Famine extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
victim.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, level * 40, level));
|
||||
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, level * 40, level));
|
||||
|
@ -16,6 +16,8 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Farmhand extends EcoEnchant {
|
||||
public Farmhand() {
|
||||
super(
|
||||
@ -26,27 +28,37 @@ public class Farmhand extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onTill(PlayerInteractEvent event) {
|
||||
public void onTill(@NotNull final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
if (!event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClickedBlock() == null)
|
||||
if (event.getClickedBlock() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getClickedBlock().getType().equals(Material.DIRT) || event.getClickedBlock().getType().equals(Material.GRASS_BLOCK)))
|
||||
if (!(event.getClickedBlock().getType().equals(Material.DIRT) || event.getClickedBlock().getType().equals(Material.GRASS_BLOCK))) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
if (!EnchantChecks.item(item, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if (!item.getType().toString().endsWith("_HOE"))
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!AntigriefManager.canBreakBlock(player, event.getClickedBlock())) return;
|
||||
if (!item.getType().toString().endsWith("_HOE")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, event.getClickedBlock())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getClickedBlock().setType(Material.FARMLAND);
|
||||
int initial = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-radius");
|
||||
@ -69,13 +81,17 @@ public class Farmhand extends EcoEnchant {
|
||||
Location loc = event.getClickedBlock().getLocation().add(vec);
|
||||
Block block = event.getClickedBlock().getWorld().getBlockAt(loc);
|
||||
|
||||
if(!AntigriefManager.canBreakBlock(player, block)) continue;
|
||||
|
||||
if (!(block.getType().equals(Material.DIRT) || block.getType().equals(Material.GRASS_BLOCK)))
|
||||
if (!AntigriefManager.canBreakBlock(player, block)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!block.getWorld().getBlockAt(loc.add(0, 1, 0)).getType().equals(Material.AIR))
|
||||
if (!(block.getType().equals(Material.DIRT) || block.getType().equals(Material.GRASS_BLOCK))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!block.getWorld().getBlockAt(loc.add(0, 1, 0)).getType().equals(Material.AIR)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
block.setType(Material.FARMLAND);
|
||||
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "per-block-damage")) {
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -25,27 +26,32 @@ public class Fetching extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onWolfKill(EntityDeathByEntityEvent event) {
|
||||
public void onWolfKill(@NotNull final EntityDeathByEntityEvent event) {
|
||||
LivingEntity entity = event.getVictim();
|
||||
|
||||
if(entity instanceof Player && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "not-on-players"))
|
||||
if (entity instanceof Player && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "not-on-players")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(event.getKiller() instanceof Wolf))
|
||||
if (!(event.getKiller() instanceof Wolf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Wolf wolf = (Wolf) event.getKiller();
|
||||
|
||||
if(!wolf.isTamed() || wolf.getOwner() == null)
|
||||
if (!wolf.isTamed() || wolf.getOwner() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(wolf.getOwner() instanceof Player))
|
||||
if (!(wolf.getOwner() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) wolf.getOwner();
|
||||
|
||||
if(!(EnchantChecks.helmet(player, this)))
|
||||
if (!(EnchantChecks.helmet(player, this))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int xp = event.getXp();
|
||||
Collection<ItemStack> drops = event.getDrops();
|
||||
|
@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Finality extends EcoEnchant {
|
||||
public Finality() {
|
||||
@ -19,14 +20,20 @@ public class Finality extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double minhealth = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "minimum-health-per-level");
|
||||
if (victim.getHealth() > level * minhealth)
|
||||
if (victim.getHealth() > level * minhealth) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(30); // cba to do this properly
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Finishing extends EcoEnchant {
|
||||
public Finishing() {
|
||||
super(
|
||||
@ -17,14 +19,19 @@ public class Finishing extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double minhealth = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "minimum-health-per-level");
|
||||
if (victim.getHealth() > level * minhealth)
|
||||
if (victim.getHealth() > level * minhealth) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(30); // cba to do this properly
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FireAffinity extends EcoEnchant {
|
||||
public FireAffinity() {
|
||||
super(
|
||||
@ -16,8 +18,13 @@ public class FireAffinity extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if(attacker.getFireTicks() == 0) return;
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker.getFireTicks() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
@ -6,6 +6,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FirstStrike extends EcoEnchant {
|
||||
public FirstStrike() {
|
||||
super(
|
||||
@ -16,9 +18,13 @@ public class FirstStrike extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if (victim.getHealth() != victim.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (victim.getHealth() != victim.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Flinch extends EcoEnchant {
|
||||
public Flinch() {
|
||||
@ -21,11 +22,15 @@ public class Flinch extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDeflect(Player blocker, LivingEntity attacker, int level, EntityDamageByEntityEvent event) {
|
||||
public void onDeflect(@NotNull final Player blocker,
|
||||
@NotNull final LivingEntity attacker,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level");
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int finalDuration = duration * level;
|
||||
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -26,17 +27,17 @@ public class Forcefield extends EcoEnchant implements EcoRunnable {
|
||||
private final HashMap<Player, Integer> players = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(ArmorEquipEvent event) {
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
public void onPlayerJoin(@NotNull final PlayerJoinEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
public void onPlayerLeave(@NotNull final PlayerQuitEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ public class Forcefield extends EcoEnchant implements EcoRunnable {
|
||||
players.clear();
|
||||
this.getPlugin().getServer().getOnlinePlayers().forEach(player -> {
|
||||
int level = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
if(level > 0) {
|
||||
if (level > 0) {
|
||||
players.put(player, level);
|
||||
}
|
||||
});
|
||||
@ -53,7 +54,9 @@ public class Forcefield extends EcoEnchant implements EcoRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
players.forEach((player, level) -> {
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
double initialDistance = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance");
|
||||
double bonus = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
|
||||
double distance = initialDistance + (level * bonus);
|
||||
@ -61,11 +64,13 @@ public class Forcefield extends EcoEnchant implements EcoRunnable {
|
||||
final double damage = damagePerPoint * level;
|
||||
|
||||
for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, 2.0d, distance)) {
|
||||
if(!(e instanceof Monster)) continue;
|
||||
if (!(e instanceof Monster)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
((Monster) e).damage(damage);
|
||||
|
||||
if(NumberUtils.randFloat(0, 1) < 0.2) {
|
||||
if (NumberUtils.randFloat(0, 1) < 0.2) {
|
||||
EnchantChecks.getArmorPoints(player, EcoEnchants.FORCEFIELD, 1);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Freerunner extends EcoEnchant {
|
||||
public Freerunner() {
|
||||
super(
|
||||
@ -16,10 +18,13 @@ public class Freerunner extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onFallDamage(LivingEntity faller, int level, EntityDamageEvent event) {
|
||||
public void onFallDamage(@NotNull final LivingEntity faller,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Frozen extends EcoEnchant {
|
||||
public Frozen() {
|
||||
@ -22,25 +23,30 @@ public class Frozen extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onHurt(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
public void onHurt(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(event.getDamager() instanceof LivingEntity))
|
||||
if (!(event.getDamager() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
LivingEntity victim = (LivingEntity) event.getDamager();
|
||||
|
||||
final int points = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
|
||||
if (points == 0)
|
||||
if (points == 0) {
|
||||
return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, points))
|
||||
}
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, points)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int divisor = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "points-per-level");
|
||||
final int level = (int) Math.ceil((double) points / divisor);
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.entity.PigZombie;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Fury extends EcoEnchant {
|
||||
public Fury() {
|
||||
@ -25,20 +26,28 @@ public class Fury extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player
|
||||
&& ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f
|
||||
&& !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double distancePerLevel = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance-per-level");
|
||||
final double distance = distancePerLevel * level;
|
||||
|
||||
for (Entity e : victim.getWorld().getNearbyEntities(victim.getLocation(), distance, distance, distance)) {
|
||||
if (!(e instanceof Monster)) continue;
|
||||
if (!(e instanceof Monster)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e instanceof PigZombie) {
|
||||
((PigZombie) e).setAngry(true);
|
||||
|
@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Goliath extends EcoEnchant {
|
||||
public Goliath() {
|
||||
@ -18,16 +19,20 @@ public class Goliath extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if (victim.getHealth() <= attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (victim.getHealth() <= attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double timesMoreHealth = victim.getHealth() / attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = 1 + (multiplier * level * timesMoreHealth);
|
||||
if(bonus - 1 > this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-cap")) {
|
||||
if (bonus - 1 > this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-cap")) {
|
||||
bonus = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-cap") + 1;
|
||||
}
|
||||
event.setDamage(damage * bonus);
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Energizing extends EcoEnchant {
|
||||
public Energizing() {
|
||||
@ -19,7 +20,10 @@ public class Energizing extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level") * level;
|
||||
int amplifier = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-level") + (level - 2);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Force extends EcoEnchant {
|
||||
public Force() {
|
||||
@ -18,7 +19,11 @@ public class Force extends EcoEnchant {
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = (multiplier * (level + 6)) + 1;
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Frenzy extends EcoEnchant {
|
||||
public Frenzy() {
|
||||
@ -19,15 +20,20 @@ public class Frenzy extends EcoEnchant {
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onFrenzyKill(EntityDeathEvent event) {
|
||||
if (event.getEntity().getKiller() == null)
|
||||
public void onFrenzyKill(@NotNull final EntityDeathEvent event) {
|
||||
if (event.getEntity().getKiller() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getEntity().getKiller();
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) return;
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
|
@ -8,6 +8,8 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
@ -17,7 +19,7 @@ import java.util.Set;
|
||||
* Class for storing all enchantment rarities
|
||||
*/
|
||||
public class EnchantmentRarity implements Registerable, Updatable {
|
||||
private static final Set<EnchantmentRarity> rarities = new HashSet<>();
|
||||
private static final Set<EnchantmentRarity> REGISTERED = new HashSet<>();
|
||||
|
||||
private final String name;
|
||||
private final double probability;
|
||||
@ -36,7 +38,12 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
* @param lootProbability The probability of an item in a loot chest having an enchantment with this rarity
|
||||
* @param customColor The custom display color, or null if not enabled
|
||||
*/
|
||||
public EnchantmentRarity(String name, double probability, int minimumLevel, double villagerProbability, double lootProbability, String customColor) {
|
||||
public EnchantmentRarity(@NotNull final String name,
|
||||
final double probability,
|
||||
final int minimumLevel,
|
||||
final double villagerProbability,
|
||||
final double lootProbability,
|
||||
@Nullable final String customColor) {
|
||||
this.name = name;
|
||||
this.probability = probability;
|
||||
this.minimumLevel = minimumLevel;
|
||||
@ -47,31 +54,31 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
Optional<EnchantmentRarity> matching = rarities.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
matching.ifPresent(rarities::remove);
|
||||
Optional<EnchantmentRarity> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
matching.ifPresent(REGISTERED::remove);
|
||||
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_probability",
|
||||
(player) -> NumberUtils.format(this.probability)
|
||||
player -> NumberUtils.format(this.probability)
|
||||
));
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_minlevel",
|
||||
(player) -> NumberUtils.format(this.minimumLevel)
|
||||
player -> NumberUtils.format(this.minimumLevel)
|
||||
));
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_villagerprobability",
|
||||
(player) -> NumberUtils.format(this.villagerProbability)
|
||||
player -> NumberUtils.format(this.villagerProbability)
|
||||
));
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_lootprobability",
|
||||
(player) -> NumberUtils.format(this.lootProbability)
|
||||
player -> NumberUtils.format(this.lootProbability)
|
||||
));
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_color",
|
||||
(player) -> this.customColor
|
||||
player -> this.customColor
|
||||
));
|
||||
|
||||
rarities.add(this);
|
||||
REGISTERED.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,8 +151,8 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
*
|
||||
* @return The matching EnchantmentRarity, or null if not found
|
||||
*/
|
||||
public static EnchantmentRarity getByName(String name) {
|
||||
Optional<EnchantmentRarity> matching = rarities.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
public static EnchantmentRarity getByName(@NotNull final String name) {
|
||||
Optional<EnchantmentRarity> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
return matching.orElse(null);
|
||||
}
|
||||
|
||||
@ -156,7 +163,7 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
Set<String> raritiesNames = EcoEnchantsConfigs.RARITY.getRarities();
|
||||
raritiesNames.forEach((rarity) -> {
|
||||
raritiesNames.forEach(rarity -> {
|
||||
double probability = EcoEnchantsConfigs.RARITY.getDouble("rarities." + rarity + ".table-probability");
|
||||
int minimumLevel = EcoEnchantsConfigs.RARITY.getInt("rarities." + rarity + ".minimum-level");
|
||||
double villagerProbability = EcoEnchantsConfigs.RARITY.getDouble("rarities." + rarity + ".villager-probability");
|
||||
@ -176,7 +183,7 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
* @return A set of all rarities
|
||||
*/
|
||||
public static Set<EnchantmentRarity> values() {
|
||||
return rarities;
|
||||
return REGISTERED;
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -6,6 +6,7 @@ import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
@ -16,11 +17,11 @@ import java.util.Set;
|
||||
* Class for storing all enchantment rarities
|
||||
*/
|
||||
public class EnchantmentTarget implements Registerable, Updatable {
|
||||
private static final Set<EnchantmentTarget> targets = new HashSet<>();
|
||||
private static final Set<EnchantmentTarget> REGISTERED = new HashSet<>();
|
||||
public static final EnchantmentTarget ALL = new EnchantmentTarget("all", new HashSet<>());
|
||||
|
||||
static {
|
||||
targets.add(ALL);
|
||||
REGISTERED.add(ALL);
|
||||
}
|
||||
|
||||
private final String name;
|
||||
@ -32,7 +33,8 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
* @param name The name of the rarity
|
||||
* @param materials The items for the target
|
||||
*/
|
||||
public EnchantmentTarget(String name, Set<Material> materials) {
|
||||
public EnchantmentTarget(@NotNull final String name,
|
||||
@NotNull final Set<Material> materials) {
|
||||
this.name = name;
|
||||
materials.removeIf(Objects::isNull);
|
||||
this.materials = materials;
|
||||
@ -40,10 +42,10 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
Optional<EnchantmentTarget> matching = targets.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
matching.ifPresent(targets::remove);
|
||||
Optional<EnchantmentTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
matching.ifPresent(REGISTERED::remove);
|
||||
matching.ifPresent(enchantmentTarget -> ALL.materials.removeAll(enchantmentTarget.getMaterials()));
|
||||
targets.add(this);
|
||||
REGISTERED.add(this);
|
||||
ALL.materials.addAll(this.getMaterials());
|
||||
}
|
||||
|
||||
@ -72,8 +74,8 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
*
|
||||
* @return The matching EnchantmentTarget, or null if not found
|
||||
*/
|
||||
public static EnchantmentTarget getByName(String name) {
|
||||
Optional<EnchantmentTarget> matching = targets.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
public static EnchantmentTarget getByName(@NotNull final String name) {
|
||||
Optional<EnchantmentTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
return matching.orElse(null);
|
||||
}
|
||||
|
||||
@ -85,7 +87,7 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
public static void update() {
|
||||
Set<String> targetNames = EcoEnchantsConfigs.TARGET.getTargets();
|
||||
ALL.materials.clear();
|
||||
targetNames.forEach((name) -> {
|
||||
targetNames.forEach(name -> {
|
||||
Set<Material> materials = EcoEnchantsConfigs.TARGET.getTargetMaterials(name);
|
||||
new EnchantmentTarget(name, materials).register();
|
||||
});
|
||||
@ -97,7 +99,7 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
* @return A set of all rarities
|
||||
*/
|
||||
public static Set<EnchantmentTarget> values() {
|
||||
return targets;
|
||||
return REGISTERED;
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -7,18 +7,42 @@ import com.willfp.eco.util.lambda.ObjectCallable;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EnchantmentType implements Updatable {
|
||||
private static final List<EnchantmentType> values = new ArrayList<>();
|
||||
private static final List<EnchantmentType> REGISTERED = new ArrayList<>();
|
||||
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType("normal", false, () -> Configs.LANG.getString("not-curse-color"));
|
||||
public static final EnchantmentType CURSE = new EnchantmentType("curse", false, () -> Configs.LANG.getString("curse-color"));
|
||||
public static final EnchantmentType SPECIAL = new EnchantmentType("special", () -> !Configs.CONFIG.getBool("types.special.allow-multiple"), () -> Configs.LANG.getString("special-color"));
|
||||
public static final EnchantmentType ARTIFACT = new EnchantmentType("artifact", () -> !Configs.CONFIG.getBool("types.artifact.allow-multiple"), () -> Configs.LANG.getString("artifact-color"), Artifact.class);
|
||||
public static final EnchantmentType SPELL = new EnchantmentType("spell", true, () -> Configs.LANG.getString("spell-color"), Spell.class);
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType(
|
||||
"normal",
|
||||
false,
|
||||
() -> Configs.LANG.getString("not-curse-color")
|
||||
);
|
||||
public static final EnchantmentType CURSE = new EnchantmentType(
|
||||
"curse",
|
||||
false,
|
||||
() -> Configs.LANG.getString("curse-color")
|
||||
);
|
||||
public static final EnchantmentType SPECIAL = new EnchantmentType(
|
||||
"special",
|
||||
() -> !Configs.CONFIG.getBool("types.special.allow-multiple"),
|
||||
() -> Configs.LANG.getString("special-color")
|
||||
);
|
||||
public static final EnchantmentType ARTIFACT = new EnchantmentType(
|
||||
"artifact",
|
||||
() -> !Configs.CONFIG.getBool("types.artifact.allow-multiple"),
|
||||
() -> Configs.LANG.getString("artifact-color"),
|
||||
Artifact.class
|
||||
);
|
||||
public static final EnchantmentType SPELL = new EnchantmentType(
|
||||
"spell",
|
||||
true,
|
||||
() -> Configs.LANG.getString("spell-color"),
|
||||
Spell.class
|
||||
);
|
||||
|
||||
private boolean singular;
|
||||
private String color;
|
||||
@ -36,7 +60,9 @@ public class EnchantmentType implements Updatable {
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param color The color for enchantments with this type in lore to have
|
||||
*/
|
||||
public EnchantmentType(String name, boolean singular, String color) {
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
final boolean singular,
|
||||
@NotNull final String color) {
|
||||
this(name, () -> singular, () -> color);
|
||||
}
|
||||
|
||||
@ -49,7 +75,9 @@ public class EnchantmentType implements Updatable {
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
*/
|
||||
public EnchantmentType(String name, boolean singular, ObjectCallable<String> colorCallable) {
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
final boolean singular,
|
||||
@NotNull final ObjectCallable<String> colorCallable) {
|
||||
this(name, () -> singular, colorCallable);
|
||||
}
|
||||
|
||||
@ -63,7 +91,10 @@ public class EnchantmentType implements Updatable {
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required
|
||||
*/
|
||||
public EnchantmentType(String name, boolean singular, ObjectCallable<String> colorCallable, Class<? extends EcoEnchant> requiredToExtend) {
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
final boolean singular,
|
||||
@NotNull final ObjectCallable<String> colorCallable,
|
||||
@Nullable final Class<? extends EcoEnchant> requiredToExtend) {
|
||||
this(name, () -> singular, colorCallable, requiredToExtend);
|
||||
}
|
||||
|
||||
@ -74,7 +105,9 @@ public class EnchantmentType implements Updatable {
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
*/
|
||||
public EnchantmentType(String name, ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable) {
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
@NotNull final ObjectCallable<Boolean> singularCallable,
|
||||
@NotNull final ObjectCallable<String> colorCallable) {
|
||||
this(name, singularCallable, colorCallable, null);
|
||||
}
|
||||
|
||||
@ -86,14 +119,17 @@ public class EnchantmentType implements Updatable {
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required
|
||||
*/
|
||||
public EnchantmentType(String name, ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable, Class<? extends EcoEnchant> requiredToExtend) {
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
@NotNull final ObjectCallable<Boolean> singularCallable,
|
||||
@NotNull final ObjectCallable<String> colorCallable,
|
||||
@Nullable final Class<? extends EcoEnchant> requiredToExtend) {
|
||||
this.name = name;
|
||||
this.singularCallable = singularCallable;
|
||||
this.colorCallable = colorCallable;
|
||||
this.requiredToExtend = requiredToExtend;
|
||||
color = colorCallable.call();
|
||||
singular = singularCallable.call();
|
||||
values.add(this);
|
||||
REGISTERED.add(this);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
@ -119,10 +155,10 @@ public class EnchantmentType implements Updatable {
|
||||
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
values.forEach(EnchantmentType::refresh);
|
||||
REGISTERED.forEach(EnchantmentType::refresh);
|
||||
}
|
||||
|
||||
public static List<EnchantmentType> values() {
|
||||
return new ArrayList<>(values);
|
||||
return new ArrayList<>(REGISTERED);
|
||||
}
|
||||
}
|
||||
|
@ -8,48 +8,73 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class EnchantmentUtils {
|
||||
public static boolean passedChance(EcoEnchant enchantment, int level) {
|
||||
public static boolean passedChance(@NotNull final EcoEnchant enchantment,
|
||||
final int level) {
|
||||
return NumberUtils.randFloat(0, 1) < ((enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level") * level) / 100);
|
||||
}
|
||||
|
||||
public static void registerPlaceholders(EcoEnchant enchantment) {
|
||||
|
||||
public static void registerPlaceholders(@NotNull final EcoEnchant enchantment) {
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + "enabled", (player) -> String.valueOf(enchantment.isEnabled()))
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + "enabled",
|
||||
player -> String.valueOf(enchantment.isEnabled())
|
||||
)
|
||||
);
|
||||
|
||||
enchantment.getConfig().config.getKeys(true).forEach(string -> {
|
||||
enchantment.getConfig().getConfig().getKeys(true).forEach(string -> {
|
||||
String key = string.replace("\\.", "_").replace("-", "_");
|
||||
Object object = enchantment.getConfig().config.get(string);
|
||||
Object object = enchantment.getConfig().getConfig().get(string);
|
||||
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + key, (player) -> StringUtils.internalToString(object))
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + key,
|
||||
player -> StringUtils.internalToString(object)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
if (enchantment.getConfig().config.get(EcoEnchants.CONFIG_LOCATION + "chance-per-level") != null) {
|
||||
if (enchantment.getConfig().getConfig().get(EcoEnchants.CONFIG_LOCATION + "chance-per-level") != null) {
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + "chance_per_level", (player) -> NumberUtils.format(enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")))
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + "chance_per_level",
|
||||
player -> NumberUtils.format(enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (enchantment.getConfig().config.get(EcoEnchants.CONFIG_LOCATION + "multiplier") != null) {
|
||||
if (enchantment.getConfig().getConfig().get(EcoEnchants.CONFIG_LOCATION + "multiplier") != null) {
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + "multiplier", (player) -> NumberUtils.format(enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier")))
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + "multiplier",
|
||||
player -> NumberUtils.format(enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"))
|
||||
)
|
||||
);
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + "multiplier_percentage", (player) -> NumberUtils.format(enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier") * 100))
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + "multiplier_percentage",
|
||||
player -> NumberUtils.format(enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier") * 100)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (enchantment instanceof Spell) {
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + "cooldown", (player) -> NumberUtils.format(Spell.getCooldown((Spell) enchantment, player)), true)
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + "cooldown",
|
||||
player -> NumberUtils.format(Spell.getCooldown((Spell) enchantment, player)),
|
||||
true
|
||||
)
|
||||
);
|
||||
PlaceholderManager.registerPlaceholder(
|
||||
new PlaceholderEntry(enchantment.getPermissionName() + "_" + "cooldown_total", (player) -> NumberUtils.format(((Spell) enchantment).getCooldownTime()))
|
||||
new PlaceholderEntry(
|
||||
enchantment.getPermissionName() + "_" + "cooldown_total",
|
||||
player -> NumberUtils.format(((Spell) enchantment).getCooldownTime())
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,31 @@
|
||||
package com.willfp.ecoenchants.integrations.essentials;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility class for interfacing with EssentialsX
|
||||
*/
|
||||
@UtilityClass
|
||||
public class EssentialsManager {
|
||||
private static final Set<EssentialsWrapper> registered = new HashSet<>();
|
||||
private static final Set<EssentialsWrapper> REGISTERED = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new essentials integration
|
||||
*
|
||||
* @param essentials The integration to register
|
||||
*/
|
||||
public static void register(EssentialsWrapper essentials) {
|
||||
registered.add(essentials);
|
||||
public static void register(@NotNull final EssentialsWrapper essentials) {
|
||||
REGISTERED.add(essentials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all {@link com.willfp.ecoenchants.enchantments.EcoEnchant}s with Essentials
|
||||
*/
|
||||
public static void registerEnchantments() {
|
||||
registered.forEach((EssentialsWrapper::registerAllEnchantments));
|
||||
REGISTERED.forEach(EssentialsWrapper::registerAllEnchantments);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import com.willfp.eco.util.integrations.Integration;
|
||||
*/
|
||||
public interface EssentialsWrapper extends Integration {
|
||||
/**
|
||||
* @see EssentialsManager#registerEnchantments()
|
||||
* @see EssentialsManager#registerEnchantments();
|
||||
*/
|
||||
void registerAllEnchantments();
|
||||
}
|
||||
|
||||
|
@ -24,4 +24,4 @@ public interface FastGetEnchantsProxy extends AbstractProxy {
|
||||
*/
|
||||
int getLevelOnItem(@NotNull ItemStack itemStack,
|
||||
@NotNull Enchantment enchantment);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class Glacial extends BiomesEnchantment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(@NotNull Biome biome) {
|
||||
public boolean isValid(@NotNull final Biome biome) {
|
||||
return Arrays.stream(new String[]{"snowy", "ice", "frozen"}).anyMatch(biome.name().toLowerCase()::contains);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Endershot extends EcoEnchant {
|
||||
public Endershot() {
|
||||
@ -23,28 +24,38 @@ public class Endershot extends EcoEnchant {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBowShoot(EntityShootBowEvent event) {
|
||||
if(McmmoManager.isFake(event))
|
||||
public void onBowShoot(@NotNull final EntityShootBowEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
if (event.getProjectile().getType() != EntityType.ARROW)
|
||||
}
|
||||
if (event.getProjectile().getType() != EntityType.ARROW) {
|
||||
return;
|
||||
if(!(event.getEntity() instanceof Player))
|
||||
}
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if(!player.isSneaking()) return;
|
||||
if (!player.isSneaking()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if(!EnchantChecks.mainhand(player, this)) return;
|
||||
if(this.getDisabledWorlds().contains(player.getWorld())) return;
|
||||
|
||||
if(!player.getInventory().contains(Material.ENDER_PEARL, 1) && !player.getGameMode().equals(GameMode.CREATIVE))
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player.getInventory().contains(Material.ENDER_PEARL, 1) && !player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean hasInfinity = EnchantChecks.mainhand(player, ARROW_INFINITE) && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "work-with-infinity");
|
||||
if(!hasInfinity) {
|
||||
if (!hasInfinity) {
|
||||
ItemStack pearl = new ItemStack(Material.ENDER_PEARL, 1);
|
||||
player.getInventory().remove(pearl);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Firewand extends Spell {
|
||||
public Firewand() {
|
||||
@ -18,20 +19,26 @@ public class Firewand extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUse(Player player, int level, PlayerInteractEvent event) {
|
||||
public void onUse(@NotNull final Player player,
|
||||
final int level,
|
||||
@NotNull final PlayerInteractEvent event) {
|
||||
SmallFireball fireball = player.launchProjectile(SmallFireball.class, player.getEyeLocation().getDirection().multiply(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity")));
|
||||
fireball.setIsIncendiary(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire"));
|
||||
fireball.setMetadata("eco-damage", new FixedMetadataValue(this.getPlugin(), this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level") * level));
|
||||
if(this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "no-explode")) {
|
||||
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "no-explode")) {
|
||||
fireball.setMetadata("nobreak", new FixedMetadataValue(this.getPlugin(), true));
|
||||
}
|
||||
fireball.setShooter(player);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onFireballDamage(EntityDamageByEntityEvent event) {
|
||||
if(!(event.getDamager() instanceof SmallFireball)) return;
|
||||
if(event.getDamager().getMetadata("eco-damage").isEmpty()) return;
|
||||
public void onFireballDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof SmallFireball)) {
|
||||
return;
|
||||
}
|
||||
if (event.getDamager().getMetadata("eco-damage").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double multiplier = event.getDamager().getMetadata("eco-damage").get(0).asDouble();
|
||||
|
||||
@ -39,9 +46,13 @@ public class Firewand extends Spell {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onFireballExplode(EntityExplodeEvent event) {
|
||||
if(!(event.getEntity() instanceof SmallFireball)) return;
|
||||
if(event.getEntity().getMetadata("nobreak").isEmpty()) return;
|
||||
public void onFireballExplode(@NotNull final EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof SmallFireball)) {
|
||||
return;
|
||||
}
|
||||
if (event.getEntity().getMetadata("nobreak").isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public abstract class BaseConfig extends PluginDependent {
|
||||
/**
|
||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
@Getter(AccessLevel.PUBLIC)
|
||||
private final YamlConfiguration config;
|
||||
|
||||
/**
|
||||
|
@ -12,14 +12,14 @@ public class Lang extends BaseConfig {
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return StringUtils.translate(config.getString("messages.prefix"));
|
||||
return StringUtils.translate(this.getConfig().getString("messages.prefix"));
|
||||
}
|
||||
|
||||
public String getNoPermission() {
|
||||
return getPrefix() + StringUtils.translate(config.getString("messages.no-permission"));
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages.no-permission"));
|
||||
}
|
||||
|
||||
public String getMessage(String message) {
|
||||
return getPrefix() + StringUtils.translate(config.getString("messages." + message));
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages." + message));
|
||||
}
|
||||
}
|
@ -131,4 +131,4 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,11 +41,15 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) return;
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if (victim.getHealth() > event.getFinalDamage()) return;
|
||||
if (victim.getHealth() > event.getFinalDamage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityDeathByEntityBuilder builtEvent = new EntityDeathByEntityBuilder();
|
||||
builtEvent.setVictim(victim);
|
||||
@ -77,7 +81,9 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis
|
||||
}
|
||||
});
|
||||
|
||||
if (atomicBuiltEvent.get() == null) return;
|
||||
if (atomicBuiltEvent.get() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
builtEvent = atomicBuiltEvent.get();
|
||||
events.remove(builtEvent);
|
||||
|
Loading…
Reference in New Issue
Block a user