Repository navigation
WorldEdit transformers for 1.8.8 + give more control to transformers (wrapper) #1429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0utplay
merged 3 commits into
CloudNetService:nightly
from
DasBabyPixel:fix/classtransformer
Jul 15, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
...-jvm/src/main/java/eu/cloudnetservice/wrapper/transform/bukkit/FAWEConfigTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Copyright 2019-2024 CloudNetService team & contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package eu.cloudnetservice.wrapper.transform.bukkit; | ||
|
|
||
| import eu.cloudnetservice.wrapper.transform.ClassTransformer; | ||
| import java.lang.classfile.ClassTransform; | ||
| import java.lang.classfile.CodeTransform; | ||
| import lombok.NonNull; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * A transformer implementation that disables the {@code setAccessible} method in the FAWE Config on old FAWE versions. | ||
| * This is due to the fact that the method uses illegal reflection in the attempt to set a final field which is not | ||
| * possible anymore on newer java versions. | ||
| */ | ||
| @ApiStatus.Internal | ||
| public final class FAWEConfigTransformer implements ClassTransformer { | ||
|
|
||
| private static final String CNI_CONFIG = "com/boydti/fawe/config/Config"; | ||
| private static final String MN_SET_ACCESSIBLE = "setAccessible"; | ||
|
|
||
| /** | ||
| * Constructs a new instance of this transformer, usually done via SPI. | ||
| */ | ||
| public FAWEConfigTransformer() { | ||
| // used by SPI | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull ClassTransform provideClassTransform() { | ||
| CodeTransform codeTransform = (builder, _) -> builder.return_(); | ||
| return ClassTransform.transformingMethodBodies( | ||
| mm -> mm.methodName().equalsString(MN_SET_ACCESSIBLE), | ||
| codeTransform); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull TransformWillingness classTransformWillingness(@NonNull String internalClassName) { | ||
| var isFaweConfig = CNI_CONFIG.equals(internalClassName); | ||
| return isFaweConfig ? TransformWillingness.ACCEPT_ONCE : TransformWillingness.REJECT; | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
...main/java/eu/cloudnetservice/wrapper/transform/bukkit/FAWEReflectionUtilsTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Copyright 2019-2024 CloudNetService team & contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package eu.cloudnetservice.wrapper.transform.bukkit; | ||
|
|
||
| import eu.cloudnetservice.wrapper.transform.ClassTransformer; | ||
| import java.lang.classfile.ClassTransform; | ||
| import java.lang.classfile.CodeTransform; | ||
| import java.lang.constant.ClassDesc; | ||
| import java.lang.constant.ConstantDescs; | ||
| import java.lang.constant.MethodTypeDesc; | ||
| import java.lang.reflect.Field; | ||
| import lombok.NonNull; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * A transformer implementation that rewrites the {@code setFailsafeFieldValue} method in the {@code ReflectionUtils} | ||
| * class on old FAWE versions. This is due to the fact that the method uses illegal reflection in the attempt to set a final field which is | ||
| * not possible anymore on newer java versions. | ||
| */ | ||
| @ApiStatus.Internal | ||
| public final class FAWEReflectionUtilsTransformer implements ClassTransformer { | ||
|
|
||
| private static final String CNI_REFLECTION_UTILS = "com/boydti/fawe/util/ReflectionUtils"; | ||
| private static final String MN_SET_FAILSAFE_FIELD_VALUE = "setFailsafeFieldValue"; | ||
| private static final ClassDesc CD_FIELD = ClassDesc.of(Field.class.getName()); | ||
| private static final String MN_FIELD_SET_ACCESSIBLE = "setAccessible"; | ||
| private static final MethodTypeDesc MTD_SET_ACCESSIBLE = MethodTypeDesc.of(ConstantDescs.CD_void, | ||
| ConstantDescs.CD_boolean); | ||
| private static final String MN_FIELD_SET = "set"; | ||
| private static final MethodTypeDesc MTD_SET = MethodTypeDesc.of(ConstantDescs.CD_void, ConstantDescs.CD_Object, | ||
| ConstantDescs.CD_Object); | ||
|
|
||
| /** | ||
| * Constructs a new instance of this transformer, usually done via SPI. | ||
| */ | ||
| public FAWEReflectionUtilsTransformer() { | ||
| // used by SPI | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull ClassTransform provideClassTransform() { | ||
| CodeTransform codeTransform = (builder, _) -> { | ||
| // field.setAccessible(true); | ||
| builder.aload(0).iconst_1(); | ||
| builder.invokevirtual(CD_FIELD, MN_FIELD_SET_ACCESSIBLE, MTD_SET_ACCESSIBLE); | ||
|
|
||
| // field.set(instance, value); | ||
| builder.aload(0).aload(1).aload(2); | ||
| builder.invokevirtual(CD_FIELD, MN_FIELD_SET, MTD_SET); | ||
|
|
||
| // return; | ||
| builder.return_(); | ||
| }; | ||
| return ClassTransform.transformingMethodBodies( | ||
| mm -> mm.methodName().equalsString(MN_SET_FAILSAFE_FIELD_VALUE), | ||
| codeTransform); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull TransformWillingness classTransformWillingness(@NonNull String internalClassName) { | ||
| var isFaweReflectionUtils = internalClassName.equals(CNI_REFLECTION_UTILS); | ||
| return isFaweReflectionUtils ? TransformWillingness.ACCEPT_ONCE : TransformWillingness.REJECT; | ||
| } | ||
| } | ||
72 changes: 72 additions & 0 deletions
72
...java/eu/cloudnetservice/wrapper/transform/bukkit/FAWEWorldEditDownloadURLTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright 2019-2024 CloudNetService team & contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package eu.cloudnetservice.wrapper.transform.bukkit; | ||
|
|
||
| import eu.cloudnetservice.wrapper.transform.ClassTransformer; | ||
| import java.lang.classfile.ClassTransform; | ||
| import java.lang.classfile.CodeTransform; | ||
| import java.lang.classfile.instruction.ConstantInstruction; | ||
| import java.lang.constant.ConstantDescs; | ||
| import lombok.NonNull; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * A transformer implementation that allows FAWEs automatic downloading of WorldEdit on older versions. The URL has | ||
| * changed a while ago, this updates the download URL to work again. | ||
| */ | ||
| @ApiStatus.Internal | ||
| public final class FAWEWorldEditDownloadURLTransformer implements ClassTransformer { | ||
|
|
||
| private static final String OLD_DOWNLOAD_URL = "https://addons.cursecdn.com/files/2431/372/worldedit-bukkit-6.1.7.2.jar"; | ||
| private static final String NEW_DOWNLOAD_URL = "https://mediafilez.forgecdn.net/files/2431/372/worldedit-bukkit-6.1.7.2.jar"; | ||
| private static final String CNI_JARS = "com/boydti/fawe/util/Jars"; | ||
|
|
||
| /** | ||
| * Constructs a new instance of this transformer, usually done via SPI. | ||
| */ | ||
| public FAWEWorldEditDownloadURLTransformer() { | ||
| // used by SPI | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull ClassTransform provideClassTransform() { | ||
| CodeTransform codeTransform = (builder, element) -> { | ||
| if (element instanceof ConstantInstruction.LoadConstantInstruction inst | ||
| && inst.constantValue() instanceof String string | ||
| && string.equals(OLD_DOWNLOAD_URL)) { | ||
| builder.ldc(NEW_DOWNLOAD_URL); | ||
| return; | ||
| } | ||
| builder.with(element); | ||
| }; | ||
| return ClassTransform.transformingMethodBodies( | ||
| mm -> mm.methodName().equalsString(ConstantDescs.CLASS_INIT_NAME), | ||
| codeTransform); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull TransformWillingness classTransformWillingness(@NonNull String internalClassName) { | ||
| var isJars = internalClassName.equals(CNI_JARS); | ||
| return isJars ? TransformWillingness.ACCEPT_ONCE : TransformWillingness.REJECT; | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
...n/java/eu/cloudnetservice/wrapper/transform/bukkit/WorldEditJava8DetectorTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright 2019-2024 CloudNetService team & contributors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package eu.cloudnetservice.wrapper.transform.bukkit; | ||
|
|
||
| import eu.cloudnetservice.wrapper.transform.ClassTransformer; | ||
| import java.lang.classfile.ClassTransform; | ||
| import java.lang.classfile.CodeTransform; | ||
| import lombok.NonNull; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * A transformer implementation that disables warnings produced by WorldEdit on older versions if the java version is | ||
| * not Java 8. | ||
| */ | ||
| @ApiStatus.Internal | ||
| public final class WorldEditJava8DetectorTransformer implements ClassTransformer { | ||
|
|
||
| private static final String CN_JAVA_8_DETECTOR = "com/sk89q/worldedit/util/Java8Detector"; | ||
| private static final String MN_NOTIFY_IF_NOT_8 = "notifyIfNot8"; | ||
|
|
||
| /** | ||
| * Constructs a new instance of this transformer, usually done via SPI. | ||
| */ | ||
| public WorldEditJava8DetectorTransformer() { | ||
| // used by SPI | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull ClassTransform provideClassTransform() { | ||
| CodeTransform codeTransform = (builder, _) -> builder.return_(); | ||
| return ClassTransform.transformingMethodBodies( | ||
| mm -> mm.methodName().equalsString(MN_NOTIFY_IF_NOT_8), | ||
| codeTransform); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public @NonNull TransformWillingness classTransformWillingness(@NonNull String internalClassName) { | ||
| var isJava8Detector = internalClassName.equals(CN_JAVA_8_DETECTOR); | ||
| return isJava8Detector ? TransformWillingness.ACCEPT_ONCE : TransformWillingness.REJECT; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.