Compare commits
87 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
726f4a44c4 | ||
|
|
eafae209a6 | ||
|
|
04c450b46a | ||
|
|
d4e1f58f2a | ||
|
|
b0806b934b | ||
|
|
a21ecfbdde | ||
|
|
f3a6861bc6 | ||
|
|
eaa295e6a3 | ||
|
|
399387eca1 | ||
|
|
272f551aae | ||
|
|
d8c5fc0959 | ||
|
|
d1ca106d01 | ||
|
|
99f5174e28 | ||
|
|
d9f4aee384 | ||
|
|
c2aae8c2eb | ||
|
|
52061b7b51 | ||
|
|
762969c172 | ||
|
|
62d5cf885f | ||
|
|
1e70a9fdea | ||
|
|
ec8a65b4f8 | ||
|
|
a163219372 | ||
|
|
4d6e097f8f | ||
|
|
497adbe7b1 | ||
|
|
78907412b2 | ||
|
|
d6bec5d88b | ||
|
|
aab1f31ca0 | ||
|
|
5ea586eaae | ||
|
|
2ffc293211 | ||
|
|
88bedef420 | ||
|
|
dac5ffce9a | ||
|
|
d641adadea | ||
|
|
46269354c6 | ||
|
|
2d93465d1d | ||
|
|
484d4dde75 | ||
|
|
5e9a408704 | ||
|
|
f1b113f435 | ||
|
|
5d553d725c | ||
|
|
a3be846083 | ||
|
|
54e0b3f482 | ||
|
|
93794fe454 | ||
|
|
7f4a0c800e | ||
|
|
853864f6f0 | ||
|
|
0cb6e8f669 | ||
|
|
d30f657eec | ||
|
|
d60ecdd340 | ||
|
|
07310df68a | ||
|
|
5c91aa220a | ||
|
|
756a76057a | ||
|
|
b6f27ee232 | ||
|
|
74ca2e82ef | ||
|
|
4039439fda | ||
|
|
7dac671690 | ||
|
|
411d517a9a | ||
|
|
0d84141116 | ||
|
|
6bfd5bd153 | ||
|
|
b7d421e1a8 | ||
|
|
2e9d811d3f | ||
|
|
672b295917 | ||
|
|
60a83478e8 | ||
|
|
c880a476d4 | ||
|
|
692305d595 | ||
|
|
9d4cc2961c | ||
|
|
358b389875 | ||
|
|
7fa25c2500 | ||
|
|
91c58c4a53 | ||
|
|
4ccee91c64 | ||
|
|
eef87342a1 | ||
|
|
efc70ea7a8 | ||
|
|
de38299264 | ||
|
|
bc94f43299 | ||
|
|
ed705cc577 | ||
|
|
93410490c5 | ||
|
|
33914ac284 | ||
|
|
2acf2ee687 | ||
|
|
0470552168 | ||
|
|
3e724eea18 | ||
|
|
33ba5c9d31 | ||
|
|
94ab094952 | ||
|
|
58f5d3f352 | ||
|
|
912872e791 | ||
|
|
7a65e6e821 | ||
|
|
3f446f6072 | ||
|
|
50f57abd6c | ||
|
|
2c5eae6c6c | ||
|
|
1e3e54b8c5 | ||
|
|
0ce9119a94 | ||
|
|
bf76ba9f5a |
@@ -86,6 +86,11 @@ allprojects {
|
||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
@@ -94,5 +99,4 @@ allprojects {
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = findProperty("version")
|
||||
java.sourceCompatibility = JavaVersion.VERSION_16
|
||||
version = findProperty("version")
|
||||
@@ -1,15 +1,29 @@
|
||||
plugins {
|
||||
id 'com.github.johnrengelman.shadow'
|
||||
}
|
||||
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot:1.17-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'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.7'
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
build.dependsOn publishToMavenLocal
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) {
|
||||
from components.java
|
||||
artifactId 'eco'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,11 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
onSend(event.getPacket(), event.getPlayer(), event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final EcoPlugin getPlugin() {
|
||||
return (EcoPlugin) super.getPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the packet adapter with ProtocolLib.
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.impl.PluginCommand;
|
||||
import com.willfp.eco.core.config.ConfigHandler;
|
||||
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;
|
||||
@@ -14,8 +15,10 @@ 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.Internals;
|
||||
import com.willfp.eco.internal.UpdateChecker;
|
||||
import com.willfp.eco.internal.arrows.ArrowDataListener;
|
||||
import com.willfp.eco.internal.config.updating.EcoConfigHandler;
|
||||
import com.willfp.eco.internal.events.EcoEventManager;
|
||||
import com.willfp.eco.internal.extensions.EcoExtensionLoader;
|
||||
import com.willfp.eco.internal.factory.EcoMetadataValueFactory;
|
||||
@@ -25,9 +28,11 @@ 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.commons.lang.Validate;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@@ -42,6 +47,7 @@ import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"deprecation", "DeprecatedIsStillUsed"})
|
||||
public abstract class EcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Loaded eco plugins.
|
||||
@@ -50,8 +56,11 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* The name of the plugin.
|
||||
*
|
||||
* @deprecated Pointless, use getName instead.
|
||||
*/
|
||||
@Getter
|
||||
@Deprecated
|
||||
private final String pluginName;
|
||||
|
||||
/**
|
||||
@@ -162,6 +171,100 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private boolean outdated = false;
|
||||
|
||||
/**
|
||||
* If the plugin supports extensions.
|
||||
*/
|
||||
@Getter
|
||||
private final boolean supportingExtensions;
|
||||
|
||||
/**
|
||||
* Create a new plugin without a specified color, proxy support, spigot, or bStats.
|
||||
*/
|
||||
protected EcoPlugin() {
|
||||
this("&f");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy support, spigot, or bStats.
|
||||
*
|
||||
* @param color The color.
|
||||
*/
|
||||
protected EcoPlugin(@NotNull final String color) {
|
||||
this("", color);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new plugin unlinked to spigot and bStats.
|
||||
*
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
*/
|
||||
protected EcoPlugin(@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this(0, 0, proxyPackage, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy or extension support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String color) {
|
||||
this(resourceId, bStatsId, "", color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this(resourceId, bStatsId, "", color, supportingExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without extension support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this(resourceId, bStatsId, proxyPackage, color, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this("", resourceId, bStatsId, proxyPackage, color, supportingExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
*
|
||||
@@ -170,17 +273,43 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @deprecated pluginName is redundant.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
protected EcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this.pluginName = pluginName;
|
||||
this(pluginName, resourceId, bStatsId, proxyPackage, color, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
*
|
||||
* @param pluginName The name of the plugin.
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
* @deprecated pluginName is redundant.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
protected EcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this.pluginName = this.getName();
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
this.supportingExtensions = supportingExtensions;
|
||||
|
||||
this.scheduler = new EcoScheduler(this);
|
||||
this.eventManager = new EcoEventManager(this);
|
||||
@@ -188,7 +317,7 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
this.metadataValueFactory = new EcoMetadataValueFactory(this);
|
||||
this.runnableFactory = new EcoRunnableFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
this.configHandler = new EcoConfigHandler(this);
|
||||
this.logger = new EcoLogger(this);
|
||||
|
||||
this.langYml = new LangYml(this);
|
||||
@@ -205,24 +334,38 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
super.onEnable();
|
||||
|
||||
this.getLogger().info("");
|
||||
this.getLogger().info("Loading " + this.color + this.pluginName);
|
||||
this.getLogger().info("Loading " + this.getColor() + this.getName());
|
||||
|
||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||
|
||||
new UpdateChecker(this).getVersion(version -> {
|
||||
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
|
||||
DefaultArtifactVersion mostRecentVersion = new DefaultArtifactVersion(version);
|
||||
if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) {
|
||||
this.outdated = true;
|
||||
this.getScheduler().runTimer(() -> {
|
||||
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);
|
||||
}
|
||||
});
|
||||
if (this.getResourceId() != 0) {
|
||||
new UpdateChecker(this).getVersion(version -> {
|
||||
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
|
||||
DefaultArtifactVersion mostRecentVersion = new DefaultArtifactVersion(version);
|
||||
if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) {
|
||||
this.outdated = true;
|
||||
this.getScheduler().runTimer(() -> {
|
||||
this.getLogger().info("&c " + this.getName() + " 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
new Metrics(this, this.bStatsId);
|
||||
DefaultArtifactVersion runningVersion = new DefaultArtifactVersion(Internals.getInstance().getPlugin().getDescription().getVersion());
|
||||
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(this.getMinimumEcoVersion());
|
||||
if (!(runningVersion.compareTo(requiredVersion) > 0 || runningVersion.equals(requiredVersion))) {
|
||||
this.getLogger().severe("You are running an outdated version of eco!");
|
||||
this.getLogger().severe("You must be on at least" + this.getMinimumEcoVersion());
|
||||
this.getLogger().severe("Download the newest version here:");
|
||||
this.getLogger().severe("https://polymart.org/download/773/recent/JSpprMspkuyecf5y1wQ2Jn8OoLQSQ_IW");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
if (this.getBStatsId() != 0) {
|
||||
new Metrics(this, this.getBStatsId());
|
||||
}
|
||||
|
||||
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
|
||||
|
||||
@@ -253,11 +396,23 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener));
|
||||
|
||||
this.getCommands().forEach(AbstractCommand::register);
|
||||
this.getPluginCommands().forEach(PluginCommand::register);
|
||||
|
||||
this.getScheduler().runLater(this::afterLoad, 1);
|
||||
|
||||
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
|
||||
|
||||
if (this.isSupportingExtensions()) {
|
||||
this.getExtensionLoader().loadExtensions();
|
||||
|
||||
if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) {
|
||||
this.getLogger().info("&cNo extensions found");
|
||||
} else {
|
||||
this.getLogger().info("Extensions Loaded:");
|
||||
this.getExtensionLoader().getLoadedExtensions().forEach(extension -> this.getLogger().info("- " + extension.getName() + " v" + extension.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
this.enable();
|
||||
|
||||
this.getLogger().info("");
|
||||
@@ -272,8 +427,13 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
|
||||
this.getEventManager().unregisterAllListeners();
|
||||
this.getScheduler().cancelAll();
|
||||
this.getConfigHandler().saveAllConfigs();
|
||||
|
||||
this.disable();
|
||||
|
||||
if (this.isSupportingExtensions()) {
|
||||
this.getExtensionLoader().unloadExtensions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,8 +486,7 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
* Default code to be executed on plugin reload.
|
||||
*/
|
||||
public final void reload() {
|
||||
this.getConfigYml().update();
|
||||
this.getLangYml().update();
|
||||
this.getConfigHandler().updateConfigs();
|
||||
|
||||
this.getConfigHandler().callUpdate();
|
||||
this.getConfigHandler().callUpdate(); // Call twice to fix issues
|
||||
@@ -338,42 +497,79 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on enable.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public abstract void enable();
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on disable.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public abstract void disable();
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on load.
|
||||
* <p>
|
||||
* This is executed before enabling.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public abstract void load();
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on reload.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public abstract void onReload();
|
||||
public void onReload() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed after the server is up.
|
||||
* <p>
|
||||
* Override when needed.
|
||||
*/
|
||||
public abstract void postLoad();
|
||||
public void postLoad() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific integrations to be tested and loaded.
|
||||
*
|
||||
* @return A list of integrations.
|
||||
*/
|
||||
public abstract List<IntegrationLoader> getIntegrationLoaders();
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* The command to be registered.
|
||||
* The commands to be registered.
|
||||
*
|
||||
* @return A list of commands.
|
||||
* @deprecated Use {@link this#getPluginCommands()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* The commands to be registered.
|
||||
*
|
||||
* @return A list of commands.
|
||||
*/
|
||||
public abstract List<AbstractCommand> getCommands();
|
||||
public List<PluginCommand> getPluginCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* ProtocolLib packet adapters to be registered.
|
||||
@@ -382,7 +578,9 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
*
|
||||
* @return A list of packet adapters.
|
||||
*/
|
||||
public abstract List<AbstractPacketAdapter> getPacketAdapters();
|
||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* All listeners to be registered.
|
||||
@@ -396,7 +594,9 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
*
|
||||
* @return A list of all updatable classes.
|
||||
*/
|
||||
public abstract List<Class<?>> getUpdatableClasses();
|
||||
public List<Class<?>> getUpdatableClasses() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the display module for the plugin.
|
||||
@@ -405,12 +605,86 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
*/
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
Validate.isTrue(
|
||||
this.getDisplayModule() == null,
|
||||
"Display module exists!"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum version of eco to use the plugin.
|
||||
*
|
||||
* @return The version.
|
||||
*/
|
||||
protected String getMinimumEcoVersion() {
|
||||
return "5.0.0";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin's logger.
|
||||
*
|
||||
* @return The logger.
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unwrapped config.
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @return The bukkit config.
|
||||
* @deprecated Use {@link EcoPlugin#getConfigYml()} instead.
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
@Deprecated
|
||||
public final FileConfiguration getConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
return this.getConfigYml().getHandle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @deprecated Use eco config system.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void saveConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
super.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @deprecated Use eco config system.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void saveDefaultConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
super.saveDefaultConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Does not use eco config system, don't use.
|
||||
*
|
||||
* @deprecated Use eco config system.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public final void reloadConfig() {
|
||||
this.getLogger().warning("Call to default config method in eco plugin!");
|
||||
|
||||
super.reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@ import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class PluginDependent {
|
||||
public abstract class PluginDependent<T extends EcoPlugin> {
|
||||
/**
|
||||
* The {@link EcoPlugin} that is stored.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EcoPlugin plugin;
|
||||
private final T plugin;
|
||||
|
||||
/**
|
||||
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
protected PluginDependent(@NotNull final EcoPlugin plugin) {
|
||||
protected PluginDependent(@NotNull final T plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,22 @@ public class Prerequisite {
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running 1.17
|
||||
* Requires the server to be running 1.17.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Prerequisite v1_17 = new Prerequisite(
|
||||
() -> ProxyConstants.NMS_VERSION.contains("17"),
|
||||
"Requires server to be running 1.17+"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running 1.17.
|
||||
*/
|
||||
public static final Prerequisite HAS_1_17 = new Prerequisite(
|
||||
() -> ProxyConstants.NMS_VERSION.contains("17"),
|
||||
"Requires server to be running 1.17+"
|
||||
);
|
||||
|
||||
/**
|
||||
* If the necessary prerequisite condition has been met.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor {
|
||||
@Deprecated
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
public abstract class AbstractCommand extends PluginDependent<EcoPlugin> implements CommandExecutor {
|
||||
/**
|
||||
* The name of the command
|
||||
* <p>
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public abstract class AbstractTabCompleter implements TabCompleter {
|
||||
/**
|
||||
* The {@link AbstractCommand} that is tab-completed.
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CommandBase {
|
||||
/**
|
||||
* Get command name.
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get command permission.
|
||||
*
|
||||
* @return The permission.
|
||||
*/
|
||||
String getPermission();
|
||||
|
||||
/**
|
||||
* If only players can execute the command.
|
||||
*
|
||||
* @return If true.
|
||||
*/
|
||||
boolean isPlayersOnly();
|
||||
|
||||
/**
|
||||
* Add a subcommand to the command.
|
||||
*
|
||||
* @param command The subcommand.
|
||||
* @return The parent command.
|
||||
*/
|
||||
CommandBase addSubcommand(@NotNull CommandBase command);
|
||||
|
||||
/**
|
||||
* Get the handler.
|
||||
*
|
||||
* @return The handler.
|
||||
*/
|
||||
CommandHandler getHandler();
|
||||
|
||||
/**
|
||||
* Get the tab completer.
|
||||
*
|
||||
* @return The tab completer.
|
||||
*/
|
||||
TabCompleteHandler getTabCompleter();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CommandHandler {
|
||||
/**
|
||||
* The code to be called on execution.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
*/
|
||||
void onExecute(@NotNull CommandSender sender,
|
||||
@NotNull List<String> args);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TabCompleteHandler {
|
||||
/**
|
||||
* Handle Tab Completion.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
* @return The tab completion results.
|
||||
*/
|
||||
List<String> tabComplete(@NotNull CommandSender sender,
|
||||
@NotNull List<String> args);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.willfp.eco.core.command.impl;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.commands.HandledCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PluginCommand extends HandledCommand implements CommandExecutor, TabCompleter {
|
||||
/**
|
||||
* Create a new command.
|
||||
* <p>
|
||||
* The command will not be registered until {@link this#register()} is called.
|
||||
* <p>
|
||||
* The name cannot be the same as an existing command as this will conflict.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @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 PluginCommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
super(plugin, name, permission, playersOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the command with the server,
|
||||
* <p>
|
||||
* Requires the command name to exist, defined in plugin.yml.
|
||||
*/
|
||||
public final void register() {
|
||||
org.bukkit.command.PluginCommand command = Bukkit.getPluginCommand(this.getName());
|
||||
assert command != null;
|
||||
command.setExecutor(this);
|
||||
command.setTabCompleter(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation used to clean up boilerplate.
|
||||
* Used for parity with {@link CommandExecutor#onCommand(CommandSender, Command, String, String[])}.
|
||||
*
|
||||
* @param sender The executor of the 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 EcoPlugin}
|
||||
*/
|
||||
@Override
|
||||
public final boolean onCommand(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command,
|
||||
@NotNull final String label,
|
||||
@NotNull final String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(this.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.handle(sender, args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation used to clean up boilerplate.
|
||||
* Used for parity with {@link TabCompleter#onTabComplete(CommandSender, Command, String, String[])}.
|
||||
*
|
||||
* @param sender The executor of the 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 The list of tab-completions.
|
||||
*/
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull final CommandSender sender,
|
||||
@NotNull final Command command,
|
||||
@NotNull final String label,
|
||||
@NotNull final String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(this.getName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.handleTabCompletion(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.willfp.eco.core.command.impl;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandBase;
|
||||
import com.willfp.eco.internal.commands.HandledCommand;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Subcommand extends HandledCommand {
|
||||
/**
|
||||
* Create subcommand.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param name The subcommand name.
|
||||
* @param permission The subcommand permission.
|
||||
* @param playersOnly If the subcommand only works on players.
|
||||
*/
|
||||
protected Subcommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
super(plugin, name, permission, playersOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create subcommand.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param name The name of the subcommand.
|
||||
* @param parent The parent command.
|
||||
*/
|
||||
protected Subcommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final CommandBase parent) {
|
||||
super(plugin, name, parent.getPermission(), parent.isPlayersOnly());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.UpdatableYamlConfig;
|
||||
import com.willfp.eco.internal.config.yaml.UpdatableYamlConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -11,6 +11,13 @@ public interface Config {
|
||||
*/
|
||||
void clearCache();
|
||||
|
||||
/**
|
||||
* Convert the config into readable text.
|
||||
*
|
||||
* @return The plaintext.
|
||||
*/
|
||||
String toPlaintext();
|
||||
|
||||
/**
|
||||
* Get if the config contains a key.
|
||||
*
|
||||
@@ -42,7 +49,7 @@ public interface Config {
|
||||
* Set an object in config.
|
||||
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#set(String, Object)}
|
||||
*
|
||||
* @param path The path.
|
||||
* @param path The path.
|
||||
* @param object The object.
|
||||
*/
|
||||
void set(@NotNull String path,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ConfigHandler {
|
||||
/**
|
||||
* Invoke all update methods.
|
||||
*/
|
||||
void callUpdate();
|
||||
|
||||
/**
|
||||
* Register an updatable class.
|
||||
*
|
||||
* @param updatableClass The class with an update method.
|
||||
*/
|
||||
void registerUpdatableClass(@NotNull Class<?> updatableClass);
|
||||
|
||||
/**
|
||||
* Save all configs.
|
||||
*/
|
||||
void saveAllConfigs();
|
||||
|
||||
/**
|
||||
* Update all updatable configs.
|
||||
*/
|
||||
void updateConfigs();
|
||||
|
||||
/**
|
||||
* Add new config to be saved.
|
||||
*
|
||||
* @param config The config.
|
||||
*/
|
||||
void addConfig(@NotNull LoadableConfig config);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.UpdatableYamlConfig;
|
||||
import com.willfp.eco.internal.config.yaml.UpdatableYamlConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface JSONConfig extends Config {
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
List<JSONConfig> getSubsections(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of subsections from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.config.json.LoadableJsonConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class JsonStaticBaseConfig extends LoadableJsonConfig {
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.json, lang.json).
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected JsonStaticBaseConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
super(configName, plugin, "", plugin.getClass());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.LoadableYamlConfig;
|
||||
import com.willfp.eco.internal.config.yaml.LoadableYamlConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.ConfigWrapper;
|
||||
import com.willfp.eco.internal.config.yaml.YamlConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class YamlConfig extends ConfigWrapper<YamlConfiguration> {
|
||||
public abstract class YamlConfig extends YamlConfigWrapper<YamlConfiguration> {
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
* <p>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.willfp.eco.core.data;
|
||||
|
||||
import com.willfp.eco.core.config.BaseConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.internal.config.ConfigSection;
|
||||
import com.willfp.eco.core.config.JSONConfig;
|
||||
import com.willfp.eco.core.config.JsonStaticBaseConfig;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import com.willfp.eco.internal.config.json.JsonConfigSection;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -20,93 +21,21 @@ public class Data {
|
||||
/**
|
||||
* Instance of eco data.yml.
|
||||
*/
|
||||
private static BaseConfig dataYml = null;
|
||||
private static JSONConfig datafile = null;
|
||||
|
||||
/**
|
||||
* All cached player data.
|
||||
*/
|
||||
private static final Map<UUID, Config> PLAYER_DATA = new HashMap<>();
|
||||
private static final Map<UUID, Map<EcoPlugin, JSONConfig>> PLAYER_DATA = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Write an integer to a player's data.
|
||||
* Initialize the player data with an instance of data.json.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param key The key.
|
||||
* @param data The data.
|
||||
*/
|
||||
public void writeInt(@NotNull final OfflinePlayer player,
|
||||
@NotNull final NamespacedKey key,
|
||||
final int data) {
|
||||
getPlayerConfig(player).set(key.toString(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to a player's data.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param key The key.
|
||||
* @param data The data.
|
||||
*/
|
||||
public void writeString(@NotNull final OfflinePlayer player,
|
||||
@NotNull final NamespacedKey key,
|
||||
@NotNull final String data) {
|
||||
getPlayerConfig(player).set(key.toString(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a double to a player's data.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param key The key.
|
||||
* @param data The data.
|
||||
*/
|
||||
public void writeDouble(@NotNull final OfflinePlayer player,
|
||||
@NotNull final NamespacedKey key,
|
||||
final double data) {
|
||||
getPlayerConfig(player).set(key.toString(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an integer from a player's data.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param key The key.
|
||||
*/
|
||||
public int readInt(@NotNull final OfflinePlayer player,
|
||||
@NotNull final NamespacedKey key) {
|
||||
return getPlayerConfig(player).getInt(key.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a string from a player's data.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param key The key.
|
||||
*/
|
||||
public String readString(@NotNull final OfflinePlayer player,
|
||||
@NotNull final NamespacedKey key) {
|
||||
return getPlayerConfig(player).getString(key.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a double from a player's data.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param key The key.
|
||||
*/
|
||||
public double readDouble(@NotNull final OfflinePlayer player,
|
||||
@NotNull final NamespacedKey key) {
|
||||
return getPlayerConfig(player).getDouble(key.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the player data with an instance of data.yml.
|
||||
*
|
||||
* @param config data.yml.
|
||||
* @param config data.json.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void init(@NotNull final BaseConfig config) {
|
||||
dataYml = config;
|
||||
public void init(@NotNull final JsonStaticBaseConfig config) {
|
||||
datafile = config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,25 +45,39 @@ public class Data {
|
||||
* @throws IOException Error during saving.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void save(@NotNull final BaseConfig config) throws IOException {
|
||||
for (Map.Entry<UUID, Config> entry : PLAYER_DATA.entrySet()) {
|
||||
for (String key : entry.getValue().getKeys(false)) {
|
||||
config.set("player-data." + entry.getKey().toString() + "." + key, entry.getValue().get(key));
|
||||
}
|
||||
public void save(@NotNull final Config config) throws IOException {
|
||||
for (Map.Entry<UUID, Map<EcoPlugin, JSONConfig>> entry : PLAYER_DATA.entrySet()) {
|
||||
entry.getValue().forEach((plugin, jsonConfig) -> {
|
||||
for (String key : jsonConfig.getKeys(false)) {
|
||||
config.set("player-data." + plugin.getName().toLowerCase() + "." + entry.getKey().toString() + "." + key, jsonConfig);
|
||||
}
|
||||
});
|
||||
}
|
||||
config.save();
|
||||
((LoadableConfig) config).save();
|
||||
}
|
||||
|
||||
private Config getPlayerConfig(@NotNull final OfflinePlayer player) {
|
||||
Config config = PLAYER_DATA.get(player.getUniqueId());
|
||||
/**
|
||||
* Get the data for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param plugin The plugin.
|
||||
* @return The data.
|
||||
*/
|
||||
public JSONConfig getData(@NotNull final OfflinePlayer player,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
if (!PLAYER_DATA.containsKey(player.getUniqueId())) {
|
||||
PLAYER_DATA.put(player.getUniqueId(), new HashMap<>());
|
||||
}
|
||||
|
||||
JSONConfig config = PLAYER_DATA.get(player.getUniqueId()).get(plugin);
|
||||
|
||||
if (config == null) {
|
||||
config = dataYml.getSubsectionOrNull("player-data." + player.getUniqueId());
|
||||
config = (JSONConfig) datafile.getSubsectionOrNull("player-data." + plugin.getName().toLowerCase() + "." + player.getUniqueId());
|
||||
if (config == null) {
|
||||
config = new ConfigSection(new YamlConfiguration());
|
||||
config = new JsonConfigSection(new HashMap<>());
|
||||
}
|
||||
PLAYER_DATA.put(player.getUniqueId(), config);
|
||||
return getPlayerConfig(player);
|
||||
PLAYER_DATA.get(player.getUniqueId()).put(plugin, config);
|
||||
return getData(player, plugin);
|
||||
}
|
||||
|
||||
return config;
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.Getter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class DisplayModule extends PluginDependent {
|
||||
public abstract class DisplayModule extends PluginDependent<EcoPlugin> {
|
||||
/**
|
||||
* The priority of the module.
|
||||
*/
|
||||
@@ -61,6 +61,6 @@ public abstract class DisplayModule extends PluginDependent {
|
||||
* @return The plugin name.
|
||||
*/
|
||||
final String getPluginName() {
|
||||
return super.getPlugin().getPluginName();
|
||||
return super.getPlugin().getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerJumpEvent extends PlayerMoveEvent {
|
||||
/**
|
||||
* Internal bukkit.
|
||||
*/
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
/**
|
||||
* Create a new PlayerJumpEvent.
|
||||
*
|
||||
* @param event The PlayerMoveEvent.
|
||||
*/
|
||||
public PlayerJumpEvent(@NotNull final PlayerMoveEvent event) {
|
||||
super(event.getPlayer(), event.getFrom(), event.getTo());
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal bukkit.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal bukkit.
|
||||
*
|
||||
* @return The handlers.
|
||||
*/
|
||||
public static @NotNull HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public abstract class Extension {
|
||||
*/
|
||||
public final String getName() {
|
||||
Validate.notNull(metadata, "Metadata cannot be null!");
|
||||
return this.metadata.getName();
|
||||
return this.metadata.name();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +81,6 @@ public abstract class Extension {
|
||||
*/
|
||||
public final String getVersion() {
|
||||
Validate.notNull(metadata, "Metadata cannot be null!");
|
||||
return this.metadata.getVersion();
|
||||
return this.metadata.version();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,11 @@ import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MetadataValueFactory {
|
||||
/**
|
||||
* Create a metadata value for a given plugin and object.
|
||||
*
|
||||
* @param value The object to store in metadata.
|
||||
* @return The metadata value.
|
||||
*/
|
||||
FixedMetadataValue create(@NotNull Object value);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
package com.willfp.eco.core.gui.menu;
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.core.items.builder.ItemStackBuilder;
|
||||
import com.willfp.eco.internal.gui.FillerSlot;
|
||||
import com.willfp.eco.util.ListUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FillerMask {
|
||||
/**
|
||||
* Mask.
|
||||
*/
|
||||
@Getter
|
||||
private final List<List<Slot>> mask;
|
||||
|
||||
/**
|
||||
* Create a new filler mask.
|
||||
*
|
||||
* @param material The mask material.
|
||||
* @param pattern The pattern.
|
||||
*/
|
||||
public FillerMask(@NotNull final Material material,
|
||||
@NotNull final String... pattern) {
|
||||
if (material == Material.AIR) {
|
||||
@@ -23,11 +32,9 @@ public class FillerMask {
|
||||
|
||||
mask = ListUtils.create2DList(6, 9);
|
||||
|
||||
ItemStack itemStack = new ItemStack(material);
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName("§r");
|
||||
itemStack.setItemMeta(meta);
|
||||
ItemStack itemStack = new ItemStackBuilder(material)
|
||||
.setDisplayName("&r")
|
||||
.build();
|
||||
|
||||
int row = 0;
|
||||
|
||||
|
||||
@@ -16,24 +16,72 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface Menu {
|
||||
/**
|
||||
* Get the amount of rows.
|
||||
*
|
||||
* @return The amount of rows.
|
||||
*/
|
||||
int getRows();
|
||||
|
||||
/**
|
||||
* Get slot at given row and column.
|
||||
*
|
||||
* @param row The row.
|
||||
* @param column The column.
|
||||
* @return The row.
|
||||
*/
|
||||
Slot getSlot(int row,
|
||||
int column);
|
||||
|
||||
/**
|
||||
* Get the menu title.
|
||||
*
|
||||
* @return The title.
|
||||
*/
|
||||
String getTitle();
|
||||
|
||||
/**
|
||||
* Open the inventory for the player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The inventory.
|
||||
*/
|
||||
Inventory open(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Create a builder with a given amount of rows.
|
||||
*
|
||||
* @param rows The rows.
|
||||
* @return The builder.
|
||||
*/
|
||||
static Builder builder(final int rows) {
|
||||
return new Builder(rows);
|
||||
}
|
||||
|
||||
class Builder {
|
||||
/**
|
||||
* The amount of rows.
|
||||
*/
|
||||
private final int rows;
|
||||
|
||||
/**
|
||||
* The title.
|
||||
*/
|
||||
private String title = "Menu";
|
||||
|
||||
/**
|
||||
* The mask slots.
|
||||
*/
|
||||
private List<List<Slot>> maskSlots;
|
||||
|
||||
/**
|
||||
* The slots.
|
||||
*/
|
||||
private final List<List<Slot>> slots;
|
||||
|
||||
/**
|
||||
* The close event handler.
|
||||
*/
|
||||
private Consumer<InventoryCloseEvent> onClose = (event) -> {
|
||||
};
|
||||
|
||||
|
||||
@@ -1,34 +1,76 @@
|
||||
package com.willfp.eco.core.gui.slot;
|
||||
|
||||
import com.willfp.eco.internal.gui.EcoSlot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface Slot {
|
||||
ItemStack getItemStack();
|
||||
/**
|
||||
* Get the ItemStack that would be shown to a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The ItemStack.
|
||||
*/
|
||||
ItemStack getItemStack(@NotNull Player player);
|
||||
|
||||
/**
|
||||
* Create a builder for an ItemStack.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
* @return The builder.
|
||||
*/
|
||||
static Builder builder(@NotNull final ItemStack itemStack) {
|
||||
return new Builder(itemStack);
|
||||
return new Builder((player) -> itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder for a player-specific ItemStack.
|
||||
*
|
||||
* @param provider The provider.
|
||||
* @return The builder.
|
||||
*/
|
||||
static Builder builder(@NotNull final Function<Player, ItemStack> provider) {
|
||||
return new Builder(provider);
|
||||
}
|
||||
|
||||
class Builder {
|
||||
private final ItemStack itemStack;
|
||||
/**
|
||||
* Provider.
|
||||
*/
|
||||
private final Function<Player, ItemStack> provider;
|
||||
|
||||
/**
|
||||
* Left click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onLeftClick = null;
|
||||
|
||||
/**
|
||||
* Right click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onRightClick = null;
|
||||
|
||||
/**
|
||||
* Shift-Left-Click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick = null;
|
||||
|
||||
/**
|
||||
* Shift-Right-Click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onShiftRightClick = null;
|
||||
|
||||
/**
|
||||
* Middle click handler.
|
||||
*/
|
||||
private BiConsumer<InventoryClickEvent, Slot> onMiddleClick = null;
|
||||
|
||||
Builder(@NotNull final ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
Builder(@NotNull final Function<Player, ItemStack> provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public Builder onLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
@@ -57,7 +99,7 @@ public interface Slot {
|
||||
}
|
||||
|
||||
public Slot build() {
|
||||
return new EcoSlot(itemStack, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick);
|
||||
return new EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PlaceholderManager {
|
||||
public static String getResult(@Nullable final Player player,
|
||||
@NotNull final String identifier) {
|
||||
Optional<PlaceholderEntry> matching = REGISTERED_PLACEHOLDERS.stream().filter(expansion -> expansion.getIdentifier().equalsIgnoreCase(identifier)).findFirst();
|
||||
if (!matching.isPresent()) {
|
||||
if (matching.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
PlaceholderEntry entry = matching.get();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
|
||||
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.TestableStack;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
@@ -40,6 +41,7 @@ public final class Items {
|
||||
*/
|
||||
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) {
|
||||
@@ -48,8 +50,26 @@ public final class Items {
|
||||
return new MaterialTestableItem(material);
|
||||
}
|
||||
|
||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||
return part == null ? new EmptyTestableItem() : part;
|
||||
if (split.length == 2) {
|
||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||
|
||||
if (part == null) {
|
||||
Material material = Material.getMaterial(split[0].toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
return new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
||||
} else {
|
||||
return part;
|
||||
}
|
||||
}
|
||||
|
||||
if (split.length == 3) {
|
||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||
return part == null ? new EmptyTestableItem() : new TestableStack(part, Integer.parseInt(split[2]));
|
||||
}
|
||||
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EnchantedBookBuilder extends AbstractItemStackBuilder<EnchantmentStorageMeta, EnchantedBookBuilder> {
|
||||
/**
|
||||
* Create a new EnchantedBookBuilder.
|
||||
*/
|
||||
public EnchantedBookBuilder() {
|
||||
super(Material.ENCHANTED_BOOK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an enchantment to the item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param level The level.
|
||||
* @return The builder.
|
||||
*/
|
||||
public EnchantedBookBuilder addStoredEnchantment(@NotNull final Enchantment enchantment,
|
||||
final int level) {
|
||||
this.getMeta().addStoredEnchant(enchantment, level, true);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface ItemBuilder {
|
||||
/**
|
||||
* Set the ItemStack amount.
|
||||
*
|
||||
* @param amount The amount.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setAmount(int amount);
|
||||
|
||||
/**
|
||||
* Set the ItemStack amount.
|
||||
*
|
||||
* @param amount The amount.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setAmount(@NotNull Supplier<Integer> amount);
|
||||
|
||||
/**
|
||||
* Add an enchantment to the item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param level The level.
|
||||
* @return The builder.r
|
||||
*/
|
||||
ItemBuilder addEnchantment(@NotNull Enchantment enchantment,
|
||||
int level);
|
||||
|
||||
/**
|
||||
* Add an enchantment to the item.
|
||||
*
|
||||
* @param enchantment The enchantment.
|
||||
* @param level The level.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addEnchantment(@NotNull Supplier<Enchantment> enchantment,
|
||||
@NotNull Supplier<Integer> level);
|
||||
|
||||
/**
|
||||
* Set the item display name.
|
||||
*
|
||||
* @param name The name.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setDisplayName(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Set the item display name.
|
||||
*
|
||||
* @param name The name.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setDisplayName(@NotNull Supplier<String> name);
|
||||
|
||||
/**
|
||||
* Add lore line.
|
||||
*
|
||||
* @param line The line.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLine(@NotNull String line);
|
||||
|
||||
/**
|
||||
* Add lore line.
|
||||
*
|
||||
* @param line The line.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLine(@NotNull Supplier<String> line);
|
||||
|
||||
/**
|
||||
* Add lore lines.
|
||||
*
|
||||
* @param lines The lines.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLines(@NotNull List<String> lines);
|
||||
|
||||
/**
|
||||
* Add lore lines.
|
||||
*
|
||||
* @param lines The lines.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addLoreLines(@NotNull Supplier<List<String>> lines);
|
||||
|
||||
/**
|
||||
* Add ItemFlags.
|
||||
*
|
||||
* @param itemFlags The flags.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addItemFlag(@NotNull ItemFlag... itemFlags);
|
||||
|
||||
/**
|
||||
* Add ItemFlags.
|
||||
*
|
||||
* @param itemFlags The flags.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder addItemFlag(@NotNull Supplier<ItemFlag[]> itemFlags);
|
||||
|
||||
/**
|
||||
* Write meta key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param type The type.
|
||||
* @param value The value.
|
||||
* @param <A> The type.
|
||||
* @param <B> The type.
|
||||
* @return The builder.
|
||||
*/
|
||||
<A, B> ItemBuilder writeMetaKey(@NotNull NamespacedKey key,
|
||||
@NotNull PersistentDataType<A, B> type,
|
||||
@NotNull B value);
|
||||
|
||||
/**
|
||||
* Write meta key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param type The type.
|
||||
* @param value The value.
|
||||
* @param <A> The type.
|
||||
* @param <B> The type.
|
||||
* @return The builder.
|
||||
*/
|
||||
<A, B> ItemBuilder writeMetaKey(@NotNull Supplier<NamespacedKey> key,
|
||||
@NotNull Supplier<PersistentDataType<A, B>> type,
|
||||
@NotNull Supplier<B> value);
|
||||
|
||||
/**
|
||||
* Set unbreakable.
|
||||
*
|
||||
* @param unbreakable If the item should be unbreakable.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setUnbreakable(boolean unbreakable);
|
||||
|
||||
/**
|
||||
* Set unbreakable.
|
||||
*
|
||||
* @param unbreakable If the item should be unbreakable.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setUnbreakable(@NotNull Supplier<Boolean> unbreakable);
|
||||
|
||||
/**
|
||||
* Set custom model data.
|
||||
*
|
||||
* @param data The data.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setCustomModelData(@Nullable Integer data);
|
||||
|
||||
/**
|
||||
* Set custom model data.
|
||||
*
|
||||
* @param data The data.
|
||||
* @return The builder.
|
||||
*/
|
||||
ItemBuilder setCustomModelData(@NotNull Supplier<Integer> data);
|
||||
|
||||
/**
|
||||
* Build the item.
|
||||
*
|
||||
* @return The item.
|
||||
*/
|
||||
ItemStack build();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ItemStackBuilder extends AbstractItemStackBuilder<ItemMeta, ItemStackBuilder> {
|
||||
/**
|
||||
* Create a new ItemStackBuilder.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public ItemStackBuilder(@NotNull final Material material) {
|
||||
super(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemStackBuilder to modify an existing item.
|
||||
*
|
||||
* @param base The ItemStack to start with.
|
||||
*/
|
||||
public ItemStackBuilder(@NotNull final ItemStack base) {
|
||||
super(base);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LeatherArmorBuilder extends AbstractItemStackBuilder<LeatherArmorMeta, LeatherArmorBuilder> {
|
||||
/**
|
||||
* Create a new ItemStackBuilder.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public LeatherArmorBuilder(@NotNull final Material material) {
|
||||
super(material);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemStackBuilder to modify an existing item.
|
||||
*
|
||||
* @param base The ItemStack to start with.
|
||||
*/
|
||||
public LeatherArmorBuilder(@NotNull final ItemStack base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set leather color.
|
||||
*
|
||||
* @param color The color.
|
||||
* @return The builder.
|
||||
*/
|
||||
public LeatherArmorBuilder setColor(@NotNull final java.awt.Color color) {
|
||||
Color bukkitColor = Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue());
|
||||
this.getMeta().setColor(bukkitColor);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.willfp.eco.core.items.builder;
|
||||
|
||||
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SkullBuilder extends AbstractItemStackBuilder<SkullMeta, SkullBuilder> {
|
||||
/**
|
||||
* Create a new EnchantedBookBuilder.
|
||||
*/
|
||||
public SkullBuilder() {
|
||||
super(Material.PLAYER_HEAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set skull texture.
|
||||
*
|
||||
* @param texture The texture.
|
||||
* @return The builder.
|
||||
*/
|
||||
public SkullBuilder setSkullTexture(@NotNull final String texture) {
|
||||
SkullUtils.setSkullTexture(this.getMeta(), texture);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,18 @@ package com.willfp.eco.core.recipe;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Recipes {
|
||||
@@ -59,4 +64,29 @@ public class Recipes {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and register recipe.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param key The key.
|
||||
* @param output The output.
|
||||
* @param recipeStrings The recipe.
|
||||
* @return The recipe.
|
||||
*/
|
||||
public CraftingRecipe createAndRegisterRecipe(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String key,
|
||||
@NotNull final ItemStack output,
|
||||
@NotNull final List<String> recipeStrings) {
|
||||
ShapedCraftingRecipe.Builder builder = ShapedCraftingRecipe.builder(plugin, key).setOutput(output);
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
builder.setRecipePart(i, Items.lookup(recipeStrings.get(i)));
|
||||
}
|
||||
|
||||
ShapedCraftingRecipe recipe = builder.build();
|
||||
recipe.register();
|
||||
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.core.recipe.parts;
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import com.willfp.eco.internal.Internals;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestableStack implements TestableItem {
|
||||
/**
|
||||
* The item.
|
||||
*/
|
||||
private final TestableItem handle;
|
||||
|
||||
/**
|
||||
* The amount.
|
||||
*/
|
||||
@Getter
|
||||
private final int amount;
|
||||
|
||||
/**
|
||||
* Create a new testable stack.
|
||||
*
|
||||
* @param item The item.
|
||||
* @param amount The amount.
|
||||
*/
|
||||
public TestableStack(@NotNull final TestableItem item,
|
||||
final int amount) {
|
||||
Validate.isTrue(!(item instanceof TestableStack));
|
||||
|
||||
this.handle = item;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item matches the material.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is of the specified material.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack != null && handle.matches(itemStack) && itemStack.getAmount() >= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
ItemStack temp = handle.getItem().clone();
|
||||
ItemMeta meta = temp.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add("");
|
||||
String add = Internals.getInstance().getPlugin().getLangYml().getString("multiple-in-craft");
|
||||
add = add.replace("%amount%", String.valueOf(amount));
|
||||
lore.add(add);
|
||||
meta.setLore(lore);
|
||||
temp.setItemMeta(meta);
|
||||
temp.setAmount(amount);
|
||||
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class ShapedCraftingRecipe extends PluginDependent implements CraftingRecipe {
|
||||
public final class ShapedCraftingRecipe extends PluginDependent<EcoPlugin> implements CraftingRecipe {
|
||||
/**
|
||||
* Recipe parts.
|
||||
*/
|
||||
|
||||
100
eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
Normal file
100
eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.willfp.eco.core.web;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Paste {
|
||||
/**
|
||||
* The contents.
|
||||
*/
|
||||
@Getter
|
||||
private final String contents;
|
||||
|
||||
/**
|
||||
* Create a new paste.
|
||||
*
|
||||
* @param contents The contents.
|
||||
*/
|
||||
public Paste(@NotNull final String contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload to hastebin and get a token.
|
||||
*
|
||||
* @return The token.
|
||||
*/
|
||||
public String getHastebinToken() {
|
||||
try {
|
||||
String url = "https://hastebin.com/documents";
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
|
||||
con.setRequestMethod("POST");
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
|
||||
con.setDoOutput(true);
|
||||
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
|
||||
wr.writeBytes(URLEncoder.encode(contents, StandardCharsets.UTF_8));
|
||||
wr.flush();
|
||||
wr.close();
|
||||
|
||||
BufferedReader iny = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
String output;
|
||||
StringBuilder responseBuilder = new StringBuilder();
|
||||
|
||||
while ((output = iny.readLine()) != null) {
|
||||
responseBuilder.append(output);
|
||||
}
|
||||
iny.close();
|
||||
|
||||
String responseString = responseBuilder.toString();
|
||||
|
||||
responseString = responseString.replace("{\"key\":\"", "");
|
||||
responseString = responseString.replace("\"}", "");
|
||||
|
||||
return responseString;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paste from hastebin.
|
||||
*
|
||||
* @param token The token.
|
||||
* @return The paste.
|
||||
*/
|
||||
public static Paste getFromHastebin(@NotNull final String token) {
|
||||
try {
|
||||
StringBuilder result = new StringBuilder();
|
||||
URL url = new URL("https://hastebin.com/raw/" + token);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
try (var reader = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream()))) {
|
||||
for (String line; (line = reader.readLine()) != null;) {
|
||||
result.append(line);
|
||||
}
|
||||
}
|
||||
return new Paste(URLDecoder.decode(result.toString(), StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
18
eco-api/src/main/java/com/willfp/eco/internal/Internals.java
Normal file
18
eco-api/src/main/java/com/willfp/eco/internal/Internals.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Internals {
|
||||
private static Internals internals;
|
||||
|
||||
public static void setInterfacing(@NotNull final Internals internals) {
|
||||
Internals.internals = internals;
|
||||
}
|
||||
|
||||
public abstract EcoPlugin getPlugin();
|
||||
|
||||
public static Internals getInstance() {
|
||||
return internals;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UpdateChecker extends PluginDependent {
|
||||
public class UpdateChecker extends PluginDependent<EcoPlugin> {
|
||||
/**
|
||||
* Create an update checker for the specified spigot resource id.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArrowDataListener extends PluginDependent implements Listener {
|
||||
public class ArrowDataListener extends PluginDependent<EcoPlugin> implements Listener {
|
||||
/**
|
||||
* Listener to add metadata to arrows about the enchantments on the bow that shot them.
|
||||
*
|
||||
@@ -31,15 +31,13 @@ public class ArrowDataListener extends PluginDependent implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onLaunch(final ProjectileLaunchEvent event) {
|
||||
if (!(event.getEntity() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof Arrow arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Arrow arrow = (Arrow) event.getEntity();
|
||||
LivingEntity entity = (LivingEntity) arrow.getShooter();
|
||||
if (!(arrow.getShooter() instanceof LivingEntity entity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.getEquipment() == null) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
package com.willfp.eco.internal.commands;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.command.CommandBase;
|
||||
import com.willfp.eco.core.command.CommandHandler;
|
||||
import com.willfp.eco.core.command.TabCompleteHandler;
|
||||
import com.willfp.eco.internal.commands.util.CommandUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class HandledCommand extends PluginDependent<EcoPlugin> implements CommandBase {
|
||||
/**
|
||||
* The name of the command.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The permission required to execute the command.
|
||||
* <p>
|
||||
* Written out as a string for flexibility with subclasses.
|
||||
*/
|
||||
@Getter
|
||||
private final String permission;
|
||||
|
||||
/**
|
||||
* Should the command only be allowed to be executed by players?
|
||||
* <p>
|
||||
* In other worlds, only allowed to be executed by console.
|
||||
*/
|
||||
@Getter
|
||||
private final boolean playersOnly;
|
||||
|
||||
/**
|
||||
* All subcommands for the command.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final List<CommandBase> subcommands;
|
||||
|
||||
/**
|
||||
* Create a new command.
|
||||
* <p>
|
||||
* The name cannot be the same as an existing command as this will conflict.
|
||||
*
|
||||
* @param plugin Instance of a plugin.
|
||||
* @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 HandledCommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
super(plugin);
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
this.playersOnly = playersOnly;
|
||||
this.subcommands = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a subcommand to the command.
|
||||
*
|
||||
* @param subcommand The subcommand.
|
||||
* @return The parent command.
|
||||
*/
|
||||
@Override
|
||||
public final CommandBase addSubcommand(@NotNull final CommandBase subcommand) {
|
||||
subcommands.add(subcommand);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the command.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
*/
|
||||
protected final void handle(@NotNull final CommandSender sender,
|
||||
@NotNull final String[] args) {
|
||||
if (!CommandUtils.canExecute(sender, this, this.getPlugin())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length > 0) {
|
||||
for (CommandBase subcommand : this.getSubcommands()) {
|
||||
if (subcommand.getName().equalsIgnoreCase(args[0])) {
|
||||
if (!CommandUtils.canExecute(sender, subcommand, this.getPlugin())) {
|
||||
return;
|
||||
}
|
||||
|
||||
((HandledCommand) subcommand).handle(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.getHandler().onExecute(sender, Arrays.asList(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the tab completion.
|
||||
*
|
||||
* @param sender The sender.
|
||||
* @param args The arguments.
|
||||
*/
|
||||
protected final List<String> handleTabCompletion(@NotNull final CommandSender sender,
|
||||
@NotNull final String[] args) {
|
||||
|
||||
if (!sender.hasPermission(this.getPermission())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
this.getSubcommands().stream().map(CommandBase::getName).collect(Collectors.toList()),
|
||||
completions
|
||||
);
|
||||
|
||||
Collections.sort(completions);
|
||||
|
||||
if (!completions.isEmpty()) {
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.length >= 2) {
|
||||
HandledCommand command = null;
|
||||
|
||||
for (CommandBase subcommand : this.getSubcommands()) {
|
||||
if (args[0].equalsIgnoreCase(subcommand.getName())) {
|
||||
command = (HandledCommand) subcommand;
|
||||
}
|
||||
}
|
||||
|
||||
if (command != null) {
|
||||
return command.handleTabCompletion(sender, Arrays.copyOfRange(args, 1, args.length));
|
||||
}
|
||||
}
|
||||
|
||||
return this.getTabCompleter().tabComplete(sender, Arrays.asList(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract CommandHandler getHandler();
|
||||
|
||||
@Override
|
||||
public TabCompleteHandler getTabCompleter() {
|
||||
return (sender, args) -> new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.willfp.eco.internal.commands.util;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.CommandBase;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class CommandUtils {
|
||||
public boolean canExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final CommandBase command,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
if (command.isPlayersOnly() && !(sender instanceof Player)) {
|
||||
sender.sendMessage(plugin.getLangYml().getMessage("not-player"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(command.getPermission()) && sender instanceof Player) {
|
||||
sender.sendMessage(plugin.getLangYml().getNoPermission());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
|
||||
/**
|
||||
* Config section.
|
||||
*
|
||||
* @param section The section.
|
||||
*/
|
||||
public ConfigSection(@NotNull final ConfigurationSection section) {
|
||||
this.init(section);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface LoadableConfig {
|
||||
/**
|
||||
* Create the file.
|
||||
*/
|
||||
void createFile();
|
||||
|
||||
/**
|
||||
* Get resource path as relative to base directory.
|
||||
*
|
||||
* @return The resource path.
|
||||
*/
|
||||
String getResourcePath();
|
||||
|
||||
/**
|
||||
* Save the config.
|
||||
*
|
||||
* @throws IOException If error in saving.
|
||||
*/
|
||||
void save() throws IOException;
|
||||
|
||||
/**
|
||||
* Get the config file.
|
||||
*
|
||||
* @return The file.
|
||||
*/
|
||||
File getConfigFile();
|
||||
|
||||
/**
|
||||
* Get the config name (including extension)
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.config.json;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonConfigSection extends JsonConfigWrapper {
|
||||
/**
|
||||
* Config section.
|
||||
*
|
||||
* @param values The values.
|
||||
*/
|
||||
public JsonConfigSection(@NotNull final Map<String, Object> values) {
|
||||
this.init(values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
package com.willfp.eco.internal.config.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.core.config.JSONConfig;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class JsonConfigWrapper implements JSONConfig, Cloneable {
|
||||
/**
|
||||
* The linked {@link ConfigurationSection} where values are physically stored.
|
||||
*/
|
||||
@Getter
|
||||
private final Gson handle = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
/**
|
||||
* All stored values.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Object> values = new HashMap<>();
|
||||
|
||||
/**
|
||||
* All cached values.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Object> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Abstract config.
|
||||
*/
|
||||
protected JsonConfigWrapper() {
|
||||
|
||||
}
|
||||
|
||||
public void init(@NotNull final Map<String, Object> values) {
|
||||
this.values.clear();
|
||||
this.values.putAll(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPlaintext() {
|
||||
return this.getHandle().toJson(this.getValues());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull final String path) {
|
||||
return getOfKnownType(path, Object.class) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected <T> T getOfKnownType(@NotNull final String path,
|
||||
@NotNull final Class<T> clazz) {
|
||||
return getOfKnownType(path, clazz, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected <T> T getOfKnownType(@NotNull final String path,
|
||||
@NotNull final Class<T> clazz,
|
||||
final boolean isBase) {
|
||||
String closestPath = path;
|
||||
|
||||
if (cache.containsKey(path) && isBase) {
|
||||
return (T) cache.get(path);
|
||||
}
|
||||
|
||||
if (path.contains(".")) {
|
||||
String[] split = path.split("\\.");
|
||||
closestPath = split[0];
|
||||
}
|
||||
|
||||
if (values.get(closestPath) instanceof Map && !path.equals(closestPath)) {
|
||||
JsonConfigSection section = new JsonConfigSection((Map<String, Object>) values.get(closestPath));
|
||||
return section.getOfKnownType(path.substring(closestPath.length() + 1), clazz, false);
|
||||
} else {
|
||||
if (values.containsKey(closestPath)) {
|
||||
return (T) values.get(closestPath);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getKeys(final boolean deep) {
|
||||
if (deep) {
|
||||
return new ArrayList<>(getDeepKeys(new HashSet<>(), ""));
|
||||
} else {
|
||||
return new ArrayList<>(values.keySet());
|
||||
}
|
||||
}
|
||||
|
||||
protected Set<String> getDeepKeys(@NotNull final Set<String> list,
|
||||
@NotNull final String root) {
|
||||
for (String key : values.keySet()) {
|
||||
list.add(root + key);
|
||||
|
||||
if (values.get(key) instanceof Map) {
|
||||
JsonConfigSection section = new JsonConfigSection((Map<String, Object>) values.get(key));
|
||||
list.addAll(section.getDeepKeys(list, root + key + "."));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object get(@NotNull final String path) {
|
||||
return getOfKnownType(path, Object.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull final String path,
|
||||
@Nullable final Object object) {
|
||||
setRecursively(path, object, true);
|
||||
clearCache();
|
||||
}
|
||||
|
||||
protected void setRecursively(@NotNull final String path,
|
||||
@Nullable final Object object,
|
||||
final boolean isBase) {
|
||||
String closestPath = path;
|
||||
|
||||
if (path.contains(".")) {
|
||||
String[] split = path.split("\\.");
|
||||
closestPath = split[0];
|
||||
}
|
||||
|
||||
if (values.get(closestPath) instanceof Map && !path.equals(closestPath)) {
|
||||
JsonConfigSection section = new JsonConfigSection((Map<String, Object>) values.get(closestPath));
|
||||
section.setRecursively(path.substring(closestPath.length() + 1), object, false);
|
||||
values.put(closestPath, section.getValues());
|
||||
} else {
|
||||
Object obj = object;
|
||||
|
||||
if (object instanceof JSONConfig) {
|
||||
obj = ((JsonConfigWrapper) object).getValues();
|
||||
}
|
||||
|
||||
values.put(path, obj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Config getSubsection(@NotNull final String path) {
|
||||
Config subsection = getSubsectionOrNull(path);
|
||||
Validate.notNull(subsection);
|
||||
return subsection;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Config getSubsectionOrNull(@NotNull final String path) {
|
||||
if (values.containsKey(path)) {
|
||||
Map<String, Object> subsection = (Map<String, Object>) values.get(path);
|
||||
return new JsonConfigSection(subsection);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JSONConfig> getSubsections(@NotNull final String path) {
|
||||
List<JSONConfig> subsections = getSubsectionsOrNull(path);
|
||||
Validate.notNull(subsections);
|
||||
return subsections;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<JSONConfig> getSubsectionsOrNull(@NotNull final String path) {
|
||||
List<Map<String, Object>> maps = (List<Map<String, Object>>) getOfKnownType(path, Object.class);
|
||||
|
||||
if (maps == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<JSONConfig> configs = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> map : maps) {
|
||||
configs.add(new JsonConfigSection(map));
|
||||
}
|
||||
|
||||
return configs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(@NotNull final String path) {
|
||||
// ew
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Double.class), 0D).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Integer getIntOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getInt(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(@NotNull final String path,
|
||||
final int def) {
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Integer.class), def);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
return (List<Integer>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getInts(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBool(@NotNull final String path) {
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Boolean.class), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Boolean getBoolOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getBool(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Boolean> getBools(@NotNull final String path) {
|
||||
return (List<Boolean>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getBools(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getString(@NotNull final String path) {
|
||||
return StringUtils.translate(Objects.requireNonNullElse(getOfKnownType(path, String.class), ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getStringOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getString(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
return StringUtils.translateList((List<String>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<String> getStringsOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getStrings(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(@NotNull final String path) {
|
||||
return Objects.requireNonNullElse(getOfKnownType(path, Double.class), 0D);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Double getDoubleOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getDouble(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Double> getDoubles(@NotNull final String path) {
|
||||
return (List<Double>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getDoubles(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONConfig clone() {
|
||||
return new JsonConfigSection(new HashMap<>(this.getValues()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.willfp.eco.internal.config.json;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class LoadableJsonConfig extends JsonConfigWrapper implements LoadableConfig {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
* Plugin handle.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* The full name of the config file (eg config.json).
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The subdirectory path.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final String subDirectoryPath;
|
||||
|
||||
/**
|
||||
* The provider of the config.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final Class<?> source;
|
||||
|
||||
/**
|
||||
* Abstract config.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
* @param subDirectoryPath The subdirectory path.
|
||||
* @param source The class that owns the resource.
|
||||
*/
|
||||
protected LoadableJsonConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final Class<?> source) {
|
||||
this.plugin = plugin;
|
||||
this.name = configName + ".json";
|
||||
this.source = source;
|
||||
this.subDirectoryPath = subDirectoryPath;
|
||||
|
||||
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
|
||||
if (!new File(directory, this.name).exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(directory, this.name);
|
||||
|
||||
try {
|
||||
init(this.configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
plugin.getConfigHandler().addConfig(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createFile() {
|
||||
String resourcePath = getResourcePath();
|
||||
InputStream in = source.getResourceAsStream(resourcePath);
|
||||
|
||||
File outFile = new File(this.getPlugin().getDataFolder(), resourcePath);
|
||||
int lastIndex = resourcePath.lastIndexOf('/');
|
||||
File outDir = new File(this.getPlugin().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!outFile.exists()) {
|
||||
OutputStream out = new FileOutputStream(outFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource path as relative to base directory.
|
||||
*
|
||||
* @return The resource path.
|
||||
*/
|
||||
@Override
|
||||
public String getResourcePath() {
|
||||
String resourcePath;
|
||||
|
||||
if (subDirectoryPath.isEmpty()) {
|
||||
resourcePath = name;
|
||||
} else {
|
||||
resourcePath = subDirectoryPath + name;
|
||||
}
|
||||
|
||||
return "/" + resourcePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config.
|
||||
*
|
||||
* @throws IOException If error in saving.
|
||||
*/
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
configFile.delete();
|
||||
Files.write(configFile.toPath(), this.toPlaintext().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the config.
|
||||
*
|
||||
* @param file The config file.
|
||||
* @throws FileNotFoundException If the file doesn't exist.
|
||||
*/
|
||||
public void init(@NotNull final File file) throws FileNotFoundException {
|
||||
super.init(this.getHandle().fromJson(new FileReader(file), HashMap.class));
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,31 @@
|
||||
package com.willfp.eco.internal.config.updating;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.config.ConfigHandler;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
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 com.willfp.eco.internal.config.yaml.UpdatableYamlConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigHandler extends PluginDependent {
|
||||
public class EcoConfigHandler extends PluginDependent<EcoPlugin> implements ConfigHandler {
|
||||
/**
|
||||
* A set of all configs that can be saved.
|
||||
*/
|
||||
private final List<LoadableConfig> configs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* A set of all classes that can be updated.
|
||||
*/
|
||||
@@ -25,25 +36,26 @@ public class ConfigHandler extends PluginDependent {
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public ConfigHandler(@NotNull final EcoPlugin plugin) {
|
||||
public EcoConfigHandler(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke all update methods.
|
||||
*/
|
||||
@Override
|
||||
public void callUpdate() {
|
||||
updatableClasses.forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).forEach(method -> {
|
||||
if (method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||
if (method.getParameterTypes().length != 0) {
|
||||
throw new InvalidUpdateMethodException("Update method must not have parameters.");
|
||||
}
|
||||
if (!Modifier.isStatic(method.getModifiers())) {
|
||||
throw new InvalidUpdateMethodException("Update method must be static.");
|
||||
}
|
||||
|
||||
try {
|
||||
method.invoke(null);
|
||||
if (method.getParameterCount() == 0) {
|
||||
method.invoke(null);
|
||||
} else if (method.getParameterCount() == 1) {
|
||||
method.invoke(null, this.getPlugin());
|
||||
} else {
|
||||
throw new InvalidUpdateMethodException("Update method must have 0 parameters or a plugin parameter.");
|
||||
}
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidUpdateMethodException("Update method generated an exception.");
|
||||
@@ -52,15 +64,11 @@ public class ConfigHandler extends PluginDependent {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an updatable class.
|
||||
*
|
||||
* @param updatableClass The class with an update method.
|
||||
*/
|
||||
@Override
|
||||
public void registerUpdatableClass(@NotNull final Class<?> updatableClass) {
|
||||
boolean isValid = false;
|
||||
for (Method method : updatableClass.getDeclaredMethods()) {
|
||||
if (Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0 && method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||
if (Modifier.isStatic(method.getModifiers()) && (method.getParameterCount() == 0 || method.getParameterCount() == 1) && method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
@@ -72,4 +80,29 @@ public class ConfigHandler extends PluginDependent {
|
||||
|
||||
updatableClasses.add(updatableClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllConfigs() {
|
||||
try {
|
||||
for (LoadableConfig config : configs) {
|
||||
config.save();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConfig(@NotNull final LoadableConfig config) {
|
||||
configs.add(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateConfigs() {
|
||||
for (LoadableConfig config : configs) {
|
||||
if (config instanceof UpdatableYamlConfig updatableYamlConfig) {
|
||||
updatableYamlConfig.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.willfp.eco.internal.config.updating.exceptions;
|
||||
|
||||
import com.willfp.eco.internal.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.internal.config.updating.EcoConfigHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InvalidUpdatableClassException extends RuntimeException {
|
||||
/**
|
||||
* Called when an updatable class is registered into an {@link ConfigHandler}.
|
||||
* Called when an updatable class is registered into an {@link EcoConfigHandler}.
|
||||
*
|
||||
* @param message The error message.
|
||||
*/
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.internal.config.LoadableConfig;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration> {
|
||||
public abstract class LoadableYamlConfig extends YamlConfigWrapper<YamlConfiguration> implements LoadableConfig {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
@Getter
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
@@ -77,7 +74,8 @@ public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration
|
||||
init(YamlConfiguration.loadConfiguration(configFile));
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
@Override
|
||||
public void createFile() {
|
||||
String resourcePath = getResourcePath();
|
||||
InputStream in = source.getResourceAsStream(resourcePath);
|
||||
|
||||
@@ -102,14 +100,12 @@ public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
|
||||
plugin.getConfigHandler().addConfig(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource path as relative to base directory.
|
||||
*
|
||||
* @return The resource path.
|
||||
*/
|
||||
protected String getResourcePath() {
|
||||
@Override
|
||||
public String getResourcePath() {
|
||||
String resourcePath;
|
||||
|
||||
if (subDirectoryPath.isEmpty()) {
|
||||
@@ -121,35 +117,7 @@ public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration
|
||||
return "/" + resourcePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get YamlConfiguration as found in jar.
|
||||
*
|
||||
* @return The YamlConfiguration.
|
||||
*/
|
||||
protected YamlConfiguration getConfigInJar() {
|
||||
InputStream newIn = source.getResourceAsStream(getResourcePath());
|
||||
|
||||
if (newIn == null) {
|
||||
throw new NullPointerException(name + " is null?");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
newConfig.load(reader);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the config.
|
||||
*
|
||||
* @throws IOException If error in saving.
|
||||
*/
|
||||
@Override
|
||||
public void save() throws IOException {
|
||||
this.getHandle().save(this.getConfigFile());
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -84,4 +88,23 @@ public abstract class UpdatableYamlConfig extends LoadableYamlConfig {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public YamlConfiguration getConfigInJar() {
|
||||
InputStream newIn = this.getSource().getResourceAsStream(getResourcePath());
|
||||
|
||||
if (newIn == null) {
|
||||
throw new NullPointerException(this.getName() + " is null?");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
newConfig.load(reader);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class YamlConfigSection extends YamlConfigWrapper<ConfigurationSection> {
|
||||
/**
|
||||
* Config section.
|
||||
*
|
||||
* @param section The section.
|
||||
*/
|
||||
public YamlConfigSection(@NotNull final ConfigurationSection section) {
|
||||
this.init(section);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
package com.willfp.eco.internal.config.yaml;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -15,7 +16,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class ConfigWrapper<T extends ConfigurationSection> implements Config {
|
||||
public abstract class YamlConfigWrapper<T extends ConfigurationSection> implements Config {
|
||||
/**
|
||||
* The linked {@link ConfigurationSection} where values are physically stored.
|
||||
*/
|
||||
@@ -30,7 +31,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
||||
/**
|
||||
* Abstract config.
|
||||
*/
|
||||
protected ConfigWrapper() {
|
||||
protected YamlConfigWrapper() {
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +40,15 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toPlaintext() {
|
||||
YamlConfiguration temp = new YamlConfiguration();
|
||||
for (String key : handle.getKeys(true)) {
|
||||
temp.set(key, handle.get(key));
|
||||
}
|
||||
return temp.saveToString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void clearCache() {
|
||||
cache.clear();
|
||||
@@ -86,7 +96,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
||||
if (raw == null) {
|
||||
cache.put(path, null);
|
||||
} else {
|
||||
cache.put(path, new ConfigSection(raw));
|
||||
cache.put(path, new YamlConfigSection(raw));
|
||||
}
|
||||
return getSubsectionOrNull(path);
|
||||
}
|
||||
@@ -210,7 +220,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
||||
@NotNull
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<String>) cache.get(path);
|
||||
return StringUtils.translateList((List<String>) cache.get(path));
|
||||
} else {
|
||||
cache.put(path, has(path) ? new ArrayList<>(handle.getStringList(path)) : new ArrayList<>());
|
||||
return getStrings(path);
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoEventManager extends PluginDependent implements EventManager {
|
||||
public class EcoEventManager extends PluginDependent<EcoPlugin> implements EventManager {
|
||||
/**
|
||||
* Manager class for event management.
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Concrete implementation of {@link ExtensionLoader}.
|
||||
*/
|
||||
public class EcoExtensionLoader extends PluginDependent implements ExtensionLoader {
|
||||
public class EcoExtensionLoader extends PluginDependent<EcoPlugin> implements ExtensionLoader {
|
||||
/**
|
||||
* All currently loaded extensions.
|
||||
*/
|
||||
@@ -110,11 +110,10 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!(object instanceof Extension)) {
|
||||
if (!(object instanceof Extension extension)) {
|
||||
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
||||
}
|
||||
|
||||
Extension extension = (Extension) object;
|
||||
extension.setMetadata(metadata);
|
||||
extension.enable();
|
||||
extensions.add(extension);
|
||||
|
||||
@@ -1,32 +1,8 @@
|
||||
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;
|
||||
public record ExtensionMetadata(@NotNull String version,
|
||||
@NotNull String name) {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.willfp.eco.core.factory.MetadataValueFactory;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoMetadataValueFactory extends PluginDependent implements MetadataValueFactory {
|
||||
public class EcoMetadataValueFactory extends PluginDependent<EcoPlugin> implements MetadataValueFactory {
|
||||
/**
|
||||
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link EcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.willfp.eco.core.factory.NamespacedKeyFactory;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoNamespacedKeyFactory extends PluginDependent implements NamespacedKeyFactory {
|
||||
public class EcoNamespacedKeyFactory extends PluginDependent<EcoPlugin> implements NamespacedKeyFactory {
|
||||
/**
|
||||
* Factory class to produce {@link NamespacedKey}s associated with an {@link EcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EcoRunnableFactory extends PluginDependent implements RunnableFactory {
|
||||
public class EcoRunnableFactory extends PluginDependent<EcoPlugin> implements RunnableFactory {
|
||||
/**
|
||||
* Factory class to produce {@link RunnableTask}s associated with an {@link EcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -59,7 +59,7 @@ public class EcoMenu implements Menu {
|
||||
if (i == rows * 9) {
|
||||
break;
|
||||
}
|
||||
ItemStack slotItem = item.getItemStack();
|
||||
ItemStack slotItem = item.getItemStack(player);
|
||||
ItemMeta meta = slotItem.getItemMeta();
|
||||
if (meta != null) {
|
||||
List<String> lore = meta.getLore();
|
||||
|
||||
@@ -2,16 +2,18 @@ package com.willfp.eco.internal.gui;
|
||||
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoSlot implements Slot {
|
||||
@Getter
|
||||
private final ItemStack itemStack;
|
||||
private final Function<Player, ItemStack> provider;
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onLeftClick;
|
||||
|
||||
@@ -23,13 +25,13 @@ public class EcoSlot implements Slot {
|
||||
|
||||
private final BiConsumer<InventoryClickEvent, Slot> onMiddleClick;
|
||||
|
||||
public EcoSlot(@NotNull final ItemStack itemStack,
|
||||
public EcoSlot(@NotNull final Function<Player, ItemStack> provider,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onLeftClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onRightClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onShiftRightClick,
|
||||
@Nullable final BiConsumer<InventoryClickEvent, Slot> onMiddleClick) {
|
||||
this.itemStack = itemStack;
|
||||
this.provider = provider;
|
||||
this.onLeftClick = onLeftClick == null ? ((event, slot) -> { }) : onLeftClick;
|
||||
this.onRightClick = onRightClick == null ? ((event, slot) -> { }) : onRightClick;
|
||||
this.onShiftLeftClick = onShiftLeftClick == null ? ((event, slot) -> { }) : onShiftLeftClick;
|
||||
@@ -39,23 +41,17 @@ public class EcoSlot implements Slot {
|
||||
|
||||
public void handleInventoryClick(@NotNull final InventoryClickEvent event) {
|
||||
switch (event.getClick()) {
|
||||
case LEFT:
|
||||
this.onLeftClick.accept(event, this);
|
||||
break;
|
||||
case RIGHT:
|
||||
this.onRightClick.accept(event, this);
|
||||
break;
|
||||
case SHIFT_LEFT:
|
||||
this.onShiftLeftClick.accept(event, this);
|
||||
break;
|
||||
case SHIFT_RIGHT:
|
||||
this.onShiftRightClick.accept(event, this);
|
||||
break;
|
||||
case MIDDLE:
|
||||
this.onMiddleClick.accept(event, this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case LEFT -> this.onLeftClick.accept(event, this);
|
||||
case RIGHT -> this.onRightClick.accept(event, this);
|
||||
case SHIFT_LEFT -> this.onShiftLeftClick.accept(event, this);
|
||||
case SHIFT_RIGHT -> this.onShiftRightClick.accept(event, this);
|
||||
case MIDDLE -> this.onMiddleClick.accept(event, this);
|
||||
default -> { }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(@NotNull final Player player) {
|
||||
return provider.apply(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ public class FillerSlot extends EcoSlot {
|
||||
* @param itemStack The ItemStack.
|
||||
*/
|
||||
public FillerSlot(@NotNull final ItemStack itemStack) {
|
||||
super(itemStack, null, null, null, null, null);
|
||||
super((player) -> itemStack, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.willfp.eco.internal.items;
|
||||
|
||||
import com.willfp.eco.core.items.builder.ItemBuilder;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class AbstractItemStackBuilder<T extends ItemMeta, U extends AbstractItemStackBuilder<T, U>> implements ItemBuilder {
|
||||
/**
|
||||
* The ItemMeta used while building.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final T meta;
|
||||
|
||||
/**
|
||||
* The ItemStack.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final ItemStack base;
|
||||
|
||||
/**
|
||||
* Create a new ItemStackBuilder.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
protected AbstractItemStackBuilder(@NotNull final Material material) {
|
||||
this(new ItemStack(material));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ItemStackBuilder to modify an existing item.
|
||||
*
|
||||
* @param base The ItemStack to start with.
|
||||
*/
|
||||
protected AbstractItemStackBuilder(@NotNull final ItemStack base) {
|
||||
this.base = base;
|
||||
this.meta = (T) base.getItemMeta();
|
||||
assert meta != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setAmount(final int amount) {
|
||||
Validate.isTrue(amount >= 1 && amount <= base.getMaxStackSize());
|
||||
base.setAmount(amount);
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setAmount(@NotNull final Supplier<Integer> amount) {
|
||||
return setAmount(amount.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addEnchantment(@NotNull final Enchantment enchantment,
|
||||
final int level) {
|
||||
meta.addEnchant(enchantment, level, true);
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addEnchantment(@NotNull final Supplier<Enchantment> enchantment,
|
||||
@NotNull final Supplier<Integer> level) {
|
||||
return addEnchantment(enchantment.get(), level.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setDisplayName(@NotNull final String name) {
|
||||
meta.setDisplayName(StringUtils.translate(name));
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setDisplayName(@NotNull final Supplier<String> name) {
|
||||
String result = name.get();
|
||||
|
||||
return result == null ? (U) this : setDisplayName(name.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addLoreLine(@NotNull final String line) {
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
lore.add(StringUtils.translate(line));
|
||||
meta.setLore(lore);
|
||||
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addLoreLine(@NotNull final Supplier<String> line) {
|
||||
String result = line.get();
|
||||
|
||||
return result == null ? (U) this : addLoreLine(line.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addLoreLines(@NotNull final List<String> lines) {
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||
assert lore != null;
|
||||
for (String line : lines) {
|
||||
lore.add(StringUtils.translate(line));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addLoreLines(@NotNull final Supplier<List<String>> lines) {
|
||||
List<String> result = lines.get();
|
||||
|
||||
return result == null ? (U) this : addLoreLines(lines.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addItemFlag(@NotNull final ItemFlag... itemFlags) {
|
||||
meta.addItemFlags(itemFlags);
|
||||
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U addItemFlag(@NotNull final Supplier<ItemFlag[]> itemFlags) {
|
||||
ItemFlag[] result = itemFlags.get();
|
||||
|
||||
return result == null ? (U) this : addItemFlag(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> U writeMetaKey(@NotNull final NamespacedKey key,
|
||||
@NotNull final PersistentDataType<A, B> type,
|
||||
@NotNull final B value) {
|
||||
meta.getPersistentDataContainer().set(key, type, value);
|
||||
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A, B> U writeMetaKey(@NotNull final Supplier<NamespacedKey> key,
|
||||
@NotNull final Supplier<PersistentDataType<A, B>> type,
|
||||
@NotNull final Supplier<B> value) {
|
||||
return writeMetaKey(key.get(), type.get(), value.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setUnbreakable(final boolean unbreakable) {
|
||||
meta.setUnbreakable(unbreakable);
|
||||
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setUnbreakable(@NotNull final Supplier<Boolean> unbreakable) {
|
||||
Boolean result = unbreakable.get();
|
||||
|
||||
return result == null ? (U) this : setUnbreakable(unbreakable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setCustomModelData(@Nullable final Integer data) {
|
||||
meta.setCustomModelData(data);
|
||||
|
||||
return (U) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public U setCustomModelData(@NotNull final Supplier<Integer> data) {
|
||||
Integer result = data.get();
|
||||
|
||||
return result == null ? (U) this : setCustomModelData(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack build() {
|
||||
base.setItemMeta(meta);
|
||||
|
||||
return base;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoScheduler extends PluginDependent implements Scheduler {
|
||||
public class EcoScheduler extends PluginDependent<EcoPlugin> implements Scheduler {
|
||||
/**
|
||||
* Create a scheduler to manage the tasks of an {@link EcoPlugin}.
|
||||
*
|
||||
|
||||
@@ -121,8 +121,7 @@ public class DurabilityUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
if (item.getItemMeta() instanceof Damageable meta) {
|
||||
meta.setDamage(meta.getDamage() - repair);
|
||||
|
||||
if (meta.getDamage() < 0) {
|
||||
|
||||
@@ -39,6 +39,33 @@ public class StringUtils {
|
||||
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Translate a list of strings - converts Placeholders and Color codes.
|
||||
*
|
||||
* @param list The messages to translate.
|
||||
* @param player The player to translate placeholders with respect to.
|
||||
* @return The message, translated.
|
||||
*/
|
||||
public List<String> translateList(@NotNull final List<String> list,
|
||||
@Nullable final Player player) {
|
||||
List<String> translated = new ArrayList<>();
|
||||
for (String string : list) {
|
||||
translated.add(translate(string, player));
|
||||
}
|
||||
|
||||
return translated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a list of strings - converts Placeholders and Color codes.
|
||||
*
|
||||
* @param list The messages to translate.
|
||||
* @return The message, translated.
|
||||
*/
|
||||
public List<String> translateList(@NotNull final List<String> list) {
|
||||
return translateList(list, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string - converts Placeholders and Color codes.
|
||||
*
|
||||
@@ -79,16 +106,16 @@ public class StringUtils {
|
||||
@NotNull final Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
StringBuilder builder = new StringBuilder(message.length() + 4 * 8);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
|
||||
matcher.appendReplacement(builder, COLOR_CHAR + "x"
|
||||
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
|
||||
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
|
||||
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
|
||||
}
|
||||
|
||||
return matcher.appendTail(buffer).toString();
|
||||
return matcher.appendTail(builder).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,8 +225,7 @@ public class StringUtils {
|
||||
return (String) object;
|
||||
} else if (object instanceof Double) {
|
||||
return NumberUtils.format((Double) object);
|
||||
} else if (object instanceof Collection<?>) {
|
||||
Collection<?> c = (Collection<?>) object;
|
||||
} else if (object instanceof Collection<?> c) {
|
||||
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
|
||||
} else {
|
||||
return String.valueOf(object);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.core.Prerequisite;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -10,6 +11,8 @@ import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
@@ -17,7 +20,7 @@ public class TeamUtils {
|
||||
/**
|
||||
* Ore ChatColors.
|
||||
*/
|
||||
private static final BiMap<Material, ChatColor> MATERIAL_COLORS = HashBiMap.create();
|
||||
private static final Map<Material, ChatColor> MATERIAL_COLORS = new HashMap<>();
|
||||
|
||||
/**
|
||||
* All chat color teams.
|
||||
@@ -73,13 +76,25 @@ public class TeamUtils {
|
||||
fromChatColor(value);
|
||||
}
|
||||
|
||||
MATERIAL_COLORS.forcePut(Material.COAL_ORE, ChatColor.BLACK);
|
||||
MATERIAL_COLORS.forcePut(Material.IRON_ORE, ChatColor.GRAY);
|
||||
MATERIAL_COLORS.forcePut(Material.GOLD_ORE, ChatColor.YELLOW);
|
||||
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
|
||||
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
|
||||
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
|
||||
MATERIAL_COLORS.forcePut(Material.EMERALD_ORE, ChatColor.GREEN);
|
||||
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||
MATERIAL_COLORS.put(Material.COAL_ORE, ChatColor.BLACK);
|
||||
MATERIAL_COLORS.put(Material.IRON_ORE, ChatColor.GRAY);
|
||||
MATERIAL_COLORS.put(Material.GOLD_ORE, ChatColor.YELLOW);
|
||||
MATERIAL_COLORS.put(Material.LAPIS_ORE, ChatColor.BLUE);
|
||||
MATERIAL_COLORS.put(Material.REDSTONE_ORE, ChatColor.RED);
|
||||
MATERIAL_COLORS.put(Material.DIAMOND_ORE, ChatColor.AQUA);
|
||||
MATERIAL_COLORS.put(Material.EMERALD_ORE, ChatColor.GREEN);
|
||||
MATERIAL_COLORS.put(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||
|
||||
if (Prerequisite.HAS_1_17.isMet()) {
|
||||
MATERIAL_COLORS.put(Material.COPPER_ORE, ChatColor.GOLD);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_COPPER_ORE, ChatColor.GOLD);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_COAL_ORE, ChatColor.BLACK);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_IRON_ORE, ChatColor.GRAY);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_GOLD_ORE, ChatColor.YELLOW);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_LAPIS_ORE, ChatColor.BLUE);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_REDSTONE_ORE, ChatColor.RED);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_DIAMOND_ORE, ChatColor.AQUA);
|
||||
MATERIAL_COLORS.put(Material.DEEPSLATE_EMERALD_ORE, ChatColor.GREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
if (!(player instanceof CraftPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,10 @@ import java.util.Arrays;
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
if (!(object instanceof IChatBaseComponent)) {
|
||||
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||
if (iChatBaseComponent == null) {
|
||||
continue;
|
||||
|
||||
@@ -11,6 +11,10 @@ public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
if (!(player instanceof CraftPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,10 @@ import java.util.Arrays;
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
if (!(object instanceof IChatBaseComponent)) {
|
||||
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||
if (iChatBaseComponent == null) {
|
||||
continue;
|
||||
|
||||
@@ -11,6 +11,10 @@ public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
if (!(player instanceof CraftPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,10 @@ import java.util.Arrays;
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
if (!(object instanceof IChatBaseComponent)) {
|
||||
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||
if (iChatBaseComponent == null) {
|
||||
continue;
|
||||
|
||||
@@ -11,6 +11,10 @@ public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
if (!(player instanceof CraftPlayer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((CraftPlayer) player).getHandle().d.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,10 @@ import java.util.Arrays;
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
if (!(object instanceof IChatBaseComponent)) {
|
||||
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||
if (iChatBaseComponent == null) {
|
||||
continue;
|
||||
|
||||
@@ -4,6 +4,7 @@ version rootProject.version
|
||||
dependencies {
|
||||
implementation 'org.apache.maven:maven-artifact:3.0.3'
|
||||
implementation 'org.bstats:bstats-bukkit:1.7'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.7'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly project(":eco-core:core-proxy")
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||
@@ -16,6 +17,15 @@ dependencies {
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
|
||||
|
||||
// CombatLogX V10 + NewbieHelper Expansion
|
||||
compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT'
|
||||
compileOnly 'com.SirBlobman.combatlogx.expansions:NewbieHelper:10.0.0.0-SNAPSHOT'
|
||||
|
||||
// CombatLogX V11 + NewbieHelper Expansion
|
||||
compileOnly 'com.github.sirblobman.combatlogx:api:11.0.0.0-SNAPSHOT'
|
||||
compileOnly 'com.github.sirblobman.combatlogx.expansion:newbie-helper:11.0.0.0-SNAPSHOT'
|
||||
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
@@ -23,4 +33,4 @@ processResources {
|
||||
filesNotMatching(["**/*.png", "**/models/**", "**/textures/**"]) {
|
||||
expand projectVersion: project.version
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.internal.Internals;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoInternals extends Internals {
|
||||
private final EcoSpigotPlugin plugin;
|
||||
|
||||
EcoInternals(@NotNull final EcoSpigotPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EcoSpigotPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,17 @@ package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.data.Data;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.core.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||
import com.willfp.eco.internal.Internals;
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.spigot.config.DataYml;
|
||||
import com.willfp.eco.spigot.config.DataJson;
|
||||
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
||||
import com.willfp.eco.spigot.display.PacketChat;
|
||||
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
||||
@@ -25,9 +24,15 @@ import com.willfp.eco.spigot.eventlisteners.ArmorListener;
|
||||
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
|
||||
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
||||
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
|
||||
import com.willfp.eco.spigot.eventlisteners.PlayerJumpListeners;
|
||||
import com.willfp.eco.spigot.gui.GUIListener;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.*;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatSpartan;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatVulcan;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogXV10;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogXV11;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefKingdoms;
|
||||
@@ -40,8 +45,11 @@ import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import com.willfp.eco.util.TridentUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -56,29 +64,30 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
||||
private static EcoSpigotPlugin instance;
|
||||
|
||||
/**
|
||||
* data.yml.
|
||||
* data.json.
|
||||
*/
|
||||
private final DataYml dataYml;
|
||||
private final DataJson dataJson;
|
||||
|
||||
/**
|
||||
* Create a new instance of eco.
|
||||
*/
|
||||
public EcoSpigotPlugin() {
|
||||
super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||
super(87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||
instance = this;
|
||||
Internals.setInterfacing(new EcoInternals(this));
|
||||
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized"));
|
||||
|
||||
SkullProxy skullProxy = InternalProxyUtils.getProxy(SkullProxy.class);
|
||||
SkullProxy skullProxy = ProxyUtils.getProxy(SkullProxy.class);
|
||||
SkullUtils.initialize(skullProxy::setSkullTexture);
|
||||
|
||||
BlockBreakProxy blockBreakProxy = InternalProxyUtils.getProxy(BlockBreakProxy.class);
|
||||
BlockBreakProxy blockBreakProxy = ProxyUtils.getProxy(BlockBreakProxy.class);
|
||||
BlockUtils.initialize(blockBreakProxy::breakBlock);
|
||||
|
||||
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
|
||||
TridentStackProxy tridentStackProxy = ProxyUtils.getProxy(TridentStackProxy.class);
|
||||
TridentUtils.initialize(tridentStackProxy::getTridentStack);
|
||||
|
||||
this.dataYml = new DataYml(this);
|
||||
Data.init(this.dataYml);
|
||||
this.dataJson = new DataJson(this);
|
||||
Data.init(this.dataJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,27 +98,17 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
||||
@Override
|
||||
public void disable() {
|
||||
try {
|
||||
Data.save(this.dataYml);
|
||||
Data.save(this.dataJson);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
new CollatedRunnable(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postLoad() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
return Arrays.asList(
|
||||
@@ -120,7 +119,20 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
||||
new IntegrationLoader("Towny", () -> AntigriefManager.register(new AntigriefTowny())),
|
||||
new IntegrationLoader("Lands", () -> AntigriefManager.register(new AntigriefLands(this))),
|
||||
new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())),
|
||||
new IntegrationLoader("CombatLogX", () -> AntigriefManager.register(new AntigriefCombatLogX())),
|
||||
new IntegrationLoader("CombatLogX", () -> {
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
Plugin plugin_CombatLogX = pluginManager.getPlugin("CombatLogX");
|
||||
if (plugin_CombatLogX == null) return;
|
||||
|
||||
String pluginVersion = plugin_CombatLogX.getDescription().getVersion();
|
||||
if (pluginVersion.startsWith("10")) {
|
||||
AntigriefManager.register(new AntigriefCombatLogXV10());
|
||||
}
|
||||
|
||||
if(pluginVersion.startsWith("11")) {
|
||||
AntigriefManager.register(new AntigriefCombatLogXV11());
|
||||
}
|
||||
}),
|
||||
|
||||
// Anticheat
|
||||
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
||||
@@ -134,11 +146,6 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
List<AbstractPacketAdapter> adapters = new ArrayList<>(Arrays.asList(
|
||||
@@ -163,19 +170,9 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
||||
new ArmorListener(),
|
||||
new DispenserArmorListener(),
|
||||
new EntityDeathByEntityListeners(this),
|
||||
new ShapedRecipeListener(),
|
||||
new ShapedRecipeListener(this),
|
||||
new PlayerJumpListeners(),
|
||||
new GUIListener(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getUpdatableClasses() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||
import com.willfp.eco.proxy.util.ProxyFactory;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class InternalProxyUtils {
|
||||
/**
|
||||
* Get the implementation of a specified proxy.
|
||||
*
|
||||
* @param proxyClass The proxy interface.
|
||||
* @param <T> The type of the proxy.
|
||||
* @return The proxy implementation.
|
||||
*/
|
||||
public @NotNull <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
|
||||
return new ProxyFactory<>(EcoSpigotPlugin.getInstance(), proxyClass).getProxy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||
import com.willfp.eco.proxy.util.ProxyFactory;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class ProxyUtils {
|
||||
public <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxy) {
|
||||
return new ProxyFactory<>(EcoSpigotPlugin.getInstance(), proxy).getProxy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.spigot.config;
|
||||
|
||||
import com.willfp.eco.core.config.JsonStaticBaseConfig;
|
||||
import com.willfp.eco.spigot.EcoSpigotPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DataJson extends JsonStaticBaseConfig {
|
||||
/**
|
||||
* Init data.json.
|
||||
*
|
||||
* @param plugin EcoSpigotPlugin.
|
||||
*/
|
||||
public DataJson(@NotNull final EcoSpigotPlugin plugin) {
|
||||
super("data", plugin);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.eco.spigot.config;
|
||||
|
||||
import com.willfp.eco.core.config.BaseConfig;
|
||||
import com.willfp.eco.spigot.EcoSpigotPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DataYml extends BaseConfig {
|
||||
/**
|
||||
* Init data.yml.
|
||||
*
|
||||
* @param plugin EcoSpigotPlugin.
|
||||
*/
|
||||
public DataYml(@NotNull final EcoSpigotPlugin plugin) {
|
||||
super("data", false, plugin);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package com.willfp.eco.spigot.display;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import com.willfp.eco.spigot.ProxyUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PacketAutoRecipe extends AbstractPacketAdapter {
|
||||
}
|
||||
|
||||
try {
|
||||
InternalProxyUtils.getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle());
|
||||
ProxyUtils.getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
|
||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
|
||||
import com.willfp.eco.spigot.ProxyUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PacketChat extends AbstractPacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(InternalProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
|
||||
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
|
||||
packet.getChatComponents().write(i, newComponent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||
import com.willfp.eco.spigot.ProxyUtils;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@@ -35,7 +35,7 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
@NotNull final PacketEvent event) {
|
||||
List<MerchantRecipe> recipes = new ArrayList<>();
|
||||
|
||||
if (((EcoPlugin) this.getPlugin()).getConfigYml().getBool("villager-display-fix")) {
|
||||
if (this.getPlugin().getConfigYml().getBool("villager-display-fix")) {
|
||||
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||
ItemStack result = recipe.getResult();
|
||||
ItemMeta meta = result.getItemMeta();
|
||||
@@ -48,7 +48,7 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
}
|
||||
|
||||
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||
MerchantRecipe newRecipe = InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe);
|
||||
MerchantRecipe newRecipe = ProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe);
|
||||
recipes.add(newRecipe);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,7 @@ public class DispenserArmorListener implements Listener {
|
||||
@EventHandler
|
||||
public void dispenseArmorEvent(@NotNull final BlockDispenseArmorEvent event) {
|
||||
ArmorType type = ArmorType.matchType(event.getItem());
|
||||
if (type != null && event.getTargetEntity() instanceof Player) {
|
||||
Player p = (Player) event.getTargetEntity();
|
||||
if (type != null && event.getTargetEntity() instanceof Player p) {
|
||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p);
|
||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class EntityDeathByEntityListeners extends PluginDependent implements Listener {
|
||||
public class EntityDeathByEntityListeners extends PluginDependent<EcoPlugin> implements Listener {
|
||||
/**
|
||||
* The events currently being built.
|
||||
*/
|
||||
@@ -41,12 +41,10 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onEntityDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof LivingEntity victim)) {
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
||||
|
||||
if (victim.getHealth() > event.getFinalDamage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.core.events.PlayerJumpEvent;
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PlayerJumpListeners implements Listener {
|
||||
/**
|
||||
* For jump listeners.
|
||||
*/
|
||||
private static final Set<UUID> PREVIOUS_PLAYERS_ON_GROUND = new HashSet<>();
|
||||
|
||||
/**
|
||||
* For jump listeners.
|
||||
*/
|
||||
private static final DecimalFormat FORMAT = new DecimalFormat("0.00");
|
||||
|
||||
/**
|
||||
* Called when a player jumps.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onJump(@NotNull final PlayerMoveEvent event) {
|
||||
if (McmmoManager.isFake(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (player.getVelocity().getY() > 0) {
|
||||
float jumpVelocity = 0.42f;
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
jumpVelocity += ((float) player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.1F;
|
||||
}
|
||||
jumpVelocity = Float.parseFloat(FORMAT.format(jumpVelocity).replace(',', '.'));
|
||||
if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER
|
||||
&& PREVIOUS_PLAYERS_ON_GROUND.contains(player.getUniqueId())
|
||||
&& !player.isOnGround()
|
||||
&& Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerJumpEvent(event));
|
||||
}
|
||||
}
|
||||
if (player.isOnGround()) {
|
||||
PREVIOUS_PLAYERS_ON_GROUND.add(player.getUniqueId());
|
||||
} else {
|
||||
PREVIOUS_PLAYERS_ON_GROUND.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,18 @@ package com.willfp.eco.spigot.gui;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.gui.menu.FillerMask;
|
||||
import com.willfp.eco.core.gui.menu.Menu;
|
||||
import com.willfp.eco.core.gui.slot.Slot;
|
||||
import com.willfp.eco.internal.gui.EcoMenu;
|
||||
import com.willfp.eco.internal.gui.EcoSlot;
|
||||
import com.willfp.eco.internal.gui.MenuHandler;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GUIListener extends PluginDependent implements Listener {
|
||||
public class GUIListener extends PluginDependent<EcoPlugin> implements Listener {
|
||||
/**
|
||||
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||
*
|
||||
@@ -65,31 +60,4 @@ public class GUIListener extends PluginDependent implements Listener {
|
||||
|
||||
this.getPlugin().getScheduler().run(() -> MenuHandler.unregisterMenu(event.getInventory()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void test(@NotNull final AsyncPlayerChatEvent event) {
|
||||
String message = event.getMessage();
|
||||
if (!message.equals("guitest")) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getPlugin().getScheduler().run(() -> {
|
||||
Menu.builder(5)
|
||||
.setMask(new FillerMask(
|
||||
Material.BLACK_STAINED_GLASS_PANE,
|
||||
"111111111",
|
||||
"100000001",
|
||||
"100000001",
|
||||
"100000001",
|
||||
"111111111"
|
||||
))
|
||||
.setSlot(1, 3, Slot.builder(new ItemStack(Material.TNT))
|
||||
.onLeftClick((event1, slot) -> event1.getWhoClicked().sendMessage("CLICK"))
|
||||
.build())
|
||||
.setTitle("Poggers")
|
||||
.onClose(event1 -> event1.getPlayer().sendMessage("CLOSED"))
|
||||
.build()
|
||||
.open(event.getPlayer());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package com.willfp.eco.spigot.integrations.antigrief;
|
||||
|
||||
import com.SirBlobman.combatlogx.api.ICombatLogX;
|
||||
import com.SirBlobman.combatlogx.api.expansion.Expansion;
|
||||
import com.SirBlobman.combatlogx.api.expansion.ExpansionManager;
|
||||
import com.SirBlobman.combatlogx.expansion.newbie.helper.NewbieHelper;
|
||||
import com.SirBlobman.combatlogx.expansion.newbie.helper.listener.ListenerPVP;
|
||||
import com.willfp.eco.spigot.EcoSpigotPlugin;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -13,28 +13,19 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AntigriefCombatLogX implements AntigriefWrapper {
|
||||
import java.util.Optional;
|
||||
|
||||
public class AntigriefCombatLogXV10 implements AntigriefWrapper {
|
||||
/**
|
||||
* Instance of CombatLogX.
|
||||
*/
|
||||
private final ICombatLogX instance = (ICombatLogX) Bukkit.getPluginManager().getPlugin("CombatLogX");
|
||||
|
||||
/**
|
||||
* PVPManager for CombatLogX NewbieHelper.
|
||||
*/
|
||||
private ListenerPVP pvp = null;
|
||||
private final ICombatLogX instance;
|
||||
|
||||
/**
|
||||
* Create new CombatLogX antigrief.
|
||||
*/
|
||||
public AntigriefCombatLogX() {
|
||||
assert instance != null;
|
||||
EcoSpigotPlugin.getInstance().getScheduler().runLater(() -> {
|
||||
Expansion expansionUncast = instance.getExpansionManager().getExpansionByName("NewbieHelper").orElse(null);
|
||||
if (expansionUncast instanceof NewbieHelper) {
|
||||
pvp = ((NewbieHelper) expansionUncast).getPVPListener();
|
||||
}
|
||||
}, 3);
|
||||
public AntigriefCombatLogXV10() {
|
||||
this.instance = (ICombatLogX) Bukkit.getPluginManager().getPlugin("CombatLogX");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,11 +53,17 @@ public class AntigriefCombatLogX implements AntigriefWrapper {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pvp == null) {
|
||||
return true;
|
||||
// Only run checks if the NewbieHelper expansion is installed on the server.
|
||||
ExpansionManager expansionManager = this.instance.getExpansionManager();
|
||||
Optional<Expansion> optionalExpansion = expansionManager.getExpansionByName("NewbieHelper");
|
||||
if(optionalExpansion.isPresent()) {
|
||||
Expansion expansion = optionalExpansion.get();
|
||||
NewbieHelper newbieHelper = (NewbieHelper) expansion;
|
||||
ListenerPVP pvpListener = newbieHelper.getPVPListener();
|
||||
return (pvpListener.isPVPEnabled(player) && pvpListener.isPVPEnabled((Player) victim));
|
||||
}
|
||||
|
||||
return (pvp.isPVPEnabled(player) && pvp.isPVPEnabled((Player) victim));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.willfp.eco.spigot.integrations.antigrief;
|
||||
|
||||
import com.github.sirblobman.combatlogx.api.ICombatLogX;
|
||||
import com.github.sirblobman.combatlogx.api.expansion.Expansion;
|
||||
import com.github.sirblobman.combatlogx.api.expansion.ExpansionManager;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefWrapper;
|
||||
import combatlogx.expansion.newbie.helper.NewbieHelperExpansion;
|
||||
import combatlogx.expansion.newbie.helper.manager.PVPManager;
|
||||
import combatlogx.expansion.newbie.helper.manager.ProtectionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class AntigriefCombatLogXV11 implements AntigriefWrapper {
|
||||
/**
|
||||
* Instance of CombatLogX.
|
||||
*/
|
||||
private final ICombatLogX instance;
|
||||
|
||||
/**
|
||||
* Create new CombatLogX antigrief.
|
||||
*/
|
||||
public AntigriefCombatLogXV11() {
|
||||
this.instance = (ICombatLogX) Bukkit.getPluginManager().getPlugin("CombatLogX");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(@NotNull final Player player,
|
||||
@NotNull final Location location) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(@NotNull final Player player,
|
||||
@NotNull final LivingEntity victim) {
|
||||
if (!(victim instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only run checks if the NewbieHelper expansion is installed on the server.
|
||||
ExpansionManager expansionManager = this.instance.getExpansionManager();
|
||||
Optional<Expansion> optionalExpansion = expansionManager.getExpansion("NewbieHelper");
|
||||
if(optionalExpansion.isPresent()) {
|
||||
Expansion expansion = optionalExpansion.get();
|
||||
NewbieHelperExpansion newbieHelperExpansion = (NewbieHelperExpansion) expansion;
|
||||
|
||||
ProtectionManager protectionManager = newbieHelperExpansion.getProtectionManager();
|
||||
PVPManager pvpManager = newbieHelperExpansion.getPVPManager();
|
||||
|
||||
Player victimPlayer = (Player) victim;
|
||||
boolean victimProtected = protectionManager.isProtected(victimPlayer);
|
||||
boolean victimDisabledPvP = pvpManager.isDisabled(victimPlayer);
|
||||
boolean playerDisabledPvp = pvpManager.isDisabled(player);
|
||||
return (!victimProtected && !victimDisabledPvP && !playerDisabledPvp);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "CombatLogX";
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AntigriefLands extends PluginDependent implements AntigriefWrapper {
|
||||
public class AntigriefLands extends PluginDependent<EcoPlugin> implements AntigriefWrapper {
|
||||
/**
|
||||
* Lands integration.
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ public class McmmoIntegrationImpl implements McmmoWrapper {
|
||||
/**
|
||||
* Disabled if mcmmo is outdated or missing classes.
|
||||
*/
|
||||
boolean disabled = false;
|
||||
private boolean disabled = false;
|
||||
|
||||
/**
|
||||
* Initialize mcMMO integration.
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.willfp.eco.spigot.recipes;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.items.Items;
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import com.willfp.eco.core.recipe.Recipes;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.TestableStack;
|
||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
@@ -18,7 +21,16 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ShapedRecipeListener implements Listener {
|
||||
public class ShapedRecipeListener extends PluginDependent<EcoPlugin> implements Listener {
|
||||
/**
|
||||
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public ShapedRecipeListener(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
@@ -26,12 +38,10 @@ public class ShapedRecipeListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void complexRecipeListener(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
@@ -58,12 +68,10 @@ public class ShapedRecipeListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void complexRecipeListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
@@ -92,22 +100,52 @@ public class ShapedRecipeListener implements Listener {
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void stackedRecipeListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
CraftingRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getPlugin().getScheduler().runLater(() -> {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack inMatrix = event.getInventory().getMatrix()[i];
|
||||
TestableItem inRecipe = matched.getParts().get(i);
|
||||
|
||||
if (inRecipe instanceof TestableStack testableStack) {
|
||||
inMatrix.setAmount(inMatrix.getAmount() - (testableStack.getAmount() - 1));
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
||||
|
||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe)) {
|
||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe shapedCraftingRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedCraftingRecipe shapedCraftingRecipe = (ShapedCraftingRecipe) craftingRecipe;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
||||
@@ -127,20 +165,16 @@ public class ShapedRecipeListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
||||
|
||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe)) {
|
||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe shapedCraftingRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedCraftingRecipe shapedCraftingRecipe = (ShapedCraftingRecipe) craftingRecipe;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
||||
@@ -162,12 +196,10 @@ public class ShapedRecipeListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
@@ -187,12 +219,10 @@ public class ShapedRecipeListener implements Listener {
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
3
eco-core/core-plugin/src/main/resources/data.json
Normal file
3
eco-core/core-plugin/src/main/resources/data.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
multiple-in-craft: '&l&c! &fThis recipe requires &a%amount%&f of this item.'
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user