Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
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
Comment thread
DasBabyPixel marked this conversation as resolved.
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;
}
}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
eu.cloudnetservice.wrapper.transform.bukkit.BukkitCommodoreTransformer
eu.cloudnetservice.wrapper.transform.bukkit.BukkitJavaVersionCheckTransformer
eu.cloudnetservice.wrapper.transform.bukkit.PaperConfigTransformer
eu.cloudnetservice.wrapper.transform.bukkit.FAWEConfigTransformer
eu.cloudnetservice.wrapper.transform.bukkit.FAWEReflectionUtilsTransformer
eu.cloudnetservice.wrapper.transform.bukkit.WorldEditJava8DetectorTransformer
eu.cloudnetservice.wrapper.transform.bukkit.FAWEWorldEditDownloadURLTransformer
eu.cloudnetservice.wrapper.transform.minestom.MinestomStopCleanlyTransformer
eu.cloudnetservice.wrapper.transform.netty.OldEpollDisableTransformer