Skip to content

Instantly share code, notes, and snippets.

@Densyakun
Created February 11, 2018 19:24
Show Gist options
  • Save Densyakun/41cd233a175fd9f9ca850b63061ef70b to your computer and use it in GitHub Desktop.
Save Densyakun/41cd233a175fd9f9ca850b63061ef70b to your computer and use it in GitHub Desktop.
[BukkitPlugin]ブロックが爆破すると、吹っ飛ぶプラグイン。楽しい。TNTを大量に設置すると大爆発が起こる。This bukkit plugin is pop block on explosion.
package org.densyakun.bukkit.blockpop;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class Main extends JavaPlugin implements Listener {
public TNTGame tntgame;
@Override
public void onEnable() {
new Thread(tntgame = new TNTGame(getServer().getWorld("world"))).start();
getServer().getPluginManager().registerEvents(this, this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (label.equalsIgnoreCase("tntstart")) {
if (tntgame != null) {
tntgame.tnt = true;
sender.sendMessage("TNTSTARTED.");
}
} else if (label.equalsIgnoreCase("tntstop")) {
if (tntgame != null) {
tntgame.tnt = false;
sender.sendMessage("TNTSTOPED.");
}
}
return true;
}
@Override
public void onDisable() {
if (tntgame != null)
tntgame.run = false;
}
@EventHandler
public void BlockPlace(BlockPlaceEvent e) {
if (e.getBlock().getType() == Material.TNT) {
e.getBlock().getWorld().spawnEntity(e.getBlock().getLocation(), EntityType.PRIMED_TNT);
e.getBlock().setType(Material.AIR);
}
}
@EventHandler
public void EntityExplode(EntityExplodeEvent e) {
for (int a = 0; a < e.blockList().size(); a++) {
if (e.blockList().get(a).getType() == Material.TNT) {
e.blockList().get(a).getWorld().spawnEntity(e.blockList().get(a).getLocation(), EntityType.PRIMED_TNT)
.setVelocity(new Vector(
(e.blockList().get(a).getLocation().getX() - e.getEntity().getLocation().getX()) / 2,
e.blockList().get(a).getLocation().getY() - e.getEntity().getLocation().getY(),
(e.blockList().get(a).getLocation().getZ() - e.getEntity().getLocation().getZ()) / 2));
} else {
e.blockList().get(a).getWorld()
.spawnFallingBlock(e.blockList().get(a).getLocation(), e.blockList().get(a).getType(),
e.blockList().get(a).getData())
.setVelocity(new Vector(
(e.blockList().get(a).getLocation().getX() - e.getEntity().getLocation().getX()) / 2,
e.blockList().get(a).getLocation().getY() - e.getEntity().getLocation().getY(),
(e.blockList().get(a).getLocation().getZ() - e.getEntity().getLocation().getZ()) / 2));
}
e.blockList().get(a).setType(Material.AIR);
}
e.blockList().clear();
}
}
class TNTGame implements Runnable {
public boolean run = true;
public boolean tnt = false;
public World world;
public TNTGame(World world) {
this.world = world;
}
@Override
public void run() {
while (run) {
if (tnt && world != null) {
world.spawnEntity(new Location(world, 353 + new Random().nextInt(24) + 0.5, 82.0,
-267 + new Random().nextInt(24) + 0.5), EntityType.PRIMED_TNT);
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment