Skip to content

Instantly share code, notes, and snippets.

@DevSrSouza
Last active March 30, 2020 03:48
Show Gist options
  • Save DevSrSouza/2ea8c1235800dd68bdf78b9643f83c6a to your computer and use it in GitHub Desktop.
Save DevSrSouza/2ea8c1235800dd68bdf78b9643f83c6a to your computer and use it in GitHub Desktop.
Mineradora Exemplo
import org.bukkit.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Mineradora implements CommandExecutor{
private MineradoraThread thread = null;
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if(commandSender.isOp()) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("start")) {
if(!mineradora(true, ((Player)commandSender).getLocation())){
commandSender.sendMessage("Ja esta ligada");
}else{
commandSender.sendMessage("Voce ligou a mineradora");
}
} else if (args[0].equalsIgnoreCase("stop")) {
if(!mineradora(false, null)) {
commandSender.sendMessage("Nao esta ligada");
}else{
commandSender.sendMessage("Voce desligou a mineradora");
}
}
}
}
return false;
}
public boolean mineradora(boolean start, Location mid) {
if (start) {
if(thread == null) {
thread = new MineradoraThread(mid);
thread.start();
return true;
}else{
return false;
}
}else{
if(thread != null) {
thread.interrupt();
thread = null;
return true;
}else{
return false;
}
}
}
public class MineradoraThread extends Thread {
private Location mid;
private Location max;
private Location min;
public MineradoraThread(Location mid) {
this.mid = mid;
max = mid.clone().add(5,0,5);
min = mid.clone().subtract(5,0,5);
}
@Override
public synchronized void start() {
Bukkit.getScheduler().runTask(Main.plugin, new Runnable() {
@Override
public void run() {
for(int z = 0; z <= max.getBlockX() - min.getBlockX(); z++) {
Location zPosition = min.clone().add(0,0, z);
Location zMaxPosition = zPosition.clone();
zMaxPosition.setX(max.getX());
zPosition.getBlock().setType(Material.WOOD);
zMaxPosition.getBlock().setType(Material.WOOD);
Location xPosition = min.clone().add(z,0, 0);
Location xMaxPosition = xPosition.clone();
xMaxPosition.setZ(max.getZ());
xPosition.getBlock().setType(Material.WOOD);
xMaxPosition.getBlock().setType(Material.WOOD);
}
max.getBlock().setType(Material.DIAMOND_BLOCK);
min.getBlock().setType(Material.DIAMOND_BLOCK);
}
});
super.start();
}
@Override
public void run() {
Location minNEW = min.clone().add(1,0,1);
Location maxNEW = max.clone().subtract(1,0,1);
for(int i = minNEW.getBlockY(); i > 1; i--) {
for(int x = 0; x <= maxNEW.getBlockX() - minNEW.getBlockX(); x++) {
for(int z = 0; z <= maxNEW.getBlockZ() - minNEW.getBlockZ(); z++) {
int newZ = x%2 > 0 ? (maxNEW.getBlockZ() - minNEW.getBlockZ()) - z : z;
Location block = minNEW.clone().add(x, 0, newZ);
block.setY(i);
if(block.getBlock().getType() != Material.AIR && block.getBlock().getType() != Material.BEDROCK) {
Bukkit.getScheduler().runTask(Main.plugin, () -> {
block.getBlock().getDrops().forEach(item -> block.getWorld().dropItemNaturally(min.clone().subtract(1,1,0), item));
block.getBlock().setType(Material.AIR);
});
//block.getWorld().spawnParticle(Particle.BLOCK_CRACK, block.getBlockX()+0.5, block.getBlockY()+0.5, block.getBlockZ()+0.5, block.getBlock().getTypeId());
try {
sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}else{
continue;
}
}
}
}
i
}
}
}
@RafaelrainBR
Copy link

_ Código Topzera souza_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment