Help with Slap Plugin

Discussion in 'Plugin Development' started by dlcruz129, Sep 29, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    dlcruz129

    Hello.

    I wrote a plugin titled "Slap", which, when the player types /slap <player> [damage], it will broadcast a message to the server (<Slapped player> was slapped by <Slapping player>!), and launch the slapped player in a random direction. (Similar to the slap command in Source Mod, commonly found on TF2 servers)

    I get the following error message when running the command, however:
    Show Spoiler
    Code:
    29.09 15:22:02 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 15:22:02 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 15:22:02 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:594)
    29.09 15:22:02 [Server] INFO at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:132)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    29.09 15:22:02 [Server] INFO at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:230)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:834)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:887)
    29.09 15:22:02 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:976)
    29.09 15:22:02 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:527)
    29.09 15:22:02 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    29.09 15:22:02 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 15:22:02 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0


    Here is my code:
    Show Spoiler

    Code:java
    1. package com.github.TypoKign.Slap;
    2. import java.util.Random;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.util.Vector;
    11.  
    12.  
    13. public final class Slap extends JavaPlugin{
    14.  
    15. public void onEnable() {
    16.  
    17. }
    18.  
    19. public void onDisable() {
    20.  
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    24. Player player = (Player) sender;
    25. if(cmd.getName().equalsIgnoreCase("slap")) {
    26. if (player.hasPermission("Slap.slap")) {
    27. if (args.length > 0) {
    28. if (args.length == 1) {
    29. getServer().broadcastMessage(Bukkit.getPlayer(args[1]).getDisplayName() + ChatColor.GREEN + "was slapped by" + player.getDisplayName() + ChatColor.GREEN + "!");
    30. slapPlayer(Bukkit.getPlayer(args[1]), 0D);
    31. } else {
    32. slapPlayer(Bukkit.getPlayer(args[1]), Double.parseDouble(args[2]));
    33. }
    34. }
    35. }
    36. }
    37. return false;
    38.  
    39. }
    40.  
    41. public void slapPlayer(Player playerName, Double damage) {
    42. playerName.damage(damage);
    43. Random random = new Random();
    44. playerName.setVelocity(new Vector(random.nextGaussian(),random.nextDouble(),random.nextGaussian()));
    45. }
    46.  
    47. }
    48.  



    Any help is appreciated!

    --Dlcruz
     
  2. Offline

    ZeusAllMighty11

    The first element in an array is actually 0, not 1.

    So you are checking for a second argument, which there is none of, and executing your code with it, hence the error.

    Just change args[1] to args[0]
     
    tommycake50 likes this.
  3. Offline

    tommycake50

    You didn't pay attention when learning about arrays did you?
    In arrays indexes start at 0.
    Edit: ninja'd by TheGreenGamerHD.
     
  4. Offline

    dlcruz129

    Damn, I always make that mistake :p

    However, I am still getting the same error.

    UPDATED CODE:
    Code:java
    1. package com.github.TypoKign.Slap;
    2. import java.util.Random;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.util.Vector;
    11.  
    12.  
    13. public final class Slap extends JavaPlugin{
    14.  
    15. public void onEnable() {
    16.  
    17. }
    18.  
    19. public void onDisable() {
    20.  
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    24. Player player = (Player) sender;
    25. if(cmd.getName().equalsIgnoreCase("slap")) {
    26. if (player.hasPermission("Slap.slap")) {
    27. if (args.length > 0) {
    28. if (args.length == 1) {
    29. getServer().broadcastMessage(Bukkit.getPlayer(args[1]).getDisplayName() + ChatColor.GREEN + "was slapped by" + player.getDisplayName() + ChatColor.GREEN + "!");
    30. slapPlayer(Bukkit.getPlayer(args[0]), 0D);
    31. } else {
    32. slapPlayer(Bukkit.getPlayer(args[0]), Double.parseDouble(args[1]));
    33. }
    34. }
    35. }
    36. }
    37. return false;
    38.  
    39. }
    40.  
    41. public void slapPlayer(Player playerName, Double damage) {
    42. playerName.damage(damage);
    43. Random random = new Random();
    44. playerName.setVelocity(new Vector(random.nextGaussian(),random.nextDouble(),random.nextGaussian()));
    45. }
    46.  
    47. }
    48.  
     
  5. Offline

    tommycake50

    You didn't change the one on line 29.
     
  6. Offline

    MrSparkzz

    Your code is looking for the second argument (Lines 29 & 32), but you have it check if the arguments length is 1.

    EDIT: Ninja'd by tommycake50
     
  7. Offline

    dlcruz129

    After making some changes to make the plugin Console/Command block compatible, it broke again with a NPE.

    Full crash:
    Code:
    29.09 17:10:11 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:11 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:11 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:11 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:11 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:11 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:11 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:11 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:11 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:11 [Server] WARNING Task #1547 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:11 [Server] INFO ... 8 more
    29.09 17:10:11 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:11 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:11 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:11 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:11 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:11 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:11 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:11 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:11 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:11 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:11 [Server] WARNING Task #1541 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:10 [Server] INFO ... 8 more
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:10 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:10 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:10 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:10 [Server] WARNING Task #1540 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:10 [Server] INFO ... 8 more
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:10 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:10 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:10 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:10 [Server] WARNING Task #1539 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:10 [Server] INFO ... 8 more
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:10 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:10 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:10 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:10 [Server] WARNING Task #1537 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:10 [Server] INFO ... 8 more
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:10 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:10 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:10 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:10 [Server] WARNING Task #1535 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:10 [Server] INFO ... 8 more
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:10 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:10 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    29.09 17:10:10 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:520)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    29.09 17:10:10 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:58)
    29.09 17:10:10 [Server] INFO at com.earth2me.essentials.commands.Commandsudo$1.run(Commandsudo.java:64)
    29.09 17:10:10 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.09 17:10:10 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'slap' in plugin Slap v1.0
    29.09 17:10:10 [Server] WARNING Task #1530 for Essentials vPre2.12.1.2 generated an exception
    29.09 17:10:09 [Server] INFO ... 8 more
    29.09 17:10:09 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.09 17:10:09 [Server] INFO at com.github.TypoKign.Slap.Slap.onCommand(Slap.java:32)
    29.09 17:10:09 [Server] INFO at com.github.TypoKign.Slap.Slap.slapPlayer(Slap.java:52)
    29.09 17:10:09 [Server] INFO Caused by: java.lang.NullPointerException
    29.09 17:10:09 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    29.09 17:10:09 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:415)
    29.09 17:10:09 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:483)
    
    UPDATED CODE:

    Code:java
    1. package com.github.TypoKign.Slap;
    2. import java.util.Random;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.util.Vector;
    11.  
    12.  
    13. public final class Slap extends JavaPlugin{
    14.  
    15. public void onEnable() {
    16.  
    17. }
    18.  
    19. public void onDisable() {
    20.  
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    24. if(cmd.getName().equalsIgnoreCase("slap")) {
    25. if (sender.hasPermission("Slap.slap")) {
    26. if (args.length > 0) {
    27. if (sender instanceof Player) {
    28. Player player = (Player) sender;
    29. if (args.length == 1) {
    30. sender.sendMessage(ChatColor.GREEN+"Slapped " + args[0]);
    31. getServer().getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Slapped by " + player.getDisplayName());
    32. slapPlayer(Bukkit.getPlayer(args[0]).getDisplayName(), 0D);
    33. return true;
    34. } else {
    35. sender.sendMessage(ChatColor.GREEN+"Slapped " + args[0]);
    36. getServer().getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Slapped by " + player.getDisplayName());
    37. slapPlayer(Bukkit.getPlayer(args[0]).getDisplayName(), Double.parseDouble(args[1]));
    38. return true;
    39. }
    40. } else {
    41. getServer().getPlayer(args[0]).sendMessage(ChatColor.GREEN + "Slapped by Console or Command Block");
    42. slapPlayer(Bukkit.getPlayer(args[0]).getDisplayName(), 0D);
    43. }
    44. }
    45. }
    46. }
    47. return false;
    48.  
    49. }
    50.  
    51. public void slapPlayer(String playerName, Double damage) {
    52. getServer().getPlayer(playerName).damage(damage);
    53. Random random = new Random();
    54. getServer().getPlayer(playerName).setVelocity(new Vector(random.nextGaussian(),random.nextDouble(),random.nextGaussian()));
    55. }
    56.  
    57. }
    58.  


    Bump! I'm still having trouble with this, so any help is appreciated. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Offline

    tommycake50

    Display name can be different from qualified name. use .getName
     
Thread Status:
Not open for further replies.

Share This Page