Compare commits
96 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54e0b3f482 | ||
|
|
93794fe454 | ||
|
|
7f4a0c800e | ||
|
|
853864f6f0 | ||
|
|
0cb6e8f669 | ||
|
|
d30f657eec | ||
|
|
d60ecdd340 | ||
|
|
07310df68a | ||
|
|
5c91aa220a | ||
|
|
756a76057a | ||
|
|
b6f27ee232 | ||
|
|
74ca2e82ef | ||
|
|
4039439fda | ||
|
|
7dac671690 | ||
|
|
411d517a9a | ||
|
|
0d84141116 | ||
|
|
6bfd5bd153 | ||
|
|
b7d421e1a8 | ||
|
|
2e9d811d3f | ||
|
|
672b295917 | ||
|
|
60a83478e8 | ||
|
|
c880a476d4 | ||
|
|
692305d595 | ||
|
|
9d4cc2961c | ||
|
|
358b389875 | ||
|
|
7fa25c2500 | ||
|
|
91c58c4a53 | ||
|
|
4ccee91c64 | ||
|
|
eef87342a1 | ||
|
|
efc70ea7a8 | ||
|
|
de38299264 | ||
|
|
bc94f43299 | ||
|
|
ed705cc577 | ||
|
|
93410490c5 | ||
|
|
33914ac284 | ||
|
|
2acf2ee687 | ||
|
|
0470552168 | ||
|
|
3e724eea18 | ||
|
|
33ba5c9d31 | ||
|
|
94ab094952 | ||
|
|
58f5d3f352 | ||
|
|
912872e791 | ||
|
|
7a65e6e821 | ||
|
|
3f446f6072 | ||
|
|
50f57abd6c | ||
|
|
2c5eae6c6c | ||
|
|
1e3e54b8c5 | ||
|
|
0ce9119a94 | ||
|
|
bf76ba9f5a | ||
|
|
8a065bf7ca | ||
|
|
5f045d02a6 | ||
|
|
f07ef3045b | ||
|
|
007a579f5a | ||
|
|
9b19cd412a | ||
|
|
08b5cc1612 | ||
|
|
47aa61c7b3 | ||
|
|
ef1ee84358 | ||
|
|
49a36a4e81 | ||
|
|
bf76dec28e | ||
|
|
a0f51d79e8 | ||
|
|
9be516e511 | ||
|
|
a130935c62 | ||
|
|
4359bd17ae | ||
|
|
07726959e9 | ||
|
|
13c8187b3b | ||
|
|
be1267ef0c | ||
|
|
e61e9bc0a8 | ||
|
|
ec801cd776 | ||
|
|
a5b5bc6b46 | ||
|
|
f5efb50d71 | ||
|
|
d65c04aaa7 | ||
|
|
aa69d2a1a9 | ||
|
|
685cd5f998 | ||
|
|
bae4b567c8 | ||
|
|
0eb3315d61 | ||
|
|
0a42320b78 | ||
|
|
6ce0de8db7 | ||
|
|
345d4cd1b5 | ||
|
|
950c092025 | ||
|
|
0c6bb8c1b7 | ||
|
|
0f9cb7db7a | ||
|
|
7d4262e0ef | ||
|
|
e543be7a13 | ||
|
|
3d7027bf47 | ||
|
|
632b42ad65 | ||
|
|
bcd79e3886 | ||
|
|
8fbcf485b3 | ||
|
|
6a64be2e25 | ||
|
|
3f9f3991d8 | ||
|
|
54a8d942fa | ||
|
|
6aa14be577 | ||
|
|
d6db7673d8 | ||
|
|
d002073124 | ||
|
|
4bc98cae81 | ||
|
|
2696baf1d6 | ||
|
|
3c3cc36403 |
20
build.gradle
20
build.gradle
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
id 'com.github.johnrengelman.shadow' version '5.2.0'
|
id 'com.github.johnrengelman.shadow' version '7.0.0'
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
id 'java'
|
id 'java'
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@ allprojects {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
|
|
||||||
@@ -54,10 +53,10 @@ allprojects {
|
|||||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||||
|
|
||||||
// Lombok
|
// Lombok
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
compileOnly 'org.projectlombok:lombok:1.18.20'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||||
testCompileOnly 'org.projectlombok:lombok:1.18.16'
|
testCompileOnly 'org.projectlombok:lombok:1.18.20'
|
||||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
|
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
@@ -77,6 +76,7 @@ allprojects {
|
|||||||
shadowJar {
|
shadowJar {
|
||||||
relocate('org.bstats.bukkit', 'com.willfp.eco.shaded.bstats')
|
relocate('org.bstats.bukkit', 'com.willfp.eco.shaded.bstats')
|
||||||
relocate('org.apache.maven', 'com.willfp.eco.shaded.maven')
|
relocate('org.apache.maven', 'com.willfp.eco.shaded.maven')
|
||||||
|
relocate('com.google.gson', 'com.willfp.eco.shaded.gson')
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
@@ -87,6 +87,11 @@ allprojects {
|
|||||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_16
|
||||||
|
targetCompatibility = JavaVersion.VERSION_16
|
||||||
|
}
|
||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
compileJava.dependsOn clean
|
compileJava.dependsOn clean
|
||||||
|
|
||||||
@@ -95,5 +100,4 @@ allprojects {
|
|||||||
|
|
||||||
group = 'com.willfp'
|
group = 'com.willfp'
|
||||||
archivesBaseName = project.name
|
archivesBaseName = project.name
|
||||||
version = findProperty("version")
|
version = findProperty("version")
|
||||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
<!-- Internals don't need javadoc. -->
|
<!-- Internals don't need javadoc. -->
|
||||||
<suppress files="[\\/]internal[\\/]" checks="MissingJavadocMethod"/>
|
<suppress files="[\\/]internal[\\/]" checks="MissingJavadocMethod"/>
|
||||||
<suppress files="[\\/]internal[\\/]" checks="JavadocVariable"/>
|
<suppress files="[\\/]internal[\\/]" checks="JavadocVariable"/>
|
||||||
|
<suppress files="[\\/]eco[\\/]spigot[\\/]" checks="MissingJavadocMethod"/>
|
||||||
|
<suppress files="[\\/]eco[\\/]spigot[\\/]" checks="JavadocVariable"/>
|
||||||
|
|
||||||
<!-- Modified version of library -->
|
<!-- Modified version of library -->
|
||||||
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
|
<suppress files="ArmorEquipEvent.java" checks="JavadocVariable"/>
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id 'com.github.johnrengelman.shadow'
|
||||||
|
}
|
||||||
|
|
||||||
group 'com.willfp'
|
group 'com.willfp'
|
||||||
version rootProject.version
|
version rootProject.version
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
|
||||||
compileOnly 'org.apache.maven:maven-artifact:3.0.3'
|
compileOnly 'org.apache.maven:maven-artifact:3.0.3'
|
||||||
compileOnly 'org.bstats:bstats-bukkit:1.7'
|
compileOnly 'org.bstats:bstats-bukkit:1.7'
|
||||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||||
|
compileOnly 'com.google.code.gson:gson:2.8.7'
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava.options.encoding = 'UTF-8'
|
compileJava.options.encoding = 'UTF-8'
|
||||||
@@ -18,7 +23,6 @@ publishing {
|
|||||||
publications {
|
publications {
|
||||||
shadow(MavenPublication) {
|
shadow(MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
artifact shadowJar
|
|
||||||
artifactId 'eco'
|
artifactId 'eco'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,32 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
|||||||
// Empty rather than abstract as implementations don't need both
|
// Empty rather than abstract as implementations don't need both
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The code that should be executed once the packet has been received.
|
||||||
|
*
|
||||||
|
* @param packet The packet.
|
||||||
|
* @param player The player.
|
||||||
|
* @param event The event.
|
||||||
|
*/
|
||||||
|
public void onReceive(@NotNull final PacketContainer packet,
|
||||||
|
@NotNull final Player player,
|
||||||
|
@NotNull final PacketEvent event) {
|
||||||
|
// Empty rather than abstract as implementations don't need both
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* THe code that should be executed once the packet has been sent.
|
||||||
|
*
|
||||||
|
* @param packet The packet.
|
||||||
|
* @param player The player.
|
||||||
|
* @param event The event.
|
||||||
|
*/
|
||||||
|
public void onSend(@NotNull final PacketContainer packet,
|
||||||
|
@NotNull final Player player,
|
||||||
|
@NotNull final PacketEvent event) {
|
||||||
|
// Empty rather than abstract as implementations don't need both
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Boilerplate to assert that the packet is of the specified type.
|
* Boilerplate to assert that the packet is of the specified type.
|
||||||
*
|
*
|
||||||
@@ -94,6 +120,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onReceive(event.getPacket(), event.getPlayer());
|
onReceive(event.getPacket(), event.getPlayer());
|
||||||
|
onReceive(event.getPacket(), event.getPlayer(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,6 +139,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSend(event.getPacket(), event.getPlayer());
|
onSend(event.getPacket(), event.getPlayer());
|
||||||
|
onSend(event.getPacket(), event.getPlayer(), event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ public abstract class EcoPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
this.getEventManager().unregisterAllListeners();
|
this.getEventManager().unregisterAllListeners();
|
||||||
this.getScheduler().cancelAll();
|
this.getScheduler().cancelAll();
|
||||||
|
this.getConfigHandler().saveAllConfigs();
|
||||||
|
|
||||||
this.disable();
|
this.disable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.willfp.eco.core;
|
package com.willfp.eco.core;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.proxy.ProxyConstants;
|
||||||
import com.willfp.eco.util.ClassUtils;
|
import com.willfp.eco.util.ClassUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -14,6 +15,7 @@ public class Prerequisite {
|
|||||||
* All existing prerequisites are registered on creation.
|
* All existing prerequisites are registered on creation.
|
||||||
*/
|
*/
|
||||||
private static final List<Prerequisite> VALUES = new ArrayList<>();
|
private static final List<Prerequisite> VALUES = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requires the server to be running an implementation of paper.
|
* Requires the server to be running an implementation of paper.
|
||||||
*/
|
*/
|
||||||
@@ -22,6 +24,23 @@ public class Prerequisite {
|
|||||||
"Requires server to be running paper (or a fork)"
|
"Requires server to be running paper (or a fork)"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requires the server to be running 1.17.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static final Prerequisite v1_17 = new Prerequisite(
|
||||||
|
() -> ProxyConstants.NMS_VERSION.contains("17"),
|
||||||
|
"Requires server to be running 1.17+"
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requires the server to be running 1.17.
|
||||||
|
*/
|
||||||
|
public static final Prerequisite HAS_1_17 = new Prerequisite(
|
||||||
|
() -> ProxyConstants.NMS_VERSION.contains("17"),
|
||||||
|
"Requires server to be running 1.17+"
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the necessary prerequisite condition has been met.
|
* If the necessary prerequisite condition has been met.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.core.config;
|
package com.willfp.eco.core.config;
|
||||||
|
|
||||||
import com.willfp.eco.internal.config.UpdatableYamlConfig;
|
import com.willfp.eco.internal.config.yaml.UpdatableYamlConfig;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ public interface Config {
|
|||||||
*/
|
*/
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the config into readable text.
|
||||||
|
*
|
||||||
|
* @return The plaintext.
|
||||||
|
*/
|
||||||
|
String toPlaintext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get if the config contains a key.
|
* Get if the config contains a key.
|
||||||
*
|
*
|
||||||
@@ -42,7 +49,7 @@ public interface Config {
|
|||||||
* Set an object in config.
|
* Set an object in config.
|
||||||
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#set(String, Object)}
|
* Default implementations call {@link org.bukkit.configuration.file.YamlConfiguration#set(String, Object)}
|
||||||
*
|
*
|
||||||
* @param path The path.
|
* @param path The path.
|
||||||
* @param object The object.
|
* @param object The object.
|
||||||
*/
|
*/
|
||||||
void set(@NotNull String path,
|
void set(@NotNull String path,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.core.config;
|
package com.willfp.eco.core.config;
|
||||||
|
|
||||||
import com.willfp.eco.internal.config.UpdatableYamlConfig;
|
import com.willfp.eco.internal.config.yaml.UpdatableYamlConfig;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.willfp.eco.core.config;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface JSONConfig extends Config {
|
||||||
|
/**
|
||||||
|
* Get a list of subsections from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
List<JSONConfig> getSubsections(@NotNull String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of subsections from config.
|
||||||
|
*
|
||||||
|
* @param path The key to fetch the value from.
|
||||||
|
* @return The found value, or null if not found.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
List<JSONConfig> getSubsectionsOrNull(@NotNull String path);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.willfp.eco.core.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.internal.config.json.LoadableJsonConfig;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class JsonStaticBaseConfig extends LoadableJsonConfig {
|
||||||
|
/**
|
||||||
|
* Config implementation for configs present in the plugin's base directory (eg config.json, lang.json).
|
||||||
|
* <p>
|
||||||
|
* Does not automatically update.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
*/
|
||||||
|
protected JsonStaticBaseConfig(@NotNull final String configName,
|
||||||
|
@NotNull final EcoPlugin plugin) {
|
||||||
|
super(configName, plugin, "", plugin.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.willfp.eco.core.config;
|
package com.willfp.eco.core.config;
|
||||||
|
|
||||||
import com.willfp.eco.internal.config.LoadableYamlConfig;
|
import com.willfp.eco.internal.config.yaml.LoadableYamlConfig;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.willfp.eco.core.config;
|
package com.willfp.eco.core.config;
|
||||||
|
|
||||||
import com.willfp.eco.internal.config.ConfigWrapper;
|
import com.willfp.eco.internal.config.yaml.YamlConfigWrapper;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public abstract class YamlConfig extends ConfigWrapper<YamlConfiguration> {
|
public abstract class YamlConfig extends YamlConfigWrapper<YamlConfiguration> {
|
||||||
/**
|
/**
|
||||||
* Config implementation for passing YamlConfigurations.
|
* Config implementation for passing YamlConfigurations.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
85
eco-api/src/main/java/com/willfp/eco/core/data/Data.java
Normal file
85
eco-api/src/main/java/com/willfp/eco/core/data/Data.java
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package com.willfp.eco.core.data;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.core.config.Config;
|
||||||
|
import com.willfp.eco.core.config.JSONConfig;
|
||||||
|
import com.willfp.eco.core.config.JsonStaticBaseConfig;
|
||||||
|
import com.willfp.eco.internal.config.LoadableConfig;
|
||||||
|
import com.willfp.eco.internal.config.json.JSONConfigSection;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class Data {
|
||||||
|
/**
|
||||||
|
* Instance of eco data.yml.
|
||||||
|
*/
|
||||||
|
private static JSONConfig datafile = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All cached player data.
|
||||||
|
*/
|
||||||
|
private static final Map<UUID, Map<EcoPlugin, JSONConfig>> PLAYER_DATA = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the player data with an instance of data.json.
|
||||||
|
*
|
||||||
|
* @param config data.json.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void init(@NotNull final JsonStaticBaseConfig config) {
|
||||||
|
datafile = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save to data.yml.
|
||||||
|
*
|
||||||
|
* @param config Instance of data.yml.
|
||||||
|
* @throws IOException Error during saving.
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void save(@NotNull final Config config) throws IOException {
|
||||||
|
for (Map.Entry<UUID, Map<EcoPlugin, JSONConfig>> entry : PLAYER_DATA.entrySet()) {
|
||||||
|
entry.getValue().forEach((plugin, jsonConfig) -> {
|
||||||
|
for (String key : jsonConfig.getKeys(false)) {
|
||||||
|
config.set("player-data." + plugin.getName().toLowerCase() + "." + entry.getKey().toString() + "." + key, jsonConfig);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
((LoadableConfig) config).save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the data for a player.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @return The data.
|
||||||
|
*/
|
||||||
|
public JSONConfig getData(@NotNull final OfflinePlayer player,
|
||||||
|
@NotNull final EcoPlugin plugin) {
|
||||||
|
if (!PLAYER_DATA.containsKey(player.getUniqueId())) {
|
||||||
|
PLAYER_DATA.put(player.getUniqueId(), new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONConfig config = PLAYER_DATA.get(player.getUniqueId()).get(plugin);
|
||||||
|
|
||||||
|
if (config == null) {
|
||||||
|
config = (JSONConfig) datafile.getSubsectionOrNull("player-data." + plugin.getName().toLowerCase() + "." + player.getUniqueId());
|
||||||
|
if (config == null) {
|
||||||
|
config = new JSONConfigSection(new HashMap<>());
|
||||||
|
}
|
||||||
|
PLAYER_DATA.get(player.getUniqueId()).put(plugin, config);
|
||||||
|
return getData(player, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package com.willfp.eco.core.events;
|
||||||
|
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class PlayerJumpEvent extends PlayerMoveEvent {
|
||||||
|
/**
|
||||||
|
* Internal bukkit.
|
||||||
|
*/
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new PlayerJumpEvent.
|
||||||
|
*
|
||||||
|
* @param event The PlayerMoveEvent.
|
||||||
|
*/
|
||||||
|
public PlayerJumpEvent(@NotNull final PlayerMoveEvent event) {
|
||||||
|
super(event.getPlayer(), event.getFrom(), event.getTo());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal bukkit.
|
||||||
|
*
|
||||||
|
* @return The handlers.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal bukkit.
|
||||||
|
*
|
||||||
|
* @return The handlers.
|
||||||
|
*/
|
||||||
|
public static @NotNull HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,5 +4,11 @@ import org.bukkit.metadata.FixedMetadataValue;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface MetadataValueFactory {
|
public interface MetadataValueFactory {
|
||||||
|
/**
|
||||||
|
* Create a metadata value for a given plugin and object.
|
||||||
|
*
|
||||||
|
* @param value The object to store in metadata.
|
||||||
|
* @return The metadata value.
|
||||||
|
*/
|
||||||
FixedMetadataValue create(@NotNull Object value);
|
FixedMetadataValue create(@NotNull Object value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.willfp.eco.core.gui.menu;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.gui.slot.Slot;
|
||||||
|
import com.willfp.eco.core.items.builder.ItemStackBuilder;
|
||||||
|
import com.willfp.eco.internal.gui.FillerSlot;
|
||||||
|
import com.willfp.eco.util.ListUtils;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FillerMask {
|
||||||
|
/**
|
||||||
|
* Mask.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final List<List<Slot>> mask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new filler mask.
|
||||||
|
*
|
||||||
|
* @param material The mask material.
|
||||||
|
* @param pattern The pattern.
|
||||||
|
*/
|
||||||
|
public FillerMask(@NotNull final Material material,
|
||||||
|
@NotNull final String... pattern) {
|
||||||
|
if (material == Material.AIR) {
|
||||||
|
throw new IllegalArgumentException("Material cannot be air!");
|
||||||
|
}
|
||||||
|
|
||||||
|
mask = ListUtils.create2DList(6, 9);
|
||||||
|
|
||||||
|
ItemStack itemStack = new ItemStackBuilder(material)
|
||||||
|
.setDisplayName("&r")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
int row = 0;
|
||||||
|
|
||||||
|
for (String patternRow : pattern) {
|
||||||
|
int column = 0;
|
||||||
|
if (patternRow.length() != 9) {
|
||||||
|
throw new IllegalArgumentException("Invalid amount of columns in pattern!");
|
||||||
|
}
|
||||||
|
for (char c : patternRow.toCharArray()) {
|
||||||
|
if (c == '0') {
|
||||||
|
mask.get(row).set(column, null);
|
||||||
|
} else if (c == '1') {
|
||||||
|
mask.get(row).set(column, new FillerSlot(itemStack));
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid character in pattern! (Must only be 0 and 1)");
|
||||||
|
}
|
||||||
|
|
||||||
|
column++;
|
||||||
|
}
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
146
eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
Normal file
146
eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
package com.willfp.eco.core.gui.menu;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.gui.slot.Slot;
|
||||||
|
import com.willfp.eco.internal.gui.EcoMenu;
|
||||||
|
import com.willfp.eco.internal.gui.FillerSlot;
|
||||||
|
import com.willfp.eco.util.ListUtils;
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public interface Menu {
|
||||||
|
/**
|
||||||
|
* Get the amount of rows.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int getRows();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get slot at given row and column.
|
||||||
|
*
|
||||||
|
* @param row The row.
|
||||||
|
* @param column The column.
|
||||||
|
* @return The row.
|
||||||
|
*/
|
||||||
|
Slot getSlot(int row,
|
||||||
|
int column);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the menu title.
|
||||||
|
*
|
||||||
|
* @return The title.
|
||||||
|
*/
|
||||||
|
String getTitle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the inventory for the player.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @return The inventory.
|
||||||
|
*/
|
||||||
|
Inventory open(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a builder with a given amount of rows.
|
||||||
|
*
|
||||||
|
* @param rows The rows.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
static Builder builder(final int rows) {
|
||||||
|
return new Builder(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Builder {
|
||||||
|
/**
|
||||||
|
* The amount of rows.
|
||||||
|
*/
|
||||||
|
private final int rows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The title.
|
||||||
|
*/
|
||||||
|
private String title = "Menu";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mask slots.
|
||||||
|
*/
|
||||||
|
private List<List<Slot>> maskSlots;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The slots.
|
||||||
|
*/
|
||||||
|
private final List<List<Slot>> slots;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The close event handler.
|
||||||
|
*/
|
||||||
|
private Consumer<InventoryCloseEvent> onClose = (event) -> {
|
||||||
|
};
|
||||||
|
|
||||||
|
Builder(final int rows) {
|
||||||
|
this.rows = rows;
|
||||||
|
this.slots = ListUtils.create2DList(rows, 9);
|
||||||
|
this.maskSlots = ListUtils.create2DList(rows, 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setTitle(@NotNull final String title) {
|
||||||
|
this.title = StringUtils.translate(title);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setSlot(final int row,
|
||||||
|
final int column,
|
||||||
|
@NotNull final Slot slot) {
|
||||||
|
if (row < 1 || row > this.rows) {
|
||||||
|
throw new IllegalArgumentException("Invalid row number!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column < 1 || column > 9) {
|
||||||
|
throw new IllegalArgumentException("Invalid column number!");
|
||||||
|
}
|
||||||
|
|
||||||
|
slots.get(row - 1).set(column - 1, slot);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setMask(@NotNull final FillerMask mask) {
|
||||||
|
this.maskSlots = mask.getMask();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder onClose(@NotNull final Consumer<InventoryCloseEvent> action) {
|
||||||
|
this.onClose = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Menu build() {
|
||||||
|
List<List<Slot>> finalSlots = maskSlots;
|
||||||
|
for (int i = 0; i < slots.size(); i++) {
|
||||||
|
for (int j = 0; j < slots.get(i).size(); j++) {
|
||||||
|
Slot slot = slots.get(i).get(j);
|
||||||
|
if (slot != null) {
|
||||||
|
finalSlots.get(i).set(j, slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (List<Slot> finalSlot : finalSlots) {
|
||||||
|
for (int j = 0; j < finalSlot.size(); j++) {
|
||||||
|
if (finalSlot.get(j) == null) {
|
||||||
|
finalSlot.set(j, new FillerSlot(new ItemStack(Material.AIR)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EcoMenu(rows, finalSlots, title, onClose);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
105
eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
Normal file
105
eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package com.willfp.eco.core.gui.slot;
|
||||||
|
|
||||||
|
import com.willfp.eco.internal.gui.EcoSlot;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public interface Slot {
|
||||||
|
/**
|
||||||
|
* Get the ItemStack that would be shown to a player.
|
||||||
|
*
|
||||||
|
* @param player The player.
|
||||||
|
* @return The ItemStack.
|
||||||
|
*/
|
||||||
|
ItemStack getItemStack(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a builder for an ItemStack.
|
||||||
|
*
|
||||||
|
* @param itemStack The ItemStack.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
static Builder builder(@NotNull final ItemStack itemStack) {
|
||||||
|
return new Builder((player) -> itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a builder for a player-specific ItemStack.
|
||||||
|
*
|
||||||
|
* @param provider The provider.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
static Builder builder(@NotNull final Function<Player, ItemStack> provider) {
|
||||||
|
return new Builder(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Builder {
|
||||||
|
/**
|
||||||
|
* Provider.
|
||||||
|
*/
|
||||||
|
private final Function<Player, ItemStack> provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Left click handler.
|
||||||
|
*/
|
||||||
|
private BiConsumer<InventoryClickEvent, Slot> onLeftClick = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Right click handler.
|
||||||
|
*/
|
||||||
|
private BiConsumer<InventoryClickEvent, Slot> onRightClick = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift-Left-Click handler.
|
||||||
|
*/
|
||||||
|
private BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift-Right-Click handler.
|
||||||
|
*/
|
||||||
|
private BiConsumer<InventoryClickEvent, Slot> onShiftRightClick = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Middle click handler.
|
||||||
|
*/
|
||||||
|
private BiConsumer<InventoryClickEvent, Slot> onMiddleClick = null;
|
||||||
|
|
||||||
|
Builder(@NotNull final Function<Player, ItemStack> provider) {
|
||||||
|
this.provider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder onLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||||
|
this.onLeftClick = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder onRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||||
|
this.onRightClick = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder onShiftLeftClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||||
|
this.onShiftLeftClick = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder onShiftRightClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||||
|
this.onShiftRightClick = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder onMiddleClick(@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||||
|
this.onMiddleClick = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Slot build() {
|
||||||
|
return new EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ public class PlaceholderManager {
|
|||||||
public static String getResult(@Nullable final Player player,
|
public static String getResult(@Nullable final Player player,
|
||||||
@NotNull final String identifier) {
|
@NotNull final String identifier) {
|
||||||
Optional<PlaceholderEntry> matching = REGISTERED_PLACEHOLDERS.stream().filter(expansion -> expansion.getIdentifier().equalsIgnoreCase(identifier)).findFirst();
|
Optional<PlaceholderEntry> matching = REGISTERED_PLACEHOLDERS.stream().filter(expansion -> expansion.getIdentifier().equalsIgnoreCase(identifier)).findFirst();
|
||||||
if (!matching.isPresent()) {
|
if (matching.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PlaceholderEntry entry = matching.get();
|
PlaceholderEntry entry = matching.get();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
|
|||||||
|
|
||||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||||
|
import com.willfp.eco.core.recipe.parts.TestableStack;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@@ -40,6 +41,7 @@ public final class Items {
|
|||||||
*/
|
*/
|
||||||
public TestableItem lookup(@NotNull final String key) {
|
public TestableItem lookup(@NotNull final String key) {
|
||||||
String[] split = key.toLowerCase().split(":");
|
String[] split = key.toLowerCase().split(":");
|
||||||
|
|
||||||
if (split.length == 1) {
|
if (split.length == 1) {
|
||||||
Material material = Material.getMaterial(key.toUpperCase());
|
Material material = Material.getMaterial(key.toUpperCase());
|
||||||
if (material == null || material == Material.AIR) {
|
if (material == null || material == Material.AIR) {
|
||||||
@@ -48,8 +50,26 @@ public final class Items {
|
|||||||
return new MaterialTestableItem(material);
|
return new MaterialTestableItem(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
if (split.length == 2) {
|
||||||
return part == null ? new EmptyTestableItem() : part;
|
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||||
|
|
||||||
|
if (part == null) {
|
||||||
|
Material material = Material.getMaterial(split[0].toUpperCase());
|
||||||
|
if (material == null || material == Material.AIR) {
|
||||||
|
return new EmptyTestableItem();
|
||||||
|
}
|
||||||
|
return new TestableStack(new MaterialTestableItem(material), Integer.parseInt(split[1]));
|
||||||
|
} else {
|
||||||
|
return part;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (split.length == 3) {
|
||||||
|
CustomItem part = REGISTRY.get(new NamespacedKey(split[0], split[1]));
|
||||||
|
return part == null ? new EmptyTestableItem() : new TestableStack(part, Integer.parseInt(split[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EmptyTestableItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.willfp.eco.core.items.builder;
|
||||||
|
|
||||||
|
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class EnchantedBookBuilder extends AbstractItemStackBuilder<EnchantmentStorageMeta, EnchantedBookBuilder> {
|
||||||
|
/**
|
||||||
|
* Create a new EnchantedBookBuilder.
|
||||||
|
*/
|
||||||
|
public EnchantedBookBuilder() {
|
||||||
|
super(Material.ENCHANTED_BOOK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an enchantment to the item.
|
||||||
|
*
|
||||||
|
* @param enchantment The enchantment.
|
||||||
|
* @param level The level.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
public EnchantedBookBuilder addStoredEnchantment(@NotNull final Enchantment enchantment,
|
||||||
|
final int level) {
|
||||||
|
this.getMeta().addStoredEnchant(enchantment, level, true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package com.willfp.eco.core.items.builder;
|
||||||
|
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public interface ItemBuilder {
|
||||||
|
/**
|
||||||
|
* Set the ItemStack amount.
|
||||||
|
*
|
||||||
|
* @param amount The amount.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setAmount(int amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the ItemStack amount.
|
||||||
|
*
|
||||||
|
* @param amount The amount.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setAmount(@NotNull Supplier<Integer> amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an enchantment to the item.
|
||||||
|
*
|
||||||
|
* @param enchantment The enchantment.
|
||||||
|
* @param level The level.
|
||||||
|
* @return The builder.r
|
||||||
|
*/
|
||||||
|
ItemBuilder addEnchantment(@NotNull Enchantment enchantment,
|
||||||
|
int level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an enchantment to the item.
|
||||||
|
*
|
||||||
|
* @param enchantment The enchantment.
|
||||||
|
* @param level The level.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addEnchantment(@NotNull Supplier<Enchantment> enchantment,
|
||||||
|
@NotNull Supplier<Integer> level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the item display name.
|
||||||
|
*
|
||||||
|
* @param name The name.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setDisplayName(@NotNull String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the item display name.
|
||||||
|
*
|
||||||
|
* @param name The name.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setDisplayName(@NotNull Supplier<String> name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add lore line.
|
||||||
|
*
|
||||||
|
* @param line The line.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addLoreLine(@NotNull String line);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add lore line.
|
||||||
|
*
|
||||||
|
* @param line The line.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addLoreLine(@NotNull Supplier<String> line);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add lore lines.
|
||||||
|
*
|
||||||
|
* @param lines The lines.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addLoreLines(@NotNull List<String> lines);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add lore lines.
|
||||||
|
*
|
||||||
|
* @param lines The lines.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addLoreLines(@NotNull Supplier<List<String>> lines);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add ItemFlags.
|
||||||
|
*
|
||||||
|
* @param itemFlags The flags.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addItemFlag(@NotNull ItemFlag... itemFlags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add ItemFlags.
|
||||||
|
*
|
||||||
|
* @param itemFlags The flags.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder addItemFlag(@NotNull Supplier<ItemFlag[]> itemFlags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write meta key.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param type The type.
|
||||||
|
* @param value The value.
|
||||||
|
* @param <A> The type.
|
||||||
|
* @param <B> The type.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
<A, B> ItemBuilder writeMetaKey(@NotNull NamespacedKey key,
|
||||||
|
@NotNull PersistentDataType<A, B> type,
|
||||||
|
@NotNull B value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write meta key.
|
||||||
|
*
|
||||||
|
* @param key The key.
|
||||||
|
* @param type The type.
|
||||||
|
* @param value The value.
|
||||||
|
* @param <A> The type.
|
||||||
|
* @param <B> The type.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
<A, B> ItemBuilder writeMetaKey(@NotNull Supplier<NamespacedKey> key,
|
||||||
|
@NotNull Supplier<PersistentDataType<A, B>> type,
|
||||||
|
@NotNull Supplier<B> value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set unbreakable.
|
||||||
|
*
|
||||||
|
* @param unbreakable If the item should be unbreakable.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setUnbreakable(boolean unbreakable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set unbreakable.
|
||||||
|
*
|
||||||
|
* @param unbreakable If the item should be unbreakable.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setUnbreakable(@NotNull Supplier<Boolean> unbreakable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set custom model data.
|
||||||
|
*
|
||||||
|
* @param data The data.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setCustomModelData(@Nullable Integer data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set custom model data.
|
||||||
|
*
|
||||||
|
* @param data The data.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
ItemBuilder setCustomModelData(@NotNull Supplier<Integer> data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the item.
|
||||||
|
*
|
||||||
|
* @return The item.
|
||||||
|
*/
|
||||||
|
ItemStack build();
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.willfp.eco.core.items.builder;
|
||||||
|
|
||||||
|
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ItemStackBuilder extends AbstractItemStackBuilder<ItemMeta, ItemStackBuilder> {
|
||||||
|
/**
|
||||||
|
* Create a new ItemStackBuilder.
|
||||||
|
*
|
||||||
|
* @param material The material.
|
||||||
|
*/
|
||||||
|
public ItemStackBuilder(@NotNull final Material material) {
|
||||||
|
super(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ItemStackBuilder to modify an existing item.
|
||||||
|
*
|
||||||
|
* @param base The ItemStack to start with.
|
||||||
|
*/
|
||||||
|
public ItemStackBuilder(@NotNull final ItemStack base) {
|
||||||
|
super(base);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.willfp.eco.core.items.builder;
|
||||||
|
|
||||||
|
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||||
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class LeatherArmorBuilder extends AbstractItemStackBuilder<LeatherArmorMeta, LeatherArmorBuilder> {
|
||||||
|
/**
|
||||||
|
* Create a new ItemStackBuilder.
|
||||||
|
*
|
||||||
|
* @param material The material.
|
||||||
|
*/
|
||||||
|
public LeatherArmorBuilder(@NotNull final Material material) {
|
||||||
|
super(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ItemStackBuilder to modify an existing item.
|
||||||
|
*
|
||||||
|
* @param base The ItemStack to start with.
|
||||||
|
*/
|
||||||
|
public LeatherArmorBuilder(@NotNull final ItemStack base) {
|
||||||
|
super(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set leather color.
|
||||||
|
*
|
||||||
|
* @param color The color.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
public LeatherArmorBuilder setColor(@NotNull final java.awt.Color color) {
|
||||||
|
Color bukkitColor = Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue());
|
||||||
|
this.getMeta().setColor(bukkitColor);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.willfp.eco.core.items.builder;
|
||||||
|
|
||||||
|
import com.willfp.eco.internal.items.AbstractItemStackBuilder;
|
||||||
|
import com.willfp.eco.util.SkullUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class SkullBuilder extends AbstractItemStackBuilder<SkullMeta, SkullBuilder> {
|
||||||
|
/**
|
||||||
|
* Create a new EnchantedBookBuilder.
|
||||||
|
*/
|
||||||
|
public SkullBuilder() {
|
||||||
|
super(Material.PLAYER_HEAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set skull texture.
|
||||||
|
*
|
||||||
|
* @param texture The texture.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
public SkullBuilder setSkullTexture(@NotNull final String texture) {
|
||||||
|
SkullUtils.setSkullTexture(this.getMeta(), texture);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,13 +2,18 @@ package com.willfp.eco.core.recipe;
|
|||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.core.items.Items;
|
||||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||||
|
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class Recipes {
|
public class Recipes {
|
||||||
@@ -59,4 +64,29 @@ public class Recipes {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and register recipe.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @param key The key.
|
||||||
|
* @param output The output.
|
||||||
|
* @param recipeStrings The recipe.
|
||||||
|
* @return The recipe.
|
||||||
|
*/
|
||||||
|
public CraftingRecipe createAndRegisterRecipe(@NotNull final EcoPlugin plugin,
|
||||||
|
@NotNull final String key,
|
||||||
|
@NotNull final ItemStack output,
|
||||||
|
@NotNull final List<String> recipeStrings) {
|
||||||
|
ShapedCraftingRecipe.Builder builder = ShapedCraftingRecipe.builder(plugin, key).setOutput(output);
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
builder.setRecipePart(i, Items.lookup(recipeStrings.get(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ShapedCraftingRecipe recipe = builder.build();
|
||||||
|
recipe.register();
|
||||||
|
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.willfp.eco.core.recipe.parts;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.items.TestableItem;
|
||||||
|
import com.willfp.eco.internal.InternalInterfacing;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TestableStack implements TestableItem {
|
||||||
|
/**
|
||||||
|
* The item.
|
||||||
|
*/
|
||||||
|
private final TestableItem handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The amount.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final int amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new testable stack.
|
||||||
|
*
|
||||||
|
* @param item The item.
|
||||||
|
* @param amount The amount.
|
||||||
|
*/
|
||||||
|
public TestableStack(@NotNull final TestableItem item,
|
||||||
|
final int amount) {
|
||||||
|
Validate.isTrue(!(item instanceof TestableStack));
|
||||||
|
|
||||||
|
this.handle = item;
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the item matches the material.
|
||||||
|
*
|
||||||
|
* @param itemStack The item to test.
|
||||||
|
* @return If the item is of the specified material.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||||
|
return itemStack != null && handle.matches(itemStack) && itemStack.getAmount() >= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItem() {
|
||||||
|
ItemStack temp = handle.getItem().clone();
|
||||||
|
ItemMeta meta = temp.getItemMeta();
|
||||||
|
assert meta != null;
|
||||||
|
|
||||||
|
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||||
|
assert lore != null;
|
||||||
|
lore.add("");
|
||||||
|
String add = InternalInterfacing.getInstance().getLang().getString("multiple-in-craft");
|
||||||
|
add = add.replace("%amount%", String.valueOf(amount));
|
||||||
|
lore.add(add);
|
||||||
|
meta.setLore(lore);
|
||||||
|
temp.setItemMeta(meta);
|
||||||
|
temp.setAmount(amount);
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
69
eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
Normal file
69
eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package com.willfp.eco.core.web;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class Paste {
|
||||||
|
/**
|
||||||
|
* The contents.
|
||||||
|
*/
|
||||||
|
private final String contents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new paste.
|
||||||
|
*
|
||||||
|
* @param contents The contents.
|
||||||
|
*/
|
||||||
|
public Paste(@NotNull final String contents) {
|
||||||
|
this.contents = contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload to hastebin and get a token.
|
||||||
|
*
|
||||||
|
* @return The token.
|
||||||
|
*/
|
||||||
|
public String getHastebinToken() {
|
||||||
|
try {
|
||||||
|
String urly = "https://hastebin.com/documents";
|
||||||
|
URL obj = new URL(urly);
|
||||||
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
|
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
|
|
||||||
|
con.setDoOutput(true);
|
||||||
|
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
|
||||||
|
wr.writeBytes(contents);
|
||||||
|
wr.flush();
|
||||||
|
wr.close();
|
||||||
|
|
||||||
|
BufferedReader iny = new BufferedReader(
|
||||||
|
new InputStreamReader(con.getInputStream()));
|
||||||
|
String output;
|
||||||
|
StringBuilder responseBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
while ((output = iny.readLine()) != null) {
|
||||||
|
responseBuilder.append(output);
|
||||||
|
}
|
||||||
|
iny.close();
|
||||||
|
|
||||||
|
String responseString = responseBuilder.toString();
|
||||||
|
|
||||||
|
responseString = responseString.replace("{\"key\":\"", "");
|
||||||
|
responseString = responseString.replace("\"}", "");
|
||||||
|
|
||||||
|
return responseString;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.willfp.eco.internal;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.config.base.LangYml;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public abstract class InternalInterfacing {
|
||||||
|
private static InternalInterfacing interfacing;
|
||||||
|
|
||||||
|
public static void setInterfacing(@NotNull final InternalInterfacing interfacing) {
|
||||||
|
InternalInterfacing.interfacing = interfacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract LangYml getLang();
|
||||||
|
|
||||||
|
public static InternalInterfacing getInstance() {
|
||||||
|
return interfacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,14 +31,13 @@ public class ArrowDataListener extends PluginDependent implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onLaunch(final ProjectileLaunchEvent event) {
|
public void onLaunch(final ProjectileLaunchEvent event) {
|
||||||
if (!(event.getEntity() instanceof Arrow)) {
|
if (!(event.getEntity() instanceof Arrow arrow)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
if (!(event.getEntity().getShooter() instanceof LivingEntity)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arrow arrow = (Arrow) event.getEntity();
|
|
||||||
LivingEntity entity = (LivingEntity) arrow.getShooter();
|
LivingEntity entity = (LivingEntity) arrow.getShooter();
|
||||||
|
|
||||||
if (entity.getEquipment() == null) {
|
if (entity.getEquipment() == null) {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.willfp.eco.internal.config;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class ConfigSection extends ConfigWrapper<ConfigurationSection> {
|
|
||||||
/**
|
|
||||||
* Config section.
|
|
||||||
*
|
|
||||||
* @param section The section.
|
|
||||||
*/
|
|
||||||
protected ConfigSection(@NotNull final ConfigurationSection section) {
|
|
||||||
this.init(section);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.willfp.eco.internal.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface LoadableConfig {
|
||||||
|
/**
|
||||||
|
* Create the file.
|
||||||
|
*/
|
||||||
|
void createFile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get resource path as relative to base directory.
|
||||||
|
*
|
||||||
|
* @return The resource path.
|
||||||
|
*/
|
||||||
|
String getResourcePath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the config.
|
||||||
|
*
|
||||||
|
* @throws IOException If error in saving.
|
||||||
|
*/
|
||||||
|
void save() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the config file.
|
||||||
|
*
|
||||||
|
* @return The file.
|
||||||
|
*/
|
||||||
|
File getConfigFile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the config name (including extension)
|
||||||
|
*
|
||||||
|
* @return The name.
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.willfp.eco.internal.config.json;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class JSONConfigSection extends JSONConfigWrapper {
|
||||||
|
/**
|
||||||
|
* Config section.
|
||||||
|
*
|
||||||
|
* @param values The values.
|
||||||
|
*/
|
||||||
|
public JSONConfigSection(@NotNull final Map<String, Object> values) {
|
||||||
|
this.init(values);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,345 @@
|
|||||||
|
package com.willfp.eco.internal.config.json;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.willfp.eco.core.config.Config;
|
||||||
|
import com.willfp.eco.core.config.JSONConfig;
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "unused"})
|
||||||
|
public abstract class JSONConfigWrapper implements JSONConfig, Cloneable {
|
||||||
|
/**
|
||||||
|
* The linked {@link ConfigurationSection} where values are physically stored.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final Gson handle = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All stored values.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final Map<String, Object> values = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All cached values.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final Map<String, Object> cache = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract config.
|
||||||
|
*/
|
||||||
|
protected JSONConfigWrapper() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(@NotNull final Map<String, Object> values) {
|
||||||
|
this.values.clear();
|
||||||
|
this.values.putAll(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void clearCache() {
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toPlaintext() {
|
||||||
|
return this.getHandle().toJson(this.getValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean has(@NotNull final String path) {
|
||||||
|
return getOfKnownType(path, Object.class) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected <T> T getOfKnownType(@NotNull final String path,
|
||||||
|
@NotNull final Class<T> clazz) {
|
||||||
|
return getOfKnownType(path, clazz, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected <T> T getOfKnownType(@NotNull final String path,
|
||||||
|
@NotNull final Class<T> clazz,
|
||||||
|
final boolean isBase) {
|
||||||
|
String closestPath = path;
|
||||||
|
|
||||||
|
if (cache.containsKey(path) && isBase) {
|
||||||
|
return (T) cache.get(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path.contains(".")) {
|
||||||
|
String[] split = path.split("\\.");
|
||||||
|
closestPath = split[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (values.get(closestPath) instanceof Map && !path.equals(closestPath)) {
|
||||||
|
JSONConfigSection section = new JSONConfigSection((Map<String, Object>) values.get(closestPath));
|
||||||
|
return section.getOfKnownType(path.substring(closestPath.length() + 1), clazz, false);
|
||||||
|
} else {
|
||||||
|
if (values.containsKey(closestPath)) {
|
||||||
|
return (T) values.get(closestPath);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<String> getKeys(final boolean deep) {
|
||||||
|
if (deep) {
|
||||||
|
return new ArrayList<>(getDeepKeys(new HashSet<>(), ""));
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>(values.keySet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Set<String> getDeepKeys(@NotNull final Set<String> list,
|
||||||
|
@NotNull final String root) {
|
||||||
|
for (String key : values.keySet()) {
|
||||||
|
list.add(root + key);
|
||||||
|
|
||||||
|
if (values.get(key) instanceof Map) {
|
||||||
|
JSONConfigSection section = new JSONConfigSection((Map<String, Object>) values.get(key));
|
||||||
|
list.addAll(section.getDeepKeys(list, root + key + "."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Object get(@NotNull final String path) {
|
||||||
|
return getOfKnownType(path, Object.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(@NotNull final String path,
|
||||||
|
@Nullable final Object object) {
|
||||||
|
setRecursively(path, object, true);
|
||||||
|
clearCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setRecursively(@NotNull final String path,
|
||||||
|
@Nullable final Object object,
|
||||||
|
final boolean isBase) {
|
||||||
|
String closestPath = path;
|
||||||
|
|
||||||
|
if (path.contains(".")) {
|
||||||
|
String[] split = path.split("\\.");
|
||||||
|
closestPath = split[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (values.get(closestPath) instanceof Map && !path.equals(closestPath)) {
|
||||||
|
JSONConfigSection section = new JSONConfigSection((Map<String, Object>) values.get(closestPath));
|
||||||
|
section.setRecursively(path.substring(closestPath.length() + 1), object, false);
|
||||||
|
values.put(closestPath, section.getValues());
|
||||||
|
} else {
|
||||||
|
Object obj = object;
|
||||||
|
|
||||||
|
if (object instanceof JSONConfig) {
|
||||||
|
obj = ((JSONConfigWrapper) object).getValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
values.put(path, obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public Config getSubsection(@NotNull final String path) {
|
||||||
|
Config subsection = getSubsectionOrNull(path);
|
||||||
|
Validate.notNull(subsection);
|
||||||
|
return subsection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Config getSubsectionOrNull(@NotNull final String path) {
|
||||||
|
if (values.containsKey(path)) {
|
||||||
|
Map<String, Object> subsection = (Map<String, Object>) values.get(path);
|
||||||
|
return new JSONConfigSection(subsection);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<JSONConfig> getSubsections(@NotNull final String path) {
|
||||||
|
List<JSONConfig> subsections = getSubsectionsOrNull(path);
|
||||||
|
Validate.notNull(subsections);
|
||||||
|
return subsections;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public List<JSONConfig> getSubsectionsOrNull(@NotNull final String path) {
|
||||||
|
List<Map<String, Object>> maps = (List<Map<String, Object>>) getOfKnownType(path, Object.class);
|
||||||
|
|
||||||
|
if (maps == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<JSONConfig> configs = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Map<String, Object> map : maps) {
|
||||||
|
configs.add(new JSONConfigSection(map));
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInt(@NotNull final String path) {
|
||||||
|
// ew
|
||||||
|
return Objects.requireNonNullElse(getOfKnownType(path, Double.class), 0D).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Integer getIntOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInt(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInt(@NotNull final String path,
|
||||||
|
final int def) {
|
||||||
|
return Objects.requireNonNullElse(getOfKnownType(path, Integer.class), def);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<Integer> getInts(@NotNull final String path) {
|
||||||
|
return (List<Integer>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getInts(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getBool(@NotNull final String path) {
|
||||||
|
return Objects.requireNonNullElse(getOfKnownType(path, Boolean.class), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Boolean getBoolOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBool(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<Boolean> getBools(@NotNull final String path) {
|
||||||
|
return (List<Boolean>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getBools(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public String getString(@NotNull final String path) {
|
||||||
|
return StringUtils.translate(Objects.requireNonNullElse(getOfKnownType(path, String.class), ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public String getStringOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getString(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<String> getStrings(@NotNull final String path) {
|
||||||
|
return StringUtils.translateList((List<String>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public List<String> getStringsOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getStrings(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDouble(@NotNull final String path) {
|
||||||
|
return Objects.requireNonNullElse(getOfKnownType(path, Double.class), 0D);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Double getDoubleOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDouble(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public List<Double> getDoubles(@NotNull final String path) {
|
||||||
|
return (List<Double>) Objects.requireNonNullElse(getOfKnownType(path, Object.class), new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||||
|
if (has(path)) {
|
||||||
|
return getDoubles(path);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONConfigWrapper clone() {
|
||||||
|
return new JSONConfigSection(new HashMap<>(this.getValues()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
package com.willfp.eco.internal.config.json;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.internal.config.LoadableConfig;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "unused"})
|
||||||
|
public abstract class LoadableJsonConfig extends JSONConfigWrapper implements LoadableConfig {
|
||||||
|
/**
|
||||||
|
* The physical config file, as stored on disk.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final File configFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plugin handle.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final EcoPlugin plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The full name of the config file (eg config.json).
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subdirectory path.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final String subDirectoryPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The provider of the config.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final Class<?> source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract config.
|
||||||
|
*
|
||||||
|
* @param configName The name of the config
|
||||||
|
* @param plugin The plugin.
|
||||||
|
* @param subDirectoryPath The subdirectory path.
|
||||||
|
* @param source The class that owns the resource.
|
||||||
|
*/
|
||||||
|
protected LoadableJsonConfig(@NotNull final String configName,
|
||||||
|
@NotNull final EcoPlugin plugin,
|
||||||
|
@NotNull final String subDirectoryPath,
|
||||||
|
@NotNull final Class<?> source) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.name = configName + ".json";
|
||||||
|
this.source = source;
|
||||||
|
this.subDirectoryPath = subDirectoryPath;
|
||||||
|
|
||||||
|
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
|
||||||
|
if (!directory.exists()) {
|
||||||
|
directory.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!new File(directory, this.name).exists()) {
|
||||||
|
createFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.configFile = new File(directory, this.name);
|
||||||
|
|
||||||
|
try {
|
||||||
|
init(this.configFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getConfigHandler().addConfig(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createFile() {
|
||||||
|
String resourcePath = getResourcePath();
|
||||||
|
InputStream in = source.getResourceAsStream(resourcePath);
|
||||||
|
|
||||||
|
File outFile = new File(this.getPlugin().getDataFolder(), resourcePath);
|
||||||
|
int lastIndex = resourcePath.lastIndexOf('/');
|
||||||
|
File outDir = new File(this.getPlugin().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
||||||
|
|
||||||
|
if (!outDir.exists()) {
|
||||||
|
outDir.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!outFile.exists()) {
|
||||||
|
OutputStream out = new FileOutputStream(outFile);
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
out.close();
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get resource path as relative to base directory.
|
||||||
|
*
|
||||||
|
* @return The resource path.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getResourcePath() {
|
||||||
|
String resourcePath;
|
||||||
|
|
||||||
|
if (subDirectoryPath.isEmpty()) {
|
||||||
|
resourcePath = name;
|
||||||
|
} else {
|
||||||
|
resourcePath = subDirectoryPath + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "/" + resourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the config.
|
||||||
|
*
|
||||||
|
* @throws IOException If error in saving.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void save() throws IOException {
|
||||||
|
configFile.delete();
|
||||||
|
Files.write(configFile.toPath(), this.toPlaintext().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the config.
|
||||||
|
*
|
||||||
|
* @param file The config file.
|
||||||
|
* @throws FileNotFoundException If the file doesn't exist.
|
||||||
|
*/
|
||||||
|
public void init(@NotNull final File file) throws FileNotFoundException {
|
||||||
|
super.init(this.getHandle().fromJson(new FileReader(file), HashMap.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,29 @@
|
|||||||
package com.willfp.eco.internal.config.updating;
|
package com.willfp.eco.internal.config.updating;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.core.PluginDependent;
|
||||||
import com.willfp.eco.core.config.ConfigUpdater;
|
import com.willfp.eco.core.config.ConfigUpdater;
|
||||||
|
import com.willfp.eco.internal.config.LoadableConfig;
|
||||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException;
|
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdatableClassException;
|
||||||
import com.willfp.eco.internal.config.updating.exceptions.InvalidUpdateMethodException;
|
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 org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ConfigHandler extends PluginDependent {
|
public class ConfigHandler extends PluginDependent {
|
||||||
|
/**
|
||||||
|
* A set of all configs that can be saved.
|
||||||
|
*/
|
||||||
|
private final List<LoadableConfig> configs = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of all classes that can be updated.
|
* A set of all classes that can be updated.
|
||||||
*/
|
*/
|
||||||
@@ -35,15 +44,18 @@ public class ConfigHandler extends PluginDependent {
|
|||||||
public void callUpdate() {
|
public void callUpdate() {
|
||||||
updatableClasses.forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).forEach(method -> {
|
updatableClasses.forEach(clazz -> Arrays.stream(clazz.getDeclaredMethods()).forEach(method -> {
|
||||||
if (method.isAnnotationPresent(ConfigUpdater.class)) {
|
if (method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||||
if (method.getParameterTypes().length != 0) {
|
|
||||||
throw new InvalidUpdateMethodException("Update method must not have parameters.");
|
|
||||||
}
|
|
||||||
if (!Modifier.isStatic(method.getModifiers())) {
|
if (!Modifier.isStatic(method.getModifiers())) {
|
||||||
throw new InvalidUpdateMethodException("Update method must be static.");
|
throw new InvalidUpdateMethodException("Update method must be static.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
method.invoke(null);
|
if (method.getParameterCount() == 0) {
|
||||||
|
method.invoke(null);
|
||||||
|
} else if (method.getParameterCount() == 1) {
|
||||||
|
method.invoke(null, this.getPlugin());
|
||||||
|
} else {
|
||||||
|
throw new InvalidUpdateMethodException("Update method must have 0 parameters or a plugin parameter.");
|
||||||
|
}
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new InvalidUpdateMethodException("Update method generated an exception.");
|
throw new InvalidUpdateMethodException("Update method generated an exception.");
|
||||||
@@ -60,7 +72,7 @@ public class ConfigHandler extends PluginDependent {
|
|||||||
public void registerUpdatableClass(@NotNull final Class<?> updatableClass) {
|
public void registerUpdatableClass(@NotNull final Class<?> updatableClass) {
|
||||||
boolean isValid = false;
|
boolean isValid = false;
|
||||||
for (Method method : updatableClass.getDeclaredMethods()) {
|
for (Method method : updatableClass.getDeclaredMethods()) {
|
||||||
if (Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length == 0 && method.isAnnotationPresent(ConfigUpdater.class)) {
|
if (Modifier.isStatic(method.getModifiers()) && (method.getParameterCount() == 0 || method.getParameterCount() == 1) && method.isAnnotationPresent(ConfigUpdater.class)) {
|
||||||
isValid = true;
|
isValid = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -72,4 +84,25 @@ public class ConfigHandler extends PluginDependent {
|
|||||||
|
|
||||||
updatableClasses.add(updatableClass);
|
updatableClasses.add(updatableClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save all configs.
|
||||||
|
*/
|
||||||
|
public void saveAllConfigs() {
|
||||||
|
try {
|
||||||
|
for (LoadableConfig config : configs) {
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new config to be saved.
|
||||||
|
* @param config The config.
|
||||||
|
*/
|
||||||
|
public void addConfig(@NotNull final LoadableConfig config) {
|
||||||
|
configs.add(config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.willfp.eco.internal.config.yaml;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ConfigSection extends YamlConfigWrapper<ConfigurationSection> {
|
||||||
|
/**
|
||||||
|
* Config section.
|
||||||
|
*
|
||||||
|
* @param section The section.
|
||||||
|
*/
|
||||||
|
public ConfigSection(@NotNull final ConfigurationSection section) {
|
||||||
|
this.init(section);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,23 @@
|
|||||||
package com.willfp.eco.internal.config;
|
package com.willfp.eco.internal.config.yaml;
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.internal.config.LoadableConfig;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration> {
|
public abstract class LoadableYamlConfig extends YamlConfigWrapper<YamlConfiguration> implements LoadableConfig {
|
||||||
/**
|
/**
|
||||||
* The physical config file, as stored on disk.
|
* The physical config file, as stored on disk.
|
||||||
*/
|
*/
|
||||||
@Getter(AccessLevel.PROTECTED)
|
@Getter
|
||||||
private final File configFile;
|
private final File configFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -77,7 +74,8 @@ public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration
|
|||||||
init(YamlConfiguration.loadConfiguration(configFile));
|
init(YamlConfiguration.loadConfiguration(configFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createFile() {
|
@Override
|
||||||
|
public void createFile() {
|
||||||
String resourcePath = getResourcePath();
|
String resourcePath = getResourcePath();
|
||||||
InputStream in = source.getResourceAsStream(resourcePath);
|
InputStream in = source.getResourceAsStream(resourcePath);
|
||||||
|
|
||||||
@@ -102,14 +100,12 @@ public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration
|
|||||||
}
|
}
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin.getConfigHandler().addConfig(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get resource path as relative to base directory.
|
public String getResourcePath() {
|
||||||
*
|
|
||||||
* @return The resource path.
|
|
||||||
*/
|
|
||||||
protected String getResourcePath() {
|
|
||||||
String resourcePath;
|
String resourcePath;
|
||||||
|
|
||||||
if (subDirectoryPath.isEmpty()) {
|
if (subDirectoryPath.isEmpty()) {
|
||||||
@@ -121,35 +117,7 @@ public abstract class LoadableYamlConfig extends ConfigWrapper<YamlConfiguration
|
|||||||
return "/" + resourcePath;
|
return "/" + resourcePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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 {
|
public void save() throws IOException {
|
||||||
this.getHandle().save(this.getConfigFile());
|
this.getHandle().save(this.getConfigFile());
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
package com.willfp.eco.internal.config;
|
package com.willfp.eco.internal.config.yaml;
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -84,4 +88,23 @@ public abstract class UpdatableYamlConfig extends LoadableYamlConfig {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public YamlConfiguration getConfigInJar() {
|
||||||
|
InputStream newIn = this.getSource().getResourceAsStream(getResourcePath());
|
||||||
|
|
||||||
|
if (newIn == null) {
|
||||||
|
throw new NullPointerException(this.getName() + " is null?");
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||||
|
YamlConfiguration newConfig = new YamlConfiguration();
|
||||||
|
|
||||||
|
try {
|
||||||
|
newConfig.load(reader);
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package com.willfp.eco.internal.config;
|
package com.willfp.eco.internal.config.yaml;
|
||||||
|
|
||||||
import com.willfp.eco.util.StringUtils;
|
|
||||||
import com.willfp.eco.core.config.Config;
|
import com.willfp.eco.core.config.Config;
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "unused"})
|
@SuppressWarnings({"unchecked", "unused"})
|
||||||
public abstract class ConfigWrapper<T extends ConfigurationSection> implements Config {
|
public abstract class YamlConfigWrapper<T extends ConfigurationSection> implements Config {
|
||||||
/**
|
/**
|
||||||
* The linked {@link ConfigurationSection} where values are physically stored.
|
* The linked {@link ConfigurationSection} where values are physically stored.
|
||||||
*/
|
*/
|
||||||
@@ -30,7 +31,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
/**
|
/**
|
||||||
* Abstract config.
|
* Abstract config.
|
||||||
*/
|
*/
|
||||||
protected ConfigWrapper() {
|
protected YamlConfigWrapper() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +40,15 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toPlaintext() {
|
||||||
|
YamlConfiguration temp = new YamlConfiguration();
|
||||||
|
for (String key : handle.getKeys(true)) {
|
||||||
|
temp.set(key, handle.get(key));
|
||||||
|
}
|
||||||
|
return temp.saveToString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void clearCache() {
|
public final void clearCache() {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
@@ -64,6 +74,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
@Override
|
@Override
|
||||||
public void set(@NotNull final String path,
|
public void set(@NotNull final String path,
|
||||||
@Nullable final Object object) {
|
@Nullable final Object object) {
|
||||||
|
cache.remove(path);
|
||||||
handle.set(path, object);
|
handle.set(path, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +92,12 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
if (cache.containsKey(path)) {
|
if (cache.containsKey(path)) {
|
||||||
return (Config) cache.get(path);
|
return (Config) cache.get(path);
|
||||||
} else {
|
} else {
|
||||||
cache.put(path, new ConfigSection(Objects.requireNonNull(handle.getConfigurationSection(path))));
|
ConfigurationSection raw = handle.getConfigurationSection(path);
|
||||||
|
if (raw == null) {
|
||||||
|
cache.put(path, null);
|
||||||
|
} else {
|
||||||
|
cache.put(path, new ConfigSection(raw));
|
||||||
|
}
|
||||||
return getSubsectionOrNull(path);
|
return getSubsectionOrNull(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +220,7 @@ public abstract class ConfigWrapper<T extends ConfigurationSection> implements C
|
|||||||
@NotNull
|
@NotNull
|
||||||
public List<String> getStrings(@NotNull final String path) {
|
public List<String> getStrings(@NotNull final String path) {
|
||||||
if (cache.containsKey(path)) {
|
if (cache.containsKey(path)) {
|
||||||
return (List<String>) cache.get(path);
|
return StringUtils.translateList((List<String>) cache.get(path));
|
||||||
} else {
|
} else {
|
||||||
cache.put(path, has(path) ? new ArrayList<>(handle.getStringList(path)) : new ArrayList<>());
|
cache.put(path, has(path) ? new ArrayList<>(handle.getStringList(path)) : new ArrayList<>());
|
||||||
return getStrings(path);
|
return getStrings(path);
|
||||||
@@ -110,11 +110,10 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(object instanceof Extension)) {
|
if (!(object instanceof Extension extension)) {
|
||||||
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
Extension extension = (Extension) object;
|
|
||||||
extension.setMetadata(metadata);
|
extension.setMetadata(metadata);
|
||||||
extension.enable();
|
extension.enable();
|
||||||
extensions.add(extension);
|
extensions.add(extension);
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.willfp.eco.internal.gui;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.gui.menu.Menu;
|
||||||
|
import com.willfp.eco.core.gui.slot.Slot;
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class EcoMenu implements Menu {
|
||||||
|
@Getter
|
||||||
|
private final int rows;
|
||||||
|
|
||||||
|
private final List<List<Slot>> slots;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final String title;
|
||||||
|
|
||||||
|
private final Consumer<InventoryCloseEvent> onClose;
|
||||||
|
|
||||||
|
public EcoMenu(final int rows,
|
||||||
|
@NotNull final List<List<Slot>> slots,
|
||||||
|
@NotNull final String title,
|
||||||
|
@NotNull final Consumer<InventoryCloseEvent> onClose) {
|
||||||
|
this.rows = rows;
|
||||||
|
this.slots = slots;
|
||||||
|
this.title = title;
|
||||||
|
this.onClose = onClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Slot getSlot(final int row,
|
||||||
|
final int column) {
|
||||||
|
if (row < 1 || row > this.rows) {
|
||||||
|
throw new IllegalArgumentException("Invalid row number!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column < 1 || column > 9) {
|
||||||
|
throw new IllegalArgumentException("Invalid column number!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return slots.get(row - 1).get(column - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory open(@NotNull final Player player) {
|
||||||
|
Inventory inventory = Bukkit.createInventory(null, rows * 9, title);
|
||||||
|
int i = 0;
|
||||||
|
for (List<Slot> row : slots) {
|
||||||
|
for (Slot item : row) {
|
||||||
|
if (i == rows * 9) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ItemStack slotItem = item.getItemStack(player);
|
||||||
|
ItemMeta meta = slotItem.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
List<String> lore = meta.getLore();
|
||||||
|
if (lore != null) {
|
||||||
|
lore.replaceAll(s -> StringUtils.translate(s, player));
|
||||||
|
meta.setLore(lore);
|
||||||
|
}
|
||||||
|
slotItem.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
inventory.setItem(i, slotItem);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
player.openInventory(inventory);
|
||||||
|
MenuHandler.registerMenu(inventory, this);
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleClose(@NotNull final InventoryCloseEvent event) {
|
||||||
|
onClose.accept(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.willfp.eco.internal.gui;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.gui.slot.Slot;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class EcoSlot implements Slot {
|
||||||
|
@Getter
|
||||||
|
private final Function<Player, ItemStack> provider;
|
||||||
|
|
||||||
|
private final BiConsumer<InventoryClickEvent, Slot> onLeftClick;
|
||||||
|
|
||||||
|
private final BiConsumer<InventoryClickEvent, Slot> onRightClick;
|
||||||
|
|
||||||
|
private final BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick;
|
||||||
|
|
||||||
|
private final BiConsumer<InventoryClickEvent, Slot> onShiftRightClick;
|
||||||
|
|
||||||
|
private final BiConsumer<InventoryClickEvent, Slot> onMiddleClick;
|
||||||
|
|
||||||
|
public EcoSlot(@NotNull final Function<Player, ItemStack> provider,
|
||||||
|
@Nullable final BiConsumer<InventoryClickEvent, Slot> onLeftClick,
|
||||||
|
@Nullable final BiConsumer<InventoryClickEvent, Slot> onRightClick,
|
||||||
|
@Nullable final BiConsumer<InventoryClickEvent, Slot> onShiftLeftClick,
|
||||||
|
@Nullable final BiConsumer<InventoryClickEvent, Slot> onShiftRightClick,
|
||||||
|
@Nullable final BiConsumer<InventoryClickEvent, Slot> onMiddleClick) {
|
||||||
|
this.provider = provider;
|
||||||
|
this.onLeftClick = onLeftClick == null ? ((event, slot) -> { }) : onLeftClick;
|
||||||
|
this.onRightClick = onRightClick == null ? ((event, slot) -> { }) : onRightClick;
|
||||||
|
this.onShiftLeftClick = onShiftLeftClick == null ? ((event, slot) -> { }) : onShiftLeftClick;
|
||||||
|
this.onShiftRightClick = onShiftRightClick == null ? ((event, slot) -> { }) : onShiftRightClick;
|
||||||
|
this.onMiddleClick = onMiddleClick == null ? ((event, slot) -> { }) : onMiddleClick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleInventoryClick(@NotNull final InventoryClickEvent event) {
|
||||||
|
switch (event.getClick()) {
|
||||||
|
case LEFT -> this.onLeftClick.accept(event, this);
|
||||||
|
case RIGHT -> this.onRightClick.accept(event, this);
|
||||||
|
case SHIFT_LEFT -> this.onShiftLeftClick.accept(event, this);
|
||||||
|
case SHIFT_RIGHT -> this.onShiftRightClick.accept(event, this);
|
||||||
|
case MIDDLE -> this.onMiddleClick.accept(event, this);
|
||||||
|
default -> { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack(@NotNull final Player player) {
|
||||||
|
return provider.apply(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.willfp.eco.internal.gui;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class FillerSlot extends EcoSlot {
|
||||||
|
/**
|
||||||
|
* Create new filler slot.
|
||||||
|
*
|
||||||
|
* @param itemStack The ItemStack.
|
||||||
|
*/
|
||||||
|
public FillerSlot(@NotNull final ItemStack itemStack) {
|
||||||
|
super((player) -> itemStack, null, null, null, null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.willfp.eco.internal.gui;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.gui.menu.Menu;
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class MenuHandler {
|
||||||
|
private static final Map<Inventory, Menu> MENUS = new HashMap<>();
|
||||||
|
|
||||||
|
public void registerMenu(@NotNull final Inventory inventory,
|
||||||
|
@NotNull final Menu menu) {
|
||||||
|
MENUS.put(inventory, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterMenu(@NotNull final Inventory inventory) {
|
||||||
|
MENUS.remove(inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Menu getMenu(@NotNull final Inventory inventory) {
|
||||||
|
return MENUS.get(inventory);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
package com.willfp.eco.internal.items;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.items.builder.ItemBuilder;
|
||||||
|
import com.willfp.eco.util.StringUtils;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public abstract class AbstractItemStackBuilder<T extends ItemMeta, U extends AbstractItemStackBuilder<T, U>> implements ItemBuilder {
|
||||||
|
/**
|
||||||
|
* The ItemMeta used while building.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final T meta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ItemStack.
|
||||||
|
*/
|
||||||
|
@Getter(AccessLevel.PROTECTED)
|
||||||
|
private final ItemStack base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ItemStackBuilder.
|
||||||
|
*
|
||||||
|
* @param material The material.
|
||||||
|
*/
|
||||||
|
protected AbstractItemStackBuilder(@NotNull final Material material) {
|
||||||
|
this(new ItemStack(material));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ItemStackBuilder to modify an existing item.
|
||||||
|
*
|
||||||
|
* @param base The ItemStack to start with.
|
||||||
|
*/
|
||||||
|
protected AbstractItemStackBuilder(@NotNull final ItemStack base) {
|
||||||
|
this.base = base;
|
||||||
|
this.meta = (T) base.getItemMeta();
|
||||||
|
assert meta != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setAmount(final int amount) {
|
||||||
|
Validate.isTrue(amount >= 1 && amount <= base.getMaxStackSize());
|
||||||
|
base.setAmount(amount);
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setAmount(@NotNull final Supplier<Integer> amount) {
|
||||||
|
return setAmount(amount.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addEnchantment(@NotNull final Enchantment enchantment,
|
||||||
|
final int level) {
|
||||||
|
meta.addEnchant(enchantment, level, true);
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addEnchantment(@NotNull final Supplier<Enchantment> enchantment,
|
||||||
|
@NotNull final Supplier<Integer> level) {
|
||||||
|
return addEnchantment(enchantment.get(), level.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setDisplayName(@NotNull final String name) {
|
||||||
|
meta.setDisplayName(StringUtils.translate(name));
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setDisplayName(@NotNull final Supplier<String> name) {
|
||||||
|
String result = name.get();
|
||||||
|
|
||||||
|
return result == null ? (U) this : setDisplayName(name.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addLoreLine(@NotNull final String line) {
|
||||||
|
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||||
|
assert lore != null;
|
||||||
|
lore.add(StringUtils.translate(line));
|
||||||
|
meta.setLore(lore);
|
||||||
|
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addLoreLine(@NotNull final Supplier<String> line) {
|
||||||
|
String result = line.get();
|
||||||
|
|
||||||
|
return result == null ? (U) this : addLoreLine(line.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addLoreLines(@NotNull final List<String> lines) {
|
||||||
|
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||||
|
assert lore != null;
|
||||||
|
for (String line : lines) {
|
||||||
|
lore.add(StringUtils.translate(line));
|
||||||
|
}
|
||||||
|
meta.setLore(lore);
|
||||||
|
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addLoreLines(@NotNull final Supplier<List<String>> lines) {
|
||||||
|
List<String> result = lines.get();
|
||||||
|
|
||||||
|
return result == null ? (U) this : addLoreLines(lines.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addItemFlag(@NotNull final ItemFlag... itemFlags) {
|
||||||
|
meta.addItemFlags(itemFlags);
|
||||||
|
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U addItemFlag(@NotNull final Supplier<ItemFlag[]> itemFlags) {
|
||||||
|
ItemFlag[] result = itemFlags.get();
|
||||||
|
|
||||||
|
return result == null ? (U) this : addItemFlag(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <A, B> U writeMetaKey(@NotNull final NamespacedKey key,
|
||||||
|
@NotNull final PersistentDataType<A, B> type,
|
||||||
|
@NotNull final B value) {
|
||||||
|
meta.getPersistentDataContainer().set(key, type, value);
|
||||||
|
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <A, B> U writeMetaKey(@NotNull final Supplier<NamespacedKey> key,
|
||||||
|
@NotNull final Supplier<PersistentDataType<A, B>> type,
|
||||||
|
@NotNull final Supplier<B> value) {
|
||||||
|
return writeMetaKey(key.get(), type.get(), value.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setUnbreakable(final boolean unbreakable) {
|
||||||
|
meta.setUnbreakable(unbreakable);
|
||||||
|
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setUnbreakable(@NotNull final Supplier<Boolean> unbreakable) {
|
||||||
|
Boolean result = unbreakable.get();
|
||||||
|
|
||||||
|
return result == null ? (U) this : setUnbreakable(unbreakable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setCustomModelData(@Nullable final Integer data) {
|
||||||
|
meta.setCustomModelData(data);
|
||||||
|
|
||||||
|
return (U) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public U setCustomModelData(@NotNull final Supplier<Integer> data) {
|
||||||
|
Integer result = data.get();
|
||||||
|
|
||||||
|
return result == null ? (U) this : setCustomModelData(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack build() {
|
||||||
|
base.setItemMeta(meta);
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,15 +37,6 @@ public class BlockUtils {
|
|||||||
if (blocks.size() > limit || blocks.size() > 2500) {
|
if (blocks.size() > limit || blocks.size() > 2500) {
|
||||||
return blocks;
|
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));
|
blocks.addAll(getNearbyBlocks(block, allowedMaterials, blocks, limit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,8 +121,7 @@ public class DurabilityUtils {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.getItemMeta() instanceof Damageable) {
|
if (item.getItemMeta() instanceof Damageable meta) {
|
||||||
Damageable meta = (Damageable) item.getItemMeta();
|
|
||||||
meta.setDamage(meta.getDamage() - repair);
|
meta.setDamage(meta.getDamage() - repair);
|
||||||
|
|
||||||
if (meta.getDamage() < 0) {
|
if (meta.getDamage() < 0) {
|
||||||
|
|||||||
31
eco-api/src/main/java/com/willfp/eco/util/ListUtils.java
Normal file
31
eco-api/src/main/java/com/willfp/eco/util/ListUtils.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.willfp.eco.util;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class ListUtils {
|
||||||
|
/**
|
||||||
|
* Initialize 2D list of a given size.
|
||||||
|
*
|
||||||
|
* @param rows The amount of rows.
|
||||||
|
* @param columns The amount of columns.
|
||||||
|
* @param <T> The type of the object stored in the list.
|
||||||
|
* @return The list, filled will null objects.
|
||||||
|
*/
|
||||||
|
public <T> List<List<T>> create2DList(final int rows,
|
||||||
|
final int columns) {
|
||||||
|
List<List<T>> list = new ArrayList<>(rows);
|
||||||
|
while (list.size() < rows) {
|
||||||
|
List<T> row = new ArrayList<>(columns);
|
||||||
|
while (row.size() < columns) {
|
||||||
|
row.add(null);
|
||||||
|
}
|
||||||
|
list.add(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,20 +10,10 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class NumberUtils {
|
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.
|
* Sin lookup table.
|
||||||
*/
|
*/
|
||||||
private static final double[] SIN_LOOKUP = new double[FAST_TRIG_MODULUS];
|
private static final double[] SIN_LOOKUP = new double[65536];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set of roman numerals to look up.
|
* Set of roman numerals to look up.
|
||||||
@@ -45,15 +35,11 @@ public class NumberUtils {
|
|||||||
NUMERALS.put(4, "IV");
|
NUMERALS.put(4, "IV");
|
||||||
NUMERALS.put(1, "I");
|
NUMERALS.put(1, "I");
|
||||||
|
|
||||||
for (int i = 0; i < SIN_LOOKUP.length; i++) {
|
for (int i = 0; i < 65536; ++i) {
|
||||||
SIN_LOOKUP[i] = Math.sin((i * Math.PI) / (FAST_TRIG_PRECISION * 180));
|
SIN_LOOKUP[i] = Math.sin((double) i * 3.141592653589793D * 2.0D / 65536.0D);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
* Get the sin of a number.
|
||||||
*
|
*
|
||||||
@@ -61,7 +47,8 @@ public class NumberUtils {
|
|||||||
* @return The sin.
|
* @return The sin.
|
||||||
*/
|
*/
|
||||||
public static double fastSin(final double a) {
|
public static double fastSin(final double a) {
|
||||||
return sinLookup((int) (a * FAST_TRIG_PRECISION + 0.5f));
|
float f = (float) a;
|
||||||
|
return SIN_LOOKUP[(int) (f * 10430.378F) & '\uffff'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,7 +58,8 @@ public class NumberUtils {
|
|||||||
* @return The cosine.
|
* @return The cosine.
|
||||||
*/
|
*/
|
||||||
public static double fastCos(final double a) {
|
public static double fastCos(final double a) {
|
||||||
return sinLookup((int) ((a + 90f) * FAST_TRIG_PRECISION + 0.5f));
|
float f = (float) a;
|
||||||
|
return SIN_LOOKUP[(int) (f * 10430.378F + 16384.0F) & '\uffff'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,6 +39,33 @@ public class StringUtils {
|
|||||||
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
|
.add(Pattern.compile("<#" + "([A-Fa-f0-9]{6})" + ">"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate a list of strings - converts Placeholders and Color codes.
|
||||||
|
*
|
||||||
|
* @param list The messages to translate.
|
||||||
|
* @param player The player to translate placeholders with respect to.
|
||||||
|
* @return The message, translated.
|
||||||
|
*/
|
||||||
|
public List<String> translateList(@NotNull final List<String> list,
|
||||||
|
@Nullable final Player player) {
|
||||||
|
List<String> translated = new ArrayList<>();
|
||||||
|
for (String string : list) {
|
||||||
|
translated.add(translate(string, player));
|
||||||
|
}
|
||||||
|
|
||||||
|
return translated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate a list of strings - converts Placeholders and Color codes.
|
||||||
|
*
|
||||||
|
* @param list The messages to translate.
|
||||||
|
* @return The message, translated.
|
||||||
|
*/
|
||||||
|
public List<String> translateList(@NotNull final List<String> list) {
|
||||||
|
return translateList(list, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate a string - converts Placeholders and Color codes.
|
* Translate a string - converts Placeholders and Color codes.
|
||||||
*
|
*
|
||||||
@@ -79,16 +106,16 @@ public class StringUtils {
|
|||||||
@NotNull final Pattern pattern) {
|
@NotNull final Pattern pattern) {
|
||||||
Matcher matcher = pattern.matcher(message);
|
Matcher matcher = pattern.matcher(message);
|
||||||
|
|
||||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
StringBuilder builder = new StringBuilder(message.length() + 4 * 8);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group(1);
|
String group = matcher.group(1);
|
||||||
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
|
matcher.appendReplacement(builder, COLOR_CHAR + "x"
|
||||||
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
|
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
|
||||||
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
|
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
|
||||||
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
|
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
return matcher.appendTail(buffer).toString();
|
return matcher.appendTail(builder).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -198,8 +225,7 @@ public class StringUtils {
|
|||||||
return (String) object;
|
return (String) object;
|
||||||
} else if (object instanceof Double) {
|
} else if (object instanceof Double) {
|
||||||
return NumberUtils.format((Double) object);
|
return NumberUtils.format((Double) object);
|
||||||
} else if (object instanceof Collection<?>) {
|
} else if (object instanceof Collection<?> c) {
|
||||||
Collection<?> c = (Collection<?>) object;
|
|
||||||
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
|
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
|
||||||
} else {
|
} else {
|
||||||
return String.valueOf(object);
|
return String.valueOf(object);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util;
|
|||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import com.willfp.eco.core.Prerequisite;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@@ -10,6 +11,8 @@ import org.bukkit.scoreboard.Scoreboard;
|
|||||||
import org.bukkit.scoreboard.Team;
|
import org.bukkit.scoreboard.Team;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
@@ -17,7 +20,7 @@ public class TeamUtils {
|
|||||||
/**
|
/**
|
||||||
* Ore ChatColors.
|
* Ore ChatColors.
|
||||||
*/
|
*/
|
||||||
private static final BiMap<Material, ChatColor> MATERIAL_COLORS = HashBiMap.create();
|
private static final Map<Material, ChatColor> MATERIAL_COLORS = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All chat color teams.
|
* All chat color teams.
|
||||||
@@ -73,12 +76,25 @@ public class TeamUtils {
|
|||||||
fromChatColor(value);
|
fromChatColor(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
MATERIAL_COLORS.forcePut(Material.COAL_ORE, ChatColor.BLACK);
|
MATERIAL_COLORS.put(Material.COAL_ORE, ChatColor.BLACK);
|
||||||
MATERIAL_COLORS.forcePut(Material.IRON_ORE, ChatColor.GRAY);
|
MATERIAL_COLORS.put(Material.IRON_ORE, ChatColor.GRAY);
|
||||||
MATERIAL_COLORS.forcePut(Material.GOLD_ORE, ChatColor.YELLOW);
|
MATERIAL_COLORS.put(Material.GOLD_ORE, ChatColor.YELLOW);
|
||||||
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
|
MATERIAL_COLORS.put(Material.LAPIS_ORE, ChatColor.BLUE);
|
||||||
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
|
MATERIAL_COLORS.put(Material.REDSTONE_ORE, ChatColor.RED);
|
||||||
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
|
MATERIAL_COLORS.put(Material.DIAMOND_ORE, ChatColor.AQUA);
|
||||||
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
MATERIAL_COLORS.put(Material.EMERALD_ORE, ChatColor.GREEN);
|
||||||
|
MATERIAL_COLORS.put(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||||
|
|
||||||
|
if (Prerequisite.HAS_1_17.isMet()) {
|
||||||
|
MATERIAL_COLORS.put(Material.COPPER_ORE, ChatColor.GOLD);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_COPPER_ORE, ChatColor.GOLD);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_COAL_ORE, ChatColor.BLACK);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_IRON_ORE, ChatColor.GRAY);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_GOLD_ORE, ChatColor.YELLOW);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_LAPIS_ORE, ChatColor.BLUE);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_REDSTONE_ORE, ChatColor.RED);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_DIAMOND_ORE, ChatColor.AQUA);
|
||||||
|
MATERIAL_COLORS.put(Material.DEEPSLATE_EMERALD_ORE, ChatColor.GREEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,18 +22,29 @@ import java.util.Arrays;
|
|||||||
public final class ChatComponent implements ChatComponentProxy {
|
public final class ChatComponent implements ChatComponentProxy {
|
||||||
@Override
|
@Override
|
||||||
public Object modifyComponent(@NotNull final Object object) {
|
public Object modifyComponent(@NotNull final Object object) {
|
||||||
if (!(object instanceof IChatBaseComponent)) {
|
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||||
chatComponent.stream().forEach(this::modifyBaseComponent);
|
if (iChatBaseComponent == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(iChatBaseComponent);
|
||||||
|
}
|
||||||
|
|
||||||
return chatComponent;
|
return chatComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||||
component.getSiblings().forEach(this::modifyBaseComponent);
|
for (IChatBaseComponent sibling : component.getSiblings()) {
|
||||||
|
if (sibling == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(sibling);
|
||||||
|
}
|
||||||
if (component instanceof ChatMessage) {
|
if (component instanceof ChatMessage) {
|
||||||
Arrays.stream(((ChatMessage) component).getArgs())
|
Arrays.stream(((ChatMessage) component).getArgs())
|
||||||
.filter(o -> o instanceof IChatBaseComponent)
|
.filter(o -> o instanceof IChatBaseComponent)
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.willfp.eco.proxy.v1_16_R1;
|
package com.willfp.eco.proxy.v1_16_R1;
|
||||||
|
|
||||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
|
||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe;
|
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
@@ -11,30 +10,56 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
/**
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
* Handle.
|
||||||
|
*/
|
||||||
|
private final Field handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new Villager Trade.
|
||||||
|
*/
|
||||||
|
public VillagerTrade() {
|
||||||
try {
|
try {
|
||||||
// Bukkit MerchantRecipe result
|
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
handle.setAccessible(true);
|
||||||
fResult.setAccessible(true);
|
return;
|
||||||
ItemStack result = merchantRecipe.getResult();
|
} catch (NoSuchFieldException e) {
|
||||||
Display.displayAndFinalize(result);
|
|
||||||
fResult.set(merchantRecipe, result);
|
|
||||||
|
|
||||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
|
||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
|
||||||
fHandle.setAccessible(true);
|
|
||||||
net.minecraft.server.v1_16_R1.MerchantRecipe handle = (net.minecraft.server.v1_16_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
|
||||||
fSelling.setAccessible(true);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
|
||||||
Display.displayAndFinalize(selling);
|
|
||||||
|
|
||||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||||
|
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||||
|
|
||||||
|
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
||||||
|
Display.display(recipe.getResult().clone()),
|
||||||
|
recipe.getUses(),
|
||||||
|
recipe.getMaxUses(),
|
||||||
|
recipe.hasExperienceReward(),
|
||||||
|
recipe.getVillagerExperience(),
|
||||||
|
recipe.getPriceMultiplier()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (ItemStack ingredient : recipe.getIngredients()) {
|
||||||
|
newRecipe.addIngredient(Display.display(ingredient.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
|
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
||||||
|
|
||||||
|
return newRecipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private net.minecraft.server.v1_16_R1.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||||
|
try {
|
||||||
|
return (net.minecraft.server.v1_16_R1.MerchantRecipe) handle.get(recipe);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Not CMR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,18 +22,29 @@ import java.util.Arrays;
|
|||||||
public final class ChatComponent implements ChatComponentProxy {
|
public final class ChatComponent implements ChatComponentProxy {
|
||||||
@Override
|
@Override
|
||||||
public Object modifyComponent(@NotNull final Object object) {
|
public Object modifyComponent(@NotNull final Object object) {
|
||||||
if (!(object instanceof IChatBaseComponent)) {
|
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||||
chatComponent.stream().forEach(this::modifyBaseComponent);
|
if (iChatBaseComponent == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(iChatBaseComponent);
|
||||||
|
}
|
||||||
|
|
||||||
return chatComponent;
|
return chatComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||||
component.getSiblings().forEach(this::modifyBaseComponent);
|
for (IChatBaseComponent sibling : component.getSiblings()) {
|
||||||
|
if (sibling == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(sibling);
|
||||||
|
}
|
||||||
if (component instanceof ChatMessage) {
|
if (component instanceof ChatMessage) {
|
||||||
Arrays.stream(((ChatMessage) component).getArgs())
|
Arrays.stream(((ChatMessage) component).getArgs())
|
||||||
.filter(o -> o instanceof IChatBaseComponent)
|
.filter(o -> o instanceof IChatBaseComponent)
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.willfp.eco.proxy.v1_16_R2;
|
package com.willfp.eco.proxy.v1_16_R2;
|
||||||
|
|
||||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
|
||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe;
|
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
@@ -11,30 +10,56 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
/**
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
* Handle.
|
||||||
|
*/
|
||||||
|
private final Field handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new Villager Trade.
|
||||||
|
*/
|
||||||
|
public VillagerTrade() {
|
||||||
try {
|
try {
|
||||||
// Bukkit MerchantRecipe result
|
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
handle.setAccessible(true);
|
||||||
fResult.setAccessible(true);
|
return;
|
||||||
ItemStack result = merchantRecipe.getResult();
|
} catch (NoSuchFieldException e) {
|
||||||
Display.displayAndFinalize(result);
|
|
||||||
fResult.set(merchantRecipe, result);
|
|
||||||
|
|
||||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
|
||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
|
||||||
fHandle.setAccessible(true);
|
|
||||||
net.minecraft.server.v1_16_R2.MerchantRecipe handle = (net.minecraft.server.v1_16_R2.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
|
|
||||||
fSelling.setAccessible(true);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
|
||||||
Display.displayAndFinalize(selling);
|
|
||||||
|
|
||||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||||
|
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||||
|
|
||||||
|
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
||||||
|
Display.display(recipe.getResult().clone()),
|
||||||
|
recipe.getUses(),
|
||||||
|
recipe.getMaxUses(),
|
||||||
|
recipe.hasExperienceReward(),
|
||||||
|
recipe.getVillagerExperience(),
|
||||||
|
recipe.getPriceMultiplier()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (ItemStack ingredient : recipe.getIngredients()) {
|
||||||
|
newRecipe.addIngredient(Display.display(ingredient.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
|
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
||||||
|
|
||||||
|
return newRecipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private net.minecraft.server.v1_16_R2.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||||
|
try {
|
||||||
|
return (net.minecraft.server.v1_16_R2.MerchantRecipe) handle.get(recipe);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Not CMR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,18 +22,29 @@ import java.util.Arrays;
|
|||||||
public final class ChatComponent implements ChatComponentProxy {
|
public final class ChatComponent implements ChatComponentProxy {
|
||||||
@Override
|
@Override
|
||||||
public Object modifyComponent(@NotNull final Object object) {
|
public Object modifyComponent(@NotNull final Object object) {
|
||||||
if (!(object instanceof IChatBaseComponent)) {
|
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||||
chatComponent.stream().forEach(this::modifyBaseComponent);
|
if (iChatBaseComponent == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(iChatBaseComponent);
|
||||||
|
}
|
||||||
|
|
||||||
return chatComponent;
|
return chatComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||||
component.getSiblings().forEach(this::modifyBaseComponent);
|
for (IChatBaseComponent sibling : component.getSiblings()) {
|
||||||
|
if (sibling == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(sibling);
|
||||||
|
}
|
||||||
if (component instanceof ChatMessage) {
|
if (component instanceof ChatMessage) {
|
||||||
Arrays.stream(((ChatMessage) component).getArgs())
|
Arrays.stream(((ChatMessage) component).getArgs())
|
||||||
.filter(o -> o instanceof IChatBaseComponent)
|
.filter(o -> o instanceof IChatBaseComponent)
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package com.willfp.eco.proxy.v1_16_R3;
|
package com.willfp.eco.proxy.v1_16_R3;
|
||||||
|
|
||||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
|
||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
|
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
@@ -11,30 +10,56 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
public final class VillagerTrade implements VillagerTradeProxy {
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
@Override
|
/**
|
||||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
* Handle.
|
||||||
|
*/
|
||||||
|
private final Field handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new Villager Trade.
|
||||||
|
*/
|
||||||
|
public VillagerTrade() {
|
||||||
try {
|
try {
|
||||||
// Bukkit MerchantRecipe result
|
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
handle.setAccessible(true);
|
||||||
fResult.setAccessible(true);
|
return;
|
||||||
ItemStack result = merchantRecipe.getResult();
|
} catch (NoSuchFieldException e) {
|
||||||
Display.displayAndFinalize(result);
|
|
||||||
fResult.set(merchantRecipe, result);
|
|
||||||
|
|
||||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
|
||||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
|
||||||
fHandle.setAccessible(true);
|
|
||||||
net.minecraft.server.v1_16_R3.MerchantRecipe handle = (net.minecraft.server.v1_16_R3.MerchantRecipe) fHandle.get(merchantRecipe); // NMS RecipeR
|
|
||||||
|
|
||||||
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
|
|
||||||
fSelling.setAccessible(true);
|
|
||||||
|
|
||||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
|
||||||
Display.displayAndFinalize(selling);
|
|
||||||
|
|
||||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
|
||||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||||
|
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||||
|
|
||||||
|
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
||||||
|
Display.display(recipe.getResult().clone()),
|
||||||
|
recipe.getUses(),
|
||||||
|
recipe.getMaxUses(),
|
||||||
|
recipe.hasExperienceReward(),
|
||||||
|
recipe.getVillagerExperience(),
|
||||||
|
recipe.getPriceMultiplier()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (ItemStack ingredient : recipe.getIngredients()) {
|
||||||
|
newRecipe.addIngredient(Display.display(ingredient.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
|
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
||||||
|
|
||||||
|
return newRecipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private net.minecraft.server.v1_16_R3.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||||
|
try {
|
||||||
|
return (net.minecraft.server.v1_16_R3.MerchantRecipe) handle.get(recipe);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Not CMR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
6
eco-core/core-nms/v1_17_R1/build.gradle
Normal file
6
eco-core/core-nms/v1_17_R1/build.gradle
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
group 'com.willfp'
|
||||||
|
version rootProject.version
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly 'org.spigotmc:spigot:1.17-R0.1-SNAPSHOT'
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.willfp.eco.proxy.v1_17_R1;
|
||||||
|
|
||||||
|
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||||
|
import net.minecraft.network.protocol.game.PacketPlayOutAutoRecipe;
|
||||||
|
import net.minecraft.resources.MinecraftKey;
|
||||||
|
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_17_R1;
|
||||||
|
|
||||||
|
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||||
|
import net.minecraft.core.BlockPosition;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.craftbukkit.v1_17_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().d.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package com.willfp.eco.proxy.v1_17_R1;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
|
||||||
|
import com.willfp.eco.core.display.Display;
|
||||||
|
import net.minecraft.nbt.MojangsonParser;
|
||||||
|
import net.minecraft.network.chat.ChatBaseComponent;
|
||||||
|
import net.minecraft.network.chat.ChatHoverable;
|
||||||
|
import net.minecraft.network.chat.ChatMessage;
|
||||||
|
import net.minecraft.network.chat.ChatModifier;
|
||||||
|
import net.minecraft.network.chat.IChatBaseComponent;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public final class ChatComponent implements ChatComponentProxy {
|
||||||
|
@Override
|
||||||
|
public Object modifyComponent(@NotNull final Object object) {
|
||||||
|
if (!(object instanceof IChatBaseComponent chatComponent)) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (IChatBaseComponent iChatBaseComponent : chatComponent) {
|
||||||
|
if (iChatBaseComponent == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(iChatBaseComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chatComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||||
|
for (IChatBaseComponent sibling : component.getSiblings()) {
|
||||||
|
if (sibling == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifyBaseComponent(sibling);
|
||||||
|
}
|
||||||
|
if (component instanceof ChatMessage) {
|
||||||
|
Arrays.stream(((ChatMessage) component).getArgs())
|
||||||
|
.filter(o -> o instanceof IChatBaseComponent)
|
||||||
|
.map(o -> (IChatBaseComponent) o)
|
||||||
|
.forEach(this::modifyBaseComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatHoverable hoverable = component.getChatModifier().getHoverEvent();
|
||||||
|
|
||||||
|
if (hoverable == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject jsonObject = hoverable.b();
|
||||||
|
JsonElement json = hoverable.b().get("contents");
|
||||||
|
if (json.getAsJsonObject().get("id") == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (json.getAsJsonObject().get("tag") == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String id = json.getAsJsonObject().get("id").toString();
|
||||||
|
String tag = json.getAsJsonObject().get("tag").toString();
|
||||||
|
ItemStack itemStack = getFromTag(tag, id);
|
||||||
|
|
||||||
|
Display.displayAndFinalize(itemStack);
|
||||||
|
|
||||||
|
json.getAsJsonObject().remove("tag");
|
||||||
|
String newTag = toJson(itemStack);
|
||||||
|
json.getAsJsonObject().add("tag", new JsonPrimitive(newTag));
|
||||||
|
|
||||||
|
jsonObject.remove("contents");
|
||||||
|
jsonObject.add("contents", json);
|
||||||
|
ChatHoverable newHoverable = ChatHoverable.a(jsonObject);
|
||||||
|
ChatModifier modifier = component.getChatModifier();
|
||||||
|
modifier = modifier.setChatHoverable(newHoverable);
|
||||||
|
|
||||||
|
((ChatBaseComponent) component).setChatModifier(modifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ItemStack getFromTag(@NotNull final String jsonTag,
|
||||||
|
@NotNull final String id) {
|
||||||
|
String processedId = id;
|
||||||
|
String processedJsonTag = jsonTag;
|
||||||
|
processedId = processedId.replace("minecraft:", "");
|
||||||
|
processedId = processedId.toUpperCase();
|
||||||
|
processedId = processedId.replace("\"", "");
|
||||||
|
processedJsonTag = processedJsonTag.substring(1, processedJsonTag.length() - 1);
|
||||||
|
processedJsonTag = processedJsonTag.replace("id:", "\"id\":");
|
||||||
|
processedJsonTag = processedJsonTag.replace("\\", "");
|
||||||
|
Material material = Material.getMaterial(processedId);
|
||||||
|
|
||||||
|
assert material != null;
|
||||||
|
ItemStack itemStack = new ItemStack(material);
|
||||||
|
net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||||
|
|
||||||
|
try {
|
||||||
|
nmsStack.setTag(MojangsonParser.parse(processedJsonTag));
|
||||||
|
} catch (CommandSyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return CraftItemStack.asBukkitCopy(nmsStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String toJson(@NotNull final ItemStack itemStack) {
|
||||||
|
return CraftItemStack.asNMSCopy(itemStack).getOrCreateTag().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.willfp.eco.proxy.v1_17_R1;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public final class Skull implements SkullProxy {
|
||||||
|
/**
|
||||||
|
* Cached method to set the gameProfile.
|
||||||
|
*/
|
||||||
|
private Method setProfile = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||||
|
@NotNull final String base64) {
|
||||||
|
try {
|
||||||
|
if (setProfile == null) {
|
||||||
|
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
|
||||||
|
setProfile.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID uuid = new UUID(
|
||||||
|
base64.substring(base64.length() - 20).hashCode(),
|
||||||
|
base64.substring(base64.length() - 10).hashCode()
|
||||||
|
);
|
||||||
|
|
||||||
|
GameProfile profile = new GameProfile(uuid, "talismans");
|
||||||
|
profile.getProperties().put("textures", new Property("textures", base64));
|
||||||
|
|
||||||
|
setProfile.invoke(meta, profile);
|
||||||
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.willfp.eco.proxy.v1_17_R1;
|
||||||
|
|
||||||
|
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||||
|
import org.bukkit.entity.Trident;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public final class TridentStack implements TridentStackProxy {
|
||||||
|
@Override
|
||||||
|
public ItemStack getTridentStack(@NotNull final Trident trident) {
|
||||||
|
return trident.getItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.willfp.eco.proxy.v1_17_R1;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.display.Display;
|
||||||
|
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||||
|
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMerchantRecipe;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
public final class VillagerTrade implements VillagerTradeProxy {
|
||||||
|
/**
|
||||||
|
* Handle.
|
||||||
|
*/
|
||||||
|
private final Field handle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new Villager Trade.
|
||||||
|
*/
|
||||||
|
public VillagerTrade() {
|
||||||
|
try {
|
||||||
|
handle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||||
|
handle.setAccessible(true);
|
||||||
|
return;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Error!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MerchantRecipe displayTrade(@NotNull final MerchantRecipe recipe) {
|
||||||
|
CraftMerchantRecipe oldRecipe = (CraftMerchantRecipe) recipe;
|
||||||
|
|
||||||
|
CraftMerchantRecipe newRecipe = new CraftMerchantRecipe(
|
||||||
|
Display.display(recipe.getResult().clone()),
|
||||||
|
recipe.getUses(),
|
||||||
|
recipe.getMaxUses(),
|
||||||
|
recipe.hasExperienceReward(),
|
||||||
|
recipe.getVillagerExperience(),
|
||||||
|
recipe.getPriceMultiplier()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (ItemStack ingredient : recipe.getIngredients()) {
|
||||||
|
newRecipe.addIngredient(Display.display(ingredient.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
|
getHandle(newRecipe).setSpecialPrice(getHandle(oldRecipe).getSpecialPrice());
|
||||||
|
|
||||||
|
return newRecipe;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private net.minecraft.world.item.trading.MerchantRecipe getHandle(@NotNull final CraftMerchantRecipe recipe) {
|
||||||
|
try {
|
||||||
|
return (net.minecraft.world.item.trading.MerchantRecipe) handle.get(recipe);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Not CMR");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ version rootProject.version
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.apache.maven:maven-artifact:3.0.3'
|
implementation 'org.apache.maven:maven-artifact:3.0.3'
|
||||||
implementation 'org.bstats:bstats-bukkit:1.7'
|
implementation 'org.bstats:bstats-bukkit:1.7'
|
||||||
|
implementation 'com.google.code.gson:gson:2.8.7'
|
||||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||||
compileOnly project(":eco-core:core-proxy")
|
compileOnly project(":eco-core:core-proxy")
|
||||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||||
|
|||||||
@@ -3,15 +3,19 @@ package com.willfp.eco.spigot;
|
|||||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import com.willfp.eco.core.command.AbstractCommand;
|
import com.willfp.eco.core.command.AbstractCommand;
|
||||||
|
import com.willfp.eco.core.config.base.LangYml;
|
||||||
|
import com.willfp.eco.core.data.Data;
|
||||||
import com.willfp.eco.core.display.Display;
|
import com.willfp.eco.core.display.Display;
|
||||||
import com.willfp.eco.core.display.DisplayModule;
|
import com.willfp.eco.core.display.DisplayModule;
|
||||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||||
import com.willfp.eco.core.integrations.anticheat.AnticheatManager;
|
import com.willfp.eco.core.integrations.anticheat.AnticheatManager;
|
||||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||||
|
import com.willfp.eco.internal.InternalInterfacing;
|
||||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||||
|
import com.willfp.eco.spigot.config.DataJson;
|
||||||
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
||||||
import com.willfp.eco.spigot.display.PacketChat;
|
import com.willfp.eco.spigot.display.PacketChat;
|
||||||
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
||||||
@@ -23,9 +27,13 @@ import com.willfp.eco.spigot.eventlisteners.ArmorListener;
|
|||||||
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
|
import com.willfp.eco.spigot.eventlisteners.DispenserArmorListener;
|
||||||
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
||||||
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
|
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
|
||||||
|
import com.willfp.eco.spigot.eventlisteners.PlayerJumpListeners;
|
||||||
|
import com.willfp.eco.spigot.gui.GUIListener;
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
|
||||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
|
||||||
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatSpartan;
|
||||||
|
import com.willfp.eco.spigot.integrations.anticheat.AnticheatVulcan;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefCombatLogX;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
|
||||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
|
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
|
||||||
@@ -42,6 +50,7 @@ import lombok.Getter;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -53,6 +62,11 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
@Getter
|
@Getter
|
||||||
private static EcoSpigotPlugin instance;
|
private static EcoSpigotPlugin instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data.json.
|
||||||
|
*/
|
||||||
|
private final DataJson dataJson;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of eco.
|
* Create a new instance of eco.
|
||||||
*/
|
*/
|
||||||
@@ -69,21 +83,30 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
|
|
||||||
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
|
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
|
||||||
TridentUtils.initialize(tridentStackProxy::getTridentStack);
|
TridentUtils.initialize(tridentStackProxy::getTridentStack);
|
||||||
|
|
||||||
|
this.dataJson = new DataJson(this);
|
||||||
|
Data.init(this.dataJson);
|
||||||
|
|
||||||
|
InternalInterfacing.setInterfacing(new InternalInterfacing() {
|
||||||
|
@Override
|
||||||
|
public LangYml getLang() {
|
||||||
|
return EcoSpigotPlugin.getInstance().getLangYml();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
new CollatedRunnable(this);
|
new CollatedRunnable(this);
|
||||||
this.getEventManager().registerListener(new NaturalExpGainListeners());
|
|
||||||
this.getEventManager().registerListener(new ArmorListener());
|
|
||||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
|
||||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
|
||||||
this.getEventManager().registerListener(new ShapedRecipeListener());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disable() {
|
public void disable() {
|
||||||
|
try {
|
||||||
|
Data.save(this.dataJson);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -117,6 +140,8 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
||||||
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
|
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
|
||||||
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())),
|
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())),
|
||||||
|
new IntegrationLoader("Spartan", () -> AnticheatManager.register(this, new AnticheatSpartan())),
|
||||||
|
new IntegrationLoader("Vulcan", () -> AnticheatManager.register(this, new AnticheatVulcan())),
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
|
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
|
||||||
@@ -130,19 +155,32 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||||
return Arrays.asList(
|
List<AbstractPacketAdapter> adapters = new ArrayList<>(Arrays.asList(
|
||||||
new PacketAutoRecipe(this),
|
new PacketAutoRecipe(this),
|
||||||
new PacketChat(this),
|
new PacketChat(this),
|
||||||
new PacketOpenWindowMerchant(this),
|
|
||||||
new PacketSetCreativeSlot(this),
|
new PacketSetCreativeSlot(this),
|
||||||
new PacketSetSlot(this),
|
new PacketSetSlot(this),
|
||||||
new PacketWindowItems(this)
|
new PacketWindowItems(this)
|
||||||
);
|
));
|
||||||
|
|
||||||
|
if (!this.getConfigYml().getBool("disable-display-on-villagers")) {
|
||||||
|
adapters.add(new PacketOpenWindowMerchant(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
return adapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Listener> getListeners() {
|
public List<Listener> getListeners() {
|
||||||
return new ArrayList<>();
|
return Arrays.asList(
|
||||||
|
new NaturalExpGainListeners(),
|
||||||
|
new ArmorListener(),
|
||||||
|
new DispenserArmorListener(),
|
||||||
|
new EntityDeathByEntityListeners(this),
|
||||||
|
new ShapedRecipeListener(this),
|
||||||
|
new PlayerJumpListeners(),
|
||||||
|
new GUIListener(this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.willfp.eco.spigot.config;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.config.JsonStaticBaseConfig;
|
||||||
|
import com.willfp.eco.spigot.EcoSpigotPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class DataJson extends JsonStaticBaseConfig {
|
||||||
|
/**
|
||||||
|
* Init data.json.
|
||||||
|
*
|
||||||
|
* @param plugin EcoSpigotPlugin.
|
||||||
|
*/
|
||||||
|
public DataJson(@NotNull final EcoSpigotPlugin plugin) {
|
||||||
|
super("data", plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
package com.willfp.eco.spigot.display;
|
package com.willfp.eco.spigot.display;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.events.ListenerPriority;
|
||||||
import com.comphenix.protocol.events.PacketContainer;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import org.bukkit.NamespacedKey;
|
||||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemFlag;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||||
/**
|
/**
|
||||||
@@ -20,16 +26,32 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
|||||||
* @param plugin The plugin to listen through.
|
* @param plugin The plugin to listen through.
|
||||||
*/
|
*/
|
||||||
public PacketOpenWindowMerchant(@NotNull final EcoPlugin plugin) {
|
public PacketOpenWindowMerchant(@NotNull final EcoPlugin plugin) {
|
||||||
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false);
|
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, ListenerPriority.MONITOR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSend(@NotNull final PacketContainer packet,
|
public void onSend(@NotNull final PacketContainer packet,
|
||||||
@NotNull final Player player) {
|
@NotNull final Player player,
|
||||||
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0);
|
@NotNull final PacketEvent event) {
|
||||||
|
List<MerchantRecipe> recipes = new ArrayList<>();
|
||||||
|
|
||||||
recipes = recipes.stream().peek(merchantRecipe -> InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(merchantRecipe)).collect(Collectors.toList());
|
if (((EcoPlugin) this.getPlugin()).getConfigYml().getBool("villager-display-fix")) {
|
||||||
|
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||||
|
ItemStack result = recipe.getResult();
|
||||||
|
ItemMeta meta = result.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_POTION_EFFECTS);
|
||||||
|
meta.getPersistentDataContainer().remove(NamespacedKey.fromString("ecoenchants:ecoenchantlore-skip"));
|
||||||
|
result.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
packet.getMerchantRecipeLists().writeSafely(0, recipes);
|
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
|
||||||
|
MerchantRecipe newRecipe = InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe);
|
||||||
|
recipes.add(newRecipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
packet.getMerchantRecipeLists().write(0, recipes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ public class DispenserArmorListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void dispenseArmorEvent(@NotNull final BlockDispenseArmorEvent event) {
|
public void dispenseArmorEvent(@NotNull final BlockDispenseArmorEvent event) {
|
||||||
ArmorType type = ArmorType.matchType(event.getItem());
|
ArmorType type = ArmorType.matchType(event.getItem());
|
||||||
if (type != null && event.getTargetEntity() instanceof Player) {
|
if (type != null && event.getTargetEntity() instanceof Player p) {
|
||||||
Player p = (Player) event.getTargetEntity();
|
|
||||||
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p);
|
ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p);
|
||||||
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
Bukkit.getPluginManager().callEvent(armorEquipEvent);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,10 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis
|
|||||||
*/
|
*/
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDamage(@NotNull final EntityDamageByEntityEvent event) {
|
public void onEntityDamage(@NotNull final EntityDamageByEntityEvent event) {
|
||||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
if (!(event.getEntity() instanceof LivingEntity victim)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LivingEntity victim = (LivingEntity) event.getEntity();
|
|
||||||
|
|
||||||
if (victim.getHealth() > event.getFinalDamage()) {
|
if (victim.getHealth() > event.getFinalDamage()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.willfp.eco.spigot.eventlisteners;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.events.PlayerJumpEvent;
|
||||||
|
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class PlayerJumpListeners implements Listener {
|
||||||
|
/**
|
||||||
|
* For jump listeners.
|
||||||
|
*/
|
||||||
|
private static final Set<UUID> PREVIOUS_PLAYERS_ON_GROUND = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For jump listeners.
|
||||||
|
*/
|
||||||
|
private static final DecimalFormat FORMAT = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player jumps.
|
||||||
|
*
|
||||||
|
* @param event The event to listen for.
|
||||||
|
*/
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onJump(@NotNull final PlayerMoveEvent event) {
|
||||||
|
if (McmmoManager.isFake(event)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.getVelocity().getY() > 0) {
|
||||||
|
float jumpVelocity = 0.42f;
|
||||||
|
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||||
|
jumpVelocity += ((float) player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.1F;
|
||||||
|
}
|
||||||
|
jumpVelocity = Float.parseFloat(FORMAT.format(jumpVelocity).replace(',', '.'));
|
||||||
|
if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER
|
||||||
|
&& PREVIOUS_PLAYERS_ON_GROUND.contains(player.getUniqueId())
|
||||||
|
&& !player.isOnGround()
|
||||||
|
&& Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) {
|
||||||
|
Bukkit.getPluginManager().callEvent(new PlayerJumpEvent(event));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player.isOnGround()) {
|
||||||
|
PREVIOUS_PLAYERS_ON_GROUND.add(player.getUniqueId());
|
||||||
|
} else {
|
||||||
|
PREVIOUS_PLAYERS_ON_GROUND.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.willfp.eco.spigot.gui;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.core.PluginDependent;
|
||||||
|
import com.willfp.eco.core.gui.menu.Menu;
|
||||||
|
import com.willfp.eco.internal.gui.EcoMenu;
|
||||||
|
import com.willfp.eco.internal.gui.EcoSlot;
|
||||||
|
import com.willfp.eco.internal.gui.MenuHandler;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class GUIListener extends PluginDependent implements Listener {
|
||||||
|
/**
|
||||||
|
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin to manage.
|
||||||
|
*/
|
||||||
|
public GUIListener(@NotNull final EcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handleSlotClick(@NotNull final InventoryClickEvent event) {
|
||||||
|
if (!(event.getWhoClicked() instanceof Player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getClickedInventory() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Menu menu = MenuHandler.getMenu(event.getClickedInventory());
|
||||||
|
if (menu == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int row = Math.floorDiv(event.getSlot(), 9);
|
||||||
|
int column = event.getSlot() - (row * 9);
|
||||||
|
|
||||||
|
EcoSlot slot = (EcoSlot) menu.getSlot(row, column);
|
||||||
|
event.setCancelled(true);
|
||||||
|
slot.handleInventoryClick(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void handleClose(@NotNull final InventoryCloseEvent event) {
|
||||||
|
if (!(event.getPlayer() instanceof Player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EcoMenu menu = (EcoMenu) MenuHandler.getMenu(event.getInventory());
|
||||||
|
if (menu == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.handleClose(event);
|
||||||
|
|
||||||
|
this.getPlugin().getScheduler().run(() -> MenuHandler.unregisterMenu(event.getInventory()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.willfp.eco.spigot.integrations.anticheat;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.integrations.anticheat.AnticheatWrapper;
|
||||||
|
import me.frep.vulcan.api.event.VulcanFlagEvent;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AnticheatVulcan implements AnticheatWrapper, Listener {
|
||||||
|
/**
|
||||||
|
* Currently exempt players.
|
||||||
|
*/
|
||||||
|
private final Set<UUID> exempt = new HashSet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPluginName() {
|
||||||
|
return "Vulcan";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exempt(@NotNull final Player player) {
|
||||||
|
this.exempt.add(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unexempt(@NotNull final Player player) {
|
||||||
|
this.exempt.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
private void onViolate(@NotNull final VulcanFlagEvent event) {
|
||||||
|
if (!exempt.contains(event.getPlayer().getUniqueId())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
package com.willfp.eco.spigot.recipes;
|
package com.willfp.eco.spigot.recipes;
|
||||||
|
|
||||||
import com.willfp.eco.core.EcoPlugin;
|
import com.willfp.eco.core.EcoPlugin;
|
||||||
|
import com.willfp.eco.core.PluginDependent;
|
||||||
import com.willfp.eco.core.items.Items;
|
import com.willfp.eco.core.items.Items;
|
||||||
import com.willfp.eco.core.items.TestableItem;
|
import com.willfp.eco.core.items.TestableItem;
|
||||||
import com.willfp.eco.core.recipe.Recipes;
|
import com.willfp.eco.core.recipe.Recipes;
|
||||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||||
|
import com.willfp.eco.core.recipe.parts.TestableStack;
|
||||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||||
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.CraftItemEvent;
|
import org.bukkit.event.inventory.CraftItemEvent;
|
||||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||||
@@ -18,7 +21,16 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ShapedRecipeListener implements Listener {
|
public class ShapedRecipeListener extends PluginDependent implements Listener {
|
||||||
|
/**
|
||||||
|
* Pass an {@link EcoPlugin} in order to interface with it.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin to manage.
|
||||||
|
*/
|
||||||
|
public ShapedRecipeListener(@NotNull final EcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on item craft.
|
* Called on item craft.
|
||||||
*
|
*
|
||||||
@@ -26,12 +38,10 @@ public class ShapedRecipeListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void complexRecipeListener(@NotNull final PrepareItemCraftEvent event) {
|
public void complexRecipeListener(@NotNull final PrepareItemCraftEvent event) {
|
||||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
|
||||||
|
|
||||||
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -58,12 +68,10 @@ public class ShapedRecipeListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void complexRecipeListener(@NotNull final CraftItemEvent event) {
|
public void complexRecipeListener(@NotNull final CraftItemEvent event) {
|
||||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
|
||||||
|
|
||||||
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -92,22 +100,52 @@ public class ShapedRecipeListener implements Listener {
|
|||||||
*
|
*
|
||||||
* @param event The event to listen for.
|
* @param event The event to listen for.
|
||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
|
public void stackedRecipeListener(@NotNull final CraftItemEvent event) {
|
||||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
if (!EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||||
|
CraftingRecipe matched = Recipes.getMatch(matrix);
|
||||||
|
|
||||||
|
if (matched == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getPlugin().getScheduler().runLater(() -> {
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
ItemStack inMatrix = event.getInventory().getMatrix()[i];
|
||||||
|
TestableItem inRecipe = matched.getParts().get(i);
|
||||||
|
|
||||||
|
if (inRecipe instanceof TestableStack testableStack) {
|
||||||
|
inMatrix.setAmount(inMatrix.getAmount() - (testableStack.getAmount() - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on item craft.
|
||||||
|
*
|
||||||
|
* @param event The event to listen for.
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||||
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
||||||
|
|
||||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe)) {
|
if (!(craftingRecipe instanceof ShapedCraftingRecipe shapedCraftingRecipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedCraftingRecipe shapedCraftingRecipe = (ShapedCraftingRecipe) craftingRecipe;
|
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||||
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
||||||
@@ -127,20 +165,16 @@ public class ShapedRecipeListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final CraftItemEvent event) {
|
public void preventUsingComplexPartInEcoRecipe(@NotNull final CraftItemEvent event) {
|
||||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
|
||||||
|
|
||||||
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
||||||
|
|
||||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe)) {
|
if (!(craftingRecipe instanceof ShapedCraftingRecipe shapedCraftingRecipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedCraftingRecipe shapedCraftingRecipe = (ShapedCraftingRecipe) craftingRecipe;
|
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||||
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
||||||
@@ -162,12 +196,10 @@ public class ShapedRecipeListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final PrepareItemCraftEvent event) {
|
public void preventUsingComplexPartInVanillaRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
|
||||||
|
|
||||||
if (EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
if (EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -187,12 +219,10 @@ public class ShapedRecipeListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final CraftItemEvent event) {
|
public void preventUsingComplexPartInVanillaRecipe(@NotNull final CraftItemEvent event) {
|
||||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
if (!(event.getRecipe() instanceof ShapedRecipe recipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
|
||||||
|
|
||||||
if (EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
if (EcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
disable-display-on-villagers: false
|
||||||
|
villager-display-fix: false
|
||||||
3
eco-core/core-plugin/src/main/resources/data.json
Normal file
3
eco-core/core-plugin/src/main/resources/data.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
multiple-in-craft: '&l&c! &fThis recipe requires &a%amount%&f of this item.'
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ loadbefore:
|
|||||||
- StatTrackers
|
- StatTrackers
|
||||||
- EcoArmor
|
- EcoArmor
|
||||||
- EcoBosses
|
- EcoBosses
|
||||||
|
- EcoSkills
|
||||||
depend:
|
depend:
|
||||||
- ProtocolLib
|
- ProtocolLib
|
||||||
softdepend:
|
softdepend:
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package com.willfp.eco.proxy.proxies;
|
|||||||
|
|
||||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||||
import org.bukkit.inventory.MerchantRecipe;
|
import org.bukkit.inventory.MerchantRecipe;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface VillagerTradeProxy extends AbstractProxy {
|
public interface VillagerTradeProxy extends AbstractProxy {
|
||||||
/**
|
/**
|
||||||
* Apply enchant display to the result of trades.
|
* Display a MerchantRecipe.
|
||||||
*
|
*
|
||||||
* @param merchantRecipe The recipe to modify.
|
* @param recipe The recipe.
|
||||||
|
* @return The new recipe.
|
||||||
*/
|
*/
|
||||||
void displayTrade(MerchantRecipe merchantRecipe);
|
MerchantRecipe displayTrade(@NotNull MerchantRecipe recipe);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
version = 5.0.0
|
version = 5.5.0
|
||||||
plugin-name = eco
|
plugin-name = eco
|
||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
BIN
lib/VulcanAPI.jar
Normal file
BIN
lib/VulcanAPI.jar
Normal file
Binary file not shown.
@@ -7,5 +7,6 @@ include ':eco-core:core-nms'
|
|||||||
include ':eco-core:core-nms:v1_16_R1'
|
include ':eco-core:core-nms:v1_16_R1'
|
||||||
include ':eco-core:core-nms:v1_16_R2'
|
include ':eco-core:core-nms:v1_16_R2'
|
||||||
include ':eco-core:core-nms:v1_16_R3'
|
include ':eco-core:core-nms:v1_16_R3'
|
||||||
|
include ':eco-core:core-nms:v1_17_R1'
|
||||||
include ':eco-core:core-proxy'
|
include ':eco-core:core-proxy'
|
||||||
include ':eco-core:core-plugin'
|
include ':eco-core:core-plugin'
|
||||||
Reference in New Issue
Block a user