Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6ba24b7a5 | ||
|
|
1b00831147 | ||
|
|
479cff60d5 | ||
|
|
d2499b1e27 | ||
|
|
4f65f33953 | ||
|
|
6d4a69c781 | ||
|
|
e90e58b50a | ||
|
|
826bdb63d0 | ||
|
|
4ecba69161 | ||
|
|
e64510ebf5 | ||
|
|
50a506af62 | ||
|
|
bdbbb7e40a | ||
|
|
f2503e989c | ||
|
|
11c54a0055 | ||
|
|
7cc24199fb | ||
|
|
068b2cca0c | ||
|
|
f67f01278e | ||
|
|
8be8e1dab2 | ||
|
|
6d3651aca1 | ||
|
|
3dd2c58595 | ||
|
|
255aa1dd54 | ||
|
|
f2c5b085e8 | ||
|
|
b8a5fe0031 | ||
|
|
5603890663 | ||
|
|
1a86cc4dbd | ||
|
|
734add6dbc | ||
|
|
5641c0def3 | ||
|
|
b74ab5349a | ||
|
|
b0971e5124 | ||
|
|
02d8c8c6b6 | ||
|
|
d9bd5257e3 | ||
|
|
c1a214f34e | ||
|
|
64d1fbb9b1 | ||
|
|
a5433fbb3f | ||
|
|
2a2aed52e0 | ||
|
|
b16266e22a | ||
|
|
2c886dc33b | ||
|
|
db9c60cf35 | ||
|
|
a34b36daec | ||
|
|
41a35e99fd | ||
|
|
8e12dad247 | ||
|
|
72afa1e5cc | ||
|
|
9904553325 | ||
|
|
ad069ab32f | ||
|
|
b83a3dd548 | ||
|
|
7f41eab5e4 | ||
|
|
0d1c2364da | ||
|
|
5bca33a9f5 | ||
|
|
1196fe8004 | ||
|
|
98ae416fa7 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -14,7 +14,7 @@ bin/
|
||||
# Gradle
|
||||
.gradle
|
||||
**/build/
|
||||
!src/**/build/
|
||||
!eco-util/src/**/build/
|
||||
.gradletasknamecache
|
||||
!gradle-wrapper.jar
|
||||
gradle-app.setting
|
||||
|
||||
148
build.gradle
148
build.gradle
@@ -6,97 +6,91 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.apache.maven:maven-artifact:3.0.3'
|
||||
implementation 'org.bstats:bstats-bukkit:1.7'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
|
||||
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
|
||||
compileOnly 'com.github.cryptomorin:kingdoms:1.10.3.1'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
compileOnly fileTree(dir: '/lib', include: ['*.jar'])
|
||||
|
||||
// Lombok
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
implementation project(":eco-util")
|
||||
implementation project(":eco-core").getSubprojects()
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'com.github.johnrengelman.shadow'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
maven { url 'https://jitpack.io' }
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
maven { url 'https://jitpack.io' }
|
||||
|
||||
// NMS (for jitpack compilation)
|
||||
maven { url 'https://repo.codemc.org/repository/nms/' }
|
||||
// NMS (for jitpack compilation)
|
||||
maven { url 'https://repo.codemc.org/repository/nms/' }
|
||||
|
||||
// bStats
|
||||
maven { url 'https://repo.codemc.org/repository/maven-public' }
|
||||
// bStats
|
||||
maven { url 'https://repo.codemc.org/repository/maven-public' }
|
||||
|
||||
// Spigot API
|
||||
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
||||
// Spigot API
|
||||
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
||||
|
||||
// PlaceholderAPI
|
||||
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
|
||||
// PlaceholderAPI
|
||||
maven { url 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
|
||||
|
||||
// ProtocolLib
|
||||
maven { url 'https://repo.dmulloy2.net/nexus/repository/public/' }
|
||||
// ProtocolLib
|
||||
maven { url 'https://repo.dmulloy2.net/nexus/repository/public/' }
|
||||
|
||||
// WorldGuard
|
||||
maven { url 'https://maven.enginehub.org/repo/' }
|
||||
// WorldGuard
|
||||
maven { url 'https://maven.enginehub.org/repo/' }
|
||||
|
||||
// FactionsUUID
|
||||
maven { url 'https://ci.ender.zone/plugin/repository/everything/' }
|
||||
// FactionsUUID
|
||||
maven { url 'https://ci.ender.zone/plugin/repository/everything/' }
|
||||
|
||||
// NoCheatPlus
|
||||
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
exclude group: "org.codehaus.plexus", module: "plexus-utils"
|
||||
exclude group: "com.mojang", module: "brigadier"
|
||||
exclude group: "org.kitteh", module: "paste-gg-api"
|
||||
exclude group: "org.spongepowered", module: "configurate-hocon"
|
||||
exclude group: "com.darkblade12", module: "particleeffect"
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.bstats.bukkit', 'com.willfp.eco.util.shaded.bstats')
|
||||
relocate('org.apache.maven', 'com.willfp.eco.util.shaded.maven')
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) {
|
||||
from components.java
|
||||
artifact shadowJar
|
||||
}
|
||||
// NoCheatPlus
|
||||
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
// Lombok
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.deprecation = true
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
exclude group: "org.codehaus.plexus", module: "plexus-utils"
|
||||
exclude group: "com.mojang", module: "brigadier"
|
||||
exclude group: "org.kitteh", module: "paste-gg-api"
|
||||
exclude group: "org.spongepowered", module: "configurate-hocon"
|
||||
exclude group: "com.darkblade12", module: "particleeffect"
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.bstats.bukkit', 'com.willfp.eco.util.shaded.bstats')
|
||||
relocate('org.apache.maven', 'com.willfp.eco.util.shaded.maven')
|
||||
}
|
||||
|
||||
jar {
|
||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||
}
|
||||
|
||||
compileJava {
|
||||
onlyIf { !sourceSets.main.allSource.files.isEmpty() }
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
build.dependsOn shadowJar
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
publishToMavenLocal.dependsOn shadowJar
|
||||
|
||||
build.dependsOn shadowJar
|
||||
build.dependsOn publishToMavenLocal
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = '1.0.1'
|
||||
version = findProperty("version")
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
8
eco-core/build.gradle
Normal file
8
eco-core/build.gradle
Normal file
@@ -0,0 +1,8 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
subprojects {
|
||||
dependencies {
|
||||
compileOnly project(":eco-util")
|
||||
}
|
||||
}
|
||||
9
eco-core/core-nms/build.gradle
Normal file
9
eco-core/core-nms/build.gradle
Normal file
@@ -0,0 +1,9 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
subprojects {
|
||||
dependencies {
|
||||
compileOnly project(':eco-core:core-proxy')
|
||||
compileOnly project(':eco-core:core-plugin')
|
||||
}
|
||||
}
|
||||
6
eco-core/core-nms/v1_15_R1/build.gradle
Normal file
6
eco-core/core-nms/v1_15_R1/build.gradle
Normal file
@@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import net.minecraft.server.v1_15_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutAutoRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class AutoCraft implements AutoCraftProxy {
|
||||
@Override
|
||||
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
|
||||
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
|
||||
Field fKey = recipePacket.getClass().getDeclaredField("b");
|
||||
fKey.setAccessible(true);
|
||||
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
|
||||
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
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_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
6
eco-core/core-nms/v1_16_R1/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R1/build.gradle
Normal file
@@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import net.minecraft.server.v1_16_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutAutoRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class AutoCraft implements AutoCraftProxy {
|
||||
@Override
|
||||
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
|
||||
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
|
||||
Field fKey = recipePacket.getClass().getDeclaredField("b");
|
||||
fKey.setAccessible(true);
|
||||
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
|
||||
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.willfp.eco.proxy.v1_16_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.util.display.Display;
|
||||
import net.minecraft.server.v1_16_R1.ChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R1.ChatHoverable;
|
||||
import net.minecraft.server.v1_16_R1.ChatMessage;
|
||||
import net.minecraft.server.v1_16_R1.ChatModifier;
|
||||
import net.minecraft.server.v1_16_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R1.MojangsonParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_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)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
chatComponent.stream().forEach(this::modifyBaseComponent);
|
||||
|
||||
return chatComponent;
|
||||
}
|
||||
|
||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||
component.getSiblings().forEach(this::modifyBaseComponent);
|
||||
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.server.v1_16_R1.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,47 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
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
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
6
eco-core/core-nms/v1_16_R2/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R2/build.gradle
Normal file
@@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import net.minecraft.server.v1_16_R2.MinecraftKey;
|
||||
import net.minecraft.server.v1_16_R2.PacketPlayOutAutoRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class AutoCraft implements AutoCraftProxy {
|
||||
@Override
|
||||
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
|
||||
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
|
||||
Field fKey = recipePacket.getClass().getDeclaredField("b");
|
||||
fKey.setAccessible(true);
|
||||
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
|
||||
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
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.util.display.Display;
|
||||
import net.minecraft.server.v1_16_R2.ChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R2.ChatHoverable;
|
||||
import net.minecraft.server.v1_16_R2.ChatMessage;
|
||||
import net.minecraft.server.v1_16_R2.ChatModifier;
|
||||
import net.minecraft.server.v1_16_R2.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R2.MojangsonParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.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)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
chatComponent.stream().forEach(this::modifyBaseComponent);
|
||||
|
||||
return chatComponent;
|
||||
}
|
||||
|
||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||
component.getSiblings().forEach(this::modifyBaseComponent);
|
||||
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.server.v1_16_R2.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,47 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
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
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R2.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
6
eco-core/core-nms/v1_16_R3/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R3/build.gradle
Normal file
@@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import net.minecraft.server.v1_16_R3.MinecraftKey;
|
||||
import net.minecraft.server.v1_16_R3.PacketPlayOutAutoRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class AutoCraft implements AutoCraftProxy {
|
||||
@Override
|
||||
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
|
||||
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
|
||||
Field fKey = recipePacket.getClass().getDeclaredField("b");
|
||||
fKey.setAccessible(true);
|
||||
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
|
||||
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
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.util.display.Display;
|
||||
import net.minecraft.server.v1_16_R3.ChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R3.ChatHoverable;
|
||||
import net.minecraft.server.v1_16_R3.ChatMessage;
|
||||
import net.minecraft.server.v1_16_R3.ChatModifier;
|
||||
import net.minecraft.server.v1_16_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R3.MojangsonParser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.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)) {
|
||||
return object;
|
||||
}
|
||||
|
||||
IChatBaseComponent chatComponent = (IChatBaseComponent) object;
|
||||
chatComponent.stream().forEach(this::modifyBaseComponent);
|
||||
|
||||
return chatComponent;
|
||||
}
|
||||
|
||||
private void modifyBaseComponent(@NotNull final IChatBaseComponent component) {
|
||||
component.getSiblings().forEach(this::modifyBaseComponent);
|
||||
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.server.v1_16_R3.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,47 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
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 Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_16_R3.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
24
eco-core/core-plugin/build.gradle
Normal file
24
eco-core/core-plugin/build.gradle
Normal file
@@ -0,0 +1,24 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
implementation 'org.apache.maven:maven-artifact:3.0.3'
|
||||
implementation 'org.bstats:bstats-bukkit:1.7'
|
||||
compileOnly project(":eco-core:core-proxy")
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
|
||||
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
|
||||
compileOnly 'com.github.cryptomorin:kingdoms:1.10.3.1'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
processResources {
|
||||
filesNotMatching(["**/*.png", "**/models/**", "**/textures/**"]) {
|
||||
expand projectVersion: project.version
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.spigot.display.packets.PacketAutoRecipe;
|
||||
import com.willfp.eco.spigot.display.packets.PacketChat;
|
||||
import com.willfp.eco.spigot.display.packets.PacketOpenWindowMerchant;
|
||||
import com.willfp.eco.spigot.display.packets.PacketSetCreativeSlot;
|
||||
import com.willfp.eco.spigot.display.packets.PacketSetSlot;
|
||||
import com.willfp.eco.spigot.display.packets.PacketWindowItems;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.plugins.AnticheatAAC;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.plugins.AnticheatMatrix;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.plugins.AnticheatNCP;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefFactionsUUID;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefGriefPrevention;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefKingdoms;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefLands;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefTowny;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.plugins.AntigriefWorldGuard;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityListeners;
|
||||
import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainListeners;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.recipe.RecipeListener;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class EcoPlugin extends AbstractEcoPlugin {
|
||||
/**
|
||||
* Instance of eco.
|
||||
*/
|
||||
@Getter
|
||||
private static EcoPlugin instance;
|
||||
|
||||
/**
|
||||
* Create a new instance of eco.
|
||||
*/
|
||||
public EcoPlugin() {
|
||||
super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
new FastCollatedDropQueue.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 RecipeListener(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postLoad() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
return Arrays.asList(
|
||||
// AntiGrief
|
||||
new IntegrationLoader("WorldGuard", () -> AntigriefManager.register(new AntigriefWorldGuard())),
|
||||
new IntegrationLoader("GriefPrevention", () -> AntigriefManager.register(new AntigriefGriefPrevention())),
|
||||
new IntegrationLoader("FactionsUUID", () -> AntigriefManager.register(new AntigriefFactionsUUID())),
|
||||
new IntegrationLoader("Towny", () -> AntigriefManager.register(new AntigriefTowny())),
|
||||
new IntegrationLoader("Lands", () -> AntigriefManager.register(new AntigriefLands(this))),
|
||||
new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())),
|
||||
|
||||
// Anticheat
|
||||
new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())),
|
||||
new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())),
|
||||
new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP()))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
return Arrays.asList(
|
||||
new PacketAutoRecipe(this),
|
||||
new PacketChat(this),
|
||||
new PacketOpenWindowMerchant(this),
|
||||
new PacketSetCreativeSlot(this),
|
||||
new PacketSetSlot(this),
|
||||
new PacketWindowItems(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Listener> getListeners() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getUpdatableClasses() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.willfp.eco.util;
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import com.willfp.eco.util.proxy.ProxyFactory;
|
||||
import com.willfp.eco.proxy.util.ProxyFactory;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class ProxyUtils {
|
||||
public class InternalProxyUtils {
|
||||
/**
|
||||
* Get the implementation of a specified proxy.
|
||||
*
|
||||
@@ -16,6 +15,6 @@ public class ProxyUtils {
|
||||
* @return The proxy implementation.
|
||||
*/
|
||||
public @NotNull <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
|
||||
return new ProxyFactory<>(AbstractEcoPlugin.getInstance(), proxyClass).getProxy();
|
||||
return new ProxyFactory<>(EcoPlugin.getInstance(), proxyClass).getProxy();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class PacketAutoRecipe extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#SET_SLOT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketAutoRecipe(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.AUTO_RECIPE, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(packet.getMinecraftKeys().getValues().get(0).getFullKey().split(":")[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.getMinecraftKeys().getValues().get(0).getFullKey().split(":")[1].contains("displayed")) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
InternalProxyUtils.getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
PacketContainer newAutoRecipe = new PacketContainer(PacketType.Play.Server.AUTO_RECIPE);
|
||||
newAutoRecipe.getMinecraftKeys().write(0, packet.getMinecraftKeys().read(0));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, newAutoRecipe);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
|
||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketChat extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#CHAT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketChat(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.CHAT, ListenerPriority.MONITOR, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
for (int i = 0; i < packet.getChatComponents().size(); i++) {
|
||||
WrappedChatComponent component = packet.getChatComponents().read(i);
|
||||
if (component == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (component.getHandle() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(InternalProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
|
||||
packet.getChatComponents().write(i, newComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.spigot.InternalProxyUtils;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#OPEN_WINDOW_MERCHANT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketOpenWindowMerchant(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0);
|
||||
|
||||
recipes = recipes.stream().peek(merchantRecipe -> InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(merchantRecipe)).collect(Collectors.toList());
|
||||
|
||||
packet.getMerchantRecipeLists().writeSafely(0, recipes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketSetCreativeSlot extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Client#SET_CREATIVE_SLOT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketSetCreativeSlot(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Client.SET_CREATIVE_SLOT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
packet.getItemModifier().modify(0, Display::revert);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketSetSlot extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#SET_SLOT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketSetSlot(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.SET_SLOT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
packet.getItemModifier().modify(0, Display::display);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.spigot.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketWindowItems extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#WINDOW_ITEMS}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketWindowItems(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.WINDOW_ITEMS, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
packet.getItemListModifier().modify(0, itemStacks -> {
|
||||
if (itemStacks == null) {
|
||||
return null;
|
||||
}
|
||||
itemStacks.forEach(Display::display);
|
||||
return itemStacks;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import me.konsolas.aac.api.AACAPI;
|
||||
@@ -12,9 +12,9 @@ import java.util.Objects;
|
||||
|
||||
public class AnticheatAAC implements AnticheatWrapper, Listener {
|
||||
/**
|
||||
* AAC exemption for EcoEnchants.
|
||||
* AAC exemption for eco.
|
||||
*/
|
||||
private final AACExemption ecoEnchantsExemption = new AACExemption("EcoEnchants");
|
||||
private final AACExemption ecoExemption = new AACExemption("eco");
|
||||
|
||||
/**
|
||||
* AAC api.
|
||||
@@ -28,11 +28,11 @@ public class AnticheatAAC implements AnticheatWrapper, Listener {
|
||||
|
||||
@Override
|
||||
public void exempt(@NotNull final Player player) {
|
||||
api.addExemption(player, ecoEnchantsExemption);
|
||||
api.addExemption(player, ecoExemption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unexempt(@NotNull final Player player) {
|
||||
api.removeExemption(player, ecoEnchantsExemption);
|
||||
api.removeExemption(player, ecoExemption);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import me.rerere.matrix.api.events.PlayerViolationEvent;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
package com.willfp.eco.spigot.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import me.vagdedes.spartan.api.PlayerViolationEvent;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import org.bukkit.Location;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import me.angeschossen.lands.api.integration.LandsIntegration;
|
||||
import me.angeschossen.lands.api.land.Area;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief.plugins;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
0
eco-core/core-plugin/src/main/resources/config.yml
Normal file
0
eco-core/core-plugin/src/main/resources/config.yml
Normal file
0
eco-core/core-plugin/src/main/resources/lang.yml
Normal file
0
eco-core/core-plugin/src/main/resources/lang.yml
Normal file
26
eco-core/core-plugin/src/main/resources/plugin.yml
Normal file
26
eco-core/core-plugin/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
name: eco
|
||||
version: ${projectVersion}
|
||||
main: com.willfp.eco.spigot.EcoPlugin
|
||||
api-version: 1.15
|
||||
authors: [Auxilor]
|
||||
website: willfp.com
|
||||
loadbefore:
|
||||
- EcoEnchants
|
||||
- Talismans
|
||||
- ItemStats
|
||||
- EcoArmor
|
||||
- Illusioner
|
||||
depend:
|
||||
- ProtocolLib
|
||||
softdepend:
|
||||
- WorldGuard
|
||||
- GriefPrevention
|
||||
- Towny
|
||||
- FactionsUUID
|
||||
- Lands
|
||||
- Kingdoms
|
||||
- NoCheatPlus
|
||||
- AAC
|
||||
- Matrix
|
||||
- Spartan
|
||||
- PlaceholderAPI
|
||||
2
eco-core/core-proxy/build.gradle
Normal file
2
eco-core/core-proxy/build.gradle
Normal file
@@ -0,0 +1,2 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface AutoCraftProxy extends AbstractProxy {
|
||||
/**
|
||||
* Fix crafting inventory on auto-recipe.
|
||||
*
|
||||
* @param packet The packet to modify.
|
||||
*/
|
||||
void modifyPacket(@NotNull Object packet) throws NoSuchFieldException, IllegalAccessException;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ChatComponentProxy extends AbstractProxy {
|
||||
/**
|
||||
* Modify hover {@link org.bukkit.inventory.ItemStack}s using EnchantDisplay#displayEnchantments.
|
||||
* @param object The NMS ChatComponent to modify.
|
||||
* @return The modified ChatComponent.
|
||||
*/
|
||||
Object modifyComponent(@NotNull Object object);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
public interface VillagerTradeProxy extends AbstractProxy {
|
||||
/**
|
||||
* Apply enchant display to the result of trades.
|
||||
*
|
||||
* @param merchantRecipe The recipe to modify.
|
||||
*/
|
||||
void displayTrade(MerchantRecipe merchantRecipe);
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
package com.willfp.eco.proxy.util;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import com.willfp.eco.util.proxy.ProxyConstants;
|
||||
import com.willfp.eco.util.proxy.UnsupportedVersionException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
24
eco-util/build.gradle
Normal file
24
eco-util/build.gradle
Normal file
@@ -0,0 +1,24 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.apache.maven:maven-artifact:3.0.3'
|
||||
compileOnly 'org.bstats:bstats-bukkit:1.7'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
}
|
||||
|
||||
compileJava.options.encoding = 'UTF-8'
|
||||
compileJava.dependsOn clean
|
||||
|
||||
build.dependsOn publishToMavenLocal
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) {
|
||||
from components.java
|
||||
artifact shadowJar
|
||||
artifactId 'eco'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@@ -85,6 +87,24 @@ public class NumberUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number from roman numeral.
|
||||
*
|
||||
* @param numeral The numeral to convert.
|
||||
* @return The number, converted from a roman numeral.
|
||||
*/
|
||||
public static int fromNumeral(@NotNull final String numeral) {
|
||||
if (numeral.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
|
||||
if (numeral.startsWith(entry.getValue())) {
|
||||
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random integer in range.
|
||||
*
|
||||
214
eco-util/src/main/java/com/willfp/eco/util/StringUtils.java
Normal file
214
eco-util/src/main/java/com/willfp/eco/util/StringUtils.java
Normal file
@@ -0,0 +1,214 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
|
||||
|
||||
@UtilityClass
|
||||
public class StringUtils {
|
||||
/**
|
||||
* Regex for gradients.
|
||||
*/
|
||||
private static final String GRADIENT_REGEX = "<\\$#[A-Fa-f0-9]{6}>";
|
||||
|
||||
/**
|
||||
* Translate a string - converts Placeholders and Color codes.
|
||||
*
|
||||
* @param message The message to translate.
|
||||
* @param player The player to translate placeholders with respect to.
|
||||
* @return The message, translated.
|
||||
*/
|
||||
public String translate(@NotNull final String message,
|
||||
@Nullable final Player player) {
|
||||
String processedMessage = message;
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
processedMessage = translateGradients(processedMessage);
|
||||
}
|
||||
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
|
||||
processedMessage = translateHexColorCodes(processedMessage);
|
||||
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
|
||||
return processedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a string without respect to a player.
|
||||
*
|
||||
* @param message The message to translate.
|
||||
* @return The message, translated.
|
||||
* @see StringUtils#translate(String, Player)
|
||||
*/
|
||||
public String translate(@NotNull final String message) {
|
||||
return translate(message, null);
|
||||
}
|
||||
|
||||
private static String translateHexColorCodes(@NotNull final String message) {
|
||||
Pattern hexPattern = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + "");
|
||||
Matcher matcher = hexPattern.matcher(message);
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
|
||||
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
|
||||
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
|
||||
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
|
||||
}
|
||||
|
||||
return matcher.appendTail(buffer).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply gradients to the provided string.
|
||||
*
|
||||
* @param message the string to parse.
|
||||
* @return the parsed string.
|
||||
*/
|
||||
public static String translateGradients(@NotNull final String message) {
|
||||
List<String> hexes = new ArrayList<>();
|
||||
Matcher matcher = Pattern.compile(GRADIENT_REGEX).matcher(message);
|
||||
while (matcher.find()) {
|
||||
hexes.add(matcher.group().replace("<$", "").replace(">", ""));
|
||||
}
|
||||
int hexIndex = 0;
|
||||
List<String> texts = new LinkedList<>(Arrays.asList(message.split(GRADIENT_REGEX)));
|
||||
StringBuilder finalMsg = new StringBuilder();
|
||||
for (String text : texts) {
|
||||
if (texts.get(0).equalsIgnoreCase(text)) {
|
||||
finalMsg.append(text);
|
||||
continue;
|
||||
}
|
||||
if (text.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
if (hexIndex + 1 >= hexes.size()) {
|
||||
if (!finalMsg.toString().contains(text)) {
|
||||
finalMsg.append(text);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
String fromHex = hexes.get(hexIndex);
|
||||
String toHex = hexes.get(hexIndex + 1);
|
||||
finalMsg.append(insertFades(text, fromHex, toHex));
|
||||
hexIndex++;
|
||||
}
|
||||
return finalMsg.toString();
|
||||
}
|
||||
|
||||
private static String insertFades(@NotNull final String message,
|
||||
@NotNull final String fromHex,
|
||||
@NotNull final String toHex) {
|
||||
boolean bold = message.contains("&l");
|
||||
boolean italic = message.contains("&o");
|
||||
String msg = message;
|
||||
msg = msg.replace("&l", "");
|
||||
msg = msg.replace("&o", "");
|
||||
int length = msg.length();
|
||||
Color fromRGB = Color.decode(fromHex);
|
||||
Color toRGB = Color.decode(toHex);
|
||||
double rStep = Math.abs((double) (fromRGB.getRed() - toRGB.getRed()) / length);
|
||||
double gStep = Math.abs((double) (fromRGB.getGreen() - toRGB.getGreen()) / length);
|
||||
double bStep = Math.abs((double) (fromRGB.getBlue() - toRGB.getBlue()) / length);
|
||||
if (fromRGB.getRed() > toRGB.getRed()) {
|
||||
rStep = -rStep;
|
||||
}
|
||||
if (fromRGB.getGreen() > toRGB.getGreen()) {
|
||||
gStep = -gStep;
|
||||
}
|
||||
if (fromRGB.getBlue() > toRGB.getBlue()) {
|
||||
bStep = -bStep;
|
||||
}
|
||||
Color finalColor = new Color(fromRGB.getRGB());
|
||||
msg = msg.replaceAll(GRADIENT_REGEX, "");
|
||||
msg = msg.replace("", "<$>");
|
||||
for (int index = 0; index <= length; index++) {
|
||||
int red = (int) Math.round(finalColor.getRed() + rStep);
|
||||
int green = (int) Math.round(finalColor.getGreen() + gStep);
|
||||
int blue = (int) Math.round(finalColor.getBlue() + bStep);
|
||||
if (red > 255) {
|
||||
red = 255;
|
||||
}
|
||||
if (red < 0) {
|
||||
red = 0;
|
||||
}
|
||||
if (green > 255) {
|
||||
green = 255;
|
||||
}
|
||||
if (green < 0) {
|
||||
green = 0;
|
||||
}
|
||||
if (blue > 255) {
|
||||
blue = 255;
|
||||
}
|
||||
if (blue < 0) {
|
||||
blue = 0;
|
||||
}
|
||||
finalColor = new Color(red, green, blue);
|
||||
String hex = "#" + Integer.toHexString(finalColor.getRGB()).substring(2);
|
||||
String formats = "";
|
||||
if (bold) {
|
||||
formats += ChatColor.BOLD;
|
||||
}
|
||||
if (italic) {
|
||||
formats += ChatColor.ITALIC;
|
||||
}
|
||||
msg = msg.replaceFirst("<\\$>", ChatColor.of(hex) + formats);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of {@link String#valueOf}.
|
||||
* Formats collections and doubles better.
|
||||
*
|
||||
* @param object The object to convert to string.
|
||||
* @return The object stringified.
|
||||
*/
|
||||
public String internalToString(@Nullable final Object object) {
|
||||
if (object == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (object instanceof Integer) {
|
||||
return ((Integer) object).toString();
|
||||
} else if (object instanceof String) {
|
||||
return (String) object;
|
||||
} else if (object instanceof Double) {
|
||||
return NumberUtils.format((Double) object);
|
||||
} else if (object instanceof Collection<?>) {
|
||||
Collection<?> c = (Collection<?>) object;
|
||||
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
|
||||
} else {
|
||||
return String.valueOf(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a string of characters from the start of a string.
|
||||
*
|
||||
* @param string The string to remove the prefix from.
|
||||
* @param prefix The substring to remove.
|
||||
* @return The string with the prefix removed.
|
||||
*/
|
||||
public String removePrefix(@NotNull final String string,
|
||||
@NotNull final String prefix) {
|
||||
if (string.startsWith(prefix)) {
|
||||
return string.substring(prefix.length());
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,16 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class VectorUtils {
|
||||
/**
|
||||
* Cached circles to prevent many sqrt calls.
|
||||
*/
|
||||
private static final Map<Integer, Vector[]> CIRCLE_CACHE = new HashMap<>();
|
||||
|
||||
/**
|
||||
* If vector has all components as finite.
|
||||
*
|
||||
@@ -66,6 +73,11 @@ public class VectorUtils {
|
||||
* @return An array of {@link Vector}s.
|
||||
*/
|
||||
public Vector[] getCircle(final int radius) {
|
||||
Vector[] cached = CIRCLE_CACHE.get(radius);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
|
||||
double xoffset = -radius;
|
||||
@@ -85,7 +97,9 @@ public class VectorUtils {
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
Vector[] result = circleVecs.toArray(new Vector[0]);
|
||||
CIRCLE_CACHE.put(radius, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.util.command;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
@@ -112,12 +111,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
}
|
||||
|
||||
if (playersOnly && !(sender instanceof Player)) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("not-player"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("not-player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(permission) && sender instanceof Player) {
|
||||
sender.sendMessage(Configs.LANG.getNoPermission());
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getNoPermission());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
@@ -47,10 +48,12 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected BaseConfig(@NotNull final String configName,
|
||||
final boolean removeUnused) {
|
||||
super(AbstractEcoPlugin.getInstance());
|
||||
final boolean removeUnused,
|
||||
@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
this.name = configName + ".yml";
|
||||
this.removeUnused = removeUnused;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.util.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class Config extends BaseConfig {
|
||||
/**
|
||||
* Config.yml.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public Config(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super("config", true, plugin);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,17 @@ package com.willfp.eco.util.config.configs;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Lang extends BaseConfig {
|
||||
/**
|
||||
* lang.yml.
|
||||
* Lang.yml.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public Lang() {
|
||||
super("lang", false);
|
||||
public Lang(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super("lang", false, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
159
eco-util/src/main/java/com/willfp/eco/util/display/Display.java
Normal file
159
eco-util/src/main/java/com/willfp/eco/util/display/Display.java
Normal file
@@ -0,0 +1,159 @@
|
||||
package com.willfp.eco.util.display;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@UtilityClass
|
||||
public class Display {
|
||||
/**
|
||||
* Registered display functions.
|
||||
*/
|
||||
private static final List<Map<String, Function<ItemStack, ItemStack>>> DISPLAY_FUNCTIONS = new ArrayList<>(10000);
|
||||
|
||||
/**
|
||||
* Registered revert functions.
|
||||
*/
|
||||
private static final List<Function<ItemStack, ItemStack>> REVERT_FUNCTIONS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Registered finalize functions.
|
||||
*/
|
||||
public static final List<Function<ItemStack, ItemStack>> FINALIZE_FUNCTIONS = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Registered finalize test functions.
|
||||
*/
|
||||
public static final List<Predicate<ItemStack>> FINALIZE_TEST_FUNCTIONS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Register display module.
|
||||
*
|
||||
* @param module The module.
|
||||
*/
|
||||
public void registerDisplayModule(@NotNull final DisplayModule module) {
|
||||
int priority = module.getPriority();
|
||||
if (priority > 9999) {
|
||||
priority = 9999;
|
||||
}
|
||||
Function<ItemStack, ItemStack> function = module.getFunction();
|
||||
|
||||
Map<String, Function<ItemStack, ItemStack>> functions = DISPLAY_FUNCTIONS.get(priority);
|
||||
if (functions == null) {
|
||||
functions = new HashMap<>();
|
||||
}
|
||||
|
||||
functions.remove(module.getId());
|
||||
functions.put(module.getId(), function);
|
||||
|
||||
DISPLAY_FUNCTIONS.set(priority, functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register revert function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
public void registerRevertModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
||||
REVERT_FUNCTIONS.add(function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register finalize function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
public void registerFinalizeModule(@NotNull final Function<ItemStack, ItemStack> function) {
|
||||
FINALIZE_FUNCTIONS.add(function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register finalize test function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
public void registerFinalizeTestModule(@NotNull final Predicate<ItemStack> function) {
|
||||
FINALIZE_TEST_FUNCTIONS.add(function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display on ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
public ItemStack display(@NotNull final ItemStack itemStack) {
|
||||
for (Map<String, Function<ItemStack, ItemStack>> displayFunctions : DISPLAY_FUNCTIONS) {
|
||||
if (displayFunctions == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Function<ItemStack, ItemStack> displayFunction : displayFunctions.values()) {
|
||||
displayFunction.apply(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display on ItemStacks and then finalize.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
public ItemStack displayAndFinalize(@NotNull final ItemStack itemStack) {
|
||||
return finalize(display(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert on ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
public ItemStack revert(@NotNull final ItemStack itemStack) {
|
||||
for (Function<ItemStack, ItemStack> displayFunction : REVERT_FUNCTIONS) {
|
||||
displayFunction.apply(itemStack);
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
public ItemStack finalize(@NotNull final ItemStack itemStack) {
|
||||
for (Function<ItemStack, ItemStack> function : FINALIZE_FUNCTIONS) {
|
||||
function.apply(itemStack);
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize an ItemStacks.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
*/
|
||||
public boolean isFinalized(@NotNull final ItemStack itemStack) {
|
||||
for (Predicate<ItemStack> function : FINALIZE_TEST_FUNCTIONS) {
|
||||
if (function.test(itemStack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
DISPLAY_FUNCTIONS.add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.willfp.eco.util.display;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class DisplayModule {
|
||||
/**
|
||||
* Priority of the display module, where lower numbers are executed sooner.
|
||||
*/
|
||||
@Getter
|
||||
private final int priority;
|
||||
|
||||
/**
|
||||
* The function executed on display.
|
||||
*/
|
||||
@Getter
|
||||
private final Function<ItemStack, ItemStack> function;
|
||||
|
||||
/**
|
||||
* Function id for unregistration.
|
||||
*/
|
||||
@Getter
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Create new display module.
|
||||
*
|
||||
* @param function The function.
|
||||
* @param priority The priority.
|
||||
* @param id The id.
|
||||
*/
|
||||
public DisplayModule(@NotNull final Function<ItemStack, ItemStack> function,
|
||||
final int priority,
|
||||
@NotNull final String id) {
|
||||
this.function = function;
|
||||
this.priority = priority;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public final class DropManager {
|
||||
/**
|
||||
* The currently used type, or implementation, of {@link AbstractDropQueue}.
|
||||
* <p>
|
||||
* Standard by default, used if drops.collate key is not present in config.
|
||||
*/
|
||||
@Getter
|
||||
private DropQueueType type = DropQueueType.COLLATED;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -13,10 +12,9 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
/**
|
||||
@@ -24,7 +22,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* <p>
|
||||
* Cleared and updated every tick.
|
||||
*/
|
||||
private static final HashMap<Player, CollatedDrops> COLLATED_MAP = new HashMap<>();
|
||||
private static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Backend implementation of {@link AbstractDropQueue}
|
||||
@@ -104,7 +102,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollatedRunnable extends PluginDependent {
|
||||
public static class CollatedRunnable {
|
||||
/**
|
||||
* The {@link BukkitTask} that the runnable represents.
|
||||
*/
|
||||
@@ -118,7 +116,6 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, CollatedDrops> entry : COLLATED_MAP.entrySet()) {
|
||||
new InternalDropQueue(entry.getKey())
|
||||
@@ -126,6 +123,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
COLLATED_MAP.remove(entry.getKey());
|
||||
}
|
||||
COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.drops.telekinesis;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -7,20 +8,20 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoTelekinesisTests implements TelekinesisTests {
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
/**
|
||||
* Set of tests that return if the player is telekinetic.
|
||||
*/
|
||||
private final Set<Function<Player, Boolean>> tests = new HashSet<>();
|
||||
private static final Set<Function<Player, Boolean>> TESTS = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new test to check against.
|
||||
*
|
||||
* @param test The test to register, where the boolean output is if the player is telekinetic.
|
||||
*/
|
||||
@Override
|
||||
public void registerTest(@NotNull final Function<Player, Boolean> test) {
|
||||
tests.add(test);
|
||||
TESTS.add(test);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,9 +32,8 @@ public class EcoTelekinesisTests implements TelekinesisTests {
|
||||
* @param player The player to test.
|
||||
* @return If the player is telekinetic.
|
||||
*/
|
||||
@Override
|
||||
public boolean testPlayer(@NotNull final Player player) {
|
||||
for (Function<Player, Boolean> test : tests) {
|
||||
for (Function<Player, Boolean> test : TESTS) {
|
||||
if (test.apply(player)) {
|
||||
return true;
|
||||
}
|
||||
@@ -12,7 +12,16 @@ public abstract class Extension {
|
||||
* The {@link AbstractEcoPlugin} that this extension is for.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
private final AbstractEcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new extension for a plugin.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected Extension(@NotNull final AbstractEcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata containing version and name.
|
||||
@@ -100,7 +100,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
Object object = null;
|
||||
try {
|
||||
cls = cl.loadClass(mainClass);
|
||||
object = cls.getConstructor().newInstance();
|
||||
object = cls.getConstructor(AbstractEcoPlugin.class).newInstance(this.getPlugin());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user