mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-09-07 13:08:19 +02:00
Fixes #58
This commit is contained in:
parent
f3c03a9c24
commit
1a41b4bd0d
@ -128,7 +128,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && 158 < element.getLineNumber() && element.getLineNumber() < 168) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && 158 < element.getLineNumber() && element.getLineNumber() < 168) {
|
||||||
// Then this method is being called when creating a new movement packet, we return a fake ID!
|
// Then this method is being called when creating a new movement packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && 158 < element.getLineNumber() && element.getLineNumber() < 168) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && 158 < element.getLineNumber() && element.getLineNumber() < 168) {
|
||||||
// Then this method is being called when creating a new movement packet, we return a fake ID!
|
// Then this method is being called when creating a new movement packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
// Dirty method to check if the icon is being picked up
|
// Dirty method to check if the icon is being picked up
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getClassName().contains("EntityInsentient")) {
|
if (element != null && element.getFileName() != null && element.getClassName().contains("EntityInsentient")) {
|
||||||
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class EntityNMSWitherSkull extends EntityWitherSkull implements NMSWither
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
// Dirty method to check if the icon is being picked up
|
// Dirty method to check if the icon is being picked up
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getClassName().contains("EntityInsentient")) {
|
if (element != null && element.getFileName() != null && element.getClassName().contains("EntityInsentient")) {
|
||||||
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class EntityNMSWitherSkull extends EntityWitherSkull implements NMSWither
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
// Dirty method to check if the icon is being picked up
|
// Dirty method to check if the icon is being picked up
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getClassName().contains("EntityInsentient")) {
|
if (element != null && element.getFileName() != null && element.getClassName().contains("EntityInsentient")) {
|
||||||
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class EntityNMSWitherSkull extends EntityWitherSkull implements NMSWither
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
|
|||||||
public ItemStack getItemStack() {
|
public ItemStack getItemStack() {
|
||||||
// Dirty method to check if the icon is being picked up
|
// Dirty method to check if the icon is being picked up
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getClassName().contains("EntityInsentient")) {
|
if (element != null && element.getFileName() != null && element.getClassName().contains("EntityInsentient")) {
|
||||||
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
return null; // Try to pickup this, dear entity ignoring the pickupDelay!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class EntityNMSWitherSkull extends EntityWitherSkull implements NMSWither
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 134 && element.getLineNumber() < 144) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 137 && element.getLineNumber() < 147) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 142 && element.getLineNumber() < 152) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 142 && element.getLineNumber() < 152) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
|
|||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
StackTraceElement element = ReflectionUtils.getStackTraceElement(2);
|
||||||
if (element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 142 && element.getLineNumber() < 152) {
|
if (element != null && element.getFileName() != null && element.getFileName().equals("EntityTrackerEntry.java") && element.getLineNumber() > 142 && element.getLineNumber() < 152) {
|
||||||
// Then this method is being called when creating a new packet, we return a fake ID!
|
// Then this method is being called when creating a new packet, we return a fake ID!
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@ package com.gmail.filoghost.holographicdisplays.util;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import com.gmail.filoghost.holographicdisplays.HolographicDisplays;
|
||||||
|
|
||||||
public class ReflectionUtils {
|
public class ReflectionUtils {
|
||||||
|
|
||||||
private static Method getStackTraceElementMethod;
|
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public static void putInPrivateStaticMap(Class<?> clazz, String fieldName, Object key, Object value) throws Exception {
|
public static void putInPrivateStaticMap(Class<?> clazz, String fieldName, Object key, Object value) throws Exception {
|
||||||
@ -28,6 +29,11 @@ public class ReflectionUtils {
|
|||||||
return field.get(handle);
|
return field.get(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Method getStackTraceElementMethod;
|
||||||
|
private static Method getStackTraceDepthMethod;
|
||||||
|
|
||||||
|
private static boolean stackTraceErrorPrinted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If you only need one stack trace element this is faster than Throwable.getStackTrace()[element],
|
* If you only need one stack trace element this is faster than Throwable.getStackTrace()[element],
|
||||||
* it doesn't generate the full stack trace.
|
* it doesn't generate the full stack trace.
|
||||||
@ -38,11 +44,25 @@ public class ReflectionUtils {
|
|||||||
getStackTraceElementMethod = Throwable.class.getDeclaredMethod("getStackTraceElement", int.class);
|
getStackTraceElementMethod = Throwable.class.getDeclaredMethod("getStackTraceElement", int.class);
|
||||||
getStackTraceElementMethod.setAccessible(true);
|
getStackTraceElementMethod.setAccessible(true);
|
||||||
}
|
}
|
||||||
|
if (getStackTraceDepthMethod == null) {
|
||||||
|
getStackTraceDepthMethod = Throwable.class.getDeclaredMethod("getStackTraceDepth");
|
||||||
|
getStackTraceDepthMethod.setAccessible(true);
|
||||||
|
}
|
||||||
|
|
||||||
return (StackTraceElement) getStackTraceElementMethod.invoke(new Throwable(), index);
|
Throwable dummyThrowable = new Throwable();
|
||||||
} catch (Exception e) {
|
int depth = (Integer) getStackTraceDepthMethod.invoke(dummyThrowable);
|
||||||
// Fallback
|
|
||||||
return new Throwable().getStackTrace()[index];
|
if (index < depth) {
|
||||||
|
return (StackTraceElement) getStackTraceElementMethod.invoke(new Throwable(), index);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (!stackTraceErrorPrinted) {
|
||||||
|
HolographicDisplays.getInstance().getLogger().log(Level.WARNING, "Unable to get a stacktrace element, please inform the developer. You will only see this error once to avoid spam.", t);
|
||||||
|
stackTraceErrorPrinted = true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user