Add /vomit

This commit is contained in:
Trever Fischer 2012-04-01 15:10:14 -04:00
parent 4b4e8acae9
commit 1d4138866d
3 changed files with 105 additions and 0 deletions

View File

@ -37,6 +37,7 @@ public class Plugin extends JavaPlugin {
private Server m_api;
private JoinListener m_listener;
private MOTDCommand m_motdCommand;
private VomitCommand m_vomitCommand;
public Server api() {
return m_api;
@ -58,6 +59,8 @@ public class Plugin extends JavaPlugin {
m_motdCommand = new MOTDCommand(this);
getCommand("motd").setExecutor(m_motdCommand);
m_vomitCommand = new VomitCommand(this);
getCommand("vomit").setExecutor(m_vomitCommand);
log.info("[Caminus] Plugin enabled");
}

View File

@ -0,0 +1,95 @@
package us.camin;
/*
This file is part of Caminus
Caminus is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Caminus is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Caminus. If not, see <http://www.gnu.org/licenses/>.
*/
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.inventory.ItemStack;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import org.bukkit.Location;
import java.lang.Thread;
import java.lang.Runnable;
public class VomitCommand implements CommandExecutor {
private Plugin m_plugin;
public VomitCommand(Plugin p) {
m_plugin = p;
}
private class VomitRunner implements Runnable {
private ItemStack m_stack;
private Player m_target;
private int m_qty;
public VomitRunner(ItemStack stack, Player target, int quantity) {
m_stack = stack;
m_target = target;
m_qty = quantity;
}
public void run() {
for(int i = 0;i<m_qty;i++) {
Location vomitLocation = m_target.getEyeLocation();
double speed = 0.5;
double pitch = vomitLocation.getPitch()+90;
double yaw = vomitLocation.getYaw()+90;
double xSpeed = Math.cos(Math.toRadians(yaw))*Math.sin(Math.toRadians(pitch));
double zSpeed = Math.sin(Math.toRadians(pitch))*Math.sin(Math.toRadians(yaw));
double ySpeed = Math.cos(Math.toRadians(pitch));
Vector vomitVelocity = new Vector(xSpeed*speed, ySpeed*speed, zSpeed*speed);
Item item = m_target.getWorld().dropItem(vomitLocation, m_stack);
item.setPickupDelay(3);
item.setVelocity(vomitVelocity);
try {
Thread.currentThread().sleep(10);
} catch (InterruptedException e) {
}
}
}
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
if (sender.hasPermission("caminus.vomit")) {
if (split.length < 3) {
sender.sendMessage("Usage: /"+command+" player quantity item");
return true;
}
String target = split[0];
Player player = sender.getServer().getPlayer(target);
int qty;
try {
qty = Integer.parseInt(split[1]);
} catch (NumberFormatException e) {
sender.sendMessage("Not a number: "+split[1]);
return true;
}
String itemName = split[2];
ItemStack stack = new ItemStack(Material.valueOf(itemName.toUpperCase()));
Thread runner = new Thread(new VomitRunner(stack, player, qty));
runner.start();
}
return true;
}
}

View File

@ -7,6 +7,9 @@ commands:
motd:
description: Displays the MOTD
usage: /<command>
vomit:
description: Causes a player to vomit blocks
usage: /<command> player quantity item
permissions:
caminus.*:
default: op
@ -14,9 +17,13 @@ permissions:
children:
caminus.whitelisted: true
caminus.freedoorday: true
caminus.vomit: true
caminus.freedoorday:
default: false
description: Enables free half door day
caminus.vomit:
default: op
description: Enables /vomit
caminus.whitelisted:
default: op
description: Allows user to bypass caminus API whitelisting