Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.wakils.Launch;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- // import org.bukkit.event.Listener;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin { // remember to 'implements Listener' when bringing a listener into the code
- @Override
- public void onEnable() {
- // this.getServer().getPluginManager().registerEvents(this, this);
- }
- @Override
- public void onDisable() {
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (label.equalsIgnoreCase("launch") || label.equalsIgnoreCase("lch") ) {
- if (!(sender instanceof Player)) {
- sender.sendMessage("Console can't use /launch");
- return true;
- }
- Player player = (Player) sender;
- // /launch
- if (!(player.hasPermission("launch.use"))) {
- player.sendMessage(ChatColor.RED + "" + "You don't have permission to do this!");
- return true;
- }
- if (args.length == 0) {
- player.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
- player.setVelocity(player.getLocation().getDirection().multiply(2).setY(2));
- return true;
- }
- // /launch NUMBER/PLAYER
- if (args.length == 1) {
- // help
- if (args[0].equalsIgnoreCase("help")) {
- fail(player);
- return true;
- }
- //launch NUMBER
- if (isNum(args[0])) {
- player.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
- player.setVelocity(player.getLocation().getDirection().multiply(Integer.parseInt(args[0])).setY(2));
- return true;
- }
- //launch PLAYER
- if (!isNum(args[0])) {
- Player target = Bukkit.getServer().getPlayer(args[0]);
- if (!(player.hasPermission("launch.use.others"))) {
- player.sendMessage(ChatColor.RED + "" + "You don't have permission to do this!");
- return true;
- }
- if(target == null) {
- player.sendMessage(ChatColor.AQUA + args[0] + ChatColor.DARK_GREEN + " is either offline or doesn't exist.");
- return true;
- }
- if (!(target == player)) {
- player.sendMessage(ChatColor.DARK_GREEN + "You made " + ChatColor.YELLOW + ChatColor.BOLD + target.getName() +
- ChatColor.RESET + ChatColor.GREEN + " launch up into the sky!");
- }
- target.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
- target.setVelocity(target.getLocation().getDirection().multiply(2).setY(2));
- return true;
- }
- }
- // /launch PLAYER NUMBER
- Player target = Bukkit.getServer().getPlayer(args[0]);
- if (args.length == 2) {
- if (!(player.hasPermission("launch.use.others"))) {
- player.sendMessage(ChatColor.RED + "" + "You don't have permission to do this!");
- return true;
- }
- if(target == null) {
- player.sendMessage(ChatColor.AQUA + args[0] + ChatColor.DARK_GREEN + " is either offline or doesn't exist.");
- return true;
- }
- if(args[1] == null) {
- if (!(target == player)) {
- player.sendMessage(ChatColor.DARK_GREEN + "You made " + ChatColor.YELLOW + ChatColor.BOLD + target.getName() +
- ChatColor.RESET + ChatColor.GREEN + " launch up into the sky.");
- }
- target.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
- target.setVelocity(target.getLocation().getDirection().multiply(2).setY(2));
- return true;
- }
- if (!(target == player)) {
- player.sendMessage(ChatColor.DARK_GREEN + "You made " + ChatColor.YELLOW + ChatColor.BOLD + target.getName() +
- ChatColor.RESET + ChatColor.GREEN + " launch up into the sky.");
- }
- target.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
- target.setVelocity(target.getLocation().getDirection().multiply(Integer.parseInt(args[1])).setY(2));
- return true;
- }
- fail(player);
- }
- return false;
- }
- public boolean isNum(String num) {
- try {
- Integer.parseInt(num);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- public void fail(final Player player) {
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4=== &6&lLAUNCH &4==="));
- player.sendMessage(ChatColor.BLUE + "Usage:");
- player.sendMessage(ChatColor.GRAY + "/lch " + ChatColor.WHITE + "- launches yourself");
- player.sendMessage(ChatColor.GRAY + "/lch <integer> " + ChatColor.WHITE + "- launches yourself at increased velocity");
- player.sendMessage(ChatColor.GRAY + "/lch <player>" + ChatColor.WHITE + " - launches player");
- player.sendMessage(ChatColor.GRAY + "/lch <player> <integer>" + ChatColor.WHITE + " - launches player at increased velocity");
- player.sendMessage(ChatColor.GRAY + "/lch help");
- player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4=== &6&lLAUNCH &4==="));
- }
- // @EventHandler
- // public void onFall(EntityDamageEvent event) {
- // if (event.getEntity() instanceof Player) {
- // Player player = (Player) event.getEntity();
- // if (event.getCause() == DamageCause.FALL) {
- // this is where i need to check if the damage is caused by /launch
- // event.setCancelled(true);
- // }
- // }
- // }
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement