Compare commits

..

36 Commits
4.3.1 ... 5.0.0

Author SHA1 Message Date
Auxilor
fd87683b6a Fixed display 2021-04-04 16:48:33 +01:00
Auxilor
83da1e7b95 Fixed ShapedCraftingRecipe 2021-04-04 16:34:08 +01:00
Auxilor
9f9515675a Removed ULands as softdepend 2021-04-04 16:27:43 +01:00
Auxilor
1aa084cd90 Fixed main class 2021-04-04 16:27:24 +01:00
Auxilor
525ec0260f Renamed CustomItems to Items 2021-04-04 15:17:02 +01:00
Auxilor
ac15ffee6c Moved ConfigUpdater into core 2021-04-04 15:09:53 +01:00
Auxilor
83d68c5046 Fixed RunnableTask 2021-04-04 15:03:26 +01:00
Auxilor
7d1186811f Cleaned up util initialization 2021-04-04 14:53:40 +01:00
Auxilor
88bc01e5df Refactored shaped recipes 2021-04-04 14:45:17 +01:00
Auxilor
78d2459c7a Changed dependencies 2021-04-04 13:58:40 +01:00
Auxilor
21f4bd79eb Changed TeamUtils teams 2021-04-04 13:50:17 +01:00
Auxilor
64147c6261 Refactoring 2021-04-04 13:45:13 +01:00
Auxilor
c67c486f2f Registered custom logger 2021-04-04 13:31:07 +01:00
Auxilor
ae419bacb3 Refactored Config and Lang into ConfigYml and LangYml 2021-04-04 13:30:27 +01:00
Auxilor
17b0214f2f Added <#ffffff> hex pattern 2021-04-04 13:23:18 +01:00
Auxilor
963f706018 Added more gradient and hex patterns 2021-04-04 13:22:05 +01:00
Auxilor
74398cda62 Removed hardcoded author in PAPI integration 2021-04-04 13:15:23 +01:00
Auxilor
8321af5af2 Renamed RecipePart into CustomItem system 2021-04-03 20:13:34 +01:00
Auxilor
2524d86462 Removed unneeded fully qualified name 2021-04-03 19:57:43 +01:00
Auxilor
e050bf83df Removed 1.15 support 2021-04-03 19:57:27 +01:00
Auxilor
91c936a06f ArrowDataListener now sends the whole ItemStack 2021-04-03 19:53:48 +01:00
Auxilor
93dfd44410 Removed broken ULands integration 2021-04-03 16:37:02 +01:00
Auxilor
304d0cdebf Updated spigot api to 1.16.5 2021-04-03 16:34:49 +01:00
Auxilor
108d878939 Refactored internal/util into internal/core/util 2021-04-03 16:34:19 +01:00
Auxilor
e10e327c56 Updated v1_16_R3 to spigot 1.16.5 2021-04-03 15:28:27 +01:00
Auxilor
cabea9fba9 Added fast sin and cos functions 2021-04-03 15:22:00 +01:00
Auxilor
f9159cf245 Added setters to config 2021-04-03 14:26:27 +01:00
Auxilor
2db011ae10 Refactoring and removed serialization system 2021-04-03 14:19:11 +01:00
Auxilor
f96716966d Removed deprecated DisplayModule method 2021-04-03 14:01:47 +01:00
Auxilor
7515efbde9 Added CraftItemStack check to FastItemStackHandler 2021-04-03 13:57:28 +01:00
Auxilor
4ebd0d79d5 Updated to 5.0.0 2021-04-03 13:26:34 +01:00
Auxilor
0c3b5d3c30 Began implementing FastItemStack 2021-04-03 12:32:39 +01:00
Auxilor
e0b06dedff Continued refactor 2021-04-03 11:01:47 +01:00
Auxilor
187ac8163d Merge branch 'master' into develop
# Conflicts:
#	eco-api/src/main/java/com/willfp/eco/internal/config/AbstractConfig.java
#	eco-api/src/main/java/com/willfp/eco/internal/config/ConfigSection.java
#	eco-api/src/main/java/com/willfp/eco/internal/config/ConfigWrapper.java
#	eco-api/src/main/java/com/willfp/eco/util/SerializationUtils.java
#	eco-api/src/main/java/com/willfp/eco/util/config/Config.java
#	eco-api/src/main/java/com/willfp/eco/util/config/StaticOptionalConfig.java
#	eco-api/src/main/java/com/willfp/eco/util/serialization/Deserializer.java
#	eco-api/src/main/java/com/willfp/eco/util/serialization/EcoSerializable.java
#	eco-api/src/main/java/com/willfp/eco/util/serialization/NoRegisteredDeserializerException.java
2021-04-03 10:49:02 +01:00
Auxilor
ac2078957d Began refactor 2021-04-03 10:48:31 +01:00
Auxilor
352d495301 Renamed eco-util to eco-api 2021-04-03 10:22:01 +01:00
171 changed files with 1222 additions and 1805 deletions

2
.gitignore vendored
View File

@@ -14,7 +14,7 @@ bin/
# Gradle
.gradle
**/build/
!eco-util/src/**/build/
!eco-api/src/**/build/
.gradletasknamecache
!gradle-wrapper.jar
gradle-app.setting

View File

@@ -6,7 +6,7 @@ plugins {
}
dependencies {
implementation project(":eco-util")
implementation project(":eco-api")
implementation project(":eco-core").getSubprojects()
}
@@ -51,7 +51,6 @@ allprojects {
}
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
compileOnly 'org.jetbrains:annotations:19.0.0'
// Lombok
@@ -76,8 +75,8 @@ allprojects {
}
shadowJar {
relocate('org.bstats.bukkit', 'com.willfp.eco.util.shaded.bstats')
relocate('org.apache.maven', 'com.willfp.eco.util.shaded.maven')
relocate('org.bstats.bukkit', 'com.willfp.eco.shaded.bstats')
relocate('org.apache.maven', 'com.willfp.eco.shaded.maven')
}
jar {

View File

@@ -5,6 +5,10 @@
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<!-- Internals don't need javadoc. -->
<suppress files="[\\/]internal[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]internal[\\/]" checks="JavadocVariable"/>
<!-- Modified version of library -->
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
<suppress files="ArmorEquipEvent.java" checks="MissingJavadocMethod"/>

View File

@@ -2,6 +2,7 @@ group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
compileOnly 'org.apache.maven:maven-artifact:3.0.3'
compileOnly 'org.bstats:bstats-bukkit:1.7'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.protocollib;
package com.willfp.eco.core;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
@@ -6,7 +6,6 @@ import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.Getter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -35,7 +34,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* @param priority The priority at which the adapter should be ran on packet send/receive.
* @param postLoad If the packet adapter should be registered after the server has loaded.
*/
protected AbstractPacketAdapter(@NotNull final AbstractEcoPlugin plugin,
protected AbstractPacketAdapter(@NotNull final EcoPlugin plugin,
@NotNull final PacketType type,
@NotNull final ListenerPriority priority,
final boolean postLoad) {
@@ -51,7 +50,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
* @param type The {@link PacketType} to listen for.
* @param postLoad If the packet adapter should be registered after the server has loaded.
*/
protected AbstractPacketAdapter(@NotNull final AbstractEcoPlugin plugin,
protected AbstractPacketAdapter(@NotNull final EcoPlugin plugin,
@NotNull final PacketType type,
final boolean postLoad) {
this(plugin, type, ListenerPriority.NORMAL, postLoad);

View File

@@ -1,29 +1,29 @@
package com.willfp.eco.util.plugin;
package com.willfp.eco.core;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.config.base.ConfigYml;
import com.willfp.eco.core.config.base.LangYml;
import com.willfp.eco.internal.config.updating.ConfigHandler;
import com.willfp.eco.core.display.Display;
import com.willfp.eco.core.display.DisplayModule;
import com.willfp.eco.core.events.EventManager;
import com.willfp.eco.core.extensions.ExtensionLoader;
import com.willfp.eco.core.factory.MetadataValueFactory;
import com.willfp.eco.core.factory.NamespacedKeyFactory;
import com.willfp.eco.core.factory.RunnableFactory;
import com.willfp.eco.core.integrations.IntegrationLoader;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import com.willfp.eco.core.scheduling.Scheduler;
import com.willfp.eco.internal.UpdateChecker;
import com.willfp.eco.internal.arrows.ArrowDataListener;
import com.willfp.eco.internal.bukkit.events.EcoEventManager;
import com.willfp.eco.internal.bukkit.logging.EcoLogger;
import com.willfp.eco.internal.bukkit.scheduling.EcoScheduler;
import com.willfp.eco.internal.events.EcoEventManager;
import com.willfp.eco.internal.extensions.EcoExtensionLoader;
import com.willfp.eco.util.bukkit.events.EventManager;
import com.willfp.eco.util.bukkit.keys.NamespacedKeyFactory;
import com.willfp.eco.util.bukkit.logging.Logger;
import com.willfp.eco.util.bukkit.meta.MetadataValueFactory;
import com.willfp.eco.util.bukkit.scheduling.RunnableFactory;
import com.willfp.eco.util.bukkit.scheduling.Scheduler;
import com.willfp.eco.util.command.AbstractCommand;
import com.willfp.eco.util.config.configs.Config;
import com.willfp.eco.util.config.configs.Lang;
import com.willfp.eco.util.config.updating.ConfigHandler;
import com.willfp.eco.util.display.Display;
import com.willfp.eco.util.display.DisplayModule;
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
import com.willfp.eco.util.integrations.IntegrationLoader;
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.updater.UpdateChecker;
import com.willfp.eco.internal.factory.EcoMetadataValueFactory;
import com.willfp.eco.internal.factory.EcoNamespacedKeyFactory;
import com.willfp.eco.internal.factory.EcoRunnableFactory;
import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI;
import com.willfp.eco.internal.logging.EcoLogger;
import com.willfp.eco.internal.scheduling.EcoScheduler;
import lombok.Getter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.bstats.bukkit.Metrics;
@@ -39,9 +39,10 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public abstract class AbstractEcoPlugin extends JavaPlugin {
public abstract class EcoPlugin extends JavaPlugin {
/**
* Loaded eco plugins.
*/
@@ -83,22 +84,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
@Getter
private final Set<String> loadedIntegrations = new HashSet<>();
/**
* Set of external plugin integrations.
*/
private final List<IntegrationLoader> integrationLoaders = new ArrayList<>();
/**
* Set of classes to be processed on config update.
*/
private final List<Class<?>> updatableClasses = new ArrayList<>();
/**
* The internal plugin logger.
*/
@Getter
private final Logger log;
/**
* The internal plugin scheduler.
*/
@@ -115,13 +105,13 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* Config.yml.
*/
@Getter
private final Config configYml;
private final ConfigYml configYml;
/**
* Lang.yml.
*/
@Getter
private final Lang langYml;
private final LangYml langYml;
/**
* The internal factory to produce {@link org.bukkit.NamespacedKey}s.
@@ -136,7 +126,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
private final MetadataValueFactory metadataValueFactory;
/**
* The internal factory to produce {@link com.willfp.eco.util.bukkit.scheduling.EcoBukkitRunnable}s.
* The internal factory to produce {@link com.willfp.eco.core.scheduling.RunnableTask}s.
*/
@Getter
private final RunnableFactory runnableFactory;
@@ -144,7 +134,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
/**
* The loader for all plugin extensions.
*
* @see com.willfp.eco.util.extensions.Extension
* @see com.willfp.eco.core.extensions.Extension
*/
@Getter
private final ExtensionLoader extensionLoader;
@@ -161,6 +151,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
@Getter
private DisplayModule displayModule;
/**
* The logger for the plugin.
*/
private final Logger logger;
/**
* If the server is running an outdated version of the plugin.
*/
@@ -176,28 +171,28 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* @param proxyPackage The package where proxy implementations are stored.
* @param color The color of the plugin (used in messages, such as &a, &b)
*/
protected AbstractEcoPlugin(@NotNull final String pluginName,
final int resourceId,
final int bStatsId,
@NotNull final String proxyPackage,
@NotNull final String color) {
protected EcoPlugin(@NotNull final String pluginName,
final int resourceId,
final int bStatsId,
@NotNull final String proxyPackage,
@NotNull final String color) {
this.pluginName = pluginName;
this.resourceId = resourceId;
this.bStatsId = bStatsId;
this.proxyPackage = proxyPackage;
this.color = color;
this.log = new EcoLogger(this);
this.scheduler = new EcoScheduler(this);
this.eventManager = new EcoEventManager(this);
this.namespacedKeyFactory = new NamespacedKeyFactory(this);
this.metadataValueFactory = new MetadataValueFactory(this);
this.runnableFactory = new RunnableFactory(this);
this.namespacedKeyFactory = new EcoNamespacedKeyFactory(this);
this.metadataValueFactory = new EcoMetadataValueFactory(this);
this.runnableFactory = new EcoRunnableFactory(this);
this.extensionLoader = new EcoExtensionLoader(this);
this.configHandler = new ConfigHandler(this);
this.logger = new EcoLogger(this);
this.langYml = new Lang(this);
this.configYml = new Config(this);
this.langYml = new LangYml(this);
this.configYml = new ConfigYml(this);
LOADED_ECO_PLUGINS.add(this.getName().toLowerCase());
}
@@ -207,10 +202,10 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
*/
@Override
public final void onEnable() {
super.onLoad();
super.onEnable();
this.getLog().info("");
this.getLog().info("Loading " + this.color + this.pluginName);
this.getLogger().info("");
this.getLogger().info("Loading " + this.color + this.pluginName);
this.getEventManager().registerListener(new ArrowDataListener(this));
@@ -220,9 +215,9 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) {
this.outdated = true;
this.getScheduler().runTimer(() -> {
this.getLog().info("&c " + this.pluginName + " is out of date! (Version " + this.getDescription().getVersion() + ")");
this.getLog().info("&cThe newest version is &f" + version);
this.getLog().info("&cDownload the new version!");
this.getLogger().info("&c " + this.pluginName + " is out of date! (Version " + this.getDescription().getVersion() + ")");
this.getLogger().info("&cThe newest version is &f" + version);
this.getLogger().info("&cDownload the new version!");
}, 0, 864000);
}
});
@@ -243,7 +238,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
}
}));
this.getLog().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
Prerequisite.update();
@@ -265,7 +260,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
this.enable();
this.getLog().info("");
this.getLogger().info("");
}
/**
@@ -308,23 +303,23 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
});
if (!Prerequisite.HAS_PAPER.isMet()) {
this.getLog().error("");
this.getLog().error("----------------------------");
this.getLog().error("");
this.getLog().error("You don't seem to be running paper!");
this.getLog().error("Paper is strongly recommended for all servers,");
this.getLog().error("and some things may not function properly without it");
this.getLog().error("Download Paper from &fhttps://papermc.io");
this.getLog().error("");
this.getLog().error("----------------------------");
this.getLog().error("");
this.getLogger().severe("");
this.getLogger().severe("----------------------------");
this.getLogger().severe("");
this.getLogger().severe("You don't seem to be running paper!");
this.getLogger().severe("Paper is strongly recommended for all servers,");
this.getLogger().severe("and some things may not function properly without it");
this.getLogger().severe("Download Paper from &fhttps://papermc.io");
this.getLogger().severe("");
this.getLogger().severe("----------------------------");
this.getLogger().severe("");
}
this.postLoad();
this.reload();
this.getLog().info("Loaded " + this.color + this.pluginName);
this.getLogger().info("Loaded " + this.color + this.pluginName);
}
/**
@@ -409,5 +404,13 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* @return The display module, or null.
*/
@Nullable
protected abstract DisplayModule createDisplayModule();
protected DisplayModule createDisplayModule() {
return null;
}
@NotNull
@Override
public Logger getLogger() {
return logger;
}
}

View File

@@ -0,0 +1,22 @@
package com.willfp.eco.core;
import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public abstract class PluginDependent {
/**
* The {@link EcoPlugin} that is stored.
*/
@Getter(AccessLevel.PROTECTED)
private final EcoPlugin plugin;
/**
* Pass an {@link EcoPlugin} in order to interface with it.
*
* @param plugin The plugin to manage.
*/
protected PluginDependent(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
}

View File

@@ -1,7 +1,6 @@
package com.willfp.eco.util.optional;
package com.willfp.eco.core;
import com.willfp.eco.util.ClassUtils;
import com.willfp.eco.util.proxy.ProxyConstants;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
@@ -15,15 +14,6 @@ public class Prerequisite {
* All existing prerequisites are registered on creation.
*/
private static final List<Prerequisite> VALUES = new ArrayList<>();
/**
* Requires the server to be running minecraft version 1.16 or higher.
*/
public static final Prerequisite MINIMUM_1_16 = new Prerequisite(
() -> !ProxyConstants.NMS_VERSION.contains("15"),
"Requires minimum server version of 1.16"
);
/**
* Requires the server to be running an implementation of paper.
*/

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.util.command;
package com.willfp.eco.core.command;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -43,12 +43,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
* <p>
* The name cannot be the same as an existing command as this will conflict.
*
* @param plugin The owning {@link AbstractEcoPlugin}.
* @param plugin The owning {@link EcoPlugin}.
* @param name The name used in execution.
* @param permission The permission required to execute the command.
* @param playersOnly If only players should be able to execute this command.
*/
protected AbstractCommand(@NotNull final AbstractEcoPlugin plugin,
protected AbstractCommand(@NotNull final EcoPlugin plugin,
@NotNull final String name,
@NotNull final String permission,
final boolean playersOnly) {
@@ -98,7 +98,7 @@ public abstract class AbstractCommand extends PluginDependent implements Command
* @param command The bukkit command.
* @param label The name of the executed command.
* @param args The arguments of the command (anything after the physical command name)
* @return If the command was processed by the linked {@link AbstractEcoPlugin}
* @return If the command was processed by the linked {@link EcoPlugin}
*/
@Override
public final boolean onCommand(@NotNull final CommandSender sender,

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.command;
package com.willfp.eco.core.command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.config;
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.AbstractUpdatableConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.internal.config.UpdatableYamlConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class BaseConfig extends AbstractUpdatableConfig {
public abstract class BaseConfig extends UpdatableYamlConfig {
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
@@ -18,7 +18,7 @@ public abstract class BaseConfig extends AbstractUpdatableConfig {
*/
protected BaseConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final AbstractEcoPlugin plugin,
@NotNull final EcoPlugin plugin,
@NotNull final String... updateBlacklist) {
super(configName, plugin, "", plugin.getClass(), removeUnused, updateBlacklist);
}
@@ -34,7 +34,7 @@ public abstract class BaseConfig extends AbstractUpdatableConfig {
*/
protected BaseConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final AbstractEcoPlugin plugin) {
@NotNull final EcoPlugin plugin) {
super(configName, plugin, "", plugin.getClass(), removeUnused, "");
}
}

View File

@@ -1,7 +1,5 @@
package com.willfp.eco.util.config;
package com.willfp.eco.core.config;
import com.willfp.eco.util.serialization.EcoSerializable;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -30,15 +28,6 @@ public interface Config {
@NotNull
List<String> getKeys(boolean deep);
/**
* Set an object in config.
*
* @param path The path.
* @param object The object.
*/
void set(@NotNull String path,
@NotNull EcoSerializable<?> object);
/**
* Get an object from config.
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#get(String)}.
@@ -47,49 +36,17 @@ public interface Config {
* @return The object.
*/
@Nullable
Object getRaw(@NotNull String path);
Object get(@NotNull String path);
/**
* Get an object from config.
* Set an object in config.
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#set(String, Object)}
*
* @param path The path.
* @param clazz The class of the object.
* @param <T> The type of the object.
* @return The object.
* @param path The path.
* @param object The object.
*/
@NotNull <T extends EcoSerializable<T>> T get(@NotNull String path,
@NotNull Class<T> clazz);
/**
* Get an object from config.
*
* @param path The path.
* @param clazz The class of the object.
* @param <T> The type of the object.
* @return The object, or null if not found.
*/
@Nullable <T extends EcoSerializable<T>> T getOrNull(@NotNull String path,
@NotNull Class<T> clazz);
/**
* Get bukkit configuration section from config.
*
* @param path The key to check.
* @return The configuration section. Throws NPE if not found.
*/
@NotNull
@Deprecated
ConfigurationSection getSection(@NotNull String path);
/**
* Get bukkit configuration section from config.
*
* @param path The key to check.
* @return The configuration section, or null if not found.
*/
@Nullable
@Deprecated
ConfigurationSection getSectionOrNull(@NotNull String path);
void set(@NotNull String path,
@Nullable Object object);
/**
* Get subsection from config.

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.config.updating.annotations;
package com.willfp.eco.core.config;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.config;
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.AbstractUpdatableConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.internal.config.UpdatableYamlConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class ExtendableConfig extends AbstractUpdatableConfig {
public abstract class ExtendableConfig extends UpdatableYamlConfig {
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
@@ -19,7 +19,7 @@ public abstract class ExtendableConfig extends AbstractUpdatableConfig {
*/
protected ExtendableConfig(@NotNull final String configName,
final boolean removeUnused,
@NotNull final AbstractEcoPlugin plugin,
@NotNull final EcoPlugin plugin,
@NotNull final Class<?> source,
@NotNull final String subDirectoryPath,
@NotNull final String... updateBlacklist) {

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.config;
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.AbstractConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.internal.config.LoadableYamlConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public abstract class StaticBaseConfig extends AbstractConfig {
public abstract class StaticBaseConfig extends LoadableYamlConfig {
/**
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
* <p>
@@ -14,7 +14,7 @@ public abstract class StaticBaseConfig extends AbstractConfig {
* @param plugin The plugin.
*/
protected StaticBaseConfig(@NotNull final String configName,
@NotNull final AbstractEcoPlugin plugin) {
@NotNull final EcoPlugin plugin) {
super(configName, plugin, "", plugin.getClass());
}
}

View File

@@ -0,0 +1,18 @@
package com.willfp.eco.core.config;
import com.willfp.eco.internal.config.ConfigWrapper;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
public abstract class YamlConfig extends ConfigWrapper<YamlConfiguration> {
/**
* Config implementation for passing YamlConfigurations.
* <p>
* Does not automatically update.
*
* @param config The YamlConfiguration handle.
*/
public YamlConfig(@NotNull final YamlConfiguration config) {
init(config);
}
}

View File

@@ -0,0 +1,17 @@
package com.willfp.eco.core.config.base;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public class ConfigYml extends BaseConfig {
/**
* Config.yml.
*
* @param plugin The plugin.
*/
public ConfigYml(@NotNull final EcoPlugin plugin) {
super("config", true, plugin);
}
}

View File

@@ -1,16 +1,16 @@
package com.willfp.eco.util.config.configs;
package com.willfp.eco.core.config.base;
import com.willfp.eco.util.config.BaseConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
public class Lang extends BaseConfig {
public class LangYml extends BaseConfig {
/**
* Lang.yml.
*
* @param plugin The plugin.
*/
public Lang(@NotNull final AbstractEcoPlugin plugin) {
public LangYml(@NotNull final EcoPlugin plugin) {
super("lang", false, plugin);
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.display;
package com.willfp.eco.core.display;
import lombok.experimental.UtilityClass;
import org.apache.commons.lang.Validate;
@@ -16,7 +16,6 @@ import java.util.List;
import java.util.Map;
@UtilityClass
@SuppressWarnings("deprecation")
public class Display {
/**
* The prefix for lore lines.
@@ -80,7 +79,6 @@ public class Display {
List<DisplayModule> modules = MODULES.get(priority);
for (DisplayModule module : modules) {
Object[] varargs = pluginVarArgs.get(module.getPluginName());
module.display(itemStack);
module.display(itemStack, varargs);
}
}

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.util.display;
package com.willfp.eco.core.display;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import lombok.Getter;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@@ -19,7 +19,7 @@ public abstract class DisplayModule extends PluginDependent {
* @param plugin The plugin that the display is for.
* @param priority The priority of the module.
*/
protected DisplayModule(@NotNull final AbstractEcoPlugin plugin,
protected DisplayModule(@NotNull final EcoPlugin plugin,
@NotNull final DisplayPriority priority) {
super(plugin);
this.priority = priority;
@@ -36,26 +36,13 @@ public abstract class DisplayModule extends PluginDependent {
// Technically optional.
}
/**
* Display an item.
* <p>
* This method exists for parity with older plugins that don't include the varargs.
*
* @param itemStack The item.
* @deprecated Use {@link this#display(ItemStack, Object...)} instead.
*/
@Deprecated
protected void display(@NotNull final ItemStack itemStack) {
// Technically optional.
}
/**
* Revert an item.
*
* @param itemStack The item.
*/
protected void revert(@NotNull final ItemStack itemStack) {
// Technically optoinal.
// Technically optional.
}
/**

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.display;
package com.willfp.eco.core.display;
public enum DisplayPriority {
/**

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops;
package com.willfp.eco.core.drops;
import com.willfp.eco.internal.drops.AbstractDropQueue;
import com.willfp.eco.internal.drops.DropManager;

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.core.events;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
public class ArmorEquipEvent extends PlayerEvent {
private static final HandlerList HANDLERS = new HandlerList();
public ArmorEquipEvent(@NotNull final Player player) {
super(player);
}
/**
* Gets a list of handlers handling this event.
*
* @return A list of handlers handling this event.
*/
@Override
@NotNull
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.events.entitydeathbyentity;
package com.willfp.eco.core.events;
import lombok.Getter;
import org.bukkit.entity.Entity;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.bukkit.events;
package com.willfp.eco.core.events;
import org.bukkit.event.Listener;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.events.naturalexpgainevent;
package com.willfp.eco.core.events;
import lombok.Getter;
import org.bukkit.event.Event;

View File

@@ -1,25 +1,25 @@
package com.willfp.eco.util.extensions;
package com.willfp.eco.core.extensions;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.internal.extensions.ExtensionMetadata;
import com.willfp.eco.core.EcoPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public abstract class Extension {
/**
* The {@link AbstractEcoPlugin} that this extension is for.
* The {@link EcoPlugin} that this extension is for.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin;
private final EcoPlugin plugin;
/**
* Create a new extension for a plugin.
*
* @param plugin The plugin.
*/
protected Extension(@NotNull final AbstractEcoPlugin plugin) {
protected Extension(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
@@ -71,7 +71,7 @@ public abstract class Extension {
*/
public final String getName() {
Validate.notNull(metadata, "Metadata cannot be null!");
return this.metadata.name;
return this.metadata.getName();
}
/**
@@ -81,36 +81,6 @@ public abstract class Extension {
*/
public final String getVersion() {
Validate.notNull(metadata, "Metadata cannot be null!");
return this.metadata.version;
}
/**
* Wrapper for the string and version of the extension.
* Contains versions and name.
* Designed for internal use.
*/
@ApiStatus.Internal
public static final class ExtensionMetadata {
/**
* The version of the extension.
*/
private final @NotNull String version;
/**
* The extension's name.
*/
private final @NotNull String name;
/**
* Create a new extension metadata.
*
* @param version The version for the extension to be.
* @param name The name of the extension.
*/
public ExtensionMetadata(@NotNull final String version,
@NotNull final String name) {
this.version = version;
this.name = name;
}
return this.metadata.getVersion();
}
}

View File

@@ -1,6 +1,4 @@
package com.willfp.eco.util.extensions.loader;
import com.willfp.eco.util.extensions.Extension;
package com.willfp.eco.core.extensions;
import java.util.Set;
@@ -20,11 +18,6 @@ public interface ExtensionLoader {
*/
void unloadExtensions();
/**
* Reload all extensions.
*/
void reloadExtensions();
/**
* Retrieve a set of all loaded extensions.
*

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.extensions;
package com.willfp.eco.core.extensions;
import org.jetbrains.annotations.NotNull;

View File

@@ -0,0 +1,8 @@
package com.willfp.eco.core.factory;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
public interface MetadataValueFactory {
FixedMetadataValue create(@NotNull Object value);
}

View File

@@ -0,0 +1,14 @@
package com.willfp.eco.core.factory;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
public interface NamespacedKeyFactory {
/**
* Create an {@link NamespacedKey} associated with an {@link com.willfp.eco.core.EcoPlugin}.
*
* @param key The key in the {@link NamespacedKey}.
* @return The created {@link NamespacedKey}.
*/
NamespacedKey create(@NotNull String key);
}

View File

@@ -0,0 +1,16 @@
package com.willfp.eco.core.factory;
import com.willfp.eco.core.scheduling.RunnableTask;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
public interface RunnableFactory {
/**
* Create a {@link RunnableTask}.
*
* @param consumer Lambda of the code to run, where the parameter represents the instance of the runnable.
* @return The created {@link RunnableTask}.
*/
RunnableTask create(@NotNull Consumer<RunnableTask> consumer);
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations;
package com.willfp.eco.core.integrations;
public interface Integration {
/**

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations;
package com.willfp.eco.core.integrations;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.anticheat;
package com.willfp.eco.core.integrations.anticheat;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
@@ -22,7 +22,7 @@ public class AnticheatManager {
* @param plugin The plugin.
* @param anticheat The anticheat to register.
*/
public void register(@NotNull final AbstractEcoPlugin plugin,
public void register(@NotNull final EcoPlugin plugin,
@NotNull final AnticheatWrapper anticheat) {
if (anticheat instanceof Listener) {
plugin.getEventManager().registerListener((Listener) anticheat);

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.anticheat;
package com.willfp.eco.core.integrations.anticheat;
import com.willfp.eco.util.integrations.Integration;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.antigrief;
package com.willfp.eco.core.integrations.antigrief;
import lombok.experimental.UtilityClass;
import org.bukkit.Location;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.antigrief;
package com.willfp.eco.core.integrations.antigrief;
import com.willfp.eco.util.integrations.Integration;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.mcmmo;
package com.willfp.eco.core.integrations.mcmmo;
import lombok.experimental.UtilityClass;
import org.bukkit.block.Block;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.mcmmo;
package com.willfp.eco.core.integrations.mcmmo;
import org.bukkit.block.Block;
import org.bukkit.event.Event;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.placeholder;
package com.willfp.eco.core.integrations.placeholder;
import lombok.Getter;
import org.apache.commons.lang.Validate;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.integrations.placeholder;
package com.willfp.eco.core.integrations.placeholder;
import com.willfp.eco.util.integrations.Integration;
import com.willfp.eco.core.integrations.Integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.integrations.placeholder;
package com.willfp.eco.core.integrations.placeholder;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;

View File

@@ -0,0 +1,59 @@
package com.willfp.eco.core.items;
import lombok.Getter;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Predicate;
public class CustomItem implements TestableItem {
/**
* The key.
*/
@Getter
private final NamespacedKey key;
/**
* The test for ItemStacks to pass.
*/
private final Predicate<ItemStack> test;
/**
* Example Item: what the user should see.
*/
private final ItemStack item;
/**
* Create a new complex recipe part.
*
* @param key The item key.
* @param test The test.
* @param item The example ItemStacks.
*/
public CustomItem(@NotNull final NamespacedKey key,
@NotNull final Predicate<ItemStack> test,
@NotNull final ItemStack item) {
this.key = key;
this.test = test;
this.item = item;
}
@Override
public boolean matches(@Nullable final ItemStack itemStack) {
return test.test(itemStack);
}
@Override
public ItemStack getItem() {
return item;
}
/**
* Register the item.
*/
public void register() {
Items.registerCustomItem(this.getKey(), this);
}
}

View File

@@ -0,0 +1,69 @@
package com.willfp.eco.core.items;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
@UtilityClass
@SuppressWarnings("deprecation")
public final class Items {
/**
* All recipe parts.
*/
private static final Map<NamespacedKey, CustomItem> REGISTRY = new HashMap<>();
/**
* Register a new recipe part.
*
* @param key The key of the recipe part.
* @param part The recipe part.
*/
public void registerCustomItem(@NotNull final NamespacedKey key,
@NotNull final CustomItem part) {
REGISTRY.put(key, part);
}
/**
* Lookup item from string.
* <p>
* Used for recipes.
*
* @param key The string to test.
* @return The found testable item, or an empty item if not found.
*/
public TestableItem lookup(@NotNull final String key) {
String[] split = key.toLowerCase().split(":");
if (split.length == 1) {
Material material = Material.getMaterial(key.toUpperCase());
if (material == null || material == Material.AIR) {
return new EmptyTestableItem();
}
return new MaterialTestableItem(material);
}
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
return part == null ? new EmptyTestableItem() : part;
}
/**
* Get if itemStack is a custom item.
*
* @param itemStack The itemStack to check.
* @return If is recipe.
*/
public boolean isCustomItem(@NotNull final ItemStack itemStack) {
for (CustomItem item : REGISTRY.values()) {
if (item.matches(itemStack)) {
return true;
}
}
return false;
}
}

View File

@@ -1,9 +1,9 @@
package com.willfp.eco.util.recipe.parts;
package com.willfp.eco.core.items;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public interface RecipePart {
public interface TestableItem {
/**
* If an ItemStack matches the recipe part.
*
@@ -13,10 +13,9 @@ public interface RecipePart {
boolean matches(@Nullable ItemStack itemStack);
/**
* Get a displayed itemstack, for autocraft.
* Get an example item.
*
* @return The item, displayed.
* @return The item.
*/
ItemStack getDisplayed();
ItemStack getItem();
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.proxy;
package com.willfp.eco.core.proxy;
public interface AbstractProxy {

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.proxy;
package com.willfp.eco.core.proxy;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.proxy;
package com.willfp.eco.core.proxy;
import org.jetbrains.annotations.NotNull;

View File

@@ -0,0 +1,62 @@
package com.willfp.eco.core.recipe;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@UtilityClass
@SuppressWarnings("deprecation")
public class Recipes {
/**
* Registry of all recipes.
*/
private static final BiMap<NamespacedKey, CraftingRecipe> RECIPES = HashBiMap.create();
/**
* Register a recipe.
*
* @param recipe The recipe.
*/
public void register(@NotNull final CraftingRecipe recipe) {
RECIPES.forcePut(recipe.getKey(), recipe);
}
/**
* Get recipe matching matrix.
*
* @param matrix The matrix to test.
* @return The match, or null if not found.
*/
@Nullable
public CraftingRecipe getMatch(@NotNull final ItemStack[] matrix) {
return RECIPES.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
}
/**
* Get recipe by key.
*
* @param key The key.
* @return The recipe, or null if not found.
*/
@Nullable
public CraftingRecipe getRecipe(@NotNull final NamespacedKey key) {
CraftingRecipe recipe = RECIPES.get(key);
if (recipe != null) {
return recipe;
}
if (key.getKey().contains("_displayed")) {
NamespacedKey otherKey = new NamespacedKey(key.getNamespace(), key.getKey().replace("_displayed", ""));
return RECIPES.get(otherKey);
}
return null;
}
}

View File

@@ -1,14 +1,15 @@
package com.willfp.eco.util.recipe.parts;
package com.willfp.eco.core.recipe.parts;
import com.willfp.eco.core.items.TestableItem;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
public class EmptyRecipePart implements RecipePart {
public class EmptyTestableItem implements TestableItem {
/**
* Create a new empty recipe part.
*/
public EmptyRecipePart() {
public EmptyTestableItem() {
}
@@ -24,7 +25,7 @@ public class EmptyRecipePart implements RecipePart {
}
@Override
public ItemStack getDisplayed() {
public ItemStack getItem() {
return new ItemStack(Material.AIR);
}
}

View File

@@ -1,12 +1,13 @@
package com.willfp.eco.util.recipe.parts;
package com.willfp.eco.core.recipe.parts;
import com.willfp.eco.core.items.TestableItem;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SimpleRecipePart implements RecipePart {
public class MaterialTestableItem implements TestableItem {
/**
* The material.
*/
@@ -18,7 +19,7 @@ public class SimpleRecipePart implements RecipePart {
*
* @param material The material.
*/
public SimpleRecipePart(@NotNull final Material material) {
public MaterialTestableItem(@NotNull final Material material) {
this.material = material;
}
@@ -34,7 +35,7 @@ public class SimpleRecipePart implements RecipePart {
}
@Override
public ItemStack getDisplayed() {
public ItemStack getItem() {
return new ItemStack(material);
}
}

View File

@@ -0,0 +1,51 @@
package com.willfp.eco.core.recipe.recipes;
import com.willfp.eco.core.items.TestableItem;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface CraftingRecipe {
/**
* Test matrix against recipe.
*
* @param matrix The matrix to check.
* @return If the recipe matches.
*/
boolean test(@NotNull ItemStack[] matrix);
/**
* Register the recipe.
*/
void register();
/**
* The recipe parts.
*
* @return The parts.
*/
List<TestableItem> getParts();
/**
* Get the recipe key.
*
* @return The key.
*/
NamespacedKey getKey();
/**
* Get the displayed recipe key.
*
* @return The key.
*/
NamespacedKey getDisplayedKey();
/**
* Get the recipe output.
*
* @return The output.
*/
ItemStack getOutput();
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.recipe.recipes;
package com.willfp.eco.core.recipe.recipes;
import lombok.Getter;

View File

@@ -1,24 +1,29 @@
package com.willfp.eco.util.recipe.recipes;
package com.willfp.eco.core.recipe.recipes;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.recipe.Recipes;
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
import com.willfp.eco.util.recipe.parts.RecipePart;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.items.TestableItem;
import com.willfp.eco.core.recipe.Recipes;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public final class EcoShapedRecipe extends PluginDependent {
@SuppressWarnings("deprecation")
public final class ShapedCraftingRecipe extends PluginDependent implements CraftingRecipe {
/**
* Recipe parts.
*/
@Getter
private final RecipePart[] parts;
private final List<TestableItem> parts;
/**
* The key of the recipe.
@@ -38,10 +43,10 @@ public final class EcoShapedRecipe extends PluginDependent {
@Getter
private final ItemStack output;
private EcoShapedRecipe(@NotNull final AbstractEcoPlugin plugin,
@NotNull final String key,
@NotNull final RecipePart[] parts,
@NotNull final ItemStack output) {
private ShapedCraftingRecipe(@NotNull final EcoPlugin plugin,
@NotNull final String key,
@NotNull final List<TestableItem> parts,
@NotNull final ItemStack output) {
super(plugin);
this.parts = parts;
@@ -50,36 +55,11 @@ public final class EcoShapedRecipe extends PluginDependent {
this.output = output;
}
/**
* Get item material at a specific index.
*
* @param index The index to check.
* @return The material.
*/
public Material getMaterialAtIndex(final int index) {
return parts[index].getDisplayed().getType();
}
/**
* Get "real" item at specific index.
*
* @param index The index to check.
* @return The item.
*/
public ItemStack getDisplayedAtIndex(final int index) {
return parts[index].getDisplayed();
}
/**
* Test matrix against recipe.
*
* @param matrix The matrix to check.
* @return If the recipe matches.
*/
@Override
public boolean test(@NotNull final ItemStack[] matrix) {
boolean matches = true;
for (int i = 0; i < 9; i++) {
if (!parts[i].matches(matrix[i])) {
if (!parts.get(i).matches(matrix[i])) {
matches = false;
}
}
@@ -87,20 +67,29 @@ public final class EcoShapedRecipe extends PluginDependent {
return matches;
}
/**
* Register the recipe.
*/
@Override
public void register() {
Recipes.register(this);
}
@Override
public String toString() {
return "EcoShapedRecipe{"
+ "parts=" + Arrays.toString(parts)
+ ", key='" + key + '\''
+ ", output=" + output
+ '}';
Bukkit.getServer().removeRecipe(this.getKey());
Bukkit.getServer().removeRecipe(this.getDisplayedKey());
ShapedRecipe shapedRecipe = new ShapedRecipe(this.getKey(), this.getOutput());
shapedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) {
char character = String.valueOf(i).toCharArray()[0];
shapedRecipe.setIngredient(character, parts.get(i).getItem().getType());
}
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
displayedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) {
char character = String.valueOf(i).toCharArray()[0];
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(parts.get(i).getItem()));
}
Bukkit.getServer().addRecipe(shapedRecipe);
Bukkit.getServer().addRecipe(displayedRecipe);
}
/**
@@ -110,7 +99,7 @@ public final class EcoShapedRecipe extends PluginDependent {
* @param key The recipe key.
* @return A new builder.
*/
public static Builder builder(@NotNull final AbstractEcoPlugin plugin,
public static Builder builder(@NotNull final EcoPlugin plugin,
@NotNull final String key) {
return new Builder(plugin, key);
}
@@ -119,7 +108,7 @@ public final class EcoShapedRecipe extends PluginDependent {
/**
* The recipe parts.
*/
private final RecipePart[] recipeParts = new RecipePart[9];
private final List<TestableItem> recipeParts = new ArrayList<>(Arrays.asList(null, null, null, null, null, null, null, null, null)); // Jank
/**
* The output of the recipe.
@@ -134,7 +123,7 @@ public final class EcoShapedRecipe extends PluginDependent {
/**
* The plugin that created the recipe.
*/
private final AbstractEcoPlugin plugin;
private final EcoPlugin plugin;
/**
* Create a new recipe builder.
@@ -142,7 +131,7 @@ public final class EcoShapedRecipe extends PluginDependent {
* @param plugin The plugin that owns the recipe.
* @param key The recipe key.
*/
private Builder(@NotNull final AbstractEcoPlugin plugin,
private Builder(@NotNull final EcoPlugin plugin,
@NotNull final String key) {
this.key = key;
this.plugin = plugin;
@@ -156,8 +145,8 @@ public final class EcoShapedRecipe extends PluginDependent {
* @return The builder.
*/
public Builder setRecipePart(@NotNull final RecipePosition position,
@NotNull final RecipePart part) {
this.recipeParts[position.getIndex()] = part;
@NotNull final TestableItem part) {
recipeParts.set(position.getIndex(), part);
return this;
}
@@ -169,8 +158,8 @@ public final class EcoShapedRecipe extends PluginDependent {
* @return The builder.
*/
public Builder setRecipePart(final int position,
@NotNull final RecipePart part) {
this.recipeParts[position] = part;
@NotNull final TestableItem part) {
recipeParts.set(position, part);
return this;
}
@@ -190,14 +179,14 @@ public final class EcoShapedRecipe extends PluginDependent {
*
* @return The built recipe.
*/
public EcoShapedRecipe build() {
public ShapedCraftingRecipe build() {
for (int i = 0; i < 9; i++) {
if (recipeParts[i] == null) {
recipeParts[i] = new EmptyRecipePart();
if (recipeParts.get(i) == null) {
recipeParts.set(i, new EmptyTestableItem());
}
}
return new EcoShapedRecipe(plugin, key.toLowerCase(), recipeParts, output);
return new ShapedCraftingRecipe(plugin, key.toLowerCase(), recipeParts, output);
}
}
}

View File

@@ -0,0 +1,59 @@
package com.willfp.eco.core.scheduling;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
public interface RunnableTask extends Runnable {
/**
* Run the task.
*
* @return The created {@link BukkitTask}.
*/
@NotNull BukkitTask runTask();
/**
* Run the task asynchronously.
*
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskAsynchronously();
/**
* Run the task after a specified number of ticks.
*
* @param delay The number of ticks to wait.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskLater(long delay);
/**
* Run the task asynchronously after a specified number of ticks.
*
* @param delay The number of ticks to wait.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskLaterAsynchronously(long delay);
/**
* Run the task repeatedly on a timer.
*
* @param delay The delay before the task is first ran (in ticks).
* @param period The ticks elapsed before the task is ran again.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskTimer(long delay, long period);
/**
* Run the task repeatedly on a timer asynchronously.
*
* @param delay The delay before the task is first ran (in ticks).
* @param period The ticks elapsed before the task is ran again.
* @return The created {@link BukkitTask}
*/
@NotNull BukkitTask runTaskTimerAsynchronously(long delay, long period);
/**
* Cancel the task.
*/
void cancel();
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.bukkit.scheduling;
package com.willfp.eco.core.scheduling;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
@@ -68,7 +68,7 @@ public interface Scheduler {
long repeat);
/**
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
* Cancel all running tasks from the linked {@link EcoPlugin}.
*/
void cancelAll();
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.tuples;
package com.willfp.eco.core.tuples;
import lombok.Getter;
import lombok.Setter;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.tuples;
package com.willfp.eco.core.tuples;
import lombok.Getter;
import lombok.Setter;

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.util.updater;
package com.willfp.eco.internal;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.util.Consumer;
import org.jetbrains.annotations.NotNull;
@@ -16,7 +16,7 @@ public class UpdateChecker extends PluginDependent {
*
* @param plugin The plugin to check.
*/
public UpdateChecker(@NotNull final AbstractEcoPlugin plugin) {
public UpdateChecker(@NotNull final EcoPlugin plugin) {
super(plugin);
}

View File

@@ -1,9 +1,8 @@
package com.willfp.eco.internal.arrows;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
@@ -14,16 +13,14 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class ArrowDataListener extends PluginDependent implements Listener {
/**
* Listener to add metadata to arrows about the enchantments on the bow that shot them.
*
* @param plugin The {@link AbstractEcoPlugin} that registered the listener.
* @param plugin The {@link EcoPlugin} that registered the listener.
*/
@ApiStatus.Internal
public ArrowDataListener(@NotNull final AbstractEcoPlugin plugin) {
public ArrowDataListener(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@@ -54,7 +51,6 @@ public class ArrowDataListener extends PluginDependent implements Listener {
return;
}
Map<Enchantment, Integer> enchantments = item.getItemMeta().getEnchants();
arrow.setMetadata("enchantments", this.getPlugin().getMetadataValueFactory().create(enchantments));
arrow.setMetadata("shot-from", this.getPlugin().getMetadataValueFactory().create(item));
}
}

View File

@@ -3,14 +3,13 @@ package com.willfp.eco.internal.config;
import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;
public class ConfigSection extends AbstractUndefinedConfig<ConfigurationSection> {
public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
/**
* Config section.
*
* @param section The section.
*/
protected ConfigSection(@NotNull final ConfigurationSection section) {
super("subsection");
this.init(section);
}
}

View File

@@ -1,11 +1,10 @@
package com.willfp.eco.internal.config;
import com.willfp.eco.util.SerializationUtils;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.config.Config;
import com.willfp.eco.util.serialization.EcoSerializable;
import com.willfp.eco.core.config.Config;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemorySection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -15,12 +14,13 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
@SuppressWarnings({"unchecked", "unused", "DeprecatedIsStillUsed"})
public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> implements Config {
@SuppressWarnings({"unchecked", "unused"})
public abstract class ConfigWrapper<T extends ConfigurationSection> implements Config {
/**
* The linked {@link MemorySection} where values are physically stored.
* The linked {@link ConfigurationSection} where values are physically stored.
*/
protected T config = null;
@Getter
private T handle = null;
/**
* Cached values for faster reading.
@@ -29,15 +29,13 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
/**
* Abstract config.
*
* @param configName The name of the config
*/
protected AbstractUndefinedConfig(@NotNull final String configName) {
protected ConfigWrapper() {
}
protected Config init(@NotNull final T config) {
this.config = config;
this.handle = config;
return this;
}
@@ -48,98 +46,44 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
@Override
public boolean has(@NotNull final String path) {
return config.contains(path);
return handle.contains(path);
}
@NotNull
@Override
public List<String> getKeys(final boolean deep) {
return new ArrayList<>(config.getKeys(deep));
return new ArrayList<>(handle.getKeys(deep));
}
@Override
@Nullable
public Object get(@NotNull final String path) {
return handle.get(path);
}
@Override
public void set(@NotNull final String path,
@NotNull final EcoSerializable<?> object) {
Config serializedConfig = object.serialize();
for (String key : serializedConfig.getKeys(true)) {
Object raw = serializedConfig.getRaw(key);
config.set(path + "." + key, raw);
cache.put(path + "." + key, raw);
}
}
@Override
@Nullable
public Object getRaw(@NotNull final String path) {
return config.get(path);
}
@Override
@NotNull
public <T extends EcoSerializable<T>> T get(@NotNull final String path,
@NotNull final Class<T> clazz) {
T object = getOrNull(path, clazz);
if (object == null) {
throw new NullPointerException("Object cannot be null!");
} else {
return object;
}
}
@Override
@Nullable
public <T extends EcoSerializable<T>> T getOrNull(@NotNull final String path,
@NotNull final Class<T> clazz) {
if (cache.containsKey(path)) {
return (T) cache.get(path);
} else {
Config section = getSubsectionOrNull(path);
if (section == null) {
return null;
}
cache.put(path, SerializationUtils.deserialize(section, clazz));
return getOrNull(path, clazz);
}
}
@Override
@NotNull
@Deprecated
public ConfigurationSection getSection(@NotNull final String path) {
ConfigurationSection section = getSectionOrNull(path);
if (section == null) {
throw new NullPointerException("Section cannot be null!");
} else {
return section;
}
}
@Override
@Nullable
@Deprecated
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
if (cache.containsKey(path)) {
return (ConfigurationSection) cache.get(path);
} else {
cache.put(path, config.getConfigurationSection(path));
return getSectionOrNull(path);
}
@Nullable final Object object) {
handle.set(path, object);
}
@Override
@NotNull
public Config getSubsection(@NotNull final String path) {
return new ConfigSection(this.getSection(path));
Config subsection = getSubsectionOrNull(path);
Validate.notNull(subsection);
return subsection;
}
@Override
@Nullable
public Config getSubsectionOrNull(@NotNull final String path) {
ConfigurationSection section = this.getSectionOrNull(path);
if (section == null) {
return null;
if (cache.containsKey(path)) {
return (Config) cache.get(path);
} else {
cache.put(path, new ConfigSection(Objects.requireNonNull(handle.getConfigurationSection(path))));
return getSubsectionOrNull(path);
}
return new ConfigSection(section);
}
@Override
@@ -147,7 +91,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (int) cache.get(path);
} else {
cache.put(path, config.getInt(path, 0));
cache.put(path, handle.getInt(path, 0));
return getInt(path);
}
}
@@ -168,7 +112,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (int) cache.get(path);
} else {
cache.put(path, config.getInt(path, def));
cache.put(path, handle.getInt(path, def));
return getInt(path);
}
}
@@ -179,7 +123,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (List<Integer>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(config.getIntegerList(path)) : new ArrayList<>());
cache.put(path, has(path) ? new ArrayList<>(handle.getIntegerList(path)) : new ArrayList<>());
return getInts(path);
}
}
@@ -199,7 +143,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (boolean) cache.get(path);
} else {
cache.put(path, config.getBoolean(path));
cache.put(path, handle.getBoolean(path));
return getBool(path);
}
}
@@ -220,7 +164,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (List<Boolean>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(config.getBooleanList(path)) : new ArrayList<>());
cache.put(path, has(path) ? new ArrayList<>(handle.getBooleanList(path)) : new ArrayList<>());
return getBools(path);
}
}
@@ -241,7 +185,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (String) cache.get(path);
} else {
cache.put(path, StringUtils.translate(Objects.requireNonNull(config.getString(path, ""))));
cache.put(path, StringUtils.translate(Objects.requireNonNull(handle.getString(path, ""))));
return getString(path);
}
}
@@ -262,7 +206,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (List<String>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(config.getStringList(path)) : new ArrayList<>());
cache.put(path, has(path) ? new ArrayList<>(handle.getStringList(path)) : new ArrayList<>());
return getStrings(path);
}
}
@@ -282,7 +226,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (double) cache.get(path);
} else {
cache.put(path, config.getDouble(path));
cache.put(path, handle.getDouble(path));
return getDouble(path);
}
}
@@ -303,7 +247,7 @@ public abstract class AbstractUndefinedConfig<T extends ConfigurationSection> im
if (cache.containsKey(path)) {
return (List<Double>) cache.get(path);
} else {
cache.put(path, has(path) ? new ArrayList<>(config.getDoubleList(path)) : new ArrayList<>());
cache.put(path, has(path) ? new ArrayList<>(handle.getDoubleList(path)) : new ArrayList<>());
return getDoubles(path);
}
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.internal.config;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.configuration.InvalidConfigurationException;
@@ -16,7 +16,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
public abstract class AbstractConfig extends AbstractUndefinedConfig<YamlConfiguration> {
public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration> {
/**
* The physical config file, as stored on disk.
*/
@@ -27,7 +27,7 @@ public abstract class AbstractConfig extends AbstractUndefinedConfig<YamlConfigu
* Plugin handle.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin;
private final EcoPlugin plugin;
/**
* The full name of the config file (eg config.yml).
@@ -55,11 +55,10 @@ public abstract class AbstractConfig extends AbstractUndefinedConfig<YamlConfigu
* @param subDirectoryPath The subdirectory path.
* @param source The class that owns the resource.
*/
protected AbstractConfig(@NotNull final String configName,
@NotNull final AbstractEcoPlugin plugin,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source) {
super(configName);
protected LoadableYamlConfig(@NotNull final String configName,
@NotNull final EcoPlugin plugin,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source) {
this.plugin = plugin;
this.name = configName + ".yml";
this.source = source;
@@ -147,12 +146,11 @@ public abstract class AbstractConfig extends AbstractUndefinedConfig<YamlConfigu
}
/**
* Get config handle.
* Save the config.
*
* @return The config.
* @throws IOException If error in saving.
*/
@Deprecated
public YamlConfiguration getConfig() {
return (YamlConfiguration) super.config;
public void save() throws IOException {
this.getHandle().save(this.getConfigFile());
}
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.internal.config;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
@@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class AbstractUpdatableConfig extends AbstractConfig {
public abstract class UpdatableYamlConfig extends LoadableYamlConfig {
/**
* Whether keys not in the base config should be removed on update.
*/
@@ -31,12 +31,12 @@ public abstract class AbstractUpdatableConfig extends AbstractConfig {
* @param removeUnused Whether keys not present in the default config should be removed on update.
* @param updateBlacklist Substring of keys to not add/remove keys for.
*/
protected AbstractUpdatableConfig(@NotNull final String configName,
@NotNull final AbstractEcoPlugin plugin,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source,
final boolean removeUnused,
@NotNull final String... updateBlacklist) {
protected UpdatableYamlConfig(@NotNull final String configName,
@NotNull final EcoPlugin plugin,
@NotNull final String subDirectoryPath,
@NotNull final Class<?> source,
final boolean removeUnused,
@NotNull final String... updateBlacklist) {
super(configName, plugin, subDirectoryPath, source);
this.removeUnused = removeUnused;
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
@@ -53,33 +53,33 @@ public abstract class AbstractUpdatableConfig extends AbstractConfig {
public void update() {
super.clearCache();
try {
config.load(this.getConfigFile());
this.getHandle().load(this.getConfigFile());
YamlConfiguration newConfig = this.getConfigInJar();
if (newConfig.getKeys(true).equals(config.getKeys(true))) {
if (newConfig.getKeys(true).equals(this.getHandle().getKeys(true))) {
return;
}
newConfig.getKeys(true).forEach((s -> {
if (!config.getKeys(true).contains(s)) {
if (!this.getHandle().getKeys(true).contains(s)) {
if (updateBlacklist.stream().noneMatch(s::contains)) {
config.set(s, newConfig.get(s));
this.getHandle().set(s, newConfig.get(s));
}
}
}));
if (this.removeUnused) {
config.getKeys(true).forEach((s -> {
this.getHandle().getKeys(true).forEach((s -> {
if (!newConfig.getKeys(true).contains(s)) {
if (updateBlacklist.stream().noneMatch(s::contains)) {
config.set(s, null);
this.getHandle().set(s, null);
}
}
}));
}
config.save(this.getConfigFile());
this.getHandle().save(this.getConfigFile());
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.config.updating;
package com.willfp.eco.internal.config.updating;
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
import com.willfp.eco.util.config.updating.exceptions.InvalidUpdatableClassException;
import com.willfp.eco.util.config.updating.exceptions.InvalidUpdateMethodException;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException;
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
@@ -21,11 +21,11 @@ public class ConfigHandler extends PluginDependent {
private final Set<Class<?>> updatableClasses = new HashSet<>();
/**
* Creates a new config handler and links it to an {@link AbstractEcoPlugin}.
* Creates a new config handler and links it to an {@link EcoPlugin}.
*
* @param plugin The plugin to manage.
*/
public ConfigHandler(@NotNull final AbstractEcoPlugin plugin) {
public ConfigHandler(@NotNull final EcoPlugin plugin) {
super(plugin);
}

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.util.config.updating.exceptions;
package com.willfp.eco.internal.config.updating.exceptions;
import com.willfp.eco.util.config.updating.ConfigHandler;
import com.willfp.eco.internal.config.updating.ConfigHandler;
import org.jetbrains.annotations.NotNull;
public class InvalidUpdatableClassException extends RuntimeException {

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.config.updating.exceptions;
package com.willfp.eco.internal.config.updating.exceptions;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.internal.drops.impl;
import com.willfp.eco.internal.drops.AbstractDropQueue;
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
import com.willfp.eco.util.TelekinesisUtils;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.Bukkit;

View File

@@ -1,8 +1,8 @@
package com.willfp.eco.internal.bukkit.events;
package com.willfp.eco.internal.events;
import com.willfp.eco.util.bukkit.events.EventManager;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.events.EventManager;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
@@ -13,10 +13,10 @@ public class EcoEventManager extends PluginDependent implements EventManager {
/**
* Manager class for event management.
*
* @param plugin The {@link AbstractEcoPlugin} that this manages the events of.
* @param plugin The {@link EcoPlugin} that this manages the events of.
*/
@ApiStatus.Internal
public EcoEventManager(@NotNull final AbstractEcoPlugin plugin) {
public EcoEventManager(@NotNull final EcoPlugin plugin) {
super(plugin);
}

View File

@@ -1,11 +1,11 @@
package com.willfp.eco.internal.extensions;
import com.willfp.eco.util.extensions.Extension;
import com.willfp.eco.util.extensions.MalformedExtensionException;
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.extensions.Extension;
import com.willfp.eco.core.extensions.MalformedExtensionException;
import com.willfp.eco.core.extensions.ExtensionLoader;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
@@ -31,11 +31,11 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
private final Set<Extension> extensions = new HashSet<>();
/**
* Create a new extension loader and link it to a specific {@link AbstractEcoPlugin}.
* Create a new extension loader and link it to a specific {@link EcoPlugin}.
*
* @param plugin The plugin to manage
*/
public EcoExtensionLoader(@NotNull final AbstractEcoPlugin plugin) {
public EcoExtensionLoader(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@@ -63,7 +63,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
try {
loadExtension(extensionJar);
} catch (MalformedExtensionException e) {
this.getPlugin().getLog().error(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
this.getPlugin().getLogger().severe(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
}
}
}
@@ -99,13 +99,13 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
Validate.notNull(name, "Name is missing!");
Validate.notNull(version, "Version is missing!");
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
ExtensionMetadata metadata = new ExtensionMetadata(version, name);
Class<?> cls;
Object object = null;
try {
cls = cl.loadClass(mainClass);
object = cls.getConstructor(AbstractEcoPlugin.class).newInstance(this.getPlugin());
object = cls.getConstructor(EcoPlugin.class).newInstance(this.getPlugin());
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
@@ -129,15 +129,6 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
extensions.clear();
}
/**
* Unloads, then loads all extensions.
*/
@Override
public void reloadExtensions() {
unloadExtensions();
loadExtensions();
}
/**
* Returns all loaded extensions.
*

View File

@@ -0,0 +1,32 @@
package com.willfp.eco.internal.extensions;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class ExtensionMetadata {
/**
* The version of the extension.
*/
@NotNull
@Getter
private final String version;
/**
* The extension's name.
*/
@NotNull
@Getter
private final String name;
/**
* Create a new extension metadata.
*
* @param version The version for the extension to be.
* @param name The name of the extension.
*/
public ExtensionMetadata(@NotNull final String version,
@NotNull final String name) {
this.version = version;
this.name = name;
}
}

View File

@@ -1,26 +1,28 @@
package com.willfp.eco.util.bukkit.meta;
package com.willfp.eco.internal.factory;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.factory.MetadataValueFactory;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
public class MetadataValueFactory extends PluginDependent {
public class EcoMetadataValueFactory extends PluginDependent implements MetadataValueFactory {
/**
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link AbstractEcoPlugin}.
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link EcoPlugin}.
*
* @param plugin The plugin that this factory creates values for.
*/
public MetadataValueFactory(@NotNull final AbstractEcoPlugin plugin) {
public EcoMetadataValueFactory(@NotNull final EcoPlugin plugin) {
super(plugin);
}
/**
* Create an {@link FixedMetadataValue} associated with an {@link AbstractEcoPlugin} with a specified value.
* Create an {@link FixedMetadataValue} associated with an {@link EcoPlugin} with a specified value.
*
* @param value The value of meta key.
* @return The created {@link FixedMetadataValue}.
*/
@Override
public FixedMetadataValue create(@NotNull final Object value) {
return new FixedMetadataValue(this.getPlugin(), value);
}

View File

@@ -0,0 +1,22 @@
package com.willfp.eco.internal.factory;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.factory.NamespacedKeyFactory;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
public class EcoNamespacedKeyFactory extends PluginDependent implements NamespacedKeyFactory {
/**
* Factory class to produce {@link NamespacedKey}s associated with an {@link EcoPlugin}.
*
* @param plugin The plugin that this factory creates keys for.
*/
public EcoNamespacedKeyFactory(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@Override
public NamespacedKey create(@NotNull final String key) {
return new NamespacedKey(this.getPlugin(), key);
}
}

View File

@@ -0,0 +1,31 @@
package com.willfp.eco.internal.factory;
import com.willfp.eco.core.factory.RunnableFactory;
import com.willfp.eco.core.scheduling.RunnableTask;
import com.willfp.eco.internal.scheduling.EcoRunnableTask;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
public class EcoRunnableFactory extends PluginDependent implements RunnableFactory {
/**
* Factory class to produce {@link RunnableTask}s associated with an {@link EcoPlugin}.
*
* @param plugin The plugin that this factory creates runnables for.
*/
public EcoRunnableFactory(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@Override
public RunnableTask create(@NotNull final Consumer<RunnableTask> consumer) {
return new EcoRunnableTask(this.getPlugin()) {
@Override
public void run() {
consumer.accept(this);
}
};
}
}

View File

@@ -1,8 +1,8 @@
package com.willfp.eco.util.integrations.placeholder.plugins;
package com.willfp.eco.internal.integrations;
import com.willfp.eco.util.integrations.placeholder.PlaceholderIntegration;
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
@@ -13,14 +13,14 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
/**
* The linked plugin.
*/
private final AbstractEcoPlugin plugin;
private final EcoPlugin plugin;
/**
* Create a new PlaceholderAPI integration.
*
* @param plugin The plugin to manage placeholders for.
*/
public PlaceholderIntegrationPAPI(@NotNull final AbstractEcoPlugin plugin) {
public PlaceholderIntegrationPAPI(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
@@ -36,7 +36,7 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
@Override
public @NotNull String getAuthor() {
return "Auxilor";
return String.join(", ", plugin.getDescription().getAuthors());
}
@Override

View File

@@ -0,0 +1,32 @@
package com.willfp.eco.internal.logging;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.logging.Level;
import java.util.logging.Logger;
public class EcoLogger extends Logger {
public EcoLogger(@NotNull final EcoPlugin plugin) {
super(plugin.getName(), (String) null);
String prefix = plugin.getDescription().getPrefix();
this.setParent(plugin.getServer().getLogger());
this.setLevel(Level.ALL);
}
@Override
public void info(@NotNull final String msg) {
super.info(StringUtils.translate(msg));
}
@Override
public void warning(@NotNull final String msg) {
super.warning(StringUtils.translate(msg));
}
@Override
public void severe(@NotNull final String msg) {
super.severe(StringUtils.translate(msg));
}
}

View File

@@ -0,0 +1,73 @@
package com.willfp.eco.internal.scheduling;
import com.willfp.eco.internal.factory.EcoRunnableFactory;
import com.willfp.eco.core.scheduling.RunnableTask;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public abstract class EcoRunnableTask extends BukkitRunnable implements RunnableTask {
/**
* The linked {@link EcoPlugin} to associate runnables with.
*/
private final EcoPlugin plugin;
/**
* Creates a new {@link EcoRunnableTask}.
* <p>
* Cannot be instantiated normally, use {@link EcoRunnableFactory}.
*
* @param plugin The {@link EcoPlugin} to associate runnables with.
*/
@ApiStatus.Internal
public EcoRunnableTask(@NotNull final EcoPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the {@link EcoPlugin} that created this runnable.
*
* @return The linked plugin.
*/
protected final EcoPlugin getPlugin() {
return this.plugin;
}
@Override
@NotNull
public final synchronized BukkitTask runTask() {
return super.runTask(plugin);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskAsynchronously() {
return super.runTaskAsynchronously(plugin);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskLater(final long delay) {
return super.runTaskLater(plugin, delay);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskLaterAsynchronously(final long delay) {
return super.runTaskLaterAsynchronously(plugin, delay);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskTimer(final long delay, final long period) {
return super.runTaskTimer(plugin, delay, period);
}
@Override
@NotNull
public final synchronized BukkitTask runTaskTimerAsynchronously(final long delay, final long period) {
return super.runTaskTimerAsynchronously(plugin, delay, period);
}
}

View File

@@ -1,8 +1,8 @@
package com.willfp.eco.internal.bukkit.scheduling;
package com.willfp.eco.internal.scheduling;
import com.willfp.eco.util.bukkit.scheduling.Scheduler;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.core.scheduling.Scheduler;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.EcoPlugin;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.ApiStatus;
@@ -10,12 +10,12 @@ import org.jetbrains.annotations.NotNull;
public class EcoScheduler extends PluginDependent implements Scheduler {
/**
* Create a scheduler to manage the tasks of an {@link AbstractEcoPlugin}.
* Create a scheduler to manage the tasks of an {@link EcoPlugin}.
*
* @param plugin The plugin to manage.
*/
@ApiStatus.Internal
public EcoScheduler(@NotNull final AbstractEcoPlugin plugin) {
public EcoScheduler(@NotNull final EcoPlugin plugin) {
super(plugin);
}
@@ -100,7 +100,7 @@ public class EcoScheduler extends PluginDependent implements Scheduler {
}
/**
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
* Cancel all running tasks from the linked {@link EcoPlugin}.
*/
@Override
public void cancelAll() {

View File

@@ -15,7 +15,7 @@ import java.util.Set;
import java.util.function.BiConsumer;
@UtilityClass
public class BlockUtils {
public class BlockUtils {
/**
* If the meta set function has been set.
*/
@@ -37,6 +37,15 @@ public class BlockUtils {
if (blocks.size() > limit || blocks.size() > 2500) {
return blocks;
}
}
}
// Running twice to get more spherical shape.
for (BlockFace face : BlockFace.values()) {
Block block = start.getRelative(face);
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
if (blocks.size() > limit || blocks.size() > 2500) {
return blocks;
}
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
}
}
@@ -49,7 +58,6 @@ public class BlockUtils {
* @param start The initial block.
* @param allowedMaterials A list of all valid {@link Material}s.
* @param limit The maximum size of vein to return.
*
* @return A set of all {@link Block}s.
*/
public Set<Block> getVein(@NotNull final Block start,

View File

@@ -10,6 +10,21 @@ import java.util.concurrent.ThreadLocalRandom;
@UtilityClass
public class NumberUtils {
/**
* Precision.
*/
private static final int FAST_TRIG_PRECISION = 100;
/**
* Modulus.
*/
private static final int FAST_TRIG_MODULUS = 360 * FAST_TRIG_PRECISION;
/**
* Sin lookup table.
*/
private static final double[] SIN_LOOKUP = new double[FAST_TRIG_MODULUS];
/**
* Set of roman numerals to look up.
*/
@@ -29,6 +44,34 @@ public class NumberUtils {
NUMERALS.put(5, "V");
NUMERALS.put(4, "IV");
NUMERALS.put(1, "I");
for (int i = 0; i < SIN_LOOKUP.length; i++) {
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180));
}
}
private static double sinLookup(final int a) {
return a >= 0 ? SIN_LOOKUP[a % FAST_TRIG_MODULUS] : -SIN_LOOKUP[-a % FAST_TRIG_MODULUS];
}
/**
* Get the sin of a number.
*
* @param a The number.
* @return The sin.
*/
public static double fastSin(final double a) {
return sinLookup((int) (a * FAST_TRIG_PRECISION + 0.5f));
}
/**
* Get the cosine of a number.
*
* @param a The number.
* @return The cosine.
*/
public static double fastCos(final double a) {
return sinLookup((int) ((a + 90f) * FAST_TRIG_PRECISION + 0.5f));
}
/**

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.util;
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
import com.willfp.eco.util.optional.Prerequisite;
import com.google.common.collect.ImmutableList;
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
@@ -21,19 +21,23 @@ import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
@UtilityClass
public class StringUtils {
/**
* Regex for gradients.
* Regexes for gradients.
*/
private static final Pattern GRADIENT_REGEX = Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>");
private static final List<Pattern> GRADIENT_PATTERNS = new ImmutableList.Builder<Pattern>()
.add(Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>"))
.add(Pattern.compile("<G:([0-9A-Fa-f]{6})>(.*?)</G:([0-9A-Fa-f]{6})>"))
.add(Pattern.compile("<#:([0-9A-Fa-f]{6})>(.*?)</#:([0-9A-Fa-f]{6})>"))
.add(Pattern.compile("\\{#:([0-9A-Fa-f]{6})}(.*?)\\{/#:([0-9A-Fa-f]{6})}"))
.build();
/**
* Regex for hex codes.
* Regexes for hex codes.
*/
private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
/**
* Regex for hex codes.
*/
private static final Pattern ALT_HEX_PATTERN = Pattern.compile("\\{#" + "([A-Fa-f0-9]{6})" + "}");
private static final List<Pattern> HEX_PATTERNS = new ImmutableList.Builder<Pattern>()
.add(Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + ""))
.add(Pattern.compile("\\{#" + "([A-Fa-f0-9]{6})" + "}"))
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
.build();
/**
* Translate a string - converts Placeholders and Color codes.
@@ -45,9 +49,7 @@ public class StringUtils {
public String translate(@NotNull final String message,
@Nullable final Player player) {
String processedMessage = message;
if (Prerequisite.MINIMUM_1_16.isMet()) {
processedMessage = translateGradients(processedMessage);
}
processedMessage = translateGradients(processedMessage);
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
processedMessage = translateHexColorCodes(processedMessage);
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
@@ -67,20 +69,15 @@ public class StringUtils {
private static String translateHexColorCodes(@NotNull final String message) {
String processedMessage = message;
for (HexParseMode parseMode : HexParseMode.values()) {
processedMessage = translateHexColorCodes(processedMessage, parseMode);
for (Pattern pattern : HEX_PATTERNS) {
processedMessage = translateHexColorCodes(processedMessage, pattern);
}
return processedMessage;
}
private static String translateHexColorCodes(@NotNull final String message,
@NotNull final HexParseMode mode) {
Matcher matcher;
if (mode == HexParseMode.CMI) {
matcher = ALT_HEX_PATTERN.matcher(message);
} else {
matcher = HEX_PATTERN.matcher(message);
}
@NotNull final Pattern pattern) {
Matcher matcher = pattern.matcher(message);
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
while (matcher.find()) {
@@ -171,12 +168,14 @@ public class StringUtils {
*/
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))));
for (Pattern pattern : GRADIENT_PATTERNS) {
Matcher matcher = pattern.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))));
}
}
return processedString;
}
@@ -221,9 +220,4 @@ public class StringUtils {
}
return string;
}
private enum HexParseMode {
CMI,
NORMAL
}
}

View File

@@ -2,7 +2,6 @@ package com.willfp.eco.util;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.willfp.eco.util.optional.Prerequisite;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -45,10 +44,10 @@ public class TeamUtils {
Team team;
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EE-" + color.name())) {
team = SCOREBOARD.registerNewTeam("EE-" + color.name());
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EC-" + color.name())) {
team = SCOREBOARD.registerNewTeam("EC-" + color.name());
} else {
team = SCOREBOARD.getTeam("EE-" + color.name());
team = SCOREBOARD.getTeam("EC-" + color.name());
}
assert team != null;
team.setColor(color);
@@ -80,9 +79,6 @@ public class TeamUtils {
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
if (Prerequisite.MINIMUM_1_16.isMet()) {
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
}
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.telekinesis;
package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;

View File

@@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@UtilityClass
@@ -78,7 +79,7 @@ public class VectorUtils {
return cached;
}
ArrayList<Vector> circleVecs = new ArrayList<>();
List<Vector> vectors = new ArrayList<>();
double xoffset = -radius;
double zoffset = -radius;
@@ -86,7 +87,7 @@ public class VectorUtils {
while (zoffset <= radius) {
while (xoffset <= radius) {
if (Math.round(Math.sqrt((xoffset * xoffset) + (zoffset * zoffset))) <= radius) {
circleVecs.add(new Vector(xoffset, 0, zoffset));
vectors.add(new Vector(xoffset, 0, zoffset));
} else {
xoffset++;
continue;
@@ -97,7 +98,7 @@ public class VectorUtils {
zoffset++;
}
Vector[] result = circleVecs.toArray(new Vector[0]);
Vector[] result = vectors.toArray(new Vector[0]);
CIRCLE_CACHE.put(radius, result);
return result;
}
@@ -109,21 +110,21 @@ public class VectorUtils {
* @return An array of {@link Vector}s.
*/
public Vector[] getSquare(final int radius) {
ArrayList<Vector> circleVecs = new ArrayList<>();
List<Vector> vectors = new ArrayList<>();
int xoffset = -radius;
int zoffset = -radius;
while (zoffset <= radius) {
while (xoffset <= radius) {
circleVecs.add(new Vector(xoffset, 0, zoffset));
vectors.add(new Vector(xoffset, 0, zoffset));
xoffset++;
}
xoffset = -radius;
zoffset++;
}
return circleVecs.toArray(new Vector[0]);
return vectors.toArray(new Vector[0]);
}
/**
@@ -133,16 +134,16 @@ public class VectorUtils {
* @return An array of {@link Vector}s.
*/
public Vector[] getCube(final int radius) {
ArrayList<Vector> cubeVecs = new ArrayList<>();
List<Vector> vectors = new ArrayList<>();
for (int y = -radius; y <= radius; y++) {
for (int z = -radius; z <= radius; z++) {
for (int x = -radius; x <= radius; x++) {
cubeVecs.add(new Vector(x, y, z));
vectors.add(new Vector(x, y, z));
}
}
}
return cubeVecs.toArray(new Vector[0]);
return vectors.toArray(new Vector[0]);
}
}

View File

@@ -3,6 +3,6 @@ version rootProject.version
subprojects {
dependencies {
compileOnly project(":eco-util")
compileOnly project(":eco-api")
}
}

View File

@@ -1,6 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT'
}

View File

@@ -1,19 +0,0 @@
package com.willfp.eco.proxy.v1_15_R1;
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
import net.minecraft.server.v1_15_R1.MinecraftKey;
import net.minecraft.server.v1_15_R1.PacketPlayOutAutoRecipe;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
public final class AutoCraft implements AutoCraftProxy {
@Override
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
Field fKey = recipePacket.getClass().getDeclaredField("b");
fKey.setAccessible(true);
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
}
}

View File

@@ -1,16 +0,0 @@
package com.willfp.eco.proxy.v1_15_R1;
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
import net.minecraft.server.v1_15_R1.BlockPosition;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public final class BlockBreak implements BlockBreakProxy {
@Override
public void breakBlock(@NotNull final Player player,
@NotNull final Block block) {
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
}
}

View File

@@ -1,11 +0,0 @@
package com.willfp.eco.proxy.v1_15_R1;
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
import org.jetbrains.annotations.NotNull;
public final class ChatComponent implements ChatComponentProxy {
@Override
public Object modifyComponent(@NotNull final Object object) {
return object;
}
}

View File

@@ -1,15 +0,0 @@
package com.willfp.eco.proxy.v1_15_R1;
import com.willfp.eco.proxy.proxies.CooldownProxy;
import net.minecraft.server.v1_15_R1.EntityHuman;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public final class Cooldown implements CooldownProxy {
@Override
public double getAttackCooldown(@NotNull final Player player) {
EntityHuman entityHuman = ((CraftPlayer) player).getHandle();
return entityHuman.s(0);
}
}

Some files were not shown because too many files have changed in this diff Show More