Remove Forge support as it was used only in 1.7

This commit is contained in:
filoghost 2018-08-21 00:12:00 +02:00
parent 4214b251cf
commit 6d095f8165
11 changed files with 61 additions and 175 deletions

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_10_R1.Entity;
import net.minecraft.server.v1_10_R1.EntityTypes;
import net.minecraft.server.v1_10_R1.MathHelper;
@ -42,15 +40,9 @@ public class NmsManagerImpl implements NMSManager {
validateEntityMethod.setAccessible(true);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
throw new UnsupportedOperationException("Forge based servers are not supported");
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
@Override

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_11_R1.Entity;
import net.minecraft.server.v1_11_R1.EntityTypes;
import net.minecraft.server.v1_11_R1.MathHelper;
@ -44,22 +42,18 @@ public class NmsManagerImpl implements NMSManager {
@SuppressWarnings("unchecked")
public void registerCustomEntity(Class<? extends Entity> entityClass, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
throw new UnsupportedOperationException("Forge based servers are not supported");
} else {
// Use reflection to get the RegistryID of entities.
RegistryID<Class<? extends Entity>> registryID = (RegistryID<Class<? extends Entity>>) ReflectionUtils.getPrivateField(RegistryMaterials.class, EntityTypes.b, "a");
Object[] idToClassMap = (Object[]) ReflectionUtils.getPrivateField(RegistryID.class, registryID, "d");
// Save the the ID -> entity class mapping before the registration.
Object oldValue = idToClassMap[id];
// Use reflection to get the RegistryID of entities.
RegistryID<Class<? extends Entity>> registryID = (RegistryID<Class<? extends Entity>>) ReflectionUtils.getPrivateField(RegistryMaterials.class, EntityTypes.b, "a");
Object[] idToClassMap = (Object[]) ReflectionUtils.getPrivateField(RegistryID.class, registryID, "d");
// Save the the ID -> entity class mapping before the registration.
Object oldValue = idToClassMap[id];
// Register the entity class.
registryID.a(entityClass, id);
// Register the entity class.
registryID.a(entityClass, id);
// Restore the ID -> entity class mapping.
idToClassMap[id] = oldValue;
}
// Restore the ID -> entity class mapping.
idToClassMap[id] = oldValue;
}
@Override

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityTypes;
import net.minecraft.server.v1_12_R1.MathHelper;
@ -44,22 +42,18 @@ public class NmsManagerImpl implements NMSManager {
@SuppressWarnings("unchecked")
public void registerCustomEntity(Class<? extends Entity> entityClass, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
throw new UnsupportedOperationException("Forge based servers are not supported");
} else {
// Use reflection to get the RegistryID of entities.
RegistryID<Class<? extends Entity>> registryID = (RegistryID<Class<? extends Entity>>) ReflectionUtils.getPrivateField(RegistryMaterials.class, EntityTypes.b, "a");
Object[] idToClassMap = (Object[]) ReflectionUtils.getPrivateField(RegistryID.class, registryID, "d");
// Save the the ID -> entity class mapping before the registration.
Object oldValue = idToClassMap[id];
// Use reflection to get the RegistryID of entities.
RegistryID<Class<? extends Entity>> registryID = (RegistryID<Class<? extends Entity>>) ReflectionUtils.getPrivateField(RegistryMaterials.class, EntityTypes.b, "a");
Object[] idToClassMap = (Object[]) ReflectionUtils.getPrivateField(RegistryID.class, registryID, "d");
// Save the the ID -> entity class mapping before the registration.
Object oldValue = idToClassMap[id];
// Register the entity class.
registryID.a(entityClass, id);
// Register the entity class.
registryID.a(entityClass, id);
// Restore the ID -> entity class mapping.
idToClassMap[id] = oldValue;
}
// Restore the ID -> entity class mapping.
idToClassMap[id] = oldValue;
}
@Override

View File

@ -21,8 +21,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_13_R1.Entity;
import net.minecraft.server.v1_13_R1.EntityTypes;
import net.minecraft.server.v1_13_R1.MathHelper;
@ -45,29 +43,25 @@ public class NmsManagerImpl implements NMSManager {
@SuppressWarnings("unchecked")
public void registerCustomEntity(Class<? extends Entity> entityClass, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
throw new UnsupportedOperationException("Forge based servers are not supported");
} else {
// Use reflection to get the RegistryID of entities.
RegistryID<EntityTypes<?>> registryID = (RegistryID<EntityTypes<?>>) ReflectionUtils.getPrivateField(RegistryMaterials.class, EntityTypes.REGISTRY, "a");
Object[] idToClassMap = (Object[]) ReflectionUtils.getPrivateField(RegistryID.class, registryID, "d");
// Use reflection to get the RegistryID of entities.
RegistryID<EntityTypes<?>> registryID = (RegistryID<EntityTypes<?>>) ReflectionUtils.getPrivateField(RegistryMaterials.class, EntityTypes.REGISTRY, "a");
Object[] idToClassMap = (Object[]) ReflectionUtils.getPrivateField(RegistryID.class, registryID, "d");
// Save the the ID -> EntityTypes mapping before the registration.
Object oldValue = idToClassMap[id];
// Register the EntityTypes object.
registryID.a(new EntityTypes<Entity>(entityClass, new Function<World, Entity>() {
@Override
public Entity apply(World world) {
return null;
}
// Save the the ID -> EntityTypes mapping before the registration.
Object oldValue = idToClassMap[id];
}, true, true, null), id);
// Register the EntityTypes object.
registryID.a(new EntityTypes<Entity>(entityClass, new Function<World, Entity>() {
@Override
public Entity apply(World world) {
return null;
}
}, true, true, null), id);
// Restore the ID -> EntityTypes mapping.
idToClassMap[id] = oldValue;
}
// Restore the ID -> EntityTypes mapping.
idToClassMap[id] = oldValue;
}
@Override

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_8_R1.Entity;
import net.minecraft.server.v1_8_R1.EntityTypes;
import net.minecraft.server.v1_8_R1.MathHelper;
@ -38,24 +36,13 @@ public class NmsManagerImpl implements NMSManager {
registerCustomEntity(EntityNMSItem.class, "Item", 1);
registerCustomEntity(EntityNMSSlime.class, "Slime", 55);
if (!VersionUtils.isForgeServer()) {
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
// Forge entity registration.
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_8_R1.EntityTypes");
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75624_e", entityClass, Integer.valueOf(id));
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
@Override

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_8_R2.Entity;
import net.minecraft.server.v1_8_R2.EntityTypes;
import net.minecraft.server.v1_8_R2.MathHelper;
@ -38,24 +36,13 @@ public class NmsManagerImpl implements NMSManager {
registerCustomEntity(EntityNMSItem.class, "Item", 1);
registerCustomEntity(EntityNMSSlime.class, "Slime", 55);
if (!VersionUtils.isForgeServer()) {
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
// Forge entity registration.
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_8_R2.EntityTypes");
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75624_e", entityClass, Integer.valueOf(id));
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
@Override

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_8_R3.Entity;
import net.minecraft.server.v1_8_R3.EntityTypes;
import net.minecraft.server.v1_8_R3.MathHelper;
@ -38,24 +36,13 @@ public class NmsManagerImpl implements NMSManager {
registerCustomEntity(EntityNMSItem.class, "Item", 1);
registerCustomEntity(EntityNMSSlime.class, "Slime", 55);
if (!VersionUtils.isForgeServer()) {
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
validateEntityMethod = World.class.getDeclaredMethod("a", Entity.class);
validateEntityMethod.setAccessible(true);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
// Forge entity registration.
Class<?> entityTypesClass = Class.forName("net.minecraft.server.v1_8_R3.EntityTypes");
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75626_c", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(entityTypesClass, "field_75624_e", entityClass, Integer.valueOf(id));
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
@Override

View File

@ -19,7 +19,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_9_R1.Entity;
import net.minecraft.server.v1_9_R1.EntityTypes;
@ -41,15 +40,9 @@ public class NmsManagerImpl implements NMSManager {
validateEntityMethod.setAccessible(true);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
throw new UnsupportedOperationException("Forge based servers are not supported");
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
@Override

View File

@ -20,8 +20,6 @@ import com.gmail.filoghost.holographicdisplays.nms.interfaces.entity.NMSItem;
import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
import com.gmail.filoghost.holographicdisplays.util.ReflectionUtils;
import com.gmail.filoghost.holographicdisplays.util.Validator;
import com.gmail.filoghost.holographicdisplays.util.VersionUtils;
import net.minecraft.server.v1_9_R2.Entity;
import net.minecraft.server.v1_9_R2.EntityTypes;
import net.minecraft.server.v1_9_R2.MathHelper;
@ -42,15 +40,9 @@ public class NmsManagerImpl implements NMSManager {
validateEntityMethod.setAccessible(true);
}
@SuppressWarnings("rawtypes")
public void registerCustomEntity(Class entityClass, String name, int id) throws Exception {
if (VersionUtils.isForgeServer()) {
throw new UnsupportedOperationException("Forge based servers are not supported");
} else {
// Normal entity registration.
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
public void registerCustomEntity(Class<?> entityClass, String name, int id) throws Exception {
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "d", entityClass, name);
ReflectionUtils.putInPrivateStaticMap(EntityTypes.class, "f", entityClass, Integer.valueOf(id));
}
@Override

View File

@ -111,16 +111,7 @@ public class HolographicDisplays extends JavaPlugin {
}
try {
if (VersionUtils.isForgeServer()) {
getLogger().info("Trying to enable Forge support...");
}
nmsManager.setup();
if (VersionUtils.isForgeServer()) {
getLogger().info("Successfully added Forge support!");
}
} catch (Exception e) {
e.printStackTrace();
printWarnAndDisable(

View File

@ -21,31 +21,6 @@ public class VersionUtils {
}
}
/**
* This method uses a regex to get the version of this Minecraft release.
* Example: 1.8.1
* @return the version of this release or null if not found.
*/
public static String extractMinecraftVersion() {
Matcher matcher = Pattern.compile("(\\(MC: )([\\d\\.]+)(\\))").matcher(Bukkit.getVersion());
if (matcher.find()) {
return matcher.group(2);
} else {
return null;
}
}
/**
* @return if the server is based on Forge.
*/
public static boolean isForgeServer() {
try {
Class.forName("net.minecraftforge.common.MinecraftForge");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
/**
* @return 1 if reference > comparison, 0 if reference == comparison, -1 if reference < comparison