|
@@ -2,50 +2,55 @@ package de.Linus122.customoregen;
|
|
|
|
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
|
|
|
|
-import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.OfflinePlayer;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.block.Block;
|
|
-import org.bukkit.entity.Player;
|
|
|
|
|
|
+import org.bukkit.block.BlockFace;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.Listener;
|
|
-import org.bukkit.event.block.BlockFormEvent;
|
|
|
|
|
|
+import org.bukkit.event.block.BlockFromToEvent;
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
|
|
public class Events implements Listener {
|
|
public class Events implements Listener {
|
|
@SuppressWarnings("deprecation")
|
|
@SuppressWarnings("deprecation")
|
|
@EventHandler
|
|
@EventHandler
|
|
- public void onCobbleGen(BlockFormEvent event) {
|
|
|
|
|
|
+ public void onFromTo(BlockFromToEvent event) {
|
|
if (Main.disabledWorlds.contains(event.getBlock().getLocation().getWorld().getName())) {
|
|
if (Main.disabledWorlds.contains(event.getBlock().getLocation().getWorld().getName())) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
- Material newBlock = event.getNewState().getType();
|
|
|
|
- Block b = event.getBlock();
|
|
|
|
|
|
|
|
- if (newBlock.equals(Material.COBBLESTONE) || newBlock.equals(Material.STONE)) {
|
|
|
|
-
|
|
|
|
- OfflinePlayer p = Main.getOwner(b.getLocation());
|
|
|
|
- if(p == null) return;
|
|
|
|
- GeneratorConfig gc = Main.getGeneratorConfigForPlayer(p);
|
|
|
|
- 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;
|
|
|
|
|
|
+ int id = event.getBlock().getTypeId();
|
|
|
|
+ if ((id >= 8) && (id <= 11)) {
|
|
|
|
+ Block b = event.getToBlock();
|
|
|
|
+ int toid = b.getTypeId();
|
|
|
|
+ if ((toid == 0) && (generatesCobble(id, b))) {
|
|
|
|
+ OfflinePlayer p = Main.getOwner(b.getLocation());
|
|
|
|
+ if (p == null)
|
|
|
|
+ return;
|
|
|
|
+ GeneratorConfig gc = Main.getGeneratorConfigForPlayer(p);
|
|
|
|
+ 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.setType(Material.getMaterial(winning.name));
|
|
|
|
+ // <Block>.setData(...) is deprecated, but there is no
|
|
|
|
+ // alternative to it. #spigot
|
|
|
|
+ b.setData(winning.damage, true);
|
|
}
|
|
}
|
|
- event.setCancelled(true);
|
|
|
|
- b.setType(Material.getMaterial(winning.name));
|
|
|
|
- b.setData(winning.damage, true);
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
@EventHandler
|
|
@EventHandler
|
|
- public void onJoin(PlayerJoinEvent e){
|
|
|
|
|
|
+ public void onJoin(PlayerJoinEvent e) {
|
|
Main.getGeneratorConfigForPlayer(e.getPlayer());
|
|
Main.getGeneratorConfigForPlayer(e.getPlayer());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -59,4 +64,19 @@ public class Events implements Listener {
|
|
}
|
|
}
|
|
return new GeneratorItem("COBBLESTONE", (byte) 0, 0); // DEFAULT
|
|
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 };
|
|
|
|
+
|
|
|
|
+ public 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)) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|