Compare commits
201 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd87683b6a | ||
|
|
83da1e7b95 | ||
|
|
9f9515675a | ||
|
|
1aa084cd90 | ||
|
|
525ec0260f | ||
|
|
ac15ffee6c | ||
|
|
83d68c5046 | ||
|
|
7d1186811f | ||
|
|
88bc01e5df | ||
|
|
78d2459c7a | ||
|
|
21f4bd79eb | ||
|
|
64147c6261 | ||
|
|
c67c486f2f | ||
|
|
ae419bacb3 | ||
|
|
17b0214f2f | ||
|
|
963f706018 | ||
|
|
74398cda62 | ||
|
|
8321af5af2 | ||
|
|
2524d86462 | ||
|
|
e050bf83df | ||
|
|
91c936a06f | ||
|
|
93dfd44410 | ||
|
|
304d0cdebf | ||
|
|
108d878939 | ||
|
|
e10e327c56 | ||
|
|
cabea9fba9 | ||
|
|
f9159cf245 | ||
|
|
2db011ae10 | ||
|
|
f96716966d | ||
|
|
7515efbde9 | ||
|
|
4ebd0d79d5 | ||
|
|
0c3b5d3c30 | ||
|
|
e0b06dedff | ||
|
|
187ac8163d | ||
|
|
ac2078957d | ||
|
|
352d495301 | ||
|
|
864456e61e | ||
|
|
bd7ce1cf3c | ||
|
|
9565ab0641 | ||
|
|
45c53b96dc | ||
|
|
861325ac3f | ||
|
|
70c015c1f0 | ||
|
|
8f3755b130 | ||
|
|
697ff0ccbb | ||
|
|
f117847fc3 | ||
|
|
bd88d40309 | ||
|
|
2fd8aab230 | ||
|
|
5ec10ec617 | ||
|
|
270270d015 | ||
|
|
3364b01c9d | ||
|
|
4beda35adf | ||
|
|
fd3e79378b | ||
|
|
4d0068e551 | ||
|
|
6933c0e5ef | ||
|
|
839b3724e7 | ||
|
|
6006865358 | ||
|
|
4907b4b6e6 | ||
|
|
29735cdf83 | ||
|
|
ae4b2ce0d0 | ||
|
|
786cbbcd7d | ||
|
|
6d3f2fc5dc | ||
|
|
6697cc412e | ||
|
|
17a877a89a | ||
|
|
9d4149c58f | ||
|
|
123ac79918 | ||
|
|
1670c8b3fb | ||
|
|
6125044e4c | ||
|
|
492439470c | ||
|
|
e9e39345ed | ||
|
|
cf29df7bce | ||
|
|
c259cb5a45 | ||
|
|
4148f55bb5 | ||
|
|
b63791c14b | ||
|
|
294dfabd54 | ||
|
|
d7f7cad863 | ||
|
|
afd8df5b48 | ||
|
|
b9d1f36604 | ||
|
|
403a7a7da8 | ||
|
|
f6fb5bcf66 | ||
|
|
194eb8b5f5 | ||
|
|
853aaca071 | ||
|
|
18dabd6bcf | ||
|
|
bb42505d66 | ||
|
|
b4d59077e3 | ||
|
|
104d55c11b | ||
|
|
b5af17cf08 | ||
|
|
78ae662ced | ||
|
|
32e48db3ce | ||
|
|
8a27e75c02 | ||
|
|
bf55e9b189 | ||
|
|
bfbaa3d033 | ||
|
|
64f87d5741 | ||
|
|
cb3441286c | ||
|
|
5e97a0f894 | ||
|
|
de2166dfdb | ||
|
|
abd361f4b5 | ||
|
|
422f8ead23 | ||
|
|
7c05dd7457 | ||
|
|
3ef7622c6f | ||
|
|
8207d62b1f | ||
|
|
75a0b1dd0d | ||
|
|
d1307e35db | ||
|
|
0a6b197a97 | ||
|
|
8d6512886c | ||
|
|
5c0c0f3e2a | ||
|
|
e2c2fc776a | ||
|
|
576050b31e | ||
|
|
f9a43bd336 | ||
|
|
203f2f599a | ||
|
|
baa5d37744 | ||
|
|
17f6af2a70 | ||
|
|
eae213f58e | ||
|
|
3a6a133560 | ||
|
|
57cf144c57 | ||
|
|
5c29859d49 | ||
|
|
02510127d1 | ||
|
|
f6b5c8f7e0 | ||
|
|
dbfef3094b | ||
|
|
b5c3af752c | ||
|
|
d0366b39e2 | ||
|
|
ed5390d2b5 | ||
|
|
e31857a15d | ||
|
|
32e119d187 | ||
|
|
5690eccd14 | ||
|
|
2faf3732df | ||
|
|
8670fb36e0 | ||
|
|
7c001c4809 | ||
|
|
bce1dd9fee | ||
|
|
412c2e1e3c | ||
|
|
dd7ffac974 | ||
|
|
7ad59e0166 | ||
|
|
2f2bdbb9f5 | ||
|
|
d23dc10bc5 | ||
|
|
46c2e3f90a | ||
|
|
1776b668a4 | ||
|
|
10dccd0f38 | ||
|
|
f1918eb1ec | ||
|
|
436b33fde2 | ||
|
|
cfa5cab1fa | ||
|
|
a8ba4dd812 | ||
|
|
94bf383d23 | ||
|
|
096207de82 | ||
|
|
3cb654f5df | ||
|
|
5552cc4fb0 | ||
|
|
94aacf8cca | ||
|
|
128d473b33 | ||
|
|
d5679dd58f | ||
|
|
b1e8165ecb | ||
|
|
d0a3d644f3 | ||
|
|
35b060af53 | ||
|
|
337dba23b4 | ||
|
|
433f9f53ab | ||
|
|
ba7a748efd | ||
|
|
1365fdae88 | ||
|
|
6a159bf049 | ||
|
|
31e0e93951 | ||
|
|
876343facb | ||
|
|
f0cd9ae16d | ||
|
|
b220428b8c | ||
|
|
8386aacfd8 | ||
|
|
3c54e24102 | ||
|
|
3dc0693b8c | ||
|
|
f087113ddf | ||
|
|
d5d1f5d8cc | ||
|
|
0d5bf901e2 | ||
|
|
ae0445f47b | ||
|
|
a6ba24b7a5 | ||
|
|
1b00831147 | ||
|
|
479cff60d5 | ||
|
|
d2499b1e27 | ||
|
|
4f65f33953 | ||
|
|
6d4a69c781 | ||
|
|
e90e58b50a | ||
|
|
826bdb63d0 | ||
|
|
4ecba69161 | ||
|
|
e64510ebf5 | ||
|
|
50a506af62 | ||
|
|
bdbbb7e40a | ||
|
|
f2503e989c | ||
|
|
11c54a0055 | ||
|
|
7cc24199fb | ||
|
|
068b2cca0c | ||
|
|
f67f01278e | ||
|
|
8be8e1dab2 | ||
|
|
6d3651aca1 | ||
|
|
3dd2c58595 | ||
|
|
255aa1dd54 | ||
|
|
f2c5b085e8 | ||
|
|
b8a5fe0031 | ||
|
|
5603890663 | ||
|
|
1a86cc4dbd | ||
|
|
734add6dbc | ||
|
|
5641c0def3 | ||
|
|
b74ab5349a | ||
|
|
b0971e5124 | ||
|
|
02d8c8c6b6 | ||
|
|
d9bd5257e3 | ||
|
|
c1a214f34e | ||
|
|
64d1fbb9b1 | ||
|
|
a5433fbb3f | ||
|
|
2a2aed52e0 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,7 +14,7 @@ bin/
|
||||
# Gradle
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
!eco-api/src/**/build/
|
||||
.gradletasknamecache
|
||||
!gradle-wrapper.jar
|
||||
gradle-app.setting
|
||||
|
||||
93
build.gradle
93
build.gradle
@@ -6,31 +6,17 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.apache.maven:maven-artifact:3.0.3'
|
||||
implementation 'org.bstats:bstats-bukkit:1.7'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
|
||||
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
|
||||
compileOnly 'com.github.cryptomorin:kingdoms:1.10.3.1'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
compileOnly fileTree(dir: 'lib', include: ['*.jar'])
|
||||
|
||||
// Lombok
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
implementation project(":eco-api")
|
||||
implementation project(":eco-core").getSubprojects()
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
repositories {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
@@ -39,7 +25,7 @@ repositories {
|
||||
// NMS (for jitpack compilation)
|
||||
maven { url 'https://repo.codemc.org/repository/nms/' }
|
||||
|
||||
// bStats
|
||||
// bStats, mcMMO
|
||||
maven { url 'https://repo.codemc.org/repository/maven-public' }
|
||||
|
||||
// Spigot API
|
||||
@@ -59,44 +45,55 @@ repositories {
|
||||
|
||||
// NoCheatPlus
|
||||
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
// CombatLogX
|
||||
maven { url 'https://nexus.sirblobman.xyz/repository/public/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
// Lombok
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
configurations.all {
|
||||
exclude group: "org.codehaus.plexus", module: "plexus-utils"
|
||||
exclude group: "com.mojang", module: "brigadier"
|
||||
exclude group: "org.kitteh", module: "paste-gg-api"
|
||||
exclude group: "org.spongepowered", module: "configurate-hocon"
|
||||
exclude group: "com.darkblade12", module: "particleeffect"
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.bstats.bukkit', 'com.willfp.eco.util.shaded.bstats')
|
||||
relocate('org.apache.maven', 'com.willfp.eco.util.shaded.maven')
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) {
|
||||
from components.java
|
||||
artifact shadowJar
|
||||
exclude group: "com.github.cryptomorin", module: "XSeries"
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.bstats.bukkit', 'com.willfp.eco.shaded.bstats')
|
||||
relocate('org.apache.maven', 'com.willfp.eco.shaded.maven')
|
||||
}
|
||||
|
||||
jar {
|
||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||
}
|
||||
|
||||
compileJava {
|
||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
build.dependsOn shadowJar
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
publishToMavenLocal.dependsOn shadowJar
|
||||
|
||||
build.dependsOn shadowJar
|
||||
build.dependsOn publishToMavenLocal
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = '1.1.2'
|
||||
version = findProperty("version")
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
@@ -115,7 +115,6 @@
|
||||
<!-- Checks for imports -->
|
||||
<!-- See https://checkstyle.org/config_imports.html -->
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||||
|
||||
<suppressions>
|
||||
<!-- Internals don't need javadoc. -->
|
||||
<suppress files="[\\/]internal[\\/]" checks="MissingJavadocMethod"/>
|
||||
<suppress files="[\\/]internal[\\/]" checks="JavadocVariable"/>
|
||||
|
||||
<!-- Modified version of library -->
|
||||
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
|
||||
<suppress files="ArmorEquipEvent.java" checks="MissingJavadocMethod"/>
|
||||
|
||||
25
eco-api/build.gradle
Normal file
25
eco-api/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.apache.maven:maven-artifact:3.0.3'
|
||||
compileOnly 'org.bstats:bstats-bukkit:1.7'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
build.dependsOn publishToMavenLocal
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) {
|
||||
from components.java
|
||||
artifact shadowJar
|
||||
artifactId 'eco'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.protocollib;
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
@@ -6,7 +6,6 @@ import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,7 +34,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* @param priority The priority at which the adapter should be ran on packet send/receive.
|
||||
* @param postLoad If the packet adapter should be registered after the server has loaded.
|
||||
*/
|
||||
protected AbstractPacketAdapter(@NotNull final AbstractEcoPlugin plugin,
|
||||
protected AbstractPacketAdapter(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final PacketType type,
|
||||
@NotNull final ListenerPriority priority,
|
||||
final boolean postLoad) {
|
||||
@@ -51,7 +50,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* @param type The {@link PacketType} to listen for.
|
||||
* @param postLoad If the packet adapter should be registered after the server has loaded.
|
||||
*/
|
||||
protected AbstractPacketAdapter(@NotNull final AbstractEcoPlugin plugin,
|
||||
protected AbstractPacketAdapter(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final PacketType type,
|
||||
final boolean postLoad) {
|
||||
this(plugin, type, ListenerPriority.NORMAL, postLoad);
|
||||
@@ -61,6 +60,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* The code that should be executed once the packet has been received.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
*/
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
@@ -71,6 +71,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* THe code that should be executed once the packet has been sent.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
*/
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
416
eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
Normal file
416
eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
Normal file
@@ -0,0 +1,416 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.config.base.ConfigYml;
|
||||
import com.willfp.eco.core.config.base.LangYml;
|
||||
import com.willfp.eco.internal.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.events.EventManager;
|
||||
import com.willfp.eco.core.extensions.ExtensionLoader;
|
||||
import com.willfp.eco.core.factory.MetadataValueFactory;
|
||||
import com.willfp.eco.core.factory.NamespacedKeyFactory;
|
||||
import com.willfp.eco.core.factory.RunnableFactory;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
import com.willfp.eco.internal.UpdateChecker;
|
||||
import com.willfp.eco.internal.arrows.ArrowDataListener;
|
||||
import com.willfp.eco.internal.events.EcoEventManager;
|
||||
import com.willfp.eco.internal.extensions.EcoExtensionLoader;
|
||||
import com.willfp.eco.internal.factory.EcoMetadataValueFactory;
|
||||
import com.willfp.eco.internal.factory.EcoNamespacedKeyFactory;
|
||||
import com.willfp.eco.internal.factory.EcoRunnableFactory;
|
||||
import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.internal.logging.EcoLogger;
|
||||
import com.willfp.eco.internal.scheduling.EcoScheduler;
|
||||
import lombok.Getter;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class EcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Loaded eco plugins.
|
||||
*/
|
||||
public static final List<String> LOADED_ECO_PLUGINS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The name of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private final String pluginName;
|
||||
|
||||
/**
|
||||
* The spigot resource ID of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private final int resourceId;
|
||||
|
||||
/**
|
||||
* The bStats resource ID of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private final int bStatsId;
|
||||
|
||||
/**
|
||||
* The package where proxy implementations are.
|
||||
*/
|
||||
@Getter
|
||||
private final String proxyPackage;
|
||||
|
||||
/**
|
||||
* The color of the plugin, used in messages.
|
||||
*/
|
||||
@Getter
|
||||
private final String color;
|
||||
|
||||
/**
|
||||
* Loaded integrations.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<String> loadedIntegrations = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Set of classes to be processed on config update.
|
||||
*/
|
||||
private final List<Class<?>> updatableClasses = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The internal plugin scheduler.
|
||||
*/
|
||||
@Getter
|
||||
private final Scheduler scheduler;
|
||||
|
||||
/**
|
||||
* The internal plugin Event Manager.
|
||||
*/
|
||||
@Getter
|
||||
private final EventManager eventManager;
|
||||
|
||||
/**
|
||||
* Config.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final ConfigYml configYml;
|
||||
|
||||
/**
|
||||
* Lang.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final LangYml langYml;
|
||||
|
||||
/**
|
||||
* The internal factory to produce {@link org.bukkit.NamespacedKey}s.
|
||||
*/
|
||||
@Getter
|
||||
private final NamespacedKeyFactory namespacedKeyFactory;
|
||||
|
||||
/**
|
||||
* The internal factory to produce {@link org.bukkit.metadata.FixedMetadataValue}s.
|
||||
*/
|
||||
@Getter
|
||||
private final MetadataValueFactory metadataValueFactory;
|
||||
|
||||
/**
|
||||
* The internal factory to produce {@link com.willfp.eco.core.scheduling.RunnableTask}s.
|
||||
*/
|
||||
@Getter
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
/**
|
||||
* The loader for all plugin extensions.
|
||||
*
|
||||
* @see com.willfp.eco.core.extensions.Extension
|
||||
*/
|
||||
@Getter
|
||||
private final ExtensionLoader extensionLoader;
|
||||
|
||||
/**
|
||||
* The handler class for updatable classes.
|
||||
*/
|
||||
@Getter
|
||||
private final ConfigHandler configHandler;
|
||||
|
||||
/**
|
||||
* The display module for the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private DisplayModule displayModule;
|
||||
|
||||
/**
|
||||
* The logger for the plugin.
|
||||
*/
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* If the server is running an outdated version of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private boolean outdated = 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)
|
||||
*/
|
||||
protected EcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this.pluginName = pluginName;
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
|
||||
this.scheduler = new EcoScheduler(this);
|
||||
this.eventManager = new EcoEventManager(this);
|
||||
this.namespacedKeyFactory = new EcoNamespacedKeyFactory(this);
|
||||
this.metadataValueFactory = new EcoMetadataValueFactory(this);
|
||||
this.runnableFactory = new EcoRunnableFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
this.logger = new EcoLogger(this);
|
||||
|
||||
this.langYml = new LangYml(this);
|
||||
this.configYml = new ConfigYml(this);
|
||||
|
||||
LOADED_ECO_PLUGINS.add(this.getName().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Default code to be executed on plugin enable.
|
||||
*/
|
||||
@Override
|
||||
public final void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
this.getLogger().info("");
|
||||
this.getLogger().info("Loading " + this.color + this.pluginName);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
new Metrics(this, this.bStatsId);
|
||||
|
||||
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
|
||||
|
||||
if (enabledPlugins.contains("PlaceholderAPI")) {
|
||||
this.loadedIntegrations.add("PlaceholderAPI");
|
||||
PlaceholderManager.addIntegration(new PlaceholderIntegrationPAPI(this));
|
||||
}
|
||||
|
||||
this.getIntegrationLoaders().forEach((integrationLoader -> {
|
||||
if (enabledPlugins.contains(integrationLoader.getPluginName())) {
|
||||
this.loadedIntegrations.add(integrationLoader.getPluginName());
|
||||
integrationLoader.load();
|
||||
}
|
||||
}));
|
||||
|
||||
this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
|
||||
|
||||
Prerequisite.update();
|
||||
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (!abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
|
||||
updatableClasses.addAll(this.getUpdatableClasses());
|
||||
|
||||
this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener));
|
||||
|
||||
this.getCommands().forEach(AbstractCommand::register);
|
||||
|
||||
this.getScheduler().runLater(this::afterLoad, 1);
|
||||
|
||||
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
|
||||
|
||||
this.enable();
|
||||
|
||||
this.getLogger().info("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Default code to be executed on plugin disable.
|
||||
*/
|
||||
@Override
|
||||
public final void onDisable() {
|
||||
super.onDisable();
|
||||
|
||||
this.getEventManager().unregisterAllListeners();
|
||||
this.getScheduler().cancelAll();
|
||||
|
||||
this.disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default code to be executed on plugin load.
|
||||
*/
|
||||
@Override
|
||||
public final void onLoad() {
|
||||
super.onLoad();
|
||||
|
||||
this.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default code to be executed after the server is up.
|
||||
*/
|
||||
public final void afterLoad() {
|
||||
this.displayModule = createDisplayModule();
|
||||
|
||||
if (this.getDisplayModule() != null) {
|
||||
Display.registerDisplayModule(this.getDisplayModule());
|
||||
}
|
||||
|
||||
this.getPacketAdapters().forEach(abstractPacketAdapter -> {
|
||||
if (abstractPacketAdapter.isPostLoad()) {
|
||||
abstractPacketAdapter.register();
|
||||
}
|
||||
});
|
||||
|
||||
if (!Prerequisite.HAS_PAPER.isMet()) {
|
||||
this.getLogger().severe("");
|
||||
this.getLogger().severe("----------------------------");
|
||||
this.getLogger().severe("");
|
||||
this.getLogger().severe("You don't seem to be running paper!");
|
||||
this.getLogger().severe("Paper is strongly recommended for all servers,");
|
||||
this.getLogger().severe("and some things may not function properly without it");
|
||||
this.getLogger().severe("Download Paper from &fhttps://papermc.io");
|
||||
this.getLogger().severe("");
|
||||
this.getLogger().severe("----------------------------");
|
||||
this.getLogger().severe("");
|
||||
}
|
||||
|
||||
this.postLoad();
|
||||
|
||||
this.reload();
|
||||
|
||||
this.getLogger().info("Loaded " + this.color + this.pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default code to be executed on plugin reload.
|
||||
*/
|
||||
public final void reload() {
|
||||
this.getConfigYml().update();
|
||||
this.getLangYml().update();
|
||||
|
||||
this.getConfigHandler().callUpdate();
|
||||
this.getConfigHandler().callUpdate(); // Call twice to fix issues
|
||||
this.getScheduler().cancelAll();
|
||||
|
||||
this.onReload();
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on enable.
|
||||
*/
|
||||
public abstract void enable();
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on disable.
|
||||
*/
|
||||
public abstract void disable();
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on load.
|
||||
*/
|
||||
public abstract void load();
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed on reload.
|
||||
*/
|
||||
public abstract void onReload();
|
||||
|
||||
/**
|
||||
* The plugin-specific code to be executed after the server is up.
|
||||
*/
|
||||
public abstract void postLoad();
|
||||
|
||||
/**
|
||||
* The plugin-specific integrations to be tested and loaded.
|
||||
*
|
||||
* @return A list of integrations.
|
||||
*/
|
||||
public abstract List<IntegrationLoader> getIntegrationLoaders();
|
||||
|
||||
/**
|
||||
* The command to be registered.
|
||||
*
|
||||
* @return A list of commands.
|
||||
*/
|
||||
public abstract List<AbstractCommand> getCommands();
|
||||
|
||||
/**
|
||||
* ProtocolLib packet adapters to be registered.
|
||||
* <p>
|
||||
* If the plugin does not require ProtocolLib this can be left empty.
|
||||
*
|
||||
* @return A list of packet adapters.
|
||||
*/
|
||||
public abstract List<AbstractPacketAdapter> getPacketAdapters();
|
||||
|
||||
/**
|
||||
* All listeners to be registered.
|
||||
*
|
||||
* @return A list of all listeners.
|
||||
*/
|
||||
public abstract List<Listener> getListeners();
|
||||
|
||||
/**
|
||||
* All updatable classes.
|
||||
*
|
||||
* @return A list of all updatable classes.
|
||||
*/
|
||||
public abstract List<Class<?>> getUpdatableClasses();
|
||||
|
||||
/**
|
||||
* Create the display module for the plugin.
|
||||
*
|
||||
* @return The display module, or null.
|
||||
*/
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class PluginDependent {
|
||||
/**
|
||||
* The {@link EcoPlugin} that is stored.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
protected PluginDependent(@NotNull final EcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.willfp.eco.util.optional;
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.util.ClassUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -15,15 +14,6 @@ public class Prerequisite {
|
||||
* All existing prerequisites are registered on creation.
|
||||
*/
|
||||
private static final List<Prerequisite> VALUES = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Requires the server to be running minecraft version 1.16 or higher.
|
||||
*/
|
||||
public static final Prerequisite MINIMUM_1_16 = new Prerequisite(
|
||||
() -> !Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].contains("15"),
|
||||
"Requires minimum server version of 1.16"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running an implementation of paper.
|
||||
*/
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.willfp.eco.util.command;
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -16,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor, Registerable {
|
||||
public abstract class AbstractCommand extends PluginDependent implements CommandExecutor {
|
||||
/**
|
||||
* The name of the command
|
||||
* <p>
|
||||
@@ -45,12 +43,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
* <p>
|
||||
* The name cannot be the same as an existing command as this will conflict.
|
||||
*
|
||||
* @param plugin The owning {@link AbstractEcoPlugin}.
|
||||
* @param plugin The owning {@link EcoPlugin}.
|
||||
* @param name The name used in execution.
|
||||
* @param permission The permission required to execute the command.
|
||||
* @param playersOnly If only players should be able to execute this command.
|
||||
*/
|
||||
protected AbstractCommand(@NotNull final AbstractEcoPlugin plugin,
|
||||
protected AbstractCommand(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String name,
|
||||
@NotNull final String permission,
|
||||
final boolean playersOnly) {
|
||||
@@ -100,7 +98,7 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
* @param command The bukkit command.
|
||||
* @param label The name of the executed command.
|
||||
* @param args The arguments of the command (anything after the physical command name)
|
||||
* @return If the command was processed by the linked {@link AbstractEcoPlugin}
|
||||
* @return If the command was processed by the linked {@link EcoPlugin}
|
||||
*/
|
||||
@Override
|
||||
public final boolean onCommand(@NotNull final CommandSender sender,
|
||||
@@ -112,12 +110,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
}
|
||||
|
||||
if (playersOnly && !(sender instanceof Player)) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("not-player"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("not-player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(permission) && sender instanceof Player) {
|
||||
sender.sendMessage(Configs.LANG.getNoPermission());
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getNoPermission());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -131,7 +129,6 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
* <p>
|
||||
* Requires the command name to exist, defined in plugin.yml.
|
||||
*/
|
||||
@Override
|
||||
public final void register() {
|
||||
PluginCommand command = Bukkit.getPluginCommand(name);
|
||||
assert command != null;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.command;
|
||||
package com.willfp.eco.core.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.UpdatableYamlConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BaseConfig extends UpdatableYamlConfig {
|
||||
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||
* <p>
|
||||
* Automatically updates.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param plugin The plugin.
|
||||
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||
*/
|
||||
protected BaseConfig(@NotNull final String configName,
|
||||
final boolean removeUnused,
|
||||
@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String... updateBlacklist) {
|
||||
super(configName, plugin, "", plugin.getClass(), removeUnused, updateBlacklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||
* <p>
|
||||
* Automatically updates.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected BaseConfig(@NotNull final String configName,
|
||||
final boolean removeUnused,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
super(configName, plugin, "", plugin.getClass(), removeUnused, "");
|
||||
}
|
||||
}
|
||||
219
eco-api/src/main/java/com/willfp/eco/core/config/Config.java
Normal file
219
eco-api/src/main/java/com/willfp/eco/core/config/Config.java
Normal file
@@ -0,0 +1,219 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Config {
|
||||
/**
|
||||
* Clears cache.
|
||||
*/
|
||||
void clearCache();
|
||||
|
||||
/**
|
||||
* Get if the config contains a key.
|
||||
*
|
||||
* @param path The key to check.
|
||||
* @return If contained.
|
||||
*/
|
||||
boolean has(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get config keys.
|
||||
*
|
||||
* @param deep If keys from subsections should be fetched too.
|
||||
* @return A list of keys.
|
||||
*/
|
||||
@NotNull
|
||||
List<String> getKeys(boolean deep);
|
||||
|
||||
/**
|
||||
* Get an object from config.
|
||||
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#get(String)}.
|
||||
*
|
||||
* @param path The path.
|
||||
* @return The object.
|
||||
*/
|
||||
@Nullable
|
||||
Object get(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Set an object in config.
|
||||
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#set(String, Object)}
|
||||
*
|
||||
* @param path The path.
|
||||
* @param object The object.
|
||||
*/
|
||||
void set(@NotNull String path,
|
||||
@Nullable Object object);
|
||||
|
||||
/**
|
||||
* Get subsection from config.
|
||||
*
|
||||
* @param path The key to check.
|
||||
* @return The subsection. Throws NPE if not found.
|
||||
*/
|
||||
@NotNull
|
||||
Config getSubsection(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get subsection from config.
|
||||
*
|
||||
* @param path The key to check.
|
||||
* @return The subsection, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
Config getSubsectionOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get an integer from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
int getInt(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get an integer from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
Integer getIntOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get an integer from config with a specified default (not found) value.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @param def The value to default to if not found.
|
||||
* @return The found value, or the default.
|
||||
*/
|
||||
int getInt(@NotNull String path,
|
||||
int def);
|
||||
|
||||
/**
|
||||
* Get a list of integers from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
List<Integer> getInts(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of integers from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<Integer> getIntsOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a boolean from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or false if not found.
|
||||
*/
|
||||
boolean getBool(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a boolean from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
Boolean getBoolOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of booleans from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
List<Boolean> getBools(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of booleans from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<Boolean> getBoolsOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a string from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or an empty string if not found.
|
||||
*/
|
||||
@NotNull
|
||||
String getString(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a string from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
String getStringOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of strings from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
List<String> getStrings(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of strings from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<String> getStringsOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a decimal from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
double getDouble(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a decimal from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
Double getDoubleOrNull(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of decimals from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
List<Double> getDoubles(@NotNull String path);
|
||||
|
||||
/**
|
||||
* Get a list of decimals from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
List<Double> getDoublesOrNull(@NotNull String path);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.config.updating.annotations;
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.UpdatableYamlConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class ExtendableConfig extends UpdatableYamlConfig {
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||
* <p>
|
||||
* Automatically updates.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param plugin The plugin.
|
||||
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||
* @param subDirectoryPath The subdirectory path.
|
||||
* @param source The class that owns the resource.
|
||||
*/
|
||||
protected ExtendableConfig(@NotNull final String configName,
|
||||
final boolean removeUnused,
|
||||
@NotNull final EcoPlugin plugin,
|
||||
@NotNull final Class<?> source,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final String... updateBlacklist) {
|
||||
super(configName, plugin, subDirectoryPath, source, removeUnused, updateBlacklist);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.LoadableYamlConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class StaticBaseConfig extends LoadableYamlConfig {
|
||||
/**
|
||||
* Config implementation for configs present in the plugin's base directory (eg config.yml, lang.yml).
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected StaticBaseConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin) {
|
||||
super(configName, plugin, "", plugin.getClass());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.willfp.eco.core.config;
|
||||
|
||||
import com.willfp.eco.internal.config.ConfigWrapper;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class YamlConfig extends ConfigWrapper<YamlConfiguration> {
|
||||
/**
|
||||
* Config implementation for passing YamlConfigurations.
|
||||
* <p>
|
||||
* Does not automatically update.
|
||||
*
|
||||
* @param config The YamlConfiguration handle.
|
||||
*/
|
||||
public YamlConfig(@NotNull final YamlConfiguration config) {
|
||||
init(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.core.config.base;
|
||||
|
||||
import com.willfp.eco.core.config.BaseConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ConfigYml extends BaseConfig {
|
||||
/**
|
||||
* Config.yml.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public ConfigYml(@NotNull final EcoPlugin plugin) {
|
||||
super("config", true, plugin);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.willfp.eco.util.config.configs;
|
||||
package com.willfp.eco.core.config.base;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.core.config.BaseConfig;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Lang extends BaseConfig {
|
||||
public class LangYml extends BaseConfig {
|
||||
/**
|
||||
* lang.yml.
|
||||
* Lang.yml.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public Lang() {
|
||||
super("lang", false);
|
||||
public LangYml(@NotNull final EcoPlugin plugin) {
|
||||
super("lang", false, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,7 +20,7 @@ public class Lang extends BaseConfig {
|
||||
* @return The prefix.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return StringUtils.translate(this.getConfig().getString("messages.prefix"));
|
||||
return this.getString("messages.prefix");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,7 +29,7 @@ public class Lang extends BaseConfig {
|
||||
* @return The message.
|
||||
*/
|
||||
public String getNoPermission() {
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages.no-permission"));
|
||||
return getPrefix() + this.getString("messages.no-permission");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,6 +39,6 @@ public class Lang extends BaseConfig {
|
||||
* @return The message with a prefix appended.
|
||||
*/
|
||||
public String getMessage(@NotNull final String message) {
|
||||
return getPrefix() + StringUtils.translate(this.getConfig().getString("messages." + message));
|
||||
return getPrefix() + this.getString("messages." + message);
|
||||
}
|
||||
}
|
||||
216
eco-api/src/main/java/com/willfp/eco/core/display/Display.java
Normal file
216
eco-api/src/main/java/com/willfp/eco/core/display/Display.java
Normal file
@@ -0,0 +1,216 @@
|
||||
package com.willfp.eco.core.display;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class Display {
|
||||
/**
|
||||
* The prefix for lore lines.
|
||||
*/
|
||||
public static final String PREFIX = "§z";
|
||||
|
||||
/**
|
||||
* All registered display modules.
|
||||
*/
|
||||
private static final Map<DisplayPriority, List<DisplayModule>> MODULES = new HashMap<>();
|
||||
|
||||
/**
|
||||
* NamespacedKey for finalizing.
|
||||
*/
|
||||
private static NamespacedKey finalizeKey = null;
|
||||
|
||||
/**
|
||||
* Register display module.
|
||||
*
|
||||
* @param module The module.
|
||||
*/
|
||||
public void registerDisplayModule(@NotNull final DisplayModule module) {
|
||||
List<DisplayModule> modules = MODULES.get(module.getPriority());
|
||||
|
||||
modules.removeIf(module1 -> module1.getPluginName().equalsIgnoreCase(module.getPluginName()));
|
||||
|
||||
modules.add(module);
|
||||
|
||||
MODULES.put(module.getPriority(), modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display on ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack display(@NotNull final ItemStack itemStack) {
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return itemStack; // return early if there's no customization of the item
|
||||
}
|
||||
|
||||
Map<String, Object[]> pluginVarArgs = new HashMap<>();
|
||||
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
List<DisplayModule> modules = MODULES.get(priority);
|
||||
for (DisplayModule module : modules) {
|
||||
pluginVarArgs.put(module.getPluginName(), module.generateVarArgs(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
revert(itemStack);
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
List<DisplayModule> modules = MODULES.get(priority);
|
||||
for (DisplayModule module : modules) {
|
||||
Object[] varargs = pluginVarArgs.get(module.getPluginName());
|
||||
module.display(itemStack, varargs);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display on ItemStacks and then finalize.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
||||
return finalize(display(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert on ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack revert(@NotNull final ItemStack itemStack) {
|
||||
if (Display.isFinalized(itemStack)) {
|
||||
unfinalize(itemStack);
|
||||
}
|
||||
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
List<String> lore = meta.getLore();
|
||||
|
||||
if (lore != null && lore.removeIf(line -> line.startsWith(Display.PREFIX))) { // only apply lore modification if needed
|
||||
meta.setLore(lore);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
List<DisplayModule> modules = MODULES.get(priority);
|
||||
for (DisplayModule module : modules) {
|
||||
module.revert(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
|
||||
if (itemStack.getType().getMaxStackSize() > 1) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(finalizeKey, PersistentDataType.INTEGER, 1);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unfinalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The itemstack.
|
||||
*/
|
||||
public ItemStack unfinalize(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.remove(finalizeKey);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* If an item is finalized.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return If finalized.
|
||||
*/
|
||||
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
||||
Validate.notNull(finalizeKey, "Key cannot be null!");
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
return container.has(finalizeKey, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set key to be used for finalization.
|
||||
*
|
||||
* @param finalizeKey The key.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void setFinalizeKey(@NotNull final NamespacedKey finalizeKey) {
|
||||
Display.finalizeKey = finalizeKey;
|
||||
}
|
||||
|
||||
static {
|
||||
for (DisplayPriority priority : DisplayPriority.values()) {
|
||||
MODULES.put(priority, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.willfp.eco.core.display;
|
||||
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class DisplayModule extends PluginDependent {
|
||||
/**
|
||||
* The priority of the module.
|
||||
*/
|
||||
@Getter
|
||||
private final DisplayPriority priority;
|
||||
|
||||
/**
|
||||
* Create a new display module.
|
||||
*
|
||||
* @param plugin The plugin that the display is for.
|
||||
* @param priority The priority of the module.
|
||||
*/
|
||||
protected DisplayModule(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final DisplayPriority priority) {
|
||||
super(plugin);
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an item.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @param args Optional args for display.
|
||||
*/
|
||||
protected void display(@NotNull final ItemStack itemStack,
|
||||
@NotNull final Object... args) {
|
||||
// Technically optional.
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert an item.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
protected void revert(@NotNull final ItemStack itemStack) {
|
||||
// Technically optional.
|
||||
}
|
||||
|
||||
/**
|
||||
* Create varargs to pass back to itemstack after reverting, but before display.
|
||||
*
|
||||
* @param itemStack The itemStack.
|
||||
* @return The plugin-specific varargs.
|
||||
*/
|
||||
protected Object[] generateVarArgs(@NotNull final ItemStack itemStack) {
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of plugin.
|
||||
*
|
||||
* @return The plugin name.
|
||||
*/
|
||||
final String getPluginName() {
|
||||
return super.getPlugin().getPluginName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.core.display;
|
||||
|
||||
public enum DisplayPriority {
|
||||
/**
|
||||
* Ran first.
|
||||
*/
|
||||
LOWEST,
|
||||
|
||||
/**
|
||||
* Ran second.
|
||||
*/
|
||||
LOW,
|
||||
|
||||
/**
|
||||
* Ran third.
|
||||
*/
|
||||
HIGH,
|
||||
|
||||
/**
|
||||
* Ran last.
|
||||
*/
|
||||
HIGHEST
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.willfp.eco.util.drops;
|
||||
package com.willfp.eco.core.drops;
|
||||
|
||||
import com.willfp.eco.util.drops.internal.AbstractDropQueue;
|
||||
import com.willfp.eco.util.drops.internal.DropManager;
|
||||
import com.willfp.eco.util.drops.internal.DropQueueType;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.drops.internal.InternalDropQueue;
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import com.willfp.eco.internal.drops.DropManager;
|
||||
import com.willfp.eco.internal.drops.DropQueueType;
|
||||
import com.willfp.eco.internal.drops.impl.FastCollatedDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.InternalDropQueue;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ArmorEquipEvent extends PlayerEvent {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public ArmorEquipEvent(@NotNull final Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of handlers handling this event.
|
||||
*
|
||||
* @return A list of handlers handling this event.
|
||||
*/
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.entitydeathbyentity;
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.bukkit.events;
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.naturalexpgainevent;
|
||||
package com.willfp.eco.core.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -1,18 +1,27 @@
|
||||
package com.willfp.eco.util.extensions;
|
||||
package com.willfp.eco.core.extensions;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.internal.extensions.ExtensionMetadata;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Extension {
|
||||
/**
|
||||
* The {@link AbstractEcoPlugin} that this extension is for.
|
||||
* The {@link EcoPlugin} that this extension is for.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new extension for a plugin.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected Extension(@NotNull final EcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata containing version and name.
|
||||
@@ -62,7 +71,7 @@ public abstract class Extension {
|
||||
*/
|
||||
public final String getName() {
|
||||
Validate.notNull(metadata, "Metadata cannot be null!");
|
||||
return this.metadata.name;
|
||||
return this.metadata.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,36 +81,6 @@ public abstract class Extension {
|
||||
*/
|
||||
public final String getVersion() {
|
||||
Validate.notNull(metadata, "Metadata cannot be null!");
|
||||
return this.metadata.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for the string and version of the extension.
|
||||
* Contains versions and name.
|
||||
* Designed for internal use.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static final class ExtensionMetadata {
|
||||
/**
|
||||
* The version of the extension.
|
||||
*/
|
||||
private final @NotNull String version;
|
||||
|
||||
/**
|
||||
* The extension's name.
|
||||
*/
|
||||
private final @NotNull String name;
|
||||
|
||||
/**
|
||||
* Create a new extension metadata.
|
||||
*
|
||||
* @param version The version for the extension to be.
|
||||
* @param name The name of the extension.
|
||||
*/
|
||||
public ExtensionMetadata(@NotNull final String version,
|
||||
@NotNull final String name) {
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
}
|
||||
return this.metadata.getVersion();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
package com.willfp.eco.util.extensions.loader;
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
package com.willfp.eco.core.extensions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -20,11 +18,6 @@ public interface ExtensionLoader {
|
||||
*/
|
||||
void unloadExtensions();
|
||||
|
||||
/**
|
||||
* Reload all extensions.
|
||||
*/
|
||||
void reloadExtensions();
|
||||
|
||||
/**
|
||||
* Retrieve a set of all loaded extensions.
|
||||
*
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.extensions;
|
||||
package com.willfp.eco.core.extensions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.willfp.eco.core.factory;
|
||||
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface MetadataValueFactory {
|
||||
FixedMetadataValue create(@NotNull Object value);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.core.factory;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface NamespacedKeyFactory {
|
||||
/**
|
||||
* Create an {@link NamespacedKey} associated with an {@link com.willfp.eco.core.EcoPlugin}.
|
||||
*
|
||||
* @param key The key in the {@link NamespacedKey}.
|
||||
* @return The created {@link NamespacedKey}.
|
||||
*/
|
||||
NamespacedKey create(@NotNull String key);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.core.factory;
|
||||
|
||||
import com.willfp.eco.core.scheduling.RunnableTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface RunnableFactory {
|
||||
/**
|
||||
* Create a {@link RunnableTask}.
|
||||
*
|
||||
* @param consumer Lambda of the code to run, where the parameter represents the instance of the runnable.
|
||||
* @return The created {@link RunnableTask}.
|
||||
*/
|
||||
RunnableTask create(@NotNull Consumer<RunnableTask> consumer);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations;
|
||||
package com.willfp.eco.core.integrations;
|
||||
|
||||
public interface Integration {
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations;
|
||||
package com.willfp.eco.core.integrations;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.integrations.anticheat;
|
||||
package com.willfp.eco.core.integrations.anticheat;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -11,11 +11,6 @@ import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class AnticheatManager {
|
||||
/**
|
||||
* The linked {@link AbstractEcoPlugin} to register anticheat listeners to.
|
||||
*/
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* A set of all registered anticheats.
|
||||
*/
|
||||
@@ -24,9 +19,11 @@ public class AnticheatManager {
|
||||
/**
|
||||
* Register a new anticheat.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param anticheat The anticheat to register.
|
||||
*/
|
||||
public void register(@NotNull final AnticheatWrapper anticheat) {
|
||||
public void register(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final AnticheatWrapper anticheat) {
|
||||
if (anticheat instanceof Listener) {
|
||||
plugin.getEventManager().registerListener((Listener) anticheat);
|
||||
}
|
||||
@@ -49,8 +46,6 @@ public class AnticheatManager {
|
||||
* @param player The player to remove the exemption.
|
||||
*/
|
||||
public void unexemptPlayer(@NotNull final Player player) {
|
||||
plugin.getScheduler().runLater(() -> {
|
||||
anticheats.forEach(anticheat -> anticheat.unexempt(player));
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.integrations.anticheat;
|
||||
package com.willfp.eco.core.integrations.anticheat;
|
||||
|
||||
import com.willfp.eco.util.integrations.Integration;
|
||||
import com.willfp.eco.core.integrations.Integration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.antigrief;
|
||||
package com.willfp.eco.core.integrations.antigrief;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Location;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.integrations.antigrief;
|
||||
package com.willfp.eco.core.integrations.antigrief;
|
||||
|
||||
import com.willfp.eco.util.integrations.Integration;
|
||||
import com.willfp.eco.core.integrations.Integration;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.willfp.eco.core.integrations.mcmmo;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class McmmoManager {
|
||||
/**
|
||||
* A set of all registered integrations.
|
||||
*/
|
||||
private final Set<McmmoWrapper> regsistered = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new integration.
|
||||
*
|
||||
* @param integration The integration to register.
|
||||
*/
|
||||
public void register(@NotNull final McmmoWrapper integration) {
|
||||
regsistered.add(integration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bonus drop count from block.
|
||||
*
|
||||
* @param block The block.
|
||||
* @return The bonus drop count.
|
||||
*/
|
||||
public int getBonusDropCount(@NotNull final Block block) {
|
||||
for (McmmoWrapper mcmmoWrapper : regsistered) {
|
||||
return mcmmoWrapper.getBonusDropCount(block);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if event is fake.
|
||||
*
|
||||
* @param event The event to check.
|
||||
* @return If the event is fake.
|
||||
*/
|
||||
public boolean isFake(@NotNull final Event event) {
|
||||
for (McmmoWrapper mcmmoWrapper : regsistered) {
|
||||
return mcmmoWrapper.isFake(event);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.core.integrations.mcmmo;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface McmmoWrapper {
|
||||
/**
|
||||
* Get bonus drop count of block.
|
||||
*
|
||||
* @param block The block.
|
||||
* @return The drop multiplier.
|
||||
*/
|
||||
int getBonusDropCount(@NotNull Block block);
|
||||
|
||||
/**
|
||||
* Get if event is fake.
|
||||
*
|
||||
* @param event The event.
|
||||
* @return If is fake.
|
||||
*/
|
||||
boolean isFake(@NotNull Event event);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.placeholder;
|
||||
package com.willfp.eco.core.integrations.placeholder;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.integrations.placeholder;
|
||||
package com.willfp.eco.core.integrations.placeholder;
|
||||
|
||||
import com.willfp.eco.util.integrations.Integration;
|
||||
import com.willfp.eco.core.integrations.Integration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.placeholder;
|
||||
package com.willfp.eco.core.integrations.placeholder;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CustomItem implements TestableItem {
|
||||
/**
|
||||
* The key.
|
||||
*/
|
||||
@Getter
|
||||
private final NamespacedKey key;
|
||||
|
||||
/**
|
||||
* The test for ItemStacks to pass.
|
||||
*/
|
||||
private final Predicate<ItemStack> test;
|
||||
|
||||
/**
|
||||
* Example Item: what the user should see.
|
||||
*/
|
||||
private final ItemStack item;
|
||||
|
||||
/**
|
||||
* Create a new complex recipe part.
|
||||
*
|
||||
* @param key The item key.
|
||||
* @param test The test.
|
||||
* @param item The example ItemStacks.
|
||||
*/
|
||||
public CustomItem(@NotNull final NamespacedKey key,
|
||||
@NotNull final Predicate<ItemStack> test,
|
||||
@NotNull final ItemStack item) {
|
||||
this.key = key;
|
||||
this.test = test;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return test.test(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the item.
|
||||
*/
|
||||
public void register() {
|
||||
Items.registerCustomItem(this.getKey(), this);
|
||||
}
|
||||
}
|
||||
69
eco-api/src/main/java/com/willfp/eco/core/items/Items.java
Normal file
69
eco-api/src/main/java/com/willfp/eco/core/items/Items.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class Items {
|
||||
/**
|
||||
* All recipe parts.
|
||||
*/
|
||||
private static final Map<NamespacedKey, CustomItem> REGISTRY = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Register a new recipe part.
|
||||
*
|
||||
* @param key The key of the recipe part.
|
||||
* @param part The recipe part.
|
||||
*/
|
||||
public void registerCustomItem(@NotNull final NamespacedKey key,
|
||||
@NotNull final CustomItem part) {
|
||||
REGISTRY.put(key, part);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup item from string.
|
||||
* <p>
|
||||
* Used for recipes.
|
||||
*
|
||||
* @param key The string to test.
|
||||
* @return The found testable item, or an empty item if not found.
|
||||
*/
|
||||
public TestableItem lookup(@NotNull final String key) {
|
||||
String[] split = key.toLowerCase().split(":");
|
||||
if (split.length == 1) {
|
||||
Material material = Material.getMaterial(key.toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
return new MaterialTestableItem(material);
|
||||
}
|
||||
|
||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||
return part == null ? new EmptyTestableItem() : part;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if itemStack is a custom item.
|
||||
*
|
||||
* @param itemStack The itemStack to check.
|
||||
* @return If is recipe.
|
||||
*/
|
||||
public boolean isCustomItem(@NotNull final ItemStack itemStack) {
|
||||
for (CustomItem item : REGISTRY.values()) {
|
||||
if (item.matches(itemStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface TestableItem {
|
||||
/**
|
||||
* If an ItemStack matches the recipe part.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item matches.
|
||||
*/
|
||||
boolean matches(@Nullable ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get an example item.
|
||||
*
|
||||
* @return The item.
|
||||
*/
|
||||
ItemStack getItem();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.core.proxy;
|
||||
|
||||
public interface AbstractProxy {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.core.proxy;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.core.proxy;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.willfp.eco.core.recipe;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Recipes {
|
||||
/**
|
||||
* Registry of all recipes.
|
||||
*/
|
||||
private static final BiMap<NamespacedKey, CraftingRecipe> RECIPES = HashBiMap.create();
|
||||
|
||||
|
||||
/**
|
||||
* Register a recipe.
|
||||
*
|
||||
* @param recipe The recipe.
|
||||
*/
|
||||
public void register(@NotNull final CraftingRecipe recipe) {
|
||||
RECIPES.forcePut(recipe.getKey(), recipe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipe matching matrix.
|
||||
*
|
||||
* @param matrix The matrix to test.
|
||||
* @return The match, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public CraftingRecipe getMatch(@NotNull final ItemStack[] matrix) {
|
||||
return RECIPES.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipe by key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @return The recipe, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public CraftingRecipe getRecipe(@NotNull final NamespacedKey key) {
|
||||
CraftingRecipe recipe = RECIPES.get(key);
|
||||
if (recipe != null) {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
if (key.getKey().contains("_displayed")) {
|
||||
NamespacedKey otherKey = new NamespacedKey(key.getNamespace(), key.getKey().replace("_displayed", ""));
|
||||
|
||||
return RECIPES.get(otherKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.willfp.eco.core.recipe.parts;
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EmptyTestableItem implements TestableItem {
|
||||
/**
|
||||
* Create a new empty recipe part.
|
||||
*/
|
||||
public EmptyTestableItem() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item is empty.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is empty.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack == null || itemStack.getType() == Material.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.core.recipe.parts;
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MaterialTestableItem implements TestableItem {
|
||||
/**
|
||||
* The material.
|
||||
*/
|
||||
@Getter
|
||||
private final Material material;
|
||||
|
||||
/**
|
||||
* Create a new simple recipe part.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public MaterialTestableItem(@NotNull final Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 && itemStack.getType() == material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return new ItemStack(material);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.willfp.eco.core.recipe.recipes;
|
||||
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CraftingRecipe {
|
||||
/**
|
||||
* Test matrix against recipe.
|
||||
*
|
||||
* @param matrix The matrix to check.
|
||||
* @return If the recipe matches.
|
||||
*/
|
||||
boolean test(@NotNull ItemStack[] matrix);
|
||||
|
||||
/**
|
||||
* Register the recipe.
|
||||
*/
|
||||
void register();
|
||||
|
||||
/**
|
||||
* The recipe parts.
|
||||
*
|
||||
* @return The parts.
|
||||
*/
|
||||
List<TestableItem> getParts();
|
||||
|
||||
/**
|
||||
* Get the recipe key.
|
||||
*
|
||||
* @return The key.
|
||||
*/
|
||||
NamespacedKey getKey();
|
||||
|
||||
/**
|
||||
* Get the displayed recipe key.
|
||||
*
|
||||
* @return The key.
|
||||
*/
|
||||
NamespacedKey getDisplayedKey();
|
||||
|
||||
/**
|
||||
* Get the recipe output.
|
||||
*
|
||||
* @return The output.
|
||||
*/
|
||||
ItemStack getOutput();
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.willfp.eco.core.recipe.recipes;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
public enum RecipePosition {
|
||||
/**
|
||||
* Top left of matrix.
|
||||
*/
|
||||
TOP_LEFT(0),
|
||||
|
||||
/**
|
||||
* Top middle of matrix.
|
||||
*/
|
||||
TOP_MIDDLE(1),
|
||||
|
||||
/**
|
||||
* Top right of matrix.
|
||||
*/
|
||||
TOP_RIGHT(2),
|
||||
|
||||
/**
|
||||
* Middle left of matrix.
|
||||
*/
|
||||
MIDDLE_LEFT(3),
|
||||
|
||||
/**
|
||||
* Middle of matrix.
|
||||
*/
|
||||
MIDDLE(4),
|
||||
|
||||
/**
|
||||
* Middle right of matrix.
|
||||
*/
|
||||
MIDDLE_RIGHT(5),
|
||||
|
||||
/**
|
||||
* Bottom left of matrix.
|
||||
*/
|
||||
BOTTOM_LEFT(6),
|
||||
|
||||
/**
|
||||
* Bottom middle of matrix.
|
||||
*/
|
||||
BOTTOM_MIDDLE(7),
|
||||
|
||||
/**
|
||||
* Bottom right of matrix.
|
||||
*/
|
||||
BOTTOM_RIGHT(8);
|
||||
|
||||
/**
|
||||
* The index within a crafting table matrix.
|
||||
*/
|
||||
@Getter
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Recipe position with crafting table index.
|
||||
*
|
||||
* @param index The index.
|
||||
*/
|
||||
RecipePosition(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
package com.willfp.eco.core.recipe.recipes;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import com.willfp.eco.core.recipe.Recipes;
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public final class ShapedCraftingRecipe extends PluginDependent implements CraftingRecipe {
|
||||
/**
|
||||
* Recipe parts.
|
||||
*/
|
||||
@Getter
|
||||
private final List<TestableItem> parts;
|
||||
|
||||
/**
|
||||
* The key of the recipe.
|
||||
*/
|
||||
@Getter
|
||||
private final NamespacedKey key;
|
||||
|
||||
/**
|
||||
* The key of the displayed recipe.
|
||||
*/
|
||||
@Getter
|
||||
private final NamespacedKey displayedKey;
|
||||
|
||||
/**
|
||||
* The recipe's output.
|
||||
*/
|
||||
@Getter
|
||||
private final ItemStack output;
|
||||
|
||||
private ShapedCraftingRecipe(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String key,
|
||||
@NotNull final List<TestableItem> parts,
|
||||
@NotNull final ItemStack output) {
|
||||
super(plugin);
|
||||
|
||||
this.parts = parts;
|
||||
this.key = plugin.getNamespacedKeyFactory().create(key);
|
||||
this.displayedKey = plugin.getNamespacedKeyFactory().create(key + "_displayed");
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(@NotNull final ItemStack[] matrix) {
|
||||
boolean matches = true;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (!parts.get(i).matches(matrix[i])) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
Recipes.register(this);
|
||||
|
||||
Bukkit.getServer().removeRecipe(this.getKey());
|
||||
Bukkit.getServer().removeRecipe(this.getDisplayedKey());
|
||||
|
||||
ShapedRecipe shapedRecipe = new ShapedRecipe(this.getKey(), this.getOutput());
|
||||
shapedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
shapedRecipe.setIngredient(character, parts.get(i).getItem().getType());
|
||||
}
|
||||
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
|
||||
displayedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(parts.get(i).getItem()));
|
||||
}
|
||||
|
||||
Bukkit.getServer().addRecipe(shapedRecipe);
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new recipe builder.
|
||||
*
|
||||
* @param plugin The plugin that owns the recipe.
|
||||
* @param key The recipe key.
|
||||
* @return A new builder.
|
||||
*/
|
||||
public static Builder builder(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String key) {
|
||||
return new Builder(plugin, key);
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
/**
|
||||
* The recipe parts.
|
||||
*/
|
||||
private final List<TestableItem> recipeParts = new ArrayList<>(Arrays.asList(null, null, null, null, null, null, null, null, null)); // Jank
|
||||
|
||||
/**
|
||||
* The output of the recipe.
|
||||
*/
|
||||
private ItemStack output = null;
|
||||
|
||||
/**
|
||||
* The key of the recipe.
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The plugin that created the recipe.
|
||||
*/
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new recipe builder.
|
||||
*
|
||||
* @param plugin The plugin that owns the recipe.
|
||||
* @param key The recipe key.
|
||||
*/
|
||||
private Builder(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String key) {
|
||||
this.key = key;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a recipe part.
|
||||
*
|
||||
* @param position The position of the recipe within a crafting matrix.
|
||||
* @param part The part of the recipe.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setRecipePart(@NotNull final RecipePosition position,
|
||||
@NotNull final TestableItem part) {
|
||||
recipeParts.set(position.getIndex(), part);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a recipe part.
|
||||
*
|
||||
* @param position The position of the recipe within a crafting matrix.
|
||||
* @param part The part of the recipe.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setRecipePart(final int position,
|
||||
@NotNull final TestableItem part) {
|
||||
recipeParts.set(position, part);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the output of the recipe.
|
||||
*
|
||||
* @param output The output.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setOutput(@NotNull final ItemStack output) {
|
||||
this.output = output;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the recipe.
|
||||
*
|
||||
* @return The built recipe.
|
||||
*/
|
||||
public ShapedCraftingRecipe build() {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (recipeParts.get(i) == null) {
|
||||
recipeParts.set(i, new EmptyTestableItem());
|
||||
}
|
||||
}
|
||||
|
||||
return new ShapedCraftingRecipe(plugin, key.toLowerCase(), recipeParts, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.willfp.eco.core.scheduling;
|
||||
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface RunnableTask extends Runnable {
|
||||
/**
|
||||
* Run the task.
|
||||
*
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
@NotNull BukkitTask runTask();
|
||||
|
||||
/**
|
||||
* Run the task asynchronously.
|
||||
*
|
||||
* @return The created {@link BukkitTask}
|
||||
*/
|
||||
@NotNull BukkitTask runTaskAsynchronously();
|
||||
|
||||
/**
|
||||
* Run the task after a specified number of ticks.
|
||||
*
|
||||
* @param delay The number of ticks to wait.
|
||||
* @return The created {@link BukkitTask}
|
||||
*/
|
||||
@NotNull BukkitTask runTaskLater(long delay);
|
||||
|
||||
/**
|
||||
* Run the task asynchronously after a specified number of ticks.
|
||||
*
|
||||
* @param delay The number of ticks to wait.
|
||||
* @return The created {@link BukkitTask}
|
||||
*/
|
||||
@NotNull BukkitTask runTaskLaterAsynchronously(long delay);
|
||||
|
||||
/**
|
||||
* Run the task repeatedly on a timer.
|
||||
*
|
||||
* @param delay The delay before the task is first ran (in ticks).
|
||||
* @param period The ticks elapsed before the task is ran again.
|
||||
* @return The created {@link BukkitTask}
|
||||
*/
|
||||
@NotNull BukkitTask runTaskTimer(long delay, long period);
|
||||
|
||||
/**
|
||||
* Run the task repeatedly on a timer asynchronously.
|
||||
*
|
||||
* @param delay The delay before the task is first ran (in ticks).
|
||||
* @param period The ticks elapsed before the task is ran again.
|
||||
* @return The created {@link BukkitTask}
|
||||
*/
|
||||
@NotNull BukkitTask runTaskTimerAsynchronously(long delay, long period);
|
||||
|
||||
/**
|
||||
* Cancel the task.
|
||||
*/
|
||||
void cancel();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.bukkit.scheduling;
|
||||
package com.willfp.eco.core.scheduling;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -12,7 +12,8 @@ public interface Scheduler {
|
||||
* @param ticksLater The amount of ticks to wait before execution.
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
BukkitTask runLater(@NotNull Runnable runnable, long ticksLater);
|
||||
BukkitTask runLater(@NotNull Runnable runnable,
|
||||
long ticksLater);
|
||||
|
||||
/**
|
||||
* Run the task repeatedly on a timer.
|
||||
@@ -22,7 +23,9 @@ public interface Scheduler {
|
||||
* @param repeat The amount of ticks to wait between executions.
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
BukkitTask runTimer(@NotNull Runnable runnable, long delay, long repeat);
|
||||
BukkitTask runTimer(@NotNull Runnable runnable,
|
||||
long delay,
|
||||
long repeat);
|
||||
|
||||
/**
|
||||
* Run the task repeatedly and asynchronously on a timer.
|
||||
@@ -32,7 +35,9 @@ public interface Scheduler {
|
||||
* @param repeat The amount of ticks to wait between executions.
|
||||
* @return The created {@link BukkitTask}.
|
||||
*/
|
||||
BukkitTask runAsyncTimer(@NotNull Runnable runnable, long delay, long repeat);
|
||||
BukkitTask runAsyncTimer(@NotNull Runnable runnable,
|
||||
long delay,
|
||||
long repeat);
|
||||
|
||||
/**
|
||||
* Run the task.
|
||||
@@ -58,10 +63,12 @@ public interface Scheduler {
|
||||
* @param repeat The amount of ticks to wait between executions.
|
||||
* @return The id of the task.
|
||||
*/
|
||||
int syncRepeating(@NotNull Runnable runnable, long delay, long repeat);
|
||||
int syncRepeating(@NotNull Runnable runnable,
|
||||
long delay,
|
||||
long repeat);
|
||||
|
||||
/**
|
||||
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
|
||||
* Cancel all running tasks from the linked {@link EcoPlugin}.
|
||||
*/
|
||||
void cancelAll();
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.willfp.eco.util.tuplets;
|
||||
package com.willfp.eco.core.tuples;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ToString
|
||||
public class Pair<A, B> {
|
||||
/**
|
||||
* The first value in the pair.
|
||||
* The first item in the tuple.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -16,7 +14,7 @@ public class Pair<A, B> {
|
||||
private A first;
|
||||
|
||||
/**
|
||||
* The second value in the pair.
|
||||
* The second item in the tuple.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.willfp.eco.core.tuples;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Triplet<A, B, C> extends Pair<A, B> {
|
||||
/**
|
||||
* The third item in the tuple.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Nullable
|
||||
private C third;
|
||||
|
||||
/**
|
||||
* Create a triple of values.
|
||||
*
|
||||
* @param first The first item in the pair.
|
||||
* @param second The second item in the pair.
|
||||
* @param third The third item in the pair.
|
||||
*/
|
||||
public Triplet(@Nullable final A first,
|
||||
@Nullable final B second,
|
||||
@Nullable final C third) {
|
||||
super(first, second);
|
||||
|
||||
this.third = third;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.willfp.eco.util.updater;
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UpdateChecker extends PluginDependent {
|
||||
*
|
||||
* @param plugin The plugin to check.
|
||||
*/
|
||||
public UpdateChecker(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public UpdateChecker(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.willfp.eco.util.arrows;
|
||||
package com.willfp.eco.internal.arrows;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -14,16 +13,14 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ArrowDataListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Listener to add metadata to arrows about the enchantments on the bow that shot them.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that registered the listener.
|
||||
* @param plugin The {@link EcoPlugin} that registered the listener.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public ArrowDataListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public ArrowDataListener(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -54,7 +51,6 @@ public class ArrowDataListener extends PluginDependent implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchantments = item.getItemMeta().getEnchants();
|
||||
arrow.setMetadata("enchantments", this.getPlugin().getMetadataValueFactory().create(enchantments));
|
||||
arrow.setMetadata("shot-from", this.getPlugin().getMetadataValueFactory().create(item));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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.
|
||||
*/
|
||||
protected ConfigSection(@NotNull final ConfigurationSection section) {
|
||||
this.init(section);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.core.config.Config;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class ConfigWrapper<T extends ConfigurationSection> implements Config {
|
||||
/**
|
||||
* The linked {@link ConfigurationSection} where values are physically stored.
|
||||
*/
|
||||
@Getter
|
||||
private T handle = null;
|
||||
|
||||
/**
|
||||
* Cached values for faster reading.
|
||||
*/
|
||||
private final Map<String, Object> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Abstract config.
|
||||
*/
|
||||
protected ConfigWrapper() {
|
||||
|
||||
}
|
||||
|
||||
protected Config init(@NotNull final T config) {
|
||||
this.handle = config;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull final String path) {
|
||||
return handle.contains(path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getKeys(final boolean deep) {
|
||||
return new ArrayList<>(handle.getKeys(deep));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object get(@NotNull final String path) {
|
||||
return handle.get(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(@NotNull final String path,
|
||||
@Nullable final Object object) {
|
||||
handle.set(path, object);
|
||||
}
|
||||
|
||||
@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 (cache.containsKey(path)) {
|
||||
return (Config) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, new ConfigSection(Objects.requireNonNull(handle.getConfigurationSection(path))));
|
||||
return getSubsectionOrNull(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (int) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, handle.getInt(path, 0));
|
||||
return getInt(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (int) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, handle.getInt(path, def));
|
||||
return getInt(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Integer>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, has(path) ? new ArrayList<>(handle.getIntegerList(path)) : new ArrayList<>());
|
||||
return getInts(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (boolean) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, handle.getBoolean(path));
|
||||
return getBool(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Boolean>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, has(path) ? new ArrayList<>(handle.getBooleanList(path)) : new ArrayList<>());
|
||||
return getBools(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (String) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, StringUtils.translate(Objects.requireNonNull(handle.getString(path, ""))));
|
||||
return getString(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<String>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, has(path) ? new ArrayList<>(handle.getStringList(path)) : new ArrayList<>());
|
||||
return getStrings(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (double) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, handle.getDouble(path));
|
||||
return getDouble(path);
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Double>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, has(path) ? new ArrayList<>(handle.getDoubleList(path)) : new ArrayList<>());
|
||||
return getDoubles(path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getDoubles(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
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> {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
* Plugin handle.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* The full name of the config file (eg config.yml).
|
||||
*/
|
||||
@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 LoadableYamlConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final Class<?> source) {
|
||||
this.plugin = plugin;
|
||||
this.name = configName + ".yml";
|
||||
this.source = source;
|
||||
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);
|
||||
init(YamlConfiguration.loadConfiguration(configFile));
|
||||
}
|
||||
|
||||
private 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.
|
||||
*/
|
||||
protected String getResourcePath() {
|
||||
String resourcePath;
|
||||
|
||||
if (subDirectoryPath.isEmpty()) {
|
||||
resourcePath = name;
|
||||
} else {
|
||||
resourcePath = subDirectoryPath + name;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
public void save() throws IOException {
|
||||
this.getHandle().save(this.getConfigFile());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
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.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class UpdatableYamlConfig extends LoadableYamlConfig {
|
||||
/**
|
||||
* Whether keys not in the base config should be removed on update.
|
||||
*/
|
||||
private final boolean removeUnused;
|
||||
|
||||
/**
|
||||
* List of blacklisted update keys.
|
||||
*/
|
||||
private final List<String> updateBlacklist;
|
||||
|
||||
/**
|
||||
* Updatable 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.
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||
*/
|
||||
protected UpdatableYamlConfig(@NotNull final String configName,
|
||||
@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final Class<?> source,
|
||||
final boolean removeUnused,
|
||||
@NotNull final String... updateBlacklist) {
|
||||
super(configName, plugin, subDirectoryPath, source);
|
||||
this.removeUnused = removeUnused;
|
||||
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
|
||||
this.updateBlacklist.removeIf(String::isEmpty);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the config.
|
||||
* <p>
|
||||
* Writes missing values, however removes comments due to how configs are stored internally in bukkit.
|
||||
*/
|
||||
public void update() {
|
||||
super.clearCache();
|
||||
try {
|
||||
this.getHandle().load(this.getConfigFile());
|
||||
|
||||
YamlConfiguration newConfig = this.getConfigInJar();
|
||||
|
||||
if (newConfig.getKeys(true).equals(this.getHandle().getKeys(true))) {
|
||||
return;
|
||||
}
|
||||
|
||||
newConfig.getKeys(true).forEach((s -> {
|
||||
if (!this.getHandle().getKeys(true).contains(s)) {
|
||||
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||
this.getHandle().set(s, newConfig.get(s));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
if (this.removeUnused) {
|
||||
this.getHandle().getKeys(true).forEach((s -> {
|
||||
if (!newConfig.getKeys(true).contains(s)) {
|
||||
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||
this.getHandle().set(s, null);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
this.getHandle().save(this.getConfigFile());
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.willfp.eco.util.config.updating;
|
||||
package com.willfp.eco.internal.config.updating;
|
||||
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.config.updating.exceptions.InvalidUpdatableClassException;
|
||||
import com.willfp.eco.util.config.updating.exceptions.InvalidUpdateMethodException;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException;
|
||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -21,11 +21,11 @@ public class ConfigHandler extends PluginDependent {
|
||||
private final Set<Class<?>> updatableClasses = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Creates a new config handler and links it to an {@link AbstractEcoPlugin}.
|
||||
* Creates a new config handler and links it to an {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public ConfigHandler(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public ConfigHandler(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util.config.updating.exceptions;
|
||||
package com.willfp.eco.internal.config.updating.exceptions;
|
||||
|
||||
import com.willfp.eco.util.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.internal.config.updating.ConfigHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InvalidUpdatableClassException extends RuntimeException {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.config.updating.exceptions;
|
||||
package com.willfp.eco.internal.config.updating.exceptions;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public final class DropManager {
|
||||
/**
|
||||
* The currently used type, or implementation, of {@link AbstractDropQueue}.
|
||||
* <p>
|
||||
* Default is {@link DropQueueType#COLLATED}, however this can be changed.
|
||||
*/
|
||||
@Getter
|
||||
private DropQueueType type = DropQueueType.COLLATED;
|
||||
|
||||
/**
|
||||
* Sets the type of Drop Queue to be used.
|
||||
*
|
||||
* @param type The type.
|
||||
*/
|
||||
public static void setType(@NotNull final DropQueueType type) {
|
||||
DropManager.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
public enum DropQueueType {
|
||||
/**
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -9,14 +8,11 @@ import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
/**
|
||||
@@ -24,7 +20,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* <p>
|
||||
* Cleared and updated every tick.
|
||||
*/
|
||||
private static final HashMap<Player, CollatedDrops> COLLATED_MAP = new HashMap<>();
|
||||
public static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Backend implementation of {@link AbstractDropQueue}
|
||||
@@ -39,7 +35,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues the drops to be managed by the {@link CollatedRunnable}.
|
||||
* Queues the drops to be managed by the runnable.
|
||||
*/
|
||||
@Override
|
||||
public void push() {
|
||||
@@ -52,7 +48,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* The items, location, and xp linked to a player's drops.
|
||||
*/
|
||||
@ToString
|
||||
private static final class CollatedDrops {
|
||||
public static final class CollatedDrops {
|
||||
/**
|
||||
* A collection of all ItemStacks to be dropped at the end of the tick.
|
||||
*/
|
||||
@@ -103,32 +99,4 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollatedRunnable extends PluginDependent {
|
||||
/**
|
||||
* The {@link BukkitTask} that the runnable represents.
|
||||
*/
|
||||
@Getter
|
||||
private final BukkitTask runnableTask;
|
||||
|
||||
/**
|
||||
* Create and run a new runnable to process collated drops.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, CollatedDrops> entry : COLLATED_MAP.entrySet()) {
|
||||
new InternalDropQueue(entry.getKey())
|
||||
.setLocation(entry.getValue().getLocation())
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
}
|
||||
COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import com.willfp.eco.util.TelekinesisUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
@@ -133,6 +135,11 @@ public class InternalDropQueue implements AbstractDropQueue {
|
||||
assert world != null;
|
||||
loc = loc.add(0.5, 0.5, 0.5);
|
||||
|
||||
items.removeIf(itemStack -> itemStack.getType() == Material.AIR);
|
||||
if (items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasTelekinesis) {
|
||||
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
||||
for (ItemStack drop : leftover.values()) {
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.willfp.eco.util.bukkit.events;
|
||||
package com.willfp.eco.internal.events;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.events.EventManager;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -11,13 +12,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class EcoEventManager extends PluginDependent implements EventManager {
|
||||
/**
|
||||
* Manager class for event management.
|
||||
* <p>
|
||||
* Prevents calls to {@link AbstractEcoPlugin#getInstance()}.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that this manages the events of.
|
||||
* @param plugin The {@link EcoPlugin} that this manages the events of.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public EcoEventManager(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public EcoEventManager(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.willfp.eco.util.extensions.loader;
|
||||
package com.willfp.eco.internal.extensions;
|
||||
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.extensions.MalformedExtensionException;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.extensions.Extension;
|
||||
import com.willfp.eco.core.extensions.MalformedExtensionException;
|
||||
import com.willfp.eco.core.extensions.ExtensionLoader;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -29,11 +31,11 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
private final Set<Extension> extensions = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Create a new extension loader and link it to a specific {@link AbstractEcoPlugin}.
|
||||
* Create a new extension loader and link it to a specific {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin to manage
|
||||
*/
|
||||
public EcoExtensionLoader(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public EcoExtensionLoader(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -61,7 +63,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
try {
|
||||
loadExtension(extensionJar);
|
||||
} catch (MalformedExtensionException e) {
|
||||
this.getPlugin().getLog().error(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
|
||||
this.getPlugin().getLogger().severe(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,13 +96,16 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
String mainClass = extensionYml.getString("main");
|
||||
String name = extensionYml.getString("name");
|
||||
String version = extensionYml.getString("version");
|
||||
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
|
||||
Validate.notNull(name, "Name is missing!");
|
||||
Validate.notNull(version, "Version is missing!");
|
||||
|
||||
ExtensionMetadata metadata = new ExtensionMetadata(version, name);
|
||||
|
||||
Class<?> cls;
|
||||
Object object = null;
|
||||
try {
|
||||
cls = cl.loadClass(mainClass);
|
||||
object = cls.getConstructor().newInstance();
|
||||
object = cls.getConstructor(EcoPlugin.class).newInstance(this.getPlugin());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -124,15 +129,6 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
extensions.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unloads, then loads all extensions.
|
||||
*/
|
||||
@Override
|
||||
public void reloadExtensions() {
|
||||
unloadExtensions();
|
||||
loadExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all loaded extensions.
|
||||
*
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.internal.extensions;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExtensionMetadata {
|
||||
/**
|
||||
* The version of the extension.
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
private final String version;
|
||||
|
||||
/**
|
||||
* The extension's name.
|
||||
*/
|
||||
@NotNull
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Create a new extension metadata.
|
||||
*
|
||||
* @param version The version for the extension to be.
|
||||
* @param name The name of the extension.
|
||||
*/
|
||||
public ExtensionMetadata(@NotNull final String version,
|
||||
@NotNull final String name) {
|
||||
this.version = version;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,28 @@
|
||||
package com.willfp.eco.util.bukkit.meta;
|
||||
package com.willfp.eco.internal.factory;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependentFactory;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.factory.MetadataValueFactory;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MetadataValueFactory extends PluginDependentFactory {
|
||||
public class EcoMetadataValueFactory extends PluginDependent implements MetadataValueFactory {
|
||||
/**
|
||||
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link AbstractEcoPlugin}.
|
||||
* Factory class to produce {@link FixedMetadataValue}s associated with an {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin that this factory creates values for.
|
||||
*/
|
||||
public MetadataValueFactory(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public EcoMetadataValueFactory(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link FixedMetadataValue} associated with an {@link AbstractEcoPlugin} with a specified value.
|
||||
* Create an {@link FixedMetadataValue} associated with an {@link EcoPlugin} with a specified value.
|
||||
*
|
||||
* @param value The value of meta key.
|
||||
* @return The created {@link FixedMetadataValue}.
|
||||
*/
|
||||
@Override
|
||||
public FixedMetadataValue create(@NotNull final Object value) {
|
||||
return new FixedMetadataValue(this.getPlugin(), value);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.internal.factory;
|
||||
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.factory.NamespacedKeyFactory;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoNamespacedKeyFactory extends PluginDependent implements NamespacedKeyFactory {
|
||||
/**
|
||||
* Factory class to produce {@link NamespacedKey}s associated with an {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin that this factory creates keys for.
|
||||
*/
|
||||
public EcoNamespacedKeyFactory(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
@Override
|
||||
public NamespacedKey create(@NotNull final String key) {
|
||||
return new NamespacedKey(this.getPlugin(), key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.willfp.eco.internal.factory;
|
||||
|
||||
import com.willfp.eco.core.factory.RunnableFactory;
|
||||
import com.willfp.eco.core.scheduling.RunnableTask;
|
||||
import com.willfp.eco.internal.scheduling.EcoRunnableTask;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EcoRunnableFactory extends PluginDependent implements RunnableFactory {
|
||||
/**
|
||||
* Factory class to produce {@link RunnableTask}s associated with an {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin that this factory creates runnables for.
|
||||
*/
|
||||
public EcoRunnableFactory(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RunnableTask create(@NotNull final Consumer<RunnableTask> consumer) {
|
||||
return new EcoRunnableTask(this.getPlugin()) {
|
||||
@Override
|
||||
public void run() {
|
||||
consumer.accept(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.willfp.eco.util.integrations.placeholder.plugins;
|
||||
package com.willfp.eco.internal.integrations;
|
||||
|
||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderIntegration;
|
||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -13,14 +13,14 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
|
||||
/**
|
||||
* The linked plugin.
|
||||
*/
|
||||
private final AbstractEcoPlugin plugin;
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new PlaceholderAPI integration.
|
||||
*
|
||||
* @param plugin The plugin to manage placeholders for.
|
||||
*/
|
||||
public PlaceholderIntegrationPAPI(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public PlaceholderIntegrationPAPI(@NotNull final EcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PlaceholderIntegrationPAPI extends PlaceholderExpansion implements
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "Auxilor";
|
||||
return String.join(", ", plugin.getDescription().getAuthors());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.internal.logging;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EcoLogger extends Logger {
|
||||
public EcoLogger(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin.getName(), (String) null);
|
||||
String prefix = plugin.getDescription().getPrefix();
|
||||
this.setParent(plugin.getServer().getLogger());
|
||||
this.setLevel(Level.ALL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(@NotNull final String msg) {
|
||||
super.info(StringUtils.translate(msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(@NotNull final String msg) {
|
||||
super.warning(StringUtils.translate(msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void severe(@NotNull final String msg) {
|
||||
super.severe(StringUtils.translate(msg));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.willfp.eco.internal.scheduling;
|
||||
|
||||
import com.willfp.eco.internal.factory.EcoRunnableFactory;
|
||||
import com.willfp.eco.core.scheduling.RunnableTask;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class EcoRunnableTask extends BukkitRunnable implements RunnableTask {
|
||||
/**
|
||||
* The linked {@link EcoPlugin} to associate runnables with.
|
||||
*/
|
||||
private final EcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Creates a new {@link EcoRunnableTask}.
|
||||
* <p>
|
||||
* Cannot be instantiated normally, use {@link EcoRunnableFactory}.
|
||||
*
|
||||
* @param plugin The {@link EcoPlugin} to associate runnables with.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public EcoRunnableTask(@NotNull final EcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link EcoPlugin} that created this runnable.
|
||||
*
|
||||
* @return The linked plugin.
|
||||
*/
|
||||
protected final EcoPlugin getPlugin() {
|
||||
return this.plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTask() {
|
||||
return super.runTask(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskAsynchronously() {
|
||||
return super.runTaskAsynchronously(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskLater(final long delay) {
|
||||
return super.runTaskLater(plugin, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskLaterAsynchronously(final long delay) {
|
||||
return super.runTaskLaterAsynchronously(plugin, delay);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskTimer(final long delay, final long period) {
|
||||
return super.runTaskTimer(plugin, delay, period);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public final synchronized BukkitTask runTaskTimerAsynchronously(final long delay, final long period) {
|
||||
return super.runTaskTimerAsynchronously(plugin, delay, period);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.willfp.eco.util.bukkit.scheduling;
|
||||
package com.willfp.eco.internal.scheduling;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -9,12 +10,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EcoScheduler extends PluginDependent implements Scheduler {
|
||||
/**
|
||||
* Create a scheduler to manage the tasks of an {@link AbstractEcoPlugin}.
|
||||
* Create a scheduler to manage the tasks of an {@link EcoPlugin}.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public EcoScheduler(@NotNull final AbstractEcoPlugin plugin) {
|
||||
public EcoScheduler(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ public class EcoScheduler extends PluginDependent implements Scheduler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel all running tasks from the linked {@link AbstractEcoPlugin}.
|
||||
* Cancel all running tasks from the linked {@link EcoPlugin}.
|
||||
*/
|
||||
@Override
|
||||
public void cancelAll() {
|
||||
96
eco-api/src/main/java/com/willfp/eco/util/BlockUtils.java
Normal file
96
eco-api/src/main/java/com/willfp/eco/util/BlockUtils.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@UtilityClass
|
||||
public class BlockUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The block break function.
|
||||
*/
|
||||
private BiConsumer<Player, Block> blockBreakConsumer = null;
|
||||
|
||||
private Set<Block> getNearbyBlocks(@NotNull final Block start,
|
||||
@NotNull final List<Material> allowedMaterials,
|
||||
@NotNull final Set<Block> blocks,
|
||||
final int limit) {
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Block block = start.getRelative(face);
|
||||
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
|
||||
blocks.add(block);
|
||||
if (blocks.size() > limit || blocks.size() > 2500) {
|
||||
return blocks;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Running twice to get more spherical shape.
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Block block = start.getRelative(face);
|
||||
if (!blocks.contains(block) && allowedMaterials.contains(block.getType())) {
|
||||
if (blocks.size() > limit || blocks.size() > 2500) {
|
||||
return blocks;
|
||||
}
|
||||
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a set of all blocks in contact with each other of a specific type.
|
||||
*
|
||||
* @param start The initial block.
|
||||
* @param allowedMaterials A list of all valid {@link Material}s.
|
||||
* @param limit The maximum size of vein to return.
|
||||
* @return A set of all {@link Block}s.
|
||||
*/
|
||||
public Set<Block> getVein(@NotNull final Block start,
|
||||
@NotNull final List<Material> allowedMaterials,
|
||||
final int limit) {
|
||||
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Break the block as if the player had done it manually.
|
||||
*
|
||||
* @param player The player to break the block as.
|
||||
* @param block The block to break.
|
||||
*/
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(blockBreakConsumer, "Must be initialized!");
|
||||
|
||||
blockBreakConsumer.accept(player, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the block break function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final BiConsumer<Player, Block> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
blockBreakConsumer = function;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -37,12 +38,20 @@ public class DurabilityUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Special edge case
|
||||
if (item.getType() == Material.CARVED_PUMPKIN || item.getType() == Material.PLAYER_HEAD) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event3);
|
||||
|
||||
if (!event3.isCancelled()) {
|
||||
int damage2 = event3.getDamage();
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
|
||||
@@ -58,7 +67,6 @@ public class DurabilityUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Damage an item in a player's inventory without breaking it.
|
||||
@@ -78,12 +86,15 @@ public class DurabilityUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event3);
|
||||
|
||||
if (!event3.isCancelled()) {
|
||||
int damage2 = event3.getDamage();
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
|
||||
@@ -93,7 +104,6 @@ public class DurabilityUtils {
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Repair an item in a player's inventory.
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Map;
|
||||
@@ -9,6 +10,21 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@UtilityClass
|
||||
public class NumberUtils {
|
||||
/**
|
||||
* Precision.
|
||||
*/
|
||||
private static final int FAST_TRIG_PRECISION = 100;
|
||||
|
||||
/**
|
||||
* Modulus.
|
||||
*/
|
||||
private static final int FAST_TRIG_MODULUS = 360 * FAST_TRIG_PRECISION;
|
||||
|
||||
/**
|
||||
* Sin lookup table.
|
||||
*/
|
||||
private static final double[] SIN_LOOKUP = new double[FAST_TRIG_MODULUS];
|
||||
|
||||
/**
|
||||
* Set of roman numerals to look up.
|
||||
*/
|
||||
@@ -28,6 +44,34 @@ public class NumberUtils {
|
||||
NUMERALS.put(5, "V");
|
||||
NUMERALS.put(4, "IV");
|
||||
NUMERALS.put(1, "I");
|
||||
|
||||
for (int i = 0; i < SIN_LOOKUP.length; i++) {
|
||||
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180));
|
||||
}
|
||||
}
|
||||
|
||||
private static double sinLookup(final int a) {
|
||||
return a >= 0 ? SIN_LOOKUP[a % FAST_TRIG_MODULUS] : -SIN_LOOKUP[-a % FAST_TRIG_MODULUS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sin of a number.
|
||||
*
|
||||
* @param a The number.
|
||||
* @return The sin.
|
||||
*/
|
||||
public static double fastSin(final double a) {
|
||||
return sinLookup((int) (a * FAST_TRIG_PRECISION + 0.5f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cosine of a number.
|
||||
*
|
||||
* @param a The number.
|
||||
* @return The cosine.
|
||||
*/
|
||||
public static double fastCos(final double a) {
|
||||
return sinLookup((int) ((a + 90f) * FAST_TRIG_PRECISION + 0.5f));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +136,10 @@ public class NumberUtils {
|
||||
* @param numeral The numeral to convert.
|
||||
* @return The number, converted from a roman numeral.
|
||||
*/
|
||||
public static int fromNumeral(String numeral) {
|
||||
if (numeral.isEmpty()) return 0;
|
||||
public static int fromNumeral(@NotNull final String numeral) {
|
||||
if (numeral.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
|
||||
if (numeral.startsWith(entry.getValue())) {
|
||||
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
|
||||
49
eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java
Normal file
49
eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@UtilityClass
|
||||
public class SkullUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The meta set function.
|
||||
*/
|
||||
private BiConsumer<SkullMeta, String> metaSetConsumer = null;
|
||||
|
||||
/**
|
||||
* Set the texture of a skull from base64.
|
||||
*
|
||||
* @param meta The meta to modify.
|
||||
* @param base64 The base64 texture.
|
||||
*/
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(metaSetConsumer, "Must be initialized!");
|
||||
|
||||
metaSetConsumer.accept(meta, base64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the skull texture function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
metaSetConsumer = function;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
223
eco-api/src/main/java/com/willfp/eco/util/StringUtils.java
Normal file
223
eco-api/src/main/java/com/willfp/eco/util/StringUtils.java
Normal file
@@ -0,0 +1,223 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
|
||||
|
||||
@UtilityClass
|
||||
public class StringUtils {
|
||||
/**
|
||||
* Regexes for gradients.
|
||||
*/
|
||||
private static final List<Pattern> GRADIENT_PATTERNS = new ImmutableList.Builder<Pattern>()
|
||||
.add(Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>"))
|
||||
.add(Pattern.compile("<G:([0-9A-Fa-f]{6})>(.*?)</G:([0-9A-Fa-f]{6})>"))
|
||||
.add(Pattern.compile("<#:([0-9A-Fa-f]{6})>(.*?)</#:([0-9A-Fa-f]{6})>"))
|
||||
.add(Pattern.compile("\\{#:([0-9A-Fa-f]{6})}(.*?)\\{/#:([0-9A-Fa-f]{6})}"))
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Regexes for hex codes.
|
||||
*/
|
||||
private static final List<Pattern> HEX_PATTERNS = new ImmutableList.Builder<Pattern>()
|
||||
.add(Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + ""))
|
||||
.add(Pattern.compile("\\{#" + "([A-Fa-f0-9]{6})" + "}"))
|
||||
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Translate a string - converts Placeholders and Color codes.
|
||||
*
|
||||
* @param message The message to translate.
|
||||
* @param player The player to translate placeholders with respect to.
|
||||
* @return The message, translated.
|
||||
*/
|
||||
public String translate(@NotNull final String message,
|
||||
@Nullable final Player player) {
|
||||
String processedMessage = message;
|
||||
processedMessage = translateGradients(processedMessage);
|
||||
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
|
||||
processedMessage = translateHexColorCodes(processedMessage);
|
||||
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
|
||||
return processedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string without respect to a player.
|
||||
*
|
||||
* @param message The message to translate.
|
||||
* @return The message, translated.
|
||||
* @see StringUtils#translate(String, Player)
|
||||
*/
|
||||
public String translate(@NotNull final String message) {
|
||||
return translate(message, null);
|
||||
}
|
||||
|
||||
private static String translateHexColorCodes(@NotNull final String message) {
|
||||
String processedMessage = message;
|
||||
for (Pattern pattern : HEX_PATTERNS) {
|
||||
processedMessage = translateHexColorCodes(processedMessage, pattern);
|
||||
}
|
||||
return processedMessage;
|
||||
}
|
||||
|
||||
private static String translateHexColorCodes(@NotNull final String message,
|
||||
@NotNull final Pattern pattern) {
|
||||
Matcher matcher = pattern.matcher(message);
|
||||
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors a string with a gradient.
|
||||
*
|
||||
* @param string The string to color.
|
||||
* @param start The start color.
|
||||
* @param end The end color.
|
||||
* @return The string, colored.
|
||||
*/
|
||||
private static String processGradients(@NotNull final String string,
|
||||
@NotNull final Color start,
|
||||
@NotNull final Color end) {
|
||||
String processedString = string;
|
||||
List<ChatColor> modifiers = new ArrayList<>();
|
||||
if (processedString.contains("&l")) {
|
||||
modifiers.add(ChatColor.BOLD);
|
||||
}
|
||||
if (processedString.contains("&o")) {
|
||||
modifiers.add(ChatColor.ITALIC);
|
||||
}
|
||||
if (processedString.contains("&n")) {
|
||||
modifiers.add(ChatColor.UNDERLINE);
|
||||
}
|
||||
if (processedString.contains("&k")) {
|
||||
modifiers.add(ChatColor.MAGIC);
|
||||
}
|
||||
processedString = processedString.replace("&l", "");
|
||||
processedString = processedString.replace("&o", "");
|
||||
processedString = processedString.replace("&n", "");
|
||||
processedString = processedString.replace("&k", "");
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
ChatColor[] colors = getGradientColors(start, end, processedString.length());
|
||||
String[] characters = processedString.split("");
|
||||
for (int i = 0; i < processedString.length(); i++) {
|
||||
stringBuilder.append(colors[i]);
|
||||
modifiers.forEach(stringBuilder::append);
|
||||
stringBuilder.append(characters[i]);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates chatColors for gradients.
|
||||
*
|
||||
* @param start The start color.
|
||||
* @param end The end color.
|
||||
* @param step How many colors are returned.
|
||||
* @return Array of chat colors.
|
||||
*/
|
||||
private static ChatColor[] getGradientColors(@NotNull final Color start,
|
||||
@NotNull final Color end,
|
||||
final int step) {
|
||||
ChatColor[] colors = new ChatColor[step];
|
||||
int stepR = Math.abs(start.getRed() - end.getRed()) / (step - 1);
|
||||
int stepG = Math.abs(start.getGreen() - end.getGreen()) / (step - 1);
|
||||
int stepB = Math.abs(start.getBlue() - end.getBlue()) / (step - 1);
|
||||
int[] direction = new int[]{
|
||||
start.getRed() < end.getRed() ? +1 : -1,
|
||||
start.getGreen() < end.getGreen() ? +1 : -1,
|
||||
start.getBlue() < end.getBlue() ? +1 : -1
|
||||
};
|
||||
|
||||
for (int i = 0; i < step; i++) {
|
||||
Color color = new Color(start.getRed() + ((stepR * i) * direction[0]), start.getGreen() + ((stepG * i) * direction[1]), start.getBlue() + ((stepB * i) * direction[2]));
|
||||
colors[i] = ChatColor.of(color);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add gradients to a string.
|
||||
*
|
||||
* @param string The string.
|
||||
* @return The string, colorized.
|
||||
*/
|
||||
private static String translateGradients(@NotNull final String string) {
|
||||
String processedString = string;
|
||||
for (Pattern pattern : GRADIENT_PATTERNS) {
|
||||
Matcher matcher = pattern.matcher(string);
|
||||
while (matcher.find()) {
|
||||
String start = matcher.group(1);
|
||||
String end = matcher.group(3);
|
||||
String content = matcher.group(2);
|
||||
processedString = processedString.replace(matcher.group(), processGradients(content, new Color(Integer.parseInt(start, 16)), new Color(Integer.parseInt(end, 16))));
|
||||
}
|
||||
}
|
||||
return processedString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of {@link String#valueOf}.
|
||||
* Formats collections and doubles better.
|
||||
*
|
||||
* @param object The object to convert to string.
|
||||
* @return The object stringified.
|
||||
*/
|
||||
public String internalToString(@Nullable final Object object) {
|
||||
if (object == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (object instanceof Integer) {
|
||||
return ((Integer) object).toString();
|
||||
} else if (object instanceof String) {
|
||||
return (String) object;
|
||||
} else if (object instanceof Double) {
|
||||
return NumberUtils.format((Double) object);
|
||||
} else if (object instanceof Collection<?>) {
|
||||
Collection<?> c = (Collection<?>) object;
|
||||
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
|
||||
} else {
|
||||
return String.valueOf(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a string of characters from the start of a string.
|
||||
*
|
||||
* @param string The string to remove the prefix from.
|
||||
* @param prefix The substring to remove.
|
||||
* @return The string with the prefix removed.
|
||||
*/
|
||||
public String removePrefix(@NotNull final String string,
|
||||
@NotNull final String prefix) {
|
||||
if (string.startsWith(prefix)) {
|
||||
return string.substring(prefix.length());
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.willfp.eco.util;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@@ -45,10 +44,10 @@ public class TeamUtils {
|
||||
|
||||
Team team;
|
||||
|
||||
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EE-" + color.name())) {
|
||||
team = SCOREBOARD.registerNewTeam("EE-" + color.name());
|
||||
if (!SCOREBOARD.getTeams().stream().map(Team::getName).collect(Collectors.toList()).contains("EC-" + color.name())) {
|
||||
team = SCOREBOARD.registerNewTeam("EC-" + color.name());
|
||||
} else {
|
||||
team = SCOREBOARD.getTeam("EE-" + color.name());
|
||||
team = SCOREBOARD.getTeam("EC-" + color.name());
|
||||
}
|
||||
assert team != null;
|
||||
team.setColor(color);
|
||||
@@ -80,9 +79,6 @@ public class TeamUtils {
|
||||
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
|
||||
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
|
||||
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
|
||||
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.drops.telekinesis;
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -7,20 +8,20 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoTelekinesisTests implements TelekinesisTests {
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
/**
|
||||
* Set of tests that return if the player is telekinetic.
|
||||
*/
|
||||
private final Set<Function<Player, Boolean>> tests = new HashSet<>();
|
||||
private static final Set<Function<Player, Boolean>> TESTS = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new test to check against.
|
||||
*
|
||||
* @param test The test to register, where the boolean output is if the player is telekinetic.
|
||||
*/
|
||||
@Override
|
||||
public void registerTest(@NotNull final Function<Player, Boolean> test) {
|
||||
tests.add(test);
|
||||
TESTS.add(test);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,9 +32,8 @@ public class EcoTelekinesisTests implements TelekinesisTests {
|
||||
* @param player The player to test.
|
||||
* @return If the player is telekinetic.
|
||||
*/
|
||||
@Override
|
||||
public boolean testPlayer(@NotNull final Player player) {
|
||||
for (Function<Player, Boolean> test : tests) {
|
||||
for (Function<Player, Boolean> test : TESTS) {
|
||||
if (test.apply(player)) {
|
||||
return true;
|
||||
}
|
||||
49
eco-api/src/main/java/com/willfp/eco/util/TridentUtils.java
Normal file
49
eco-api/src/main/java/com/willfp/eco/util/TridentUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class TridentUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The meta set function.
|
||||
*/
|
||||
private Function<Trident, ItemStack> tridentFunction = null;
|
||||
|
||||
/**
|
||||
* Get a trident's ItemStack.
|
||||
*
|
||||
* @param trident The trident to query.
|
||||
* @return The trident's ItemStack.
|
||||
*/
|
||||
public ItemStack getItemStack(@NotNull final Trident trident) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(tridentFunction, "Must be initialized!");
|
||||
|
||||
return tridentFunction.apply(trident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the trident function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final Function<Trident, ItemStack> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
tridentFunction = function;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,17 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class VectorUtils {
|
||||
/**
|
||||
* Cached circles to prevent many sqrt calls.
|
||||
*/
|
||||
private static final Map<Integer, Vector[]> CIRCLE_CACHE = new HashMap<>();
|
||||
|
||||
/**
|
||||
* If vector has all components as finite.
|
||||
*
|
||||
@@ -66,7 +74,12 @@ public class VectorUtils {
|
||||
* @return An array of {@link Vector}s.
|
||||
*/
|
||||
public Vector[] getCircle(final int radius) {
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
Vector[] cached = CIRCLE_CACHE.get(radius);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
List<Vector> vectors = new ArrayList<>();
|
||||
|
||||
double xoffset = -radius;
|
||||
double zoffset = -radius;
|
||||
@@ -74,7 +87,7 @@ public class VectorUtils {
|
||||
while (zoffset <= radius) {
|
||||
while (xoffset <= radius) {
|
||||
if (Math.round(Math.sqrt((xoffset * xoffset) + (zoffset * zoffset))) <= radius) {
|
||||
circleVecs.add(new Vector(xoffset, 0, zoffset));
|
||||
vectors.add(new Vector(xoffset, 0, zoffset));
|
||||
} else {
|
||||
xoffset++;
|
||||
continue;
|
||||
@@ -85,7 +98,9 @@ public class VectorUtils {
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
Vector[] result = vectors.toArray(new Vector[0]);
|
||||
CIRCLE_CACHE.put(radius, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,21 +110,21 @@ public class VectorUtils {
|
||||
* @return An array of {@link Vector}s.
|
||||
*/
|
||||
public Vector[] getSquare(final int radius) {
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
List<Vector> vectors = new ArrayList<>();
|
||||
|
||||
int xoffset = -radius;
|
||||
int zoffset = -radius;
|
||||
|
||||
while (zoffset <= radius) {
|
||||
while (xoffset <= radius) {
|
||||
circleVecs.add(new Vector(xoffset, 0, zoffset));
|
||||
vectors.add(new Vector(xoffset, 0, zoffset));
|
||||
xoffset++;
|
||||
}
|
||||
xoffset = -radius;
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
return vectors.toArray(new Vector[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,16 +134,16 @@ public class VectorUtils {
|
||||
* @return An array of {@link Vector}s.
|
||||
*/
|
||||
public Vector[] getCube(final int radius) {
|
||||
ArrayList<Vector> cubeVecs = new ArrayList<>();
|
||||
List<Vector> vectors = new ArrayList<>();
|
||||
|
||||
for (int y = -radius; y <= radius; y++) {
|
||||
for (int z = -radius; z <= radius; z++) {
|
||||
for (int x = -radius; x <= radius; x++) {
|
||||
cubeVecs.add(new Vector(x, y, z));
|
||||
vectors.add(new Vector(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cubeVecs.toArray(new Vector[0]);
|
||||
return vectors.toArray(new Vector[0]);
|
||||
}
|
||||
}
|
||||
8
eco-core/build.gradle
Normal file
8
eco-core/build.gradle
Normal file
@@ -0,0 +1,8 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
subprojects {
|
||||
dependencies {
|
||||
compileOnly project(":eco-api")
|
||||
}
|
||||
}
|
||||
9
eco-core/core-nms/build.gradle
Normal file
9
eco-core/core-nms/build.gradle
Normal file
@@ -0,0 +1,9 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
subprojects {
|
||||
dependencies {
|
||||
compileOnly project(':eco-core:core-proxy')
|
||||
compileOnly project(':eco-core:core-plugin')
|
||||
}
|
||||
}
|
||||
6
eco-core/core-nms/v1_16_R1/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R1/build.gradle
Normal file
@@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import net.minecraft.server.v1_16_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutAutoRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class AutoCraft implements AutoCraftProxy {
|
||||
@Override
|
||||
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
|
||||
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
|
||||
Field fKey = recipePacket.getClass().getDeclaredField("b");
|
||||
fKey.setAccessible(true);
|
||||
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
|
||||
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user