Browse Source

fixed bug on 1.12

MasterCake 5 years ago
parent
commit
bd4f7d8457
3 changed files with 16 additions and 7 deletions
  1. 1 1
      pom.xml
  2. 15 5
      src/xyz/spaceio/customoregen/Events.java
  3. 0 1
      src/xyz/spaceio/hooks/SkyblockAPICached.java

+ 1 - 1
pom.xml

@@ -4,7 +4,7 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>xyz.spaceio</groupId>
 	<artifactId>CustomOreGen</artifactId>
-	<version>1.3.19-SNAPSHOT</version>
+	<version>1.3.21-SNAPSHOT</version>
 	<repositories>
 		<!-- Spigot repository -->
 		<repository>

+ 15 - 5
src/xyz/spaceio/customoregen/Events.java

@@ -1,6 +1,7 @@
 package xyz.spaceio.customoregen;
 
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Random;
 
@@ -25,10 +26,19 @@ public class Events implements Listener {
 	private CustomOreGen plugin;
 	
 	private boolean useLegacyBlockPlaceMethod;
+	private Method legacyBlockPlaceMethod;
 	
 	public Events(CustomOreGen customOreGen) {
 		this.plugin = customOreGen;
-		this.useLegacyBlockPlaceMethod = Arrays.stream(Block.class.getMethods()).anyMatch(method -> method.getName() == "getTypeId");
+		this.useLegacyBlockPlaceMethod = Arrays.stream(Block.class.getMethods()).anyMatch(method -> method.getName() == "setTypeIdAndData");
+		if(this.useLegacyBlockPlaceMethod) {
+			try {
+				legacyBlockPlaceMethod = Block.class.getMethod("setTypeIdAndData", int.class , byte.class, boolean.class);
+			} catch (NoSuchMethodException | SecurityException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
 	}
 
 	@SuppressWarnings("deprecation")
@@ -75,13 +85,13 @@ public class Events implements Listener {
 				// <Block>.setData(...) is deprecated, but there is no
 				// alternative to it. #spigot
 				if(useLegacyBlockPlaceMethod) {
-					 try {
-						b.getClass().getMethod("setTypeIdAndData", Material.class, byte.class, boolean.class).invoke(b, Material.getMaterial(winning.getName()).getId() , winning.getDamage(), true);
-					} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
-							| NoSuchMethodException | SecurityException e) {
+					try {
+						legacyBlockPlaceMethod.invoke(b, Material.getMaterial(winning.getName()).getId() , winning.getDamage(), true);
+					} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
 						// TODO Auto-generated catch block
 						e.printStackTrace();
 					}
+	
 				}else {
 					Bukkit.getScheduler().runTask(plugin, () -> {
 						b.setType(Material.getMaterial(winning.getName()));

+ 0 - 1
src/xyz/spaceio/hooks/SkyblockAPICached.java

@@ -1,6 +1,5 @@
 package xyz.spaceio.hooks;
 
-import java.util.Map;
 import java.util.Optional;
 import java.util.UUID;
 import java.util.Map.Entry;