Compare commits

..

136 Commits
1.0.1 ... 4.1.0

Author SHA1 Message Date
Auxilor
853aaca071 Updated to 4.1.0 2021-02-18 14:26:48 +00:00
Auxilor
18dabd6bcf Added StaticOptionalConfig 2021-02-18 14:26:37 +00:00
Auxilor
bb42505d66 Hopeful fix 2021-02-17 16:07:08 +00:00
Auxilor
b4d59077e3 Fixed load order again 2021-02-17 15:55:39 +00:00
Auxilor
104d55c11b Changed load order again 2021-02-17 15:49:51 +00:00
Auxilor
b5af17cf08 Changed load order 2021-02-17 15:45:33 +00:00
Auxilor
78ae662ced Fixed RecipeParts 2021-02-17 15:20:39 +00:00
Auxilor
32e48db3ce Removed @Nullable because it's annoying 2021-02-17 15:02:52 +00:00
Auxilor
8a27e75c02 Fixed EcoPlugin 2021-02-17 14:55:34 +00:00
Auxilor
bf55e9b189 Constructor change 2021-02-17 14:54:28 +00:00
Auxilor
bfbaa3d033 Removed redundant check 2021-02-17 14:42:03 +00:00
Auxilor
64f87d5741 Cleaned up recipes 2021-02-17 13:54:02 +00:00
Auxilor
cb3441286c Removed redundant Registerable interface 2021-02-17 13:39:32 +00:00
Auxilor
5e97a0f894 Refactored ArrowDataListener 2021-02-17 13:35:32 +00:00
Auxilor
de2166dfdb Reworked tuples 2021-02-17 13:33:57 +00:00
Auxilor
abd361f4b5 Refactored config internals 2021-02-17 13:30:06 +00:00
Auxilor
422f8ead23 Removed RecipeListener from api 2021-02-17 13:27:28 +00:00
Auxilor
7c05dd7457 Reworked recipes 2021-02-17 13:20:34 +00:00
Auxilor
3ef7622c6f Updated to 4.0.0 2021-02-17 12:50:16 +00:00
Auxilor
8207d62b1f Reworked display system. 2021-02-17 12:50:01 +00:00
Auxilor
75a0b1dd0d Added @Internal annotations 2021-02-17 12:05:14 +00:00
Auxilor
d1307e35db Minor code issues 2021-02-16 19:48:20 +00:00
Auxilor
0a6b197a97 Cleaned various internals 2021-02-16 19:44:34 +00:00
Auxilor
8d6512886c Removed redundant PluginDependentFactory.java 2021-02-16 19:37:55 +00:00
Auxilor
5c0c0f3e2a Refactored Scheduler.java 2021-02-16 19:35:55 +00:00
Auxilor
e2c2fc776a Moved break blocks into block utils 2021-02-16 19:34:26 +00:00
Auxilor
576050b31e Updated to 3.8.0 2021-02-16 19:22:20 +00:00
Auxilor
f9a43bd336 Added trident util initializatoin 2021-02-16 19:17:59 +00:00
Auxilor
203f2f599a Added trident utils 2021-02-16 19:16:48 +00:00
Auxilor
baa5d37744 Added PlayerUtils 2021-02-16 19:11:02 +00:00
Auxilor
17f6af2a70 Added Skull texture setter 2021-02-16 18:07:47 +00:00
Auxilor
eae213f58e More refactoring, splitting api and internal 2021-02-14 16:31:16 +00:00
Auxilor
3a6a133560 Added caching to AbstractConfig 2021-02-14 15:32:10 +00:00
Auxilor
57cf144c57 Refactoring to remove internal components from API 2021-02-14 15:23:42 +00:00
Auxilor
5c29859d49 Updated to 3.7.0 2021-02-10 10:50:46 +00:00
Auxilor
02510127d1 Added getParts to EcoShapedRecipe 2021-02-10 10:50:31 +00:00
Auxilor
f6b5c8f7e0 Updated to eco 3.6.1 2021-02-09 09:30:29 +00:00
Auxilor
dbfef3094b Fixed villager trade being finalized 2021-02-09 09:30:08 +00:00
Auxilor
b5c3af752c Fixed bugs with new config system 2021-02-07 20:18:00 +00:00
Auxilor
d0366b39e2 Updated to 3.6.0 2021-02-07 20:03:46 +00:00
Auxilor
ed5390d2b5 Reworked config system (again) 2021-02-07 20:03:31 +00:00
Auxilor
e31857a15d Merge remote-tracking branch 'origin/master' into master
# Conflicts:
#	gradle.properties
2021-02-07 19:29:52 +00:00
Auxilor
32e119d187 Updated to 3.5.0 2021-02-07 19:29:32 +00:00
Auxilor
5690eccd14 Refactored config system and added update blacklist 2021-02-07 19:29:05 +00:00
Auxilor
2faf3732df Updated to 3.4.4 2021-02-07 15:00:52 +00:00
Auxilor
8670fb36e0 Changed ItemStats to StatTrackers 2021-02-07 15:00:36 +00:00
Auxilor
7c001c4809 Updated to 3.4.3 2021-02-03 09:14:20 +00:00
Auxilor
bce1dd9fee Fixed finalize issues 2021-02-03 09:13:45 +00:00
Auxilor
412c2e1e3c Updated to 3.4.2 2021-02-01 16:04:28 +00:00
Auxilor
dd7ffac974 Cleaned up DurabilityUtils and added edge case 2021-02-01 16:04:17 +00:00
Auxilor
7ad59e0166 Updated to 3.4.1 2021-02-01 08:54:30 +00:00
Auxilor
2f2bdbb9f5 Prevented dropping empty dropqueue or air 2021-02-01 08:54:17 +00:00
Auxilor
d23dc10bc5 Improved finalization (again) 2021-01-30 14:48:14 +00:00
Auxilor
46c2e3f90a Updated to 3.4.0 2021-01-30 14:31:51 +00:00
Auxilor
1776b668a4 Improved Display system 2021-01-30 14:31:31 +00:00
Auxilor
10dccd0f38 Updated to 3.3.3 2021-01-28 13:13:21 +00:00
Auxilor
f1918eb1ec Stopped removing final modifier on villager trades 2021-01-28 13:13:02 +00:00
Auxilor
436b33fde2 Fixed lands 2021-01-27 10:33:08 +00:00
Auxilor
cfa5cab1fa Updated to 3.3.2 2021-01-27 10:28:02 +00:00
Auxilor
a8ba4dd812 Updated KingdomsX integration 2021-01-27 10:27:44 +00:00
Auxilor
94bf383d23 Added setType to DropManager 2021-01-27 09:56:23 +00:00
Auxilor
096207de82 Fixed EcoEventManager javadoc 2021-01-27 09:36:03 +00:00
Auxilor
3cb654f5df Refactored integration packages on the backend 2021-01-27 09:34:04 +00:00
Auxilor
5552cc4fb0 Updated to 3.3.1 2021-01-27 08:34:31 +00:00
Auxilor
94aacf8cca Changed AntigriefKingdoms integration 2021-01-27 08:34:19 +00:00
Auxilor
128d473b33 Added direct mcMMO support 2021-01-24 16:04:40 +00:00
Auxilor
d5679dd58f Downgraded back to 3.2.2 2021-01-23 19:45:44 +00:00
Auxilor
b1e8165ecb Removed ReflectionUtils.java 2021-01-23 19:44:40 +00:00
Auxilor
d0a3d644f3 Updated to 3.3.0 2021-01-23 19:38:23 +00:00
Auxilor
35b060af53 Added ReflectionUtils to use Unsafe to set final fields 2021-01-23 19:38:06 +00:00
Auxilor
337dba23b4 Removed PacketPlayOutRecipeUpdateFix 2021-01-22 19:45:29 +00:00
Auxilor
433f9f53ab Revert "Revert "Changed the fix for PacketPlayOutRecipeUpdateFix""
This reverts commit 1365fdae
2021-01-22 19:29:46 +00:00
Auxilor
ba7a748efd Re-fixed the rework of the fix of the changed fix of the fix 2021-01-22 19:29:11 +00:00
Auxilor
1365fdae88 Revert "Changed the fix for PacketPlayOutRecipeUpdateFix"
This reverts commit 876343fa
2021-01-22 17:53:36 +00:00
Auxilor
6a159bf049 Changed PacketPlayOutRecipeUpdateFix 2021-01-22 10:29:05 +00:00
Auxilor
31e0e93951 Updated to 3.2.1 2021-01-21 08:38:38 +00:00
Auxilor
876343facb Changed the fix for PacketPlayOutRecipeUpdateFix 2021-01-21 08:38:28 +00:00
Auxilor
f0cd9ae16d Updated to 3.2.0 2021-01-20 20:13:09 +00:00
Auxilor
b220428b8c Added StaticBaseConfig, a non-updating config implementation 2021-01-20 20:12:53 +00:00
Auxilor
8386aacfd8 Updated to 3.1.3 2021-01-20 19:06:07 +00:00
Auxilor
3c54e24102 Reworked gradients 2021-01-20 19:05:55 +00:00
Auxilor
3dc0693b8c Reworked gradients 2021-01-20 18:47:56 +00:00
Auxilor
f087113ddf Updated to 3.1.2 2021-01-20 17:38:51 +00:00
Auxilor
d5d1f5d8cc Added fix for PacketPlayOutRecipeUpdate being too large 2021-01-20 17:35:29 +00:00
Auxilor
0d5bf901e2 Updated to 3.1.1 2021-01-20 11:27:57 +00:00
Auxilor
ae0445f47b Fixed recipe listener registration 2021-01-20 11:27:46 +00:00
Auxilor
a6ba24b7a5 Added auto version 2021-01-19 17:39:25 +00:00
Auxilor
1b00831147 Prevented duplicate module registration 2021-01-19 17:38:36 +00:00
Auxilor
479cff60d5 Fixed list emptiness java 2021-01-19 17:30:01 +00:00
Auxilor
d2499b1e27 Fixed artifact id name 2021-01-19 17:10:45 +00:00
Auxilor
4f65f33953 Reworked project structure 2021-01-19 17:02:04 +00:00
Auxilor
6d4a69c781 Removed debug message 2021-01-19 14:30:39 +00:00
Auxilor
e90e58b50a Moved event listeners 2021-01-19 14:29:09 +00:00
Auxilor
826bdb63d0 Removed pointless bukkit services 2021-01-19 14:07:48 +00:00
Auxilor
4ecba69161 Updated to 3.0.3 2021-01-19 13:59:21 +00:00
Auxilor
e64510ebf5 Fixed FastCollatedDropQueueRunnable 2021-01-19 13:58:57 +00:00
Auxilor
50a506af62 Added gradient support 2021-01-19 11:36:47 +00:00
Auxilor
bdbbb7e40a Added redundant config.yml and lang.yml 2021-01-18 09:50:24 +00:00
Auxilor
f2503e989c Made eco an AbstractEcoPlugin and updated to 3.0.1 2021-01-18 09:48:36 +00:00
Auxilor
11c54a0055 Finally fixed proxies 2021-01-17 15:52:40 +00:00
Auxilor
7cc24199fb Kept trying to fix proxy error. 2021-01-17 15:01:01 +00:00
Auxilor
068b2cca0c Removed getInstance method 2021-01-17 14:22:29 +00:00
Auxilor
f67f01278e Moved cached proxies into cached factories 2021-01-17 13:35:53 +00:00
Auxilor
8be8e1dab2 Fixed DropManager updatable 2021-01-17 12:45:08 +00:00
Auxilor
6d3651aca1 Fixed fields 2021-01-17 12:42:37 +00:00
Auxilor
3dd2c58595 Added loadbefore 2021-01-17 12:40:02 +00:00
Auxilor
255aa1dd54 Re-added RecipePartUtils 2021-01-17 11:51:48 +00:00
Auxilor
f2c5b085e8 Removed all getInstance calls 2021-01-17 11:37:58 +00:00
Auxilor
b8a5fe0031 Fixed EcoShapedRecipe 2021-01-17 10:48:55 +00:00
Auxilor
5603890663 Reworked eco to be a spigot plugin 2021-01-17 10:48:34 +00:00
Auxilor
1a86cc4dbd Fixed shading errors. 2021-01-14 20:06:27 +00:00
Auxilor
734add6dbc Cleaned 2021-01-14 19:25:21 +00:00
Auxilor
5641c0def3 Updated to 1.3.1 2021-01-14 19:24:37 +00:00
Auxilor
b74ab5349a Fixed shading issues 2021-01-14 19:24:13 +00:00
Auxilor
b0971e5124 Renamed LookupUtils to RecipePartUtils 2021-01-14 14:06:50 +00:00
Auxilor
02d8c8c6b6 Updated to 1.3.0 2021-01-14 13:06:32 +00:00
Auxilor
d9bd5257e3 Added custom item registry 2021-01-14 13:06:03 +00:00
Auxilor
c1a214f34e Fixed crafting 2021-01-14 11:31:05 +00:00
Auxilor
64d1fbb9b1 Updated to 1.2.0 2021-01-14 10:57:23 +00:00
Auxilor
a5433fbb3f Added recipe system 2021-01-14 10:55:44 +00:00
Auxilor
2a2aed52e0 Optimised VectorUtils getCircle() 2021-01-12 14:52:36 +00:00
Auxilor
b16266e22a Cleaned up numerals 2021-01-10 20:05:50 +00:00
Auxilor
2c886dc33b Updated to 1.1.2 2021-01-10 18:51:37 +00:00
Auxilor
db9c60cf35 Added fromNumeral method 2021-01-10 18:51:21 +00:00
Auxilor
a34b36daec Updated to 1.1.1 2021-01-08 22:18:17 +00:00
Auxilor
41a35e99fd Call update is now invoked twice 2021-01-08 22:18:00 +00:00
Auxilor
8e12dad247 Added players to packet adapters 2021-01-08 08:02:15 +00:00
Auxilor
72afa1e5cc Updated to 1.1.0 2021-01-08 08:01:21 +00:00
Auxilor
9904553325 Updated to 1.0.6 2021-01-05 14:17:41 +00:00
Auxilor
ad069ab32f Cleaned up loader 2021-01-05 14:17:26 +00:00
Auxilor
b83a3dd548 Fixed TelekinesisUtils and updated to 1.0.5 2021-01-05 09:09:05 +00:00
Auxilor
7f41eab5e4 Fixed compileOnly issues with jitpack 2021-01-04 12:46:00 +00:00
Auxilor
0d1c2364da Fixed telekinesistests registration and updated to 1.0.4 2021-01-04 12:45:05 +00:00
Auxilor
5bca33a9f5 Added protected getter for BaseConfig and updated to 1.0.3 2021-01-02 17:55:22 +00:00
Auxilor
1196fe8004 Updated to 1.0.2 2021-01-01 16:54:05 +00:00
Auxilor
98ae416fa7 Reduced loaded integration verbosity 2021-01-01 16:53:32 +00:00
175 changed files with 4226 additions and 968 deletions

