Skip to content

Instantly share code, notes, and snippets.

@Dinner1111
Last active December 20, 2015 14:49
Show Gist options
  • Save Dinner1111/6149334 to your computer and use it in GitHub Desktop.
Save Dinner1111/6149334 to your computer and use it in GitHub Desktop.
package io.github.Dinner1111.KittyCannon;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.*;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class KittyCannonPlugin extends JavaPlugin implements CommandExecutor {
double pitch;
double yaw;
double x;
double y;
double z;
float explosionPower;
Player p;
int task;
Vector vec;
Location loc;
@Override
public void onEnable() {
getLogger().info("Kittens: ready to cannon!");
}
@Override
public void onDisable() {
getLogger().info("Too much kitty carnage?");
}
public boolean onCommand(CommandSender sender, Command cmd, String cmdLine, String[] args) {
p = (Player) sender;
explosionPower = 1.5f;
if (cmd.getName().equalsIgnoreCase("kittycannon")) {
if (sender.hasPermission("Cannon.Kitty")) {
if (args.length == 0) {
if (sender instanceof Player) {
pitch = ((p.getLocation().getPitch() + 90) * Math.PI) / 180;
yaw = ((p.getLocation().getYaw() + 90) * Math.PI) / 180;
x = Math.sin(pitch) * Math.cos(yaw);
y = Math.sin(pitch) * Math.sin(yaw);
z = Math.cos(pitch);
vec = new Vector(x, z, y).multiply(2);
Ocelot e = (Ocelot) p.getWorld().spawnEntity(p.getLocation(), EntityType.OCELOT);
e.setVelocity(vec);
p.sendMessage(ChatColor.GRAY + "Another one bites the dust...");
task = Bukkit.getServer().getScheduler()
.scheduleSyncDelayedTask(this, new Runnable() {
public void run() {
e.getWorld().createExplosion(e.getLocation(), explosionPower); // error
e.setHealth(0); // error
Bukkit.getScheduler().cancelTask(task);
}
}, 10);
}
} else {
return false;
}
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment