Skip to content

Commit

Permalink
Fix excesive logs for checking if block is a tile entity
Browse files Browse the repository at this point in the history
  • Loading branch information
SBPrime committed Jan 17, 2022
1 parent fed7a77 commit 065d472
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 52 deletions.
4 changes: 2 additions & 2 deletions AsyncWorldEdit-API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
4 changes: 2 additions & 2 deletions AsyncWorldEdit-APIInner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
<dependency>
<groupId>org.primesoft.asyncworldedit</groupId>
Expand Down
4 changes: 2 additions & 2 deletions AsyncWorldEdit-BlocksHub_v3x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-Utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_10_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_11_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_12_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_12_R1_12_1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_8_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_9_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit-spigot_v1_9_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions AsyncWorldEdit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.0.0, 3.0.0)</version>
<version>[2.17.0, 3.0.0)</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down Expand Up @@ -176,7 +176,7 @@
<version>7.3.0</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
Expand All @@ -66,7 +67,8 @@
public final class TileEntityUtils {

private final static Map<Material, Boolean> m_isTileEntity;
public static final String TILE_ENTITY = "net.minecraft.world.level.block.BlockTileEntity";
private static final String TILE_ENTITY = "net.minecraft.world.level.block.BlockTileEntity";
private static final String BLOCK = "net.minecraft.world.level.block.Block";

private TileEntityUtils() {
}
Expand All @@ -88,22 +90,19 @@ private static Map<Material, Boolean> cacheMaterials() {
Method iBlockData_getBlock = null;
Method block_isTileEntity = null;

boolean getStateLog = true;
boolean getBlockLog = true;

final Map<Material, Boolean> result = new HashMap<>();
for (Material m : Material.values()) {
for (Material material : Material.values()) {
boolean isTilleEntity = false;
if (m.isBlock() && !m.isLegacy()) {
BlockData bd;
try {
bd = m.createBlockData();
} catch (Exception ex) {
ExceptionHelper.printException(ex, "Unable to create block data for '" + m + "'.");
bd = null;
}

if (material.isBlock() && !material.isLegacy()) {
final BlockData bd = getBlockData(material);
Object blockDataState = null;
if (bd != null) {
if (blockData_getState == null) {
blockData_getState = findMethod(bd.getClass(), "getState", true);
blockData_getState = findMethod(bd.getClass(), "getState", getStateLog);
getStateLog = false;
}

blockDataState = blockData_getState != null ? Reflection.invoke(bd, Object.class, blockData_getState, "Unable to get block state") : null;
Expand All @@ -112,7 +111,11 @@ private static Map<Material, Boolean> cacheMaterials() {
Object nmsBlock = null;
if (blockDataState != null) {
if (iBlockData_getBlock == null) {
iBlockData_getBlock = findMethod(blockDataState.getClass(), "getBlock", true);
iBlockData_getBlock = findMethod(blockDataState.getClass(),
m -> m.getName().equals("getBlock") || m.getReturnType().getName().equals(BLOCK));
if (iBlockData_getBlock == null) {
LoggerProvider.log("Unable to find getBlock in '" + blockDataState.getClass().getName() + "'");
}
}

nmsBlock = iBlockData_getBlock != null ? Reflection.invoke(blockDataState, Object.class, iBlockData_getBlock, "Unable to get NMS block") : null;
Expand All @@ -132,12 +135,23 @@ private static Map<Material, Boolean> cacheMaterials() {
}
}

result.put(m, isTilleEntity);
result.put(material, isTilleEntity);
}

return Collections.unmodifiableMap(result);
}

private static BlockData getBlockData(final Material material) {
BlockData bd;
try {
bd = material.createBlockData();
} catch (Exception ex) {
ExceptionHelper.printException(ex, "Unable to create block data for '" + material + "'.");
bd = null;
}
return bd;
}

private static boolean classExtends(
Class<?> cls,
final String className) {
Expand All @@ -158,12 +172,25 @@ private static Method findMethod(
final String name,
boolean log) {

Method result = findMethod(orgCls, m -> m.getName().equals(name));

if (result == null && log) {
LoggerProvider.log("Unable to find '" + name + "' in '" + (orgCls == null ? "null" : orgCls.getName()) + "'");
}

return result;
}

private static Method findMethod(
final Class<?> orgCls,
final Predicate<Method> filter) {

Class<?> cls = orgCls;
Method result = null;
while (cls != null && !Object.class.equals(cls) && result == null) {
Optional<Method> method = Stream.of(cls.getMethods())
.filter(i -> i.getName().equals(name))
.filter(i -> i.getParameterCount() == 0)
.filter(filter)
.findFirst();

cls = cls.getSuperclass();
Expand All @@ -172,11 +199,7 @@ private static Method findMethod(
result = method.get();
}
}

if (result == null && log) {
LoggerProvider.log("Unable to find '" + name + "' in '" + (orgCls == null ? "null" : orgCls.getName()) + "'");
}

return result;
}

}
8 changes: 4 additions & 4 deletions AsyncWorldEditInjector/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.0.0, 3.0.0)</version>
<version>[2.17.0, 3.0.0)</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -60,7 +60,7 @@
<dependency>
<groupId>org.primesoft.asyncworldedit</groupId>
<artifactId>AsyncWorldEdit-Utils</artifactId>
<version>3.9.3</version>
<version>3.9.4</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -78,9 +78,9 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
Expand Down
6 changes: 3 additions & 3 deletions AsyncWorldEditInjector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId>
<version>7.2.0</version>
<version>7.2.8</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8-SNAPSHOT-6004.jar</systemPath>
<systemPath>${project.basedir}/../libs/worldedit/worldedit-bukkit-7.2.8.jar</systemPath>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
Expand All @@ -75,7 +75,7 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>[2.0.0, 3.0.0)</version>
<version>[2.17.0, 3.0.0)</version>
<type>jar</type>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>AsyncWorldEdit_AllInOne</artifactId>
<version>${global.awe.version}</version>
<properties>
<global.awe.version>3.9.3</global.awe.version>
<global.awe.version>3.9.4</global.awe.version>
<global.awe-api.version>3.9.0</global.awe-api.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit 065d472

Please sign in to comment.