2
.gitignore vendored
View File

@@ -14,7 +14,7 @@ bin/
# Gradle
.gradle
**/build/
!src/**/build/
!eco-util/src/**/build/
.gradletasknamecache
!gradle-wrapper.jar
gradle-app.setting

View File

@@ -6,31 +6,17 @@ plugins {
}
dependencies {
implementation 'org.apache.maven:maven-artifact:3.0.3'
implementation 'org.bstats:bstats-bukkit:1.7'
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
compileOnly 'me.clip:placeholderapi:2.10.9'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
compileOnly 'com.github.TechFortress:GriefPrevention:16.14.0'
compileOnly 'com.massivecraft:Factions:1.6.9.5-U0.5.10'
compileOnly 'com.github.cryptomorin:kingdoms:1.10.3.1'
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
compileOnly 'com.github.angeschossen:LandsAPI:4.7.3'
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
compileOnly 'org.jetbrains:annotations:19.0.0'
compileOnly fileTree(dir: '/lib', include: ['*.jar'])
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
implementation project(":eco-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 {
repositories {
mavenCentral()
jcenter()
mavenLocal()
@@ -39,7 +25,7 @@ repositories {
// NMS (for jitpack compilation)
maven { url 'https://repo.codemc.org/repository/nms/' }
// bStats
// bStats, mcMMO
maven { url 'https://repo.codemc.org/repository/maven-public' }
// Spigot API
@@ -59,44 +45,53 @@ repositories {
// NoCheatPlus
maven { url 'https://repo.md-5.net/content/repositories/snapshots/' }
}
}
tasks.withType(JavaCompile) {
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 {
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 {
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
}
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

View File

@@ -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
View File

@@ -0,0 +1,8 @@
group 'com.willfp'
version rootProject.version
subprojects {
dependencies {
compileOnly project(":eco-util")
}
}

View 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')
}
}

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT'
}

View File

@@ -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"));
}
}

