Browse Source

Refactor cobble generation detection to resolve a bug when lava is poured over water replacing the air blocks above the water instead of the water, detection now fallsback on mc code to determine whether cobble/stone would generate and is in turn a lot cleaner than before. Also bumped version and tested askyblock on 1.12.2 with no issues.

dblosevn 6 years ago
parent
commit
b5cf527bcc
3 changed files with 41 additions and 73 deletions
  1. 1 1
      README.md
  2. 39 71
      src/de/Linus122/customoregen/Events.java
  3. 1 1
      src/plugin.yml

+ 1 - 1
README.md

@@ -1,5 +1,5 @@
 # CustomOreGen
-Spigot 1.7 - 1.11
+Spigot 1.7 - 1.12
 
 Just a tiny plugin for customizing the default ore generator of minecraft.
 

+ 39 - 71
src/de/Linus122/customoregen/Events.java

@@ -1,74 +1,66 @@
 package de.Linus122.customoregen;
 
-import java.util.AbstractMap;
 import java.util.Random;
-import java.util.Map.Entry;
-
 import org.bukkit.Material;
 import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
 import org.bukkit.entity.Player;
 import org.bukkit.event.EventHandler;
 import org.bukkit.event.Listener;
-import org.bukkit.event.block.BlockFromToEvent;
+import org.bukkit.event.block.BlockFormEvent;
 
 public class Events implements Listener {
+	@SuppressWarnings("deprecation")
 	@EventHandler
-	public void onFromTo(BlockFromToEvent event) {
+	public void onCobbleGen(BlockFormEvent event) {
 		if (Main.disabledWorlds.contains(event.getBlock().getLocation().getWorld().getName())) {
 			return;
 		}
-		// System.out.println("From: " + event.getBlock().getType().name());
-		// System.out.println("To: " + event.getToBlock().getType().name());
-		// System.out.println("Face: " + event.getFace().name());
-
-		int id = event.getBlock().getTypeId();
-		if ((id >= 8) && (id <= 11)) {
-			Block b = event.getToBlock();
-			Entry<Boolean, Boolean> e = generatesCobble(id, b);
-			boolean generatesCobble = e.getKey();
-			boolean stoneGen = e.getValue();
 
-			int toid = b.getTypeId();
-			if ((toid == 0) && (generatesCobble)) {
-				GeneratorConfig gc = null;
+		Material newBlock = event.getNewState().getType();
+		Block b = event.getBlock();
+		
+		//System.out.println("From: " + event.getBlock().getType().name());
+		//System.out.println("To: " + newBlock.name());
+		
+		if (newBlock.equals(Material.COBBLESTONE) || newBlock.equals(Material.STONE)) {
+			GeneratorConfig gc = null;
 
-				Player p = Main.getOwner(b.getLocation());
-				if (p == null) {
-					gc = Main.generatorConfigs.get(0);
-				} else {
-					int islandLevel = Main.getLevel(p);
+			Player p = Main.getOwner(b.getLocation());
+			if (p == null) {
+				gc = Main.generatorConfigs.get(0);
+			} else {
+				int islandLevel = Main.getLevel(p);
 
-					if (Main.activeInWorld.getName().equals(b.getWorld().getName())) {
-						for (GeneratorConfig gc2 : Main.generatorConfigs) {
-							if (gc2 == null) {
-								continue;
-							}
-
-							if (p.hasPermission(gc2.permission) && islandLevel >= gc2.unlock_islandLevel) {
-								// Weiter
-								gc = gc2;
-							}
+				if (Main.activeInWorld.getName().equals(b.getWorld().getName())) {
+					for (GeneratorConfig gc2 : Main.generatorConfigs) {
+						if (gc2 == null) {
+							continue;
+						}
 
+						if (p.hasPermission(gc2.permission) && islandLevel >= gc2.unlock_islandLevel) {
+							// Weiter
+							gc = gc2;
 						}
+
 					}
 				}
-				if (gc == null)
-					return;
-				if (getObject(gc) == null)
-					return;
-				GeneratorItem winning = getObject(gc);
-				if (Material.getMaterial(winning.name) == null)
-					return;
-				// b.setType(Material.getMaterial(winning));
-				if (Material.getMaterial(winning.name).equals(Material.COBBLESTONE) && winning.damage == 0
-						&& stoneGen) {
-					return;
-				}
-				b.setTypeIdAndData(Material.getMaterial(winning.name).getId(), winning.damage, true);
 			}
+			if (gc == null)
+				return;
+			if (getObject(gc) == null)
+				return;
+			GeneratorItem winning = getObject(gc);
+			if (Material.getMaterial(winning.name) == null)
+				return;
+
+			if (Material.getMaterial(winning.name).equals(Material.COBBLESTONE) && winning.damage == 0) {
+				return;
+			}
+			event.setCancelled(true);
+			b.setTypeIdAndData(Material.getMaterial(winning.name).getId(), winning.damage, true);
 		}
 	}
+	
 
 	public GeneratorItem getObject(GeneratorConfig gc) {
 
@@ -80,28 +72,4 @@ public class Events implements Listener {
 		}
 		return new GeneratorItem("COBBLESTONE", (byte) 0, 0); // DEFAULT
 	}
-
-	private final BlockFace[] faces = { BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST,
-			BlockFace.SOUTH, BlockFace.WEST };
-
-	@SuppressWarnings("deprecation")
-	public Entry<Boolean, Boolean> generatesCobble(int id, Block b) {
-		int mirrorID1 = (id == 8) || (id == 9) ? 10 : 8;
-		int mirrorID2 = (id == 8) || (id == 9) ? 11 : 9;
-
-		for (BlockFace face : this.faces) {
-			Block r = b.getRelative(face, 1);
-			if ((r.getTypeId() == mirrorID1) || (r.getTypeId() == mirrorID2)) {
-				Entry<Boolean, Boolean> e = new AbstractMap.SimpleEntry<Boolean, Boolean>(true, false);
-				if (face.equals(BlockFace.UP)) {
-					e.setValue(true);
-				} else {
-					e.setValue(false);
-				}
-				return e;
-			}
-		}
-		Entry<Boolean, Boolean> e = new AbstractMap.SimpleEntry<Boolean, Boolean>(false, false);
-		return new AbstractMap.SimpleEntry<Boolean, Boolean>(false, false);
-	}
 }

+ 1 - 1
src/plugin.yml

@@ -1,5 +1,5 @@
 name: CustomOreGen
-version: 1.2.2
+version: 1.2.3
 description: Controls the Ore-Generator
 author: Linus122
 soft-depends: [ASkyBlock, AcidIsland, uSkyBlock]