Explorar o código

improve performance

MasterCake %!s(int64=3) %!d(string=hai) anos
pai
achega
a25696d0d3
Modificáronse 1 ficheiros con 10 adicións e 3 borrados
  1. 10 3
      src/main/java/xyz/spaceio/customoregen/Events.java

+ 10 - 3
src/main/java/xyz/spaceio/customoregen/Events.java

@@ -26,6 +26,7 @@ public class Events implements Listener {
 	private CustomOreGen plugin;
 	
 	private boolean useLegacyBlockPlaceMethod;
+	private boolean useLevelledClass;
 	private Method legacyBlockPlaceMethod;
 	
 	private boolean enableStoneGenerator;
@@ -46,6 +47,13 @@ public class Events implements Listener {
 			}
 		}
 		this.enableStoneGenerator = plugin.getConfig().getBoolean("enable-stone-generator");
+		
+		try {
+			Class.forName("org.bukkit.block.data.Levelled");
+			useLevelledClass = true;
+		} catch( ClassNotFoundException e ) {
+			useLevelledClass = false;
+		}
 	}
 
 	@SuppressWarnings("deprecation")
@@ -161,8 +169,7 @@ public class Events implements Listener {
 	}
 	
 	public Type getType(Block b) {
-		try {
-			Class.forName("org.bukkit.block.data.Levelled");
+		if(useLevelledClass) {
 			if(b.getBlockData() != null && b.getBlockData() instanceof org.bukkit.block.data.Levelled) {
 				org.bukkit.block.data.Levelled level = (org.bukkit.block.data.Levelled) b.getBlockData();
 				if(level.getLevel() == 0) {
@@ -179,7 +186,7 @@ public class Events implements Listener {
 					}
 				}
 			}
-		} catch( ClassNotFoundException e ) {
+		} else {
 			switch(b.getType().name()) {
 				case "WATER":
 					return Type.WATER;