Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e31857a15d | ||
|
|
32e119d187 | ||
|
|
5690eccd14 | ||
|
|
2faf3732df | ||
|
|
8670fb36e0 | ||
|
|
7c001c4809 | ||
|
|
bce1dd9fee | ||
|
|
412c2e1e3c | ||
|
|
dd7ffac974 | ||
|
|
7ad59e0166 | ||
|
|
2f2bdbb9f5 |
@@ -7,7 +7,7 @@ website: willfp.com
|
|||||||
loadbefore:
|
loadbefore:
|
||||||
- EcoEnchants
|
- EcoEnchants
|
||||||
- Talismans
|
- Talismans
|
||||||
- ItemStats
|
- StatTrackers
|
||||||
- EcoArmor
|
- EcoArmor
|
||||||
- Illusioner
|
- Illusioner
|
||||||
depend:
|
depend:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util;
|
|||||||
|
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.SoundCategory;
|
import org.bukkit.SoundCategory;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -37,25 +38,32 @@ public class DurabilityUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special edge case
|
||||||
|
if (item.getType() == Material.CARVED_PUMPKIN || item.getType() == Material.PLAYER_HEAD) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||||
Bukkit.getPluginManager().callEvent(event3);
|
Bukkit.getPluginManager().callEvent(event3);
|
||||||
|
|
||||||
if (!event3.isCancelled()) {
|
if (!event3.isCancelled()) {
|
||||||
int damage2 = event3.getDamage();
|
int damage2 = event3.getDamage();
|
||||||
if (item.getItemMeta() instanceof Damageable) {
|
Damageable meta = (Damageable) item.getItemMeta();
|
||||||
Damageable meta = (Damageable) item.getItemMeta();
|
meta.setDamage(meta.getDamage() + damage2);
|
||||||
meta.setDamage(meta.getDamage() + damage2);
|
|
||||||
|
|
||||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||||
meta.setDamage(item.getType().getMaxDurability());
|
meta.setDamage(item.getType().getMaxDurability());
|
||||||
item.setItemMeta((ItemMeta) meta);
|
item.setItemMeta((ItemMeta) meta);
|
||||||
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
player.getInventory().clear(slot);
|
player.getInventory().clear(slot);
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
||||||
} else {
|
} else {
|
||||||
item.setItemMeta((ItemMeta) meta);
|
item.setItemMeta((ItemMeta) meta);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,20 +86,22 @@ public class DurabilityUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||||
Bukkit.getPluginManager().callEvent(event3);
|
Bukkit.getPluginManager().callEvent(event3);
|
||||||
|
|
||||||
if (!event3.isCancelled()) {
|
if (!event3.isCancelled()) {
|
||||||
int damage2 = event3.getDamage();
|
int damage2 = event3.getDamage();
|
||||||
if (item.getItemMeta() instanceof Damageable) {
|
Damageable meta = (Damageable) item.getItemMeta();
|
||||||
Damageable meta = (Damageable) item.getItemMeta();
|
meta.setDamage(meta.getDamage() + damage2);
|
||||||
meta.setDamage(meta.getDamage() + damage2);
|
|
||||||
|
|
||||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||||
meta.setDamage(item.getType().getMaxDurability() - 1);
|
meta.setDamage(item.getType().getMaxDurability() - 1);
|
||||||
}
|
|
||||||
item.setItemMeta((ItemMeta) meta);
|
|
||||||
}
|
}
|
||||||
|
item.setItemMeta((ItemMeta) meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,76 +1,51 @@
|
|||||||
package com.willfp.eco.util.config;
|
package com.willfp.eco.util.config;
|
||||||
|
|
||||||
import com.willfp.eco.util.StringUtils;
|
|
||||||
import com.willfp.eco.util.internal.PluginDependent;
|
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public abstract class BaseConfig extends PluginDependent implements ValueGetter {
|
|
||||||
/**
|
|
||||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.PUBLIC)
|
|
||||||
private final YamlConfiguration config;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The physical config file, as stored on disk.
|
|
||||||
*/
|
|
||||||
@Getter(AccessLevel.PROTECTED)
|
|
||||||
private final File configFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The full name of the config file (eg config.yml).
|
|
||||||
*/
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
|
public abstract class BaseConfig extends StaticBaseConfig {
|
||||||
/**
|
/**
|
||||||
* Whether keys not in the base config should be removed on update.
|
* Whether keys not in the base config should be removed on update.
|
||||||
*/
|
*/
|
||||||
private final boolean removeUnused;
|
private final boolean removeUnused;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of blacklisted update keys.
|
||||||
|
*/
|
||||||
|
private final List<String> updateBlacklist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||||
* <p>
|
* <p>
|
||||||
* Automatically updates.
|
* Automatically updates.
|
||||||
*
|
*
|
||||||
* @param configName The name of the config
|
* @param configName The name of the config
|
||||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||||
* @param plugin The plugin.
|
* @param plugin The plugin.
|
||||||
|
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||||
*/
|
*/
|
||||||
protected BaseConfig(@NotNull final String configName,
|
protected BaseConfig(@NotNull final String configName,
|
||||||
final boolean removeUnused,
|
final boolean removeUnused,
|
||||||
@NotNull final AbstractEcoPlugin plugin) {
|
@NotNull final AbstractEcoPlugin plugin,
|
||||||
super(plugin);
|
@Nullable final String... updateBlacklist) {
|
||||||
this.name = configName + ".yml";
|
super(configName, plugin);
|
||||||
this.removeUnused = removeUnused;
|
this.removeUnused = removeUnused;
|
||||||
|
this.updateBlacklist = Arrays.asList(updateBlacklist);
|
||||||
if (!new File(this.getPlugin().getDataFolder(), this.name).exists()) {
|
|
||||||
createFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.configFile = new File(this.getPlugin().getDataFolder(), this.name);
|
|
||||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createFile() {
|
|
||||||
this.getPlugin().saveResource(name, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the config.
|
* Update the config.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -78,11 +53,11 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
|||||||
*/
|
*/
|
||||||
public void update() {
|
public void update() {
|
||||||
try {
|
try {
|
||||||
config.load(configFile);
|
config.load(this.getConfigFile());
|
||||||
|
|
||||||
InputStream newIn = this.getPlugin().getResource(name);
|
InputStream newIn = this.getPlugin().getResource(this.getName());
|
||||||
if (newIn == null) {
|
if (newIn == null) {
|
||||||
this.getPlugin().getLog().error(name + " is null?");
|
this.getPlugin().getLog().error(this.getName() + " is null?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||||
@@ -95,127 +70,25 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
|||||||
|
|
||||||
newConfig.getKeys(true).forEach((s -> {
|
newConfig.getKeys(true).forEach((s -> {
|
||||||
if (!config.getKeys(true).contains(s)) {
|
if (!config.getKeys(true).contains(s)) {
|
||||||
config.set(s, newConfig.get(s));
|
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||||
|
config.set(s, newConfig.get(s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (this.removeUnused) {
|
if (this.removeUnused) {
|
||||||
config.getKeys(true).forEach((s -> {
|
config.getKeys(true).forEach((s -> {
|
||||||
if (!newConfig.getKeys(true).contains(s)) {
|
if (!newConfig.getKeys(true).contains(s)) {
|
||||||
config.set(s, null);
|
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||||
|
config.set(s, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
config.save(configFile);
|
config.save(this.getConfigFile());
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getInt(@NotNull final String path) {
|
|
||||||
return config.getInt(path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config with a specified default (not found) value.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @param def The value to default to if not found.
|
|
||||||
* @return The found value, or the default.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int getInt(@NotNull final String path,
|
|
||||||
final int def) {
|
|
||||||
return config.getInt(path, def);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of integers from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Integer> getInts(@NotNull final String path) {
|
|
||||||
return config.getIntegerList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a boolean from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or false if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean getBool(@NotNull final String path) {
|
|
||||||
return config.getBoolean(path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of booleans from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Boolean> getBools(@NotNull final String path) {
|
|
||||||
return config.getBooleanList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or an empty string if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public String getString(@NotNull final String path) {
|
|
||||||
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of strings from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<String> getStrings(@NotNull final String path) {
|
|
||||||
return config.getStringList(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a decimal from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public double getDouble(@NotNull final String path) {
|
|
||||||
return config.getDouble(path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of decimals from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@NotNull
|
|
||||||
public List<Double> getDoubles(@NotNull final String path) {
|
|
||||||
return config.getDoubleList(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,21 @@ import com.willfp.eco.util.internal.PluginDependent;
|
|||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class StaticBaseConfig extends PluginDependent implements ValueGetter {
|
public abstract class StaticBaseConfig extends PluginDependent {
|
||||||
/**
|
/**
|
||||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||||
*/
|
*/
|
||||||
@Getter(AccessLevel.PUBLIC)
|
@Getter(AccessLevel.PUBLIC)
|
||||||
private final YamlConfiguration config;
|
protected final YamlConfiguration config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The physical config file, as stored on disk.
|
* The physical config file, as stored on disk.
|
||||||
@@ -28,6 +30,7 @@ public abstract class StaticBaseConfig extends PluginDependent implements ValueG
|
|||||||
/**
|
/**
|
||||||
* The full name of the config file (eg config.yml).
|
* The full name of the config file (eg config.yml).
|
||||||
*/
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,8 +38,8 @@ public abstract class StaticBaseConfig extends PluginDependent implements ValueG
|
|||||||
* <p>
|
* <p>
|
||||||
* Does not automatically update.
|
* Does not automatically update.
|
||||||
*
|
*
|
||||||
* @param configName The name of the config
|
* @param configName The name of the config
|
||||||
* @param plugin The plugin.
|
* @param plugin The plugin.
|
||||||
*/
|
*/
|
||||||
protected StaticBaseConfig(@NotNull final String configName,
|
protected StaticBaseConfig(@NotNull final String configName,
|
||||||
@NotNull final AbstractEcoPlugin plugin) {
|
@NotNull final AbstractEcoPlugin plugin) {
|
||||||
@@ -55,17 +58,68 @@ public abstract class StaticBaseConfig extends PluginDependent implements ValueG
|
|||||||
this.getPlugin().saveResource(name, false);
|
this.getPlugin().saveResource(name, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get if the config contains a key.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return If contained.
|
||||||
|
*/
|
||||||
|
public boolean has(@NotNull final String path) {
|
||||||
|
return config.contains(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration section from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The configuration section. Throws NPE if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public ConfigurationSection getSection(@NotNull final String path) {
|
||||||
|
ConfigurationSection section = getSectionOrNull(path);
|
||||||
|
if (section == null) {
|
||||||
|
throw new NullPointerException("Section cannot be null!");
|
||||||
|
} else {
|
||||||
|
return section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get configuration section from config.
|
||||||
|
*
|
||||||
|
* @param path The key to check.
|
||||||
|
* @return The configuration section, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
|
||||||
|
return config.getConfigurationSection(path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an integer from config.
|
* Get an integer from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or 0 if not found.
|
* @return The found value, or 0 if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getInt(@NotNull final String path) {
|
public int getInt(@NotNull final String path) {
|
||||||
return config.getInt(path, 0);
|
return config.getInt(path, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an integer from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Integer getIntOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInt(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an integer from config with a specified default (not found) value.
|
* Get an integer from config with a specified default (not found) value.
|
||||||
*
|
*
|
||||||
@@ -73,7 +127,6 @@ public abstract class StaticBaseConfig extends PluginDependent implements ValueG
|
|||||||
* @param def The value to default to if not found.
|
* @param def The value to default to if not found.
|
||||||
* @return The found value, or the default.
|
* @return The found value, or the default.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getInt(@NotNull final String path,
|
public int getInt(@NotNull final String path,
|
||||||
final int def) {
|
final int def) {
|
||||||
return config.getInt(path, def);
|
return config.getInt(path, def);
|
||||||
@@ -85,79 +138,177 @@ public abstract class StaticBaseConfig extends PluginDependent implements ValueG
|
|||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Integer> getInts(@NotNull final String path) {
|
public List<Integer> getInts(@NotNull final String path) {
|
||||||
return config.getIntegerList(path);
|
return config.getIntegerList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of integers from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInts(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a boolean from config.
|
* Get a boolean from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or false if not found.
|
* @return The found value, or false if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public boolean getBool(@NotNull final String path) {
|
public boolean getBool(@NotNull final String path) {
|
||||||
return config.getBoolean(path, false);
|
return config.getBoolean(path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a boolean from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Boolean getBoolOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBool(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of booleans from config.
|
* Get a list of booleans from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Boolean> getBools(@NotNull final String path) {
|
public List<Boolean> getBools(@NotNull final String path) {
|
||||||
return config.getBooleanList(path);
|
return config.getBooleanList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of booleans from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBools(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a string from config.
|
* Get a string from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or an empty string if not found.
|
* @return The found value, or an empty string if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getString(@NotNull final String path) {
|
public String getString(@NotNull final String path) {
|
||||||
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
return StringUtils.translate(Objects.requireNonNull(config.getString(path, "")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public String getStringOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getString(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of strings from config.
|
* Get a list of strings from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<String> getStrings(@NotNull final String path) {
|
public List<String> getStrings(@NotNull final String path) {
|
||||||
return config.getStringList(path);
|
return config.getStringList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of strings from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<String> getStringsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getStrings(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a decimal from config.
|
* Get a decimal from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or 0 if not found.
|
* @return The found value, or 0 if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public double getDouble(@NotNull final String path) {
|
public double getDouble(@NotNull final String path) {
|
||||||
return config.getDouble(path, 0);
|
return config.getDouble(path, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a decimal from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Double getDoubleOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDouble(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of decimals from config.
|
* Get a list of decimals from config.
|
||||||
*
|
*
|
||||||
* @param path The key to fetch the value from.
|
* @param path The key to fetch the value from.
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Double> getDoubles(@NotNull final String path) {
|
public List<Double> getDoubles(@NotNull final String path) {
|
||||||
return config.getDoubleList(path);
|
return config.getDoubleList(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of decimals from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDoubles(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
package com.willfp.eco.util.config;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public interface ValueGetter {
|
|
||||||
/**
|
|
||||||
* Get an integer from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
int getInt(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an integer from config with a specified default (not found) value.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @param def The value to default to if not found.
|
|
||||||
* @return The found value, or the default.
|
|
||||||
*/
|
|
||||||
int getInt(@NotNull String path,
|
|
||||||
int def);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of integers from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<Integer> getInts(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a boolean from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or false if not found.
|
|
||||||
*/
|
|
||||||
boolean getBool(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of booleans from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<Boolean> getBools(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or an empty string if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
String getString(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of strings from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<String> getStrings(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a decimal from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or 0 if not found.
|
|
||||||
*/
|
|
||||||
double getDouble(@NotNull String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of decimals from config.
|
|
||||||
*
|
|
||||||
* @param path The key to fetch the value from.
|
|
||||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
List<Double> getDoubles(@NotNull String path);
|
|
||||||
}
|
|
||||||
@@ -130,6 +130,9 @@ public class Display {
|
|||||||
*/
|
*/
|
||||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||||
|
if (itemStack.getType().getMaxStackSize() > 1) {
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return itemStack;
|
return itemStack;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import lombok.AccessLevel;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.ExperienceOrb;
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
@@ -133,6 +134,11 @@ public class InternalDropQueue implements AbstractDropQueue {
|
|||||||
assert world != null;
|
assert world != null;
|
||||||
loc = loc.add(0.5, 0.5, 0.5);
|
loc = loc.add(0.5, 0.5, 0.5);
|
||||||
|
|
||||||
|
items.removeIf(itemStack -> itemStack.getType() == Material.AIR);
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasTelekinesis) {
|
if (hasTelekinesis) {
|
||||||
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
||||||
for (ItemStack drop : leftover.values()) {
|
for (ItemStack drop : leftover.values()) {
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 3.4.0
|
version = 3.5.0
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
Reference in New Issue
Block a user