Making a KillPlayer Plugin

Discussion in 'Plugin Development' started by Matthu699, Oct 5, 2013.

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

    Matthu699

    Hello today I decided to make a plugin that would make my factions server better but can’t seem to get the command to work. It will Enable and everything just when I try to use the command I get an Internal Error Any help would be great.

    Code:java
    1. package com.hybrah;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandSender;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public final class KillPlayer extends JavaPlugin {
    9.  
    10. public void onEnable(){
    11. getLogger().info("Has been Enabled!");
    12. }
    13. public void onDisable() {
    14. getLogger().info("Has been Disbaled");
    15. }
    16. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    17. if(cmd.getName().equalsIgnoreCase("KillPlayer")){
    18. Player target = sender.getServer().getPlayer(args[0]);
    19.  
    20. if (target == null) {
    21. sender.sendMessage(args[0] + " is not online, Try to kill a player that is online.");
    22. return true;
    23. }
    24. float explosionPower = 10F;
    25. Player target1 = sender.getWorld().getPlayer(args[0]);
    26. target1.getWorld().createExplosion(target1.getLocation(), explosionPower);
    27. target1.setHealth(0);
    28. }
    29. return false;



    Plugin.yml

    Code:
    name: KillPlayer
    main: com.hybrah.KillPlayer
    version: 1.0
    description: Kills player with Explosive force
    commands:
      KillPlayer:
        description: Kills player with explosive force
     
  2. Offline

    adam753

    Can you post the error message?
     
  3. Offline

    Goblom

    Why do you have a target and a target 1.

    You can easily do the same thing target1 does with target.getLocation();
    Code:java
    1. float explosionPower = 10F;
    2. target.getWorld().createExplosion(target.getLocation(), explosionPower);
    3. target.setHealth(0);


    That will also most likely fix your error
     
  4. Offline

    Matthu699

    Alright I will put it in and see how it goes

    That worked perfectly. I have another question so if I wanted to have a custom death message when a player is killed with that command how would I do that.

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

    adam753

    Matthu699
    Why not just broadcast a message at the end of the command?
     
  6. Offline

    jimuskin

    Syntax is sortof incorrect...
    also, try something like this:
    Code:java
    1.  
    2. public class (yourclass) extends JavaPlugin{
    3.  
    4. public void onEnable(){
    5. getLogger().info("Has been Enabled!");
    6. }
    7. public void onDisable() {
    8. getLogger().info("Has been Disbaled");
    9. }
    10. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    11. if(cmd.getName().equalsIgnoreCase("KillPlayer")){
    12. Player target = sender.getServer().getPlayer(args[0]);
    13. // Make sure the player is online.
    14. if (target == null) {
    15. sender.sendMessage(args[0] + " is not currently online.");
    16. return true;
    17. }
    18. float explosionPower = 10F; //This is the explosion power - TNT explosions are 4F by default
    19. target.getWorld().createExplosion(target.getLocation(), explosionPower);
    20. target.setHealth(0.00);
    21. }
    22. return false;
    23. }
    24. }
    25.  
     
  7. Offline

    Matthu699

  8. Offline

    adam753

    Matthu699
    Bukkit.broadcastMessage("Your message");
     
  9. Offline

    Matthu699

    Alright Thanks
     
Thread Status:
Not open for further replies.

Share This Page