Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
128d473b33 | ||
|
|
d5679dd58f | ||
|
|
b1e8165ecb | ||
|
|
d0a3d644f3 | ||
|
|
35b060af53 | ||
|
|
337dba23b4 | ||
|
|
433f9f53ab | ||
|
|
ba7a748efd | ||
|
|
1365fdae88 | ||
|
|
6a159bf049 | ||
|
|
31e0e93951 | ||
|
|
876343facb | ||
|
|
f0cd9ae16d | ||
|
|
b220428b8c | ||
|
|
8386aacfd8 | ||
|
|
3c54e24102 | ||
|
|
3dc0693b8c | ||
|
|
f087113ddf | ||
|
|
d5d1f5d8cc | ||
|
|
0d5bf901e2 | ||
|
|
ae0445f47b |
@@ -25,7 +25,7 @@ allprojects {
|
||||
// NMS (for jitpack compilation)
|
||||
maven { url 'https://repo.codemc.org/repository/nms/' }
|
||||
|
||||
// bStats
|
||||
// bStats, mcMMO
|
||||
maven { url 'https://repo.codemc.org/repository/maven-public' }
|
||||
|
||||
// Spigot API
|
||||
|
||||
@@ -115,7 +115,6 @@
|
||||
<!-- Checks for imports -->
|
||||
<!-- See https://checkstyle.org/config_imports.html -->
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
|
||||
@@ -14,6 +14,7 @@ dependencies {
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefKingdoms;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefLands;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefTowny;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefWorldGuard;
|
||||
import com.willfp.eco.spigot.integrations.mcmmo.plugins.McmmoIntegrationImpl;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
@@ -24,9 +25,9 @@ import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainListeners;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.util.integrations.mcmmo.McmmoManager;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.recipe.RecipeListener;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -56,7 +57,6 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
this.getEventManager().registerListener(new ArmorListener());
|
||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||
this.getEventManager().registerListener(new RecipeListener(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +93,10 @@ public class EcoPlugin extends AbstractEcoPlugin {
|
||||
// Anticheat
|
||||
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
||||
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
|
||||
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP()))
|
||||
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())),
|
||||
|
||||
// Misc
|
||||
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.spigot.integrations.mcmmo.plugins;
|
||||
|
||||
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
|
||||
import com.gmail.nossr50.events.fake.FakeEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.willfp.eco.util.integrations.mcmmo.McmmoWrapper;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class McmmoIntegrationImpl implements McmmoWrapper {
|
||||
@Override
|
||||
public int getBonusDropCount(@NotNull final Block block) {
|
||||
if (block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
|
||||
BonusDropMeta bonusDropMeta = (BonusDropMeta) block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
|
||||
return bonusDropMeta.asInt();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFake(@NotNull final Event event) {
|
||||
return event instanceof FakeEvent;
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,5 @@ softdepend:
|
||||
- AAC
|
||||
- Matrix
|
||||
- Spartan
|
||||
- PlaceholderAPI
|
||||
- PlaceholderAPI
|
||||
- mcMMO
|
||||
@@ -10,9 +10,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -25,7 +23,12 @@ public class StringUtils {
|
||||
/**
|
||||
* Regex for gradients.
|
||||
*/
|
||||
private static final String GRADIENT_REGEX = "<\\$#[A-Fa-f0-9]{6}>";
|
||||
private static final Pattern GRADIENT_REGEX = Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>");
|
||||
|
||||
/**
|
||||
* Regex for hex codes.
|
||||
*/
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
|
||||
|
||||
/**
|
||||
* Translate a string - converts Placeholders and Color codes.
|
||||
@@ -58,8 +61,7 @@ public class StringUtils {
|
||||
}
|
||||
|
||||
private static String translateHexColorCodes(@NotNull final String message) {
|
||||
Pattern hexPattern = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
|
||||
Matcher matcher = hexPattern.matcher(message);
|
||||
Matcher matcher = HEX_PATTERN.matcher(message);
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
@@ -73,102 +75,90 @@ public class StringUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply gradients to the provided string.
|
||||
* Colors a string with a gradient.
|
||||
*
|
||||
* @param message the string to parse.
|
||||
* @return the parsed string.
|
||||
* @param string The string to color.
|
||||
* @param start The start color.
|
||||
* @param end The end color.
|
||||
* @return The string, colored.
|
||||
*/
|
||||
public static String translateGradients(@NotNull final String message) {
|
||||
List<String> hexes = new ArrayList<>();
|
||||
Matcher matcher = Pattern.compile(GRADIENT_REGEX).matcher(message);
|
||||
while (matcher.find()) {
|
||||
hexes.add(matcher.group().replace("<$", "").replace(">", ""));
|
||||
private static String processGradients(@NotNull final String string,
|
||||
@NotNull final Color start,
|
||||
@NotNull final Color end) {
|
||||
String processedString = string;
|
||||
List<ChatColor> modifiers = new ArrayList<>();
|
||||
if (processedString.contains("&l")) {
|
||||
modifiers.add(ChatColor.BOLD);
|
||||
}
|
||||
int hexIndex = 0;
|
||||
List<String> texts = new LinkedList<>(Arrays.asList(message.split(GRADIENT_REGEX)));
|
||||
StringBuilder finalMsg = new StringBuilder();
|
||||
for (String text : texts) {
|
||||
if (texts.get(0).equalsIgnoreCase(text)) {
|
||||
finalMsg.append(text);
|
||||
continue;
|
||||
}
|
||||
if (text.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
if (hexIndex + 1 >= hexes.size()) {
|
||||
if (!finalMsg.toString().contains(text)) {
|
||||
finalMsg.append(text);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
String fromHex = hexes.get(hexIndex);
|
||||
String toHex = hexes.get(hexIndex + 1);
|
||||
finalMsg.append(insertFades(text, fromHex, toHex));
|
||||
hexIndex++;
|
||||
if (processedString.contains("&o")) {
|
||||
modifiers.add(ChatColor.ITALIC);
|
||||
}
|
||||
return finalMsg.toString();
|
||||
if (processedString.contains("&n")) {
|
||||
modifiers.add(ChatColor.UNDERLINE);
|
||||
}
|
||||
if (processedString.contains("&k")) {
|
||||
modifiers.add(ChatColor.MAGIC);
|
||||
}
|
||||
processedString = processedString.replace("&l", "");
|
||||
processedString = processedString.replace("&o", "");
|
||||
processedString = processedString.replace("&n", "");
|
||||
processedString = processedString.replace("&k", "");
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
ChatColor[] colors = getGradientColors(start, end, processedString.length());
|
||||
String[] characters = processedString.split("");
|
||||
for (int i = 0; i < processedString.length(); i++) {
|
||||
stringBuilder.append(colors[i]);
|
||||
modifiers.forEach(stringBuilder::append);
|
||||
stringBuilder.append(characters[i]);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private static String insertFades(@NotNull final String message,
|
||||
@NotNull final String fromHex,
|
||||
@NotNull final String toHex) {
|
||||
boolean bold = message.contains("&l");
|
||||
boolean italic = message.contains("&o");
|
||||
String msg = message;
|
||||
msg = msg.replace("&l", "");
|
||||
msg = msg.replace("&o", "");
|
||||
int length = msg.length();
|
||||
Color fromRGB = Color.decode(fromHex);
|
||||
Color toRGB = Color.decode(toHex);
|
||||
double rStep = Math.abs((double) (fromRGB.getRed() - toRGB.getRed()) / length);
|
||||
double gStep = Math.abs((double) (fromRGB.getGreen() - toRGB.getGreen()) / length);
|
||||
double bStep = Math.abs((double) (fromRGB.getBlue() - toRGB.getBlue()) / length);
|
||||
if (fromRGB.getRed() > toRGB.getRed()) {
|
||||
rStep = -rStep;
|
||||
/**
|
||||
* Creates chatColors for gradients.
|
||||
*
|
||||
* @param start The start color.
|
||||
* @param end The end color.
|
||||
* @param step How many colors are returned.
|
||||
* @return Array of chat colors.
|
||||
*/
|
||||
private static ChatColor[] getGradientColors(@NotNull final Color start,
|
||||
@NotNull final Color end,
|
||||
final int step) {
|
||||
ChatColor[] colors = new ChatColor[step];
|
||||
int stepR = Math.abs(start.getRed() - end.getRed()) / (step - 1);
|
||||
int stepG = Math.abs(start.getGreen() - end.getGreen()) / (step - 1);
|
||||
int stepB = Math.abs(start.getBlue() - end.getBlue()) / (step - 1);
|
||||
int[] direction = new int[]{
|
||||
start.getRed() < end.getRed() ? +1 : -1,
|
||||
start.getGreen() < end.getGreen() ? +1 : -1,
|
||||
start.getBlue() < end.getBlue() ? +1 : -1
|
||||
};
|
||||
|
||||
for (int i = 0; i < step; i++) {
|
||||
Color color = new Color(start.getRed() + ((stepR * i) * direction[0]), start.getGreen() + ((stepG * i) * direction[1]), start.getBlue() + ((stepB * i) * direction[2]));
|
||||
colors[i] = ChatColor.of(color);
|
||||
}
|
||||
if (fromRGB.getGreen() > toRGB.getGreen()) {
|
||||
gStep = -gStep;
|
||||
return colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add gradients to a string.
|
||||
*
|
||||
* @param string The string.
|
||||
* @return The string, colorized.
|
||||
*/
|
||||
private static String translateGradients(@NotNull final String string) {
|
||||
String processedString = string;
|
||||
Matcher matcher = GRADIENT_REGEX.matcher(string);
|
||||
while (matcher.find()) {
|
||||
String start = matcher.group(1);
|
||||
String end = matcher.group(3);
|
||||
String content = matcher.group(2);
|
||||
processedString = processedString.replace(matcher.group(), processGradients(content, new Color(Integer.parseInt(start, 16)), new Color(Integer.parseInt(end, 16))));
|
||||
}
|
||||
if (fromRGB.getBlue() > toRGB.getBlue()) {
|
||||
bStep = -bStep;
|
||||
}
|
||||
Color finalColor = new Color(fromRGB.getRGB());
|
||||
msg = msg.replaceAll(GRADIENT_REGEX, "");
|
||||
msg = msg.replace("", "<$>");
|
||||
for (int index = 0; index <= length; index++) {
|
||||
int red = (int) Math.round(finalColor.getRed() + rStep);
|
||||
int green = (int) Math.round(finalColor.getGreen() + gStep);
|
||||
int blue = (int) Math.round(finalColor.getBlue() + bStep);
|
||||
if (red > 255) {
|
||||
red = 255;
|
||||
}
|
||||
if (red < 0) {
|
||||
red = 0;
|
||||
}
|
||||
if (green > 255) {
|
||||
green = 255;
|
||||
}
|
||||
if (green < 0) {
|
||||
green = 0;
|
||||
}
|
||||
if (blue > 255) {
|
||||
blue = 255;
|
||||
}
|
||||
if (blue < 0) {
|
||||
blue = 0;
|
||||
}
|
||||
finalColor = new Color(red, green, blue);
|
||||
String hex = "#" + Integer.toHexString(finalColor.getRGB()).substring(2);
|
||||
String formats = "";
|
||||
if (bold) {
|
||||
formats += ChatColor.BOLD;
|
||||
}
|
||||
if (italic) {
|
||||
formats += ChatColor.ITALIC;
|
||||
}
|
||||
msg = msg.replaceFirst("<\\$>", ChatColor.of(hex) + formats);
|
||||
}
|
||||
return msg;
|
||||
return processedString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
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 lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class StaticBaseConfig 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;
|
||||
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected StaticBaseConfig(@NotNull final String configName,
|
||||
@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
this.name = configName + ".yml";
|
||||
|
||||
if (!new File(this.getPlugin().getDataFolder(), this.name).exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(this.getPlugin().getDataFolder(), this.name);
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
this.getPlugin().saveResource(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,7 @@ public class Display {
|
||||
* Display on ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack display(@NotNull final ItemStack itemStack) {
|
||||
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
|
||||
@@ -107,6 +108,7 @@ public class Display {
|
||||
* Display on ItemStacks and then finalize.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
||||
return finalize(display(itemStack));
|
||||
@@ -116,6 +118,7 @@ public class Display {
|
||||
* Revert on ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack revert(@NotNull final ItemStack itemStack) {
|
||||
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
|
||||
@@ -128,6 +131,7 @@ public class Display {
|
||||
* Finalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||
for (Function<ItemStack, ItemStack> function : FINALIZE_FUNCTIONS) {
|
||||
@@ -140,6 +144,7 @@ public class Display {
|
||||
* Finalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return If finalized.
|
||||
*/
|
||||
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
||||
for (Predicate<ItemStack> function : FINALIZE_TEST_FUNCTIONS) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.willfp.eco.util.integrations.mcmmo;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class McmmoManager {
|
||||
/**
|
||||
* A set of all registered integrations.
|
||||
*/
|
||||
private final Set<McmmoWrapper> regsistered = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new integration.
|
||||
*
|
||||
* @param integration The integration to register.
|
||||
*/
|
||||
public void register(@NotNull final McmmoWrapper integration) {
|
||||
regsistered.add(integration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bonus drop count from block.
|
||||
*
|
||||
* @param block The block.
|
||||
* @return The bonus drop count.
|
||||
*/
|
||||
public int getBonusDropCount(@NotNull final Block block) {
|
||||
for (McmmoWrapper mcmmoWrapper : regsistered) {
|
||||
return mcmmoWrapper.getBonusDropCount(block);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if event is fake.
|
||||
*
|
||||
* @param event The event to check.
|
||||
* @return If the event is fake.
|
||||
*/
|
||||
public boolean isFake(@NotNull final Event event) {
|
||||
for (McmmoWrapper mcmmoWrapper : regsistered) {
|
||||
return mcmmoWrapper.isFake(event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.util.integrations.mcmmo;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface McmmoWrapper {
|
||||
/**
|
||||
* Get bonus drop count of block.
|
||||
*
|
||||
* @param block The block.
|
||||
* @return The drop multiplier.
|
||||
*/
|
||||
int getBonusDropCount(@NotNull Block block);
|
||||
|
||||
/**
|
||||
* Get if event is fake.
|
||||
*
|
||||
* @param event The event.
|
||||
* @return If is fake.
|
||||
*/
|
||||
boolean isFake(@NotNull Event event);
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.recipe.RecipeListener;
|
||||
import com.willfp.eco.util.recipe.RecipeManager;
|
||||
import com.willfp.eco.util.updater.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
@@ -214,6 +215,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.getLog().info("Loading " + this.color + this.pluginName);
|
||||
|
||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||
this.getEventManager().registerListener(new RecipeListener(this));
|
||||
|
||||
new UpdateChecker(this).getVersion(version -> {
|
||||
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
|
||||
@@ -248,14 +250,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
|
||||
Prerequisite.update();
|
||||
|
||||
|
||||
if (ClassUtils.exists("com.comphenix.protocol.events.PacketAdapter")) {
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (!abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
}
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (!abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
|
||||
updatableClasses.addAll(this.getUpdatableClasses());
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
version = 3.1.0
|
||||
version = 3.3.0
|
||||
plugin-name = eco
|
||||
Reference in New Issue
Block a user