View File

@@ -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()));
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
}

View File

@@ -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"));
}
}

View File

@@ -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()));
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT'
}

View File

@@ -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"));
}
}

View File

@@ -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()));
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
}

View File

@@ -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"));
}
}

View File

@@ -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()));
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}
}

View 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
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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;
});
}
}

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View 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

View File

@@ -0,0 +1,2 @@
group 'com.willfp'
version rootProject.version

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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
View 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'
}
}
}

View File

@@ -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;

View File

@@ -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.
*/

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.util.drops.internal;
package com.willfp.eco.internal.drops;
public enum DropQueueType {
/**

View File

@@ -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);
}
}
}

View File

@@ -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()) {

View File

@@ -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();
}

View File

@@ -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 {
/**
* 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;
}
}

View File

@@ -2,6 +2,7 @@ package com.willfp.eco.util;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.Player;
@@ -37,12 +38,20 @@ public class DurabilityUtils {
return;
}
if (!(item.getItemMeta() instanceof Damageable)) {
return;
}
// Special edge case
if (item.getType() == Material.CARVED_PUMPKIN || item.getType() == Material.PLAYER_HEAD) {
return;
}
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
Bukkit.getPluginManager().callEvent(event3);
if (!event3.isCancelled()) {
int damage2 = event3.getDamage();
if (item.getItemMeta() instanceof Damageable) {
Damageable meta = (Damageable) item.getItemMeta();
meta.setDamage(meta.getDamage() + damage2);
@@ -58,7 +67,6 @@ public class DurabilityUtils {
}
}
}
}
/**
* Damage an item in a player's inventory without breaking it.
@@ -78,12 +86,15 @@ public class DurabilityUtils {
return;
}
if (!(item.getItemMeta() instanceof Damageable)) {
return;
}
PlayerItemDamageEvent event3 = new PlayerItemDamageEvent(player, item, damage);
Bukkit.getPluginManager().callEvent(event3);
if (!event3.isCancelled()) {
int damage2 = event3.getDamage();
if (item.getItemMeta() instanceof Damageable) {
Damageable meta = (Damageable) item.getItemMeta();
meta.setDamage(meta.getDamage() + damage2);
@@ -93,7 +104,6 @@ public class DurabilityUtils {
item.setItemMeta((ItemMeta) meta);
}
}
}
/**
* Repair an item in a player's inventory.

View File

@@ -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.
*

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -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;
}
/**

View File

@@ -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