Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
853aaca071 | ||
|
|
18dabd6bcf | ||
|
|
bb42505d66 | ||
|
|
b4d59077e3 | ||
|
|
104d55c11b | ||
|
|
b5af17cf08 | ||
|
|
78ae662ced | ||
|
|
32e48db3ce | ||
|
|
8a27e75c02 | ||
|
|
bf55e9b189 | ||
|
|
bfbaa3d033 | ||
|
|
64f87d5741 | ||
|
|
cb3441286c | ||
|
|
5e97a0f894 | ||
|
|
de2166dfdb | ||
|
|
abd361f4b5 | ||
|
|
422f8ead23 | ||
|
|
7c05dd7457 | ||
|
|
3ef7622c6f | ||
|
|
8207d62b1f | ||
|
|
75a0b1dd0d | ||
|
|
d1307e35db | ||
|
|
0a6b197a97 | ||
|
|
8d6512886c | ||
|
|
5c0c0f3e2a | ||
|
|
e2c2fc776a | ||
|
|
576050b31e | ||
|
|
f9a43bd336 | ||
|
|
203f2f599a | ||
|
|
baa5d37744 | ||
|
|
17f6af2a70 | ||
|
|
eae213f58e | ||
|
|
3a6a133560 | ||
|
|
57cf144c57 | ||
|
|
5c29859d49 | ||
|
|
02510127d1 | ||
|
|
f6b5c8f7e0 | ||
|
|
dbfef3094b | ||
|
|
b5c3af752c | ||
|
|
d0366b39e2 | ||
|
|
ed5390d2b5 | ||
|
|
e31857a15d | ||
|
|
32e119d187 | ||
|
|
5690eccd14 | ||
|
|
2faf3732df | ||
|
|
8670fb36e0 | ||
|
|
7c001c4809 | ||
|
|
bce1dd9fee | ||
|
|
412c2e1e3c | ||
|
|
dd7ffac974 | ||
|
|
7ad59e0166 | ||
|
|
2f2bdbb9f5 | ||
|
|
d23dc10bc5 | ||
|
|
46c2e3f90a | ||
|
|
1776b668a4 | ||
|
|
10dccd0f38 | ||
|
|
f1918eb1ec | ||
|
|
436b33fde2 | ||
|
|
cfa5cab1fa | ||
|
|
a8ba4dd812 | ||
|
|
94bf383d23 | ||
|
|
096207de82 | ||
|
|
3cb654f5df | ||
|
|
5552cc4fb0 | ||
|
|
94aacf8cca | ||
|
|
128d473b33 | ||
|
|
d5679dd58f | ||
|
|
b1e8165ecb | ||
|
|
d0a3d644f3 | ||
|
|
35b060af53 | ||
|
|
337dba23b4 | ||
|
|
433f9f53ab | ||
|
|
ba7a748efd | ||
|
|
1365fdae88 | ||
|
|
6a159bf049 | ||
|
|
31e0e93951 | ||
|
|
876343facb | ||
|
|
f0cd9ae16d | ||
|
|
b220428b8c | ||
|
|
8386aacfd8 | ||
|
|
3c54e24102 | ||
|
|
3dc0693b8c | ||
|
|
f087113ddf | ||
|
|
d5d1f5d8cc | ||
|
|
0d5bf901e2 | ||
|
|
ae0445f47b | ||
|
|
a6ba24b7a5 | ||
|
|
1b00831147 | ||
|
|
479cff60d5 | ||
|
|
d2499b1e27 | ||
|
|
4f65f33953 | ||
|
|
6d4a69c781 | ||
|
|
e90e58b50a | ||
|
|
826bdb63d0 | ||
|
|
4ecba69161 | ||
|
|
e64510ebf5 | ||
|
|
50a506af62 | ||
|
|
bdbbb7e40a | ||
|
|
f2503e989c | ||
|
|
11c54a0055 | ||
|
|
7cc24199fb | ||
|
|
068b2cca0c | ||
|
|
f67f01278e | ||
|
|
8be8e1dab2 | ||
|
|
6d3651aca1 | ||
|
|
3dd2c58595 | ||
|
|
255aa1dd54 | ||
|
|
f2c5b085e8 | ||
|
|
b8a5fe0031 | ||
|
|
5603890663 | ||
|
|
1a86cc4dbd | ||
|
|
734add6dbc | ||
|
|
5641c0def3 | ||
|
|
b74ab5349a | ||
|
|
b0971e5124 | ||
|
|
02d8c8c6b6 | ||
|
|
d9bd5257e3 | ||
|
|
c1a214f34e | ||
|
|
64d1fbb9b1 | ||
|
|
a5433fbb3f | ||
|
|
2a2aed52e0 | ||
|
|
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
|
||||
|
||||
149
build.gradle
149
build.gradle
@@ -6,97 +6,92 @@ 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, mcMMO
|
||||
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"
|
||||
exclude group: "com.github.cryptomorin", module: "XSeries"
|
||||
}
|
||||
|
||||
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
|
||||
@@ -115,7 +115,6 @@
|
||||
<!-- Checks for imports -->
|
||||
<!-- See https://checkstyle.org/config_imports.html -->
|
||||
<module name="AvoidStarImport"/>
|
||||
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
|
||||
<module name="RedundantImport"/>
|
||||
<module name="UnusedImports">
|
||||
<property name="processJavadoc" value="true"/>
|
||||
|
||||
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,16 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -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,15 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.CooldownProxy;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class Cooldown implements CooldownProxy {
|
||||
@Override
|
||||
public double getAttackCooldown(@NotNull final Player player) {
|
||||
EntityHuman entityHuman = ((CraftPlayer) player).getHandle();
|
||||
return entityHuman.s(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.proxy.v1_15_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,17 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_15_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
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) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
Display.display(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
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.display(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,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -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,41 @@
|
||||
package com.willfp.eco.proxy.v1_16_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,17 @@
|
||||
package com.willfp.eco.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_16_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
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) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
Display.display(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.display(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,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R2.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -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,41 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
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,17 @@
|
||||
package com.willfp.eco.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_16_R2.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
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) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
Display.display(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.display(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,16 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_16_R3.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -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,41 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
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,17 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_16_R3.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
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) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
Display.display(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.display(selling);
|
||||
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
25
eco-core/core-plugin/build.gradle
Normal file
25
eco-core/core-plugin/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
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.14'
|
||||
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 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
|
||||
compileOnly fileTree(dir: '../../lib', include: ['*.jar'])
|
||||
}
|
||||
|
||||
processResources {
|
||||
filesNotMatching(["**/*.png", "**/models/**", "**/textures/**"]) {
|
||||
expand projectVersion: project.version
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
||||
import com.willfp.eco.spigot.display.PacketChat;
|
||||
import com.willfp.eco.spigot.display.PacketOpenWindowMerchant;
|
||||
import com.willfp.eco.spigot.display.PacketSetCreativeSlot;
|
||||
import com.willfp.eco.spigot.display.PacketSetSlot;
|
||||
import com.willfp.eco.spigot.display.PacketWindowItems;
|
||||
import com.willfp.eco.spigot.drops.CollatedRunnable;
|
||||
import com.willfp.eco.spigot.eventlisteners.EntityDeathByEntityListeners;
|
||||
import com.willfp.eco.spigot.eventlisteners.NaturalExpGainListeners;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatAAC;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatMatrix;
|
||||
import com.willfp.eco.spigot.integrations.anticheat.AnticheatNCP;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefFactionsUUID;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefGriefPrevention;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefKingdoms;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
|
||||
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
|
||||
import com.willfp.eco.spigot.recipes.RecipeListener;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.PlayerUtils;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import com.willfp.eco.util.TridentUtils;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.display.Display;
|
||||
import com.willfp.eco.util.display.DisplayModule;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
|
||||
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.integrations.mcmmo.McmmoManager;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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;
|
||||
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized"));
|
||||
SkullUtils.initialize((skullMeta, base64) -> InternalProxyUtils.getProxy(SkullProxy.class).setSkullTexture(skullMeta, base64));
|
||||
BlockUtils.initialize(((player, block) -> InternalProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, block)));
|
||||
PlayerUtils.initialize(((player) -> InternalProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(player)));
|
||||
TridentUtils.initialize(((trident) -> InternalProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
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 RecipeListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
new 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())),
|
||||
|
||||
// Misc
|
||||
new IntegrationLoader("mcMMO", () -> McmmoManager.register(new McmmoIntegrationImpl()))
|
||||
);
|
||||
}
|
||||
|
||||
@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<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.eco.spigot.drops;
|
||||
|
||||
|
||||
import com.willfp.eco.internal.drops.impl.FastCollatedDropQueue;
|
||||
import com.willfp.eco.internal.drops.impl.InternalDropQueue;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class CollatedRunnable {
|
||||
/**
|
||||
* The {@link BukkitTask} that the runnable represents.
|
||||
*/
|
||||
@Getter
|
||||
private final BukkitTask runnableTask;
|
||||
|
||||
/**
|
||||
* Create and run a new runnable to process collated drops.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
|
||||
*/
|
||||
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, FastCollatedDropQueue.CollatedDrops> entry : FastCollatedDropQueue.COLLATED_MAP.entrySet()) {
|
||||
new InternalDropQueue(entry.getKey())
|
||||
.setLocation(entry.getValue().getLocation())
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
FastCollatedDropQueue.COLLATED_MAP.remove(entry.getKey());
|
||||
}
|
||||
FastCollatedDropQueue.COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.events.entitydeathbyentity;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.entitydeathbyentity;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.events.naturalexpgainevent;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainEvent;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.events.naturalexpgainevent;
|
||||
package com.willfp.eco.spigot.eventlisteners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.event.player.PlayerExpChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class NaturalExpGainListeners implements Listener {
|
||||
@@ -28,9 +29,10 @@ public class NaturalExpGainListeners implements Listener {
|
||||
|
||||
NaturalExpGainBuilder toRemove = null;
|
||||
for (NaturalExpGainBuilder searchBuilder : events) {
|
||||
if (!searchBuilder.getLocation().getWorld().equals(event.getPlayer().getLocation().getWorld())) {
|
||||
if (!Objects.equals(searchBuilder.getLocation().getWorld(), event.getPlayer().getLocation().getWorld())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52) {
|
||||
toRemove = searchBuilder;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
package com.willfp.eco.spigot.integrations.anticheat;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
@@ -1,26 +1,43 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief;
|
||||
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.kingdoms.constants.kingdom.Kingdom;
|
||||
import org.kingdoms.constants.kingdom.model.KingdomRelation;
|
||||
import org.kingdoms.constants.land.Land;
|
||||
import org.kingdoms.constants.player.DefaultKingdomPermission;
|
||||
import org.kingdoms.constants.player.KingdomPlayer;
|
||||
import org.kingdoms.managers.PvPManager;
|
||||
import org.kingdoms.managers.land.LandManager;
|
||||
|
||||
public class AntigriefKingdoms implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canBreakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
BlockBreakEvent event = new BlockBreakEvent(block, player);
|
||||
LandManager.onBreak(event);
|
||||
return !event.isCancelled();
|
||||
KingdomPlayer kp = KingdomPlayer.getKingdomPlayer(player);
|
||||
if (kp.isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Kingdom kingdom = kp.getKingdom();
|
||||
if (kingdom == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Land land = Land.getLand(block);
|
||||
|
||||
if (land == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
DefaultKingdomPermission permission = land.isNexusLand() ? DefaultKingdomPermission.NEXUS_BUILD : DefaultKingdomPermission.BUILD;
|
||||
if (!kp.hasPermission(permission)) {
|
||||
return false;
|
||||
}
|
||||
return kingdom.hasAttribute(land.getKingdom(), KingdomRelation.Attribute.BUILD);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,10 +58,7 @@ public class AntigriefKingdoms implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canPlaceBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
Block placedOn = block.getRelative(0, -1, 0);
|
||||
BlockPlaceEvent event = new BlockPlaceEvent(block, block.getState(), placedOn, player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND);
|
||||
LandManager.onPlace(event);
|
||||
return !event.isCancelled();
|
||||
return canBreakBlock(player, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
package com.willfp.eco.spigot.integrations.antigrief;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.spigot.integrations.mcmmo;
|
||||
|
||||
import com.gmail.nossr50.datatypes.meta.BonusDropMeta;
|
||||
import com.gmail.nossr50.events.fake.FakeEvent;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.willfp.eco.util.integrations.mcmmo.McmmoWrapper;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class McmmoIntegrationImpl implements McmmoWrapper {
|
||||
@Override
|
||||
public int getBonusDropCount(@NotNull final Block block) {
|
||||
if (block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).size() > 0) {
|
||||
BonusDropMeta bonusDropMeta = (BonusDropMeta) block.getMetadata(mcMMO.BONUS_DROPS_METAKEY).get(0);
|
||||
return bonusDropMeta.asInt();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFake(@NotNull final Event event) {
|
||||
return event instanceof FakeEvent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package com.willfp.eco.spigot.recipes;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.RecipeParts;
|
||||
import com.willfp.eco.util.recipe.Recipes;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
|
||||
import com.willfp.eco.util.recipe.recipes.EcoShapedRecipe;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.event.player.PlayerRecipeDiscoverEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RecipeListener implements Listener {
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void complexRecipeListener(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void complexRecipeListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
EcoShapedRecipe ecoShapedRecipe = Recipes.getShapedRecipe(recipe.getKey());
|
||||
|
||||
if (ecoShapedRecipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
RecipePart part = ecoShapedRecipe.getParts()[i];
|
||||
if (part instanceof SimpleRecipePart) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInEcoRecipe(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
EcoShapedRecipe ecoShapedRecipe = Recipes.getShapedRecipe(recipe.getKey());
|
||||
|
||||
if (ecoShapedRecipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
RecipePart part = ecoShapedRecipe.getParts()[i];
|
||||
if (part instanceof SimpleRecipePart) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents using talismans in recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : event.getInventory().getMatrix()) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents using talismans in recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingComplexPartInVanillaRecipe(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(recipe.getKey().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : event.getInventory().getMatrix()) {
|
||||
if (RecipeParts.isRecipePart(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setResult(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents learning displayed recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventLearningDisplayedRecipes(@NotNull final PlayerRecipeDiscoverEvent event) {
|
||||
if (!AbstractEcoPlugin.LOADED_ECO_PLUGINS.contains(event.getRecipe().getNamespace())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getRecipe().getKey().contains("_displayed")) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
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
27
eco-core/core-plugin/src/main/resources/plugin.yml
Normal file
27
eco-core/core-plugin/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
name: eco
|
||||
version: ${projectVersion}
|
||||
main: com.willfp.eco.spigot.EcoPlugin
|
||||
api-version: 1.15
|
||||
authors: [Auxilor]
|
||||
website: willfp.com
|
||||
loadbefore:
|
||||
- EcoEnchants
|
||||
- Talismans
|
||||
- StatTrackers
|
||||
- EcoArmor
|
||||
- Illusioner
|
||||
depend:
|
||||
- ProtocolLib
|
||||
softdepend:
|
||||
- WorldGuard
|
||||
- GriefPrevention
|
||||
- Towny
|
||||
- FactionsUUID
|
||||
- Lands
|
||||
- Kingdoms
|
||||
- NoCheatPlus
|
||||
- AAC
|
||||
- Matrix
|
||||
- Spartan
|
||||
- PlaceholderAPI
|
||||
- mcMMO
|
||||
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,17 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface BlockBreakProxy extends AbstractProxy {
|
||||
/**
|
||||
* Break the block as if the player had done it manually.
|
||||
*
|
||||
* @param player The player to break the block as.
|
||||
* @param block The block to break.
|
||||
*/
|
||||
void breakBlock(@NotNull Player player,
|
||||
@NotNull Block block);
|
||||
}
|
||||
@@ -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,15 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CooldownProxy extends AbstractProxy {
|
||||
/**
|
||||
* Get the attack cooldown for a player.
|
||||
*
|
||||
* @param player The player's attack cooldown.
|
||||
* @return A value between 0 and 1, with 1 representing full power.
|
||||
*/
|
||||
double getAttackCooldown(@NotNull Player player);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface SkullProxy extends AbstractProxy {
|
||||
/**
|
||||
* Set the texture of a skull from base64.
|
||||
*
|
||||
* @param meta The meta to modify.
|
||||
* @param base64 The base64 texture.
|
||||
*/
|
||||
void setSkullTexture(@NotNull SkullMeta meta,
|
||||
@NotNull String base64);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface TridentStackProxy extends AbstractProxy {
|
||||
/**
|
||||
* Get a trident's ItemStack.
|
||||
*
|
||||
* @param trident The trident to query.
|
||||
* @return The trident's ItemStack.
|
||||
*/
|
||||
ItemStack getTridentStack(@NotNull Trident trident);
|
||||
}
|
||||
@@ -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,4 +1,4 @@
|
||||
package com.willfp.eco.util.arrows;
|
||||
package com.willfp.eco.internal.arrows;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.bukkit.events;
|
||||
package com.willfp.eco.internal.bukkit.events;
|
||||
|
||||
import com.willfp.eco.util.bukkit.events.EventManager;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -11,8 +12,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class EcoEventManager extends PluginDependent implements EventManager {
|
||||
/**
|
||||
* Manager class for event management.
|
||||
* <p>
|
||||
* Prevents calls to {@link AbstractEcoPlugin#getInstance()}.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that this manages the events of.
|
||||
*/
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.util.bukkit.logging;
|
||||
package com.willfp.eco.internal.bukkit.logging;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.bukkit.logging.Logger;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.util.bukkit.scheduling;
|
||||
package com.willfp.eco.internal.bukkit.scheduling;
|
||||
|
||||
import com.willfp.eco.util.bukkit.scheduling.Scheduler;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class AbstractConfig extends AbstractUndefinedConfig {
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
* 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 AbstractConfig(@NotNull final String configName,
|
||||
@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final Class<?> source) {
|
||||
super(configName, plugin);
|
||||
this.source = source;
|
||||
this.subDirectoryPath = subDirectoryPath;
|
||||
|
||||
File directory = new File(this.getPlugin().getDataFolder(), subDirectoryPath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
|
||||
if (!new File(directory, this.getName()).exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(directory, this.getName());
|
||||
init(YamlConfiguration.loadConfiguration(configFile));
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
String resourcePath = getResourcePath();
|
||||
InputStream in = source.getResourceAsStream(resourcePath);
|
||||
|
||||
File outFile = new File(this.getPlugin().getDataFolder(), resourcePath);
|
||||
int lastIndex = resourcePath.lastIndexOf('/');
|
||||
File outDir = new File(this.getPlugin().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!outFile.exists()) {
|
||||
OutputStream out = new FileOutputStream(outFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource path as relative to base directory.
|
||||
*
|
||||
* @return The resource path.
|
||||
*/
|
||||
protected String getResourcePath() {
|
||||
String resourcePath;
|
||||
|
||||
if (subDirectoryPath.isEmpty()) {
|
||||
resourcePath = this.getName();
|
||||
} else {
|
||||
resourcePath = subDirectoryPath + this.getName();
|
||||
}
|
||||
|
||||
return "/" + resourcePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get YamlConfiguration as found in jar.
|
||||
*
|
||||
* @return The YamlConfiguration.
|
||||
*/
|
||||
protected YamlConfiguration getConfigInJar() {
|
||||
InputStream newIn = source.getResourceAsStream(getResourcePath());
|
||||
|
||||
if (newIn == null) {
|
||||
throw new NullPointerException(this.getName() + " is null?");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
|
||||
try {
|
||||
newConfig.load(reader);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return newConfig;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public abstract class AbstractUndefinedConfig extends PluginDependent {
|
||||
/**
|
||||
* The linked {@link YamlConfiguration} where values are physically stored.
|
||||
*/
|
||||
@Getter(AccessLevel.PUBLIC)
|
||||
protected YamlConfiguration config = null;
|
||||
|
||||
/**
|
||||
* The full name of the config file (eg config.yml).
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Cached values for faster reading.
|
||||
*/
|
||||
private final Map<String, Object> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Abstract config.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected AbstractUndefinedConfig(@NotNull final String configName,
|
||||
@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
this.name = configName + ".yml";
|
||||
}
|
||||
|
||||
protected void init(@NotNull final YamlConfiguration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears cache.
|
||||
*/
|
||||
public final void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the config contains a key.
|
||||
*
|
||||
* @param path The key to check.
|
||||
* @return If contained.
|
||||
*/
|
||||
public boolean has(@NotNull final String path) {
|
||||
return config.contains(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration section from config.
|
||||
*
|
||||
* @param path The key to check.
|
||||
* @return The configuration section. Throws NPE if not found.
|
||||
*/
|
||||
@NotNull
|
||||
public ConfigurationSection getSection(@NotNull final String path) {
|
||||
ConfigurationSection section = getSectionOrNull(path);
|
||||
if (section == null) {
|
||||
throw new NullPointerException("Section cannot be null!");
|
||||
} else {
|
||||
return section;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration section from config.
|
||||
*
|
||||
* @param path The key to check.
|
||||
* @return The configuration section, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public ConfigurationSection getSectionOrNull(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (ConfigurationSection) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getConfigurationSection(path));
|
||||
return getSectionOrNull(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
public int getInt(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (int) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getInt(path, 0));
|
||||
return getInt(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public Integer getIntOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getInt(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer from config with a specified default (not found) value.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @param def The value to default to if not found.
|
||||
* @return The found value, or the default.
|
||||
*/
|
||||
public int getInt(@NotNull final String path,
|
||||
final int def) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (int) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getInt(path, def));
|
||||
return getInt(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of integers from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Integer>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getIntegerList(path));
|
||||
return getInts(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of integers from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public List<Integer> getIntsOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getInts(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boolean from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or false if not found.
|
||||
*/
|
||||
public boolean getBool(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (boolean) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getBoolean(path));
|
||||
return getBool(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boolean from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public Boolean getBoolOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getBool(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of booleans from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
public List<Boolean> getBools(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Boolean>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getBooleanList(path));
|
||||
return getBools(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of booleans from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public List<Boolean> getBoolsOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getBools(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or an empty string if not found.
|
||||
*/
|
||||
@NotNull
|
||||
public String getString(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (String) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, StringUtils.translate(Objects.requireNonNull(config.getString(path, ""))));
|
||||
return getString(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public String getStringOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getString(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of strings from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<String>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getStringList(path));
|
||||
return getStrings(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of strings from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public List<String> getStringsOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getStrings(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a decimal from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
public double getDouble(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (double) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getDouble(path));
|
||||
return getDouble(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a decimal from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public Double getDoubleOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getDouble(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of decimals from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@NotNull
|
||||
public List<Double> getDoubles(@NotNull final String path) {
|
||||
if (cache.containsKey(path)) {
|
||||
return (List<Double>) cache.get(path);
|
||||
} else {
|
||||
cache.put(path, config.getDoubleList(path));
|
||||
return getDoubles(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of decimals from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public List<Double> getDoublesOrNull(@NotNull final String path) {
|
||||
if (has(path)) {
|
||||
return getDoubles(path);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.willfp.eco.internal.config;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractUpdatableConfig extends AbstractConfig {
|
||||
/**
|
||||
* Whether keys not in the base config should be removed on update.
|
||||
*/
|
||||
private final boolean removeUnused;
|
||||
|
||||
/**
|
||||
* List of blacklisted update keys.
|
||||
*/
|
||||
private final List<String> updateBlacklist;
|
||||
|
||||
/**
|
||||
* Updatable config.
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param plugin The plugin.
|
||||
* @param subDirectoryPath The subdirectory path.
|
||||
* @param source The class that owns the resource.
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param updateBlacklist Substring of keys to not add/remove keys for.
|
||||
*/
|
||||
protected AbstractUpdatableConfig(@NotNull final String configName,
|
||||
@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String subDirectoryPath,
|
||||
@NotNull final Class<?> source,
|
||||
final boolean removeUnused,
|
||||
@NotNull final String... updateBlacklist) {
|
||||
super(configName, plugin, subDirectoryPath, source);
|
||||
this.removeUnused = removeUnused;
|
||||
this.updateBlacklist = new ArrayList<>(Arrays.asList(updateBlacklist));
|
||||
this.updateBlacklist.removeIf(String::isEmpty);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the config.
|
||||
* <p>
|
||||
* Writes missing values, however removes comments due to how configs are stored internally in bukkit.
|
||||
*/
|
||||
public void update() {
|
||||
super.clearCache();
|
||||
try {
|
||||
config.load(this.getConfigFile());
|
||||
|
||||
YamlConfiguration newConfig = this.getConfigInJar();
|
||||
|
||||
if (newConfig.getKeys(true).equals(config.getKeys(true))) {
|
||||
return;
|
||||
}
|
||||
|
||||
newConfig.getKeys(true).forEach((s -> {
|
||||
if (!config.getKeys(true).contains(s)) {
|
||||
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||
config.set(s, newConfig.get(s));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
if (this.removeUnused) {
|
||||
config.getKeys(true).forEach((s -> {
|
||||
if (!newConfig.getKeys(true).contains(s)) {
|
||||
if (updateBlacklist.stream().noneMatch(s::contains)) {
|
||||
config.set(s, null);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
config.save(this.getConfigFile());
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public final class DropManager {
|
||||
/**
|
||||
* The currently used type, or implementation, of {@link AbstractDropQueue}.
|
||||
* <p>
|
||||
* Default is {@link DropQueueType#COLLATED}, however this can be changed.
|
||||
*/
|
||||
@Getter
|
||||
private DropQueueType type = DropQueueType.COLLATED;
|
||||
|
||||
/**
|
||||
* Sets the type of Drop Queue to be used.
|
||||
*
|
||||
* @param type The type.
|
||||
*/
|
||||
public static void setType(@NotNull final DropQueueType type) {
|
||||
DropManager.type = type;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops;
|
||||
|
||||
public enum DropQueueType {
|
||||
/**
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -9,14 +8,11 @@ import lombok.experimental.Accessors;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
/**
|
||||
@@ -24,7 +20,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* <p>
|
||||
* Cleared and updated every tick.
|
||||
*/
|
||||
private static final HashMap<Player, CollatedDrops> COLLATED_MAP = new HashMap<>();
|
||||
public static final Map<Player, CollatedDrops> COLLATED_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Backend implementation of {@link AbstractDropQueue}
|
||||
@@ -39,7 +35,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues the drops to be managed by the {@link CollatedRunnable}.
|
||||
* Queues the drops to be managed by the runnable.
|
||||
*/
|
||||
@Override
|
||||
public void push() {
|
||||
@@ -52,7 +48,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
* The items, location, and xp linked to a player's drops.
|
||||
*/
|
||||
@ToString
|
||||
private static final class CollatedDrops {
|
||||
public static final class CollatedDrops {
|
||||
/**
|
||||
* A collection of all ItemStacks to be dropped at the end of the tick.
|
||||
*/
|
||||
@@ -103,32 +99,4 @@ public class FastCollatedDropQueue extends InternalDropQueue {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollatedRunnable extends PluginDependent {
|
||||
/**
|
||||
* The {@link BukkitTask} that the runnable represents.
|
||||
*/
|
||||
@Getter
|
||||
private final BukkitTask runnableTask;
|
||||
|
||||
/**
|
||||
* Create and run a new runnable to process collated drops.
|
||||
*
|
||||
* @param plugin The {@link AbstractEcoPlugin} that manages the processing.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public CollatedRunnable(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
runnableTask = plugin.getScheduler().runTimer(() -> {
|
||||
for (Map.Entry<Player, CollatedDrops> entry : COLLATED_MAP.entrySet()) {
|
||||
new InternalDropQueue(entry.getKey())
|
||||
.setLocation(entry.getValue().getLocation())
|
||||
.addItems(entry.getValue().getDrops())
|
||||
.addXP(entry.getValue().getXp())
|
||||
.push();
|
||||
}
|
||||
COLLATED_MAP.clear();
|
||||
}, 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
package com.willfp.eco.internal.drops.impl;
|
||||
|
||||
import com.willfp.eco.internal.drops.AbstractDropQueue;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
@@ -133,6 +135,11 @@ public class InternalDropQueue implements AbstractDropQueue {
|
||||
assert world != null;
|
||||
loc = loc.add(0.5, 0.5, 0.5);
|
||||
|
||||
items.removeIf(itemStack -> itemStack.getType() == Material.AIR);
|
||||
if (items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasTelekinesis) {
|
||||
HashMap<Integer, ItemStack> leftover = player.getInventory().addItem(items.toArray(new ItemStack[0]));
|
||||
for (ItemStack drop : leftover.values()) {
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.willfp.eco.util.extensions.loader;
|
||||
package com.willfp.eco.internal.extensions;
|
||||
|
||||
|
||||
import com.willfp.eco.util.extensions.Extension;
|
||||
import com.willfp.eco.util.extensions.MalformedExtensionException;
|
||||
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -94,13 +96,16 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
String mainClass = extensionYml.getString("main");
|
||||
String name = extensionYml.getString("name");
|
||||
String version = extensionYml.getString("version");
|
||||
Validate.notNull(name, "Name is missing!");
|
||||
Validate.notNull(version, "Version is missing!");
|
||||
|
||||
Extension.ExtensionMetadata metadata = new Extension.ExtensionMetadata(version, name);
|
||||
|
||||
Class<?> cls;
|
||||
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();
|
||||
}
|
||||
@@ -1,20 +1,34 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@UtilityClass
|
||||
public class BlockUtils {
|
||||
public class BlockUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The block break function.
|
||||
*/
|
||||
private BiConsumer<Player, Block> blockBreakConsumer = null;
|
||||
|
||||
private Set<Block> getNearbyBlocks(@NotNull final Block start,
|
||||
@NotNull final List<Material> allowedMaterials,
|
||||
@NotNull final HashSet<Block> blocks,
|
||||
@NotNull final Set<Block> blocks,
|
||||
final int limit) {
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
Block block = start.getRelative(face);
|
||||
@@ -29,7 +43,6 @@ public class BlockUtils {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a set of all blocks in contact with each other of a specific type.
|
||||
*
|
||||
@@ -44,4 +57,32 @@ public class BlockUtils {
|
||||
final int limit) {
|
||||
return getNearbyBlocks(start, allowedMaterials, new HashSet<>(), limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Break the block as if the player had done it manually.
|
||||
*
|
||||
* @param player The player to break the block as.
|
||||
* @param block The block to break.
|
||||
*/
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(blockBreakConsumer, "Must be initialized!");
|
||||
|
||||
blockBreakConsumer.accept(player, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the block break function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final BiConsumer<Player, Block> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
blockBreakConsumer = function;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -37,25 +38,32 @@ public class DurabilityUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Special edge case
|
||||
if (item.getType() == Material.CARVED_PUMPKIN || item.getType() == Material.PLAYER_HEAD) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event3);
|
||||
|
||||
if (!event3.isCancelled()) {
|
||||
int damage2 = event3.getDamage();
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
|
||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||
meta.setDamage(item.getType().getMaxDurability());
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
player.getInventory().clear(slot);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
||||
} else {
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||
meta.setDamage(item.getType().getMaxDurability());
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, item);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
player.getInventory().clear(slot);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1, 1);
|
||||
} else {
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,20 +86,22 @@ public class DurabilityUtils {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item.getItemMeta() instanceof Damageable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event3);
|
||||
|
||||
if (!event3.isCancelled()) {
|
||||
int damage2 = event3.getDamage();
|
||||
if (item.getItemMeta() instanceof Damageable) {
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
Damageable meta = (Damageable) item.getItemMeta();
|
||||
meta.setDamage(meta.getDamage() + damage2);
|
||||
|
||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||
meta.setDamage(item.getType().getMaxDurability() - 1);
|
||||
}
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
if (meta.getDamage() >= item.getType().getMaxDurability()) {
|
||||
meta.setDamage(item.getType().getMaxDurability() - 1);
|
||||
}
|
||||
item.setItemMeta((ItemMeta) meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
54
eco-util/src/main/java/com/willfp/eco/util/PlayerUtils.java
Normal file
54
eco-util/src/main/java/com/willfp/eco/util/PlayerUtils.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class PlayerUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The cooldown function.
|
||||
*/
|
||||
private Function<Player, Double> cooldownFunction = null;
|
||||
|
||||
/**
|
||||
* Get the attack cooldown for a player.
|
||||
*
|
||||
* @param player The player's attack cooldown.
|
||||
* @return A value between 0 and 1, with 1 representing full power.
|
||||
*/
|
||||
public double getAttackCooldown(@NotNull final Player player) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(cooldownFunction, "Must be initialized!");
|
||||
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
return player.getAttackCooldown();
|
||||
}
|
||||
|
||||
return cooldownFunction.apply(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the cooldown function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final Function<Player, Double> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
cooldownFunction = function;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
49
eco-util/src/main/java/com/willfp/eco/util/SkullUtils.java
Normal file
49
eco-util/src/main/java/com/willfp/eco/util/SkullUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@UtilityClass
|
||||
public class SkullUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The meta set function.
|
||||
*/
|
||||
private BiConsumer<SkullMeta, String> metaSetConsumer = null;
|
||||
|
||||
/**
|
||||
* Set the texture of a skull from base64.
|
||||
*
|
||||
* @param meta The meta to modify.
|
||||
* @param base64 The base64 texture.
|
||||
*/
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(metaSetConsumer, "Must be initialized!");
|
||||
|
||||
metaSetConsumer.accept(meta, base64);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the skull texture function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final BiConsumer<SkullMeta, String> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
metaSetConsumer = function;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
204
eco-util/src/main/java/com/willfp/eco/util/StringUtils.java
Normal file
204
eco-util/src/main/java/com/willfp/eco/util/StringUtils.java
Normal file
@@ -0,0 +1,204 @@
|
||||
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.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.md_5.bungee.api.ChatColor.COLOR_CHAR;
|
||||
|
||||
@UtilityClass
|
||||
public class StringUtils {
|
||||
/**
|
||||
* Regex for gradients.
|
||||
*/
|
||||
private static final Pattern GRADIENT_REGEX = Pattern.compile("<GRADIENT:([0-9A-Fa-f]{6})>(.*?)</GRADIENT:([0-9A-Fa-f]{6})>");
|
||||
|
||||
/**
|
||||
* Regex for hex codes.
|
||||
*/
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([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) {
|
||||
Matcher matcher = HEX_PATTERN.matcher(message);
|
||||
StringBuffer buffer = new StringBuffer(message.length() + 4 * 8);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, COLOR_CHAR + "x"
|
||||
+ COLOR_CHAR + group.charAt(0) + COLOR_CHAR + group.charAt(1)
|
||||
+ COLOR_CHAR + group.charAt(2) + COLOR_CHAR + group.charAt(3)
|
||||
+ COLOR_CHAR + group.charAt(4) + COLOR_CHAR + group.charAt(5));
|
||||
}
|
||||
|
||||
return matcher.appendTail(buffer).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors a string with a gradient.
|
||||
*
|
||||
* @param string The string to color.
|
||||
* @param start The start color.
|
||||
* @param end The end color.
|
||||
* @return The string, colored.
|
||||
*/
|
||||
private static String processGradients(@NotNull final String string,
|
||||
@NotNull final Color start,
|
||||
@NotNull final Color end) {
|
||||
String processedString = string;
|
||||
List<ChatColor> modifiers = new ArrayList<>();
|
||||
if (processedString.contains("&l")) {
|
||||
modifiers.add(ChatColor.BOLD);
|
||||
}
|
||||
if (processedString.contains("&o")) {
|
||||
modifiers.add(ChatColor.ITALIC);
|
||||
}
|
||||
if (processedString.contains("&n")) {
|
||||
modifiers.add(ChatColor.UNDERLINE);
|
||||
}
|
||||
if (processedString.contains("&k")) {
|
||||
modifiers.add(ChatColor.MAGIC);
|
||||
}
|
||||
processedString = processedString.replace("&l", "");
|
||||
processedString = processedString.replace("&o", "");
|
||||
processedString = processedString.replace("&n", "");
|
||||
processedString = processedString.replace("&k", "");
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
ChatColor[] colors = getGradientColors(start, end, processedString.length());
|
||||
String[] characters = processedString.split("");
|
||||
for (int i = 0; i < processedString.length(); i++) {
|
||||
stringBuilder.append(colors[i]);
|
||||
modifiers.forEach(stringBuilder::append);
|
||||
stringBuilder.append(characters[i]);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates chatColors for gradients.
|
||||
*
|
||||
* @param start The start color.
|
||||
* @param end The end color.
|
||||
* @param step How many colors are returned.
|
||||
* @return Array of chat colors.
|
||||
*/
|
||||
private static ChatColor[] getGradientColors(@NotNull final Color start,
|
||||
@NotNull final Color end,
|
||||
final int step) {
|
||||
ChatColor[] colors = new ChatColor[step];
|
||||
int stepR = Math.abs(start.getRed() - end.getRed()) / (step - 1);
|
||||
int stepG = Math.abs(start.getGreen() - end.getGreen()) / (step - 1);
|
||||
int stepB = Math.abs(start.getBlue() - end.getBlue()) / (step - 1);
|
||||
int[] direction = new int[]{
|
||||
start.getRed() < end.getRed() ? +1 : -1,
|
||||
start.getGreen() < end.getGreen() ? +1 : -1,
|
||||
start.getBlue() < end.getBlue() ? +1 : -1
|
||||
};
|
||||
|
||||
for (int i = 0; i < step; i++) {
|
||||
Color color = new Color(start.getRed() + ((stepR * i) * direction[0]), start.getGreen() + ((stepG * i) * direction[1]), start.getBlue() + ((stepB * i) * direction[2]));
|
||||
colors[i] = ChatColor.of(color);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add gradients to a string.
|
||||
*
|
||||
* @param string The string.
|
||||
* @return The string, colorized.
|
||||
*/
|
||||
private static String translateGradients(@NotNull final String string) {
|
||||
String processedString = string;
|
||||
Matcher matcher = GRADIENT_REGEX.matcher(string);
|
||||
while (matcher.find()) {
|
||||
String start = matcher.group(1);
|
||||
String end = matcher.group(3);
|
||||
String content = matcher.group(2);
|
||||
processedString = processedString.replace(matcher.group(), processGradients(content, new Color(Integer.parseInt(start, 16)), new Color(Integer.parseInt(end, 16))));
|
||||
}
|
||||
return processedString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal implementation of {@link String#valueOf}.
|
||||
* Formats collections and doubles better.
|
||||
*
|
||||
* @param object The object to convert to string.
|
||||
* @return The object stringified.
|
||||
*/
|
||||
public String internalToString(@Nullable final Object object) {
|
||||
if (object == null) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (object instanceof Integer) {
|
||||
return ((Integer) object).toString();
|
||||
} else if (object instanceof String) {
|
||||
return (String) object;
|
||||
} else if (object instanceof Double) {
|
||||
return NumberUtils.format((Double) object);
|
||||
} else if (object instanceof Collection<?>) {
|
||||
Collection<?> c = (Collection<?>) object;
|
||||
return c.stream().map(StringUtils::internalToString).collect(Collectors.joining(", "));
|
||||
} else {
|
||||
return String.valueOf(object);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a string of characters from the start of a string.
|
||||
*
|
||||
* @param string The string to remove the prefix from.
|
||||
* @param prefix The substring to remove.
|
||||
* @return The string with the prefix removed.
|
||||
*/
|
||||
public String removePrefix(@NotNull final String string,
|
||||
@NotNull final String prefix) {
|
||||
if (string.startsWith(prefix)) {
|
||||
return string.substring(prefix.length());
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
49
eco-util/src/main/java/com/willfp/eco/util/TridentUtils.java
Normal file
49
eco-util/src/main/java/com/willfp/eco/util/TridentUtils.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class TridentUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The meta set function.
|
||||
*/
|
||||
private Function<Trident, ItemStack> tridentFunction = null;
|
||||
|
||||
/**
|
||||
* Get a trident's ItemStack.
|
||||
*
|
||||
* @param trident The trident to query.
|
||||
* @return The trident's ItemStack.
|
||||
*/
|
||||
public ItemStack getItemStack(@NotNull final Trident trident) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(tridentFunction, "Must be initialized!");
|
||||
|
||||
return tridentFunction.apply(trident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the trident function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final Function<Trident, ItemStack> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
tridentFunction = function;
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,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,11 +1,11 @@
|
||||
package com.willfp.eco.util.bukkit.keys;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependentFactory;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NamespacedKeyFactory extends PluginDependentFactory {
|
||||
public class NamespacedKeyFactory extends PluginDependent {
|
||||
/**
|
||||
* Factory class to produce {@link NamespacedKey}s associated with an {@link AbstractEcoPlugin}.
|
||||
*
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user