Pārlūkot izejas kodu

improve performance

MasterCake 3 gadi atpakaļ
vecāks
revīzija
a25696d0d3
1 mainītis faili ar 10 papildinājumiem un 3 dzēšanām
  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;