use of org.bukkit.entity.TNTPrimed in project TotalFreedomMod by TotalFreedom.
the class Landminer method onPlayerMove.
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event) {
if (!(ConfigEntry.LANDMINES_ENABLED.getBoolean() && ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) {
return;
}
final Player player = event.getPlayer();
final Iterator<Landmine> lit = landmines.iterator();
while (lit.hasNext()) {
final Landmine landmine = lit.next();
final Location location = landmine.location;
if (location.getBlock().getType() != Material.TNT) {
lit.remove();
continue;
}
if (landmine.planter.equals(player)) {
break;
}
if (!player.getWorld().equals(location.getWorld())) {
continue;
}
if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius))) {
break;
}
landmine.location.getBlock().setType(Material.AIR);
final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class);
tnt1.setFuseTicks(40);
tnt1.setPassenger(player);
tnt1.setVelocity(new Vector(0.0, 2.0, 0.0));
final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class);
tnt2.setFuseTicks(1);
player.setGameMode(GameMode.SURVIVAL);
lit.remove();
}
}
use of org.bukkit.entity.TNTPrimed in project Essentials by drtshock.
the class Commandnuke method run.
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NoSuchFieldException, NotEnoughArgumentsException {
Collection<Player> targets;
if (args.length > 0) {
targets = new ArrayList<>();
int pos = 0;
for (String arg : args) {
targets.add(getPlayer(server, sender, args, pos).getBase());
pos++;
}
} else {
targets = ess.getOnlinePlayers();
}
ess.getTNTListener().enable();
for (Player player : targets) {
if (player == null) {
continue;
}
player.sendMessage(tl("nuke"));
final Location loc = player.getLocation();
final World world = loc.getWorld();
for (int x = -10; x <= 10; x += 5) {
for (int z = -10; z <= 10; z += 5) {
final Location tntloc = new Location(world, loc.getBlockX() + x, world.getHighestBlockYAt(loc) + 64, loc.getBlockZ() + z);
final TNTPrimed tnt = world.spawn(tntloc, TNTPrimed.class);
}
}
}
}
use of org.bukkit.entity.TNTPrimed in project TotalFreedomMod by TotalFreedom.
the class ItemFun method onPlayerInteractEvent.
@EventHandler
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
return;
}
final Player player = event.getPlayer();
final FPlayer fPlayer = plugin.pl.getPlayer(player);
switch(event.getMaterial()) {
case RAW_FISH:
{
final int RADIUS_HIT = 5;
final int STRENGTH = 4;
// Clownfish
if (DepreciationAggregator.getData_MaterialData(event.getItem().getData()) != 2) {
break;
}
if (!plugin.al.isSeniorAdmin(player)) {
final StringBuilder msg = new StringBuilder();
final char[] chars = ("You are a clown.").toCharArray();
for (char c : chars) {
msg.append(FUtil.randomChatColor()).append(c);
}
player.sendMessage(msg.toString());
player.getEquipment().getItemInMainHand().setType(Material.POTATO_ITEM);
break;
}
event.setCancelled(true);
boolean didHit = false;
final Location playerLoc = player.getLocation();
final Vector playerLocVec = playerLoc.toVector();
final List<Player> players = player.getWorld().getPlayers();
for (final Player target : players) {
if (target == player) {
continue;
}
final Location targetPos = target.getLocation();
final Vector targetPosVec = targetPos.toVector();
try {
if (targetPosVec.distanceSquared(playerLocVec) < (RADIUS_HIT * RADIUS_HIT)) {
FUtil.setFlying(player, false);
target.setVelocity(targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
didHit = true;
}
} catch (IllegalArgumentException ex) {
}
}
if (didHit) {
final Sound[] sounds = Sound.values();
for (Sound sound : sounds) {
if (sound.toString().contains("HIT")) {
playerLoc.getWorld().playSound(randomOffset(playerLoc, 5.0), sound, 100.0f, randomDoubleRange(0.5, 2.0).floatValue());
}
}
}
break;
}
case CARROT_ITEM:
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
break;
}
if (!plugin.al.isSeniorAdmin(player)) {
break;
}
Location location = player.getLocation().clone();
Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
Vector playerDirection = location.getDirection().normalize();
double distance = 150.0;
Block targetBlock = DepreciationAggregator.getTargetBlock(player, null, Math.round((float) distance));
if (targetBlock != null) {
distance = location.distance(targetBlock.getLocation());
}
final List<Block> affected = new ArrayList<>();
Block lastBlock = null;
for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
Block block = playerPostion.clone().add(playerDirection.clone().multiply(offset)).toLocation(player.getWorld()).getBlock();
if (!block.equals(lastBlock)) {
if (block.isEmpty()) {
affected.add(block);
block.setType(Material.TNT);
} else {
break;
}
}
lastBlock = block;
}
new BukkitRunnable() {
@Override
public void run() {
for (Block tntBlock : affected) {
TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
tnt.setFuseTicks(5);
tntBlock.setType(Material.AIR);
}
}
}.runTaskLater(plugin, 30L);
event.setCancelled(true);
break;
}
case BONE:
{
if (!fPlayer.mobThrowerEnabled()) {
break;
}
Location player_pos = player.getLocation();
Vector direction = player_pos.getDirection().normalize();
LivingEntity rezzed_mob = (LivingEntity) player.getWorld().spawnEntity(player_pos.add(direction.multiply(2.0)), fPlayer.mobThrowerCreature());
rezzed_mob.setVelocity(direction.multiply(fPlayer.mobThrowerSpeed()));
fPlayer.enqueueMob(rezzed_mob);
event.setCancelled(true);
break;
}
case SULPHUR:
{
if (!fPlayer.isMP44Armed()) {
break;
}
event.setCancelled(true);
if (fPlayer.toggleMP44Firing()) {
fPlayer.startArrowShooter(plugin);
} else {
fPlayer.stopArrowShooter();
}
break;
}
case BLAZE_ROD:
{
if (!ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
break;
}
if (!plugin.al.isSeniorAdmin(player)) {
break;
}
event.setCancelled(true);
Block targetBlock;
if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
targetBlock = DepreciationAggregator.getTargetBlock(player, null, 120);
} else {
targetBlock = event.getClickedBlock();
}
if (targetBlock == null) {
player.sendMessage("Can't resolve target block.");
break;
}
player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
player.getWorld().strikeLightning(targetBlock.getLocation());
break;
}
}
}
Aggregations